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


##########
accord-core/src/main/java/accord/coordinate/Propose.java:
##########
@@ -77,6 +78,7 @@ abstract class Propose<R> implements Callback<AcceptReply>
         this.callback = callback;
         this.acceptOks = new ArrayList<>();
         this.acceptTracker = new QuorumTracker(topologies);
+        Invariants.checkState(txnId.kind().isSyncPoint() || 
deps.keyDeps.txnIdCount() == 0 || deps.keyDeps.txnId(deps.keyDeps.txnIdCount() 
- 1).compareTo(executeAt) < 0);

Review Comment:
   can we get a useful error msg to know what happened?



##########
accord-core/src/main/java/accord/local/CommandStore.java:
##########
@@ -594,8 +594,68 @@ public final boolean isRejectedIfNotPreAccepted(TxnId 
txnId, Unseekables<?> part
         return null != rejectBefore.foldl(participants, (rejectIfBefore, test) 
-> rejectIfBefore.compareTo(test) > 0 ? null : test, txnId, Objects::isNull);
     }
 
-    public final void removeRedundantDependencies(Unseekables<?> participants, 
Deps deps, WaitingOn.Update builder)
+    public final void removeRedundantDependencies(Unseekables<?> participants, 
WaitingOn.Update builder)
     {
+        // Note: we do not need to track the bootstraps we implicitly depend 
upon, because we will not serve any read requests until this has completed
+        //  and since we are a timestamp store, and we write only this will 
sort itself out naturally
+        // TODO (required): make sure we have no races on HLC around SyncPoint 
else this resolution may not work (we need to know the micros equivalent 
timestamp of the snapshot)
+        class KeyState
+        {
+            Int2ObjectHashMap<Keys> partiallyBootstrapping;
+
+            /**
+             * Are the participating ranges for the txn fully covered by 
bootstrapping ranges for this command store
+             */
+            boolean isFullyBootstrapping(WaitingOn.Update builder, Range 
range, int txnIdx)
+            {
+                if (builder.directKeyDeps.foldEachKey(txnIdx, range, true, 
(r0, k, p) -> p && r0.contains(k)))
+                    return true;
+
+                if (partiallyBootstrapping == null)
+                    partiallyBootstrapping = new Int2ObjectHashMap<>();
+                Keys prev = partiallyBootstrapping.get(txnIdx);
+                Keys remaining = prev;
+                if (remaining == null) remaining = 
builder.directKeyDeps.participatingKeys(txnIdx);
+                else Invariants.checkState(!remaining.isEmpty());
+                remaining = remaining.subtract(range);
+                if (prev == null) Invariants.checkState(!remaining.isEmpty());
+                partiallyBootstrapping.put(txnIdx, remaining);
+                return remaining.isEmpty();
+            }
+        }
+
+        KeyDeps directKeyDeps = builder.directKeyDeps;
+        if (!directKeyDeps.isEmpty())
+        {
+            redundantBefore().foldl(directKeyDeps.keys(), (e, s, d, b) -> {
+                // TODO (desired, efficiency): foldlInt so we can track the 
lower rangeidx bound and not revisit unnecessarily
+                // find the txnIdx below which we are known to be fully 
redundant locally due to having been applied or invalidated
+                int bootstrapIdx = d.txnIds().find(e.bootstrappedAt);
+                if (bootstrapIdx < 0) bootstrapIdx = -1 - bootstrapIdx;
+                int appliedIdx = 
d.txnIds().find(e.locallyAppliedOrInvalidatedBefore);
+                if (appliedIdx < 0) appliedIdx = -1 - appliedIdx;
+
+                // remove intersecting transactions with known redundant txnId
+                // note that we must exclude all transactions that are 
pre-bootstrap, and perform the more complicated dance below,
+                // as these transactions may be only partially applied, and we 
may need to wait for them on another key.
+                if (appliedIdx > bootstrapIdx)
+                {
+                    d.forEach(e.range, bootstrapIdx, appliedIdx, b, s, (b0, 
s0, txnIdx) -> {
+                        b0.removeWaitingOnDirectKeyTxnId(txnIdx);
+                    });
+                }
+
+                if (bootstrapIdx > 0)

Review Comment:
   I posted this comment to the wrong line... this is the range logic and I 
posted to the directKey logic...



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