mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-24 17:09:48 +00:00
Fix FullClusterRestartIT#testSnapshotRestore (#38795)
This test failed on 7.1 when running full cluster restart tests against pre-7.0 clusters (e.g. 6.6 clusters). The fixes the expected type in the templates after the cluster restart.
This commit is contained in:
parent
339a15bb09
commit
9f6c77fad4
@ -62,7 +62,6 @@ import static java.util.Collections.singletonMap;
|
||||
import static org.elasticsearch.cluster.routing.UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING;
|
||||
import static org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider.SETTING_ALLOCATION_MAX_RETRY;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
@ -214,7 +213,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
|
||||
logger.debug("--> creating [{}] replicas for index [{}]", numReplicas, index);
|
||||
Request setNumberOfReplicas = new Request("PUT", "/" + index + "/_settings");
|
||||
setNumberOfReplicas.setJsonEntity("{ \"index\": { \"number_of_replicas\" : " + numReplicas + " }}");
|
||||
Response response = client().performRequest(setNumberOfReplicas);
|
||||
client().performRequest(setNumberOfReplicas);
|
||||
|
||||
ensureGreenLongWait(index);
|
||||
|
||||
@ -836,10 +835,10 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
|
||||
* old and new versions. All of the snapshots include an index, a template,
|
||||
* and some routing configuration.
|
||||
*/
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/38603")
|
||||
public void testSnapshotRestore() throws IOException {
|
||||
int count;
|
||||
if (isRunningAgainstOldCluster() && getOldClusterVersion().major < 8) {
|
||||
Version oldClusterVersion = getOldClusterVersion();
|
||||
if (isRunningAgainstOldCluster() && oldClusterVersion.major < 8) {
|
||||
// Create the index
|
||||
count = between(200, 300);
|
||||
indexRandomDocuments(count, true, true, i -> jsonBuilder().startObject().field("field", "value").endObject());
|
||||
@ -859,7 +858,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
|
||||
// Stick a routing attribute into to cluster settings so we can see it after the restore
|
||||
Request addRoutingSettings = new Request("PUT", "/_cluster/settings");
|
||||
addRoutingSettings.setJsonEntity(
|
||||
"{\"persistent\": {\"cluster.routing.allocation.exclude.test_attr\": \"" + getOldClusterVersion() + "\"}}");
|
||||
"{\"persistent\": {\"cluster.routing.allocation.exclude.test_attr\": \"" + oldClusterVersion + "\"}}");
|
||||
client().performRequest(addRoutingSettings);
|
||||
|
||||
// Stick a template into the cluster so we can see it after the restore
|
||||
@ -890,7 +889,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
|
||||
templateBuilder.startObject("alias2"); {
|
||||
templateBuilder.startObject("filter"); {
|
||||
templateBuilder.startObject("term"); {
|
||||
templateBuilder.field("version", isRunningAgainstOldCluster() ? getOldClusterVersion() : Version.CURRENT);
|
||||
templateBuilder.field("version", isRunningAgainstOldCluster() ? oldClusterVersion : Version.CURRENT);
|
||||
}
|
||||
templateBuilder.endObject();
|
||||
}
|
||||
@ -901,12 +900,6 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
|
||||
templateBuilder.endObject().endObject();
|
||||
Request createTemplateRequest = new Request("PUT", "/_template/test_template");
|
||||
createTemplateRequest.setJsonEntity(Strings.toString(templateBuilder));
|
||||
|
||||
// In 7.0, type names are no longer expected by default in put index template requests.
|
||||
// We therefore use the deprecated typed APIs when running against the current version, but testing with a pre-7 version
|
||||
if (isRunningAgainstOldCluster() == false && getOldClusterVersion().major < 7) {
|
||||
createTemplateRequest.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true");
|
||||
}
|
||||
createTemplateRequest.setOptions(allowTypesRemovalWarnings());
|
||||
|
||||
client().performRequest(createTemplateRequest);
|
||||
@ -932,7 +925,7 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
|
||||
createSnapshot.setJsonEntity("{\"indices\": \"" + index + "\"}");
|
||||
client().performRequest(createSnapshot);
|
||||
|
||||
checkSnapshot("old_snap", count, getOldClusterVersion());
|
||||
checkSnapshot("old_snap", count, oldClusterVersion);
|
||||
if (false == isRunningAgainstOldCluster()) {
|
||||
checkSnapshot("new_snap", count, Version.CURRENT);
|
||||
}
|
||||
@ -1029,7 +1022,8 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkSnapshot(final String snapshotName, final int count, final Version tookOnVersion) throws IOException {
|
||||
private void checkSnapshot(final String snapshotName, final int count, final Version tookOnVersion)
|
||||
throws IOException {
|
||||
// Check the snapshot metadata, especially the version
|
||||
Request listSnapshotRequest = new Request("GET", "/_snapshot/repo/" + snapshotName);
|
||||
Map<String, Object> listSnapshotResponse = entityAsMap(client().performRequest(listSnapshotRequest));
|
||||
@ -1112,12 +1106,6 @@ public class FullClusterRestartIT extends AbstractFullClusterRestartTestCase {
|
||||
|
||||
// Check that the template was restored successfully
|
||||
Request getTemplateRequest = new Request("GET", "/_template/test_template");
|
||||
|
||||
// In 7.0, type names are no longer returned by default in get index template requests.
|
||||
// We therefore use the deprecated typed APIs when running against the current version.
|
||||
if (isRunningAgainstAncientCluster() == false) {
|
||||
getTemplateRequest.addParameter(INCLUDE_TYPE_NAME_PARAMETER, "true");
|
||||
}
|
||||
getTemplateRequest.setOptions(allowTypesRemovalWarnings());
|
||||
|
||||
Map<String, Object> getTemplateResponse = entityAsMap(client().performRequest(getTemplateRequest));
|
||||
|
@ -63,7 +63,11 @@ public abstract class AbstractFullClusterRestartTestCase extends ESRestTestCase
|
||||
|
||||
private final Version oldClusterVersion = Version.fromString(System.getProperty("tests.old_cluster_version"));
|
||||
|
||||
public final boolean isRunningAgainstAncientCluster() {
|
||||
/**
|
||||
* @return true if test is running against an old cluster before that last major, in this case
|
||||
* when System.getProperty("tests.is_old_cluster" == true) and oldClusterVersion is before {@link Version#V_7_0_0}
|
||||
*/
|
||||
protected final boolean isRunningAgainstAncientCluster() {
|
||||
return isRunningAgainstOldCluster() && oldClusterVersion.before(Version.V_7_0_0);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user