CalvinKirs commented on code in PR #39015:
URL: https://github.com/apache/doris/pull/39015#discussion_r1706874335


##########
fe/fe-core/src/main/java/org/apache/doris/common/lock/AbstractMonitoredLock.java:
##########
@@ -0,0 +1,104 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.common.lock;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract base class for a monitored lock that tracks lock acquisition,
+ * release, and attempt times. It provides mechanisms for monitoring the
+ * duration for which a lock is held and logging any instances where locks
+ * are held longer than a specified timeout or fail to be acquired within
+ * a specified timeout.
+ */
+public abstract class AbstractMonitoredLock {
+    protected static final long HOLD_TIMEOUT = 5000; // Lock hold timeout in 
milliseconds
+    private static final Logger LOG = 
LoggerFactory.getLogger(AbstractMonitoredLock.class);
+
+    // Thread-local variable to store the lock start time
+    private final ThreadLocal<Long> lockStartTime = new ThreadLocal<>();
+
+
+    /**
+     * Method to be called after successfully acquiring the lock.
+     * Sets the start time for the lock.
+     */
+    protected void afterLock() {
+        lockStartTime.set(System.nanoTime());
+    }
+
+    /**
+     * Method to be called after releasing the lock.
+     * Calculates the lock hold time and logs a warning if it exceeds the hold 
timeout.
+     */
+    protected void afterUnlock() {
+        Long startTime = lockStartTime.get();
+        if (startTime != null) {
+            long lockHoldTimeNanos = System.nanoTime() - startTime;
+            long lockHoldTimeMs = lockHoldTimeNanos >> 20;
+            Thread currentThread = Thread.currentThread();

Review Comment:
   done



##########
fe/fe-core/src/main/java/org/apache/doris/common/lock/AbstractMonitoredLock.java:
##########
@@ -0,0 +1,104 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.common.lock;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Abstract base class for a monitored lock that tracks lock acquisition,
+ * release, and attempt times. It provides mechanisms for monitoring the
+ * duration for which a lock is held and logging any instances where locks
+ * are held longer than a specified timeout or fail to be acquired within
+ * a specified timeout.
+ */
+public abstract class AbstractMonitoredLock {
+    protected static final long HOLD_TIMEOUT = 5000; // Lock hold timeout in 
milliseconds

Review Comment:
   done



-- 
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