Package org.opensearch.repositories
Class RepositoryData
java.lang.Object
org.opensearch.repositories.RepositoryData
A class that represents the data in a repository, as captured in the
repository's index blob.
- Opensearch.internal:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final long
The generation value indicating that the repository generation could not be determined.static final RepositoryData
An instance initialized for an empty repository.static final long
The generation value indicating the repository has no index generational files.static final long
The generation value indicating that the repository generation is unknown. -
Constructor Summary
ConstructorsConstructorDescriptionRepositoryData
(long genId, Map<String, SnapshotId> snapshotIds, Map<String, SnapshotState> snapshotStates, Map<String, Version> snapshotVersions, Map<IndexId, List<SnapshotId>> indexSnapshots, ShardGenerations shardGenerations, IndexMetaDataGenerations indexMetaDataGenerations) -
Method Summary
Modifier and TypeMethodDescriptionaddSnapshot
(SnapshotId snapshotId, SnapshotState snapshotState, Version version, ShardGenerations shardGenerations, Map<IndexId, String> indexMetaBlobs, Map<String, String> newIdentifiers) Add a snapshot and its indices to the repository; returns a new instance.protected RepositoryData
copy()
boolean
long
getGenId()
Gets the generational index file id from which this instance was read.Returns an unmodifiable map of the index names toIndexId
in the repository.Returns an unmodifiable collection of the snapshot ids.getSnapshots
(IndexId indexId) Returns an immutable collection of the snapshot ids for the snapshots that contain the given index.getSnapshotState
(SnapshotId snapshotId) Returns theSnapshotState
for the given snapshot.getVersion
(SnapshotId snapshotId) Returns theVersion
for the given snapshot ornull
if unknown.int
hashCode()
indexMetaDataToRemoveAfterRemovingSnapshots
(Collection<SnapshotId> snapshotIds) Returns a map ofIndexId
to a collection ofString
containing all theIndexId
and theIndexMetadata
blob name in it that can be removed after removing the given snapshot from the repository.indicesToUpdateAfterRemovingSnapshot
(Collection<SnapshotId> snapshotIds) Returns the list ofIndexId
that have their snapshots updated but not removed (because they are still referenced by other snapshots) after removing the given snapshot from the repository.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.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
(List<String> indices) Resolve the given index names to index ids.Resolve the given index names to index ids, creating new index ids for new indices in the repository.static RepositoryData
snapshotsFromXContent
(org.opensearch.common.xcontent.XContentParser parser, long genId, boolean fixBrokenShardGens) Reads an instance ofRepositoryData
from x-content, loading the snapshots and indices metadata.org.opensearch.common.xcontent.XContentBuilder
snapshotsToXContent
(org.opensearch.common.xcontent.XContentBuilder builder, Version repoMetaVersion) Writes the snapshots metadata and the related indices metadata to x-content.withGenId
(long newGeneration) Create a new instance with the given generation and all other fields equal to this instance.withVersions
(Map<SnapshotId, Version> versions) Creates a copy of this instance that contains updated version data.
-
Field Details
-
EMPTY_REPO_GEN
public static final long EMPTY_REPO_GENThe generation value indicating the repository has no index generational files.- See Also:
-
UNKNOWN_REPO_GEN
public static final long UNKNOWN_REPO_GENThe generation value indicating that the repository generation is unknown.- See Also:
-
CORRUPTED_REPO_GEN
public static final long CORRUPTED_REPO_GENThe generation value indicating that the repository generation could not be determined.- See Also:
-
EMPTY
An instance initialized for an empty repository.
-
-
Constructor Details
-
RepositoryData
public RepositoryData(long genId, Map<String, SnapshotId> snapshotIds, Map<String, SnapshotState> snapshotStates, Map<String, Version> snapshotVersions, Map<IndexId, List<SnapshotId>> indexSnapshots, ShardGenerations shardGenerations, IndexMetaDataGenerations indexMetaDataGenerations)
-
-
Method Details
-
copy
-
withVersions
Creates a copy of this instance that contains updated version data.- Parameters:
versions
- map of snapshot versions- Returns:
- copy with updated version data
-
shardGenerations
-
getGenId
public long getGenId()Gets the generational index file id from which this instance was read. -
getSnapshotIds
Returns an unmodifiable collection of the snapshot ids. -
getSnapshotState
Returns theSnapshotState
for the given snapshot. Returnsnull
if there is no state for the snapshot. -
getVersion
Returns theVersion
for the given snapshot ornull
if unknown. -
getIndices
Returns an unmodifiable map of the index names toIndexId
in the repository. -
indicesToUpdateAfterRemovingSnapshot
Returns the list ofIndexId
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
-
indexMetaDataToRemoveAfterRemovingSnapshots
public Map<IndexId,Collection<String>> indexMetaDataToRemoveAfterRemovingSnapshots(Collection<SnapshotId> snapshotIds) Returns a map ofIndexId
to a collection ofString
containing all theIndexId
and theIndexMetadata
blob name in it that can be removed after removing the given snapshot from the repository. NOTE: Does not return a mapping forIndexId
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, SnapshotState snapshotState, Version version, ShardGenerations shardGenerations, @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 snapshotsnapshotState
- State of the new snapshotshardGenerations
- 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.indexMetaBlobs
- Map of index metadata blob uuidsnewIdentifiers
- Map of new index metadata blob uuids keyed by the identifiers of theIndexMetadata
in them
-
withGenId
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(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 removeupdatedShardGenerations
- Shard generations that changed as a result of removing the snapshot. TheString[]
passed for eachIndexId
contains the new shard generation id for each changed shard indexed by its shardId
-
getSnapshots
Returns an immutable collection of the snapshot ids for the snapshots that contain the given index. -
equals
-
hashCode
public int hashCode() -
resolveIndexId
Resolve the index name to the index id specific to the repository, throwing an exception if the index could not be resolved. -
resolveIndices
Resolve the given index names to index ids. -
resolveNewIndices
public List<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 resolveinFlightIds
- name to index mapping for currently in-flight snapshots not yet in the repository data to fall back to
-
snapshotsToXContent
public org.opensearch.common.xcontent.XContentBuilder snapshotsToXContent(org.opensearch.common.xcontent.XContentBuilder builder, Version repoMetaVersion) throws IOException Writes the snapshots metadata and the related indices metadata to x-content.- Throws:
IOException
-
indexMetaDataGenerations
-
snapshotsFromXContent
public static RepositoryData snapshotsFromXContent(org.opensearch.common.xcontent.XContentParser parser, long genId, boolean fixBrokenShardGens) throws IOException Reads an instance ofRepositoryData
from x-content, loading the snapshots and indices metadata.- Parameters:
fixBrokenShardGens
- set totrue
to filter out broken shard generations read from theparser
viaShardGenerations.fixShardGeneration(java.lang.String)
. Used to disable fixing broken generations when reading from cached bytes that we trust to not contain broken generations.- Throws:
IOException
-