public class SnapshotsService extends AbstractLifecycleComponent implements ClusterStateApplier
A typical snapshot creating process looks like this:
createSnapshot(SnapshotRequest, CreateSnapshotListener)
is called and makes sure that no snapshots is currently running
and registers the new snapshot in cluster statebeginSnapshot(ClusterState, SnapshotsInProgress.Entry, boolean, CreateSnapshotListener)
method
kicks in and initializes the snapshot in the repository and then populates list of shards that needs to be snapshotted in cluster stateSnapshotShardsService.processIndexShardSnapshots(ClusterChangedEvent)
methodSnapshotShardsService#sendSnapshotShardUpdate(Snapshot, ShardId, ShardSnapshotStatus, DiscoveryNode)
methodSnapshotShardsService.innerUpdateSnapshotState(org.elasticsearch.snapshots.SnapshotShardsService.UpdateIndexShardSnapshotStatusRequest)
method marks the snapshot as completedendSnapshot(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 stateModifier and Type | Class and Description |
---|---|
static interface |
SnapshotsService.CreateSnapshotListener
Listener for create snapshot operation
|
static interface |
SnapshotsService.DeleteSnapshotListener
Listener for delete snapshot operation
|
static interface |
SnapshotsService.SnapshotCompletionListener |
static class |
SnapshotsService.SnapshotRequest
Snapshot creation request
|
lifecycle
deprecationLogger, logger, settings
Constructor and Description |
---|
SnapshotsService(Settings settings,
ClusterService clusterService,
IndexNameExpressionResolver indexNameExpressionResolver,
RepositoriesService repositoriesService,
ThreadPool threadPool) |
Modifier and Type | Method and Description |
---|---|
void |
addListener(SnapshotsService.SnapshotCompletionListener listener)
Adds snapshot completion listener
|
void |
applyClusterState(ClusterChangedEvent event)
Called when a new cluster state (
ClusterChangedEvent.state() needs to be applied |
static void |
checkIndexClosing(ClusterState currentState,
java.util.Set<IndexMetaData> indices)
Check if any of the indices to be closed are currently being snapshotted.
|
static void |
checkIndexDeletion(ClusterState currentState,
java.util.Set<IndexMetaData> indices)
Check if any of the indices to be deleted are currently being snapshotted.
|
void |
createSnapshot(SnapshotsService.SnapshotRequest request,
SnapshotsService.CreateSnapshotListener listener)
Initializes the snapshotting process.
|
java.util.List<SnapshotInfo> |
currentSnapshots(java.lang.String repositoryName)
Returns a list of currently running snapshots from repository sorted by snapshot creation date
|
java.util.List<SnapshotsInProgress.Entry> |
currentSnapshots(java.lang.String repository,
java.util.List<java.lang.String> snapshots)
Returns status of the currently running snapshots
|
void |
deleteSnapshot(java.lang.String repositoryName,
java.lang.String snapshotName,
SnapshotsService.DeleteSnapshotListener listener,
boolean immediatePriority)
Deletes a snapshot from the repository, looking up the
Snapshot reference before deleting. |
protected void |
doClose() |
protected void |
doStart() |
protected void |
doStop() |
RepositoriesService |
getRepositoriesService() |
RepositoryData |
getRepositoryData(java.lang.String repositoryName)
Gets the
RepositoryData for the given repository. |
static boolean |
isRepositoryInUse(ClusterState clusterState,
java.lang.String repository)
Checks if a repository is currently in use by one of the snapshots
|
void |
removeListener(SnapshotsService.SnapshotCompletionListener listener)
Removes snapshot completion listener
|
SnapshotInfo |
snapshot(java.lang.String repositoryName,
SnapshotId snapshotId)
Retrieves snapshot from repository
|
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
|
java.util.Map<ShardId,IndexShardSnapshotStatus> |
snapshotShards(java.lang.String repositoryName,
SnapshotInfo snapshotInfo)
Returns status of shards currently finished snapshots
|
addLifecycleListener, close, lifecycleState, removeLifecycleListener, start, stop
logDeprecatedSetting, logRemovedSetting, nodeName
@Inject public SnapshotsService(Settings settings, ClusterService clusterService, IndexNameExpressionResolver indexNameExpressionResolver, RepositoriesService repositoriesService, ThreadPool threadPool)
public RepositoryData getRepositoryData(java.lang.String repositoryName)
RepositoryData
for the given repository.repositoryName
- repository namepublic SnapshotInfo snapshot(java.lang.String repositoryName, SnapshotId snapshotId)
repositoryName
- repository namesnapshotId
- snapshot idSnapshotMissingException
- if snapshot is not foundpublic java.util.List<SnapshotInfo> snapshots(java.lang.String repositoryName, java.util.List<SnapshotId> snapshotIds, java.util.Set<SnapshotId> incompatibleSnapshotIds, boolean ignoreUnavailable)
repositoryName
- repository namesnapshotIds
- snapshots for which to fetch snapshot informationincompatibleSnapshotIds
- snapshots for which not to fetch snapshot informationignoreUnavailable
- if true, snapshots that could not be read will only be logged with a warning,
if false, they will throw an errorpublic java.util.List<SnapshotInfo> currentSnapshots(java.lang.String repositoryName)
repositoryName
- repository namepublic void createSnapshot(SnapshotsService.SnapshotRequest request, SnapshotsService.CreateSnapshotListener listener)
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 requestlistener
- snapshot creation listenerpublic java.util.List<SnapshotsInProgress.Entry> currentSnapshots(java.lang.String repository, java.util.List<java.lang.String> snapshots)
This method is executed on master node
repository
- repository idsnapshots
- list of snapshots that will be used as a filter, empty list means no snapshots are filteredpublic java.util.Map<ShardId,IndexShardSnapshotStatus> snapshotShards(java.lang.String repositoryName, SnapshotInfo snapshotInfo) throws java.io.IOException
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 namesnapshotInfo
- snapshot infojava.io.IOException
public void applyClusterState(ClusterChangedEvent event)
ClusterStateApplier
ClusterChangedEvent.state()
needs to be appliedapplyClusterState
in interface ClusterStateApplier
public void deleteSnapshot(java.lang.String repositoryName, java.lang.String snapshotName, SnapshotsService.DeleteSnapshotListener listener, boolean immediatePriority)
Snapshot
reference before deleting.
If the snapshot is still running cancels the snapshot first and then deletes it from the repository.repositoryName
- repositoryNamesnapshotName
- snapshotNamelistener
- listenerpublic static boolean isRepositoryInUse(ClusterState clusterState, java.lang.String repository)
clusterState
- cluster staterepository
- repository idpublic static void checkIndexDeletion(ClusterState currentState, java.util.Set<IndexMetaData> indices)
public static void checkIndexClosing(ClusterState currentState, java.util.Set<IndexMetaData> indices)
public void addListener(SnapshotsService.SnapshotCompletionListener listener)
listener
- listenerpublic void removeListener(SnapshotsService.SnapshotCompletionListener listener)
listener
- listenerprotected void doStart()
doStart
in class AbstractLifecycleComponent
protected void doStop()
doStop
in class AbstractLifecycleComponent
protected void doClose()
doClose
in class AbstractLifecycleComponent
public RepositoriesService getRepositoriesService()