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);
}
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();
}
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;
}
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);
}
}
Aggregations