Search in sources :

Example 11 with TimeOut

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

the class LeaderFailureAfterFreshStartTest method test.

@Test
public void test() throws Exception {
    handle.clear();
    handle.put("timestamp", SKIPVAL);
    try {
        CloudJettyRunner initialLeaderJetty = shardToLeaderJetty.get("shard1");
        List<CloudJettyRunner> otherJetties = getOtherAvailableJetties(initialLeaderJetty);
        log.info("Leader node_name: {},  url: {}", initialLeaderJetty.coreNodeName, initialLeaderJetty.url);
        for (CloudJettyRunner cloudJettyRunner : otherJetties) {
            log.info("Nonleader node_name: {},  url: {}", cloudJettyRunner.coreNodeName, cloudJettyRunner.url);
        }
        CloudJettyRunner secondNode = otherJetties.get(0);
        CloudJettyRunner freshNode = otherJetties.get(1);
        // shutdown a node to simulate fresh start
        otherJetties.remove(freshNode);
        forceNodeFailures(singletonList(freshNode));
        del("*:*");
        waitForThingsToLevelOut(30);
        checkShardConsistency(false, true);
        // index a few docs and commit
        for (int i = 0; i < 100; i++) {
            indexDoc(id, docId, i1, 50, tlong, 50, t1, "document number " + docId++);
        }
        commit();
        waitForThingsToLevelOut(30);
        checkShardConsistency(false, true);
        // bring down the other node and index a few docs; so the leader and other node segments diverge
        forceNodeFailures(singletonList(secondNode));
        for (int i = 0; i < 10; i++) {
            indexDoc(id, docId, i1, 50, tlong, 50, t1, "document number " + docId++);
            if (i % 2 == 0) {
                commit();
            }
        }
        commit();
        restartNodes(singletonList(secondNode));
        // start the freshNode 
        restartNodes(singletonList(freshNode));
        String replicationProperties = (String) freshNode.jetty.getSolrHome() + "/cores/" + DEFAULT_TEST_COLLECTION_NAME + "/data/replication.properties";
        String md5 = DigestUtils.md5Hex(Files.readAllBytes(Paths.get(replicationProperties)));
        // shutdown the original leader
        log.info("Now shutting down initial leader");
        forceNodeFailures(singletonList(initialLeaderJetty));
        waitForNewLeader(cloudClient, "shard1", (Replica) initialLeaderJetty.client.info, new TimeOut(15, SECONDS));
        waitTillNodesActive();
        log.info("Updating mappings from zk");
        updateMappingsFromZk(jettys, clients, true);
        assertEquals("Node went into replication", md5, DigestUtils.md5Hex(Files.readAllBytes(Paths.get(replicationProperties))));
        success = true;
    } finally {
        System.clearProperty("solr.disableFingerprint");
    }
}
Also used : TimeOut(org.apache.solr.util.TimeOut) Test(org.junit.Test)

Example 12 with TimeOut

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

the class AbstractFullDistribZkTestBase method checkForCollection.

protected void checkForCollection(String collectionName, List<Integer> numShardsNumReplicaList, List<String> nodesAllowedToRunShards) throws Exception {
    // check for an expectedSlices new collection - we poll the state
    final TimeOut timeout = new TimeOut(120, TimeUnit.SECONDS);
    boolean success = false;
    String checkResult = "Didnt get to perform a single check";
    while (!timeout.hasTimedOut()) {
        checkResult = checkCollectionExpectations(collectionName, numShardsNumReplicaList, nodesAllowedToRunShards);
        if (checkResult == null) {
            success = true;
            break;
        }
        Thread.sleep(500);
    }
    if (!success) {
        super.printLayout();
        fail(checkResult);
    }
}
Also used : TimeOut(org.apache.solr.util.TimeOut)

Example 13 with TimeOut

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

the class OneQuery method progress.

static synchronized void progress(int myId, String core) {
    if (nextTimeout.hasTimedOut()) {
        log.info(String.format(Locale.ROOT, " s indexed: [run %,8d] [cycle %,8d] [last minute %,8d] Last core updated: %s. Seconds left in cycle %,4d", myId, docsThisCycle.get(), myId - lastCount, core, stopTimeout.timeLeft(TimeUnit.SECONDS)));
        lastCount = myId;
        nextTimeout = new TimeOut(60, TimeUnit.SECONDS);
    }
}
Also used : TimeOut(org.apache.solr.util.TimeOut)

Example 14 with TimeOut

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

the class SolrExampleTestsBase method testCommitWithinOnDelete.

