Search in sources :

Example 71 with Replica

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

the class ForceLeaderTest method unsetLeader.

protected void unsetLeader(String collection, String slice) throws Exception {
    DistributedQueue inQueue = Overseer.getStateUpdateQueue(cloudClient.getZkStateReader().getZkClient());
    ZkStateReader zkStateReader = cloudClient.getZkStateReader();
    ZkNodeProps m = new ZkNodeProps(Overseer.QUEUE_OPERATION, OverseerAction.LEADER.toLower(), ZkStateReader.SHARD_ID_PROP, slice, ZkStateReader.COLLECTION_PROP, collection);
    inQueue.offer(Utils.toJSON(m));
    ClusterState clusterState = null;
    boolean transition = false;
    for (int counter = 10; counter > 0; counter--) {
        clusterState = zkStateReader.getClusterState();
        Replica newLeader = clusterState.getSlice(collection, slice).getLeader();
        if (newLeader == null) {
            transition = true;
            break;
        }
        Thread.sleep(1000);
    }
    if (!transition) {
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Could not unset replica leader" + ". Cluster state: " + printClusterStateInfo(collection));
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) ClusterState(org.apache.solr.common.cloud.ClusterState) ZkNodeProps(org.apache.solr.common.cloud.ZkNodeProps) Replica(org.apache.solr.common.cloud.Replica) SolrException(org.apache.solr.common.SolrException)

Example 72 with Replica

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

the class DeleteReplicaTest method deleteReplicaAndVerifyDirectoryCleanup.

@Test
public void deleteReplicaAndVerifyDirectoryCleanup() throws Exception {
    final String collectionName = "deletereplica_test";
    CollectionAdminRequest.createCollection(collectionName, "conf", 1, 2).process(cluster.getSolrClient());
    Replica leader = cluster.getSolrClient().getZkStateReader().getLeaderRetry(collectionName, "shard1");
    //Confirm that the instance and data directory exist
    CoreStatus coreStatus = getCoreStatus(leader);
    assertTrue("Instance directory doesn't exist", Files.exists(Paths.get(coreStatus.getInstanceDirectory())));
    assertTrue("DataDirectory doesn't exist", Files.exists(Paths.get(coreStatus.getDataDirectory())));
    CollectionAdminRequest.deleteReplica(collectionName, "shard1", leader.getName()).process(cluster.getSolrClient());
    Replica newLeader = cluster.getSolrClient().getZkStateReader().getLeaderRetry(collectionName, "shard1");
    assertFalse(leader.equals(newLeader));
    //Confirm that the instance and data directory were deleted by default
    assertFalse("Instance directory still exists", Files.exists(Paths.get(coreStatus.getInstanceDirectory())));
    assertFalse("DataDirectory still exists", Files.exists(Paths.get(coreStatus.getDataDirectory())));
}
Also used : CoreStatus(org.apache.solr.client.solrj.request.CoreStatus) Replica(org.apache.solr.common.cloud.Replica) Test(org.junit.Test)

Example 73 with Replica

use of org.apache.solr.common.cloud.Replica 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 74 with Replica

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

the class CollectionsAPISolrJTest method testBalanceShardUnique.

@Test
public void testBalanceShardUnique() throws IOException, SolrServerException, KeeperException, InterruptedException {
    final String collection = "balancedProperties";
    CollectionAdminRequest.createCollection(collection, "conf", 2, 2).process(cluster.getSolrClient());
    CollectionAdminResponse response = CollectionAdminRequest.balanceReplicaProperty(collection, "preferredLeader").process(cluster.getSolrClient());
    assertEquals(0, response.getStatus());
    waitForState("Expecting 'preferredleader' property to be balanced across all shards", collection, (n, c) -> {
        for (Slice slice : c) {
            int count = 0;
            for (Replica replica : slice) {
                if ("true".equals(replica.getStr("property.preferredleader")))
                    count += 1;
            }
            if (count != 1)
                return false;
        }
        return true;
    });
}
Also used : CollectionAdminResponse(org.apache.solr.client.solrj.response.CollectionAdminResponse) Slice(org.apache.solr.common.cloud.Slice) Replica(org.apache.solr.common.cloud.Replica) Test(org.junit.Test)

Example 75 with Replica

use of org.apache.solr.common.cloud.Replica 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

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