Skip to content

Commit

Permalink
Increase logging level for SLMSnapshotBlockingIntegTests
Browse files Browse the repository at this point in the history
Related to #46508
  • Loading branch information
dakrone committed Sep 12, 2019
1 parent b52c2d5 commit 00a5669
Showing 1 changed file with 32 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.snapshots.SnapshotMissingException;
import org.elasticsearch.snapshots.mockstore.MockRepository;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.junit.annotations.TestLogging;
import org.elasticsearch.xpack.core.LocalStateCompositeXPackPlugin;
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicy;
Expand All @@ -41,16 +42,34 @@
/**
* Tests for Snapshot Lifecycle Management that require a slow or blocked snapshot repo (using {@link MockRepository}
*/
@TestLogging(value = "org.elasticsearch.xpack.slm:TRACE,org.elasticsearch.xpack.core.slm:TRACE",
reason = "https://github.com/elastic/elasticsearch/issues/46508")
public class SLMSnapshotBlockingIntegTests extends ESIntegTestCase {

static final String REPO = "my-repo";

@After
public void resetSLMSettings() {
public void resetSLMSettings() throws Exception {
// unset retention settings
client().admin().cluster().prepareUpdateSettings()
.setTransientSettings(Settings.builder()
.put(LifecycleSettings.SLM_RETENTION_SCHEDULE, (String) null)
.build())
.get();

// Cancel/delete all snapshots
assertBusy(() -> {
logger.info("--> wiping all snapshots");
client().admin().cluster().prepareGetSnapshots(REPO).get().getSnapshots(REPO)
.forEach(snapshotInfo -> {
try {
client().admin().cluster().prepareDeleteSnapshot(REPO, snapshotInfo.snapshotId().getName()).get();
} catch (Exception e) {
logger.warn("exception cleaning up snapshot " + snapshotInfo.snapshotId().getName(), e);
fail("exception cleanup up snapshot");
}
});
});
}

@Override
Expand All @@ -61,20 +80,19 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
public void testSnapshotInProgress() throws Exception {
final String indexName = "test";
final String policyName = "test-policy";
final String repoId = "my-repo";
int docCount = 20;
for (int i = 0; i < docCount; i++) {
index(indexName, "_doc", i + "", Collections.singletonMap("foo", "bar"));
}

// Create a snapshot repo
initializeRepo(repoId);
initializeRepo(REPO);

logger.info("--> creating policy {}", policyName);
createSnapshotPolicy(policyName, "snap", "1 2 3 4 5 ?", repoId, indexName, true);
createSnapshotPolicy(policyName, "snap", "1 2 3 4 5 ?", REPO, indexName, true);

logger.info("--> blocking master from completing snapshot");
blockMasterFromFinalizingSnapshotOnIndexFile(repoId);
blockMasterFromFinalizingSnapshotOnIndexFile(REPO);

logger.info("--> executing snapshot lifecycle");
final String snapshotName = executePolicy(policyName);
Expand All @@ -96,11 +114,11 @@ public void testSnapshotInProgress() throws Exception {
});

logger.info("--> unblocking snapshots");
unblockRepo(repoId);
unblockRepo(REPO);

// Cancel/delete the snapshot
try {
client().admin().cluster().prepareDeleteSnapshot(repoId, snapshotName).get();
client().admin().cluster().prepareDeleteSnapshot(REPO, snapshotName).get();
} catch (SnapshotMissingException e) {
// ignore
}
Expand All @@ -109,16 +127,15 @@ public void testSnapshotInProgress() throws Exception {
public void testRetentionWhileSnapshotInProgress() throws Exception {
final String indexName = "test";
final String policyId = "slm-policy";
final String repoId = "slm-repo";
int docCount = 20;
for (int i = 0; i < docCount; i++) {
index(indexName, "_doc", i + "", Collections.singletonMap("foo", "bar"));
}

initializeRepo(repoId);
initializeRepo(REPO);

logger.info("--> creating policy {}", policyId);
createSnapshotPolicy(policyId, "snap", "1 2 3 4 5 ?", repoId, indexName, true,
createSnapshotPolicy(policyId, "snap", "1 2 3 4 5 ?", REPO, indexName, true,
new SnapshotRetentionConfiguration(TimeValue.timeValueSeconds(0), null, null));

// Create a snapshot and wait for it to be complete (need something that can be deleted)
Expand All @@ -127,7 +144,7 @@ public void testRetentionWhileSnapshotInProgress() throws Exception {
assertBusy(() -> {
try {
SnapshotsStatusResponse s =
client().admin().cluster().prepareSnapshotStatus(repoId).setSnapshots(completedSnapshotName).get();
client().admin().cluster().prepareSnapshotStatus(REPO).setSnapshots(completedSnapshotName).get();
assertThat("expected a snapshot but none were returned", s.getSnapshots().size(), equalTo(1));
SnapshotStatus status = s.getSnapshots().get(0);
logger.info("--> waiting for snapshot {} to be completed, got: {}", completedSnapshotName, status.getState());
Expand All @@ -147,7 +164,7 @@ public void testRetentionWhileSnapshotInProgress() throws Exception {

// Take another snapshot, but before doing that, block it from completing
logger.info("--> blocking nodes from completing snapshot");
blockAllDataNodes(repoId);
blockAllDataNodes(REPO);
final String secondSnapName = executePolicy(policyId);

// Check that the executed snapshot shows up in the SLM output as in_progress
Expand Down Expand Up @@ -178,8 +195,8 @@ public void testRetentionWhileSnapshotInProgress() throws Exception {
Thread.sleep(1500);

logger.info("--> unblocking snapshots");
unblockRepo(repoId);
unblockAllDataNodes(repoId);
unblockRepo(REPO);
unblockAllDataNodes(REPO);

// Check that the snapshot created by the policy has been removed by retention
assertBusy(() -> {
Expand All @@ -188,19 +205,12 @@ public void testRetentionWhileSnapshotInProgress() throws Exception {
logger.info("--> waiting for snapshot to be deleted");
try {
SnapshotsStatusResponse s =
client().admin().cluster().prepareSnapshotStatus(repoId).setSnapshots(completedSnapshotName).get();
client().admin().cluster().prepareSnapshotStatus(REPO).setSnapshots(completedSnapshotName).get();
assertNull("expected no snapshot but one was returned", s.getSnapshots().get(0));
} catch (SnapshotMissingException e) {
// Great, we wanted it to be deleted!
}
});

// Cancel/delete the snapshot
try {
client().admin().cluster().prepareDeleteSnapshot(repoId, secondSnapName).get();
} catch (SnapshotMissingException e) {
// ignore
}
}

private void initializeRepo(String repoName) {
Expand Down

0 comments on commit 00a5669

Please sign in to comment.