Class BlobStoreRepository
- All Implemented Interfaces:
Closeable
,AutoCloseable
,LifecycleComponent
,org.elasticsearch.core.Releasable
,Repository
- Direct Known Subclasses:
FsRepository
,MeteredBlobStoreRepository
This repository works with any BlobStore
implementation. The blobStore could be (and preferred) lazy initialized in
createBlobStore()
.
org.elasticsearch.repositories.blobstore
.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.repositories.Repository
Repository.Factory
-
Field Summary
Modifier and TypeFieldDescriptionWhen set totrue
,bestEffortConsistency
will be set totrue
and concurrent modifications of the repository contents will not result in the repository being marked as corrupted.protected BigArrays
static Setting<ByteSizeValue>
Size hint for the IO buffer size to use when reading from and writing to the repository.protected int
IO buffer size hint for reading and writing to the underlying blob store.Setting to disable caching of the latest repository data.static ChecksumBlobStoreFormat<Metadata>
static String
static String
static ChecksumBlobStoreFormat<IndexMetadata>
static Setting<ByteSizeValue>
static Setting<ByteSizeValue>
Setting that defines the maximum number of snapshots to which the repository may grow.protected RepositoryMetadata
static String
static String
static String
AllBlobStoreRepository
implementations can be made read-only by setting this key totrue
in their settings.static ChecksumBlobStoreFormat<SnapshotInfo>
static String
static String
Setting to disable writing theindex.latest
blob which enables the contents of this repository to be used with a url-repository.protected boolean
protected ThreadPool
static String
static String
Fields inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
lifecycle
-
Constructor Summary
ModifierConstructorDescriptionprotected
BlobStoreRepository(RepositoryMetadata metadata, boolean compress, org.elasticsearch.common.xcontent.NamedXContentRegistry namedXContentRegistry, ClusterService clusterService, BigArrays bigArrays, RecoverySettings recoverySettings)
Constructs new BlobStoreRepository -
Method Summary
Modifier and TypeMethodDescriptionprotected void
abstract BlobPath
basePath()
Returns base path of the repositoryprotected BlobContainer
maintains single lazy instance ofBlobContainer
Maintains single lazy instance ofBlobStore
.boolean
canUpdateInPlace(Settings updatedSettings, Set<String> ignoredSettings)
Check if this instancesSettings
can be changed to the provided updated settings without recreating the repository.protected ByteSizeValue
Returns data file chunk size.void
cleanup(long repositoryStateId, Version repositoryMetaVersion, ActionListener<RepositoryCleanupResult> listener)
Runs cleanup actions on the repository.void
cloneShardSnapshot(SnapshotId source, SnapshotId target, RepositoryShardId shardId, String shardGeneration, ActionListener<ShardSnapshotResult> listener)
Clones a shard snapshot.protected abstract BlobStore
Creates new BlobStore to read and write data.void
deleteSnapshots(Collection<SnapshotId> snapshotIds, long repositoryStateId, Version repositoryMetaVersion, ActionListener<RepositoryData> listener)
Deletes snapshotsprotected void
doClose()
protected void
doStart()
protected void
doStop()
void
endVerification(String seed)
Called at the end of repository verification process.void
executeConsistentStateUpdate(Function<RepositoryData,ClusterStateUpdateTask> createUpdateTask, String source, Consumer<Exception> onFailure)
Execute a cluster state update with a consistent view of the currentRepositoryData
.void
finalizeSnapshot(ShardGenerations shardGenerations, long repositoryStateId, Metadata clusterMetadata, SnapshotInfo snapshotInfo, Version repositoryMetaVersion, Function<ClusterState,ClusterState> stateTransformer, ActionListener<RepositoryData> listener)
Finalizes snapshotting processprotected BlobStore
Returns metadata about this repository.void
getRepositoryData(ActionListener<RepositoryData> listener)
Returns aRepositoryData
to describe the data in the repository, including the snapshots and the indices across all snapshots found in the repository.long
Returns restore throttle time in nanosecondsgetShardSnapshotStatus(SnapshotId snapshotId, IndexId indexId, ShardId shardId)
Retrieve shard snapshot status for the stored snapshotgetSnapshotGlobalMetadata(SnapshotId snapshotId)
Returns global metadata associated with the snapshot.getSnapshotIndexMetaData(RepositoryData repositoryData, SnapshotId snapshotId, IndexId index)
Returns the index metadata associated with the snapshot.void
getSnapshotInfo(GetSnapshotInfoContext context)
Reads snapshot descriptions from the repository.long
Returns snapshot throttle time in nanosecondsboolean
void
initializeSnapshot(SnapshotId snapshotId, List<IndexId> indices, Metadata clusterMetadata)
Starts snapshotting processprotected boolean
Returns true if metadata and snapshot files should be compressedboolean
Returns true if the repository supports only read operationsloadShardSnapshot(BlobContainer shardContainer, SnapshotId snapshotId)
Loads information about shard snapshotmaybeRateLimitRestores(InputStream stream)
Wrap the restore rate limiter (controlled by the repository setting `max_restore_bytes_per_sec` and the cluster setting `indices.recovery.max_bytes_per_sec`) around the given stream.maybeRateLimitRestores(InputStream stream, RateLimitingInputStream.Listener throttleListener)
Wrap the restore rate limiter (controlled by the repository setting `max_restore_bytes_per_sec` and the cluster setting `indices.recovery.max_bytes_per_sec`) around the given stream.maybeRateLimitSnapshots(InputStream stream)
Wrap the snapshot rate limiter (controlled by the repository setting `max_snapshot_bytes_per_sec`) around the given stream.maybeRateLimitSnapshots(InputStream stream, RateLimitingInputStream.Listener throttleListener)
Wrap the snapshot rate limiter (controlled by the repository setting `max_snapshot_bytes_per_sec`) around the given stream.void
restoreShard(Store store, SnapshotId snapshotId, IndexId indexId, ShardId snapshotShardId, RecoveryState recoveryState, ActionListener<Void> listener)
Restores snapshot of the shard.shardContainer(IndexId indexId, int shardId)
void
snapshotShard(SnapshotShardContext context)
Creates a snapshot of the shard referenced by the givenSnapshotShardContext
.Verifies repository on the master node and returns the verification token.stats()
Returns stats on the repository usageboolean
toString()
void
updateState(ClusterState state)
Update the repository with the incoming cluster state.void
verify(String seed, DiscoveryNode localNode)
Verifies repository settings on data node.protected void
writeIndexGen(RepositoryData repositoryData, long expectedGen, Version version, Function<ClusterState,ClusterState> stateFilter, ActionListener<RepositoryData> listener)
Writing a new index generation is a three step process.Methods inherited from class org.elasticsearch.common.component.AbstractLifecycleComponent
addLifecycleListener, close, lifecycleState, removeLifecycleListener, start, stop
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.elasticsearch.common.component.LifecycleComponent
addLifecycleListener, lifecycleState, removeLifecycleListener, start, stop
Methods inherited from interface org.elasticsearch.core.Releasable
close
Methods inherited from interface org.elasticsearch.repositories.Repository
adaptUserMetadata, getSnapshotInfo
-
Field Details
-
metadata
-
threadPool
-
SNAPSHOT_PREFIX
- See Also:
- Constant Field Values
-
INDEX_FILE_PREFIX
- See Also:
- Constant Field Values
-
INDEX_LATEST_BLOB
- See Also:
- Constant Field Values
-
METADATA_PREFIX
- See Also:
- Constant Field Values
-
METADATA_NAME_FORMAT
- See Also:
- Constant Field Values
-
SNAPSHOT_NAME_FORMAT
- See Also:
- Constant Field Values
-
UPLOADED_DATA_BLOB_PREFIX
- See Also:
- Constant Field Values
-
URL_REPOSITORY_TYPE
- See Also:
- Constant Field Values
-
READONLY_SETTING_KEY
AllBlobStoreRepository
implementations can be made read-only by setting this key totrue
in their settings.- See Also:
- Constant Field Values
-
ALLOW_CONCURRENT_MODIFICATION
When set totrue
,bestEffortConsistency
will be set totrue
and concurrent modifications of the repository contents will not result in the repository being marked as corrupted. Note: This setting is intended as a backwards compatibility solution for 7.x and will go away in 8. -
CACHE_REPOSITORY_DATA
Setting to disable caching of the latest repository data. -
BUFFER_SIZE_SETTING
Size hint for the IO buffer size to use when reading from and writing to the repository. -
SUPPORT_URL_REPO
Setting to disable writing theindex.latest
blob which enables the contents of this repository to be used with a url-repository. -
MAX_SNAPSHOTS_SETTING
Setting that defines the maximum number of snapshots to which the repository may grow. Trying to create a snapshot into the repository that would move it above this size will throw an exception. -
supportURLRepo
protected final boolean supportURLRepo -
GLOBAL_METADATA_FORMAT
-
INDEX_METADATA_FORMAT
-
SNAPSHOT_FORMAT
-
INDEX_SHARD_SNAPSHOT_FORMAT
public static final ChecksumBlobStoreFormat<BlobStoreIndexShardSnapshot> INDEX_SHARD_SNAPSHOT_FORMAT -
INDEX_SHARD_SNAPSHOTS_FORMAT
public static final ChecksumBlobStoreFormat<BlobStoreIndexShardSnapshots> INDEX_SHARD_SNAPSHOTS_FORMAT -
MAX_SNAPSHOT_BYTES_PER_SEC
-
MAX_RESTORE_BYTES_PER_SEC
-
bigArrays
-
bufferSize
protected final int bufferSizeIO buffer size hint for reading and writing to the underlying blob store.
-
-
Constructor Details
-
BlobStoreRepository
protected BlobStoreRepository(RepositoryMetadata metadata, boolean compress, org.elasticsearch.common.xcontent.NamedXContentRegistry namedXContentRegistry, ClusterService clusterService, BigArrays bigArrays, RecoverySettings recoverySettings)Constructs new BlobStoreRepository- Parameters:
metadata
- The metadata for this repository including name and settingsclusterService
- ClusterService
-
-
Method Details
-
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
-
executeConsistentStateUpdate
public void executeConsistentStateUpdate(Function<RepositoryData,ClusterStateUpdateTask> createUpdateTask, String source, Consumer<Exception> onFailure)Description copied from interface:Repository
Execute a cluster state update with a consistent view of the currentRepositoryData
. TheClusterState
passed to the task generated throughcreateUpdateTask
is guaranteed to point at the same state for this repository as the did the state at the time theRepositoryData
was loaded. This allows for operations on the repository that need a consistent view of both the cluster state and the repository contents at one point in time like for example, checking if a snapshot is in the repository before adding the delete operation for it to the cluster state.- Specified by:
executeConsistentStateUpdate
in interfaceRepository
- Parameters:
createUpdateTask
- function to supply cluster state update tasksource
- the source of the cluster state update taskonFailure
- error handler invoked on failure to get a consistent view of the currentRepositoryData
-
cloneShardSnapshot
public void cloneShardSnapshot(SnapshotId source, SnapshotId target, RepositoryShardId shardId, @Nullable String shardGeneration, ActionListener<ShardSnapshotResult> listener)Description copied from interface:Repository
Clones a shard snapshot.- Specified by:
cloneShardSnapshot
in interfaceRepository
- Parameters:
source
- source snapshottarget
- target snapshotshardId
- shard idshardGeneration
- shard generation in repolistener
- listener to complete with new shard generation once clone has completed
-
canUpdateInPlace
Description copied from interface:Repository
Check if this instancesSettings
can be changed to the provided updated settings without recreating the repository.- Specified by:
canUpdateInPlace
in interfaceRepository
- Parameters:
updatedSettings
- new repository settingsignoredSettings
- setting names to ignore even if changed- Returns:
- true if the repository can be updated in place
-
updateState
Description copied from interface:Repository
Update the repository with the incoming cluster state. This method is invoked fromRepositoriesService.applyClusterState(org.elasticsearch.cluster.ClusterChangedEvent)
and thus the same semantics as withClusterStateApplier.applyClusterState(org.elasticsearch.cluster.ClusterChangedEvent)
apply for theClusterState
that is passed here.- Specified by:
updateState
in interfaceRepository
- Parameters:
state
- new cluster state
-
threadPool
-
getBlobStore
-
blobContainer
maintains single lazy instance ofBlobContainer
-
blobStore
Maintains single lazy instance ofBlobStore
. Public for testing. -
createBlobStore
Creates new BlobStore to read and write data.- Throws:
Exception
-
basePath
Returns base path of the repository -
isCompress
protected final boolean isCompress()Returns true if metadata and snapshot files should be compressed- Returns:
- true if compression is needed
-
chunkSize
Returns data file chunk size.This method should return null if no chunking is needed.
- Returns:
- chunk size
-
getMetadata
Description copied from interface:Repository
Returns metadata about this repository.- Specified by:
getMetadata
in interfaceRepository
-
stats
Description copied from interface:Repository
Returns stats on the repository usage- Specified by:
stats
in interfaceRepository
-
initializeSnapshot
public void initializeSnapshot(SnapshotId snapshotId, List<IndexId> indices, Metadata clusterMetadata)Description copied from interface:Repository
Starts snapshotting process- Specified by:
initializeSnapshot
in interfaceRepository
- Parameters:
snapshotId
- snapshot idindices
- list of indices to be snapshottedclusterMetadata
- cluster metadata
-
deleteSnapshots
public void deleteSnapshots(Collection<SnapshotId> snapshotIds, long repositoryStateId, Version repositoryMetaVersion, ActionListener<RepositoryData> listener)Description copied from interface:Repository
Deletes snapshots- Specified by:
deleteSnapshots
in interfaceRepository
- Parameters:
snapshotIds
- snapshot idsrepositoryStateId
- the unique id identifying the state of the repository when the snapshot deletion beganrepositoryMetaVersion
- version of the updated repository metadata to writelistener
- completion listener
-
cleanup
public void cleanup(long repositoryStateId, Version repositoryMetaVersion, ActionListener<RepositoryCleanupResult> listener)Runs cleanup actions on the repository. Increments the repository state id by one before executing any modifications on the repository. TODO: Add shard level cleanups TODO: Add unreferenced index metadata cleanup- Deleting stale indices
cleanupStaleIndices(java.util.Map<java.lang.String, org.elasticsearch.common.blobstore.BlobContainer>, java.util.Set<java.lang.String>)
- Deleting unreferenced root level blobs
cleanupStaleRootFiles(long, java.util.Collection<org.elasticsearch.snapshots.SnapshotId>, java.util.List<java.lang.String>)
- Parameters:
repositoryStateId
- Current repository state idrepositoryMetaVersion
- version of the updated repository metadata to writelistener
- Listener to complete when done
- Deleting stale indices
-
finalizeSnapshot
public void finalizeSnapshot(ShardGenerations shardGenerations, long repositoryStateId, Metadata clusterMetadata, SnapshotInfo snapshotInfo, Version repositoryMetaVersion, Function<ClusterState,ClusterState> stateTransformer, ActionListener<RepositoryData> listener)Description copied from interface:Repository
Finalizes snapshotting processThis method is called on master after all shards are snapshotted.
- Specified by:
finalizeSnapshot
in interfaceRepository
- Parameters:
shardGenerations
- updated shard generationsrepositoryStateId
- the unique id identifying the state of the repository when the snapshot beganclusterMetadata
- cluster metadatasnapshotInfo
- SnapshotInfo instance to write for this snapshotrepositoryMetaVersion
- version of the updated repository metadata to writestateTransformer
- a function that filters the last cluster state update that the snapshot finalization will execute and is used to remove any state tracked for the in-progress snapshot from the cluster statelistener
- listener to be invoked with the newRepositoryData
after completing the snapshot
-
getSnapshotInfo
Description copied from interface:Repository
Reads snapshot descriptions from the repository.- Specified by:
getSnapshotInfo
in interfaceRepository
- Parameters:
context
- get-snapshot-info-context
-
getSnapshotGlobalMetadata
Description copied from interface:Repository
Returns global metadata associated with the snapshot.- Specified by:
getSnapshotGlobalMetadata
in interfaceRepository
- Parameters:
snapshotId
- the snapshot id to load the global metadata from- Returns:
- the global metadata about the snapshot
-
getSnapshotIndexMetaData
public IndexMetadata getSnapshotIndexMetaData(RepositoryData repositoryData, SnapshotId snapshotId, IndexId index) throws IOExceptionDescription copied from interface:Repository
Returns the index metadata associated with the snapshot.- Specified by:
getSnapshotIndexMetaData
in interfaceRepository
- Parameters:
repositoryData
- currentRepositoryData
snapshotId
- the snapshot id to load the index metadata fromindex
- theIndexId
to load the metadata from- Returns:
- the index metadata about the given index for the given snapshot
- Throws:
IOException
-
shardContainer
-
getSnapshotThrottleTimeInNanos
public long getSnapshotThrottleTimeInNanos()Description copied from interface:Repository
Returns snapshot throttle time in nanoseconds- Specified by:
getSnapshotThrottleTimeInNanos
in interfaceRepository
-
getRestoreThrottleTimeInNanos
public long getRestoreThrottleTimeInNanos()Description copied from interface:Repository
Returns restore throttle time in nanoseconds- Specified by:
getRestoreThrottleTimeInNanos
in interfaceRepository
-
assertSnapshotOrGenericThread
protected void assertSnapshotOrGenericThread() -
startVerification
Description copied from interface:Repository
Verifies repository on the master node and returns the verification token.If the verification token is not null, it's passed to all data nodes for verification. If it's null - no additional verification is required
- Specified by:
startVerification
in interfaceRepository
- Returns:
- verification token that should be passed to all Index Shard Repositories for additional verification or null
-
endVerification
Description copied from interface:Repository
Called at the end of repository verification process.This method should perform all necessary cleanup of the temporary files created in the repository
- Specified by:
endVerification
in interfaceRepository
- Parameters:
seed
- verification request generated byRepository.startVerification()
command
-
getRepositoryData
Description copied from interface:Repository
Returns aRepositoryData
to describe the data in the repository, including the snapshots and the indices across all snapshots found in the repository. Throws aRepositoryException
if there was an error in reading the data.- Specified by:
getRepositoryData
in interfaceRepository
- Parameters:
listener
- listener that may be resolved on different kinds of threads including transport and cluster state applier threads and therefore must fork to a new thread for executing any long running actions
-
isReadOnly
public boolean isReadOnly()Description copied from interface:Repository
Returns true if the repository supports only read operations- Specified by:
isReadOnly
in interfaceRepository
- Returns:
- true if the repository is read/only
-
writeIndexGen
protected void writeIndexGen(RepositoryData repositoryData, long expectedGen, Version version, Function<ClusterState,ClusterState> stateFilter, ActionListener<RepositoryData> listener)Writing a new index generation is a three step process. First, theRepositoryMetadata
entry for this repository is set into a pending state by incrementing its pending generationP
while its safe generationN
remains unchanged. Second, the updatedRepositoryData
is written to generationP + 1
. Lastly, theRepositoryMetadata
entry for this repository is updated to the new generationP + 1
and thus pending and safe generation are set to the same value marking the end of the update of the repository data.- Parameters:
repositoryData
- RepositoryData to writeexpectedGen
- expected repository generation at the start of the operationversion
- version of the repository metadata to writestateFilter
- filter for the last cluster state update executed by this methodlistener
- completion listener
-
snapshotShard
Description copied from interface:Repository
Creates a snapshot of the shard referenced by the givenSnapshotShardContext
.As snapshot process progresses, implementation of this method should update
IndexShardSnapshotStatus
object returned bySnapshotShardContext.status()
and check itsIndexShardSnapshotStatus.isAborted()
to see if the snapshot process should be aborted.- Specified by:
snapshotShard
in interfaceRepository
- Parameters:
context
- snapshot shard context that must be completed viaSnapshotShardContext.onResponse(org.elasticsearch.repositories.ShardSnapshotResult)
orActionListener.Delegating.onFailure(java.lang.Exception)
-
restoreShard
public void restoreShard(Store store, SnapshotId snapshotId, IndexId indexId, ShardId snapshotShardId, RecoveryState recoveryState, ActionListener<Void> listener)Description copied from interface:Repository
Restores snapshot of the shard.The index can be renamed on restore, hence different
shardId
andsnapshotShardId
are supplied.- Specified by:
restoreShard
in interfaceRepository
- Parameters:
store
- the store to restore the index intosnapshotId
- snapshot idindexId
- id of the index in the repository from which the restore is occurringsnapshotShardId
- shard id (in the snapshot)recoveryState
- recovery statelistener
- listener to invoke once done
-
maybeRateLimitRestores
Wrap the restore rate limiter (controlled by the repository setting `max_restore_bytes_per_sec` and the cluster setting `indices.recovery.max_bytes_per_sec`) around the given stream. Any throttling is reported to the given listener and not otherwise recorded in the value returned bygetRestoreThrottleTimeInNanos()
. -
maybeRateLimitRestores
public InputStream maybeRateLimitRestores(InputStream stream, RateLimitingInputStream.Listener throttleListener)Wrap the restore rate limiter (controlled by the repository setting `max_restore_bytes_per_sec` and the cluster setting `indices.recovery.max_bytes_per_sec`) around the given stream. Any throttling is recorded in the value returned bygetRestoreThrottleTimeInNanos()
. -
maybeRateLimitSnapshots
Wrap the snapshot rate limiter (controlled by the repository setting `max_snapshot_bytes_per_sec`) around the given stream. Any throttling is recorded in the value returned bygetSnapshotThrottleTimeInNanos()
. -
maybeRateLimitSnapshots
public InputStream maybeRateLimitSnapshots(InputStream stream, RateLimitingInputStream.Listener throttleListener)Wrap the snapshot rate limiter (controlled by the repository setting `max_snapshot_bytes_per_sec`) around the given stream. Any throttling is reported to the given listener and not otherwise recorded in the value returned bygetSnapshotThrottleTimeInNanos()
. -
getShardSnapshotStatus
public IndexShardSnapshotStatus getShardSnapshotStatus(SnapshotId snapshotId, IndexId indexId, ShardId shardId)Description copied from interface:Repository
Retrieve shard snapshot status for the stored snapshot- Specified by:
getShardSnapshotStatus
in interfaceRepository
- Parameters:
snapshotId
- snapshot idindexId
- the snapshotted index id for the shard to get status forshardId
- shard id- Returns:
- snapshot status
-
verify
Description copied from interface:Repository
Verifies repository settings on data node.- Specified by:
verify
in interfaceRepository
- Parameters:
seed
- value returned byRepository.startVerification()
localNode
- the local node information, for inclusion in verification errors
-
toString
-
loadShardSnapshot
public BlobStoreIndexShardSnapshot loadShardSnapshot(BlobContainer shardContainer, SnapshotId snapshotId)Loads information about shard snapshot -
supportURLRepo
public boolean supportURLRepo() -
hasAtomicOverwrites
public boolean hasAtomicOverwrites()- Returns:
- whether this repository performs overwrites atomically. In practice we only overwrite the `index.latest` blob so this is not very important, but the repository analyzer does test that overwrites happen atomically. It will skip those tests if the repository overrides this method to indicate that it does not support atomic overwrites.
-