Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docs/reference/modules/cluster/allocation_awareness.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
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 =
Expand All @@ -52,17 +54,28 @@ 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);
}

void setUseAdaptiveReplicaSelection(boolean useAdaptiveReplicaSelection) {
this.useAdaptiveReplicaSelection = useAdaptiveReplicaSelection;
}

List<String> getAwarenessAttributes() {
return awarenessAttributes;
}

private void setAwarenessAttributes(List<String> awarenessAttributes) {
this.awarenessAttributes = awarenessAttributes;
}
Expand Down