mirror of https://github.com/apache/lucene.git
SOLR-7989: After a new leader is elected it, it should ensure it's state is ACTIVE if it has already registered with ZK.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1714211 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
820eea1f3d
commit
15ac4b0e83
|
@ -384,6 +384,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
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
@ -78,6 +82,14 @@ public class CloudDescriptor {
|
|||
this.isLeader = isLeader;
|
||||
}
|
||||
|
||||
public boolean hasRegistered() {
|
||||
return hasRegistered;
|
||||
}
|
||||
|
||||
public void setHasRegistered(boolean hasRegistered) {
|
||||
this.hasRegistered = hasRegistered;
|
||||
}
|
||||
|
||||
public void setShardId(String shardId) {
|
||||
this.shardId = shardId;
|
||||
}
|
||||
|
|
|
@ -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.MatchAllDocsQuery;
|
|||
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;
|
||||
|
@ -404,6 +405,7 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {
|
|||
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);
|
||||
|
||||
|
@ -442,6 +444,21 @@ final class ShardLeaderElectionContext extends ShardLeaderElectionContextBase {
|
|||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue