-
Notifications
You must be signed in to change notification settings - Fork 373
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
Conversation
`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.
Codecov ReportPatch coverage:
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
... 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. |
google/cloud/spanner/options.h
Outdated
/** | ||
* 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 | ||
*/ |
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.
This assumes the reader understands leader regions already, and it is not a good "brief" comment.
/** | |
* 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 | |
*/ |
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.
Excellent. Done. Thanks.
BatchCreateSessions()
calls made during theSessionPool
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 instantiatingOptionsSpan
objects when appropriate.Add similar
OptionsSpan
objects tosession_pool_integration_test.cc
, which uses "FriendForTest" access to reach intoSessionPool
, 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 theSessionPoolOptionList
, marking it as a valid option to pass tospanner::MakeConnection()
.Also add a slight optimization to
SessionPool::Grow()
, which skips even trying to create sessions whenComputeCreateCounts()
returns an empty vector.This change is