diff --git a/dtmsvr/trans_class.go b/dtmsvr/trans_class.go index 02f08da..77d1843 100644 --- a/dtmsvr/trans_class.go +++ b/dtmsvr/trans_class.go @@ -33,7 +33,8 @@ type TransGlobal struct { NextCronInterval int64 NextCronTime *time.Time dtmimp.TransOptions - lastTouched time.Time // record the start time of process + lastTouched time.Time // record the start time of process + updateBranchSync bool } // TableName TableName diff --git a/dtmsvr/trans_status.go b/dtmsvr/trans_status.go index dcee6b1..188c260 100644 --- a/dtmsvr/trans_status.go +++ b/dtmsvr/trans_status.go @@ -40,7 +40,7 @@ func (t *TransGlobal) changeStatus(db *common.DB, status string) *gorm.DB { } func (t *TransGlobal) changeBranchStatus(db *common.DB, b *TransBranch, status string) { - if common.DtmConfig.UpdateBranchSync > 0 || t.TransType == "saga" && t.TimeoutToFail > 0 { + if common.DtmConfig.UpdateBranchSync > 0 || t.updateBranchSync { err := db.Transaction(func(tx *gorm.DB) error { dbr := tx.Clauses(clause.Locking{Strength: "UPDATE"}).Model(&TransGlobal{}).Where("gid=? and status=?", t.Gid, t.Status).Find(&[]TransGlobal{}) checkAffected(dbr) // check TransGlobal is not modified diff --git a/dtmsvr/trans_type_saga.go b/dtmsvr/trans_type_saga.go index 3760a89..46ed6d3 100644 --- a/dtmsvr/trans_type_saga.go +++ b/dtmsvr/trans_type_saga.go @@ -59,6 +59,9 @@ func (t *transSagaProcessor) ProcessOnce(db *common.DB, branches []TransBranch) if t.CustomData != "" { dtmimp.MustUnmarshalString(t.CustomData, &csc) } + if csc.Concurrent || t.TimeoutToFail > 0 { // when saga is not normal, update branch sync + t.updateBranchSync = true + } // resultStats var rsAToStart, rsAStarted, rsADone, rsAFailed, rsASucceed, rsCToStart, rsCDone, rsCSucceed int branchResults := make([]branchResult, n) // save the branch result