ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject ignite git commit: BPlusTree: do not init old value when it is not used.
Date Thu, 19 Jan 2017 16:16:50 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-3477 f6011a5cf -> d85439582


BPlusTree: do not init old value when it is not used.


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

Branch: refs/heads/ignite-3477
Commit: d854395829f145c4fb4ca0cd30db7a3314bc58cb
Parents: f6011a5
Author: sboikov <sboikov@gridgain.com>
Authored: Thu Jan 19 19:16:51 2017 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Thu Jan 19 19:16:51 2017 +0300

----------------------------------------------------------------------
 .../cache/IgniteCacheOffheapManagerImpl.java    | 42 ++++++----
 .../cache/database/tree/BPlusTree.java          | 88 +++++++++++---------
 .../query/h2/database/H2TreeIndex.java          | 21 ++++-
 .../query/h2/opt/GridH2IndexBase.java           | 21 ++++-
 .../processors/query/h2/opt/GridH2Table.java    |  2 +-
 5 files changed, 115 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d8543958/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java
index 63a5072..aab5a75 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java
@@ -920,13 +920,13 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter
imple
                     assert old.link() != 0 : old;
 
                     if (pendingEntries != null && old.expireTime() != 0)
-                        pendingEntries.remove(new PendingRow(old.expireTime(), old.link()));
+                        pendingEntries.removex(new PendingRow(old.expireTime(), old.link()));
 
                     rowStore.removeRow(old.link());
                 }
 
                 if (pendingEntries != null && expireTime != 0)
-                    pendingEntries.put(new PendingRow(expireTime, dataRow.link()));
+                    pendingEntries.putx(new PendingRow(expireTime, dataRow.link()));
 
                 updateIgfsMetrics(key, (old != null ? old.value() : null), val);
             }
@@ -950,7 +950,7 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter
imple
                     assert dataRow.link() != 0 : dataRow;
 
                     if (pendingEntries != null && dataRow.expireTime() != 0)
-                        pendingEntries.remove(new PendingRow(dataRow.expireTime(), dataRow.link()));
+                        pendingEntries.removex(new PendingRow(dataRow.expireTime(), dataRow.link()));
 
                     storageSize.decrementAndGet();
 
@@ -1242,6 +1242,15 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter
imple
             return compareKeys(row.key(), link);
         }
 
