ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [6/7] ignite git commit: IGNITE-1814: Debug.
Date Mon, 02 Nov 2015 12:02:03 GMT
IGNITE-1814: Debug.


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

Branch: refs/heads/ignite-1814
Commit: c374c160b502cc57eaeec03e3735202b1791647c
Parents: a28fe9b
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Mon Nov 2 14:43:14 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Mon Nov 2 14:43:14 2015 +0300

----------------------------------------------------------------------
 .../portable/PortablePositionReadable.java      |  8 ++++
 .../internal/portable/PortableReaderExImpl.java |  7 +++-
 .../ignite/internal/portable/PortableUtils.java |  8 ++--
 .../portable/builder/PortableBuilderImpl.java   | 44 +++++++++++++++-----
 .../portable/builder/PortableBuilderReader.java |  2 +-
 .../streams/PortableAbstractInputStream.java    | 18 ++++++++
 .../streams/PortableHeapInputStream.java        |  5 +++
 .../streams/PortableOffheapInputStream.java     |  5 +++
 .../PlatformBigEndianInputStreamImpl.java       |  5 +++
 .../memory/PlatformInputStreamImpl.java         | 10 +++++
 10 files changed, 93 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/c374c160/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePositionReadable.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePositionReadable.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePositionReadable.java
