ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [13/15] ignite git commit: tmp
Date Fri, 10 Feb 2017 12:37:28 GMT
tmp


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

Branch: refs/heads/ignite-3477-compact2
Commit: ad7055266cd4b2941b502770680b007813e9d578
Parents: 6445351
Author: sboikov <sboikov@gridgain.com>
Authored: Fri Feb 10 14:19:42 2017 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Fri Feb 10 14:19:42 2017 +0300

----------------------------------------------------------------------
 .../apache/ignite/internal/IgniteKernal.java    |   5 +
 .../cache/database/tree/io/DataPageIO.java      | 176 +++++++++++++++++--
 2 files changed, 166 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ad705526/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index bc111e6..28a11d4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -107,6 +107,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheUtilityKey;
 import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
 import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
 import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO;
 import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
 import org.apache.ignite.internal.processors.clock.GridClockSyncProcessor;
 import org.apache.ignite.internal.processors.closure.GridClosureProcessor;
@@ -1139,10 +1140,14 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable
{
 
                             String id = U.id8(localNode().id());
 
+                            double cnt = DataPageIO.cnt.sumThenReset();
+                            double found = DataPageIO.foundCnt.sumThenReset();
+
                             String msg = NL +
                                 "Metrics for local node (to disable set 'metricsLogFrequency'
to 0)" + NL +
                                 "    ^-- Node [id=" + id + ", name=" + name() + ", uptime="
+ getUpTimeFormatted() + "]" + NL +
                                 "    ^-- H/N/C [hosts=" + hosts + ", nodes=" + nodes + ",
CPUs=" + cpus + "]" + NL +
+                                "    ^-- cnt=" + cnt + ", precent=" + found / cnt * 100 +
NL +
                                 "    ^-- CPU [cur=" + dblFmt.format(cpuLoadPct) + "%, avg="
+
                                 dblFmt.format(avgCpuLoadPct) + "%, GC=" + dblFmt.format(gcPct)
+ "%]" + NL +
                                 "    ^-- PageMemory [pages=" + (pageMem != null ? pageMem.loadedPages()
: 0) + "]" + NL +

http://git-wip-us.apache.org/repos/asf/ignite/blob/ad705526/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 ec2a2e1..4a57b77 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,8 +29,10 @@ import org.apache.ignite.internal.processors.cache.CacheObject;
 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.GridUnsafe;
 import org.apache.ignite.internal.util.typedef.internal.SB;
 import org.jetbrains.annotations.Nullable;
+import org.jsr166.LongAdder8;
 
 /**
  * Data pages IO.
@@ -63,7 +65,19 @@ public class DataPageIO extends PageIO {
     private static final int INDIRECT_CNT_OFF = DIRECT_CNT_OFF + 1;
 
     /** */
-    private static final int FIRST_ENTRY_OFF = INDIRECT_CNT_OFF + 1;
+    private static final int REMOVED_CNT_OFF = INDIRECT_CNT_OFF + 1;
+
+    /** */
+    private static final int REMOVED_ITEMS_OFF = REMOVED_CNT_OFF + 1;
+
+    /** */
+    private static final int MAX_REMOVED_CNT = 8;
+
+    /** */
+    private static final int REMOVED_ITEM_SIZE = 4;
+
+    /** */
+    private static final int FIRST_ENTRY_OFF = REMOVED_ITEMS_OFF + MAX_REMOVED_CNT * REMOVED_ITEM_SIZE;
 
     /** */
     private static final int ITEMS_OFF = FIRST_ENTRY_OFF + 2;
