Skip to content

Commit dc5c31d

Browse files
authored
Add a deprecation warning regarding allocation awareness in search request (#48351)
This is a follow up of #43453 where we added a system property to disallow allocation awareness in search requests. Since search requests will no longer check the allocation awareness attributes for routing in the next major version, this change adds a deprecation warning on any setup that uses these attributes. Relates #43453
1 parent c6b733f commit dc5c31d

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

qa/evil-tests/src/test/java/org/elasticsearch/cluster/routing/EvilSystemPropertyTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public void testDisableSearchAllocationAwareness() {
3434
.build();
3535
OperationRouting routing = new OperationRouting(indexSettings,
3636
new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS));
37+
assertWarnings(OperationRouting.IGNORE_AWARENESS_ATTRIBUTES_DEPRECATION_MESSAGE);
3738
assertThat(routing.getAwarenessAttributes().size(), equalTo(1));
3839
assertThat(routing.getAwarenessAttributes().get(0), equalTo("test"));
3940
System.setProperty("es.search.ignore_awareness_attributes", "true");

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919

2020
package org.elasticsearch.cluster.routing;
2121

22+
import org.apache.logging.log4j.LogManager;
2223
import org.elasticsearch.Version;
2324
import org.elasticsearch.cluster.ClusterState;
2425
import org.elasticsearch.cluster.metadata.IndexMetaData;
2526
import org.elasticsearch.cluster.node.DiscoveryNodes;
2627
import org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider;
2728
import org.elasticsearch.common.Nullable;
2829
import org.elasticsearch.common.Strings;
30+
import org.elasticsearch.common.logging.DeprecationLogger;
2931
import org.elasticsearch.common.settings.ClusterSettings;
3032
import org.elasticsearch.common.settings.Setting;
3133
import org.elasticsearch.common.settings.Settings;
@@ -50,14 +52,23 @@ public class OperationRouting {
5052
Setting.boolSetting("cluster.routing.use_adaptive_replica_selection", true,
5153
Setting.Property.Dynamic, Setting.Property.NodeScope);
5254

55+
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(OperationRouting.class));
56+
private static final String IGNORE_AWARENESS_ATTRIBUTES_PROPERTY = "es.search.ignore_awareness_attributes";
57+
static final String IGNORE_AWARENESS_ATTRIBUTES_DEPRECATION_MESSAGE =
58+
"searches will not be routed based on awareness attributes starting in version 8.0.0; " +
59+
"to opt into this behaviour now please set the system property [" + IGNORE_AWARENESS_ATTRIBUTES_PROPERTY + "] to [true]";
60+
5361
private List<String> awarenessAttributes;
5462
private boolean useAdaptiveReplicaSelection;
5563

5664
public OperationRouting(Settings settings, ClusterSettings clusterSettings) {
5765
// whether to ignore awareness attributes when routing requests
58-
boolean ignoreAwarenessAttr = parseBoolean(System.getProperty("es.search.ignore_awareness_attributes"), false);
66+
boolean ignoreAwarenessAttr = parseBoolean(System.getProperty(IGNORE_AWARENESS_ATTRIBUTES_PROPERTY), false);
5967
if (ignoreAwarenessAttr == false) {
6068
awarenessAttributes = AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING.get(settings);
69+
if (awarenessAttributes.isEmpty() == false) {
70+
deprecationLogger.deprecated(IGNORE_AWARENESS_ATTRIBUTES_DEPRECATION_MESSAGE);
71+
}
6172
clusterSettings.addSettingsUpdateConsumer(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING,
6273
this::setAwarenessAttributes);
6374
} else {
@@ -77,7 +88,13 @@ List<String> getAwarenessAttributes() {
7788
}
7889

7990
private void setAwarenessAttributes(List<String> awarenessAttributes) {
80-
this.awarenessAttributes = awarenessAttributes;
91+
boolean ignoreAwarenessAttr = parseBoolean(System.getProperty(IGNORE_AWARENESS_ATTRIBUTES_PROPERTY), false);
92+
if (ignoreAwarenessAttr == false) {
93+
if (this.awarenessAttributes.isEmpty() && awarenessAttributes.isEmpty() == false) {
94+
deprecationLogger.deprecated(IGNORE_AWARENESS_ATTRIBUTES_DEPRECATION_MESSAGE);
95+
}
96+
this.awarenessAttributes = awarenessAttributes;
97+
}
8198
}
8299

83100
public ShardIterator indexShards(ClusterState clusterState, String index, String id, @Nullable String routing) {

server/src/test/java/org/elasticsearch/cluster/routing/OperationRoutingTests.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.action.support.replication.ClusterStateCreationUtils;
2323
import org.elasticsearch.cluster.ClusterState;
2424
import org.elasticsearch.cluster.metadata.IndexMetaData;
25+
import org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider;
2526
import org.elasticsearch.cluster.service.ClusterService;
2627
import org.elasticsearch.common.settings.ClusterSettings;
2728
import org.elasticsearch.common.settings.Settings;
@@ -44,14 +45,14 @@
4445
import java.util.Set;
4546
import java.util.TreeMap;
4647

48+
import static org.elasticsearch.cluster.routing.OperationRouting.IGNORE_AWARENESS_ATTRIBUTES_DEPRECATION_MESSAGE;
4749
import static org.hamcrest.CoreMatchers.containsString;
4850
import static org.hamcrest.Matchers.containsInAnyOrder;
4951
import static org.hamcrest.Matchers.equalTo;
5052
import static org.hamcrest.Matchers.greaterThan;
5153
import static org.hamcrest.object.HasToString.hasToString;
5254

53-
public class OperationRoutingTests extends ESTestCase{
54-
55+
public class OperationRoutingTests extends ESTestCase {
5556
public void testGenerateShardId() {
5657
int[][] possibleValues = new int[][] {
5758
{8,4,2}, {20, 10, 2}, {36, 12, 3}, {15,5,1}
@@ -606,4 +607,14 @@ public void testAdaptiveReplicaSelection() throws Exception {
606607
terminate(threadPool);
607608
}
608609

610+
public void testAllocationAwarenessDeprecation() {
611+
OperationRouting routing = new OperationRouting(
612+
Settings.builder()
613+
.put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING.getKey(), "foo")
614+
.build(),
615+
new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)
616+
);
617+
assertWarnings(IGNORE_AWARENESS_ATTRIBUTES_DEPRECATION_MESSAGE);
618+
}
619+
609620
}

0 commit comments

Comments
 (0)