XiaoFeiASK commented on code in PR #1125:
URL:
https://github.com/apache/incubator-seata-go/pull/1125#discussion_r3522892071
##########
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:
ok,已补充相关测试。另外可以确认 TC 的 branchReport 会更新
applicationData,第二阶段会回传最新值,因此不会出现二阶段拿到旧数据的问题。
--
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]