protect access with sync

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1292093 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2012-02-22 00:41:15 +00:00
parent 2a13b648fa
commit 075b60307e

View File

@ -494,9 +494,9 @@ public class Overseer implements NodeStateChangeListener, ShardLeaderListener {
try { try {
List<String> liveNodes = zkClient.getChildren( List<String> liveNodes = zkClient.getChildren(
ZkStateReader.LIVE_NODES_ZKNODE, this, true); ZkStateReader.LIVE_NODES_ZKNODE, this, true);
Set<String> liveNodesSet = new HashSet<String>(); synchronized (nodeStateWatches) {
liveNodesSet.addAll(liveNodes); processLiveNodesChanged(nodeStateWatches.keySet(), liveNodes);
processLiveNodesChanged(nodeStateWatches.keySet(), liveNodes); }
} catch (KeeperException e) { } catch (KeeperException e) {
if (e.code() == KeeperException.Code.SESSIONEXPIRED if (e.code() == KeeperException.Code.SESSIONEXPIRED
|| e.code() == KeeperException.Code.CONNECTIONLOSS) { || e.code() == KeeperException.Code.CONNECTIONLOSS) {
@ -528,7 +528,9 @@ public class Overseer implements NodeStateChangeListener, ShardLeaderListener {
Set<String> downNodes = complement(oldLiveNodes, liveNodes); Set<String> downNodes = complement(oldLiveNodes, liveNodes);
for(String node: downNodes) { for(String node: downNodes) {
NodeStateWatcher watcher = nodeStateWatches.remove(node); synchronized (nodeStateWatches) {
NodeStateWatcher watcher = nodeStateWatches.remove(node);
}
log.debug("Removed NodeStateWatcher for node:" + node); log.debug("Removed NodeStateWatcher for node:" + node);
} }
} }