You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "belliottsmith (via GitHub)" <gi...@apache.org> on 2025/07/14 16:52:31 UTC

[PR] Cfr async [cassandra]

belliottsmith opened a new pull request, #4248:
URL: https://github.com/apache/cassandra/pull/4248

   Thanks for sending a pull request! Here are some tips if you're new here:
    
    * Ensure you have added or run the [appropriate tests](https://cassandra.apache.org/_/development/testing.html) for your PR.
    * Be sure to keep the PR description updated to reflect all changes.
    * Write your PR title to summarize what this PR proposes.
    * If possible, provide a concise example to reproduce the issue for a faster review.
    * Read our [contributor guidelines](https://cassandra.apache.org/_/development/index.html)
    * If you're making a documentation change, see our [guide to documentation contribution](https://cassandra.apache.org/_/development/documentation.html)
    
   Commit messages should follow the following format:
   
   ```
   <One sentence description, usually Jira title or CHANGES.txt summary>
   
   <Optional lengthier description (context on patch)>
   
   patch by <Authors>; reviewed by <Reviewers> for CASSANDRA-#####
   
   Co-authored-by: Name1 <email1>
   Co-authored-by: Name2 <email2>
   
   ```
   
   The [Cassandra Jira](https://issues.apache.org/jira/projects/CASSANDRA/issues/)
   
   


-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Cfr async [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Cfr async [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #4248:
URL: https://github.com/apache/cassandra/pull/4248#discussion_r2211613839


##########
src/java/org/apache/cassandra/service/accord/CommandsForRanges.java:
##########
@@ -122,15 +130,54 @@ public NavigableMap<Timestamp, CommandSummaries.Summary> byTxnId()
         return this;
     }
 
-    public static class Manager implements AccordCache.Listener<TxnId, Command>
+    public static class Manager implements AccordCache.Listener<TxnId, Command>, Runnable
     {
+        static class IntervalTreeEdit extends IntrusiveStack<IntervalTreeEdit>
+        {
+            final TxnId txnId;
+            final @Nullable Object[] update, remove;
+
+            IntervalTreeEdit(TxnId txnId, Object[] update, Object[] remove)
+            {
+                this.txnId = txnId;
+                this.update = update;
+                this.remove = remove;
+            }
+
+            public static boolean push(IntervalTreeEdit edit, Manager manager)
+            {
+                return null == IntrusiveStack.getAndPush(pendingEditsUpdater, manager, edit);
+            }
+
+            public IntervalTreeEdit reverse()
+            {
+                return reverse(this);
+            }
+
+            boolean isSize(int size)
+            {
+                return IntrusiveStack.isSize(size, this);
+            }
+
+            IntervalTreeEdit merge(IntervalTreeEdit next)
+            {
+                Invariants.require(this.txnId.equals(next.txnId));
+                Object[] remove = this.remove == null ? next.remove : next.remove == null ? this.remove : IntervalBTree.update(this.remove, next.remove, COMPARATORS);
+                return new IntervalTreeEdit(txnId, next.update, remove);

Review Comment:
   don't merge `update` as the assumption this is the side effect of a txn, so another update coming after the fact doesn't make sense?



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Cfr async [cassandra]

Posted by "belliottsmith (via GitHub)" <gi...@apache.org>.
belliottsmith merged PR #4248:
URL: https://github.com/apache/cassandra/pull/4248


-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Cfr async [cassandra]

Posted by "belliottsmith (via GitHub)" <gi...@apache.org>.
belliottsmith commented on code in PR #4248:
URL: https://github.com/apache/cassandra/pull/4248#discussion_r2211602060


##########
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);
-                        }
+                            IntervalTreeEdit.push(new IntervalTreeEdit(txnId, toMap(txnId, upd), cur == null ? null : toMap(txnId, cur)), this);
                     }
                 }
             }
         }
 
+        private void pushEdit(IntervalTreeEdit edit)

Review Comment:
   oh this must be a bad rebase, hopefully nothing else lost. let me fix that now



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Cfr async [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #4248:
URL: https://github.com/apache/cassandra/pull/4248#discussion_r2211582307


##########
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);
-                        }
+                            IntervalTreeEdit.push(new IntervalTreeEdit(txnId, toMap(txnId, upd), cur == null ? null : toMap(txnId, cur)), this);
                     }
                 }
             }
         }
 
+        private void pushEdit(IntervalTreeEdit edit)

Review Comment:
   this is private and nothing touches it; is this dead code?



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] Cfr async [cassandra]

Posted by "belliottsmith (via GitHub)" <gi...@apache.org>.
belliottsmith commented on code in PR #4248:
URL: https://github.com/apache/cassandra/pull/4248#discussion_r2211681501


##########
src/java/org/apache/cassandra/service/accord/CommandsForRanges.java:
##########
@@ -122,15 +130,54 @@ public NavigableMap<Timestamp, CommandSummaries.Summary> byTxnId()
         return this;
     }
 
-    public static class Manager implements AccordCache.Listener<TxnId, Command>
+    public static class Manager implements AccordCache.Listener<TxnId, Command>, Runnable
     {
+        static class IntervalTreeEdit extends IntrusiveStack<IntervalTreeEdit>
+        {
+            final TxnId txnId;
+            final @Nullable Object[] update, remove;
+
+            IntervalTreeEdit(TxnId txnId, Object[] update, Object[] remove)
+            {
+                this.txnId = txnId;
+                this.update = update;
+                this.remove = remove;
+            }
+
+            public static boolean push(IntervalTreeEdit edit, Manager manager)
+            {
+                return null == IntrusiveStack.getAndPush(pendingEditsUpdater, manager, edit);
+            }
+
+            public IntervalTreeEdit reverse()
+            {
+                return reverse(this);
+            }
+
+            boolean isSize(int size)
+            {
+                return IntrusiveStack.isSize(size, this);
+            }
+
+            IntervalTreeEdit merge(IntervalTreeEdit next)
+            {
+                Invariants.require(this.txnId.equals(next.txnId));
+                Object[] remove = this.remove == null ? next.remove : next.remove == null ? this.remove : IntervalBTree.update(this.remove, next.remove, COMPARATORS);
+                return new IntervalTreeEdit(txnId, next.update, remove);

Review Comment:
   More the update is always like an image record - it's the latest info we want in the map. So we only need the last one.



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org