Package org.apache.cassandra.locator
Class ReplicaPlans
java.lang.Object
org.apache.cassandra.locator.ReplicaPlans
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ReplicaPlans.SelectorSelect all nodes, transient or otherwise, as targets for the operation.static final ReplicaPlans.SelectorSelect all full nodes, live or down, as write targets. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Collection<InetAddressAndPort>filterBatchlogEndpoints(boolean preferLocalRack, String localRack, com.google.common.collect.Multimap<String, InetAddressAndPort> endpoints) static Collection<InetAddressAndPort>filterBatchlogEndpointsDynamic(boolean preferLocalRack, String localRack, com.google.common.collect.Multimap<String, InetAddressAndPort> endpoints, Predicate<InetAddressAndPort> isAlive) static Collection<InetAddressAndPort>filterBatchlogEndpointsRandom(boolean preferLocalRack, String localRack, com.google.common.collect.Multimap<String, InetAddressAndPort> endpoints, Consumer<List<?>> shuffle, Predicate<InetAddressAndPort> isAlive, Function<Integer, Integer> indexPicker) static ReplicaPlan.ForWriteforBatchlogWrite(boolean isAny) Requires that the provided endpoints are alive.static ReplicaPlan.ForWriteforForwardingCounterWrite(Keyspace keyspace, Token token, Replica replica) A forwarding counter write is always sent to a single owning coordinator for the range, by the original coordinator (if it is not itself an owner)static ReplicaPlan.ForRangeReadforFullRangeRead(Keyspace keyspace, ConsistencyLevel consistencyLevel, AbstractBounds<PartitionPosition> range, Set<InetAddressAndPort> endpointsToContact, int vnodeCount) Construct a plan for reading the provided range at the provided consistency level on given endpoints.static ReplicaPlan.ForWritestatic ReplicaPlan.ForPaxosWriteforPaxos(Keyspace keyspace, DecoratedKey key, ConsistencyLevel consistencyForPaxos) Construct the plan for a paxos round - NOT the write or read consistency level for either the write or comparison, but for the paxos linearisation agreement.static ReplicaPlan.ForRangeReadforRangeRead(Keyspace keyspace, Index.QueryPlan indexQueryPlan, ConsistencyLevel consistencyLevel, AbstractBounds<PartitionPosition> range, int vnodeCount) Construct a plan for reading the provided range at the provided consistency level.static ReplicaPlan.ForTokenReadforRead(Keyspace keyspace, Token token, Index.QueryPlan indexQueryPlan, ConsistencyLevel consistencyLevel, SpeculativeRetryPolicy retry) Construct a plan for reading the provided token at the provided consistency level.static ReplicaPlan.ForWriteforReadRepair(Token token, ReplicaPlan<?, ?> readPlan) static ReplicaPlan.ForRangeReadforSingleReplicaRead(Keyspace keyspace, AbstractBounds<PartitionPosition> range, Replica replica, int vnodeCount) Construct a plan for reading from a single node - this permits no speculation or read-repairstatic ReplicaPlan.ForTokenReadforSingleReplicaRead(Keyspace keyspace, Token token, Replica replica) Construct a plan for reading from a single node - this permits no speculation or read-repairstatic ReplicaPlan.ForWriteforSingleReplicaWrite(Keyspace keyspace, Token token, Replica replica) Construct a ReplicaPlan for writing to exactly one node, with CL.ONE.static ReplicaPlan.ForWriteforWrite(Keyspace keyspace, ConsistencyLevel consistencyLevel, Token token, ReplicaPlans.Selector selector) static ReplicaPlan.ForWriteforWrite(Keyspace keyspace, ConsistencyLevel consistencyLevel, EndpointsForToken natural, EndpointsForToken pending, Predicate<Replica> isAlive, ReplicaPlans.Selector selector) static ReplicaPlan.ForWriteforWrite(Keyspace keyspace, ConsistencyLevel consistencyLevel, ReplicaLayout.ForTokenWrite liveAndDown, ReplicaLayout.ForTokenWrite live, ReplicaPlans.Selector selector) static ReplicaPlan.ForWriteforWrite(Keyspace keyspace, ConsistencyLevel consistencyLevel, ReplicaLayout.ForTokenWrite liveAndDown, ReplicaPlans.Selector selector) static booleanisSufficientLiveReplicasForRead(AbstractReplicationStrategy replicationStrategy, ConsistencyLevel consistencyLevel, Endpoints<?> liveReplicas) static ReplicaPlan.ForRangeReadmaybeMerge(Keyspace keyspace, ConsistencyLevel consistencyLevel, ReplicaPlan.ForRangeRead left, ReplicaPlan.ForRangeRead right) Take two range read plans for adjacent ranges, and check if it is OK (and worthwhile) to combine them into a single planstatic List<InetAddressAndPort>sortByProximity(Collection<InetAddressAndPort> endpoints) static ReplicaPlans.SelectorwriteReadRepair(ReplicaPlan<?, ?> readPlan) TODO: Transient Replication C-14404/C-14665 TODO: We employ this even when there is no monotonicity to guarantee, e.g.
-
Field Details
-
writeAll
Select all nodes, transient or otherwise, as targets for the operation. This is may no longer be useful once we finish implementing transient replication support, however it can be of value to stipulate that a location writes to all nodes without regard to transient status. -
writeNormal
Select all full nodes, live or down, as write targets. If there are insufficient nodes to complete the write, but there are live transient nodes, select a sufficient number of these to reach our consistency level. Pending nodes are always contacted, whether or not they are full. When a transient replica is undergoing a pending move to a new node, if we write (transiently) to it, this write would not be replicated to the pending transient node, and so when completing the move, the write could effectively have not reached the promised consistency level.
-
-
Constructor Details
-
ReplicaPlans
public ReplicaPlans()
-
-
Method Details
-
isSufficientLiveReplicasForRead
public static boolean isSufficientLiveReplicasForRead(AbstractReplicationStrategy replicationStrategy, ConsistencyLevel consistencyLevel, Endpoints<?> liveReplicas) -
forSingleReplicaWrite
public static ReplicaPlan.ForWrite forSingleReplicaWrite(Keyspace keyspace, Token token, Replica replica) Construct a ReplicaPlan for writing to exactly one node, with CL.ONE. This node is *assumed* to be alive. -
forForwardingCounterWrite
public static ReplicaPlan.ForWrite forForwardingCounterWrite(Keyspace keyspace, Token token, Replica replica) A forwarding counter write is always sent to a single owning coordinator for the range, by the original coordinator (if it is not itself an owner) -
forLocalBatchlogWrite
-
forBatchlogWrite
Requires that the provided endpoints are alive. Converts them to their relevant system replicas. Note that the liveAndDown collection and live are equal to the provided endpoints.- Parameters:
isAny- if batch consistency level is ANY, in which case a local node will be picked- Throws:
UnavailableException
-
filterBatchlogEndpoints
public static Collection<InetAddressAndPort> filterBatchlogEndpoints(boolean preferLocalRack, String localRack, com.google.common.collect.Multimap<String, InetAddressAndPort> endpoints) -
filterBatchlogEndpointsRandom
public static Collection<InetAddressAndPort> filterBatchlogEndpointsRandom(boolean preferLocalRack, String localRack, com.google.common.collect.Multimap<String, InetAddressAndPort> endpoints, Consumer<List<?>> shuffle, Predicate<InetAddressAndPort> isAlive, Function<Integer, Integer> indexPicker) -
filterBatchlogEndpointsDynamic
public static Collection<InetAddressAndPort> filterBatchlogEndpointsDynamic(boolean preferLocalRack, String localRack, com.google.common.collect.Multimap<String, InetAddressAndPort> endpoints, Predicate<InetAddressAndPort> isAlive) -
sortByProximity
-
forReadRepair
public static ReplicaPlan.ForWrite forReadRepair(Token token, ReplicaPlan<?, ?> readPlan) throws UnavailableException- Throws:
UnavailableException
-
forWrite
public static ReplicaPlan.ForWrite forWrite(Keyspace keyspace, ConsistencyLevel consistencyLevel, Token token, ReplicaPlans.Selector selector) throws UnavailableException - Throws:
UnavailableException
-
forWrite
public static ReplicaPlan.ForWrite forWrite(Keyspace keyspace, ConsistencyLevel consistencyLevel, EndpointsForToken natural, EndpointsForToken pending, Predicate<Replica> isAlive, ReplicaPlans.Selector selector) throws UnavailableException - Throws:
UnavailableException
-
forWrite
public static ReplicaPlan.ForWrite forWrite(Keyspace keyspace, ConsistencyLevel consistencyLevel, ReplicaLayout.ForTokenWrite liveAndDown, ReplicaPlans.Selector selector) throws UnavailableException - Throws:
UnavailableException
-
forWrite
public static ReplicaPlan.ForWrite forWrite(Keyspace keyspace, ConsistencyLevel consistencyLevel, ReplicaLayout.ForTokenWrite liveAndDown, ReplicaLayout.ForTokenWrite live, ReplicaPlans.Selector selector) throws UnavailableException - Throws:
UnavailableException
-
writeReadRepair
TODO: Transient Replication C-14404/C-14665 TODO: We employ this even when there is no monotonicity to guarantee, e.g. in case of CL.TWO, CL.ONE with speculation, etc. Construct a read-repair write plan to provide monotonicity guarantees on any data we return as part of a read. Since this is not a regular write, this is just to guarantee future reads will read this data, we select only the minimal number of nodes to meet the consistency level, and prefer nodes we contacted on read to minimise data transfer. -
forPaxos
public static ReplicaPlan.ForPaxosWrite forPaxos(Keyspace keyspace, DecoratedKey key, ConsistencyLevel consistencyForPaxos) throws UnavailableException Construct the plan for a paxos round - NOT the write or read consistency level for either the write or comparison, but for the paxos linearisation agreement. This will select all live nodes as the candidates for the operation. Only the required number of participants- Throws:
UnavailableException
-
forSingleReplicaRead
public static ReplicaPlan.ForTokenRead forSingleReplicaRead(Keyspace keyspace, Token token, Replica replica) Construct a plan for reading from a single node - this permits no speculation or read-repair -
forSingleReplicaRead
public static ReplicaPlan.ForRangeRead forSingleReplicaRead(Keyspace keyspace, AbstractBounds<PartitionPosition> range, Replica replica, int vnodeCount) Construct a plan for reading from a single node - this permits no speculation or read-repair -
forRead
public static ReplicaPlan.ForTokenRead forRead(Keyspace keyspace, Token token, @Nullable Index.QueryPlan indexQueryPlan, ConsistencyLevel consistencyLevel, SpeculativeRetryPolicy retry) Construct a plan for reading the provided token at the provided consistency level. This translates to a collection of - candidates who are: alive, replicate the token, and are sorted by their snitch scores - contacts who are: the first blockFor + (retry == ALWAYS ? 1 : 0) candidates The candidate collection can be used for speculation, although at present it would break EACH_QUORUM to do so without further filtering -
forRangeRead
public static ReplicaPlan.ForRangeRead forRangeRead(Keyspace keyspace, @Nullable Index.QueryPlan indexQueryPlan, ConsistencyLevel consistencyLevel, AbstractBounds<PartitionPosition> range, int vnodeCount) Construct a plan for reading the provided range at the provided consistency level. This translates to a collection of - candidates who are: alive, replicate the range, and are sorted by their snitch scores - contacts who are: the first blockFor candidates There is no speculation for range read queries at present, so we never 'always speculate' here, and a failed response fails the query. -
forFullRangeRead
public static ReplicaPlan.ForRangeRead forFullRangeRead(Keyspace keyspace, ConsistencyLevel consistencyLevel, AbstractBounds<PartitionPosition> range, Set<InetAddressAndPort> endpointsToContact, int vnodeCount) Construct a plan for reading the provided range at the provided consistency level on given endpoints. Note that: - given range may span multiple vnodes - endpoints should be alive and satifies consistency requirement. - each endpoint will be considered as replica of entire token ring, so coordinator can execute request with given range -
maybeMerge
public static ReplicaPlan.ForRangeRead maybeMerge(Keyspace keyspace, ConsistencyLevel consistencyLevel, ReplicaPlan.ForRangeRead left, ReplicaPlan.ForRangeRead right) Take two range read plans for adjacent ranges, and check if it is OK (and worthwhile) to combine them into a single plan
-