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

Streamline top level reader close listeners and forbid general usage #14084

Merged
merged 11 commits into from
Oct 14, 2015

Conversation

s1monw
Copy link
Contributor

@s1monw s1monw commented Oct 13, 2015

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.

@@ -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) {
Copy link
Contributor

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

@rmuir
Copy link
Contributor

rmuir commented Oct 13, 2015

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.
@s1monw s1monw force-pushed the close_the_wrapper_only branch from 8340fa7 to e3f00e3 Compare October 13, 2015 15:25
@s1monw
Copy link
Contributor Author

s1monw commented Oct 13, 2015

@rmuir I found a couple of more bugs, I think you should take another look - this change pays off though.... also @jpountz can you take a look if you have a chance?

if (reader() instanceof DirectoryReader) {
return (DirectoryReader) reader();
}
throw new IllegalStateException("Can't use " + reader().getClass() + " as an directory reader");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/an/a/

@s1monw
Copy link
Contributor Author

s1monw commented Oct 13, 2015

@jpountz @rmuir I pushed a new commit cleaning up several things, I think we are pretty ready here

}
}

final class NonClosingReaderWrapper extends FilterDirectoryReader {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it be static?

@jpountz
Copy link
Contributor

jpountz commented Oct 13, 2015

LGTM, just left very minor comments

@rmuir
Copy link
Contributor

rmuir commented Oct 14, 2015

looks good here too. i have nothing to add to adrien's suggestions. this is a good cleanup!

s1monw added a commit that referenced this pull request Oct 14, 2015
Streamline top level reader close listeners and forbid general usage
@s1monw s1monw merged commit 5828796 into elastic:master Oct 14, 2015
@s1monw s1monw deleted the close_the_wrapper_only branch October 14, 2015 07:39
s1monw added a commit that referenced this pull request Oct 14, 2015
Streamline top level reader close listeners and forbid general usage
s1monw added a commit to s1monw/elasticsearch that referenced this pull request Oct 14, 2015
Streamline top level reader close listeners and forbid general usage
s1monw added a commit to s1monw/elasticsearch that referenced this pull request Oct 14, 2015
Streamline top level reader close listeners and forbid general usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants