Package org.apache.cassandra.locator
Class TokenMetadata
java.lang.Object
org.apache.cassandra.locator.TokenMetadata
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classTracks the assignment of racks and endpoints in each datacenter for all the "normal" endpoints in this TokenMetadata. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBootstrapTokens(Collection<Token> tokens, InetAddressAndPort endpoint) voidaddLeavingEndpoint(InetAddressAndPort endpoint) voidaddMovingEndpoint(Token token, InetAddressAndPort endpoint) Add a new moving endpointvoidaddReplaceTokens(Collection<Token> replacingTokens, InetAddressAndPort newNode, InetAddressAndPort oldNode) Return a cached TokenMetadata with only tokenToEndpointMap, i.e., the same as cloneOnlyTokenMap but uses a cached copy that is invalided when the ring changes, so in the common case no extra locking is required.voidcalculatePendingRanges(AbstractReplicationStrategy strategy, String keyspaceName) Calculate pending ranges according to bootsrapping and leaving nodes.voidused by testsCreate a copy of TokenMetadata with tokenToEndpointMap reflecting situation after all current leave operations have finished.Create a copy of TokenMetadata with tokenToEndpointMap reflecting situation after all current leave, and move operations have finished.Create a copy of TokenMetadata with only tokenToEndpointMap.cloneWithNewPartitioner(IPartitioner newPartitioner) To be used by tests only (viaStorageService.setPartitionerUnsafe(org.apache.cassandra.dht.IPartitioner)).decorateKey(ByteBuffer key) static TokenfirstToken(ArrayList<Token> ring, Token start) static intfirstTokenIndex(ArrayList<Token> ring, Token start, boolean insertMin) com.google.common.collect.ImmutableMultimap<String,InetAddressAndPort> getDC2AllEndpoints(IEndpointSnitch snitch) getEndpoint(Token token) getEndpointForHostId(UUID hostId) Return the end-point for a unique host IDcom.google.common.collect.Multimap<InetAddressAndPort,Token> getHostId(InetAddressAndPort endpoint) Return the unique host ID for an end-point.caller should not modify leavingEndpointsEndpoints which are migrating to the new tokensgetPendingRanges(String keyspaceName) a mutable map may be returned but caller should not modify itgetPendingRanges(String keyspaceName, InetAddressAndPort endpoint) getPendingRangesMM(String keyspaceName) getPredecessor(Token token) getPrimaryRangesFor(Collection<Token> tokens) getReplacementNode(InetAddressAndPort endpoint) getReplacingNode(InetAddressAndPort endpoint) longintintintgetSuccessor(Token token) getTokens(InetAddressAndPort endpoint) getWriteEndpoints(Token token, String keyspaceName, EndpointsForToken natural) Deprecated.retained for benefit of old testsvoidbooleanisLeaving(InetAddressAndPort endpoint) booleanisMember(InetAddressAndPort endpoint) booleanisMoving(InetAddressAndPort endpoint) booleanisTokenInLocalPendingRange(String keyspaceName, Token token) pendingEndpointsForToken(Token token, String keyspaceName) intvoidremoveBootstrapTokens(Collection<Token> tokens) voidremoveEndpoint(InetAddressAndPort endpoint) voidremoveFromMoving(InetAddressAndPort endpoint) Remove pair of token/address from moving endpointsringIterator(ArrayList<Token> ring, Token start, boolean includeMin) iterator over the Tokens in the given ring, starting with the token for the node owning start (which does not have to be a Token in the ring)voidsetPendingRangesUnsafe(String keyspaceName, com.google.common.collect.Multimap<Range<Token>, Replica> rangeMap) toString()voidunsafeCalculatePendingRanges(AbstractReplicationStrategy strategy, String keyspaceName) voidupdateHostId(UUID hostId, InetAddressAndPort endpoint) Store an end-point to host ID mapping.voidupdateHostIds(Map<UUID, InetAddressAndPort> hostIdToEndpointMap) voidupdateNormalToken(Token token, InetAddressAndPort endpoint) Update token map with a single token/endpoint pair in normal state.voidupdateNormalTokens(com.google.common.collect.Multimap<InetAddressAndPort, Token> endpointTokens) Update token map with a set of token/endpoint pairs in normal state.voidupdateNormalTokens(Collection<Token> tokens, InetAddressAndPort endpoint) This is called when the snitch properties for many endpoints are updated, it will update the topology mappings of any endpoints whose snitch has changed, see CASSANDRA-10238.updateTopology(InetAddressAndPort endpoint) This is called when the snitch properties for this endpoint are updated, see CASSANDRA-10238.
-
Field Details
-
partitioner
-
-
Constructor Details
-
TokenMetadata
public TokenMetadata() -
TokenMetadata
-
-
Method Details
-
cloneWithNewPartitioner
To be used by tests only (viaStorageService.setPartitionerUnsafe(org.apache.cassandra.dht.IPartitioner)). -
pendingRangeChanges
- Returns:
- the number of nodes bootstrapping into source's primary range
-
updateNormalToken
Update token map with a single token/endpoint pair in normal state. -
updateNormalTokens
-
updateNormalTokens
public void updateNormalTokens(com.google.common.collect.Multimap<InetAddressAndPort, Token> endpointTokens) Update token map with a set of token/endpoint pairs in normal state. Prefer this whenever there are multiple pairs to update, as each update (whether a single or multiple) is expensive (CASSANDRA-3831). -
updateHostId
Store an end-point to host ID mapping. Each ID must be unique, and cannot be changed after the fact. -
updateHostIds
-
getHostId
Return the unique host ID for an end-point. -
getEndpointForHostId
Return the end-point for a unique host ID -
getEndpointToHostIdMapForReading
- Returns:
- a copy of the endpoint-to-id map for read-only operations
-
addBootstrapTokens
-
addReplaceTokens
public void addReplaceTokens(Collection<Token> replacingTokens, InetAddressAndPort newNode, InetAddressAndPort oldNode) -
getReplacementNode
-
getReplacingNode
-
removeBootstrapTokens
-
addLeavingEndpoint
-
addMovingEndpoint
Add a new moving endpoint- Parameters:
token- token which is node moving toendpoint- address of the moving node
-
removeEndpoint
-
updateTopology
This is called when the snitch properties for this endpoint are updated, see CASSANDRA-10238. -
updateTopology
This is called when the snitch properties for many endpoints are updated, it will update the topology mappings of any endpoints whose snitch has changed, see CASSANDRA-10238. -
removeFromMoving
Remove pair of token/address from moving endpoints- Parameters:
endpoint- address of the moving node
-
getTokens
-
isMember
-
isLeaving
-
isMoving
-
cloneOnlyTokenMap
Create a copy of TokenMetadata with only tokenToEndpointMap. That is, pending ranges, bootstrap tokens and leaving endpoints are not included in the copy. -
cachedOnlyTokenMap
Return a cached TokenMetadata with only tokenToEndpointMap, i.e., the same as cloneOnlyTokenMap but uses a cached copy that is invalided when the ring changes, so in the common case no extra locking is required. Callers must *NOT* mutate the returned metadata object. -
cloneAfterAllLeft
Create a copy of TokenMetadata with tokenToEndpointMap reflecting situation after all current leave operations have finished.- Returns:
- new token metadata
-
cloneAfterAllSettled
Create a copy of TokenMetadata with tokenToEndpointMap reflecting situation after all current leave, and move operations have finished.- Returns:
- new token metadata
-
getEndpoint
-
getPrimaryRangesFor
-
sortedTokens
-
getPendingRangesMM
-
getPendingRanges
a mutable map may be returned but caller should not modify it -
getPendingRanges
-
setPendingRangesUnsafe
-
calculatePendingRanges
Calculate pending ranges according to bootsrapping and leaving nodes. Reasoning is: (1) When in doubt, it is better to write too much to a node than too little. That is, if there are multiple nodes moving, calculate the biggest ranges a node could have. Cleaning up unneeded data afterwards is better than missing writes during movement. (2) When a node leaves, ranges for other nodes can only grow (a node might get additional ranges, but it will not lose any of its current ranges as a result of a leave). Therefore we will first remove _all_ leaving tokens for the sake of calculation and then check what ranges would go where if all nodes are to leave. This way we get the biggest possible ranges with regard current leave operations, covering all subsets of possible final range values. (3) When a node bootstraps, ranges of other nodes can only get smaller. Without doing complex calculations to see if multiple bootstraps overlap, we simply base calculations on the same token ring used before (reflecting situation after all leave operations have completed). Bootstrapping nodes will be added and removed one by one to that metadata and checked what their ranges would be. This will give us the biggest possible ranges the node could have. It might be that other bootstraps make our actual final ranges smaller, but it does not matter as we can clean up the data afterwards. NOTE: This is heavy and ineffective operation. This will be done only once when a node changes state in the cluster, so it should be manageable. -
unsafeCalculatePendingRanges
-
getPredecessor
-
getSuccessor
-
getBootstrapTokens
- Returns:
- a copy of the bootstrapping tokens map
-
getAllEndpoints
-
getSizeOfAllEndpoints
public int getSizeOfAllEndpoints() -
getAllMembers
-
getLeavingEndpoints
caller should not modify leavingEndpoints -
getSizeOfLeavingEndpoints
public int getSizeOfLeavingEndpoints() -
getMovingEndpoints
Endpoints which are migrating to the new tokens- Returns:
- set of addresses of moving endpoints
-
getSizeOfMovingEndpoints
public int getSizeOfMovingEndpoints() -
firstTokenIndex
-
firstToken
-
ringIterator
iterator over the Tokens in the given ring, starting with the token for the node owning start (which does not have to be a Token in the ring)- Parameters:
includeMin- True if the minimum token should be returned in the ring even if it has no owner.
-
clearUnsafe
public void clearUnsafe()used by tests -
toString
-
pendingEndpointsForToken
-
getWriteEndpoints
@Deprecated(since="4.0") public EndpointsForToken getWriteEndpoints(Token token, String keyspaceName, EndpointsForToken natural) Deprecated.retained for benefit of old tests -
getEndpointToTokenMapForReading
public com.google.common.collect.Multimap<InetAddressAndPort,Token> getEndpointToTokenMapForReading()- Returns:
- an endpoint to token multimap representation of tokenToEndpointMap (a copy)
-
getNormalAndBootstrappingTokenToEndpointMap
- Returns:
- a (stable copy, won't be modified) Token to Endpoint map for all the normal and bootstrapping nodes in the cluster.
-
getDC2AllEndpoints
public com.google.common.collect.ImmutableMultimap<String,InetAddressAndPort> getDC2AllEndpoints(IEndpointSnitch snitch) - Returns:
- a (stable copy, won't be modified) datacenter to Endpoint map for all the nodes in the cluster.
-
getTopology
- Returns:
- the Topology map of nodes to DCs + Racks This is only allowed when a copy has been made of TokenMetadata, to avoid concurrent modifications when Topology methods are subsequently used by the caller.
-
getRingVersion
public long getRingVersion() -
invalidateCachedRings
public void invalidateCachedRings() -
decorateKey
-
isTokenInLocalPendingRange
-