From 559f083dc6a49d2d486f6ab7cc8316eba940e6a7 Mon Sep 17 00:00:00 2001 From: Benny Halevy Date: Tue, 14 Jan 2025 17:09:03 +0200 Subject: [PATCH] tablet_allocator: load_balancer: table_size_desc: keep target_tablet_size as member Rather than target_max_tablet_size. We need both the target as well as max and min tablet sizes, so there is no sense in keeping the max and deriving the target and the minimum for the max value. Signed-off-by: Benny Halevy --- service/tablet_allocator.cc | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/service/tablet_allocator.cc b/service/tablet_allocator.cc index 4006b15e1a..e22d4b97b8 100644 --- a/service/tablet_allocator.cc +++ b/service/tablet_allocator.cc @@ -479,22 +479,19 @@ class load_balancer { // due to the average size dropping below the merge threshold, as tablet count doubles. const uint64_t _target_tablet_size = default_target_tablet_size; - static constexpr uint64_t target_max_tablet_size(uint64_t target_tablet_size) { - return target_tablet_size * 2; - } - static constexpr uint64_t target_min_tablet_size(uint64_t max_tablet_size) { - return double(max_tablet_size / 2) * 0.5; - } - struct table_size_desc { - uint64_t target_max_tablet_size; + uint64_t target_tablet_size; uint64_t avg_tablet_size; locator::resize_decision resize_decision; size_t tablet_count; size_t shard_count; + uint64_t target_max_tablet_size() const noexcept { + return target_tablet_size * 2; + } + uint64_t target_min_tablet_size() const noexcept { - return load_balancer::target_min_tablet_size(target_max_tablet_size); + return target_tablet_size / 2; } }; @@ -516,7 +513,7 @@ class load_balancer { return left_growing_mode && d.tablet_count > 1 && d.avg_tablet_size < d.target_min_tablet_size(); } static bool table_needs_split(const table_size_desc& d) { - return d.avg_tablet_size > d.target_max_tablet_size; + return d.avg_tablet_size > d.target_max_tablet_size(); } bool table_needs_resize(const table_size_desc& d) const { @@ -531,9 +528,9 @@ class load_balancer { bool table_needs_resize_cancellation(const table_size_desc& d) const { auto& way = d.resize_decision.way; if (std::holds_alternative(way)) { - return d.avg_tablet_size < d.target_max_tablet_size / 2; + return d.avg_tablet_size < d.target_tablet_size; } else if (std::holds_alternative(way)) { - return d.avg_tablet_size > d.target_min_tablet_size() * 2; + return d.avg_tablet_size > d.target_tablet_size; } return false; } @@ -560,7 +557,7 @@ class load_balancer { return [] (const table_id_and_size_desc& a, const table_id_and_size_desc& b) { auto urgency = [] (const table_size_desc& d) -> double { // FIXME: only takes into account split today. - return double(d.avg_tablet_size) / d.target_max_tablet_size; + return double(d.avg_tablet_size) / d.target_max_tablet_size(); }; return urgency(a.second) < urgency(b.second); }; @@ -1083,7 +1080,7 @@ public: }); table_size_desc size_desc { - .target_max_tablet_size = target_max_tablet_size(_target_tablet_size), + .target_tablet_size = _target_tablet_size, .avg_tablet_size = avg_tablet_size, .resize_decision = tmap.resize_decision(), .tablet_count = tmap.tablet_count(),