yujun777 commented on code in PR #29005:
URL: https://github.com/apache/doris/pull/29005#discussion_r1444155642


##########
fe/fe-core/src/main/java/org/apache/doris/system/Backend.java:
##########
@@ -823,4 +830,56 @@ public String getTagMapString() {
         return "{" + new PrintableMap<>(tagMap, ":", true, false).toString() + 
"}";
     }
 
+    private void delExpireStatUnLock(long windowRight) {
+        while (true) {
+            Pair<Long, Long> stat = cloneFailedWindow.peekFirst();
+            if (stat == null || stat.first >= windowRight) {
+                break;
+            }
+            cloneFailedWindow.pollFirst();
+        }
+    }
+
+    public void updateCloneFailedWindow() {
+        lock.lock();
+        /*
+                       oldestTimeStamp            windowRight          
currentTimeStamp
+                            ^                            ^                     
  ^
+                            |                            |                     
  |
+                            |                            |         window      
  |
+                            |            toDel           |
+        */
+        long curFailTimeStamp = System.currentTimeMillis();
+        Long windowRight = curFailTimeStamp - 
Config.be_check_health_window_length * 1000L;
+
+        delExpireStatUnLock(windowRight);
+
+        if (cloneFailedWindow.peekLast() != null
+                && curFailTimeStamp <= cloneFailedWindow.peekLast().first + 10 
* 1000) {
+            cloneFailedWindow.peekLast().second++;
+        } else {
+            cloneFailedWindow.addLast(Pair.of(curFailTimeStamp, 1L));
+        }
+        lock.unlock();
+    }
+
+    public boolean isExceedCloneFailedLimit() {
+        lock.lock();
+        long currentTimeStamp = System.currentTimeMillis();
+        long windowRight = currentTimeStamp - 
Config.be_check_health_window_length * 1000L;
+
+        delExpireStatUnLock(windowRight);
+
+        long count = cloneFailedWindow.stream()
+                .filter(stat -> (stat.first <= currentTimeStamp && stat.first 
>= windowRight))
+                .mapToLong(stat -> stat.second).sum();
+        lock.unlock();
+        return count > Config.clone_tablet_in_window_failed_limit_number;
+    }
+
+    public void clearCloneFailedWindow() {
+        lock.lock();
+        cloneFailedWindow.clear();
+        lock.unlock();

Review Comment:
   unlock should use in finally block of 'try {} finally {}';



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to