java.lang.Object
org.elasticsearch.cluster.metadata.Metadata
All Implemented Interfaces:
Iterable<IndexMetadata>, Diffable<Metadata>, Writeable, ChunkedToXContent

public class Metadata extends Object implements Iterable<IndexMetadata>, Diffable<Metadata>, ChunkedToXContent
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.

  • Field Details

    • ON_NEXT_INDEX_FIND_MAPPINGS_NOOP

      public static final Runnable ON_NEXT_INDEX_FIND_MAPPINGS_NOOP
    • ALL

      public static final String ALL
      See Also:
    • UNKNOWN_CLUSTER_UUID

      public static final String UNKNOWN_CLUSTER_UUID
      See Also:
    • API_ONLY

      public static EnumSet<Metadata.XContentContext> API_ONLY
      Indicates that this custom metadata will be returned as part of an API call but will not be persisted
    • API_AND_GATEWAY

      public static EnumSet<Metadata.XContentContext> 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

      public static EnumSet<Metadata.XContentContext> 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

      public static EnumSet<Metadata.XContentContext> 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

      public static final Setting<Boolean> SETTING_READ_ONLY_SETTING
    • CLUSTER_READ_ONLY_BLOCK

      public static final ClusterBlock CLUSTER_READ_ONLY_BLOCK
    • SETTING_READ_ONLY_ALLOW_DELETE_SETTING

      public static final Setting<Boolean> SETTING_READ_ONLY_ALLOW_DELETE_SETTING
    • CLUSTER_READ_ONLY_ALLOW_DELETE_BLOCK

      public static final ClusterBlock CLUSTER_READ_ONLY_ALLOW_DELETE_BLOCK
    • EMPTY_METADATA

      public static final Metadata EMPTY_METADATA
    • CONTEXT_MODE_PARAM

      public static final String CONTEXT_MODE_PARAM
      See Also:
    • CONTEXT_MODE_SNAPSHOT

      public static final String CONTEXT_MODE_SNAPSHOT
    • CONTEXT_MODE_GATEWAY

      public static final String CONTEXT_MODE_GATEWAY
    • CONTEXT_MODE_API

      public static final String CONTEXT_MODE_API
    • DEDUPLICATED_MAPPINGS_PARAM

      public static final String DEDUPLICATED_MAPPINGS_PARAM
      See Also:
    • GLOBAL_STATE_FILE_PREFIX

      public static final String GLOBAL_STATE_FILE_PREFIX
      See Also:
    • MAPPINGS_AS_HASH_VERSION

      public static final TransportVersion MAPPINGS_AS_HASH_VERSION
    • FORMAT

      public static final MetadataStateFormat<Metadata> FORMAT
      State format for Metadata to write to and load from disk
  • Method Details

    • withIncrementedVersion

      public Metadata withIncrementedVersion()
    • withLifecycleState

      public Metadata 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. 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 index
      lifecycleState - A non-null lifecycle execution state
      Returns:
      a Metadata instance where the index has the provided lifecycle state
    • withIndexSettingsUpdates

      public Metadata withIndexSettingsUpdates(Map<Index,Settings> updates)
    • withCoordinationMetadata

      public Metadata withCoordinationMetadata(CoordinationMetadata coordinationMetadata)
    • withLastCommittedValues

      public Metadata withLastCommittedValues(boolean clusterUUIDCommitted, CoordinationMetadata.VotingConfiguration lastCommittedConfiguration)
    • withAllocationAndTermUpdatesOnly

      public Metadata withAllocationAndTermUpdatesOnly(Map<String,IndexMetadata> updates)
      Creates a copy of this instance updated with the given IndexMetadata that must only contain changes to primary terms and in-sync allocation ids relative to the existing entries. This method is only used by IndexMetadataUpdater.applyChanges(Metadata, RoutingTable).
      Parameters:
      updates - map of index name to IndexMetadata.
      Returns:
      updated metadata instance
    • withAddedIndex

      public Metadata withAddedIndex(IndexMetadata index)
      Creates a copy of this instance with the given index added.
      Parameters:
      index - index to add
      Returns:
      copy with added index
    • version

      public long version()
    • clusterUUID

      public String clusterUUID()
    • clusterUUIDCommitted

      public boolean clusterUUIDCommitted()
      Whether the current node with the given cluster state is locked into the cluster with the UUID returned by clusterUUID(), meaning that it will not accept any cluster state with a different clusterUUID.
    • settings

      public Settings settings()
      Returns the merged transient and persistent settings.
    • transientSettings

      public Settings transientSettings()
    • persistentSettings

      public Settings persistentSettings()
    • hashesOfConsistentSettings

      public Map<String,String> hashesOfConsistentSettings()
    • coordinationMetadata

      public CoordinationMetadata coordinationMetadata()
    • oldestIndexVersion

      public IndexVersion oldestIndexVersion()
    • equalsAliases

      public boolean equalsAliases(Metadata other)
    • indicesLookupInitialized

      public boolean indicesLookupInitialized()
    • getIndicesLookup

      public SortedMap<String,IndexAbstraction> getIndicesLookup()
    • sameIndicesLookup

      public boolean sameIndicesLookup(Metadata other)
    • findAllAliases

      public Map<String,List<AliasMetadata>> findAllAliases(String[] concreteIndices)
      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

      public Map<String,List<AliasMetadata>> 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).
      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.
    • findDataStreamAliases

      public Map<String,List<DataStreamAlias>> findDataStreamAliases(String[] aliases, String[] dataStreams)
      Finds the specific data stream aliases that match with the specified aliases directly or partially via wildcards, and that point to the specified data streams (directly or matching data streams via wildcards).
      Parameters:
      aliases - The aliases to look for. Might contain include or exclude wildcards.
      dataStreams - The data streams that the aliases must point to in order to be returned
      Returns:
      A map of data stream name to the list of DataStreamAlias objects that match. If a data stream does not have matching aliases then the result will not include the data stream'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

      public Map<String,DataStream> findDataStreams(String... concreteIndices)
      Finds the parent data streams, if any, for the specified concrete indices.
    • indexIsADataStream

      public boolean indexIsADataStream(String indexName)
      Checks whether the provided index is a data stream.
    • getConcreteAllIndices

      public String[] getConcreteAllIndices()
      Returns all the concrete indices.
    • getConcreteVisibleIndices

      public String[] getConcreteVisibleIndices()
      Returns all the concrete indices that are not hidden.
    • getConcreteAllOpenIndices

      public String[] getConcreteAllOpenIndices()
      Returns all of the concrete indices that are open.
    • getConcreteVisibleOpenIndices

      public String[] getConcreteVisibleOpenIndices()
      Returns all of the concrete indices that are open and not hidden.
    • getConcreteAllClosedIndices

      public String[] getConcreteAllClosedIndices()
      Returns all of the concrete indices that are closed.
    • getConcreteVisibleClosedIndices

      public String[] getConcreteVisibleClosedIndices()
      Returns all of the concrete indices that are closed and not hidden.
    • resolveWriteIndexRouting

      public String resolveWriteIndexRouting(@Nullable String routing, String aliasOrIndex)
      Returns indexing routing for the given aliasOrIndex. Resolves routing from the alias metadata used in the write index.
    • resolveIndexRouting

      public String resolveIndexRouting(@Nullable String routing, String aliasOrIndex)
      Returns indexing routing for the given index.
    • hasIndex

      public boolean hasIndex(String index)
      Checks whether an index exists (as of this Metadata 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

      public boolean hasIndex(Index index)
      Checks whether an index exists. Similar to hasIndex(String), but ensures that the index has the same UUID as the given Index.
      Parameters:
      index - An Index 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

      public boolean hasIndexAbstraction(String index)
      Checks whether an index abstraction (that is, index, alias, or data stream) exists (as of this Metadata 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

      public IndexMetadata index(String index)
    • index

      public IndexMetadata index(Index index)
    • hasIndexMetadata

      public boolean hasIndexMetadata(IndexMetadata indexMetadata)
      Returns true iff existing index has the same IndexMetadata instance
    • getIndexSafe

      public IndexMetadata getIndexSafe(Index index)
      Returns the IndexMetadata for this index.
      Throws:
      IndexNotFoundException - if no metadata for this index is found
    • indices

      public Map<String,IndexMetadata> indices()
    • getIndices

      public Map<String,IndexMetadata> getIndices()
    • hasAlias

      public boolean hasAlias(String aliasName)
      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

      public Set<Index> aliasedIndices(String aliasName)
      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

      public Set<String> aliasedIndices()
      Returns:
      the names of all indices aliases.
    • templates

      public Map<String,IndexTemplateMetadata> templates()
    • getTemplates

      public Map<String,IndexTemplateMetadata> getTemplates()
    • componentTemplates

      public Map<String,ComponentTemplate> componentTemplates()
    • templatesV2

      public Map<String,ComposableIndexTemplate> templatesV2()
    • isTimeSeriesTemplate

      public boolean isTimeSeriesTemplate(ComposableIndexTemplate indexTemplate)
    • dataStreams

      public Map<String,DataStream> dataStreams()
    • dataStreamAliases

      public Map<String,DataStreamAlias> dataStreamAliases()
    • dataStreamAliasesByDataStream

      public Map<String,List<DataStreamAlias>> dataStreamAliasesByDataStream()
      Return a map of DataStreamAlias objects by DataStream name
      Returns:
      a map of DataStreamAlias objects by DataStream name
    • nodeShutdowns

      public NodesShutdownMetadata nodeShutdowns()
    • isIndexManagedByILM

      public boolean isIndexManagedByILM(IndexMetadata indexMetadata)
      Indicates if the provided index is managed by ILM. This takes into account if the index is part of data stream that's potentially managed by data stream lifecycle and the value of the IndexSettings.PREFER_ILM_SETTING
    • customs

      public Map<String,Metadata.Custom> customs()
    • reservedStateMetadata

      public Map<String,ReservedStateMetadata> reservedStateMetadata()
      Returns the full ReservedStateMetadata Map for all reserved state namespaces.
      Returns:
      a map of namespace to ReservedStateMetadata
    • indexGraveyard

      public IndexGraveyard indexGraveyard()
      The collection of index deletions in the cluster.
    • custom

      public <T extends Metadata.Custom> T custom(String type)
    • custom

      public <T extends Metadata.Custom> T custom(String type, T defaultValue)
    • 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

      public Iterator<IndexMetadata> iterator()
      Specified by:
      iterator in interface Iterable<IndexMetadata>
    • stream

      public Stream<IndexMetadata> stream()
    • size

      public int size()
    • isGlobalStateEquals

      public static boolean isGlobalStateEquals(Metadata metadata1, Metadata metadata2)
    • diff

      public Diff<Metadata> diff(Metadata previousState)
      Description copied from interface: Diffable
      Returns serializable object representing differences between this and previousState
      Specified by:
      diff in interface Diffable<Metadata>
    • readDiffFrom

      public static Diff<Metadata> readDiffFrom(StreamInput in) throws IOException
      Throws:
      IOException
    • fromXContent

      public static Metadata fromXContent(XContentParser parser) throws IOException
      Throws:
      IOException
    • toXContentChunked

      public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params p)
      Description copied from interface: ChunkedToXContent
      Create an iterator of ToXContent chunks for a REST response. Each chunk is serialized with the same XContentBuilder and ToXContent.Params, which is also the same as the ToXContent.Params passed as the params argument. For best results, all chunks should be O(1) size. The last chunk in the iterator must always yield at least one byte of output. See also ChunkedToXContentHelper for some handy utilities.

      Note that chunked response bodies cannot send deprecation warning headers once transmission has started, so implementations must check for deprecated feature use before returning.

      Specified by:
      toXContentChunked in interface ChunkedToXContent
      Returns:
      iterator over chunks of ToXContent
    • getMappingsByHash

      public Map<String,MappingMetadata> getMappingsByHash()
    • readFrom

      public static Metadata readFrom(StreamInput in) throws IOException
      Throws:
      IOException
    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      Throws:
      IOException
    • builder

      public static Metadata.Builder builder()
    • builder

      public static Metadata.Builder builder(Metadata metadata)
    • copyAndUpdate

      public Metadata copyAndUpdate(Consumer<Metadata.Builder> updater)