Package org.elasticsearch.gateway
Class MetaStateService
- java.lang.Object
-
- org.elasticsearch.gateway.MetaStateService
-
public class MetaStateService extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected MetaDataStateFormat<IndexMetaData>INDEX_META_DATA_FORMATprotected MetaDataStateFormat<Manifest>MANIFEST_FORMATprotected MetaDataStateFormat<MetaData>META_DATA_FORMAT
-
Constructor Summary
Constructors Constructor Description MetaStateService(NodeEnvironment nodeEnv, NamedXContentRegistry namedXContentRegistry)
-
Method Summary
Modifier and Type Method Description voidcleanupIndex(Index index, long currentGeneration)Removes old state files in index directory.IndexMetaDataloadIndexState(Index index)Loads the index state for the provided index name, returning null if doesn't exists.ManifestloadManifestOrEmpty()Loads Manifest file from disk, returnsManifest.empty()if there is no manifest file.voidwriteGlobalStateAndUpdateManifest(java.lang.String reason, MetaData metaData)Writes global metadata and updates manifest file accordingly.longwriteIndex(java.lang.String reason, IndexMetaData indexMetaData)Writes the index state.voidwriteIndexAndUpdateManifest(java.lang.String reason, IndexMetaData metaData)Writes index metadata and updates manifest file accordingly.longwriteManifestAndCleanup(java.lang.String reason, Manifest manifest)Writes manifest file (represented byManifest) to disk and performs cleanup of old manifest state file if the write succeeds or newly created manifest state if the write fails.
-
-
-
Field Detail
-
META_DATA_FORMAT
protected MetaDataStateFormat<MetaData> META_DATA_FORMAT
-
INDEX_META_DATA_FORMAT
protected MetaDataStateFormat<IndexMetaData> INDEX_META_DATA_FORMAT
-
MANIFEST_FORMAT
protected MetaDataStateFormat<Manifest> MANIFEST_FORMAT
-
-
Constructor Detail
-
MetaStateService
public MetaStateService(NodeEnvironment nodeEnv, NamedXContentRegistry namedXContentRegistry)
-
-
Method Detail
-
loadIndexState
@Nullable public IndexMetaData loadIndexState(Index index) throws java.io.IOException
Loads the index state for the provided index name, returning null if doesn't exists.- Throws:
java.io.IOException
-
loadManifestOrEmpty
public Manifest loadManifestOrEmpty() throws java.io.IOException
Loads Manifest file from disk, returnsManifest.empty()if there is no manifest file.- Throws:
java.io.IOException
-
writeManifestAndCleanup
public long writeManifestAndCleanup(java.lang.String reason, Manifest manifest) throws WriteStateExceptionWrites manifest file (represented byManifest) to disk and performs cleanup of old manifest state file if the write succeeds or newly created manifest state if the write fails.- Throws:
WriteStateException- if exception when writing state occurs. See alsoWriteStateException.isDirty()
-
writeIndex
public long writeIndex(java.lang.String reason, IndexMetaData indexMetaData) throws WriteStateExceptionWrites the index state.This method is public for testing purposes.
- Throws:
WriteStateException- if exception when writing state occurs.WriteStateException.isDirty()will always return false, because new index state file is not yet referenced by manifest file.
-
cleanupIndex
public void cleanupIndex(Index index, long currentGeneration)
Removes old state files in index directory.- Parameters:
index- index to perform clean up on.currentGeneration- current state generation to keep in the index directory.
-
writeIndexAndUpdateManifest
public void writeIndexAndUpdateManifest(java.lang.String reason, IndexMetaData metaData) throws java.io.IOExceptionWrites index metadata and updates manifest file accordingly. Used by tests.- Throws:
java.io.IOException
-
writeGlobalStateAndUpdateManifest
public void writeGlobalStateAndUpdateManifest(java.lang.String reason, MetaData metaData) throws java.io.IOExceptionWrites global metadata and updates manifest file accordingly. Used by tests.- Throws:
java.io.IOException
-
-