Search in sources :

Example 61 with DocCollection

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

the class AbstractFullDistribZkTestBase method getTotalReplicas.

/* Total number of replicas (number of cores serving an index to the collection) shown by the cluster state */
protected int getTotalReplicas(String collection) {
    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
    DocCollection coll = zkStateReader.getClusterState().getCollectionOrNull(collection);
    // support for when collection hasn't been created yet
    if (coll == null)
        return 0;
    int cnt = 0;
    for (Slice slices : coll.getSlices()) {
        cnt += slices.getReplicas().size();
    }
    return cnt;
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection)

Example 62 with DocCollection

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

the class DeleteInactiveReplicaTest method deleteInactiveReplicaTest.

@Test
public void deleteInactiveReplicaTest() throws Exception {
    String collectionName = "delDeadColl";
    int replicationFactor = 2;
    int numShards = 2;
    int maxShardsPerNode = ((((numShards + 1) * replicationFactor) / cluster.getJettySolrRunners().size())) + 1;
    CollectionAdminRequest.createCollection(collectionName, "conf", numShards, replicationFactor).setMaxShardsPerNode(maxShardsPerNode).process(cluster.getSolrClient());
    waitForState("Expected a cluster of 2 shards and 2 replicas", collectionName, (n, c) -> {
        return DocCollection.isFullyActive(n, c, numShards, replicationFactor);
    });
    DocCollection collectionState = getCollectionState(collectionName);
    Slice shard = getRandomShard(collectionState);
    Replica replica = getRandomReplica(shard);
    JettySolrRunner jetty = cluster.getReplicaJetty(replica);
    cluster.stopJettySolrRunner(jetty);
    waitForState("Expected replica " + replica.getName() + " on down node to be removed from cluster state", collectionName, (n, c) -> {
        Replica r = c.getReplica(replica.getCoreName());
        return r == null || r.getState() != Replica.State.ACTIVE;
    });
    log.info("Removing replica {}/{} ", shard.getName(), replica.getName());
    CollectionAdminRequest.deleteReplica(collectionName, shard.getName(), replica.getName()).process(cluster.getSolrClient());
    waitForState("Expected deleted replica " + replica.getName() + " to be removed from cluster state", collectionName, (n, c) -> {
        return c.getReplica(replica.getCoreName()) == null;
    });
    cluster.startJettySolrRunner(jetty);
    log.info("restarted jetty");
    CoreContainer cc = jetty.getCoreContainer();
    CoreContainer.CoreLoadFailure loadFailure = cc.getCoreInitFailures().get(replica.getCoreName());
    assertNotNull("Deleted core was still loaded!", loadFailure);
    assertTrue("Unexpected load failure message: " + loadFailure.exception.getMessage(), loadFailure.exception.getMessage().contains("does not exist in shard"));
    // Check that we can't create a core with no coreNodeName
    try (SolrClient queryClient = getHttpSolrClient(jetty.getBaseUrl().toString())) {
        Exception e = expectThrows(Exception.class, () -> {
            CoreAdminRequest.Create createRequest = new CoreAdminRequest.Create();
            createRequest.setCoreName("testcore");
            createRequest.setCollection(collectionName);
            createRequest.setShardId("shard2");
            queryClient.request(createRequest);
        });
        assertTrue("Unexpected error message: " + e.getMessage(), e.getMessage().contains("coreNodeName missing"));
    }
}
Also used : JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) CoreAdminRequest(org.apache.solr.client.solrj.request.CoreAdminRequest) Replica(org.apache.solr.common.cloud.Replica) CoreContainer(org.apache.solr.core.CoreContainer) SolrClient(org.apache.solr.client.solrj.SolrClient) Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection) Test(org.junit.Test)

Example 63 with DocCollection

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

the class DeleteReplicaTest method deleteReplicaByCount.

@Test
public void deleteReplicaByCount() throws Exception {
    final String collectionName = "deleteByCount";
    pickRandom(CollectionAdminRequest.createCollection(collectionName, "conf", 1, 3), CollectionAdminRequest.createCollection(collectionName, "conf", 1, 1, 1, 1), CollectionAdminRequest.createCollection(collectionName, "conf", 1, 1, 0, 2), CollectionAdminRequest.createCollection(collectionName, "conf", 1, 0, 1, 2)).process(cluster.getSolrClient());
    waitForState("Expected a single shard with three replicas", collectionName, clusterShape(1, 3));
    CollectionAdminRequest.deleteReplicasFromShard(collectionName, "shard1", 2).process(cluster.getSolrClient());
    waitForState("Expected a single shard with a single replica", collectionName, clusterShape(1, 1));
    try {
        CollectionAdminRequest.deleteReplicasFromShard(collectionName, "shard1", 1).process(cluster.getSolrClient());
        fail("Expected Exception, Can't delete the last replica by count");
    } catch (SolrException e) {
        // expected
        assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, e.code());
        assertTrue(e.getMessage().contains("There is only one replica available"));
    }
    DocCollection docCollection = getCollectionState(collectionName);
    // We know that since leaders are preserved, PULL replicas should not be left alone in the shard
    assertEquals(0, docCollection.getSlice("shard1").getReplicas(EnumSet.of(Replica.Type.PULL)).size());
}
Also used : DocCollection(org.apache.solr.common.cloud.DocCollection) SolrException(org.apache.solr.common.SolrException) Test(org.junit.Test)

Example 64 with DocCollection

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

the class DeleteReplicaTest method deleteLiveReplicaTest.

@Test
public void deleteLiveReplicaTest() throws Exception {
    final String collectionName = "delLiveColl";
    CollectionAdminRequest.createCollection(collectionName, "conf", 2, 2).process(cluster.getSolrClient());
    DocCollection state = getCollectionState(collectionName);
    Slice shard = getRandomShard(state);
    Replica replica = getRandomReplica(shard, (r) -> r.getState() == Replica.State.ACTIVE);
    CoreStatus coreStatus = getCoreStatus(replica);
    Path dataDir = Paths.get(coreStatus.getDataDirectory());
    Exception e = expectThrows(Exception.class, () -> {
        CollectionAdminRequest.deleteReplica(collectionName, shard.getName(), replica.getName()).setOnlyIfDown(true).process(cluster.getSolrClient());
    });
    assertTrue("Unexpected error message: " + e.getMessage(), e.getMessage().contains("state is 'active'"));
    assertTrue("Data directory for " + replica.getName() + " should not have been deleted", Files.exists(dataDir));
    CollectionAdminRequest.deleteReplica(collectionName, shard.getName(), replica.getName()).process(cluster.getSolrClient());
    waitForState("Expected replica " + replica.getName() + " to have been removed", collectionName, (n, c) -> {
        Slice testShard = c.getSlice(shard.getName());
        return testShard.getReplica(replica.getName()) == null;
    });
    assertFalse("Data directory for " + replica.getName() + " should have been removed", Files.exists(dataDir));
}
Also used : Path(java.nio.file.Path) CoreStatus(org.apache.solr.client.solrj.request.CoreStatus) Slice(org.apache.solr.common.cloud.Slice) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica) SolrException(org.apache.solr.common.SolrException) Test(org.junit.Test)

Example 65 with DocCollection

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

the class CollectionsAPIDistributedZkTest method testCreateNodeSet.

@Test
public void testCreateNodeSet() throws Exception {
    JettySolrRunner jetty1 = cluster.getRandomJetty(random());
    JettySolrRunner jetty2 = cluster.getRandomJetty(random());
    List<String> baseUrls = ImmutableList.of(jetty1.getBaseUrl().toString(), jetty2.getBaseUrl().toString());
    CollectionAdminRequest.createCollection("nodeset_collection", "conf", 2, 1).setCreateNodeSet(baseUrls.get(0) + "," + baseUrls.get(1)).process(cluster.getSolrClient());
    DocCollection collectionState = getCollectionState("nodeset_collection");
    for (Replica replica : collectionState.getReplicas()) {
        String replicaUrl = replica.getCoreUrl();
        boolean matchingJetty = false;
        for (String jettyUrl : baseUrls) {
            if (replicaUrl.startsWith(jettyUrl))
                matchingJetty = true;
        }
        if (matchingJetty == false)
            fail("Expected replica to be on " + baseUrls + " but was on " + replicaUrl);
    }
}
Also used : 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)

Aggregations

DocCollection (org.apache.solr.common.cloud.DocCollection)187 Slice (org.apache.solr.common.cloud.Slice)120 Replica (org.apache.solr.common.cloud.Replica)86 HashMap (java.util.HashMap)55 ClusterState (org.apache.solr.common.cloud.ClusterState)52 ArrayList (java.util.ArrayList)50 Map (java.util.Map)42 SolrException (org.apache.solr.common.SolrException)41 Test (org.junit.Test)39 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)32 List (java.util.List)23 NamedList (org.apache.solr.common.util.NamedList)23 HashSet (java.util.HashSet)21 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)19 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)19 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)19 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)17 SolrQuery (org.apache.solr.client.solrj.SolrQuery)16 SolrInputDocument (org.apache.solr.common.SolrInputDocument)16 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)15