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

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 23faebc6e5d [fix](compaction) fix CompactionPermitLimiter causing 
compaction to stall #35078 (#35510)
23faebc6e5d is described below

commit 23faebc6e5d8a27d28f653fecb505e6cdd1b77be
Author: Sun Chenyang <[email protected]>
AuthorDate: Tue May 28 23:29:34 2024 +0800

    [fix](compaction) fix CompactionPermitLimiter causing compaction to stall 
#35078 (#35510)
---
 be/src/olap/compaction_permit_limiter.cpp | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/be/src/olap/compaction_permit_limiter.cpp 
b/be/src/olap/compaction_permit_limiter.cpp
index 8ca2d49886e..88654da70b7 100644
--- a/be/src/olap/compaction_permit_limiter.cpp
+++ b/be/src/olap/compaction_permit_limiter.cpp
@@ -26,20 +26,26 @@ CompactionPermitLimiter::CompactionPermitLimiter() : 
_used_permits(0) {}
 
 void CompactionPermitLimiter::request(int64_t permits) {
     DorisMetrics::instance()->compaction_waitting_permits->set_value(permits);
-    if (permits > config::total_permits_for_compaction_score) {
+    // 1. config::total_permits_for_compaction_score = 20000
+    // 2. Thread-B requests permits 11000, used_permits = 11000
+    // 3. Thread-A requests permits 12000,wait for used_permits + 12000 <= 
20000
+    // 4. adjust config::total_permits_for_compaction_score = 10000
+    // 5. Thread-B releases permits,used_permits = 0,notify 
Thread-A,used_permits + 12000 <= 10000
+    // we need to initialize total_permits instead of using the config.
+    int64_t total_permits = config::total_permits_for_compaction_score;
+    if (permits > total_permits) {
         // when tablet's compaction score is larger than 
"config::total_permits_for_compaction_score",
         // it's necessary to do compaction for this tablet because this tablet 
will not get "permits"
         // anyway. otherwise, compaction task for this tablet will not be 
executed forever.
         std::unique_lock<std::mutex> lock(_permits_mutex);
-        _permits_cv.wait(lock, [permits, this] {
-            return _used_permits == 0 ||
-                   _used_permits + permits <= 
config::total_permits_for_compaction_score;
+        _permits_cv.wait(lock, [permits, total_permits, this] {
+            return _used_permits == 0 || _used_permits + permits <= 
total_permits;
         });
     } else {
-        if (_used_permits + permits > 
config::total_permits_for_compaction_score) {
+        if (_used_permits + permits > total_permits) {
             std::unique_lock<std::mutex> lock(_permits_mutex);
-            _permits_cv.wait(lock, [permits, this] {
-                return _used_permits + permits <= 
config::total_permits_for_compaction_score;
+            _permits_cv.wait(lock, [permits, total_permits, this] {
+                return _used_permits + permits <= total_permits;
             });
         }
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to