From 321ef28c8caec325b4e0656ccf9f8ba087acb7f1 Mon Sep 17 00:00:00 2001 From: Rennbon <343688972@qq.com> Date: Wed, 9 Mar 2022 20:50:18 +0800 Subject: [PATCH] refact: rm StatsFailed func --- dtmsvr/storage/boltdb/boltdb.go | 16 ---------------- dtmsvr/storage/redis/redis.go | 26 -------------------------- dtmsvr/storage/sql/sql.go | 11 ----------- dtmsvr/storage/store.go | 1 - dtmsvr/storage/trans.go | 2 +- dtmsvr/trans_status.go | 3 ++- 6 files changed, 3 insertions(+), 56 deletions(-) diff --git a/dtmsvr/storage/boltdb/boltdb.go b/dtmsvr/storage/boltdb/boltdb.go index 8d1cb36..83d234c 100644 --- a/dtmsvr/storage/boltdb/boltdb.go +++ b/dtmsvr/storage/boltdb/boltdb.go @@ -11,7 +11,6 @@ import ( "strings" "time" - "github.com/dtm-labs/dtm/dtmcli" "github.com/dtm-labs/dtm/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmcli/logger" "github.com/dtm-labs/dtm/dtmsvr/storage" @@ -364,21 +363,6 @@ func (s *Store) ChangeGlobalStatus(global *storage.TransGlobalStore, newStatus s dtmimp.E2P(err) } -// StatusFailed change global trans status to failed with reason -func (s *Store) StatusFailed(global *storage.TransGlobalStore, updates []string) { - old := global.Status - global.Status = dtmcli.StatusFailed - err := s.boltDb.Update(func(t *bolt.Tx) error { - g := tGetGlobal(t, global.Gid) - if g == nil || g.Status != old { - return storage.ErrNotFound - } - tPutGlobal(t, global) - return nil - }) - dtmimp.E2P(err) -} - // TouchCronTime updates cronTime func (s *Store) TouchCronTime(global *storage.TransGlobalStore, nextCronInterval int64, nextCronTime *time.Time) { oldUnix := global.NextCronTime.Unix() diff --git a/dtmsvr/storage/redis/redis.go b/dtmsvr/storage/redis/redis.go index f3e08de..d2cca87 100644 --- a/dtmsvr/storage/redis/redis.go +++ b/dtmsvr/storage/redis/redis.go @@ -9,7 +9,6 @@ import ( "github.com/go-redis/redis/v8" - "github.com/dtm-labs/dtm/dtmcli" "github.com/dtm-labs/dtm/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmcli/logger" "github.com/dtm-labs/dtm/dtmsvr/config" @@ -232,31 +231,6 @@ end dtmimp.E2P(err) } -// StatusFailed change global trans status to failed with reason -func (s *Store) StatusFailed(global *storage.TransGlobalStore, updates []string) { - old := global.Status - global.Status = dtmcli.StatusFailed - args := newArgList(). - AppendGid(global.Gid). - AppendObject(global). - AppendRaw(old). - AppendRaw(false). - AppendRaw(global.Gid). - AppendRaw(dtmcli.StatusFailed) - _, err := callLua(args, `-- ChangeGlobalStatus -local old = redis.call('GET', KEYS[4]) -if old ~= ARGV[4] then - return 'NOT_FOUND' -end -redis.call('SET', KEYS[1], ARGV[3], 'EX', ARGV[2]) -redis.call('SET', KEYS[4], ARGV[7], 'EX', ARGV[2]) -if ARGV[5] == '1' then - redis.call('ZREM', KEYS[3], ARGV[6]) -end -`) - dtmimp.E2P(err) -} - // LockOneGlobalTrans finds GlobalTrans func (s *Store) LockOneGlobalTrans(expireIn time.Duration) *storage.TransGlobalStore { expired := time.Now().Add(expireIn).Unix() diff --git a/dtmsvr/storage/sql/sql.go b/dtmsvr/storage/sql/sql.go index 0f10255..fa8bcdd 100644 --- a/dtmsvr/storage/sql/sql.go +++ b/dtmsvr/storage/sql/sql.go @@ -11,7 +11,6 @@ import ( "math" "time" - "github.com/dtm-labs/dtm/dtmcli" "github.com/dtm-labs/dtm/dtmcli/dtmimp" "github.com/dtm-labs/dtm/dtmsvr/config" "github.com/dtm-labs/dtm/dtmsvr/storage" @@ -128,16 +127,6 @@ func (s *Store) ChangeGlobalStatus(global *storage.TransGlobalStore, newStatus s } } -// StatusFailed change global trans status to failed with reason -func (s *Store) StatusFailed(global *storage.TransGlobalStore, updates []string) { - old := global.Status - global.Status = dtmcli.StatusFailed - dbr := dbGet().Must().Model(global).Where("status=? and gid=?", old, global.Gid).Select(updates).Updates(global) - if dbr.RowsAffected == 0 { - dtmimp.E2P(storage.ErrNotFound) - } -} - // TouchCronTime updates cronTime func (s *Store) TouchCronTime(global *storage.TransGlobalStore, nextCronInterval int64, nextCronTime *time.Time) { global.UpdateTime = dtmutil.GetNextTime(0) diff --git a/dtmsvr/storage/store.go b/dtmsvr/storage/store.go index 8a6c62a..391c4dd 100644 --- a/dtmsvr/storage/store.go +++ b/dtmsvr/storage/store.go @@ -28,7 +28,6 @@ type Store interface { LockGlobalSaveBranches(gid string, status string, branches []TransBranchStore, branchStart int) MaySaveNewTrans(global *TransGlobalStore, branches []TransBranchStore) error ChangeGlobalStatus(global *TransGlobalStore, newStatus string, updates []string, finished bool) - StatusFailed(global *TransGlobalStore, updates []string) TouchCronTime(global *TransGlobalStore, nextCronInterval int64, nextCronTime *time.Time) LockOneGlobalTrans(expireIn time.Duration) *TransGlobalStore ResetCronTime(timeout time.Duration, limit int64) (succeedCount int64, hasRemaining bool, err error) diff --git a/dtmsvr/storage/trans.go b/dtmsvr/storage/trans.go index b535065..07a06ba 100644 --- a/dtmsvr/storage/trans.go +++ b/dtmsvr/storage/trans.go @@ -40,7 +40,7 @@ type TransGlobalStore struct { Owner string `json:"owner,omitempty"` Ext TransGlobalExt `json:"-" gorm:"-"` ForceStopReason string `json:"force_stop_reason,omitempty" gorm:"-"` // only for request - ExtData string `json:"ext_data,omitempty"` // storage of ext. a db field to store many values. like Options + ExtData string `json:"ext_data,omitempty"` // storage of ext. a db field to store many values. like Options dtmcli.TransOptions } diff --git a/dtmsvr/trans_status.go b/dtmsvr/trans_status.go index 41ca28a..8952d17 100644 --- a/dtmsvr/trans_status.go +++ b/dtmsvr/trans_status.go @@ -77,8 +77,9 @@ func (t *TransGlobal) statusFailed(extData string) { now := time.Now() t.UpdateTime = &now t.ExtData = extData - GetStore().StatusFailed(&t.TransGlobalStore, updates) + GetStore().ChangeGlobalStatus(&t.TransGlobalStore, dtmcli.StatusFailed, updates, false) logger.Infof("StatusFailed to %s ok for %s", dtmcli.StatusFailed, t.TransGlobalStore.String()) + t.Status = dtmcli.StatusFailed } func (t *TransGlobal) changeBranchStatus(b *TransBranch, status string, branchPos int) {