You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by 기준 <0c...@gmail.com> on 2025/03/29 00:23:26 UTC
[Question] What is the `close` contract of sliced IndexInput?
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
Re: [Question] What is the `close` contract of sliced IndexInput?
Posted by Bruno Roustant <br...@gmail.com>.
Ah, ByteBuffersDataInput isn't closeable, as explained by Michael above.
Le mer. 2 avr. 2025 à 15:34, Bruno Roustant <br...@gmail.com> a
écrit :
> Recently I wondered the same question because
>
> BufferedIndexInput.SliceIndexInput.close() calls base.close() where base
> is a clone of the original input (so in the end it's a noop?)
>
> ByteBuffersIndexInput.close() simply sets in = null but does not call
> in.close() (shouldn't it do so?)
>
Re: [Question] What is the `close` contract of sliced IndexInput?
Posted by Bruno Roustant <br...@gmail.com>.
Recently I wondered the same question because
BufferedIndexInput.SliceIndexInput.close() calls base.close() where base is
a clone of the original input (so in the end it's a noop?)
ByteBuffersIndexInput.close() simply sets in = null but does not call
in.close() (shouldn't it do so?)
Re: [Question] What is the `close` contract of sliced IndexInput?
Posted by Uwe Schindler <uw...@thetaphi.de>.
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 <ms...@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 기준 <0c...@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
Re: [Question] What is the `close` contract of sliced IndexInput?
Posted by Michael Froh <ms...@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 기준 <0c...@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
>
Re: [Question] What is the `close` contract of sliced IndexInput?
Posted by Uwe Schindler <uw...@thetaphi.de>.
Hi,
The general contract is that only the original Index input needs to be closed. Slices and clones don't need a close, they are just views on the original input.
All clones or slices always have a noop close method? So it won't hurt to call close.
Uwe
Am 29. März 2025 01:23:26 MEZ schrieb "기준" <0c...@gmail.com>:
>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