Search in sources :

Example 6 with MergePolicy

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

the class TestUtil method reduceOpenFiles.

/** just tries to configure things to keep the open file
   * count lowish */
public static void reduceOpenFiles(IndexWriter w) {
    // keep number of open files lowish
    MergePolicy mp = w.getConfig().getMergePolicy();
    mp.setNoCFSRatio(1.0);
    if (mp instanceof LogMergePolicy) {
        LogMergePolicy lmp = (LogMergePolicy) mp;
        lmp.setMergeFactor(Math.min(5, lmp.getMergeFactor()));
    } else if (mp instanceof TieredMergePolicy) {
        TieredMergePolicy tmp = (TieredMergePolicy) mp;
        tmp.setMaxMergeAtOnce(Math.min(5, tmp.getMaxMergeAtOnce()));
        tmp.setSegmentsPerTier(Math.min(5, tmp.getSegmentsPerTier()));
    }
    MergeScheduler ms = w.getConfig().getMergeScheduler();
    if (ms instanceof ConcurrentMergeScheduler) {
        // wtf... shouldnt it be even lower since it's 1 by default?!?!
        ((ConcurrentMergeScheduler) ms).setMaxMergesAndThreads(3, 2);
    }
}
Also used : TieredMergePolicy(org.apache.lucene.index.TieredMergePolicy) MergePolicy(org.apache.lucene.index.MergePolicy) LogMergePolicy(org.apache.lucene.index.LogMergePolicy) TieredMergePolicy(org.apache.lucene.index.TieredMergePolicy) LogMergePolicy(org.apache.lucene.index.LogMergePolicy) ConcurrentMergeScheduler(org.apache.lucene.index.ConcurrentMergeScheduler) MergeScheduler(org.apache.lucene.index.MergeScheduler) ConcurrentMergeScheduler(org.apache.lucene.index.ConcurrentMergeScheduler)

Example 7 with MergePolicy

use of org.apache.lucene.index.MergePolicy in project elasticsearch by elastic.

the class InternalEngine method getIndexWriterConfig.

private IndexWriterConfig getIndexWriterConfig(boolean create) {
    final IndexWriterConfig iwc = new IndexWriterConfig(engineConfig.getAnalyzer());
    // we by default don't commit on close
    iwc.setCommitOnClose(false);
    iwc.setOpenMode(create ? IndexWriterConfig.OpenMode.CREATE : IndexWriterConfig.OpenMode.APPEND);
    iwc.setIndexDeletionPolicy(deletionPolicy);
    // with tests.verbose, lucene sets this up: plumb to align with filesystem stream
    boolean verbose = false;
    try {
        verbose = Boolean.parseBoolean(System.getProperty("tests.verbose"));
    } catch (Exception ignore) {
    }
    iwc.setInfoStream(verbose ? InfoStream.getDefault() : new LoggerInfoStream(logger));
    iwc.setMergeScheduler(mergeScheduler);
    MergePolicy mergePolicy = config().getMergePolicy();
    // Give us the opportunity to upgrade old segments while performing
    // background merges
    mergePolicy = new ElasticsearchMergePolicy(mergePolicy);
    iwc.setMergePolicy(mergePolicy);
    iwc.setSimilarity(engineConfig.getSimilarity());
    iwc.setRAMBufferSizeMB(engineConfig.getIndexingBufferSize().getMbFrac());
    iwc.setCodec(engineConfig.getCodec());
    // always use compound on flush - reduces # of file-handles on refresh
    iwc.setUseCompoundFile(true);
    return iwc;
}
Also used : MergePolicy(org.apache.lucene.index.MergePolicy) ElasticsearchMergePolicy(org.elasticsearch.index.shard.ElasticsearchMergePolicy) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) LockObtainFailedException(org.apache.lucene.store.LockObtainFailedException) TranslogCorruptedException(org.elasticsearch.index.translog.TranslogCorruptedException) IOException(java.io.IOException) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) LiveIndexWriterConfig(org.apache.lucene.index.LiveIndexWriterConfig) LoggerInfoStream(org.elasticsearch.common.lucene.LoggerInfoStream) ElasticsearchMergePolicy(org.elasticsearch.index.shard.ElasticsearchMergePolicy)

Example 8 with MergePolicy

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

the class WrapperMergePolicyFactoryTest method testProperlyInitializesWrappedMergePolicy.

