19
19
20
20
package org .elasticsearch .cluster .routing ;
21
21
22
+ import org .apache .logging .log4j .LogManager ;
22
23
import org .elasticsearch .Version ;
23
24
import org .elasticsearch .cluster .ClusterState ;
24
25
import org .elasticsearch .cluster .metadata .IndexMetaData ;
25
26
import org .elasticsearch .cluster .node .DiscoveryNodes ;
26
27
import org .elasticsearch .cluster .routing .allocation .decider .AwarenessAllocationDecider ;
27
28
import org .elasticsearch .common .Nullable ;
28
29
import org .elasticsearch .common .Strings ;
30
+ import org .elasticsearch .common .logging .DeprecationLogger ;
29
31
import org .elasticsearch .common .settings .ClusterSettings ;
30
32
import org .elasticsearch .common .settings .Setting ;
31
33
import org .elasticsearch .common .settings .Settings ;
@@ -50,14 +52,23 @@ public class OperationRouting {
50
52
Setting .boolSetting ("cluster.routing.use_adaptive_replica_selection" , true ,
51
53
Setting .Property .Dynamic , Setting .Property .NodeScope );
52
54
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
+
53
61
private List <String > awarenessAttributes ;
54
62
private boolean useAdaptiveReplicaSelection ;
55
63
56
64
public OperationRouting (Settings settings , ClusterSettings clusterSettings ) {
57
65
// 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 );
59
67
if (ignoreAwarenessAttr == false ) {
60
68
awarenessAttributes = AwarenessAllocationDecider .CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING .get (settings );
69
+ if (awarenessAttributes .isEmpty () == false ) {
70
+ deprecationLogger .deprecated (IGNORE_AWARENESS_ATTRIBUTES_DEPRECATION_MESSAGE );
71
+ }
61
72
clusterSettings .addSettingsUpdateConsumer (AwarenessAllocationDecider .CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING ,
62
73
this ::setAwarenessAttributes );
63
74
} else {
@@ -77,7 +88,13 @@ List<String> getAwarenessAttributes() {
77
88
}
78
89
79
90
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
+ }
81
98
}
82
99
83
100
public ShardIterator indexShards (ClusterState clusterState , String index , String id , @ Nullable String routing ) {
0 commit comments