@@ -79,10 +79,12 @@ class AsyncStreamingReadRpcTracking
7979
8080BigtableRandomTwoLeastUsed::BigtableRandomTwoLeastUsed (
8181 CompletionQueue cq,
82- internal::DynamicChannelPool<BigtableStub>::StubFactoryFn factory_fn,
82+ internal::DynamicChannelPool<BigtableStub>::StubFactoryFn
83+ refreshing_channel_stub_factory_fn,
8384 std::vector<std::shared_ptr<BigtableStub>> children)
8485 : pool_(internal::DynamicChannelPool<BigtableStub>::Create(
85- std::move (cq), std::move(children), std::move(factory_fn))) {}
86+ std::move (cq), std::move(children),
87+ std::move(refreshing_channel_stub_factory_fn))) {}
8688
8789std::unique_ptr<google::cloud::internal::StreamingReadRpc<
8890 google::bigtable::v2::ReadRowsResponse>>
@@ -93,8 +95,7 @@ BigtableRandomTwoLeastUsed::ReadRows(
9395 auto child = Child ();
9496 auto stub = child->AcquireStub ();
9597 auto result = stub->ReadRows (std::move (context), options, request);
96- std::weak_ptr<internal::StubWrapper<BigtableStub>> weak = child;
97- auto release_fn = [weak = std::move (weak)]() {
98+ auto release_fn = [weak = child->MakeWeak ()] {
9899 auto child = weak.lock ();
99100 if (child) child->ReleaseStub ();
100101 };
@@ -111,8 +112,7 @@ BigtableRandomTwoLeastUsed::SampleRowKeys(
111112 auto child = Child ();
112113 auto stub = child->AcquireStub ();
113114 auto result = stub->SampleRowKeys (std::move (context), options, request);
114- std::weak_ptr<internal::StubWrapper<BigtableStub>> weak = child;
115- auto release_fn = [weak = std::move (weak)]() {
115+ auto release_fn = [weak = child->MakeWeak ()] {
116116 auto child = weak.lock ();
117117 if (child) child->ReleaseStub ();
118118 };
@@ -141,8 +141,7 @@ BigtableRandomTwoLeastUsed::MutateRows(
141141 auto child = Child ();
142142 auto stub = child->AcquireStub ();
143143 auto result = stub->MutateRows (std::move (context), options, request);
144- std::weak_ptr<internal::StubWrapper<BigtableStub>> weak = child;
145- auto release_fn = [weak = std::move (weak)]() {
144+ auto release_fn = [weak = child->MakeWeak ()] {
146145 auto child = weak.lock ();
147146 if (child) child->ReleaseStub ();
148147 };
@@ -203,8 +202,7 @@ BigtableRandomTwoLeastUsed::ExecuteQuery(
203202 auto child = Child ();
204203 auto stub = child->AcquireStub ();
205204 auto result = stub->ExecuteQuery (std::move (context), options, request);
206- std::weak_ptr<internal::StubWrapper<BigtableStub>> weak = child;
207- auto release_fn = [weak = std::move (weak)]() {
205+ auto release_fn = [weak = child->MakeWeak ()] {
208206 auto child = weak.lock ();
209207 if (child) child->ReleaseStub ();
210208 };
@@ -224,8 +222,7 @@ BigtableRandomTwoLeastUsed::AsyncReadRows(
224222 auto stub = child->AcquireStub ();
225223 auto result =
226224 stub->AsyncReadRows (cq, std::move (context), std::move (options), request);
227- std::weak_ptr<internal::StubWrapper<BigtableStub>> weak = child;
228- auto release_fn = [weak = std::move (weak)]() {
225+ auto release_fn = [weak = child->MakeWeak ()] {
229226 auto child = weak.lock ();
230227 if (child) child->ReleaseStub ();
231228 };
@@ -245,8 +242,7 @@ BigtableRandomTwoLeastUsed::AsyncSampleRowKeys(
245242 auto stub = child->AcquireStub ();
246243 auto result = stub->AsyncSampleRowKeys (cq, std::move (context),
247244 std::move (options), request);
248- std::weak_ptr<internal::StubWrapper<BigtableStub>> weak = child;
249- auto release_fn = [weak = std::move (weak)]() {
245+ auto release_fn = [weak = child->MakeWeak ()] {
250246 auto child = weak.lock ();
251247 if (child) child->ReleaseStub ();
252248 };
@@ -280,9 +276,7 @@ BigtableRandomTwoLeastUsed::AsyncMutateRows(
280276 auto stub = child->AcquireStub ();
281277 auto result = stub->AsyncMutateRows (cq, std::move (context),
282278 std::move (options), request);
283-
284- std::weak_ptr<internal::StubWrapper<BigtableStub>> weak = child;
285- auto release_fn = [weak = std::move (weak)]() {
279+ auto release_fn = [weak = child->MakeWeak ()] {
286280 auto child = weak.lock ();
287281 if (child) child->ReleaseStub ();
288282 };
@@ -334,21 +328,10 @@ BigtableRandomTwoLeastUsed::AsyncPrepareQuery(
334328 return result;
335329}
336330
337- std::shared_ptr<internal::StubWrapper <BigtableStub>>
331+ std::shared_ptr<internal::StubUsageWrapper <BigtableStub>>
338332BigtableRandomTwoLeastUsed::Child () {
339333 std::cout << __PRETTY_FUNCTION__ << std::endl;
340334 return pool_->GetChannelRandomTwoLeastUsed ();
341- // std::unique_lock<std::mutex> lk(mu_);
342- // std::vector<std::size_t> indices(pool_->size(lk) - 1);
343- // // TODO(sdhart): Maybe use iota on iterators instead of indices
344- // std::iota(indices.begin(), indices.end(), 0);
345- // std::shuffle(indices.begin(), indices.end(), rng_);
346- // auto channel_1 = pool_->GetChannel(lk, indices[0]);
347- // auto channel_2 = pool_->GetChannel(lk, indices[1]);
348- //
349- // return channel_1->outstanding_rpcs(lk) < channel_2->outstanding_rpcs(lk)
350- // ? channel_1
351- // : channel_2;
352335}
353336
354337GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
0 commit comments