Skip to content

Commit 59d22fb

Browse files
committed
average per minute with tests
1 parent e5a1ff8 commit 59d22fb

File tree

7 files changed

+290
-121
lines changed

7 files changed

+290
-121
lines changed

google/cloud/bigtable/internal/bigtable_random_two_least_used_decorator.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ BigtableRandomTwoLeastUsed::AsyncPrepareQuery(
329329
return result;
330330
}
331331

332-
std::shared_ptr<ChannelUsageWrapper<BigtableStub>>
332+
std::shared_ptr<ChannelUsage<BigtableStub>>
333333
BigtableRandomTwoLeastUsed::Child() {
334334
std::cout << __PRETTY_FUNCTION__ << std::endl;
335335
return pool_->GetChannelRandomTwoLeastUsed();

google/cloud/bigtable/internal/bigtable_random_two_least_used_decorator.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ class BigtableRandomTwoLeastUsed : public BigtableStub {
129129
google::bigtable::v2::PrepareQueryRequest const& request) override;
130130

131131
private:
132-
std::shared_ptr<ChannelUsageWrapper<BigtableStub>> Child();
133-
134-
// std::mutex mu_;
132+
std::shared_ptr<ChannelUsage<BigtableStub>> Child();
135133
std::shared_ptr<DynamicChannelPool<BigtableStub>> pool_;
136134
};
137135

google/cloud/bigtable/internal/bigtable_stub_factory.cc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,30 +85,34 @@ std::shared_ptr<BigtableStub> CreateBigtableStubRandomTwoLeastUsed(
8585

8686
auto refreshing_channel_stub_factory =
8787
[stub_factory = std::move(stub_factory), cq_impl, refresh_state,
88-
auth = std::move(auth), options](std::uint32_t id)
89-
-> std::shared_ptr<ChannelUsageWrapper<BigtableStub>> {
90-
auto wrapper = std::make_shared<ChannelUsageWrapper<BigtableStub>>();
88+
auth = std::move(auth), options](
89+
std::uint32_t id,
90+
bool prime_channel) -> std::shared_ptr<ChannelUsage<BigtableStub>> {
91+
auto wrapper = std::make_shared<ChannelUsage<BigtableStub>>();
9192
auto connection_status_fn = [weak = wrapper->MakeWeak()](Status const& s) {
9293
if (auto self = weak.lock()) {
93-
self->SetLastRefreshStatus(s);
94+
self->set_last_refresh_status(s);
9495
}
9596
if (!s.ok()) {
9697
GCP_LOG(WARNING) << "Failed to refresh connection. Error: " << s;
9798
}
9899
};
99100
auto channel = CreateGrpcChannel(*auth, options, id);
101+
if (prime_channel) {
102+
(void)channel->GetState(true);
103+
}
100104
ScheduleChannelRefresh(cq_impl, refresh_state, channel,
101105
std::move(connection_status_fn));
102106
wrapper->set_channel(stub_factory(std::move(channel)));
103107
return wrapper;
104108
};
105109

106-
std::vector<std::shared_ptr<ChannelUsageWrapper<BigtableStub>>> children(
110+
std::vector<std::shared_ptr<ChannelUsage<BigtableStub>>> children(
107111
std::max(1, options.get<GrpcNumChannelsOption>()));
108112
std::uint32_t id = 0;
109113
std::generate(children.begin(), children.end(),
110114
[&id, &refreshing_channel_stub_factory] {
111-
return refreshing_channel_stub_factory(id++);
115+
return refreshing_channel_stub_factory(id++, false);
112116
});
113117

114118
return std::make_shared<BigtableRandomTwoLeastUsed>(

google/cloud/bigtable/internal/connection_refresh_state.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ namespace {
3030
*/
3131
auto constexpr kConnectionReadyTimeout = std::chrono::seconds(10);
3232

33+
void LogFailedConnectionRefresh(Status const& conn_status) {
34+
if (!conn_status.ok()) {
35+
GCP_LOG(WARNING) << "Failed to refresh connection. Error: " << conn_status;
36+
}
37+
}
38+
3339
} // namespace
3440

3541
ConnectionRefreshState::ConnectionRefreshState(
@@ -53,12 +59,6 @@ bool ConnectionRefreshState::enabled() const {
5359
return max_conn_refresh_period_.count() != 0;
5460
}
5561

56-
void LogFailedConnectionRefresh(Status const& conn_status) {
57-
if (!conn_status.ok()) {
58-
GCP_LOG(WARNING) << "Failed to refresh connection. Error: " << conn_status;
59-
}
60-
}
61-
6262
void ScheduleChannelRefresh(
6363
std::shared_ptr<internal::CompletionQueueImpl> const& cq_impl,
6464
std::shared_ptr<ConnectionRefreshState> const& state,

0 commit comments

Comments
 (0)