SOLR-12011: Remove FORCEPREPAREFORLEADERSHIP

This commit is contained in:
Cao Manh Dat 2018-03-05 16:33:45 +07:00
parent 3344306473
commit 27eb6ba062
4 changed files with 1 additions and 149 deletions

View File

@ -50,7 +50,6 @@ import org.apache.solr.cloud.OverseerTaskQueue;
import org.apache.solr.cloud.OverseerTaskQueue.QueueEvent;
import org.apache.solr.cloud.ZkController;
import org.apache.solr.cloud.ZkShardTerms;
import org.apache.solr.cloud.api.collections.OverseerCollectionMessageHandler;
import org.apache.solr.cloud.overseer.SliceMutator;
import org.apache.solr.cloud.rule.ReplicaAssigner;
import org.apache.solr.cloud.rule.Rule;
@ -73,9 +72,7 @@ import org.apache.solr.common.params.AutoScalingParams;
import org.apache.solr.common.params.CollectionAdminParams;
import org.apache.solr.common.params.CollectionParams;
import org.apache.solr.common.params.CollectionParams.CollectionAction;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.common.params.CoreAdminParams.CoreAdminAction;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
@ -87,7 +84,6 @@ import org.apache.solr.core.backup.repository.BackupRepository;
import org.apache.solr.core.snapshots.CollectionSnapshotMetaData;
import org.apache.solr.core.snapshots.SolrSnapshotManager;
import org.apache.solr.handler.RequestHandlerBase;
import org.apache.solr.handler.component.ShardHandler;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
@ -1153,20 +1149,6 @@ public class CollectionsHandler extends RequestHandlerBase implements Permission
}
}
// Call all live replicas to prepare themselves for leadership, e.g. set last published
// state to active.
for (Replica rep : liveReplicas) {
ShardHandler shardHandler = handler.coreContainer.getShardHandlerFactory().getShardHandler();
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(CoreAdminParams.ACTION, CoreAdminAction.FORCEPREPAREFORLEADERSHIP.toString());
params.set(CoreAdminParams.CORE, rep.getStr("core"));
String nodeName = rep.getNodeName();
OverseerCollectionMessageHandler.sendShardRequest(nodeName, params, shardHandler, null, null,
CommonParams.CORES_HANDLER_PATH, handler.coreContainer.getZkController().getZkStateReader()); // synchronous request
}
// Wait till we have an active leader
boolean success = false;
for (int i = 0; i < 9; i++) {

View File

@ -220,21 +220,6 @@ enum CoreAdminOperation implements CoreAdminOp {
}
}),
INVOKE_OP(INVOKE, new InvokeOp()),
FORCEPREPAREFORLEADERSHIP_OP(FORCEPREPAREFORLEADERSHIP, it -> {
final SolrParams params = it.req.getParams();
log().info("I have been forcefully prepare myself for leadership.");
ZkController zkController = it.handler.coreContainer.getZkController();
if (zkController == null) {
throw new SolrException(ErrorCode.BAD_REQUEST, "Only valid for SolrCloud");
}
String cname = params.get(CoreAdminParams.CORE);
if (cname == null) {
throw new IllegalArgumentException(CoreAdminParams.CORE + " is required");
}
}),
BACKUPCORE_OP(BACKUPCORE, new BackupCoreOp()),
RESTORECORE_OP(RESTORECORE, new RestoreCoreOp()),
CREATESNAPSHOT_OP(CREATESNAPSHOT, new CreateSnapshotOp()),

View File

