Interface Repository

All Superinterfaces:
AutoCloseable, Closeable, LifecycleComponent, org.elasticsearch.core.Releasable
All Known Implementing Classes:
BlobStoreRepository, FilterRepository, FsRepository, MeteredBlobStoreRepository

public interface Repository extends LifecycleComponent
An interface for interacting with a repository in snapshot and restore.

Implementations are responsible for reading and writing both metadata and shard data to and from a repository backend.

To perform a snapshot:

  • Method Details

    • getMetadata

      RepositoryMetadata getMetadata()
      Returns metadata about this repository.
    • getSnapshotInfo

      void getSnapshotInfo(GetSnapshotInfoContext context)
      Reads snapshot descriptions from the repository.
      Parameters:
      context - get-snapshot-info-context
    • getSnapshotInfo

      default void getSnapshotInfo(SnapshotId snapshotId, ActionListener<SnapshotInfo> listener)
      Reads a single snapshot description from the repository
      Parameters:
      snapshotId - snapshot id to read description for
      listener - listener to resolve with snapshot description (is resolved on the ThreadPool.Names.SNAPSHOT_META pool)
    • getSnapshotGlobalMetadata

      Metadata getSnapshotGlobalMetadata(SnapshotId snapshotId)
      Returns global metadata associated with the snapshot.
      Parameters:
      snapshotId - the snapshot id to load the global metadata from
      Returns:
      the global metadata about the snapshot
    • getSnapshotIndexMetaData

      IndexMetadata getSnapshotIndexMetaData(RepositoryData repositoryData, SnapshotId snapshotId, IndexId index) throws IOException
      Returns the index metadata associated with the snapshot.
      Parameters:
      repositoryData - current RepositoryData
      snapshotId - the snapshot id to load the index metadata from
      index - the IndexId to load the metadata from
      Returns:
      the index metadata about the given index for the given snapshot
      Throws:
      IOException
    • getRepositoryData

      void getRepositoryData(ActionListener<RepositoryData> listener)
      Returns a RepositoryData to describe the data in the repository, including the snapshots and the indices across all snapshots found in the repository. Throws a RepositoryException if there was an error in reading the data.
      Parameters:
      listener - listener that may be resolved on different kinds of threads including transport and cluster state applier threads and therefore must fork to a new thread for executing any long running actions
    • initializeSnapshot

      @Deprecated void initializeSnapshot(SnapshotId snapshotId, List<IndexId> indices, Metadata metadata)
      Deprecated.
      this method is only used when taking snapshots in a mixed version cluster where a master node older than SnapshotsService.NO_REPO_INITIALIZE_VERSION is present.
      Starts snapshotting process
      Parameters:
      snapshotId - snapshot id
      indices - list of indices to be snapshotted
      metadata - cluster metadata
    • finalizeSnapshot

      void finalizeSnapshot(ShardGenerations shardGenerations, long repositoryStateId, Metadata clusterMetadata, SnapshotInfo snapshotInfo, Version repositoryMetaVersion, Function<ClusterState,​ClusterState> stateTransformer, ActionListener<RepositoryData> listener)
      Finalizes snapshotting process

      This method is called on master after all shards are snapshotted.

      Parameters:
      shardGenerations - updated shard generations
      repositoryStateId - the unique id identifying the state of the repository when the snapshot began
      clusterMetadata - cluster metadata
      snapshotInfo - SnapshotInfo instance to write for this snapshot
      repositoryMetaVersion - version of the updated repository metadata to write
      stateTransformer - a function that filters the last cluster state update that the snapshot finalization will execute and is used to remove any state tracked for the in-progress snapshot from the cluster state
      listener - listener to be invoked with the new RepositoryData after completing the snapshot
    • deleteSnapshots

      void deleteSnapshots(Collection<SnapshotId> snapshotIds, long repositoryStateId, Version repositoryMetaVersion, ActionListener<RepositoryData> listener)
      Deletes snapshots
      Parameters:
      snapshotIds - snapshot ids
      repositoryStateId - the unique id identifying the state of the repository when the snapshot deletion began
      repositoryMetaVersion - version of the updated repository metadata to write
      listener - completion listener
    • getSnapshotThrottleTimeInNanos

      long getSnapshotThrottleTimeInNanos()
      Returns snapshot throttle time in nanoseconds
    • getRestoreThrottleTimeInNanos

      long getRestoreThrottleTimeInNanos()
      Returns restore throttle time in nanoseconds
    • stats

      default RepositoryStats stats()
      Returns stats on the repository usage
    • startVerification

      String startVerification()
      Verifies repository on the master node and returns the verification token.

      If the verification token is not null, it's passed to all data nodes for verification. If it's null - no additional verification is required

      Returns:
      verification token that should be passed to all Index Shard Repositories for additional verification or null
    • endVerification

      void endVerification(String verificationToken)
      Called at the end of repository verification process.

      This method should perform all necessary cleanup of the temporary files created in the repository

      Parameters:
      verificationToken - verification request generated by startVerification() command
    • verify

      void verify(String verificationToken, DiscoveryNode localNode)
      Verifies repository settings on data node.
      Parameters:
      verificationToken - value returned by startVerification()
      localNode - the local node information, for inclusion in verification errors
    • isReadOnly

      boolean isReadOnly()
      Returns true if the repository supports only read operations
      Returns:
      true if the repository is read/only
    • snapshotShard

      void snapshotShard(SnapshotShardContext snapshotShardContext)
      Creates a snapshot of the shard referenced by the given SnapshotShardContext.

      As snapshot process progresses, implementation of this method should update IndexShardSnapshotStatus object returned by SnapshotShardContext.status() and check its IndexShardSnapshotStatus.isAborted() to see if the snapshot process should be aborted.

      Parameters:
      snapshotShardContext - snapshot shard context that must be completed via SnapshotShardContext.onResponse(org.elasticsearch.repositories.ShardSnapshotResult) or ActionListener.Delegating.onFailure(java.lang.Exception)
    • restoreShard

      void restoreShard(Store store, SnapshotId snapshotId, IndexId indexId, ShardId snapshotShardId, RecoveryState recoveryState, ActionListener<Void> listener)
      Restores snapshot of the shard.

      The index can be renamed on restore, hence different shardId and snapshotShardId are supplied.

      Parameters:
      store - the store to restore the index into
      snapshotId - snapshot id
      indexId - id of the index in the repository from which the restore is occurring
      snapshotShardId - shard id (in the snapshot)
      recoveryState - recovery state
      listener - listener to invoke once done
    • getShardSnapshotStatus

      IndexShardSnapshotStatus getShardSnapshotStatus(SnapshotId snapshotId, IndexId indexId, ShardId shardId)
      Retrieve shard snapshot status for the stored snapshot
      Parameters:
      snapshotId - snapshot id
      indexId - the snapshotted index id for the shard to get status for
      shardId - shard id
      Returns:
      snapshot status
    • canUpdateInPlace

      default boolean canUpdateInPlace(Settings updatedSettings, Set<String> ignoredSettings)
      Check if this instances Settings can be changed to the provided updated settings without recreating the repository.
      Parameters:
      updatedSettings - new repository settings
      ignoredSettings - setting names to ignore even if changed
      Returns:
      true if the repository can be updated in place
    • updateState

      void updateState(ClusterState state)
      Update the repository with the incoming cluster state. This method is invoked from RepositoriesService.applyClusterState(org.elasticsearch.cluster.ClusterChangedEvent) and thus the same semantics as with ClusterStateApplier.applyClusterState(org.elasticsearch.cluster.ClusterChangedEvent) apply for the ClusterState that is passed here.
      Parameters:
      state - new cluster state
    • executeConsistentStateUpdate

      void executeConsistentStateUpdate(Function<RepositoryData,​ClusterStateUpdateTask> createUpdateTask, String source, Consumer<Exception> onFailure)
      Execute a cluster state update with a consistent view of the current RepositoryData. The ClusterState passed to the task generated through createUpdateTask is guaranteed to point at the same state for this repository as the did the state at the time the RepositoryData was loaded. This allows for operations on the repository that need a consistent view of both the cluster state and the repository contents at one point in time like for example, checking if a snapshot is in the repository before adding the delete operation for it to the cluster state.
      Parameters:
      createUpdateTask - function to supply cluster state update task
      source - the source of the cluster state update task
      onFailure - error handler invoked on failure to get a consistent view of the current RepositoryData
    • cloneShardSnapshot

      void cloneShardSnapshot(SnapshotId source, SnapshotId target, RepositoryShardId shardId, @Nullable String shardGeneration, ActionListener<ShardSnapshotResult> listener)
      Clones a shard snapshot.
      Parameters:
      source - source snapshot
      target - target snapshot
      shardId - shard id
      shardGeneration - shard generation in repo
      listener - listener to complete with new shard generation once clone has completed
    • adaptUserMetadata

      default Map<String,​Object> adaptUserMetadata(Map<String,​Object> userMetadata)
      Hook that allows a repository to filter the user supplied snapshot metadata in SnapshotsInProgress.Entry.userMetadata() during snapshot initialization.
    • assertSnapshotMetaThread

      static boolean assertSnapshotMetaThread()