Class SnapshotsService

  • All Implemented Interfaces:, java.lang.AutoCloseable, ClusterStateApplier, LifecycleComponent, Releasable

    public class SnapshotsService
    extends AbstractLifecycleComponent
    implements ClusterStateApplier
    Service responsible for creating snapshots

    A typical snapshot creating process looks like this:

    • On the master node the createSnapshot(CreateSnapshotRequest, ActionListener) is called and makes sure that no snapshot is currently running and registers the new snapshot in cluster state
    • When cluster state is updated the beginSnapshot(ClusterState, SnapshotsInProgress.Entry, boolean, ActionListener) method kicks in and initializes the snapshot in the repository and then populates list of shards that needs to be snapshotted in cluster state
    • Each data node is watching for these shards and when new shards scheduled for snapshotting appear in the cluster state, data nodes start processing them through SnapshotShardsService.processIndexShardSnapshots(org.elasticsearch.cluster.SnapshotsInProgress, org.elasticsearch.cluster.node.DiscoveryNode) method
    • Once shard snapshot is created data node updates state of the shard in the cluster state using the SnapshotShardsService.sendSnapshotShardUpdate(org.elasticsearch.snapshots.Snapshot, org.elasticsearch.index.shard.ShardId, org.elasticsearch.cluster.SnapshotsInProgress.ShardSnapshotStatus, org.elasticsearch.cluster.node.DiscoveryNode) method
    • When last shard is completed master node in SnapshotShardsService.innerUpdateSnapshotState(org.elasticsearch.snapshots.SnapshotShardsService.UpdateIndexShardSnapshotStatusRequest, org.elasticsearch.action.ActionListener<org.elasticsearch.snapshots.SnapshotShardsService.UpdateIndexShardSnapshotStatusResponse>) method marks the snapshot as completed
    • After cluster state is updated, the endSnapshot(SnapshotsInProgress.Entry) finalizes snapshot in the repository, notifies all snapshotCompletionListeners that snapshot is completed, and finally calls removeSnapshotFromClusterState(Snapshot, SnapshotInfo, Exception) to remove snapshot from cluster state
    • Method Detail

      • getRepositoryData

        public RepositoryData getRepositoryData​(java.lang.String repositoryName)
        Gets the RepositoryData for the given repository.
        repositoryName - repository name
        repository data
      • snapshot

        public SnapshotInfo snapshot​(java.lang.String repositoryName,
                                     SnapshotId snapshotId)
        Retrieves snapshot from repository
        repositoryName - repository name
        snapshotId - snapshot id
        SnapshotMissingException - if snapshot is not found
      • snapshots

        public java.util.List<SnapshotInfo> snapshots​(java.lang.String repositoryName,
                                                      java.util.List<SnapshotId> snapshotIds,
                                                      java.util.Set<SnapshotId> incompatibleSnapshotIds,
                                                      boolean ignoreUnavailable)
        Returns a list of snapshots from repository sorted by snapshot creation date
        repositoryName - repository name
        snapshotIds - snapshots for which to fetch snapshot information
        incompatibleSnapshotIds - snapshots for which not to fetch snapshot information
        ignoreUnavailable - if true, snapshots that could not be read will only be logged with a warning, if false, they will throw an error
        list of snapshots
      • currentSnapshots

        public java.util.List<SnapshotInfo> currentSnapshots​(java.lang.String repositoryName)
        Returns a list of currently running snapshots from repository sorted by snapshot creation date
        repositoryName - repository name
        list of snapshots
      • createSnapshot

        public void createSnapshot​(CreateSnapshotRequest request,
                                   ActionListener<Snapshot> listener)
        Initializes the snapshotting process.

        This method is used by clients to start snapshot. It makes sure that there is no snapshots are currently running and creates a snapshot record in cluster state metadata.

        request - snapshot request
        listener - snapshot creation listener
      • currentSnapshots

        public java.util.List<SnapshotsInProgress.Entry> currentSnapshots​(java.lang.String repository,
                                                                          java.util.List<java.lang.String> snapshots)
        Returns status of the currently running snapshots

        This method is executed on master node

        repository - repository id
        snapshots - list of snapshots that will be used as a filter, empty list means no snapshots are filtered
        list of metadata for currently running snapshots
      • snapshotShards

        public java.util.Map<ShardId,​IndexShardSnapshotStatus> snapshotShards​(java.lang.String repositoryName,
                                                                                    RepositoryData repositoryData,
                                                                                    SnapshotInfo snapshotInfo)
        Returns status of shards currently finished snapshots

        This method is executed on master node and it's complimentary to the SnapshotShardsService.currentSnapshotShards(Snapshot) because it returns similar information but for already finished snapshots.

        repositoryName - repository name
        snapshotInfo - snapshot info
        map of shard id to snapshot status
      • deleteSnapshot

        public void deleteSnapshot​(java.lang.String repositoryName,
                                   java.lang.String snapshotName,
                                   ActionListener<java.lang.Void> listener,
                                   boolean immediatePriority)
        Deletes a snapshot from the repository, looking up the Snapshot reference before deleting. If the snapshot is still running cancels the snapshot first and then deletes it from the repository.
        repositoryName - repositoryName
        snapshotName - snapshotName
        listener - listener
      • isRepositoryInUse

        public static boolean isRepositoryInUse​(ClusterState clusterState,
                                                java.lang.String repository)
        Checks if a repository is currently in use by one of the snapshots
        clusterState - cluster state
        repository - repository id
        true if repository is currently in use by one of the running snapshots
      • checkIndexDeletion

        public static void checkIndexDeletion​(ClusterState currentState,
                                              java.util.Set<IndexMetaData> indices)
        Check if any of the indices to be deleted are currently being snapshotted. Fail as deleting an index that is being snapshotted (with partial == false) makes the snapshot fail.
      • checkIndexClosing

        public static void checkIndexClosing​(ClusterState currentState,
                                             java.util.Set<IndexMetaData> indices)
        Check if any of the indices to be closed are currently being snapshotted. Fail as closing an index that is being snapshotted (with partial == false) makes the snapshot fail.