xtern commented on code in PR #9992:
URL: https://github.com/apache/ignite/pull/9992#discussion_r883648695


##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java:
##########
@@ -601,6 +602,104 @@ private class RemoveFromLeaf extends 
GetPageHandler<Remove> {
         }
     }
 
+    /** */
+    private final PageHandler<Remove, Result> rmvRangeFromLeaf;
+
+    /**
+     *
+     */
+    private class RemoveRangeFromLeaf extends GetPageHandler<RemoveRange> {
+        /** {@inheritDoc} */
+        @Override public Result run0(long leafId, long leafPage, long 
leafAddr, BPlusIO<L> io, RemoveRange r, int lvl)
+            throws IgniteCheckedException {
+            assert lvl == 0 : lvl; // Leaf.
+
+            // Check the triangle invariant.
+            if (io.getForward(leafAddr) != r.fwdId)
+                return RETRY;
+
+            final int cnt = io.getCount(leafAddr);
+
+            assert cnt <= Short.MAX_VALUE : cnt;
+
+            int idx = findInsertionPoint(lvl, io, leafAddr, 0, cnt, r.lower, 
0);
+
+            if (idx < 0) {
+                idx = fix(idx);
+
+                // Before the page was locked, its state could have changed, 
so you need to make sure that
+                // it has elements from the range, otherwise repeat the search.
+                if (idx == cnt || compare(io, leafAddr, idx, r.upper) > 0)
+                    return RETRY;
+            }
+
+            r.highIdx = findInsertionPoint(lvl, io, leafAddr, idx, cnt, 
r.upper, 0);
+
+            int highIdx = r.highIdx >= 0 ? r.highIdx : fix(r.highIdx) - 1;
+
+            if (r.remaining != -1 && highIdx - idx + 1 >= r.remaining)
+                highIdx = idx + r.remaining - 1;
+
+            assert highIdx >= idx : "low=" + idx + ", high=" + highIdx;
+
+            r.highIdx = r.highIdx >= 0 ? highIdx : -highIdx - 1;
+
+            assert idx >= 0 && idx < cnt : idx;
+
+            int rmvCnt = highIdx - idx + 1;
+
+            // Need to do inner replace when we remove the rightmost element 
and the leaf have no forward page,
+            // i.e. it is not the rightmost leaf of the tree.
+            boolean needReplaceInner = canGetRowFromInner && highIdx == cnt - 
1 && io.getForward(leafAddr) != 0;
+
+            // !!! Before modifying state we have to make sure that we will 
not go for retry.
+
+            // We may need to replace inner key or want to merge this leaf 
with sibling after the remove -> keep lock.
+            if (needReplaceInner ||

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to