Skip to content

Commit 5fc2e7e

Browse files
committed
Specific test case for followup priority setting
We cannot set the priority in all InternalTestClusters because the deprecation warning makes some tests unhappy. This commit adds a specific test instead.
1 parent cf9953f commit 5fc2e7e

File tree

2 files changed

+126
-5
lines changed

2 files changed

+126
-5
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.elasticsearch.cluster.action.shard;
20+
21+
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
22+
import org.elasticsearch.cluster.ClusterState;
23+
import org.elasticsearch.cluster.ClusterStateUpdateTask;
24+
import org.elasticsearch.cluster.health.ClusterHealthStatus;
25+
import org.elasticsearch.cluster.service.ClusterService;
26+
import org.elasticsearch.common.Priority;
27+
import org.elasticsearch.common.settings.Settings;
28+
import org.elasticsearch.plugins.Plugin;
29+
import org.elasticsearch.test.ESIntegTestCase;
30+
import org.elasticsearch.test.transport.MockTransportService;
31+
32+
import java.util.Collection;
33+
import java.util.Collections;
34+
import java.util.concurrent.atomic.AtomicBoolean;
35+
36+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
37+
import static org.hamcrest.Matchers.equalTo;
38+
39+
public class ShardStateActionIT extends ESIntegTestCase {
40+
41+
@Override
42+
protected Settings nodeSettings(int nodeOrdinal) {
43+
final Settings.Builder builder = Settings.builder().put(super.nodeSettings(nodeOrdinal));
44+
if (randomBoolean()) {
45+
builder.put(ShardStateAction.FOLLOW_UP_REROUTE_PRIORITY_SETTING.getKey(), randomPriority());
46+
}
47+
return builder.build();
48+
}
49+
50+
@Override
51+
protected Collection<Class<? extends Plugin>> nodePlugins() {
52+
return Collections.singletonList(MockTransportService.TestPlugin.class);
53+
}
54+
55+
public void testFollowupRerouteAlwaysOccursEventually() {
56+
// Shows that no matter how cluster.routing.allocation.shard_state.reroute.priority is set, a follow-up reroute eventually occurs.
57+
// Can be removed when this setting is removed, as we copiously test the default case.
58+
59+
internalCluster().ensureAtLeastNumDataNodes(2);
60+
61+
if (randomBoolean()) {
62+
assertAcked(client().admin().cluster().prepareUpdateSettings().setPersistentSettings(Settings.builder()
63+
.put(ShardStateAction.FOLLOW_UP_REROUTE_PRIORITY_SETTING.getKey(), randomPriority())));
64+
}
65+
66+
createIndex("test");
67+
final ClusterHealthResponse clusterHealthResponse
68+
= client().admin().cluster().prepareHealth().setWaitForNoInitializingShards(true).setWaitForEvents(Priority.LANGUID).get();
69+
assertFalse(clusterHealthResponse.isTimedOut());
70+
assertThat(clusterHealthResponse.getStatus(), equalTo(ClusterHealthStatus.GREEN));
71+
72+
assertAcked(client().admin().cluster().prepareUpdateSettings().setPersistentSettings(Settings.builder()
73+
.putNull(ShardStateAction.FOLLOW_UP_REROUTE_PRIORITY_SETTING.getKey())));
74+
}
75+
76+
public void testFollowupRerouteCanBeSetToHigherPriority() {
77+
// Shows that in a cluster under unbearable pressure we can still assign replicas (for now at least) by setting
78+
// cluster.routing.allocation.shard_state.reroute.priority to a higher priority. Can be removed when this setting is removed, as
79+
// we should at that point be confident that the default priority is appropriate for all clusters.
80+
81+
internalCluster().ensureAtLeastNumDataNodes(2);
82+
83+
assertAcked(client().admin().cluster().prepareUpdateSettings().setPersistentSettings(Settings.builder()
84+
.put(ShardStateAction.FOLLOW_UP_REROUTE_PRIORITY_SETTING.getKey(), "urgent")));
85+
86+
// ensure that the master always has a HIGH priority pending task
87+
final AtomicBoolean stopSpammingMaster = new AtomicBoolean();
88+
final ClusterService masterClusterService = internalCluster().getInstance(ClusterService.class, internalCluster().getMasterName());
89+
masterClusterService.submitStateUpdateTask("spam",
90+
new ClusterStateUpdateTask(Priority.HIGH) {
91+
@Override
92+
public ClusterState execute(ClusterState currentState) {
93+
return currentState;
94+
}
95+
96+
@Override
97+
public void onFailure(String source, Exception e) {
98+
throw new AssertionError(source, e);
99+
}
100+
101+
@Override
102+
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
103+
if (stopSpammingMaster.get() == false) {
104+
masterClusterService.submitStateUpdateTask("spam", this);
105+
}
106+
}
107+
});
108+
109+
// even with the master under such pressure, all shards of the index can be assigned; in particular, after the primaries have
110+
// started there's a follow-up reroute at a higher priority than the spam
111+
createIndex("test");
112+
assertFalse(client().admin().cluster().prepareHealth().setWaitForGreenStatus().get().isTimedOut());
113+
114+
stopSpammingMaster.set(true);
115+
assertFalse(client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).get().isTimedOut());
116+
117+
assertAcked(client().admin().cluster().prepareUpdateSettings().setPersistentSettings(Settings.builder()
118+
.putNull(ShardStateAction.FOLLOW_UP_REROUTE_PRIORITY_SETTING.getKey())));
119+
}
120+
121+
private String randomPriority() {
122+
return randomFrom("immediate", "urgent", "high", "normal", "low");
123+
// not "languid", because we use that to wait for no pending tasks
124+
}
125+
126+
}

test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,11 +501,6 @@ private static Settings getRandomNodeSettings(long seed) {
501501
timeValueMillis(RandomNumbers.randomIntBetween(random, 750, 10000000)).getStringRep());
502502
}
503503

504-
if (rarely()) {
505-
builder.put(ShardStateAction.FOLLOW_UP_REROUTE_PRIORITY_SETTING.getKey(),
506-
randomFrom("immediate", "urgent", "high", "normal", "low"));
507-
}
508-
509504
return builder.build();
510505
}
511506

0 commit comments

Comments
 (0)