This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch branch-1.18.x
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/branch-1.18.x by this push:
     new 78f9f0c8c KUDU-3722 unit mismatch in ProceedWithFlush
78f9f0c8c is described below

commit 78f9f0c8c84518349149ee3312b4601dccb26c04
Author: James Teng <[email protected]>
AuthorDate: Sun Nov 30 17:04:51 2025 +0800

    KUDU-3722 unit mismatch in ProceedWithFlush
    
    MaintenanceManager's ProceedWithFlush function uses units inconsistent
    with process_memory::UnderMemoryPressure when checking memory pressure:
    soft_limit and pressure_threshold are treated as decimals (0–1)
    while used_memory_percentage is a percentage (0–100). This causes
    ProceedWithFlush to always return true once memory usage exceeds
    memory_pressure_percentage, which is not the intended behavior
    introduced by KUDU-3407.
    
    This patch converts soft_limit and pressure_threshold to percentages,
    replaces division with an equivalent multiplication form, and updates
    the relevant tests.
    
    Change-Id: Icb4c299a83c61bd934d67f32446696988bbe3a08
    Reviewed-on: http://gerrit.cloudera.org:8080/23726
    Tested-by: Alexey Serbin <[email protected]>
    Reviewed-by: Alexey Serbin <[email protected]>
    (cherry picked from commit 6799d13cc53190604d141ca1ebf26882edb3b88a)
    Reviewed-on: http://gerrit.cloudera.org:8080/23748
    Reviewed-by: Zoltan Martonka <[email protected]>
    Reviewed-by: Abhishek Chennaka <[email protected]>
---
 src/kudu/util/maintenance_manager-test.cc | 26 +++++++++++++-------------
 src/kudu/util/maintenance_manager.cc      | 17 ++++++++++-------
 2 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/src/kudu/util/maintenance_manager-test.cc 
b/src/kudu/util/maintenance_manager-test.cc
index 247f5d1ed..a1f58c24c 100644
--- a/src/kudu/util/maintenance_manager-test.cc
+++ b/src/kudu/util/maintenance_manager-test.cc
@@ -349,16 +349,16 @@ class MaintenanceManagerTest : public KuduTest {
     // simulated.
     manager_->set_memory_pressure_func_for_tests(
         [&](double* /* consumption */) {
-          double pressure_ratio = 
static_cast<double>(FLAGS_memory_pressure_percentage) / 100;
-          if (memory_pressure_pct_.load() >= pressure_ratio) {
-            double pressure_threshold = pressure_ratio;
-            double soft_limit = 
static_cast<double>(FLAGS_memory_limit_soft_percentage) / 100;
-            return pressure_threshold >= soft_limit || 
memory_pressure_pct_.load() >=
-                soft_limit ||Random(GetRandomSeed32()).NextDoubleFraction() >=
-                FLAGS_run_non_memory_ops_prob * (soft_limit - 
memory_pressure_pct_.load())
-                / (soft_limit - pressure_threshold);
+          static const double pressure_threshold = 
FLAGS_memory_pressure_percentage;
+          static const double soft_limit = FLAGS_memory_limit_soft_percentage;
+          static const double pressure_diff = soft_limit - pressure_threshold;
+          if (memory_pressure_pct_.load() < pressure_threshold) {
+            return false;
           }
-          return false;
+          const double used_diff = soft_limit - memory_pressure_pct_.load();
+          return pressure_diff <= 0 || used_diff <= 0 ||
+              Random(GetRandomSeed32()).NextDoubleFraction() * pressure_diff >=
+                  FLAGS_run_non_memory_ops_prob * used_diff;
         });
     ASSERT_OK(manager_->Start());
   }
@@ -492,7 +492,7 @@ TEST_F(MaintenanceManagerTest, 
TestMemoryPressurePrioritizesMemory) {
   ASSERT_EQ(0, op.DurationHistogram()->TotalCount());
 
   // Fake that the server is under memory pressure.
-  memory_pressure_pct_ = 0.7;
+  memory_pressure_pct_ = 70;
 
   ASSERT_EVENTUALLY([&]() {
       ASSERT_EQ(op.DurationHistogram()->TotalCount(), 1);
@@ -513,7 +513,7 @@ TEST_F(MaintenanceManagerTest, 
TestMemoryPressurePerformsNoMemoryOp) {
 
   // Now fake that the server is under memory pressure and make our op runnable
   // by giving it a perf score.
-  memory_pressure_pct_ = 0.7;
+  memory_pressure_pct_ = 70;
   op.set_perf_improvement(1);
 
   // Even though we're under memory pressure, and even though our op doesn't
@@ -593,7 +593,7 @@ TEST_F(MaintenanceManagerTest, 
TestPrioritizeLogRetentionUnderMemoryPressure) {
   op3.set_logs_retained_bytes(99);
   op3.set_ram_anchored(101);
 
-  memory_pressure_pct_ = 0.7;
+  memory_pressure_pct_ = 70;
   manager_->RegisterOp(&op1);
   manager_->RegisterOp(&op2);
   manager_->RegisterOp(&op3);
@@ -1032,7 +1032,7 @@ TEST_F(MaintenanceManagerTest, ComprehensiveTest) {
   SKIP_IF_SLOW_NOT_ALLOWED();
 
   // Select policies here.
-  memory_pressure_pct_ = 0.6;
+  memory_pressure_pct_ = 60;
   FLAGS_run_non_memory_ops_prob = 0.2;
   FLAGS_data_gc_prioritization_prob = 0.5;
 
diff --git a/src/kudu/util/maintenance_manager.cc 
b/src/kudu/util/maintenance_manager.cc
index ac2ac9067..721c22c8f 100644
--- a/src/kudu/util/maintenance_manager.cc
+++ b/src/kudu/util/maintenance_manager.cc
@@ -721,13 +721,16 @@ void 
MaintenanceManager::DecreaseOpCountAndNotifyWaiters(MaintenanceOp* op) {
 }
 
 bool MaintenanceManager::ProceedWithFlush(double* used_memory_percentage) {
-  if (process_memory::UnderMemoryPressure(used_memory_percentage)) {
-    double pressure_threshold = 
static_cast<double>(FLAGS_memory_pressure_percentage) / 100;
-    double soft_limit = 
static_cast<double>(FLAGS_memory_limit_soft_percentage) / 100;
-    return pressure_threshold >= soft_limit || *used_memory_percentage >= 
soft_limit ||
-        rand_.NextDoubleFraction() >= FLAGS_run_non_memory_ops_prob *
-        (soft_limit - *used_memory_percentage) / (soft_limit - 
pressure_threshold);
+  if (!process_memory::UnderMemoryPressure(used_memory_percentage)) {
+    return false;
   }
-  return false;
+
+  static const double pressure_threshold = FLAGS_memory_pressure_percentage;
+  static const double soft_limit = FLAGS_memory_limit_soft_percentage;
+  static const double pressure_diff = soft_limit - pressure_threshold;
+  const double used_diff = soft_limit - *used_memory_percentage;
+  return pressure_diff <= 0 || used_diff <= 0 ||
+      rand_.NextDoubleFraction() * pressure_diff >=
+          FLAGS_run_non_memory_ops_prob * used_diff;
 }
 } // namespace kudu

Reply via email to