bxfjb opened a new issue, #9791:
URL: https://github.com/apache/rocketmq/issues/9791

   ### Before Creating the Bug Report
   
   - [x] I found a bug, not just asking a question, which should be created in 
[GitHub Discussions](https://github.com/apache/rocketmq/discussions).
   
   - [x] I have searched the [GitHub 
Issues](https://github.com/apache/rocketmq/issues) and [GitHub 
Discussions](https://github.com/apache/rocketmq/discussions)  of this 
repository and believe that this is not a duplicate.
   
   - [x] I have confirmed that this bug belongs to the current repository, not 
other repositories of RocketMQ.
   
   
   ### Runtime platform environment
   
   any
   
   ### RocketMQ version
   
   develop
   
   ### JDK Version
   
   any
   
   ### Describe the Bug
   
   Theoretically producers that belongs to the same producer group should have 
the same behavior, but rocketmq didn't define this constraint in code, which 
means users could run several producers that pub messages to different topics 
in only one producer group.
   In transaction message check process, broker would select a active producer 
channel and send check request to get local transaction state, by calling 
`getAvailableChannel`. As shown, the selection may not differentiate producers, 
for broker think they are the same, even though there is no such mechanism to 
guarantee this.
   The above description may lead to the following results: users may misuse 
producer group, and the check state request may be sent to the wrong producer, 
and get wrong result, which happened in our production.
   ```
   private final ConcurrentMap<String /* group name */, ConcurrentMap<Channel, 
ClientChannelInfo>> groupChannelTable =
           new ConcurrentHashMap<>();
   ...
   public Channel getAvailableChannel(String groupId) {
           if (groupId == null) {
               return null;
           }
           List<Channel> channelList;
           ConcurrentMap<Channel, ClientChannelInfo> 
channelClientChannelInfoHashMap = groupChannelTable.get(groupId);
           if (channelClientChannelInfoHashMap != null) {
               channelList = new 
ArrayList<>(channelClientChannelInfoHashMap.keySet());
           } else {
               log.warn("Check transaction failed, channel table is empty. 
groupId={}", groupId);
               return null;
           }
   
           int size = channelList.size();
           if (0 == size) {
               log.warn("Channel list is empty. groupId={}", groupId);
               return null;
           }
   
           Channel lastActiveChannel = null;
   
           int index = positiveAtomicCounter.incrementAndGet() % size;
           Channel channel = channelList.get(index);
           int count = 0;
           boolean isOk = channel.isActive() && channel.isWritable();
           while (count++ < GET_AVAILABLE_CHANNEL_RETRY_COUNT) {
               if (isOk) {
                   return channel;
               }
               if (channel.isActive()) {
                   lastActiveChannel = channel;
               }
               index = (++index) % size;
               channel = channelList.get(index);
               isOk = channel.isActive() && channel.isWritable();
           }
   
           return lastActiveChannel;
       }
   ```
   
   ### Steps to Reproduce
   
   Run multiple producers, produce some trans msgs to different topics.
   
   ### What Did You Expect to See?
   
   Trans msgs should get committed/rollbacked correctly.
   
   ### What Did You See Instead?
   
   Trans msgs may be committed/rollbacked wrongly.
   
   ### Additional Context
   
   Solution is not clear for now, maybe we can build a lineage mechanism to 
connect producers with topics?


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to