Skip to content
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

add awaitsfixed tests for running ILM actions during snapshot #37552

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion x-pack/plugin/ilm/qa/multi-node/build.gradle
Expand Up @@ -5,6 +5,11 @@ dependencies {
testCompile project(path: xpackProject('plugin').path, configuration: 'testArtifacts')
}

integTestRunner {
/* To support taking index snapshots, we have to set path.repo setting */
systemProperty 'tests.path.repo', new File(buildDir, "cluster/shared/repo")
}

integTestCluster {
numNodes = 4
clusterName = 'ilm'
Expand All @@ -16,5 +21,4 @@ integTestCluster {
setting 'xpack.ml.enabled', 'false'
setting 'xpack.license.self_generated.type', 'trial'
setting 'indices.lifecycle.poll_interval', '1000ms'

}
Expand Up @@ -19,6 +19,7 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.engine.FrozenEngine;
import org.elasticsearch.test.rest.ESRestTestCase;
Expand Down Expand Up @@ -358,6 +359,45 @@ public void testDeleteOnlyShouldNotMakeIndexReadonly() throws Exception {
indexDocument();
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37541")
public void testDeleteDuringSnapshot() throws Exception {
// Create the repository before taking the snapshot.
Request request = new Request("PUT", "/_snapshot/repo");
request.setJsonEntity(Strings
.toString(JsonXContent.contentBuilder()
.startObject()
.field("type", "fs")
.startObject("settings")
.field("compress", randomBoolean())
.field("location", System.getProperty("tests.path.repo"))
.field("max_snapshot_bytes_per_sec", "256b")
.endObject()
.endObject()));
assertOK(client().performRequest(request));
// create delete policy
createNewSingletonPolicy("delete", new DeleteAction(), TimeValue.timeValueMillis(0));
// create index without policy
createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0));
// index document so snapshot actually does something
indexDocument();
// start snapshot
request = new Request("PUT", "/_snapshot/repo/snapshot");
request.addParameter("wait_for_completion", "false");
request.setJsonEntity("{\"indices\": \"" + index + "\"}");
assertOK(client().performRequest(request));
// add policy and expect it to trigger delete immediately (while snapshot in progress)
updatePolicy(index, policy);
// assert that index was deleted
assertBusy(() -> assertFalse(indexExists(index)));
// assert that snapshot is still in progress and clean up
assertThat(getSnapshotState("snapshot"), equalTo("IN_PROGRESS"));
assertOK(client().performRequest(new Request("DELETE", "/_snapshot/repo/snapshot")));
ResponseException e = expectThrows(ResponseException.class,
() -> client().performRequest(new Request("GET", "/_snapshot/repo/snapshot")));
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(404));
}

public void testReadOnly() throws Exception {
createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0));
Expand Down Expand Up @@ -427,6 +467,54 @@ public void testShrinkAction() throws Exception {
expectThrows(ResponseException.class, this::indexDocument);
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37541")
public void testShrinkDuringSnapshot() throws Exception {
String shrunkenIndex = ShrinkAction.SHRUNKEN_INDEX_PREFIX + index;
// Create the repository before taking the snapshot.
Request request = new Request("PUT", "/_snapshot/repo");
request.setJsonEntity(Strings
.toString(JsonXContent.contentBuilder()
.startObject()
.field("type", "fs")
.startObject("settings")
.field("compress", randomBoolean())
.field("location", System.getProperty("tests.path.repo"))
.field("max_snapshot_bytes_per_sec", "256b")
.endObject()
.endObject()));
assertOK(client().performRequest(request));
// create delete policy
createNewSingletonPolicy("warm", new ShrinkAction(1), TimeValue.timeValueMillis(0));
// create index without policy
createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 2)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0));
// index document so snapshot actually does something
indexDocument();
// start snapshot
request = new Request("PUT", "/_snapshot/repo/snapshot");
request.addParameter("wait_for_completion", "false");
request.setJsonEntity("{\"indices\": \"" + index + "\"}");
assertOK(client().performRequest(request));
// add policy and expect it to trigger delete immediately (while snapshot in progress)
updatePolicy(index, policy);
// assert that index was shrunk and original index was deleted
assertBusy(() -> {
assertTrue(indexExists(shrunkenIndex));
assertTrue(aliasExists(shrunkenIndex, index));
Map<String, Object> settings = getOnlyIndexSettings(shrunkenIndex);
assertThat(getStepKeyForIndex(shrunkenIndex), equalTo(TerminalPolicyStep.KEY));
assertThat(settings.get(IndexMetaData.SETTING_NUMBER_OF_SHARDS), equalTo(String.valueOf(1)));
assertThat(settings.get(IndexMetaData.INDEX_BLOCKS_WRITE_SETTING.getKey()), equalTo("true"));
});
expectThrows(ResponseException.class, this::indexDocument);
// assert that snapshot is still in progress and clean up
assertThat(getSnapshotState("snapshot"), equalTo("IN_PROGRESS"));
assertOK(client().performRequest(new Request("DELETE", "/_snapshot/repo/snapshot")));
ResponseException e = expectThrows(ResponseException.class,
() -> client().performRequest(new Request("GET", "/_snapshot/repo/snapshot")));
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(404));
talevy marked this conversation as resolved.
Show resolved Hide resolved
}

