Class RepositoryData

java.lang.Object
org.elasticsearch.repositories.RepositoryData

public final class RepositoryData
extends java.lang.Object
A class that represents the data in a repository, as captured in the repository's index blob.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static long CORRUPTED_REPO_GEN
    The generation value indicating that the repository generation could not be determined.
    static RepositoryData EMPTY
    An instance initialized for an empty repository.
    static long EMPTY_REPO_GEN
    The generation value indicating the repository has no index generational files.
    static long UNKNOWN_REPO_GEN
    The generation value indicating that the repository generation is unknown.
  • Constructor Summary

    Constructors 
    Constructor Description
    RepositoryData​(long genId, java.util.Map<java.lang.String,​SnapshotId> snapshotIds, java.util.Map<java.lang.String,​SnapshotState> snapshotStates, java.util.Map<java.lang.String,​Version> snapshotVersions, java.util.Map<IndexId,​java.util.List<SnapshotId>> indexSnapshots, ShardGenerations shardGenerations)  
  • Method Summary

    Modifier and Type Method Description
    RepositoryData addSnapshot​(SnapshotId snapshotId, SnapshotState snapshotState, Version version, ShardGenerations shardGenerations)
    Add a snapshot and its indices to the repository; returns a new instance.
    protected RepositoryData copy()  
    boolean equals​(java.lang.Object obj)  
    long getGenId()
    Gets the generational index file id from which this instance was read.
    java.util.Map<java.lang.String,​IndexId> getIndices()
    Returns an unmodifiable map of the index names to IndexId in the repository.
    java.util.Collection<SnapshotId> getSnapshotIds()
    Returns an unmodifiable collection of the snapshot ids.
    java.util.List<SnapshotId> getSnapshots​(IndexId indexId)
    Returns an immutable collection of the snapshot ids for the snapshots that contain the given index.
    SnapshotState getSnapshotState​(SnapshotId snapshotId)
    Returns the SnapshotState for the given snapshot.
    Version getVersion​(SnapshotId snapshotId)
    Returns the Version for the given snapshot or null if unknown.
    int hashCode()  
    java.util.List<IndexId> indicesToUpdateAfterRemovingSnapshot​(java.util.Collection<SnapshotId> snapshotIds)
    Returns the list of IndexId that have their snapshots updated but not removed (because they are still referenced by other snapshots) after removing the given snapshot from the repository.
    RepositoryData removeSnapshots​(java.util.Collection<SnapshotId> snapshots, ShardGenerations updatedShardGenerations)
    Remove snapshots and remove any indices that no longer exist in the repository due to the deletion of the snapshots.
    IndexId resolveIndexId​(java.lang.String indexName)
    Resolve the index name to the index id specific to the repository, throwing an exception if the index could not be resolved.
    java.util.List<IndexId> resolveIndices​(java.util.List<java.lang.String> indices)
    Resolve the given index names to index ids.
    java.util.List<IndexId> resolveNewIndices​(java.util.List<java.lang.String> indicesToResolve)
    Resolve the given index names to index ids, creating new index ids for new indices in the repository.
    ShardGenerations shardGenerations()  
    static RepositoryData snapshotsFromXContent​(org.elasticsearch.common.xcontent.XContentParser parser, long genId, boolean fixBrokenShardGens)
    Reads an instance of RepositoryData from x-content, loading the snapshots and indices metadata.
    org.elasticsearch.common.xcontent.XContentBuilder snapshotsToXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, boolean shouldWriteShardGens)
    Writes the snapshots metadata and the related indices metadata to x-content.
    RepositoryData withGenId​(long newGeneration)
    Create a new instance with the given generation and all other fields equal to this instance.
    RepositoryData withVersions​(java.util.Map<SnapshotId,​Version> versions)
    Creates a copy of this instance that contains updated version data.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

  • Method Details

    • copy

      protected RepositoryData copy()
    • withVersions

      public RepositoryData withVersions​(java.util.Map<SnapshotId,​Version> versions)
      Creates a copy of this instance that contains updated version data.
      Parameters:
      versions - map of snapshot versions
      Returns:
      copy with updated version data
    • shardGenerations

      public ShardGenerations shardGenerations()
    • getGenId

      public long getGenId()
      Gets the generational index file id from which this instance was read.
    • getSnapshotIds

      public java.util.Collection<SnapshotId> getSnapshotIds()
      Returns an unmodifiable collection of the snapshot ids.
    • getSnapshotState

      @Nullable public SnapshotState getSnapshotState​(SnapshotId snapshotId)
      Returns the SnapshotState for the given snapshot. Returns null if there is no state for the snapshot.
    • getVersion

      @Nullable public Version getVersion​(SnapshotId snapshotId)
      Returns the Version for the given snapshot or null if unknown.
    • getIndices

      public java.util.Map<java.lang.String,​IndexId> getIndices()
      Returns an unmodifiable map of the index names to IndexId in the repository.
    • indicesToUpdateAfterRemovingSnapshot

      public java.util.List<IndexId> indicesToUpdateAfterRemovingSnapshot​(java.util.Collection<SnapshotId> snapshotIds)
      Returns the list of IndexId that have their snapshots updated but not removed (because they are still referenced by other snapshots) after removing the given snapshot from the repository.
      Parameters:
      snapshotIds - SnapshotId to remove
      Returns:
      List of indices that are changed but not removed
    • addSnapshot

      public RepositoryData addSnapshot​(SnapshotId snapshotId, SnapshotState snapshotState, Version version, ShardGenerations shardGenerations)
      Add a snapshot and its indices to the repository; returns a new instance. If the snapshot already exists in the repository data, this method throws an IllegalArgumentException.
      Parameters:
      snapshotId - Id of the new snapshot
      snapshotState - State of the new snapshot
      shardGenerations - Updated shard generations in the new snapshot. For each index contained in the snapshot an array of new generations indexed by the shard id they correspond to must be supplied.
    • withGenId

      public RepositoryData withGenId​(long newGeneration)
      Create a new instance with the given generation and all other fields equal to this instance.
      Parameters:
      newGeneration - New Generation
      Returns:
      New instance
    • removeSnapshots

      public RepositoryData removeSnapshots​(java.util.Collection<SnapshotId> snapshots, ShardGenerations updatedShardGenerations)
      Remove snapshots and remove any indices that no longer exist in the repository due to the deletion of the snapshots.
      Parameters:
      snapshots - Snapshot ids to remove
      updatedShardGenerations - Shard generations that changed as a result of removing the snapshot. The String[] passed for each IndexId contains the new shard generation id for each changed shard indexed by its shardId
    • getSnapshots

      public java.util.List<SnapshotId> getSnapshots​(IndexId indexId)
      Returns an immutable collection of the snapshot ids for the snapshots that contain the given index.
    • equals

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • resolveIndexId

      public IndexId resolveIndexId​(java.lang.String indexName)
      Resolve the index name to the index id specific to the repository, throwing an exception if the index could not be resolved.
    • resolveIndices

      public java.util.List<IndexId> resolveIndices​(java.util.List<java.lang.String> indices)
      Resolve the given index names to index ids.
    • resolveNewIndices

      public java.util.List<IndexId> resolveNewIndices​(java.util.List<java.lang.String> indicesToResolve)
      Resolve the given index names to index ids, creating new index ids for new indices in the repository.
    • snapshotsToXContent

      public org.elasticsearch.common.xcontent.XContentBuilder snapshotsToXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, boolean shouldWriteShardGens) throws java.io.IOException
      Writes the snapshots metadata and the related indices metadata to x-content.
      Throws:
      java.io.IOException
    • snapshotsFromXContent

      public static RepositoryData snapshotsFromXContent​(org.elasticsearch.common.xcontent.XContentParser parser, long genId, boolean fixBrokenShardGens) throws java.io.IOException
      Reads an instance of RepositoryData from x-content, loading the snapshots and indices metadata.
      Parameters:
      fixBrokenShardGens - set to true to filter out broken shard generations read from the parser via ShardGenerations.fixShardGeneration(java.lang.String). Used to disable fixing broken generations when reading from cached bytes that we trust to not contain broken generations.
      Throws:
      java.io.IOException