Skip to content

Commit

Permalink
fix minor potential of race by only checking state once in conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
jakelandis committed Aug 14, 2019
1 parent 0f7174d commit eab50a0
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
Expand All @@ -42,6 +43,7 @@ public class WatcherLifeCycleService implements ClusterStateListener {
private final AtomicReference<List<ShardRouting>> previousShardRoutings = new AtomicReference<>(Collections.emptyList());
private volatile boolean shutDown = false; // indicates that the node has been shutdown and we should never start watcher after this.
private volatile WatcherService watcherService;
private final EnumSet<WatcherState> stopStates = EnumSet.of(WatcherState.STOPPED, WatcherState.STOPPING);

WatcherLifeCycleService(ClusterService clusterService, WatcherService watcherService) {
this.watcherService = watcherService;
Expand Down Expand Up @@ -93,8 +95,7 @@ public void clusterChanged(ClusterChangedEvent event) {
}

boolean isWatcherStoppedManually = isWatcherStoppedManually(event.state());
boolean isStoppedOrStopping = this.state.get() == WatcherState.STOPPED ||
this.state.get() == WatcherState.STOPPING;
boolean isStoppedOrStopping = stopStates.contains(this.state.get());
// if this is not a data node, we need to start it ourselves possibly
if (event.state().nodes().getLocalNode().isDataNode() == false &&
isWatcherStoppedManually == false && isStoppedOrStopping) {
Expand Down

0 comments on commit eab50a0

Please sign in to comment.