dcapwell commented on code in PR #106:
URL: https://github.com/apache/cassandra-accord/pull/106#discussion_r1697535293


##########
accord-core/src/main/java/accord/local/Command.java:
##########
@@ -1484,47 +1485,70 @@ public boolean removeWaitingOn(Key key)
 
             public boolean isWaitingOn(Key key)
             {
-                int index = keys.indexOf(key) + txnIds.size();
+                int index = keys.indexOf(key) + txnIdCount();
                 return index >= 0 && waitingOn.get(index);
             }
 
-            void initialiseWaiting(int index)
-            {
-                waitingOn.set(index);
-            }
-
             public boolean isWaiting()
             {
                 return !waitingOn.isEmpty();
             }
 
             public TxnId minWaitingOnTxnId()
             {
-                int index = waitingOn.firstSetBit();
-                return index < 0 || index >= txnIds.size() ? null : 
txnIds.get(index);
+                int index = minWaitingOnTxnIdx();
+                return index < 0 ? null : txnId(index);
+            }
+
+            public int minWaitingOnTxnIdx()
+            {
+                int directRangeTxnIdCount = directRangeDeps.txnIdCount();
+                int minWaitingOnDirectRangeIndex = 
waitingOn.nextSetBitBefore(0, directRangeTxnIdCount);
+                if (directKeyDeps == KeyDeps.NONE)
+                    return minWaitingOnDirectRangeIndex;
+
+                int directKeyTxnIdCount = directKeyDeps.txnIdCount();
+                int txnIdCount = directKeyTxnIdCount + directRangeTxnIdCount;
+                int minWaitingOnDirectKeyIndex = 
waitingOn.nextSetBitBefore(directRangeTxnIdCount, txnIdCount);
+                if (minWaitingOnDirectKeyIndex < 0)
+                    return minWaitingOnDirectRangeIndex;
+                if (minWaitingOnDirectRangeIndex < 0)
+                    return minWaitingOnDirectKeyIndex;
+                int c = 
directRangeDeps.txnId(minWaitingOnDirectRangeIndex).compareTo(directKeyDeps.txnId(minWaitingOnDirectKeyIndex
 - directRangeDeps.txnIdCount()));
+                return c < 0 ? minWaitingOnDirectRangeIndex : 
minWaitingOnDirectKeyIndex;
+            }
+
+            public boolean isWaitingOnDirectRangeTxnIdx(int idx)
+            {
+                return waitingOn.get(idx);
             }
 
-            public boolean isWaitingOn(int txnIdx)
+            public boolean isWaitingOnDirectKeyTxnIdx(int idx)
             {
-                return waitingOn.get(txnIdx);
+                return waitingOn.get(idx + directRangeDeps.txnIdCount());
             }
 
             public void updateExecuteAtLeast(Timestamp executeAtLeast)
             {
                 this.executeAtLeast = Timestamp.nonNullOrMax(executeAtLeast, 
this.executeAtLeast);
             }
 
-            boolean removeWaitingOnTxnId(int i)
+            boolean removeWaitingOnDirectRangeTxnId(int i)
             {
                 return removeWaitingOn(i);
             }
 
+            boolean removeWaitingOnDirectKeyTxnId(int i)

Review Comment:
   the remove index methods don't actually check that their input is correct, 
we should add a check... I added that to my feedback branch



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