Class GridClusterStateProcessor
- java.lang.Object
-
- org.apache.ignite.internal.processors.GridProcessorAdapter
-
- org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor
-
- All Implemented Interfaces:
GridComponent,MetastorageLifecycleListener,IGridClusterStateProcessor,GridProcessor
public class GridClusterStateProcessor extends GridProcessorAdapter implements IGridClusterStateProcessor, MetastorageLifecycleListener
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.ignite.internal.GridComponent
GridComponent.DiscoveryDataExchangeType
-
-
Field Summary
Fields Modifier and Type Field Description static StringBASELINE_NODE_ATTRIBUTES_SYS_VIEWstatic StringBASELINE_NODE_ATTRIBUTES_SYS_VIEW_DESCstatic StringBASELINE_NODES_SYS_VIEWstatic StringBASELINE_NODES_SYS_VIEW_DESCstatic StringDATA_LOST_ON_DEACTIVATION_WARNINGWarning of unsafe cluster deactivation.-
Fields inherited from class org.apache.ignite.internal.processors.GridProcessorAdapter
ctx, diagnosticLog, log
-
-
Constructor Summary
Constructors Constructor Description GridClusterStateProcessor(GridKernalContext ctx)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafterStateChangeFinished(IgniteUuid msgId, boolean success)ExchangeActionsautoAdjustExchangeActions(ExchangeActions exchActs)Add fake state change request into exchange actions if cluster is not persistent and baseline autoadjustment is enabled with zero timeout.booleanautoAdjustInMemoryClusterState(UUID nodeId, Collection<ClusterNode> topSnapshot, DiscoCache discoCache, long topVer, int minorTopVer)Update baseline locally if cluster is not persistent and baseline autoadjustment is enabled with zero timeout.voidbaselineAutoAdjustEnabled(boolean baselineAutoAdjustEnabled)IgniteFuture<?>baselineAutoAdjustEnabledAsync(boolean baselineAutoAdjustEnabled)BaselineAutoAdjustStatusbaselineAutoAdjustStatus()longbaselineAutoAdjustTimeout()voidbaselineAutoAdjustTimeout(long baselineAutoAdjustTimeout)IgniteFuture<?>baselineAutoAdjustTimeoutAsync(long baselineAutoAdjustTimeout)DistributedBaselineConfigurationbaselineConfiguration()voidcacheProcessorStarted()IgniteInternalFuture<?>changeGlobalState(ClusterState state, boolean forceDeactivation, Collection<? extends BaselineNode> baselineNodes, boolean forceChangeBaselineTopology)IgniteInternalFuture<?>changeGlobalState(ClusterState state, boolean forceDeactivation, Collection<? extends BaselineNode> baselineNodes, boolean forceChangeBaselineTopology, boolean isAutoAdjust)DiscoveryDataClusterStateclusterState()voidcollectGridNodeData(DiscoveryDataBag dataBag)Collects discovery data on nodes already in grid on receivingTcpDiscoveryNodeAddedMessage.voidcollectJoiningNodeData(DiscoveryDataBag dataBag)Collects discovery data on joining node before sendingTcpDiscoveryJoinRequestMessagerequest.booleancompatibilityMode()protected IgniteCheckedExceptionconcurrentStateChangeError(ClusterState state, ClusterState transitionState)@Nullable GridComponent.DiscoveryDataExchangeTypediscoveryDataType()Gets unique component type to distinguish components providing discovery data.booleanevictionsAllowed()protected booleanisApplicable(ChangeGlobalStateMessage msg, DiscoveryDataClusterState state)booleanisBaselineAutoAdjustEnabled()protected static booleanisEquivalent(ChangeGlobalStateMessage msg, DiscoveryDataClusterState state)longlastStateChangeTime()voidonBaselineTopologyChanged(BaselineTopology blt, BaselineTopologyHistoryItem prevBltHistItem)voidonExchangeFinishedOnCoordinator(IgniteInternalFuture exchangeFuture, boolean hasMovingPartitions)voidonGridDataReceived(DiscoveryDataBag.GridDiscoveryData data)Receives discovery data object from remote nodes (called on new node during discovery process).voidonKernalStart(boolean active)Callback that notifies that kernal has successfully started, including all managers and processors.voidonKernalStop(boolean cancel)Callback to notify that kernal is about to stop.@Nullable IgniteInternalFuture<Boolean>onLocalJoin(DiscoCache discoCache)@Nullable ChangeGlobalStateFinishMessageonNodeLeft(ClusterNode node)voidonReadyForRead(ReadOnlyMetastorage metastorage)Is called when metastorage is made ready for read-only operations very early on node startup phase.voidonReadyForReadWrite(ReadWriteMetastorage metastorage)Fully functional metastore capable of performing reading and writing operations.voidonStateChangeError(Map<UUID,Exception> errs, StateChangeRequest req)voidonStateChangeExchangeDone(StateChangeRequest req)booleanonStateChangeMessage(AffinityTopologyVersion topVer, ChangeGlobalStateMessage msg, DiscoCache discoCache)voidonStateFinishMessage(ChangeGlobalStateFinishMessage msg)DiscoveryDataClusterStatependingState(ChangeGlobalStateMessage stateMsg)booleanpublicApiActiveState(boolean waitForTransition)IgniteFuture<Boolean>publicApiActiveStateAsync(boolean asyncWaitForTransition)ClusterStatepublicApiState(boolean waitForTransition)IgniteFuture<ClusterState>publicApiStateAsync(boolean asyncWaitForTransition)voidresetBranchingHistory(long newBranchingHash)Resets branching history on current BaselineTopology.voidstart()Starts grid component.static ClusterStatestateWithMinimalFeatures(ClusterState state1, ClusterState state2)Gets state of given two with minimal number of features.voidstop(boolean cancel)Stops grid component.StringtoString()@Nullable IgniteNodeValidationResultvalidateNode(ClusterNode node)Validates that new node can join grid topology, this method is called on coordinator node before new node joins topology.@Nullable IgniteNodeValidationResultvalidateNode(ClusterNode node, DiscoveryDataBag.JoiningNodeDiscoveryData discoData)Validates that new node can join grid topology, this method is called on coordinator node before new node joins topology.protected IgniteInternalFuture<?>wrapStateChangeFuture(IgniteInternalFuture fut, ChangeGlobalStateMessage msg)-
Methods inherited from class org.apache.ignite.internal.processors.GridProcessorAdapter
assertParameter, onDisconnected, onJoiningNodeDataReceived, onReconnected, printMemoryStats
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.ignite.internal.GridComponent
onDisconnected, onJoiningNodeDataReceived, onReconnected, printMemoryStats
-
-
-
-
Field Detail
-
DATA_LOST_ON_DEACTIVATION_WARNING
public static final String DATA_LOST_ON_DEACTIVATION_WARNING
Warning of unsafe cluster deactivation.- See Also:
- Constant Field Values
-
BASELINE_NODES_SYS_VIEW
public static final String BASELINE_NODES_SYS_VIEW
-
BASELINE_NODES_SYS_VIEW_DESC
public static final String BASELINE_NODES_SYS_VIEW_DESC
- See Also:
- Constant Field Values
-
BASELINE_NODE_ATTRIBUTES_SYS_VIEW
public static final String BASELINE_NODE_ATTRIBUTES_SYS_VIEW
-
BASELINE_NODE_ATTRIBUTES_SYS_VIEW_DESC
public static final String BASELINE_NODE_ATTRIBUTES_SYS_VIEW_DESC
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GridClusterStateProcessor
public GridClusterStateProcessor(GridKernalContext ctx)
- Parameters:
ctx- Kernal context.
-
-
Method Detail
-
validateNode
@Nullable public @Nullable IgniteNodeValidationResult validateNode(ClusterNode node)
Validates that new node can join grid topology, this method is called on coordinator node before new node joins topology.- Specified by:
validateNodein interfaceGridComponent- Overrides:
validateNodein classGridProcessorAdapter- Parameters:
node- Joining node.- Returns:
- Validation result or
nullin case of success.
-
compatibilityMode
public boolean compatibilityMode()
- Returns:
TrueifIGridClusterStateProcessorhas detected that cluster is working in compatibility mode (nodes of different versions are joined to the cluster).
-
publicApiState
public ClusterState publicApiState(boolean waitForTransition)
- Specified by:
publicApiStatein interfaceIGridClusterStateProcessor- Parameters:
waitForTransition- Wait end of transition or not.- Returns:
- Current cluster state to be used on public API.
-
publicApiStateAsync
public IgniteFuture<ClusterState> publicApiStateAsync(boolean asyncWaitForTransition)
- Specified by:
publicApiStateAsyncin interfaceIGridClusterStateProcessor- Parameters:
asyncWaitForTransition- Wait end of transition or not.- Returns:
- Current cluster state to be used on public API.
-
publicApiActiveState
public boolean publicApiActiveState(boolean waitForTransition)
- Specified by:
publicApiActiveStatein interfaceIGridClusterStateProcessor- Returns:
- Cluster state to be used on public API.
-
publicApiActiveStateAsync
public IgniteFuture<Boolean> publicApiActiveStateAsync(boolean asyncWaitForTransition)
- Specified by:
publicApiActiveStateAsyncin interfaceIGridClusterStateProcessor- Returns:
- Cluster state to be used on public API.
-
lastStateChangeTime
public long lastStateChangeTime()
- Specified by:
lastStateChangeTimein interfaceIGridClusterStateProcessor- Returns:
- Time of last cluster state change to be used on public API.
-
onReadyForRead
public void onReadyForRead(ReadOnlyMetastorage metastorage) throws IgniteCheckedException
Is called when metastorage is made ready for read-only operations very early on node startup phase. Reference for read-only metastorage should be used only within this method and shouldn't be stored to any field.- Specified by:
onReadyForReadin interfaceMetastorageLifecycleListener- Parameters:
metastorage- Read-only meta storage.- Throws:
IgniteCheckedException
-
onReadyForReadWrite
public void onReadyForReadWrite(ReadWriteMetastorage metastorage) throws IgniteCheckedException
Fully functional metastore capable of performing reading and writing operations. Components interested in using metastore are allowed to keep reference passed into the method in their fields.- Specified by:
onReadyForReadWritein interfaceMetastorageLifecycleListener- Parameters:
metastorage- Fully functional meta storage.- Throws:
IgniteCheckedException
-
resetBranchingHistory
public void resetBranchingHistory(long newBranchingHash) throws IgniteCheckedExceptionResets branching history on current BaselineTopology.- Throws:
IgniteCheckedException- If write to metastore has failed.
-
start
public void start() throws IgniteCheckedExceptionStarts grid component.- Specified by:
startin interfaceGridComponent- Overrides:
startin classGridProcessorAdapter- Throws:
IgniteCheckedException- Throws in case of any errors.
-
onKernalStart
public void onKernalStart(boolean active) throws IgniteCheckedExceptionCallback that notifies that kernal has successfully started, including all managers and processors.- Specified by:
onKernalStartin interfaceGridComponent- Overrides:
onKernalStartin classGridProcessorAdapter- Parameters:
active- Cluster active flag (note: should be used carefully since state can change concurrently).- Throws:
IgniteCheckedException- Thrown in case of any errors.
-
onKernalStop
public void onKernalStop(boolean cancel)
Callback to notify that kernal is about to stop.- Specified by:
onKernalStopin interfaceGridComponent- Overrides:
onKernalStopin classGridProcessorAdapter- Parameters:
cancel- Flag indicating whether jobs should be canceled.
-
onLocalJoin
@Nullable public @Nullable IgniteInternalFuture<Boolean> onLocalJoin(DiscoCache discoCache)
- Specified by:
onLocalJoinin interfaceIGridClusterStateProcessor- Parameters:
discoCache- Discovery data cache.- Returns:
- If transition is in progress returns future which is completed when transition finishes.
-
onNodeLeft
@Nullable public @Nullable ChangeGlobalStateFinishMessage onNodeLeft(ClusterNode node)
- Specified by:
onNodeLeftin interfaceIGridClusterStateProcessor- Parameters:
node- Failed node.- Returns:
- Message if cluster state changed.
-
onStateFinishMessage
public void onStateFinishMessage(ChangeGlobalStateFinishMessage msg)
- Specified by:
onStateFinishMessagein interfaceIGridClusterStateProcessor- Parameters:
msg- Message.
-
afterStateChangeFinished
protected void afterStateChangeFinished(IgniteUuid msgId, boolean success)
-
onStateChangeMessage
public boolean onStateChangeMessage(AffinityTopologyVersion topVer, ChangeGlobalStateMessage msg, DiscoCache discoCache)
- Specified by:
onStateChangeMessagein interfaceIGridClusterStateProcessor- Parameters:
topVer- Current topology version.msg- Message.discoCache- Current nodes.- Returns:
Trueif need start state change process.
-
isApplicable
protected boolean isApplicable(ChangeGlobalStateMessage msg, DiscoveryDataClusterState state)
- Parameters:
msg- State change message.state- Current cluster state.- Returns:
Trueif state change from message can be applied to the current state.
-
isEquivalent
protected static boolean isEquivalent(ChangeGlobalStateMessage msg, DiscoveryDataClusterState state)
- Parameters:
msg- State change message.state- Current cluster state.- Returns:
Trueif states are equivalent.
-
clusterState
public DiscoveryDataClusterState clusterState()
- Specified by:
clusterStatein interfaceIGridClusterStateProcessor- Returns:
- Current cluster state, should be called only from discovery thread.
-
pendingState
public DiscoveryDataClusterState pendingState(ChangeGlobalStateMessage stateMsg)
- Specified by:
pendingStatein interfaceIGridClusterStateProcessor- Returns:
- Pending cluster state which will be used when state transition is finished.
-
concurrentStateChangeError
protected IgniteCheckedException concurrentStateChangeError(ClusterState state, ClusterState transitionState)
- Parameters:
state- New state.transitionState- State in transition.- Returns:
- State change error.
-
cacheProcessorStarted
public void cacheProcessorStarted()
- Specified by:
cacheProcessorStartedin interfaceIGridClusterStateProcessor
-
stop
public void stop(boolean cancel) throws IgniteCheckedExceptionStops grid component.- Specified by:
stopin interfaceGridComponent- Overrides:
stopin classGridProcessorAdapter- Parameters:
cancel- Iftrue, then all ongoing tasks or jobs for relevant components need to be cancelled.- Throws:
IgniteCheckedException- Thrown in case of any errors.
-
discoveryDataType
@Nullable public @Nullable GridComponent.DiscoveryDataExchangeType discoveryDataType()
Gets unique component type to distinguish components providing discovery data. Must return non-null value if component implements any of methodsGridComponent.collectJoiningNodeData(DiscoveryDataBag)orGridComponent.collectGridNodeData(DiscoveryDataBag).- Specified by:
discoveryDataTypein interfaceGridComponent- Overrides:
discoveryDataTypein classGridProcessorAdapter- Returns:
- Unique component type for discovery data exchange.
-
collectJoiningNodeData
public void collectJoiningNodeData(DiscoveryDataBag dataBag)
Collects discovery data on joining node before sendingTcpDiscoveryJoinRequestMessagerequest.- Specified by:
collectJoiningNodeDatain interfaceGridComponent- Overrides:
collectJoiningNodeDatain classGridProcessorAdapter- Parameters:
dataBag- container object to store discovery data in.
-
collectGridNodeData
public void collectGridNodeData(DiscoveryDataBag dataBag)
Collects discovery data on nodes already in grid on receivingTcpDiscoveryNodeAddedMessage.- Specified by:
collectGridNodeDatain interfaceGridComponent- Overrides:
collectGridNodeDatain classGridProcessorAdapter- Parameters:
dataBag- container object to store discovery data in.
-
onGridDataReceived
public void onGridDataReceived(DiscoveryDataBag.GridDiscoveryData data)
Receives discovery data object from remote nodes (called on new node during discovery process).- Specified by:
onGridDataReceivedin interfaceGridComponent- Overrides:
onGridDataReceivedin classGridProcessorAdapter- Parameters:
data-DiscoveryDataBag.GridDiscoveryDatainterface to retrieve discovery data collected on remote nodes (data common for all nodes in grid and specific for each node).
-
changeGlobalState
public IgniteInternalFuture<?> changeGlobalState(ClusterState state, boolean forceDeactivation, Collection<? extends BaselineNode> baselineNodes, boolean forceChangeBaselineTopology)
- Specified by:
changeGlobalStatein interfaceIGridClusterStateProcessor- Parameters:
state- New cluster state.forceDeactivation- Iftrue, cluster deactivation will be forced.baselineNodes- New baseline nodes.forceChangeBaselineTopology- Force change baseline topology.- Returns:
- State change future.
- See Also:
ClusterState.INACTIVE
-
changeGlobalState
public IgniteInternalFuture<?> changeGlobalState(ClusterState state, boolean forceDeactivation, Collection<? extends BaselineNode> baselineNodes, boolean forceChangeBaselineTopology, boolean isAutoAdjust)
- Parameters:
state- New cluster state.forceDeactivation- Iftrue, cluster deactivation will be forced.baselineNodes- New baseline nodes.forceChangeBaselineTopology- Force change baseline topology.isAutoAdjust- Auto adjusting baseline flag.- Returns:
- State change future.
- See Also:
ClusterState.INACTIVE
-
validateNode
@Nullable public @Nullable IgniteNodeValidationResult validateNode(ClusterNode node, DiscoveryDataBag.JoiningNodeDiscoveryData discoData)
Validates that new node can join grid topology, this method is called on coordinator node before new node joins topology.- Specified by:
validateNodein interfaceGridComponent- Overrides:
validateNodein classGridProcessorAdapter- Parameters:
node- Joining node.discoData- Joining node discovery data.- Returns:
- Validation result or
nullin case of success.
-
wrapStateChangeFuture
protected IgniteInternalFuture<?> wrapStateChangeFuture(IgniteInternalFuture fut, ChangeGlobalStateMessage msg)
- Parameters:
fut- Original state change future.msg- State change message.- Returns:
- Wrapped state change future.
-
onStateChangeError
public void onStateChangeError(Map<UUID,Exception> errs, StateChangeRequest req)
- Specified by:
onStateChangeErrorin interfaceIGridClusterStateProcessor- Parameters:
errs- Errors.req- State change request.
-
onStateChangeExchangeDone
public void onStateChangeExchangeDone(StateChangeRequest req)
- Specified by:
onStateChangeExchangeDonein interfaceIGridClusterStateProcessor- Parameters:
req- State change request.
-
onBaselineTopologyChanged
public void onBaselineTopologyChanged(BaselineTopology blt, BaselineTopologyHistoryItem prevBltHistItem) throws IgniteCheckedException
- Specified by:
onBaselineTopologyChangedin interfaceIGridClusterStateProcessor- Parameters:
blt- New baseline topology.prevBltHistItem- Previous baseline history item.- Throws:
IgniteCheckedException
-
autoAdjustInMemoryClusterState
public boolean autoAdjustInMemoryClusterState(UUID nodeId, Collection<ClusterNode> topSnapshot, DiscoCache discoCache, long topVer, int minorTopVer)
Update baseline locally if cluster is not persistent and baseline autoadjustment is enabled with zero timeout.- Parameters:
nodeId- Id of the node that initiated the operation (joined/left/failed).topSnapshot- Topology snapshot from the discovery message.discoCache- Discovery cache from the discovery manager.topVer- Topology version.minorTopVer- Minor topology version.- Returns:
trueif baseline was changed and discovery cache recalculation is required.
-
autoAdjustExchangeActions
public ExchangeActions autoAdjustExchangeActions(ExchangeActions exchActs)
Add fake state change request into exchange actions if cluster is not persistent and baseline autoadjustment is enabled with zero timeout.- Parameters:
exchActs- Current exchange actions.- Returns:
- New exchange actions.
-
onExchangeFinishedOnCoordinator
public void onExchangeFinishedOnCoordinator(IgniteInternalFuture exchangeFuture, boolean hasMovingPartitions)
- Specified by:
onExchangeFinishedOnCoordinatorin interfaceIGridClusterStateProcessor- Parameters:
exchangeFuture- Exchange future.hasMovingPartitions-Trueif there are moving partitions.
-
evictionsAllowed
public boolean evictionsAllowed()
- Specified by:
evictionsAllowedin interfaceIGridClusterStateProcessor- Returns:
Trueif partition evictions are allowed in current state.
-
isBaselineAutoAdjustEnabled
public boolean isBaselineAutoAdjustEnabled()
- Returns:
- Value of manual baseline control or auto adjusting baseline.
TrueIf cluster in auto-adjust.FalseIf cluster in manuale.
-
baselineAutoAdjustEnabled
public void baselineAutoAdjustEnabled(boolean baselineAutoAdjustEnabled)
- Parameters:
baselineAutoAdjustEnabled- Value of manual baseline control or auto adjusting baseline.TrueIf cluster in auto-adjust.FalseIf cluster in manuale.- Throws:
IgniteException- If operation failed.
-
baselineAutoAdjustEnabledAsync
public IgniteFuture<?> baselineAutoAdjustEnabledAsync(boolean baselineAutoAdjustEnabled)
- Parameters:
baselineAutoAdjustEnabled- Value of manual baseline control or auto adjusting baseline.TrueIf cluster in auto-adjust.FalseIf cluster in manuale.- Returns:
- Future for await operation completion.
-
baselineAutoAdjustTimeout
public long baselineAutoAdjustTimeout()
- Returns:
- Value of time which we would wait before the actual topology change since last server topology change (node join/left/fail).
- Throws:
IgniteException- If operation failed.
-
baselineAutoAdjustTimeout
public void baselineAutoAdjustTimeout(long baselineAutoAdjustTimeout)
- Parameters:
baselineAutoAdjustTimeout- Value of time which we would wait before the actual topology change since last server topology change (node join/left/fail).- Throws:
IgniteException- If failed.
-
baselineAutoAdjustTimeoutAsync
public IgniteFuture<?> baselineAutoAdjustTimeoutAsync(long baselineAutoAdjustTimeout)
- Parameters:
baselineAutoAdjustTimeout- Value of time which we would wait before the actual topology change since last server topology change (node join/left/fail).- Returns:
- Future for await operation completion.
-
baselineConfiguration
public DistributedBaselineConfiguration baselineConfiguration()
- Returns:
- Baseline configuration.
-
baselineAutoAdjustStatus
public BaselineAutoAdjustStatus baselineAutoAdjustStatus()
- Returns:
- Status of baseline auto-adjust.
-
stateWithMinimalFeatures
public static ClusterState stateWithMinimalFeatures(ClusterState state1, ClusterState state2)
Gets state of given two with minimal number of features. The order:ClusterState.ACTIVE>ClusterState.ACTIVE_READ_ONLY>ClusterState.INACTIVE. Explain:
ClusterState.INACTIVEhas the smallast number of available features. You can't use caches in this state.
InClusterState.ACTIVE_READ_ONLYyou have more available features thanClusterState.INACTIVEstate, such as reading from caches, but can't write into them.
InClusterState.ACTIVEyou can update caches. It's a state with the biggest number of features.- Parameters:
state1- First given state.state2- Second given state.- Returns:
- State with minimal number of available features.
-
toString
public String toString()
- Overrides:
toStringin classGridProcessorAdapter
-
-