From 76f5254a75de7c6e75502369cd53b8bc35e99d8a Mon Sep 17 00:00:00 2001 From: Dawid Weiss Date: Tue, 10 Dec 2024 19:26:18 +0100 Subject: [PATCH] IndexInput.isLoaded seems to return false for mmap index inputs on Windows #14050 (#14053) --- .../lucene/store/MemorySegmentIndexInput.java | 13 +++++++++++-- .../lucene/tests/store/BaseDirectoryTestCase.java | 6 +++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lucene/core/src/java21/org/apache/lucene/store/MemorySegmentIndexInput.java b/lucene/core/src/java21/org/apache/lucene/store/MemorySegmentIndexInput.java index 2fc9f6369b7..2424b53645b 100644 --- a/lucene/core/src/java21/org/apache/lucene/store/MemorySegmentIndexInput.java +++ b/lucene/core/src/java21/org/apache/lucene/store/MemorySegmentIndexInput.java @@ -27,6 +27,7 @@ import java.util.Objects; import java.util.Optional; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.BitUtil; +import org.apache.lucene.util.Constants; import org.apache.lucene.util.GroupVIntUtil; import org.apache.lucene.util.IOConsumer; @@ -422,12 +423,20 @@ abstract class MemorySegmentIndexInput extends IndexInput @Override public Optional isLoaded() { + boolean isLoaded = true; for (MemorySegment seg : segments) { if (seg.isLoaded() == false) { - return Optional.of(Boolean.FALSE); + isLoaded = false; + break; } } - return Optional.of(Boolean.TRUE); + + if (Constants.WINDOWS && isLoaded == false) { + // see https://github.com/apache/lucene/issues/14050 + return Optional.empty(); + } + + return Optional.of(isLoaded); } @Override diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/store/BaseDirectoryTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/tests/store/BaseDirectoryTestCase.java index d8ec0529b5f..6defa5eb8c7 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/tests/store/BaseDirectoryTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/tests/store/BaseDirectoryTestCase.java @@ -63,6 +63,7 @@ import org.apache.lucene.tests.util.LuceneTestCase; import org.apache.lucene.tests.util.TestUtil; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.BitUtil; +import org.apache.lucene.util.Constants; import org.apache.lucene.util.GroupVIntUtil; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.packed.PackedInts; @@ -1667,7 +1668,10 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase { in = orig.slice("slice", startOffset, totalLength - startOffset); } var loaded = in.isLoaded(); - if (FilterDirectory.unwrap(dir) instanceof MMapDirectory + + if (Constants.WINDOWS) { + // On Windows, we temporarily don't care until this is fixed: #14050 + } else if (FilterDirectory.unwrap(dir) instanceof MMapDirectory // direct IO wraps MMap but does not support isLoaded && !(dir.getClass().getName().contains("DirectIO"))) { assertTrue(loaded.isPresent());