You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "sherlock-lin (via GitHub)" <gi...@apache.org> on 2023/05/29 13:50:42 UTC

[GitHub] [rocketmq] sherlock-lin opened a new pull request, #6832: 1. optimize registerProducer design

sherlock-lin opened a new pull request, #6832:
URL: https://github.com/apache/rocketmq/pull/6832

   <!-- Please make sure the target branch is right. In most case, the target branch should be `develop`. -->
   
   ### Which Issue(s) This PR Fixes
   
   <!-- Please ensure that the related issue has already been created, and [link this pull request to that issue using keywords](<https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword>) to ensure automatic closure. -->
   
   Fixes #issue_id
   
   ### Brief Description
   
   I try optimize ProducerManager registerProducer design and I think the previous code was redundant
   
   <!-- Write a brief description for your pull request to help the maintainer understand the reasons behind your changes. -->
   
   ### How Did You Test This Change?
   
   <!-- In order to ensure the code quality of Apache RocketMQ, we expect every pull request to have undergone thorough testing. -->
   
   I verify through unit testing
   
   ![image](https://github.com/apache/rocketmq/assets/19645523/6db3ee1c-570f-4cce-97c7-b951d477853d)
   
   


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

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


[GitHub] [rocketmq] sherlock-lin closed pull request #6832: 1. optimize registerProducer design

Posted by "sherlock-lin (via GitHub)" <gi...@apache.org>.
sherlock-lin closed pull request #6832: 1. optimize registerProducer design
URL: https://github.com/apache/rocketmq/pull/6832


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

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


[GitHub] [rocketmq] sherlock-lin commented on pull request #6832: 1. optimize registerProducer design

Posted by "sherlock-lin (via GitHub)" <gi...@apache.org>.
sherlock-lin commented on PR #6832:
URL: https://github.com/apache/rocketmq/pull/6832#issuecomment-1571221662

   > Hi @sherlock-lin Please link this PR to target ISSUE
   
   
   
   > Hi @sherlock-lin Please link this PR to target ISSUE
   
   


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

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


[GitHub] [rocketmq] sherlock-lin commented on a diff in pull request #6832: [ISSUE #6844] Optimize registerProducer design

Posted by "sherlock-lin (via GitHub)" <gi...@apache.org>.
sherlock-lin commented on code in PR #6832:
URL: https://github.com/apache/rocketmq/pull/6832#discussion_r1217529639


##########
broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java:
##########
@@ -161,24 +161,15 @@ public synchronized boolean doChannelCloseEvent(final String remoteAddr, final C
     }
 
     public synchronized void registerProducer(final String group, final ClientChannelInfo clientChannelInfo) {
-        ClientChannelInfo clientChannelInfoFound = null;
-
+        this.groupChannelTable.putIfAbsent(group, new ConcurrentHashMap<>());
         ConcurrentHashMap<Channel, ClientChannelInfo> channelTable = this.groupChannelTable.get(group);

Review Comment:
   I also tried this way, but this method returns null when the object is not found
   ![image](https://github.com/apache/rocketmq/assets/19645523/15e6ce3c-d42f-43e4-9fe0-95ca3114d1bf)
   



##########
broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java:
##########
@@ -161,24 +161,15 @@ public synchronized boolean doChannelCloseEvent(final String remoteAddr, final C
     }
 
     public synchronized void registerProducer(final String group, final ClientChannelInfo clientChannelInfo) {
-        ClientChannelInfo clientChannelInfoFound = null;
-
+        this.groupChannelTable.putIfAbsent(group, new ConcurrentHashMap<>());
         ConcurrentHashMap<Channel, ClientChannelInfo> channelTable = this.groupChannelTable.get(group);
-        if (null == channelTable) {
-            channelTable = new ConcurrentHashMap<>();
-            this.groupChannelTable.put(group, channelTable);
-        }
 
-        clientChannelInfoFound = channelTable.get(clientChannelInfo.getChannel());
+        ClientChannelInfo clientChannelInfoFound = channelTable.putIfAbsent(clientChannelInfo.getChannel(), clientChannelInfo);

Review Comment:
   Thanks, but here we need to update the timestamp when it exists and add it when it doesn't。So we can't use computeIfAbsent instead of if else



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

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


[GitHub] [rocketmq] drpmma commented on a diff in pull request #6832: [ISSUE #6844] Optimize registerProducer design

Posted by "drpmma (via GitHub)" <gi...@apache.org>.
drpmma commented on code in PR #6832:
URL: https://github.com/apache/rocketmq/pull/6832#discussion_r1217384716


##########
broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java:
##########
@@ -161,24 +161,15 @@ public synchronized boolean doChannelCloseEvent(final String remoteAddr, final C
     }
 
     public synchronized void registerProducer(final String group, final ClientChannelInfo clientChannelInfo) {
-        ClientChannelInfo clientChannelInfoFound = null;
-
+        this.groupChannelTable.putIfAbsent(group, new ConcurrentHashMap<>());
         ConcurrentHashMap<Channel, ClientChannelInfo> channelTable = this.groupChannelTable.get(group);
-        if (null == channelTable) {
-            channelTable = new ConcurrentHashMap<>();
-            this.groupChannelTable.put(group, channelTable);
-        }
 
-        clientChannelInfoFound = channelTable.get(clientChannelInfo.getChannel());
+        ClientChannelInfo clientChannelInfoFound = channelTable.putIfAbsent(clientChannelInfo.getChannel(), clientChannelInfo);

Review Comment:
   It's recommended to use computeIfAbsent rather than if else.



##########
broker/src/main/java/org/apache/rocketmq/broker/client/ProducerManager.java:
##########
@@ -161,24 +161,15 @@ public synchronized boolean doChannelCloseEvent(final String remoteAddr, final C
     }
 
     public synchronized void registerProducer(final String group, final ClientChannelInfo clientChannelInfo) {
-        ClientChannelInfo clientChannelInfoFound = null;
-
+        this.groupChannelTable.putIfAbsent(group, new ConcurrentHashMap<>());
         ConcurrentHashMap<Channel, ClientChannelInfo> channelTable = this.groupChannelTable.get(group);

Review Comment:
   Why not use the return value of putIfAbsent?



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

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


[GitHub] [rocketmq] sherlock-lin commented on pull request #6832: 1. optimize registerProducer design

Posted by "sherlock-lin (via GitHub)" <gi...@apache.org>.
sherlock-lin commented on PR #6832:
URL: https://github.com/apache/rocketmq/pull/6832#issuecomment-1571223416

   > Hi @sherlock-lin Please link this PR to target ISSUE
   
   Hi @mxsm I have linked  target ISSUE


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

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