Search in sources :

Example 36 with UpdateResponse

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

Example 37 with UpdateResponse

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());
    }
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrException(org.apache.solr.common.SolrException)

Example 38 with UpdateResponse

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));
        }
    }
}
Also used : UpdateResponse(org.apache.solr.client.solrj.response.UpdateResponse) SolrInputDocument(org.apache.solr.common.SolrInputDocument) SolrDocument(org.apache.solr.common.SolrDocument) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 39 with UpdateResponse

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

Example 40 with UpdateResponse

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

Aggregations

UpdateResponse (org.apache.solr.client.solrj.response.UpdateResponse)47 SolrInputDocument (org.apache.solr.common.SolrInputDocument)20 IOException (java.io.IOException)16 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)16 SolrServerException (org.apache.solr.client.solrj.SolrServerException)15 ArrayList (java.util.ArrayList)10 SolrClient (org.apache.solr.client.solrj.SolrClient)9 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)8 SolrDocument (org.apache.solr.common.SolrDocument)8 NamedList (org.apache.solr.common.util.NamedList)7 SolrException (org.apache.solr.common.SolrException)6 Test (org.junit.Test)6 Future (java.util.concurrent.Future)5 ExecutorService (java.util.concurrent.ExecutorService)4 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)4 DefaultSolrThreadFactory (org.apache.solr.util.DefaultSolrThreadFactory)4 HashMap (java.util.HashMap)3 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)3 SolrException (com.odysseusinc.arachne.portal.model.solr.SolrException)2 MalformedURLException (java.net.MalformedURLException)2