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
3 changes: 2 additions & 1 deletion src/include/dbconnector/pool/connection_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ConnectionPool : public std::enable_shared_from_this<ConnectionPool<Connec
uint64_t GetIdleTimeoutMillis() const;
void SetIdleTimeoutMillis(uint64_t new_idle_timeout_millis);

bool IsReaperRunning();
bool EnsureReaperRunning();
void ShutdownReaper();

Expand Down Expand Up @@ -111,7 +112,7 @@ class ConnectionPool : public std::enable_shared_from_this<ConnectionPool<Connec

std::thread reaper_thread;
std::condition_variable reaper_cv;
std::atomic<bool> reaper_shutdown_flag {false};
std::atomic<bool> reaper_shutdown_flag {true};

std::atomic<bool> tl_cache_enabled {false};
std::atomic<uint64_t> tl_cache_hits {0};
Expand Down
5 changes: 5 additions & 0 deletions src/include/dbconnector/pool/connection_pool_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,11 @@ void ConnectionPool<ConnectionT>::ReaperLoop() {
}
}

template <typename ConnectionT>
bool ConnectionPool<ConnectionT>::IsReaperRunning() {
return !reaper_shutdown_flag.load(std::memory_order_relaxed);
}

template <typename ConnectionT>
bool ConnectionPool<ConnectionT>::EnsureReaperRunning() {
if (!TimeoutEnabled()) {
Expand Down
5 changes: 5 additions & 0 deletions test/test_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,12 @@ TEST_CASE("Test pool disable running", group_name) {

TEST_CASE("Test pool with a reaper", group_name) {
auto pool = std::make_shared<TestConnectionPool>(4, 1000, false);
REQUIRE(!pool->IsReaperRunning());
REQUIRE(!pool->EnsureReaperRunning());
pool->SetMaxLifetimeMillis(1000);
REQUIRE(pool->EnsureReaperRunning());
REQUIRE(pool->EnsureReaperRunning());
REQUIRE(pool->IsReaperRunning());

{
auto conn = pool->WaitAcquire();
Expand Down Expand Up @@ -269,10 +271,13 @@ TEST_CASE("Test pool with a reaper", group_name) {

TEST_CASE("Test pool with a reaper restart", group_name) {
auto pool = std::make_shared<TestConnectionPool>(4, 1000, false);
REQUIRE(!pool->IsReaperRunning());
REQUIRE(!pool->EnsureReaperRunning());
pool->SetMaxLifetimeMillis(1000);
REQUIRE(pool->EnsureReaperRunning());
REQUIRE(pool->IsReaperRunning());
pool->ShutdownReaper();
REQUIRE(!pool->IsReaperRunning());

{
auto conn = pool->WaitAcquire();
Expand Down
Loading