From c155c02f6cd48fbd7b4995b243dd713e3c19717a Mon Sep 17 00:00:00 2001 From: Darren Bolduc Date: Fri, 27 Aug 2021 15:02:48 -0400 Subject: [PATCH] cleanup(bigtable): remove ClientOptions from benchmark (#7233) --- google/cloud/bigtable/benchmarks/benchmark.cc | 21 ++++++++++++------- google/cloud/bigtable/benchmarks/benchmark.h | 5 ++--- .../read_sync_vs_async_benchmark.cc | 2 +- .../testing/embedded_server_test_fixture.cc | 4 +++- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/google/cloud/bigtable/benchmarks/benchmark.cc b/google/cloud/bigtable/benchmarks/benchmark.cc index 20ea7deed714b..cc5fa7140447c 100644 --- a/google/cloud/bigtable/benchmarks/benchmark.cc +++ b/google/cloud/bigtable/benchmarks/benchmark.cc @@ -15,6 +15,7 @@ #include "google/cloud/bigtable/benchmarks/benchmark.h" #include "google/cloud/bigtable/benchmarks/random_mutation.h" #include "google/cloud/bigtable/table_admin.h" +#include "google/cloud/internal/background_threads_impl.h" #include "google/cloud/internal/getenv.h" #include #include @@ -68,7 +69,7 @@ google::cloud::StatusOr ParseArgs( Benchmark::Benchmark(BenchmarkOptions options) : options_(std::move(options)), key_width_(KeyWidth()) { - auto opts = Options{}.set(options_.thread_count); + opts_.set(options_.thread_count); if (options_.use_embedded_server) { server_ = CreateEmbeddedServer(); std::string address = server_->address(); @@ -76,12 +77,11 @@ Benchmark::Benchmark(BenchmarkOptions options) << "\n"; server_thread_ = std::thread([this]() { server_->Wait(); }); - opts.set(grpc::InsecureChannelCredentials()) + opts_.set(grpc::InsecureChannelCredentials()) .set(address) .set(address) .set(address); } - client_options_ = ClientOptions(std::move(opts)); } Benchmark::~Benchmark() { @@ -98,7 +98,7 @@ Benchmark::~Benchmark() { std::string Benchmark::CreateTable() { // Create the table, with an initial split. bigtable::TableAdmin admin( - bigtable::CreateDefaultAdminClient(options_.project_id, client_options_), + bigtable::MakeAdminClient(options_.project_id, opts_), options_.instance_id); std::vector splits{"user0", "user1", "user2", "user3", "user4", @@ -112,7 +112,7 @@ std::string Benchmark::CreateTable() { void Benchmark::DeleteTable() { bigtable::TableAdmin admin( - bigtable::CreateDefaultAdminClient(options_.project_id, client_options_), + bigtable::MakeAdminClient(options_.project_id, opts_), options_.instance_id); auto status = admin.DeleteTable(options_.table_id); if (!status.ok()) { @@ -122,8 +122,8 @@ void Benchmark::DeleteTable() { } std::shared_ptr Benchmark::MakeDataClient() { - return bigtable::CreateDefaultDataClient( - options_.project_id, options_.instance_id, client_options_); + return bigtable::MakeDataClient(options_.project_id, options_.instance_id, + opts_); } google::cloud::StatusOr Benchmark::PopulateTable() { @@ -289,6 +289,13 @@ int Benchmark::read_rows_count() const { return server_->read_rows_count(); } +void Benchmark::DisableBackgroundThreads(CompletionQueue& cq) { + opts_.set([&cq] { + return absl::make_unique< + google::cloud::internal::CustomerSuppliedBackgroundThreads>(cq); + }); +} + google::cloud::StatusOr Benchmark::PopulateTableShard( bigtable::Table& table, std::int64_t begin, std::int64_t end) const { auto start = std::chrono::steady_clock::now(); diff --git a/google/cloud/bigtable/benchmarks/benchmark.h b/google/cloud/bigtable/benchmarks/benchmark.h index 454d952b4c8c7..adb006a42170d 100644 --- a/google/cloud/bigtable/benchmarks/benchmark.h +++ b/google/cloud/bigtable/benchmarks/benchmark.h @@ -119,8 +119,7 @@ class Benchmark { int read_rows_count() const; //@} - /// Return a mutable reference to client options. - ClientOptions& ClientOptionsRef() { return client_options_; } + void DisableBackgroundThreads(CompletionQueue& cq); private: /// Populate the table rows in the range [@p begin, @p end) @@ -135,7 +134,7 @@ class Benchmark { BenchmarkOptions options_; int key_width_; - bigtable::ClientOptions client_options_; + Options opts_; std::unique_ptr server_; std::thread server_thread_; }; diff --git a/google/cloud/bigtable/benchmarks/read_sync_vs_async_benchmark.cc b/google/cloud/bigtable/benchmarks/read_sync_vs_async_benchmark.cc index 1d8d609898b26..5a4215d8e4f00 100644 --- a/google/cloud/bigtable/benchmarks/read_sync_vs_async_benchmark.cc +++ b/google/cloud/bigtable/benchmarks/read_sync_vs_async_benchmark.cc @@ -147,7 +147,7 @@ int main(int argc, char* argv[]) { Benchmark benchmark(*options); google::cloud::CompletionQueue cq; - benchmark.ClientOptionsRef().DisableBackgroundThreads(cq); + benchmark.DisableBackgroundThreads(cq); // Create and populate the table for the benchmark. benchmark.CreateTable(); diff --git a/google/cloud/bigtable/testing/embedded_server_test_fixture.cc b/google/cloud/bigtable/testing/embedded_server_test_fixture.cc index 2bd869f536c53..913d335690e44 100644 --- a/google/cloud/bigtable/testing/embedded_server_test_fixture.cc +++ b/google/cloud/bigtable/testing/embedded_server_test_fixture.cc @@ -15,6 +15,7 @@ #include "google/cloud/bigtable/testing/embedded_server_test_fixture.h" #include "google/cloud/grpc_error_delegate.h" #include "google/cloud/internal/build_info.h" +#include "google/cloud/internal/user_agent_prefix.h" #include namespace google { @@ -48,7 +49,8 @@ void EmbeddedServerTestFixture::SetUp() { StartServer(); grpc::ChannelArguments channel_arguments; - channel_arguments.SetUserAgentPrefix(ClientOptions::UserAgentPrefix()); + channel_arguments.SetUserAgentPrefix( + google::cloud::internal::UserAgentPrefix()); std::string project_id = kProjectId; std::string instance_id = kInstanceId; std::string table_id = kTableId;