Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Searchable Snapshot] IndexInput clones close handling #5243

Closed
Tracked by #5087
aabukhalil opened this issue Nov 14, 2022 · 3 comments · Fixed by #6351
Closed
Tracked by #5087

[Searchable Snapshot] IndexInput clones close handling #5243

aabukhalil opened this issue Nov 14, 2022 · 3 comments · Fixed by #6351
Assignees
Labels
distributed framework enhancement Enhancement or improvement to existing feature or request

Comments

@aabukhalil
Copy link
Contributor

When Lucene clones IndexInput it will not close it, it will only close the original IndexInput. So we need to keep track of the cloned IndexInputs and close them when they are not used anymore. Scope here is find how to detect the unused IndexInput, is relying on GC and Cleaner is the only option here ? and then implement it

@aabukhalil
Copy link
Contributor Author

this has been estimated as 5 points

@andrross
Copy link
Member

andrross commented Jan 3, 2023

Since the cloned instances are never explicitly closed, then java.lang.ref.Cleaner is the supported mechanism in Java for tracking when those references are no longer in use.

However, given the stated behavior from Lucene:

If you access the cloned IndexInput after closing the original object, any readXXX methods will throw AlreadyClosedException.

Then the question is whether we need to track the cloned instances at all? Per the API contract the cloned instances should become unusable when the original instance is closed, so for the purpose of reference counting and ensuring the underlying cached objects remain alive then it seems possible that we can only track the original instance and ignore the clones (because Lucene ensures that cloned instances are never used beyond the lifetime of the original). We might need to add logic to the clones to fail with the appropriate AlreadyClosedException if they are accessed after the original is closed.

@andrross
Copy link
Member

andrross commented Jan 20, 2023

Then the question is whether we need to track the cloned instances at all?

The answer to this question is "yes". With the caching design, and IndexInput instance may end up fetching any number blocks from the cache. Beyond that, the cloned IndexInput instances may fetch different blocks from the cache than the original IndexInput. An alternative approach that doesn't require using the Cleaner could be to have the original IndexInput hold a reference to every block that it or its cloned IndexInputs touched throughout the lifetime of the original, and then release them all when the original is closed. Since we don't control how long that original IndexInput will stay alive, it is better to free the resources using the Cleaner when the clones become unreachable (which may happen while the original IndexInput is still being used, therefore releasing resources sooner than the alternative approach would).

andrross added a commit to andrross/OpenSearch that referenced this issue Feb 16, 2023
As detailed [in this issue][1], Lucene does not close the cloned
IndexInput instances, so we are using the Cleaner mechanism from the JDK
to close any unclosed clones.

A single static Cleaner instance to ensure any unclosed clone of an
IndexInput is closed. This instance creates a single daemon thread on
which it performs the cleaning actions. For an already-closed
IndexInput, the cleaning action is a no-op. For an open IndexInput, the
close action will decrement a reference count.

[1]: opensearch-project#5243 (comment)

Signed-off-by: Andrew Ross <andrross@amazon.com>
andrross added a commit to andrross/OpenSearch that referenced this issue Feb 17, 2023
As detailed [in this issue][1], Lucene does not close the cloned
IndexInput instances, so we are using the Cleaner mechanism from the JDK
to close any unclosed clones.

A single static Cleaner instance to ensure any unclosed clone of an
IndexInput is closed. This instance creates a single daemon thread on
which it performs the cleaning actions. For an already-closed
IndexInput, the cleaning action is a no-op. For an open IndexInput, the
close action will decrement a reference count.

[1]: opensearch-project#5243 (comment)

Signed-off-by: Andrew Ross <andrross@amazon.com>
andrross added a commit to andrross/OpenSearch that referenced this issue Feb 17, 2023
As detailed [in this issue][1], Lucene does not close the cloned
IndexInput instances, so we are using the Cleaner mechanism from the JDK
to close any unclosed clones.

A single static Cleaner instance to ensure any unclosed clone of an
IndexInput is closed. This instance creates a single daemon thread on
which it performs the cleaning actions. For an already-closed
IndexInput, the cleaning action is a no-op. For an open IndexInput, the
close action will decrement a reference count.

[1]: opensearch-project#5243 (comment)

Signed-off-by: Andrew Ross <andrross@amazon.com>
andrross added a commit to andrross/OpenSearch that referenced this issue Feb 17, 2023
As detailed [in this issue][1], Lucene does not close the cloned
IndexInput instances, so we are using the Cleaner mechanism from the JDK
to close any unclosed clones.

A single static Cleaner instance to ensure any unclosed clone of an
IndexInput is closed. This instance creates a single daemon thread on
which it performs the cleaning actions. For an already-closed
IndexInput, the cleaning action is a no-op. For an open IndexInput, the
close action will decrement a reference count.

[1]: opensearch-project#5243 (comment)

Signed-off-by: Andrew Ross <andrross@amazon.com>
andrross added a commit to andrross/OpenSearch that referenced this issue Feb 17, 2023
As detailed [in this issue][1], Lucene does not close the cloned
IndexInput instances, so we are using the Cleaner mechanism from the JDK
to close any unclosed clones.

A single static Cleaner instance to ensure any unclosed clone of an
IndexInput is closed. This instance creates a single daemon thread on
which it performs the cleaning actions. For an already-closed
IndexInput, the cleaning action is a no-op. For an open IndexInput, the
close action will decrement a reference count.

[1]: opensearch-project#5243 (comment)

Signed-off-by: Andrew Ross <andrross@amazon.com>
andrross added a commit that referenced this issue Feb 17, 2023
As detailed [in this issue][1], Lucene does not close the cloned
IndexInput instances, so we are using the Cleaner mechanism from the JDK
to close any unclosed clones.

A single static Cleaner instance to ensure any unclosed clone of an
IndexInput is closed. This instance creates a single daemon thread on
which it performs the cleaning actions. For an already-closed
IndexInput, the cleaning action is a no-op. For an open IndexInput, the
close action will decrement a reference count.

[1]: #5243 (comment)

Signed-off-by: Andrew Ross <andrross@amazon.com>
opensearch-trigger-bot bot pushed a commit that referenced this issue Feb 17, 2023
As detailed [in this issue][1], Lucene does not close the cloned
IndexInput instances, so we are using the Cleaner mechanism from the JDK
to close any unclosed clones.

A single static Cleaner instance to ensure any unclosed clone of an
IndexInput is closed. This instance creates a single daemon thread on
which it performs the cleaning actions. For an already-closed
IndexInput, the cleaning action is a no-op. For an open IndexInput, the
close action will decrement a reference count.

[1]: #5243 (comment)

Signed-off-by: Andrew Ross <andrross@amazon.com>
(cherry picked from commit dae1566)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
andrross pushed a commit that referenced this issue Feb 17, 2023
As detailed [in this issue][1], Lucene does not close the cloned
IndexInput instances, so we are using the Cleaner mechanism from the JDK
to close any unclosed clones.

A single static Cleaner instance to ensure any unclosed clone of an
IndexInput is closed. This instance creates a single daemon thread on
which it performs the cleaning actions. For an already-closed
IndexInput, the cleaning action is a no-op. For an open IndexInput, the
close action will decrement a reference count.

[1]: #5243 (comment)


(cherry picked from commit dae1566)

Signed-off-by: Andrew Ross <andrross@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distributed framework enhancement Enhancement or improvement to existing feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants