Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ Bug Fixes

* GITHUB#17019: Fix int overflow bugs when sizing FuzzySet. (Greg Miller)

* GITHUB#17053: Avoid flushing pending DocValues updates to disk for merging segments. (Ke Wei)

Changes in Runtime Behavior
---------------------
* GITHUB#14187: The query cache is now disabled by default. (Adrien Grand)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5481,10 +5481,14 @@ private synchronized void closeMergeReaders(
rld.dropChanges();
}
rld.release(sr);
release(rld);
if (drop) {
// Drop the merged-away segment from the pool before releasing it, so that
// release() doesn't write its pending DV updates: they were already carried over to
// the merged segment, and the checkpoint after the write could delete update files
// that other source segments of this merge still need.
readerPool.drop(rld.info);
}
release(rld);
}
deleter.decRef(mr.reader.getSegmentInfo().files());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.lucene.document.BinaryDocValuesField;
import org.apache.lucene.document.Document;
Expand All @@ -48,6 +49,67 @@
*/
public class TestMergeCarryOverFromDisk extends LuceneTestCase {

public void testReleasePendingUpdatesWithoutReaderPooling() throws Exception {
IndexWriterConfig conf =
new IndexWriterConfig()
.setReaderPooling(false)
.setMergeScheduler(new SerialMergeScheduler())
.setMaxDocValuesOverlays(1);
try (MergePausingDirectory dir = new MergePausingDirectory(newDirectory())) {
try (IndexWriter writer = new IndexWriter(dir, conf)) {
// Create two source segments with the same id so each update affects both documents.
for (int segment = 0; segment < 2; segment++) {
Document document = new Document();
document.add(new StringField("id", "0", StringField.Store.NO));
document.add(new NumericDocValuesField("ndv", 0));
writer.addDocument(document);
writer.flush();
}
Thread merger =
new Thread(
() -> {
try {
writer.forceMerge(1);
} catch (Throwable t) {
dir.failure.set(t);
}
},
"forceMerge");
merger.start();
try {
// Pause the merge until creating the pending update DV delta.
assertTrue(dir.mergeStarted.await(60, TimeUnit.SECONDS));
// Creating the new dv delta files to the two segments with written to disk.
writer.updateNumericDocValue(new Term("id", "0"), "ndv", 100);
writer.flush();
// Crating another update without writing all pending DV updates to disk.
writer.updateNumericDocValue(new Term("id", "0"), "ndv", 200);
writer.addDocument(new Document());
// Only flush the empty document buffer, without written DV to disk, to make sure we can
// trigger the written DV updates to disk in merge thread.
assertTrue(writer.flushNextBuffer());
} finally {
dir.resumeMerge.countDown();
merger.join(60000);
}
assertFalse(merger.isAlive());
assertNull("forceMerge failed: " + dir.failure.get(), dir.failure.get());
writer.commit();
Comment thread
kkewwei marked this conversation as resolved.
Resolved
try (DirectoryReader reader = DirectoryReader.open(dir)) {
assertEquals(3, reader.numDocs());
int updatedDocs = 0;
NumericDocValues values = MultiDocValues.getNumericValues(reader, "ndv");
while (values.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
assertEquals(200, values.longValue());
updatedDocs++;
}
// Both two documents must retain the latest value.
assertEquals(2, updatedDocs);
}
}
}
}

/** Wraps a directory, pausing the first merge output write until the test releases it. */
private static class MergePausingDirectory extends FilterDirectory {
final CountDownLatch mergeStarted = new CountDownLatch(1);
Expand Down
Loading