ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [1/4] ignite git commit: ignite-gg-11810
Date Fri, 23 Dec 2016 12:06:44 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-11810 6f1ed0daf -> 0a556cbb7


http://git-wip-us.apache.org/repos/asf/ignite/blob/664ceac5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusIO.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusIO.java
index 6c739a5..10df6f1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusIO.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusIO.java
@@ -72,8 +72,8 @@ public abstract class BPlusIO<L> extends PageIO {
     }
 
     /** {@inheritDoc} */
-    @Override public void initNewPage(long buf, long pageId) {
-        super.initNewPage(buf, pageId);
+    @Override public void initNewPage(long buf, long pageId, int pageSize) {
+        super.initNewPage(buf, pageId, pageSize);
 
         setCount(buf, 0);
         setForward(buf, 0);
@@ -160,7 +160,7 @@ public abstract class BPlusIO<L> extends PageIO {
      * @param buf Buffer.
      * @return Max items count.
      */
-    public abstract int getMaxCount(int pageSize, long buf);
+    public abstract int getMaxCount(long buf, int pageSize);
 
     /**
      * Store the needed info about the row in the page. Leaf and inner pages can store different info.
@@ -263,6 +263,7 @@ public abstract class BPlusIO<L> extends PageIO {
      * @param fwdBuf Forward buffer.
      * @param mid Bisection index.
      * @param cnt Initial elements count in the page being split.
+     * @param pageSize Page size.
      * @throws IgniteCheckedException If failed.
      */
     public void splitForwardPage(
@@ -270,9 +271,10 @@ public abstract class BPlusIO<L> extends PageIO {
         long fwdId,
         long fwdBuf,
         int mid,
-        int cnt
+        int cnt,
+        int pageSize
     ) throws IgniteCheckedException {
-        initNewPage(fwdBuf, fwdId);
+        initNewPage(fwdBuf, fwdId, pageSize);
 
         cnt -= mid;
 
@@ -320,13 +322,13 @@ public abstract class BPlusIO<L> extends PageIO {
      * @throws IgniteCheckedException If failed.
      */
     public boolean merge(
-        int pageSize,
         BPlusIO<L> prntIo,
         long prnt,
         int prntIdx,
         long left,
         long right,
-        boolean emptyBranch
+        boolean emptyBranch,
+        int pageSize
     ) throws IgniteCheckedException {
         int prntCnt = prntIo.getCount(prnt);
         int leftCnt = getCount(left);
@@ -338,7 +340,7 @@ public abstract class BPlusIO<L> extends PageIO {
         if (!isLeaf() && !emptyBranch)
             newCnt++;
 
-        if (newCnt > getMaxCount(pageSize, left)) {
+        if (newCnt > getMaxCount(left, pageSize)) {
             assert !emptyBranch;
 
             return false;

http://git-wip-us.apache.org/repos/asf/ignite/blob/664ceac5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java
index d0ead51..7158770 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusInnerIO.java
@@ -45,7 +45,7 @@ public abstract class BPlusInnerIO<L> extends BPlusIO<L> {
     }
 
     /** {@inheritDoc} */
-    @Override public int getMaxCount(int pageSize, long buf) {
+    @Override public int getMaxCount(long buf, int pageSize) {
         // The structure of the page is the following:
         // |ITEMS_OFF|w|A|x|B|y|C|z|
         // where capital letters are data items, lowercase letters are 8 byte page references.
@@ -157,9 +157,10 @@ public abstract class BPlusInnerIO<L> extends BPlusIO<L> {
         long leftChildId,
         L row,
         byte[] rowBytes,
-        long rightChildId
+        long rightChildId,
+        int pageSize
     ) throws IgniteCheckedException {
-        initNewPage(newRootBuf, newRootId);
+        initNewPage(newRootBuf, newRootId, pageSize);
 
         setCount(newRootBuf, 1);
         setLeft(newRootBuf, 0, leftChildId);

http://git-wip-us.apache.org/repos/asf/ignite/blob/664ceac5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java
index 76c621c..cf97764 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/BPlusLeafIO.java
@@ -35,7 +35,7 @@ public abstract class BPlusLeafIO<L> extends BPlusIO<L> {
     }
 
     /** {@inheritDoc} */
-    @Override public int getMaxCount(int pageSize, long buf) {
+    @Override public int getMaxCount(long buf, int pageSize) {
         return (pageSize - ITEMS_OFF) / itemSize;
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/664ceac5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/CacheVersionIO.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/CacheVersionIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/CacheVersionIO.java
index ed75d12..fac3e20 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/CacheVersionIO.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/CacheVersionIO.java
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.internal.processors.cache.database.tree.io;
 
+import java.nio.ByteBuffer;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.pagemem.PageUtils;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
@@ -58,6 +59,29 @@ public class CacheVersionIO {
      * @param ver Version to write.
      * @param allowNull Is {@code null} version allowed.
      */
+    public static void write(ByteBuffer buf, GridCacheVersion ver, boolean allowNull) {
+        if (ver == null) {
+            if (allowNull)
+                buf.put(NULL_PROTO_VER);
+            else
+                throw new IllegalStateException("Cache version is null");
+        }
+        else {
+            byte protoVer = 1; // Version of serialization protocol.
+
+            buf.put(protoVer);
+            buf.putInt(ver.topologyVersion());
+            buf.putInt(ver.nodeOrderAndDrIdRaw());
+            buf.putLong(ver.globalTime());
+            buf.putLong(ver.order());
+        }
+    }
+
+    /**
+     * @param buf Byte buffer.
+     * @param ver Version to write.
+     * @param allowNull Is {@code null} version allowed.
+     */
     public static void write(long buf, GridCacheVersion ver, boolean allowNull) {
         if (ver == null) {
             if (allowNull)
@@ -102,6 +126,53 @@ public class CacheVersionIO {
      * @return Size of serialized version.
      * @throws IgniteCheckedException If failed.
      */
+    public static int readSize(ByteBuffer buf, boolean allowNull) throws IgniteCheckedException {
+        byte protoVer = checkProtocolVersion(buf.get(buf.position()), allowNull);
+
+        switch (protoVer) {
+            case NULL_PROTO_VER:
+                return NULL_SIZE;
+
+            case 1:
+                return SIZE_V1;
+
+            default:
+                throw new IllegalStateException();
+        }
+    }
+
+    /**
+     * Reads GridCacheVersion instance from the given buffer. Moves buffer's position by the number of used
+     * bytes.
+     *
+     * @param buf Byte buffer.
+     * @param allowNull Is {@code null} version allowed.
+     * @return Version.
+     * @throws IgniteCheckedException If failed.
+     */
+    public static GridCacheVersion read(ByteBuffer buf, boolean allowNull) throws IgniteCheckedException {
+        byte protoVer = checkProtocolVersion(buf.get(), allowNull);
+
+        if (protoVer == NULL_PROTO_VER)
+            return null;
+
+        int topVer = buf.getInt();
+        int nodeOrderDrId = buf.getInt();
+        long globalTime = buf.getLong();
+        long order = buf.getLong();
+
+        return new GridCacheVersion(topVer, nodeOrderDrId, globalTime, order);
+    }
+
+    /**
+     * Gets needed buffer size to read the whole version instance.
+     * Does not change buffer position.
+     *
+     * @param buf Buffer.
+     * @param allowNull Is {@code null} version allowed.
+     * @return Size of serialized version.
+     * @throws IgniteCheckedException If failed.
+     */
     public static int readSize(long buf, boolean allowNull) throws IgniteCheckedException {
         byte protoVer = checkProtocolVersion(PageUtils.getByte(buf, 0), allowNull);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/664ceac5/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 ca8ea39..c9baf05 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
@@ -17,6 +17,7 @@
 
 package org.apache.ignite.internal.processors.cache.database.tree.io;
 
+import java.nio.ByteBuffer;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
@@ -88,21 +89,22 @@ public class DataPageIO extends PageIO {
     }
 
     /** {@inheritDoc} */
-    @Override public void initNewPage(long buf, long pageId) {
-        super.initNewPage(buf, pageId);
+    @Override public void initNewPage(long buf, long pageId, int pageSize) {
+        super.initNewPage(buf, pageId, pageSize);
 
-        setEmptyPage(buf);
+        setEmptyPage(buf, pageSize);
         setFreeListPageId(buf, 0L);
     }
 
     /**
      * @param buf Buffer.
+     * @param pageSize Page size.
      */
-    private void setEmptyPage(long buf) {
+    private void setEmptyPage(long buf, int pageSize) {
         setDirectCount(buf, 0);
         setIndirectCount(buf, 0);
-        setFirstEntryOffset(buf, buf.capacity());
-        setRealFreeSpace(buf, buf.capacity() - ITEMS_OFF);
+        setFirstEntryOffset(buf, pageSize, pageSize);
+        setRealFreeSpace(buf, pageSize - ITEMS_OFF, pageSize);
     }
 
     /**
@@ -163,9 +165,10 @@ public class DataPageIO extends PageIO {
     /**
      * @param buf Buffer.
      * @param dataOff Entry data offset.
+     * @param pageSize Page size.
      */
-    private void setFirstEntryOffset(long buf, int dataOff) {
-        assert dataOff >= ITEMS_OFF + ITEM_SIZE && dataOff <= buf.capacity(): dataOff;
+    private void setFirstEntryOffset(long buf, int dataOff, int pageSize) {
+        assert dataOff >= ITEMS_OFF + ITEM_SIZE && dataOff <= pageSize : dataOff;
 
         PageUtils.putShort(buf, FIRST_ENTRY_OFF, (short)dataOff);
     }
@@ -182,8 +185,8 @@ public class DataPageIO extends PageIO {
      * @param buf Buffer.
      * @param freeSpace Free space.
      */
-    private void setRealFreeSpace(long buf, int freeSpace) {
-        assert freeSpace == actualFreeSpace(buf): freeSpace + " != " + actualFreeSpace(buf);
+    private void setRealFreeSpace(long buf, int freeSpace, int pageSize) {
+        assert freeSpace == actualFreeSpace(buf, pageSize): freeSpace + " != " + actualFreeSpace(buf, pageSize);
 
         PageUtils.putShort(buf, FREE_SPACE_OFF, (short)freeSpace);
     }
@@ -218,7 +221,7 @@ public class DataPageIO extends PageIO {
     }
 
     /**
-     * Equivalent for {@link #actualFreeSpace(long)} but reads saved value.
+     * Equivalent for {@link #actualFreeSpace(long, int)} but reads saved value.
      *
      * @param buf Buffer.
      * @return Free space.
@@ -316,9 +319,10 @@ public class DataPageIO extends PageIO {
 
     /**
      * @param buf Buffer.
+     * @param pageSize Page size.
      * @return String representation.
      */
-    public String printPageLayout(long buf) {
+    public String printPageLayout(long buf, int pageSize) {
         int directCnt = getDirectCount(buf);
         int indirectCnt = getIndirectCount(buf);
         int free = getRealFreeSpace(buf);
@@ -337,7 +341,7 @@ public class DataPageIO extends PageIO {
 
             short item = getItem(buf, i);
 
-            if (item < ITEMS_OFF || item >= buf.capacity())
+            if (item < ITEMS_OFF || item >= pageSize)
                 valid = false;
 
             entriesSize += getPageEntrySize(buf, item, SHOW_PAYLOAD_LEN | SHOW_LINK);
@@ -375,7 +379,7 @@ public class DataPageIO extends PageIO {
 
         b.a("][free=").a(free);
 
-        int actualFree = buf.capacity() - ITEMS_OFF - (entriesSize + (directCnt + indirectCnt) * ITEM_SIZE);
+        int actualFree = pageSize - ITEMS_OFF - (entriesSize + (directCnt + indirectCnt) * ITEM_SIZE);
 
         if (free != actualFree) {
             b.a(", actualFree=").a(actualFree);
@@ -395,19 +399,19 @@ public class DataPageIO extends PageIO {
      * @param itemId Fixed item ID (the index used for referencing an entry from the outside).
      * @return Data entry offset in bytes.
      */
-    private int getDataOffset(long buf, int itemId) {
+    private int getDataOffset(long buf, int itemId, int pageSize) {
         assert checkIndex(itemId): itemId;
 
         int directCnt = getDirectCount(buf);
 
-        assert directCnt > 0: "itemId=" + itemId + ", directCnt=" + directCnt + ", page=" + printPageLayout(buf);
+        assert directCnt > 0: "itemId=" + itemId + ", directCnt=" + directCnt + ", page=" + printPageLayout(buf, pageSize);
 
         if (itemId >= directCnt) { // Need to do indirect lookup.
             int indirectCnt = getIndirectCount(buf);
 
             // Must have indirect items here.
             assert indirectCnt > 0: "itemId=" + itemId + ", directCnt=" + directCnt + ", indirectCnt=" + indirectCnt +
-                ", page=" + printPageLayout(buf);
+                ", page=" + printPageLayout(buf, pageSize);
 
             int indirectItemIdx = findIndirectItemIndex(buf, itemId, directCnt, indirectCnt);
 
@@ -449,18 +453,16 @@ public class DataPageIO extends PageIO {
      * @param itemId Item to position on.
      * @return Link to the next fragment or {@code 0} if it is the last fragment or the data row is not fragmented.
      */
-    public long setPositionAndLimitOnPayload(final long buf, final int itemId) {
-        int dataOff = getDataOffset(buf, itemId);
+    public DataPagePayload readPayload(final long buf, final int itemId, final int pageSize) {
+        int dataOff = getDataOffset(buf, itemId, pageSize);
 
         boolean fragmented = isFragmented(buf, dataOff);
         long nextLink = fragmented ? getNextFragmentLink(buf, dataOff) : 0;
         int payloadSize = getPageEntrySize(buf, dataOff, 0);
 
-        buf.position(dataOff + PAYLOAD_LEN_SIZE + (fragmented ? LINK_SIZE : 0));
-
-        buf.limit(buf.position() + payloadSize);
-
-        return nextLink;
+        return new DataPagePayload(dataOff + PAYLOAD_LEN_SIZE + (fragmented ? LINK_SIZE : 0),
+            payloadSize,
+            nextLink);
     }
 
     /**
@@ -593,13 +595,14 @@ public class DataPageIO extends PageIO {
     /**
      * @param buf Buffer.
      * @param itemId Fixed item ID (the index used for referencing an entry from the outside).
+     * @param pageSize Page size.
      * @return Next link for fragmented entries or {@code 0} if none.
      * @throws IgniteCheckedException If failed.
      */
-    public long removeRow(long buf, int itemId) throws IgniteCheckedException {
+    public long removeRow(long buf, int itemId, int pageSize) throws IgniteCheckedException {
         assert checkIndex(itemId) : itemId;
 
-        final int dataOff = getDataOffset(buf, itemId);
+        final int dataOff = getDataOffset(buf, itemId, pageSize);
         final long nextLink = isFragmented(buf, dataOff) ? getNextFragmentLink(buf, dataOff) : 0;
 
         // Record original counts to calculate delta in free space in the end of remove.
@@ -615,7 +618,7 @@ public class DataPageIO extends PageIO {
             assert (indirectCnt == 0 && itemId == 0) ||
                 (indirectCnt == 1 && itemId == itemId(getItem(buf, 1))) : itemId;
 
-            setEmptyPage(buf);
+            setEmptyPage(buf, pageSize);
         }
         else {
             // Get the entry size before the actual remove.
@@ -642,15 +645,15 @@ public class DataPageIO extends PageIO {
 
             if (indirectId == 0) {// For the last direct item with no indirect item.
                 if (dropLast)
-                    moveItems(buf, directCnt, indirectCnt, -1);
+                    moveItems(buf, directCnt, indirectCnt, -1, pageSize);
                 else
                     curIndirectCnt++;
             }
             else {
                 if (dropLast)
-                    moveItems(buf, directCnt, indirectId - directCnt, -1);
+                    moveItems(buf, directCnt, indirectId - directCnt, -1, pageSize);
 
-                moveItems(buf, indirectId + 1, directCnt + indirectCnt - indirectId - 1, dropLast ? -2 : -1);
+                moveItems(buf, indirectId + 1, directCnt + indirectCnt - indirectId - 1, dropLast ? -2 : -1, pageSize);
 
                 if (dropLast)
                     curIndirectCnt--;
@@ -662,8 +665,9 @@ public class DataPageIO extends PageIO {
             assert getIndirectCount(buf) <= getDirectCount(buf);
 
             // Increase free space.
-            setRealFreeSpace(buf, getRealFreeSpace(buf) + rmvEntrySize +
-                ITEM_SIZE * (directCnt - getDirectCount(buf) + indirectCnt - getIndirectCount(buf)));
+            setRealFreeSpace(buf,
+                getRealFreeSpace(buf) + rmvEntrySize + ITEM_SIZE * (directCnt - getDirectCount(buf) + indirectCnt - getIndirectCount(buf)),
+                pageSize);
         }
 
         return nextLink;
@@ -674,12 +678,13 @@ public class DataPageIO extends PageIO {
      * @param idx Index.
      * @param cnt Count.
      * @param step Step.
+     * @param pageSize Page size.
      */
-    private void moveItems(long buf, int idx, int cnt, int step) {
+    private void moveItems(long buf, int idx, int cnt, int step, int pageSize) {
         assert cnt >= 0: cnt;
 
         if (cnt != 0)
-            moveBytes(buf, itemOffset(idx), cnt * ITEM_SIZE, step * ITEM_SIZE);
+            moveBytes(buf, itemOffset(idx), cnt * ITEM_SIZE, step * ITEM_SIZE, pageSize);
     }
 
     /**
@@ -699,12 +704,14 @@ public class DataPageIO extends PageIO {
      * @param buf Buffer.
      * @param row Cache data row.
      * @param rowSize Row size.
+     * @param pageSize Page size.
      * @throws IgniteCheckedException If failed.
      */
     public void addRow(
         long buf,
         CacheDataRow row,
-        int rowSize
+        int rowSize,
+        int pageSize
     ) throws IgniteCheckedException {
         assert rowSize <= getFreeSpace(buf): "can't call addRow if not enough space for the whole row";
 
@@ -713,11 +720,11 @@ public class DataPageIO extends PageIO {
         int directCnt = getDirectCount(buf);
         int indirectCnt = getIndirectCount(buf);
 
-        int dataOff = getDataOffsetForWrite(buf, fullEntrySize, directCnt, indirectCnt);
+        int dataOff = getDataOffsetForWrite(buf, fullEntrySize, directCnt, indirectCnt, pageSize);
 
         writeRowData(buf, dataOff, rowSize, row);
 
-        int itemId = addItem(buf, fullEntrySize, directCnt, indirectCnt, dataOff);
+        int itemId = addItem(buf, fullEntrySize, directCnt, indirectCnt, dataOff, pageSize);
 
         setLink(row, buf, itemId);
     }
@@ -726,11 +733,14 @@ public class DataPageIO extends PageIO {
      * Adds row to this data page and sets respective link to the given row object.
      *
      * @param buf Buffer.
+     * @param payload Payload.
+     * @param pageSize Page size.
      * @throws IgniteCheckedException If failed.
      */
     public void addRow(
         long buf,
-        byte[] payload
+        byte[] payload,
+        int pageSize
     ) throws IgniteCheckedException {
         assert payload.length <= getFreeSpace(buf): "can't call addRow if not enough space for the whole row";
 
@@ -739,11 +749,11 @@ public class DataPageIO extends PageIO {
         int directCnt = getDirectCount(buf);
         int indirectCnt = getIndirectCount(buf);
 
-        int dataOff = getDataOffsetForWrite(buf, fullEntrySize, directCnt, indirectCnt);
+        int dataOff = getDataOffsetForWrite(buf, fullEntrySize, directCnt, indirectCnt, pageSize);
 
         writeRowData(buf, dataOff, payload);
 
-        addItem(buf, fullEntrySize, directCnt, indirectCnt, dataOff);
+        addItem(buf, fullEntrySize, directCnt, indirectCnt, dataOff, pageSize);
     }
 
     /**
@@ -752,6 +762,7 @@ public class DataPageIO extends PageIO {
      * @param directCnt Direct items count.
      * @param indirectCnt Indirect items count.
      * @param dataOff First entry offset.
+     * @param pageSize Page size.
      * @return First entry offset after compaction.
      */
     private int compactIfNeed(
@@ -759,10 +770,11 @@ public class DataPageIO extends PageIO {
         final int entryFullSize,
         final int directCnt,
         final int indirectCnt,
-        int dataOff
+        int dataOff,
+        int pageSize
     ) {
         if (!isEnoughSpace(entryFullSize, dataOff, directCnt, indirectCnt)) {
-            dataOff = compactDataEntries(buf, directCnt);
+            dataOff = compactDataEntries(buf, directCnt, pageSize);
 
             assert isEnoughSpace(entryFullSize, dataOff, directCnt, indirectCnt);
         }
@@ -778,20 +790,27 @@ public class DataPageIO extends PageIO {
      * @param directCnt Direct items count.
      * @param indirectCnt Indirect items count.
      * @param dataOff Data offset.
+     * @param pageSize Page size.
      * @return Item ID.
      */
-    private int addItem(final long buf, final int fullEntrySize, final int directCnt,
-        final int indirectCnt, final int dataOff) {
-        setFirstEntryOffset(buf, dataOff);
+    private int addItem(final long buf,
+        final int fullEntrySize,
+        final int directCnt,
+        final int indirectCnt,
+        final int dataOff,
+        final int pageSize)
+    {
+        setFirstEntryOffset(buf, dataOff, pageSize);
 
-        int itemId = insertItem(buf, dataOff, directCnt, indirectCnt);
+        int itemId = insertItem(buf, dataOff, directCnt, indirectCnt, pageSize);
 
         assert checkIndex(itemId): itemId;
         assert getIndirectCount(buf) <= getDirectCount(buf);
 
         // Update free space. If number of indirect items changed, then we were able to reuse an item slot.
-        setRealFreeSpace(buf, getRealFreeSpace(buf) - fullEntrySize +
-            (getIndirectCount(buf) != indirectCnt ? ITEM_SIZE : 0));
+        setRealFreeSpace(buf,
+            getRealFreeSpace(buf) - fullEntrySize + (getIndirectCount(buf) != indirectCnt ? ITEM_SIZE : 0),
+            pageSize);
 
         return itemId;
     }
@@ -801,13 +820,14 @@ public class DataPageIO extends PageIO {
      * @param fullEntrySize Full entry size.
      * @param directCnt Direct items count.
      * @param indirectCnt Indirect items count.
+     * @param pageSize Page size.
      * @return Offset in the buffer where the entry must be written.
      */
-    private int getDataOffsetForWrite(long buf, int fullEntrySize, int directCnt, int indirectCnt) {
+    private int getDataOffsetForWrite(long buf, int fullEntrySize, int directCnt, int indirectCnt, int pageSize) {
         int dataOff = getFirstEntryOffset(buf);
 
         // Compact if we do not have enough space for entry.
-        dataOff = compactIfNeed(buf, fullEntrySize, directCnt, indirectCnt, dataOff);
+        dataOff = compactIfNeed(buf, fullEntrySize, directCnt, indirectCnt, dataOff, pageSize);
 
         // We will write data right before the first entry.
         dataOff -= fullEntrySize - ITEM_SIZE;
@@ -829,9 +849,10 @@ public class DataPageIO extends PageIO {
         long buf,
         CacheDataRow row,
         int written,
-        int rowSize
+        int rowSize,
+        int pageSize
     ) throws IgniteCheckedException {
-        return addRowFragment(buf, written, rowSize, row.link(), row, null);
+        return addRowFragment(buf, written, rowSize, row.link(), row, null, pageSize);
     }
 
     /**
@@ -845,9 +866,10 @@ public class DataPageIO extends PageIO {
     public void addRowFragment(
         long buf,
         byte[] payload,
-        long lastLink
+        long lastLink,
+        int pageSize
     ) throws IgniteCheckedException {
-        addRowFragment(buf, 0, 0, lastLink, null, payload);
+        addRowFragment(buf, 0, 0, lastLink, null, payload, pageSize);
     }
 
     /**
@@ -868,7 +890,8 @@ public class DataPageIO extends PageIO {
         int rowSize,
         long lastLink,
         CacheDataRow row,
-        byte[] payload
+        byte[] payload,
+        int pageSize
     ) throws IgniteCheckedException {
         assert payload == null ^ row == null;
 
@@ -879,20 +902,24 @@ public class DataPageIO extends PageIO {
             Math.min(rowSize - written, getFreeSpace(buf));
 
         int fullEntrySize = getPageEntrySize(payloadSize, SHOW_PAYLOAD_LEN | SHOW_LINK | SHOW_ITEM);
-        int dataOff = getDataOffsetForWrite(buf, fullEntrySize, directCnt, indirectCnt);
-
-        PageUtils.putShort(buf, dataOff, (short)(payloadSize | FRAGMENTED_FLAG));
-        PageUtils.putLong(buf, dataOff + 2, lastLink);
+        int dataOff = getDataOffsetForWrite(buf, fullEntrySize, directCnt, indirectCnt, pageSize);
 
         if (payload == null) {
+            ByteBuffer buf0 = null;
+
+            buf0.position(dataOff);
+
+            buf0.putShort((short) (payloadSize | FRAGMENTED_FLAG));
+            buf0.putLong(lastLink);
+
             int rowOff = rowSize - written - payloadSize;
 
-            writeFragmentData(row, buf + dataOff + 10, rowOff, payloadSize);
+            writeFragmentData(row, buf0, rowOff, payloadSize);
         }
         else
-            PageUtils.putBytes(buf, dataOff + 10, payload);
+            PageUtils.putBytes(buf, dataOff, payload);
 
-        int itemId = addItem(buf, fullEntrySize, directCnt, indirectCnt, dataOff);
+        int itemId = addItem(buf, fullEntrySize, directCnt, indirectCnt, dataOff, pageSize);
 
         if (row != null)
             setLink(row, buf, itemId);
@@ -920,7 +947,7 @@ public class DataPageIO extends PageIO {
      */
     private void writeFragmentData(
         final CacheDataRow row,
-        final long buf,
+        final ByteBuffer buf,
         final int rowOff,
         final int payloadSize
     ) throws IgniteCheckedException {
@@ -946,7 +973,7 @@ public class DataPageIO extends PageIO {
      */
     private int writeFragment(
         final CacheDataRow row,
-        final long buf,
+        final ByteBuffer buf,
         final int rowOff,
         final int payloadSize,
         final EntryPart type,
@@ -1080,9 +1107,10 @@ public class DataPageIO extends PageIO {
      * @param dataOff Data offset.
      * @param directCnt Direct items count.
      * @param indirectCnt Indirect items count.
+     * @param pageSize Page size.
      * @return Item ID (insertion index).
      */
-    private int insertItem(long buf, int dataOff, int directCnt, int indirectCnt) {
+    private int insertItem(long buf, int dataOff, int directCnt, int indirectCnt, int pageSize) {
         if (indirectCnt > 0) {
             // If the first indirect item is on correct place to become the last direct item, do the transition
             // and insert the new item into the free slot which was referenced by this first indirect item.
@@ -1102,7 +1130,7 @@ public class DataPageIO extends PageIO {
         }
 
         // Move all the indirect items forward to make a free slot and insert new item at the end of direct items.
-        moveItems(buf, directCnt, indirectCnt, +1);
+        moveItems(buf, directCnt, indirectCnt, +1, pageSize);
 
         setItem(buf, directCnt, directItemFromOffset(dataOff));
 
@@ -1115,9 +1143,10 @@ public class DataPageIO extends PageIO {
     /**
      * @param buf Buffer.
      * @param directCnt Direct items count.
+     * @param pageSize Page size.
      * @return New first entry offset.
      */
-    private int compactDataEntries(long buf, int directCnt) {
+    private int compactDataEntries(long buf, int directCnt, int pageSize) {
         assert checkCount(directCnt): directCnt;
 
         int[] offs = new int[directCnt];
@@ -1131,7 +1160,7 @@ public class DataPageIO extends PageIO {
         Arrays.sort(offs);
 
         // Move right all of the entries if possible to make the page as compact as possible to its tail.
-        int prevOff = buf.capacity();
+        int prevOff = pageSize;
 
         for (int i = directCnt - 1; i >= 0; i--) {
             int off = offs[i] >>> 8;
@@ -1145,7 +1174,7 @@ public class DataPageIO extends PageIO {
             if (delta != 0) { // Move right.
                 assert delta > 0: delta;
 
-                moveBytes(buf, off, entrySize, delta);
+                moveBytes(buf, off, entrySize, delta, pageSize);
 
                 int itemId = offs[i] & 0xFF;
 
@@ -1164,9 +1193,10 @@ public class DataPageIO extends PageIO {
      * Full-scan free space calculation procedure.
      *
      * @param buf Buffer to scan.
+     * @param pageSize Page size.
      * @return Actual free space in the buffer.
      */
-    private int actualFreeSpace(long buf) {
+    private int actualFreeSpace(long buf, int pageSize) {
         int directCnt = getDirectCount(buf);
 
         int entriesSize = 0;
@@ -1179,7 +1209,7 @@ public class DataPageIO extends PageIO {
             entriesSize += entrySize;
         }
 
-        return buf.capacity() - ITEMS_OFF - entriesSize - (directCnt + getIndirectCount(buf)) * ITEM_SIZE;
+        return pageSize - ITEMS_OFF - entriesSize - (directCnt + getIndirectCount(buf)) * ITEM_SIZE;
     }
 
     /**
@@ -1187,12 +1217,13 @@ public class DataPageIO extends PageIO {
      * @param off Offset.
      * @param cnt Count.
      * @param step Step.
+     * @param pageSize Page size.
      */
-    private void moveBytes(long buf, int off, int cnt, int step) {
+    private void moveBytes(long buf, int off, int cnt, int step, int pageSize) {
         assert step != 0: step;
         assert off + step >= 0;
-        assert off + step + cnt <= buf.capacity() : "[off=" + off + ", step=" + step + ", cnt=" + cnt +
-            ", cap=" + buf.capacity() + ']';
+        assert off + step + cnt <= pageSize : "[off=" + off + ", step=" + step + ", cnt=" + cnt +
+            ", cap=" + pageSize + ']';
 
         PageHandler.copyMemory(buf, buf, off, off + step, cnt);
     }
@@ -1210,26 +1241,36 @@ public class DataPageIO extends PageIO {
         int payloadSize,
         CacheDataRow row
     ) throws IgniteCheckedException {
-        try {
-            buf.position(dataOff);
+        PageUtils.putShort(buf, dataOff, (short)payloadSize);
+        dataOff += 2;
 
-            buf.putShort((short)payloadSize);
+        byte[] bytes = row.key().valueBytes(null);
 
-            boolean ok = row.key().putValue(buf);
+        PageUtils.putInt(buf, dataOff, bytes.length);
+        dataOff += 4;
 
-            assert ok;
+        PageUtils.putBytes(buf, dataOff, bytes);
+        dataOff += bytes.length;
 
-            ok = row.value().putValue(buf);
+        PageUtils.putByte(buf, dataOff, row.key().cacheObjectType());
+        dataOff++;
 
-            assert ok;
+        bytes = row.value().valueBytes(null);
 
-            CacheVersionIO.write(buf, row.version(), false);
+        PageUtils.putInt(buf, dataOff, bytes.length);
+        dataOff += 4;
 
-            buf.putLong(row.expireTime());
-        }
-        finally {
-            buf.position(0);
-        }
+        PageUtils.putBytes(buf, dataOff, bytes);
+        dataOff += bytes.length;
+
+        PageUtils.putByte(buf, dataOff, row.value().cacheObjectType());
+        dataOff++;
+
+        CacheVersionIO.write(buf + dataOff, row.version(), false);
+
+        dataOff += CacheVersionIO.size(row.version(), false);
+
+        PageUtils.putLong(buf, dataOff, row.expireTime());
     }
 
     /**
@@ -1242,15 +1283,9 @@ public class DataPageIO extends PageIO {
         int dataOff,
         byte[] payload
     ) {
-        try {
-            buf.position(dataOff);
+        PageUtils.putShort(buf, dataOff, (short)payload.length);
+        dataOff += 2;
 
-            buf.putShort((short)payload.length);
-
-            buf.put(payload);
-        }
-        finally {
-            buf.position(0);
-        }
+        PageUtils.putBytes(buf, dataOff, payload);
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/664ceac5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPagePayload.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPagePayload.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPagePayload.java
new file mode 100644
index 0000000..203429e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/DataPagePayload.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.database.tree.io;
+
+/**
+ *
+ */
+public class DataPagePayload {
+    /** */
+    private final int off;
+
+    /** */
+    private final int payloadSize;
+
+    /** */
+    private final long nextLink;
+
+    DataPagePayload(int off, int payloadSize, long nextLink) {
+        this.off = off;
+        this.payloadSize = payloadSize;
+        this.nextLink = nextLink;
+    }
+
+    public int offset() {
+        return off;
+    }
+
+    public int payloadSize() {
+        return payloadSize;
+    }
+
+    public long nextLink() {
+        return nextLink;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/664ceac5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java
index 12646ae..3aee268 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageIO.java
@@ -275,7 +275,7 @@ public abstract class PageIO {
      * @param buf Buffer.
      * @param pageId Page ID.
      */
-    public void initNewPage(long buf, long pageId) {
+    public void initNewPage(long buf, long pageId, int pageSize) {
         setType(buf, getType());
         setVersion(buf, getVersion());
         setPageId(buf, pageId);

http://git-wip-us.apache.org/repos/asf/ignite/blob/664ceac5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java
index fb8762e..7ef4db0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PageMetaIO.java
@@ -68,8 +68,8 @@ public class PageMetaIO extends PageIO {
     }
 
     /** {@inheritDoc} */
-    @Override public void initNewPage(long buf, long pageId) {
-        super.initNewPage(buf, pageId);
+    @Override public void initNewPage(long buf, long pageId, int pageSize) {
+        super.initNewPage(buf, pageId, pageSize);
 
         setTreeRoot(buf, 0);
         setReuseListRoot(buf, 0);

http://git-wip-us.apache.org/repos/asf/ignite/blob/664ceac5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java
index 72893fb..531ba1e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/PagePartitionMetaIO.java
@@ -42,8 +42,8 @@ public class PagePartitionMetaIO extends PageMetaIO {
     );
 
     /** {@inheritDoc} */
-    @Override public void initNewPage(long buf, long pageId) {
-        super.initNewPage(buf, pageId);
+    @Override public void initNewPage(long buf, long pageId, int pageSize) {
+        super.initNewPage(buf, pageId, pageSize);
 
         setSize(buf, 0);
         setUpdateCounter(buf, 0);

http://git-wip-us.apache.org/repos/asf/ignite/blob/664ceac5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIO.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIO.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIO.java
index 81feb51..4beef7d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIO.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIO.java
@@ -126,7 +126,7 @@ public class TrackingPageIO extends PageIO {
         if (last <= lastSuccessfulBackupId) { //we can drop our data
             PageUtils.putLong(buf, LAST_BACKUP_OFFSET, nextBackupId);
 
-            PageHandler.zeroMemory(buf, SIZE_FIELD_OFFSET, buf.capacity() - SIZE_FIELD_OFFSET);
+            PageHandler.zeroMemory(buf, SIZE_FIELD_OFFSET, pageSize - SIZE_FIELD_OFFSET);
         }
         else { //we can't drop data, it is still necessary for incremental backups
             int len = cntOfPage >> 3;

http://git-wip-us.apache.org/repos/asf/ignite/blob/664ceac5/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java
index df25449..39bb44b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/util/PageHandler.java
@@ -253,7 +253,7 @@ public abstract class PageHandler<X, R> {
 
         long pageId = page.id();
 
-        init.initNewPage(buf, pageId);
+        init.initNewPage(buf, pageId, page.size());
 
         // Here we should never write full page, because it is known to be new.
         page.fullPageWalRecordPolicy(FALSE);

http://git-wip-us.apache.org/repos/asf/ignite/blob/664ceac5/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java
index 97debf1..3e78b9c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java
@@ -32,6 +32,7 @@ import org.apache.ignite.internal.pagemem.Page;
 import org.apache.ignite.internal.pagemem.PageIdAllocator;
 import org.apache.ignite.internal.pagemem.PageIdUtils;
 import org.apache.ignite.internal.pagemem.PageMemory;
+import org.apache.ignite.internal.pagemem.PageUtils;
 import org.apache.ignite.internal.processors.cache.database.tree.io.PageIO;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
@@ -190,7 +191,7 @@ public class PageMemoryNoLoadSelfTest extends GridCommonAbstractTest {
             // Check that initial pages are accessible.
             for (FullPageId id : old) {
                 try (Page page = mem.page(id.cacheId(), id.pageId())) {
-                    ByteBuffer buf = page.getForWrite();
+                    long buf = page.getForWritePointer();
 
                     assertNotNull(buf);
 
@@ -231,7 +232,7 @@ public class PageMemoryNoLoadSelfTest extends GridCommonAbstractTest {
             // Check that updated pages are accessible using new IDs.
             for (FullPageId id : updated) {
                 try (Page page = mem.page(id.cacheId(), id.pageId())) {
-                    ByteBuffer buf = page.getForWrite();
+                    long buf = page.getForWritePointer();
 
                     assertNotNull(buf);
 
@@ -242,7 +243,7 @@ public class PageMemoryNoLoadSelfTest extends GridCommonAbstractTest {
                         page.releaseWrite(false);
                     }
 
-                    buf = page.getForRead();
+                    buf = page.getForReadPointer();
 
                     assertNotNull(buf);
 
@@ -282,13 +283,13 @@ public class PageMemoryNoLoadSelfTest extends GridCommonAbstractTest {
      * @param val Value to write.
      */
     private void writePage(Page page, int val) {
-        ByteBuffer bytes = page.getForWrite();
+        long bytes = page.getForWritePointer();
 
         try {
             PageIO.setPageId(bytes, page.id());
 
             for (int i = PageIO.COMMON_HEADER_END; i < PAGE_SIZE; i++)
-                bytes.put(i, (byte)val);
+                PageUtils.putByte(bytes, i, (byte)val);
         }
         finally {
             page.releaseWrite(true);

http://git-wip-us.apache.org/repos/asf/ignite/blob/664ceac5/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIOTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIOTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIOTest.java
index 1495cc0..f4b0cc9 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIOTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/database/tree/io/TrackingPageIOTest.java
@@ -8,6 +8,10 @@ import java.util.Set;
 import java.util.TreeSet;
 import java.util.concurrent.ThreadLocalRandom;
 import junit.framework.TestCase;
+import org.apache.ignite.internal.util.GridUnsafe;
+import sun.misc.JavaNioAccess;
+import sun.misc.SharedSecrets;
+import sun.nio.ch.DirectBuffer;
 
 /**
  *
@@ -16,14 +20,29 @@ public class TrackingPageIOTest extends TestCase {
     /** Page size. */
     public static final int PAGE_SIZE = 2048;
 
+    /** */
     private final TrackingPageIO io = TrackingPageIO.VERSIONS.latest();
 
+    /** */
+    private long buf;
+
+    @Override protected void setUp() throws Exception {
+        super.setUp();
+
+        buf = GridUnsafe.allocateMemory(PAGE_SIZE);
+    }
+
+    @Override protected void tearDown() throws Exception {
+        if (buf != 0L)
+            GridUnsafe.freeMemory(buf);
+
+        super.tearDown();
+    }
+
     /**
      *
      */
     public void testBasics() {
-        ByteBuffer buf = ByteBuffer.allocate(PAGE_SIZE);
-
         io.markChanged(buf, 2, 0, -1, PAGE_SIZE);
 
         assertTrue(io.wasChanged(buf, 2, 0, -1, PAGE_SIZE));
@@ -33,12 +52,18 @@ public class TrackingPageIOTest extends TestCase {
         assertFalse(io.wasChanged(buf, 2, 1,  0, PAGE_SIZE));
     }
 
+    private long allocate() {
+        return GridUnsafe.allocateMemory(PAGE_SIZE);
+    }
+
+    private void free(long addr) {
+        GridUnsafe.freeMemory(addr);
+    }
+
     /**
      *
      */
     public void testMarkingRandomly() {
-        ByteBuffer buf = ByteBuffer.allocate(PAGE_SIZE);
-
         int cntOfPageToTrack = io.countOfPageToTrack(PAGE_SIZE);
 
         for (int i = 0; i < 1001; i++)
@@ -49,8 +74,6 @@ public class TrackingPageIOTest extends TestCase {
      *
      */
     public void testZeroingRandomly() {
-        ByteBuffer buf = ByteBuffer.allocate(PAGE_SIZE);
-
         for (int i = 0; i < 1001; i++)
             checkMarkingRandomly(buf, i, true);
     }
@@ -59,7 +82,7 @@ public class TrackingPageIOTest extends TestCase {
      * @param buf Buffer.
      * @param backupId Backup id.
      */
-    private void checkMarkingRandomly(ByteBuffer buf, int backupId, boolean testZeroing) {
+    private void checkMarkingRandomly(long buf, int backupId, boolean testZeroing) {
         ThreadLocalRandom rand = ThreadLocalRandom.current();
 
         int track = io.countOfPageToTrack(PAGE_SIZE);
@@ -106,8 +129,6 @@ public class TrackingPageIOTest extends TestCase {
     }
 
     public void testFindNextChangedPage() throws Exception {
-        ByteBuffer buf = ByteBuffer.allocate(PAGE_SIZE);
-
         for (int i = 0; i < 101; i++)
             checkFindingRandomly(buf, i);
     }
@@ -116,7 +137,7 @@ public class TrackingPageIOTest extends TestCase {
      * @param buf Buffer.
      * @param backupId Backup id.
      */
-    private void checkFindingRandomly(ByteBuffer buf, int backupId) {
+    private void checkFindingRandomly(long buf, int backupId) {
         ThreadLocalRandom rand = ThreadLocalRandom.current();
 
         int track = io.countOfPageToTrack(PAGE_SIZE);
@@ -158,8 +179,6 @@ public class TrackingPageIOTest extends TestCase {
     }
 
     public void testMerging() {
-        ByteBuffer buf = ByteBuffer.allocate(PAGE_SIZE);
-
         ThreadLocalRandom rand = ThreadLocalRandom.current();
 
         int track = io.countOfPageToTrack(PAGE_SIZE);
@@ -193,8 +212,6 @@ public class TrackingPageIOTest extends TestCase {
     }
 
     public void testMerging_MarksShouldBeDropForSuccessfulBackup() {
-        ByteBuffer buf = ByteBuffer.allocate(PAGE_SIZE);
-
         ThreadLocalRandom rand = ThreadLocalRandom.current();
 
         int track = io.countOfPageToTrack(PAGE_SIZE);
@@ -226,7 +243,7 @@ public class TrackingPageIOTest extends TestCase {
     }
 
     private void generateMarking(
-        ByteBuffer buf,
+        long buf,
         int track,
         long basePageId,
         long maxPageId,

http://git-wip-us.apache.org/repos/asf/ignite/blob/664ceac5/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java
index cfc58b0..4996eef 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeReuseSelfTest.java
@@ -17,7 +17,6 @@
 
 package org.apache.ignite.internal.processors.database;
 
-import java.nio.ByteBuffer;
 import java.util.HashSet;
 import java.util.Set;
 import org.apache.ignite.IgniteCheckedException;
@@ -88,14 +87,14 @@ public class BPlusTreeReuseSelfTest extends BPlusTreeSelfTest {
         }
 
         /** {@inheritDoc} */
-        @Override public void onReadLock(Page page, ByteBuffer buf) {
+        @Override public void onReadLock(Page page, long buf) {
             checkPageId(page, buf);
 
             assertTrue(readLocks.get().add(page.id()));
         }
 
         /** {@inheritDoc} */
-        @Override public void onReadUnlock(Page page, ByteBuffer buf) {
+        @Override public void onReadUnlock(Page page, long buf) {
             checkPageId(page, buf);
 
             assertTrue(readLocks.get().remove(page.id()));
@@ -107,8 +106,8 @@ public class BPlusTreeReuseSelfTest extends BPlusTreeSelfTest {
         }
 
         /** {@inheritDoc} */
-        @Override public void onWriteLock(Page page, ByteBuffer buf) {
-            if (buf == null)
+        @Override public void onWriteLock(Page page, long buf) {
+            if (buf == 0L)
                 return; // Failed to lock.
 
             checkPageId(page, buf);
@@ -117,7 +116,7 @@ public class BPlusTreeReuseSelfTest extends BPlusTreeSelfTest {
         }
 
         /** {@inheritDoc} */
-        @Override public void onWriteUnlock(Page page, ByteBuffer buf) {
+        @Override public void onWriteUnlock(Page page, long buf) {
             assertEquals(effectivePageId(page.id()), effectivePageId(PageIO.getPageId(buf)));
 
             assertTrue(writeLocks.get().remove(page.id()));

http://git-wip-us.apache.org/repos/asf/ignite/blob/664ceac5/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
index 4bc39ea..b524b45 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
@@ -17,7 +17,6 @@
 
 package org.apache.ignite.internal.processors.database;
 
-import java.nio.ByteBuffer;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -38,6 +37,7 @@ import org.apache.ignite.internal.pagemem.FullPageId;
 import org.apache.ignite.internal.pagemem.Page;
 import org.apache.ignite.internal.pagemem.PageIdAllocator;
 import org.apache.ignite.internal.pagemem.PageMemory;
+import org.apache.ignite.internal.pagemem.PageUtils;
 import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl;
 import org.apache.ignite.internal.processors.cache.database.DataStructure;
 import org.apache.ignite.internal.processors.cache.database.tree.BPlusTree;
@@ -1134,7 +1134,7 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
      * @param page Page.
      * @param buf Buffer.
      */
-    public static void checkPageId(Page page, ByteBuffer buf) {
+    public static void checkPageId(Page page, long buf) {
         long pageId = PageIO.getPageId(buf);
 
         // Page ID must be 0L for newly allocated page, for reused page effective ID must remain the same.
@@ -1199,7 +1199,7 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Override protected int compare(BPlusIO<Long> io, ByteBuffer buf, int idx, Long n2)
+        @Override protected int compare(BPlusIO<Long> io, long buf, int idx, Long n2)
             throws IgniteCheckedException {
             Long n1 = io.getLookupRow(this, buf, idx);
 
@@ -1207,7 +1207,7 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Override protected Long getRow(BPlusIO<Long> io, ByteBuffer buf, int idx) throws IgniteCheckedException {
+        @Override protected Long getRow(BPlusIO<Long> io, long buf, int idx) throws IgniteCheckedException {
             assert io.canGetRow() : io;
 
             return io.getLookupRow(this, buf, idx);
@@ -1247,8 +1247,8 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Override public void onReadLock(Page page, ByteBuffer buf) {
-            if (buf != null) {
+        @Override public void onReadLock(Page page, long buf) {
+            if (buf != 0L) {
                 long pageId = PageIO.getPageId(buf);
 
                 checkPageId(page, buf);
@@ -1260,7 +1260,7 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Override public void onReadUnlock(Page page, ByteBuffer buf) {
+        @Override public void onReadUnlock(Page page, long buf) {
             checkPageId(page, buf);
 
             long pageId = PageIO.getPageId(buf);
@@ -1274,8 +1274,8 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Override public void onWriteLock(Page page, ByteBuffer buf) {
-            if (buf != null) {
+        @Override public void onWriteLock(Page page, long buf) {
+            if (buf != 0L) {
                 checkPageId(page, buf);
 
                 long pageId = PageIO.getPageId(buf);
@@ -1290,7 +1290,7 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Override public void onWriteUnlock(Page page, ByteBuffer buf) {
+        @Override public void onWriteUnlock(Page page, long buf) {
             assertEquals(effectivePageId(page.id()), effectivePageId(PageIO.getPageId(buf)));
 
             assertEquals(Long.valueOf(page.id()), locks(false).remove(page.id()));
@@ -1358,15 +1358,15 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Override public int getMaxCount(ByteBuffer buf) {
+        @Override public int getMaxCount(long buf, int pageSize) {
             if (MAX_PER_PAGE != 0)
                 return MAX_PER_PAGE;
 
-            return super.getMaxCount(buf);
+            return super.getMaxCount(buf, pageSize);
         }
 
         /** {@inheritDoc} */
-        @Override public void store(ByteBuffer dst, int dstIdx, BPlusIO<Long> srcIo, ByteBuffer src, int srcIdx)
+        @Override public void store(long dst, int dstIdx, BPlusIO<Long> srcIo, long src, int srcIdx)
             throws IgniteCheckedException {
             Long row = srcIo.getLookupRow(null, src, srcIdx);
 
@@ -1382,16 +1382,16 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Override public void storeByOffset(ByteBuffer buf, int off, Long row) {
+        @Override public void storeByOffset(long buf, int off, Long row) {
             checkNotRemoved(row);
 
-            buf.putLong(off, row);
+            PageUtils.putLong(buf, off, row);
         }
 
         /** {@inheritDoc} */
-        @Override public Long getLookupRow(BPlusTree<Long,?> tree, ByteBuffer buf, int idx)
+        @Override public Long getLookupRow(BPlusTree<Long,?> tree, long buf, int idx)
             throws IgniteCheckedException {
-            Long row = buf.getLong(offset(idx));
+            Long row = PageUtils.getLong(buf, offset(idx));
 
             checkNotRemoved(row);
 
@@ -1433,29 +1433,29 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
         }
 
         /** {@inheritDoc} */
-        @Override public int getMaxCount(ByteBuffer buf) {
+        @Override public int getMaxCount(long buf, int pageSize) {
             if (MAX_PER_PAGE != 0)
                 return MAX_PER_PAGE;
 
-            return super.getMaxCount(buf);
+            return super.getMaxCount(buf, pageSize);
         }
 
         /** {@inheritDoc} */
-        @Override public void storeByOffset(ByteBuffer buf, int off, Long row) {
-            buf.putLong(off, row);
+        @Override public void storeByOffset(long buf, int off, Long row) {
+            PageUtils.putLong(buf, off, row);
         }
 
         /** {@inheritDoc} */
-        @Override public void store(ByteBuffer dst, int dstIdx, BPlusIO<Long> srcIo, ByteBuffer src, int srcIdx) {
+        @Override public void store(long dst, int dstIdx, BPlusIO<Long> srcIo, long src, int srcIdx) {
             assert srcIo == this;
 
-            dst.putLong(offset(dstIdx), src.getLong(offset(srcIdx)));
+            PageUtils.putLong(dst, offset(dstIdx), PageUtils.getLong(src, offset(srcIdx)));
         }
 
         /** {@inheritDoc} */
-        @Override public Long getLookupRow(BPlusTree<Long,?> tree, ByteBuffer buf, int idx)
+        @Override public Long getLookupRow(BPlusTree<Long,?> tree, long buf, int idx)
             throws IgniteCheckedException {
-            return buf.getLong(offset(idx));
+            return PageUtils.getLong(buf, offset(idx));
         }
     }
 }


Mime
View raw message