ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject ignite git commit: ignite-4652 - invoke closure outside of readLock
Date Fri, 17 Feb 2017 09:11:04 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-4652 80716c4ca -> c90978394


ignite-4652 - invoke closure outside of readLock


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

Branch: refs/heads/ignite-4652
Commit: c909783940ce2fc733868f8127ca4e2ecbaf6982
Parents: 80716c4
Author: Sergi Vladykin <sergi.vladykin@gmail.com>
Authored: Fri Feb 17 12:10:57 2017 +0300
Committer: Sergi Vladykin <sergi.vladykin@gmail.com>
Committed: Fri Feb 17 12:10:57 2017 +0300

----------------------------------------------------------------------
 .../cache/database/tree/BPlusTree.java          | 48 +++++++++++---------
 .../processors/database/BPlusTreeSelfTest.java  | 34 ++++++++++++++
 2 files changed, 60 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/c9097839/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 d35e7f5..0b60924 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
@@ -1578,9 +1578,15 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
                         return res;
 
                     case NOT_FOUND:
+                        if (lvl == 0)
+                            x.invokeClosure();
+
                         return x.onNotFound(page, pageId, fwdId, lvl);
 
                     case FOUND:
+                        if (lvl == 0)
+                            x.invokeClosure();
+
                         return x.onFound(page, pageId, backId, fwdId, lvl);
 
                     default:
@@ -2712,7 +2718,10 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
         final InvokeClosure<T> clo;
 
         /** */
-        boolean closureInvoked;
+        Bool closureInvoked = FALSE;
+
+        /** */
+        T foundRow;
 
         /** */
         Get op;
@@ -2768,7 +2777,11 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
                 return op.found(io, pageAddr, idx, lvl);
 
             if (lvl == 0) {
-                invokeClosure(io, pageAddr, idx);
+                if (closureInvoked == FALSE) {
+                    closureInvoked = READY;
+
+                    foundRow = getRow(io, pageAddr, idx);
+                }
 
                 return true;
             }
@@ -2783,7 +2796,8 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
                 return op.notFound(io, pageAddr, idx, lvl);
 
             if (lvl == 0) {
-                invokeClosure(null, 0L, 0);
+                if (closureInvoked == FALSE)
+                    closureInvoked = READY;
 
                 return true;
             }
@@ -2792,20 +2806,15 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
         }
 
         /**
-         * @param io IO.
-         * @param pageAddr Page address.
-         * @param idx Index of found entry.
          * @throws IgniteCheckedException If failed.
          */
-        private void invokeClosure(BPlusIO<L> io, long pageAddr, int idx) throws IgniteCheckedException
{
-            if (closureInvoked)
+        private void invokeClosure() throws IgniteCheckedException {
+            if (closureInvoked != READY)
                 return;
 
-            closureInvoked = true;
+            closureInvoked = DONE;
 
-            boolean rowFound = io != null;
-
-            clo.call(rowFound ? getRow(io, pageAddr, idx) : null);
+            clo.call(foundRow);
 
             switch (clo.operationType()) {
                 case PUT:
@@ -2813,32 +2822,27 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
 
                     assert newRow != null;
 
-                    // Row key must be equal to the old one.
-                    assert !rowFound || compare(io, pageAddr, idx, newRow) == 0;
-
                     op = new Put(newRow, false);
 
                     break;
 
                 case REMOVE:
-                    assert rowFound;
+                    assert foundRow != null;
 
                     op = new Remove(row, false);
 
                     break;
 
                 case NOOP:
-                    break;
+                    return;
 
                 default:
                     throw new IllegalStateException();
             }
 
-            if (op != null) {
-                op.copyFrom(this);
+            op.copyFrom(this);
 
-                op.invoke = this;
-            }
+            op.invoke = this;
         }
 
         /** {@inheritDoc} */
@@ -2956,7 +2960,7 @@ public abstract class BPlusTree<L, T extends L> extends DataStructure
implements
 
         /** {@inheritDoc} */
         @Override boolean isFinished() {
-            if (!closureInvoked)
+            if (closureInvoked != DONE)
                 return false;
 
             if (op == null)

http://git-wip-us.apache.org/repos/asf/ignite/blob/c9097839/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 9db156d..11891b9 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
@@ -194,6 +194,40 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
     }
 
     /**
+     * @throws IgniteCheckedException If failed.
+     */
+    public void _testBenchInvoke() throws IgniteCheckedException {
+        MAX_PER_PAGE = 10;
+
+        TestTree tree = createTestTree(true);
+
+        long start = System.nanoTime();
+
+        for (int i = 0; i < 10_000_000; i++) {
+            final long key = BPlusTree.randomInt(1000);
+
+//            tree.findOne(key); // 39
+//            tree.putx(key); // 22
+
+            tree.invoke(key, new IgniteTree.InvokeClosure<Long>() { // 25
+                @Override public void call(@Nullable Long row) throws IgniteCheckedException
{
+                    // No-op.
+                }
+
+                @Override public Long newRow() {
+                    return key;
+                }
+
+                @Override public IgniteTree.OperationType operationType() {
+                    return PUT;
+                }
+            });
+        }
+
+        X.println("   __ time: " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start));
+    }
+
+    /**
      * @param cursor cursor to check.
      * @param iterator iterator with expected result.
      * @throws IgniteCheckedException If failed


Mime
View raw message