AsperforMias commented on code in PR #1125:
URL: 
https://github.com/apache/incubator-seata-go/pull/1125#discussion_r3487738319


##########
pkg/rm/tcc/tcc_service.go:
##########
@@ -84,9 +85,47 @@ func (t *TCCServiceProxy) Prepare(ctx context.Context, 
params interface{}) (inte
                }
        }
 
-       // to set up the fence phase
        tm.SetFencePhase(ctx, enum.FencePhasePrepare)
-       return t.TCCResource.Prepare(ctx, params)
+       result, err := t.TCCResource.Prepare(ctx, params)
+       if err != nil {
+               return nil, err
+       }
+
+       bac := tm.GetBusinessActionContext(ctx)
+       if bac != nil && bac.IsDelayReport {
+               if err := t.reportActionContext(ctx, bac); err != nil {
+                       log.Warnf("[TCC] report action context failed after 
prepare, fallback to original branch applicationData (broker check-back may be 
used), xid=%s, branchId=%d, err=%v", bac.Xid, bac.BranchId, err)
+               }
+       }
+
+       return result, nil
+}
+
+func (t *TCCServiceProxy) reportActionContext(ctx context.Context, bac 
*tm.BusinessActionContext) error {
+       updatedActionContext := make(map[string]interface{})
+       for k, v := range bac.ActionContext {
+               updatedActionContext[k] = v
+       }
+       applicationData, err := json.Marshal(map[string]interface{}{
+               constant.ActionContext: updatedActionContext,
+       })
+       if err != nil {
+               log.Errorf("[TCC] marshal updated ActionContext failed, xid=%s, 
branchId=%d, err=%v", bac.Xid, bac.BranchId, err)
+               return fmt.Errorf("marshal updated ActionContext failed: %w", 
err)
+       }
+       err = rm.GetRMRemotingInstance().BranchReport(rm.BranchReportParam{

Review Comment:
   这里依赖 BranchReport 把更新后的 ActionContext 写回 TC。能确认 TC 会更新已注册分支的 applicationData 
吗?如果这里只是状态上报,那第二阶段拿到的还是旧 applicationData,主动 END_TRANSACTION 就会退回 
check-back。可以补个测试或者大概说明一下这个依赖



##########
pkg/integration/rocketmq/tcc_rocketmq_action.go:
##########
@@ -170,6 +170,15 @@ func (a *TCCRocketMQAction) buildEndTransactionHeader(bac 
*tm.BusinessActionCont
                }
        }
 
+       // fallback: if offsetMsgId is empty or failed to parse, try msgId 
(aligned with official client behaviour)
+       if commitLogOffset == 0 {

Review Comment:
   这里比之前好一些,但如果 offsetMsgId 和 msgId 都缺失或解析失败,commitLogOffset 还是会保持 0 并继续发送 
END_TRANSACTION。这个场景下可能应该直接跳过主动通知,走 check-back?否则到最后还是可能把无效 offset 发给 broker



-- 
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]

Reply via email to