Skip to content

Commit

Permalink
Wait for rollover to happen in testShrinkActionInPolicyWithoutHotPhase (
Browse files Browse the repository at this point in the history
#70658)

This also removes testShrinkAfterRollover because it was passing for the
wrong reasons (the srhunk index name it was composing never existed
anymore) and the scenario is already extensively tested in
`ShrinkActionIT`, without using a full policy that is subject to
flakiness as the managed index might get deleted before we pick up the
shrink index name from the execution state.
  • Loading branch information
andreidan authored Mar 23, 2021
1 parent 093cd95 commit 45f141e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public static String waitAndGetShrinkIndexName(RestClient client, String origina

Map<String, Map<String, Object>> indexResponse = ((Map<String, Map<String, Object>>) responseMap.get("indices"));
Map<String, Object> explainIndexResponse = indexResponse.get(originalIndex);
if(explainIndexResponse == null) {
if (explainIndexResponse == null) {
// maybe we swapped the alias from the original index to the shrunken one already
for (Map.Entry<String, Map<String, Object>> indexToExplainMap : indexResponse.entrySet()) {
// we don't know the exact name of the shrunken index, but we know it starts with the configured prefix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Template;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.IndexSettings;
Expand All @@ -39,7 +38,6 @@
import java.util.concurrent.TimeUnit;

import static org.elasticsearch.xpack.TimeSeriesRestDriver.createComposableTemplate;
import static org.elasticsearch.xpack.TimeSeriesRestDriver.createFullPolicy;
import static org.elasticsearch.xpack.TimeSeriesRestDriver.createNewSingletonPolicy;
import static org.elasticsearch.xpack.TimeSeriesRestDriver.createSnapshotRepo;
import static org.elasticsearch.xpack.TimeSeriesRestDriver.explainIndex;
Expand All @@ -48,7 +46,6 @@
import static org.elasticsearch.xpack.TimeSeriesRestDriver.indexDocument;
import static org.elasticsearch.xpack.TimeSeriesRestDriver.rolloverMaxOneDocCondition;
import static org.elasticsearch.xpack.TimeSeriesRestDriver.waitAndGetShrinkIndexName;
import static org.elasticsearch.xpack.core.ilm.ShrinkIndexNameSupplier.SHRUNKEN_INDEX_PREFIX;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -103,7 +100,6 @@ public void testRolloverIsSkippedOnManualDataStreamRollover() throws Exception {
equalTo(PhaseCompleteStep.finalStep("hot").getKey())), 30, TimeUnit.SECONDS);
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/70595")
public void testShrinkActionInPolicyWithoutHotPhase() throws Exception {
createNewSingletonPolicy(client(), policyName, "warm", new ShrinkAction(1, null));
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
Expand All @@ -116,28 +112,16 @@ public void testShrinkActionInPolicyWithoutHotPhase() throws Exception {

// Manual rollover the original index such that it's not the write index in the data stream anymore
rolloverMaxOneDocCondition(client(), dataStream);
// Wait for rollover to happen
String rolloverIndex = DataStream.getDefaultBackingIndexName(dataStream, 2);
assertBusy(() -> assertTrue("the rollover action created the rollover index", indexExists(rolloverIndex)), 30, TimeUnit.SECONDS);

String shrunkenIndex = waitAndGetShrinkIndexName(client(), backingIndexName);
assertBusy(() -> assertTrue(indexExists(shrunkenIndex)), 30, TimeUnit.SECONDS);
assertBusy(() -> assertThat(getStepKeyForIndex(client(), shrunkenIndex), equalTo(PhaseCompleteStep.finalStep("warm").getKey())));
assertBusy(() -> assertThat("the original index must've been deleted", indexExists(backingIndexName), is(false)));
}

public void testShrinkAfterRollover() throws Exception {
createFullPolicy(client(), policyName, TimeValue.ZERO);
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
indexDocument(client(), dataStream, true);

String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
String rolloverIndex = DataStream.getDefaultBackingIndexName(dataStream, 2);
String shrunkenIndex = SHRUNKEN_INDEX_PREFIX + backingIndexName;
assertBusy(() -> assertTrue("the rollover action created the rollover index", indexExists(rolloverIndex)));
assertBusy(() -> assertFalse("the original index was deleted by the shrink action", indexExists(backingIndexName)),
60, TimeUnit.SECONDS);
assertBusy(() -> assertFalse("the shrunken index was deleted by the delete action", indexExists(shrunkenIndex)),
30, TimeUnit.SECONDS);
}

public void testSearchableSnapshotAction() throws Exception {
String snapshotRepo = randomAlphaOfLengthBetween(5, 10);
createSnapshotRepo(client(), snapshotRepo, randomBoolean());
Expand Down

0 comments on commit 45f141e

Please sign in to comment.