Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-4568: The lastPublished state check before becoming a leader is not working correctly.

Mark Robert Millerb6719269fae5
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 03d9aeaf3a5..7d17f68569f 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -103,6 +103,9 @@ Bug Fixes
* SOLR-4577: The collections API should return responses (success or failure)
for each node it attempts to work with. (Mark Miller)
+* SOLR-4568: The lastPublished state check before becoming a leader is not
+ working correctly. (Mark Miller)
+
Other Changes
----------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java b/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java
index 98a882b11ea..248faa6ffae 100644
--- a/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java
+++ b/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java
@@ -17,6 +17,7 @@ package org.apache.solr.cloud;
* limitations under the License.
*/
+import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.SolrParams;
public class CloudDescriptor {
@@ -28,7 +29,7 @@ public class CloudDescriptor {
private String nodeName = null;
volatile boolean isLeader = false;
- volatile String lastPublished;
+ volatile String lastPublished = ZkStateReader.ACTIVE;
public String getLastPublished() {
return lastPublished;
diff --git a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java
index 5d5efaa56bf..2d98873dcb1 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java
@@ -132,6 +132,9 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {
syncStrategy.close();
}
+ /*
+ * weAreReplacement: has someone else been the leader already?
+ */
@Override
void runLeaderProcess(boolean weAreReplacement) throws KeeperException,
InterruptedException, IOException {
@@ -302,7 +305,7 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {
found = zkClient.getChildren(shardsElectZkPath, null, true).size();
} catch (KeeperException e) {
SolrException.log(log,
- "Errir checking for the number of election participants", e);
+ "Error checking for the number of election participants", e);
}
// on startup and after connection timeout, wait for all known shards
@@ -321,6 +324,11 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {
log.info("Was waiting for replicas to come up, but they are taking too long - assuming they won't come back till later");
return;
}
+ } else {
+ log.warn("Shard not found: " + shardId + " for collection " + collection);
+
+ return;
+
}
Thread.sleep(500);
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 389eb3a3e47..28e369cf1c0 100644
--- a/solr/core/src/java/org/apache/solr/cloud/ZkController.java
+++ b/solr/core/src/java/org/apache/solr/cloud/ZkController.java
@@ -999,7 +999,9 @@ public final class ZkController {
: null,
ZkStateReader.CORE_NODE_NAME_PROP, coreNodeName != null ? coreNodeName
: null);
- cd.getCloudDescriptor().lastPublished = state;
+ if (updateLastState) {
+ cd.getCloudDescriptor().lastPublished = state;
+ }
overseerJobQueue.offer(ZkStateReader.toJSON(m));
}
@@ -1198,11 +1200,10 @@ public final class ZkController {
}
private String doGetShardIdProcess(String coreName, CoreDescriptor descriptor) {
- final String shardZkNodeName = getCoreNodeName(descriptor);
+ final String coreNodeName = getCoreNodeName(descriptor);
int retryCount = 320;
while (retryCount-- > 0) {
- final String shardId = zkStateReader.getClusterState().getShardId(
- shardZkNodeName);
+ final String shardId = zkStateReader.getClusterState().getShardId(coreNodeName);
if (shardId != null) {
return shardId;
}
@@ -1214,7 +1215,7 @@ public final class ZkController {
}
throw new SolrException(ErrorCode.SERVER_ERROR,
- "Could not get shard_id for core: " + coreName + " coreNodeName:" + shardZkNodeName);
+ "Could not get shard_id for core: " + coreName + " coreNodeName:" + coreNodeName);
}
public static void uploadToZK(SolrZkClient zkClient, File dir, String zkPath) throws IOException, KeeperException, InterruptedException {
@@ -1272,9 +1273,15 @@ public final class ZkController {
public void preRegister(CoreDescriptor cd) throws KeeperException, InterruptedException {
// before becoming available, make sure we are not live and active
// this also gets us our assigned shard id if it was not specified
- publish(cd, ZkStateReader.DOWN);
- String shardZkNodeName = getCoreNodeName(cd);
- if (cd.getCloudDescriptor().getShardId() == null && needsToBeAssignedShardId(cd, zkStateReader.getClusterState(), shardZkNodeName)) {
+ publish(cd, ZkStateReader.DOWN, false);
+ String coreNodeName = getCoreNodeName(cd);
+
+ // make sure the node name is set on the descriptor
+ if (cd.getCloudDescriptor().getCoreNodeName() == null) {
+ cd.getCloudDescriptor().setCoreNodeName(coreNodeName);
+ }
+
+ if (cd.getCloudDescriptor().getShardId() == null && needsToBeAssignedShardId(cd, zkStateReader.getClusterState(), coreNodeName)) {
String shardId;
shardId = doGetShardIdProcess(cd.getName(), cd);
cd.getCloudDescriptor().setShardId(shardId);