From 232614cbf4d089752be2e85fe68443c4814d38c6 Mon Sep 17 00:00:00 2001 From: jimczi Date: Thu, 5 Sep 2019 13:23:22 +0200 Subject: [PATCH 1/3] Add a system property to ignore awareness attributes 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 --- .../cluster/allocation_awareness.asciidoc | 9 ++-- .../routing/EvilSystemPropertyTests.java | 49 +++++++++++++++++++ .../cluster/routing/OperationRouting.java | 21 ++++++-- 3 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 qa/evil-tests/src/test/java/org/elasticsearch/cluster/routing/EvilSystemPropertyTests.java diff --git a/docs/reference/modules/cluster/allocation_awareness.asciidoc b/docs/reference/modules/cluster/allocation_awareness.asciidoc index 4381d0281cc9d..dee82e558ad86 100644 --- a/docs/reference/modules/cluster/allocation_awareness.asciidoc +++ b/docs/reference/modules/cluster/allocation_awareness.asciidoc @@ -17,9 +17,12 @@ The allocation awareness settings can be configured in `elasticsearch.yml` and updated dynamically with the <> API. -{es} prefers using shards in the same location (with the same -awareness attribute values) to process search or GET requests. Using local -shards is usually faster than crossing rack or zone boundaries. +By default {es} uses <> +to route search or GET requests. However, with the presence of allocation awareness +attributes {es} will prefer using shards in the same location (with the same +awareness attribute values) to process these requests. This behavior can be +disabled by specifying `export ES_JAVA_OPTS="-Des.search.ignore_awareness_attributes=true"` +system property on every node that is part of the cluster. NOTE: The number of attribute values determines how many shard copies are allocated in each location. If the number of nodes in each location is diff --git a/qa/evil-tests/src/test/java/org/elasticsearch/cluster/routing/EvilSystemPropertyTests.java b/qa/evil-tests/src/test/java/org/elasticsearch/cluster/routing/EvilSystemPropertyTests.java new file mode 100644 index 0000000000000..5949360a8353a --- /dev/null +++ b/qa/evil-tests/src/test/java/org/elasticsearch/cluster/routing/EvilSystemPropertyTests.java @@ -0,0 +1,49 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.elasticsearch.cluster.routing; + +import org.elasticsearch.common.SuppressForbidden; +import org.elasticsearch.common.settings.ClusterSettings; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.test.ESTestCase; + +import static org.hamcrest.Matchers.equalTo; + +public class EvilSystemPropertyTests extends ESTestCase { + + @SuppressForbidden(reason = "manipulates system properties for testing") + public void testDisableSearchAllocationAwareness() { + Settings indexSettings = Settings.builder() + .put("cluster.routing.allocation.awareness.attributes", "test") + .build(); + OperationRouting routing = new OperationRouting(indexSettings, + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); + assertThat(routing.getAwarenessAttributes().size(), equalTo(1)); + assertThat(routing.getAwarenessAttributes().get(0), equalTo("test")); + System.setProperty("es.search.ignore_awareness_attributes", "true"); + try { + routing = new OperationRouting(indexSettings, + new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)); + assertTrue(routing.getAwarenessAttributes().isEmpty()); + } finally { + System.clearProperty("es.search.ignore_awareness_attributes"); + } + + } +} diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java b/server/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java index 08dc3d1d70971..3e1869a0ac2ea 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java @@ -24,6 +24,7 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider; +import org.elasticsearch.common.Booleans; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.ClusterSettings; @@ -42,20 +43,30 @@ import java.util.Set; import java.util.stream.Collectors; +import static org.elasticsearch.common.Booleans.parseBoolean; + public class OperationRouting { public static final Setting USE_ADAPTIVE_REPLICA_SELECTION_SETTING = Setting.boolSetting("cluster.routing.use_adaptive_replica_selection", true, Setting.Property.Dynamic, Setting.Property.NodeScope); + private List awarenessAttributes; private boolean useAdaptiveReplicaSelection; public OperationRouting(Settings settings, ClusterSettings clusterSettings) { - this.awarenessAttributes = AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING.get(settings); + // whether to ignore awareness attributes when routing requests + boolean ignoreAwarenessAttr = parseBoolean(System.getProperty("es.search.ignore_awareness_attributes"), false); + if (ignoreAwarenessAttr == false) { + awarenessAttributes = AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING.get(settings); + clusterSettings.addSettingsUpdateConsumer(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING, + this::setAwarenessAttributes); + } else { + awarenessAttributes = Collections.emptyList(); + } + this.useAdaptiveReplicaSelection = USE_ADAPTIVE_REPLICA_SELECTION_SETTING.get(settings); - clusterSettings.addSettingsUpdateConsumer(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING, - this::setAwarenessAttributes); clusterSettings.addSettingsUpdateConsumer(USE_ADAPTIVE_REPLICA_SELECTION_SETTING, this::setUseAdaptiveReplicaSelection); } @@ -63,6 +74,10 @@ void setUseAdaptiveReplicaSelection(boolean useAdaptiveReplicaSelection) { this.useAdaptiveReplicaSelection = useAdaptiveReplicaSelection; } + List getAwarenessAttributes() { + return awarenessAttributes; + } + private void setAwarenessAttributes(List awarenessAttributes) { this.awarenessAttributes = awarenessAttributes; } From a2d084e7d1b5fc2bdd5d5bb65b13ab2116a8a937 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Thu, 5 Sep 2019 14:48:08 +0200 Subject: [PATCH 2/3] Update docs/reference/modules/cluster/allocation_awareness.asciidoc apply review comment Co-Authored-By: Adrien Grand --- docs/reference/modules/cluster/allocation_awareness.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/modules/cluster/allocation_awareness.asciidoc b/docs/reference/modules/cluster/allocation_awareness.asciidoc index dee82e558ad86..1643a5f9917f8 100644 --- a/docs/reference/modules/cluster/allocation_awareness.asciidoc +++ b/docs/reference/modules/cluster/allocation_awareness.asciidoc @@ -21,7 +21,7 @@ By default {es} uses <> to route search or GET requests. However, with the presence of allocation awareness attributes {es} will prefer using shards in the same location (with the same awareness attribute values) to process these requests. This behavior can be -disabled by specifying `export ES_JAVA_OPTS="-Des.search.ignore_awareness_attributes=true"` +disabled by specifying `export ES_JAVA_OPTS="$ES_JAVA_OPTS -Des.search.ignore_awareness_attributes=true"` system property on every node that is part of the cluster. NOTE: The number of attribute values determines how many shard copies are From 77f6b45e91ee975d28ed647f2269a503dc2c4c3e Mon Sep 17 00:00:00 2001 From: jimczi Date: Thu, 5 Sep 2019 15:15:03 +0200 Subject: [PATCH 3/3] remove unused import --- .../org/elasticsearch/cluster/routing/OperationRouting.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java b/server/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java index 3e1869a0ac2ea..ea2c2b5881d9b 100644 --- a/server/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java +++ b/server/src/main/java/org/elasticsearch/cluster/routing/OperationRouting.java @@ -24,7 +24,6 @@ import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider; -import org.elasticsearch.common.Booleans; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.ClusterSettings; @@ -51,7 +50,6 @@ public class OperationRouting { Setting.boolSetting("cluster.routing.use_adaptive_replica_selection", true, Setting.Property.Dynamic, Setting.Property.NodeScope); - private List awarenessAttributes; private boolean useAdaptiveReplicaSelection;