Browse Source

add success data expire

pull/251/head
yedf2 4 years ago
parent
commit
8cc5e95a01
  1. 3
      conf.sample.yml
  2. 5
      dtmsvr/config/config.go
  3. 10
      dtmsvr/storage/redis/redis.go

3
conf.sample.yml

@ -35,7 +35,8 @@
### flollowing config is only for some Driver
# DataExpire: 604800 # Trans data will expire in 7 days. only for redis/boltdb.
# RedisPrefix: '{}' # default value is '{}'. Redis storage prefix. store data to only one slot in cluster
# SuccessDataExpire: 86400 # successful Trans data will expire in 1 days. only for redis.
# RedisPrefix: '{a}' # default value is '{a}'. Redis storage prefix. store data to only one slot in cluster
# MicroService:
# Driver: 'dtm-driver-gozero' # name of the driver to handle register/discover

5
dtmsvr/config/config.go

@ -46,8 +46,9 @@ type Store struct {
MaxOpenConns int64 `yaml:"MaxOpenConns" default:"500"`
MaxIdleConns int64 `yaml:"MaxIdleConns" default:"500"`
ConnMaxLifeTime int64 `yaml:"ConnMaxLifeTime" default:"5"`
DataExpire int64 `yaml:"DataExpire" default:"604800"` // Trans data will expire in 7 days. only for redis/boltdb.
RedisPrefix string `yaml:"RedisPrefix" default:"{a}"` // Redis storage prefix. store data to only one slot in cluster
DataExpire int64 `yaml:"DataExpire" default:"604800"` // Trans data will expire in 7 days. only for redis/boltdb.
SuccessDataExpire int64 `yaml:"SuccessDataExpire" default:"86400"` // successful Trans data will expire in 1 days. only for redis.
RedisPrefix string `yaml:"RedisPrefix" default:"{a}"` // Redis storage prefix. store data to only one slot in cluster
TransGlobalTable string `yaml:"TransGlobalTable" default:"dtm.trans_global"`
TransBranchOpTable string `yaml:"TransBranchOpTable" default:"dtm.trans_branch_op"`
}

10
dtmsvr/storage/redis/redis.go

@ -99,8 +99,8 @@ func (s *Store) UpdateBranches(branches []storage.TransBranchStore, updates []st
}
type argList struct {
Keys []string
List []interface{}
Keys []string // 1 global trans, 2 branches, 3 indices, 4 status
List []interface{} // 1 redis prefix, 2 data expire
}
func newArgList() *argList {
@ -214,7 +214,8 @@ func (s *Store) ChangeGlobalStatus(global *storage.TransGlobalStore, newStatus s
AppendRaw(old).
AppendRaw(finished).
AppendRaw(global.Gid).
AppendRaw(newStatus)
AppendRaw(newStatus).
AppendObject(conf.Store.SuccessDataExpire)
_, err := callLua(args, `-- ChangeGlobalStatus
local old = redis.call('GET', KEYS[4])
if old ~= ARGV[4] then
@ -224,6 +225,9 @@ 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])
redis.call('EXPIRE', KEYS[1], ARGV[8])
redis.call('EXPIRE', KEYS[2], ARGV[8])
redis.call('EXPIRE', KEYS[4], ARGV[8])
end
`)
dtmimp.E2P(err)

Loading…
Cancel
Save