Search in sources :

Example 91 with UpdateRequest

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;
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest)

Example 92 with UpdateRequest

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();
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) ArrayList(java.util.ArrayList) DefaultSolrThreadFactory(org.apache.solr.util.DefaultSolrThreadFactory) SolrServerException(org.apache.solr.client.solrj.SolrServerException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrDocument(org.apache.solr.common.SolrDocument) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future)

Example 93 with UpdateRequest

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;
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest)

Example 94 with UpdateRequest

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;
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest)

Example 95 with UpdateRequest

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;
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest)

Aggregations

UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)276 Test (org.junit.Test)151 Tuple (org.apache.solr.client.solrj.io.Tuple)114 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)89 SolrClientCache (org.apache.solr.client.solrj.io.SolrClientCache)88 SolrInputDocument (org.apache.solr.common.SolrInputDocument)76 StreamFactory (org.apache.solr.client.solrj.io.stream.expr.StreamFactory)64 ArrayList (java.util.ArrayList)38 StreamExpression (org.apache.solr.client.solrj.io.stream.expr.StreamExpression)36 IOException (java.io.IOException)30 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)26 SolrParams (org.apache.solr.common.params.SolrParams)26 SolrQuery (org.apache.solr.client.solrj.SolrQuery)24 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)23 AbstractUpdateRequest (org.apache.solr.client.solrj.request.AbstractUpdateRequest)22 HashMap (java.util.HashMap)21 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)21 FieldComparator (org.apache.solr.client.solrj.io.comp.FieldComparator)21 SolrServerException (org.apache.solr.client.solrj.SolrServerException)20 List (java.util.List)19