@@ -184,6 +184,7 @@ void SessionPool::Erase(std::string const& session_name) {
184184 target = std::move (session); // deferred deletion
185185 session = std::move (sessions_.back ());
186186 sessions_.pop_back ();
187+ DecrementSessionCount (lk, *target);
187188 break ;
188189 }
189190 }
@@ -287,6 +288,21 @@ Status SessionPool::CreateSessions(
287288 return return_status;
288289}
289290
291+ int SessionPool::total_sessions () const {
292+ std::lock_guard<std::mutex> lk (mu_);
293+ return total_sessions_;
294+ }
295+
296+ void SessionPool::DecrementSessionCount (
297+ std::unique_lock<std::mutex> const &,
298+ google::cloud::spanner_internal::Session const & session) {
299+ --total_sessions_;
300+ auto const & channel = session.channel ();
301+ if (channel) {
302+ --channel->session_count ;
303+ }
304+ }
305+
290306StatusOr<SessionHolder> SessionPool::Allocate (bool dissociate_from_pool) {
291307 // We choose to ignore the internal::CurrentOptions() here as it is
292308 // non-deterministic when RPCs to create sessions are actually made.
@@ -299,11 +315,7 @@ StatusOr<SessionHolder> SessionPool::Allocate(bool dissociate_from_pool) {
299315 auto session = std::move (sessions_.back ());
300316 sessions_.pop_back ();
301317 if (dissociate_from_pool) {
302- --total_sessions_;
303- auto const & channel = session->channel ();
304- if (channel) {
305- --channel->session_count ;
306- }
318+ DecrementSessionCount (lk, *session);
307319 }
308320 return {MakeSessionHolder (std::move (session), dissociate_from_pool)};
309321 }
@@ -367,11 +379,7 @@ void SessionPool::Release(std::unique_ptr<Session> session) {
367379 if (session->is_bad ()) {
368380 // Once we have support for background processing, we may want to signal
369381 // that to replenish this bad session.
370- --total_sessions_;
371- auto const & channel = session->channel ();
372- if (channel) {
373- --channel->session_count ;
374- }
382+ DecrementSessionCount (lk, *session);
375383 return ;
376384 }
377385 session->update_last_use_time ();
0 commit comments