Search in sources :

Example 76 with SolrCore

use of org.apache.solr.core.SolrCore in project lucene-solr by apache.

the class CoreAdminRequestStatusTest method testCoreAdminRequestStatus.

@Test
public void testCoreAdminRequestStatus() throws Exception {
    final File workDir = createTempDir().toFile();
    final CoreContainer cores = h.getCoreContainer();
    final CoreAdminHandler admin = new CoreAdminHandler(cores);
    Path instDir;
    try (SolrCore template = cores.getCore("collection1")) {
        assertNotNull(template);
        instDir = template.getCoreDescriptor().getInstanceDir();
    }
    assertTrue("instDir doesn't exist: " + instDir, Files.exists(instDir));
    final File instPropFile = new File(workDir, "instProp");
    FileUtils.copyDirectory(instDir.toFile(), instPropFile);
    // create a new core (using CoreAdminHandler) w/ properties
    SolrQueryResponse resp = new SolrQueryResponse();
    admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.CREATE.toString(), CoreAdminParams.INSTANCE_DIR, instPropFile.getAbsolutePath(), CoreAdminParams.NAME, "dummycore", CommonAdminParams.ASYNC, "42"), resp);
    assertNull("Exception on create", resp.getException());
    int maxRetries = 10;
    while (maxRetries-- > 0) {
        resp = new SolrQueryResponse();
        admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.REQUESTSTATUS.toString(), CoreAdminParams.REQUESTID, "42"), resp);
        if (resp.getValues().get("STATUS") != null && resp.getValues().get("STATUS").equals("completed"))
            break;
        Thread.sleep(1000);
    }
    assertEquals("The status of request was expected to be completed", "completed", resp.getValues().get("STATUS"));
    resp = new SolrQueryResponse();
    admin.handleRequestBody(req(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.REQUESTSTATUS.toString(), CoreAdminParams.REQUESTID, "9999999"), resp);
    assertEquals("Was expecting it to be invalid but found a task with the id.", "notfound", resp.getValues().get("STATUS"));
    admin.shutdown();
}
Also used : Path(java.nio.file.Path) SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) CoreContainer(org.apache.solr.core.CoreContainer) SolrCore(org.apache.solr.core.SolrCore) File(java.io.File) Test(org.junit.Test)

Example 77 with SolrCore

use of org.apache.solr.core.SolrCore in project lucene-solr by apache.

the class SolrIndexSplitterTest method testSplitByCores.

@Test
public void testSplitByCores() throws Exception {
    // add two docs
    String id1 = "dorothy";
    assertU(adoc("id", id1));
    String id2 = "kansas";
    assertU(adoc("id", id2));
    assertU(commit());
    assertJQ(req("q", "*:*"), "/response/numFound==2");
    List<DocRouter.Range> ranges = getRanges(id1, id2);
    SolrCore core1 = null, core2 = null;
    try {
        core1 = h.getCoreContainer().create("split1", ImmutableMap.of("dataDir", indexDir1.getAbsolutePath(), "configSet", "minimal"));
        core2 = h.getCoreContainer().create("split2", ImmutableMap.of("dataDir", indexDir2.getAbsolutePath(), "configSet", "minimal"));
        LocalSolrQueryRequest request = null;
        try {
            request = lrf.makeRequest("q", "dummy");
            SplitIndexCommand command = new SplitIndexCommand(request, null, Lists.newArrayList(core1, core2), ranges, new PlainIdRouter(), null, null);
            new SolrIndexSplitter(command).split();
        } finally {
            if (request != null)
                request.close();
        }
        EmbeddedSolrServer server1 = new EmbeddedSolrServer(h.getCoreContainer(), "split1");
        EmbeddedSolrServer server2 = new EmbeddedSolrServer(h.getCoreContainer(), "split2");
        server1.commit(true, true);
        server2.commit(true, true);
        assertEquals("id:dorothy should be present in split index1", 1, server1.query(new SolrQuery("id:dorothy")).getResults().getNumFound());
        assertEquals("id:kansas should not be present in split index1", 0, server1.query(new SolrQuery("id:kansas")).getResults().getNumFound());
        assertEquals("id:dorothy should not be present in split index2", 0, server2.query(new SolrQuery("id:dorothy")).getResults().getNumFound());
        assertEquals("id:kansas should be present in split index2", 1, server2.query(new SolrQuery("id:kansas")).getResults().getNumFound());
    } finally {
        h.getCoreContainer().unload("split2");
        h.getCoreContainer().unload("split1");
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) SolrCore(org.apache.solr.core.SolrCore) PlainIdRouter(org.apache.solr.common.cloud.PlainIdRouter) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Test(org.junit.Test)

Example 78 with SolrCore

use of org.apache.solr.core.SolrCore in project lucene-solr by apache.

the class UpdateParamsTest method testUpdateProcessorParamDeprecationRemoved.

/**
   * Tests that only update.chain and not update.processor works (SOLR-2105)
   */
public void testUpdateProcessorParamDeprecationRemoved() throws Exception {
    SolrCore core = h.getCore();
    UpdateRequestHandler handler = new UpdateRequestHandler();
    handler.init(null);
    MapSolrParams params = new MapSolrParams(new HashMap<String, String>());
    params.getMap().put("update.processor", "nonexistant");
    // Add a single document
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequestBase req = new SolrQueryRequestBase(core, params) {
    };
    // First check that the old param behaves as it should
    try {
        handler.handleRequestBody(req, rsp);
        assertTrue("Old param update.processor should not have any effect anymore", true);
    } catch (Exception e) {
        assertFalse("Got wrong exception while testing update.chain", e.getMessage().equals("unknown UpdateRequestProcessorChain: nonexistant"));
    }
    // Then check that the new param behaves correctly
    params.getMap().remove("update.processor");
    params.getMap().put(UpdateParams.UPDATE_CHAIN, "nonexistant");
    req.setParams(params);
    try {
        handler.handleRequestBody(req, rsp);
        assertFalse("Faulty update.chain parameter not causing an error - i.e. it is not detected", true);
    } catch (Exception e) {
        assertEquals("Got wrong exception while testing update.chain", e.getMessage(), "unknown UpdateRequestProcessorChain: nonexistant");
    }
}
Also used : SolrQueryResponse(org.apache.solr.response.SolrQueryResponse) MapSolrParams(org.apache.solr.common.params.MapSolrParams) SolrCore(org.apache.solr.core.SolrCore) SolrQueryRequestBase(org.apache.solr.request.SolrQueryRequestBase) UpdateRequestHandler(org.apache.solr.handler.UpdateRequestHandler)

Example 79 with SolrCore

use of org.apache.solr.core.SolrCore in project lucene-solr by apache.

the class TestTlogReplica method testOnlyLeaderIndexes.

public void testOnlyLeaderIndexes() throws Exception {
    createAndWaitForCollection(1, 0, 2, 0);
    CloudSolrClient cloudClient = cluster.getSolrClient();
    new UpdateRequest().add(sdoc("id", "1")).add(sdoc("id", "2")).add(sdoc("id", "3")).add(sdoc("id", "4")).process(cloudClient, collectionName);
    {
        UpdateHandler updateHandler = getSolrCore(true).get(0).getUpdateHandler();
        RefCounted<IndexWriter> iwRef = updateHandler.getSolrCoreState().getIndexWriter(null);
        assertTrue("IndexWriter at leader must see updates ", iwRef.get().hasUncommittedChanges());
        iwRef.decref();
    }
    for (SolrCore solrCore : getSolrCore(false)) {
        RefCounted<IndexWriter> iwRef = solrCore.getUpdateHandler().getSolrCoreState().getIndexWriter(null);
        assertFalse("IndexWriter at replicas must not see updates ", iwRef.get().hasUncommittedChanges());
        iwRef.decref();
    }
    checkRTG(1, 4, cluster.getJettySolrRunners());
    new UpdateRequest().deleteById("1").deleteByQuery("id:2").process(cloudClient, collectionName);
    // The DBQ is not processed at replicas, so we still can get doc2 and other docs by RTG
    checkRTG(2, 4, getSolrRunner(false));
    new UpdateRequest().commit(cloudClient, collectionName);
    waitForNumDocsInAllActiveReplicas(2);
    // Update log roll over
    for (SolrCore solrCore : getSolrCore(false)) {
        UpdateLog updateLog = solrCore.getUpdateHandler().getUpdateLog();
        assertFalse(updateLog.hasUncommittedChanges());
    }
    // UpdateLog copy over old updates
    for (int i = 15; i <= 150; i++) {
        cloudClient.add(collectionName, sdoc("id", String.valueOf(i)));
        if (random().nextInt(100) < 15 & i != 150) {
            cloudClient.commit(collectionName);
        }
    }
    checkRTG(120, 150, cluster.getJettySolrRunners());
    waitForReplicasCatchUp(20);
}
Also used : UpdateHandler(org.apache.solr.update.UpdateHandler) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) SolrIndexWriter(org.apache.solr.update.SolrIndexWriter) IndexWriter(org.apache.lucene.index.IndexWriter) RefCounted(org.apache.solr.util.RefCounted) SolrCore(org.apache.solr.core.SolrCore) UpdateLog(org.apache.solr.update.UpdateLog) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 80 with SolrCore

use of org.apache.solr.core.SolrCore in project lucene-solr by apache.

the class TestTlogReplica method assertUlogPresence.

/**
   * Asserts that Update logs exist for replicas of type {@link org.apache.solr.common.cloud.Replica.Type#NRT}, but not
   * for replicas of type {@link org.apache.solr.common.cloud.Replica.Type#PULL}
   */
private void assertUlogPresence(DocCollection collection) {
    for (Slice s : collection.getSlices()) {
        for (Replica r : s.getReplicas()) {
            SolrCore core = null;
            try {
                core = cluster.getReplicaJetty(r).getCoreContainer().getCore(r.getCoreName());
                assertNotNull(core);
                assertTrue("Update log should exist for replicas of type Append", new java.io.File(core.getUlogDir()).exists());
            } finally {
                core.close();
            }
        }
    }
}
Also used : Slice(org.apache.solr.common.cloud.Slice) SolrCore(org.apache.solr.core.SolrCore) Replica(org.apache.solr.common.cloud.Replica)

Aggregations

SolrCore (org.apache.solr.core.SolrCore)254 Test (org.junit.Test)88 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)57 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)55 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)52 SolrException (org.apache.solr.common.SolrException)41 CoreContainer (org.apache.solr.core.CoreContainer)40 NamedList (org.apache.solr.common.util.NamedList)38 HashMap (java.util.HashMap)33 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)33 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)32 File (java.io.File)28 MapSolrParams (org.apache.solr.common.params.MapSolrParams)26 ArrayList (java.util.ArrayList)25 IOException (java.io.IOException)23 SolrParams (org.apache.solr.common.params.SolrParams)19 Map (java.util.Map)17 Replica (org.apache.solr.common.cloud.Replica)17 SolrRequestHandler (org.apache.solr.request.SolrRequestHandler)15 SolrInputDocument (org.apache.solr.common.SolrInputDocument)13