Skip to content

Commit d68976d

Browse files
Create a utility class for static SnapshotsService methods (elastic#132521) (elastic#133776)
Relates ES-11650
1 parent 7e77be8 commit d68976d

File tree

18 files changed

+1282
-1155
lines changed

18 files changed

+1282
-1155
lines changed

modules/repository-s3/src/main/java/org/elasticsearch/repositories/s3/S3Repository.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.elasticsearch.repositories.blobstore.MeteredBlobStoreRepository;
4141
import org.elasticsearch.snapshots.SnapshotId;
4242
import org.elasticsearch.snapshots.SnapshotsService;
43+
import org.elasticsearch.snapshots.SnapshotsServiceUtils;
4344
import org.elasticsearch.threadpool.Scheduler;
4445
import org.elasticsearch.threadpool.ThreadPool;
4546
import org.elasticsearch.xcontent.NamedXContentRegistry;
@@ -337,7 +338,7 @@ private static ByteSizeValue objectSizeLimit(ByteSizeValue chunkSize, ByteSizeVa
337338
@Override
338339
public void finalizeSnapshot(final FinalizeSnapshotContext finalizeSnapshotContext) {
339340
final FinalizeSnapshotContext wrappedFinalizeContext;
340-
if (SnapshotsService.useShardGenerations(finalizeSnapshotContext.repositoryMetaVersion()) == false) {
341+
if (SnapshotsServiceUtils.useShardGenerations(finalizeSnapshotContext.repositoryMetaVersion()) == false) {
341342
final ListenableFuture<Void> metadataDone = new ListenableFuture<>();
342343
wrappedFinalizeContext = new FinalizeSnapshotContext(
343344
finalizeSnapshotContext.updatedShardGenerations(),

qa/repository-multi-version/src/test/java/org/elasticsearch/upgrades/MultiVersionRepositoryAccessIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import org.elasticsearch.common.settings.Settings;
1919
import org.elasticsearch.index.IndexVersion;
2020
import org.elasticsearch.index.IndexVersions;
21-
import org.elasticsearch.snapshots.SnapshotsService;
21+
import org.elasticsearch.snapshots.SnapshotsServiceUtils;
2222
import org.elasticsearch.test.rest.ESRestTestCase;
2323
import org.elasticsearch.test.rest.ObjectPath;
2424
import org.elasticsearch.xcontent.XContentParser;
@@ -183,7 +183,7 @@ public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
183183
// incompatibility in the downgrade test step. We verify that it is impossible here and then create the repo using verify=false
184184
// to check behavior on other operations below.
185185
final boolean verify = TEST_STEP != TestStep.STEP3_OLD_CLUSTER
186-
|| SnapshotsService.includesUUIDs(minNodeVersion)
186+
|| SnapshotsServiceUtils.includesUUIDs(minNodeVersion)
187187
|| minNodeVersion.before(IndexVersions.V_7_12_0);
188188
if (verify == false) {
189189
expectThrowsAnyOf(EXPECTED_BWC_EXCEPTIONS, () -> createRepository(repoName, false, true));
@@ -208,7 +208,7 @@ public void testUpgradeMovesRepoToNewMetaVersion() throws IOException {
208208
ensureSnapshotRestoreWorks(repoName, "snapshot-2", shards, index);
209209
}
210210
} else {
211-
if (SnapshotsService.includesUUIDs(minNodeVersion) == false) {
211+
if (SnapshotsServiceUtils.includesUUIDs(minNodeVersion) == false) {
212212
assertThat(TEST_STEP, is(TestStep.STEP3_OLD_CLUSTER));
213213
expectThrowsAnyOf(EXPECTED_BWC_EXCEPTIONS, () -> listSnapshots(repoName));
214214
expectThrowsAnyOf(EXPECTED_BWC_EXCEPTIONS, () -> deleteSnapshot(repoName, "snapshot-1"));

server/src/internalClusterTest/java/org/elasticsearch/snapshots/CorruptedBlobStoreRepositoryIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public void testHandlingMissingRootLevelSnapshotMetadata() throws Exception {
327327

328328
logger.info("--> verify that repo is assumed in old metadata format");
329329
assertThat(
330-
SnapshotsService.minCompatibleVersion(IndexVersion.current(), getRepositoryData(repoName), null),
330+
SnapshotsServiceUtils.minCompatibleVersion(IndexVersion.current(), getRepositoryData(repoName), null),
331331
is(SnapshotsService.OLD_SNAPSHOT_FORMAT)
332332
);
333333

@@ -336,7 +336,7 @@ public void testHandlingMissingRootLevelSnapshotMetadata() throws Exception {
336336

337337
logger.info("--> verify that repository is assumed in new metadata format after removing corrupted snapshot");
338338
assertThat(
339-
SnapshotsService.minCompatibleVersion(IndexVersion.current(), getRepositoryData(repoName), null),
339+
SnapshotsServiceUtils.minCompatibleVersion(IndexVersion.current(), getRepositoryData(repoName), null),
340340
is(IndexVersion.current())
341341
);
342342
final RepositoryData finalRepositoryData = getRepositoryData(repoName);

server/src/main/java/org/elasticsearch/action/admin/cluster/repositories/cleanup/TransportCleanupRepositoryAction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import org.elasticsearch.repositories.RepositoryCleanupResult;
3535
import org.elasticsearch.repositories.RepositoryData;
3636
import org.elasticsearch.repositories.blobstore.BlobStoreRepository;
37-
import org.elasticsearch.snapshots.SnapshotsService;
37+
import org.elasticsearch.snapshots.SnapshotsServiceUtils;
3838
import org.elasticsearch.tasks.Task;
3939
import org.elasticsearch.threadpool.ThreadPool;
4040
import org.elasticsearch.transport.TransportService;
@@ -170,8 +170,8 @@ private void cleanupRepo(String repositoryName, ActionListener<RepositoryCleanup
170170

171171
@Override
172172
public ClusterState execute(ClusterState currentState) {
173-
SnapshotsService.ensureRepositoryExists(repositoryName, currentState);
174-
SnapshotsService.ensureNotReadOnly(currentState, repositoryName);
173+
SnapshotsServiceUtils.ensureRepositoryExists(repositoryName, currentState);
174+
SnapshotsServiceUtils.ensureNotReadOnly(currentState, repositoryName);
175175
final RepositoryCleanupInProgress repositoryCleanupInProgress = RepositoryCleanupInProgress.get(currentState);
176176
if (repositoryCleanupInProgress.hasCleanupInProgress()) {
177177
throw new IllegalStateException(

server/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/TransportSnapshotsStatusAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
import org.elasticsearch.snapshots.SnapshotShardFailure;
4343
import org.elasticsearch.snapshots.SnapshotShardsService;
4444
import org.elasticsearch.snapshots.SnapshotState;
45-
import org.elasticsearch.snapshots.SnapshotsService;
45+
import org.elasticsearch.snapshots.SnapshotsServiceUtils;
4646
import org.elasticsearch.tasks.CancellableTask;
4747
import org.elasticsearch.tasks.Task;
4848
import org.elasticsearch.threadpool.ThreadPool;
@@ -113,7 +113,7 @@ protected void masterOperation(
113113
final CancellableTask cancellableTask = (CancellableTask) task;
114114

115115
final SnapshotsInProgress snapshotsInProgress = SnapshotsInProgress.get(state);
116-
List<SnapshotsInProgress.Entry> currentSnapshots = SnapshotsService.currentSnapshots(
116+
List<SnapshotsInProgress.Entry> currentSnapshots = SnapshotsServiceUtils.currentSnapshots(
117117
snapshotsInProgress,
118118
request.repository(),
119119
Arrays.asList(request.snapshots())

server/src/main/java/org/elasticsearch/action/admin/indices/rollover/MetadataRolloverService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import org.elasticsearch.indices.SystemIndices;
4949
import org.elasticsearch.injection.guice.Inject;
5050
import org.elasticsearch.snapshots.SnapshotInProgressException;
51-
import org.elasticsearch.snapshots.SnapshotsService;
51+
import org.elasticsearch.snapshots.SnapshotsServiceUtils;
5252
import org.elasticsearch.telemetry.TelemetryProvider;
5353
import org.elasticsearch.telemetry.metric.MeterRegistry;
5454
import org.elasticsearch.threadpool.ThreadPool;
@@ -295,7 +295,7 @@ private RolloverResult rolloverDataStream(
295295
boolean isFailureStoreRollover
296296
) throws Exception {
297297

298-
if (SnapshotsService.snapshottingDataStreams(currentState, Collections.singleton(dataStream.getName())).isEmpty() == false) {
298+
if (SnapshotsServiceUtils.snapshottingDataStreams(currentState, Collections.singleton(dataStream.getName())).isEmpty() == false) {
299299
// we can't roll over the snapshot concurrently because the snapshot contains the indices that existed when it was started but
300300
// the cluster metadata of when it completes so the new write index would not exist in the snapshot if there was a concurrent
301301
// rollover

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataDataStreamsService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.elasticsearch.logging.LogManager;
3636
import org.elasticsearch.logging.Logger;
3737
import org.elasticsearch.snapshots.SnapshotInProgressException;
38-
import org.elasticsearch.snapshots.SnapshotsService;
38+
import org.elasticsearch.snapshots.SnapshotsServiceUtils;
3939

4040
import java.io.IOException;
4141
import java.util.HashSet;
@@ -540,7 +540,7 @@ public static ClusterState deleteDataStreams(ClusterState currentState, Set<Data
540540
}
541541

542542
Set<String> dataStreamNames = dataStreams.stream().map(DataStream::getName).collect(Collectors.toSet());
543-
Set<String> snapshottingDataStreams = SnapshotsService.snapshottingDataStreams(currentState, dataStreamNames);
543+
Set<String> snapshottingDataStreams = SnapshotsServiceUtils.snapshottingDataStreams(currentState, dataStreamNames);
544544
if (snapshottingDataStreams.isEmpty() == false) {
545545
throw new SnapshotInProgressException(
546546
"Cannot delete data streams that are being snapshotted: ["

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataDeleteIndexService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import org.elasticsearch.injection.guice.Inject;
3535
import org.elasticsearch.snapshots.RestoreService;
3636
import org.elasticsearch.snapshots.SnapshotInProgressException;
37-
import org.elasticsearch.snapshots.SnapshotsService;
37+
import org.elasticsearch.snapshots.SnapshotsServiceUtils;
3838

3939
import java.util.HashMap;
4040
import java.util.HashSet;
@@ -171,7 +171,7 @@ public static ClusterState deleteIndices(ClusterState currentState, Set<Index> i
171171
}
172172

173173
// Check if index deletion conflicts with any running snapshots
174-
Set<Index> snapshottingIndices = SnapshotsService.snapshottingIndices(currentState, indicesToDelete);
174+
Set<Index> snapshottingIndices = SnapshotsServiceUtils.snapshottingIndices(currentState, indicesToDelete);
175175
if (snapshottingIndices.isEmpty() == false) {
176176
throw new SnapshotInProgressException(
177177
"Cannot delete indices that are being snapshotted: "

server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexStateService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
import org.elasticsearch.rest.RestStatus;
7373
import org.elasticsearch.snapshots.RestoreService;
7474
import org.elasticsearch.snapshots.SnapshotInProgressException;
75-
import org.elasticsearch.snapshots.SnapshotsService;
75+
import org.elasticsearch.snapshots.SnapshotsServiceUtils;
7676
import org.elasticsearch.tasks.TaskId;
7777
import org.elasticsearch.threadpool.ThreadPool;
7878

@@ -336,7 +336,7 @@ static ClusterState addIndexClosedBlocks(
336336
}
337337

338338
// Check if index closing conflicts with any running snapshots
339-
Set<Index> snapshottingIndices = SnapshotsService.snapshottingIndices(currentState, indicesToClose);
339+
Set<Index> snapshottingIndices = SnapshotsServiceUtils.snapshottingIndices(currentState, indicesToClose);
340340
if (snapshottingIndices.isEmpty() == false) {
341341
throw new SnapshotInProgressException(
342342
"Cannot close indices that are being snapshotted: "
@@ -907,7 +907,7 @@ static Tuple<ClusterState, List<IndexResult>> closeRoutingTable(
907907
}
908908

909909
// Check if index closing conflicts with any running snapshots
910-
Set<Index> snapshottingIndices = SnapshotsService.snapshottingIndices(currentState, Set.of(index));
910+
Set<Index> snapshottingIndices = SnapshotsServiceUtils.snapshottingIndices(currentState, Set.of(index));
911911
if (snapshottingIndices.isEmpty() == false) {
912912
closingResults.put(
913913
result.getKey(),

server/src/main/java/org/elasticsearch/repositories/FinalizeSnapshotContext.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.elasticsearch.cluster.metadata.Metadata;
1818
import org.elasticsearch.index.IndexVersion;
1919
import org.elasticsearch.snapshots.SnapshotInfo;
20-
import org.elasticsearch.snapshots.SnapshotsService;
20+
import org.elasticsearch.snapshots.SnapshotsServiceUtils;
2121

2222
import java.util.Map;
2323
import java.util.Set;
@@ -103,7 +103,11 @@ public Map<RepositoryShardId, Set<ShardGeneration>> obsoleteShardGenerations() {
103103
* Returns a new {@link ClusterState}, based on the given {@code state} with the create-snapshot entry removed.
104104
*/
105105
public ClusterState updatedClusterState(ClusterState state) {
106-
final ClusterState updatedState = SnapshotsService.stateWithoutSnapshot(state, snapshotInfo.snapshot(), updatedShardGenerations);
106+
final ClusterState updatedState = SnapshotsServiceUtils.stateWithoutSnapshot(
107+
state,
108+
snapshotInfo.snapshot(),
109+
updatedShardGenerations
110+
);
107111
// Now that the updated cluster state may have changed in-progress shard snapshots' shard generations to the latest shard
108112
// generation, let's mark any now unreferenced shard generations as obsolete and ready to be deleted.
109113
obsoleteGenerations.set(

0 commit comments

Comments
 (0)