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 65de23bf461..0f98254b26d 100644 --- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java +++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java @@ -102,8 +102,43 @@ public final class ZkController { public final static String COLLECTION_PARAM_PREFIX="collection."; public final static String CONFIGNAME_PROP="configName"; - - private final Map electionContexts = Collections.synchronizedMap(new HashMap()); + static class ContextKey { + + private String collection; + private String coreNodeName; + + public ContextKey(String collection, String coreNodeName) { + this.collection = collection; + this.coreNodeName = coreNodeName; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((collection == null) ? 0 : collection.hashCode()); + result = prime * result + + ((coreNodeName == null) ? 0 : coreNodeName.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) return true; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; + ContextKey other = (ContextKey) obj; + if (collection == null) { + if (other.collection != null) return false; + } else if (!collection.equals(other.collection)) return false; + if (coreNodeName == null) { + if (other.coreNodeName != null) return false; + } else if (!coreNodeName.equals(other.coreNodeName)) return false; + return true; + } + } + private final Map electionContexts = Collections.synchronizedMap(new HashMap()); private SolrZkClient zkClient; private ZkCmdExecutor cmdExecutor; @@ -930,7 +965,7 @@ public final class ZkController { collection, coreNodeName, ourProps, this, cc); leaderElector.setup(context); - electionContexts.put(coreNodeName, context); + electionContexts.put(new ContextKey(collection, coreNodeName), context); leaderElector.joinElection(context, false); } @@ -1030,13 +1065,14 @@ public final class ZkController { public void unregister(String coreName, CoreDescriptor cd) throws InterruptedException, KeeperException { final String coreNodeName = cd.getCloudDescriptor().getCoreNodeName(); - ElectionContext context = electionContexts.remove(coreNodeName); - - assert context != null : coreNodeName; + final String collection = cd.getCloudDescriptor().getCollectionName(); + assert collection != null; + ElectionContext context = electionContexts.remove(new ContextKey(collection, coreNodeName)); if (context != null) { context.cancelElection(); } + CloudDescriptor cloudDescriptor = cd.getCloudDescriptor(); ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION,