Package org.apache.cassandra.locator
Class ReplicaPlans
- java.lang.Object
-
- org.apache.cassandra.locator.ReplicaPlans
-
public class ReplicaPlans extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ReplicaPlans.Selector
-
Field Summary
Fields Modifier and Type Field Description static ReplicaPlans.Selector
writeAll
Select all nodes, transient or otherwise, as targets for the operation.static ReplicaPlans.Selector
writeNormal
Select all full nodes, live or down, as write targets.
-
Constructor Summary
Constructors Constructor Description ReplicaPlans()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Collection<InetAddressAndPort>
filterBatchlogEndpoints(java.lang.String localRack, com.google.common.collect.Multimap<java.lang.String,InetAddressAndPort> endpoints, java.util.function.Consumer<java.util.List<?>> shuffle, java.util.function.Predicate<InetAddressAndPort> isAlive, java.util.function.Function<java.lang.Integer,java.lang.Integer> indexPicker)
static ReplicaPlan.ForWrite
forBatchlogWrite(boolean isAny)
Requires that the provided endpoints are alive.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)static ReplicaPlan.ForWrite
forLocalBatchlogWrite()
static ReplicaPlan.ForPaxosWrite
forPaxos(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.ForRangeRead
forRangeRead(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.ForTokenRead
forRead(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.ForWrite
forReadRepair(Token token, ReplicaPlan<?,?> readPlan)
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-repairstatic ReplicaPlan.ForTokenRead
forSingleReplicaRead(Keyspace keyspace, Token token, Replica replica)
Construct a plan for reading from a single node - this permits no speculation or read-repairstatic ReplicaPlan.ForWrite
forSingleReplicaWrite(Keyspace keyspace, Token token, Replica replica)
Construct a ReplicaPlan for writing to exactly one node, with CL.ONE.static ReplicaPlan.ForWrite
forWrite(Keyspace keyspace, ConsistencyLevel consistencyLevel, Token token, ReplicaPlans.Selector selector)
static ReplicaPlan.ForWrite
forWrite(Keyspace keyspace, ConsistencyLevel consistencyLevel, EndpointsForToken natural, EndpointsForToken pending, java.util.function.Predicate<Replica> isAlive, ReplicaPlans.Selector selector)
static ReplicaPlan.ForWrite
forWrite(Keyspace keyspace, ConsistencyLevel consistencyLevel, ReplicaLayout.ForTokenWrite liveAndDown, ReplicaLayout.ForTokenWrite live, ReplicaPlans.Selector selector)
static ReplicaPlan.ForWrite
forWrite(Keyspace keyspace, ConsistencyLevel consistencyLevel, ReplicaLayout.ForTokenWrite liveAndDown, ReplicaPlans.Selector selector)
static boolean
isSufficientLiveReplicasForRead(AbstractReplicationStrategy replicationStrategy, ConsistencyLevel consistencyLevel, Endpoints<?> liveReplicas)
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 planstatic ReplicaPlans.Selector
writeReadRepair(ReplicaPlan<?,?> readPlan)
TODO: Transient Replication C-14404/C-14665 TODO: We employ this even when there is no monotonicity to guarantee, e.g.
-
-
-
Field Detail
-
writeAll
public static final ReplicaPlans.Selector 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
public static final ReplicaPlans.Selector 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.
-
-
Method Detail
-
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
public static ReplicaPlan.ForWrite forLocalBatchlogWrite()
-
forBatchlogWrite
public static ReplicaPlan.ForWrite forBatchlogWrite(boolean isAny) throws UnavailableException
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 java.util.Collection<InetAddressAndPort> filterBatchlogEndpoints(java.lang.String localRack, com.google.common.collect.Multimap<java.lang.String,InetAddressAndPort> endpoints, java.util.function.Consumer<java.util.List<?>> shuffle, java.util.function.Predicate<InetAddressAndPort> isAlive, java.util.function.Function<java.lang.Integer,java.lang.Integer> indexPicker)
-
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, java.util.function.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
public static ReplicaPlans.Selector writeReadRepair(ReplicaPlan<?,?> readPlan)
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.
-
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
-
-