You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/04/07 01:41:38 UTC

[GitHub] [rocketmq] lwclover commented on a diff in pull request #4113: [ISSUE #4112]Fix the usage of `lockInterruptibly` in `ProcessQueue` and `RouteInfoManager`【修复`lock.lockInterruptibly()` 使用不当导致的异常准确性和bug】

lwclover commented on code in PR #4113:
URL: https://github.com/apache/rocketmq/pull/4113#discussion_r844563390


##########
client/src/main/java/org/apache/rocketmq/client/impl/consumer/ProcessQueue.java:
##########
@@ -404,30 +404,33 @@ public void incTryUnlockTimes() {
     public void fillProcessQueueInfo(final ProcessQueueInfo info) {
         try {
             this.treeMapLock.readLock().lockInterruptibly();
+            try {
+                if (!this.msgTreeMap.isEmpty()) {
+                    info.setCachedMsgMinOffset(this.msgTreeMap.firstKey());
+                    info.setCachedMsgMaxOffset(this.msgTreeMap.lastKey());
+                    info.setCachedMsgCount(this.msgTreeMap.size());
+                    info.setCachedMsgSizeInMiB((int) (this.msgSize.get() / (1024 * 1024)));
+                }
 
-            if (!this.msgTreeMap.isEmpty()) {
-                info.setCachedMsgMinOffset(this.msgTreeMap.firstKey());
-                info.setCachedMsgMaxOffset(this.msgTreeMap.lastKey());
-                info.setCachedMsgCount(this.msgTreeMap.size());
-                info.setCachedMsgSizeInMiB((int) (this.msgSize.get() / (1024 * 1024)));
-            }
-
-            if (!this.consumingMsgOrderlyTreeMap.isEmpty()) {
-                info.setTransactionMsgMinOffset(this.consumingMsgOrderlyTreeMap.firstKey());
-                info.setTransactionMsgMaxOffset(this.consumingMsgOrderlyTreeMap.lastKey());
-                info.setTransactionMsgCount(this.consumingMsgOrderlyTreeMap.size());
-            }
+                if (!this.consumingMsgOrderlyTreeMap.isEmpty()) {
+                    info.setTransactionMsgMinOffset(this.consumingMsgOrderlyTreeMap.firstKey());
+                    info.setTransactionMsgMaxOffset(this.consumingMsgOrderlyTreeMap.lastKey());
+                    info.setTransactionMsgCount(this.consumingMsgOrderlyTreeMap.size());
+                }
 
-            info.setLocked(this.locked);
-            info.setTryUnlockTimes(this.tryUnlockTimes.get());
-            info.setLastLockTimestamp(this.lastLockTimestamp);
+                info.setLocked(this.locked);
+                info.setTryUnlockTimes(this.tryUnlockTimes.get());
+                info.setLastLockTimestamp(this.lastLockTimestamp);
 
-            info.setDroped(this.dropped);
-            info.setLastPullTimestamp(this.lastPullTimestamp);
-            info.setLastConsumeTimestamp(this.lastConsumeTimestamp);
-        } catch (Exception e) {
-        } finally {
-            this.treeMapLock.readLock().unlock();
+                info.setDroped(this.dropped);
+                info.setLastPullTimestamp(this.lastPullTimestamp);
+                info.setLastConsumeTimestamp(this.lastConsumeTimestamp);
+            } catch (Exception e) {

Review Comment:
   I think the line ‘catch (Exception e) ’should be removed



-- 
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: dev-unsubscribe@rocketmq.apache.org

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