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-createsClusterStateand broadcasts this state to other nodes in the cluster.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceGatewayMetaState.IndexMetaDataActionAction to perform with index metadata.static classGatewayMetaState.KeepPreviousGenerationstatic classGatewayMetaState.WriteChangedIndexMetaDatastatic classGatewayMetaState.WriteNewIndexMetaData
-
Field Summary
Fields Modifier and Type Field Description protected booleanincrementalWriteprotected static org.apache.logging.log4j.Loggerloggerprotected ClusterStatepreviousClusterStateprotected ManifestpreviousManifest
-
Constructor Summary
Constructors Constructor Description GatewayMetaState(Settings settings, NodeEnvironment nodeEnv, MetaStateService metaStateService, MetaDataIndexUpgradeService metaDataIndexUpgradeService, MetaDataUpgrader metaDataUpgrader, TransportService transportService, ClusterService clusterService, IndicesService indicesService)
-
Method Summary
Modifier and Type Method Description voidapplyClusterState(ClusterChangedEvent event)Called when a new cluster state (ClusterChangedEvent.state()needs to be appliedvoidapplyClusterStateUpdaters()longgetCurrentTerm()Returns the current termClusterStategetLastAcceptedState()Returns the last accepted cluster stateMetaDatagetMetaData()CoordinationState.PersistedStategetPersistedState(Settings settings, ClusterApplierService clusterApplierService)static java.util.Set<Index>getRelevantIndices(ClusterState state, ClusterState previousState, java.util.Set<Index> previouslyWrittenIndices)protected booleanisMasterOrDataNode()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.IndexMetaDataActionfor each relevant index.voidsetCurrentTerm(long currentTerm)Sets a new current term.voidsetLastAcceptedState(ClusterState clusterState)Sets a new last accepted cluster state.protected voidupdateClusterState(ClusterState newState, ClusterState previousState)Updates manifest and meta data on disk.protected voidupgradeMetaData(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
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, NodeEnvironment nodeEnv, MetaStateService metaStateService, MetaDataIndexUpgradeService metaDataIndexUpgradeService, MetaDataUpgrader metaDataUpgrader, TransportService transportService, ClusterService clusterService, IndicesService indicesService) 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
-
isMasterOrDataNode
protected boolean isMasterOrDataNode()
-
getMetaData
public MetaData getMetaData()
-
applyClusterState
public void applyClusterState(ClusterChangedEvent event)
Description copied from interface:ClusterStateApplierCalled when a new cluster state (ClusterChangedEvent.state()needs to be applied- Specified by:
applyClusterStatein interfaceClusterStateApplier
-
getCurrentTerm
public long getCurrentTerm()
Description copied from interface:CoordinationState.PersistedStateReturns the current term- Specified by:
getCurrentTermin interfaceCoordinationState.PersistedState
-
getLastAcceptedState
public ClusterState getLastAcceptedState()
Description copied from interface:CoordinationState.PersistedStateReturns the last accepted cluster state- Specified by:
getLastAcceptedStatein interfaceCoordinationState.PersistedState
-
setCurrentTerm
public void setCurrentTerm(long currentTerm)
Description copied from interface:CoordinationState.PersistedStateSets 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:
setCurrentTermin interfaceCoordinationState.PersistedState
-
setLastAcceptedState
public void setLastAcceptedState(ClusterState clusterState)
Description copied from interface:CoordinationState.PersistedStateSets 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:
setLastAcceptedStatein interfaceCoordinationState.PersistedState
-
updateClusterState
protected void updateClusterState(ClusterState newState, ClusterState previousState) throws WriteStateException
Updates manifest and meta data on disk.- Parameters:
newState- newClusterStatepreviousState- previousClusterState- Throws:
WriteStateException- if exception occurs. See alsoWriteStateException.isDirty().
-
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.IndexMetaDataActionfor 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.IndexMetaDataActionfor each relevant index.
-
-
-