- All Implemented Interfaces:
Iterable<IndexMetadata>
,Collection<IndexMetadata>
,Diffable<Metadata>
,Writeable
,ToXContent
,ToXContentFragment
public class Metadata
extends AbstractCollection<IndexMetadata>
implements Diffable<Metadata>, ToXContentFragment
Metadata
is the part of the ClusterState
which persists across restarts. This persistence is XContent-based, so a
round-trip through XContent must be faithful in Metadata.XContentContext.GATEWAY
context.
The details of how this is persisted are covered in PersistedClusterStateService
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static interface
Custom metadata that persists (via XContent) across restarts.static enum
Nested classes/interfaces inherited from interface org.elasticsearch.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static EnumSet<Metadata.XContentContext>
Indicates that this custom metadata will be returned as part of an API call, stored as a part of a snapshot global state, and will be persisted between node restartsstatic EnumSet<Metadata.XContentContext>
Indicates that this custom metadata will be returned as part of an API call and will be persisted between node restarts, but will not be a part of a snapshot global statestatic EnumSet<Metadata.XContentContext>
Indicates that this custom metadata will be returned as part of an API call and stored as a part of a snapshot global state, but will not be persisted between node restartsstatic EnumSet<Metadata.XContentContext>
Indicates that this custom metadata will be returned as part of an API call but will not be persistedstatic final ClusterBlock
static final ClusterBlock
static final String
static final String
static final String
static final String
static final String
static final Metadata
static final MetadataStateFormat<Metadata>
State format forMetadata
to write to and load from diskstatic final String
static final Version
static final Runnable
static final String
Fields inherited from interface org.elasticsearch.xcontent.ToXContent
EMPTY_PARAMS
-
Method Summary
Modifier and TypeMethodDescriptionaliasedIndices
(String aliasName) Returns all the indices that the alias with the provided alias name refers to.static Metadata.Builder
builder()
static Metadata.Builder
boolean
Whether the current node with the given cluster state is locked into the cluster with the UUID returned byclusterUUID()
, meaning that it will not accept any cluster state with a different clusterUUID.copyAndUpdate
(Consumer<Metadata.Builder> updater) <T extends Metadata.Custom>
T<T extends Metadata.Custom>
Tcustoms()
Returns serializable object representing differences between this and previousStateboolean
equalsAliases
(Metadata other) findAliases
(String[] aliases, String[] concreteIndices) Finds the specific index aliases that match with the specified aliases directly or partially via wildcards, and that point to the specified concrete indices (directly or matching indices via wildcards).findAllAliases
(String[] concreteIndices) Finds the specific index aliases that point to the requested concrete indices directly or that match with the indices via wildcards.findDataStreams
(String... concreteIndices) Finds the parent data streams, if any, for the specified concrete indices.findMappings
(String[] concreteIndices, Function<String, Predicate<String>> fieldFilter, Runnable onNextIndex) Finds all mappings for concrete indices.static Metadata
fromXContent
(XContentParser parser) String[]
Returns all of the concrete indices that are closed.String[]
Returns all the concrete indices.String[]
Returns all of the concrete indices that are open.String[]
Returns all of the concrete indices that are closed and not hidden.String[]
Returns all the concrete indices that are not hidden.String[]
Returns all of the concrete indices that are open and not hidden.getIndexSafe
(Index index) Returns theIndexMetadata
for this index.int
Gets the total number of shards from all indices, including replicas and closed indices.int
Gets the total number of open shards from all indices.boolean
Returns whether an alias exists with provided alias name.boolean
Checks whether an index exists (as of thisMetadata
with the given name.boolean
Checks whether an index exists.boolean
hasIndexAbstraction
(String index) Checks whether an index abstraction (that is, index, alias, or data stream) exists (as of thisMetadata
with the given name.boolean
hasIndexMetadata
(IndexMetadata indexMetadata) Returns true iff existing index has the sameIndexMetadata
instanceThe collection of index deletions in the cluster.indices()
static boolean
isGlobalStateEquals
(Metadata metadata1, Metadata metadata2) boolean
isTimeSeriesTemplate
(ComposableIndexTemplate indexTemplate) iterator()
static Metadata
readFrom
(StreamInput in) Returns the fullReservedStateMetadata
Map for all reserved state namespaces.resolveIndexRouting
(String routing, String aliasOrIndex) Returns indexing routing for the given index.resolveWriteIndexRouting
(String routing, String aliasOrIndex) Returns indexing routing for the givenaliasOrIndex
.boolean
sameIndicesLookup
(Metadata other) settings()
Returns the merged transient and persistent settings.int
size()
static Metadata
Reconciles the cluster state metadata taken at the end of a snapshot with the data streams and indices contained in the snapshot.toXContent
(XContentBuilder builder, ToXContent.Params params) long
version()
Creates a copy of this instance updated with the givenIndexMetadata
that must only contain changes to primary terms and in-sync allocation ids relative to the existing entries.withCoordinationMetadata
(CoordinationMetadata coordinationMetadata) withLifecycleState
(Index index, LifecycleExecutionState lifecycleState) Given an index and lifecycle state, returns a metadata where the lifecycle state will be associated with the given index.void
writeTo
(StreamOutput out) Write this into the StreamOutput.Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
Methods inherited from interface org.elasticsearch.xcontent.ToXContentFragment
isFragment
-
Field Details
-
ON_NEXT_INDEX_FIND_MAPPINGS_NOOP
-
ALL
- See Also:
-
UNKNOWN_CLUSTER_UUID
- See Also:
-
API_ONLY
Indicates that this custom metadata will be returned as part of an API call but will not be persisted -
API_AND_GATEWAY
Indicates that this custom metadata will be returned as part of an API call and will be persisted between node restarts, but will not be a part of a snapshot global state -
API_AND_SNAPSHOT
Indicates that this custom metadata will be returned as part of an API call and stored as a part of a snapshot global state, but will not be persisted between node restarts -
ALL_CONTEXTS
Indicates that this custom metadata will be returned as part of an API call, stored as a part of a snapshot global state, and will be persisted between node restarts -
SETTING_READ_ONLY_SETTING
-
CLUSTER_READ_ONLY_BLOCK
-
SETTING_READ_ONLY_ALLOW_DELETE_SETTING
-
CLUSTER_READ_ONLY_ALLOW_DELETE_BLOCK
-
EMPTY_METADATA
-
CONTEXT_MODE_PARAM
- See Also:
-
CONTEXT_MODE_SNAPSHOT
-
CONTEXT_MODE_GATEWAY
-
CONTEXT_MODE_API
-
DEDUPLICATED_MAPPINGS_PARAM
- See Also:
-
GLOBAL_STATE_FILE_PREFIX
- See Also:
-
MAPPINGS_AS_HASH_VERSION
-
FORMAT
State format forMetadata
to write to and load from disk
-
-
Method Details
-
withIncrementedVersion
-
withLifecycleState
Given an index and lifecycle state, returns a metadata where the lifecycle state will be associated with the given index. The passed-in index must already be present in the cluster state, this method cannot be used to add an index.- Parameters:
index
- A non-null indexlifecycleState
- A non-null lifecycle execution state- Returns:
- a
Metadata
instance where the index has the provided lifecycle state
-
withCoordinationMetadata
-
withAllocationAndTermUpdatesOnly
Creates a copy of this instance updated with the givenIndexMetadata
that must only contain changes to primary terms and in-sync allocation ids relative to the existing entries. This method is only used byIndexMetadataUpdater.applyChanges(Metadata, RoutingTable)
.- Parameters:
updates
- map of index name toIndexMetadata
.- Returns:
- updated metadata instance
-
version
public long version() -
clusterUUID
-
clusterUUIDCommitted
public boolean clusterUUIDCommitted()Whether the current node with the given cluster state is locked into the cluster with the UUID returned byclusterUUID()
, meaning that it will not accept any cluster state with a different clusterUUID. -
settings
Returns the merged transient and persistent settings. -
transientSettings
-
persistentSettings
-
hashesOfConsistentSettings
-
coordinationMetadata
-
oldestIndexVersion
-
equalsAliases
-
getIndicesLookup
-
sameIndicesLookup
-
findAllAliases
Finds the specific index aliases that point to the requested concrete indices directly or that match with the indices via wildcards.- Parameters:
concreteIndices
- The concrete indices that the aliases must point to in order to be returned.- Returns:
- A map of index name to the list of aliases metadata. If a concrete index does not have matching aliases then the result will not include the index's key.
-
findAliases
Finds the specific index aliases that match with the specified aliases directly or partially via wildcards, and that point to the specified concrete indices (directly or matching indices via wildcards).- Parameters:
aliases
- The aliases to look for. Might contain include or exclude wildcards.concreteIndices
- The concrete indices that the aliases must point to in order to be returned- Returns:
- A map of index name to the list of aliases metadata. If a concrete index does not have matching aliases then the result will not include the index's key.
-
findMappings
public Map<String,MappingMetadata> findMappings(String[] concreteIndices, Function<String, Predicate<String>> fieldFilter, Runnable onNextIndex) Finds all mappings for concrete indices. Only fields that match the provided field filter will be returned (default is a predicate that always returns true, which can be overridden via plugins)- Parameters:
onNextIndex
- a hook that gets notified for each index that's processed- See Also:
-
findDataStreams
Finds the parent data streams, if any, for the specified concrete indices. -
getConcreteAllIndices
Returns all the concrete indices. -
getConcreteVisibleIndices
Returns all the concrete indices that are not hidden. -
getConcreteAllOpenIndices
Returns all of the concrete indices that are open. -
getConcreteVisibleOpenIndices
Returns all of the concrete indices that are open and not hidden. -
getConcreteAllClosedIndices
Returns all of the concrete indices that are closed. -
getConcreteVisibleClosedIndices
Returns all of the concrete indices that are closed and not hidden. -
resolveWriteIndexRouting
Returns indexing routing for the givenaliasOrIndex
. Resolves routing from the alias metadata used in the write index. -
resolveIndexRouting
Returns indexing routing for the given index. -
hasIndex
Checks whether an index exists (as of thisMetadata
with the given name. Does not check aliases or data streams.- Parameters:
index
- An index name that may or may not exist in the cluster.- Returns:
true
if a concrete index with that name exists,false
otherwise.
-
hasIndex
Checks whether an index exists. Similar tohasIndex(String)
, but ensures that the index has the same UUID as the givenIndex
.- Parameters:
index
- AnIndex
object that may or may not exist in the cluster.- Returns:
true
if an index exists with the same name and UUID as the given index object,false
otherwise.
-
hasIndexAbstraction
Checks whether an index abstraction (that is, index, alias, or data stream) exists (as of thisMetadata
with the given name.- Parameters:
index
- An index name that may or may not exist in the cluster.- Returns:
true
if an index abstraction with that name exists,false
otherwise.
-
index
-
index
-
hasIndexMetadata
Returns true iff existing index has the sameIndexMetadata
instance -
getIndexSafe
Returns theIndexMetadata
for this index.- Throws:
IndexNotFoundException
- if no metadata for this index is found
-
indices
-
getIndices
-
hasAlias
Returns whether an alias exists with provided alias name.- Parameters:
aliasName
- The provided alias name- Returns:
- whether an alias exists with provided alias name
-
aliasedIndices
Returns all the indices that the alias with the provided alias name refers to. These are aliased indices. Not that, this only return indices that have been aliased and not indices that are behind a data stream or data stream alias.- Parameters:
aliasName
- The provided alias name- Returns:
- all aliased indices by the alias with the provided alias name
-
aliasedIndices
- Returns:
- the names of all indices aliases.
-
templates
-
getTemplates
-
componentTemplates
-
templatesV2
-
isTimeSeriesTemplate
-
dataStreams
-
dataStreamAliases
-
nodeShutdowns
-
customs
-
reservedStateMetadata
Returns the fullReservedStateMetadata
Map for all reserved state namespaces.- Returns:
- a map of namespace to
ReservedStateMetadata
-
indexGraveyard
The collection of index deletions in the cluster. -
custom
-
custom
-
getTotalNumberOfShards
public int getTotalNumberOfShards()Gets the total number of shards from all indices, including replicas and closed indices.- Returns:
- The total number shards from all indices.
-
getTotalOpenIndexShards
public int getTotalOpenIndexShards()Gets the total number of open shards from all indices. Includes replicas, but does not include shards that are part of closed indices.- Returns:
- The total number of open shards from all indices.
-
iterator
- Specified by:
iterator
in interfaceCollection<IndexMetadata>
- Specified by:
iterator
in interfaceIterable<IndexMetadata>
- Specified by:
iterator
in classAbstractCollection<IndexMetadata>
-
size
public int size()- Specified by:
size
in interfaceCollection<IndexMetadata>
- Specified by:
size
in classAbstractCollection<IndexMetadata>
-
isGlobalStateEquals
-
snapshot
Reconciles the cluster state metadata taken at the end of a snapshot with the data streams and indices contained in the snapshot. Certain actions taken during a snapshot such as rolling over a data stream or deleting a backing index may result in situations where some reconciliation is required.- Returns:
- Reconciled
Metadata
instance
-
diff
Description copied from interface:Diffable
Returns serializable object representing differences between this and previousState -
readDiffFrom
- Throws:
IOException
-
fromXContent
- Throws:
IOException
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException - Specified by:
toXContent
in interfaceToXContent
- Throws:
IOException
-
getMappingsByHash
-
readFrom
- Throws:
IOException
-
writeTo
Description copied from interface:Writeable
Write this into the StreamOutput.- Specified by:
writeTo
in interfaceWriteable
- Throws:
IOException
-
builder
-
builder
-
copyAndUpdate
-