-
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
feat(spanner): add the final pieces for the RouteToLeaderOption #11112
Conversation
The final glue to add a routing header to Spanner RPCs that should be served in the leader region. For the time being, the boolean option defaults to off (set as false), but that default can be changed with a suitably-positive value for `${GOOGLE_CLOUD_CPP_SPANNER_ROUTE_TO_LEADER}`. The conditional code can be removed to restore the defaults-to-on behavior. See googleapis#11111.
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #11112 +/- ##
=======================================
Coverage 93.78% 93.78%
=======================================
Files 1741 1741
Lines 156970 156992 +22
=======================================
+ Hits 147212 147234 +22
Misses 9758 9758
... and 4 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. |
@@ -105,6 +105,20 @@ Options DefaultOptions(Options opts) { | |||
(std::min)(min_sessions, max_sessions_per_channel * num_channels); | |||
|
|||
if (!opts.has<spanner::RouteToLeaderOption>()) { | |||
#if 1 |
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.
Do we want to leave the '#if
here or just let version control store the original version?
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.
I thought this was a little easier/clearer, but I'm happy to go the other way. Done.
@@ -830,6 +841,7 @@ ConnectionImpl::PartitionQueryImpl( | |||
Idempotency::kIdempotent, | |||
[&stub](grpc::ClientContext& context, | |||
google::spanner::v1::PartitionQueryRequest const& request) { | |||
RouteToLeader(context); |
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.
Why no if (route_to_leader)
here?
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.
Because PartitionQuery()
calls should be unconditionally routed to the leader.
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.
Consider a comment (here and the other places where it is not conditional). You probably won't forget that, I will.
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.
Done.
#if 1 | ||
// TODO(#11111): Enable on-by-default behavior. | ||
opts.set<spanner::RouteToLeaderOption>(false); | ||
if (auto e = internal::GetEnv("GOOGLE_CLOUD_CPP_SPANNER_ROUTE_TO_LEADER")) { |
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.
You have previously argued that environment variables should override the values set in the code. This does not seem to do that, thoughts?
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.
You're correct that this environment variable is different ... it is for overriding the default value rather than a value set in code. Let me think about that and get back to you on whether that difference is a feature or a bug. Thanks.
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.
OK ... on further thought I concur that this environment variable should follow the "env > user > default" model. It is supposed to be a "Big Red Button" for use when things go wrong (after we restore the on-by-default behavior), so the environment should have highest priority. Thanks. PTAL.
That said, there are environment variables that only supply a default value, which should be overridden by a user setting ... "user > env > default/empty/null. This very file has two: SPANNER_OPTIMIZER_VERSION
and SPANNER_OPTIMIZER_STATISTICS_PACKAGE
. So, we should be careful to distinguish how the environment is used in each case.
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.
Ac. SGTM. We may want to consider some updates to our ADR regarding this, but that can happen elsewhere.
@@ -85,7 +85,13 @@ TEST(Options, Defaults) { | |||
EXPECT_TRUE(opts.has<SpannerBackoffPolicyOption>()); | |||
EXPECT_TRUE(opts.has<spanner_internal::SessionPoolClockOption>()); | |||
|
|||
#if 1 |
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.
Ditto regarding #if
vs. version control.
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.
Ditto response. Done.
setting for the `RouteToLeaderOption`, rather than giving the default value when there is no user setting.
@@ -830,6 +841,7 @@ ConnectionImpl::PartitionQueryImpl( | |||
Idempotency::kIdempotent, | |||
[&stub](grpc::ClientContext& context, | |||
google::spanner::v1::PartitionQueryRequest const& request) { | |||
RouteToLeader(context); |
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.
Consider a comment (here and the other places where it is not conditional). You probably won't forget that, I will.
I've been told to include this text in the PR description: "This update contains performance optimisations that will reduce the latency of read/write transactions that originate from a region other than the default leader region." See googleapis#11112. Fixes googleapis#11111.
The final glue to add a routing header to Spanner RPCs that should be served in the leader region.
For the time being, the boolean option defaults to off (set as false), but that default can be changed with a suitably-positive value for
${GOOGLE_CLOUD_CPP_SPANNER_ROUTE_TO_LEADER}
. The conditional code can be removed to restore the defaults-to-on behavior. See #11111.This change is