Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 933FC200C1E for ; Fri, 17 Feb 2017 10:11:06 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 90418160B55; Fri, 17 Feb 2017 09:11:06 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B4B4A160B3F for ; Fri, 17 Feb 2017 10:11:05 +0100 (CET) Received: (qmail 23436 invoked by uid 500); 17 Feb 2017 09:11:05 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 23427 invoked by uid 99); 17 Feb 2017 09:11:04 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Feb 2017 09:11:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BE256DFC1C; Fri, 17 Feb 2017 09:11:04 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sergi@apache.org To: commits@ignite.apache.org Message-Id: <58e024074ce646a19225bfad0f2de519@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: ignite git commit: ignite-4652 - invoke closure outside of readLock Date: Fri, 17 Feb 2017 09:11:04 +0000 (UTC) archived-at: Fri, 17 Feb 2017 09:11:06 -0000 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 Authored: Fri Feb 17 12:10:57 2017 +0300 Committer: Sergi Vladykin 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 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 extends DataStructure implements final InvokeClosure clo; /** */ - boolean closureInvoked; + Bool closureInvoked = FALSE; + + /** */ + T foundRow; /** */ Get op; @@ -2768,7 +2777,11 @@ public abstract class BPlusTree 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 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 extends DataStructure implements } /** - * @param io IO. - * @param pageAddr Page address. - * @param idx Index of found entry. * @throws IgniteCheckedException If failed. */ - private void invokeClosure(BPlusIO 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 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 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() { // 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