diff --git a/pom.xml b/pom.xml index c01dcc5..fb4ded9 100644 --- a/pom.xml +++ b/pom.xml @@ -501,6 +501,8 @@ false false true + true + true diff --git a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java index 3b11c2f..32fa3a8 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/LLLocalLuceneIndex.java @@ -51,6 +51,7 @@ import java.util.concurrent.Phaser; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantLock; +import org.apache.commons.lang3.time.StopWatch; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper; @@ -60,6 +61,7 @@ import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.KeepOnlyLastCommitDeletionPolicy; import org.apache.lucene.index.MergeScheduler; import org.apache.lucene.index.SerialMergeScheduler; +import org.apache.lucene.index.SimpleMergedSegmentWarmer; import org.apache.lucene.index.SnapshotDeletionPolicy; import org.apache.lucene.index.TieredMergePolicy; import org.apache.lucene.misc.store.DirectIODirectory; @@ -222,6 +224,7 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { indexWriterConfig.setCommitOnClose(true); var mergePolicy = new TieredMergePolicy(); indexWriterConfig.setMergePolicy(mergePolicy); + indexWriterConfig.setMergedSegmentWarmer(new SimpleMergedSegmentWarmer(null)); int writerSchedulerMaxThreadCount; MergeScheduler mergeScheduler; if (lowMemory) { @@ -334,16 +337,21 @@ public class LLLocalLuceneIndex implements LLLuceneIndex { @Override public Mono addDocuments(Flux> documents) { - return documents.collectList().flatMap(documentsList -> this.runSafe(() -> docIndexingTime.recordCallable(() -> { - double count = documentsList.size(); - startedDocIndexings.increment(count); + return documents.collectList().flatMap(documentsList -> this.runSafe(() -> { + var count = documentsList.size(); + StopWatch stopWatch = StopWatch.createStarted(); try { - indexWriter.addDocuments(LLUtils.toDocumentsFromEntries(documentsList)); + startedDocIndexings.increment(count); + try { + indexWriter.addDocuments(LLUtils.toDocumentsFromEntries(documentsList)); + } finally { + endeddDocIndexings.increment(count); + } } finally { - endeddDocIndexings.increment(count); + docIndexingTime.record(stopWatch.getTime(TimeUnit.MILLISECONDS) / Math.max(count, 1), TimeUnit.MILLISECONDS); } return null; - }))).transform(this::ensureOpen); + })).transform(this::ensureOpen); } diff --git a/src/main/java/it/cavallium/dbengine/database/disk/OptimisticRocksDBColumn.java b/src/main/java/it/cavallium/dbengine/database/disk/OptimisticRocksDBColumn.java index 5291a9d..a73ba65 100644 --- a/src/main/java/it/cavallium/dbengine/database/disk/OptimisticRocksDBColumn.java +++ b/src/main/java/it/cavallium/dbengine/database/disk/OptimisticRocksDBColumn.java @@ -96,6 +96,7 @@ public final class OptimisticRocksDBColumn extends AbstractRocksDBColumn