Search in sources :

Example 6 with ConcurrentMergeScheduler

use of org.apache.lucene.index.ConcurrentMergeScheduler in project lucene-solr by apache.

the class TestConfig method testDefaults.

// If defaults change, add test methods to cover each version
@Test
public void testDefaults() throws Exception {
    int numDefaultsTested = 0;
    int numNullDefaults = 0;
    SolrConfig sc = new SolrConfig(new SolrResourceLoader(TEST_PATH().resolve("collection1")), "solrconfig-defaults.xml", null);
    SolrIndexConfig sic = sc.indexConfig;
    ++numDefaultsTested;
    assertEquals("default useCompoundFile", false, sic.useCompoundFile);
    ++numDefaultsTested;
    assertEquals("default maxBufferedDocs", -1, sic.maxBufferedDocs);
    ++numDefaultsTested;
    assertEquals("default ramBufferSizeMB", 100.0D, sic.ramBufferSizeMB, 0.0D);
    ++numDefaultsTested;
    assertEquals("default writeLockTimeout", -1, sic.writeLockTimeout);
    ++numDefaultsTested;
    assertEquals("default LockType", DirectoryFactory.LOCK_TYPE_NATIVE, sic.lockType);
    ++numDefaultsTested;
    assertEquals("default infoStream", InfoStream.NO_OUTPUT, sic.infoStream);
    ++numDefaultsTested;
    assertNotNull("default metrics", sic.metricsInfo);
    ++numDefaultsTested;
    ++numNullDefaults;
    assertNull("default mergePolicyFactoryInfo", sic.mergePolicyFactoryInfo);
    ++numDefaultsTested;
    ++numNullDefaults;
    assertNull("default mergeSchedulerInfo", sic.mergeSchedulerInfo);
    ++numDefaultsTested;
    ++numNullDefaults;
    assertNull("default mergedSegmentWarmerInfo", sic.mergedSegmentWarmerInfo);
    IndexSchema indexSchema = IndexSchemaFactory.buildIndexSchema("schema.xml", solrConfig);
    IndexWriterConfig iwc = sic.toIndexWriterConfig(h.getCore());
    assertNotNull("null mp", iwc.getMergePolicy());
    assertTrue("mp is not TieredMergePolicy", iwc.getMergePolicy() instanceof TieredMergePolicy);
    assertNotNull("null ms", iwc.getMergeScheduler());
    assertTrue("ms is not CMS", iwc.getMergeScheduler() instanceof ConcurrentMergeScheduler);
    assertNull("non-null mergedSegmentWarmer", iwc.getMergedSegmentWarmer());
    final int numDefaultsMapped = sic.toMap(new LinkedHashMap<>()).size();
    assertEquals("numDefaultsTested vs. numDefaultsMapped+numNullDefaults =" + sic.toMap(new LinkedHashMap<>()).keySet(), numDefaultsTested, numDefaultsMapped + numNullDefaults);
}
Also used : TieredMergePolicy(org.apache.lucene.index.TieredMergePolicy) SolrIndexConfig(org.apache.solr.update.SolrIndexConfig) IndexSchema(org.apache.solr.schema.IndexSchema) ConcurrentMergeScheduler(org.apache.lucene.index.ConcurrentMergeScheduler) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 7 with ConcurrentMergeScheduler

use of org.apache.lucene.index.ConcurrentMergeScheduler in project lucene-solr by apache.

the class TestIDVersionPostingsFormat method testMoreThanOneDocPerIDTwoSegments.

public void testMoreThanOneDocPerIDTwoSegments() throws Exception {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
    iwc.setCodec(TestUtil.alwaysPostingsFormat(new IDVersionPostingsFormat()));
    iwc.setMergePolicy(new TieredMergePolicy());
    MergeScheduler ms = iwc.getMergeScheduler();
    if (ms instanceof ConcurrentMergeScheduler) {
        iwc.setMergeScheduler(new ConcurrentMergeScheduler() {

            @Override
            protected void handleMergeException(Directory dir, Throwable exc) {
                assertTrue(exc instanceof IllegalArgumentException);
            }
        });
    }
    IndexWriter w = new IndexWriter(dir, iwc);
    Document doc = new Document();
    doc.add(makeIDField("id", 17));
    w.addDocument(doc);
    w.commit();
    doc = new Document();
    doc.add(makeIDField("id", 17));
    try {
        w.addDocument(doc);
        w.commit();
        w.forceMerge(1);
        fail("didn't hit exception");
    } catch (IllegalArgumentException iae) {
    // expected: SMS will hit this
    } catch (IOException | IllegalStateException exc) {
        // expected
        assertTrue(exc.getCause() instanceof IllegalArgumentException);
    }
    w.rollback();
    dir.close();
}
Also used : ConcurrentMergeScheduler(org.apache.lucene.index.ConcurrentMergeScheduler) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) TieredMergePolicy(org.apache.lucene.index.TieredMergePolicy) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) IndexWriter(org.apache.lucene.index.IndexWriter) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) ConcurrentMergeScheduler(org.apache.lucene.index.ConcurrentMergeScheduler) MergeScheduler(org.apache.lucene.index.MergeScheduler) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 8 with ConcurrentMergeScheduler

use of org.apache.lucene.index.ConcurrentMergeScheduler in project lucene-solr by apache.

the class SolrIndexConfig method buildMergeScheduler.

