Class MetaStateService

java.lang.Object
org.opensearch.gateway.MetaStateService

public class MetaStateService extends Object
Handles writing and loading Manifest, Metadata and IndexMetadata
Opensearch.internal:
  • Field Details

  • Constructor Details

    • MetaStateService

      public MetaStateService(NodeEnvironment nodeEnv, org.opensearch.core.xcontent.NamedXContentRegistry namedXContentRegistry)
  • Method Details

    • loadFullState

      public org.opensearch.common.collect.Tuple<Manifest,Metadata> loadFullState() throws IOException
      Loads the full state, which includes both the global state and all the indices meta data.
      When loading, manifest file is consulted (represented by Manifest 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 and Metadata 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

      public Manifest loadManifestOrEmpty() throws IOException
      Loads Manifest file from disk, returns Manifest.empty() if there is no manifest file.
      Throws:
      IOException
    • writeManifestAndCleanup

      public void writeManifestAndCleanup(String reason, Manifest manifest) throws WriteStateException
      Writes manifest file (represented by Manifest) 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 also WriteStateException.isDirty()
    • writeIndex

      public long writeIndex(String reason, IndexMetadata indexMetadata) throws WriteStateException
      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

      public void unreferenceAll() throws IOException
      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

      public void deleteAll() throws IOException
      Removes manifest file, global metadata and all index metadata
      Throws:
      IOException