74
74
import static org .elasticsearch .cluster .routing .allocation .ShardsAvailabilityHealthIndicatorService .ACTION_MIGRATE_TIERS_AWAY_FROM_INCLUDE_DATA_LOOKUP ;
75
75
import static org .elasticsearch .cluster .routing .allocation .ShardsAvailabilityHealthIndicatorService .ACTION_MIGRATE_TIERS_AWAY_FROM_REQUIRE_DATA_LOOKUP ;
76
76
import static org .elasticsearch .cluster .routing .allocation .ShardsAvailabilityHealthIndicatorService .ACTION_RESTORE_FROM_SNAPSHOT ;
77
+ import static org .elasticsearch .cluster .routing .allocation .ShardsAvailabilityHealthIndicatorService .DIAGNOSIS_WAIT_FOR_INITIALIZATION ;
77
78
import static org .elasticsearch .cluster .routing .allocation .ShardsAvailabilityHealthIndicatorService .DIAGNOSIS_WAIT_FOR_OR_FIX_DELAYED_SHARDS ;
78
79
import static org .elasticsearch .cluster .routing .allocation .ShardsAvailabilityHealthIndicatorService .NAME ;
79
80
import static org .elasticsearch .cluster .routing .allocation .ShardsAvailabilityHealthIndicatorServiceTests .ShardState .AVAILABLE ;
81
+ import static org .elasticsearch .cluster .routing .allocation .ShardsAvailabilityHealthIndicatorServiceTests .ShardState .CREATING ;
80
82
import static org .elasticsearch .cluster .routing .allocation .ShardsAvailabilityHealthIndicatorServiceTests .ShardState .INITIALIZING ;
81
83
import static org .elasticsearch .cluster .routing .allocation .ShardsAvailabilityHealthIndicatorServiceTests .ShardState .RESTARTING ;
82
84
import static org .elasticsearch .cluster .routing .allocation .ShardsAvailabilityHealthIndicatorServiceTests .ShardState .UNAVAILABLE ;
@@ -121,6 +123,98 @@ public void testShouldBeGreenWhenAllPrimariesAndReplicasAreStarted() {
121
123
);
122
124
}
123
125
126
+ public void testShouldBeYellowWhenReplicaIsInitializing () {
127
+ var clusterState = createClusterStateWith (
128
+ List .of (
129
+ index ("replicated-index" , new ShardAllocation (randomNodeId (), AVAILABLE ), new ShardAllocation (randomNodeId (), INITIALIZING ))
130
+ ),
131
+ List .of ()
132
+ );
133
+ var service = createAllocationHealthIndicatorService (clusterState );
134
+
135
+ assertThat (
136
+ service .calculate (true , HealthInfo .EMPTY_HEALTH_INFO ),
137
+ equalTo (
138
+ createExpectedResult (
139
+ YELLOW ,
140
+ "This cluster has 1 initializing replica shard." ,
141
+ Map .of ("started_primaries" , 1 , "initializing_replicas" , 1 ),
142
+ List .of (
143
+ new HealthIndicatorImpact (
144
+ NAME ,
145
+ ShardsAvailabilityHealthIndicatorService .REPLICA_UNASSIGNED_IMPACT_ID ,
146
+ 2 ,
147
+ "Searches might be slower than usual. Fewer redundant copies of the data exist on 1 index [replicated-index]." ,
148
+ List .of (ImpactArea .SEARCH )
149
+ )
150
+ ),
151
+ List .of (
152
+ new Diagnosis (
153
+ DIAGNOSIS_WAIT_FOR_INITIALIZATION ,
154
+ List .of (new Diagnosis .Resource (INDEX , List .of ("replicated-index" )))
155
+ )
156
+ )
157
+ )
158
+ )
159
+ );
160
+ }
161
+
162
+ public void testShouldBeRedWhenPrimaryIsInitializing () {
163
+ var clusterState = createClusterStateWith (
164
+ List .of (index ("unreplicated-index" , new ShardAllocation (randomNodeId (), INITIALIZING ))),
165
+ List .of ()
166
+ );
167
+ var service = createAllocationHealthIndicatorService (clusterState );
168
+
169
+ HealthIndicatorResult calculate = service .calculate (true , HealthInfo .EMPTY_HEALTH_INFO );
170
+ assertThat (
171
+ calculate ,
172
+ equalTo (
173
+ createExpectedResult (
174
+ RED ,
175
+ "This cluster has 1 initializing primary shard." ,
176
+ Map .of ("initializing_primaries" , 1 ),
177
+ List .of (
178
+ new HealthIndicatorImpact (
179
+ NAME ,
180
+ ShardsAvailabilityHealthIndicatorService .PRIMARY_UNASSIGNED_IMPACT_ID ,
181
+ 1 ,
182
+ "Cannot add data to 1 index [unreplicated-index]. Searches might return incomplete results." ,
183
+ List .of (ImpactArea .INGEST , ImpactArea .SEARCH )
184
+ )
185
+ ),
186
+ List .of (
187
+ new Diagnosis (
188
+ DIAGNOSIS_WAIT_FOR_INITIALIZATION ,
189
+ List .of (new Diagnosis .Resource (INDEX , List .of ("unreplicated-index" )))
190
+ )
191
+ )
192
+ )
193
+ )
194
+ );
195
+ }
196
+
197
+ public void testShouldBeGreenWhenAllPrimariesAreCreating () {
198
+ var clusterState = createClusterStateWith (
199
+ List .of (index ("unreplicated-index" , new ShardAllocation (randomNodeId (), CREATING ))),
200
+ List .of ()
201
+ );
202
+ var service = createAllocationHealthIndicatorService (clusterState );
203
+
204
+ assertThat (
205
+ service .calculate (true , HealthInfo .EMPTY_HEALTH_INFO ),
206
+ equalTo (
207
+ createExpectedResult (
208
+ GREEN ,
209
+ "This cluster has 1 creating primary shard." ,
210
+ Map .of ("creating_primaries" , 1 ),
211
+ Collections .emptyList (),
212
+ Collections .emptyList ()
213
+ )
214
+ )
215
+ );
216
+ }
217
+
124
218
public void testShouldBeYellowWhenThereAreUnassignedReplicas () {
125
219
var availableReplicas = randomList (0 , 5 , () -> new ShardAllocation (randomNodeId (), AVAILABLE ));
126
220
var unavailableReplicas = randomList (1 , 5 , () -> new ShardAllocation (randomNodeId (), UNAVAILABLE ));
@@ -423,10 +517,7 @@ public void testShouldBeYellowWhenRestartingReplicasReachedAllocationDelay() {
423
517
}
424
518
425
519
public void testShouldBeGreenWhenThereAreInitializingPrimaries () {
426
- var clusterState = createClusterStateWith (
427
- List .of (index ("restarting-index" , new ShardAllocation ("node-0" , INITIALIZING ))),
428
- List .of ()
429
- );
520
+ var clusterState = createClusterStateWith (List .of (index ("restarting-index" , new ShardAllocation ("node-0" , CREATING ))), List .of ());
430
521
var service = createAllocationHealthIndicatorService (clusterState );
431
522
432
523
assertThat (
@@ -643,6 +734,37 @@ public void testDiagnoseEnableIndexAllocation() {
643
734
assertThat (actions , contains (ACTION_ENABLE_INDEX_ROUTING_ALLOCATION ));
644
735
}
645
736
737
+ public void testNodeAllocationResultWithNullDecision () {
738
+ // Index definition, 1 primary no replicas, allocation is not allowed
739
+ IndexMetadata indexMetadata = IndexMetadata .builder ("red-index" )
740
+ .settings (
741
+ Settings .builder ()
742
+ .put (IndexMetadata .SETTING_VERSION_CREATED , Version .CURRENT )
743
+ .put (EnableAllocationDecider .INDEX_ROUTING_ALLOCATION_ENABLE_SETTING .getKey (), "none" )
744
+ .build ()
745
+ )
746
+ .numberOfShards (1 )
747
+ .numberOfReplicas (0 )
748
+ .build ();
749
+
750
+ var service = createAllocationHealthIndicatorService ();
751
+
752
+ // Get the list of user actions that are generated for this unassigned index shard
753
+ List <Diagnosis .Definition > actions = service .checkIsAllocationDisabled (
754
+ indexMetadata ,
755
+ List .of (
756
+ new NodeAllocationResult (
757
+ // Shard allocation is disabled on index
758
+ new DiscoveryNode (randomNodeId (), buildNewFakeTransportAddress (), Version .CURRENT ),
759
+ new NodeAllocationResult .ShardStoreInfo (10 ),
760
+ null
761
+ )
762
+ )
763
+ );
764
+
765
+ assertThat (actions , hasSize (0 ));
766
+ }
767
+
646
768
public void testDiagnoseEnableClusterAllocation () {
647
769
// Index definition, 1 primary no replicas
648
770
IndexMetadata indexMetadata = IndexMetadata .builder ("red-index" )
@@ -1336,10 +1458,13 @@ private static ShardRouting createShardRouting(ShardId shardId, boolean primary,
1336
1458
getSource (primary , allocation .state ),
1337
1459
new UnassignedInfo (UnassignedInfo .Reason .INDEX_CREATED , null )
1338
1460
);
1339
- if (allocation .state == INITIALIZING ) {
1461
+ if (allocation .state == CREATING ) {
1340
1462
return routing ;
1341
1463
}
1342
1464
routing = routing .initialize (allocation .nodeId , null , 0 );
1465
+ if (allocation .state == INITIALIZING ) {
1466
+ return routing ;
1467
+ }
1343
1468
routing = routing .moveToStarted (ShardRouting .UNAVAILABLE_EXPECTED_SHARD_SIZE );
1344
1469
if (allocation .state == AVAILABLE ) {
1345
1470
return routing ;
@@ -1369,7 +1494,7 @@ private static ShardRouting createShardRouting(ShardId shardId, boolean primary,
1369
1494
1370
1495
private static RecoverySource getSource (boolean primary , ShardState state ) {
1371
1496
if (primary ) {
1372
- return state == INITIALIZING
1497
+ return state == CREATING
1373
1498
? RecoverySource .EmptyStoreRecoverySource .INSTANCE
1374
1499
: RecoverySource .ExistingStoreRecoverySource .INSTANCE ;
1375
1500
} else {
@@ -1379,9 +1504,10 @@ private static RecoverySource getSource(boolean primary, ShardState state) {
1379
1504
1380
1505
public enum ShardState {
1381
1506
UNAVAILABLE ,
1382
- INITIALIZING ,
1507
+ CREATING ,
1383
1508
AVAILABLE ,
1384
- RESTARTING
1509
+ RESTARTING ,
1510
+ INITIALIZING ,
1385
1511
}
1386
1512
1387
1513
private record ShardAllocation (String nodeId , ShardState state , Long unassignedTimeNanos , @ Nullable UnassignedInfo unassignedInfo ) {
0 commit comments