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(spanner): add the final pieces for the RouteToLeaderOption #11112

Merged
merged 4 commits into from Mar 28, 2023

Conversation

devbww
Copy link
Collaborator

@devbww devbww commented Mar 27, 2023

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 Reviewable

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.
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Mar 27, 2023
@codecov
Copy link

codecov bot commented Mar 27, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (c1c05ac) 93.78% compared to head (c60e3ec) 93.78%.

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           
Impacted Files Coverage Δ
google/cloud/spanner/internal/connection_impl.cc 94.73% <100.00%> (-0.07%) ⬇️
google/cloud/spanner/internal/defaults.cc 97.53% <100.00%> (+0.09%) ⬆️
google/cloud/spanner/internal/defaults_test.cc 100.00% <100.00%> (ø)
google/cloud/spanner/internal/session_pool.cc 88.19% <100.00%> (+0.08%) ⬆️

... 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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@devbww devbww marked this pull request as ready for review March 27, 2023 06:54
@devbww devbww requested a review from a team as a code owner March 27, 2023 06:54
@@ -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
Copy link
Member

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?

Copy link
Collaborator Author

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);
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Member

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.

Copy link
Collaborator Author

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")) {
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

Copy link
Member

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
Copy link
Member

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.

Copy link
Collaborator Author

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);
Copy link
Member

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.

@devbww devbww merged commit bedd265 into googleapis:main Mar 28, 2023
59 checks passed
@devbww devbww deleted the route-to-leader branch March 28, 2023 06:48
devbww added a commit to devbww/google-cloud-cpp that referenced this pull request Aug 4, 2023
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.
devbww added a commit that referenced this pull request Aug 4, 2023
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 #11112.  Fixes #11111.
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.

None yet

2 participants