Search in sources :

Example 6 with CloudSolrClient

use of org.apache.solr.client.solrj.impl.CloudSolrClient in project lucene-solr by apache.

the class BaseCdcrDistributedZkTest method waitForRecoveriesToFinish.

private void waitForRecoveriesToFinish(String collection, boolean verbose) throws Exception {
    CloudSolrClient client = this.createCloudClient(null);
    try {
        client.connect();
        ZkStateReader zkStateReader = client.getZkStateReader();
        super.waitForRecoveriesToFinish(collection, zkStateReader, verbose);
    } finally {
        client.close();
    }
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 7 with CloudSolrClient

use of org.apache.solr.client.solrj.impl.CloudSolrClient in project lucene-solr by apache.

the class CdcrBootstrapTest method testConvertClusterToCdcrAndBootstrap.

/**
   * Starts a source cluster with no CDCR configuration, indexes enough documents such that
   * the at least one old tlog is closed and thrown away so that the source cluster does not have
   * all updates available in tlogs only.
   * <p>
   * Then we start a target cluster with CDCR configuration and we change the source cluster configuration
   * to use CDCR (i.e. CdcrUpdateLog, CdcrRequestHandler and CdcrUpdateProcessor) and restart it.
   * <p>
   * We test that all updates eventually make it to the target cluster and that the collectioncheckpoint
   * call returns the same version as the last update indexed on the source.
   */
@Test
public void testConvertClusterToCdcrAndBootstrap() throws Exception {
    // start the target first so that we know its zkhost
    MiniSolrCloudCluster target = new MiniSolrCloudCluster(1, createTempDir("cdcr-target"), buildJettyConfig("/solr"));
    try {
        target.waitForAllNodes(30);
        System.out.println("Target zkHost = " + target.getZkServer().getZkAddress());
        System.setProperty("cdcr.target.zkHost", target.getZkServer().getZkAddress());
        // start a cluster with no cdcr
        MiniSolrCloudCluster source = new MiniSolrCloudCluster(1, createTempDir("cdcr-source"), buildJettyConfig("/solr"));
        try {
            source.waitForAllNodes(30);
            source.uploadConfigSet(configset("cdcr-source-disabled"), "cdcr-source");
            // create a collection with the cdcr-source-disabled configset
            CollectionAdminRequest.createCollection("cdcr-source", "cdcr-source", 1, 1).withProperty("solr.directoryFactory", "solr.StandardDirectoryFactory").process(source.getSolrClient());
            CloudSolrClient sourceSolrClient = source.getSolrClient();
            sourceSolrClient.setDefaultCollection("cdcr-source");
            int docs = (TEST_NIGHTLY ? 100 : 10);
            int numDocs = 0;
            for (int k = 0; k < docs; k++) {
                UpdateRequest req = new UpdateRequest();
                for (; numDocs < (k + 1) * 100; numDocs++) {
                    SolrInputDocument doc = new SolrInputDocument();
                    doc.addField("id", "source_" + numDocs);
                    doc.addField("xyz", numDocs);
                    req.add(doc);
                }
                req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
                System.out.println("Adding " + docs + " docs with commit=true, numDocs=" + numDocs);
                req.process(sourceSolrClient);
            }
            QueryResponse response = sourceSolrClient.query(new SolrQuery("*:*"));
            assertEquals("", numDocs, response.getResults().getNumFound());
            // lets find and keep the maximum version assigned by source cluster across all our updates
            long maxVersion = Long.MIN_VALUE;
            ModifiableSolrParams params = new ModifiableSolrParams();
            params.set(CommonParams.QT, "/get");
            params.set("getVersions", numDocs);
            response = sourceSolrClient.query(params);
            List<Long> versions = (List<Long>) response.getResponse().get("versions");
            for (Long version : versions) {
                maxVersion = Math.max(maxVersion, version);
            }
            //       upload the cdcr-enabled config and restart source cluster
            source.uploadConfigSet(configset("cdcr-source"), "cdcr-source");
            JettySolrRunner runner = source.stopJettySolrRunner(0);
            source.startJettySolrRunner(runner);
            assertTrue(runner.isRunning());
            AbstractDistribZkTestBase.waitForRecoveriesToFinish("cdcr-source", source.getSolrClient().getZkStateReader(), true, true, 330);
            response = sourceSolrClient.query(new SolrQuery("*:*"));
            assertEquals("Document mismatch on source after restart", numDocs, response.getResults().getNumFound());
            // setup the target cluster
            target.uploadConfigSet(configset("cdcr-target"), "cdcr-target");
            CollectionAdminRequest.createCollection("cdcr-target", "cdcr-target", 1, 1).process(target.getSolrClient());
            CloudSolrClient targetSolrClient = target.getSolrClient();
            targetSolrClient.setDefaultCollection("cdcr-target");
            Thread.sleep(1000);
            cdcrStart(targetSolrClient);
            cdcrStart(sourceSolrClient);
            response = getCdcrQueue(sourceSolrClient);
            System.out.println("Cdcr queue response: " + response.getResponse());
            long foundDocs = waitForTargetToSync(numDocs, targetSolrClient);
            assertEquals("Document mismatch on target after sync", numDocs, foundDocs);
            params = new ModifiableSolrParams();
            params.set(CommonParams.ACTION, CdcrParams.CdcrAction.COLLECTIONCHECKPOINT.toString());
            params.set(CommonParams.QT, "/cdcr");
            response = targetSolrClient.query(params);
            Long checkpoint = (Long) response.getResponse().get(CdcrParams.CHECKPOINT);
            assertNotNull(checkpoint);
            assertEquals("COLLECTIONCHECKPOINT from target cluster should have returned the maximum " + "version across all updates made to source", maxVersion, checkpoint.longValue());
        } finally {
            source.shutdown();
        }
    } finally {
        target.shutdown();
    }
}
Also used : AbstractUpdateRequest(org.apache.solr.client.solrj.request.AbstractUpdateRequest) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) SolrQuery(org.apache.solr.client.solrj.SolrQuery) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrInputDocument(org.apache.solr.common.SolrInputDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) Test(org.junit.Test)