public void testProperlyInitializesWrappedMergePolicy() {
    final TieredMergePolicy defaultTMP = new TieredMergePolicy();
    final int testMaxMergeAtOnce = defaultTMP.getMaxMergeAtOnce() * 2;
    final double testMaxMergedSegmentMB = defaultTMP.getMaxMergedSegmentMB() * 10;
    final MergePolicyFactoryArgs args = new MergePolicyFactoryArgs();
    args.add(WrapperMergePolicyFactory.WRAPPED_PREFIX, "test");
    args.add("test.class", TieredMergePolicyFactory.class.getName());
    args.add("test.maxMergeAtOnce", testMaxMergeAtOnce);
    args.add("test.maxMergedSegmentMB", testMaxMergedSegmentMB);
    MergePolicyFactory mpf = new DefaultingWrapperMergePolicyFactory(resourceLoader, args, null) {

        @Override
        protected MergePolicy getDefaultWrappedMergePolicy() {
            throw new IllegalStateException("Should not have reached here!");
        }
    };
    final MergePolicy mp = mpf.getMergePolicy();
    assertSame(mp.getClass(), TieredMergePolicy.class);
    final TieredMergePolicy tmp = (TieredMergePolicy) mp;
    assertEquals("maxMergeAtOnce", testMaxMergeAtOnce, tmp.getMaxMergeAtOnce());
    assertEquals("maxMergedSegmentMB", testMaxMergedSegmentMB, tmp.getMaxMergedSegmentMB(), 0.0d);
}
Also used : TieredMergePolicy(org.apache.lucene.index.TieredMergePolicy) NoMergePolicy(org.apache.lucene.index.NoMergePolicy) MergePolicy(org.apache.lucene.index.MergePolicy) UpgradeIndexMergePolicy(org.apache.lucene.index.UpgradeIndexMergePolicy) TieredMergePolicy(org.apache.lucene.index.TieredMergePolicy)

Example 9 with MergePolicy

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

the class SolrIndexConfig method toIndexWriterConfig.

public IndexWriterConfig toIndexWriterConfig(SolrCore core) throws IOException {
    IndexSchema schema = core.getLatestSchema();
    IndexWriterConfig iwc = new IndexWriterConfig(new DelayedSchemaAnalyzer(core));
    if (maxBufferedDocs != -1)
        iwc.setMaxBufferedDocs(maxBufferedDocs);
    if (ramBufferSizeMB != -1)
        iwc.setRAMBufferSizeMB(ramBufferSizeMB);
    iwc.setSimilarity(schema.getSimilarity());
    MergePolicy mergePolicy = buildMergePolicy(schema);
    iwc.setMergePolicy(mergePolicy);
    MergeScheduler mergeScheduler = buildMergeScheduler(schema);
    iwc.setMergeScheduler(mergeScheduler);
    iwc.setInfoStream(infoStream);
    if (mergePolicy instanceof SortingMergePolicy) {
        Sort indexSort = ((SortingMergePolicy) mergePolicy).getSort();
        iwc.setIndexSort(indexSort);
    }
    iwc.setUseCompoundFile(useCompoundFile);
    if (mergedSegmentWarmerInfo != null) {
        // TODO: add infostream -> normal logging system (there is an issue somewhere)
        IndexReaderWarmer warmer = schema.getResourceLoader().newInstance(mergedSegmentWarmerInfo.className, IndexReaderWarmer.class, null, new Class[] { InfoStream.class }, new Object[] { iwc.getInfoStream() });
        iwc.setMergedSegmentWarmer(warmer);
    }
    return iwc;
}
Also used : SortingMergePolicy(org.apache.solr.index.SortingMergePolicy) MergePolicy(org.apache.lucene.index.MergePolicy) SortingMergePolicy(org.apache.solr.index.SortingMergePolicy) Sort(org.apache.lucene.search.Sort) IndexReaderWarmer(org.apache.lucene.index.IndexWriter.IndexReaderWarmer) IndexSchema(org.apache.solr.schema.IndexSchema) ConcurrentMergeScheduler(org.apache.lucene.index.ConcurrentMergeScheduler) MergeScheduler(org.apache.lucene.index.MergeScheduler) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 10 with MergePolicy

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

the class WrapperMergePolicyFactory method getMergePolicy.

/** Returns a wrapping {@link MergePolicy} with its set parameters configured. */
@Override
public final MergePolicy getMergePolicy() {
    final MergePolicy wrappedMP = getWrappedMergePolicy();
    final MergePolicy mp = getMergePolicyInstance(wrappedMP);
    args.invokeSetters(mp);
    return mp;
}
Also used : MergePolicy(org.apache.lucene.index.MergePolicy)

Aggregations

MergePolicy (org.apache.lucene.index.MergePolicy)11 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)5 TieredMergePolicy (org.apache.lucene.index.TieredMergePolicy)5 IndexWriter (org.apache.lucene.index.IndexWriter)3 Sort (org.apache.lucene.search.Sort)3 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)2 ConcurrentMergeScheduler (org.apache.lucene.index.ConcurrentMergeScheduler)2 LogMergePolicy (org.apache.lucene.index.LogMergePolicy)2 MergeScheduler (org.apache.lucene.index.MergeScheduler)2 NoMergePolicy (org.apache.lucene.index.NoMergePolicy)2 UpgradeIndexMergePolicy (org.apache.lucene.index.UpgradeIndexMergePolicy)2 SortField (org.apache.lucene.search.SortField)2 Directory (org.apache.lucene.store.Directory)2 SortingMergePolicy (org.apache.solr.index.SortingMergePolicy)2 IndexSchema (org.apache.solr.schema.IndexSchema)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Analyzer (org.apache.lucene.analysis.Analyzer)1 Document (org.apache.lucene.document.Document)1 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)1