ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [3/3] ignite git commit: IGNITE-1816: Getting closer to finish.
Date Wed, 11 Nov 2015 13:17:40 GMT
IGNITE-1816: Getting closer to finish.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ed3472d4
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ed3472d4
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ed3472d4

Branch: refs/heads/ignite-1816
Commit: ed3472d4eece5fe6682ff6b97a5e6fcd805f5e2c
Parents: b00502a
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Wed Nov 11 16:17:57 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Wed Nov 11 16:17:57 2015 +0300

----------------------------------------------------------------------
 .../portable/BinaryMetadataCollector.java       | 42 +++++++++++++++-----
 .../internal/portable/BinaryWriterExImpl.java   | 28 +++++++++++--
 .../portable/PortableClassDescriptor.java       | 20 +++++++---
 .../internal/portable/PortableContext.java      | 30 +++++++++-----
 .../builder/BinaryObjectBuilderImpl.java        |  4 +-
 5 files changed, 94 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ed3472d4/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataCollector.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataCollector.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataCollector.java
index 67e1a0d..ab2fbce 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataCollector.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataCollector.java
@@ -23,10 +23,13 @@ import java.lang.reflect.Proxy;
 import java.math.BigDecimal;
 import java.sql.Timestamp;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
+
+import org.apache.ignite.binary.BinaryIdMapper;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryRawWriter;
 import org.apache.ignite.binary.BinaryWriter;
