Skip to content

Commit d48786e

Browse files
authored
impl(bigtable): add DeadlineOption (#16085)
1 parent 8a2d6da commit d48786e

17 files changed

Lines changed: 682 additions & 216 deletions

generator/internal/client_generator.cc

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "generator/internal/pagination.h"
2121
#include "generator/internal/predicate_utils.h"
2222
#include "generator/internal/printer.h"
23+
#include "absl/strings/match.h"
2324
#include "absl/strings/str_cat.h"
2425
#include "absl/strings/str_replace.h"
2526
#include "google/api/client.pb.h"
@@ -456,7 +457,10 @@ Status ClientGenerator::GenerateCc() {
456457
if (MethodSignatureUsesDeprecatedField()) {
457458
CcLocalIncludes({"google/cloud/internal/disable_deprecation_warnings.inc"});
458459
}
459-
CcLocalIncludes({vars("client_header_path")});
460+
CcLocalIncludes({vars("client_header_path"),
461+
absl::StartsWithIgnoreCase(vars("service_name"), "Bigtable")
462+
? "google/cloud/bigtable/options.h"
463+
: ""});
460464
CcSystemIncludes({"memory"});
461465
if (get_iam_policy_extension_ && set_iam_policy_extension_) {
462466
CcLocalIncludes({vars("options_header_path")});
@@ -473,7 +477,7 @@ Status ClientGenerator::GenerateCc() {
473477
CcPrint(R"""(
474478
std::shared_ptr<$connection_class_name$> connection, Options opts)
475479
: connection_(std::move(connection)),
476-
options_(internal::MergeOptions(std::move(opts),
480+
options_($merge_options_fn$(std::move(opts),
477481
connection_->options())) {}
478482
$client_class_name$::~$client_class_name$() = default;
479483
)""");
@@ -488,7 +492,7 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
488492
$response_type$>>
489493
$client_class_name$::Async$method_name$(Options opts) {
490494
internal::OptionsSpan span(
491-
internal::MergeOptions(std::move(opts), options_));
495+
$merge_options_fn$(std::move(opts), options_));
492496
return connection_->Async$method_name$();
493497
}
494498
)""");
@@ -513,7 +517,7 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
513517
{"\n$return_type$\n"},
514518
// clang-format off
515519
{method_string},
516-
{" internal::OptionsSpan span(internal::MergeOptions("
520+
{" internal::OptionsSpan span($merge_options_fn$("
517521
"std::move(opts), options_));\n"},
518522
{" $request_type$ request;\n"},
519523
{method_request_string},
@@ -529,7 +533,7 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
529533
"\nfuture<Status>\n",
530534
"\nfuture<StatusOr<$longrunning_deduced_response_type$>>\n"},
531535
{method_string},
532-
{" internal::OptionsSpan span(internal::MergeOptions("
536+
{" internal::OptionsSpan span($merge_options_fn$("
533537
"std::move(opts), options_));\n"},
534538
{" $request_type$ request;\n"},
535539
{method_request_string},
@@ -541,7 +545,7 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
541545
"\nStatus\n",
542546
"\nStatusOr<$longrunning_operation_type$>\n"},
543547
{start_method_string},
544-
{" internal::OptionsSpan span(internal::MergeOptions("
548+
{" internal::OptionsSpan span($merge_options_fn$("
545549
"std::move(opts), options_));\n"},
546550
{" $request_type$ request;\n"},
547551
{method_request_string},
@@ -554,7 +558,7 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
554558
// clang-format off
555559
{"\nStreamRange<$range_output_type$>\n"},
556560
{method_string},
557-
{" internal::OptionsSpan span(internal::MergeOptions("
561+
{" internal::OptionsSpan span($merge_options_fn$("
558562
"std::move(opts), options_));\n"},
559563
{" $request_type$ request;\n"},
560564
{method_request_string},
@@ -567,7 +571,7 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
567571
// clang-format off
568572
{"\nStreamRange<$response_type$>\n"},
569573
{method_string},
570-
{" internal::OptionsSpan span(internal::MergeOptions("
574+
{" internal::OptionsSpan span($merge_options_fn$("
571575
"std::move(opts), options_));\n"},
572576
{" $request_type$ request;\n"},
573577
{method_request_string},
@@ -591,7 +595,7 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
591595
" Options opts) {\n"
592596
" internal::CheckExpectedOptions<$service_name$"
593597
"BackoffPolicyOption>(opts, __func__);\n"
594-
" internal::OptionsSpan span(internal::MergeOptions("
598+
" internal::OptionsSpan span($merge_options_fn$("
595599
"std::move(opts), options_));\n"},
596600
{" "},
597601
{ProtoNameToCppName(
@@ -644,7 +648,7 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
644648
// clang-format off
645649
{"$client_class_name$::$method_name$($request_type$ const& request"
646650
", Options opts) {\n"
647-
" internal::OptionsSpan span(internal::MergeOptions("
651+
" internal::OptionsSpan span($merge_options_fn$("
648652
"std::move(opts), options_));\n"
649653
" return connection_->$method_name$(request);\n"
650654
"}\n"} // clang-format on
@@ -659,7 +663,7 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
659663
"\nfuture<StatusOr<$longrunning_deduced_response_type$>>\n"},
660664
{"$client_class_name$::$method_name$($request_type$ const& request"
661665
", Options opts) {\n"
662-
" internal::OptionsSpan span(internal::MergeOptions("
666+
" internal::OptionsSpan span($merge_options_fn$("
663667
"std::move(opts), options_));\n"
664668
" return connection_->$method_name$(request);\n"
665669
"}\n"},
@@ -671,7 +675,7 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
671675
{"$client_class_name$::$method_name$(NoAwaitTag"
672676
", $request_type$ const& request"
673677
", Options opts) {\n"
674-
" internal::OptionsSpan span(internal::MergeOptions("
678+
" internal::OptionsSpan span($merge_options_fn$("
675679
"std::move(opts), options_));\n"
676680
" return connection_->$method_name$(NoAwaitTag{}, request);\n"
677681
"}\n"},
@@ -682,7 +686,7 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
682686
"\nfuture<StatusOr<$longrunning_deduced_response_type$>>\n"},
683687
{"$client_class_name$::$method_name$("
684688
"$longrunning_operation_type$ const& operation, Options opts) {\n"
685-
" internal::OptionsSpan span(internal::MergeOptions("
689+
" internal::OptionsSpan span($merge_options_fn$("
686690
"std::move(opts), options_));\n"
687691
" return connection_->$method_name$(operation);\n"},
688692
{"}\n"} // clang-format on
@@ -694,7 +698,7 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
694698
{"\nStreamRange<$range_output_type$>\n"
695699
"$client_class_name$::$method_name$($request_type$ request"
696700
", Options opts) {\n"
697-
" internal::OptionsSpan span(internal::MergeOptions("
701+
" internal::OptionsSpan span($merge_options_fn$("
698702
"std::move(opts), options_));\n"
699703
" return connection_->$method_name$(std::move(request));\n"
700704
"}\n"} // clang-format on
@@ -706,7 +710,7 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
706710
{"\nStreamRange<$response_type$>\n"
707711
"$client_class_name$::$method_name$($request_type$ const& request"
708712
", Options opts) {\n"
709-
" internal::OptionsSpan span(internal::MergeOptions("
713+
" internal::OptionsSpan span($merge_options_fn$("
710714
"std::move(opts), options_));\n"
711715
" return connection_->$method_name$(request);\n"
712716
"}\n"} // clang-format on
@@ -733,7 +737,7 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
733737
{"\nfuture<$return_type$>\n"},
734738
// clang-format off
735739
{method_string},
736-
{" internal::OptionsSpan span(internal::MergeOptions("
740+
{" internal::OptionsSpan span($merge_options_fn$("
737741
"std::move(opts), options_));\n"},
738742
{" $request_type$ request;\n"},
739743
{method_request_string},
@@ -752,7 +756,7 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
752756
// clang-format off
753757
{"$client_class_name$::Async$method_name$($request_type$ const& request"
754758
", Options opts) {\n"
755-
" internal::OptionsSpan span(internal::MergeOptions("
759+
" internal::OptionsSpan span($merge_options_fn$("
756760
"std::move(opts), options_));\n"
757761
" return connection_->Async$method_name$(request);\n"
758762
"}\n"} // clang-format on
@@ -768,7 +772,7 @@ std::unique_ptr<::google::cloud::AsyncStreamingReadWriteRpc<
768772
method.return_type(), R"""( $client_class_name$::)""", method.name(),
769773
absl::StrReplaceAll(method.parameters(), {{" = {}", ""}}),
770774
absl::StrFormat(R"""( {
771-
internal::OptionsSpan span(internal::MergeOptions(std::move(opts), options_));
775+
internal::OptionsSpan span($merge_options_fn$(std::move(opts), options_));
772776
return connection_->%s(request);
773777
}
774778
)""",

generator/internal/descriptor_utils.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,10 @@ VarsDictionary CreateServiceVars(
725725
vars["logging_rest_header_path"] = absl::StrCat(
726726
vars["product_path"], "internal/", ServiceNameToFilePath(service_name),
727727
"_rest_logging_decorator.h");
728+
vars["merge_options_fn"] =
729+
absl::StartsWithIgnoreCase(service_name, "Bigtable")
730+
? "bigtable_internal::MergeOptions"
731+
: "internal::MergeOptions";
728732
vars["metadata_class_name"] = absl::StrCat(service_name, "Metadata");
729733
vars["metadata_cc_path"] = absl::StrCat(vars["product_path"], "internal/",
730734
ServiceNameToFilePath(service_name),

google/cloud/bigtable/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ add_library(
229229
mutation_branch.h
230230
mutations.cc
231231
mutations.h
232+
options.cc
232233
options.h
233234
polling_policy.cc
234235
polling_policy.h
@@ -476,6 +477,7 @@ if (BUILD_TESTING)
476477
mocks/mock_row_reader_test.cc
477478
mutation_batcher_test.cc
478479
mutations_test.cc
480+
options_test.cc
479481
polling_policy_test.cc
480482
prepared_query_test.cc
481483
query_row_test.cc

0 commit comments

Comments
 (0)