Merge pull request #24 from alibaba/bugfix-1.2.2

use restore to recovery key
v4
Vinllen Chen 6 years ago committed by GitHub
commit fa33b7f163
  1. 8
      src/pkg/rdb/loader.go
  2. 21
      src/redis-shake/common/utils.go

@ -63,6 +63,8 @@ type BinEntry struct {
ExpireAt uint64 ExpireAt uint64
RealMemberCount uint32 RealMemberCount uint32
NeedReadLen byte NeedReadLen byte
IdleTime uint32
Freq uint8
} }
func (e *BinEntry) ObjEntry() (*ObjEntry, error) { func (e *BinEntry) ObjEntry() (*ObjEntry, error) {
@ -169,16 +171,18 @@ func (l *Loader) NextBinEntry() (*BinEntry, error) {
} }
case rdbFlagIdle: case rdbFlagIdle:
// ignore idle because target redis doesn't support this for given key // ignore idle because target redis doesn't support this for given key
_, err := l.ReadLength() idle, err := l.ReadLength()
if err != nil { if err != nil {
return nil, err return nil, err
} }
entry.IdleTime = idle
case rdbFlagFreq: case rdbFlagFreq:
// ignore freq because target redis doesn't support this for given key // ignore freq because target redis doesn't support this for given key
_, err := l.readUint8() freq, err := l.readUint8()
if err != nil { if err != nil {
return nil, err return nil, err
} }
entry.Freq = freq
default: default:
var key []byte var key []byte
if l.remainMember == 0 { if l.remainMember == 0 {

@ -711,12 +711,22 @@ func RestoreRdbEntry(c redigo.Conn, e *rdb.BinEntry) {
return return
} }
// fmt.Printf("kkkey: %v, value: %v\n", string(e.Key), e.Value) params := []interface{}{e.Key, ttlms, e.Value}
s, err := redigo.String(c.Do("restore", e.Key, ttlms, e.Value)) if e.IdleTime != 0 {
params = append(params, "IDLETIME")
params = append(params, e.IdleTime)
}
if e.Freq != 0 {
params = append(params, "FREQ")
params = append(params, e.Freq)
}
// fmt.Printf("key: %v, value: %v params: %v\n", string(e.Key), e.Value, params)
s, err := redigo.String(c.Do("restore", params...))
if err != nil { if err != nil {
/*The reply value of busykey in 2.8 kernel is "target key name is busy", /*The reply value of busykey in 2.8 kernel is "target key name is busy",
but in 4.0 kernel is "BUSYKEY Target key name already exists"*/ but in 4.0 kernel is "BUSYKEY Target key name already exists"*/
if strings.Contains(err.Error(), "Target key name is busy") || strings.Contains(err.Error(), "BUSYKEY Target key name already exists") { if strings.Contains(err.Error(), "Target key name is busy") ||
strings.Contains(err.Error(), "BUSYKEY Target key name already exists") {
if conf.Options.Rewrite { if conf.Options.Rewrite {
if !conf.Options.Metric { if !conf.Options.Metric {
log.Infof("warning, rewrite key: %v", string(e.Key)) log.Infof("warning, rewrite key: %v", string(e.Key))
@ -724,10 +734,11 @@ func RestoreRdbEntry(c redigo.Conn, e *rdb.BinEntry) {
var s2 string var s2 string
var rerr error var rerr error
if conf.Options.TargetReplace { if conf.Options.TargetReplace {
s2, rerr = redigo.String(c.Do("restore", e.Key, ttlms, e.Value, "replace")) params = append(params, "REPLACE")
s2, rerr = redigo.String(c.Do("restore", params...))
} else { } else {
_, _ = redigo.String(c.Do("del", e.Key)) _, _ = redigo.String(c.Do("del", e.Key))
s2, rerr = redigo.String(c.Do("restore", e.Key, ttlms, e.Value)) s2, rerr = redigo.String(c.Do("restore", params...))
} }
if rerr != nil { if rerr != nil {
log.Info(s2, rerr, "key ", string(e.Key)) log.Info(s2, rerr, "key ", string(e.Key))

Loading…
Cancel
Save