-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Streamline top level reader close listeners and forbid general usage #14084
Conversation
@@ -76,4 +74,38 @@ public LeafReader wrap(LeafReader reader) { | |||
} | |||
} | |||
|
|||
@SuppressForbidden(reason = "This is the only sane way to add a ReaderClosedListener") | |||
public static void addReaderCloseListener(IndexReader reader, IndexReader.ReaderClosedListener listener) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good in the future if we could refine this to just DirectoryReader? Really IMO nobody should be installing a readerCloseListener
on a LeafReader... caching etc should always be managed via coreCloseListener
I like the changes, thanks for improving the type safety. when merging master you can drop changes in Versions.java as it now uses a core-closed listener. |
IndexReader#addReaderCloseListener is very error prone when it comes to caching and reader wrapping. The listeners are not delegated to the sub readers nor can it's implementation change since it's final in the base class. This commit only allows installing close listeners on the top level ElasticsearchDirecotryReader which is known to work an has a defined lifetime which corresponds to its subreader. This ensure that cachesa re cleared once the reader goes out of scope.
this commit also fixes a bug where we wramed a leaf reader in a top level context which caused atomic segment readers to be used in our top level caches.
8340fa7
to
e3f00e3
Compare
if (reader() instanceof DirectoryReader) { | ||
return (DirectoryReader) reader(); | ||
} | ||
throw new IllegalStateException("Can't use " + reader().getClass() + " as an directory reader"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/an/a/
} | ||
} | ||
|
||
final class NonClosingReaderWrapper extends FilterDirectoryReader { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can it be static?
LGTM, just left very minor comments |
looks good here too. i have nothing to add to adrien's suggestions. this is a good cleanup! |
Streamline top level reader close listeners and forbid general usage
Streamline top level reader close listeners and forbid general usage
Streamline top level reader close listeners and forbid general usage
Streamline top level reader close listeners and forbid general usage
IndexReader#addReaderCloseListener is very error prone when it comes to
caching and reader wrapping. The listeners are not delegated to the sub readers
nor can it's implementation change since it's final in the base class. This commit
only allows installing close listeners on the top level ElasticsearchDirecotryReader
which is known to work an has a defined lifetime which corresponds to its subreader.
This ensure that caches are cleared once the reader goes out of scope.