This is an automated email from the ASF dual-hosted git repository.

dcapwell pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra-accord.git


The following commit(s) were added to refs/heads/trunk by this push:
     new e2ccee4f Add a table to inspect the current state of a txn (#110)
e2ccee4f is described below

commit e2ccee4f51fe4c7c7f3ea8911897135ed7e37114
Author: dcapwell <[email protected]>
AuthorDate: Wed Sep 4 09:35:23 2024 -0700

    Add a table to inspect the current state of a txn (#110)
    
    patch by David Capwell; reviewed by Benedict Elliott Smith for 
CASSANDRA-19838
---
 .../src/main/java/accord/local/Command.java        |  2 +-
 .../main/java/accord/local/cfk/CommandsForKey.java | 23 ++++++++++++++++++----
 .../src/test/java/accord/impl/basic/Cluster.java   |  2 +-
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/accord-core/src/main/java/accord/local/Command.java 
b/accord-core/src/main/java/accord/local/Command.java
index 1a886c35..89952577 100644
--- a/accord-core/src/main/java/accord/local/Command.java
+++ b/accord-core/src/main/java/accord/local/Command.java
@@ -1260,7 +1260,7 @@ public abstract class Command implements CommonAttributes
             return directRangeDeps.txnIdCount() + directKeyDeps.txnIdCount();
         }
 
-        TxnId txnId(int i)
+        public TxnId txnId(int i)
         {
             int ki = i - directRangeDeps.txnIdCount();
             if (ki < 0)
diff --git a/accord-core/src/main/java/accord/local/cfk/CommandsForKey.java 
b/accord-core/src/main/java/accord/local/cfk/CommandsForKey.java
index 5af04305..065176c1 100644
--- a/accord-core/src/main/java/accord/local/cfk/CommandsForKey.java
+++ b/accord-core/src/main/java/accord/local/cfk/CommandsForKey.java
@@ -319,7 +319,7 @@ public class CommandsForKey extends CommandsForKeyUpdate 
implements CommandsSumm
                    && Arrays.equals(missing(), info.missing());
         }
 
-        TxnId plainTxnId()
+        public TxnId plainTxnId()
         {
             return new TxnId(this);
         }
@@ -787,14 +787,29 @@ public class CommandsForKey extends CommandsForKeyUpdate 
implements CommandsSumm
         return redundantBefore.shardRedundantBefore();
     }
 
-    public TxnId nextWaitingToApply(Kinds kinds)
+    private TxnId nextWaitingToApply(Kinds kinds, @Nullable Timestamp 
untilExecuteAt)
     {
         int i = maxAppliedWriteByExecuteAt + 1;
-        while (i < committedByExecuteAt.length && 
(committedByExecuteAt[i].status != APPLIED || 
!kinds.test(committedByExecuteAt[i].kind())))
+        while (i < committedByExecuteAt.length && 
(committedByExecuteAt[i].status == APPLIED || 
!kinds.test(committedByExecuteAt[i].kind())))
+        {
+            if (untilExecuteAt != null && 
committedByExecuteAt[i].compareTo(untilExecuteAt) >= 0)
+                return null;
+
             ++i;
+        }
         return i >= committedByExecuteAt.length ? null : 
committedByExecuteAt[i];
     }
 
+    public TxnId blockedOnTxnId(TxnId txnId, @Nullable Timestamp executeAt)
+    {
+        TxnInfo minUndecided = minUndecided();
+        if (minUndecided != null && minUndecided.compareTo(txnId) < 0)
+            return minUndecided.plainTxnId();
+
+        Kinds kinds = txnId.kind().witnesses();
+        return nextWaitingToApply(kinds, executeAt);
+    }
+
     /**
      * All commands before/after (exclusive of) the given timestamp, excluding 
those that are redundant,
      * or have locally applied prior to some other command that is stable, 
will be returned by the collection.
@@ -1396,7 +1411,7 @@ public class CommandsForKey extends CommandsForKeyUpdate 
implements CommandsSumm
         return null;
     }
 
-    TxnInfo minUndecided()
+    public TxnInfo minUndecided()
     {
         return minUndecidedById < 0 ? null : byId[minUndecidedById];
     }
diff --git a/accord-core/src/test/java/accord/impl/basic/Cluster.java 
b/accord-core/src/test/java/accord/impl/basic/Cluster.java
index 7c6ad01f..7fee260b 100644
--- a/accord-core/src/test/java/accord/impl/basic/Cluster.java
+++ b/accord-core/src/test/java/accord/impl/basic/Cluster.java
@@ -893,7 +893,7 @@ public class Cluster implements Scheduler
             else
             {
                 CommandsForKey cfk = 
store.unsafeCommandsForKey().get(blockedOnKey).value();
-                blockedOn = 
cfk.nextWaitingToApply(command.txnId().kind().witnesses());
+                blockedOn = cfk.blockedOnTxnId(command.txnId(), 
command.executeAt());
                 blockedVia = Keys.of(blockedOnKey);
             }
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to