diff --git a/conf.sample.yml b/conf.sample.yml index 673c9e9..ec3ec8b 100644 --- a/conf.sample.yml +++ b/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 diff --git a/dtmsvr/config/config.go b/dtmsvr/config/config.go index a72bea7..f64fa32 100644 --- a/dtmsvr/config/config.go +++ b/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"` } diff --git a/dtmsvr/storage/redis/redis.go b/dtmsvr/storage/redis/redis.go index 7e6bbfa..a894de7 100644 --- a/dtmsvr/storage/redis/redis.go +++ b/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)