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/07/26 08:43:19 UTC

[GitHub] [rocketmq] zhouxinyu commented on a diff in pull request #4687: [ISSUE #4686] Release lock and set interrupt flag

zhouxinyu commented on code in PR #4687:
URL: https://github.com/apache/rocketmq/pull/4687#discussion_r929690937


##########
namesrv/src/main/java/org/apache/rocketmq/namesrv/kvconfig/KVConfigManager.java:
##########
@@ -62,27 +62,27 @@ public void load() {
     public void putKVConfig(final String namespace, final String key, final String value) {
         try {
             this.lock.writeLock().lockInterruptibly();
-            try {
-                HashMap<String, String> kvTable = this.configTable.get(namespace);
-                if (null == kvTable) {
-                    kvTable = new HashMap<>();
-                    this.configTable.put(namespace, kvTable);
-                    log.info("putKVConfig create new Namespace {}", namespace);
-                }
+            HashMap<String, String> kvTable = this.configTable.get(namespace);
+            if (null == kvTable) {
+                kvTable = new HashMap<>();
+                this.configTable.put(namespace, kvTable);
+                log.info("putKVConfig create new Namespace {}", namespace);
+            }
 
-                final String prev = kvTable.put(key, value);
-                if (null != prev) {
-                    log.info("putKVConfig update config item, Namespace: {} Key: {} Value: {}",
-                        namespace, key, value);
-                } else {
-                    log.info("putKVConfig create new config item, Namespace: {} Key: {} Value: {}",
-                        namespace, key, value);
-                }
-            } finally {
-                this.lock.writeLock().unlock();
+            final String prev = kvTable.put(key, value);
+            if (null != prev) {
+                log.info("putKVConfig update config item, Namespace: {} Key: {} Value: {}",
+                    namespace, key, value);
+            } else {
+                log.info("putKVConfig create new config item, Namespace: {} Key: {} Value: {}",
+                    namespace, key, value);
             }
         } catch (InterruptedException e) {
             log.error("putKVConfig InterruptedException", e);
+            // set interrupt flag
+            Thread.currentThread().interrupt();
+        } finally {
+            this.lock.writeLock().unlock();

Review Comment:
   IllegalMonitorStateException will be thrown if lock failed?



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