[
https://issues.apache.org/jira/browse/OAK-2799?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14506957#comment-14506957
]
Tommaso Teofili edited comment on OAK-2799 at 4/22/15 12:10 PM:
----------------------------------------------------------------
attached first patch.
{{OakIndexInput}} "original" (not cloned) instances have a {{WeakIdentityMap}}
holding references to clones once they get created.
Such clones get closed upon closing of the original instance.
An {{AlreadyClosedException}} is raised if {{OakIndexInput}} are already closed.
IntelliJ keeps telling me we should use {{super#clone}} in
{{OakIndexInput#clone}} and that would be inline with the usage of
{{WeakIdentityMap}} (using reference equality instead of {{#toString}} for key
comparison), otherwise it's probably safe to switch to a {{WeakHashMap}}, even
if that impl is not concurrent and therefore may require _synchronizing_ on
that or wrapping it with a concurrent version.
was (Author: teofili):
attached first patch.
{{OakIndexInput}} "original" (not cloned) instances have a {{WeakIdentityMap}}
holding references to clones once they get created.
Such clones get closed upon closing of the original instance.
An {{AlreadyClosedException}} are raised if {{OakIndexInput}} are already
closed.
IntelliJ keeps telling me we should use {{super#clone}} in
{{OakIndexInput#clone}} and that would be inline with the usage of
{{WeakIdentityMap}} (using reference equality instead of {{#toString}} for key
comparison), otherwise it's probably safe to switch to a {{WeakHashMap}}, even
if that impl is not concurrent and therefore may require _synchronizing_ on
that or wrapping it with a concurrent version.
> OakIndexInput cloned instances are not closed
> ---------------------------------------------
>
> Key: OAK-2799
> URL: https://issues.apache.org/jira/browse/OAK-2799
> Project: Jackrabbit Oak
> Issue Type: Bug
> Components: lucene
> Affects Versions: 1.2.1
> Reporter: Tommaso Teofili
> Assignee: Tommaso Teofili
> Fix For: 1.3.0, 1.2.2, 1.0.14
>
> Attachments: OAK-2799.0.patch
>
>
> Related to the inspections I was doing for OAK-2798 I also noticed that we
> don't fully comply with the {{IndexInput}} javadoc [1] as the cloned
> instances should throw the given exception if original is closed, but I also
> think that the original instance should close the cloned instances, see also
> [ByteBufferIndexInput#close|https://github.com/apache/lucene-solr/blob/lucene_solr_4_7_1/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java#L271].
> [1] : {code}
> /** Abstract base class for input from a file in a {@link Directory}. A
> * random-access input stream. Used for all Lucene index input operations.
> *
> * <p>{@code IndexInput} may only be used from one thread, because it is not
> * thread safe (it keeps internal state like file position). To allow
> * multithreaded use, every {@code IndexInput} instance must be cloned before
> * used in another thread. Subclasses must therefore implement {@link
> #clone()},
> * returning a new {@code IndexInput} which operates on the same underlying
> * resource, but positioned independently. Lucene never closes cloned
> * {@code IndexInput}s, it will only do this on the original one.
> * The original instance must take care that cloned instances throw
> * {@link AlreadyClosedException} when the original one is closed.
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)