use of org.apache.solr.client.solrj.response.RequestStatusState in project lucene-solr by apache.
the class DeleteStatusTest method testProcessAndWaitDeletesAsyncIds.
@Test
public void testProcessAndWaitDeletesAsyncIds() throws IOException, SolrServerException, InterruptedException {
final CloudSolrClient client = cluster.getSolrClient();
RequestStatusState state = CollectionAdminRequest.createCollection("requeststatus", "conf1", 1, 1).processAndWait("request1", client, MAX_WAIT_TIMEOUT);
assertSame(RequestStatusState.COMPLETED, state);
// using processAndWait deletes the requestid
state = CollectionAdminRequest.requestStatus("request1").process(client).getRequestStatus();
assertSame("Request id was not deleted by processAndWait call", RequestStatusState.NOT_FOUND, state);
}
use of org.apache.solr.client.solrj.response.RequestStatusState in project lucene-solr by apache.
the class DeleteStatusTest method waitForRequestState.
// Basically equivalent to RequestStatus.waitFor(), but doesn't delete the id from the queue
private static RequestStatusState waitForRequestState(String id, SolrClient client, int timeout) throws IOException, SolrServerException, InterruptedException {
RequestStatusState state = RequestStatusState.SUBMITTED;
long endTime = System.nanoTime() + TimeUnit.SECONDS.toNanos(MAX_WAIT_TIMEOUT);
while (System.nanoTime() < endTime) {
state = CollectionAdminRequest.requestStatus(id).process(client).getRequestStatus();
if (state == RequestStatusState.COMPLETED)
break;
assumeTrue("Error creating collection - skipping test", state != RequestStatusState.FAILED);
TimeUnit.SECONDS.sleep(1);
}
assumeTrue("Timed out creating collection - skipping test", state == RequestStatusState.COMPLETED);
return state;
}
use of org.apache.solr.client.solrj.response.RequestStatusState in project lucene-solr by apache.
the class ShardSplitTest method testSplitStaticIndexReplication.
/*
Creates a collection with replicationFactor=1, splits a shard. Restarts the sub-shard leader node.
Add a replica. Ensure count matches in leader and replica.
*/
public void testSplitStaticIndexReplication() throws Exception {
waitForThingsToLevelOut(15);
DocCollection defCol = cloudClient.getZkStateReader().getClusterState().getCollection(AbstractDistribZkTestBase.DEFAULT_COLLECTION);
Replica replica = defCol.getReplicas().get(0);
String nodeName = replica.getNodeName();
String collectionName = "testSplitStaticIndexReplication";
CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName, "conf1", 1, 1);
// some high number so we can create replicas without hindrance
create.setMaxShardsPerNode(5);
// we want to create the leader on a fixed node so that we know which one to restart later
create.setCreateNodeSet(nodeName);
create.process(cloudClient);
try (CloudSolrClient client = getCloudSolrClient(zkServer.getZkAddress(), true, cloudClient.getLbClient().getHttpClient())) {
client.setDefaultCollection(collectionName);
StoppableIndexingThread thread = new StoppableIndexingThread(controlClient, client, "i1", true);
try {
thread.start();
// give the indexer sometime to do its work
Thread.sleep(1000);
thread.safeStop();
thread.join();
client.commit();
controlClient.commit();
CollectionAdminRequest.SplitShard splitShard = CollectionAdminRequest.splitShard(collectionName);
splitShard.setShardName(SHARD1);
String asyncId = splitShard.processAsync(client);
RequestStatusState state = CollectionAdminRequest.requestStatus(asyncId).waitFor(client, 120);
if (state == RequestStatusState.COMPLETED) {
waitForRecoveriesToFinish(collectionName, true);
// let's wait to see parent shard become inactive
CountDownLatch latch = new CountDownLatch(1);
client.getZkStateReader().registerCollectionStateWatcher(collectionName, new CollectionStateWatcher() {
@Override
public boolean onStateChanged(Set<String> liveNodes, DocCollection collectionState) {
Slice parent = collectionState.getSlice(SHARD1);
Slice slice10 = collectionState.getSlice(SHARD1_0);
Slice slice11 = collectionState.getSlice(SHARD1_1);
if (slice10 != null && slice11 != null && parent.getState() == Slice.State.INACTIVE && slice10.getState() == Slice.State.ACTIVE && slice11.getState() == Slice.State.ACTIVE) {
latch.countDown();
// removes the watch
return true;
}
return false;
}
});
latch.await(1, TimeUnit.MINUTES);
if (latch.getCount() != 0) {
// sanity check
fail("Sub-shards did not become active even after waiting for 1 minute");
}
int liveNodeCount = client.getZkStateReader().getClusterState().getLiveNodes().size();
// restart the sub-shard leader node
boolean restarted = false;
for (JettySolrRunner jetty : jettys) {
int port = jetty.getBaseUrl().getPort();
if (replica.getStr(BASE_URL_PROP).contains(":" + port)) {
ChaosMonkey.kill(jetty);
ChaosMonkey.start(jetty);
restarted = true;
break;
}
}
if (!restarted) {
// sanity check
fail("We could not find a jetty to kill for replica: " + replica.getCoreUrl());
}
// add a new replica for the sub-shard
CollectionAdminRequest.AddReplica addReplica = CollectionAdminRequest.addReplicaToShard(collectionName, SHARD1_0);
// use control client because less chances of it being the node being restarted
// this is to avoid flakiness of test because of NoHttpResponseExceptions
String control_collection = client.getZkStateReader().getClusterState().getCollection("control_collection").getReplicas().get(0).getStr(BASE_URL_PROP);
try (HttpSolrClient control = new HttpSolrClient.Builder(control_collection).withHttpClient(client.getLbClient().getHttpClient()).build()) {
state = addReplica.processAndWait(control, 30);
}
if (state == RequestStatusState.COMPLETED) {
CountDownLatch newReplicaLatch = new CountDownLatch(1);
client.getZkStateReader().registerCollectionStateWatcher(collectionName, new CollectionStateWatcher() {
@Override
public boolean onStateChanged(Set<String> liveNodes, DocCollection collectionState) {
if (liveNodes.size() != liveNodeCount) {
return false;
}
Slice slice = collectionState.getSlice(SHARD1_0);
if (slice.getReplicas().size() == 2) {
if (!slice.getReplicas().stream().anyMatch(r -> r.getState() == Replica.State.RECOVERING)) {
// we see replicas and none of them are recovering
newReplicaLatch.countDown();
return true;
}
}
return false;
}
});
newReplicaLatch.await(30, TimeUnit.SECONDS);
// check consistency of sub-shard replica explicitly because checkShardConsistency methods doesn't
// handle new shards/replica so well.
ClusterState clusterState = client.getZkStateReader().getClusterState();
DocCollection collection = clusterState.getCollection(collectionName);
int numReplicasChecked = assertConsistentReplicas(collection.getSlice(SHARD1_0));
assertEquals("We should have checked consistency for exactly 2 replicas of shard1_0", 2, numReplicasChecked);
} else {
fail("Adding a replica to sub-shard did not complete even after waiting for 30 seconds!. Saw state = " + state.getKey());
}
} else {
fail("We expected shard split to succeed on a static index but it didn't. Found state = " + state.getKey());
}
} finally {
thread.safeStop();
thread.join();
}
}
}
use of org.apache.solr.client.solrj.response.RequestStatusState in project lucene-solr by apache.
the class CollectionsAPIAsyncDistributedZkTest method testSolrJAPICalls.
@Test
public void testSolrJAPICalls() throws Exception {
final CloudSolrClient client = cluster.getSolrClient();
RequestStatusState state = CollectionAdminRequest.createCollection("testasynccollectioncreation", "conf1", 1, 1).processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("CreateCollection task did not complete!", RequestStatusState.COMPLETED, state);
state = CollectionAdminRequest.createCollection("testasynccollectioncreation", "conf1", 1, 1).processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("Recreating a collection with the same should have failed.", RequestStatusState.FAILED, state);
state = CollectionAdminRequest.addReplicaToShard("testasynccollectioncreation", "shard1").processAndWait(client, MAX_TIMEOUT_SECONDS);
assertSame("Add replica did not complete", RequestStatusState.COMPLETED, state);
state = CollectionAdminRequest.splitShard("testasynccollectioncreation").setShardName("shard1").processAndWait(client, MAX_TIMEOUT_SECONDS * 2);
assertEquals("Shard split did not complete. Last recorded state: " + state, RequestStatusState.COMPLETED, state);
}
use of org.apache.solr.client.solrj.response.RequestStatusState in project lucene-solr by apache.
the class AbstractFullDistribZkTestBase method getRequestStateAfterCompletion.
static RequestStatusState getRequestStateAfterCompletion(String requestId, int waitForSeconds, SolrClient client) throws IOException, SolrServerException {
RequestStatusState state = null;
final TimeOut timeout = new TimeOut(waitForSeconds, TimeUnit.SECONDS);
while (!timeout.hasTimedOut()) {
state = getRequestState(requestId, client);
if (state == RequestStatusState.COMPLETED || state == RequestStatusState.FAILED) {
return state;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
return state;
}
Aggregations