Search in sources :

Example 16 with TimeOut

use of org.apache.solr.util.TimeOut in project lucene-solr by apache.

the class TestPullReplicaErrorHandling method assertNumDocs.

private void assertNumDocs(int numDocs, SolrClient client, int timeoutSecs) throws InterruptedException, SolrServerException, IOException {
    TimeOut t = new TimeOut(timeoutSecs, TimeUnit.SECONDS);
    long numFound = -1;
    while (!t.hasTimedOut()) {
        Thread.sleep(200);
        numFound = client.query(new SolrQuery("*:*")).getResults().getNumFound();
        if (numFound == numDocs) {
            return;
        }
    }
    fail("Didn't get expected doc count. Expected: " + numDocs + ", Found: " + numFound);
}
Also used : TimeOut(org.apache.solr.util.TimeOut) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 17 with TimeOut

use of org.apache.solr.util.TimeOut in project lucene-solr by apache.

the class TestTlogReplica method testAddDocs.

@SuppressWarnings("unchecked")
public void testAddDocs() throws Exception {
    int numTlogReplicas = 1 + random().nextInt(3);
    DocCollection docCollection = createAndWaitForCollection(1, 0, numTlogReplicas, 0);
    assertEquals(1, docCollection.getSlices().size());
    cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "1", "foo", "bar"));
    cluster.getSolrClient().commit(collectionName);
    Slice s = docCollection.getSlices().iterator().next();
    try (HttpSolrClient leaderClient = getHttpSolrClient(s.getLeader().getCoreUrl())) {
        assertEquals(1, leaderClient.query(new SolrQuery("*:*")).getResults().getNumFound());
    }
    TimeOut t = new TimeOut(REPLICATION_TIMEOUT_SECS, TimeUnit.SECONDS);
    for (Replica r : s.getReplicas(EnumSet.of(Replica.Type.TLOG))) {
        //TODO: assert replication < REPLICATION_TIMEOUT_SECS
        try (HttpSolrClient tlogReplicaClient = getHttpSolrClient(r.getCoreUrl())) {
            while (true) {
                try {
                    assertEquals("Replica " + r.getName() + " not up to date after 10 seconds", 1, tlogReplicaClient.query(new SolrQuery("*:*")).getResults().getNumFound());
                    // Append replicas process all updates
                    SolrQuery req = new SolrQuery("qt", "/admin/plugins", "stats", "true");
                    QueryResponse statsResponse = tlogReplicaClient.query(req);
                    assertEquals("Append replicas should recive all updates. Replica: " + r + ", response: " + statsResponse, 1L, ((Map<String, Object>) ((NamedList<Object>) statsResponse.getResponse()).findRecursive("plugins", "UPDATE", "updateHandler", "stats")).get("UPDATE.updateHandler.cumulativeAdds.count"));
                    break;
                } catch (AssertionError e) {
                    if (t.hasTimedOut()) {
                        throw e;
                    } else {
                        Thread.sleep(100);
                    }
                }
            }
        }
    }
    assertUlogPresence(docCollection);
}
Also used : TimeOut(org.apache.solr.util.TimeOut) NamedList(org.apache.solr.common.util.NamedList) Replica(org.apache.solr.common.cloud.Replica) SolrQuery(org.apache.solr.client.solrj.SolrQuery) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrInputDocument(org.apache.solr.common.SolrInputDocument) Slice(org.apache.solr.common.cloud.Slice) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) DocCollection(org.apache.solr.common.cloud.DocCollection)

Example 18 with TimeOut

use of org.apache.solr.util.TimeOut in project lucene-solr by apache.

the class TestRebalanceLeaders method waitForAllPreferreds.

