Package org.apache.cassandra.locator
Class NetworkTopologyStrategy
- java.lang.Object
-
- org.apache.cassandra.locator.AbstractReplicationStrategy
-
- org.apache.cassandra.locator.NetworkTopologyStrategy
-
public class NetworkTopologyStrategy extends AbstractReplicationStrategy
This Replication Strategy takes a property file that gives the intended replication factor in each datacenter. The sum total of the datacenter replication factor values should be equal to the keyspace replication factor.
So for example, if the keyspace replication factor is 6, the datacenter replication factors could be 3, 2, and 1 - so 3 replicas in one datacenter, 2 in another, and 1 in another - totaling 6.
This class also caches the Endpoints and invalidates the cache if there is a change in the number of tokens.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
REPLICATION_FACTOR
-
Fields inherited from class org.apache.cassandra.locator.AbstractReplicationStrategy
configOptions, keyspaceName, snitch
-
-
Constructor Summary
Constructors Constructor Description NetworkTopologyStrategy(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 Concrete Methods Modifier and Type Method Description EndpointsForRange
calculateNaturalReplicas(Token searchToken, TokenMetadata tokenMetadata)
calculate endpoints in one pass through the tokens by tracking our progress in each DC.java.util.Set<java.lang.String>
getDatacenters()
ReplicationFactor
getReplicationFactor()
calculate the RF based on strategy_options.ReplicationFactor
getReplicationFactor(java.lang.String dc)
boolean
hasSameSettings(AbstractReplicationStrategy other)
void
maybeWarnOnOptions(ClientState state)
protected static void
prepareOptions(java.util.Map<java.lang.String,java.lang.String> options, java.util.Map<java.lang.String,java.lang.String> previousOptions)
Support datacenter auto-expansion for CASSANDRA-14303.java.util.Collection<java.lang.String>
recognizedOptions()
protected void
validateExpectedOptions()
void
validateOptions()
-
Methods inherited from class org.apache.cassandra.locator.AbstractReplicationStrategy
createReplicationStrategy, getAddressReplicas, getAddressReplicas, getAddressReplicas, getAddressReplicas, getCachedReplicas, getClass, getLocalReplicaFor, getNaturalReplicas, getNaturalReplicasForToken, getPendingAddressRanges, getPendingAddressRanges, getRangeAddresses, getWriteResponseHandler, getWriteResponseHandler, hasTransientReplicas, maybeWarnOnOptions, prepareReplicationStrategyOptions, validateReplicationFactor, validateReplicationStrategy
-
-
-
-
Field Detail
-
REPLICATION_FACTOR
public static final java.lang.String REPLICATION_FACTOR
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
NetworkTopologyStrategy
public NetworkTopologyStrategy(java.lang.String keyspaceName, TokenMetadata tokenMetadata, IEndpointSnitch snitch, java.util.Map<java.lang.String,java.lang.String> configOptions) throws ConfigurationException
- Throws:
ConfigurationException
-
-
Method Detail
-
calculateNaturalReplicas
public EndpointsForRange calculateNaturalReplicas(Token searchToken, TokenMetadata tokenMetadata)
calculate endpoints in one pass through the tokens by tracking our progress in each DC.- Specified by:
calculateNaturalReplicas
in classAbstractReplicationStrategy
- Parameters:
searchToken
- the token to find the natural endpoints fortokenMetadata
- the token metadata used to find the searchToken, e.g. contains token to endpoint mapping information- Returns:
- a copy of the natural endpoints for the given token
- See Also:
AbstractReplicationStrategy.getNaturalReplicasForToken(org.apache.cassandra.dht.RingPosition)
-
getReplicationFactor
public ReplicationFactor getReplicationFactor()
Description copied from class:AbstractReplicationStrategy
calculate the RF based on strategy_options. When overwriting, ensure that this get() is FAST, as this is called often.- Specified by:
getReplicationFactor
in classAbstractReplicationStrategy
- Returns:
- the replication factor
-
getReplicationFactor
public ReplicationFactor getReplicationFactor(java.lang.String dc)
-
getDatacenters
public java.util.Set<java.lang.String> getDatacenters()
-
recognizedOptions
public java.util.Collection<java.lang.String> recognizedOptions()
- Overrides:
recognizedOptions
in classAbstractReplicationStrategy
-
prepareOptions
protected static void prepareOptions(java.util.Map<java.lang.String,java.lang.String> options, java.util.Map<java.lang.String,java.lang.String> previousOptions)
Support datacenter auto-expansion for CASSANDRA-14303. This hook allows us to safely auto-expand the "replication_factor" options out into the known datacenters. It is called via reflection fromAbstractReplicationStrategy.prepareReplicationStrategyOptions(Class, Map, Map)
.- Parameters:
options
- The proposed strategy options that will be potentially mutated. If empty, replication_factor will be added either from previousOptions if one exists, or from default_keyspace_rf configuration.previousOptions
- Any previous strategy options in the case of an ALTER statement
-
validateExpectedOptions
protected void validateExpectedOptions() throws ConfigurationException
- Overrides:
validateExpectedOptions
in classAbstractReplicationStrategy
- Throws:
ConfigurationException
-
validateOptions
public void validateOptions() throws ConfigurationException
- Specified by:
validateOptions
in classAbstractReplicationStrategy
- Throws:
ConfigurationException
-
maybeWarnOnOptions
public void maybeWarnOnOptions(ClientState state)
- Overrides:
maybeWarnOnOptions
in classAbstractReplicationStrategy
-
hasSameSettings
public boolean hasSameSettings(AbstractReplicationStrategy other)
- Overrides:
hasSameSettings
in classAbstractReplicationStrategy
-
-