Skip to content

Commit

Permalink
simplify installTokenMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ywelsch committed May 22, 2018
1 parent e1437e8 commit 87ad80f
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1376,14 +1376,15 @@ private void initialize(ClusterService clusterService) {
});
}

private final AtomicBoolean installTokenMetadataCheck = new AtomicBoolean(false);
// to prevent too many cluster state update tasks to be queued for doing the same update
private final AtomicBoolean installTokenMetadataInProgress = new AtomicBoolean(false);

private void installTokenMetadata(MetaData metaData) {
if (metaData.custom(TokenMetaData.TYPE) == null) {
if (installTokenMetadataCheck.compareAndSet(false, true)) {
if (installTokenMetadataInProgress.compareAndSet(false, true)) {
clusterService.submitStateUpdateTask("install-token-metadata", new ClusterStateUpdateTask(Priority.URGENT) {
@Override
public ClusterState execute(ClusterState currentState) throws Exception {
public ClusterState execute(ClusterState currentState) {
XPackPlugin.checkReadyForXPackCustomMetadata(currentState);

if (currentState.custom(TokenMetaData.TYPE) == null) {
Expand All @@ -1395,13 +1396,16 @@ public ClusterState execute(ClusterState currentState) throws Exception {

@Override
public void onFailure(String source, Exception e) {
installTokenMetadataCheck.set(false);
installTokenMetadataInProgress.set(false);
logger.error("unable to install token metadata", e);
}

@Override
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
installTokenMetadataInProgress.set(false);
}
});
}
} else {
installTokenMetadataCheck.set(false);
}
}

Expand Down

0 comments on commit 87ad80f

Please sign in to comment.