Class RepositoryData

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

public final class RepositoryData extends Object
Represents the data in a repository: the snapshots and the indices across all snapshots found in the repository.
  • Field Details

    • EMPTY_REPO_GEN

      public static final long EMPTY_REPO_GEN
      The generation value indicating the repository has no index generational files.
      See Also:
    • UNKNOWN_REPO_GEN

      public static final long UNKNOWN_REPO_GEN
      The generation value indicating that the repository generation is unknown.
      See Also:
    • CORRUPTED_REPO_GEN

      public static final long CORRUPTED_REPO_GEN
      The generation value indicating that the repository generation could not be determined.
      See Also:
    • MISSING_UUID

      public static final String MISSING_UUID
      Sentinel value for the repository UUID indicating that it is not set.
      See Also:
    • EMPTY

      public static final RepositoryData EMPTY
      An instance initialized for an empty repository.
  • Constructor Details

  • Method Details

    • copy

      protected RepositoryData copy()
    • withoutShardGenerations

      public RepositoryData withoutShardGenerations()
      Creates a copy of this instance that does not track any shard generations.
      Returns:
      repository data with empty shard generations
    • withExtraDetails

      public RepositoryData withExtraDetails(Map<SnapshotId,RepositoryData.SnapshotDetails> extraDetails)
      Creates a copy of this instance that contains additional details read from the per-snapshot metadata blobs
      Parameters:
      extraDetails - map of snapshot details
      Returns:
      copy with updated version data
    • shardGenerations

      public ShardGenerations shardGenerations()
    • getUuid

      public String getUuid()
      Returns:
      The UUID of this repository, or MISSING_UUID if this repository has no UUID because it still supports access from versions earlier than SnapshotsService.UUIDS_IN_REPO_DATA_VERSION.
    • getClusterUUID

      public String getClusterUUID()
      Returns:
      the cluster UUID of the cluster that wrote this instance to the repository or MISSING_UUID if this instance was written by a cluster older than SnapshotsService.UUIDS_IN_REPO_DATA_VERSION.
    • getGenId

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

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

      public long getIndexSnapshotCount()
      Returns:
      the number of index snapshots (i.e. the sum of the index count of each snapshot)
    • hasMissingDetails

      public boolean hasMissingDetails(SnapshotId snapshotId)
      Returns:
      whether some of the RepositoryData.SnapshotDetails of the given snapshot are missing, due to BwC, so that they must be loaded from the SnapshotInfo blob instead.
    • getSnapshotDetails

      @Nullable public RepositoryData.SnapshotDetails getSnapshotDetails(SnapshotId snapshotId)
      Returns the RepositoryData.SnapshotDetails for the given snapshot. Returns null if there are no details for the snapshot.
    • 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 IndexVersion getVersion(SnapshotId snapshotId)
      Returns the IndexVersion for the given snapshot or null if unknown.
    • getIndices

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

      public Iterator<IndexId> indicesToUpdateAfterRemovingSnapshot(Collection<SnapshotId> snapshotIds)
      Returns an iterator over 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:
      Iterator over indices that are changed but not removed
    • indexMetaDataToRemoveAfterRemovingSnapshots

      public Map<IndexId,Collection<String>> indexMetaDataToRemoveAfterRemovingSnapshots(Collection<SnapshotId> snapshotIds)
      Returns a map of IndexId to a collection of String containing all the IndexId and the IndexMetadata blob name in it that can be removed after removing the given snapshot from the repository. NOTE: Does not return a mapping for IndexId values that will be removed completely from the repository.
      Parameters:
      snapshotIds - SnapshotIds to remove
      Returns:
      map of index to index metadata blob id to delete
    • addSnapshot

      public RepositoryData addSnapshot(SnapshotId snapshotId, RepositoryData.SnapshotDetails details, FinalizeSnapshotContext.UpdatedShardGenerations updatedShardGenerations, @Nullable Map<IndexId,String> indexMetaBlobs, @Nullable Map<String,String> newIdentifiers)
      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
      details - Details of the new snapshot
      updatedShardGenerations - Updated shard generations in the new snapshot, including both indices that are included in the given snapshot and those got deleted while finalizing.
      indexMetaBlobs - Map of index metadata blob uuids
      newIdentifiers - Map of new index metadata blob uuids keyed by the identifiers of the IndexMetadata in them
    • 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
    • withoutUUIDs

      public RepositoryData withoutUUIDs()
      For test purposes, make a copy of this instance with the cluster- and repository UUIDs removed and all other fields unchanged, as if from an older version.
    • withClusterUuid

      public RepositoryData withClusterUuid(String clusterUUID)
    • removeSnapshots

      public RepositoryData removeSnapshots(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 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(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • resolveIndexId

      public IndexId resolveIndexId(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 Map<String,IndexId> resolveIndices(List<String> indices)
      Resolve the given index names to index ids.
    • hasIndex

      public boolean hasIndex(String indexName)
      Checks if any snapshot in this repository contains the specified index in indexName
    • resolveNewIndices

      public Map<String,IndexId> resolveNewIndices(List<String> indicesToResolve, Map<String,IndexId> inFlightIds)
      Resolve the given index names to index ids, creating new index ids for new indices in the repository.
      Parameters:
      indicesToResolve - names of indices to resolve
      inFlightIds - name to index mapping for currently in-flight snapshots not yet in the repository data to fall back to
    • snapshotsToXContent

      public XContentBuilder snapshotsToXContent(XContentBuilder builder, IndexVersion repoMetaVersion) throws IOException
      Writes the snapshots metadata and the related indices metadata to x-content.
      Throws:
      IOException
    • snapshotsToXContent

      public XContentBuilder snapshotsToXContent(XContentBuilder builder, IndexVersion repoMetaVersion, boolean permitMissingUuid) throws IOException
      Writes the snapshots metadata and the related indices metadata to x-content.
      Parameters:
      permitMissingUuid - indicates whether we permit the repository- and cluster UUIDs to be missing, e.g. we are serializing for the in-memory cache or running tests
      Throws:
      IOException
    • indexMetaDataGenerations

      public IndexMetaDataGenerations indexMetaDataGenerations()
    • snapshotsFromXContent

      public static RepositoryData snapshotsFromXContent(XContentParser parser, long genId, boolean fixBrokenShardGens) throws 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(org.elasticsearch.repositories.ShardGeneration). Used to disable fixing broken generations when reading from cached bytes that we trust to not contain broken generations.
      Throws:
      IOException