org.apache.cassandra.gms

## Class Gossiper

- java.lang.Object
- - org.apache.cassandra.gms.Gossiper

- All Implemented Interfaces:
    GossiperMBean, IFailureDetectionEventListener

      public class Gossiper
      extends java.lang.Object
      implements IFailureDetectionEventListener, GossiperMBean

  This module is responsible for Gossiping information for the local endpoint. This abstraction maintains the list of live and dead endpoints. Periodically i.e. every 1 second this module chooses a random node and initiates a round of Gossip with it. A round of Gossip involves 3 rounds of messaging. For instance if node A wants to initiate a round of Gossip with node B it starts off by sending node B a GossipDigestSynMessage. Node B on receipt of this message sends node A a GossipDigestAckMessage. On receipt of this message node A sends node B a GossipDigestAck2Message which completes a round of Gossip. This module as and when it hears one of the three above mentioned messages updates the Failure Detector with the liveness information. Upon hearing a GossipShutdownMessage, this module will instantly mark the remote node as down in the Failure Detector.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static long` | `aVeryLongTime`
    `static Gossiper` | `instance`
    `static int` | `intervalInMillis`
    `static java.lang.String` | `MBEAN_NAME`
    `static int` | `QUARANTINE_DELAY`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addExpireTimeForEndpoint(java.net.InetAddress endpoint, long expireTime)`
    `void` | `addLocalApplicationState(ApplicationState applicationState, VersionedValue value)`
    `void` | `addLocalApplicationStates(java.util.List<Pair<ApplicationState,VersionedValue>> states)`
    `void` | `addSavedEndpoint(java.net.InetAddress ep)` Add an endpoint we knew about previously, but whose state is unknown
    `void` | `advertiseRemoving(java.net.InetAddress endpoint, java.util.UUID hostId, java.util.UUID localHostId)` This method will begin removing an existing endpoint from the cluster by spoofing its state This should never be called unless this coordinator has had 'removenode' invoked
    `void` | `advertiseTokenRemoved(java.net.InetAddress endpoint, java.util.UUID hostId)` Handles switching the endpoint's state from REMOVING_TOKEN to REMOVED_TOKEN This should only be called after advertiseRemoving
    `void` | `assassinateEndpoint(java.lang.String address)` Do not call this method unless you know what you are doing.
    `int` | `compareEndpointStartup(java.net.InetAddress addr1, java.net.InetAddress addr2)` determine which endpoint started up earlier
    `static long` | `computeExpireTime()`
    `void` | `convict(java.net.InetAddress endpoint, double phi)` This method is part of IFailureDetectionEventListener interface.
    `java.util.Map<java.net.InetAddress,EndpointState>` | `doShadowRound()` Do a single 'shadow' round of gossip by retrieving endpoint states that will be stored exclusively in the map return value, instead of endpointStateMap.
    `void` | `forceNewerGeneration()`
    `int` | `getCurrentGenerationNumber(java.net.InetAddress endpoint)`
    `int` | `getCurrentGenerationNumber(java.lang.String address)`
    `long` | `getEndpointDowntime(java.net.InetAddress ep)`
    `long` | `getEndpointDowntime(java.lang.String address)`
    `EndpointState` | `getEndpointStateForEndpoint(java.net.InetAddress ep)`
    `java.util.Set<java.util.Map.Entry<java.net.InetAddress,EndpointState>>` | `getEndpointStates()`
    `protected long` | `getExpireTimeForEndpoint(java.net.InetAddress endpoint)`
    `java.util.UUID` | `getHostId(java.net.InetAddress endpoint)`
    `java.util.UUID` | `getHostId(java.net.InetAddress endpoint, java.util.Map<java.net.InetAddress,EndpointState> epStates)`
    `java.util.Set<java.net.InetAddress>` | `getLiveMembers()`
    `java.util.Set<java.net.InetAddress>` | `getLiveTokenOwners()`
    `CassandraVersion` | `getReleaseVersion(java.net.InetAddress ep)`
    `java.util.UUID` | `getSchemaVersion(java.net.InetAddress ep)`
    `java.util.Set<java.net.InetAddress>` | `getUnreachableMembers()`
    `java.util.Set<java.net.InetAddress>` | `getUnreachableTokenOwners()`
    `void` | `initializeNodeUnsafe(java.net.InetAddress addr, java.util.UUID uuid, int generationNbr)`
    `void` | `injectApplicationState(java.net.InetAddress endpoint, ApplicationState state, VersionedValue value)`
    `boolean` | `isAlive(java.net.InetAddress endpoint)`
    `boolean` | `isAnyNodeOn30()`
    `boolean` | `isDeadState(EndpointState epState)`
    `boolean` | `isEnabled()`
    `boolean` | `isGossipOnlyMember(java.net.InetAddress endpoint)`
    `protected boolean` | `isInShadowRound()`
    `boolean` | `isKnownEndpoint(java.net.InetAddress endpoint)`
    `boolean` | `isSafeForStartup(java.net.InetAddress endpoint, java.util.UUID localHostUUID, boolean isBootstrapping, java.util.Map<java.net.InetAddress,EndpointState> epStates)` Check if this node can safely be started and join the ring.
    `boolean` | `isSilentShutdownState(EndpointState epState)`
    `protected void` | `markAsShutdown(java.net.InetAddress endpoint)` This method is used to mark a node as shutdown; that is it gracefully exited on its own and told us about it
    `void` | `markDead(java.net.InetAddress addr, EndpointState localState)`
    `protected void` | `maybeFinishShadowRound(java.net.InetAddress respondent, boolean isInShadowRound, java.util.Map<java.net.InetAddress,EndpointState> epStateMap)`
    `void` | `maybeInitializeLocalState(int generationNbr)`
    `void` | `realMarkAlive(java.net.InetAddress addr, EndpointState localState)`
    `void` | `register(IEndpointStateChangeSubscriber subscriber)` Register for interesting state changes.
    `void` | `removeEndpoint(java.net.InetAddress endpoint)` Removes the endpoint from Gossip but retains endpoint state
    `void` | `replacedEndpoint(java.net.InetAddress endpoint)` Remove the Endpoint and evict immediately, to avoid gossiping about this node.
    `void` | `replacementQuarantine(java.net.InetAddress endpoint)` Quarantine endpoint specifically for replacement purposes.
    `boolean` | `seenAnySeed()`
    `void` | `setLastProcessedMessageAt(long timeInMillis)`
    `void` | `start(int generationNumber)`
    `void` | `start(int generationNbr, java.util.Map<ApplicationState,VersionedValue> preloadLocalStates)` Start the gossiper with the generation number, preloading the map of application states before starting
    `void` | `stop()`
    `void` | `unregister(IEndpointStateChangeSubscriber subscriber)` Unregister interest for state changes.
    `void` | `unsafeAssassinateEndpoint(java.lang.String address)`
    `static void` | `waitToSettle()`

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

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

