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


##########
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();

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



##########
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();

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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to