Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions google/cloud/spanner/internal/session_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,13 @@ std::shared_ptr<SpannerStub> SessionPool::GetStub(Session const& session) {
return GetStub(std::unique_lock<std::mutex>(mu_));
}

void SessionPool::DecrementSessionCount(
std::unique_lock<std::mutex> const&,
google::cloud::spanner_internal::Session& session) {
int SessionPool::total_sessions() const {
std::lock_guard<std::mutex> lk(mu_);
return total_sessions_;
}

void SessionPool::DecrementSessionCount(std::unique_lock<std::mutex> const&,
Session const& session) {
--total_sessions_;
auto const& channel = session.channel();
if (channel) {
Expand Down
9 changes: 6 additions & 3 deletions google/cloud/spanner/internal/session_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ class SessionPool : public std::enable_shared_from_this<SessionPool> {
/**
* Returns the number of sessions in the session pool plus the number of
* sessions allocated to running transactions.
*
* @note This function should only be used for testing as other threads
* could be modifying the underlying value immediately after it returns.
*/
int total_sessions() const { return total_sessions_; }
int total_sessions() const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is one of those "snapshotting", informational accessors that couldn't really be used in a robust program, it should at least be marked as "for testing purposes only".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a bit about using it only for testing.


private:
friend std::shared_ptr<SessionPool> MakeSessionPool(
Expand Down Expand Up @@ -215,7 +218,7 @@ class SessionPool : public std::enable_shared_from_this<SessionPool> {

// Performs the necessary bookkeeping when a session is removed from use.
void DecrementSessionCount(std::unique_lock<std::mutex> const& lk,
Session& session);
Session const& session);

spanner::Database const db_;
google::cloud::CompletionQueue cq_;
Expand All @@ -226,7 +229,7 @@ class SessionPool : public std::enable_shared_from_this<SessionPool> {
int const max_pool_size_;
std::mt19937 random_generator_;

std::mutex mu_;
mutable std::mutex mu_;
std::condition_variable cond_;
SessionHolder multiplexed_session_; // GUARDED_BY(mu_)
std::vector<std::unique_ptr<Session>> sessions_; // GUARDED_BY(mu_)
Expand Down
Loading