belliottsmith commented on code in PR #7:
URL: https://github.com/apache/cassandra-accord/pull/7#discussion_r1011900580
##########
accord-core/src/main/java/accord/coordinate/RecoverWithRoute.java:
##########
@@ -0,0 +1,133 @@
+package accord.coordinate;
+
+import java.util.Set;
+import java.util.function.BiConsumer;
+
+import accord.local.Status.ReplicationPhase;
+import accord.primitives.*;
+import com.google.common.base.Preconditions;
+
+import accord.local.Node;
+import accord.local.Node.Id;
+import accord.messages.CheckStatus;
+import accord.messages.CheckStatus.CheckStatusOk;
+import accord.messages.CheckStatus.CheckStatusOkFull;
+import accord.messages.CheckStatus.IncludeInfo;
+import accord.topology.Topologies;
+
+import static accord.local.Status.ReplicationPhase.None;
+import static accord.messages.Commit.Invalidate.commitInvalidate;
+import static accord.primitives.ProgressToken.APPLIED;
+import static accord.primitives.ProgressToken.INVALIDATED;
+
+public class RecoverWithRoute extends CheckShards
+{
+ final Ballot ballot;
+ final Route route;
+ final BiConsumer<Outcome, Throwable> callback;
+
+ private RecoverWithRoute(Node node, Topologies topologies, Ballot ballot,
TxnId txnId, Route route, BiConsumer<Outcome, Throwable> callback)
+ {
+ super(node, txnId, route, txnId.epoch, IncludeInfo.All);
+ this.ballot = ballot;
+ this.route = route;
+ this.callback = callback;
+ assert topologies.oldestEpoch() == topologies.currentEpoch() &&
topologies.currentEpoch() == txnId.epoch;
+ }
+
+ public static RecoverWithRoute recover(Node node, TxnId txnId, Route
route, BiConsumer<Outcome, Throwable> callback)
+ {
+ return recover(node, node.topology().forEpoch(route, txnId.epoch),
txnId, route, callback);
+ }
+
+ public static RecoverWithRoute recover(Node node, Topologies topologies,
TxnId txnId, Route route, BiConsumer<Outcome, Throwable> callback)
+ {
+ Ballot ballot = new Ballot(node.uniqueNow());
+ return recover(node, topologies, ballot, txnId, route, callback);
+ }
+
+ public static RecoverWithRoute recover(Node node, Ballot ballot, TxnId
txnId, Route route, BiConsumer<Outcome, Throwable> callback)
+ {
+ return recover(node, node.topology().forEpoch(route, txnId.epoch),
ballot, txnId, route, callback);
+ }
+
+ public static RecoverWithRoute recover(Node node, Topologies topologies,
Ballot ballot, TxnId txnId, Route route, BiConsumer<Outcome, Throwable>
callback)
+ {
+ RecoverWithRoute recover = new RecoverWithRoute(node, topologies,
ballot, txnId, route, callback);
+ recover.start();
+ return recover;
+ }
+
+ @Override
+ protected void contact(Set<Id> nodes)
+ {
+ node.send(nodes, to -> new CheckStatus(to, tracker.topologies(),
txnId, route, IncludeInfo.All), this);
+ }
+
+ @Override
+ protected boolean isSufficient(Id from, CheckStatusOk ok)
+ {
+ CheckStatusOkFull full = (CheckStatusOkFull)ok;
+ ReplicationPhase can = full.sufficientFor(route);
+ if (can == None)
+ return false;
+
+ if (can == ReplicationPhase.Invalidate)
+ return true;
+
+ KeyRanges rangesForNode =
tracker.topologies().forEpoch(txnId.epoch).rangesForNode(from);
+ PartialRoute route = this.route.slice(rangesForNode);
+ Preconditions.checkState(full.partialTxn.covers(route));
Review Comment:
The purpose of all of the `covers` collections is for invariant checking,
and I think they should remain runtime checks.
--
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]