|
21 | 21 |
|
22 | 22 | import org.apache.logging.log4j.Logger; |
23 | 23 | import org.elasticsearch.cluster.ClusterState; |
| 24 | +import org.elasticsearch.cluster.health.ClusterHealthStatus; |
24 | 25 | import org.elasticsearch.cluster.routing.IndexRoutingTable; |
25 | 26 | import org.elasticsearch.cluster.routing.IndexShardRoutingTable; |
26 | 27 | import org.elasticsearch.cluster.routing.ShardRouting; |
| 28 | +import org.elasticsearch.cluster.routing.ShardRoutingState; |
27 | 29 | import org.elasticsearch.cluster.routing.allocation.decider.FilterAllocationDecider; |
28 | 30 | import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocationDecider; |
| 31 | +import org.elasticsearch.common.Strings; |
29 | 32 | import org.elasticsearch.common.logging.Loggers; |
30 | 33 | import org.elasticsearch.common.settings.Setting; |
31 | 34 | import org.elasticsearch.common.settings.Settings; |
|
34 | 37 | import org.elasticsearch.test.ESIntegTestCase.ClusterScope; |
35 | 38 | import org.elasticsearch.test.ESIntegTestCase.Scope; |
36 | 39 |
|
| 40 | +import java.util.HashSet; |
37 | 41 | import java.util.List; |
| 42 | +import java.util.Set; |
38 | 43 |
|
39 | 44 | import static org.hamcrest.Matchers.equalTo; |
40 | 45 |
|
@@ -156,5 +161,58 @@ public void testInvalidIPFilterClusterSettings() { |
156 | 161 | .execute().actionGet()); |
157 | 162 | assertEquals("invalid IP address [192.168.1.1.] for [" + filterSetting.getKey() + ipKey + "]", e.getMessage()); |
158 | 163 | } |
| 164 | + |
| 165 | + public void testTransientSettingsStillApplied() throws Exception { |
| 166 | + List<String> nodes = internalCluster().startNodes(6); |
| 167 | + Set<String> excludeNodes = new HashSet<>(nodes.subList(0, 3)); |
| 168 | + Set<String> includeNodes = new HashSet<>(nodes.subList(3, 6)); |
| 169 | + logger.info("--> exclude: [{}], include: [{}]", |
| 170 | + Strings.collectionToCommaDelimitedString(excludeNodes), |
| 171 | + Strings.collectionToCommaDelimitedString(includeNodes)); |
| 172 | + ensureStableCluster(6); |
| 173 | + client().admin().indices().prepareCreate("test").get(); |
| 174 | + ensureGreen("test"); |
| 175 | + |
| 176 | + Settings exclude = Settings.builder().put("cluster.routing.allocation.exclude._name", |
| 177 | + Strings.collectionToCommaDelimitedString(excludeNodes)).build(); |
| 178 | + |
| 179 | + logger.info("--> updating settings"); |
| 180 | + client().admin().cluster().prepareUpdateSettings().setTransientSettings(exclude).get(); |
| 181 | + |
| 182 | + logger.info("--> waiting for relocation"); |
| 183 | + waitForRelocation(ClusterHealthStatus.GREEN); |
| 184 | + |
| 185 | + ClusterState state = client().admin().cluster().prepareState().get().getState(); |
| 186 | + |
| 187 | + for (ShardRouting shard : state.getRoutingTable().shardsWithState(ShardRoutingState.STARTED)) { |
| 188 | + String node = state.getRoutingNodes().node(shard.currentNodeId()).node().getName(); |
| 189 | + logger.info("--> shard on {} - {}", node, shard); |
| 190 | + assertTrue("shard on " + node + " but should only be on the include node list: " + |
| 191 | + Strings.collectionToCommaDelimitedString(includeNodes), |
| 192 | + includeNodes.contains(node)); |
| 193 | + } |
| 194 | + |
| 195 | + Settings other = Settings.builder().put("cluster.info.update.interval", "45s").build(); |
| 196 | + |
| 197 | + logger.info("--> updating settings with random persistent setting"); |
| 198 | + client().admin().cluster().prepareUpdateSettings() |
| 199 | + .setPersistentSettings(other).setTransientSettings(exclude).get(); |
| 200 | + |
| 201 | + logger.info("--> waiting for relocation"); |
| 202 | + waitForRelocation(ClusterHealthStatus.GREEN); |
| 203 | + |
| 204 | + state = client().admin().cluster().prepareState().get().getState(); |
| 205 | + |
| 206 | + // The transient settings still exist in the state |
| 207 | + assertThat(state.metaData().transientSettings(), equalTo(exclude)); |
| 208 | + |
| 209 | + for (ShardRouting shard : state.getRoutingTable().shardsWithState(ShardRoutingState.STARTED)) { |
| 210 | + String node = state.getRoutingNodes().node(shard.currentNodeId()).node().getName(); |
| 211 | + logger.info("--> shard on {} - {}", node, shard); |
| 212 | + assertTrue("shard on " + node + " but should only be on the include node list: " + |
| 213 | + Strings.collectionToCommaDelimitedString(includeNodes), |
| 214 | + includeNodes.contains(node)); |
| 215 | + } |
| 216 | + } |
159 | 217 | } |
160 | 218 |
|
0 commit comments