ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [1/3] ignite git commit: IGNITE-1816: Debugging.
Date Thu, 12 Nov 2015 08:01:37 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-1816 ed3472d4e -> d5dbf632a


IGNITE-1816: Debugging.


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

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

----------------------------------------------------------------------
 .../internal/portable/BinaryReaderExImpl.java   | 28 ++++++--
 .../internal/portable/BinaryWriterExImpl.java   | 60 ++++++++++------
 .../internal/portable/PortableSchema.java       | 76 ++++++++++++++++----
 .../builder/BinaryObjectBuilderImpl.java        |  1 -
 .../ignite/internal/util/IgniteUtils.java       | 25 +++++++
 .../marshaller/portable/PortableMarshaller.java |  3 +-
 6 files changed, 149 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/25c264fb/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
index ff33d08..d487ae1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
@@ -2620,11 +2620,29 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
                 schema0 = ctx.schemaRegistry(typeId).schema(schemaId);
 
                 if (schema0 == null) {
-                    if (fieldIdLen == 0)
-                        throw new BinaryObjectException("Cannot find schema for object without
field IDs [" +
-                            "typeId=" + typeId + ", schemaId=" + schemaId + ']');
+                    if (fieldIdLen == 0) {
+                        BinaryTypeImpl type = (BinaryTypeImpl)ctx.metaData(typeId);
 
-                    schema0 = createSchema();
+                        if (type == null || type.metadata() == null)
+                            throw new BinaryObjectException("Cannot find metadata for object
with compact footer: " +
+                                typeId);
+
+                        for (PortableSchema typeSchema : type.metadata().schemas()) {
+                            if (schemaId == typeSchema.schemaId()) {
+                                schema0 = typeSchema;
+
+                                break;
+                            }
+                        }
+
+                        if (schema0 == null)
+                            throw new BinaryObjectException("Cannot find schema for object
with compact fotter [" +
+                                "typeId=" + typeId + ", schemaId=" + schemaId + ']');
+                    }
+                    else
+                        schema0 = createSchema();
+
+                    assert schema0 != null;
 
                     ctx.schemaRegistry(typeId).addSchema(schemaId, schema0);
                 }
@@ -2632,8 +2650,6 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
                 schema = schema0;
             }
 
-            assert schema != null;
-
             int order = schema.order(id);
 
             if (order != PortableSchema.ORDER_NOT_FOUND) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/25c264fb/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 23d9311..d23bc69 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
@@ -347,7 +347,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx,
Obje
             out.writeInt(start + SCHEMA_OR_RAW_OFF_POS, out.position() - start);
 
             // Write the schema.
-            int offsetByteCnt = schema.write(this, fieldCnt, !ctx.isCompactFooter());
+            int offsetByteCnt = schema.write(this, fieldCnt, ctx.isCompactFooter());
 
             // Write raw offset if needed.
             if (rawOffPos != 0)
@@ -1853,10 +1853,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx,
Obje
          *
          * @param writer Writer.
          * @param fieldCnt Count.
-         * @param writeFieldId Whether to write field IDs.
+         * @param compactFooter Whether footer should be written in compact form.
          * @return Amount of bytes dedicated to each field offset. Could be 1, 2 or 4.
          */
-        public int write(BinaryWriterExImpl writer, int fieldCnt, boolean writeFieldId) {
+        public int write(BinaryWriterExImpl writer, int fieldCnt, boolean compactFooter)
{
             int startIdx = idx - fieldCnt * 2;
 
             assert startIdx >= 0;
@@ -1865,35 +1865,51 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx,
Obje
 
             int res;
 
-            if (lastOffset < MAX_OFFSET_1) {
-                for (int idx0 = startIdx; idx0 < idx; ) {
-                    if (writeFieldId)
-                        writer.writeInt(data[idx0++]);
+            if (compactFooter) {
+                if (lastOffset < MAX_OFFSET_1) {
+                    for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
+                        writer.writeByte((byte)data[curIdx]);
 
-                    writer.writeByte((byte) data[idx0++]);
+                    res = PortableUtils.OFFSET_1;
                 }
+                else if (lastOffset < MAX_OFFSET_2) {
+                    for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
+                        writer.writeShort((short)data[curIdx]);
 
-                res = PortableUtils.OFFSET_1;
-            }
-            else if (lastOffset < MAX_OFFSET_2) {
-                for (int idx0 = startIdx; idx0 < idx; ) {
-                    if (writeFieldId)
-                        writer.writeInt(data[idx0++]);
-
-                    writer.writeShort((short)data[idx0++]);
+                    res = PortableUtils.OFFSET_2;
                 }
+                else {
+                    for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
+                        writer.writeInt(data[curIdx]);
 
-                res = PortableUtils.OFFSET_2;
+                    res = PortableUtils.OFFSET_4;
+                }
             }
             else {
-                for (int idx0 = startIdx; idx0 < idx; ) {
-                    if (writeFieldId)
-                        writer.writeInt(data[idx0++]);
+                if (lastOffset < MAX_OFFSET_1) {
+                    for (int curIdx = startIdx; curIdx < idx;) {
+                        writer.writeInt(data[curIdx++]);
+                        writer.writeByte((byte) data[curIdx++]);
+                    }
 
-                    writer.writeInt(data[idx0++]);
+                    res = PortableUtils.OFFSET_1;
                 }
+                else if (lastOffset < MAX_OFFSET_2) {
+                    for (int curIdx = startIdx; curIdx < idx;) {
+                        writer.writeInt(data[curIdx++]);
+                        writer.writeShort((short)data[curIdx++]);
+                    }
 
-                res = PortableUtils.OFFSET_4;
+                    res = PortableUtils.OFFSET_2;
+                }
+                else {
+                    for (int curIdx = startIdx; curIdx < idx;) {
+                        writer.writeInt(data[curIdx++]);
+                        writer.writeInt(data[curIdx++]);
+                    }
+
+                    res = PortableUtils.OFFSET_4;
+                }
             }
 
             return res;

http://git-wip-us.apache.org/repos/asf/ignite/blob/25c264fb/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchema.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchema.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchema.java
index f6838c0..3cb191e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchema.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchema.java
@@ -17,7 +17,12 @@
 
 package org.apache.ignite.internal.portable;
 
-import java.io.Serializable;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -29,7 +34,7 @@ import java.util.List;
  * for quick comparisons performed within already fetched L1 cache line.
  * - When there are more fields, we store them inside a hash map.
  */
-public class PortableSchema implements Serializable {
+public class PortableSchema implements Externalizable {
     /** */
     private static final long serialVersionUID = 0L;
 
@@ -37,37 +42,82 @@ public class PortableSchema implements Serializable {
     public static final int ORDER_NOT_FOUND = -1;
 
     /** Inline flag. */
-    private final boolean inline;
+    private boolean inline;
 
     /** Map with offsets. */
-    private final HashMap<Integer, Integer> map;
+    private HashMap<Integer, Integer> map;
 
     /** ID 1. */
-    private final int id0;
+    private int id0;
 
     /** ID 2. */
-    private final int id1;
+    private int id1;
 
     /** ID 3. */
-    private final int id2;
+    private int id2;
 
     /** ID 4. */
-    private final int id3;
+    private int id3;
 
     /** ID 1. */
-    private final int id4;
+    private int id4;
 
     /** ID 2. */
-    private final int id5;
+    private int id5;
 
     /** ID 3. */
-    private final int id6;
+    private int id6;
 
     /** ID 4. */
-    private final int id7;
+    private int id7;
 
     /** Schema ID. */
-    private final int schemaId;
+    private int schemaId;
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(schemaId);
+
+        if (inline) {
+            out.writeBoolean(true);
+
+            out.writeInt(id0);
+            out.writeInt(id1);
+            out.writeInt(id2);
+            out.writeInt(id3);
+            out.writeInt(id4);
+            out.writeInt(id5);
+            out.writeInt(id6);
+            out.writeInt(id7);
+        }
+        else {
+            out.writeBoolean(false);
+            U.writeMap(out, map);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
{
+        schemaId = in.readInt();
+
+        if (in.readBoolean()) {
+            inline = true;
+
+            id0 = in.readInt();
+            id1 = in.readInt();
+            id2 = in.readInt();
+            id3 = in.readInt();
+            id4 = in.readInt();
+            id5 = in.readInt();
+            id6 = in.readInt();
+            id7 = in.readInt();
+        }
+        else {
+            inline = false;
+
+            map = U.readHashMap(in);
+        }
+    }
 
     /**
      * Constructor.

http://git-wip-us.apache.org/repos/asf/ignite/blob/25c264fb/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 402363b..268df1a 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
@@ -177,7 +177,6 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
     /** {@inheritDoc} */
     @Override public BinaryObject build() {
         try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, typeId, false)) {
-
             PortableBuilderSerializer serializationCtx = new PortableBuilderSerializer();
 
             serializationCtx.registerObjectWriting(this, 0);

http://git-wip-us.apache.org/repos/asf/ignite/blob/25c264fb/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
index 259d8c9..7337378 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -4983,6 +4983,31 @@ public abstract class IgniteUtils {
     }
 
     /**
+     * Read hash map.
+     *
+     * @param in Input.
+     * @return Read map.
+     * @throws IOException If de-serialization failed.
+     * @throws ClassNotFoundException If deserialized class could not be found.
+     */
+    @SuppressWarnings({"unchecked"})
+    @Nullable public static <K, V> HashMap<K, V> readHashMap(ObjectInput in)
+        throws IOException, ClassNotFoundException {
+        int size = in.readInt();
+
+        // Check null flag.
+        if (size == -1)
+            return null;
+
+        HashMap<K, V> map = U.newHashMap(size);
+
+        for (int i = 0; i < size; i++)
+            map.put((K)in.readObject(), (V)in.readObject());
+
+        return map;
+    }
+
+    /**
      *
      * @param in Input.
      * @return Read map.

http://git-wip-us.apache.org/repos/asf/ignite/blob/25c264fb/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java
b/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java
index 4e8217d..1704c8a 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/portable/PortableMarshaller.java
@@ -78,8 +78,7 @@ public class PortableMarshaller extends AbstractMarshaller {
     public static final boolean DFLT_KEEP_DESERIALIZED = true;
 
     /** Default value of "compact footer" flag. */
-    // TODO: Set to true.
-    public static final boolean DFLT_COMPACT_FOOTER = false;
+    public static final boolean DFLT_COMPACT_FOOTER = true;
 
     // TODO ignite-1282 Move to IgniteConfiguration.
     /** Class names. */


Mime
View raw message