Skip to content

Commit 697cc0a

Browse files
authored
feat(spanner): use prevailing Options in ConnectionImpl (#8466)
Allow the prevailing `Options` to override the connection options for the retry/backoff policies and RPC tracing parameters, so that any per-operation options are heeded. This is the final step in fixing #7690, so announce that users should now prefer to use `Options` on all Spanner client calls.
1 parent d4f3ebf commit 697cc0a

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
generated automatically from the service definitions. The new APIs can be
2727
found in the [`google/cloud/spanner/admin`](https://github.com/googleapis/google-cloud-cpp/tree/main/google/cloud/spanner/admin)
2828
tree and within the `google::cloud::spanner_admin` namespace. Starting with
29-
the v1.32.0 release, and depending on your compiler settings, using these
29+
the v1.32.0 release, and depending on your compiler settings, using the old
3030
classes/functions may elicit a deprecation warning. See
3131
[#7356](https://github.com/googleapis/google-cloud-cpp/issues/7356) for more
3232
details.
@@ -144,6 +144,15 @@ best long-term interest of our customers.
144144
as `final`. After the changes in [v1.36.0](#v1360---2022-02), there is no need
145145
or reason to be extending this class.
146146

147+
### [Spanner](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/spanner/README.md)
148+
149+
All the `spanner::Client` operations now take optional `google::cloud::Options`
150+
arguments, replacing the existing `ClientOptions`, `CommitOptions`,
151+
`PartitionOptions`, `QueryOptions`, and `ReadOptions` arguments, or adding
152+
options to operations that previously had none. Users should migrate to these
153+
new overloads. (Note that the old `spanner::*Options` types have not been
154+
deprecated as they are still used in the `spanner::Connection` interface.)
155+
147156
### New Libraries
148157

149158
<!-- TODO: update library count with next release -->

google/cloud/spanner/internal/connection_impl.cc

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,26 +325,40 @@ class StreamingPartitionedDmlResult {
325325

326326
std::shared_ptr<spanner::RetryPolicy> const&
327327
ConnectionImpl::RetryPolicyPrototype() const {
328-
// TODO(#4528) TODO(#7690): Base this on internal::CurrentOptions().
328+
// TODO(#4528): Support per-operation defaults for retry policies.
329+
auto const& options = internal::CurrentOptions();
330+
if (options.has<spanner::SpannerRetryPolicyOption>()) {
331+
return options.get<spanner::SpannerRetryPolicyOption>();
332+
}
329333
return opts_.get<spanner::SpannerRetryPolicyOption>();
330334
}
331335

332336
std::shared_ptr<spanner::BackoffPolicy> const&
333337
ConnectionImpl::BackoffPolicyPrototype() const {
334-
// TODO(#4528) TODO(#7690): Base this on internal::CurrentOptions().
338+
// TODO(#4528): Support per-operation defaults for backoff policies.
339+
auto const& options = internal::CurrentOptions();
340+
if (options.has<spanner::SpannerBackoffPolicyOption>()) {
341+
return options.get<spanner::SpannerBackoffPolicyOption>();
342+
}
335343
return opts_.get<spanner::SpannerBackoffPolicyOption>();
336344
}
337345

338346
bool ConnectionImpl::RpcStreamTracingEnabled() const {
339-
// TODO(#7690): Base this on internal::CurrentOptions() if we want to
340-
// allow per-operation options to influence "rpc-streams" tracing.
341-
return internal::Contains(opts_.get<TracingComponentsOption>(),
342-
"rpc-streams");
347+
std::string const rpc_streams = "rpc-streams";
348+
auto const& options = internal::CurrentOptions();
349+
auto const& tracing_components = options.get<TracingComponentsOption>();
350+
if (!internal::Contains(tracing_components, rpc_streams)) {
351+
auto const& tracing_components = opts_.get<TracingComponentsOption>();
352+
if (!internal::Contains(tracing_components, rpc_streams)) return false;
353+
}
354+
return true;
343355
}
344356

345357
TracingOptions const& ConnectionImpl::RpcTracingOptions() const {
346-
// TODO(#7690): Base this on internal::CurrentOptions() if we want to
347-
// allow per-operation options to influence "rpc-streams" tracing.
358+
auto const& options = internal::CurrentOptions();
359+
if (options.has<GrpcTracingOptionsOption>()) {
360+
return options.get<GrpcTracingOptionsOption>();
361+
}
348362
return opts_.get<GrpcTracingOptionsOption>();
349363
}
350364

0 commit comments

Comments
 (0)