public class SnapshotsService extends AbstractLifecycleComponent<SnapshotsService> implements ClusterStateListener
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.updateIndexShardSnapshotStatus(org.elasticsearch.cluster.metadata.SnapshotId, org.elasticsearch.index.shard.ShardId, org.elasticsearch.cluster.SnapshotsInProgress.ShardSnapshotStatus)
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(SnapshotId, SnapshotInfo, Throwable)
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 |
clusterChanged(ClusterChangedEvent event)
Called when cluster state changes.
|
void |
createSnapshot(SnapshotsService.SnapshotRequest request,
SnapshotsService.CreateSnapshotListener listener)
Initializes the snapshotting process.
|
List<Snapshot> |
currentSnapshots(String repositoryName)
Returns a list of currently running snapshots from repository sorted by snapshot creation date
|
List<SnapshotsInProgress.Entry> |
currentSnapshots(String repository,
String[] snapshots)
Returns status of the currently running snapshots
|
void |
deleteSnapshot(SnapshotId snapshotId,
SnapshotsService.DeleteSnapshotListener listener)
Deletes snapshot from repository.
|
protected void |
doClose() |
protected void |
doStart() |
protected void |
doStop() |
RepositoriesService |
getRepositoriesService() |
static boolean |
isRepositoryInUse(ClusterState clusterState,
String repository)
Checks if a repository is currently in use by one of the snapshots
|
void |
removeListener(SnapshotsService.SnapshotCompletionListener listener)
Removes snapshot completion listener
|
Snapshot |
snapshot(SnapshotId snapshotId)
Retrieves snapshot from repository
|
List<Snapshot> |
snapshots(String repositoryName,
boolean ignoreUnavailable)
Returns a list of snapshots from repository sorted by snapshot creation date
|
com.google.common.collect.ImmutableMap<ShardId,IndexShardSnapshotStatus> |
snapshotShards(SnapshotId snapshotId)
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 Snapshot snapshot(SnapshotId snapshotId)
snapshotId
- snapshot idSnapshotMissingException
- if snapshot is not foundpublic List<Snapshot> snapshots(String repositoryName, boolean ignoreUnavailable)
repositoryName
- repository namepublic List<Snapshot> currentSnapshots(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 List<SnapshotsInProgress.Entry> currentSnapshots(String repository, String[] snapshots)
This method is executed on master node
repository
- repository idsnapshots
- optional list of snapshots that will be used as a filterpublic com.google.common.collect.ImmutableMap<ShardId,IndexShardSnapshotStatus> snapshotShards(SnapshotId snapshotId) throws IOException
This method is executed on master node and it's complimentary to the SnapshotShardsService.currentSnapshotShards(SnapshotId)
because it
returns similar information but for already finished snapshots.
snapshotId
- snapshot idIOException
public void clusterChanged(ClusterChangedEvent event)
ClusterStateListener
clusterChanged
in interface ClusterStateListener
public void deleteSnapshot(SnapshotId snapshotId, SnapshotsService.DeleteSnapshotListener listener)
If the snapshot is still running cancels the snapshot first and then deletes it from the repository.
snapshotId
- snapshot idlistener
- listenerpublic static boolean isRepositoryInUse(ClusterState clusterState, String repository)
clusterState
- cluster staterepository
- repository idpublic void addListener(SnapshotsService.SnapshotCompletionListener listener)
listener
- listenerpublic void removeListener(SnapshotsService.SnapshotCompletionListener listener)
listener
- listenerprotected void doStart()
doStart
in class AbstractLifecycleComponent<SnapshotsService>
protected void doStop()
doStop
in class AbstractLifecycleComponent<SnapshotsService>
protected void doClose()
doClose
in class AbstractLifecycleComponent<SnapshotsService>
public RepositoriesService getRepositoriesService()
Copyright © 2009–2016. All rights reserved.