@@ -124,23 +124,38 @@ public Decision canAllocate(ShardRouting shardRouting, RoutingAllocation allocat
124
124
enable = this .enableAllocation ;
125
125
usedIndexSetting = false ;
126
126
}
127
- return switch (enable ) {
128
- case ALL -> allocation .decision (Decision .YES , NAME , "all allocations are allowed" );
129
- case NONE -> allocation .decision (Decision .NO , NAME , "no allocations are allowed due to %s" , setting (enable , usedIndexSetting ));
130
- case NEW_PRIMARIES -> (shardRouting .primary ()
131
- && shardRouting .active () == false
132
- && shardRouting .recoverySource ().getType () != RecoverySource .Type .EXISTING_STORE )
133
- ? allocation .decision (Decision .YES , NAME , "new primary allocations are allowed" )
134
- : allocation .decision (
127
+ switch (enable ) {
128
+ case ALL :
129
+ return allocation .decision (Decision .YES , NAME , "all allocations are allowed" );
130
+ case NONE :
131
+ return allocation .decision (Decision .NO , NAME , "no allocations are allowed due to %s" , setting (enable , usedIndexSetting ));
132
+ case NEW_PRIMARIES :
133
+ if (shardRouting .primary ()
134
+ && shardRouting .active () == false
135
+ && shardRouting .recoverySource ().getType () != RecoverySource .Type .EXISTING_STORE ) {
136
+ return allocation .decision (Decision .YES , NAME , "new primary allocations are allowed" );
137
+ } else {
138
+ return allocation .decision (
135
139
Decision .NO ,
136
140
NAME ,
137
141
"non-new primary allocations are forbidden due to %s" ,
138
142
setting (enable , usedIndexSetting )
139
143
);
140
- case PRIMARIES -> shardRouting .primary ()
141
- ? allocation .decision (Decision .YES , NAME , "primary allocations are allowed" )
142
- : allocation .decision (Decision .NO , NAME , "replica allocations are forbidden due to %s" , setting (enable , usedIndexSetting ));
143
- };
144
+ }
145
+ case PRIMARIES :
146
+ if (shardRouting .primary ()) {
147
+ return allocation .decision (Decision .YES , NAME , "primary allocations are allowed" );
148
+ } else {
149
+ return allocation .decision (
150
+ Decision .NO ,
151
+ NAME ,
152
+ "replica allocations are forbidden due to %s" ,
153
+ setting (enable , usedIndexSetting )
154
+ );
155
+ }
156
+ default :
157
+ throw new IllegalStateException ("Unknown allocation option" );
158
+ }
144
159
}
145
160
146
161
@ Override
@@ -178,16 +193,36 @@ public Decision canRebalance(ShardRouting shardRouting, RoutingAllocation alloca
178
193
enable = this .enableRebalance ;
179
194
usedIndexSetting = false ;
180
195
}
181
- return switch (enable ) {
182
- case ALL -> allocation .decision (Decision .YES , NAME , "all rebalancing is allowed" );
183
- case NONE -> allocation .decision (Decision .NO , NAME , "no rebalancing is allowed due to %s" , setting (enable , usedIndexSetting ));
184
- case PRIMARIES -> shardRouting .primary ()
185
- ? allocation .decision (Decision .YES , NAME , "primary rebalancing is allowed" )
186
- : allocation .decision (Decision .NO , NAME , "replica rebalancing is forbidden due to %s" , setting (enable , usedIndexSetting ));
187
- case REPLICAS -> shardRouting .primary ()
188
- ? allocation .decision (Decision .NO , NAME , "primary rebalancing is forbidden due to %s" , setting (enable , usedIndexSetting ))
189
- : allocation .decision (Decision .YES , NAME , "replica rebalancing is allowed" );
190
- };
196
+ switch (enable ) {
197
+ case ALL :
198
+ return allocation .decision (Decision .YES , NAME , "all rebalancing is allowed" );
199
+ case NONE :
200
+ return allocation .decision (Decision .NO , NAME , "no rebalancing is allowed due to %s" , setting (enable , usedIndexSetting ));
201
+ case PRIMARIES :
202
+ if (shardRouting .primary ()) {
203
+ return allocation .decision (Decision .YES , NAME , "primary rebalancing is allowed" );
204
+ } else {
205
+ return allocation .decision (
206
+ Decision .NO ,
207
+ NAME ,
208
+ "replica rebalancing is forbidden due to %s" ,
209
+ setting (enable , usedIndexSetting )
210
+ );
211
+ }
212
+ case REPLICAS :
213
+ if (shardRouting .primary () == false ) {
214
+ return allocation .decision (Decision .YES , NAME , "replica rebalancing is allowed" );
215
+ } else {
216
+ return allocation .decision (
217
+ Decision .NO ,
218
+ NAME ,
219
+ "primary rebalancing is forbidden due to %s" ,
220
+ setting (enable , usedIndexSetting )
221
+ );
222
+ }
223
+ default :
224
+ throw new IllegalStateException ("Unknown rebalance option" );
225
+ }
191
226
}
192
227
193
228
private static String setting (Allocation allocation , boolean usedIndexSetting ) {
0 commit comments