alex-plekhanov commented on code in PR #9992:
URL: https://github.com/apache/ignite/pull/9992#discussion_r883311825
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java:
##########
@@ -6347,4 +6491,137 @@ protected String lockRetryErrorMessage(String op) {
getClass().getSimpleName() + " [grpName=" + grpName + ",
treeName=" + name() + ", metaPageId=" +
U.hexLong(metaPageId) + "].";
}
+
+ /**
+ * The operation of deleting a range of values.
+ * <p>
+ * Performs the removal of several elements from the leaf at once.
+ */
+ protected class RemoveRange extends Remove {
+ /** Upper bound. */
+ private final L upper;
+
+ /** Lower bound. */
+ private final L lower;
+
+ /** List of removed rows. */
+ private final List<L> removedRows;
+
+ /** The number of remaining rows to remove ({@code -1}, if the limit
hasn't been specified). */
+ private int remaining;
+
+ /** Flag indicating that no more rows were found from the specified
range. */
+ private boolean completed;
+
+ /** The index of the highest row found on the page from the specified
range. */
+ private int highIdx;
+
+ /**
+ * @param lower Lower bound (inclusive).
+ * @param upper Upper bound (inclusive).
+ * @param needOld {@code True} If need return old value.
+ */
+ protected RemoveRange(L lower, L upper, boolean needOld, int limit) {
+ super(lower, needOld, rmvRangeFromLeaf);
+
+ this.lower = lower;
+ this.upper = upper;
+
+ remaining = limit <= 0 ? -1 : limit;
+ removedRows = needOld ? new LinkedList<>() : null;
Review Comment:
Not sure, but perhaps ArrayList will be more effective here (less GC
pressure)
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/tree/BPlusTree.java:
##########
@@ -6347,4 +6491,137 @@ protected String lockRetryErrorMessage(String op) {
getClass().getSimpleName() + " [grpName=" + grpName + ",
treeName=" + name() + ", metaPageId=" +
U.hexLong(metaPageId) + "].";
}
+
+ /**
+ * The operation of deleting a range of values.
+ * <p>
+ * Performs the removal of several elements from the leaf at once.
+ */
+ protected class RemoveRange extends Remove {
+ /** Upper bound. */
+ private final L upper;
+
+ /** Lower bound. */
+ private final L lower;
+
+ /** List of removed rows. */
+ private final List<L> removedRows;
+
+ /** The number of remaining rows to remove ({@code -1}, if the limit
hasn't been specified). */
+ private int remaining;
+
+ /** Flag indicating that no more rows were found from the specified
range. */
+ private boolean completed;
+
+ /** The index of the highest row found on the page from the specified
range. */
+ private int highIdx;
+
+ /**
+ * @param lower Lower bound (inclusive).
+ * @param upper Upper bound (inclusive).
+ * @param needOld {@code True} If need return old value.
+ */
+ protected RemoveRange(L lower, L upper, boolean needOld, int limit) {
+ super(lower, needOld, rmvRangeFromLeaf);
+
+ this.lower = lower;
+ this.upper = upper;
+
+ remaining = limit <= 0 ? -1 : limit;
+ removedRows = needOld ? new LinkedList<>() : null;
+ }
+
+ /**
+ * @return {@code True} if operation is completed.
+ */
+ private boolean isDone() {
+ return completed || remaining == 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override boolean notFound(BPlusIO<L> io, long pageAddr, int idx, int
lvl) throws IgniteCheckedException {
+ if (lvl != 0)
+ return false;
+
+ assert !completed;
+ assert tail == null;
+
+ // If the lower bound is higher than the rightmost item, or if
this item is outside the given range,
+ // then the search is completed - there are no items from the
given range.
+ if (idx == io.getCount(pageAddr) || compare(io, pageAddr, idx,
upper) > 0)
+ completed = true;
+
+ return true;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected boolean ceil() {
+ return !completed;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void removeDataRowFromLeaf(long pageId, long page,
long pageAddr, Boolean walPlc, BPlusIO<L> io,
Review Comment:
Each parameter on it's own line
##########
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:
This part is duplicated except one line, can we deduplicate it?
##########
modules/core/src/test/java/org/apache/ignite/internal/processors/database/BPlusTreeSelfTest.java:
##########
@@ -439,13 +465,13 @@ public void testPutRemove_1_20_pp_1() throws
IgniteCheckedException {
* @throws IgniteCheckedException If failed.
*/
@Test
- public void testPutRemove_1_20_pp_0() throws IgniteCheckedException {
Review Comment:
Why testPutRemove_1_20_pp_0 case was removed?
--
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]