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(spanner): propagate Options through SessionPool callbacks #11344

Merged
merged 2 commits into from
Apr 21, 2023

Conversation

devbww
Copy link
Contributor

@devbww devbww commented Apr 21, 2023

BatchCreateSessions() calls made during the SessionPool callback chain depend on the prevailing options to determine whether the RPC should be routed to a region leader. So, we need to ensure that the construction-time options are propagated through those callbacks by instantiating OptionsSpan objects when appropriate.

Add similar OptionsSpan objects to session_pool_integration_test.cc, which uses "FriendForTest" access to reach into SessionPool, bypassing the normal span instantiation.

Add unit tests to verify that the "x-goog-spanner-route-to-leader" header is now set appropriately when the RouteToLeaderOption is both enabled and disabled.

Add RouteToLeaderOption to the SessionPoolOptionList, marking it as a valid option to pass to spanner::MakeConnection().

Also add a slight optimization to SessionPool::Grow(), which skips even trying to create sessions when ComputeCreateCounts() returns an empty vector.


This change is Reviewable

`BatchCreateSessions()` calls made during the `SessionPool` callback
chain depend on the prevailing options to determine whether the RPC
should be routed to a region leader.  So, we need to ensure that the
construction-time options are propagated through those callbacks by
instantiating `OptionsSpan` objects when appropriate.

Add similar `OptionsSpan` objects to `session_pool_integration_test.cc`,
which uses "FriendForTest" access to reach into `SessionPool`, bypassing
the normal span instantiation.

Add unit tests to verify that the "x-goog-spanner-route-to-leader"
header is now set appropriately when the `RouteToLeaderOption` is both
enabled and disabled.

Add `RouteToLeaderOption` to the `SessionPoolOptionList`, marking it
as a valid option to pass to `spanner::MakeConnection()`.

Also add a slight optimization to `SessionPool::Grow()`, which skips
even trying to create sessions when `ComputeCreateCounts()` returns an
empty vector.
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Apr 21, 2023
@codecov
Copy link

codecov bot commented Apr 21, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.01 ⚠️

Comparison is base (43ea418) 93.73% compared to head (b53c6e0) 93.73%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11344      +/-   ##
==========================================
- Coverage   93.73%   93.73%   -0.01%     
==========================================
  Files        1792     1792              
  Lines      160022   160058      +36     
==========================================
+ Hits       149998   150030      +32     
- Misses      10024    10028       +4     
Impacted Files Coverage Δ
...integration_tests/session_pool_integration_test.cc 100.00% <100.00%> (ø)
google/cloud/spanner/internal/session_pool.cc 88.62% <100.00%> (+0.42%) ⬆️
google/cloud/spanner/internal/session_pool_test.cc 99.75% <100.00%> (+0.01%) ⬆️

... and 6 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@devbww devbww marked this pull request as ready for review April 21, 2023 07:26
@devbww devbww requested a review from a team as a code owner April 21, 2023 07:26
Comment on lines 93 to 99
/**
* Option for `google::cloud::Options` to, when present and false, suppress
* adding headers to distinguish requests served by the leader v/s non-leader
* region.
*
* @ingroup spanner-options
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

This assumes the reader understands leader regions already, and it is not a good "brief" comment.

Suggested change
/**
* Option for `google::cloud::Options` to, when present and false, suppress
* adding headers to distinguish requests served by the leader v/s non-leader
* region.
*
* @ingroup spanner-options
*/
/**
* Control route-to-leader-region headers.
*
* Unless this option is present and `false` the client library will send
* headers that route the request to the leader region.
*
* @see https://cloud.google.com/spanner/docs/instance-configurations
* for more information on multi-regional spanner instances and the role of
* leader regions.
*
* @ingroup spanner-options
*/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excellent. Done. Thanks.

@devbww devbww merged commit 6352da9 into googleapis:main Apr 21, 2023
@devbww devbww deleted the route-to-leader-span branch April 21, 2023 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants