belliottsmith commented on code in PR #3976:
URL: https://github.com/apache/cassandra/pull/3976#discussion_r1992206481


##########
src/java/org/apache/cassandra/service/accord/CommandsForRanges.java:
##########
@@ -102,22 +104,34 @@ private Loader newLoader(Unseekables<?> 
searchKeysOrRanges, RedundantBefore redu
             return new Loader(this, searchKeysOrRanges, redundantBefore, 
testKind, minTxnId, maxTxnId, findAsDep);
         }
 
+        private void updateTransitive(UnaryOperator<NavigableMap<TxnId, 
Ranges>> update)
+        {
+            transitive.updateAndGet(update);
+        }
+
         public void mergeTransitive(TxnId txnId, Ranges ranges, BiFunction<? 
super Ranges, ? super Ranges, ? extends Ranges> remappingFunction)
         {
-            transitive.merge(txnId, ranges, remappingFunction);
+            updateTransitive(transitive -> {
+                NavigableMap<TxnId, Ranges> next = new TreeMap<>(transitive);
+                next.merge(txnId, ranges, remappingFunction);
+                return next;
+            });
         }
 
         public void gcBefore(TxnId gcBefore, Ranges ranges)
         {
-            Iterator<Map.Entry<TxnId, Ranges>> iterator = 
transitive.headMap(gcBefore).entrySet().iterator();
-            while (iterator.hasNext())
-            {
-                Map.Entry<TxnId, Ranges> e = iterator.next();
-                Ranges newRanges = e.getValue().without(ranges);
-                if (newRanges.isEmpty())
-                    iterator.remove();
-                e.setValue(newRanges);
-            }
+            updateTransitive(transitive -> {
+                NavigableMap<TxnId, Ranges> next = new TreeMap<>();

Review Comment:
   I think it might be nice to return the original map if there's no changes. 
That is, keep this null until we need to edit, then insert everything 
before-hand and update from afterwards.



-- 
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]

Reply via email to