Browse Source
Merge pull request #63 from wuqinqiang/wuqq/fix-update-time
fix:to change update_time
pull/67/head
yedf2
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
5 additions and
3 deletions
-
dtmsvr/dtmsvr.go
-
dtmsvr/trans_status.go
|
|
|
@ -84,7 +84,7 @@ func updateBranchAsync() { |
|
|
|
for len(updates) > 0 { |
|
|
|
dbr := dbGet().Clauses(clause.OnConflict{ |
|
|
|
OnConstraint: "trans_branch_op_pkey", |
|
|
|
DoUpdates: clause.AssignmentColumns([]string{"status", "finish_time"}), |
|
|
|
DoUpdates: clause.AssignmentColumns([]string{"status", "finish_time","update_time"}), |
|
|
|
}).Create(updates) |
|
|
|
dtmimp.Logf("flushed %d branch status to db. affected: %d", len(updates), dbr.RowsAffected) |
|
|
|
if dbr.Error != nil { |
|
|
|
|
|
|
|
@ -46,20 +46,22 @@ func (t *TransGlobal) changeStatus(db *common.DB, status string) *gorm.DB { |
|
|
|
} |
|
|
|
|
|
|
|
func (t *TransGlobal) changeBranchStatus(db *common.DB, b *TransBranch, status string) { |
|
|
|
now := time.Now() |
|
|
|
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
|
|
|
|
dbr = tx.Model(b).Updates(map[string]interface{}{ |
|
|
|
"status": status, |
|
|
|
"finish_time": time.Now(), |
|
|
|
"finish_time": now, |
|
|
|
"update_time": now, |
|
|
|
}) |
|
|
|
checkAffected(dbr) |
|
|
|
return dbr.Error |
|
|
|
}) |
|
|
|
e2p(err) |
|
|
|
} else { // 为了性能优化,把branch的status更新异步化
|
|
|
|
updateBranchAsyncChan <- branchStatus{id: b.ID, status: status} |
|
|
|
updateBranchAsyncChan <- branchStatus{id: b.ID, status: status, finishTime: &now} |
|
|
|
} |
|
|
|
b.Status = status |
|
|
|
} |
|
|
|
|