You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2015/11/13 15:35:27 UTC
svn commit: r1714212 - in /lucene/dev/branches/branch_5x: ./ solr/
solr/core/ solr/core/src/java/org/apache/solr/cloud/
solr/core/src/test/org/apache/solr/cloud/
Author: markrmiller
Date: Fri Nov 13 14:35:27 2015
New Revision: 1714212
URL: http://svn.apache.org/viewvc?rev=1714212&view=rev
Log:
SOLR-7989: After a new leader is elected it, it should ensure it's state is ACTIVE if it has already registered with ZK.
Modified:
lucene/dev/branches/branch_5x/ (props changed)
lucene/dev/branches/branch_5x/solr/ (props changed)
lucene/dev/branches/branch_5x/solr/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_5x/solr/core/ (props changed)
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java
lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ZkController.java
lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/ForceLeaderTest.java
Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1714212&r1=1714211&r2=1714212&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Fri Nov 13 14:35:27 2015
@@ -237,6 +237,10 @@ Bug Fixes
* SOLR-8262: Comment out /stream handler from sample solrconfig.xml's for security reasons
(Joel Bernstein)
+* SOLR-7989: After a new leader is elected it should change it's state to ACTIVE even
+ if the last published state is something else if it has already registered with ZK.
+ (Ishan Chattopadhyaya, Mark Miller via noble)
+
Optimizations
----------------------
Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java?rev=1714212&r1=1714211&r2=1714212&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/CloudDescriptor.java Fri Nov 13 14:35:27 2015
@@ -44,6 +44,10 @@ public class CloudDescriptor {
volatile String shardParent = null;
private volatile boolean isLeader = false;
+
+ // set to true once a core has registered in zk
+ // set to false on detecting a session expiration
+ private volatile boolean hasRegistered = false;
volatile Replica.State lastPublished = Replica.State.ACTIVE;
public static final String NUM_SHARDS = "numShards";
@@ -77,6 +81,14 @@ public class CloudDescriptor {
public void setLeader(boolean isLeader) {
this.isLeader = isLeader;
}
+
+ public boolean hasRegistered() {
+ return hasRegistered;
+ }
+
+ public void setHasRegistered(boolean hasRegistered) {
+ this.hasRegistered = hasRegistered;
+ }
public void setShardId(String shardId) {
this.shardId = shardId;
Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java?rev=1714212&r1=1714211&r2=1714212&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ElectionContext.java Fri Nov 13 14:35:27 2015
@@ -1,5 +1,22 @@
package org.apache.solr.cloud;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
@@ -11,6 +28,7 @@ import org.apache.lucene.search.MatchAll
import org.apache.solr.cloud.overseer.OverseerAction;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrException.ErrorCode;
+import org.apache.solr.common.cloud.ClusterState;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.Slice;
import org.apache.solr.common.cloud.SolrZkClient;
@@ -39,23 +57,6 @@ import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
public abstract class ElectionContext implements Closeable {
static Logger log = LoggerFactory.getLogger(ElectionContext.class);
final String electionPath;
@@ -405,6 +406,7 @@ final class ShardLeaderElectionContext e
super.runLeaderProcess(weAreReplacement, 0);
try (SolrCore core = cc.getCore(coreName)) {
core.getCoreDescriptor().getCloudDescriptor().setLeader(true);
+ publishActiveIfRegisteredAndNotActive(core);
}
log.info("I am the new leader: " + ZkCoreNodeProps.getCoreUrl(leaderProps) + " " + shardId);
@@ -443,6 +445,21 @@ final class ShardLeaderElectionContext e
}
}
+ public void publishActiveIfRegisteredAndNotActive(SolrCore core) throws KeeperException, InterruptedException {
+ if (core.getCoreDescriptor().getCloudDescriptor().hasRegistered()) {
+ ZkStateReader zkStateReader = zkController.getZkStateReader();
+ zkStateReader.updateClusterState();
+ ClusterState clusterState = zkStateReader.getClusterState();
+ Replica rep = (clusterState == null) ? null
+ : clusterState.getReplica(collection, leaderProps.getStr(ZkStateReader.CORE_NODE_NAME_PROP));
+ if (rep != null && rep.getState() != Replica.State.ACTIVE
+ && rep.getState() != Replica.State.RECOVERING) {
+ log.info("We have become the leader after core registration but are not in an ACTIVE state - publishing ACTIVE");
+ zkController.publish(core.getCoreDescriptor(), Replica.State.ACTIVE);
+ }
+ }
+ }
+
public void checkLIR(String coreName, boolean allReplicasInLine)
throws InterruptedException, KeeperException, IOException {
if (allReplicasInLine) {
Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ZkController.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ZkController.java?rev=1714212&r1=1714211&r2=1714212&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ZkController.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/cloud/ZkController.java Fri Nov 13 14:35:27 2015
@@ -519,6 +519,7 @@ public final class ZkController {
if (descriptors != null) {
for (CoreDescriptor descriptor : descriptors) {
descriptor.getCloudDescriptor().setLeader(false);
+ descriptor.getCloudDescriptor().setHasRegistered(false);
}
}
}
@@ -973,6 +974,8 @@ public final class ZkController {
if (!didRecovery) {
publish(desc, Replica.State.ACTIVE);
}
+
+ core.getCoreDescriptor().getCloudDescriptor().setHasRegistered(true);
}
// make sure we have an update cluster state right away
Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/ForceLeaderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/ForceLeaderTest.java?rev=1714212&r1=1714211&r2=1714212&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/ForceLeaderTest.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/cloud/ForceLeaderTest.java Fri Nov 13 14:35:27 2015
@@ -1,11 +1,26 @@
package org.apache.solr.cloud;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
import java.io.IOException;
import java.util.Collections;
import java.util.List;
-import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
-
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrRequest.METHOD;
@@ -37,24 +52,6 @@ import org.slf4j.LoggerFactory;
import static org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP;
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-@AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/SOLR-7989")
public class ForceLeaderTest extends HttpPartitionTest {
protected static final transient Logger log =
LoggerFactory.getLogger(ForceLeaderTest.class);