@@ -86,6 +86,8 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
86
86
// a map of mappings type we have seen per index
87
87
private final ConcurrentMap <Tuple <String , String >, Boolean > seenMappings = ConcurrentCollections .newConcurrentMap ();
88
88
89
+ private final Object mutex = new Object ();
90
+
89
91
@ Inject public IndicesClusterStateService (Settings settings , IndicesService indicesService , ClusterService clusterService ,
90
92
ThreadPool threadPool , RecoveryTarget recoveryTarget , ShardStateAction shardStateAction ,
91
93
NodeIndexCreatedAction nodeIndexCreatedAction , NodeIndexDeletedAction nodeIndexDeletedAction ,
@@ -116,12 +118,14 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent<Indic
116
118
if (!indicesService .changesAllowed ())
117
119
return ;
118
120
119
- applyNewIndices (event );
120
- applyMappings (event );
121
- applyNewOrUpdatedShards (event );
122
- applyDeletedIndices (event );
123
- applyDeletedShards (event );
124
- applyCleanedIndices (event );
121
+ synchronized (mutex ) {
122
+ applyNewIndices (event );
123
+ applyMappings (event );
124
+ applyNewOrUpdatedShards (event );
125
+ applyDeletedIndices (event );
126
+ applyDeletedShards (event );
127
+ applyCleanedIndices (event );
128
+ }
125
129
}
126
130
127
131
private void applyCleanedIndices (final ClusterChangedEvent event ) {
@@ -426,13 +430,15 @@ private PeerRecoveryListener(StartRecoveryRequest request, ShardRouting shardRou
426
430
if (!removeShard ) {
427
431
return ;
428
432
}
429
- if (indexService .hasShard (shardRouting .shardId ().id ())) {
430
- try {
431
- indexService .removeShard (shardRouting .shardId ().id ());
432
- } catch (IndexShardMissingException e ) {
433
- // the node got closed on us, ignore it
434
- } catch (Exception e1 ) {
435
- logger .warn ("[{}][{}] failed to delete shard after ignore recovery" , e1 , indexService .index ().name (), shardRouting .shardId ().id ());
433
+ synchronized (mutex ) {
434
+ if (indexService .hasShard (shardRouting .shardId ().id ())) {
435
+ try {
436
+ indexService .removeShard (shardRouting .shardId ().id ());
437
+ } catch (IndexShardMissingException e ) {
438
+ // the node got closed on us, ignore it
439
+ } catch (Exception e1 ) {
440
+ logger .warn ("[{}][{}] failed to delete shard after ignore recovery" , e1 , indexService .index ().name (), shardRouting .shardId ().id ());
441
+ }
436
442
}
437
443
}
438
444
}
@@ -444,20 +450,22 @@ private PeerRecoveryListener(StartRecoveryRequest request, ShardRouting shardRou
444
450
445
451
private void handleRecoveryFailure (IndexService indexService , ShardRouting shardRouting , boolean sendShardFailure , Throwable failure ) {
446
452
logger .warn ("[{}][{}] failed to start shard" , failure , indexService .index ().name (), shardRouting .shardId ().id ());
447
- if (indexService .hasShard (shardRouting .shardId ().id ())) {
448
- try {
449
- indexService .cleanShard (shardRouting .shardId ().id ());
450
- } catch (IndexShardMissingException e ) {
451
- // the node got closed on us, ignore it
452
- } catch (Exception e1 ) {
453
- logger .warn ("[{}][{}] failed to delete shard after failed startup" , e1 , indexService .index ().name (), shardRouting .shardId ().id ());
453
+ synchronized (mutex ) {
454
+ if (indexService .hasShard (shardRouting .shardId ().id ())) {
455
+ try {
456
+ indexService .cleanShard (shardRouting .shardId ().id ());
457
+ } catch (IndexShardMissingException e ) {
458
+ // the node got closed on us, ignore it
459
+ } catch (Exception e1 ) {
460
+ logger .warn ("[{}][{}] failed to delete shard after failed startup" , e1 , indexService .index ().name (), shardRouting .shardId ().id ());
461
+ }
454
462
}
455
- }
456
- if ( sendShardFailure ) {
457
- try {
458
- shardStateAction . shardFailed ( shardRouting , "Failed to start shard, message [" + detailedMessage ( failure ) + "]" );
459
- } catch ( Exception e1 ) {
460
- logger . warn ( "[{}][{}] failed to mark shard as failed after a failed start" , e1 , indexService . index (). name (), shardRouting . id ());
463
+ if ( sendShardFailure ) {
464
+ try {
465
+ shardStateAction . shardFailed ( shardRouting , "Failed to start shard, message [" + detailedMessage ( failure ) + "]" );
466
+ } catch ( Exception e1 ) {
467
+ logger . warn ( "[{}][{}] failed to mark shard as failed after a failed start" , e1 , indexService . index (). name (), shardRouting . id ());
468
+ }
461
469
}
462
470
}
463
471
}
0 commit comments