Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Shutdown Kafka consumers and producer when the external stream is stopped #645
Shutdown Kafka consumers and producer when the external stream is stopped #645
Changes from 1 commit
5463b8a
c0511fe
db68d76
c419ef5
5308950
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
multiple thread unsafe ? one thread call
shutdown
, another thread callconsumeBatch
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 appears there is still race
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.
No, an atomic is not needed here, there won't be a race.
So, the
stopped
flag is to for telling theConsumer
(and theProducer
in the below case) that it's already stopped. And, when we setstopped
totrue
, we don't do anything else ( like, we don't detroy anything ), so there is nothing to guard with it, i.e. there is no such logic in our code:So there is no race.
The purpose is to to let operations on the
Consumer
fail, but it does not have to fail immediately. Take your case as an example, if one thread callshutdown
, and another callconsumeBatch
, it's fine, it does not care which one wins, evenconsumeBatch
wins, nothing bad will happen, and next time whenconsumeBatch
is called, it will fail as expected, and then,KafkaSource
will stopped reading more data. And also, we don't even need to guardshutdown
, it can be called multiple times, no side effects.Please let me know if this does not make sense to you.
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.
Regardless it does not have any impact in current implementation, I reverted it back, and now use
std::atomic_flag
.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 race i meant it not the stopped data member but at high level..
isStopped()
, returns false, context switch to 2)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.
Same for producer and we run into this problem before