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