Search in sources :

Example 51 with Replica

use of org.apache.solr.common.cloud.Replica in project lucene-solr by apache.

the class RecoveryZkTest method assertShardConsistency.

private void assertShardConsistency(Slice shard, boolean expectDocs) throws Exception {
    List<Replica> replicas = shard.getReplicas(r -> r.getState() == Replica.State.ACTIVE);
    long[] numCounts = new long[replicas.size()];
    int i = 0;
    for (Replica replica : replicas) {
        try (HttpSolrClient client = new HttpSolrClient.Builder(replica.getCoreUrl()).withHttpClient(cluster.getSolrClient().getHttpClient()).build()) {
            numCounts[i] = client.query(new SolrQuery("*:*").add("distrib", "false")).getResults().getNumFound();
            i++;
        }
    }
    for (int j = 1; j < replicas.size(); j++) {
        if (numCounts[j] != numCounts[j - 1])
            // TODO improve this!
            fail("Mismatch in counts between replicas");
        if (numCounts[j] == 0 && expectDocs)
            fail("Expected docs on shard " + shard.getName() + " but found none");
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Replica(org.apache.solr.common.cloud.Replica) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 52 with Replica

use of org.apache.solr.common.cloud.Replica in project lucene-solr by apache.

the class RecoveryZkTest method test.

@Test
public void test() throws Exception {
    final String collection = "recoverytest";
    CollectionAdminRequest.createCollection(collection, "conf", 1, 2).setMaxShardsPerNode(1).process(cluster.getSolrClient());
    waitForState("Expected a collection with one shard and two replicas", collection, clusterShape(1, 2));
    cluster.getSolrClient().setDefaultCollection(collection);
    // start a couple indexing threads
    int[] maxDocList = new int[] { 300, 700, 1200, 1350, 3000 };
    int[] maxDocNightlyList = new int[] { 3000, 7000, 12000, 30000, 45000, 60000 };
    int maxDoc;
    if (!TEST_NIGHTLY) {
        maxDoc = maxDocList[random().nextInt(maxDocList.length - 1)];
    } else {
        maxDoc = maxDocNightlyList[random().nextInt(maxDocList.length - 1)];
    }
    log.info("Indexing {} documents", maxDoc);
    indexThread = new StoppableIndexingThread(null, cluster.getSolrClient(), "1", true, maxDoc, 1, true);
    indexThread.start();
    indexThread2 = new StoppableIndexingThread(null, cluster.getSolrClient(), "2", true, maxDoc, 1, true);
    indexThread2.start();
    // give some time to index...
    int[] waitTimes = new int[] { 200, 2000, 3000 };
    Thread.sleep(waitTimes[random().nextInt(waitTimes.length - 1)]);
    // bring shard replica down
    DocCollection state = getCollectionState(collection);
    Replica leader = state.getLeader("shard1");
    Replica replica = getRandomReplica(state.getSlice("shard1"), (r) -> leader != r);
    JettySolrRunner jetty = cluster.getReplicaJetty(replica);
    jetty.stop();
    // wait a moment - lets allow some docs to be indexed so replication time is non 0
    Thread.sleep(waitTimes[random().nextInt(waitTimes.length - 1)]);
    // bring shard replica up
    jetty.start();
    // make sure replication can start
    Thread.sleep(3000);
    // stop indexing threads
    indexThread.safeStop();
    indexThread2.safeStop();
    indexThread.join();
    indexThread2.join();
    new UpdateRequest().commit(cluster.getSolrClient(), collection);
    cluster.getSolrClient().waitForState(collection, 120, TimeUnit.SECONDS, clusterShape(1, 2));
    // test that leader and replica have same doc count
    state = getCollectionState(collection);
    assertShardConsistency(state.getSlice("shard1"), true);
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica) Test(org.junit.Test)

Example 53 with Replica

use of org.apache.solr.common.cloud.Replica in project lucene-solr by apache.

the class MissingSegmentRecoveryTest method setup.

@Before
public void setup() throws SolrServerException, IOException {
    CollectionAdminRequest.createCollection(collection, "conf", 1, 2).setMaxShardsPerNode(1).process(cluster.getSolrClient());
    waitForState("Expected a collection with one shard and two replicas", collection, clusterShape(1, 2));
    cluster.getSolrClient().setDefaultCollection(collection);
    List<SolrInputDocument> docs = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("id", i);
        docs.add(doc);
    }
    cluster.getSolrClient().add(docs);
    cluster.getSolrClient().commit();
    DocCollection state = getCollectionState(collection);
    leader = state.getLeader("shard1");
    replica = getRandomReplica(state.getSlice("shard1"), (r) -> leader != r);
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Files(java.nio.file.Files) Slow(org.apache.lucene.util.LuceneTestCase.Slow) DocCollection(org.apache.solr.common.cloud.DocCollection) SolrCore(org.apache.solr.core.SolrCore) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException) Test(org.junit.Test) File(java.io.File) Replica(org.apache.solr.common.cloud.Replica) ArrayList(java.util.ArrayList) SolrServerException(org.apache.solr.client.solrj.SolrServerException) List(java.util.List) SolrQuery(org.apache.solr.client.solrj.SolrQuery) After(org.junit.After) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) Before(org.junit.Before) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ArrayList(java.util.ArrayList) DocCollection(org.apache.solr.common.cloud.DocCollection) Before(org.junit.Before)

Example 54 with Replica

use of org.apache.solr.common.cloud.Replica in project lucene-solr by apache.

the class SSLMigrationTest method getReplicas.

