Search in sources :

Example 1 with PlainIdRouter

use of org.apache.solr.common.cloud.PlainIdRouter in project lucene-solr by apache.

the class SolrIndexSplitterTest method testSplitDeletes.

// SOLR-5144
public void testSplitDeletes() throws Exception {
    LocalSolrQueryRequest request = null;
    try {
        // 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");
        // delete id2
        assertU(delI(id2));
        assertU(commit());
        // find minHash/maxHash hash ranges
        List<DocRouter.Range> ranges = getRanges(id1, id2);
        request = lrf.makeRequest("q", "dummy");
        SplitIndexCommand command = new SplitIndexCommand(request, Lists.newArrayList(indexDir1.getAbsolutePath(), indexDir2.getAbsolutePath()), null, ranges, new PlainIdRouter(), null, null);
        new SolrIndexSplitter(command).split();
        Directory directory = h.getCore().getDirectoryFactory().get(indexDir1.getAbsolutePath(), DirectoryFactory.DirContext.DEFAULT, h.getCore().getSolrConfig().indexConfig.lockType);
        DirectoryReader reader = DirectoryReader.open(directory);
        assertEquals("id:dorothy should be present in split index1", 1, reader.docFreq(new Term("id", "dorothy")));
        assertEquals("id:kansas should not be present in split index1", 0, reader.docFreq(new Term("id", "kansas")));
        assertEquals("split index1 should have only one document", 1, reader.numDocs());
        reader.close();
        h.getCore().getDirectoryFactory().release(directory);
        directory = h.getCore().getDirectoryFactory().get(indexDir2.getAbsolutePath(), DirectoryFactory.DirContext.DEFAULT, h.getCore().getSolrConfig().indexConfig.lockType);
        reader = DirectoryReader.open(directory);
        // should be empty
        assertEquals(0, reader.numDocs());
        reader.close();
        h.getCore().getDirectoryFactory().release(directory);
    } finally {
        // decrefs the searcher
        if (request != null)
            request.close();
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) DirectoryReader(org.apache.lucene.index.DirectoryReader) PlainIdRouter(org.apache.solr.common.cloud.PlainIdRouter) Term(org.apache.lucene.index.Term) Directory(org.apache.lucene.store.Directory)

Example 2 with PlainIdRouter

use of org.apache.solr.common.cloud.PlainIdRouter 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 3 with PlainIdRouter

use of org.apache.solr.common.cloud.PlainIdRouter in project lucene-solr by apache.

the class TestHashPartitioner method testHashCodes.

public void testHashCodes() throws Exception {
    DocRouter router = DocRouter.getDocRouter(PlainIdRouter.NAME);
    assertTrue(router instanceof PlainIdRouter);
    DocCollection coll = createCollection(4, router);
    doNormalIdHashing(coll);
}
Also used : PlainIdRouter(org.apache.solr.common.cloud.PlainIdRouter) DocRouter(org.apache.solr.common.cloud.DocRouter) DocCollection(org.apache.solr.common.cloud.DocCollection)

Example 4 with PlainIdRouter

use of org.apache.solr.common.cloud.PlainIdRouter in project lucene-solr by apache.

the class SolrIndexSplitterTest method getRanges.

private List<DocRouter.Range> getRanges(String id1, String id2) throws UnsupportedEncodingException {
    // find minHash/maxHash hash ranges
    byte[] bytes = id1.getBytes(StandardCharsets.UTF_8);
    int minHash = Hash.murmurhash3_x86_32(bytes, 0, bytes.length, 0);
    bytes = id2.getBytes(StandardCharsets.UTF_8);
    int maxHash = Hash.murmurhash3_x86_32(bytes, 0, bytes.length, 0);
    if (minHash > maxHash) {
        int temp = maxHash;
        maxHash = minHash;
        minHash = temp;
    }
    PlainIdRouter router = new PlainIdRouter();
    DocRouter.Range fullRange = new DocRouter.Range(minHash, maxHash);
    return router.partitionRange(2, fullRange);
}
Also used : PlainIdRouter(org.apache.solr.common.cloud.PlainIdRouter) DocRouter(org.apache.solr.common.cloud.DocRouter)

Example 5 with PlainIdRouter

use of org.apache.solr.common.cloud.PlainIdRouter in project lucene-solr by apache.

the class SolrIndexSplitterTest method testSplitByPaths.

@Test
public void testSplitByPaths() throws Exception {
    LocalSolrQueryRequest request = null;
    try {
        // 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");
        // find minHash/maxHash hash ranges
        List<DocRouter.Range> ranges = getRanges(id1, id2);
        request = lrf.makeRequest("q", "dummy");
        SplitIndexCommand command = new SplitIndexCommand(request, Lists.newArrayList(indexDir1.getAbsolutePath(), indexDir2.getAbsolutePath()), null, ranges, new PlainIdRouter(), null, null);
        new SolrIndexSplitter(command).split();
        Directory directory = h.getCore().getDirectoryFactory().get(indexDir1.getAbsolutePath(), DirectoryFactory.DirContext.DEFAULT, h.getCore().getSolrConfig().indexConfig.lockType);
        DirectoryReader reader = DirectoryReader.open(directory);
        assertEquals("id:dorothy should be present in split index1", 1, reader.docFreq(new Term("id", "dorothy")));
        assertEquals("id:kansas should not be present in split index1", 0, reader.docFreq(new Term("id", "kansas")));
        assertEquals("split index1 should have only one document", 1, reader.numDocs());
        reader.close();
        h.getCore().getDirectoryFactory().release(directory);
        directory = h.getCore().getDirectoryFactory().get(indexDir2.getAbsolutePath(), DirectoryFactory.DirContext.DEFAULT, h.getCore().getSolrConfig().indexConfig.lockType);
        reader = DirectoryReader.open(directory);
        assertEquals("id:dorothy should not be present in split index2", 0, reader.docFreq(new Term("id", "dorothy")));
        assertEquals("id:kansas should be present in split index2", 1, reader.docFreq(new Term("id", "kansas")));
        assertEquals("split index2 should have only one document", 1, reader.numDocs());
        reader.close();
        h.getCore().getDirectoryFactory().release(directory);
    } finally {
        // decrefs the searcher
        if (request != null)
            request.close();
    }
}
Also used : LocalSolrQueryRequest(org.apache.solr.request.LocalSolrQueryRequest) DirectoryReader(org.apache.lucene.index.DirectoryReader) PlainIdRouter(org.apache.solr.common.cloud.PlainIdRouter) Term(org.apache.lucene.index.Term) Directory(org.apache.lucene.store.Directory) Test(org.junit.Test)

Aggregations

PlainIdRouter (org.apache.solr.common.cloud.PlainIdRouter)7 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)4 DirectoryReader (org.apache.lucene.index.DirectoryReader)3 Directory (org.apache.lucene.store.Directory)3 DocRouter (org.apache.solr.common.cloud.DocRouter)3 Test (org.junit.Test)3 Term (org.apache.lucene.index.Term)2 DocCollection (org.apache.solr.common.cloud.DocCollection)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 EmbeddedSolrServer (org.apache.solr.client.solrj.embedded.EmbeddedSolrServer)1 CoreAdminRequest (org.apache.solr.client.solrj.request.CoreAdminRequest)1 SolrException (org.apache.solr.common.SolrException)1 CompositeIdRouter (org.apache.solr.common.cloud.CompositeIdRouter)1 Replica (org.apache.solr.common.cloud.Replica)1 Slice (org.apache.solr.common.cloud.Slice)1 ZkNodeProps (org.apache.solr.common.cloud.ZkNodeProps)1 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)1