@@ -36,17 +39,32 @@ import org.jetbrains.annotations.Nullable;
  * Writer for meta data collection.
  */
 class BinaryMetadataCollector implements BinaryWriter {
-    /** */
-    private final Map<String, Integer> meta = new HashMap<>();
+    /** Type ID. */
+    private final int typeId;
 
-    /** */
+    /** Type name. */
     private final String typeName;
 
+    /** ID mapper. */
+    private final BinaryIdMapper idMapper;
+
+    /** Collected metadata. */
+    private final Map<String, Integer> meta = new HashMap<>();
+
+    /** Schema builder. */
+    private PortableSchema.Builder schemaBuilder = PortableSchema.Builder.newBuilder();
+
     /**
+     * Constructor.
+     *
+     * @param typeId Type ID.
      * @param typeName Type name.
+     * @param idMapper ID mapper.
      */
-    BinaryMetadataCollector(String typeName) {
+    BinaryMetadataCollector(int typeId, String typeName, BinaryIdMapper idMapper) {
+        this.typeId = typeId;
         this.typeName = typeName;
+        this.idMapper = idMapper;
     }
 
     /**
@@ -56,6 +74,13 @@ class BinaryMetadataCollector implements BinaryWriter {
         return meta;
     }
 
+    /**
+     * @return Schemas.
+     */
+    Collection<PortableSchema> schemas() {
+        return Collections.singleton(schemaBuilder.build());
+    }
+
     /** {@inheritDoc} */
     @Override public void writeByte(String fieldName, byte val) throws BinaryObjectException
{
         add(fieldName, PortableClassDescriptor.Mode.BYTE);
@@ -242,13 +267,12 @@ class BinaryMetadataCollector implements BinaryWriter {
 
         if (oldFieldTypeId != null && !oldFieldTypeId.equals(fieldTypeId)) {
             throw new BinaryObjectException(
-                "Field is written twice with different types [" +
-                "typeName=" + typeName +
-                ", fieldName=" + name +
+                "Field is written twice with different types [" + "typeName=" + typeName
+ ", fieldName=" + name +
                 ", fieldTypeName1=" + PortableUtils.fieldTypeName(oldFieldTypeId) +
-                ", fieldTypeName2=" + PortableUtils.fieldTypeName(fieldTypeId) +
-                ']'
+                ", fieldTypeName2=" + PortableUtils.fieldTypeName(fieldTypeId) + ']'
             );
         }
+
+        schemaBuilder.addField(idMapper.fieldId(typeId, name));
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ed3472d4/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
index 5a48833..23d9311 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
@@ -133,7 +133,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx,
Obje
     private SchemaHolder schema;
 
     /** Schema ID. */
-    private int schemaId;
+    private int schemaId = PortableUtils.schemaInitialId();
 
     /** Amount of written fields. */
     private int fieldCnt;
@@ -1732,9 +1732,6 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx,
Obje
 
                 SCHEMA.set(schema);
             }
-
-            // Initialize offset when the first field is written.
-            schemaId = PortableUtils.schemaInitialId();
         }
 
         schemaId = PortableUtils.updateSchemaId(schemaId, fieldId);
@@ -1745,6 +1742,18 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx,
Obje
     }
 
     /**
+     * @return Current writer's schema.
+     */
+    public PortableSchema currentSchema() {
+        PortableSchema.Builder builder = PortableSchema.Builder.newBuilder();
+
+        if (schema != null)
+            schema.build(builder, fieldCnt);
+
+        return builder.build();
+    }
+
+    /**
      * Attempts to write the object as a handle.
      *
      * @param obj Object to write.
@@ -1829,6 +1838,17 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx,
Obje
         }
 
         /**
+         * Build the schema.
+         *
+         * @param builder Builder.
+         * @param fieldCnt Fields count.
+         */
+        public void build(PortableSchema.Builder builder, int fieldCnt) {
+            for (int curIdx = idx - fieldCnt * 2; curIdx < idx; curIdx += 2)
+                builder.addField(data[curIdx]);
+        }
+
+        /**
          * Write collected frames and pop them.
          *
          * @param writer Writer.

http://git-wip-us.apache.org/repos/asf/ignite/blob/ed3472d4/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
index 361c754..c6c8d34 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
@@ -80,6 +80,9 @@ public class PortableClassDescriptor {
     /** */
     private final String typeName;
 
+    /** Affinity key field name. */
+    private final String affKeyFieldName;
+
     /** */
     private final Constructor<?> ctor;
 
@@ -116,6 +119,7 @@ public class PortableClassDescriptor {
      * @param userType User type flag.
      * @param typeId Type ID.
      * @param typeName Type name.
+     * @param affKeyFieldName Affinity key field name.
      * @param idMapper ID mapper.
      * @param serializer Serializer.
      * @param metaDataEnabled Metadata enabled flag.
@@ -130,6 +134,7 @@ public class PortableClassDescriptor {
         boolean userType,
         int typeId,
         String typeName,
+        @Nullable String affKeyFieldName,
         @Nullable BinaryIdMapper idMapper,
         @Nullable BinarySerializer serializer,
         boolean metaDataEnabled,
@@ -139,12 +144,14 @@ public class PortableClassDescriptor {
     ) throws BinaryObjectException {
         assert ctx != null;
         assert cls != null;
+        assert idMapper != null;
 
         this.ctx = ctx;
         this.cls = cls;
         this.userType = userType;
         this.typeId = typeId;
         this.typeName = typeName;
+        this.affKeyFieldName = affKeyFieldName;
         this.serializer = serializer;
         this.idMapper = idMapper;
         this.keepDeserialized = keepDeserialized;
@@ -212,8 +219,6 @@ public class PortableClassDescriptor {
                 break;
 
             case OBJECT:
-                assert idMapper != null;
-
                 ctor = constructor(cls);
                 fields = new ArrayList<>();
                 fieldsMeta = metaDataEnabled ? new HashMap<String, Integer>() : null;
@@ -565,14 +570,17 @@ public class PortableClassDescriptor {
 
                     if (obj.getClass() != BinaryMetadata.class
                         && ctx.isMetaDataChanged(typeId, writer.metaDataHashSum()))
{
-                        BinaryMetadataCollector metaCollector = new BinaryMetadataCollector(typeName);
+                        BinaryMetadataCollector collector = new BinaryMetadataCollector(typeId,
typeName, idMapper);
 
                         if (serializer != null)
-                            serializer.writeBinary(obj, metaCollector);
+                            serializer.writeBinary(obj, collector);
                         else
-                            ((Binarylizable)obj).writeBinary(metaCollector);
+                            ((Binarylizable)obj).writeBinary(collector);
+
+                        BinaryMetadata meta = new BinaryMetadata(typeId, typeName, collector.meta(),
affKeyFieldName,
+                            collector.schemas());
 
-                        ctx.updateMetadata(typeId, typeName, metaCollector.meta());
+                        ctx.updateMetadata(typeId, meta);
                     }
                 }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/ed3472d4/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
index 939faa0..89c8339 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
@@ -130,6 +130,9 @@ public class PortableContext implements Externalizable {
     /** */
     private final ConcurrentMap<Integer, BinaryIdMapper> mappers = new ConcurrentHashMap8<>(0);
 
+    /** Affinity key field names. */
+    private final ConcurrentMap<Integer, String> affKeyFieldNames = new ConcurrentHashMap8<>(0);
+
     /** */
     private final Map<String, BinaryIdMapper> typeMappers = new ConcurrentHashMap8<>(0);
 
@@ -509,6 +512,7 @@ public class PortableContext implements Externalizable {
                 false,
                 clsName.hashCode(),
                 clsName,
+                null,
                 BASIC_CLS_ID_MAPPER,
                 null,
                 false,
@@ -555,6 +559,7 @@ public class PortableContext implements Externalizable {
             true,
             typeId,
             typeName,
+            null,
             idMapper,
             null,
             true,
@@ -700,6 +705,7 @@ public class PortableContext implements Externalizable {
             false,
             id,
             typeName,
+            null,
             DFLT_ID_MAPPER,
             null,
             false,
@@ -751,6 +757,11 @@ public class PortableContext implements Externalizable {
         if (mappers.put(id, idMapper) != null)
             throw new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ",
id=" + id + ']');
 
+        if (affKeyFieldName != null) {
+            if (affKeyFieldNames.put(id, affKeyFieldName) != null)
+                throw new BinaryObjectException("Duplicate type ID [clsName=" + clsName +
", id=" + id + ']');
+        }
+
         String typeName = typeName(clsName);
 
         typeMappers.put(typeName, idMapper);
@@ -765,6 +776,7 @@ public class PortableContext implements Externalizable {
                 true,
                 id,
                 typeName,
+                affKeyFieldName,
                 idMapper,
                 serializer,
                 true,
@@ -811,6 +823,14 @@ public class PortableContext implements Externalizable {
 
     /**
      * @param typeId Type ID.
+     * @return Affinity key field name.
+     */
+    public String affinityKeyFieldName(int typeId) {
+        return affKeyFieldNames.get(typeId);
+    }
+
+    /**
+     * @param typeId Type ID.
      * @param metaHashSum Meta data hash sum.
      * @return Whether meta is changed.
      */
@@ -832,16 +852,6 @@ public class PortableContext implements Externalizable {
 
     /**
      * @param typeId Type ID.
-     * @param typeName Type name.
-     * @param fields Fields map.
-     * @throws BinaryObjectException In case of error.
-     */
-    public void updateMetadata(int typeId, String typeName, Map<String, Integer> fields)
throws BinaryObjectException {
-        updateMetadata(typeId, new BinaryMetadata(typeId, typeName, fields, null, null));
-    }
-
-    /**
-     * @param typeId Type ID.
      * @param meta Meta data.
      * @throws BinaryObjectException In case of error.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/ed3472d4/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
index d485e90..402363b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
@@ -22,6 +22,7 @@ import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryObjectBuilder;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.portable.BinaryMetadata;
 import org.apache.ignite.internal.portable.BinaryObjectImpl;
 import org.apache.ignite.internal.portable.BinaryObjectOffheapImpl;
 import org.apache.ignite.internal.portable.BinaryWriterExImpl;
@@ -348,7 +349,8 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
                         typeName = metadata.typeName();
                     }
 
-                    ctx.updateMetadata(typeId, typeName, newFldsMetadata);
+                    ctx.updateMetadata(typeId, new BinaryMetadata(typeId, typeName, newFldsMetadata,
+                        ctx.affinityKeyFieldName(typeId), Collections.singleton(writer.currentSchema())));
                 }
             }
 


Mime
View raw message