Example 8 with CloudSolrClient

use of org.apache.solr.client.solrj.impl.CloudSolrClient in project lucene-solr by apache.

the class BaseCdcrDistributedZkTest method deleteById.

protected void deleteById(String collection, List<String> ids) throws IOException, SolrServerException {
    CloudSolrClient client = createCloudClient(collection);
    try {
        client.deleteById(ids);
        client.commit(true, true);
    } finally {
        client.close();
    }
}
Also used : CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 9 with CloudSolrClient

use of org.apache.solr.client.solrj.impl.CloudSolrClient in project lucene-solr by apache.

the class BaseCdcrDistributedZkTest method createCloudClient.

protected CloudSolrClient createCloudClient(String defaultCollection) {
    CloudSolrClient server = getCloudSolrClient(zkServer.getZkAddress(), random().nextBoolean());
    server.setParallelUpdates(random().nextBoolean());
    if (defaultCollection != null)
        server.setDefaultCollection(defaultCollection);
    return server;
}
Also used : CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 10 with CloudSolrClient

use of org.apache.solr.client.solrj.impl.CloudSolrClient in project lucene-solr by apache.

the class BaseCdcrDistributedZkTest method deleteByQuery.

protected void deleteByQuery(String collection, String q) throws IOException, SolrServerException {
    CloudSolrClient client = createCloudClient(collection);
    try {
        client.deleteByQuery(q);
        client.commit(true, true);
    } finally {
        client.close();
    }
}
Also used : CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Aggregations

CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)140 Test (org.junit.Test)52 ArrayList (java.util.ArrayList)40 SolrQuery (org.apache.solr.client.solrj.SolrQuery)30 HashMap (java.util.HashMap)26 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)25 SolrInputDocument (org.apache.solr.common.SolrInputDocument)25 CollectionAdminRequest (org.apache.solr.client.solrj.request.CollectionAdminRequest)24 Slice (org.apache.solr.common.cloud.Slice)24 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)22 List (java.util.List)21 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)21 Map (java.util.Map)20 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)20 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)19 NamedList (org.apache.solr.common.util.NamedList)18 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)17 Replica (org.apache.solr.common.cloud.Replica)17 SolrRequest (org.apache.solr.client.solrj.SolrRequest)15 DocCollection (org.apache.solr.common.cloud.DocCollection)15