private MergeScheduler buildMergeScheduler(IndexSchema schema) {
    String msClassName = mergeSchedulerInfo == null ? SolrIndexConfig.DEFAULT_MERGE_SCHEDULER_CLASSNAME : mergeSchedulerInfo.className;
    MergeScheduler scheduler = schema.getResourceLoader().newInstance(msClassName, MergeScheduler.class);
    if (mergeSchedulerInfo != null) {
        // if someone has them configured.
        if (scheduler instanceof ConcurrentMergeScheduler) {
            NamedList args = mergeSchedulerInfo.initArgs.clone();
            Integer maxMergeCount = (Integer) args.remove("maxMergeCount");
            if (maxMergeCount == null) {
                maxMergeCount = ((ConcurrentMergeScheduler) scheduler).getMaxMergeCount();
            }
            Integer maxThreadCount = (Integer) args.remove("maxThreadCount");
            if (maxThreadCount == null) {
                maxThreadCount = ((ConcurrentMergeScheduler) scheduler).getMaxThreadCount();
            }
            ((ConcurrentMergeScheduler) scheduler).setMaxMergesAndThreads(maxMergeCount, maxThreadCount);
            SolrPluginUtils.invokeSetters(scheduler, args);
        } else {
            SolrPluginUtils.invokeSetters(scheduler, mergeSchedulerInfo.initArgs);
        }
    }
    return scheduler;
}
Also used : NamedList(org.apache.solr.common.util.NamedList) ConcurrentMergeScheduler(org.apache.lucene.index.ConcurrentMergeScheduler) ConcurrentMergeScheduler(org.apache.lucene.index.ConcurrentMergeScheduler) MergeScheduler(org.apache.lucene.index.MergeScheduler)

Example 9 with ConcurrentMergeScheduler

use of org.apache.lucene.index.ConcurrentMergeScheduler in project lucene-solr by apache.

the class TestSearcherManager method testIntermediateClose.

public void testIntermediateClose() throws IOException, InterruptedException {
    Directory dir = newDirectory();
    // Test can deadlock if we use SMS:
    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())).setMergeScheduler(new ConcurrentMergeScheduler()));
    writer.addDocument(new Document());
    writer.commit();
    final CountDownLatch awaitEnterWarm = new CountDownLatch(1);
    final CountDownLatch awaitClose = new CountDownLatch(1);
    final AtomicBoolean triedReopen = new AtomicBoolean(false);
    final ExecutorService es = random().nextBoolean() ? null : Executors.newCachedThreadPool(new NamedThreadFactory("testIntermediateClose"));
    final SearcherFactory factory = new SearcherFactory() {

        @Override
        public IndexSearcher newSearcher(IndexReader r, IndexReader previous) {
            try {
                if (triedReopen.get()) {
                    awaitEnterWarm.countDown();
                    awaitClose.await();
                }
            } catch (InterruptedException e) {
            //
            }
            return new IndexSearcher(r, es);
        }
    };
    final SearcherManager searcherManager = random().nextBoolean() ? new SearcherManager(dir, factory) : new SearcherManager(writer, random().nextBoolean(), false, factory);
    if (VERBOSE) {
        System.out.println("sm created");
    }
    IndexSearcher searcher = searcherManager.acquire();
    try {
        assertEquals(1, searcher.getIndexReader().numDocs());
    } finally {
        searcherManager.release(searcher);
    }
    writer.addDocument(new Document());
    writer.commit();
    final AtomicBoolean success = new AtomicBoolean(false);
    final Throwable[] exc = new Throwable[1];
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                triedReopen.set(true);
                if (VERBOSE) {
                    System.out.println("NOW call maybeRefresh");
                }
                searcherManager.maybeRefresh();
                success.set(true);
            } catch (AlreadyClosedException e) {
            // expected
            } catch (Throwable e) {
                if (VERBOSE) {
                    System.out.println("FAIL: unexpected exc");
                    e.printStackTrace(System.out);
                }
                exc[0] = e;
                // use success as the barrier here to make sure we see the write
                success.set(false);
            }
        }
    });
    thread.start();
    if (VERBOSE) {
        System.out.println("THREAD started");
    }
    awaitEnterWarm.await();
    if (VERBOSE) {
        System.out.println("NOW call close");
    }
    searcherManager.close();
    awaitClose.countDown();
    thread.join();
    expectThrows(AlreadyClosedException.class, () -> {
        searcherManager.acquire();
    });
    assertFalse(success.get());
    assertTrue(triedReopen.get());
    assertNull("" + exc[0], exc[0]);
    writer.close();
    dir.close();
    if (es != null) {
        es.shutdown();
        es.awaitTermination(1, TimeUnit.SECONDS);
    }
}
Also used : NamedThreadFactory(org.apache.lucene.util.NamedThreadFactory) ConcurrentMergeScheduler(org.apache.lucene.index.ConcurrentMergeScheduler) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) Document(org.apache.lucene.document.Document) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) IndexWriter(org.apache.lucene.index.IndexWriter) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) ExecutorService(java.util.concurrent.ExecutorService) IndexReader(org.apache.lucene.index.IndexReader) Directory(org.apache.lucene.store.Directory)

Aggregations

ConcurrentMergeScheduler (org.apache.lucene.index.ConcurrentMergeScheduler)9 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)5 IndexWriter (org.apache.lucene.index.IndexWriter)4 TieredMergePolicy (org.apache.lucene.index.TieredMergePolicy)4 Directory (org.apache.lucene.store.Directory)4 IOException (java.io.IOException)3 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)3 Document (org.apache.lucene.document.Document)3 MergeScheduler (org.apache.lucene.index.MergeScheduler)3 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)3 LogMergePolicy (org.apache.lucene.index.LogMergePolicy)2 IndexSchema (org.apache.solr.schema.IndexSchema)2 Test (org.junit.Test)2 Path (java.nio.file.Path)1 LinkedHashMap (java.util.LinkedHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 EnglishAnalyzer (org.apache.lucene.analysis.en.EnglishAnalyzer)1