private List<Replica> getReplicas() {
    List<Replica> replicas = new ArrayList<Replica>();
    DocCollection collection = this.cloudClient.getZkStateReader().getClusterState().getCollection(DEFAULT_COLLECTION);
    for (Slice slice : collection.getSlices()) {
        replicas.addAll(slice.getReplicas());
    }
    return replicas;
}
Also used : Slice(org.apache.solr.common.cloud.Slice) ArrayList(java.util.ArrayList) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica)

Example 55 with Replica

use of org.apache.solr.common.cloud.Replica in project lucene-solr by apache.

the class HdfsCollectionsAPIDistributedZkTest method moveReplicaTest.

@Test
public void moveReplicaTest() throws Exception {
    cluster.waitForAllNodes(5000);
    String coll = "movereplicatest_coll";
    CloudSolrClient cloudClient = cluster.getSolrClient();
    CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(coll, "conf", 2, 2);
    create.setMaxShardsPerNode(2);
    cloudClient.request(create);
    for (int i = 0; i < 10; i++) {
        cloudClient.add(coll, sdoc("id", String.valueOf(i)));
        cloudClient.commit(coll);
    }
    List<Slice> slices = new ArrayList<>(cloudClient.getZkStateReader().getClusterState().getCollection(coll).getSlices());
    Collections.shuffle(slices, random());
    Slice slice = null;
    Replica replica = null;
    for (Slice s : slices) {
        slice = s;
        for (Replica r : s.getReplicas()) {
            if (s.getLeader() != r) {
                replica = r;
            }
        }
    }
    String dataDir = getDataDir(replica);
    Set<String> liveNodes = cloudClient.getZkStateReader().getClusterState().getLiveNodes();
    ArrayList<String> l = new ArrayList<>(liveNodes);
    Collections.shuffle(l, random());
    String targetNode = null;
    for (String node : liveNodes) {
        if (!replica.getNodeName().equals(node)) {
            targetNode = node;
            break;
        }
    }
    assertNotNull(targetNode);
    CollectionAdminRequest.MoveReplica moveReplica = new CollectionAdminRequest.MoveReplica(coll, replica.getName(), targetNode);
    moveReplica.process(cloudClient);
    checkNumOfCores(cloudClient, replica.getNodeName(), 0);
    checkNumOfCores(cloudClient, targetNode, 2);
    waitForState("Wait for recovery finish failed", coll, clusterShape(2, 2));
    slice = cloudClient.getZkStateReader().getClusterState().getCollection(coll).getSlice(slice.getName());
    boolean found = false;
    for (Replica newReplica : slice.getReplicas()) {
        if (getDataDir(newReplica).equals(dataDir)) {
            found = true;
        }
    }
    assertTrue(found);
    // data dir is reused so replication will be skipped
    for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
        SolrMetricManager manager = jetty.getCoreContainer().getMetricManager();
        List<String> registryNames = manager.registryNames().stream().filter(s -> s.startsWith("solr.core.")).collect(Collectors.toList());
        for (String registry : registryNames) {
            Map<String, Metric> metrics = manager.registry(registry).getMetrics();
            Counter counter = (Counter) metrics.get("REPLICATION./replication.requests");
            if (counter != null) {
                assertEquals(0, counter.getCount());
            }
        }
    }
}
Also used : Nightly(com.carrotsearch.randomizedtesting.annotations.Nightly) BadHdfsThreadsFilter(org.apache.solr.util.BadHdfsThreadsFilter) MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) BeforeClass(org.junit.BeforeClass) Slow(org.apache.lucene.util.LuceneTestCase.Slow) CoreAdminResponse(org.apache.solr.client.solrj.response.CoreAdminResponse) ArrayList(java.util.ArrayList) SolrServerException(org.apache.solr.client.solrj.SolrServerException) Map(java.util.Map) ThreadLeakFilters(com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters) Counter(com.codahale.metrics.Counter) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) CoreStatus(org.apache.solr.client.solrj.request.CoreStatus) AfterClass(org.junit.AfterClass) Slice(org.apache.solr.common.cloud.Slice) Set(java.util.Set) Metric(com.codahale.metrics.Metric) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Replica(org.apache.solr.common.cloud.Replica) List(java.util.List) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) ZkConfigManager(org.apache.solr.common.cloud.ZkConfigManager) Collections(java.util.Collections) CoreAdminRequest(org.apache.solr.client.solrj.request.CoreAdminRequest) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) CollectionsAPIDistributedZkTest(org.apache.solr.cloud.CollectionsAPIDistributedZkTest) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) ArrayList(java.util.ArrayList) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) Replica(org.apache.solr.common.cloud.Replica) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) Counter(com.codahale.metrics.Counter) Slice(org.apache.solr.common.cloud.Slice) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) Metric(com.codahale.metrics.Metric) Test(org.junit.Test) CollectionsAPIDistributedZkTest(org.apache.solr.cloud.CollectionsAPIDistributedZkTest)

Aggregations

Replica (org.apache.solr.common.cloud.Replica)232 Slice (org.apache.solr.common.cloud.Slice)140 DocCollection (org.apache.solr.common.cloud.DocCollection)86 ArrayList (java.util.ArrayList)81 ClusterState (org.apache.solr.common.cloud.ClusterState)67 HashMap (java.util.HashMap)60 SolrException (org.apache.solr.common.SolrException)53 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)50 Test (org.junit.Test)50 Map (java.util.Map)45 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)37 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)35 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)29 NamedList (org.apache.solr.common.util.NamedList)28 SolrQuery (org.apache.solr.client.solrj.SolrQuery)26 IOException (java.io.IOException)25 SolrInputDocument (org.apache.solr.common.SolrInputDocument)25 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)25 HashSet (java.util.HashSet)24 List (java.util.List)20