Package org.apache.cassandra.gms
Class Gossiper
java.lang.Object
org.apache.cassandra.gms.Gossiper
- All Implemented Interfaces:
GossiperMBean,IFailureDetectionEventListener,IGossiper
public class Gossiper
extends Object
implements IFailureDetectionEventListener, GossiperMBean, IGossiper
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.
This class is not threadsafe and any state changes should happen in the gossip stage.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longstatic final Gossiperstatic final intfinal Set<InetAddressAndPort>static final Stringstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExpireTimeForEndpoint(InetAddressAndPort endpoint, long expireTime) voidaddLocalApplicationState(ApplicationState applicationState, VersionedValue value) voidvoidAdd an endpoint we knew about previously, but whose state is unknownvoidadvertiseRemoving(InetAddressAndPort endpoint, UUID hostId, 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' invokedvoidadvertiseTokenRemoved(InetAddressAndPort endpoint, UUID hostId) Handles switching the endpoint's state from REMOVING_TOKEN to REMOVED_TOKEN This should only be called after advertiseRemovingvoidapplyStateLocally(Map<InetAddressAndPort, EndpointState> epStateMap) voidassassinateEndpoint(String address) Do not call this method unless you know what you are doing.voidintcompareEndpointStartup(InetAddressAndPort addr1, InetAddressAndPort addr2) determine which endpoint started up earlierReturns a map of endpoints that don't have matching tokenMetadata to gossip tokens.static longvoidconvict(InetAddressAndPort endpoint, double phi) This method is part of IFailureDetectionEventListener interface.voiddoOnChangeNotifications(InetAddressAndPort addr, ApplicationState state, VersionedValue value) doShadowRound(Set<InetAddressAndPort> peers) Do a single 'shadow' round of gossip by retrieving endpoint states that will be stored exclusively in the map return value, instead of endpointStateMap.voidvoidgetApplicationState(InetAddressAndPort endpoint, ApplicationState state) The value for the provided application state for the provided endpoint as currently known by this Gossip instance.intgetCurrentGenerationNumber(String address) intgetCurrentGenerationNumber(InetAddressAndPort endpoint) intlonggetEndpointDowntime(String address) longcom.google.common.collect.ImmutableSet<InetAddressAndPort>protected longgetExpireTimeForEndpoint(InetAddressAndPort endpoint) getForEndpoint(InetAddressAndPort ep, ApplicationState state) static StringgetGossipStatus(EndpointState epState) getHostId(InetAddressAndPort endpoint) getHostId(InetAddressAndPort endpoint, Map<InetAddressAndPort, EndpointState> epStates) booleangetMinVersion(long delay, TimeUnit timeUnit) Returns each node's database release versiongetSeeds()JMX endpoint for getting the list of seeds from the nodebooleanReturnsfalseonly if the information about the version of each node in the cluster is available and ALL the nodes are on 4.0+ (regardless of the patch version).voidinitializeNodeUnsafe(InetAddressAndPort addr, UUID uuid, int generationNbr) voidinitializeNodeUnsafe(InetAddressAndPort addr, UUID uuid, int netVersion, int generationNbr) voidCreates a new deadEndpointStatethat isempty.voidinjectApplicationState(InetAddressAndPort endpoint, ApplicationState state, VersionedValue value) booleanbooleanbooleanbooleanisAlive(InetAddressAndPort endpoint) booleanisDeadState(EndpointState epState) booleanbooleanisGossipOnlyMember(InetAddressAndPort endpoint) booleanbooleanisKnownEndpoint(InetAddressAndPort endpoint) booleanisSafeForStartup(InetAddressAndPort endpoint, UUID localHostUUID, boolean isBootstrapping, Map<InetAddressAndPort, EndpointState> epStates) Check if this node can safely be started and join the ring.booleanisSilentShutdownState(EndpointState epState) booleanisUpgradingFromVersionLowerThan(CassandraVersion referenceVersion) Returnstrueif there are nodes on version lower than the provided versionprotected voidmarkAsShutdown(InetAddressAndPort endpoint) Deprecated.see CASSANDRA-18913protected voidmarkAsShutdown(InetAddressAndPort endpoint, EndpointState remoteState) This method is used to mark a node as shutdown; that is it gracefully exited on its own and told us about itvoidmarkDead(InetAddressAndPort addr, EndpointState localState) protected voidmaybeFinishShadowRound(InetAddressAndPort respondent, boolean isInShadowRound, Map<InetAddressAndPort, EndpointState> epStateMap) voidmaybeInitializeLocalState(int generationNbr) voidnotifyFailureDetector(Map<InetAddressAndPort, EndpointState> remoteEpStateMap) voidrealMarkAlive(InetAddressAndPort addr, EndpointState localState) voidregister(IEndpointStateChangeSubscriber subscriber) Register for interesting state changes.JMX interface for triggering an update of the seed node list.voidremoveEndpoint(InetAddressAndPort endpoint) Removes the endpoint from Gossip but retains endpoint statevoidreplacedEndpoint(InetAddressAndPort endpoint) Remove the Endpoint and evict immediately, to avoid gossiping about this node.voidreplacementQuarantine(InetAddressAndPort endpoint) Quarantine endpoint specifically for replacement purposes.static voidrunInGossipStageBlocking(Runnable runnable) booleanvoidsetLastProcessedMessageAt(long timeInMillis) voidsetLooseEmptyEnabled(boolean enabled) voidstart(int generationNumber) voidstart(int generationNbr, Map<ApplicationState, VersionedValue> preloadLocalStates) Start the gossiper with the generation number, preloading the map of application states before startingvoidstop()voidstopShutdownAndWait(long timeout, TimeUnit unit) booleanvoidunregister(IEndpointStateChangeSubscriber subscriber) Unregister interest for state changes.voidunsafeAnnulEndpoint(InetAddressAndPort endpoint) voidunsafeAssassinateEndpoint(String address) voidvoidvoidvoidbooleanwaitForSchemaAgreement(long maxWait, TimeUnit unit, BooleanSupplier abortCondition) Blockingly wait for all live nodes to agree on the current schema version.static voidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.cassandra.gms.IGossiper
getReleaseVersion
-
Field Details
-
MBEAN_NAME
- See Also:
-
intervalInMillis
public static final int intervalInMillis- See Also:
-
QUARANTINE_DELAY
public static final int QUARANTINE_DELAY -
instance
-
aVeryLongTime
public static final long aVeryLongTime -
liveEndpoints
-
endpointStateMap
-
-
Constructor Details
-
Gossiper
public Gossiper(boolean registerJmx)
-
-
Method Details
-
clearUnsafe
public void clearUnsafe() -
expireUpgradeFromVersion
public void expireUpgradeFromVersion() -
setLastProcessedMessageAt
public void setLastProcessedMessageAt(long timeInMillis) -
seenAnySeed
public boolean seenAnySeed() -
register
Register for interesting state changes. -
unregister
Unregister interest for state changes.- Specified by:
unregisterin interfaceIGossiper- Parameters:
subscriber- module which implements the IEndpointStateChangeSubscriber
-
getLiveMembers
- Returns:
- a list of live gossip participants, including fat clients
-
getLiveTokenOwners
- Returns:
- a list of live ring members.
-
getUnreachableMembers
- Returns:
- a list of unreachable gossip participants, including fat clients
-
getUnreachableTokenOwners
- Returns:
- a list of unreachable token owners
-
getEndpointDowntime
-
runInGossipStageBlocking
-
convict
This method is part of IFailureDetectionEventListener interface. This is invoked by the Failure Detector when it convicts an end point.- Specified by:
convictin interfaceIFailureDetectionEventListener- Parameters:
endpoint- end point that is convicted.phi- the value of phi with with ep was convicted
-
markAsShutdown
Deprecated.see CASSANDRA-18913This 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
-
markAsShutdown
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 downremoteState- from the endpoint shutting down
-
removeEndpoint
Removes the endpoint from Gossip but retains endpoint state -
unsafeAnnulEndpoint
-
replacementQuarantine
Quarantine endpoint specifically for replacement purposes.- Parameters:
endpoint-
-
replacedEndpoint
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
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 removedhostId- - the ID of the host being removedlocalHostId- - my own host ID for replication coordination
-
advertiseTokenRemoved
Handles switching the endpoint's state from REMOVING_TOKEN to REMOVED_TOKEN This should only be called after advertiseRemoving- Parameters:
endpoint-hostId-
-
unsafeAssassinateEndpoint
- Specified by:
unsafeAssassinateEndpointin interfaceGossiperMBean- Throws:
UnknownHostException
-
assassinateEndpoint
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:
assassinateEndpointin interfaceGossiperMBean- Parameters:
address-- Throws:
UnknownHostException
-
isKnownEndpoint
-
getCurrentGenerationNumber
-
isGossipOnlyMember
-
isSafeForStartup
public boolean isSafeForStartup(InetAddressAndPort endpoint, UUID localHostUUID, boolean isBootstrapping, Map<InetAddressAndPort, 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 checklocalHostUUID- - the host id to checkisBootstrapping- - whether the node intends to bootstrap when joiningepStates- - endpoint states in the cluster- Returns:
- true if it is safe to start the node, false otherwise
-
getExpireTimeForEndpoint
-
getEndpointStateForEndpoint
- Specified by:
getEndpointStateForEndpointin interfaceIGossiper
-
inJustRemovedEndpoints
-
copyEndpointStateForEndpoint
-
getEndpoints
-
getForEndpoint
-
getEndpointCount
public int getEndpointCount() -
getHostId
-
getHostId
-
getApplicationState
The value for the provided application state for the provided endpoint as currently known by this Gossip instance.- Parameters:
endpoint- the endpoint from which to get the endpoint state.state- the endpoint state to get.- Returns:
- the value of the application state
stateforendpoint, ornullif eitherendpointis not known by Gossip or has no value forstate.
-
compareEndpointStartup
determine which endpoint started up earlier -
notifyFailureDetector
- Specified by:
notifyFailureDetectorin interfaceIGossiper
-
realMarkAlive
-
markDead
-
isAlive
-
isDeadState
-
isSilentShutdownState
-
isAdministrativelyInactiveState
-
isAdministrativelyInactiveState
-
getGossipStatus
-
applyStateLocally
- Specified by:
applyStateLocallyin interfaceIGossiper
-
doOnChangeNotifications
public void doOnChangeNotifications(InetAddressAndPort addr, ApplicationState state, VersionedValue value) -
start
public void start(int generationNumber) -
start
Start the gossiper with the generation number, preloading the map of application states before starting -
doShadowRound
-
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. Used when preparing to join the ring:- 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
maybeFinishShadowRound(InetAddressAndPort, boolean, Map). This will updateendpointShadowStateMapwith received values, in order to return an immutable copy to the caller ofdoShadowRound(). Therefor only a single shadow round execution is permitted at the same time.- Parameters:
peers- Additional peers to try gossiping with.- Returns:
- endpoint states gathered during shadow round or empty map
-
reloadSeeds
JMX interface for triggering an update of the seed node list.- Specified by:
reloadSeedsin interfaceGossiperMBean
-
getSeeds
JMX endpoint for getting the list of seeds from the node- Specified by:
getSeedsin interfaceGossiperMBean
-
maybeInitializeLocalState
public void maybeInitializeLocalState(int generationNbr) -
forceNewerGeneration
public void forceNewerGeneration() -
addSavedEndpoint
Add an endpoint we knew about previously, but whose state is unknown -
addLocalApplicationState
-
addLocalApplicationStates
-
stop
public void stop() -
isEnabled
public boolean isEnabled() -
sufficientForStartupSafetyCheck
-
maybeFinishShadowRound
protected void maybeFinishShadowRound(InetAddressAndPort respondent, boolean isInShadowRound, Map<InetAddressAndPort, EndpointState> epStateMap) -
isInShadowRound
public boolean isInShadowRound() -
initializeUnreachableNodeUnsafe
Creates a new deadEndpointStatethat isempty. This is used during host replacement for edge cases where the seed notified that the endpoint was empty, so need to add such state into gossip explicitly (as empty endpoints are not gossiped outside of the shadow round). see CASSANDRA-16213 -
initializeNodeUnsafe
-
initializeNodeUnsafe
public void initializeNodeUnsafe(InetAddressAndPort addr, UUID uuid, int netVersion, int generationNbr) -
injectApplicationState
public void injectApplicationState(InetAddressAndPort endpoint, ApplicationState state, VersionedValue value) -
getEndpointDowntime
- Specified by:
getEndpointDowntimein interfaceGossiperMBean- Throws:
UnknownHostException
-
getCurrentGenerationNumber
- Specified by:
getCurrentGenerationNumberin interfaceGossiperMBean- Throws:
UnknownHostException
-
addExpireTimeForEndpoint
-
computeExpireTime
public static long computeExpireTime() -
getReleaseVersionsWithPort
Description copied from interface:GossiperMBeanReturns each node's database release version- Specified by:
getReleaseVersionsWithPortin interfaceGossiperMBean
-
getSchemaVersion
-
waitToSettle
public static void waitToSettle() -
waitForSchemaAgreement
Blockingly wait for all live nodes to agree on the current schema version.- Parameters:
maxWait- maximum time to wait for schema agreementunit- TimeUnit of maxWait- Returns:
- true if agreement was reached, false if not
-
hasMajorVersion3OrUnknownNodes
public boolean hasMajorVersion3OrUnknownNodes()Returnsfalseonly if the information about the version of each node in the cluster is available and ALL the nodes are on 4.0+ (regardless of the patch version). -
isUpgradingFromVersionLowerThan
Returnstrueif there are nodes on version lower than the provided version -
stopShutdownAndWait
public void stopShutdownAndWait(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException - Throws:
InterruptedExceptionTimeoutException
-
getMinVersion
-
getLooseEmptyEnabled
public boolean getLooseEmptyEnabled()- Specified by:
getLooseEmptyEnabledin interfaceGossiperMBean
-
setLooseEmptyEnabled
public void setLooseEmptyEnabled(boolean enabled) - Specified by:
setLooseEmptyEnabledin interfaceGossiperMBean
-
unsafeSetEnabled
public void unsafeSetEnabled() -
unsafeClearRemoteState
-
unsafeGossipWith
-
unsafeSendShutdown
-
unsafeSendLocalEndpointStateTo
-
compareGossipAndTokenMetadata
Description copied from interface:GossiperMBeanReturns a map of endpoints that don't have matching tokenMetadata to gossip tokens. Values are lists of fixed size two (as Pair is not jmx safe), the first is the gossip tokens, the second tokenMetadata).- Specified by:
compareGossipAndTokenMetadatain interfaceGossiperMBean
-