Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions source/common/upstream/cluster_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ void ClusterManagerImpl::ThreadLocalClusterManagerImpl::drainConnPools(
pools->drainConnections(Envoy::ConnectionPool::DrainBehavior::DrainAndDelete);
container.do_not_delete_ = false;

if (container.pools_->size() == 0) {
if (container.pools_->empty()) {
host_http_conn_pool_map_.erase(old_host);
}
}
Expand Down Expand Up @@ -1393,7 +1393,7 @@ void ClusterManagerImpl::ThreadLocalClusterManagerImpl::drainAllConnPoolsWorker(
Envoy::ConnectionPool::DrainBehavior::DrainExistingConnections);
container->do_not_delete_ = false;

if (container->pools_->size() == 0) {
if (container->pools_->empty()) {
host_http_conn_pool_map_.erase(host);
}
}
Expand Down Expand Up @@ -1539,7 +1539,7 @@ void ClusterManagerImpl::ThreadLocalClusterManagerImpl::httpConnPoolIsIdle(
// Guard deletion of the container with `do_not_delete_` to avoid deletion while
// iterating through the container in `container->pools_->startDrain()`. See
// comment in `ClusterManagerImpl::ThreadLocalClusterManagerImpl::drainConnPools`.
if (!container->do_not_delete_ && container->pools_->size() == 0) {
if (!container->do_not_delete_ && container->pools_->empty()) {
ENVOY_LOG(trace, "Pool container empty for host {}, erasing host entry", host);
host_http_conn_pool_map_.erase(
host); // NOTE: `container` is erased after this point in the lambda.
Expand Down
5 changes: 5 additions & 0 deletions source/common/upstream/priority_conn_pool_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ template <typename KEY_TYPE, typename POOL_TYPE> class PriorityConnPoolMap {
*/
size_t size() const;

/**
* @return true if the pools across all priorities are empty.
*/
bool empty() const;

/**
* Destroys all mapped pools.
*/
Expand Down
10 changes: 10 additions & 0 deletions source/common/upstream/priority_conn_pool_map_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ size_t PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::size() const {
return size;
}

template <typename KEY_TYPE, typename POOL_TYPE>
bool PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::empty() const {
for (const auto& pool_map : conn_pool_maps_) {
if (!pool_map->empty()) {
return false;
}
}
return true;
}

template <typename KEY_TYPE, typename POOL_TYPE>
void PriorityConnPoolMap<KEY_TYPE, POOL_TYPE>::clear() {
for (auto& pool_map : conn_pool_maps_) {
Expand Down
4 changes: 2 additions & 2 deletions test/common/upstream/priority_conn_pool_map_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ TEST_F(PriorityConnPoolMapImplTest, TestClearEmptiesOut) {
test_map->getPool(ResourcePriority::Default, 2, getBasicFactory());
test_map->clear();

EXPECT_EQ(test_map->size(), 0);
EXPECT_TRUE(test_map->empty());
}

TEST_F(PriorityConnPoolMapImplTest, TestErase) {
Expand All @@ -124,7 +124,7 @@ TEST_F(PriorityConnPoolMapImplTest, TestErase) {
EXPECT_EQ(2, test_map->size());
EXPECT_TRUE(test_map->erasePool(ResourcePriority::Default, 1));
EXPECT_TRUE(test_map->erasePool(ResourcePriority::High, 1));
EXPECT_EQ(0, test_map->size());
EXPECT_TRUE(test_map->empty());
EXPECT_NE(pool_ptr,
&test_map->getPool(ResourcePriority::High, 1, getBasicFactory()).value().get());
}
Expand Down