|
@@ -91,6 +91,7 @@ import org.elasticsearch.index.store.Store;
|
|
|
import org.elasticsearch.index.store.StoreFileMetadata;
|
|
import org.elasticsearch.index.store.StoreFileMetadata;
|
|
|
import org.elasticsearch.indices.recovery.RecoverySettings;
|
|
import org.elasticsearch.indices.recovery.RecoverySettings;
|
|
|
import org.elasticsearch.indices.recovery.RecoveryState;
|
|
import org.elasticsearch.indices.recovery.RecoveryState;
|
|
|
|
|
+import org.elasticsearch.repositories.FinalizeSnapshotContext;
|
|
|
import org.elasticsearch.repositories.GetSnapshotInfoContext;
|
|
import org.elasticsearch.repositories.GetSnapshotInfoContext;
|
|
|
import org.elasticsearch.repositories.IndexId;
|
|
import org.elasticsearch.repositories.IndexId;
|
|
|
import org.elasticsearch.repositories.IndexMetaDataGenerations;
|
|
import org.elasticsearch.repositories.IndexMetaDataGenerations;
|
|
@@ -1336,15 +1337,10 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public void finalizeSnapshot(
|
|
|
|
|
- final ShardGenerations shardGenerations,
|
|
|
|
|
- final long repositoryStateId,
|
|
|
|
|
- final Metadata clusterMetadata,
|
|
|
|
|
- SnapshotInfo snapshotInfo,
|
|
|
|
|
- Version repositoryMetaVersion,
|
|
|
|
|
- Function<ClusterState, ClusterState> stateTransformer,
|
|
|
|
|
- final ActionListener<RepositoryData> listener
|
|
|
|
|
- ) {
|
|
|
|
|
|
|
+ public void finalizeSnapshot(final FinalizeSnapshotContext finalizeSnapshotContext) {
|
|
|
|
|
+ final long repositoryStateId = finalizeSnapshotContext.repositoryStateId();
|
|
|
|
|
+ final ShardGenerations shardGenerations = finalizeSnapshotContext.updatedShardGenerations();
|
|
|
|
|
+ final SnapshotInfo snapshotInfo = finalizeSnapshotContext.snapshotInfo();
|
|
|
assert repositoryStateId > RepositoryData.UNKNOWN_REPO_GEN
|
|
assert repositoryStateId > RepositoryData.UNKNOWN_REPO_GEN
|
|
|
: "Must finalize based on a valid repository generation but received [" + repositoryStateId + "]";
|
|
: "Must finalize based on a valid repository generation but received [" + repositoryStateId + "]";
|
|
|
final Collection<IndexId> indices = shardGenerations.indices();
|
|
final Collection<IndexId> indices = shardGenerations.indices();
|
|
@@ -1353,8 +1349,9 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
// directory if all nodes are at least at version SnapshotsService#SHARD_GEN_IN_REPO_DATA_VERSION
|
|
// directory if all nodes are at least at version SnapshotsService#SHARD_GEN_IN_REPO_DATA_VERSION
|
|
|
// If there are older version nodes in the cluster, we don't need to run this cleanup as it will have already happened
|
|
// If there are older version nodes in the cluster, we don't need to run this cleanup as it will have already happened
|
|
|
// when writing the index-${N} to each shard directory.
|
|
// when writing the index-${N} to each shard directory.
|
|
|
|
|
+ final Version repositoryMetaVersion = finalizeSnapshotContext.repositoryMetaVersion();
|
|
|
final boolean writeShardGens = SnapshotsService.useShardGenerations(repositoryMetaVersion);
|
|
final boolean writeShardGens = SnapshotsService.useShardGenerations(repositoryMetaVersion);
|
|
|
- final Consumer<Exception> onUpdateFailure = e -> listener.onFailure(
|
|
|
|
|
|
|
+ final Consumer<Exception> onUpdateFailure = e -> finalizeSnapshotContext.onFailure(
|
|
|
new SnapshotException(metadata.name(), snapshotId, "failed to update snapshot in repository", e)
|
|
new SnapshotException(metadata.name(), snapshotId, "failed to update snapshot in repository", e)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -1367,7 +1364,7 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
repoDataListener.whenComplete(existingRepositoryData -> {
|
|
repoDataListener.whenComplete(existingRepositoryData -> {
|
|
|
final int existingSnapshotCount = existingRepositoryData.getSnapshotIds().size();
|
|
final int existingSnapshotCount = existingRepositoryData.getSnapshotIds().size();
|
|
|
if (existingSnapshotCount >= maxSnapshotCount) {
|
|
if (existingSnapshotCount >= maxSnapshotCount) {
|
|
|
- listener.onFailure(
|
|
|
|
|
|
|
+ finalizeSnapshotContext.onFailure(
|
|
|
new RepositoryException(
|
|
new RepositoryException(
|
|
|
metadata.name(),
|
|
metadata.name(),
|
|
|
"Cannot add another snapshot to this repository as it "
|
|
"Cannot add another snapshot to this repository as it "
|
|
@@ -1398,23 +1395,16 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
snapshotInfo.startTime(),
|
|
snapshotInfo.startTime(),
|
|
|
snapshotInfo.endTime()
|
|
snapshotInfo.endTime()
|
|
|
);
|
|
);
|
|
|
- final RepositoryData updatedRepositoryData = existingRepositoryData.addSnapshot(
|
|
|
|
|
- snapshotId,
|
|
|
|
|
- snapshotDetails,
|
|
|
|
|
- shardGenerations,
|
|
|
|
|
- indexMetas,
|
|
|
|
|
- indexMetaIdentifiers
|
|
|
|
|
- );
|
|
|
|
|
writeIndexGen(
|
|
writeIndexGen(
|
|
|
- updatedRepositoryData,
|
|
|
|
|
|
|
+ existingRepositoryData.addSnapshot(snapshotId, snapshotDetails, shardGenerations, indexMetas, indexMetaIdentifiers),
|
|
|
repositoryStateId,
|
|
repositoryStateId,
|
|
|
repositoryMetaVersion,
|
|
repositoryMetaVersion,
|
|
|
- stateTransformer,
|
|
|
|
|
|
|
+ finalizeSnapshotContext::updatedClusterState,
|
|
|
ActionListener.wrap(newRepoData -> {
|
|
ActionListener.wrap(newRepoData -> {
|
|
|
if (writeShardGens) {
|
|
if (writeShardGens) {
|
|
|
- cleanupOldShardGens(existingRepositoryData, updatedRepositoryData);
|
|
|
|
|
|
|
+ cleanupOldShardGens(existingRepositoryData, newRepoData);
|
|
|
}
|
|
}
|
|
|
- listener.onResponse(newRepoData);
|
|
|
|
|
|
|
+ finalizeSnapshotContext.onResponse(Tuple.tuple(newRepoData, snapshotInfo));
|
|
|
}, onUpdateFailure)
|
|
}, onUpdateFailure)
|
|
|
);
|
|
);
|
|
|
}, onUpdateFailure), 2 + indices.size());
|
|
}, onUpdateFailure), 2 + indices.size());
|
|
@@ -1424,7 +1414,7 @@ public abstract class BlobStoreRepository extends AbstractLifecycleComponent imp
|
|
|
// index or global metadata will be compatible with the segments written in this snapshot as well.
|
|
// index or global metadata will be compatible with the segments written in this snapshot as well.
|
|
|
// Failing on an already existing index-${repoGeneration} below ensures that the index.latest blob is not updated in a way
|
|
// Failing on an already existing index-${repoGeneration} below ensures that the index.latest blob is not updated in a way
|
|
|
// that decrements the generation it points at
|
|
// that decrements the generation it points at
|
|
|
-
|
|
|
|
|
|
|
+ final Metadata clusterMetadata = finalizeSnapshotContext.clusterMetadata();
|
|
|
// Write Global MetaData
|
|
// Write Global MetaData
|
|
|
executor.execute(
|
|
executor.execute(
|
|
|
ActionRunnable.run(
|
|
ActionRunnable.run(
|