Search in sources :

Example 1 with SplitShard

use of org.apache.solr.client.solrj.request.CollectionAdminRequest.SplitShard in project lucene-solr by apache.

the class MultiThreadedOCPTest method testLongAndShortRunningParallelApiCalls.

private void testLongAndShortRunningParallelApiCalls() throws InterruptedException, IOException, SolrServerException {
    Thread indexThread = new Thread() {

        @Override
        public void run() {
            Random random = random();
            int max = atLeast(random, 200);
            for (int id = 101; id < max; id++) {
                try {
                    doAddDoc(String.valueOf(id));
                } catch (Exception e) {
                    log.error("Exception while adding docs", e);
                }
            }
        }
    };
    indexThread.start();
    try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
        SplitShard splitShardRequest = CollectionAdminRequest.splitShard("collection1").setShardName(SHARD1);
        splitShardRequest.processAsync("2000", client);
        RequestStatusState state = getRequestState("2000", client);
        while (state == RequestStatusState.SUBMITTED) {
            state = getRequestState("2000", client);
            Thread.sleep(10);
        }
        assertSame("SplitShard task [2000] was supposed to be in [running] but isn't. It is [" + state + "]", RequestStatusState.RUNNING, state);
        // CLUSTERSTATE is always mutually exclusive, it should return with a response before the split completes
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
        params.set("collection", "collection1");
        SolrRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        client.request(request);
        state = getRequestState("2000", client);
        assertSame("After invoking OVERSEERSTATUS, SplitShard task [2000] was still supposed to be in [running] but " + "isn't. It is [" + state + "]", RequestStatusState.RUNNING, state);
    } finally {
        try {
            indexThread.join();
        } catch (InterruptedException e) {
            log.warn("Indexing thread interrupted.");
        }
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Random(java.util.Random) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SplitShard(org.apache.solr.client.solrj.request.CollectionAdminRequest.SplitShard) RequestStatusState(org.apache.solr.client.solrj.response.RequestStatusState) SolrRequest(org.apache.solr.client.solrj.SolrRequest) IOException(java.io.IOException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 2 with SplitShard

use of org.apache.solr.client.solrj.request.CollectionAdminRequest.SplitShard in project lucene-solr by apache.

the class MultiThreadedOCPTest method testDeduplicationOfSubmittedTasks.

private void testDeduplicationOfSubmittedTasks() throws IOException, SolrServerException {
    try (SolrClient client = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)))) {
        CollectionAdminRequest.createCollection("ocptest_shardsplit2", "conf1", 4, 1).processAsync("3000", client);
        SplitShard splitShardRequest = CollectionAdminRequest.splitShard("ocptest_shardsplit2").setShardName(SHARD1);
        splitShardRequest.processAsync("3001", client);
        splitShardRequest = CollectionAdminRequest.splitShard("ocptest_shardsplit2").setShardName(SHARD2);
        splitShardRequest.processAsync("3002", client);
        // Now submit another task with the same id. At this time, hopefully the previous 3002 should still be in the queue.
        expectThrows(SolrServerException.class, () -> {
            CollectionAdminRequest.splitShard("ocptest_shardsplit2").setShardName(SHARD1).processAsync("3002", client);
            // more helpful assertion failure
            fail("Duplicate request was supposed to exist but wasn't found. De-duplication of submitted task failed.");
        });
        for (int i = 3001; i <= 3002; i++) {
            final RequestStatusState state = getRequestStateAfterCompletion(i + "", REQUEST_STATUS_TIMEOUT, client);
            assertSame("Task " + i + " did not complete, final state: " + state, RequestStatusState.COMPLETED, state);
        }
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SplitShard(org.apache.solr.client.solrj.request.CollectionAdminRequest.SplitShard) RequestStatusState(org.apache.solr.client.solrj.response.RequestStatusState)

Aggregations

SolrClient (org.apache.solr.client.solrj.SolrClient)2 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)2 SplitShard (org.apache.solr.client.solrj.request.CollectionAdminRequest.SplitShard)2 RequestStatusState (org.apache.solr.client.solrj.response.RequestStatusState)2 IOException (java.io.IOException)1 Random (java.util.Random)1 SolrRequest (org.apache.solr.client.solrj.SolrRequest)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)1 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)1