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

fix: mutations batcher race condition #896

Merged
merged 15 commits into from Dec 12, 2023
Merged

Conversation

daniel-sanche
Copy link
Contributor

@daniel-sanche daniel-sanche commented Dec 11, 2023

There was a race condition found in the threaded mutations batcher. The batcher would check the state of the queue, and then read from the queue as separate steps, which left room for other threads to change the state in between

This PR addresses the problem with the following changes:

  • queue.get will now return None if the queue is empty. This allows us to check the state and get the next items in an atomic operation, replacing the need for queue.empty
  • rewrote the _flush_async implementation, to simplify it and make it more thread-safe

@daniel-sanche daniel-sanche requested review from a team as code owners December 11, 2023 19:38
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: bigtable Issues related to the googleapis/python-bigtable API. labels Dec 11, 2023
google/cloud/bigtable/batcher.py Outdated Show resolved Hide resolved
google/cloud/bigtable/batcher.py Outdated Show resolved Hide resolved
google/cloud/bigtable/batcher.py Outdated Show resolved Hide resolved
google/cloud/bigtable/batcher.py Show resolved Hide resolved
@daniel-sanche daniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 12, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 12, 2023
Copy link
Contributor

@igorbernstein2 igorbernstein2 left a comment

Choose a reason for hiding this comment

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

lgtm

@daniel-sanche daniel-sanche added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 12, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Dec 12, 2023
@daniel-sanche daniel-sanche merged commit fe58f61 into main Dec 12, 2023
23 of 29 checks passed
@daniel-sanche daniel-sanche deleted the fix_batcher_threads branch December 12, 2023 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigtable Issues related to the googleapis/python-bigtable API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants