fix a concurrency issue around writing hashmap to json

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1292064 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2012-02-21 22:30:33 +00:00
parent 2e2d3dac91
commit 2a13b648fa
1 changed files with 18 additions and 15 deletions

View File

@ -85,7 +85,7 @@ public final class ZkController {
public final static String COLLECTION_PARAM_PREFIX="collection.";
public final static String CONFIGNAME_PROP="configName";
private final Map<String, CoreState> coreStates = Collections.synchronizedMap(new HashMap<String, CoreState>());
private final Map<String, CoreState> coreStates = new HashMap<String, CoreState>();
private SolrZkClient zkClient;
private ZkCmdExecutor cmdExecutor;
@ -900,22 +900,25 @@ public final class ZkController {
}
CoreState coreState = new CoreState(coreName,
cloudDesc.getCollectionName(), props, numShards);
coreStates.put(shardZkNodeName, coreState);
final String nodePath = "/node_states/" + getNodeName();
try {
zkClient.setData(nodePath, ZkStateReader.toJSON(coreStates.values()),
true);
} catch (KeeperException e) {
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"could not publish node state", e);
} catch (InterruptedException e) {
// Restore the interrupted status
Thread.currentThread().interrupt();
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"could not publish node state", e);
synchronized (coreStates) {
coreStates.put(shardZkNodeName, coreState);
try {
zkClient.setData(nodePath, ZkStateReader.toJSON(coreStates.values()),
true);
} catch (KeeperException e) {
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"could not publish node state", e);
} catch (InterruptedException e) {
// Restore the interrupted status
Thread.currentThread().interrupt();
throw new ZooKeeperException(SolrException.ErrorCode.SERVER_ERROR,
"could not publish node state", e);
}
}
}
private String doGetShardIdProcess(String coreName, CloudDescriptor descriptor)