Skip to content

Commit

Permalink
feat(spanner): enable leader aware routing by default
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
devbww committed Aug 4, 2023
1 parent e814f61 commit 8ebd5d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
25 changes: 10 additions & 15 deletions google/cloud/spanner/internal/defaults.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,17 @@ Options DefaultOptions(Options opts) {
min_sessions =
(std::min)(min_sessions, max_sessions_per_channel * num_channels);

// TODO(#11111): Restore on-by-default behavior.
if (!opts.has<spanner::RouteToLeaderOption>()) {
opts.set<spanner::RouteToLeaderOption>(false); // off by default
}
// ${GOOGLE_CLOUD_CPP_SPANNER_ROUTE_TO_LEADER} overrides option setting.
if (auto e = internal::GetEnv("GOOGLE_CLOUD_CPP_SPANNER_ROUTE_TO_LEADER")) {
for (auto const* disable : {"N", "n", "F", "f", "0", "off"}) {
if (*e == disable) {
// Never route to leader.
opts.set<spanner::RouteToLeaderOption>(false);
}
}
for (auto const* enable : {"Y", "y", "T", "t", "1", "on"}) {
if (*e == enable) {
// Route to leader for RW/PartitionedDml transactions.
opts.unset<spanner::RouteToLeaderOption>();
// The option defaults to on (unset), but the default can be changed with a
// suitably-negative value in `${GOOGLE_CLOUD_CPP_SPANNER_ROUTE_TO_LEADER}`.
if (auto e = internal::GetEnv("GOOGLE_CLOUD_CPP_SPANNER_ROUTE_TO_LEADER")) {
for (auto const* disable : {"N", "n", "F", "f", "0", "off"}) {
if (*e == disable) {
// Change the default from "for RW/PartitionedDml transactions"
// to "never".
opts.set<spanner::RouteToLeaderOption>(false);
break;
}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions google/cloud/spanner/internal/defaults_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ TEST(Options, Defaults) {
EXPECT_TRUE(opts.has<SpannerBackoffPolicyOption>());
EXPECT_TRUE(opts.has<spanner_internal::SessionPoolClockOption>());

// TODO(#11111): Restore on-by-default behavior.
ASSERT_TRUE(opts.has<spanner::RouteToLeaderOption>());
EXPECT_FALSE(opts.get<spanner::RouteToLeaderOption>());
EXPECT_FALSE(opts.has<spanner::RouteToLeaderOption>());
}

TEST(Options, AdminDefaults) {
Expand Down

0 comments on commit 8ebd5d5

Please sign in to comment.