Skip to content

Commit f0f6410

Browse files
Create a utility class for static SnapshotsService methods (#132521)
This moves the static methods out of the SnapshotsService to make the stateful code more visible. This is one step towards refactoring the SnapshotsService. Relates ES-11650
1 parent d3d6ca5 commit f0f6410

File tree

18 files changed

+1313
-1181
lines changed

18 files changed

+1313
-1181
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
@@ -42,6 +42,7 @@
4242
import org.elasticsearch.repositories.blobstore.MeteredBlobStoreRepository;
4343
import org.elasticsearch.snapshots.SnapshotId;
4444
import org.elasticsearch.snapshots.SnapshotsService;
45+
import org.elasticsearch.snapshots.SnapshotsServiceUtils;
4546
import org.elasticsearch.threadpool.Scheduler;
4647
import org.elasticsearch.threadpool.ThreadPool;
4748
import org.elasticsearch.xcontent.NamedXContentRegistry;
@@ -388,7 +389,7 @@ private static ByteSizeValue objectSizeLimit(ByteSizeValue chunkSize, ByteSizeVa
388389
@Override
389390
public void finalizeSnapshot(final FinalizeSnapshotContext finalizeSnapshotContext) {
390391
final FinalizeSnapshotContext wrappedFinalizeContext;
391-
if (SnapshotsService.useShardGenerations(finalizeSnapshotContext.repositoryMetaVersion()) == false) {
392+
if (SnapshotsServiceUtils.useShardGenerations(finalizeSnapshotContext.repositoryMetaVersion()) == false) {
392393
final ListenableFuture<Void> metadataDone = new ListenableFuture<>();
393394
wrappedFinalizeContext = new FinalizeSnapshotContext(
394395
finalizeSnapshotContext.serializeProjectMetadata(),

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
@@ -37,7 +37,7 @@
3737
import org.elasticsearch.repositories.RepositoryCleanupResult;
3838
import org.elasticsearch.repositories.RepositoryData;
3939
import org.elasticsearch.repositories.blobstore.BlobStoreRepository;
40-
import org.elasticsearch.snapshots.SnapshotsService;
40+
import org.elasticsearch.snapshots.SnapshotsServiceUtils;
4141
import org.elasticsearch.tasks.Task;
4242
import org.elasticsearch.threadpool.ThreadPool;
4343
import org.elasticsearch.transport.TransportService;
@@ -178,8 +178,8 @@ private void cleanupRepo(ProjectId projectId, String repositoryName, ActionListe
178178
@Override
179179
public ClusterState execute(ClusterState currentState) {
180180
final ProjectMetadata projectMetadata = currentState.metadata().getProject(projectId);
181-
SnapshotsService.ensureRepositoryExists(repositoryName, projectMetadata);
182-
SnapshotsService.ensureNotReadOnly(projectMetadata, repositoryName);
181+
SnapshotsServiceUtils.ensureRepositoryExists(repositoryName, projectMetadata);
182+
SnapshotsServiceUtils.ensureNotReadOnly(projectMetadata, repositoryName);
183183
// Repository cleanup is intentionally cluster wide exclusive
184184
final RepositoryCleanupInProgress repositoryCleanupInProgress = RepositoryCleanupInProgress.get(currentState);
185185
if (repositoryCleanupInProgress.hasCleanupInProgress()) {

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
@@ -46,7 +46,7 @@
4646
import org.elasticsearch.snapshots.SnapshotShardFailure;
4747
import org.elasticsearch.snapshots.SnapshotShardsService;
4848
import org.elasticsearch.snapshots.SnapshotState;
49-
import org.elasticsearch.snapshots.SnapshotsService;
49+
import org.elasticsearch.snapshots.SnapshotsServiceUtils;
5050
import org.elasticsearch.tasks.CancellableTask;
5151
import org.elasticsearch.tasks.Task;
5252
import org.elasticsearch.threadpool.ThreadPool;
@@ -121,7 +121,7 @@ protected void masterOperation(
121121

122122
final SnapshotsInProgress snapshotsInProgress = SnapshotsInProgress.get(state);
123123
final ProjectId projectId = projectResolver.getProjectId();
124-
List<SnapshotsInProgress.Entry> currentSnapshots = SnapshotsService.currentSnapshots(
124+
List<SnapshotsInProgress.Entry> currentSnapshots = SnapshotsServiceUtils.currentSnapshots(
125125
snapshotsInProgress,
126126
projectId,
127127
request.repository(),

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
@@ -50,7 +50,7 @@
5050
import org.elasticsearch.indices.SystemIndices;
5151
import org.elasticsearch.injection.guice.Inject;
5252
import org.elasticsearch.snapshots.SnapshotInProgressException;
53-
import org.elasticsearch.snapshots.SnapshotsService;
53+
import org.elasticsearch.snapshots.SnapshotsServiceUtils;
5454
import org.elasticsearch.telemetry.TelemetryProvider;
5555
import org.elasticsearch.telemetry.metric.MeterRegistry;
5656
import org.elasticsearch.threadpool.ThreadPool;
@@ -305,7 +305,7 @@ private RolloverResult rolloverDataStream(
305305
boolean isFailureStoreRollover
306306
) throws Exception {
307307
final ProjectMetadata metadata = projectState.metadata();
308-
Set<String> snapshottingDataStreams = SnapshotsService.snapshottingDataStreams(
308+
Set<String> snapshottingDataStreams = SnapshotsServiceUtils.snapshottingDataStreams(
309309
projectState,
310310
Collections.singleton(dataStream.getName())
311311
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import org.elasticsearch.logging.LogManager;
3838
import org.elasticsearch.logging.Logger;
3939
import org.elasticsearch.snapshots.SnapshotInProgressException;
40-
import org.elasticsearch.snapshots.SnapshotsService;
40+
import org.elasticsearch.snapshots.SnapshotsServiceUtils;
4141

4242
import java.io.IOException;
4343
import java.util.HashSet;
@@ -664,7 +664,7 @@ public static ClusterState deleteDataStreams(ProjectState projectState, Set<Data
664664
}
665665

666666
Set<String> dataStreamNames = dataStreams.stream().map(DataStream::getName).collect(Collectors.toSet());
667-
Set<String> snapshottingDataStreams = SnapshotsService.snapshottingDataStreams(projectState, dataStreamNames);
667+
Set<String> snapshottingDataStreams = SnapshotsServiceUtils.snapshottingDataStreams(projectState, dataStreamNames);
668668
if (snapshottingDataStreams.isEmpty() == false) {
669669
throw new SnapshotInProgressException(
670670
"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
@@ -35,7 +35,7 @@
3535
import org.elasticsearch.injection.guice.Inject;
3636
import org.elasticsearch.snapshots.RestoreService;
3737
import org.elasticsearch.snapshots.SnapshotInProgressException;
38-
import org.elasticsearch.snapshots.SnapshotsService;
38+
import org.elasticsearch.snapshots.SnapshotsServiceUtils;
3939

4040
import java.util.HashMap;
4141
import java.util.HashSet;
@@ -186,7 +186,7 @@ public static ClusterState deleteIndices(ProjectState projectState, Set<Index> i
186186
}
187187

188188
// Check if index deletion conflicts with any running snapshots
189-
Set<Index> snapshottingIndices = SnapshotsService.snapshottingIndices(projectState, indicesToDelete);
189+
Set<Index> snapshottingIndices = SnapshotsServiceUtils.snapshottingIndices(projectState, indicesToDelete);
190190
if (snapshottingIndices.isEmpty() == false) {
191191
throw new SnapshotInProgressException(
192192
"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
@@ -77,7 +77,7 @@
7777
import org.elasticsearch.rest.RestStatus;
7878
import org.elasticsearch.snapshots.RestoreService;
7979
import org.elasticsearch.snapshots.SnapshotInProgressException;
80-
import org.elasticsearch.snapshots.SnapshotsService;
80+
import org.elasticsearch.snapshots.SnapshotsServiceUtils;
8181
import org.elasticsearch.tasks.TaskId;
8282
import org.elasticsearch.threadpool.ThreadPool;
8383

@@ -346,7 +346,7 @@ static ClusterState addIndexClosedBlocks(
346346
}
347347

348348
// Check if index closing conflicts with any running snapshots
349-
Set<Index> snapshottingIndices = SnapshotsService.snapshottingIndices(currentProjectState, indicesToClose);
349+
Set<Index> snapshottingIndices = SnapshotsServiceUtils.snapshottingIndices(currentProjectState, indicesToClose);
350350
if (snapshottingIndices.isEmpty() == false) {
351351
throw new SnapshotInProgressException(
352352
"Cannot close indices that are being snapshotted: "
@@ -934,7 +934,7 @@ static Tuple<ClusterState, List<IndexResult>> closeRoutingTable(
934934
}
935935

936936
// Check if index closing conflicts with any running snapshots
937-
Set<Index> snapshottingIndices = SnapshotsService.snapshottingIndices(currentProjectState, Set.of(index));
937+
Set<Index> snapshottingIndices = SnapshotsServiceUtils.snapshottingIndices(currentProjectState, Set.of(index));
938938
if (snapshottingIndices.isEmpty() == false) {
939939
closingResults.put(
940940
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;
@@ -111,7 +111,11 @@ public Map<RepositoryShardId, Set<ShardGeneration>> obsoleteShardGenerations() {
111111
* Returns a new {@link ClusterState}, based on the given {@code state} with the create-snapshot entry removed.
112112
*/
113113
public ClusterState updatedClusterState(ClusterState state) {
114-
final ClusterState updatedState = SnapshotsService.stateWithoutSnapshot(state, snapshotInfo.snapshot(), updatedShardGenerations);
114+
final ClusterState updatedState = SnapshotsServiceUtils.stateWithoutSnapshot(
115+
state,
116+
snapshotInfo.snapshot(),
117+
updatedShardGenerations
118+
);
115119
// Now that the updated cluster state may have changed in-progress shard snapshots' shard generations to the latest shard
116120
// generation, let's mark any now unreferenced shard generations as obsolete and ready to be deleted.
117121
obsoleteGenerations.set(

0 commit comments

Comments
 (0)