Package org.apache.cassandra.locator
Class AbstractReplicationStrategy
- java.lang.Object
-
- org.apache.cassandra.locator.AbstractReplicationStrategy
-
- Direct Known Subclasses:
LocalStrategy
,NetworkTopologyStrategy
,SimpleStrategy
public abstract class AbstractReplicationStrategy extends java.lang.Object
A abstract parent for all replication strategies.
-
-
Field Summary
Fields Modifier and Type Field Description java.util.Map<java.lang.String,java.lang.String>
configOptions
protected java.lang.String
keyspaceName
IEndpointSnitch
snitch
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractReplicationStrategy(java.lang.String keyspaceName, TokenMetadata tokenMetadata, IEndpointSnitch snitch, java.util.Map<java.lang.String,java.lang.String> configOptions)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract EndpointsForRange
calculateNaturalReplicas(Token searchToken, TokenMetadata tokenMetadata)
Calculate the natural endpoints for the given token.static AbstractReplicationStrategy
createReplicationStrategy(java.lang.String keyspaceName, java.lang.Class<? extends AbstractReplicationStrategy> strategyClass, TokenMetadata tokenMetadata, IEndpointSnitch snitch, java.util.Map<java.lang.String,java.lang.String> strategyOptions)
RangesByEndpoint
getAddressReplicas()
RangesAtEndpoint
getAddressReplicas(InetAddressAndPort endpoint)
RangesByEndpoint
getAddressReplicas(TokenMetadata metadata)
RangesAtEndpoint
getAddressReplicas(TokenMetadata metadata, InetAddressAndPort endpoint)
EndpointsForRange
getCachedReplicas(long ringVersion, Token t)
static java.lang.Class<AbstractReplicationStrategy>
getClass(java.lang.String cls)
Replica
getLocalReplicaFor(RingPosition<?> searchPosition)
EndpointsForRange
getNaturalReplicas(RingPosition<?> searchPosition)
EndpointsForToken
getNaturalReplicasForToken(RingPosition<?> searchPosition)
get the (possibly cached) endpoints that should store the given Token.RangesAtEndpoint
getPendingAddressRanges(TokenMetadata metadata, java.util.Collection<Token> pendingTokens, InetAddressAndPort pendingAddress)
RangesAtEndpoint
getPendingAddressRanges(TokenMetadata metadata, Token pendingToken, InetAddressAndPort pendingAddress)
EndpointsByRange
getRangeAddresses(TokenMetadata metadata)
abstract ReplicationFactor
getReplicationFactor()
calculate the RF based on strategy_options.<T> AbstractWriteResponseHandler<T>
getWriteResponseHandler(ReplicaPlan.ForWrite replicaPlan, java.lang.Runnable callback, WriteType writeType, java.util.function.Supplier<Mutation> hintOnFailure, long queryStartNanoTime)
<T> AbstractWriteResponseHandler<T>
getWriteResponseHandler(ReplicaPlan.ForWrite replicaPlan, java.lang.Runnable callback, WriteType writeType, java.util.function.Supplier<Mutation> hintOnFailure, long queryStartNanoTime, ConsistencyLevel idealConsistencyLevel)
boolean
hasSameSettings(AbstractReplicationStrategy other)
boolean
hasTransientReplicas()
void
maybeWarnOnOptions()
Deprecated.void
maybeWarnOnOptions(ClientState state)
static void
prepareReplicationStrategyOptions(java.lang.Class<? extends AbstractReplicationStrategy> strategyClass, java.util.Map<java.lang.String,java.lang.String> strategyOptions, java.util.Map<java.lang.String,java.lang.String> previousStrategyOptions)
Before constructing the ARS we first give it a chance to prepare the options map in any way it would like to.java.util.Collection<java.lang.String>
recognizedOptions()
protected void
validateExpectedOptions()
abstract void
validateOptions()
protected void
validateReplicationFactor(java.lang.String s)
static void
validateReplicationStrategy(java.lang.String keyspaceName, java.lang.Class<? extends AbstractReplicationStrategy> strategyClass, TokenMetadata tokenMetadata, IEndpointSnitch snitch, java.util.Map<java.lang.String,java.lang.String> strategyOptions, ClientState state)
-
-
-
Field Detail
-
configOptions
public final java.util.Map<java.lang.String,java.lang.String> configOptions
-
keyspaceName
protected final java.lang.String keyspaceName
-
snitch
public IEndpointSnitch snitch
-
-
Constructor Detail
-
AbstractReplicationStrategy
protected AbstractReplicationStrategy(java.lang.String keyspaceName, TokenMetadata tokenMetadata, IEndpointSnitch snitch, java.util.Map<java.lang.String,java.lang.String> configOptions)
-
-
Method Detail
-
getCachedReplicas
public EndpointsForRange getCachedReplicas(long ringVersion, Token t)
-
getNaturalReplicasForToken
public EndpointsForToken getNaturalReplicasForToken(RingPosition<?> searchPosition)
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
public EndpointsForRange getNaturalReplicas(RingPosition<?> searchPosition)
-
getLocalReplicaFor
public Replica getLocalReplicaFor(RingPosition<?> searchPosition)
-
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:
getNaturalReplicasForToken(org.apache.cassandra.dht.RingPosition)
-
getWriteResponseHandler
public <T> AbstractWriteResponseHandler<T> getWriteResponseHandler(ReplicaPlan.ForWrite replicaPlan, java.lang.Runnable callback, WriteType writeType, java.util.function.Supplier<Mutation> hintOnFailure, long queryStartNanoTime)
-
getWriteResponseHandler
public <T> AbstractWriteResponseHandler<T> getWriteResponseHandler(ReplicaPlan.ForWrite replicaPlan, java.lang.Runnable callback, WriteType writeType, java.util.function.Supplier<Mutation> hintOnFailure, long queryStartNanoTime, ConsistencyLevel idealConsistencyLevel)
-
getReplicationFactor
public abstract ReplicationFactor 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
public RangesByEndpoint getAddressReplicas(TokenMetadata metadata)
-
getAddressReplicas
public RangesAtEndpoint getAddressReplicas(TokenMetadata metadata, InetAddressAndPort endpoint)
-
getRangeAddresses
public EndpointsByRange getRangeAddresses(TokenMetadata metadata)
-
getAddressReplicas
public RangesByEndpoint getAddressReplicas()
-
getAddressReplicas
public RangesAtEndpoint getAddressReplicas(InetAddressAndPort endpoint)
-
getPendingAddressRanges
public RangesAtEndpoint getPendingAddressRanges(TokenMetadata metadata, Token pendingToken, InetAddressAndPort pendingAddress)
-
getPendingAddressRanges
public RangesAtEndpoint getPendingAddressRanges(TokenMetadata metadata, java.util.Collection<Token> pendingTokens, InetAddressAndPort pendingAddress)
-
validateOptions
public abstract void validateOptions() throws ConfigurationException
- Throws:
ConfigurationException
-
maybeWarnOnOptions
@Deprecated public void maybeWarnOnOptions()
Deprecated.
-
maybeWarnOnOptions
public void maybeWarnOnOptions(ClientState state)
-
recognizedOptions
public java.util.Collection<java.lang.String> recognizedOptions()
-
createReplicationStrategy
public static AbstractReplicationStrategy createReplicationStrategy(java.lang.String keyspaceName, java.lang.Class<? extends AbstractReplicationStrategy> strategyClass, TokenMetadata tokenMetadata, IEndpointSnitch snitch, java.util.Map<java.lang.String,java.lang.String> strategyOptions)
-
prepareReplicationStrategyOptions
public static void prepareReplicationStrategyOptions(java.lang.Class<? extends AbstractReplicationStrategy> strategyClass, java.util.Map<java.lang.String,java.lang.String> strategyOptions, java.util.Map<java.lang.String,java.lang.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(java.lang.String keyspaceName, java.lang.Class<? extends AbstractReplicationStrategy> strategyClass, TokenMetadata tokenMetadata, IEndpointSnitch snitch, java.util.Map<java.lang.String,java.lang.String> strategyOptions, ClientState state) throws ConfigurationException
- Throws:
ConfigurationException
-
getClass
public static java.lang.Class<AbstractReplicationStrategy> getClass(java.lang.String cls) throws ConfigurationException
- Throws:
ConfigurationException
-
hasSameSettings
public boolean hasSameSettings(AbstractReplicationStrategy other)
-
validateReplicationFactor
protected void validateReplicationFactor(java.lang.String s) throws ConfigurationException
- Throws:
ConfigurationException
-
validateExpectedOptions
protected void validateExpectedOptions() throws ConfigurationException
- Throws:
ConfigurationException
-
-