From 20dd2504576c70399f559ba5203460a6d6bd1a64 Mon Sep 17 00:00:00 2001 From: Yonik Seeley Date: Sat, 25 Feb 2012 02:00:32 +0000 Subject: [PATCH] SOLR-3080: key coreStates by core name, create coreStates up front for consistent sync git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1293516 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/solr/cloud/ZkController.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/cloud/ZkController.java b/solr/core/src/java/org/apache/solr/cloud/ZkController.java index 609cc951ef0..17119878193 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java @@ -87,7 +87,7 @@ public final class ZkController { public final static String COLLECTION_PARAM_PREFIX="collection."; public final static String CONFIGNAME_PROP="configName"; - private Map coreStates = null; + private Map coreStates = new HashMap(); // key is the local core name private long coreStatesVersion; // bumped by 1 each time we serialize coreStates... sync on coreStates private long coreStatesPublishedVersion; // last version published to ZK... sync on coreStatesPublishLock private Object coreStatesPublishLock = new Object(); // only publish one at a time @@ -382,14 +382,14 @@ public final class ZkController { final byte[] data = zkClient.getData(path, null, null, true); - coreStates = new HashMap(); - if (data != null) { - CoreState[] states = CoreState.load(data); - List stateList = Arrays.asList(states); - for(CoreState coreState: stateList) { + CoreState[] states = CoreState.load(data); + synchronized (coreStates) { + coreStates.clear(); // TODO: should we do this? + for(CoreState coreState: states) { coreStates.put(coreState.getCoreName(), coreState); } + } } log.debug("after sync: " + coreStates); } @@ -758,11 +758,11 @@ public final class ZkController { */ public void unregister(String coreName, CloudDescriptor cloudDesc) throws InterruptedException, KeeperException { - final String zkNodeName = getNodeName() + "_" + coreName; synchronized (coreStates) { - coreStates.remove(zkNodeName); + coreStates.remove(coreName); } publishState(); + final String zkNodeName = getNodeName() + "_" + coreName; ElectionContext context = electionContexts.remove(zkNodeName); if (context != null) { context.cancelElection(); @@ -946,7 +946,7 @@ public final class ZkController { cloudDesc.getCollectionName(), props, numShards); synchronized (coreStates) { - coreStates.put(shardZkNodeName, coreState); + coreStates.put(coreName, coreState); } publishState();