index 7e8d9d3..c49c898 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePositionReadable.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePositionReadable.java
@@ -22,6 +22,14 @@ package org.apache.ignite.internal.portable;
  */
 public interface PortablePositionReadable {
     /**
+     * Read byte at the given position.
+     *
+     * @param pos Position.
+     * @return Value.
+     */
+    public byte readBytePositioned(int pos);
+
+    /**
      * Read short at the given position.
      *
      * @param pos Position.

http://git-wip-us.apache.org/repos/asf/ignite/blob/c374c160/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 f9cbae4..e243ed8 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
@@ -235,6 +235,9 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
         footerStart = footer.get1();
         footerLen = footer.get2() - footerStart;
 
+        if (footerLen % (4 + offsetSize) != 0)
+            footerLen -= 4;
+
         schemaId = in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_ID_POS);
 
         rawOff = PortableUtils.rawOffsetAbsolute(in, start);
@@ -2611,9 +2614,9 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
                     int pos;
 
                     if (offsetSize == PortableUtils.OFFSET_1)
-                        pos = start + in.readIntPositioned(searchPos + 1) & 0xFF;
+                        pos = start + (int)in.readBytePositioned(searchPos + 4) & 0xFF;
                     else if (offsetSize == PortableUtils.OFFSET_2)
-                        pos = start + in.readIntPositioned(searchPos + 2) & 0xFFFF;
+                        pos = start + (int)in.readShortPositioned(searchPos + 4) & 0xFFFF;
                     else
                         pos = start + in.readIntPositioned(searchPos + 4);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/c374c160/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 f08b48a..933f518 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
@@ -625,10 +625,6 @@ public class PortableUtils {
         int footerStart = footerStartRelative(in, start);
         int footerEnd = length(in, start);
 
-        // Take in count possible raw offset.
-        if ((((footerEnd - footerStart) >> 2) & 0x1) == 0x1)
-            footerEnd -= 4;
-
         return F.t(start + footerStart, start + footerEnd);
     }
 
@@ -651,7 +647,9 @@ public class PortableUtils {
             // Schema exists.
             int schemaOff = in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
 
-            if ((((len - schemaOff) >> 2) & 0x1) == 0x0)
+            int pairLen = 4 + fieldOffsetSize(flags);
+
+            if (((len - schemaOff) & pairLen) == 0x0)
                 // Even amount of records in schema => no raw offset.
                 return start + schemaOff;
             else

http://git-wip-us.apache.org/repos/asf/ignite/blob/c374c160/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
index 442fc35..6c5a4d2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
@@ -41,6 +41,7 @@ import java.util.Map;
 import java.util.Set;
 
 import static org.apache.ignite.internal.portable.GridPortableMarshaller.DFLT_HDR_LEN;
+import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLAGS_POS;
 import static org.apache.ignite.internal.portable.GridPortableMarshaller.HASH_CODE_POS;
 import static org.apache.ignite.internal.portable.GridPortableMarshaller.PROTO_VER_POS;
 import static org.apache.ignite.internal.portable.GridPortableMarshaller.TYPE_ID_POS;
@@ -77,6 +78,9 @@ public class PortableBuilderImpl implements PortableBuilder {
     /** Position of object in source array, or -1 if object is not created from PortableObject.
*/
     private final int start;
 
+    /** Flags. */
+    private final short flags;
+
     /** Total header length */
     private final int hdrLen;
 
@@ -115,6 +119,7 @@ public class PortableBuilderImpl implements PortableBuilder {
         this.ctx = ctx;
 
         start = -1;
+        flags = -1;
         reader = null;
         hdrLen = DFLT_HDR_LEN;
 
@@ -137,8 +142,9 @@ public class PortableBuilderImpl implements PortableBuilder {
     PortableBuilderImpl(PortableBuilderReader reader, int start) {
         this.reader = reader;
         this.start = start;
+        this.flags = reader.readShortPositioned(start + FLAGS_POS);
 
-        byte ver = reader.readByteAbsolute(start + PROTO_VER_POS);
+        byte ver = reader.readBytePositioned(start + PROTO_VER_POS);
 
         PortableUtils.checkProtocolVersion(ver);
 
@@ -229,17 +235,19 @@ public class PortableBuilderImpl implements PortableBuilder {
             int footerPos = footer.get1();
             int footerEnd = footer.get2();
 
+            int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
+
             // Get raw position.
             int rawPos = PortableUtils.rawOffsetAbsolute(reader, start);
 
             // Position reader on data.
             reader.position(start + hdrLen);
 
-            while (reader.position() < rawPos) {
+            while (reader.position() + 4 < rawPos) {
                 int fieldId = reader.readIntPositioned(footerPos);
-                int fieldLen = fieldPositionAndLength(footerPos, footerEnd, rawPos).get2();
+                int fieldLen = fieldPositionAndLength(footerPos, footerEnd, rawPos, fieldOffsetSize).get2();
 
-                footerPos += 8;
+                footerPos += 4 + fieldOffsetSize;
 
                 if (assignedFldsById.containsKey(fieldId)) {
                     Object assignedVal = assignedFldsById.remove(fieldId);
@@ -391,21 +399,32 @@ public class PortableBuilderImpl implements PortableBuilder {
      * @param footerPos Field position inside the footer (absolute).
      * @param footerEnd Footer end (absolute).
      * @param rawPos Raw data position (absolute).
+     * @param fieldOffsetSize Size of field's offset.
      * @return Tuple with field position and length.
      */
-    private IgniteBiTuple<Integer, Integer> fieldPositionAndLength(int footerPos, int
footerEnd, int rawPos) {
-        int fieldOffset = reader.readIntPositioned(footerPos + 4);
+    private IgniteBiTuple<Integer, Integer> fieldPositionAndLength(int footerPos, int
footerEnd, int rawPos,
+        int fieldOffsetSize) {
+        // Get field offset first.
+        int fieldOffset;
+
+        if (fieldOffsetSize == PortableUtils.OFFSET_1)
+            fieldOffset = reader.readIntPositioned(footerPos + 1) & 0xFF;
+        else if (fieldOffsetSize == PortableUtils.OFFSET_2)
+            fieldOffset = reader.readIntPositioned(footerPos + 2) & 0xFFFF;
+        else
+            fieldOffset = reader.readIntPositioned(footerPos + 4);
+
         int fieldPos = start + fieldOffset;
 
         // Get field length.
         int fieldLen;
 
-        if (footerPos + 8 == footerEnd)
+        if (footerPos + 4 + fieldOffsetSize == footerEnd)
             // This is the last field, compare to raw offset.
             fieldLen = rawPos - fieldPos;
         else {
             // Field is somewhere in the middle, get difference with the next offset.
-            int nextFieldOffset = reader.readIntPositioned(footerPos + 8 + 4);
+            int nextFieldOffset = reader.readIntPositioned(footerPos + fieldOffsetSize +
4 + fieldOffsetSize);
 
             fieldLen = nextFieldOffset - fieldOffset;
         }
@@ -418,6 +437,8 @@ public class PortableBuilderImpl implements PortableBuilder {
      */
     private void ensureReadCacheInit() {
         if (readCache == null) {
+            int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
+
             Map<Integer, Object> readCache = new HashMap<>();
 
             IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader,
start);
@@ -427,17 +448,18 @@ public class PortableBuilderImpl implements PortableBuilder {
 
             int rawPos = PortableUtils.rawOffsetAbsolute(reader, start);
 
-            while (footerPos < footerEnd) {
+            while (footerPos + 4 < footerEnd) {
                 int fieldId = reader.readIntPositioned(footerPos);
 
-                IgniteBiTuple<Integer, Integer> posAndLen = fieldPositionAndLength(footerPos,
footerEnd, rawPos);
+                IgniteBiTuple<Integer, Integer> posAndLen =
+                    fieldPositionAndLength(footerPos, footerEnd, rawPos, fieldOffsetSize);
 
                 Object val = reader.getValueQuickly(posAndLen.get1(), posAndLen.get2());
 
                 readCache.put(fieldId, val);
 
                 // Shift current footer position.
-                footerPos += 8;
+                footerPos += 4 + fieldOffsetSize;
             }
 
             this.readCache = readCache;

http://git-wip-us.apache.org/repos/asf/ignite/blob/c374c160/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
index 57ae3e7..9645ced 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
@@ -124,7 +124,7 @@ public class PortableBuilderReader implements PortablePositionReadable
{
      * @param pos Position in the source array.
      * @return Read byte value.
      */
-    public byte readByteAbsolute(int pos) {
+    public byte readBytePositioned(int pos) {
         return PortablePrimitives.readByte(arr, pos);
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/c374c160/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java
index 7dbee92..d7f66c9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java
@@ -158,6 +158,16 @@ public abstract class PortableAbstractInputStream extends PortableAbstractStream
     }
 
     /** {@inheritDoc} */
+    @Override public byte readBytePositioned(int pos) {
+        int delta = pos + 1 - this.pos;
+
+        if (delta > 0)
+            ensureEnoughData(delta);
+
+        return readBytePositioned0(pos);
+    }
+
+    /** {@inheritDoc} */
     @Override public short readShortPositioned(int pos) {
         int delta = pos + 2 - this.pos;
 
@@ -344,6 +354,14 @@ public abstract class PortableAbstractInputStream extends PortableAbstractStream
     protected abstract long readLongFast();
 
     /**
+     * Internal routine for positioned byte value read.
+     *
+     * @param pos Position.
+     * @return Int value.
+     */
+    protected abstract byte readBytePositioned0(int pos);
+
+    /**
      * Internal routine for positioned short value read.
      *
      * @param pos Position.

http://git-wip-us.apache.org/repos/asf/ignite/blob/c374c160/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableHeapInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableHeapInputStream.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableHeapInputStream.java
index adfeaad..e027d70 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableHeapInputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableHeapInputStream.java
@@ -123,6 +123,11 @@ public final class PortableHeapInputStream extends PortableAbstractInputStream
{
     }
 
     /** {@inheritDoc} */
+    @Override protected byte readBytePositioned0(int pos) {
+        return UNSAFE.getByte(data, BYTE_ARR_OFF + pos);
+    }
+
+    /** {@inheritDoc} */
     @Override protected short readShortPositioned0(int pos) {
         short res = UNSAFE.getShort(data, BYTE_ARR_OFF + pos);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/c374c160/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOffheapInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOffheapInputStream.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOffheapInputStream.java
index 75bffb9..1dc9b5b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOffheapInputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOffheapInputStream.java
@@ -113,6 +113,11 @@ public class PortableOffheapInputStream extends PortableAbstractInputStream
{
     }
 
     /** {@inheritDoc} */
+    @Override protected byte readBytePositioned0(int pos) {
+        return UNSAFE.getByte(ptr + pos);
+    }
+
+    /** {@inheritDoc} */
     @Override protected short readShortPositioned0(int pos) {
         short res = UNSAFE.getShort(ptr + pos);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/c374c160/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformBigEndianInputStreamImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformBigEndianInputStreamImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformBigEndianInputStreamImpl.java
index a4d711e..41bc43f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformBigEndianInputStreamImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformBigEndianInputStreamImpl.java
@@ -65,6 +65,11 @@ public class PlatformBigEndianInputStreamImpl extends PlatformInputStreamImpl
{
     }
 
     /** {@inheritDoc} */
+    @Override public byte readBytePositioned(int pos) {
+        return super.readBytePositioned(pos);
+    }
+
+    /** {@inheritDoc} */
     @Override public short readShortPositioned(int pos) {
         return Short.reverseBytes(super.readShortPositioned(pos));
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/c374c160/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformInputStreamImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformInputStreamImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformInputStreamImpl.java
index 68b4141..13da8c5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformInputStreamImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformInputStreamImpl.java
@@ -146,6 +146,16 @@ public class PlatformInputStreamImpl implements PlatformInputStream {
     }
 
     /** {@inheritDoc} */
+    @Override public byte readBytePositioned(int pos) {
+        int delta = pos + 1 - this.pos;
+
+        if (delta > 0)
+            ensureEnoughData(delta);
+
+        return UNSAFE.getByte(data + pos);
+    }
+
+    /** {@inheritDoc} */
     @Override public short readShortPositioned(int pos) {
         int delta = pos + 2 - this.pos;
 


Mime
View raw message