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");
}
}
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);
}
}
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);
}
}
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");
}
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);
}
Aggregations