Package org.elasticsearch.snapshots
Class SnapshotsService
- java.lang.Object
-
- org.elasticsearch.common.component.AbstractComponent
-
- org.elasticsearch.common.component.AbstractLifecycleComponent
-
- org.elasticsearch.snapshots.SnapshotsService
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,ClusterStateApplier
,LifecycleComponent
,Releasable
public class SnapshotsService extends AbstractLifecycleComponent implements ClusterStateApplier
Service responsible for creating snapshotsA typical snapshot creating process looks like this:
- On the master node the
createSnapshot(SnapshotRequest, CreateSnapshotListener)
is called and makes sure that no snapshots is currently running and registers the new snapshot in cluster state - When cluster state is updated the
beginSnapshot(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 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(ClusterChangedEvent)
method - Once shard snapshot is created data node updates state of the shard in the cluster state using the
SnapshotShardsService.sendSnapshotShardUpdate(Snapshot, ShardId, ShardSnapshotStatus)
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 allsnapshotCompletionListeners
that snapshot is completed, and finally callsremoveSnapshotFromClusterState(Snapshot, SnapshotInfo, Exception)
to remove snapshot from cluster state
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
SnapshotsService.CreateSnapshotListener
Listener for create snapshot operationstatic interface
SnapshotsService.DeleteSnapshotListener
Listener for delete snapshot operationstatic interface
SnapshotsService.SnapshotCompletionListener
static class
SnapshotsService.SnapshotRequest
Snapshot creation request
-
Field Summary
-
Fields inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
lifecycle
-
Fields inherited from class org.elasticsearch.common.component.AbstractComponent
logger
-
-
Constructor Summary
Constructors Constructor Description SnapshotsService(Settings settings, ClusterService clusterService, IndexNameExpressionResolver indexNameExpressionResolver, RepositoriesService repositoriesService, ThreadPool threadPool)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(SnapshotsService.SnapshotCompletionListener listener)
Adds snapshot completion listenervoid
applyClusterState(ClusterChangedEvent event)
Called when a new cluster state (ClusterChangedEvent.state()
needs to be appliedstatic 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 datejava.util.List<SnapshotsInProgress.Entry>
currentSnapshots(java.lang.String repository, java.util.List<java.lang.String> snapshots)
Returns status of the currently running snapshotsvoid
deleteSnapshot(java.lang.String repositoryName, java.lang.String snapshotName, SnapshotsService.DeleteSnapshotListener listener, boolean immediatePriority)
Deletes a snapshot from the repository, looking up theSnapshot
reference before deleting.protected void
doClose()
protected void
doStart()
protected void
doStop()
RepositoriesService
getRepositoriesService()
RepositoryData
getRepositoryData(java.lang.String repositoryName)
Gets theRepositoryData
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 snapshotsvoid
removeListener(SnapshotsService.SnapshotCompletionListener listener)
Removes snapshot completion listenerSnapshotInfo
snapshot(java.lang.String repositoryName, SnapshotId snapshotId)
Retrieves snapshot from repositoryjava.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 datejava.util.Map<ShardId,IndexShardSnapshotStatus>
snapshotShards(java.lang.String repositoryName, RepositoryData repositoryData, SnapshotInfo snapshotInfo)
Returns status of shards currently finished snapshots-
Methods inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
addLifecycleListener, close, lifecycleState, removeLifecycleListener, start, stop
-
-
-
-
Constructor Detail
-
SnapshotsService
@Inject public SnapshotsService(Settings settings, ClusterService clusterService, IndexNameExpressionResolver indexNameExpressionResolver, RepositoriesService repositoriesService, ThreadPool threadPool)
-
-
Method Detail
-
getRepositoryData
public RepositoryData getRepositoryData(java.lang.String repositoryName)
Gets theRepositoryData
for the given repository.- Parameters:
repositoryName
- repository name- Returns:
- repository data
-
snapshot
public SnapshotInfo snapshot(java.lang.String repositoryName, SnapshotId snapshotId)
Retrieves snapshot from repository- Parameters:
repositoryName
- repository namesnapshotId
- snapshot id- Returns:
- snapshot
- Throws:
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- Parameters:
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 error- Returns:
- 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- Parameters:
repositoryName
- repository name- Returns:
- list of snapshots
-
createSnapshot
public void createSnapshot(SnapshotsService.SnapshotRequest request, SnapshotsService.CreateSnapshotListener 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.
- Parameters:
request
- snapshot requestlistener
- 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 snapshotsThis method is executed on master node
- Parameters:
repository
- repository idsnapshots
- list of snapshots that will be used as a filter, empty list means no snapshots are filtered- Returns:
- list of metadata for currently running snapshots
-
snapshotShards
public java.util.Map<ShardId,IndexShardSnapshotStatus> snapshotShards(java.lang.String repositoryName, RepositoryData repositoryData, SnapshotInfo snapshotInfo) throws java.io.IOException
Returns status of shards currently finished snapshotsThis 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.- Parameters:
repositoryName
- repository namesnapshotInfo
- snapshot info- Returns:
- map of shard id to snapshot status
- Throws:
java.io.IOException
-
applyClusterState
public void applyClusterState(ClusterChangedEvent event)
Description copied from interface:ClusterStateApplier
Called when a new cluster state (ClusterChangedEvent.state()
needs to be applied- Specified by:
applyClusterState
in interfaceClusterStateApplier
-
deleteSnapshot
public void deleteSnapshot(java.lang.String repositoryName, java.lang.String snapshotName, SnapshotsService.DeleteSnapshotListener listener, boolean immediatePriority)
Deletes a snapshot from the repository, looking up theSnapshot
reference before deleting. If the snapshot is still running cancels the snapshot first and then deletes it from the repository.- Parameters:
repositoryName
- repositoryNamesnapshotName
- snapshotNamelistener
- 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- Parameters:
clusterState
- cluster staterepository
- repository id- Returns:
- 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.
-
addListener
public void addListener(SnapshotsService.SnapshotCompletionListener listener)
Adds snapshot completion listener- Parameters:
listener
- listener
-
removeListener
public void removeListener(SnapshotsService.SnapshotCompletionListener listener)
Removes snapshot completion listener- Parameters:
listener
- listener
-
doStart
protected void doStart()
- Specified by:
doStart
in classAbstractLifecycleComponent
-
doStop
protected void doStop()
- Specified by:
doStop
in classAbstractLifecycleComponent
-
doClose
protected void doClose()
- Specified by:
doClose
in classAbstractLifecycleComponent
-
getRepositoriesService
public RepositoriesService getRepositoriesService()
-
-