@@ -1376,14 +1376,15 @@ private void initialize(ClusterService clusterService) {
13761376 });
13771377 }
13781378
1379- private final AtomicBoolean installTokenMetadataCheck = new AtomicBoolean (false );
1379+ // to prevent too many cluster state update tasks to be queued for doing the same update
1380+ private final AtomicBoolean installTokenMetadataInProgress = new AtomicBoolean (false );
13801381
13811382 private void installTokenMetadata (MetaData metaData ) {
13821383 if (metaData .custom (TokenMetaData .TYPE ) == null ) {
1383- if (installTokenMetadataCheck .compareAndSet (false , true )) {
1384+ if (installTokenMetadataInProgress .compareAndSet (false , true )) {
13841385 clusterService .submitStateUpdateTask ("install-token-metadata" , new ClusterStateUpdateTask (Priority .URGENT ) {
13851386 @ Override
1386- public ClusterState execute (ClusterState currentState ) throws Exception {
1387+ public ClusterState execute (ClusterState currentState ) {
13871388 XPackPlugin .checkReadyForXPackCustomMetadata (currentState );
13881389
13891390 if (currentState .custom (TokenMetaData .TYPE ) == null ) {
@@ -1395,13 +1396,16 @@ public ClusterState execute(ClusterState currentState) throws Exception {
13951396
13961397 @ Override
13971398 public void onFailure (String source , Exception e ) {
1398- installTokenMetadataCheck .set (false );
1399+ installTokenMetadataInProgress .set (false );
13991400 logger .error ("unable to install token metadata" , e );
14001401 }
1402+
1403+ @ Override
1404+ public void clusterStateProcessed (String source , ClusterState oldState , ClusterState newState ) {
1405+ installTokenMetadataInProgress .set (false );
1406+ }
14011407 });
14021408 }
1403- } else {
1404- installTokenMetadataCheck .set (false );
14051409 }
14061410 }
14071411
0 commit comments