|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the "Elastic License |
| 4 | + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side |
| 5 | + * Public License v 1"; you may not use this file except in compliance with, at |
| 6 | + * your election, the "Elastic License 2.0", the "GNU Affero General Public |
| 7 | + * License v3.0 only", or the "Server Side Public License, v 1". |
| 8 | + */ |
| 9 | + |
| 10 | +package org.elasticsearch.upgrades; |
| 11 | + |
| 12 | +import io.netty.handler.codec.http.HttpMethod; |
| 13 | + |
| 14 | +import com.carrotsearch.randomizedtesting.annotations.Name; |
| 15 | + |
| 16 | +import org.elasticsearch.client.Request; |
| 17 | +import org.elasticsearch.client.RequestOptions; |
| 18 | +import org.elasticsearch.client.WarningsHandler; |
| 19 | +import org.elasticsearch.core.UpdateForV10; |
| 20 | +import org.elasticsearch.test.cluster.ElasticsearchCluster; |
| 21 | +import org.elasticsearch.test.cluster.FeatureFlag; |
| 22 | +import org.elasticsearch.test.cluster.local.LocalClusterConfigProvider; |
| 23 | +import org.elasticsearch.test.cluster.local.distribution.DistributionType; |
| 24 | +import org.elasticsearch.test.rest.ObjectPath; |
| 25 | +import org.junit.ClassRule; |
| 26 | +import org.junit.rules.RuleChain; |
| 27 | +import org.junit.rules.TemporaryFolder; |
| 28 | +import org.junit.rules.TestRule; |
| 29 | + |
| 30 | +import static org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator.THRESHOLD_SETTING; |
| 31 | + |
| 32 | +/** |
| 33 | + * Tests to run before and after a full cluster restart. This is run twice, |
| 34 | + * one with {@code tests.is_old_cluster} set to {@code true} against a cluster |
| 35 | + * of an older version. The cluster is shutdown and a cluster of the new |
| 36 | + * version is started with the same data directories and then this is rerun |
| 37 | + * with {@code tests.is_old_cluster} set to {@code false}. |
| 38 | + */ |
| 39 | +public class FullClusterRestartArchivedSettingsIT extends ParameterizedFullClusterRestartTestCase { |
| 40 | + |
| 41 | + private static TemporaryFolder repoDirectory = new TemporaryFolder(); |
| 42 | + |
| 43 | + protected static LocalClusterConfigProvider clusterConfig = c -> {}; |
| 44 | + |
| 45 | + private static ElasticsearchCluster cluster = ElasticsearchCluster.local() |
| 46 | + .distribution(DistributionType.DEFAULT) |
| 47 | + .version(getOldClusterTestVersion()) |
| 48 | + .nodes(2) |
| 49 | + .setting("path.repo", () -> repoDirectory.getRoot().getPath()) |
| 50 | + .setting("xpack.security.enabled", "false") |
| 51 | + // some tests rely on the translog not being flushed |
| 52 | + .setting("indices.memory.shard_inactive_time", "60m") |
| 53 | + .apply(() -> clusterConfig) |
| 54 | + .feature(FeatureFlag.TIME_SERIES_MODE) |
| 55 | + .feature(FeatureFlag.FAILURE_STORE_ENABLED) |
| 56 | + .build(); |
| 57 | + |
| 58 | + @ClassRule |
| 59 | + public static TestRule ruleChain = RuleChain.outerRule(repoDirectory).around(cluster); |
| 60 | + |
| 61 | + public FullClusterRestartArchivedSettingsIT(@Name("cluster") FullClusterRestartUpgradeStatus upgradeStatus) { |
| 62 | + super(upgradeStatus); |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + protected ElasticsearchCluster getUpgradeCluster() { |
| 67 | + return cluster; |
| 68 | + } |
| 69 | + |
| 70 | + @UpdateForV10(owner = UpdateForV10.Owner.DISTRIBUTED_COORDINATION) // this test is just about v8->v9 upgrades, remove it in v10 |
| 71 | + public void testBalancedShardsAllocatorThreshold() throws Exception { |
| 72 | + assumeTrue("test only applies for v8->v9 upgrades", getOldClusterTestVersion().getMajor() == 8); |
| 73 | + |
| 74 | + final var chosenValue = randomFrom("0", "0.1", "0.5", "0.999"); |
| 75 | + |
| 76 | + if (isRunningAgainstOldCluster()) { |
| 77 | + final var request = newXContentRequest( |
| 78 | + HttpMethod.PUT, |
| 79 | + "/_cluster/settings", |
| 80 | + (builder, params) -> builder.startObject("persistent").field(THRESHOLD_SETTING.getKey(), chosenValue).endObject() |
| 81 | + ); |
| 82 | + request.setOptions(RequestOptions.DEFAULT.toBuilder().setWarningsHandler(WarningsHandler.PERMISSIVE)); |
| 83 | + assertOK(client().performRequest(request)); |
| 84 | + } |
| 85 | + |
| 86 | + final var clusterSettingsResponse = ObjectPath.createFromResponse( |
| 87 | + client().performRequest(new Request("GET", "/_cluster/settings")) |
| 88 | + ); |
| 89 | + |
| 90 | + final var settingsPath = "persistent." + THRESHOLD_SETTING.getKey(); |
| 91 | + final var settingValue = clusterSettingsResponse.evaluate(settingsPath); |
| 92 | + |
| 93 | + if (isRunningAgainstOldCluster()) { |
| 94 | + assertEquals(chosenValue, settingValue); |
| 95 | + } else { |
| 96 | + assertNull(settingValue); |
| 97 | + assertNotNull(clusterSettingsResponse.<String>evaluate("persistent.archived." + THRESHOLD_SETTING.getKey())); |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments