Class MetaStateService

java.lang.Object
org.elasticsearch.gateway.MetaStateService

public class MetaStateService
extends java.lang.Object
Handles writing and loading Manifest, Metadata and IndexMetadata
  • 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.elasticsearch.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 metadata
    org.elasticsearch.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, returns Manifest.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 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • MetaStateService

      public MetaStateService​(NodeEnvironment nodeEnv, org.elasticsearch.common.xcontent.NamedXContentRegistry namedXContentRegistry)
  • Method Details

    • loadFullState

      public org.elasticsearch.common.collect.Tuple<Manifest,​Metadata> loadFullState() throws java.io.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:
      java.io.IOException - if some IOException when loading files occurs or there is no metadata referenced by manifest file.
    • 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, returns Manifest.empty() if there is no manifest file.
      Throws:
      java.io.IOException
    • writeManifestAndCleanup

      public void writeManifestAndCleanup​(java.lang.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​(java.lang.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​(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 java.io.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:
      java.io.IOException
    • deleteAll

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