Package org.elasticsearch.gateway
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)
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PersistedClusterStateService.OnDiskState
static class
PersistedClusterStateService.Writer
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
METADATA_DIRECTORY_NAME
static Setting<org.elasticsearch.common.unit.TimeValue>
SLOW_WRITE_LOGGING_THRESHOLD
-
Constructor Summary
Constructors Constructor Description 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)
PersistedClusterStateService(NodeEnvironment nodeEnvironment, org.elasticsearch.common.xcontent.NamedXContentRegistry namedXContentRegistry, BigArrays bigArrays, ClusterSettings clusterSettings, java.util.function.LongSupplier relativeTimeMillisSupplier)
-
Method Summary
Modifier and Type Method Description PersistedClusterStateService.Writer
createWriter()
Creates a new disk-based writer for cluster statesstatic void
deleteAll(java.nio.file.Path[] dataPaths)
Remove all persisted cluster states from the given data paths, for use in tests.java.nio.file.Path[]
getDataPaths()
java.lang.String
getNodeId()
PersistedClusterStateService.OnDiskState
loadBestOnDiskState()
Loads the best available on-disk cluster state.static NodeMetadata
nodeMetadata(java.nio.file.Path... dataPaths)
Returns the node metadata for the given data paths, and checks if the node ids are uniquestatic void
overrideVersion(Version newVersion, java.nio.file.Path... dataPaths)
Overrides the version field for the metadata in the given data pathMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
METADATA_DIRECTORY_NAME
public static final java.lang.String METADATA_DIRECTORY_NAME- See Also:
- Constant Field Values
-
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
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.IOExceptionRemove all persisted cluster states from the given data paths, for use in tests. Should only be called when there is no openPersistedClusterStateService.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.IOExceptionReturns 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.IOExceptionOverrides the version field for the metadata in the given data path- Throws:
java.io.IOException
-
loadBestOnDiskState
Loads the best available on-disk cluster state. ReturnsPersistedClusterStateService.OnDiskState.NO_ON_DISK_STATE
if no such state was found.- Throws:
java.io.IOException
-