belliottsmith commented on code in PR #7:
URL: https://github.com/apache/cassandra-accord/pull/7#discussion_r1013176402
##########
accord-core/src/main/java/accord/messages/Defer.java:
##########
@@ -0,0 +1,77 @@
+package accord.messages;
+
+import java.util.BitSet;
+import java.util.function.Function;
+
+import accord.local.*;
+import accord.primitives.TxnId;
+
+import static accord.local.PreLoadContext.contextFor;
+import static accord.messages.Defer.Ready.Expired;
+import static accord.messages.Defer.Ready.No;
+import static accord.messages.Defer.Ready.Yes;
+
+// TODO: use something more efficient? could probably assign each CommandStore
a unique ascending integer and use an int[]
+class Defer implements Listener
+{
+ public enum Ready { No, Yes, Expired }
+
+ final Function<Command, Ready> waitUntil;
+ final TxnRequest<?> request;
+ BitSet waitingOn = new BitSet(); // TODO: move to compressed integer hash
map to permit easier reclamation of ids
+ int waitingOnCount;
+ boolean isDone;
+
+ Defer(Status waitUntil, TxnRequest<?> request)
+ {
+ this(command -> {
+ int c = command.status().compareTo(waitUntil);
+ if (c < 0) return No;
+ if (c > 0) return Expired;
+ return Yes;
+ }, request);
+ }
+
+ Defer(Function<Command, Ready> waitUntil, TxnRequest<?> request)
+ {
+ this.waitUntil = waitUntil;
+ this.request = request;
+ }
+
+ void add(Command command, CommandStore commandStore)
+ {
+ if (isDone)
+ throw new IllegalStateException("Recurrent retry of " + request);
+
+ waitingOn.set(commandStore.id());
+ ++waitingOnCount;
+ command.addListener(this);
+ }
+
+ @Override
+ public void onChange(SafeCommandStore safeStore, Command command)
+ {
+ Ready ready = waitUntil.apply(command);
+ if (ready == No) return;
+ command.removeListener(this);
+ if (ready == Expired) return;
Review Comment:
If we've already committed, essentially. Though this can be simplified since
we only use it in the one place now, and actually I think this is broken given
our changed semantics for `Accept` that means we don't need to `PreAccept`
first. I've addressed this in a follow-up commit.
--
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]