public void testFreezeAction() throws Exception {
createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0));
Expand All @@ -441,6 +529,51 @@ public void testFreezeAction() throws Exception {
});
}

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37541")
public void testFreezeDuringSnapshot() throws Exception {
// Create the repository before taking the snapshot.
Request request = new Request("PUT", "/_snapshot/repo");
request.setJsonEntity(Strings
.toString(JsonXContent.contentBuilder()
.startObject()
.field("type", "fs")
.startObject("settings")
.field("compress", randomBoolean())
.field("location", System.getProperty("tests.path.repo"))
.field("max_snapshot_bytes_per_sec", "256b")
.endObject()
.endObject()));
assertOK(client().performRequest(request));
// create delete policy
createNewSingletonPolicy("cold", new FreezeAction(), TimeValue.timeValueMillis(0));
// create index without policy
createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0));
// index document so snapshot actually does something
indexDocument();
// start snapshot
request = new Request("PUT", "/_snapshot/repo/snapshot");
request.addParameter("wait_for_completion", "false");
request.setJsonEntity("{\"indices\": \"" + index + "\"}");
assertOK(client().performRequest(request));
// add policy and expect it to trigger delete immediately (while snapshot in progress)
updatePolicy(index, policy);
// assert that the index froze
assertBusy(() -> {
Map<String, Object> settings = getOnlyIndexSettings(index);
assertThat(getStepKeyForIndex(index), equalTo(TerminalPolicyStep.KEY));
assertThat(settings.get(IndexMetaData.INDEX_BLOCKS_WRITE_SETTING.getKey()), equalTo("true"));
assertThat(settings.get(IndexSettings.INDEX_SEARCH_THROTTLED.getKey()), equalTo("true"));
assertThat(settings.get(FrozenEngine.INDEX_FROZEN.getKey()), equalTo("true"));
});
// assert that snapshot is still in progress and clean up
assertThat(getSnapshotState("snapshot"), equalTo("IN_PROGRESS"));
assertOK(client().performRequest(new Request("DELETE", "/_snapshot/repo/snapshot")));
ResponseException e = expectThrows(ResponseException.class,
() -> client().performRequest(new Request("GET", "/_snapshot/repo/snapshot")));
assertThat(e.getResponse().getStatusLine().getStatusCode(), equalTo(404));
}

public void testSetPriority() throws Exception {
createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0).put(IndexMetaData.INDEX_PRIORITY_SETTING.getKey(), 100));
Expand Down Expand Up @@ -763,4 +896,15 @@ private void indexDocument() throws IOException {
Response response = client().performRequest(indexRequest);
logger.info(response.getStatusLine());
}

private String getSnapshotState(String snapshot) throws IOException {
Response response = client().performRequest(new Request("GET", "/_snapshot/repo/" + snapshot));
Map<String, Object> responseMap;
try (InputStream is = response.getEntity().getContent()) {
responseMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), is, true);
}
Map<String, Object> snapResponse = ((List<Map<String, Object>>) responseMap.get("snapshots")).get(0);
assertThat(snapResponse.get("snapshot"), equalTo(snapshot));
return (String) snapResponse.get("state");
}
}