SOLR-5243: Killing a shard in one collection can result in leader election in a different collection if they share the same coreNodeName.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1524286 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2013-09-18 03:37:53 +00:00
parent 8b8c2c05f6
commit c3bee17daa
1 changed files with 42 additions and 6 deletions

View File

@ -102,8 +102,43 @@ 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";
static class ContextKey {
private final Map<String, ElectionContext> electionContexts = Collections.synchronizedMap(new HashMap<String, ElectionContext>()); 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<ContextKey, ElectionContext> electionContexts = Collections.synchronizedMap(new HashMap<ContextKey, ElectionContext>());
private SolrZkClient zkClient; private SolrZkClient zkClient;
private ZkCmdExecutor cmdExecutor; private ZkCmdExecutor cmdExecutor;
@ -930,7 +965,7 @@ public final class ZkController {
collection, coreNodeName, ourProps, this, cc); collection, coreNodeName, ourProps, this, cc);
leaderElector.setup(context); leaderElector.setup(context);
electionContexts.put(coreNodeName, context); electionContexts.put(new ContextKey(collection, coreNodeName), context);
leaderElector.joinElection(context, false); leaderElector.joinElection(context, false);
} }
@ -1030,13 +1065,14 @@ public final class ZkController {
public void unregister(String coreName, CoreDescriptor cd) public void unregister(String coreName, CoreDescriptor cd)
throws InterruptedException, KeeperException { throws InterruptedException, KeeperException {
final String coreNodeName = cd.getCloudDescriptor().getCoreNodeName(); final String coreNodeName = cd.getCloudDescriptor().getCoreNodeName();
ElectionContext context = electionContexts.remove(coreNodeName); final String collection = cd.getCloudDescriptor().getCollectionName();
assert collection != null;
assert context != null : coreNodeName; ElectionContext context = electionContexts.remove(new ContextKey(collection, coreNodeName));
if (context != null) { if (context != null) {
context.cancelElection(); context.cancelElection();
} }
CloudDescriptor cloudDescriptor = cd.getCloudDescriptor(); CloudDescriptor cloudDescriptor = cd.getCloudDescriptor();
ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION,