Search in sources :

Example 1 with ShardState

use of com.yelp.nrtsearch.server.luceneserver.ShardState in project nrtsearch by Yelp.

the class TimeoutTest method queryWithFunction.

private TopDocs queryWithFunction(SearchRequest request, Function<SearchContext, TopDocs> func) throws Exception {
    SearcherTaxonomyManager.SearcherAndTaxonomy s = null;
    IndexState indexState = getGlobalState().getIndex(TEST_INDEX);
    ShardState shardState = indexState.getShard(0);
    try {
        s = shardState.acquire();
        SearchContext context = SearchRequestProcessor.buildContextForRequest(request, indexState, shardState, s, ProfileResult.newBuilder());
        return func.apply(context);
    } finally {
        if (s != null) {
            shardState.release(s);
        }
    }
}
Also used : ShardState(com.yelp.nrtsearch.server.luceneserver.ShardState) SearchContext(com.yelp.nrtsearch.server.luceneserver.search.SearchContext) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState) SearcherTaxonomyManager(org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager)

Example 2 with ShardState

use of com.yelp.nrtsearch.server.luceneserver.ShardState in project nrtsearch by Yelp.

the class EagerGlobalOrdinalsTest method testEagerOrdinals.

@Test
public void testEagerOrdinals() throws Exception {
    SearcherTaxonomyManager.SearcherAndTaxonomy s = null;
    ShardState shardState = getGlobalState().getIndex(DEFAULT_TEST_INDEX).getShard(0);
    try {
        FieldDef fieldDef = getGlobalState().getIndex(DEFAULT_TEST_INDEX).getField(EAGER_FIELD);
        addDocAndRefresh();
        s = shardState.acquire();
        assertGlobalOrdinals(s.searcher.getIndexReader(), fieldDef);
        doQuery(EAGER_FIELD);
        assertGlobalOrdinals(s.searcher.getIndexReader(), fieldDef);
        // create new reader version
        addDocAndRefresh();
        shardState.release(s);
        s = null;
        s = shardState.acquire();
        assertGlobalOrdinals(s.searcher.getIndexReader(), fieldDef);
    } finally {
        if (s != null) {
            shardState.release(s);
        }
    }
}
Also used : FieldDef(com.yelp.nrtsearch.server.luceneserver.field.FieldDef) ShardState(com.yelp.nrtsearch.server.luceneserver.ShardState) SearcherTaxonomyManager(org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager) Test(org.junit.Test)

Example 3 with ShardState

use of com.yelp.nrtsearch.server.luceneserver.ShardState in project nrtsearch by Yelp.

the class BucketedTieredMergePolicyTest method testFindMerges.

@Test
public void testFindMerges() throws Exception {
    setLiveSettings(5, 10000, 100);
    addData(500);
    ShardState shardState = getGlobalState().getIndex(DEFAULT_TEST_INDEX).getShard(0);
    MergePolicy policy = shardState.writer.getConfig().getMergePolicy();
    assertTrue(policy instanceof BucketedTieredMergePolicy);
    waitForMerges(shardState);
    shardState.maybeRefreshBlocking();
    SearcherAndTaxonomy s = null;
    try {
        s = getGlobalState().getIndex(DEFAULT_TEST_INDEX).getShard(0).acquire();
        assertEquals(5, s.searcher.getSlices().length);
        for (LeafSlice slice : s.searcher.getSlices()) {
            assertTrue(slice.leaves.length < 100);
            int totalDocs = 0;
            for (LeafReaderContext context : slice.leaves) {
                totalDocs += context.reader().numDocs();
            }
            assertEquals(100, totalDocs);
        }
    } finally {
        if (s != null) {
            shardState.release(s);
        }
    }
    verifyData(500);
}
Also used : ShardState(com.yelp.nrtsearch.server.luceneserver.ShardState) LeafSlice(org.apache.lucene.search.IndexSearcher.LeafSlice) MergePolicy(org.apache.lucene.index.MergePolicy) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) SearcherAndTaxonomy(org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager.SearcherAndTaxonomy) Test(org.junit.Test)

Example 4 with ShardState

use of com.yelp.nrtsearch.server.luceneserver.ShardState in project nrtsearch by Yelp.

the class EagerGlobalOrdinalsTest method testWithoutEagerOrdinals.

@Test
public void testWithoutEagerOrdinals() throws Exception {
    SearcherTaxonomyManager.SearcherAndTaxonomy s = null;
    ShardState shardState = getGlobalState().getIndex(DEFAULT_TEST_INDEX).getShard(0);
    try {
        FieldDef fieldDef = getGlobalState().getIndex(DEFAULT_TEST_INDEX).getField(NOT_EAGER_FIELD);
        addDocAndRefresh();
        s = shardState.acquire();
        assertNoGlobalOrdinals(s.searcher.getIndexReader(), fieldDef);
        doQuery(NOT_EAGER_FIELD);
        assertGlobalOrdinals(s.searcher.getIndexReader(), fieldDef);
        // create new reader version
        addDocAndRefresh();
        shardState.release(s);
        s = null;
        s = shardState.acquire();
        assertNoGlobalOrdinals(s.searcher.getIndexReader(), fieldDef);
        doQuery(NOT_EAGER_FIELD);
        assertGlobalOrdinals(s.searcher.getIndexReader(), fieldDef);
    } finally {
        if (s != null) {
            shardState.release(s);
        }
    }
}
Also used : FieldDef(com.yelp.nrtsearch.server.luceneserver.field.FieldDef) ShardState(com.yelp.nrtsearch.server.luceneserver.ShardState) SearcherTaxonomyManager(org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager) Test(org.junit.Test)

Example 5 with ShardState

use of com.yelp.nrtsearch.server.luceneserver.ShardState in project nrtsearch by Yelp.

the class BucketedTieredMergePolicyTest method testFindForcedMerges.

@Test
public void testFindForcedMerges() throws Exception {
    setLiveSettings(10, 10000, 100);
    addData(600);
    ShardState shardState = getGlobalState().getIndex(DEFAULT_TEST_INDEX).getShard(0);
    shardState.writer.forceMerge(1, true);
    waitForMerges(shardState);
    shardState.maybeRefreshBlocking();
    SearcherAndTaxonomy s = null;
    try {
        s = getGlobalState().getIndex(DEFAULT_TEST_INDEX).getShard(0).acquire();
        assertEquals(10, s.searcher.getSlices().length);
        for (LeafSlice slice : s.searcher.getSlices()) {
            assertEquals(1, slice.leaves.length);
            int totalDocs = 0;
            for (LeafReaderContext context : slice.leaves) {
                totalDocs += context.reader().numDocs();
            }
            assertEquals(60, totalDocs);
        }
    } finally {
        if (s != null) {
            shardState.release(s);
        }
    }
    verifyData(600);
    // cut virtual shards in half and re-merge
    setLiveSettings(5, 10000, 100);
    shardState.writer.forceMerge(1, true);
    waitForMerges(shardState);
    shardState.maybeRefreshBlocking();
    s = null;
    try {
        s = getGlobalState().getIndex(DEFAULT_TEST_INDEX).getShard(0).acquire();
        assertEquals(5, s.searcher.getSlices().length);
        for (LeafSlice slice : s.searcher.getSlices()) {
            assertEquals(1, slice.leaves.length);
            int totalDocs = 0;
            for (LeafReaderContext context : slice.leaves) {
                totalDocs += context.reader().numDocs();
            }
            assertEquals(120, totalDocs);
        }
    } finally {
        if (s != null) {
            shardState.release(s);
        }
    }
    verifyData(600);
}
Also used : ShardState(com.yelp.nrtsearch.server.luceneserver.ShardState) LeafSlice(org.apache.lucene.search.IndexSearcher.LeafSlice) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) SearcherAndTaxonomy(org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager.SearcherAndTaxonomy) Test(org.junit.Test)

Aggregations

ShardState (com.yelp.nrtsearch.server.luceneserver.ShardState)5 Test (org.junit.Test)4 SearcherTaxonomyManager (org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager)3 FieldDef (com.yelp.nrtsearch.server.luceneserver.field.FieldDef)2 SearcherAndTaxonomy (org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager.SearcherAndTaxonomy)2 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)2 LeafSlice (org.apache.lucene.search.IndexSearcher.LeafSlice)2 IndexState (com.yelp.nrtsearch.server.luceneserver.IndexState)1 SearchContext (com.yelp.nrtsearch.server.luceneserver.search.SearchContext)1 MergePolicy (org.apache.lucene.index.MergePolicy)1