Class PersistedClusterStateService

java.lang.Object
org.elasticsearch.gateway.PersistedClusterStateService

public class PersistedClusterStateService
extends java.lang.Object
Stores cluster metadata in a bare Lucene index (per data path) split across a number of documents. This is used by master-eligible nodes to record the last-accepted cluster state during publication. The metadata is written incrementally where possible, leaving alone any documents that have not changed. The index has the following fields: +------------------------------+-----------------------------+----------------------------------------------+ | "type" (string field) | "index_uuid" (string field) | "data" (stored binary field in SMILE format) | +------------------------------+-----------------------------+----------------------------------------------+ | GLOBAL_TYPE_NAME == "global" | (omitted) | Global metadata | | INDEX_TYPE_NAME == "index" | Index UUID | Index metadata | +------------------------------+-----------------------------+----------------------------------------------+ Additionally each commit has the following user data: +---------------------------+-------------------------+-------------------------------------------------------------------------------+ | Key symbol | Key literal | Value | +---------------------------+-------------------------+-------------------------------------------------------------------------------+ | CURRENT_TERM_KEY | "current_term" | Node's "current" term (≥ last-accepted term and the terms of all sent joins) | | LAST_ACCEPTED_VERSION_KEY | "last_accepted_version" | The cluster state version corresponding with the persisted metadata | | NODE_ID_KEY | "node_id" | The (persistent) ID of the node that wrote this metadata | | NODE_VERSION_KEY | "node_version" | The (ID of the) version of the node that wrote this metadata | +---------------------------+-------------------------+-------------------------------------------------------------------------------+ (the last-accepted term is recorded in Metadata → CoordinationMetadata so does not need repeating here)
  • Field Details

    • METADATA_DIRECTORY_NAME

      public static final java.lang.String METADATA_DIRECTORY_NAME
      See Also:
      Constant Field Values
    • SLOW_WRITE_LOGGING_THRESHOLD

      public static final Setting<org.elasticsearch.common.unit.TimeValue> SLOW_WRITE_LOGGING_THRESHOLD
  • Constructor Details

    • PersistedClusterStateService

      public PersistedClusterStateService​(NodeEnvironment nodeEnvironment, org.elasticsearch.common.xcontent.NamedXContentRegistry namedXContentRegistry, BigArrays bigArrays, ClusterSettings clusterSettings, java.util.function.LongSupplier relativeTimeMillisSupplier)
    • PersistedClusterStateService

      public PersistedClusterStateService​(java.nio.file.Path[] dataPaths, java.lang.String nodeId, org.elasticsearch.common.xcontent.NamedXContentRegistry namedXContentRegistry, BigArrays bigArrays, ClusterSettings clusterSettings, java.util.function.LongSupplier relativeTimeMillisSupplier)
  • Method Details

    • getNodeId

      public java.lang.String getNodeId()
    • createWriter

      public PersistedClusterStateService.Writer createWriter() throws java.io.IOException
      Creates a new disk-based writer for cluster states
      Throws:
      java.io.IOException
    • deleteAll

      public static void deleteAll​(java.nio.file.Path[] dataPaths) throws java.io.IOException
      Remove all persisted cluster states from the given data paths, for use in tests. Should only be called when there is no open PersistedClusterStateService.Writer on these paths.
      Throws:
      java.io.IOException
    • getDataPaths

      public java.nio.file.Path[] getDataPaths()
    • nodeMetadata

      @Nullable public static NodeMetadata nodeMetadata​(java.nio.file.Path... dataPaths) throws java.io.IOException
      Returns the node metadata for the given data paths, and checks if the node ids are unique
      Parameters:
      dataPaths - the data paths to scan
      Throws:
      java.io.IOException
    • overrideVersion

      public static void overrideVersion​(Version newVersion, java.nio.file.Path... dataPaths) throws java.io.IOException
      Overrides the version field for the metadata in the given data path
      Throws:
      java.io.IOException
    • loadBestOnDiskState

      public PersistedClusterStateService.OnDiskState loadBestOnDiskState() throws java.io.IOException
      Loads the best available on-disk cluster state. Returns PersistedClusterStateService.OnDiskState.NO_ON_DISK_STATE if no such state was found.
      Throws:
      java.io.IOException