@@ -107,6 +121,12 @@ public class DataPageIO extends PageIO {
         setIndirectCount(pageAddr, 0);
         setFirstEntryOffset(pageAddr, pageSize, pageSize);
         setRealFreeSpace(pageAddr, pageSize - ITEMS_OFF, pageSize);
+
+        clearRemoved(pageAddr);
+    }
+
+    private void clearRemoved(long pageAddr) {
+        GridUnsafe.setMemory(pageAddr + REMOVED_CNT_OFF, MAX_REMOVED_CNT * REMOVED_ITEM_SIZE
+ 1, (byte)0);
     }
 
     /**
@@ -253,6 +273,24 @@ public class DataPageIO extends PageIO {
         return PageUtils.getByte(pageAddr, DIRECT_CNT_OFF) & 0xFF;
     }
 
+    private void setRemovedCount(long pageAddr, int cnt) {
+        assert cnt >= 0 && cnt <= MAX_REMOVED_CNT : cnt;
+
+        PageUtils.putByte(pageAddr, REMOVED_CNT_OFF, (byte)cnt);
+    }
+
+    /**
+     * @param pageAddr Page address.
+     * @return Direct count.
+     */
+    private int getRemovedCount(long pageAddr) {
+        int cnt = PageUtils.getByte(pageAddr, REMOVED_CNT_OFF) & 0xFF;
+
+        assert cnt >= 0 && cnt <= MAX_REMOVED_CNT : cnt;
+
+        return cnt;
+    }
+
     /**
      * @param pageAddr Page address.
      * @param cnt Indirect count.
@@ -666,6 +704,20 @@ public class DataPageIO extends PageIO {
             // Get the entry size before the actual remove.
             int rmvEntrySize = getPageEntrySize(pageAddr, dataOff, SHOW_PAYLOAD_LEN | SHOW_LINK);
 
+            if (false && getFirstEntryOffset(pageAddr) == dataOff)
+                setFirstEntryOffset(pageAddr, getFirstEntryOffset(pageAddr) + rmvEntrySize,
pageSize);
+            else {
+                int rmvdCnt = getRemovedCount(pageAddr);
+
+                if (rmvdCnt < MAX_REMOVED_CNT) {
+                    int item = dataOff << 16 | (rmvEntrySize & 0xFFFF);
+
+                    PageUtils.putInt(pageAddr, REMOVED_ITEMS_OFF + rmvdCnt * REMOVED_ITEM_SIZE,
item);
+
+                    setRemovedCount(pageAddr, rmvdCnt + 1);
+                }
+            }
+
             int indirectId = 0;
 
             if (itemId >= directCnt) { // Need to remove indirect item.
@@ -1205,6 +1257,20 @@ public class DataPageIO extends PageIO {
         return directCnt; // Previous directCnt will be our itemId.
     }
 
+    private boolean canAddItem(long pageAddr, int directCnt, int indirectCnt, int firstEntryOff)
{
+        if (indirectCnt > 0) {
+            short item = getItemByOffset(pageAddr, ITEMS_OFF + directCnt * ITEM_SIZE);
+
+            if (itemId(item) == directCnt)
+                return true;
+        }
+
+        return firstEntryOff > (directCnt + indirectCnt) * ITEM_SIZE + ITEMS_OFF + ITEM_SIZE;
+    }
+
+    public final static LongAdder8 cnt = new LongAdder8();
+    public final static LongAdder8 foundCnt = new LongAdder8();
+
     /**
      * @param pageAddr Page address.
      * @param directCnt Direct items count.
@@ -1217,8 +1283,83 @@ public class DataPageIO extends PageIO {
         int pageSize,
         int newEntrySize,
         CacheDataRow row) throws IgniteCheckedException {
+        //cnt.increment();
+
         assert checkCount(directCnt): directCnt;
 
+        int rmvdCnt = getRemovedCount(pageAddr);
+
+        Boolean canAddItem = null;
+
+        if (rmvdCnt > 0 && row != null) {
+            canAddItem = canAddItem(pageAddr, directCnt, indirectCnt, getFirstEntryOffset(pageAddr));
+
+            if (canAddItem) {
+                int cnt = 0;
+
+                int rmvdItemOff = REMOVED_ITEMS_OFF;
+
+                for (int i = 0; i < MAX_REMOVED_CNT; i++) {
+                    int rmvdItem = PageUtils.getInt(pageAddr, rmvdItemOff);
+
+                    if (rmvdItem != 0) {
+                        int size = rmvdItem & 0xFFFF;
+
+                        assert size >= 0 && size < pageSize : size;
+
+                        if (size >= newEntrySize) {
+                            // foundCnt.increment();
+
+                            int newEntryOff = rmvdItem >>> 16;
+
+                            try {
+                                assert newEntryOff > ITEMS_OFF && newEntryOff
< pageSize /*&& newEntryOff != getFirstEntryOffset(pageAddr)*/ :
+                                    "new=" + newEntryOff +
+                                    ", first=" + getFirstEntryOffset(pageAddr) +
+                                    ", size=" + size +
+                                    ", newSize=" + newEntrySize +
+                                    ", free=" + actualFreeSpace(pageAddr, pageSize) +
+                                    ", page=" + printPageLayout(pageAddr, pageSize);
+
+                                writeRowData(pageAddr, newEntryOff, newEntrySize - ITEM_SIZE
- PAYLOAD_LEN_SIZE, row, true);
+
+                                int itemId = insertItem(pageAddr, newEntryOff, directCnt,
indirectCnt, pageSize);
+
+                                assert checkIndex(itemId) : itemId;
+                                assert getIndirectCount(pageAddr) <= getDirectCount(pageAddr);
+
+                                // Update free space. If number of indirect items changed,
then we were able to reuse an item slot.
+                                setRealFreeSpace(pageAddr,
+                                    getRealFreeSpace(pageAddr) - newEntrySize + (getIndirectCount(pageAddr)
!= indirectCnt ? ITEM_SIZE : 0),
+                                    pageSize);
+
+                                setLink(row, pageAddr, itemId);
+
+                                PageUtils.putInt(pageAddr, rmvdItemOff, 0);
+                                setRemovedCount(pageAddr, rmvdCnt - 1);
+                            }
+                            catch (AssertionError e) {
+                                e.printStackTrace(System.out);
+
+                                System.out.println();
+
+                                throw e;
+                            }
+
+                            return 0;
+                        }
+
+                        if (++cnt == rmvdCnt)
+                            break;
+                    }
+
+                    rmvdItemOff += REMOVED_ITEM_SIZE;
+                }
+            }
+
+            row = null;
+        }
+
         int[] offs = new int[directCnt];
 
         int itemOff = ITEMS_OFF;
