use of org.apache.solr.client.solrj.request.UpdateRequest in project lucene-solr by apache.
the class TestInPlaceUpdatesDistrib method simulatedDeleteRequest.
UpdateRequest simulatedDeleteRequest(String query, long version) throws SolrServerException, IOException {
String baseUrl = getBaseUrl((HttpSolrClient) LEADER);
UpdateRequest ur = new UpdateRequest();
ur.deleteByQuery(query);
ur.setParam("_version_", "" + version);
ur.setParam("update.distrib", "FROMLEADER");
ur.setParam("distrib.from", baseUrl + DEFAULT_COLLECTION + "/");
return ur;
}
use of org.apache.solr.client.solrj.request.UpdateRequest in project lucene-solr by apache.
the class TestInPlaceUpdatesDistrib method reorderedDBQsResurrectionTest.
/* Test for a situation when a document requiring in-place update cannot be "resurrected"
* when the original full indexed document has been deleted by an out of order DBQ.
* Expected behaviour in this case should be to throw the replica into LIR (since this will
* be rare). Here's an example of the situation:
ADD(id=x, val=5, ver=1)
UPD(id=x, val=10, ver = 2)
DBQ(q=val:10, v=4)
DV(id=x, val=5, ver=3)
*/
private void reorderedDBQsResurrectionTest() throws Exception {
if (onlyLeaderIndexes) {
log.info("RTG with DBQs are not working in tlog replicas");
return;
}
clearIndex();
commit();
buildRandomIndex(0);
// RTG straight from the index
SolrDocument sdoc = LEADER.getById("0");
//assertEquals(value, sdoc.get("inplace_updatable_float"));
assertEquals("title0", sdoc.get("title_s"));
long version0 = (long) sdoc.get("_version_");
String field = "inplace_updatable_int";
// put replica out of sync
List<UpdateRequest> updates = new ArrayList<>();
// full update
updates.add(simulatedUpdateRequest(null, "id", 0, "title_s", "title0_new", field, 5, "_version_", version0 + 1));
// inplace_updatable_float=101
updates.add(simulatedUpdateRequest(version0 + 1, "id", 0, field, 10, "_version_", version0 + 2));
// inplace_updatable_float=101
updates.add(simulatedUpdateRequest(version0 + 2, "id", 0, field, 5, "_version_", version0 + 3));
// supposed to not delete anything
updates.add(simulatedDeleteRequest(field + ":10", version0 + 4));
// 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
ExecutorService threadpool = ExecutorUtil.newMDCAwareFixedThreadPool(updates.size() + 1, new DefaultSolrThreadFactory(getTestName()));
// re-order the last two updates for NONLEADER 0
List<UpdateRequest> reorderedUpdates = new ArrayList<>(updates);
Collections.swap(reorderedUpdates, 2, 3);
List<Future<UpdateResponse>> updateResponses = new ArrayList<>();
for (UpdateRequest update : reorderedUpdates) {
// pretend as this update is coming from the other non-leader, so that
// the resurrection can happen from there (instead of the leader)
update.setParam(DistributedUpdateProcessor.DISTRIB_FROM, ((HttpSolrClient) NONLEADERS.get(1)).getBaseURL());
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));
int successful = 0;
for (Future<UpdateResponse> resp : updateResponses) {
try {
UpdateResponse r = resp.get();
if (r.getStatus() == 0) {
successful++;
}
} catch (Exception ex) {
if (!ex.getMessage().contains("Tried to fetch missing update" + " from the leader, but missing wasn't present at leader.")) {
throw ex;
}
}
}
// All should succeed, i.e. no LIR
assertEquals(updateResponses.size(), successful);
log.info("Non leader 0: " + ((HttpSolrClient) NONLEADERS.get(0)).getBaseURL());
log.info("Non leader 1: " + ((HttpSolrClient) NONLEADERS.get(1)).getBaseURL());
SolrDocument doc0 = NONLEADERS.get(0).getById(String.valueOf(0), params("distrib", "false"));
SolrDocument doc1 = NONLEADERS.get(1).getById(String.valueOf(0), params("distrib", "false"));
log.info("Doc in both replica 0: " + doc0);
log.info("Doc in both replica 1: " + doc1);
// assert both replicas have same effect
for (int i = 0; i < NONLEADERS.size(); i++) {
// 0th is re-ordered replica, 1st is well-ordered replica
SolrClient client = NONLEADERS.get(i);
SolrDocument doc = client.getById(String.valueOf(0), params("distrib", "false"));
assertNotNull("Client: " + ((HttpSolrClient) client).getBaseURL(), doc);
assertEquals("Client: " + ((HttpSolrClient) client).getBaseURL(), 5, doc.getFieldValue(field));
}
log.info("reorderedDBQsResurrectionTest: This test passed fine...");
clearIndex();
commit();
}
use of org.apache.solr.client.solrj.request.UpdateRequest in project lucene-solr by apache.
the class TestInPlaceUpdatesDistrib method regularUpdateRequest.
UpdateRequest regularUpdateRequest(Object... fields) throws SolrServerException, IOException {
UpdateRequest ur = new UpdateRequest();
SolrInputDocument doc = sdoc(fields);
ur.add(doc);
return ur;
}
use of org.apache.solr.client.solrj.request.UpdateRequest in project lucene-solr by apache.
the class TestInPlaceUpdatesDistrib method regularDeleteByQueryRequest.
UpdateRequest regularDeleteByQueryRequest(String q) throws SolrServerException, IOException {
UpdateRequest ur = new UpdateRequest();
ur.deleteByQuery(q);
return ur;
}
use of org.apache.solr.client.solrj.request.UpdateRequest in project lucene-solr by apache.
the class TestInPlaceUpdatesDistrib method regularDeleteRequest.
UpdateRequest regularDeleteRequest(int id) throws SolrServerException, IOException {
UpdateRequest ur = new UpdateRequest();
ur.deleteById("" + id);
return ur;
}
Aggregations