Package org.opensearch.gateway
Class MetaStateService
java.lang.Object
org.opensearch.gateway.MetaStateService
public class MetaStateService
extends java.lang.Object
-
Field Summary
Fields Modifier and Type Field Description protected MetadataStateFormat<IndexMetadata>
INDEX_METADATA_FORMAT
protected MetadataStateFormat<Manifest>
MANIFEST_FORMAT
protected MetadataStateFormat<Metadata>
METADATA_FORMAT
-
Constructor Summary
Constructors Constructor Description MetaStateService(NodeEnvironment nodeEnv, org.opensearch.common.xcontent.NamedXContentRegistry namedXContentRegistry)
-
Method Summary
Modifier and Type Method Description void
cleanupIndex(Index index, long currentGeneration)
Removes old state files in index directory.void
deleteAll()
Removes manifest file, global metadata and all index metadataorg.opensearch.common.collect.Tuple<Manifest,Metadata>
loadFullState()
Loads the full state, which includes both the global state and all the indices meta data.IndexMetadata
loadIndexState(Index index)
Loads the index state for the provided index name, returning null if doesn't exists.Manifest
loadManifestOrEmpty()
Loads Manifest file from disk, returnsManifest.empty()
if there is no manifest file.void
unreferenceAll()
Creates empty cluster state file on disk, deleting global metadata and unreferencing all index metadata (only used for dangling indices at that point).long
writeIndex(java.lang.String reason, IndexMetadata indexMetadata)
Writes the index state.void
writeManifestAndCleanup(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 Details
-
Constructor Details
-
MetaStateService
public MetaStateService(NodeEnvironment nodeEnv, org.opensearch.common.xcontent.NamedXContentRegistry namedXContentRegistry)
-
-
Method Details
-
loadFullState
public org.opensearch.common.collect.Tuple<Manifest,Metadata> loadFullState() throws java.io.IOExceptionLoads the full state, which includes both the global state and all the indices meta data.
When loading, manifest file is consulted (represented byManifest
class), to load proper generations.
If there is no manifest file on disk, this method fallbacks to BWC mode, where latest generation of global and indices metadata is loaded. Please note that currently there is no way to distinguish between manifest file being removed and manifest file was not yet created. It means that this method always fallbacks to BWC mode, if there is no manifest file.- Returns:
- tuple of
Manifest
andMetadata
with global metadata and indices metadata. If there is no state on disk, meta state with globalGeneration -1 and empty meta data is returned. - Throws:
java.io.IOException
- if some IOException when loading files occurs or there is no metadata referenced by manifest file.
-
loadIndexState
Loads the index state for the provided index name, returning null if doesn't exists.- Throws:
java.io.IOException
-
loadManifestOrEmpty
Loads Manifest file from disk, returnsManifest.empty()
if there is no manifest file.- Throws:
java.io.IOException
-
writeManifestAndCleanup
public void 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
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.
-
unreferenceAll
public void unreferenceAll() throws java.io.IOExceptionCreates empty cluster state file on disk, deleting global metadata and unreferencing all index metadata (only used for dangling indices at that point).- Throws:
java.io.IOException
-
deleteAll
public void deleteAll() throws java.io.IOExceptionRemoves manifest file, global metadata and all index metadata- Throws:
java.io.IOException
-