You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by da...@apache.org on 2018/10/16 22:53:25 UTC
[10/50] [abbrv] lucene-solr:jira/http2: SOLR-11812: Remove backward
compatibility of old LIR implementation in 8.0
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a37a2139/solr/core/src/test/org/apache/solr/cloud/LIRRollingUpdatesTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/LIRRollingUpdatesTest.java b/solr/core/src/test/org/apache/solr/cloud/LIRRollingUpdatesTest.java
deleted file mode 100644
index 88be4db..0000000
--- a/solr/core/src/test/org/apache/solr/cloud/LIRRollingUpdatesTest.java
+++ /dev/null
@@ -1,473 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.solr.cloud;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.lang.invoke.MethodHandles;
-import java.net.URI;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
-import java.util.function.Supplier;
-
-import org.apache.solr.JSONTestUtil;
-import org.apache.solr.client.solrj.SolrServerException;
-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.QueryRequest;
-import org.apache.solr.common.SolrInputDocument;
-import org.apache.solr.common.cloud.Replica;
-import org.apache.solr.common.cloud.Slice;
-import org.apache.solr.common.cloud.ZkCoreNodeProps;
-import org.apache.solr.common.cloud.ZkStateReader;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.common.util.TimeSource;
-import org.apache.solr.util.TimeOut;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class LIRRollingUpdatesTest extends SolrCloudTestCase {
-
- private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
- private static Map<URI, SocketProxy> proxies;
- private static Map<URI, JettySolrRunner> jettys;
-
- @BeforeClass
- public static void setupCluster() throws Exception {
- configureCluster(3)
- .addConfig("conf", configset("cloud-minimal"))
- .configure();
- // Add proxies
- proxies = new HashMap<>(cluster.getJettySolrRunners().size());
- jettys = new HashMap<>(cluster.getJettySolrRunners().size());
- for (JettySolrRunner jetty:cluster.getJettySolrRunners()) {
- SocketProxy proxy = new SocketProxy();
- jetty.setProxyPort(proxy.getListenPort());
- cluster.stopJettySolrRunner(jetty);//TODO: Can we avoid this restart
- cluster.startJettySolrRunner(jetty);
- proxy.open(jetty.getBaseUrl().toURI());
- log.info("Adding proxy for URL: " + jetty.getBaseUrl() + ". Proxy: " + proxy.getUrl());
- proxies.put(proxy.getUrl(), proxy);
- jettys.put(proxy.getUrl(), jetty);
- }
- }
-
-
- @AfterClass
- public static void tearDownCluster() throws Exception {
- for (SocketProxy proxy:proxies.values()) {
- proxy.close();
- }
- proxies = null;
- jettys = null;
- }
-
- @Test
- // 12-Jun-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 21-May-2018
- // commented 15-Sep-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 09-Aug-2018
- public void testNewReplicaOldLeader() throws Exception {
-
- String collection = "testNewReplicaOldLeader";
- CollectionAdminRequest.createCollection(collection, 1, 2)
- .setCreateNodeSet("")
- .process(cluster.getSolrClient());
- Properties oldLir = new Properties();
- oldLir.setProperty("lirVersion", "old");
-
- CollectionAdminRequest
- .addReplicaToShard(collection, "shard1")
- .setProperties(oldLir)
- .setNode(cluster.getJettySolrRunner(0).getNodeName())
- .process(cluster.getSolrClient());
-
- CollectionAdminRequest
- .addReplicaToShard(collection, "shard1")
- .setProperties(oldLir)
- .setNode(cluster.getJettySolrRunner(1).getNodeName())
- .process(cluster.getSolrClient());
- waitForState("Time waiting for 1x2 collection", collection, clusterShape(1, 2));
-
- addDocs(collection, 2, 0);
-
- Slice shard1 = getCollectionState(collection).getSlice("shard1");
- //introduce network partition between leader & replica
- Replica notLeader = shard1.getReplicas(x -> x != shard1.getLeader()).get(0);
- assertTrue(runInOldLIRMode(collection, "shard1", notLeader));
- getProxyForReplica(notLeader).close();
- getProxyForReplica(shard1.getLeader()).close();
-
- addDoc(collection, 2, getJettyForReplica(shard1.getLeader()));
- waitForState("Replica " + notLeader.getName() + " is not put as DOWN", collection,
- (liveNodes, collectionState) ->
- collectionState.getSlice("shard1").getReplica(notLeader.getName()).getState() == Replica.State.DOWN);
- getProxyForReplica(shard1.getLeader()).reopen();
- getProxyForReplica(notLeader).reopen();
- // make sure that, when new replica works with old leader, it still can recovery normally
- waitForState("Timeout waiting for recovering", collection, clusterShape(1, 2));
- assertDocsExistInAllReplicas(Collections.singletonList(notLeader), collection, 0, 2);
-
- // make sure that, when new replica restart during LIR, it still can recovery normally (by looking at LIR node)
- getProxyForReplica(notLeader).close();
- getProxyForReplica(shard1.getLeader()).close();
-
- addDoc(collection, 3, getJettyForReplica(shard1.getLeader()));
- waitForState("Replica " + notLeader.getName() + " is not put as DOWN", collection,
- (liveNodes, collectionState) ->
- collectionState.getSlice("shard1").getReplica(notLeader.getName()).getState() == Replica.State.DOWN);
-
- JettySolrRunner notLeaderJetty = getJettyForReplica(notLeader);
- notLeaderJetty.stop();
- waitForState("Node did not leave", collection, (liveNodes, collectionState) -> liveNodes.size() == 2);
- upgrade(notLeaderJetty);
- notLeaderJetty.start();
-
- getProxyForReplica(shard1.getLeader()).reopen();
- getProxyForReplica(notLeader).reopen();
- waitForState("Timeout waiting for recovering", collection, clusterShape(1, 2));
- assertFalse(runInOldLIRMode(collection, "shard1", notLeader));
- assertDocsExistInAllReplicas(Collections.singletonList(notLeader), collection, 0, 3);
-
- CollectionAdminRequest.deleteCollection(collection).process(cluster.getSolrClient());
- }
-
- @Test
- // 12-Jun-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 04-May-2018
- // commented 15-Sep-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 09-Aug-2018
- public void testNewLeaderOldReplica() throws Exception {
- // in case of new leader & old replica, new leader can still put old replica into LIR
-
- String collection = "testNewLeaderOldReplica";
- CollectionAdminRequest.createCollection(collection, 1, 2)
- .setCreateNodeSet("")
- .process(cluster.getSolrClient());
- Properties oldLir = new Properties();
- oldLir.setProperty("lirVersion", "old");
-
- CollectionAdminRequest
- .addReplicaToShard(collection, "shard1")
- .setNode(cluster.getJettySolrRunner(0).getNodeName())
- .process(cluster.getSolrClient());
- waitForState("Timeout waiting for shard1 become active", collection, (liveNodes, collectionState) -> {
- Slice shard1 = collectionState.getSlice("shard1");
- if (shard1.getReplicas().size() == 1 && shard1.getLeader() != null) return true;
- return false;
- });
-
- CollectionAdminRequest
- .addReplicaToShard(collection, "shard1")
- .setProperties(oldLir)
- .setNode(cluster.getJettySolrRunner(1).getNodeName())
- .process(cluster.getSolrClient());
- waitForState("Time waiting for 1x2 collection", collection, clusterShape(1, 2));
-
- Slice shard1 = getCollectionState(collection).getSlice("shard1");
- Replica notLeader = shard1.getReplicas(x -> x != shard1.getLeader()).get(0);
- Replica leader = shard1.getLeader();
-
- assertTrue(runInOldLIRMode(collection, "shard1", notLeader));
- assertFalse(runInOldLIRMode(collection, "shard1", leader));
-
- addDocs(collection, 2, 0);
- getProxyForReplica(notLeader).close();
- getProxyForReplica(leader).close();
-
- JettySolrRunner leaderJetty = getJettyForReplica(leader);
- addDoc(collection, 2, leaderJetty);
- waitForState("Replica " + notLeader.getName() + " is not put as DOWN", collection,
- (liveNodes, collectionState) ->
- collectionState.getSlice("shard1").getReplica(notLeader.getName()).getState() == Replica.State.DOWN);
- // wait a little bit
- Thread.sleep(500);
- getProxyForReplica(notLeader).reopen();
- getProxyForReplica(leader).reopen();
-
- waitForState("Timeout waiting for recovering", collection, clusterShape(1, 2));
- assertDocsExistInAllReplicas(Collections.singletonList(notLeader), collection, 0, 2);
-
- // ensure that after recovery, the upgraded replica will clean its LIR status cause it is no longer needed
- assertFalse(cluster.getSolrClient().getZkStateReader().getZkClient().exists(
- ZkController.getLeaderInitiatedRecoveryZnodePath(collection, "shard1", notLeader.getName()), true));
- // ensure that, leader should not register other replica's term
- try (ZkShardTerms zkShardTerms = new ZkShardTerms(collection, "shard1", cluster.getZkClient())) {
- assertFalse(zkShardTerms.getTerms().containsKey(notLeader.getName()));
- }
- CollectionAdminRequest.deleteCollection(collection).process(cluster.getSolrClient());
- }
-
- public void testLeaderAndMixedReplicas(boolean leaderInOldMode) throws Exception {
- // in case of new leader and mixed old replica and new replica, new leader can still put all of them into recovery
- // step1 : setup collection
- String collection = "testMixedReplicas-"+leaderInOldMode;
- CollectionAdminRequest.createCollection(collection, 1, 2)
- .setCreateNodeSet("")
- .process(cluster.getSolrClient());
- Properties oldLir = new Properties();
- oldLir.setProperty("lirVersion", "old");
-
- if (leaderInOldMode) {
- CollectionAdminRequest
- .addReplicaToShard(collection, "shard1")
- .setProperties(oldLir)
- .setNode(cluster.getJettySolrRunner(0).getNodeName())
- .process(cluster.getSolrClient());
- } else {
- CollectionAdminRequest
- .addReplicaToShard(collection, "shard1")
- .setNode(cluster.getJettySolrRunner(0).getNodeName())
- .process(cluster.getSolrClient());
- }
-
- waitForState("Timeout waiting for shard1 become active", collection, clusterShape(1, 1));
-
- CollectionAdminRequest
- .addReplicaToShard(collection, "shard1")
- .setProperties(oldLir)
- .setNode(cluster.getJettySolrRunner(1).getNodeName())
- .process(cluster.getSolrClient());
-
- CollectionAdminRequest
- .addReplicaToShard(collection, "shard1")
- .setNode(cluster.getJettySolrRunner(2).getNodeName())
- .process(cluster.getSolrClient());
- waitForState("Timeout waiting for shard1 become active", collection, clusterShape(1, 3));
-
- Slice shard1 = getCollectionState(collection).getSlice("shard1");
- Replica replicaInOldMode = shard1.getReplicas(x -> x != shard1.getLeader()).get(0);
- Replica replicaInNewMode = shard1.getReplicas(x -> x != shard1.getLeader()).get(1);
- Replica leader = shard1.getLeader();
-
- assertEquals(leaderInOldMode, runInOldLIRMode(collection, "shard1", leader));
- if (!runInOldLIRMode(collection, "shard1", replicaInOldMode)) {
- Replica temp = replicaInOldMode;
- replicaInOldMode = replicaInNewMode;
- replicaInNewMode = temp;
- }
- assertTrue(runInOldLIRMode(collection, "shard1", replicaInOldMode));
- assertFalse(runInOldLIRMode(collection, "shard1", replicaInNewMode));
-
- addDocs(collection, 2, 0);
-
- // step2 : introduce network partition then add doc, replicas should be put into recovery
- getProxyForReplica(replicaInOldMode).close();
- getProxyForReplica(replicaInNewMode).close();
- getProxyForReplica(leader).close();
-
- JettySolrRunner leaderJetty = getJettyForReplica(leader);
- addDoc(collection, 2, leaderJetty);
-
- Replica finalReplicaInOldMode = replicaInOldMode;
- waitForState("Replica " + replicaInOldMode.getName() + " is not put as DOWN", collection,
- (liveNodes, collectionState) ->
- collectionState.getSlice("shard1").getReplica(finalReplicaInOldMode.getName()).getState() == Replica.State.DOWN);
- Replica finalReplicaInNewMode = replicaInNewMode;
- waitForState("Replica " + finalReplicaInNewMode.getName() + " is not put as DOWN", collection,
- (liveNodes, collectionState) ->
- collectionState.getSlice("shard1").getReplica(finalReplicaInNewMode.getName()).getState() == Replica.State.DOWN);
-
- // wait a little bit
- Thread.sleep(500);
- getProxyForReplica(replicaInOldMode).reopen();
- getProxyForReplica(replicaInNewMode).reopen();
- getProxyForReplica(leader).reopen();
-
- waitForState("Timeout waiting for recovering", collection, clusterShape(1, 3));
- assertDocsExistInAllReplicas(Arrays.asList(replicaInNewMode, replicaInOldMode), collection, 0, 2);
-
- addDocs(collection, 3, 3);
-
- // ensure that, leader should not register other replica's term
- try (ZkShardTerms zkShardTerms = new ZkShardTerms(collection, "shard1", cluster.getZkClient())) {
- assertFalse(zkShardTerms.getTerms().containsKey(replicaInOldMode.getName()));
- }
-
- // step3 : upgrade the replica running in old mode to the new mode
- getProxyForReplica(leader).close();
- getProxyForReplica(replicaInOldMode).close();
- addDoc(collection, 6, leaderJetty);
- JettySolrRunner oldJetty = getJettyForReplica(replicaInOldMode);
- oldJetty.stop();
- waitForState("Node did not leave", collection, (liveNodes, collectionState)
- -> liveNodes.size() == 2);
- upgrade(oldJetty);
-
- oldJetty.start();
- getProxyForReplica(leader).reopen();
- getProxyForReplica(replicaInOldMode).reopen();
-
- waitForState("Timeout waiting for recovering", collection, clusterShape(1, 3));
- assertDocsExistInAllReplicas(Arrays.asList(replicaInNewMode, replicaInOldMode), collection, 0, 6);
-
- CollectionAdminRequest.deleteCollection(collection).process(cluster.getSolrClient());
- }
-
- @Test
- // 12-Jun-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 04-May-2018
- // commented 15-Sep-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 09-Aug-2018
- public void testNewLeaderAndMixedReplicas() throws Exception {
- testLeaderAndMixedReplicas(false);
- }
-
- @Test
- // 12-Jun-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 04-May-2018
- public void testOldLeaderAndMixedReplicas() throws Exception {
- testLeaderAndMixedReplicas(true);
- }
-
- private void upgrade(JettySolrRunner solrRunner) {
- File[] corePaths = new File(solrRunner.getSolrHome()).listFiles();
- for (File corePath : corePaths) {
- File coreProperties = new File(corePath, "core.properties");
- if (!coreProperties.exists()) continue;
- Properties properties = new Properties();
-
- try (Reader reader = new InputStreamReader(new FileInputStream(coreProperties), "UTF-8")) {
- properties.load(reader);
- } catch (Exception e) {
- continue;
- }
- properties.remove("lirVersion");
- try (Writer writer = new OutputStreamWriter(new FileOutputStream(coreProperties), "UTF-8")) {
- properties.store(writer, "Upgraded");
- } catch (Exception e) {
- continue;
- }
- }
- }
-
- protected void assertDocsExistInAllReplicas(List<Replica> notLeaders,
- String testCollectionName, int firstDocId, int lastDocId)
- throws Exception {
- Replica leader =
- cluster.getSolrClient().getZkStateReader().getLeaderRetry(testCollectionName, "shard1", 10000);
- HttpSolrClient leaderSolr = getHttpSolrClient(leader, testCollectionName);
- List<HttpSolrClient> replicas =
- new ArrayList<HttpSolrClient>(notLeaders.size());
-
- for (Replica r : notLeaders) {
- replicas.add(getHttpSolrClient(r, testCollectionName));
- }
- try {
- for (int d = firstDocId; d <= lastDocId; d++) {
- String docId = String.valueOf(d);
- assertDocExists(leaderSolr, testCollectionName, docId);
- for (HttpSolrClient replicaSolr : replicas) {
- assertDocExists(replicaSolr, testCollectionName, docId);
- }
- }
- } finally {
- if (leaderSolr != null) {
- leaderSolr.close();
- }
- for (HttpSolrClient replicaSolr : replicas) {
- replicaSolr.close();
- }
- }
- }
-
- protected void assertDocExists(HttpSolrClient solr, String coll, String docId) throws Exception {
- NamedList rsp = realTimeGetDocId(solr, docId);
- String match = JSONTestUtil.matchObj("/id", rsp.get("doc"), docId);
- assertTrue("Doc with id=" + docId + " not found in " + solr.getBaseURL()
- + " due to: " + match + "; rsp="+rsp, match == null);
- }
-
- private NamedList realTimeGetDocId(HttpSolrClient solr, String docId) throws SolrServerException, IOException {
- QueryRequest qr = new QueryRequest(params("qt", "/get", "id", docId, "distrib", "false"));
- return solr.request(qr);
- }
-
- protected HttpSolrClient getHttpSolrClient(Replica replica, String coll) throws Exception {
- ZkCoreNodeProps zkProps = new ZkCoreNodeProps(replica);
- String url = zkProps.getBaseUrl() + "/" + coll;
- return getHttpSolrClient(url);
- }
-
- private <T> void waitFor(int waitTimeInSecs, T expected, Supplier<T> supplier) throws InterruptedException {
- TimeOut timeOut = new TimeOut(waitTimeInSecs, TimeUnit.SECONDS, new TimeSource.CurrentTimeSource());
- while (!timeOut.hasTimedOut()) {
- if (expected == supplier.get()) return;
- Thread.sleep(100);
- }
- assertEquals(expected, supplier.get());
- }
-
- private boolean runInOldLIRMode(String collection, String shard, Replica replica) {
- try (ZkShardTerms shardTerms = new ZkShardTerms(collection, shard, cluster.getZkClient())) {
- return !shardTerms.registered(replica.getName());
- }
- }
-
- private void addDoc(String collection, int docId, JettySolrRunner solrRunner) throws IOException, SolrServerException {
- try (HttpSolrClient solrClient = new HttpSolrClient.Builder(solrRunner.getBaseUrl().toString()).build()) {
- solrClient.add(collection, new SolrInputDocument("id", String.valueOf(docId), "fieldName_s", String.valueOf(docId)));
- }
- }
-
- private void addDocs(String collection, int numDocs, int startId) throws SolrServerException, IOException {
- List<SolrInputDocument> docs = new ArrayList<>(numDocs);
- for (int i = 0; i < numDocs; i++) {
- int id = startId + i;
- docs.add(new SolrInputDocument("id", String.valueOf(id), "fieldName_s", String.valueOf(id)));
- }
- cluster.getSolrClient().add(collection, docs);
- cluster.getSolrClient().commit(collection);
- }
-
-
- protected JettySolrRunner getJettyForReplica(Replica replica) throws Exception {
- String replicaBaseUrl = replica.getStr(ZkStateReader.BASE_URL_PROP);
- assertNotNull(replicaBaseUrl);
- URL baseUrl = new URL(replicaBaseUrl);
-
- JettySolrRunner proxy = jettys.get(baseUrl.toURI());
- assertNotNull("No proxy found for " + baseUrl + "!", proxy);
- return proxy;
- }
-
- protected SocketProxy getProxyForReplica(Replica replica) throws Exception {
- String replicaBaseUrl = replica.getStr(ZkStateReader.BASE_URL_PROP);
- assertNotNull(replicaBaseUrl);
- URL baseUrl = new URL(replicaBaseUrl);
-
- SocketProxy proxy = proxies.get(baseUrl.toURI());
- if (proxy == null && !baseUrl.toExternalForm().endsWith("/")) {
- baseUrl = new URL(baseUrl.toExternalForm() + "/");
- proxy = proxies.get(baseUrl.toURI());
- }
- assertNotNull("No proxy found for " + baseUrl + "!", proxy);
- return proxy;
- }
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a37a2139/solr/core/src/test/org/apache/solr/cloud/TestLeaderInitiatedRecoveryThread.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestLeaderInitiatedRecoveryThread.java b/solr/core/src/test/org/apache/solr/cloud/TestLeaderInitiatedRecoveryThread.java
deleted file mode 100644
index ce9d9ad..0000000
--- a/solr/core/src/test/org/apache/solr/cloud/TestLeaderInitiatedRecoveryThread.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * 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.
- */
-package org.apache.solr.cloud;
-
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.solr.SolrTestCaseJ4;
-import org.apache.solr.common.SolrException;
-import org.apache.solr.common.cloud.Replica;
-import org.apache.solr.common.cloud.ZkCoreNodeProps;
-import org.apache.solr.common.cloud.ZkStateReader;
-import org.apache.solr.common.util.TimeSource;
-import org.apache.solr.core.CoreContainer;
-import org.apache.solr.util.MockCoreContainer.MockCoreDescriptor;
-import org.apache.solr.util.TimeOut;
-import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.data.Stat;
-import org.junit.Test;
-
-/**
- * Test for {@link LeaderInitiatedRecoveryThread}
- */
-@Deprecated
-@SolrTestCaseJ4.SuppressSSL
-public class TestLeaderInitiatedRecoveryThread extends AbstractFullDistribZkTestBase {
-
- public TestLeaderInitiatedRecoveryThread() {
- sliceCount = 1;
- fixShardCount(2);
- }
-
- @Test
- //17-Aug-2018 commented @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // 09-Apr-2018
- @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 20-Sep-2018
- public void testPublishDownState() throws Exception {
- waitForRecoveriesToFinish(true);
-
- final String leaderCoreNodeName = shardToLeaderJetty.get(SHARD1).coreNodeName;
- final CloudJettyRunner leaderRunner = shardToLeaderJetty.get(SHARD1);
- final CoreContainer coreContainer1 = leaderRunner.jetty.getCoreContainer();
- final ZkController zkController1 = coreContainer1.getZkController();
-
- CloudJettyRunner notLeader = null;
- for (CloudJettyRunner cloudJettyRunner : shardToJetty.get(SHARD1)) {
- if (cloudJettyRunner != leaderRunner) {
- notLeader = cloudJettyRunner;
- break;
- }
- }
- assertNotNull(notLeader);
- Replica replica = cloudClient.getZkStateReader().getClusterState().getCollection(DEFAULT_COLLECTION).getReplica(notLeader.coreNodeName);
- ZkCoreNodeProps replicaCoreNodeProps = new ZkCoreNodeProps(replica);
-
- MockCoreDescriptor cd = new MockCoreDescriptor() {
- public CloudDescriptor getCloudDescriptor() {
- return new CloudDescriptor(shardToLeaderJetty.get(SHARD1).info.getStr(ZkStateReader.CORE_NAME_PROP), new Properties(), this) {
- @Override
- public String getCoreNodeName() {
- return shardToLeaderJetty.get(SHARD1).info.getStr(ZkStateReader.CORE_NODE_NAME_PROP);
- }
- @Override
- public boolean isLeader() {
- return true;
- }
- };
- }
- };
-
- /*
- 1. Test that publishDownState throws exception when zkController.isReplicaInRecoveryHandling == false
- */
-
- SolrException e = expectThrows(SolrException.class,
- "publishDownState should not have succeeded because replica url is not marked in leader initiated recovery in ZkController",
- () -> {
- LeaderInitiatedRecoveryThread thread = new LeaderInitiatedRecoveryThread(zkController1, coreContainer1,
- DEFAULT_COLLECTION, SHARD1, replicaCoreNodeProps, 1, cd);
- assertFalse(zkController1.isReplicaInRecoveryHandling(replicaCoreNodeProps.getCoreUrl()));
- thread.run();
- });
- assertEquals(e.code(), SolrException.ErrorCode.INVALID_STATE.code);
-
- /*
- 2. Test that a non-live replica cannot be put into LIR or down state
- */
- LeaderInitiatedRecoveryThread thread = new LeaderInitiatedRecoveryThread(zkController1, coreContainer1,
- DEFAULT_COLLECTION, SHARD1, replicaCoreNodeProps, 1, cd);
- // kill the replica
- int children = cloudClient.getZkStateReader().getZkClient().getChildren("/live_nodes", null, true).size();
- ChaosMonkey.stop(notLeader.jetty);
- TimeOut timeOut = new TimeOut(60, TimeUnit.SECONDS, TimeSource.NANO_TIME);
- while (!timeOut.hasTimedOut()) {
- if (children > cloudClient.getZkStateReader().getZkClient().getChildren("/live_nodes", null, true).size()) {
- break;
- }
- Thread.sleep(500);
- }
- assertTrue(children > cloudClient.getZkStateReader().getZkClient().getChildren("/live_nodes", null, true).size());
-
- int cversion = getOverseerCversion();
- // Thread should not publish LIR and down state for node which is not live, regardless of whether forcePublish is true or false
- assertFalse(thread.publishDownState(replicaCoreNodeProps.getCoreName(), replica.getName(), replica.getNodeName(), replicaCoreNodeProps.getCoreUrl(), false));
- // lets assert that we did not publish anything to overseer queue, simplest way is to assert that cversion of overseer queue zk node is still the same
- assertEquals(cversion, getOverseerCversion());
-
- assertFalse(thread.publishDownState(replicaCoreNodeProps.getCoreName(), replica.getName(), replica.getNodeName(), replicaCoreNodeProps.getCoreUrl(), true));
- // lets assert that we did not publish anything to overseer queue
- assertEquals(cversion, getOverseerCversion());
-
-
- /*
- 3. Test that if ZK connection loss then thread should not attempt to publish down state even if forcePublish=true
- */
- ChaosMonkey.start(notLeader.jetty);
- waitForRecoveriesToFinish(true);
-
- thread = new LeaderInitiatedRecoveryThread(zkController1, coreContainer1,
- DEFAULT_COLLECTION, SHARD1, replicaCoreNodeProps, 1, cd) {
- @Override
- protected void updateLIRState(String replicaCoreNodeName) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "", new KeeperException.ConnectionLossException());
- }
- };
- assertFalse(thread.publishDownState(replicaCoreNodeProps.getCoreName(), replica.getName(), replica.getNodeName(), replicaCoreNodeProps.getCoreUrl(), false));
- assertFalse(thread.publishDownState(replicaCoreNodeProps.getCoreName(), replica.getName(), replica.getNodeName(), replicaCoreNodeProps.getCoreUrl(), true));
- assertNull(zkController1.getLeaderInitiatedRecoveryState(DEFAULT_COLLECTION, SHARD1, replica.getName()));
-
-
- /*
- 4. Test that if ZK connection loss or session expired then thread should not attempt to publish down state even if forcePublish=true
- */
- thread = new LeaderInitiatedRecoveryThread(zkController1, coreContainer1,
- DEFAULT_COLLECTION, SHARD1, replicaCoreNodeProps, 1, cd) {
- @Override
- protected void updateLIRState(String replicaCoreNodeName) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "", new KeeperException.SessionExpiredException());
- }
- };
- assertFalse(thread.publishDownState(replicaCoreNodeProps.getCoreName(), replica.getName(), replica.getNodeName(), replicaCoreNodeProps.getCoreUrl(), false));
- assertFalse(thread.publishDownState(replicaCoreNodeProps.getCoreName(), replica.getName(), replica.getNodeName(), replicaCoreNodeProps.getCoreUrl(), true));
- assertNull(zkController1.getLeaderInitiatedRecoveryState(DEFAULT_COLLECTION, SHARD1, replica.getName()));
-
-
- /*
- 5. Test that any exception other then ZK connection loss or session expired should publish down state only if forcePublish=true
- */
- thread = new LeaderInitiatedRecoveryThread(zkController1, coreContainer1,
- DEFAULT_COLLECTION, SHARD1, replicaCoreNodeProps, 1, cd) {
- @Override
- protected void updateLIRState(String replicaCoreNodeName) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "bogus exception");
- }
- };
- // the following should return true because regardless of the bogus exception in setting LIR state, we still want recovery commands to be sent,
- // however the following will not publish a down state
- cversion = getOverseerCversion();
- assertTrue(thread.publishDownState(replicaCoreNodeProps.getCoreName(), replica.getName(), replica.getNodeName(), replicaCoreNodeProps.getCoreUrl(), false));
-
- // lets assert that we did not publish anything to overseer queue, simplest way is to assert that cversion of overseer queue zk node is still the same
- assertEquals(cversion, getOverseerCversion());
-
- assertTrue(thread.publishDownState(replicaCoreNodeProps.getCoreName(), replica.getName(), replica.getNodeName(), replicaCoreNodeProps.getCoreUrl(), true));
- // this should have published a down state so assert that cversion has incremented
- assertTrue(getOverseerCversion() > cversion);
-
- timeOut = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME);
- while (!timeOut.hasTimedOut()) {
- Replica r = cloudClient.getZkStateReader().getClusterState().getCollection(DEFAULT_COLLECTION).getReplica(replica.getName());
- if (r.getState() == Replica.State.DOWN) {
- break;
- }
- Thread.sleep(500);
- }
-
- assertNull(zkController1.getLeaderInitiatedRecoveryState(DEFAULT_COLLECTION, SHARD1, replica.getName()));
- assertEquals(Replica.State.DOWN, cloudClient.getZkStateReader().getClusterState().getCollection(DEFAULT_COLLECTION).getReplica(replica.getName()).getState());
-
- /*
- 6. Test that non-leader cannot set LIR nodes
- */
-
- final CoreContainer coreContainer2 = notLeader.jetty.getCoreContainer();
- final ZkController zkController2 = coreContainer2.getZkController();
-
- thread = new LeaderInitiatedRecoveryThread(zkController2, coreContainer2,
- DEFAULT_COLLECTION, SHARD1, replicaCoreNodeProps, 1, coreContainer2.getCores().iterator().next().getCoreDescriptor()) {
- @Override
- protected void updateLIRState(String replicaCoreNodeName) {
- throw expectThrows(ZkController.NotLeaderException.class, () -> super.updateLIRState(replicaCoreNodeName));
- }
- };
- cversion = getOverseerCversion();
- assertFalse(thread.publishDownState(replicaCoreNodeProps.getCoreName(), replica.getName(), replica.getNodeName(), replicaCoreNodeProps.getCoreUrl(), false));
- assertEquals(cversion, getOverseerCversion());
-
- /*
- 7. assert that we can write a LIR state if everything else is fine
- */
- // reset the zkcontroller to the one from the leader
- final CoreContainer coreContainer3 = leaderRunner.jetty.getCoreContainer();
- final ZkController zkController3 = coreContainer3.getZkController();
- thread = new LeaderInitiatedRecoveryThread(zkController3, coreContainer3,
- DEFAULT_COLLECTION, SHARD1, replicaCoreNodeProps, 1, coreContainer3.getCores().iterator().next().getCoreDescriptor());
- thread.publishDownState(replicaCoreNodeProps.getCoreName(), replica.getName(), replica.getNodeName(), replicaCoreNodeProps.getCoreUrl(), false);
- timeOut = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME);
- while (!timeOut.hasTimedOut()) {
- Replica.State state = zkController3.getLeaderInitiatedRecoveryState(DEFAULT_COLLECTION, SHARD1, replica.getName());
- if (state == Replica.State.DOWN) {
- break;
- }
- Thread.sleep(500);
- }
- assertNotNull(zkController3.getLeaderInitiatedRecoveryStateObject(DEFAULT_COLLECTION, SHARD1, replica.getName()));
- assertEquals(Replica.State.DOWN, zkController3.getLeaderInitiatedRecoveryState(DEFAULT_COLLECTION, SHARD1, replica.getName()));
-
- /*
- 7. Test that
- */
- }
-
- protected int getOverseerCversion() throws KeeperException, InterruptedException {
- Stat stat = new Stat();
- cloudClient.getZkStateReader().getZkClient().getData("/overseer/queue", null, stat, true);
- return stat.getCversion();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/a37a2139/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsTest.java b/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsTest.java
index 1c1b1d2..1745ae4f 100644
--- a/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsTest.java
+++ b/solr/core/src/test/org/apache/solr/cloud/ZkShardTermsTest.java
@@ -84,7 +84,7 @@ public class ZkShardTermsTest extends SolrCloudTestCase {
zkShardTerms.registerTerm("replica1");
zkShardTerms.registerTerm("replica2");
- // normal case when leader start lir process
+ // normal case when leader failed to send an update to replica
zkShardTerms.ensureTermsIsHigher("replica1", Collections.singleton("replica2"));
zkShardTerms.startRecovering("replica2");
assertEquals(zkShardTerms.getTerm("replica2"), 1);
@@ -95,7 +95,6 @@ public class ZkShardTermsTest extends SolrCloudTestCase {
assertEquals(zkShardTerms.getTerm("replica2"), 1);
assertEquals(zkShardTerms.getTerm("replica2_recovering"), -1);
- // stack of lir processes
zkShardTerms.ensureTermsIsHigher("replica1", Collections.singleton("replica2"));
assertEquals(zkShardTerms.getTerm("replica1"), 2);
assertEquals(zkShardTerms.getTerm("replica2"), 1);