Browse Source

refact: rm StatsFailed func

pull/251/head
Rennbon 4 years ago
parent
commit
321ef28c8c
  1. 16
      dtmsvr/storage/boltdb/boltdb.go
  2. 26
      dtmsvr/storage/redis/redis.go
  3. 11
      dtmsvr/storage/sql/sql.go
  4. 1
      dtmsvr/storage/store.go
  5. 2
      dtmsvr/storage/trans.go
  6. 3
      dtmsvr/trans_status.go

16
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()

26
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()

11
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)

1
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)

2
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
}

3
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) {

Loading…
Cancel
Save