boolean waitForAllPreferreds() throws KeeperException, InterruptedException {
    boolean goAgain = true;
    TimeOut timeout = new TimeOut(timeoutMs, TimeUnit.MILLISECONDS);
    while (!timeout.hasTimedOut()) {
        goAgain = false;
        Map<String, Slice> slices = cloudClient.getZkStateReader().getClusterState().getCollection(COLLECTION_NAME).getSlicesMap();
        for (Map.Entry<String, Replica> ent : expected.entrySet()) {
            Replica me = slices.get(ent.getKey()).getReplica(ent.getValue().getName());
            if (me.getBool("property.preferredleader", false) == false) {
                goAgain = true;
                break;
            }
        }
        if (goAgain) {
            Thread.sleep(250);
        } else {
            return true;
        }
    }
    return false;
}
Also used : TimeOut(org.apache.solr.util.TimeOut) Slice(org.apache.solr.common.cloud.Slice) HashMap(java.util.HashMap) Map(java.util.Map) Replica(org.apache.solr.common.cloud.Replica)

Example 19 with TimeOut

use of org.apache.solr.util.TimeOut in project lucene-solr by apache.

the class TestRebalanceLeaders method checkConsistency.

// After we've called the rebalance command, we want to insure that:
// 1> all replicas appear once and only once in the respective leader election queue
// 2> All the replicas we _think_ are leaders are in the 0th position in the leader election queue.
// 3> The node that ZooKeeper thinks is the leader is the one we think should be the leader.
void checkConsistency() throws InterruptedException, KeeperException {
    TimeOut timeout = new TimeOut(timeoutMs, TimeUnit.MILLISECONDS);
    boolean checkAppearOnce = false;
    boolean checkElectionZero = false;
    boolean checkZkLeadersAgree = false;
    while (!timeout.hasTimedOut()) {
        checkAppearOnce = checkAppearOnce();
        checkElectionZero = checkElectionZero();
        checkZkLeadersAgree = checkZkLeadersAgree();
        if (checkAppearOnce && checkElectionZero && checkZkLeadersAgree) {
            return;
        }
        Thread.sleep(1000);
    }
    fail("Checking the rebalance leader command failed, checkAppearOnce=" + checkAppearOnce + " checkElectionZero=" + checkElectionZero + " checkZkLeadersAgree=" + checkZkLeadersAgree);
}
Also used : TimeOut(org.apache.solr.util.TimeOut)

Example 20 with TimeOut

use of org.apache.solr.util.TimeOut in project lucene-solr by apache.

the class TestPullReplica method waitForDeletion.

private void waitForDeletion(String collection) throws InterruptedException, KeeperException {
    TimeOut t = new TimeOut(10, TimeUnit.SECONDS);
    while (cluster.getSolrClient().getZkStateReader().getClusterState().hasCollection(collection)) {
        LOG.info("Collection not yet deleted");
        try {
            Thread.sleep(100);
            if (t.hasTimedOut()) {
                fail("Timed out waiting for collection " + collection + " to be deleted.");
            }
            cluster.getSolrClient().getZkStateReader().forceUpdateCollection(collection);
        } catch (SolrException e) {
            return;
        }
    }
}
Also used : TimeOut(org.apache.solr.util.TimeOut) SolrException(org.apache.solr.common.SolrException)

Aggregations

TimeOut (org.apache.solr.util.TimeOut)48 SolrException (org.apache.solr.common.SolrException)15 Slice (org.apache.solr.common.cloud.Slice)15 DocCollection (org.apache.solr.common.cloud.DocCollection)14 Replica (org.apache.solr.common.cloud.Replica)13 SolrQuery (org.apache.solr.client.solrj.SolrQuery)11 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)8 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)8 HashMap (java.util.HashMap)7 Test (org.junit.Test)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 SolrInputDocument (org.apache.solr.common.SolrInputDocument)6 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)6 NamedList (org.apache.solr.common.util.NamedList)6 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)5 Map (java.util.Map)4 SolrServerException (org.apache.solr.client.solrj.SolrServerException)4 Collections.singletonList (java.util.Collections.singletonList)3 HashSet (java.util.HashSet)3