rocketmq icon indicating copy to clipboard operation
rocketmq copied to clipboard

The TransactionMQProducer When check set state ROLLBACK_MESSAGE ,the execute should not COMMIT_MESSAGE again!

Open ZhangHLong opened this issue 5 years ago • 5 comments

When I execute this code,I can see the halfmq on RocketMQ-Console,actually,the check was priority set ‘LocalTransactionState.ROLLBACK_MESSAGE’ ,then the executeLocalTransaction back ‘LocalTransactionState.COMMIT_MESSAGE’。Strictly speaking,this mq message was rollback, but was not the case!!

`public static void main(String[] args) throws MQClientException { String topic = "topic_test"; TransactionMQProducer producer = new TransactionMQProducer("test_group"); producer.setNamesrvAddr("localhost:9876"); producer.setTransactionListener(new TransactionListener() { @Override public LocalTransactionState executeLocalTransaction(Message msg, Object arg) { System.out.println(" execute local trans: begin "); doSomeThing(65); System.out.println(" execute local trans: over "); return LocalTransactionState.COMMIT_MESSAGE; }

        @Override
        public LocalTransactionState checkLocalTransaction(MessageExt msg) {
            System.out.println(" check: begin ");
            doSomeThing(30);
            System.out.println(" check: over ");
            return LocalTransactionState.ROLLBACK_MESSAGE;
        }

        private void doSomeThing(long second) {
            try {
                TimeUnit.SECONDS.sleep(second);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    });
    producer.start();

    try {
        String msgbody = "mq-half-message";
        Message message = new Message(topic, msgbody.getBytes());
        message.setKeys("mq-key");
        TransactionSendResult send = producer.sendMessageInTransaction(message, null);
        System.out.println(send);
    } catch (Exception e) {
        e.printStackTrace();
    }
}`

ZhangHLong avatar Feb 25 '21 07:02 ZhangHLong

image

ZhangHLong avatar Feb 25 '21 07:02 ZhangHLong

The transaction message review first executes executeLocalTransaction, then there is no commit, and then checkLocalTransaction will be executed all the time

panzhi33 avatar Feb 25 '21 09:02 panzhi33

The transaction message review first executes executeLocalTransaction, then there is no commit, and then checkLocalTransaction will be executed all the time

The half message was send ,when executes executeLocalTransaction blocked,the checkLocalTransaction begin to execute and set the half message would be rollback,how can executeLocalTransaction change the state? I can not understand it。

It's like a variable happens ABA problems;

ZhangHLong avatar Feb 26 '21 02:02 ZhangHLong

when the method executeLocalTransaction return COMMIT, method checkLocalTransaction will be not executed. when the method executeLocalTransaction return UNKNOW, method checkLocalTransaction will be executed until the result is returned。 when the method executeLocalTransaction blocking, from the perspective of Broker, the status of this Half status message is unknown. Therefore, the Broker will periodically ask the sender to check the Half status message and report its final status.

fengyiluo avatar Feb 26 '21 08:02 fengyiluo

The problem still exists

version:4.7.1 config:transientStorePoolEnable=false

DeerplayHub avatar Jul 29 '22 03:07 DeerplayHub

This issue is stale because it has been open for 365 days with no activity. It will be closed in 3 days if no further activity occurs.

github-actions[bot] avatar Jul 30 '23 00:07 github-actions[bot]

This issue was closed because it has been inactive for 3 days since being marked as stale.

github-actions[bot] avatar Aug 03 '23 00:08 github-actions[bot]