Skip to content

Fix SearchableSnapshotActionIT #66698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.elasticsearch.xpack.core.ilm.SetPriorityAction;
import org.elasticsearch.xpack.core.ilm.ShrinkAction;
import org.elasticsearch.xpack.core.ilm.Step;
import org.junit.After;
import org.junit.Before;

import java.io.IOException;
Expand All @@ -51,22 +52,45 @@
import static org.elasticsearch.xpack.TimeSeriesRestDriver.getStepKeyForIndex;
import static org.elasticsearch.xpack.TimeSeriesRestDriver.indexDocument;
import static org.elasticsearch.xpack.TimeSeriesRestDriver.rolloverMaxOneDocCondition;
import static org.hamcrest.Matchers.containsStringIgnoringCase;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;

public class SearchableSnapshotActionIT extends ESRestTestCase {

private String policy;
private String dataStream;
private String snapshotRepo;

@Before
public void refreshIndex() {
dataStream = "logs-" + randomAlphaOfLength(10).toLowerCase(Locale.ROOT);
policy = "policy-" + randomAlphaOfLength(5);
snapshotRepo = randomAlphaOfLengthBetween(4, 10);
}

@After
public void waitNoRestoresInProgressInRepo() throws Exception {
/*
* This should be a "fairly quick" wait as each test waits for the searchable snapshot action
* to complete.
* It seems that sometime there is a discrepancy between the {@link org.elasticsearch.repositories.RepositoryData}
* status of the snapshots and the cluster state {@link org.elasticsearch.cluster.RestoreInProgress} metadata, which
* will prevent {@link #wipeCluster} from wiping the snapshots as the cluster state would show some
* as "in progress" and won't be able to delete them.
*/
assertBusy(() -> {
try {
Response response = client().performRequest(new Request("GET", "/_snapshot/" + snapshotRepo + "/_status"));
assertThat(EntityUtils.toString(response.getEntity()), containsStringIgnoringCase("\"snapshots\":[]"));
} catch (IOException e) {
// converting to AssertionError here so assertBusy retries
throw new AssertionError(e);
}
});
}

public void testSearchableSnapshotAction() throws Exception {
String snapshotRepo = randomAlphaOfLengthBetween(4, 10);
createSnapshotRepo(client(), snapshotRepo, randomBoolean());
createNewSingletonPolicy(client(), policy, "cold", new SearchableSnapshotAction(snapshotRepo, true));

Expand All @@ -93,7 +117,6 @@ public void testSearchableSnapshotAction() throws Exception {
}

public void testSearchableSnapshotForceMergesIndexToOneSegment() throws Exception {
String snapshotRepo = randomAlphaOfLengthBetween(4, 10);
createSnapshotRepo(client(), snapshotRepo, randomBoolean());
createNewSingletonPolicy(client(), policy, "cold", new SearchableSnapshotAction(snapshotRepo, true));

Expand Down Expand Up @@ -140,7 +163,6 @@ public void testSearchableSnapshotForceMergesIndexToOneSegment() throws Exceptio

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/pull/54433")
public void testDeleteActionDeletesSearchableSnapshot() throws Exception {
String snapshotRepo = randomAlphaOfLengthBetween(4, 10);
createSnapshotRepo(client(), snapshotRepo, randomBoolean());

// create policy with cold and delete phases
Expand Down Expand Up @@ -212,7 +234,6 @@ public void testCreateInvalidPolicy() {
}

public void testUpdatePolicyToAddPhasesYieldsInvalidActionsToBeSkipped() throws Exception {
String snapshotRepo = randomAlphaOfLengthBetween(4, 10);
createSnapshotRepo(client(), snapshotRepo, randomBoolean());
createPolicy(client(), policy,
new Phase("hot", TimeValue.ZERO, Map.of(RolloverAction.NAME, new RolloverAction(null, null, 1L), SearchableSnapshotAction.NAME,
Expand Down Expand Up @@ -266,9 +287,8 @@ public void testUpdatePolicyToAddPhasesYieldsInvalidActionsToBeSkipped() throws
}, 30, TimeUnit.SECONDS);
}

public void testRestoredIndexManagedByLocalPolicySkipsIllegalActions() throws Exception{
public void testRestoredIndexManagedByLocalPolicySkipsIllegalActions() throws Exception {
// let's create a data stream, rollover it and convert the first generation backing index into a searchable snapshot
String snapshotRepo = randomAlphaOfLengthBetween(4, 10);
createSnapshotRepo(client(), snapshotRepo, randomBoolean());
createPolicy(client(), policy,
new Phase("hot", TimeValue.ZERO, Map.of(RolloverAction.NAME, new RolloverAction(null, null, 1L),
Expand Down