22
22
import java .util .HashMap ;
23
23
import java .util .List ;
24
24
import java .util .Map ;
25
+ import java .util .function .Function ;
25
26
26
27
import com .carrotsearch .hppc .ObjectIntHashMap ;
27
28
import org .elasticsearch .cluster .metadata .IndexMetaData ;
34
35
import org .elasticsearch .common .settings .Setting .Property ;
35
36
import org .elasticsearch .common .settings .Settings ;
36
37
38
+ import static java .util .Collections .emptyList ;
39
+
37
40
/**
38
41
* This {@link AllocationDecider} controls shard allocation based on
39
42
* {@code awareness} key-value pairs defined in the node configuration.
@@ -78,13 +81,13 @@ public class AwarenessAllocationDecider extends AllocationDecider {
78
81
79
82
public static final String NAME = "awareness" ;
80
83
81
- public static final Setting <String [] > CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING =
82
- new Setting <> ("cluster.routing.allocation.awareness.attributes" , "" , s -> Strings . tokenizeToStringArray ( s , "," ), Property .Dynamic ,
84
+ public static final Setting <List < String > > CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING =
85
+ Setting . listSetting ("cluster.routing.allocation.awareness.attributes" , emptyList (), Function . identity ( ), Property .Dynamic ,
83
86
Property .NodeScope );
84
87
public static final Setting <Settings > CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING =
85
88
Setting .groupSetting ("cluster.routing.allocation.awareness.force." , Property .Dynamic , Property .NodeScope );
86
89
87
- private volatile String [] awarenessAttributes ;
90
+ private volatile List < String > awarenessAttributes ;
88
91
89
92
private volatile Map <String , List <String >> forcedAwarenessAttributes ;
90
93
@@ -109,7 +112,7 @@ private void setForcedAwarenessAttributes(Settings forceSettings) {
109
112
this .forcedAwarenessAttributes = forcedAwarenessAttributes ;
110
113
}
111
114
112
- private void setAwarenessAttributes (String [] awarenessAttributes ) {
115
+ private void setAwarenessAttributes (List < String > awarenessAttributes ) {
113
116
this .awarenessAttributes = awarenessAttributes ;
114
117
}
115
118
@@ -124,7 +127,7 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl
124
127
}
125
128
126
129
private Decision underCapacity (ShardRouting shardRouting , RoutingNode node , RoutingAllocation allocation , boolean moveToNode ) {
127
- if (awarenessAttributes .length == 0 ) {
130
+ if (awarenessAttributes .isEmpty () ) {
128
131
return allocation .decision (Decision .YES , NAME ,
129
132
"allocation awareness is not enabled, set cluster setting [%s] to enable it" ,
130
133
CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING .getKey ());
@@ -138,7 +141,7 @@ private Decision underCapacity(ShardRouting shardRouting, RoutingNode node, Rout
138
141
return allocation .decision (Decision .NO , NAME ,
139
142
"node does not contain the awareness attribute [%s]; required attributes cluster setting [%s=%s]" ,
140
143
awarenessAttribute , CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING .getKey (),
141
- allocation .debugDecision () ? Strings .arrayToCommaDelimitedString (awarenessAttributes ) : null );
144
+ allocation .debugDecision () ? Strings .collectionToCommaDelimitedString (awarenessAttributes ) : null );
142
145
}
143
146
144
147
// build attr_value -> nodes map
0 commit comments