dcapwell commented on code in PR #4248:
URL: https://github.com/apache/cassandra/pull/4248#discussion_r2211627015
##########
src/java/org/apache/cassandra/service/accord/CommandsForRanges.java:
##########
@@ -155,16 +202,93 @@ public void onUpdate(AccordCacheEntry<TxnId, Command>
state)
{
RangeRoute cur = cachedRangeTxnsById.put(cmd.txnId(),
upd);
if (!upd.equals(cur))
- {
- if (cur != null)
- remove(txnId, cur);
- cachedRangeTxnsByRange =
IntervalBTree.update(cachedRangeTxnsByRange, toMap(txnId, upd), COMPARATORS);
- }
+ pushEdit(new IntervalTreeEdit(txnId, toMap(txnId,
upd), cur == null ? null : toMap(txnId, cur)));
}
}
}
}
+ private void pushEdit(IntervalTreeEdit edit)
+ {
+ if (IntervalTreeEdit.push(edit, this))
+ commandStore.executor().submitExclusive(this);
+ }
+
+ @Override
+ public void run()
+ {
+ if (drainPendingEditsLock.tryLock())
+ {
+ try
+ {
+ drainPendingEditsInternal();
+ }
+ finally
+ {
+ drainPendingEditsLock.unlock();
+ postUnlock();
+ }
+ }
+ }
+
+ Object[] cachedRangeTxnsByRange()
+ {
+ drainPendingEditsLock.lock();
+ try
+ {
+ drainPendingEditsInternal();
+ return cachedRangeTxnsByRange;
+ }
+ finally
+ {
+ drainPendingEditsLock.unlock();
+ postUnlock();
+ }
+ }
+
+ void drainPendingEditsInternal()
+ {
+ IntervalTreeEdit edits = pendingEditsUpdater.getAndSet(this, null);
+ if (edits == null)
+ return;
+
+ if (edits.isSize(1))
+ {
+ if (edits.update != null) cachedRangeTxnsByRange =
IntervalBTree.update(cachedRangeTxnsByRange, edits.update, COMPARATORS);
+ if (edits.remove != null) cachedRangeTxnsByRange =
IntervalBTree.subtract(cachedRangeTxnsByRange, edits.remove, COMPARATORS);
+ return;
+ }
+
+ edits = edits.reverse();
+ Map<TxnId, IntervalTreeEdit> editMap = new HashMap<>();
+ for (IntervalTreeEdit edit : edits)
+ editMap.merge(edit.txnId, edit, IntervalTreeEdit::merge);
+
+ List<TxnIdInterval> update = new ArrayList<>(), remove = new
ArrayList<>();
+ for (IntervalTreeEdit edit : editMap.values())
+ {
+ if (edit.update != null)
update.addAll(BTreeSet.wrap(edit.update, COMPARATORS.totalOrder()));
+ if (edit.remove != null)
remove.addAll(BTreeSet.wrap(edit.remove, COMPARATORS.totalOrder()));
+ }
+
+ if (!remove.isEmpty())
Review Comment:
should the `remove` be first? if we added a range it shows up in `update`,
but later on update/evict remove it, won't we populate it after removing it?
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]