Skip to content

Commit 17b5304

Browse files
authored
refactor(bigtable): channel refresh (#8840)
1 parent 6afccef commit 17b5304

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

google/cloud/bigtable/internal/common_client.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,9 @@ class CommonClient {
148148
args.SetInt(GRPC_ARG_CHANNEL_ID, idx);
149149
auto res = grpc::CreateCustomChannel(
150150
opts_.get<EndpointOption>(), opts_.get<GrpcCredentialOption>(), args);
151-
if (opts_.get<MaxConnectionRefreshOption>().count() == 0) {
152-
return res;
151+
if (refresh_state_->enabled()) {
152+
ScheduleChannelRefresh(refresh_cq_, refresh_state_, res);
153153
}
154-
ScheduleChannelRefresh(refresh_cq_, refresh_state_, res);
155154
return res;
156155
}
157156

google/cloud/bigtable/internal/connection_refresh_state.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ std::chrono::milliseconds ConnectionRefreshState::RandomizedRefreshDelay() {
4848
max_conn_refresh_period_.count())(rng_));
4949
}
5050

51+
bool ConnectionRefreshState::enabled() const {
52+
return max_conn_refresh_period_.count() != 0;
53+
}
54+
5155
void ScheduleChannelRefresh(
5256
std::shared_ptr<CompletionQueue> const& cq,
5357
std::shared_ptr<ConnectionRefreshState> const& state,

google/cloud/bigtable/internal/connection_refresh_state.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class ConnectionRefreshState {
6868
std::chrono::milliseconds max_conn_refresh_period);
6969
std::chrono::milliseconds RandomizedRefreshDelay();
7070
OutstandingTimers& timers() { return *timers_; }
71+
bool enabled() const;
7172

7273
private:
7374
std::mutex mu_;

google/cloud/bigtable/internal/connection_refresh_state_test.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ TEST_F(OutstandingTimersTest, TimerRegisteredAfterCancelAllGetCancelled) {
106106
continuation_promise.get_future().get();
107107
}
108108

109+
TEST(ConnectionRefreshState, Enabled) {
110+
using ms = std::chrono::milliseconds;
111+
ConnectionRefreshState state(std::make_shared<CompletionQueue>(), ms(0),
112+
ms(1000));
113+
EXPECT_TRUE(state.enabled());
114+
}
115+
116+
TEST(ConnectionRefreshState, Disabled) {
117+
using ms = std::chrono::milliseconds;
118+
ConnectionRefreshState state(std::make_shared<CompletionQueue>(), ms(0),
119+
ms(0));
120+
EXPECT_FALSE(state.enabled());
121+
}
122+
109123
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
110124
} // namespace bigtable_internal
111125
} // namespace cloud

0 commit comments

Comments
 (0)