@ -24,28 +24,15 @@ import java.util.List;
import java.util.Properties;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrRequest.METHOD;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.cloud.DistributedQueue;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
import org.apache.solr.client.solrj.request.GenericSolrRequest;
import org.apache.solr.client.solrj.response.SimpleSolrResponse;
import org.apache.solr.cloud.overseer.OverseerAction;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.cloud.ClusterState;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.cloud.Replica.State;
import org.apache.solr.common.cloud.ZkNodeProps;
import org.apache.solr.common.cloud.ZkStateReader;
import org.apache.solr.common.params.CoreAdminParams;
import org.apache.solr.common.params.CoreAdminParams.CoreAdminAction;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.Utils;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.KeeperException.NoNodeException;
import org.junit.Ignore;
@ -53,8 +40,6 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.solr.common.cloud.ZkStateReader.CORE_NAME_PROP;
public class ForceLeaderTest extends HttpPartitionTest {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final boolean onlyLeaderIndexes = random().nextBoolean();
@ -330,105 +315,6 @@ public class ForceLeaderTest extends HttpPartitionTest {
}
}
/**
* Test that FORCELEADER can set last published state of all down (live) replicas to active (so
* that they become worthy candidates for leader election).
*/
@Slow
public void testLastPublishedStateIsActive() throws Exception {
handle.put("maxScore", SKIPVAL);
handle.put("timestamp", SKIPVAL);
String testCollectionName = "forceleader_last_published";
createOldLirCollection(testCollectionName, 3);
cloudClient.setDefaultCollection(testCollectionName);
log.info("Collection created: " + testCollectionName);
try {
List<Replica> notLeaders = ensureAllReplicasAreActive(testCollectionName, SHARD1, 1, 3, maxWaitSecsToSeeAllActive);
assertEquals("Expected 2 replicas for collection " + testCollectionName
+ " but found " + notLeaders.size() + "; clusterState: "
+ printClusterStateInfo(testCollectionName), 2, notLeaders.size());
Replica leader = cloudClient.getZkStateReader().getLeaderRetry(testCollectionName, SHARD1);
JettySolrRunner notLeader0 = getJettyOnPort(getReplicaPort(notLeaders.get(0)));
ZkController zkController = notLeader0.getCoreContainer().getZkController();
// Mark all replicas down
setReplicaState(testCollectionName, SHARD1, leader, State.DOWN);
for (Replica rep : notLeaders) {
setReplicaState(testCollectionName, SHARD1, rep, State.DOWN);
}
zkController.getZkStateReader().forceUpdateCollection(testCollectionName);
// Assert all replicas are down and that there is no leader
assertEquals(0, getActiveOrRecoveringReplicas(testCollectionName, SHARD1).size());
// Now force leader
doForceLeader(cloudClient, testCollectionName, SHARD1);
// Assert that last published states of the two replicas are active now
for (Replica rep: notLeaders) {
assertEquals(Replica.State.ACTIVE, getLastPublishedState(testCollectionName, SHARD1, rep));
}
} finally {
log.info("Cleaning up after the test.");
attemptCollectionDelete(cloudClient, testCollectionName);
}
}
protected void setReplicaState(String collection, String slice, Replica replica, Replica.State state) throws Exception {
DistributedQueue inQueue = Overseer.getStateUpdateQueue(cloudClient.getZkStateReader().getZkClient());
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
String baseUrl = zkStateReader.getBaseUrlForNodeName(replica.getNodeName());
ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, OverseerAction.STATE.toLower(),
ZkStateReader.BASE_URL_PROP, baseUrl,
ZkStateReader.NODE_NAME_PROP, replica.getNodeName(),
ZkStateReader.SHARD_ID_PROP, slice,
ZkStateReader.COLLECTION_PROP, collection,
ZkStateReader.CORE_NAME_PROP, replica.getStr(CORE_NAME_PROP),
ZkStateReader.CORE_NODE_NAME_PROP, replica.getName(),
ZkStateReader.STATE_PROP, state.toString());
inQueue.offer(Utils.toJSON(m));
boolean transition = false;
Replica.State replicaState = null;
for (int counter = 10; counter > 0; counter--) {
ClusterState clusterState = zkStateReader.getClusterState();
replicaState = clusterState.getCollection(collection).getSlice(slice).getReplica(replica.getName()).getState();
if (replicaState == state) {
transition = true;
break;
}
Thread.sleep(1000);
}
if (!transition) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not set replica [" + replica.getName() + "] as " + state +
". Last known state of the replica: " + replicaState);
}
}
protected Replica.State getLastPublishedState(String collection, String slice, Replica replica) throws SolrServerException, IOException,
KeeperException, InterruptedException {
ZkStateReader zkStateReader = cloudClient.getZkStateReader();
String baseUrl = zkStateReader.getBaseUrlForNodeName(replica.getNodeName());
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(CoreAdminParams.ACTION, CoreAdminAction.STATUS.toString());
params.set(CoreAdminParams.CORE, replica.getStr("core"));
SolrRequest<SimpleSolrResponse> req = new GenericSolrRequest(METHOD.GET, "/admin/cores", params);
NamedList resp = null;
try (HttpSolrClient hsc = getHttpSolrClient(baseUrl)) {
resp = hsc.request(req);
}
String lastPublished = (((NamedList<NamedList<String>>)resp.get("status")).get(replica.getStr("core"))).get("lastPublished");
return Replica.State.getState(lastPublished);
}
void assertSendDocFails(int docId) throws Exception {
// sending a doc in this state fails
try {

View File

@ -56,8 +56,7 @@ public class CoreApiMapping {
REQUESTSTATUS(PER_CORE_COMMANDS, GET, CoreAdminAction.REQUESTSTATUS, "request-status", null),/*TODO*/
OVERSEEROP(NODEAPIS, POST, CoreAdminAction.OVERSEEROP, "overseer-op", null),
REJOINLEADERELECTION(NODEAPIS, POST, CoreAdminAction.REJOINLEADERELECTION, "rejoin-leader-election", null),
INVOKE(NODEINVOKE, GET, CoreAdminAction.INVOKE,"invoke", null),
FORCEPREPAREFORLEADERSHIP(PER_CORE_COMMANDS, POST, CoreAdminAction.FORCEPREPAREFORLEADERSHIP, "force-prepare-for-leadership", null);
INVOKE(NODEINVOKE, GET, CoreAdminAction.INVOKE,"invoke", null);
public final String commandName;
public final EndPoint endPoint;