AlexStocks commented on code in PR #1054: URL: https://github.com/apache/incubator-seata-go/pull/1054#discussion_r2990636009
########## pkg/integration/rocketmq/transaction_listener.go: ########## @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package rocketmq + +import ( + "fmt" + + "github.com/apache/rocketmq-client-go/v2/primitive" + + "seata.apache.org/seata-go/v2/pkg/constant" + "seata.apache.org/seata-go/v2/pkg/protocol/message" + "seata.apache.org/seata-go/v2/pkg/remoting/getty" + "seata.apache.org/seata-go/v2/pkg/util/log" +) + +type SeataTransactionListener struct { + producer *SeataMQProducer +} + +func NewSeataTransactionListener(producer *SeataMQProducer) *SeataTransactionListener { + return &SeataTransactionListener{producer: producer} +} + +func (l *SeataTransactionListener) ExecuteLocalTransaction(msg *primitive.Message) primitive.LocalTransactionState { + xid := msg.GetProperty(constant.PropertySeataXID) + if xid == "" { + return primitive.CommitMessageState + } + log.Debugf("[SeataTransactionListener] ExecuteLocalTransaction, xid=%s, returning UnknownState", xid) + return primitive.UnknowState +} + +func (l *SeataTransactionListener) CheckLocalTransaction(msgExt *primitive.MessageExt) primitive.LocalTransactionState { + xid := msgExt.GetProperty(constant.PropertySeataXID) + if xid == "" { + log.Warnf("[SeataTransactionListener] CheckLocalTransaction: missing XID, rollback") + return primitive.RollbackMessageState + } + + branchIdStr := msgExt.GetProperty(constant.PropertySeataBranchId) + log.Infof("[SeataTransactionListener] CheckLocalTransaction, xid=%s, branchId=%s", xid, branchIdStr) + + globalStatus, err := l.queryGlobalStatus(xid) + if err != nil { + log.Errorf("[SeataTransactionListener] Query global status failed, xid=%s, err=%v", xid, err) + return primitive.UnknowState + } + + switch globalStatus { Review Comment: [P1] 这块是新 feature 的核心完成路径,但当前新增测试只覆盖了 `ParseTCCResource/GetActionName` 这种静态元数据,完全没有覆盖 `CheckLocalTransaction()` 对 `Committed/Rollbacked/Begin/...` 的状态映射,也没有覆盖 `queryGlobalStatus()` 的异常分支。回查状态一旦映射错,消息就会被错误提交或回滚,风险不低。建议至少补一组 listener 单测,把主要全局状态和请求失败分支都跑一遍。 -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