- - ### Field Detail

    - #### MBEAN_NAME

          public static final java.lang.String MBEAN_NAME

      See Also:
        Constant Field Values

    - #### intervalInMillis

          public static final int intervalInMillis

      See Also:
        Constant Field Values

    - #### QUARANTINE_DELAY

          public static final int QUARANTINE_DELAY

    - #### instance

          public static final Gossiper instance

    - #### aVeryLongTime

          public static final long aVeryLongTime

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### setLastProcessedMessageAt

          public void setLastProcessedMessageAt(long timeInMillis)

    - #### seenAnySeed

          public boolean seenAnySeed()

    - #### register

          public void register(IEndpointStateChangeSubscriber subscriber)

      Register for interesting state changes.
      Parameters:
        `subscriber` - module which implements the IEndpointStateChangeSubscriber

    - #### unregister

          public void unregister(IEndpointStateChangeSubscriber subscriber)

      Unregister interest for state changes.
      Parameters:
        `subscriber` - module which implements the IEndpointStateChangeSubscriber

    - #### getLiveMembers

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

      Returns:
        a list of live gossip participants, including fat clients

    - #### getLiveTokenOwners

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

      Returns:
        a list of live ring members.

    - #### getUnreachableMembers

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

      Returns:
        a list of unreachable gossip participants, including fat clients

    - #### getUnreachableTokenOwners

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

      Returns:
        a list of unreachable token owners

    - #### getEndpointDowntime

          public long getEndpointDowntime(java.net.InetAddress ep)

    - #### convict

          public void convict(java.net.InetAddress endpoint,
                              double phi)

      This method is part of IFailureDetectionEventListener interface. This is invoked by the Failure Detector when it convicts an end point.
      Specified by:
        `convict` in interface `IFailureDetectionEventListener`
      Parameters:
        `endpoint` - end point that is convicted.
        `phi` - the value of phi with with ep was convicted

    - #### markAsShutdown

          protected void markAsShutdown(java.net.InetAddress endpoint)

      This method is used to mark a node as shutdown; that is it gracefully exited on its own and told us about it
      Parameters:
        `endpoint` - endpoint that has shut itself down

    - #### removeEndpoint

          public void removeEndpoint(java.net.InetAddress endpoint)

      Removes the endpoint from Gossip but retains endpoint state

    - #### replacementQuarantine

          public void replacementQuarantine(java.net.InetAddress endpoint)

      Quarantine endpoint specifically for replacement purposes.
      Parameters:
        `endpoint` -

    - #### replacedEndpoint

          public void replacedEndpoint(java.net.InetAddress endpoint)

      Remove the Endpoint and evict immediately, to avoid gossiping about this node. This should only be called when a token is taken over by a new IP address.
      Parameters:
        `endpoint` - The endpoint that has been replaced

    - #### advertiseRemoving

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

      This method will begin removing an existing endpoint from the cluster by spoofing its state This should never be called unless this coordinator has had 'removenode' invoked
      Parameters:
        `endpoint` - - the endpoint being removed
        `hostId` - - the ID of the host being removed
        `localHostId` - - my own host ID for replication coordination

    - #### advertiseTokenRemoved

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

      Handles switching the endpoint's state from REMOVING_TOKEN to REMOVED_TOKEN This should only be called after advertiseRemoving
      Parameters:
        `endpoint` -
        `hostId` -

    - #### unsafeAssassinateEndpoint

          public void unsafeAssassinateEndpoint(java.lang.String address)
                                         throws java.net.UnknownHostException

      Specified by:
        `unsafeAssassinateEndpoint` in interface `GossiperMBean`
      Throws:
        `java.net.UnknownHostException`

    - #### assassinateEndpoint

          public void assassinateEndpoint(java.lang.String address)
                                   throws java.net.UnknownHostException

      Do not call this method unless you know what you are doing. It will try extremely hard to obliterate any endpoint from the ring, even if it does not know about it.
      Specified by:
        `assassinateEndpoint` in interface `GossiperMBean`
      Parameters:
        `address` -
      Throws:
        `java.net.UnknownHostException`

    - #### isKnownEndpoint

          public boolean isKnownEndpoint(java.net.InetAddress endpoint)

    - #### getCurrentGenerationNumber

          public int getCurrentGenerationNumber(java.net.InetAddress endpoint)

    - #### isGossipOnlyMember

          public boolean isGossipOnlyMember(java.net.InetAddress endpoint)

    - #### isSafeForStartup

          public boolean isSafeForStartup(java.net.InetAddress endpoint,
                                          java.util.UUID localHostUUID,
                                          boolean isBootstrapping,
                                          java.util.Map<java.net.InetAddress,EndpointState> epStates)

      Check if this node can safely be started and join the ring. If the node is bootstrapping, examines gossip state for any previous status to decide whether it's safe to allow this node to start and bootstrap. If not bootstrapping, compares the host ID that the node itself has (obtained by reading from system.local or generated if not present) with the host ID obtained from gossip for the endpoint address (if any). This latter case prevents a non-bootstrapping, new node from being started with the same address of a previously started, but currently down predecessor.
      Parameters:
        `endpoint` - - the endpoint to check
        `localHostUUID` - - the host id to check
        `isBootstrapping` - - whether the node intends to bootstrap when joining
        `epStates` - - endpoint states in the cluster
      Returns:
        true if it is safe to start the node, false otherwise

    - #### getExpireTimeForEndpoint

          protected long getExpireTimeForEndpoint(java.net.InetAddress endpoint)

    - #### getEndpointStateForEndpoint

          public EndpointState getEndpointStateForEndpoint(java.net.InetAddress ep)

    - #### getEndpointStates

          public java.util.Set<java.util.Map.Entry<java.net.InetAddress,EndpointState>> getEndpointStates()

    - #### getHostId

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

    - #### getHostId

          public java.util.UUID getHostId(java.net.InetAddress endpoint,
                                          java.util.Map<java.net.InetAddress,EndpointState> epStates)

    - #### compareEndpointStartup

          public int compareEndpointStartup(java.net.InetAddress addr1,
                                            java.net.InetAddress addr2)

      determine which endpoint started up earlier

    - #### realMarkAlive

          public void realMarkAlive(java.net.InetAddress addr,
                                    EndpointState localState)

    - #### markDead

          public void markDead(java.net.InetAddress addr,
                               EndpointState localState)

    - #### isAlive

          public boolean isAlive(java.net.InetAddress endpoint)

    - #### isDeadState

          public boolean isDeadState(EndpointState epState)

    - #### isSilentShutdownState

          public boolean isSilentShutdownState(EndpointState epState)

    - #### start

          public void start(int generationNumber)

    - #### start

          public void start(int generationNbr,
                            java.util.Map<ApplicationState,VersionedValue> preloadLocalStates)

      Start the gossiper with the generation number, preloading the map of application states before starting

    - #### doShadowRound

          public java.util.Map<java.net.InetAddress,EndpointState> doShadowRound()

      Do a single 'shadow' round of gossip by retrieving endpoint states that will be stored exclusively in the map return value, instead of endpointStateMap.
      - when replacing a node, to get and assume its tokens
      - when joining, to check that the local host id matches any previous id for the endpoint address
      Method is synchronized, as we use an in-progress flag to indicate that shadow round must be cleared again by calling `maybeFinishShadowRound(InetAddress, boolean, Map)`. This will update `endpointShadowStateMap` with received values, in order to return an immutable copy to the caller of `doShadowRound()`. Therefor only a single shadow round execution is permitted at the same time.
      Returns:
        endpoint states gathered during shadow round or empty map

    - #### maybeInitializeLocalState

          public void maybeInitializeLocalState(int generationNbr)

    - #### forceNewerGeneration

          public void forceNewerGeneration()

    - #### addSavedEndpoint

          public void addSavedEndpoint(java.net.InetAddress ep)

      Add an endpoint we knew about previously, but whose state is unknown

    - #### addLocalApplicationState

          public void addLocalApplicationState(ApplicationState applicationState,
                                               VersionedValue value)

    - #### addLocalApplicationStates

          public void addLocalApplicationStates(java.util.List<Pair<ApplicationState,VersionedValue>> states)

    - #### stop

          public void stop()

    - #### isEnabled

          public boolean isEnabled()

    - #### isAnyNodeOn30

          public boolean isAnyNodeOn30()

    - #### maybeFinishShadowRound

          protected void maybeFinishShadowRound(java.net.InetAddress respondent,
                                                boolean isInShadowRound,
                                                java.util.Map<java.net.InetAddress,EndpointState> epStateMap)

    - #### isInShadowRound

          protected boolean isInShadowRound()

    - #### initializeNodeUnsafe

          public void initializeNodeUnsafe(java.net.InetAddress addr,
                                           java.util.UUID uuid,
                                           int generationNbr)

    - #### injectApplicationState

          public void injectApplicationState(java.net.InetAddress endpoint,
                                             ApplicationState state,
                                             VersionedValue value)

    - #### getEndpointDowntime

          public long getEndpointDowntime(java.lang.String address)
                                   throws java.net.UnknownHostException

      Specified by:
        `getEndpointDowntime` in interface `GossiperMBean`
      Throws:
        `java.net.UnknownHostException`

    - #### getCurrentGenerationNumber

          public int getCurrentGenerationNumber(java.lang.String address)
                                         throws java.net.UnknownHostException

      Specified by:
        `getCurrentGenerationNumber` in interface `GossiperMBean`
      Throws:
        `java.net.UnknownHostException`

    - #### addExpireTimeForEndpoint

          public void addExpireTimeForEndpoint(java.net.InetAddress endpoint,
                                               long expireTime)

    - #### computeExpireTime

          public static long computeExpireTime()

    - #### getReleaseVersion

          @Nullable
          public CassandraVersion getReleaseVersion(java.net.InetAddress ep)

    - #### getSchemaVersion

          @Nullable
          public java.util.UUID getSchemaVersion(java.net.InetAddress ep)

    - #### waitToSettle

          public static void waitToSettle()

Copyright © 2018 The Apache Software Foundation