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
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/conn_pool_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ template <typename KEY_TYPE, typename POOL_TYPE> class ConnPoolMap {
*/
size_t size() const;

/**
* @return true if the pools are empty.
*/
size_t empty() const;

Choose a reason for hiding this comment

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

should this return bool instead of size_t?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it definitely should. @lambdai can you post a followup to fix that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops. Sure


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

template <typename KEY_TYPE, typename POOL_TYPE>
size_t ConnPoolMap<KEY_TYPE, POOL_TYPE>::empty() const {
return active_pools_.empty();
}

template <typename KEY_TYPE, typename POOL_TYPE> void ConnPoolMap<KEY_TYPE, POOL_TYPE>::clear() {
Common::AutoDebugRecursionChecker assert_not_in(recursion_checker_);
for (auto& pool_pair : active_pools_) {
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