Skip to content

Commit a4d34f3

Browse files
feat(bigtable): add support for AsyncPrepareQuery (#15457)
* feat(bigtable): add support for AsyncPrepareQuery * chore: generate bigtable with new config * chore: manually introduce async prepare query where expected
1 parent 7362dd8 commit a4d34f3

16 files changed

+192
-1
lines changed

generator/generator_config.textproto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,8 @@ service {
579579
"MutateRows",
580580
"ReadModifyWriteRow",
581581
"ReadRows",
582-
"SampleRowKeys"
582+
"SampleRowKeys",
583+
"PrepareQuery"
583584
]
584585
omit_repo_metadata: true
585586
}

google/cloud/bigtable/internal/bigtable_auth_decorator.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,27 @@ BigtableAuth::AsyncReadModifyWriteRow(
242242
});
243243
}
244244

245+
future<StatusOr<google::bigtable::v2::PrepareQueryResponse>>
246+
BigtableAuth::AsyncPrepareQuery(
247+
google::cloud::CompletionQueue& cq,
248+
std::shared_ptr<grpc::ClientContext> context,
249+
google::cloud::internal::ImmutableOptions options,
250+
google::bigtable::v2::PrepareQueryRequest const& request) {
251+
return auth_->AsyncConfigureContext(std::move(context))
252+
.then([cq, child = child_, options = std::move(options),
253+
request](future<StatusOr<std::shared_ptr<grpc::ClientContext>>>
254+
f) mutable {
255+
auto context = f.get();
256+
if (!context) {
257+
return make_ready_future(
258+
StatusOr<google::bigtable::v2::PrepareQueryResponse>(
259+
std::move(context).status()));
260+
}
261+
return child->AsyncPrepareQuery(cq, *std::move(context),
262+
std::move(options), request);
263+
});
264+
}
265+
245266
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
246267
} // namespace bigtable_internal
247268
} // namespace cloud

google/cloud/bigtable/internal/bigtable_auth_decorator.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ class BigtableAuth : public BigtableStub {
124124
google::cloud::internal::ImmutableOptions options,
125125
google::bigtable::v2::ReadModifyWriteRowRequest const& request) override;
126126

127+
future<StatusOr<google::bigtable::v2::PrepareQueryResponse>>
128+
AsyncPrepareQuery(
129+
google::cloud::CompletionQueue& cq,
130+
std::shared_ptr<grpc::ClientContext> context,
131+
google::cloud::internal::ImmutableOptions options,
132+
google::bigtable::v2::PrepareQueryRequest const& request) override;
133+
127134
private:
128135
std::shared_ptr<google::cloud::internal::GrpcAuthenticationStrategy> auth_;
129136
std::shared_ptr<BigtableStub> child_;

google/cloud/bigtable/internal/bigtable_channel_refresh.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ BigtableChannelRefresh::AsyncReadModifyWriteRow(
149149
std::move(options), request);
150150
}
151151

152+
future<StatusOr<google::bigtable::v2::PrepareQueryResponse>>
153+
BigtableChannelRefresh::AsyncPrepareQuery(
154+
google::cloud::CompletionQueue& cq,
155+
std::shared_ptr<grpc::ClientContext> context,
156+
google::cloud::internal::ImmutableOptions options,
157+
google::bigtable::v2::PrepareQueryRequest const& request) {
158+
return child_->AsyncPrepareQuery(cq, std::move(context), std::move(options),
159+
request);
160+
}
161+
152162
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
153163
} // namespace bigtable_internal
154164
} // namespace cloud

google/cloud/bigtable/internal/bigtable_channel_refresh.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ class BigtableChannelRefresh : public BigtableStub {
131131
google::cloud::internal::ImmutableOptions,
132132
google::bigtable::v2::ReadModifyWriteRowRequest const& request) override;
133133

134+
future<StatusOr<google::bigtable::v2::PrepareQueryResponse>>
135+
AsyncPrepareQuery(
136+
google::cloud::CompletionQueue& cq,
137+
std::shared_ptr<grpc::ClientContext> context,
138+
google::cloud::internal::ImmutableOptions options,
139+
google::bigtable::v2::PrepareQueryRequest const& request) override;
140+
134141
private:
135142
std::shared_ptr<BigtableStub> child_;
136143
std::shared_ptr<ConnectionRefreshState> refresh_state_;

google/cloud/bigtable/internal/bigtable_logging_decorator.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,24 @@ BigtableLogging::AsyncReadModifyWriteRow(
319319
tracing_options_);
320320
}
321321

322+
future<StatusOr<google::bigtable::v2::PrepareQueryResponse>>
323+
BigtableLogging::AsyncPrepareQuery(
324+
google::cloud::CompletionQueue& cq,
325+
std::shared_ptr<grpc::ClientContext> context,
326+
google::cloud::internal::ImmutableOptions options,
327+
google::bigtable::v2::PrepareQueryRequest const& request) {
328+
return google::cloud::internal::LogWrapper(
329+
[this](google::cloud::CompletionQueue& cq,
330+
std::shared_ptr<grpc::ClientContext> context,
331+
google::cloud::internal::ImmutableOptions options,
332+
google::bigtable::v2::PrepareQueryRequest const& request) {
333+
return child_->AsyncPrepareQuery(cq, std::move(context),
334+
std::move(options), request);
335+
},
336+
cq, std::move(context), std::move(options), request, __func__,
337+
tracing_options_);
338+
}
339+
322340
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
323341
} // namespace bigtable_internal
324342
} // namespace cloud

google/cloud/bigtable/internal/bigtable_logging_decorator.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ class BigtableLogging : public BigtableStub {
124124
google::cloud::internal::ImmutableOptions options,
125125
google::bigtable::v2::ReadModifyWriteRowRequest const& request) override;
126126

127+
future<StatusOr<google::bigtable::v2::PrepareQueryResponse>>
128+
AsyncPrepareQuery(
129+
google::cloud::CompletionQueue& cq,
130+
std::shared_ptr<grpc::ClientContext> context,
131+
google::cloud::internal::ImmutableOptions options,
132+
google::bigtable::v2::PrepareQueryRequest const& request) override;
133+
127134
private:
128135
std::shared_ptr<BigtableStub> child_;
129136
TracingOptions tracing_options_;

google/cloud/bigtable/internal/bigtable_metadata_decorator.cc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,42 @@ BigtableMetadata::AsyncReadModifyWriteRow(
697697
std::move(options), request);
698698
}
699699

700+
future<StatusOr<google::bigtable::v2::PrepareQueryResponse>>
701+
BigtableMetadata::AsyncPrepareQuery(
702+
google::cloud::CompletionQueue& cq,
703+
std::shared_ptr<grpc::ClientContext> context,
704+
google::cloud::internal::ImmutableOptions options,
705+
google::bigtable::v2::PrepareQueryRequest const& request) {
706+
std::vector<std::string> params;
707+
params.reserve(2);
708+
709+
static auto* name_matcher = [] {
710+
return new google::cloud::internal::RoutingMatcher<
711+
google::bigtable::v2::PrepareQueryRequest>{
712+
"name=",
713+
{
714+
{[](google::bigtable::v2::PrepareQueryRequest const& request)
715+
-> std::string const& { return request.instance_name(); },
716+
std::regex{"(projects/[^/]+/instances/[^/]+)",
717+
std::regex::optimize}},
718+
}};
719+
}();
720+
name_matcher->AppendParam(request, params);
721+
722+
if (!request.app_profile_id().empty()) {
723+
params.push_back(absl::StrCat(
724+
"app_profile_id=", internal::UrlEncode(request.app_profile_id())));
725+
}
726+
727+
if (params.empty()) {
728+
SetMetadata(*context, *options);
729+
} else {
730+
SetMetadata(*context, *options, absl::StrJoin(params, "&"));
731+
}
732+
return child_->AsyncPrepareQuery(cq, std::move(context), std::move(options),
733+
request);
734+
}
735+
700736
void BigtableMetadata::SetMetadata(grpc::ClientContext& context,
701737
Options const& options,
702738
std::string const& request_params) {

google/cloud/bigtable/internal/bigtable_metadata_decorator.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ class BigtableMetadata : public BigtableStub {
124124
google::cloud::internal::ImmutableOptions options,
125125
google::bigtable::v2::ReadModifyWriteRowRequest const& request) override;
126126

127+
future<StatusOr<google::bigtable::v2::PrepareQueryResponse>>
128+
AsyncPrepareQuery(
129+
google::cloud::CompletionQueue& cq,
130+
std::shared_ptr<grpc::ClientContext> context,
131+
google::cloud::internal::ImmutableOptions options,
132+
google::bigtable::v2::PrepareQueryRequest const& request) override;
133+
127134
private:
128135
void SetMetadata(grpc::ClientContext& context, Options const& options,
129136
std::string const& request_params);

google/cloud/bigtable/internal/bigtable_round_robin_decorator.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,16 @@ BigtableRoundRobin::AsyncReadModifyWriteRow(
159159
std::move(options), request);
160160
}
161161

162+
future<StatusOr<google::bigtable::v2::PrepareQueryResponse>>
163+
BigtableRoundRobin::AsyncPrepareQuery(
164+
google::cloud::CompletionQueue& cq,
165+
std::shared_ptr<grpc::ClientContext> context,
166+
google::cloud::internal::ImmutableOptions options,
167+
google::bigtable::v2::PrepareQueryRequest const& request) {
168+
return Child()->AsyncPrepareQuery(cq, std::move(context), std::move(options),
169+
request);
170+
}
171+
162172
std::shared_ptr<BigtableStub> BigtableRoundRobin::Child() {
163173
std::unique_lock<std::mutex> lk(mu_);
164174
auto const current = current_;

0 commit comments

Comments
 (0)