ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [15/50] ignite git commit: ignite-db - split fix
Date Thu, 28 Apr 2016 08:52:45 GMT
ignite-db - split fix


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

Branch: refs/heads/ignite-db-x-10884
Commit: d9a3a82fbe6aaba78fa2adda476070ba8031c224
Parents: 29179ce
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Sun Apr 24 21:13:16 2016 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Sun Apr 24 21:13:16 2016 +0300

----------------------------------------------------------------------
 .../cache/database/tree/BPlusTree.java          | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d9a3a82f/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 05fa56b..aa54554 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
@@ -1043,12 +1043,22 @@ public abstract class BPlusTree<L, T extends L> {
      * @param io IO.
      * @param buf Splitting buffer.
      * @param fwdBuf Forward buffer.
+     * @param idx Insertion index.
+     * @return {@code true} The middle index was shifted to the right.
      * @throws IgniteCheckedException If failed.
      */
-    private void splitPage(BPlusIO io, ByteBuffer buf, ByteBuffer fwdBuf)
+    private boolean splitPage(BPlusIO io, ByteBuffer buf, ByteBuffer fwdBuf, int idx)
         throws IgniteCheckedException {
         int cnt = io.getCount(buf);
-        int mid = 1 + (cnt >>> 1);
+        int mid = cnt >>> 1;
+
+        boolean res = false;
+
+        if (idx > mid) { // If insertion is going to be to the forward page, keep more
in the back page.
+            mid++;
+
+            res = true;
+        }
 
         cnt -= mid;
 
@@ -1061,6 +1071,8 @@ public abstract class BPlusTree<L, T extends L> {
         // Setup forward-backward refs.
         io.setForward(fwdBuf, io.getForward(buf));
         io.setForward(buf, PageIO.getPageId(fwdBuf));
+
+        return res;
     }
 
     /**
@@ -1105,12 +1117,12 @@ public abstract class BPlusTree<L, T extends L> {
             ByteBuffer fwdBuf = fwd.getForInitialWrite();
             io.initNewPage(fwdBuf, fwd.id());
 
-            splitPage(io, buf, fwdBuf);
+            boolean midShift = splitPage(io, buf, fwdBuf, idx);
 
             // Do insert.
             int cnt = io.getCount(buf);
 
-            if (idx <= cnt) {
+            if (idx < cnt || (idx == cnt && !midShift)) {
                 insertSimple(io, buf, row, idx, rightId);
 
                 // Fix leftmost child of forward page, because newly inserted row will go
up.


Mime
View raw message