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): enable leader aware routing by default #12319

Merged
merged 2 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it me, or we have used this sequence of values elsewhere? Should we have a function? And why not OFF, since we have N and n?
Neither of those questions is blockin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we have ParseBoolean() in google/cloud/tracing_options.cc, which we could probably try to common-ize now.

As for the values, I just stuck with the ParseBoolean() choices, so that refactoring was a possibility.

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