You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/10/28 16:28:28 UTC

[1/3] ignite git commit: IGNITE-1770: WIP on schema.

Repository: ignite
Updated Branches:
  refs/heads/ignite-1770 37269c1f5 -> d6a5d8e31


IGNITE-1770: WIP on schema.


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

Branch: refs/heads/ignite-1770
Commit: 22e50156be3a4f117f1c38e7e1ec852ef27b48b6
Parents: 37269c1
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Oct 28 16:29:47 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Oct 28 16:29:47 2015 +0300

----------------------------------------------------------------------
 .../portable/PortableClassDescriptor.java       | 120 +++++++++++++++----
 .../internal/portable/PortableObjectSchema.java |  46 +++++++
 .../java/org/apache/ignite/MyBenchmark.java     |  19 ++-
 3 files changed, 159 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/22e50156/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 25ec856..02c408e 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
@@ -38,6 +38,7 @@ import java.util.UUID;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
 import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.marshaller.MarshallerExclusions;
 import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
 import org.apache.ignite.marshaller.portable.PortableMarshaller;
@@ -63,6 +64,9 @@ public class PortableClassDescriptor {
     /** */
     private final PortableSerializer serializer;
 
+    /** ID mapper. */
+    private final PortableIdMapper idMapper;
+
     /** */
     private final Mode mode;
 
@@ -102,6 +106,9 @@ public class PortableClassDescriptor {
     /** */
     private final boolean excluded;
 
+    /** Object schemas. */
+    private volatile Object schemas;
+
     /**
      * @param ctx Context.
      * @param cls Class.
@@ -138,6 +145,7 @@ public class PortableClassDescriptor {
         this.typeId = typeId;
         this.typeName = typeName;
         this.serializer = serializer;
+        this.idMapper = idMapper;
         this.keepDeserialized = keepDeserialized;
         this.registered = registered;
 
@@ -307,6 +315,74 @@ public class PortableClassDescriptor {
     }
 
     /**
+     * Get ID mapper.
+     *
+     * @return ID mapper.
+     */
+    public PortableIdMapper idMapper() {
+        return idMapper;
+    }
+
+    /**
+     * Get schema for the given schema ID.
+     *
+     * @param schemaId Schema ID.
+     * @return Schema or {@code null} if there are no such schema.
+     */
+    @SuppressWarnings("unchecked")
+    @Nullable public PortableObjectSchema schema(int schemaId) {
+        Object schemas0 = schemas;
+
+        if (schemas0 instanceof IgniteBiTuple) {
+            // The most common case goes first.
+            IgniteBiTuple<Integer, PortableObjectSchema> curSchema =
+                (IgniteBiTuple<Integer, PortableObjectSchema>)schemas0;
+
+            if (curSchema.get1() == schemaId)
+                return curSchema.get2();
+        }
+        else if (schemas0 instanceof Map) {
+            Map<Integer, PortableObjectSchema> curSchemas = (Map<Integer, PortableObjectSchema>)schemas0;
+
+            return curSchemas.get(schemaId);
+        }
+
+        return null;
+    }
+
+    /**
+     * Add schema.
+     *
+     * @param schemaId Schema ID.
+     * @param fields Fields.
+     */
+    @SuppressWarnings("unchecked")
+    public void addSchema(int schemaId, Map<Integer, Integer> fields) {
+        synchronized (this) {
+            if (schemas == null)
+                schemas = new IgniteBiTuple<>(schemaId, new PortableObjectSchema(schemaId, fields));
+            else if (schemas instanceof IgniteBiTuple) {
+                IgniteBiTuple<Integer, PortableObjectSchema> curSchema =
+                    (IgniteBiTuple<Integer, PortableObjectSchema>)schemas;
+
+                if (curSchema.get1() != schemaId) {
+                    Map newSchemas = new HashMap();
+
+                    newSchemas.put(curSchema.get1(), curSchema.get2());
+                    newSchemas.put(schemaId, new PortableObjectSchema(schemaId, fields));
+
+                    schemas = newSchemas;
+                }
+            }
+            else {
+                Map<Integer, PortableObjectSchema> curSchemas = (Map<Integer, PortableObjectSchema>)schemas;
+
+                curSchemas.put(schemaId, new PortableObjectSchema(schemaId, fields));
+            }
+        }
+    }
+
+    /**
      * @return portableWriteReplace() method
      */
     @Nullable Method getWriteReplaceMethod() {
@@ -409,57 +485,57 @@ public class PortableClassDescriptor {
                 break;
 
             case SHORT_ARR:
-                writer.doWriteShortArray((short[])obj);
+                writer.doWriteShortArray((short[]) obj);
 
                 break;
 
             case INT_ARR:
-                writer.doWriteIntArray((int[])obj);
+                writer.doWriteIntArray((int[]) obj);
 
                 break;
 
             case LONG_ARR:
-                writer.doWriteLongArray((long[])obj);
+                writer.doWriteLongArray((long[]) obj);
 
                 break;
 
             case FLOAT_ARR:
-                writer.doWriteFloatArray((float[])obj);
+                writer.doWriteFloatArray((float[]) obj);
 
                 break;
 
             case DOUBLE_ARR:
-                writer.doWriteDoubleArray((double[])obj);
+                writer.doWriteDoubleArray((double[]) obj);
 
                 break;
 
             case CHAR_ARR:
-                writer.doWriteCharArray((char[])obj);
+                writer.doWriteCharArray((char[]) obj);
 
                 break;
 
             case BOOLEAN_ARR:
-                writer.doWriteBooleanArray((boolean[])obj);
+                writer.doWriteBooleanArray((boolean[]) obj);
 
                 break;
 
             case DECIMAL_ARR:
-                writer.doWriteDecimalArray((BigDecimal[])obj);
+                writer.doWriteDecimalArray((BigDecimal[]) obj);
 
                 break;
 
             case STRING_ARR:
-                writer.doWriteStringArray((String[])obj);
+                writer.doWriteStringArray((String[]) obj);
 
                 break;
 
             case UUID_ARR:
-                writer.doWriteUuidArray((UUID[])obj);
+                writer.doWriteUuidArray((UUID[]) obj);
 
                 break;
 
             case DATE_ARR:
-                writer.doWriteDateArray((Date[])obj);
+                writer.doWriteDateArray((Date[]) obj);
 
                 break;
 
@@ -927,57 +1003,57 @@ public class PortableClassDescriptor {
                     break;
 
                 case SHORT_ARR:
-                    writer.writeShortArrayField((short[])val);
+                    writer.writeShortArrayField((short[]) val);
 
                     break;
 
                 case INT_ARR:
-                    writer.writeIntArrayField((int[])val);
+                    writer.writeIntArrayField((int[]) val);
 
                     break;
 
                 case LONG_ARR:
-                    writer.writeLongArrayField((long[])val);
+                    writer.writeLongArrayField((long[]) val);
 
                     break;
 
                 case FLOAT_ARR:
-                    writer.writeFloatArrayField((float[])val);
+                    writer.writeFloatArrayField((float[]) val);
 
                     break;
 
                 case DOUBLE_ARR:
-                    writer.writeDoubleArrayField((double[])val);
+                    writer.writeDoubleArrayField((double[]) val);
 
                     break;
 
                 case CHAR_ARR:
-                    writer.writeCharArrayField((char[])val);
+                    writer.writeCharArrayField((char[]) val);
 
                     break;
 
                 case BOOLEAN_ARR:
-                    writer.writeBooleanArrayField((boolean[])val);
+                    writer.writeBooleanArrayField((boolean[]) val);
 
                     break;
 
                 case DECIMAL_ARR:
-                    writer.writeDecimalArrayField((BigDecimal[])val);
+                    writer.writeDecimalArrayField((BigDecimal[]) val);
 
                     break;
 
                 case STRING_ARR:
-                    writer.writeStringArrayField((String[])val);
+                    writer.writeStringArrayField((String[]) val);
 
                     break;
 
                 case UUID_ARR:
-                    writer.writeUuidArrayField((UUID[])val);
+                    writer.writeUuidArrayField((UUID[]) val);
 
                     break;
 
                 case DATE_ARR:
-                    writer.writeDateArrayField((Date[])val);
+                    writer.writeDateArrayField((Date[]) val);
 
                     break;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/22e50156/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectSchema.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectSchema.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectSchema.java
new file mode 100644
index 0000000..a661781
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectSchema.java
@@ -0,0 +1,46 @@
+package org.apache.ignite.internal.portable;
+
+import java.util.Map;
+
+/**
+ * Portable object schema.
+ */
+public class PortableObjectSchema {
+    /** Schema ID. */
+    private final int schemaId;
+
+    /** Fields. */
+    private final Map<Integer, Integer> fields;
+
+    /**
+     * Constructor.
+     *
+     * @param schemaId Schema ID.
+     * @param fields Fields.
+     */
+    public PortableObjectSchema(int schemaId, Map<Integer, Integer> fields) {
+        this.schemaId = schemaId;
+        this.fields = fields;
+    }
+
+    /**
+     * Get schema ID.
+     *
+     * @return Schema ID.
+     */
+    public int schemaId() {
+        return schemaId;
+    }
+
+    /**
+     * Get field offset position.
+     *
+     * @param fieldId Field ID.
+     * @return Field offset position.
+     */
+    public int fieldOffsetPosition(int fieldId) {
+        Integer pos = fields.get(fieldId);
+
+        return pos != null ? pos : 0;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/22e50156/modules/microbench/src/main/java/org/apache/ignite/MyBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/microbench/src/main/java/org/apache/ignite/MyBenchmark.java b/modules/microbench/src/main/java/org/apache/ignite/MyBenchmark.java
index 1f3dce4..662acee 100644
--- a/modules/microbench/src/main/java/org/apache/ignite/MyBenchmark.java
+++ b/modules/microbench/src/main/java/org/apache/ignite/MyBenchmark.java
@@ -31,16 +31,20 @@
 
 package org.apache.ignite;
 
+import org.apache.ignite.internal.portable.GridPortableMarshaller;
 import org.apache.ignite.internal.portable.PortableContext;
 import org.apache.ignite.internal.portable.PortableMetaDataHandler;
+import org.apache.ignite.internal.portable.PortableObjectImpl;
 import org.apache.ignite.internal.portable.streams.PortableSimpleMemoryAllocator;
 import org.apache.ignite.internal.util.IgniteUtils;
 
+import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
 import org.apache.ignite.marshaller.portable.PortableMarshaller;
 import org.apache.ignite.portable.PortableException;
 import org.apache.ignite.portable.PortableMarshalAware;
 import org.apache.ignite.portable.PortableMetadata;
+import org.apache.ignite.portable.PortableObject;
 import org.apache.ignite.portable.PortableReader;
 import org.apache.ignite.portable.PortableWriter;
 import org.apache.ignite.util.MarshallerContextMicrobenchImpl;
@@ -84,7 +88,7 @@ public class MyBenchmark {
 
     private static byte[] marshAddrBytes;
 
-    private static byte[] optMarshAddrBytes;
+    private static PortableObject marshPortable;
 
     @Setup
     public static void setup() throws Exception {
@@ -104,7 +108,9 @@ public class MyBenchmark {
         optMarsh.setContext(new MarshallerContextMicrobenchImpl(null));
 
         marshAddrBytes = marsh.marshal(new Address());
-        optMarshAddrBytes = optMarsh.marshal(new Address());
+
+        marshPortable = new PortableObjectImpl(U.<GridPortableMarshaller>field(marsh, "impl").context(),
+            marshAddrBytes, 0);
 
         byte[] data = marsh.marshal(new Address());
 
@@ -116,9 +122,14 @@ public class MyBenchmark {
 //        return marsh.marshal(new Address());
 //    }
 
+//    @Benchmark
+//    public Address testAddressRead() throws Exception {
+//        return marsh.unmarshal(marshAddrBytes, null);
+//    }
+
     @Benchmark
-    public Address testAddressRead() throws Exception {
-        return marsh.unmarshal(marshAddrBytes, null);
+    public Object testFieldRead() throws Exception {
+        return marshPortable.field("street");
     }
 
     private static final Address addr = new Address();


[2/3] ignite git commit: IGNITE-1770: WIP on schema.

Posted by vo...@apache.org.
IGNITE-1770: WIP on schema.


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

Branch: refs/heads/ignite-1770
Commit: 69faf96f61de5adf8335207b4adcb44e09b06886
Parents: 22e5015
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Oct 28 17:44:23 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Oct 28 17:44:23 2015 +0300

----------------------------------------------------------------------
 .../portable/PortableClassDescriptor.java       | 62 -------------
 .../internal/portable/PortableContext.java      | 95 ++++++++++++++++++++
 .../internal/portable/PortableReaderExImpl.java | 71 ++++++++++++---
 .../java/org/apache/ignite/MyBenchmark.java     | 41 ++++++---
 4 files changed, 181 insertions(+), 88 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/69faf96f/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 02c408e..5005e68 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
@@ -106,9 +106,6 @@ public class PortableClassDescriptor {
     /** */
     private final boolean excluded;
 
-    /** Object schemas. */
-    private volatile Object schemas;
-
     /**
      * @param ctx Context.
      * @param cls Class.
@@ -324,65 +321,6 @@ public class PortableClassDescriptor {
     }
 
     /**
-     * Get schema for the given schema ID.
-     *
-     * @param schemaId Schema ID.
-     * @return Schema or {@code null} if there are no such schema.
-     */
-    @SuppressWarnings("unchecked")
-    @Nullable public PortableObjectSchema schema(int schemaId) {
-        Object schemas0 = schemas;
-
-        if (schemas0 instanceof IgniteBiTuple) {
-            // The most common case goes first.
-            IgniteBiTuple<Integer, PortableObjectSchema> curSchema =
-                (IgniteBiTuple<Integer, PortableObjectSchema>)schemas0;
-
-            if (curSchema.get1() == schemaId)
-                return curSchema.get2();
-        }
-        else if (schemas0 instanceof Map) {
-            Map<Integer, PortableObjectSchema> curSchemas = (Map<Integer, PortableObjectSchema>)schemas0;
-
-            return curSchemas.get(schemaId);
-        }
-
-        return null;
-    }
-
-    /**
-     * Add schema.
-     *
-     * @param schemaId Schema ID.
-     * @param fields Fields.
-     */
-    @SuppressWarnings("unchecked")
-    public void addSchema(int schemaId, Map<Integer, Integer> fields) {
-        synchronized (this) {
-            if (schemas == null)
-                schemas = new IgniteBiTuple<>(schemaId, new PortableObjectSchema(schemaId, fields));
-            else if (schemas instanceof IgniteBiTuple) {
-                IgniteBiTuple<Integer, PortableObjectSchema> curSchema =
-                    (IgniteBiTuple<Integer, PortableObjectSchema>)schemas;
-
-                if (curSchema.get1() != schemaId) {
-                    Map newSchemas = new HashMap();
-
-                    newSchemas.put(curSchema.get1(), curSchema.get2());
-                    newSchemas.put(schemaId, new PortableObjectSchema(schemaId, fields));
-
-                    schemas = newSchemas;
-                }
-            }
-            else {
-                Map<Integer, PortableObjectSchema> curSchemas = (Map<Integer, PortableObjectSchema>)schemas;
-
-                curSchemas.put(schemaId, new PortableObjectSchema(schemaId, fields));
-            }
-        }
-    }
-
-    /**
      * @return portableWriteReplace() method
      */
     @Nullable Method getWriteReplaceMethod() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/69faf96f/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 b0405ac..15e1162 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
@@ -150,6 +150,9 @@ public class PortableContext implements Externalizable {
     /** */
     private boolean keepDeserialized;
 
+    /** Object schemas. */
+    private volatile Map<Integer, Object> schemas;
+
     /**
      * For {@link Externalizable}.
      */
@@ -832,6 +835,98 @@ public class PortableContext implements Externalizable {
     }
 
     /**
+     * Get schema for the given schema ID.
+     *
+     * @param schemaId Schema ID.
+     * @return Schema or {@code null} if there are no such schema.
+     */
+    @SuppressWarnings("unchecked")
+    @Nullable public PortableObjectSchema schema(int typeId, int schemaId) {
+        Map<Integer, Object> schemas0 = schemas;
+
+        if (schemas0 != null) {
+            Object typeSchemas = schemas0.get(typeId);
+
+            if (typeSchemas instanceof IgniteBiTuple) {
+                // The most common case goes first.
+                IgniteBiTuple<Integer, PortableObjectSchema> schema =
+                    (IgniteBiTuple<Integer, PortableObjectSchema>)typeSchemas;
+
+                if (schema.get1() == schemaId)
+                    return schema.get2();
+            }
+            else if (typeSchemas instanceof Map) {
+                Map<Integer, PortableObjectSchema> curSchemas = (Map<Integer, PortableObjectSchema>)typeSchemas;
+
+                return curSchemas.get(schemaId);
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Add schema.
+     *
+     * @param schemaId Schema ID.
+     * @param newTypeSchema New schema.
+     */
+    @SuppressWarnings("unchecked")
+    public void addSchema(int typeId, int schemaId, PortableObjectSchema newTypeSchema) {
+        synchronized (this) {
+            if (schemas == null) {
+                // This is the very first schema recorded.
+                Map<Integer, Object> newSchemas = new HashMap<>();
+
+                newSchemas.put(typeId, new IgniteBiTuple<>(schemaId, newTypeSchema));
+
+                schemas = newSchemas;
+            }
+            else {
+                Object typeSchemas = schemas.get(typeId);
+
+                if (typeSchemas == null) {
+                    // This is the very first object schema.
+                    Map<Integer, Object> newSchemas = new HashMap<>(schemas);
+
+                    newSchemas.put(typeId, new IgniteBiTuple<>(schemaId, newTypeSchema));
+
+                    schemas = newSchemas;
+                }
+                else if (typeSchemas instanceof IgniteBiTuple) {
+                    IgniteBiTuple<Integer, PortableObjectSchema> typeSchema =
+                        (IgniteBiTuple<Integer, PortableObjectSchema>)typeSchemas;
+
+                    if (typeSchema.get1() != schemaId) {
+                        Map<Integer, PortableObjectSchema> newTypeSchemas = new HashMap();
+
+                        newTypeSchemas.put(typeSchema.get1(), typeSchema.get2());
+                        newTypeSchemas.put(schemaId, newTypeSchema);
+
+                        Map<Integer, Object> newSchemas = new HashMap<>(schemas);
+
+                        newSchemas.put(typeId, newTypeSchemas);
+
+                        schemas = newSchemas;
+                    }
+                }
+                else {
+                    Map<Integer, PortableObjectSchema> newTypeSchemas =
+                        new HashMap((Map<Integer, PortableObjectSchema>)typeSchemas);
+
+                    newTypeSchemas.put(schemaId, newTypeSchema);
+
+                    Map<Integer, Object> newSchemas = new HashMap<>(schemas);
+
+                    newSchemas.put(typeId, newTypeSchemas);
+
+                    schemas = newSchemas;
+                }
+            }
+        }
+    }
+
+    /**
      * Returns instance of {@link OptimizedMarshaller}.
      *
      * @return Optimized marshaller.

http://git-wip-us.apache.org/repos/asf/ignite/blob/69faf96f/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
index 861e649..12ef3bf 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
@@ -47,6 +47,7 @@ import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.Map;
 import java.util.Properties;
@@ -156,6 +157,12 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
     /** ID mapper. */
     private PortableIdMapper idMapper;
 
+    /** Schema Id. */
+    private int schemaId;
+
+    /** Object schema. */
+    private PortableObjectSchema schema;
+
     /**
      * @param ctx Context.
      * @param arr Array.
@@ -220,6 +227,8 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
         footerStart = footer.get1();
         footerEnd = footer.get2();
 
+        schemaId = in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_ID_POS);
+
         rawOff = PortableUtils.rawOffsetAbsolute(in, start);
 
         if (typeId == UNREGISTERED_TYPE_ID) {
@@ -2524,27 +2533,63 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Field offset.
      */
     private boolean hasField(int id) {
-        assert hdrLen != 0;
+        if (schema == null) {
+            PortableObjectSchema schema0 = ctx.schema(typeId, schemaId);
 
-        int searchHead = footerStart;
-        int searchTail = footerEnd;
+            if (schema0 == null) {
+                Map<Integer, Integer> fields = new HashMap<>(256, 0.5f);
 
-        while (true) {
-            if (searchHead >= searchTail)
-                return false;
+                int searchPos = footerStart;
 
-            int id0 = in.readIntPositioned(searchHead);
+                while (searchPos < footerEnd) {
+                    int fieldId = in.readIntPositioned(searchPos);
 
-            if (id0 == id) {
-                int offset = in.readIntPositioned(searchHead + 4);
+                    fields.put(fieldId, searchPos + 4 - footerStart);
 
-                in.position(start + offset);
+                    searchPos += 8;
+                }
+
+                schema0 = new PortableObjectSchema(schemaId, fields);
 
-                return true;
+                ctx.addSchema(typeId, schemaId, schema0);
             }
 
-            searchHead += 8;
+            schema = schema0;
         }
+
+        int fieldOffsetPos = schema.fieldOffsetPosition(id);
+
+        if (fieldOffsetPos != 0) {
+            int fieldOffset = in.readIntPositioned(start + footerStart + fieldOffsetPos);
+
+            in.position(start + fieldOffset);
+
+            return true;
+        }
+        else
+            return false;
+
+//        assert hdrLen != 0;
+//
+//        int searchHead = footerStart;
+//        int searchTail = footerEnd;
+//
+//        while (true) {
+//            if (searchHead >= searchTail)
+//                return false;
+//
+//            int id0 = in.readIntPositioned(searchHead);
+//
+//            if (id0 == id) {
+//                int offset = in.readIntPositioned(searchHead + 4);
+//
+//                in.position(start + offset);
+//
+//                return true;
+//            }
+//
+//            searchHead += 8;
+//        }
     }
 
     /** {@inheritDoc} */
@@ -2635,7 +2680,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
 
     /** {@inheritDoc} */
     @Override public long skip(long n) throws IOException {
-        return skipBytes((int)n);
+        return skipBytes((int) n);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/69faf96f/modules/microbench/src/main/java/org/apache/ignite/MyBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/microbench/src/main/java/org/apache/ignite/MyBenchmark.java b/modules/microbench/src/main/java/org/apache/ignite/MyBenchmark.java
index 662acee..fb9710f 100644
--- a/modules/microbench/src/main/java/org/apache/ignite/MyBenchmark.java
+++ b/modules/microbench/src/main/java/org/apache/ignite/MyBenchmark.java
@@ -107,14 +107,10 @@ public class MyBenchmark {
         optMarsh = new OptimizedMarshaller();
         optMarsh.setContext(new MarshallerContextMicrobenchImpl(null));
 
-        marshAddrBytes = marsh.marshal(new Address());
+        marshAddrBytes = marsh.marshal(new ManyFields());
 
         marshPortable = new PortableObjectImpl(U.<GridPortableMarshaller>field(marsh, "impl").context(),
             marshAddrBytes, 0);
-
-        byte[] data = marsh.marshal(new Address());
-
-        System.out.println(data.length);
     }
 
 //    @Benchmark
@@ -122,22 +118,26 @@ public class MyBenchmark {
 //        return marsh.marshal(new Address());
 //    }
 
-//    @Benchmark
-//    public Address testAddressRead() throws Exception {
-//        return marsh.unmarshal(marshAddrBytes, null);
-//    }
-
     @Benchmark
-    public Object testFieldRead() throws Exception {
-        return marshPortable.field("street");
+    public Object testRead() throws Exception {
+        return marsh.unmarshal(marshAddrBytes, null);
     }
 
+//    @Benchmark
+//    public Object testFieldRead() throws Exception {
+//        return marshPortable.field("street");
+//    }
+
     private static final Address addr = new Address();
 
     public static void main(String[] args) throws Exception {
 //        setup();
-//        while (true)
+//        while (true) {
 //            marsh.unmarshal(marshAddrBytes, null);
+////            String val = marshPortable.field("street");
+////
+////            System.out.println(val);
+//        }
 
         Options opts = new OptionsBuilder().include(MyBenchmark.class.getSimpleName()).build();
         new Runner(opts).run();
@@ -166,6 +166,21 @@ public class MyBenchmark {
         return customer;
     }
 
+    static class ManyFields {
+        public int field1 = 1;
+        public int field2 = 2;
+        public int field3 = 3;
+        public int field4 = 4;
+        public int field5 = 5;
+
+        public int field6 = 6;
+        public int field7 = 7;
+        public int field8 = 8;
+        public int field9 = 9;
+        public int field10 = 10;
+
+    }
+
     static class Address implements PortableMarshalAware, Externalizable {
         public int streetNum = 49;
         public int flatNum = 30;


[3/3] ignite git commit: IGNITE-1770: Fixed bug causing incorrect raw offset calculation in nested objects.

Posted by vo...@apache.org.
IGNITE-1770: Fixed bug causing incorrect raw offset calculation in nested objects.


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

Branch: refs/heads/ignite-1770
Commit: d6a5d8e31a1abe1d74dece017f49fe3a3aed8c7c
Parents: 69faf96
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Oct 28 18:29:09 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Oct 28 18:29:09 2015 +0300

----------------------------------------------------------------------
 .../java/org/apache/ignite/internal/portable/PortableUtils.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d6a5d8e3/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
index 38b6e6c..eafcbd1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
@@ -631,7 +631,7 @@ public class PortableUtils {
 
         if (PortableUtils.isRawOnly(flags))
             // No schema, raw offset is located on schema offset position.
-            return in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
+            return start + in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
         else {
             // Schema exists.
             int schemaOff = in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);