Package org.opensearch.gateway
Class MetaStateService
java.lang.Object
org.opensearch.gateway.MetaStateService
- Opensearch.internal:
-
Field Summary
Modifier and TypeFieldDescriptionprotected MetadataStateFormat
<IndexMetadata> protected MetadataStateFormat
<Manifest> protected MetadataStateFormat
<Metadata> -
Constructor Summary
ConstructorDescriptionMetaStateService
(NodeEnvironment nodeEnv, org.opensearch.core.xcontent.NamedXContentRegistry namedXContentRegistry) -
Method Summary
Modifier and TypeMethodDescriptionvoid
cleanupIndex
(org.opensearch.core.index.Index index, long currentGeneration) Removes old state files in index directory.void
Removes manifest file, global metadata and all index metadataLoads the full state, which includes both the global state and all the indices meta data.loadIndexState
(org.opensearch.core.index.Index index) Loads the index state for the provided index name, returning null if doesn't exists.Loads Manifest file from disk, returnsManifest.empty()
if there is no manifest file.void
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
(String reason, IndexMetadata indexMetadata) Writes the index state.void
writeManifestAndCleanup
(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
-
METADATA_FORMAT
-
INDEX_METADATA_FORMAT
-
MANIFEST_FORMAT
-
-
Constructor Details
-
MetaStateService
public MetaStateService(NodeEnvironment nodeEnv, org.opensearch.core.xcontent.NamedXContentRegistry namedXContentRegistry)
-
-
Method Details
-
loadFullState
Loads 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:
IOException
- if some IOException when loading files occurs or there is no metadata referenced by manifest file.
-
loadIndexState
@Nullable public IndexMetadata loadIndexState(org.opensearch.core.index.Index index) throws IOException Loads the index state for the provided index name, returning null if doesn't exists.- Throws:
IOException
-
loadManifestOrEmpty
Loads Manifest file from disk, returnsManifest.empty()
if there is no manifest file.- Throws:
IOException
-
writeManifestAndCleanup
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.- Throws:
WriteStateException
- if exception when writing state occurs. See alsoWriteStateException.isDirty()
-
writeIndex
Writes 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(org.opensearch.core.index.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.
-
unreferenceAll
Creates empty cluster state file on disk, deleting global metadata and unreferencing all index metadata (only used for dangling indices at that point).- Throws:
IOException
-
deleteAll
Removes manifest file, global metadata and all index metadata- Throws:
IOException
-