ignite-gg-11810

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

Branch: refs/heads/ignite-gg-11810
Commit: 80bf5806b7d6945c09af3b8f024acfd8f814123f
Parents: 0a556cb
Author: sboikov <sboi...@gridgain.com>
Authored: Fri Dec 23 15:46:44 2016 +0300
Committer: sboikov <sboi...@gridgain.com>
Committed: Fri Dec 23 15:46:44 2016 +0300

----------------------------------------------------------------------
 .../ignite/internal/pagemem/PageUtils.java      | 38 ++++++++++++++++++++
 .../cache/database/CacheDataRowAdapter.java     |  2 +-
 .../cache/database/tree/io/DataPageIO.java      | 12 +++++--
 3 files changed, 48 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/80bf5806/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageUtils.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageUtils.java 
b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageUtils.java
index b6faeb1..6f46cd5 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageUtils.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/pagemem/PageUtils.java
@@ -29,10 +29,17 @@ public class PageUtils {
     private static final Unsafe unsafe = GridUnsafe.UNSAFE;
 
     public static byte getByte(long buf, int off) {
+        assert buf > 0 : buf;
+        assert off >= 0;
+
         return unsafe.getByte(buf + off);
     }
 
     public static byte[] getBytes(long buf, int off, int len) {
+        assert buf > 0 : buf;
+        assert off >= 0;
+        assert len >= 0;
+
         byte[] bytes = new byte[len];
 
         unsafe.copyMemory(null, buf + off, bytes, GridUnsafe.BYTE_ARR_OFF, 
len);
@@ -41,38 +48,69 @@ public class PageUtils {
     }
 
     public static void getBytes(long src, int srcOff, byte[] dst, int dstOff, 
int len) {
+        assert src > 0;
+        assert srcOff > 0;
+        assert dst != null;
+        assert dstOff >= 0;
+        assert len >= 0;
+
         unsafe.copyMemory(null, src + srcOff, dst, GridUnsafe.BYTE_ARR_OFF + 
dstOff, len);
     }
 
     public static short getShort(long buf, int off) {
+        assert buf > 0 : buf;
+        assert off >= 0;
+
         return unsafe.getShort(buf + off);
     }
 
     public static int getInt(long buf, int off) {
+        assert buf > 0 : buf;
+        assert off >= 0;
+
         return unsafe.getInt(buf + off);
     }
 
     public static long getLong(long buf, int off) {
+        assert buf > 0 : buf;
+        assert off >= 0;
+
         return unsafe.getLong(buf + off);
     }
 
     public static void putBytes(long buf, int off, byte[] bytes) {
+        assert buf > 0 : buf;
+        assert off >= 0;
+        assert bytes != null;
+
         unsafe.copyMemory(bytes, GridUnsafe.BYTE_ARR_OFF, null, buf + off, 
bytes.length);
     }
 
     public static void putByte(long buf, int off, byte v) {
+        assert buf > 0 : buf;
+        assert off >= 0;
+
         unsafe.putByte(buf + off, v);
     }
 
     public static void putShort(long buf, int off, short v) {
+        assert buf > 0 : buf;
+        assert off >= 0;
+
         unsafe.putShort(buf + off, v);
     }
 
     public static void putInt(long buf, int off, int v) {
+        assert buf > 0 : buf;
+        assert off >= 0;
+
         unsafe.putInt(buf + off, v);
     }
 
     public static void putLong(long buf, int off, long v) {
+        assert buf > 0 : buf;
+        assert off >= 0;
+
         unsafe.putLong(buf + off, v);
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/80bf5806/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
index 59e2fc4..1e7a99b 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/CacheDataRowAdapter.java
@@ -104,7 +104,7 @@ public class CacheDataRowAdapter implements CacheDataRow {
                     if (first) {
                         if (nextLink == 0) {
                             // Fast path for a single page row.
-                            readFullRow(coctx, data.offset(), keyOnly);
+                            readFullRow(coctx, buf + data.offset(), keyOnly);
 
                             return;
                         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/80bf5806/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java
index c9baf05..fcb7fb9 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPageIO.java
@@ -29,6 +29,8 @@ import 
org.apache.ignite.internal.processors.cache.database.CacheDataRow;
 import 
org.apache.ignite.internal.processors.cache.database.tree.util.PageHandler;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.util.typedef.internal.SB;
+import sun.misc.JavaNioAccess;
+import sun.misc.SharedSecrets;
 
 /**
  * Data pages IO.
@@ -184,9 +186,10 @@ public class DataPageIO extends PageIO {
     /**
      * @param buf Buffer.
      * @param freeSpace Free space.
+     * @param pageSize Page size.
      */
     private void setRealFreeSpace(long buf, int freeSpace, int pageSize) {
-        assert freeSpace == actualFreeSpace(buf, pageSize): freeSpace + " != " 
+ actualFreeSpace(buf, pageSize);
+        assert freeSpace == actualFreeSpace(buf, pageSize) : freeSpace + " != 
" + actualFreeSpace(buf, pageSize);
 
         PageUtils.putShort(buf, FREE_SPACE_OFF, (short)freeSpace);
     }
@@ -872,6 +875,9 @@ public class DataPageIO extends PageIO {
         addRowFragment(buf, 0, 0, lastLink, null, payload, pageSize);
     }
 
+    // TODO GG-11810.
+    private JavaNioAccess nioAccess = SharedSecrets.getJavaNioAccess();
+
     /**
      * Adds maximum possible fragment of the given row to this data page and 
sets respective link to the row.
      *
@@ -905,11 +911,11 @@ public class DataPageIO extends PageIO {
         int dataOff = getDataOffsetForWrite(buf, fullEntrySize, directCnt, 
indirectCnt, pageSize);
 
         if (payload == null) {
-            ByteBuffer buf0 = null;
+            ByteBuffer buf0 = nioAccess.newDirectByteBuffer(buf, pageSize, 
null);
 
             buf0.position(dataOff);
 
-            buf0.putShort((short) (payloadSize | FRAGMENTED_FLAG));
+            buf0.putShort((short)(payloadSize | FRAGMENTED_FLAG));
             buf0.putLong(lastLink);
 
             int rowOff = rowSize - written - payloadSize;

Reply via email to