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

Ensure validation of the reader context is executed first #61831

Merged
merged 11 commits into from
Sep 7, 2020

Conversation

jimczi
Copy link
Contributor

@jimczi jimczi commented Sep 2, 2020

This change makes sure that we validate the reader context (SearchOperationListener#validateReaderContext)
before any other operation. This bug was introduced in #61062 so I marked this PR as a non-issue since it does not appear in any released version.

Relates #61446
Relates #61062

This change makes sure that we validate the reader context (`SearchOperationListener#validateReaderContext)
before any other operation.

Relates elastic#61446
@jimczi jimczi added >non-issue :Search/Search Search-related issues that do not fall into other categories v8.0.0 v7.10.0 labels Sep 2, 2020
@jimczi jimczi requested a review from dnhatn September 2, 2020 07:51
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Search)

@elasticmachine elasticmachine added the Team:Search Meta label for search team label Sep 2, 2020
Copy link
Member

@dnhatn dnhatn left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks, Jim!

@@ -61,6 +61,7 @@ public LegacyReaderContext(long id, IndexService indexService, IndexShard indexS
if (searcher == null) {
Engine.Searcher delegate = searcherSupplier.acquireSearcher(source);
onClose = delegate::close;
// wrap the searcher so that closing is a noop, the actual closing happens when this context is closed
Copy link
Member

Choose a reason for hiding this comment

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

++

Copy link
Member

Choose a reason for hiding this comment

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

@jimczi I looked at this again (while investigating the perf issue). I think we need to double-check with synchronization before acquiring a searcher to avoid leaking it.

Copy link
Member

Choose a reason for hiding this comment

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

Or we can just always addOnClose(delegate) instead.

Copy link
Member

Choose a reason for hiding this comment

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

I found another issue while investigating the perf issue. We don't have a happens-before relation between the initial search and subsequent scroll requests. The searcher field needs to be volatile; otherwise, we might acquire and wrap searcher more than once. I've pushed 0c42f9c. Let me know if you are ok with this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch, thanks!

@jimczi
Copy link
Contributor Author

jimczi commented Sep 7, 2020

@elasticmachine run elasticsearch-ci/packaging-sample-windows

@jimczi jimczi merged commit 38dc926 into elastic:master Sep 7, 2020
@jimczi jimczi deleted the search_op_listener_validation branch September 7, 2020 08:47
@jimczi jimczi removed the v7.10.0 label Sep 7, 2020
dnhatn added a commit to dnhatn/elasticsearch that referenced this pull request Sep 10, 2020
)

This change makes sure that reader context is validated (`SearchOperationListener#validateReaderContext)
before any other operation and that it is correctly recycled or removed at the end of the operation.
This commit also fixes a race condition bug that would allocate the security reader for scrolls more than once.

Relates elastic#61446

Co-authored-by: Nhat Nguyen <[email protected]>
dnhatn added a commit that referenced this pull request Sep 10, 2020
This change makes sure that reader context is validated (`SearchOperationListener#validateReaderContext)
before any other operation and that it is correctly recycled or removed at the end of the operation.
This commit also fixes a race condition bug that would allocate the security reader for scrolls more than once.

Relates #61446

Co-authored-by: Nhat Nguyen <[email protected]>
@dnhatn
Copy link
Member

dnhatn commented Sep 10, 2020

I've backported this in 4d528e9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>non-issue :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team v7.10.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants