Skip to content

Commit 2b9130f

Browse files
authored
impl(v3): add generator support for connection cq access (#15912)
1 parent f944a14 commit 2b9130f

11 files changed

Lines changed: 119 additions & 1 deletion

generator/generator_config.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ message ServiceConfiguration {
167167
// RPCs. If set to false (the default), a no-op resumption function will be
168168
// generated.
169169
bool omit_streaming_updater = 29;
170+
171+
// In rare cases, specifically bigtable::WaitForConsistency, the
172+
// CompletionQueue from the BackgroundThreads owned by the Connection is
173+
// needed elsewhere. This emits a protected accessor and friend function for
174+
// that purpose.
175+
bool emit_completion_queue_accessor = 30;
170176
}
171177

172178
message DiscoveryDocumentDefinedProduct {

generator/generator_config.textproto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ service {
588588
{rpc_name: "BigtableTableAdmin.CheckConsistency", idempotency: IDEMPOTENT}
589589
]
590590
omit_repo_metadata: true
591+
emit_completion_queue_accessor: true
591592
}
592593
593594
# Billing

generator/internal/connection_generator.cc

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ Status ConnectionGenerator::GenerateHeader() {
5757
{vars("idempotency_policy_header_path"), vars("retry_traits_header_path"),
5858
HasLongrunningMethod() ? "google/cloud/no_await_tag.h" : "",
5959
IsExperimental() ? "google/cloud/experimental_tag.h" : "",
60+
HasEmitCompletionQueueAccessor() ? "google/cloud/completion_queue.h"
61+
: "",
6062
"google/cloud/backoff_policy.h",
6163
HasLongrunningMethod() || HasAsyncMethod() ? "google/cloud/future.h"
6264
: "",
@@ -91,7 +93,21 @@ Status ConnectionGenerator::GenerateHeader() {
9193
}
9294
}
9395

94-
auto result = HeaderOpenNamespaces();
96+
Status result;
97+
if (HasEmitCompletionQueueAccessor()) {
98+
result = HeaderOpenNamespaces();
99+
if (!result.ok()) return result;
100+
HeaderPrint(R"""(class $connection_class_name$;)""");
101+
HeaderCloseNamespaces();
102+
103+
result = HeaderOpenNamespaces(NamespaceType::kInternal);
104+
if (!result.ok()) return result;
105+
HeaderPrint(
106+
R"""(StatusOr<CompletionQueue> completion_queue($product_namespace$::$connection_class_name$ const& conn);)""");
107+
HeaderCloseNamespaces();
108+
}
109+
110+
result = HeaderOpenNamespaces();
95111
if (!result.ok()) return result;
96112

97113
HeaderPrint(R"""(
@@ -315,6 +331,13 @@ class $connection_class_name$ {
315331
__FILE__, __LINE__);
316332
}
317333

334+
if (HasEmitCompletionQueueAccessor()) {
335+
HeaderPrint(R"""( protected:
336+
friend StatusOr<CompletionQueue> $product_internal_namespace$::completion_queue(
337+
$connection_class_name$ const& conn);
338+
virtual StatusOr<CompletionQueue> completion_queue() const;
339+
)""");
340+
}
318341
// close abstract interface Connection base class
319342
HeaderPrint("};\n");
320343

@@ -490,6 +513,15 @@ future<StatusOr<$response_type$>>
490513
__FILE__, __LINE__);
491514
}
492515

516+
if (HasEmitCompletionQueueAccessor()) {
517+
CcPrint(
518+
R"""(
519+
StatusOr<CompletionQueue> $connection_class_name$::completion_queue() const {
520+
return Status(StatusCode::kUnimplemented, "not implemented");
521+
}
522+
)""");
523+
}
524+
493525
if (HasGenerateGrpcTransport()) {
494526
EmitFactoryFunctionDefinition(EndpointLocationStyle());
495527
}

generator/internal/connection_impl_generator.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ class $connection_class_name$Impl
133133
std::make_shared<google::cloud::internal::InvocationIdGenerator>();)""");
134134
}
135135

136+
if (HasEmitCompletionQueueAccessor()) {
137+
HeaderPrint(
138+
R"""(
139+
StatusOr<CompletionQueue> completion_queue() const override;
140+
)""");
141+
}
142+
136143
// This closes the *ConnectionImpl class definition.
137144
HeaderPrint("\n};\n");
138145

@@ -208,6 +215,15 @@ std::unique_ptr<PollingPolicy> polling_policy(Options const& options) {
208215
} // namespace
209216
)""");
210217

218+
if (HasEmitCompletionQueueAccessor()) {
219+
CcPrint(R"""(
220+
StatusOr<CompletionQueue> completion_queue(
221+
$product_namespace$::$connection_class_name$ const& conn) {
222+
return conn.completion_queue();
223+
}
224+
)""");
225+
}
226+
211227
// streaming updater functions
212228
if (!OmitStreamingUpdater(vars())) {
213229
for (auto const& method : methods()) {
@@ -242,6 +258,14 @@ void $service_name$$method_name$StreamingUpdater(
242258
CcPrintMethod(method, __FILE__, __LINE__, AsyncMethodDefinition(method));
243259
}
244260

261+
if (HasEmitCompletionQueueAccessor()) {
262+
CcPrint(R"""(
263+
StatusOr<CompletionQueue> $connection_class_name$Impl::completion_queue() const {
264+
return background_->cq();
265+
}
266+
)""");
267+
}
268+
245269
CcCloseNamespaces();
246270
return {};
247271
}

generator/internal/service_code_generator.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,11 @@ bool ServiceCodeGenerator::IsDeprecated() const {
511511
return service_descriptor_->options().deprecated();
512512
}
513513

514+
bool ServiceCodeGenerator::HasEmitCompletionQueueAccessor() const {
515+
return vars().find("emit_completion_queue_accessor") != vars().end() &&
516+
vars().at("emit_completion_queue_accessor") == "true";
517+
}
518+
514519
} // namespace generator_internal
515520
} // namespace cloud
516521
} // namespace google

generator/internal/service_code_generator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ class ServiceCodeGenerator : public GeneratorInterface {
246246
*/
247247
bool IsDeprecated() const;
248248

249+
bool HasEmitCompletionQueueAccessor() const;
250+
249251
private:
250252
void SetMethods();
251253

generator/standalone_main.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,11 @@ std::vector<std::future<google::cloud::Status>> GenerateCodeFromProtos(
296296
if (service.omit_streaming_updater()) {
297297
args.emplace_back("--cpp_codegen_opt=omit_streaming_updater=true");
298298
}
299+
if (service.emit_completion_queue_accessor()) {
300+
args.emplace_back(
301+
"--cpp_codegen_opt=emit_completion_queue_accessor=true");
302+
}
303+
299304
if (service.generate_round_robin_decorator()) {
300305
args.emplace_back(
301306
"--cpp_codegen_opt=generate_round_robin_decorator=true");

google/cloud/bigtable/admin/bigtable_table_admin_connection.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ BigtableTableAdminConnection::AsyncCheckConsistency(
382382
Status(StatusCode::kUnimplemented, "not implemented"));
383383
}
384384

385+
StatusOr<CompletionQueue> BigtableTableAdminConnection::completion_queue()
386+
const {
387+
return Status(StatusCode::kUnimplemented, "not implemented");
388+
}
389+
385390
std::shared_ptr<BigtableTableAdminConnection> MakeBigtableTableAdminConnection(
386391
Options options) {
387392
internal::CheckExpectedOptions<CommonOptionList, GrpcOptionList,

google/cloud/bigtable/admin/bigtable_table_admin_connection.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "google/cloud/bigtable/admin/bigtable_table_admin_connection_idempotency_policy.h"
2323
#include "google/cloud/bigtable/admin/internal/bigtable_table_admin_retry_traits.h"
2424
#include "google/cloud/backoff_policy.h"
25+
#include "google/cloud/completion_queue.h"
2526
#include "google/cloud/future.h"
2627
#include "google/cloud/internal/retry_policy_impl.h"
2728
#include "google/cloud/no_await_tag.h"
@@ -34,6 +35,27 @@
3435
#include "google/longrunning/operations.grpc.pb.h"
3536
#include <memory>
3637

38+
namespace google {
39+
namespace cloud {
40+
namespace bigtable_admin {
41+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
42+
class BigtableTableAdminConnection;
43+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
44+
} // namespace bigtable_admin
45+
} // namespace cloud
46+
} // namespace google
47+
48+
namespace google {
49+
namespace cloud {
50+
namespace bigtable_admin_internal {
51+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
52+
StatusOr<CompletionQueue> completion_queue(
53+
bigtable_admin::BigtableTableAdminConnection const& conn);
54+
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
55+
} // namespace bigtable_admin_internal
56+
} // namespace cloud
57+
} // namespace google
58+
3759
namespace google {
3860
namespace cloud {
3961
namespace bigtable_admin {
@@ -359,6 +381,11 @@ class BigtableTableAdminConnection {
359381
StatusOr<google::bigtable::admin::v2::CheckConsistencyResponse>>
360382
AsyncCheckConsistency(
361383
google::bigtable::admin::v2::CheckConsistencyRequest const& request);
384+
385+
protected:
386+
friend StatusOr<CompletionQueue> bigtable_admin_internal::completion_queue(
387+
BigtableTableAdminConnection const& conn);
388+
virtual StatusOr<CompletionQueue> completion_queue() const;
362389
};
363390

364391
/**

google/cloud/bigtable/admin/internal/bigtable_table_admin_connection_impl.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ std::unique_ptr<PollingPolicy> polling_policy(Options const& options) {
6060

6161
} // namespace
6262

63+
StatusOr<CompletionQueue> completion_queue(
64+
bigtable_admin::BigtableTableAdminConnection const& conn) {
65+
return conn.completion_queue();
66+
}
67+
6368
BigtableTableAdminConnectionImpl::BigtableTableAdminConnectionImpl(
6469
std::unique_ptr<google::cloud::BackgroundThreads> background,
6570
std::shared_ptr<bigtable_admin_internal::BigtableTableAdminStub> stub,
@@ -1293,6 +1298,11 @@ BigtableTableAdminConnectionImpl::AsyncCheckConsistency(
12931298
std::move(current), std::move(request_copy), __func__);
12941299
}
12951300

1301+
StatusOr<CompletionQueue> BigtableTableAdminConnectionImpl::completion_queue()
1302+
const {
1303+
return background_->cq();
1304+
}
1305+
12961306
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
12971307
} // namespace bigtable_admin_internal
12981308
} // namespace cloud

0 commit comments

Comments
 (0)