@@ -1234,19 +1375,21 @@ public class DataPageIO extends PageIO {
         Arrays.sort(offs);
 
         if (row != null) {
-            boolean canAddItem = false;
-
-            if (indirectCnt > 0) {
-                short item = getItemByOffset(pageAddr, itemOff);
-
-                if (itemId(item) == directCnt)
-                    canAddItem = true;
-            }
-
-            if (!canAddItem) {
-                int firstOff = offs[0] >>> 8;
-                canAddItem = firstOff > (directCnt + indirectCnt) * ITEM_SIZE + ITEMS_OFF
+ ITEM_SIZE;
-            }
+            if (canAddItem == null)
+                canAddItem = canAddItem(pageAddr, directCnt, indirectCnt, getFirstEntryOffset(pageAddr));
+//            boolean canAddItem = false;
+//
+//            if (indirectCnt > 0) {
+//                short item = getItemByOffset(pageAddr, itemOff);
+//
+//                if (itemId(item) == directCnt)
+//                    canAddItem = true;
+//            }
+//
+//            if (!canAddItem) {
+//                int firstOff = offs[0] >>> 8;
+//                canAddItem = firstOff > (directCnt + indirectCnt) * ITEM_SIZE + ITEMS_OFF
+ ITEM_SIZE;
+//            }
 
             if (!canAddItem)
                 row = null;
@@ -1309,7 +1452,7 @@ public class DataPageIO extends PageIO {
             if (delta != 0) { // Move right.
                 assert delta > 0 : delta;
 
-                if (row != null && delta >= newEntrySize) {
+                if (false && row != null && delta >= newEntrySize) {
                     int newEntryOff = curOff + curEntrySize;
 
                     writeRowData(pageAddr, newEntryOff, newEntrySize - ITEM_SIZE - PAYLOAD_LEN_SIZE,
row, true);
@@ -1366,6 +1509,9 @@ public class DataPageIO extends PageIO {
             prevOff = off;
         }
 
+        if (rmvdCnt > 0)
+            clearRemoved(pageAddr);
+
         return prevOff;
     }
 


Mime
View raw message