-
Notifications
You must be signed in to change notification settings - Fork 378
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): spanner::Client construction from Options #7706
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,13 +36,15 @@ | |
#include "google/cloud/spanner/transaction.h" | ||
#include "google/cloud/spanner/version.h" | ||
#include "google/cloud/backoff_policy.h" | ||
#include "google/cloud/internal/non_constructible.h" | ||
#include "google/cloud/optional.h" | ||
#include "google/cloud/options.h" | ||
#include "google/cloud/status.h" | ||
#include "google/cloud/status_or.h" | ||
#include <google/spanner/v1/spanner.pb.h> | ||
#include <grpcpp/grpcpp.h> | ||
#include <functional> | ||
#include <initializer_list> | ||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
@@ -128,10 +130,31 @@ class Client { | |
* with unit testing, callers may create fake/mock `Connection` objects that | ||
* are injected into the `Client`. | ||
*/ | ||
explicit Client(std::shared_ptr<Connection> conn, ClientOptions opts = {}) | ||
explicit Client(std::shared_ptr<Connection> conn, Options opts = {}) | ||
: conn_(std::move(conn)), opts_(std::move(opts)) {} | ||
|
||
/// No default construction. Use `Client(std::shared_ptr<Connection>)` | ||
/** | ||
* Constructs a `Client` object using the specified @p conn and @p opts. | ||
* | ||
* Note that the previous constructor, which uses the new way to represent | ||
* options of all varieties (`google::cloud::Options`), is now preferred. | ||
*/ | ||
explicit Client(std::shared_ptr<Connection> conn, ClientOptions const& opts) | ||
: conn_(std::move(conn)), opts_(opts) {} | ||
|
||
/** | ||
* Constructs a `Client` object using the specified @p conn and an empty | ||
* initializer list. | ||
* | ||
* @note This constructor exists solely for backwards compatibility. It | ||
* prevents existing code that uses `Client(conn, {})` from breaking | ||
* due to ambiguity introduced by the `Options` overload. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In pubsub, I introduced this constructor as Changing from a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I don't think |
||
explicit Client(std::shared_ptr<Connection> conn, | ||
std::initializer_list<internal::NonConstructible>) | ||
: Client(std::move(conn)) {} | ||
|
||
/// No default construction. | ||
Client() = delete; | ||
|
||
//@{ | ||
|
@@ -648,7 +671,8 @@ class Client { | |
QueryOptions OverlayQueryOptions(QueryOptions const&); | ||
|
||
std::shared_ptr<Connection> conn_; | ||
ClientOptions opts_; | ||
Options opts_; | ||
QueryOptions query_opts_{opts_}; | ||
}; | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "google/cloud/spanner/client_options.h" | ||
#include "google/cloud/spanner/options.h" | ||
|
||
namespace google { | ||
namespace cloud { | ||
namespace spanner { | ||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
||
ClientOptions::operator Options() const { | ||
Options opts; | ||
auto optimizer_version = query_options_.optimizer_version(); | ||
if (optimizer_version) { | ||
opts.set<RequestOptimizerVersionOption>(*optimizer_version); | ||
} | ||
auto optimizer_statistics_package = | ||
query_options_.optimizer_statistics_package(); | ||
if (optimizer_statistics_package) { | ||
opts.set<RequestOptimizerStatisticsPackageOption>( | ||
*optimizer_statistics_package); | ||
} | ||
auto request_priority = query_options_.request_priority(); | ||
if (request_priority) { | ||
opts.set<RequestPriorityOption>(*request_priority); | ||
} | ||
auto request_tag = query_options_.request_tag(); | ||
if (request_tag) { | ||
opts.set<RequestTagOption>(*request_tag); | ||
} | ||
return opts; | ||
} | ||
|
||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
} // namespace spanner | ||
} // namespace cloud | ||
} // namespace google |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
#include "google/cloud/spanner/query_options.h" | ||
#include "google/cloud/spanner/version.h" | ||
#include "google/cloud/options.h" | ||
|
||
namespace google { | ||
namespace cloud { | ||
|
@@ -35,6 +36,12 @@ class ClientOptions { | |
ClientOptions(ClientOptions&&) = default; | ||
ClientOptions& operator=(ClientOptions&&) = default; | ||
|
||
/** | ||
* Convert the `ClientOptions` to the new, recommended way to represent | ||
* options of all varieties, `google::cloud::Options`. | ||
*/ | ||
explicit operator Options() const; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in pubsub a conversion method like this was hidden away in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking that a customer might want to call this as part of their own migration, but I'm just guessing. In any case, with |
||
|
||
/// Returns the `QueryOptions` | ||
QueryOptions const& query_options() const { return query_options_; } | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "google/cloud/spanner/query_options.h" | ||
#include "google/cloud/spanner/options.h" | ||
|
||
namespace google { | ||
namespace cloud { | ||
namespace spanner { | ||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN | ||
|
||
QueryOptions::QueryOptions(Options const& opts) { | ||
if (opts.has<RequestOptimizerVersionOption>()) { | ||
optimizer_version_ = opts.get<RequestOptimizerVersionOption>(); | ||
} | ||
if (opts.has<RequestOptimizerStatisticsPackageOption>()) { | ||
optimizer_statistics_package_ = | ||
opts.get<RequestOptimizerStatisticsPackageOption>(); | ||
} | ||
if (opts.has<RequestPriorityOption>()) { | ||
request_priority_ = opts.get<RequestPriorityOption>(); | ||
} | ||
if (opts.has<RequestTagOption>()) { | ||
request_tag_ = opts.get<RequestTagOption>(); | ||
} | ||
} | ||
|
||
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END | ||
} // namespace spanner | ||
} // namespace cloud | ||
} // namespace google |
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.
mark as
@deprecated
?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.
I planned to leave deprecating
ClientOptions
to a later stage.