Package org.elasticsearch.snapshots
This package exposes the Elasticsearch Snapshot functionality.
Preliminaries
There are two communication channels between all nodes and master in the snapshot functionality:
- The master updates the cluster state by adding, removing or altering the contents of its custom entry
SnapshotsInProgress. All nodes consume the state of theSnapshotsInProgressand will start or abort relevant shard snapshot tasks accordingly. - Nodes that are executing shard snapshot tasks report either success or failure of their snapshot task by submitting a
SnapshotShardsService.UpdateIndexShardSnapshotStatusRequestto the master node that will update the snapshot's entry in the cluster state accordingly.
Snapshot Creation
Snapshots are created by the following sequence of events:
- An invocation of
SnapshotsService.createSnapshot(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest, org.elasticsearch.action.ActionListener<org.elasticsearch.snapshots.Snapshot>)enqueues a cluster state update to create aSnapshotsInProgress.Entryin the cluster state'sSnapshotsInProgress. This initial snapshot entry has its state set toINITand an empty map set for the state of the individual shard's snapshots. - After the snapshot's entry with state
INITis in the cluster state,SnapshotsServicedetermines the primary shards' assignments for all indices that are being snapshotted and updates the existingSnapshotsInProgress.Entrywith stateSTARTEDand adds the map ofShardIdtoSnapshotsInProgress.ShardSnapshotStatusthat tracks the assignment of which node is to snapshot which shard. All shard snapshots are executed on the shard's primary node. Thus all shards for which the primary node was found to have a healthy copy of the shard are marked as being in stateINITin this map. If the primary for a shard is unassigned, it is marked asMISSINGin this map. In case the primary is initializing at this point, it is marked as in stateWAITING. In case a shard's primary is relocated at any point after itsSnapshotsInProgress.Entryhas moved to stateSTARTEDand thus been assigned to a specific cluster node, that shard's snapshot will fail and move to stateFAILED. - The new
SnapshotsInProgress.Entryis then observed bySnapshotShardsService.clusterChanged(org.elasticsearch.cluster.ClusterChangedEvent)on all nodes and since the entry is in stateSTARTEDtheSnapshotShardsServicewill check if any local primary shards are to be snapshotted (signaled by the shard's snapshot state beingINIT). For those local primary shards found in stateINIT) the snapshot process of writing the shard's data files to the snapshot'sRepositoryis executed. Once the snapshot execution finishes for a shard anUpdateIndexShardSnapshotStatusRequestis sent to the master node signaling either statusSUCCESSorFAILED. The master node will then update a shard's state in the snapshotsSnapshotsInProgress.Entrywhenever it receives such aUpdateIndexShardSnapshotStatusRequest. - If as a result of the received status update requests, all shards in the cluster state are in a completed state, i.e are marked as
either
SUCCESS,FAILEDorMISSING, theSnapshotShardsServicewill update the state of theEntryitself and mark it asSUCCESS. At the same timeSnapshotsService.endSnapshot(org.elasticsearch.cluster.SnapshotsInProgress.Entry)is executed, writing the metadata necessary to finalize the snapshot in the repository to the repository. - After writing the final metadata to the repository, a cluster state update to remove the snapshot from the cluster state is
submitted and the removal of the snapshot's
SnapshotsInProgress.Entryfrom the cluster state completes the snapshot process.
Deleting a Snapshot
Deleting a snapshot can take the form of either simply deleting it from the repository or (if it has not completed yet) aborting it and subsequently deleting it from the repository.
Aborting a Snapshot
- Aborting a snapshot starts by updating the state of the snapshot's
SnapshotsInProgress.EntrytoABORTED. - The snapshot's state change to
ABORTEDin cluster state is then picked up by theSnapshotShardsServiceon all nodes. Those nodes that have shard snapshot actions for the snapshot assigned to them, will abort them and notify master about the shards snapshot status accordingly. If the shard snapshot action completed or was in stateFINALIZEwhen the abort was registered by theSnapshotShardsService, then the shard's state will be reported to master asSUCCESS. Otherwise, it will be reported asFAILED. - Once all the shards are reported to master as either
SUCCESSorFAILEDtheSnapshotsServiceon the master will finish the snapshot process as all shard's states are now completed and hence the snapshot can be completed as explained in point 4 of the snapshot creation section above.
Deleting a Snapshot from a Repository
- Assuming there are no entries in the cluster state's
SnapshotsInProgress, deleting a snapshot starts by theSnapshotsServicecreating an entry for deleting the snapshot in the cluster state'sSnapshotDeletionsInProgress. - Once the cluster state contains the deletion entry in
SnapshotDeletionsInProgresstheSnapshotsServicewill invokeRepository.deleteSnapshot(org.elasticsearch.snapshots.SnapshotId, long, org.elasticsearch.action.ActionListener<java.lang.Void>)for the given snapshot, which will remove files associated with the snapshot from the repository as well as update its meta-data to reflect the deletion of the snapshot. - After the deletion of the snapshot's data from the repository finishes, the
SnapshotsServicewill submit a cluster state update to remove the deletion's entry inSnapshotDeletionsInProgresswhich concludes the process of deleting a snapshot.
-
Class Summary Class Description RestoreInfo Information about successfully completed restore operation.RestoreService Service responsible for restoring snapshotsRestoreService.RestoreCompletionResponse RestoreService.RestoreInProgressUpdater Snapshot Basic information about a snapshot - a SnapshotId and the repository that the snapshot belongs to.SnapshotId SnapshotId - snapshot name + snapshot UUIDSnapshotInfo Information about a snapshotSnapshotInfo.SnapshotInfoBuilder SnapshotShardFailure Stores information about failures that occurred during shard snapshotting processSnapshotShardsService This service runs on data and master nodes and controls currently snapshotted shards on these nodes.SnapshotShardsService.UpdateIndexShardSnapshotStatusRequest Internal request that is used to send changes in snapshot status to masterSnapshotsService Service responsible for creating snapshotsSnapshotUtils Snapshot utilities -
Enum Summary Enum Description SnapshotState Represents the state that a snapshot can be in -
Exception Summary Exception Description ConcurrentSnapshotExecutionException Thrown when a user tries to multiple conflicting snapshot/restore operations at the same time.InvalidSnapshotNameException Thrown on the attempt to create a snapshot with invalid nameSnapshotCreationException Thrown when snapshot creation fails completelySnapshotException Generic snapshot exceptionSnapshotInProgressException Thrown on the attempt to execute an action that requires that no snapshot is in progress.SnapshotMissingException Thrown if requested snapshot doesn't existSnapshotRestoreException Snapshot restore exception