Package org.apache.cassandra.locator
Class AbstractReplicationStrategy
java.lang.Object
org.apache.cassandra.locator.AbstractReplicationStrategy
- Direct Known Subclasses:
LocalStrategy,NetworkTopologyStrategy,SimpleStrategy
A abstract parent for all replication strategies.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractReplicationStrategy(String keyspaceName, TokenMetadata tokenMetadata, IEndpointSnitch snitch, Map<String, String> configOptions) -
Method Summary
Modifier and TypeMethodDescriptionabstract EndpointsForRangecalculateNaturalReplicas(Token searchToken, TokenMetadata tokenMetadata) Calculate the natural endpoints for the given token.static AbstractReplicationStrategycreateReplicationStrategy(String keyspaceName, Class<? extends AbstractReplicationStrategy> strategyClass, TokenMetadata tokenMetadata, IEndpointSnitch snitch, Map<String, String> strategyOptions) getAddressReplicas(InetAddressAndPort endpoint) getAddressReplicas(TokenMetadata metadata) getAddressReplicas(TokenMetadata metadata, InetAddressAndPort endpoint) getCachedReplicas(long ringVersion, Token t) static Class<AbstractReplicationStrategy>getLocalReplicaFor(Token searchPosition) getNaturalReplicas(RingPosition<?> searchPosition) getNaturalReplicasForToken(RingPosition<?> searchPosition) get the (possibly cached) endpoints that should store the given Token.getPendingAddressRanges(TokenMetadata metadata, Collection<Token> pendingTokens, InetAddressAndPort pendingAddress) getPendingAddressRanges(TokenMetadata metadata, Token pendingToken, InetAddressAndPort pendingAddress) getRangeAddresses(TokenMetadata metadata) abstract ReplicationFactorcalculate the RF based on strategy_options.<T> AbstractWriteResponseHandler<T>getWriteResponseHandler(ReplicaPlan.ForWrite replicaPlan, Runnable callback, WriteType writeType, Supplier<Mutation> hintOnFailure, Dispatcher.RequestTime requestTime) <T> AbstractWriteResponseHandler<T>getWriteResponseHandler(ReplicaPlan.ForWrite replicaPlan, Runnable callback, WriteType writeType, Supplier<Mutation> hintOnFailure, Dispatcher.RequestTime requestTime, ConsistencyLevel idealConsistencyLevel) booleanbooleanbooleanCheck if the token is in a naturally replicated range or pending rangevoidDeprecated.See CASSANDRA-17212voidmaybeWarnOnOptions(ClientState state) static voidprepareReplicationStrategyOptions(Class<? extends AbstractReplicationStrategy> strategyClass, Map<String, String> strategyOptions, Map<String, String> previousStrategyOptions) Before constructing the ARS we first give it a chance to prepare the options map in any way it would like to.protected voidabstract voidprotected voidstatic voidvalidateReplicationStrategy(String keyspaceName, Class<? extends AbstractReplicationStrategy> strategyClass, TokenMetadata tokenMetadata, IEndpointSnitch snitch, Map<String, String> strategyOptions, ClientState state)
-
Field Details
-
configOptions
-
keyspaceName
-
snitch
-
-
Constructor Details
-
AbstractReplicationStrategy
protected AbstractReplicationStrategy(String keyspaceName, TokenMetadata tokenMetadata, IEndpointSnitch snitch, Map<String, String> configOptions)
-
-
Method Details
-
getCachedReplicas
-
getNaturalReplicasForToken
get the (possibly cached) endpoints that should store the given Token. Note that while the endpoints are conceptually a Set (no duplicates will be included), we return a List to avoid an extra allocation when sorting by proximity later- Parameters:
searchPosition- the position the natural endpoints are requested for- Returns:
- a copy of the natural endpoints for the given token
-
getNaturalReplicas
-
isTokenInLocalNaturalOrPendingRange
Check if the token is in a naturally replicated range or pending range- Parameters:
token- the position to check- Returns:
- true if the token is in a natural or pending locally replicationed range, false otherwise
-
getLocalReplicaFor
-
calculateNaturalReplicas
public abstract EndpointsForRange calculateNaturalReplicas(Token searchToken, TokenMetadata tokenMetadata) Calculate the natural endpoints for the given token. Endpoints are returned in the order they occur in the ring following the searchToken, as defined by the replication strategy. Note that the order of the replicas is _implicitly relied upon_ by the definition of "primary" range inStorageService.getPrimaryRangesForEndpoint(String, InetAddressAndPort)which is in turn relied on by various components like repair and size estimate calculations.- Parameters:
tokenMetadata- the token metadata used to find the searchToken, e.g. contains token to endpoint mapping informationsearchToken- the token to find the natural endpoints for- Returns:
- a copy of the natural endpoints for the given token
- See Also:
-
getWriteResponseHandler
public <T> AbstractWriteResponseHandler<T> getWriteResponseHandler(ReplicaPlan.ForWrite replicaPlan, Runnable callback, WriteType writeType, Supplier<Mutation> hintOnFailure, Dispatcher.RequestTime requestTime) -
getWriteResponseHandler
public <T> AbstractWriteResponseHandler<T> getWriteResponseHandler(ReplicaPlan.ForWrite replicaPlan, Runnable callback, WriteType writeType, Supplier<Mutation> hintOnFailure, Dispatcher.RequestTime requestTime, ConsistencyLevel idealConsistencyLevel) -
getReplicationFactor
calculate the RF based on strategy_options. When overwriting, ensure that this get() is FAST, as this is called often.- Returns:
- the replication factor
-
hasTransientReplicas
public boolean hasTransientReplicas() -
getAddressReplicas
-
getAddressReplicas
-
getRangeAddresses
-
getAddressReplicas
-
getAddressReplicas
-
getPendingAddressRanges
public RangesAtEndpoint getPendingAddressRanges(TokenMetadata metadata, Token pendingToken, InetAddressAndPort pendingAddress) -
getPendingAddressRanges
public RangesAtEndpoint getPendingAddressRanges(TokenMetadata metadata, Collection<Token> pendingTokens, InetAddressAndPort pendingAddress) -
validateOptions
- Throws:
ConfigurationException
-
maybeWarnOnOptions
Deprecated.See CASSANDRA-17212 -
maybeWarnOnOptions
-
recognizedOptions
-
createReplicationStrategy
public static AbstractReplicationStrategy createReplicationStrategy(String keyspaceName, Class<? extends AbstractReplicationStrategy> strategyClass, TokenMetadata tokenMetadata, IEndpointSnitch snitch, Map<String, String> strategyOptions) -
prepareReplicationStrategyOptions
public static void prepareReplicationStrategyOptions(Class<? extends AbstractReplicationStrategy> strategyClass, Map<String, String> strategyOptions, Map<String, String> previousStrategyOptions) Before constructing the ARS we first give it a chance to prepare the options map in any way it would like to. For example datacenter auto-expansion or other templating to make the user interface more usable. Note that this may mutate the passed strategyOptions Map. We do this prior to the construction of the strategyClass itself because at that point the option map is already immutable and comes fromReplicationParams(and should probably stay that way so we don't start having bugs related to ReplicationParams being mutable). Instead ARS classes get a static hook here via the prepareOptions(Map, Map) method to mutate the user input before it becomes an immutable part of the ReplicationParams.- Parameters:
strategyClass- The class to call prepareOptions onstrategyOptions- The proposed strategy options that will be potentially mutated by the prepareOptions method.previousStrategyOptions- In the case of an ALTER statement, the previous strategy options of this class. This map cannot be mutated.
-
validateReplicationStrategy
public static void validateReplicationStrategy(String keyspaceName, Class<? extends AbstractReplicationStrategy> strategyClass, TokenMetadata tokenMetadata, IEndpointSnitch snitch, Map<String, String> strategyOptions, ClientState state) throws ConfigurationException- Throws:
ConfigurationException
-
getClass
- Throws:
ConfigurationException
-
hasSameSettings
-
validateReplicationFactor
- Throws:
ConfigurationException
-
validateExpectedOptions
- Throws:
ConfigurationException
-