paulirwin commented on code in PR #1138:
URL: https://github.com/apache/lucenenet/pull/1138#discussion_r1987678092
##########
src/Lucene.Net/Store/MMapDirectory.cs:
##########
@@ -314,7 +314,7 @@ internal virtual ByteBuffer[] Map(MMapIndexInput input,
FileStream fc, long offs
input.memoryMappedFile = MemoryMappedFile.CreateFromFile(
fileStream: fc,
mapName: null,
- capacity: length,
+ capacity: fc.Length, // use the full length of the file
Review Comment:
If `FileStream.Length` is not reliable (I do not believe this to be the
case) then we have bigger problems, because the only caller to this internal
method passes in `fc.Length` as the `length` argument (see line 243). My
hypothesis (since this bug is not reproducible) was that the file length on
disk was growing between the call to this method and the call to create the
memory mapped file as a race condition. I'm fine with reverting it and letting
this fail in that case, it might have just been a one-off fluke. But note that
if the reason for reverting it is that `FileStream.Length` is unreliable, then
the calling code would be invalid as well (additionally, CreateFromFile would
be bogus too, as no matter what we pass, it uses that same property to check
the capacity argument). I do not think we should assume that it is unreliable
and try to work around that unless you have a proposed solution. But I'm also
fine with accepting this code as possibly rarely concurrency-unsafe.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]