Skip to content

Use a threadsafe map in SearchAsyncActionTests #34506

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

Merged

Conversation

danielmitterdorfer
Copy link
Member

Today SearchAsyncActionTests#testFanOutAndCollect uses a simple HashMap for
the nodeToContextMap variable, which is then accessed from multiple threads
without, apparently, explicit synchronisation. This provides an explanation for
the test failure identified in #29242 in which .toString() returns "[]"
just before .isEmpty returns false, without any concurrent modifications.

This change converts nodeToContextMap to a newConcurrentMap() so that this
cannot occur. It also fixes a race condition in the detection of double-calling
the subsequent search phase.

This is a backport of #33700 to 5.6.

Relates #33700
Relates #29242

Today `SearchAsyncActionTests#testFanOutAndCollect` uses a simple `HashMap` for
the `nodeToContextMap` variable, which is then accessed from multiple threads
without, apparently, explicit synchronisation. This provides an explanation for
the test failure identified in elastic#29242 in which `.toString()` returns `"[]"`
just before `.isEmpty` returns `false`, without any concurrent modifications.

This change converts `nodeToContextMap` to a `newConcurrentMap()` so that this
cannot occur. It also fixes a race condition in the detection of double-calling
the subsequent search phase.

This is a backport of elastic#33700 to 5.6.

Relates elastic#33700
Relates elastic#29242
@danielmitterdorfer danielmitterdorfer added >test Issues or PRs that are addressing/adding tests :Search/Search Search-related issues that do not fall into other categories v5.6.13 labels Oct 16, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@danielmitterdorfer
Copy link
Member Author

As this was not a clean cherry-pick to 5.6 I've created a separate PR. I'd appreciate if you could have a look @DaveCTurner as you've created the original PR.

Copy link
Contributor

@DaveCTurner DaveCTurner left a comment

Choose a reason for hiding this comment

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

LGTM. I think we could not have backported the latchTriggered thing since the corresponding assertion was only introduced to investigate #29242 (and I don't know that it ever fired) but there's no harm in doing so.

@danielmitterdorfer
Copy link
Member Author

Ok. Basically I just backported the changes in #33700 verbatim. Thanks for your review; I'll merge as is then.

@danielmitterdorfer danielmitterdorfer merged commit 06e8b46 into elastic:5.6 Oct 16, 2018
@danielmitterdorfer danielmitterdorfer deleted the conc-map-test-backport branch October 16, 2018 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Search/Search Search-related issues that do not fall into other categories >test Issues or PRs that are addressing/adding tests v5.6.13
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants