org.apache.cassandra.locator

## Class TokenMetadata

- java.lang.Object
- - org.apache.cassandra.locator.TokenMetadata

-     public class TokenMetadata
      extends java.lang.Object

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `TokenMetadata.Topology` Tracks the assignment of racks and endpoints in each datacenter for all the "normal" endpoints in this TokenMetadata.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TokenMetadata()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addBootstrapToken(Token token, java.net.InetAddress endpoint)` Deprecated.
    `void` | `addBootstrapTokens(java.util.Collection<Token> tokens, java.net.InetAddress endpoint)`
    `void` | `addLeavingEndpoint(java.net.InetAddress endpoint)`
    `void` | `addMovingEndpoint(Token token, java.net.InetAddress endpoint)` Add a new moving endpoint
    `TokenMetadata` | `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.
    `void` | `clearUnsafe()` used by tests
    `TokenMetadata` | `cloneAfterAllLeft()` Create a copy of TokenMetadata with tokenToEndpointMap reflecting situation after all current leave operations have finished.
    `TokenMetadata` | `cloneAfterAllSettled()` Create a copy of TokenMetadata with tokenToEndpointMap reflecting situation after all current leave, and move operations have finished.
    `TokenMetadata` | `cloneOnlyTokenMap()` Create a copy of TokenMetadata with only tokenToEndpointMap.
    `static Token` | `firstToken(java.util.ArrayList<Token> ring, Token start)`
    `static int` | `firstTokenIndex(java.util.ArrayList ring, Token start, boolean insertMin)`
    `java.util.Set<java.net.InetAddress>` | `getAllEndpoints()`
    `BiMultiValMap<Token,java.net.InetAddress>` | `getBootstrapTokens()`
    `java.net.InetAddress` | `getEndpoint(Token token)`
    `java.net.InetAddress` | `getEndpointForHostId(java.util.UUID hostId)` Return the end-point for a unique host ID
    `java.util.Map<java.net.InetAddress,java.util.UUID>` | `getEndpointToHostIdMapForReading()`
    `com.google.common.collect.Multimap<java.net.InetAddress,Token>` | `getEndpointToTokenMapForReading()`
    `java.util.UUID` | `getHostId(java.net.InetAddress endpoint)` Return the unique host ID for an end-point.
    `java.util.Set<java.net.InetAddress>` | `getLeavingEndpoints()` caller should not modify leavingEndpoints
    `java.util.Set<Pair<Token,java.net.InetAddress>>` | `getMovingEndpoints()` Endpoints which are migrating to the new tokens
    `java.util.Map<Token,java.net.InetAddress>` | `getNormalAndBootstrappingTokenToEndpointMap()`
    `java.util.Map<Range<Token>,java.util.Collection<java.net.InetAddress>>` | `getPendingRanges(java.lang.String keyspaceName)` a mutable map may be returned but caller should not modify it
    `java.util.List<Range<Token>>` | `getPendingRanges(java.lang.String keyspaceName, java.net.InetAddress endpoint)`
    `Token` | `getPredecessor(Token token)`
    `Range<Token>` | `getPrimaryRangeFor(Token right)` Deprecated.
    `java.util.Collection<Range<Token>>` | `getPrimaryRangesFor(java.util.Collection<Token> tokens)`
    `long` | `getRingVersion()`
    `Token` | `getSuccessor(Token token)`
    `Token` | `getToken(java.net.InetAddress endpoint)` Deprecated.
    `java.util.Collection<Token>` | `getTokens(java.net.InetAddress endpoint)`
    `TokenMetadata.Topology` | `getTopology()`
    `java.util.Collection<java.net.InetAddress>` | `getWriteEndpoints(Token token, java.lang.String keyspaceName, java.util.Collection<java.net.InetAddress> naturalEndpoints)` Deprecated. retained for benefit of old tests
    `void` | `invalidateCachedRings()`
    `boolean` | `isLeaving(java.net.InetAddress endpoint)`
    `boolean` | `isMember(java.net.InetAddress endpoint)`
    `boolean` | `isMoving(java.net.InetAddress endpoint)`
    `java.util.Collection<java.net.InetAddress>` | `pendingEndpointsFor(Token token, java.lang.String keyspaceName)`
    `int` | `pendingRangeChanges(java.net.InetAddress source)`
    `java.lang.String` | `printPendingRanges()`
    `void` | `removeBootstrapTokens(java.util.Collection<Token> tokens)`
    `void` | `removeEndpoint(java.net.InetAddress endpoint)`
    `void` | `removeFromMoving(java.net.InetAddress endpoint)` Remove pair of token/address from moving endpoints
    `static java.util.Iterator<Token>` | `ringIterator(java.util.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)
    `void` | `setPendingRanges(java.lang.String keyspaceName, com.google.common.collect.Multimap<Range<Token>,java.net.InetAddress> rangeMap)`
    `java.util.ArrayList<Token>` | `sortedTokens()`
    `java.lang.String` | `toString()`
    `void` | `updateHostId(java.util.UUID hostId, java.net.InetAddress endpoint)` Store an end-point to host ID mapping.
    `void` | `updateNormalToken(Token token, java.net.InetAddress endpoint)` Update token map with a single token/endpoint pair in normal state.
    `void` | `updateNormalTokens(java.util.Collection<Token> tokens, java.net.InetAddress endpoint)`
    `void` | `updateNormalTokens(com.google.common.collect.Multimap<java.net.InetAddress,Token> endpointTokens)` Update token map with a set of token/endpoint pairs in normal state.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### TokenMetadata

          public TokenMetadata()

  - ### Method Detail

    - #### pendingRangeChanges

          public int pendingRangeChanges(java.net.InetAddress source)

      Returns:
        the number of nodes bootstrapping into source's primary range

    - #### updateNormalToken

          public void updateNormalToken(Token token,
                               java.net.InetAddress endpoint)

      Update token map with a single token/endpoint pair in normal state.

    - #### updateNormalTokens

          public void updateNormalTokens(java.util.Collection<Token> tokens,
                                java.net.InetAddress endpoint)

    - #### updateNormalTokens

          public void updateNormalTokens(com.google.common.collect.Multimap<java.net.InetAddress,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).
      Parameters:
        `endpointTokens` -

    - #### updateHostId

          public void updateHostId(java.util.UUID hostId,
                          java.net.InetAddress endpoint)

      Store an end-point to host ID mapping. Each ID must be unique, and cannot be changed after the fact.
      Parameters:
        `hostId` -
        `endpoint` -

    - #### getHostId

          public java.util.UUID getHostId(java.net.InetAddress endpoint)

      Return the unique host ID for an end-point.

    - #### getEndpointForHostId

          public java.net.InetAddress getEndpointForHostId(java.util.UUID hostId)

      Return the end-point for a unique host ID

    - #### getEndpointToHostIdMapForReading

          public java.util.Map<java.net.InetAddress,java.util.UUID> getEndpointToHostIdMapForReading()

      Returns:
        a copy of the endpoint-to-id map for read-only operations

    - #### addBootstrapToken

          @Deprecated
          public void addBootstrapToken(Token token,
                                          java.net.InetAddress endpoint)

      Deprecated.

    - #### addBootstrapTokens

          public void addBootstrapTokens(java.util.Collection<Token> tokens,
                                java.net.InetAddress endpoint)

    - #### removeBootstrapTokens

          public void removeBootstrapTokens(java.util.Collection<Token> tokens)

    - #### addLeavingEndpoint

          public void addLeavingEndpoint(java.net.InetAddress endpoint)

    - #### addMovingEndpoint

          public void addMovingEndpoint(Token token,
                               java.net.InetAddress endpoint)

      Add a new moving endpoint
      Parameters:
        `token` - token which is node moving to
        `endpoint` - address of the moving node

    - #### removeEndpoint

          public void removeEndpoint(java.net.InetAddress endpoint)

    - #### removeFromMoving

          public void removeFromMoving(java.net.InetAddress endpoint)

      Remove pair of token/address from moving endpoints
      Parameters:
        `endpoint` - address of the moving node

    - #### getTokens

          public java.util.Collection<Token> getTokens(java.net.InetAddress endpoint)

    - #### getToken

          @Deprecated
          public Token getToken(java.net.InetAddress endpoint)

      Deprecated.

    - #### isMember

          public boolean isMember(java.net.InetAddress endpoint)

    - #### isLeaving

          public boolean isLeaving(java.net.InetAddress endpoint)

    - #### isMoving

          public boolean isMoving(java.net.InetAddress endpoint)

    - #### cloneOnlyTokenMap

          public TokenMetadata 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

          public TokenMetadata 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

          public TokenMetadata cloneAfterAllLeft()

      Create a copy of TokenMetadata with tokenToEndpointMap reflecting situation after all current leave operations have finished.
      Returns:
        new token metadata

    - #### cloneAfterAllSettled

          public TokenMetadata cloneAfterAllSettled()

      Create a copy of TokenMetadata with tokenToEndpointMap reflecting situation after all current leave, and move operations have finished.
      Returns:
        new token metadata

    - #### getEndpoint

          public java.net.InetAddress getEndpoint(Token token)

    - #### getPrimaryRangesFor

          public java.util.Collection<Range<Token>> getPrimaryRangesFor(java.util.Collection<Token> tokens)

    - #### getPrimaryRangeFor

          @Deprecated
          public Range<Token> getPrimaryRangeFor(Token right)

      Deprecated.

    - #### sortedTokens

          public java.util.ArrayList<Token> sortedTokens()

    - #### getPendingRanges

          public java.util.Map<Range<Token>,java.util.Collection<java.net.InetAddress>> getPendingRanges(java.lang.String keyspaceName)

      a mutable map may be returned but caller should not modify it

    - #### getPendingRanges

          public java.util.List<Range<Token>> getPendingRanges(java.lang.String keyspaceName,
                                                      java.net.InetAddress endpoint)

    - #### setPendingRanges

          public void setPendingRanges(java.lang.String keyspaceName,
                              com.google.common.collect.Multimap<Range<Token>,java.net.InetAddress> rangeMap)

    - #### getPredecessor

          public Token getPredecessor(Token token)

    - #### getSuccessor

          public Token getSuccessor(Token token)

    - #### getBootstrapTokens

          public BiMultiValMap<Token,java.net.InetAddress> getBootstrapTokens()

      Returns:
        a copy of the bootstrapping tokens map

    - #### getAllEndpoints

          public java.util.Set<java.net.InetAddress> getAllEndpoints()

    - #### getLeavingEndpoints

          public java.util.Set<java.net.InetAddress> getLeavingEndpoints()

      caller should not modify leavingEndpoints

    - #### getMovingEndpoints

          public java.util.Set<Pair<Token,java.net.InetAddress>> getMovingEndpoints()

      Endpoints which are migrating to the new tokens
      Returns:
        set of addresses of moving endpoints

    - #### firstTokenIndex

          public static int firstTokenIndex(java.util.ArrayList ring,
                            Token start,
                            boolean insertMin)

    - #### firstToken

          public static Token firstToken(java.util.ArrayList<Token> ring,
                         Token start)

    - #### ringIterator

          public static java.util.Iterator<Token> ringIterator(java.util.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)
      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

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### printPendingRanges

          public java.lang.String printPendingRanges()

    - #### pendingEndpointsFor

          public java.util.Collection<java.net.InetAddress> pendingEndpointsFor(Token token,
                                                                       java.lang.String keyspaceName)

    - #### getWriteEndpoints

          public java.util.Collection<java.net.InetAddress> getWriteEndpoints(Token token,
                                                                     java.lang.String keyspaceName,
                                                                     java.util.Collection<java.net.InetAddress> naturalEndpoints)

      Deprecated. retained for benefit of old tests

    - #### getEndpointToTokenMapForReading

          public com.google.common.collect.Multimap<java.net.InetAddress,Token> getEndpointToTokenMapForReading()

      Returns:
        an endpoint to token multimap representation of tokenToEndpointMap (a copy)

    - #### getNormalAndBootstrappingTokenToEndpointMap

          public java.util.Map<Token,java.net.InetAddress> getNormalAndBootstrappingTokenToEndpointMap()

      Returns:
        a (stable copy, won't be modified) Token to Endpoint map for all the normal and bootstrapping nodes in the cluster.

    - #### getTopology

          public TokenMetadata.Topology 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()

Copyright © 2014 The Apache Software Foundation