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
This commit is contained in:
parent
2290865559
commit
f2a6c88f83
|
@ -17,9 +17,12 @@ The allocation awareness settings can be configured in
|
|||
`elasticsearch.yml` and updated dynamically with the
|
||||
<<cluster-update-settings,cluster-update-settings>> 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 <<search-adaptive-replica,adaptive replica selection>>
|
||||
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="$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
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -42,6 +42,8 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.elasticsearch.common.Booleans.parseBoolean;
|
||||
|
||||
public class OperationRouting {
|
||||
|
||||
public static final Setting<Boolean> USE_ADAPTIVE_REPLICA_SELECTION_SETTING =
|
||||
|
@ -52,10 +54,17 @@ public class OperationRouting {
|
|||
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 +72,10 @@ public class OperationRouting {
|
|||
this.useAdaptiveReplicaSelection = useAdaptiveReplicaSelection;
|
||||
}
|
||||
|
||||
List<String> getAwarenessAttributes() {
|
||||
return awarenessAttributes;
|
||||
}
|
||||
|
||||
private void setAwarenessAttributes(List<String> awarenessAttributes) {
|
||||
this.awarenessAttributes = awarenessAttributes;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue