ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [2/5] ignite git commit: IGNITE-1961: WIP 2 (TC is fine).
Date Fri, 20 Nov 2015 14:43:04 GMT
IGNITE-1961: WIP 2 (TC is fine).


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

Branch: refs/heads/ignite-1961
Commit: 5254065c8cad91e75708078cefe7fe9fdc0d2621
Parents: 7a7bc5c
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Fri Nov 20 16:47:37 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Fri Nov 20 16:47:37 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/BinaryReaderExImpl.java   | 76 ++++++++++++--------
 1 file changed, 48 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/5254065c/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 01e07c7..0ca23e4 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
@@ -266,7 +266,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
             schema = null;
         }
 
-        in.position(start);
+        streamPosition(start);
     }
 
     /**
@@ -297,10 +297,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
      * @throws BinaryObjectException In case of error.
      */
     public Object unmarshal(int offset) throws BinaryObjectException {
-        // Random reads prevent any further speculations.
-        matching = false;
-
-        in.position(offset);
+        streamPositionRandom(offset);
 
         return in.position() >= 0 ? unmarshal() : null;
     }
@@ -395,18 +392,18 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
      * @return Field.
      */
     private <T> T readHandleField() {
-        int handle = positionForHandle() - in.readInt();
+        int handlePos = positionForHandle() - in.readInt();
 
-        Object obj = rCtx.get(handle);
+        Object obj = rCtx.get(handlePos);
 
         if (obj == null) {
             int retPos = in.position();
 
-            in.position(handle);
+            streamPosition(handlePos);
 
             obj = doReadObject();
 
-            in.position(retPos);
+            streamPosition(retPos);
         }
 
         return (T)obj;
@@ -1387,7 +1384,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
 
     /** {@inheritDoc} */
     @Override public BinaryRawReader rawReader() {
-        in.position(rawOff);
+        streamPositionRandom(rawOff);
 
         return this;
     }
@@ -1405,17 +1402,18 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
             case NULL:
                 return null;
 
-            case HANDLE:
-                int handle = start - in.readInt();
+            case HANDLE: {
+                int handlePos = start - in.readInt();
 
-                BinaryObject handledPo = rCtx.get(handle);
+                BinaryObject obj = rCtx.get(handlePos);
 
-                if (handledPo != null)
-                    return handledPo;
+                if (obj != null)
+                    return obj;
 
-                in.position(handle);
+                in.position(handlePos);
 
                 return unmarshal();
+            }
 
             case OBJ:
                 PortableUtils.checkProtocolVersion(in.readByte());
@@ -1598,7 +1596,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
         // String will copy necessary array part for us.
         String res = new String(in.array(), pos, strLen, UTF_8);
 
-        in.position(pos + strLen);
+        streamPosition(pos + strLen);
 
         return res;
     }
@@ -1659,18 +1657,18 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
                 break;
 
             case HANDLE:
-                int handle = start - in.readInt();
+                int handlePos = start - in.readInt();
 
-                obj = rCtx.get(handle);
+                obj = rCtx.get(handlePos);
 
                 if (obj == null) {
                     int retPos = in.position();
 
-                    in.position(handle);
+                    streamPosition(handlePos);
 
                     obj = doReadObject();
 
-                    in.position(retPos);
+                    streamPosition(retPos);
                 }
 
                 break;
@@ -1678,14 +1676,14 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
             case OBJ:
                 PortableClassDescriptor desc = ctx.descriptorForTypeId(userType, typeId,
ldr);
 
-                in.position(start + hdrLen);
+                streamPosition(start + hdrLen);
 
                 if (desc == null)
                     throw new BinaryInvalidTypeException("Unknown type ID: " + typeId);
 
                 obj = desc.read(this);
 
-                in.position(footerStart + footerLen);
+                streamPosition(footerStart + footerLen);
 
                 break;
 
@@ -1876,7 +1874,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
                     throw new BinaryObjectException("Failed to unmarshal object with optimized
marshaller", e);
                 }
 
-                in.position(in.position() + dataLen);
+                streamPosition(in.position() + dataLen);
 
                 break;
 
@@ -2299,7 +2297,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
 
             int pos = in.position();
 
-            in.position(in.position() + len);
+            streamPosition(in.position() + len);
 
             int start = in.readInt();
 
@@ -2593,7 +2591,8 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
 
             int pos = start + PortableUtils.fieldOffsetRelative(in, offsetPos, fieldOffsetLen);
 
-            in.position(pos);
+            // TODO: Convert to unsafe mode.
+            streamPosition(pos);
 
             return true;
         }
@@ -2624,7 +2623,8 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
                 int pos = start + PortableUtils.fieldOffsetRelative(in, searchPos + PortableUtils.FIELD_ID_LEN,
                     fieldOffsetLen);
 
-                in.position(pos);
+                // TODO: Convert to unsafe mode.
+                streamPosition(pos);
 
                 return true;
             }
@@ -2633,6 +2633,26 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
         }
     }
 
+    /**
+     * Set stream position.
+     *
+     * @param pos Position.
+     */
+    private void streamPosition(int pos) {
+        in.position(pos);
+    }
+
+    /**
+     * Set stream position as a part of some random read. Further speculations will be disabled
after this call.
+     *
+     * @param pos Position.
+     */
+    private void streamPositionRandom(int pos) {
+        streamPosition(pos);
+
+        matching = false;
+    }
+
     /** {@inheritDoc} */
     @Override public int readUnsignedByte() throws IOException {
         return readByte() & 0xff;
@@ -2699,7 +2719,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
     @Override public int skipBytes(int n) throws IOException {
         int toSkip = Math.min(in.remaining(), n);
 
-        in.position(in.position() + toSkip);
+        streamPositionRandom(in.position() + toSkip);
 
         return toSkip;
     }


Mime
View raw message