belliottsmith commented on code in PR #7:
URL: https://github.com/apache/cassandra-accord/pull/7#discussion_r1011992265
##########
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:
True, the premise was that if we're having to fetch it remotely it's
probably better to save it to save time if we have to try again. But maybe it's
better to simplify.
--
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]