Package org.elasticsearch.gateway
Class GatewayMetaState
- java.lang.Object
-
- org.elasticsearch.gateway.GatewayMetaState
-
- All Implemented Interfaces:
ClusterStateApplier
,CoordinationState.PersistedState
public class GatewayMetaState extends java.lang.Object implements ClusterStateApplier, CoordinationState.PersistedState
This class is responsible for storing/retrieving metadata to/from disk. When instance of this class is created, constructor ensures that this version is compatible with state stored on disk and performs state upgrade if necessary. Also it checks that atomic move is supported on the filesystem level, because it's a must for metadata store algorithm. Please note that the state being loaded when constructing the instance of this class is NOT the state that will be used as aClusterState.metaData()
. Instead when node is starting up, it callsgetMetaData()
method and if this node is elected as master, it requests metaData from other master eligible nodes. After that, master node performs re-conciliation on the gathered results, re-createsClusterState
and broadcasts this state to other nodes in the cluster.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
GatewayMetaState.IndexMetaDataAction
Action to perform with index metadata.static class
GatewayMetaState.KeepPreviousGeneration
static class
GatewayMetaState.WriteChangedIndexMetaData
static class
GatewayMetaState.WriteNewIndexMetaData
-
Field Summary
Fields Modifier and Type Field Description protected boolean
incrementalWrite
protected static org.apache.logging.log4j.Logger
logger
protected ClusterState
previousClusterState
protected Manifest
previousManifest
-
Constructor Summary
Constructors Constructor Description GatewayMetaState(Settings settings, MetaStateService metaStateService, MetaDataIndexUpgradeService metaDataIndexUpgradeService, MetaDataUpgrader metaDataUpgrader, TransportService transportService, ClusterService clusterService)
-
Method Summary
Modifier and Type Method Description void
applyClusterState(ClusterChangedEvent event)
Called when a new cluster state (ClusterChangedEvent.state()
needs to be applied.void
applyClusterStateUpdaters()
long
getCurrentTerm()
Returns the current termClusterState
getLastAcceptedState()
Returns the last accepted cluster stateMetaData
getMetaData()
CoordinationState.PersistedState
getPersistedState(Settings settings, ClusterApplierService clusterApplierService)
static java.util.Set<Index>
getRelevantIndices(ClusterState state, ClusterState previousState, java.util.Set<Index> previouslyWrittenIndices)
static java.util.List<GatewayMetaState.IndexMetaDataAction>
resolveIndexMetaDataActions(java.util.Map<Index,java.lang.Long> previouslyWrittenIndices, java.util.Set<Index> relevantIndices, MetaData previousMetaData, MetaData newMetaData)
Returns list ofGatewayMetaState.IndexMetaDataAction
for each relevant index.void
setCurrentTerm(long currentTerm)
Sets a new current term.void
setLastAcceptedState(ClusterState clusterState)
Sets a new last accepted cluster state.protected void
upgradeMetaData(MetaDataIndexUpgradeService metaDataIndexUpgradeService, MetaDataUpgrader metaDataUpgrader)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.cluster.coordination.CoordinationState.PersistedState
close, markLastAcceptedStateAsCommitted
-
-
-
-
Field Detail
-
logger
protected static final org.apache.logging.log4j.Logger logger
-
previousManifest
protected Manifest previousManifest
-
previousClusterState
protected ClusterState previousClusterState
-
incrementalWrite
protected boolean incrementalWrite
-
-
Constructor Detail
-
GatewayMetaState
public GatewayMetaState(Settings settings, MetaStateService metaStateService, MetaDataIndexUpgradeService metaDataIndexUpgradeService, MetaDataUpgrader metaDataUpgrader, TransportService transportService, ClusterService clusterService) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
getPersistedState
public CoordinationState.PersistedState getPersistedState(Settings settings, ClusterApplierService clusterApplierService)
-
applyClusterStateUpdaters
public void applyClusterStateUpdaters()
-
upgradeMetaData
protected void upgradeMetaData(MetaDataIndexUpgradeService metaDataIndexUpgradeService, MetaDataUpgrader metaDataUpgrader) throws java.io.IOException
- Throws:
java.io.IOException
-
getMetaData
public MetaData getMetaData()
-
applyClusterState
public void applyClusterState(ClusterChangedEvent event)
Description copied from interface:ClusterStateApplier
Called when a new cluster state (ClusterChangedEvent.state()
needs to be applied. The cluster state to be applied is already committed when this method is called, so an applier must therefore be prepared to deal with any state it receives without throwing an exception. Throwing an exception from an applier is very bad because it will stop the application of this state before it has reached all the other appliers, and will likely result in another attempt to apply the same (or very similar) cluster state which might continue until this node is removed from the cluster.- Specified by:
applyClusterState
in interfaceClusterStateApplier
-
getCurrentTerm
public long getCurrentTerm()
Description copied from interface:CoordinationState.PersistedState
Returns the current term- Specified by:
getCurrentTerm
in interfaceCoordinationState.PersistedState
-
getLastAcceptedState
public ClusterState getLastAcceptedState()
Description copied from interface:CoordinationState.PersistedState
Returns the last accepted cluster state- Specified by:
getLastAcceptedState
in interfaceCoordinationState.PersistedState
-
setCurrentTerm
public void setCurrentTerm(long currentTerm)
Description copied from interface:CoordinationState.PersistedState
Sets a new current term. After a successful call to this method,CoordinationState.PersistedState.getCurrentTerm()
should return the last term that was set. The value returned byCoordinationState.PersistedState.getLastAcceptedState()
should not be influenced by calls to this method.- Specified by:
setCurrentTerm
in interfaceCoordinationState.PersistedState
-
setLastAcceptedState
public void setLastAcceptedState(ClusterState clusterState)
Description copied from interface:CoordinationState.PersistedState
Sets a new last accepted cluster state. After a successful call to this method,CoordinationState.PersistedState.getLastAcceptedState()
should return the last cluster state that was set. The value returned byCoordinationState.PersistedState.getCurrentTerm()
should not be influenced by calls to this method.- Specified by:
setLastAcceptedState
in interfaceCoordinationState.PersistedState
-
getRelevantIndices
public static java.util.Set<Index> getRelevantIndices(ClusterState state, ClusterState previousState, java.util.Set<Index> previouslyWrittenIndices)
-
resolveIndexMetaDataActions
public static java.util.List<GatewayMetaState.IndexMetaDataAction> resolveIndexMetaDataActions(java.util.Map<Index,java.lang.Long> previouslyWrittenIndices, java.util.Set<Index> relevantIndices, MetaData previousMetaData, MetaData newMetaData)
Returns list ofGatewayMetaState.IndexMetaDataAction
for each relevant index. For each relevant index there are 3 options:-
GatewayMetaState.KeepPreviousGeneration
- index metadata is already stored to disk and index metadata version is not changed, no action is required. -
GatewayMetaState.WriteNewIndexMetaData
- there is no index metadata on disk and index metadata for this index should be written. -
GatewayMetaState.WriteChangedIndexMetaData
- index metadata is already on disk, but index metadata version has changed. Updated index metadata should be written to disk.
- Parameters:
previouslyWrittenIndices
- A list of indices for which the state was already written beforerelevantIndices
- The list of indices for which state should potentially be writtenpreviousMetaData
- The last meta data we know ofnewMetaData
- The new metadata- Returns:
- list of
GatewayMetaState.IndexMetaDataAction
for each relevant index.
-
-
-