ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [36/50] ignite git commit: ignite-db - size + minor
Date Thu, 28 Apr 2016 08:53:06 GMT
ignite-db - size + minor


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

Branch: refs/heads/ignite-db-x-10884
Commit: c523c6fac50a7f6a56e66504da0a096e6f7e3a44
Parents: 2b30543
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Wed Apr 27 02:06:18 2016 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Wed Apr 27 02:06:18 2016 +0300

----------------------------------------------------------------------
 .../cache/database/tree/BPlusTree.java          | 55 +++++++++++++++++---
 .../processors/database/BPlusTreeSelfTest.java  |  9 +---
 2 files changed, 49 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/c523c6fa/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 70f1af5..e712a41 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
@@ -577,7 +577,7 @@ public abstract class BPlusTree<L, T extends L> {
      * @param upper Upper bound.
      * @return Cursor.
      */
-    private GridCursor<T> findNoLower(L upper) throws IgniteCheckedException {
+    private GridCursor<T> findLowerUnbounded(L upper) throws IgniteCheckedException
{
         ForwardCursor cursor = new ForwardCursor(upper);
 
         long firstPageId;
@@ -608,7 +608,7 @@ public abstract class BPlusTree<L, T extends L> {
      */
     public final GridCursor<T> find(L lower, L upper) throws IgniteCheckedException
{
         if (lower == null)
-            return findNoLower(upper);
+            return findLowerUnbounded(upper);
 
         GetCursor g = new GetCursor(lower, upper);
 
@@ -996,11 +996,52 @@ public abstract class BPlusTree<L, T extends L> {
      * @param max Max.
      * @return Random value from {@code 0} (inclusive) to the given max value (exclusive).
      */
-     public int randomInt(int max) {
+    public int randomInt(int max) {
          return ThreadLocalRandom.current().nextInt(max);
      }
 
     /**
+     * TODO may produce wrong results on concurrent access
+     *
+     * @return Size.
+     * @throws IgniteCheckedException If failed.
+     */
+    public final long size() throws IgniteCheckedException {
+        long cnt = 0;
+        long pageId;
+
+        try (Page meta = page(metaPageId)) {
+            pageId = getFirstPageId(meta, 0); // Level 0 is always at the bottom.
+        }
+
+        BPlusIO<L> io = null;
+
+        while (pageId != 0) {
+            try (Page page = page(pageId)) {
+                ByteBuffer buf = page.getForRead();
+
+                try {
+                    if (io == null) {
+                        io = io(buf);
+
+                        assert io.isLeaf();
+                    }
+
+                    cnt += io.getCount(buf);
+
+
+                    pageId = io.getForward(buf);
+                }
+                finally {
+                    page.releaseRead();
+                }
+            }
+        }
+
+        return cnt;
+    }
+
+    /**
      * @param row Row.
      * @return Old row.
      * @throws IgniteCheckedException If failed.
@@ -1708,9 +1749,9 @@ public abstract class BPlusTree<L, T extends L> {
         /**
          * @param t Tail.
          * @return {@code true} If merged successfully or end reached.
-         * @throws IgniteCheckedException
+         * @throws IgniteCheckedException If failed.
          */
-        private boolean mergeDown(Tail<L> t) throws IgniteCheckedException {
+        private boolean mergeBottomUp(Tail<L> t) throws IgniteCheckedException {
             assert needMergeEmptyBranch == FALSE || needMergeEmptyBranch == DONE: needMergeEmptyBranch;
 
             if (t.down == null)
@@ -1719,7 +1760,7 @@ public abstract class BPlusTree<L, T extends L> {
             if (t.down.sibling == null) // We've merged something there.
                 return false;
 
-            return mergeDown(t.down) && merge(t);
+            return mergeBottomUp(t.down) && merge(t);
         }
 
         /**
@@ -1745,7 +1786,7 @@ public abstract class BPlusTree<L, T extends L> {
                 needMergeEmptyBranch = DONE;
             }
 
-            mergeDown(tail);
+            mergeBottomUp(tail);
 
             if (needReplaceInner == READY) {
                 // If we've merged empty branch right now, then the inner key was dropped.

http://git-wip-us.apache.org/repos/asf/ignite/blob/c523c6fa/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
index eebd304..813fdc3 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java
@@ -475,9 +475,6 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
             if (i % 1000 == 0)
                 X.println(" --> " + i + "  " + x);
 
-//            if (i >= 57)
-//                X.println(tree.printTree());
-
             if (tree.randomInt(2) == 0)
                 assertEquals(map.put(x, x), tree.put(x));
             else {
@@ -489,11 +486,7 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
             if (i % 100 == 0) {
                 GridCursor<Long> cursor = tree.find(null, null);
 
-                int size = 0;
-
                 while (cursor.next()) {
-                    size++;
-
                     x = cursor.get();
 
                     assert x != null;
@@ -501,7 +494,7 @@ public class BPlusTreeSelfTest extends GridCommonAbstractTest {
                     assertEquals(map.get(x), x);
                 }
 
-                assertEquals(map.size(), size);
+                assertEquals(map.size(), tree.size());
             }
         }
     }


Mime
View raw message