ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [10/25] ignite git commit: ignite-gg-11810
Date Wed, 11 Jan 2017 13:22:44 GMT
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/6afd2e79
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6afd2e79
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6afd2e79

Branch: refs/heads/ignite-gg-11810
Commit: 6afd2e795b409f20218991253ccd068a44409902
Parents: 80bf580
Author: sboikov <sboikov@gridgain.com>
Authored: Fri Dec 23 17:06:25 2016 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Fri Dec 23 17:06:25 2016 +0300

----------------------------------------------------------------------
 .../cache/database/tree/io/DataPageIO.java      |  41 +++++-
 .../database/FreeListImplSelfTest.java          | 127 ++++++++++++-------
 2 files changed, 116 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6afd2e79/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 fcb7fb9..0aaa2a4 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
@@ -23,6 +23,7 @@ import java.util.Collection;
 import java.util.HashSet;
 import org.apache.ignite.IgniteCheckedException;
 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.CacheObject;
 import org.apache.ignite.internal.processors.cache.database.CacheDataRow;
@@ -148,7 +149,9 @@ public class DataPageIO extends PageIO {
      * @return Data page entry size.
      */
     private int getPageEntrySize(int payloadLen, int show) {
-        assert payloadLen > 0: payloadLen;
+        if (payloadLen == 0)
+            System.out.println();
+        assert payloadLen > 0 : payloadLen;
 
         int res = payloadLen;
 
@@ -400,6 +403,7 @@ 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 Data entry offset in bytes.
      */
     private int getDataOffset(long buf, int itemId, int pageSize) {
@@ -711,11 +715,13 @@ public class DataPageIO extends PageIO {
      * @throws IgniteCheckedException If failed.
      */
     public void addRow(
-        long buf,
+        final long buf,
         CacheDataRow row,
-        int rowSize,
-        int pageSize
+        final int rowSize,
+        final int pageSize
     ) throws IgniteCheckedException {
+        System.out.println("Start add row " + buf + " " + printPageLayout(buf, pageSize));
+
         assert rowSize <= getFreeSpace(buf): "can't call addRow if not enough space for
the whole row";
 
         int fullEntrySize = getPageEntrySize(rowSize, SHOW_PAYLOAD_LEN | SHOW_ITEM);
@@ -730,6 +736,8 @@ public class DataPageIO extends PageIO {
         int itemId = addItem(buf, fullEntrySize, directCnt, indirectCnt, dataOff, pageSize);
 
         setLink(row, buf, itemId);
+
+        System.out.println("Add row " + buf + " " + printPageLayout(buf, pageSize));
     }
 
     /**
@@ -845,6 +853,7 @@ public class DataPageIO extends PageIO {
      * @param row Cache data row.
      * @param written Number of bytes of row size that was already written.
      * @param rowSize Row size.
+     * @param pageSize Page size.
      * @return Written payload size.
      * @throws IgniteCheckedException If failed.
      */
@@ -864,6 +873,7 @@ public class DataPageIO extends PageIO {
      * @param buf Byte buffer.
      * @param payload Payload bytes.
      * @param lastLink Link to the previous written fragment (link to the tail).
+     * @param pageSize Page size.
      * @throws IgniteCheckedException If failed.
      */
     public void addRowFragment(
@@ -887,6 +897,7 @@ public class DataPageIO extends PageIO {
      * @param lastLink Link to the previous written fragment (link to the tail).
      * @param row Row.
      * @param payload Payload bytes.
+     * @param pageSize Page size.
      * @return Written payload size.
      * @throws IgniteCheckedException If failed.
      */
@@ -912,24 +923,40 @@ public class DataPageIO extends PageIO {
 
         if (payload == null) {
             ByteBuffer buf0 = nioAccess.newDirectByteBuffer(buf, pageSize, null);
+            buf0.order(PageMemory.NATIVE_BYTE_ORDER);
 
             buf0.position(dataOff);
 
-            buf0.putShort((short)(payloadSize | FRAGMENTED_FLAG));
+            short p = (short)(payloadSize | FRAGMENTED_FLAG);
+
+            System.out.println("Start add row fragment " + buf + " " + dataOff + " " + payloadSize
+ " " + p);
+
+            buf0.putShort(p);
             buf0.putLong(lastLink);
 
             int rowOff = rowSize - written - payloadSize;
 
+            System.out.println("Size1: " + PageUtils.getShort(buf, dataOff));
+
             writeFragmentData(row, buf0, rowOff, payloadSize);
+
+            System.out.println("Size2: " + PageUtils.getShort(buf, dataOff));
+        }
+        else {
+            PageUtils.putShort(buf, dataOff, (short)(payloadSize | FRAGMENTED_FLAG));
+
+            PageUtils.putLong(buf, dataOff + 2, lastLink);
+
+            PageUtils.putBytes(buf, dataOff + 10, payload);
         }
-        else
-            PageUtils.putBytes(buf, dataOff, payload);
 
         int itemId = addItem(buf, fullEntrySize, directCnt, indirectCnt, dataOff, pageSize);
 
         if (row != null)
             setLink(row, buf, itemId);
 
+        System.out.println("Add fragment " + buf + " " + printPageLayout(buf, pageSize));
+
         return payloadSize;
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/6afd2e79/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java
index 2b93d48..fd3e0f5 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/database/FreeListImplSelfTest.java
@@ -237,13 +237,17 @@ public class FreeListImplSelfTest extends GridCommonAbstractTest {
     protected void checkInsertDeleteSingleThreaded(int pageSize) throws Exception {
         FreeList list = createFreeList(pageSize);
 
-        Random rnd = new Random();
+        long seed = 1482500591478L;//System.currentTimeMillis();
+
+        Random rnd = new Random(seed);
+
+        System.out.println("Seed " + seed);
 
         Map<Long, TestDataRow> stored = new HashMap<>();
 
-        for (int i = 0; i < 100; i++) {
-            int keySize = rnd.nextInt(pageSize * 3 / 2) + 10;
-            int valSize = rnd.nextInt(pageSize * 5 / 2) + 10;
+        {
+            int keySize = 749;
+            int valSize = 2426;
 
             TestDataRow row = new TestDataRow(keySize, valSize);
 
@@ -255,55 +259,88 @@ public class FreeListImplSelfTest extends GridCommonAbstractTest {
 
             assertNull(old);
         }
+        {
+            int keySize = 472;
+            int valSize = 83;
 
-        boolean grow = true;
-
-        for (int i = 0; i < 1_000_000; i++) {
-            if (grow) {
-                if (stored.size() > 20_000) {
-                    grow = false;
-
-                    info("Shrink... [" + stored.size() + ']');
-                }
-            }
-            else {
-                if (stored.size() < 1_000) {
-                    grow = true;
-
-                    info("Grow... [" + stored.size() + ']');
-                }
-            }
-
-            boolean insert = rnd.nextInt(100) < 70 == grow;
-
-            if (insert) {
-                int keySize = rnd.nextInt(pageSize * 3 / 2) + 10;
-                int valSize = rnd.nextInt(pageSize * 3 / 2) + 10;
-
-                TestDataRow row = new TestDataRow(keySize, valSize);
-
-                list.insertDataRow(row);
+            TestDataRow row = new TestDataRow(keySize, valSize);
 
-                assertTrue(row.link() != 0L);
+            list.insertDataRow(row);
 
-                TestDataRow old = stored.put(row.link(), row);
+            assertTrue(row.link() != 0L);
 
-                assertNull(old);
-            }
-            else {
-                Iterator<TestDataRow> it = stored.values().iterator();
+            TestDataRow old = stored.put(row.link(), row);
 
-                if (it.hasNext()) {
-                    TestDataRow row = it.next();
+            assertNull(old);
+        }
 
-                    TestDataRow rmvd = stored.remove(row.link);
 
-                    assertTrue(rmvd == row);
 
-                    list.removeDataRowByLink(row.link);
-                }
-            }
-        }
+//        for (int i = 0; i < 100; i++) {
+//            int keySize = rnd.nextInt(pageSize * 3 / 2) + 10;
+//            int valSize = rnd.nextInt(pageSize * 5 / 2) + 10;
+//
+//            System.out.println("Add " + keySize + " " + valSize);
+//
+//            TestDataRow row = new TestDataRow(keySize, valSize);
+//
+//            list.insertDataRow(row);
+//
+//            assertTrue(row.link() != 0L);
+//
+//            TestDataRow old = stored.put(row.link(), row);
+//
+//            assertNull(old);
+//        }
+
+//        boolean grow = true;
+//
+//        for (int i = 0; i < 1_000_000; i++) {
+//            if (grow) {
+//                if (stored.size() > 20_000) {
+//                    grow = false;
+//
+//                    info("Shrink... [" + stored.size() + ']');
+//                }
+//            }
+//            else {
+//                if (stored.size() < 1_000) {
+//                    grow = true;
+//
+//                    info("Grow... [" + stored.size() + ']');
+//                }
+//            }
+//
+//            boolean insert = rnd.nextInt(100) < 70 == grow;
+//
+//            if (insert) {
+//                int keySize = rnd.nextInt(pageSize * 3 / 2) + 10;
+//                int valSize = rnd.nextInt(pageSize * 3 / 2) + 10;
+//
+//                TestDataRow row = new TestDataRow(keySize, valSize);
+//
+//                list.insertDataRow(row);
+//
+//                assertTrue(row.link() != 0L);
+//
+//                TestDataRow old = stored.put(row.link(), row);
+//
+//                assertNull(old);
+//            }
+//            else {
+//                Iterator<TestDataRow> it = stored.values().iterator();
+//
+//                if (it.hasNext()) {
+//                    TestDataRow row = it.next();
+//
+//                    TestDataRow rmvd = stored.remove(row.link);
+//
+//                    assertTrue(rmvd == row);
+//
+//                    list.removeDataRowByLink(row.link);
+//                }
+//            }
+//        }
     }
 
     /**


Mime
View raw message