bdeggleston commented on code in PR #66:
URL: https://github.com/apache/cassandra-accord/pull/66#discussion_r1346245913
##########
accord-core/src/main/java/accord/coordinate/CoordinateSyncPoint.java:
##########
@@ -19,74 +19,114 @@
package accord.coordinate;
import java.util.List;
+import java.util.function.BiConsumer;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import accord.local.Node;
import accord.messages.Apply;
import accord.messages.PreAccept.PreAcceptOk;
import accord.primitives.Ballot;
import accord.primitives.Deps;
-import accord.primitives.FullRangeRoute;
import accord.primitives.FullRoute;
-import accord.primitives.Ranges;
+import accord.primitives.Seekables;
import accord.primitives.SyncPoint;
import accord.primitives.Timestamp;
import accord.primitives.Txn;
import accord.primitives.Txn.Kind;
import accord.primitives.TxnId;
import accord.topology.Topologies;
+import accord.utils.async.AsyncChains;
import accord.utils.async.AsyncResult;
-import accord.utils.Invariants;
import static accord.coordinate.Propose.Invalidate.proposeAndCommitInvalidate;
import static accord.primitives.Timestamp.mergeMax;
import static accord.primitives.Txn.Kind.ExclusiveSyncPoint;
import static accord.utils.Functions.foldl;
+import static accord.utils.Invariants.checkArgument;
+import static accord.utils.Invariants.checkState;
/**
* Perform initial rounds of PreAccept and Accept until we have reached
agreement about when we should execute.
* If we are preempted by a recovery coordinator, we abort and let them
complete (and notify us about the execution result)
*
* TODO (desired, testing): dedicated burn test to validate outcomes
*/
-public class CoordinateSyncPoint extends CoordinatePreAccept<SyncPoint>
+public class CoordinateSyncPoint<S extends Seekables<?, ?>> extends
CoordinatePreAccept<SyncPoint<S>>
{
- final Ranges ranges;
- private CoordinateSyncPoint(Node node, TxnId txnId, Txn txn, FullRoute<?>
route, Ranges ranges)
+ @SuppressWarnings("unused")
+ private static final Logger logger =
LoggerFactory.getLogger(CoordinateSyncPoint.class);
+
+ final S keysOrRanges;
+ // Whether to wait on the dependencies applying globally before returning
a result
+ final boolean async;
+
+ private CoordinateSyncPoint(Node node, TxnId txnId, Txn txn, FullRoute<?>
route, S keysOrRanges, boolean async)
{
super(node, txnId, txn, route, node.topology().withOpenEpochs(route,
txnId, txnId));
- this.ranges = ranges;
+ checkArgument(txnId.rw() == Kind.SyncPoint || async, "Exclusive sync
points only support async application");
+ this.keysOrRanges = keysOrRanges;
+ this.async = async;
+ }
+
+ public static <S extends Seekables<?, ?>>
AsyncResult<CoordinateSyncPoint<S>> exclusive(Node node, S keysOrRanges)
+ {
+ return coordinate(node, ExclusiveSyncPoint, keysOrRanges, true);
}
- public static AsyncResult<SyncPoint> exclusive(Node node, Ranges
keysOrRanges)
+ public static <S extends Seekables<?, ?>> CoordinateSyncPoint<S>
exclusive(Node node, TxnId txnId, S keysOrRanges)
{
- return coordinate(node, ExclusiveSyncPoint, keysOrRanges);
+ return coordinate(node, txnId, keysOrRanges, true);
}
- public static AsyncResult<SyncPoint> inclusive(Node node, Ranges
keysOrRanges)
+ public static <S extends Seekables<?, ?>>
AsyncResult<CoordinateSyncPoint<S>> inclusive(Node node, S keysOrRanges,
boolean async)
{
- return coordinate(node, Kind.SyncPoint, keysOrRanges);
+ return coordinate(node, Kind.SyncPoint, keysOrRanges, async);
}
- private static AsyncResult<SyncPoint> coordinate(Node node, Kind kind,
Ranges ranges)
+ private static <S extends Seekables<?, ?>>
AsyncResult<CoordinateSyncPoint<S>> coordinate(Node node, Kind kind, S
keysOrRanges, boolean async)
{
- TxnId txnId = node.nextTxnId(kind, ranges.domain());
- return node.withEpoch(txnId.epoch(), () -> {
- FullRangeRoute route = (FullRangeRoute) node.computeRoute(txnId,
ranges);
- CoordinateSyncPoint coordinate = new CoordinateSyncPoint(node,
txnId, node.agent().emptyTxn(kind, ranges), route, ranges);
- coordinate.start();
- return coordinate;
- }).beginAsResult();
+ checkState(kind == Kind.SyncPoint || kind == ExclusiveSyncPoint);
Review Comment:
I think we'd want this to be a checkArgument?
--
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]