Skip to content

Commit f2a6c88

Browse files
authored
Add a system property to ignore awareness attributes (#46375)
This is a follow up of #19191 for 7.x. This change adds a system property called "es.routing.search_ignore_awareness_attributes" that when set to true will effectively ignore allocation awareness attributes when routing search and get requests. This is now the default in 8.x so this commit adds a way to opt-in to this new behavior in a minor version of 7.x. Relates #45735
1 parent 2290865 commit f2a6c88

File tree

3 files changed

+71
-6
lines changed

3 files changed

+71
-6
lines changed

docs/reference/modules/cluster/allocation_awareness.asciidoc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ The allocation awareness settings can be configured in
1717
`elasticsearch.yml` and updated dynamically with the
1818
<<cluster-update-settings,cluster-update-settings>> API.
1919

20-
{es} prefers using shards in the same location (with the same
21-
awareness attribute values) to process search or GET requests. Using local
22-
shards is usually faster than crossing rack or zone boundaries.
20+
By default {es} uses <<search-adaptive-replica,adaptive replica selection>>
21+
to route search or GET requests. However, with the presence of allocation awareness
22+
attributes {es} will prefer using shards in the same location (with the same
23+
awareness attribute values) to process these requests. This behavior can be
24+
disabled by specifying `export ES_JAVA_OPTS="$ES_JAVA_OPTS -Des.search.ignore_awareness_attributes=true"`
25+
system property on every node that is part of the cluster.
2326

2427
NOTE: The number of attribute values determines how many shard copies are
2528
allocated in each location. If the number of nodes in each location is
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.routing;
20+
21+
import org.elasticsearch.common.SuppressForbidden;
22+
import org.elasticsearch.common.settings.ClusterSettings;
23+
import org.elasticsearch.common.settings.Settings;
24+
import org.elasticsearch.test.ESTestCase;
25+
26+
import static org.hamcrest.Matchers.equalTo;
27+
28+
public class EvilSystemPropertyTests extends ESTestCase {
29+
30+
@SuppressForbidden(reason = "manipulates system properties for testing")
31+
public void testDisableSearchAllocationAwareness() {
32+
Settings indexSettings = Settings.builder()
33+
.put("cluster.routing.allocation.awareness.attributes", "test")
34+
.build();
35+
OperationRouting routing = new OperationRouting(indexSettings,
36+
new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
37+
assertThat(routing.getAwarenessAttributes().size(), equalTo(1));
38+
assertThat(routing.getAwarenessAttributes().get(0), equalTo("test"));
39+
System.setProperty("es.search.ignore_awareness_attributes", "true");
40+
try {
41+
routing = new OperationRouting(indexSettings,
42+
new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
43+
assertTrue(routing.getAwarenessAttributes().isEmpty());
44+
} finally {
45+
System.clearProperty("es.search.ignore_awareness_attributes");
46+
}
47+
48+
}
49+
}

server/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import java.util.Set;
4343
import java.util.stream.Collectors;
4444

45+
import static org.elasticsearch.common.Booleans.parseBoolean;
46+
4547
public class OperationRouting {
4648

4749
public static final Setting<Boolean> USE_ADAPTIVE_REPLICA_SELECTION_SETTING =
@@ -52,17 +54,28 @@ public class OperationRouting {
5254
private boolean useAdaptiveReplicaSelection;
5355

5456
public OperationRouting(Settings settings, ClusterSettings clusterSettings) {
55-
this.awarenessAttributes = AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING.get(settings);
57+
// whether to ignore awareness attributes when routing requests
58+
boolean ignoreAwarenessAttr = parseBoolean(System.getProperty("es.search.ignore_awareness_attributes"), false);
59+
if (ignoreAwarenessAttr == false) {
60+
awarenessAttributes = AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING.get(settings);
61+
clusterSettings.addSettingsUpdateConsumer(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING,
62+
this::setAwarenessAttributes);
63+
} else {
64+
awarenessAttributes = Collections.emptyList();
65+
}
66+
5667
this.useAdaptiveReplicaSelection = USE_ADAPTIVE_REPLICA_SELECTION_SETTING.get(settings);
57-
clusterSettings.addSettingsUpdateConsumer(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING,
58-
this::setAwarenessAttributes);
5968
clusterSettings.addSettingsUpdateConsumer(USE_ADAPTIVE_REPLICA_SELECTION_SETTING, this::setUseAdaptiveReplicaSelection);
6069
}
6170

6271
void setUseAdaptiveReplicaSelection(boolean useAdaptiveReplicaSelection) {
6372
this.useAdaptiveReplicaSelection = useAdaptiveReplicaSelection;
6473
}
6574

75+
List<String> getAwarenessAttributes() {
76+
return awarenessAttributes;
77+
}
78+
6679
private void setAwarenessAttributes(List<String> awarenessAttributes) {
6780
this.awarenessAttributes = awarenessAttributes;
6881
}

0 commit comments

Comments
 (0)