-
-
Notifications
You must be signed in to change notification settings - Fork 671
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
fixes race condition in Searcher #1464
Conversation
fixes #1461 fixes a race condition in Searcher, by avoiding repeated calls to open_segment_readers and passing them instead as argument
667edff
to
097a0b6
Compare
Codecov Report
@@ Coverage Diff @@
## main #1464 +/- ##
==========================================
- Coverage 94.07% 94.06% -0.01%
==========================================
Files 238 239 +1
Lines 44564 44636 +72
==========================================
+ Hits 41922 41989 +67
- Misses 2642 2647 +5
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
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.
@PSeitz aside from clippy nits, LGTM
I did have one unrelated change I was sneaking into my PR, that I wanted to ask about.
Is Relaxed
memory order safe here? Both a load and store are happening, so AcqRel
seems safer to me. And this is by no means a hot path so being conservative seems fair.
Line 212 in 998b126
let generation_id = searcher_generation_counter.fetch_add(1, atomic::Ordering::Relaxed); |
@@ -204,7 +201,7 @@ impl InnerIndexReader { | |||
Ok(segment_readers) | |||
} | |||
|
|||
fn create_new_searcher_generation( | |||
fn track_segment_readers_in_inventory( |
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.
The previous name seems better to me, since we are creating a SearcherGeneration
and making sure to do it in a way that we track it int the inventory, and the inventory tracks SearcherGeneration
not segment readers.
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.
my issue with the previous name was that it's not clear that inventory is used to track and not the source of the generation
Yeah, I think there could be scenarios where simultaneous reloads are triggered at the same time from multiple threads. |
@shikhar The operation is still Atomic... I think we just want to ensure that the id delivered are unique, and Relaxed is sufficient for that. AcqRel stuff is about instruction reordering. |
I think it could be an issue when two threads increment, but due to weak fencing, we get two times the same value back. If now one of those callers has a new segment in their list, we have the same id to different It's very unlikely though, and on many platforms Relaxed is already AcqRel. |
The memory orderings mostly determine how other memory accesses are ordered w.r.t. the atomic accesses, they do not affect the atomicity of an operation like However, their accesses to other memory locations that are shared with other threads will not be ordered w.r.t. the ID generation, e.g. their accesses to While I suspect that this is not an issue (this would have involve unsafe code if I understand things correctly), my personal choice would be |
This is a very bad argument :). Also ARM is pretty popular.
You cannot get two times the same value back... That's not what ordering is about. ... Anyway let's defensively go for |
Thanks folks, I need to learn more about memory orderings :) |
fixes #1461
fixes a race condition in Searcher, by avoiding repeated calls to open_segment_readers and passing them instead as argument