belliottsmith commented on code in PR #7:
URL: https://github.com/apache/cassandra-accord/pull/7#discussion_r1014500676


##########
accord-core/src/main/java/accord/coordinate/RecoverWithHomeKey.java:
##########
@@ -0,0 +1,85 @@
+package accord.coordinate;
+
+import java.util.function.BiConsumer;
+
+import accord.api.RoutingKey;
+import accord.local.Node;
+import accord.local.Node.Id;
+import accord.messages.CheckStatus.CheckStatusOk;
+import accord.messages.CheckStatus.IncludeInfo;
+import accord.primitives.Route;
+import accord.primitives.RoutingKeys;
+import accord.primitives.TxnId;
+
+import static accord.local.PreLoadContext.contextFor;
+
+/**
+ * A result of null indicates the transaction is globally persistent
+ * A result of CheckStatusOk indicates the maximum status found for the 
transaction, which may be used to assess progress
+ */
+public class RecoverWithHomeKey extends CheckShards implements 
BiConsumer<Object, Throwable>
+{
+    final RoutingKey homeKey;
+    final BiConsumer<Outcome, Throwable> callback;
+
+    RecoverWithHomeKey(Node node, TxnId txnId, RoutingKey homeKey, 
BiConsumer<Outcome, Throwable> callback)
+    {
+        super(node, txnId, RoutingKeys.of(homeKey), txnId.epoch, 
IncludeInfo.Route);
+        this.homeKey = homeKey;
+        this.callback = callback;
+    }
+
+    public static RecoverWithHomeKey recover(Node node, TxnId txnId, 
RoutingKey homeKey, BiConsumer<Outcome, Throwable> callback)
+    {
+        RecoverWithHomeKey maybeRecover = new RecoverWithHomeKey(node, txnId, 
homeKey, callback);
+        maybeRecover.start();
+        return maybeRecover;
+    }
+
+    @Override
+    public void accept(Object unused, Throwable fail)
+    {
+        callback.accept(null, fail);
+    }
+
+    @Override
+    protected boolean isSufficient(Id from, CheckStatusOk ok)
+    {
+        return ok.route != null;
+    }
+
+    @Override
+    protected void onDone(Done done, Throwable fail)
+    {
+        if (fail != null)
+        {
+            callback.accept(null, fail);
+        }
+        else if (merged == null || !(merged.route instanceof Route))
+        {
+            switch (done)
+            {
+                default: throw new IllegalStateException();
+                case Exhausted:
+                    callback.accept(null, new Timeout(txnId, homeKey));
+                    return;
+                case Success:
+                    callback.accept(null, new IllegalStateException());
+                    return;
+                case ReachedQuorum:
+                    Invalidate.invalidate(node, txnId, contactKeys, homeKey, 
callback);
+            }
+        }
+        else
+        {
+            // save route
+            node.ifLocal(contextFor(txnId), merged.route.homeKey, txnId.epoch, 
safeStore -> {
+                // TODO (soon): do not load Command to update the route

Review Comment:
   No, ifLocal just means do this if we own it - which may or may not be the 
case (ever) for the homeKey. Basically, if we’re the home shard we probably 
want to know the Route in case we need to recover the transaction. If we aren’t 
the home shard there’s probably no need to preemptively save 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: [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