Browse Source

update sync optimized

pull/55/head
yedf2 4 years ago
parent
commit
cc3725d94a
  1. 3
      dtmsvr/trans_class.go
  2. 2
      dtmsvr/trans_status.go
  3. 3
      dtmsvr/trans_type_saga.go

3
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

2
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

3
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

Loading…
Cancel
Save