Skip to content

Commit 1b8547e

Browse files
Dry up Snapshot IT Infrastructure (#62578)
Mainly just shortening the diff of #61839 here by moving test utilities to the abstract test case. Also, making use of the now available functionality to simplify existing tests and improve logging in them.
1 parent a653a1c commit 1b8547e

File tree

6 files changed

+127
-170
lines changed

6 files changed

+127
-170
lines changed

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

Lines changed: 34 additions & 87 deletions
Large diffs are not rendered by default.

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.Collections;
5050
import java.util.Locale;
5151
import java.util.Map;
52+
import java.util.concurrent.ExecutionException;
5253
import java.util.function.Function;
5354
import java.util.stream.Collectors;
5455

@@ -111,8 +112,7 @@ public void testConcurrentlyChangeRepositoryContents() throws Exception {
111112
.put("compress", false)
112113
.put("chunk_size", randomIntBetween(100, 1000), ByteSizeUnit.BYTES)));
113114

114-
logger.info("--> delete snapshot");
115-
client.admin().cluster().prepareDeleteSnapshot(repoName, snapshot).get();
115+
startDeleteSnapshot(repoName, snapshot).get();
116116

117117
logger.info("--> make sure snapshot doesn't exist");
118118
expectThrows(SnapshotMissingException.class, () -> client.admin().cluster().prepareGetSnapshots(repoName)
@@ -180,8 +180,7 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
180180
logger.info("--> verify index-N blob is found at the new location");
181181
assertThat(getRepositoryData(repoName).getGenId(), is(beforeMoveGen + 1));
182182

183-
logger.info("--> delete snapshot");
184-
client().admin().cluster().prepareDeleteSnapshot(repoName, snapshot).get();
183+
startDeleteSnapshot(repoName, snapshot).get();
185184

186185
logger.info("--> verify index-N blob is found at the expected location");
187186
assertThat(getRepositoryData(repoName).getGenId(), is(beforeMoveGen + 2));
@@ -241,7 +240,7 @@ public void testHandlingMissingRootLevelSnapshotMetadata() throws Exception {
241240
is(SnapshotsService.OLD_SNAPSHOT_FORMAT));
242241

243242
logger.info("--> verify that snapshot with missing root level metadata can be deleted");
244-
assertAcked(client().admin().cluster().prepareDeleteSnapshot(repoName, snapshotToCorrupt.getName()).get());
243+
assertAcked(startDeleteSnapshot(repoName, snapshotToCorrupt.getName()).get());
245244

246245
logger.info("--> verify that repository is assumed in new metadata format after removing corrupted snapshot");
247246
assertThat(PlainActionFuture.get(f -> threadPool.generic().execute(
@@ -291,7 +290,7 @@ public void testMountCorruptedRepositoryData() throws Exception {
291290
expectThrows(RepositoryException.class, () -> getRepositoryData(otherRepo));
292291
}
293292

294-
public void testHandleSnapshotErrorWithBwCFormat() throws IOException {
293+
public void testHandleSnapshotErrorWithBwCFormat() throws IOException, ExecutionException, InterruptedException {
295294
final String repoName = "test-repo";
296295
final Path repoPath = randomRepoPath();
297296
createRepository(repoName, "fs", repoPath);
@@ -315,13 +314,12 @@ public void testHandleSnapshotErrorWithBwCFormat() throws IOException {
315314
assertFileExists(initialShardMetaPath);
316315
Files.move(initialShardMetaPath, shardPath.resolve(BlobStoreRepository.INDEX_FILE_PREFIX + "1"));
317316

318-
logger.info("--> delete old version snapshot");
319-
client().admin().cluster().prepareDeleteSnapshot(repoName, oldVersionSnapshot).get();
317+
startDeleteSnapshot(repoName, oldVersionSnapshot).get();
320318

321319
createFullSnapshot(repoName, "snapshot-2");
322320
}
323321

324-
public void testRepairBrokenShardGenerations() throws IOException {
322+
public void testRepairBrokenShardGenerations() throws Exception {
325323
final String repoName = "test-repo";
326324
final Path repoPath = randomRepoPath();
327325
createRepository(repoName, "fs", repoPath);
@@ -336,8 +334,7 @@ public void testRepairBrokenShardGenerations() throws IOException {
336334

337335
createFullSnapshot(repoName, "snapshot-1");
338336

339-
logger.info("--> delete old version snapshot");
340-
client().admin().cluster().prepareDeleteSnapshot(repoName, oldVersionSnapshot).get();
337+
startDeleteSnapshot(repoName, oldVersionSnapshot).get();
341338

342339
logger.info("--> move shard level metadata to new generation and make RepositoryData point at an older generation");
343340
final IndexId indexId = getRepositoryData(repoName).resolveIndexId(indexName);

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

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,11 @@
3232
import org.elasticsearch.action.admin.indices.stats.ShardStats;
3333
import org.elasticsearch.action.index.IndexRequestBuilder;
3434
import org.elasticsearch.action.support.ActiveShardCount;
35-
import org.elasticsearch.action.support.PlainActionFuture;
3635
import org.elasticsearch.action.support.master.AcknowledgedResponse;
3736
import org.elasticsearch.client.AdminClient;
3837
import org.elasticsearch.client.Client;
3938
import org.elasticsearch.client.node.NodeClient;
40-
import org.elasticsearch.cluster.ClusterChangedEvent;
4139
import org.elasticsearch.cluster.ClusterState;
42-
import org.elasticsearch.cluster.ClusterStateListener;
4340
import org.elasticsearch.cluster.ClusterStateUpdateTask;
4441
import org.elasticsearch.cluster.NamedDiff;
4542
import org.elasticsearch.cluster.SnapshotsInProgress;
@@ -111,6 +108,7 @@
111108
import java.util.concurrent.atomic.AtomicBoolean;
112109
import java.util.concurrent.atomic.AtomicReference;
113110
import java.util.function.Consumer;
111+
import java.util.function.Function;
114112

115113
import static org.elasticsearch.index.seqno.RetentionLeaseActions.RETAIN_ALL;
116114
import static org.elasticsearch.test.NodeRoles.nonMasterNode;
@@ -340,13 +338,13 @@ public void testRestoreCustomMetadata() throws Exception {
340338
equalTo("before_snapshot_s_gw_noapi"));
341339
}
342340

343-
private void updateClusterState(final ClusterStateUpdater updater) throws InterruptedException {
341+
private void updateClusterState(final Function<ClusterState, ClusterState> updater) throws InterruptedException {
344342
final CountDownLatch countDownLatch = new CountDownLatch(1);
345343
final ClusterService clusterService = internalCluster().getInstance(ClusterService.class);
346344
clusterService.submitStateUpdateTask("test", new ClusterStateUpdateTask() {
347345
@Override
348-
public ClusterState execute(ClusterState currentState) throws Exception {
349-
return updater.execute(currentState);
346+
public ClusterState execute(ClusterState currentState) {
347+
return updater.apply(currentState);
350348
}
351349

352350
@Override
@@ -362,10 +360,6 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
362360
countDownLatch.await();
363361
}
364362

365-
private interface ClusterStateUpdater {
366-
ClusterState execute(ClusterState currentState) throws Exception;
367-
}
368-
369363
public void testSnapshotDuringNodeShutdown() throws Exception {
370364
logger.info("--> start 2 nodes");
371365
Client client = client();
@@ -857,10 +851,9 @@ public void testRestoreShrinkIndex() throws Exception {
857851
assertAcked(client.admin().indices().prepareResizeIndex(sourceIdx, shrunkIdx).get());
858852

859853
logger.info("--> snapshot the shrunk index");
860-
CreateSnapshotResponse createResponse = client.admin().cluster()
854+
assertSuccessful(client.admin().cluster()
861855
.prepareCreateSnapshot(repo, snapshot)
862-
.setWaitForCompletion(true).setIndices(shrunkIdx).get();
863-
assertEquals(SnapshotState.SUCCESS, createResponse.getSnapshotInfo().state());
856+
.setWaitForCompletion(true).setIndices(shrunkIdx).execute());
864857

865858
logger.info("--> delete index and stop the data node");
866859
assertAcked(client.admin().indices().prepareDelete(sourceIdx).get());
@@ -912,7 +905,7 @@ public void testSnapshotWithDateMath() {
912905
assertThat(snapshots.get(0).getState().completed(), equalTo(true));
913906
}
914907

915-
public void testSnapshotTotalAndIncrementalSizes() throws IOException {
908+
public void testSnapshotTotalAndIncrementalSizes() throws Exception {
916909
Client client = client();
917910
final String indexName = "test-blocks-1";
918911
final String repositoryName = "repo-" + indexName;
@@ -966,7 +959,7 @@ public void testSnapshotTotalAndIncrementalSizes() throws IOException {
966959
createFullSnapshot(repositoryName, snapshot1);
967960

968961
// drop 1st one to avoid miscalculation as snapshot reuses some files of prev snapshot
969-
assertAcked(client.admin().cluster().prepareDeleteSnapshot(repositoryName, snapshot0).get());
962+
assertAcked(startDeleteSnapshot(repositoryName, snapshot0).get());
970963

971964
response = client.admin().cluster().prepareSnapshotStatus(repositoryName)
972965
.setSnapshots(snapshot1)
@@ -1209,24 +1202,9 @@ public void testAbortWaitsOnDataNode() throws Exception {
12091202
createRepository(repoName, "mock");
12101203
blockAllDataNodes(repoName);
12111204
final String snapshotName = "test-snap";
1212-
final ActionFuture<CreateSnapshotResponse> snapshotResponse =
1213-
client().admin().cluster().prepareCreateSnapshot(repoName, snapshotName).setWaitForCompletion(true).execute();
1205+
final ActionFuture<CreateSnapshotResponse> snapshotResponse = startFullSnapshot(repoName, snapshotName);
12141206
waitForBlock(dataNodeName, repoName, TimeValue.timeValueSeconds(30L));
12151207

1216-
final ClusterService clusterService = internalCluster().getInstance(ClusterService.class, otherDataNode);
1217-
final PlainActionFuture<Void> abortVisibleFuture = PlainActionFuture.newFuture();
1218-
clusterService.addListener(new ClusterStateListener() {
1219-
@Override
1220-
public void clusterChanged(ClusterChangedEvent event) {
1221-
final SnapshotsInProgress snapshotsInProgress = event.state().custom(SnapshotsInProgress.TYPE);
1222-
if (snapshotsInProgress != null && snapshotsInProgress.entries().stream()
1223-
.anyMatch(entry -> entry.state() == SnapshotsInProgress.State.ABORTED)) {
1224-
abortVisibleFuture.onResponse(null);
1225-
clusterService.removeListener(this);
1226-
}
1227-
}
1228-
});
1229-
12301208
final AtomicBoolean blocked = new AtomicBoolean(true);
12311209

12321210
final TransportService transportService = internalCluster().getInstance(TransportService.class, otherDataNode);
@@ -1241,10 +1219,10 @@ public void onRequestSent(DiscoveryNode node, long requestId, String action, Tra
12411219
});
12421220

12431221
logger.info("--> abort snapshot");
1244-
final ActionFuture<AcknowledgedResponse> deleteResponse =
1245-
client().admin().cluster().prepareDeleteSnapshot(repoName, snapshotName).execute();
1222+
final ActionFuture<AcknowledgedResponse> deleteResponse = startDeleteSnapshot(repoName, snapshotName);
12461223

1247-
abortVisibleFuture.get(30L, TimeUnit.SECONDS);
1224+
awaitClusterState(otherDataNode, state -> state.custom(SnapshotsInProgress.TYPE, SnapshotsInProgress.EMPTY)
1225+
.entries().stream().anyMatch(entry -> entry.state() == SnapshotsInProgress.State.ABORTED));
12481226

12491227
assertFalse("delete should not be able to finish until data node is unblocked", deleteResponse.isDone());
12501228
blocked.set(false);
@@ -1261,8 +1239,7 @@ public void testPartialSnapshotAllShardsMissing() throws Exception {
12611239
createIndex("some-index");
12621240
stopNode(dataNode);
12631241
ensureStableCluster(1);
1264-
final CreateSnapshotResponse createSnapshotResponse = client().admin().cluster().prepareCreateSnapshot(repoName, "test-snap")
1265-
.setPartial(true).setWaitForCompletion(true).get();
1242+
final CreateSnapshotResponse createSnapshotResponse = startFullSnapshot(repoName, "test-snap", true).get();
12661243
assertThat(createSnapshotResponse.getSnapshotInfo().state(), is(SnapshotState.PARTIAL));
12671244
}
12681245

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

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.elasticsearch.snapshots;
2121

2222
import org.apache.lucene.util.BytesRef;
23-
import org.apache.lucene.util.LuceneTestCase;
2423
import org.elasticsearch.ElasticsearchException;
2524
import org.elasticsearch.ExceptionsHelper;
2625
import org.elasticsearch.Version;
@@ -101,6 +100,7 @@
101100
import java.util.List;
102101
import java.util.Locale;
103102
import java.util.Map;
103+
import java.util.concurrent.ExecutionException;
104104
import java.util.concurrent.TimeUnit;
105105
import java.util.function.Consumer;
106106
import java.util.function.Predicate;
@@ -140,7 +140,6 @@
140140
import static org.hamcrest.Matchers.nullValue;
141141

142142
// The tests in here do a lot of state updates and other writes to disk and are slowed down too much by WindowsFS
143-
@LuceneTestCase.SuppressFileSystems(value = "WindowsFS")
144143
public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCase {
145144

146145
@Override
@@ -423,8 +422,7 @@ public void testEmptySnapshot() throws Exception {
423422
createRepository("test-repo", "fs");
424423

425424
logger.info("--> snapshot");
426-
CreateSnapshotResponse createSnapshotResponse = client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap")
427-
.setWaitForCompletion(true).get();
425+
CreateSnapshotResponse createSnapshotResponse = startFullSnapshot("test-repo", "test-snap").get();
428426
assertThat(createSnapshotResponse.getSnapshotInfo().totalShards(), equalTo(0));
429427
assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), equalTo(0));
430428

@@ -1186,8 +1184,7 @@ public void testDeleteSnapshot() throws Exception {
11861184

11871185
assertDocCount("test-idx", 10L * numberOfSnapshots);
11881186

1189-
logger.info("--> delete the last snapshot");
1190-
client.admin().cluster().prepareDeleteSnapshot("test-repo", lastSnapshot).get();
1187+
startDeleteSnapshot("test-repo", lastSnapshot).get();
11911188
logger.info("--> make sure that number of files is back to what it was when the first snapshot was made");
11921189
assertFileCount(repo, numberOfFiles[0]);
11931190
}
@@ -1318,8 +1315,7 @@ public void testDeleteSnapshotWithMissingIndexAndShardMetadata() throws Exceptio
13181315
Files.delete(shardZero.resolve("snap-" + snapshotInfo.snapshotId().getUUID() + ".dat"));
13191316
}
13201317

1321-
logger.info("--> delete snapshot");
1322-
client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap-1").get();
1318+
startDeleteSnapshot("test-repo", "test-snap-1").get();
13231319

13241320
logger.info("--> make sure snapshot doesn't exist");
13251321

@@ -1354,8 +1350,7 @@ public void testDeleteSnapshotWithMissingMetadata() throws Exception {
13541350
Path metadata = repo.resolve("meta-" + createSnapshotResponse.getSnapshotInfo().snapshotId().getUUID() + ".dat");
13551351
Files.delete(metadata);
13561352

1357-
logger.info("--> delete snapshot");
1358-
client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap-1").get();
1353+
startDeleteSnapshot("test-repo", "test-snap-1").get();
13591354

13601355
logger.info("--> make sure snapshot doesn't exist");
13611356
expectThrows(SnapshotMissingException.class, () -> client.admin().cluster().prepareGetSnapshots("test-repo")
@@ -1388,8 +1383,7 @@ public void testDeleteSnapshotWithCorruptedSnapshotFile() throws Exception {
13881383
try(SeekableByteChannel outChan = Files.newByteChannel(snapshotPath, StandardOpenOption.WRITE)) {
13891384
outChan.truncate(randomInt(10));
13901385
}
1391-
logger.info("--> delete snapshot");
1392-
client.admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap-1").get();
1386+
startDeleteSnapshot("test-repo", "test-snap-1").get();
13931387

13941388
logger.info("--> make sure snapshot doesn't exist");
13951389
expectThrows(SnapshotMissingException.class,
@@ -1442,7 +1436,7 @@ public void testDeleteSnapshotWithCorruptedGlobalState() throws Exception {
14421436
assertThat(snapshotStatusResponse.getSnapshots(), hasSize(1));
14431437
assertThat(snapshotStatusResponse.getSnapshots().get(0).getSnapshot().getSnapshotId().getName(), equalTo("test-snap"));
14441438

1445-
assertAcked(client().admin().cluster().prepareDeleteSnapshot("test-repo", "test-snap").get());
1439+
assertAcked(startDeleteSnapshot("test-repo", "test-snap").get());
14461440
expectThrows(SnapshotMissingException.class, () -> client().admin().cluster()
14471441
.prepareGetSnapshots("test-repo").addSnapshots("test-snap").get().getSnapshots("test-repo"));
14481442
assertRequestBuilderThrows(client().admin().cluster().prepareSnapshotStatus("test-repo").addSnapshots("test-snap"),
@@ -2637,7 +2631,7 @@ public void testRestoreSnapshotWithCorruptedIndexMetadata() throws Exception {
26372631
}
26382632
}
26392633

2640-
assertAcked(client().admin().cluster().prepareDeleteSnapshot("test-repo", snapshotInfo.snapshotId().getName()).get());
2634+
assertAcked(startDeleteSnapshot("test-repo", snapshotInfo.snapshotId().getName()).get());
26412635
}
26422636

26432637
/**
@@ -2756,8 +2750,7 @@ public void testCannotCreateSnapshotsWithSameName() throws Exception {
27562750
assertThat(e.getMessage(), containsString("snapshot with the same name already exists"));
27572751
}
27582752

2759-
logger.info("--> delete the first snapshot");
2760-
client.admin().cluster().prepareDeleteSnapshot(repositoryName, snapshotName).get();
2753+
startDeleteSnapshot(repositoryName, snapshotName).get();
27612754

27622755
logger.info("--> try creating a snapshot with the same name, now it should work because the first one was deleted");
27632756
createSnapshotResponse = client.admin()
@@ -2816,7 +2809,7 @@ public void testGetSnapshotsRequest() throws Exception {
28162809
assertEquals(1, getSnapshotsResponse.getSnapshots("test-repo").size());
28172810
assertEquals("snap-on-empty-repo", getSnapshotsResponse.getSnapshots("test-repo").get(0).snapshotId().getName());
28182811
unblockNode(repositoryName, initialBlockedNode); // unblock node
2819-
client.admin().cluster().prepareDeleteSnapshot(repositoryName, "snap-on-empty-repo").get();
2812+
startDeleteSnapshot(repositoryName, "snap-on-empty-repo").get();
28202813

28212814
final int numSnapshots = randomIntBetween(1, 3) + 1;
28222815
logger.info("--> take {} snapshot(s)", numSnapshots - 1);
@@ -3319,7 +3312,7 @@ public void testRestoreIncreasesPrimaryTerms() {
33193312
assertThat(restoredIndexMetadata.getSettings().get(IndexMetadata.SETTING_HISTORY_UUID), notNullValue());
33203313
}
33213314

3322-
public void testSnapshotDifferentIndicesBySameName() throws InterruptedException {
3315+
public void testSnapshotDifferentIndicesBySameName() throws InterruptedException, ExecutionException {
33233316
String indexName = "testindex";
33243317
String repoName = "test-repo";
33253318
Path absolutePath = randomRepoPath().toAbsolutePath();
@@ -3376,8 +3369,7 @@ public void testSnapshotDifferentIndicesBySameName() throws InterruptedException
33763369
snapshotToRestore = "snap-1";
33773370
expectedCount = docCount;
33783371
}
3379-
logger.info("--> deleting snapshot [{}]", snapshotToDelete);
3380-
assertAcked(client().admin().cluster().prepareDeleteSnapshot(repoName, snapshotToDelete).get());
3372+
assertAcked(startDeleteSnapshot(repoName, snapshotToDelete).get());
33813373
logger.info("--> restoring snapshot [{}]", snapshotToRestore);
33823374
client().admin().cluster().prepareRestoreSnapshot(repoName, snapshotToRestore).setIndices(indexName).setRenamePattern(indexName)
33833375
.setRenameReplacement("restored-3").setWaitForCompletion(true).get();

0 commit comments

Comments
 (0)