-
Notifications
You must be signed in to change notification settings - Fork 385
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): control replicas/regions used in non-transactional reads #13031
Conversation
Add the `DirectedReadOption` to indicate which replicas or regions should be used for `Client::Read()`, `Client::ExecuteQuery()`, and `Client::ProfileQuery()` calls in read-only or single-use transactions. - The `IncludeReplicas` variant lists the replicas to try (in order) to process the request, and what to do if the list is exhausted without finding a healthy replica. - The `ExcludeReplicas` variant lists replicas that should be excluded from serving the request.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #13031 +/- ##
========================================
Coverage 93.61% 93.62%
========================================
Files 2078 2079 +1
Lines 181842 182034 +192
========================================
+ Hits 170235 170427 +192
Misses 11607 11607
☔ View full report in Codecov by Sentry. |
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
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.
The use of output arguments is not very consistent with the rest of the code in google-cloud-cpp
.
static void ToProto( | ||
spanner::ReplicaSelection const& from, | ||
google::spanner::v1::DirectedReadOptions::ReplicaSelection* to) { |
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.
Generally we prefer return types over "output arguments as pointers". Any reason to do differently here?
static void ToProto( | |
spanner::ReplicaSelection const& from, | |
google::spanner::v1::DirectedReadOptions::ReplicaSelection* to) { | |
static google::spanner::v1::DirectedReadOptions::ReplicaSelection ToProto( | |
spanner::ReplicaSelection const& from) { |
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.
Changed as you suggested.
@@ -494,6 +546,10 @@ spanner::RowStream ConnectionImpl::ReadImpl( | |||
*std::move(params.read_options.request_tag)); | |||
} | |||
request->mutable_request_options()->set_transaction_tag(ctx.tag); | |||
absl::visit(DirectedReadVisitor([&request] { | |||
return request->mutable_directed_read_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 looks less like a factory and more like just passing a pointer or reference? Ah, I see, it leaves request
unmodified if the visitor does no affect request.directed_read_options()
.
Please consider a comment, our future selves may be as confused as I was.
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.
@@ -4887,6 +4930,9 @@ void RunAll(bool emulator) { | |||
SampleBanner("spanner_set_request_tag"); | |||
SetRequestTag(client); | |||
|
|||
SampleBanner("spanner_directed_read"); |
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.
nit: at 5000+ lines, maybe it is time to split this file? It requires some planning because one cannot just remove region tags from a file...
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.
Yeah. I'm in two minds. This really is a tangle, with each sample largely dependent on the state left by those before it. So, any splitting doesn't really make it easier to understand. But I'll give some more thought to a better state, and how we might get there.
Add the
DirectedReadOption
to indicate which replicas or regions should be used forClient::Read()
,Client::ExecuteQuery()
, andClient::ProfileQuery()
calls in read-only or single-use transactions.The
IncludeReplicas
variant lists the replicas to try (in order) to process the request, and what to do if the list is exhausted without finding a healthy replica.The
ExcludeReplicas
variant lists replicas that should be excluded from serving the request.This change is