说在前面
结束事务管理器
源码解析
往上返回到这个方法,发送最终消息成功删除准备事务提交消息,org.apache.rocketmq.broker.transaction.queue.TransactionalMessageServiceImpl#deletePrepareMessage
@Override
public boolean deletePrepareMessage(MessageExt msgExt) {
// =》
if (this.transactionalMessageBridge.putOpMessage(msgExt, TransactionalMessageUtil.REMOVETAG)) {
log.info("Transaction op message write successfully. messageId={}, queueId={} msgExt:{}", msgExt.getMsgId(), msgExt.getQueueId(), msgExt);
return true;
} else {
log.error("Transaction op message write failed. messageId is {}, queueId is {}", msgExt.getMsgId(), msgExt.getQueueId());
return false;
} }
进入这个方法,org.apache.rocketmq.broker.transaction.queue.TransactionalMessageBridge#putOpMessage
public boolean putOpMessage(MessageExt messageExt, String opType) {
MessageQueue messageQueue = new MessageQueue(messageExt.getTopic(),
this.brokerController.getBrokerConfig().getBrokerName(), messageExt.getQueueId());
if (TransactionalMessageUtil.REMOVETAG.equals(opType)) {
// 事务消息提交或回滚时添加删除标记=》
return addRemoveTagInTransactionOp(messageExt, messageQueue);
}
return true; }
进入这个方法,事务消息提交或回滚时添加删除标记,org.apache.rocketmq.broker.transaction.queue.TransactionalMessageBridge#addRemoveTagInTransactionOp
private boolean addRemoveTagInTransactionOp(MessageExt messageExt, MessageQueue messageQueue) {
Message message = new Message(TransactionalMessageUtil.buildOpTopic(), TransactionalMessageUtil.REMOVETAG,
String.valueOf(messageExt.getQueueOffset()).getBytes(TransactionalMessageUtil.charset));
writeOp(message, messageQueue);
return true; }
进入这个方法,org.apache.rocketmq.broker.transaction.queue.TransactionalMessageBridge#writeOp
private void writeOp(Message message, MessageQueue mq) {
MessageQueue opQueue;
if (opQueueMap.containsKey(mq)) {
opQueue = opQueueMap.get(mq);
} else {
opQueue = getOpQueueByHalf(mq);
MessageQueue oldQueue = opQueueMap.putIfAbsent(mq, opQueue);
if (oldQueue != null) {
opQueue = oldQueue;
}
}
if (opQueue == null) {
opQueue = new MessageQueue(TransactionalMessageUtil.buildOpTopic(), mq.getBrokerName(), mq.getQueueId());
}
// 存储消息
putMessage(makeOpMessageInner(message, opQueue)); }
进入这个方法,org.apache.rocketmq.broker.transaction.queue.TransactionalMessageBridge#putMessage前面介绍过了。
往上返回到这个方法,事务消息回滚,org.apache.rocketmq.broker.transaction.queue.TransactionalMessageServiceImpl#rollbackMessage
@Override
public OperationResult rollbackMessage(EndTransactionRequestHeader requestHeader) {
return getHalfMessageByOffset(requestHeader.getCommitLogOffset()); }
进入这个方法,org.apache.rocketmq.broker.transaction.queue.TransactionalMessageServiceImpl#getHalfMessageByOffset
private OperationResult getHalfMessageByOffset(long commitLogOffset) {
OperationResult response = new OperationResult();
// 根据offset查询消息=》
MessageExt messageExt = this.transactionalMessageBridge.lookMessageByOffset(commitLogOffset);
if (messageExt != null) {
response.setPrepareMessage(messageExt);
response.setResponseCode(ResponseCode.SUCCESS);
} else {
response.setResponseCode(ResponseCode.SYSTEM_ERROR);
response.setResponseRemark("Find prepared transaction message failed");
}
return response; }
进入这个方法,根据offset查询消息,org.apache.rocketmq.store.DefaultMessageStore#lookMessageByOffset(long)前面介绍过了。
往上返回到这个方法,事务消息回滚成功删除准备提交事务消息,org.apache.rocketmq.broker.transaction.queue.TransactionalMessageServiceImpl#deletePrepareMessage前面介绍过了。
往上返回到这个方法,org.apache.rocketmq.broker.processor.EndTransactionProcessor#processRequest结束。
说在最后
本次解析仅代表个人观点,仅供参考。
加入技术微信群
钉钉技术群