lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r1524287 - in /lucene/dev/branches/branch_4x: ./ solr/ solr/core/ solr/core/src/java/org/apache/solr/cloud/ZkController.java
Date Wed, 18 Sep 2013 03:40:32 GMT
Author: markrmiller
Date: Wed Sep 18 03:40:31 2013
New Revision: 1524287

URL: http://svn.apache.org/r1524287
Log:
SOLR-5243: Killing a shard in one collection can result in leader election in a different
collection if they share the same coreNodeName.

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/solr/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/   (props changed)
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/cloud/ZkController.java

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/cloud/ZkController.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/cloud/ZkController.java?rev=1524287&r1=1524286&r2=1524287&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/cloud/ZkController.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/cloud/ZkController.java
Wed Sep 18 03:40:31 2013
@@ -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<String, ElectionContext> electionContexts = Collections.synchronizedMap(new
HashMap<String, ElectionContext>());
+  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<ContextKey, ElectionContext> electionContexts = Collections.synchronizedMap(new
HashMap<ContextKey, ElectionContext>());
   
   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,



Mime
View raw message