Just to complement your statement:

The default MMapDirectory uses MemorySegmentIndexInput. This one implements the 
close logic similar so Clones or slices cannot be closed: They do not get the 
Arena which controls lifetime of file mapping (it is null): 
<https://github.com/apache/lucene/blob/dba6c2c2fd98dce4a1348109ecad09cd3ba44e5f/lucene/core/src/java21/org/apache/lucene/store/MemorySegmentIndexInput.java#L699>

Here it is cloned or sliced: 
<https://github.com/apache/lucene/blob/dba6c2c2fd98dce4a1348109ecad09cd3ba44e5f/lucene/core/src/java21/org/apache/lucene/store/MemorySegmentIndexInput.java#L569>

Uwe

Am 31. März 2025 20:10:18 MESZ schrieb Michael Froh <msf...@gmail.com>:
>Checking a few of the implementations, the general rule seems to be that
>sliced IndexInput instances don't get closed or the close operation is a
>no-op.
>
>For example, in NIOFSIndexInput, the slice constructor sets isClone to
>true, which make the close() method a no-op:
>https://github.com/apache/lucene/blob/7e20d5b3aad13739a2ae9fa36774e68ccae43ac4/lucene/core/src/java/org/apache/lucene/store/NIOFSDirectory.java#L123
>
>Similarly, for DirectIOIndexInput, the slice constructor sets isClosable to
>false, which makes close() a no-op:
>https://github.com/apache/lucene/blob/f8fac44b321ee089571f1cee31fa1d90046d7c01/lucene/misc/src/java/org/apache/lucene/misc/store/DirectIODirectory.java#L330
>
>ByteBuffersIndexInput has a close() method that doesn't close anything
>(since ByteBuffersDataInput isn't closeable):
>https://github.com/apache/lucene/blob/cfdd20f5bc8387ba24653ca2ba15aa5be10d0ae0/lucene/core/src/java/org/apache/lucene/store/ByteBuffersIndexInput.java#L37
>
>So, the implicit contract seems to be that it's okay to close a sliced
>IndexInput, but it's not necessary.
>
>Hope that helps,
>Froh
>
>
>On Fri, Mar 28, 2025 at 5:26 PM 기준 <0ctopus13pr...@gmail.com> wrote:
>
>> Hi all, hope you are doing great.
>>
>> Wondering what is the contract of `close` of sliced IndexInput?
>> Could not find any related documents wrt this.
>>
>> I find many places in Lucene do not close sliced IndexInput, and when
>> cleaning resources, it just close origin IndexInput.
>>
>> Would appreciate it if someone could help clarify the contract.
>> Fundamental question is that can we skip calling `close` a sliced
>> IndexInput??
>>
>> Thank you
>>

--
Uwe Schindler
Achterdiek 19, 28357 Bremen
https://www.thetaphi.de

Reply via email to