aweisberg commented on code in PR #7:
URL: https://github.com/apache/cassandra-accord/pull/7#discussion_r1014458432
##########
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:
Oops, my intent behind the question was non-sensical, I was looking at
`ifLocal` which is really there to detect requests routed to us for things we
don't own anymore (correct?).
Your point does seem valid though. We don't expect to go through recovery
multiple times often.
Is it also likely we will record the route as part of recovery to a command
store?
--
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]