@Test
public void testCommitWithinOnDelete() throws Exception {
    // make sure it is empty...
    SolrClient client = getSolrClient();
    // delete everything!
    client.deleteByQuery("*:*");
    client.commit();
    QueryResponse rsp = client.query(new SolrQuery("*:*"));
    Assert.assertEquals(0, rsp.getResults().getNumFound());
    // Now add one document...
    SolrInputDocument doc3 = new SolrInputDocument();
    doc3.addField("id", "id3");
    doc3.addField("name", "doc3");
    doc3.addField("price", 10);
    client.add(doc3);
    client.commit();
    // now check that it comes out...
    rsp = client.query(new SolrQuery("id:id3"));
    Assert.assertEquals(1, rsp.getResults().getNumFound());
    // now test commitWithin on a delete
    UpdateRequest up = new UpdateRequest();
    up.setCommitWithin(1000);
    up.deleteById("id3");
    up.process(client);
    // the document should still be there
    rsp = client.query(new SolrQuery("id:id3"));
    Assert.assertEquals(1, rsp.getResults().getNumFound());
    // check if the doc has been deleted every 250 ms for 30 seconds
    TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS);
    do {
        // wait 250 ms
        Thread.sleep(250);
        rsp = client.query(new SolrQuery("id:id3"));
        if (rsp.getResults().getNumFound() == 0) {
            return;
        }
    } while (!timeout.hasTimedOut());
    Assert.fail("commitWithin failed to commit");
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) TimeOut(org.apache.solr.util.TimeOut) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) Test(org.junit.Test)

Example 15 with TimeOut

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

the class TestTlogReplica method doReplaceLeader.

/*
   * validate leader election and that replication still happens on a new leader
   */
private void doReplaceLeader(boolean removeReplica) throws Exception {
    DocCollection docCollection = createAndWaitForCollection(1, 0, 2, 0);
    // Add a document and commit
    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());
    }
    waitForNumDocsInAllReplicas(1, docCollection.getReplicas(EnumSet.of(Replica.Type.TLOG)), REPLICATION_TIMEOUT_SECS);
    // Delete leader replica from shard1
    JettySolrRunner leaderJetty = null;
    if (removeReplica) {
        CollectionAdminRequest.deleteReplica(collectionName, "shard1", s.getLeader().getName()).process(cluster.getSolrClient());
    } else {
        leaderJetty = cluster.getReplicaJetty(s.getLeader());
        ChaosMonkey.kill(leaderJetty);
        waitForState("Leader replica not removed", collectionName, clusterShape(1, 1));
        // Wait for cluster state to be updated
        waitForState("Replica state not updated in cluster state", collectionName, clusterStateReflectsActiveAndDownReplicas());
    }
    docCollection = assertNumberOfReplicas(0, 1, 0, true, true);
    // Wait until a new leader is elected
    TimeOut t = new TimeOut(30, TimeUnit.SECONDS);
    while (!t.hasTimedOut()) {
        docCollection = getCollectionState(collectionName);
        Replica leader = docCollection.getSlice("shard1").getLeader();
        if (leader != null && leader.isActive(cluster.getSolrClient().getZkStateReader().getClusterState().getLiveNodes())) {
            break;
        }
        Thread.sleep(500);
    }
    assertFalse("Timeout waiting for a new leader to be elected", t.hasTimedOut());
    // There is a new leader, I should be able to add and commit
    cluster.getSolrClient().add(collectionName, new SolrInputDocument("id", "2", "foo", "zoo"));
    cluster.getSolrClient().commit(collectionName);
    // Queries should still work
    waitForNumDocsInAllReplicas(2, docCollection.getReplicas(EnumSet.of(Replica.Type.TLOG)), REPLICATION_TIMEOUT_SECS);
    // Start back the node
    if (removeReplica) {
        CollectionAdminRequest.addReplicaToShard(collectionName, "shard1", Replica.Type.TLOG).process(cluster.getSolrClient());
    } else {
        ChaosMonkey.start(leaderJetty);
    }
    waitForState("Expected collection to be 1x2", collectionName, clusterShape(1, 2));
    // added replica should replicate from the leader
    waitForNumDocsInAllReplicas(2, docCollection.getReplicas(EnumSet.of(Replica.Type.TLOG)), REPLICATION_TIMEOUT_SECS);
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrInputDocument(org.apache.solr.common.SolrInputDocument) Slice(org.apache.solr.common.cloud.Slice) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) TimeOut(org.apache.solr.util.TimeOut) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

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