From f46acc5236b4de29b0d1b3c567e6518e2032c43f Mon Sep 17 00:00:00 2001 From: Igor Nikonov Date: Wed, 20 Dec 2023 20:38:02 +0000 Subject: [PATCH] Add comment & polishing --- src/Common/GetPriorityForLoadBalancing.cpp | 8 ++++++++ src/Common/PoolWithFailoverBase.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Common/GetPriorityForLoadBalancing.cpp b/src/Common/GetPriorityForLoadBalancing.cpp index 161ac96f5ec..f0065f47c9b 100644 --- a/src/Common/GetPriorityForLoadBalancing.cpp +++ b/src/Common/GetPriorityForLoadBalancing.cpp @@ -35,6 +35,14 @@ std::function GetPriorityForLoadBalancing::getPriorityFu case LoadBalancing::ROUND_ROBIN: auto local_last_used = last_used.fetch_add(1) % pool_size; + // Example: pool_size = 5 + // | local_last_used | i=0 | i=1 | i=2 | i=3 | i=4 | + // | 0 | 4 | 0 | 1 | 2 | 3 | + // | 1 | 3 | 4 | 0 | 1 | 2 | + // | 2 | 2 | 3 | 4 | 0 | 1 | + // | 3 | 1 | 2 | 3 | 4 | 0 | + // | 4 | 0 | 1 | 2 | 3 | 4 | + get_priority = [pool_size, local_last_used](size_t i) { size_t priority = pool_size - 1; diff --git a/src/Common/PoolWithFailoverBase.h b/src/Common/PoolWithFailoverBase.h index 543a39fbc39..b8c032fad7b 100644 --- a/src/Common/PoolWithFailoverBase.h +++ b/src/Common/PoolWithFailoverBase.h @@ -147,7 +147,7 @@ protected: return std::make_tuple(shared_pool_states, nested_pools, last_error_decrease_time); } - NestedPools nested_pools; + const NestedPools nested_pools; const time_t decrease_error_period; const size_t max_error_cap;