use of org.apache.solr.client.solrj.response.UpdateResponse in project lucene-solr by apache.
the class CdcrReplicator method sendRequest.
private void sendRequest(UpdateRequest req) throws IOException, SolrServerException, CdcrReplicatorException {
UpdateResponse rsp = req.process(state.getClient());
if (rsp.getStatus() != 0) {
throw new CdcrReplicatorException(req, rsp);
}
state.resetConsecutiveErrors();
}
use of org.apache.solr.client.solrj.response.UpdateResponse in project lucene-solr by apache.
the class TestCloudDeleteByQuery method testMalformedDBQ.
public void testMalformedDBQ(SolrClient client) throws Exception {
assertNotNull("client not initialized", client);
try {
UpdateResponse rsp = update(params()).deleteByQuery("foo_i:not_a_num").process(client);
fail("Expected DBQ failure: " + rsp.toString());
} catch (SolrException e) {
assertEquals("not the expected DBQ failure: " + e.getMessage(), 400, e.code());
}
}
use of org.apache.solr.client.solrj.response.UpdateResponse in project lucene-solr by apache.
the class BasicDistributedZkTest method testUpdateProcessorsRunOnlyOnce.
/**
* Expects a RegexReplaceProcessorFactories in the chain which will
* "double up" the values in two (stored) string fields.
* <p>
* If the values are "double-doubled" or "not-doubled" then we know
* the processor was not run the appropriate number of times
* </p>
*/
private void testUpdateProcessorsRunOnlyOnce(final String chain) throws Exception {
final String fieldA = "regex_dup_A_s";
final String fieldB = "regex_dup_B_s";
final String val = "x";
final String expected = "x_x";
final ModifiableSolrParams updateParams = new ModifiableSolrParams();
updateParams.add(UpdateParams.UPDATE_CHAIN, chain);
final int numLoops = atLeast(50);
for (int i = 1; i < numLoops; i++) {
// add doc to random client
SolrClient updateClient = clients.get(random().nextInt(clients.size()));
SolrInputDocument doc = new SolrInputDocument();
addFields(doc, id, i, fieldA, val, fieldB, val);
UpdateResponse ures = add(updateClient, updateParams, doc);
assertEquals(chain + ": update failed", 0, ures.getStatus());
ures = updateClient.commit();
assertEquals(chain + ": commit failed", 0, ures.getStatus());
}
// query for each doc, and check both fields to ensure the value is correct
for (int i = 1; i < numLoops; i++) {
final String query = id + ":" + i;
QueryResponse qres = queryServer(new SolrQuery(query));
assertEquals(chain + ": query failed: " + query, 0, qres.getStatus());
assertEquals(chain + ": didn't find correct # docs with query: " + query, 1, qres.getResults().getNumFound());
SolrDocument doc = qres.getResults().get(0);
for (String field : new String[] { fieldA, fieldB }) {
assertEquals(chain + ": doc#" + i + " has wrong value for " + field, expected, doc.getFirstValue(field));
}
}
}
use of org.apache.solr.client.solrj.response.UpdateResponse in project lucene-solr by apache.
the class TestInPlaceUpdatesDistrib method reorderedDBQIndividualReplicaTest.
private void reorderedDBQIndividualReplicaTest() throws Exception {
if (onlyLeaderIndexes) {
log.info("RTG with DBQs are not working in tlog replicas");
return;
}
clearIndex();
commit();
// put replica out of sync
float newinplace_updatable_float = 100;
long version0 = 2000;
List<UpdateRequest> updates = new ArrayList<>();
updates.add(simulatedUpdateRequest(null, "id", 0, "title_s", "title0_new", "inplace_updatable_float", newinplace_updatable_float, "_version_", // full update
version0 + 1));
updates.add(simulatedUpdateRequest(version0 + 1, "id", 0, "inplace_updatable_float", newinplace_updatable_float + 1, "_version_", // inplace_updatable_float=101
version0 + 2));
updates.add(simulatedDeleteRequest("inplace_updatable_float:" + (newinplace_updatable_float + 1), version0 + 3));
// Reordering needs to happen using parallel threads
ExecutorService threadpool = ExecutorUtil.newMDCAwareFixedThreadPool(updates.size() + 1, new DefaultSolrThreadFactory(getTestName()));
// re-order the updates by swapping the last two
List<UpdateRequest> reorderedUpdates = new ArrayList<>(updates);
reorderedUpdates.set(1, updates.get(2));
reorderedUpdates.set(2, updates.get(1));
List<Future<UpdateResponse>> updateResponses = new ArrayList<>();
for (UpdateRequest update : reorderedUpdates) {
AsyncUpdateWithRandomCommit task = new AsyncUpdateWithRandomCommit(update, NONLEADERS.get(0), random().nextLong());
updateResponses.add(threadpool.submit(task));
// while we can't guarantee/trust what order the updates are executed in, since multiple threads
// are involved, but we're trying to bias the thread scheduling to run them in the order submitted
Thread.sleep(100);
}
threadpool.shutdown();
assertTrue("Thread pool didn't terminate within 15 secs", threadpool.awaitTermination(15, TimeUnit.SECONDS));
// assert all requests were successful
for (Future<UpdateResponse> resp : updateResponses) {
assertEquals(0, resp.get().getStatus());
}
SolrDocument doc = NONLEADERS.get(0).getById(String.valueOf(0), params("distrib", "false"));
assertNull("This doc was supposed to have been deleted, but was: " + doc, doc);
log.info("reorderedDBQIndividualReplicaTest: This test passed fine...");
clearIndex();
commit();
}
use of org.apache.solr.client.solrj.response.UpdateResponse in project lucene-solr by apache.
the class TestInPlaceUpdatesDistrib method outOfOrderUpdatesIndividualReplicaTest.
private void outOfOrderUpdatesIndividualReplicaTest() throws Exception {
clearIndex();
commit();
buildRandomIndex(0);
float inplace_updatable_float = 1;
// update doc, set
index("id", 0, "inplace_updatable_float", map("set", inplace_updatable_float));
LEADER.commit();
// RTG straight from the index
SolrDocument sdoc = LEADER.getById("0");
assertEquals(inplace_updatable_float, sdoc.get("inplace_updatable_float"));
assertEquals("title0", sdoc.get("title_s"));
long version0 = (long) sdoc.get("_version_");
// put replica out of sync
float newinplace_updatable_float = 100;
List<UpdateRequest> updates = new ArrayList<>();
// full update
updates.add(simulatedUpdateRequest(null, "id", 0, "title_s", "title0_new", "inplace_updatable_float", newinplace_updatable_float, "_version_", version0 + 1));
for (int i = 1; i < atLeast(3); i++) {
updates.add(simulatedUpdateRequest(version0 + i, "id", 0, "inplace_updatable_float", newinplace_updatable_float + i, "_version_", version0 + i + 1));
}
// order the updates correctly for NONLEADER 1
for (UpdateRequest update : updates) {
log.info("Issuing well ordered update: " + update.getDocuments());
NONLEADERS.get(1).request(update);
}
// Reordering needs to happen using parallel threads, since some of these updates will
// be blocking calls, waiting for some previous updates to arrive on which it depends.
ExecutorService threadpool = ExecutorUtil.newMDCAwareFixedThreadPool(updates.size() + 1, new DefaultSolrThreadFactory(getTestName()));
// re-order the updates for NONLEADER 0
List<UpdateRequest> reorderedUpdates = new ArrayList<>(updates);
Collections.shuffle(reorderedUpdates, r);
List<Future<UpdateResponse>> updateResponses = new ArrayList<>();
for (UpdateRequest update : reorderedUpdates) {
AsyncUpdateWithRandomCommit task = new AsyncUpdateWithRandomCommit(update, NONLEADERS.get(0), random().nextLong());
updateResponses.add(threadpool.submit(task));
// while we can't guarantee/trust what order the updates are executed in, since multiple threads
// are involved, but we're trying to bias the thread scheduling to run them in the order submitted
Thread.sleep(10);
}
threadpool.shutdown();
assertTrue("Thread pool didn't terminate within 15 secs", threadpool.awaitTermination(15, TimeUnit.SECONDS));
// assert all requests were successful
for (Future<UpdateResponse> resp : updateResponses) {
assertEquals(0, resp.get().getStatus());
}
// assert both replicas have same effect
for (SolrClient client : NONLEADERS) {
// 0th is re-ordered replica, 1st is well-ordered replica
log.info("Testing client: " + ((HttpSolrClient) client).getBaseURL());
assertReplicaValue(client, 0, "inplace_updatable_float", (newinplace_updatable_float + (float) (updates.size() - 1)), "inplace_updatable_float didn't match for replica at client: " + ((HttpSolrClient) client).getBaseURL());
assertReplicaValue(client, 0, "title_s", "title0_new", "Title didn't match for replica at client: " + ((HttpSolrClient) client).getBaseURL());
assertEquals(version0 + updates.size(), getReplicaValue(client, 0, "_version_"));
}
log.info("outOfOrderUpdatesIndividualReplicaTest: This test passed fine...");
}
Aggregations