Skip to content

Commit

Permalink
IndexInput.isLoaded seems to return false for mmap index inputs on Wi…
Browse files Browse the repository at this point in the history
…ndows #14050 (#14053)
  • Loading branch information
dweiss committed Dec 11, 2024
1 parent 4cdb673 commit 1d370a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;

Expand Down Expand Up @@ -422,12 +423,20 @@ void advise(long offset, long length, IOConsumer<MemorySegment> advice) throws I

@Override
public Optional<Boolean> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
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;
Expand Down Expand Up @@ -1667,7 +1668,10 @@ private void testIsLoaded(int startOffset) throws IOException {
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());
Expand Down

0 comments on commit 1d370a9

Please sign in to comment.