Skip to content

Commit c276459

Browse files
committed
rebase with latest code
1 parent 57d64ba commit c276459

7 files changed

Lines changed: 26 additions & 22 deletions

‎google/cloud/internal/rest_pure_background_threads_impl.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,6 @@ struct RestPureQueueTraits {
5252
}
5353
};
5454

55-
/// Background threads that run on a RestPureCompletionQueue.
56-
using AutomaticallyCreatedRestPureBackgroundThreads =
57-
google::cloud::internal::AutomaticallyCreatedBackgroundThreadsImpl<
58-
RestPureCompletionQueue, RestPureBackgroundThreads,
59-
RestPureQueueTraits>;
60-
6155
/// Background threads that run on a RestPureCompletionQueue.
6256
using AutomaticallyCreatedRestPureBackgroundThreads =
6357
google::cloud::internal::AutomaticallyCreatedBackgroundThreadsImpl<

‎google/cloud/storage/grpc_plugin.cc‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ google::cloud::storage::Client MakeGrpcClient(Options opts) {
3838
auto stub = std::make_unique<storage_internal::GrpcStub>(opts);
3939
storage_internal::TracingConnection::AsyncRunner runner;
4040
if (google::cloud::internal::TracingEnabled(opts)) {
41-
auto threads = std::shared_ptr<google::cloud::BackgroundThreads>(
42-
google::cloud::internal::MakeBackgroundThreadsFactory(opts)());
43-
runner = [threads](std::function<void()> f) {
44-
threads->cq().RunAsync(std::move(f));
41+
runner = [cq = stub->cq()](std::function<void()> f) mutable {
42+
cq.RunAsync(std::move(f));
4543
};
4644
}
4745
return storage::internal::ClientImplDetails::CreateWithoutDecorations(

‎google/cloud/storage/internal/grpc/stub.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class GrpcStub : public GenericStub {
5151
google::storage::v2::WriteObjectResponse>;
5252

5353
Options options() const override;
54+
google::cloud::CompletionQueue cq() const { return background_->cq(); }
5455

5556
StatusOr<storage::internal::ListBucketsResponse> ListBuckets(
5657
rest_internal::RestContext& context, Options const& options,

‎google/cloud/storage/internal/tracing_connection.cc‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,25 @@ GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3030

3131
TracingConnection::TracingConnection(std::shared_ptr<StorageConnection> impl,
3232
AsyncRunner runner)
33-
: impl_(std::move(impl)), runner_(std::move(runner)) {
34-
if (!runner_) {
35-
auto threads =
36-
std::make_shared<google::cloud::rest_internal::
37-
AutomaticallyCreatedRestPureBackgroundThreads>(1U);
38-
runner_ = [threads](std::function<void()> f) {
39-
threads->cq().RunAsync(std::move(f));
40-
};
41-
}
42-
}
33+
: impl_(std::move(impl)), runner_(std::move(runner)) {}
4334

4435
TracingConnection::~TracingConnection() = default;
4536

37+
TracingConnection::AsyncRunner const& TracingConnection::runner() {
38+
absl::call_once(once_flag_, [this] {
39+
if (!runner_) {
40+
auto threads =
41+
std::make_shared<google::cloud::rest_internal::
42+
AutomaticallyCreatedRestPureBackgroundThreads>(
43+
1U);
44+
runner_ = [threads](std::function<void()> f) {
45+
threads->cq().RunAsync(std::move(f));
46+
};
47+
}
48+
});
49+
return runner_;
50+
}
51+
4652
BucketMetadataCache& TracingConnection::cache() {
4753
static BucketMetadataCache instance(10000);
4854
return instance;
@@ -65,7 +71,7 @@ void TracingConnection::MaybeTriggerBackgroundFetch(
6571
}
6672

6773
auto current_options = google::cloud::internal::SaveCurrentOptions();
68-
runner_([this, bucket_name, current_options]() {
74+
runner()([this, bucket_name, current_options]() {
6975
google::cloud::internal::OptionsSpan span(current_options);
7076
storage::internal::GetBucketMetadataRequest request(bucket_name);
7177
auto result = impl_->GetBucketMetadata(request);

‎google/cloud/storage/internal/tracing_connection.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "google/cloud/storage/internal/storage_connection.h"
2020
#include "google/cloud/storage/parallel_upload.h"
2121
#include "google/cloud/storage/version.h"
22+
#include "absl/base/call_once.h"
2223
#include <functional>
2324
#include <memory>
2425
#include <string>
@@ -206,8 +207,11 @@ class TracingConnection : public storage::internal::StorageConnection {
206207

207208
static BucketMetadataCache& cache();
208209

210+
AsyncRunner const& runner();
211+
209212
std::shared_ptr<StorageConnection> impl_;
210213
AsyncRunner runner_;
214+
absl::once_flag once_flag_;
211215
};
212216

213217
std::shared_ptr<storage::internal::StorageConnection> MakeTracingClient(

‎google/cloud/storage/tests/object_plenty_clients_serially_integration_test.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ TEST_F(ObjectPlentyClientsSeriallyIntegrationTest, PlentyClientsSerially) {
5454
// The regional_bucket was created in the us-west2 region.
5555
auto options = Options{}.set<RestEndpointOption>(
5656
"https://storage.us-west2.rep.googleapis.com");
57-
auto client = MakeIntegrationTestClient(options);
5857

58+
auto client = MakeIntegrationTestClient(options);
5959
auto object_name = MakeRandomObjectName();
6060
std::string expected = LoremIpsum();
6161

‎google/cloud/storage/tests/object_plenty_clients_simultaneously_integration_test.cc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ TEST_F(ObjectPlentyClientsSimultaneouslyIntegrationTest,
4747

4848
auto client = MakeIntegrationTestClient();
4949
auto object_name = MakeRandomObjectName();
50+
5051
std::string expected = LoremIpsum();
5152

5253
// Create the object, but only if it does not exist already.

0 commit comments

Comments
 (0)