+        /** {@inheritDoc} */
+        @Override protected CacheDataRow getRow(BPlusIO<CacheSearchRow> io, long pageAddr,
int idx)
+            throws IgniteCheckedException {
+            int hash = ((RowLinkIO)io).getHash(pageAddr, idx);
+            long link = ((RowLinkIO)io).getLink(pageAddr, idx);
+
+            return rowStore.dataRow(hash, link);
+        }
+
         /**
          * @param key Key.
          * @param link Link.
@@ -1270,11 +1279,14 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter
imple
 
                         int len = PageUtils.getInt(addr, 0);
 
-                        int size = Math.min(bytes.length, len);
+                        int lenCmp = Integer.compare(len, bytes.length);
+
+                        if (lenCmp != 0)
+                            return lenCmp;
 
                         addr += 5; // Skip length and type byte.
 
-                        for (int i = 0; i < size; i++) {
+                        for (int i = 0; i < len; i++) {
                             byte b1 = PageUtils.getByte(addr, i);
                             byte b2 = bytes[i];
 
@@ -1282,7 +1294,7 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter
imple
                                 return b1 > b2 ? 1 : -1;
                         }
 
-                        return Integer.compare(len, bytes.length);
+                        return 0;
                     }
                 }
                 finally {
@@ -1297,9 +1309,12 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter
imple
             byte[] bytes1 = other.key().valueBytes(cctx.cacheObjectContext());
             byte[] bytes2 = key.valueBytes(cctx.cacheObjectContext());
 
-            int len = Math.min(bytes1.length, bytes2.length);
+            int lenCmp = Integer.compare(bytes1.length, bytes2.length);
 
-            for (int i = 0; i < len; i++) {
+            if (lenCmp != 0)
+                return lenCmp;
+
+            for (int i = 0; i < bytes1.length; i++) {
                 byte b1 = bytes1[i];
                 byte b2 = bytes2[i];
 
@@ -1307,16 +1322,7 @@ public class IgniteCacheOffheapManagerImpl extends GridCacheManagerAdapter
imple
                     return b1 > b2 ? 1 : -1;
             }
 
-            return Integer.compare(bytes1.length, bytes2.length);
-        }
-
-        /** {@inheritDoc} */
-        @Override protected CacheDataRow getRow(BPlusIO<CacheSearchRow> io, long pageAddr,
int idx)
-            throws IgniteCheckedException {
-            int hash = ((RowLinkIO)io).getHash(pageAddr, idx);
-            long link = ((RowLinkIO)io).getLink(pageAddr, idx);
-
-            return rowStore.dataRow(hash, link);
+            return 0;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/d8543958/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java
index e4afc13..ff4be4b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/tree/BPlusTree.java
@@ -322,7 +322,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
                 assert p.oldRow == null;
 
                 // Get old row in leaf page to reduce contention at upper level.
-                p.oldRow = getRow(io, pageAddr, idx);
+                p.oldRow = p.needOld ? getRow(io, pageAddr, idx) : (T)Boolean.TRUE;
 
                 p.finish();
 
@@ -1292,13 +1292,12 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
 
     /**
      * @param row Lookup row.
-     * @param bag Reuse bag.
      * @return Removed row.
      * @throws IgniteCheckedException If failed.
      */
     @SuppressWarnings("unused")
-    public final T removeCeil(L row, ReuseBag bag) throws IgniteCheckedException {
-        return doRemove(row, true, bag);
+    public final T removeCeil(L row) throws IgniteCheckedException {
+        return doRemove(row, true, true);
     }
 
     /**
@@ -1307,20 +1306,31 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
      * @throws IgniteCheckedException If failed.
      */
     @Override public final T remove(L row) throws IgniteCheckedException {
-        return doRemove(row, false, null);
+        return doRemove(row, false, true);
+    }
+
+    /**
+     * @param row Lookup row.
+     * @throws IgniteCheckedException If failed.
+     * @return {@code True} if removed row.
+     */
+    public final boolean removex(L row) throws IgniteCheckedException {
+        Boolean res = (Boolean)doRemove(row, false, false);
+
+        return res != null ? res : false;
     }
 
     /**
      * @param row Lookup row.
      * @param ceil If we can remove ceil row when we can not find exact.
-     * @param bag Reuse bag.
+     * @param needOld {@code True} if need return removed row.
      * @return Removed row.
      * @throws IgniteCheckedException If failed.
      */
-    private T doRemove(L row, boolean ceil, ReuseBag bag) throws IgniteCheckedException {
+    private T doRemove(L row, boolean ceil, boolean needOld) throws IgniteCheckedException
{
         checkDestroyed();
 
-        Remove r = new Remove(row, ceil, bag);
+        Remove r = new Remove(row, ceil, needOld);
 
         try {
             for (;;) {
@@ -1355,7 +1365,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
 
                         assert r.isFinished();
 
-                        return r.removed;
+                        return r.rmvd;
                 }
             }
         }
@@ -1564,19 +1574,30 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
      * {@inheritDoc}
      */
     @Override public final T put(T row) throws IgniteCheckedException {
-        return put(row, null);
+        return put(row, true);
+    }
+
+    /**
+     * @param row New value.
+     * @throws IgniteCheckedException If failed.
+     * @return {@code True} if replaced existing row.
+     */
+    public boolean putx(T row) throws IgniteCheckedException {
+        Boolean res = (Boolean)put(row, false);
+
+        return res != null ? res : false;
     }
 
     /**
-     * @param row Row.
-     * @param bag Reuse bag.
+     * @param row New value.
+     * @param needOld {@code True} If need return old value.
      * @return Old row.
      * @throws IgniteCheckedException If failed.
      */
-    public final T put(T row, ReuseBag bag) throws IgniteCheckedException {
+    private T put(T row, boolean needOld) throws IgniteCheckedException {
         checkDestroyed();
 
-        Put p = new Put(row, bag);
+        Put p = new Put(row, needOld);
 
         try {
             for (;;) { // Go down with retries.
@@ -2116,16 +2137,16 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
         Bool needReplaceInner = FALSE;
 
         /** */
-        private ReuseBag bag;
+        private final boolean needOld;
 
         /**
          * @param row Row.
-         * @param bag Reuse bag.
+         * @param needOld {@code True} If need return old value.
          */
-        private Put(T row, ReuseBag bag) {
+        private Put(T row, boolean needOld) {
             super(row);
 
-            this.bag = bag;
+            this.needOld = needOld;
         }
 
         /** {@inheritDoc} */
@@ -2234,7 +2255,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
          */
         private L insertWithSplit(Page page, BPlusIO<L> io, final long pageAddr, int
idx, int lvl)
             throws IgniteCheckedException {
-            long fwdId = allocatePage(bag);
+            long fwdId = allocatePage(null);
 
             try (Page fwd = page(fwdId)) {
                 // Need to check this before the actual split, because after the split we
will have new forward page here.
@@ -2281,7 +2302,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
                     }
 
                     if (!hadFwd && lvl == getRootLevel()) { // We are splitting root.
-                        long newRootId = allocatePage(bag);
+                        long newRootId = allocatePage(null);
 
                         try (Page newRoot = page(newRootId)) {
                             if (io.isLeaf())
@@ -2350,7 +2371,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
         Bool needMergeEmptyBranch = FALSE;
 
         /** Removed row. */
-        private T removed;
+        private T rmvd;
 
         /** Current page. */
         private Page page;
@@ -2359,31 +2380,23 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
         private Object freePages;
 
         /** */
-        private ReuseBag bag;
+        private final boolean needOld;
 
         /**
          * @param row Row.
          * @param ceil If we can remove ceil row when we can not find exact.
+         * @param needOld {@code True} If need return old value.
          */
-        private Remove(L row, boolean ceil, ReuseBag bag) {
+        private Remove(L row, boolean ceil, boolean needOld) {
             super(row);
 
             this.ceil = ceil;
-            this.bag = bag;
-        }
-
-        /**
-         * @return Reuse bag.
-         */
-        private ReuseBag bag() {
-            return bag != null ? bag : this;
+            this.needOld = needOld;
         }
 
         /** {@inheritDoc} */
         @SuppressWarnings("unchecked")
         @Override public long pollFreePage() {
-            assert bag == null;
-
             if (freePages == null)
                 return 0;
 
@@ -2404,7 +2417,6 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
         @SuppressWarnings("unchecked")
         @Override public void addFreePage(long pageId) {
             assert pageId != 0;
-            assert bag == null; // Otherwise we have to add the given pageId to that bag.
 
             if (freePages == null)
                 freePages = pageId;
@@ -2523,7 +2535,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
          * @return {@code true} If already removed from leaf.
          */
         private boolean isRemoved() {
-            return removed != null;
+            return rmvd != null;
         }
 
         /**
@@ -2799,7 +2811,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
             assert !isRemoved(): "already removed";
 
             // Detach the row.
-            removed = getRow(io, pageAddr, idx);
+            rmvd = needOld ? getRow(io, pageAddr, idx) : (T)Boolean.TRUE;
 
             doRemove(page, io, pageAddr, cnt, idx);
 
@@ -3000,7 +3012,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
             if (release)
                 writeUnlockAndClose(page, pageAddr);
 
-            bag().addFreePage(pageId);
+            addFreePage(pageId);
         }
 
         /**
@@ -3021,7 +3033,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
         @SuppressWarnings("unchecked")
         private void reuseFreePages() throws IgniteCheckedException {
             // If we have a bag, then it will be processed at the upper level.
-            if (reuseList != null && bag == null && freePages != null)
+            if (reuseList != null && freePages != null)
                 reuseList.addForRecycle(this);
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/d8543958/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java
index 6cabd77..33379b0 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/database/H2TreeIndex.java
@@ -136,7 +136,6 @@ public class H2TreeIndex extends GridH2IndexBase {
     }
 
     /** {@inheritDoc} */
-    @SuppressWarnings("StatementWithEmptyBody")
     @Override public GridH2Row put(GridH2Row row) {
         try {
             return tree.put(row);
@@ -147,6 +146,16 @@ public class H2TreeIndex extends GridH2IndexBase {
     }
 
     /** {@inheritDoc} */
+    @Override public boolean putx(GridH2Row row) {
+        try {
+            return tree.putx(row);
+        }
+        catch (IgniteCheckedException e) {
+            throw DbException.convert(e);
+        }
+    }
+
+    /** {@inheritDoc} */
     @Override public GridH2Row remove(SearchRow row) {
         try {
             return tree.remove(row);
@@ -157,6 +166,16 @@ public class H2TreeIndex extends GridH2IndexBase {
     }
 
     /** {@inheritDoc} */
+    @Override public void removex(SearchRow row) {
+        try {
+            tree.removex(row);
+        }
+        catch (IgniteCheckedException e) {
+            throw DbException.convert(e);
+        }
+    }
+
+    /** {@inheritDoc} */
     @Override public double getCost(Session ses, int[] masks, TableFilter[] filters, int
filter, SortOrder sortOrder) {
         long rowCnt = getRowCountApproximation();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/d8543958/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
index 4ef015b..ea7173c 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2IndexBase.java
@@ -178,7 +178,7 @@ public abstract class GridH2IndexBase extends BaseIndex {
     }
 
     /**
-     * Put row if absent.
+     * Puts row.
      *
      * @param row Row.
      * @return Existing row or {@code null}.
@@ -186,6 +186,16 @@ public abstract class GridH2IndexBase extends BaseIndex {
     public abstract GridH2Row put(GridH2Row row);
 
     /**
+     * Puts row.
+     *
+     * @param row Row.
+     * @return {@code True} if replaced existing row.
+     */
+    public boolean putx(GridH2Row row) {
+        return put(row) != null;
+    }
+
+    /**
      * Remove row from index.
      *
      * @param row Row.
@@ -194,6 +204,15 @@ public abstract class GridH2IndexBase extends BaseIndex {
     public abstract GridH2Row remove(SearchRow row);
 
     /**
+     * Remove row from index, does not return removed row.
+     *
+     * @param row Row.
+     */
+    public void removex(SearchRow row) {
+        remove(row);
+    }
+
+    /**
      * Finds a single row by the given row.
      *
      * @param row Search row.

http://git-wip-us.apache.org/repos/asf/ignite/blob/d8543958/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
index 3251b3d..5024959 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2Table.java
@@ -615,7 +615,7 @@ public class GridH2Table extends TableBase {
                                 "not supported [idx=" + idx + ", old=" + old + ", old2="
+ old2 + ']');
                     }
                     else if (old != null) // Row was not replaced, need to remove manually.
-                        idx.remove(old);
+                        idx.removex(old);
                 }
             }
             else {


Mime
View raw message