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

feat: Minimize contention in Bigtable Client initialization. #2923

Merged
merged 2 commits into from
Jul 31, 2019

Conversation

coryan
Copy link
Contributor

@coryan coryan commented Jul 30, 2019

Channel pools for Bigtable clients are lazy initialized, the first
thread that needs them creates them. To avoid deadlocks and unbound
priority inversions this thread releases the locks while creating the
pools, and relocks before saving the newly created pool.

In some cases two (or more) threads may create the pool, in this case
the pool created by the second thread is discarded. We were discarding
this work with the lock held, which resulted in deadlocks for some
users inside Google (this should not affect external users).


This change is Reviewable

Channel pools for Bigtable clients are lazy initialized, the first
thread that needs them creates them. To avoid deadlocks and unbound
priority inversions this thread releases the locks while creating the
pools, and relocks before saving the newly created pool.

In some cases two (or more) threads may create the pool, in this case
the pool created by the second thread is discarded. We were discarding
this work with the lock held, which resulted in deadlocks for some
users inside Google (this should not affect external users).
@coryan coryan added api: bigtable Issues related to the Bigtable API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Jul 30, 2019
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jul 30, 2019
@codecov
Copy link

codecov bot commented Jul 30, 2019

Codecov Report

Merging #2923 into master will decrease coverage by 0.07%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2923      +/-   ##
==========================================
- Coverage   90.75%   90.68%   -0.08%     
==========================================
  Files         297      297              
  Lines       19943    20007      +64     
==========================================
+ Hits        18100    18144      +44     
- Misses       1843     1863      +20
Impacted Files Coverage Δ
google/cloud/bigtable/internal/common_client.h 89.47% <0%> (-10.53%) ⬇️
google/cloud/storage/well_known_headers.h 74.07% <0%> (-3.71%) ⬇️
...le/cloud/bigtable/internal/async_retry_unary_rpc.h 64.15% <0%> (-1.24%) ⬇️
google/cloud/storage/internal/curl_client.cc 94.7% <0%> (-0.34%) ⬇️
google/cloud/bigtable/mutations.h 100% <0%> (ø) ⬆️
...gle/cloud/storage/internal/access_control_common.h 100% <0%> (ø) ⬆️
google/cloud/bigtable/app_profile_config.h 100% <0%> (ø) ⬆️
google/cloud/internal/retry_policy.h 100% <0%> (ø) ⬆️
google/cloud/bigtable/examples/data_snippets.cc 85.16% <0%> (ø) ⬆️
google/cloud/storage/internal/generic_request.h 83.78% <0%> (+2.7%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1b13d0a...d4386f3. Read the comment docs.

} else {
// Some other thread created the pool and saved it in `stubs_`. The work
// in this thread was superfluous. We release the lock while clearing the
// channels to minimize contention, this seems to workaround other bugs
Copy link
Contributor

Choose a reason for hiding this comment

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

s/contention, this/contention. This/

Although, I'm not sure the "seems to workaround" part is useful. I'm not even sure what "the Google implementation of std::mutex" is referring to.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still not sure what "bugs inside Google" means, but you can fill me in later.

@coryan coryan merged commit c1448e4 into googleapis:master Jul 31, 2019
@coryan coryan deleted the fix-cloud-bigtable-deadlock branch July 31, 2019 14:02
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 Bigtable API. cla: yes This human has signed the Contributor License Agreement. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants