delete single command failed when filter key given

v4
vinllen 6 years ago
parent 16a96112ef
commit dd790a47d0
  1. 2
      ChangeLog
  2. 9
      src/redis-shake/command/redis-command.go
  3. 2
      src/redis-shake/main/main.go
  4. 17
      src/redis-shake/sync.go

@ -1,7 +1,7 @@
2019-06-07 Alibaba Cloud. 2019-06-07 Alibaba Cloud.
* VERSION: 1.6.6 * VERSION: 1.6.6
* cherry-pick merge v1.4.4 * cherry-pick merge v1.4.4
* * BUGFIX: delete single command failed when filter key given.
2019-06-06 Alibaba Cloud. 2019-06-06 Alibaba Cloud.
* VERSION: 1.6.5 * VERSION: 1.6.5
* IMPROVE: run rump in parallel to support several db nodes behind proxy. * IMPROVE: run rump in parallel to support several db nodes behind proxy.

@ -17,7 +17,7 @@ var RedisCommands = map[string]redisCommand{
"setex": {nil, 1, 1, 1}, "setex": {nil, 1, 1, 1},
"psetex": {nil, 1, 1, 1}, "psetex": {nil, 1, 1, 1},
"append": {nil, 1, 1, 1}, "append": {nil, 1, 1, 1},
"del": {nil, 1, -1, 1}, "del": {nil, 1, 0, 1},
"unlink": {nil, 1, -1, 1}, "unlink": {nil, 1, -1, 1},
"setbit": {nil, 1, 1, 1}, "setbit": {nil, 1, 1, 1},
"bitfield": {nil, 1, 1, 1}, "bitfield": {nil, 1, 1, 1},
@ -86,7 +86,7 @@ var RedisCommands = map[string]redisCommand{
"pfmerge": {nil, 1, -1, 1}, "pfmerge": {nil, 1, -1, 1},
} }
func GetMatchKeys(redis_cmd redisCommand, args [][]byte, filterkeys []string) (new_args [][]byte, ret bool) { func GetMatchKeys(redis_cmd redisCommand, args [][]byte, filterkeys []string) (new_args [][]byte, pass bool) {
lastkey := redis_cmd.lastkey - 1 lastkey := redis_cmd.lastkey - 1
keystep := redis_cmd.keystep keystep := redis_cmd.keystep
@ -107,10 +107,10 @@ func GetMatchKeys(redis_cmd redisCommand, args [][]byte, filterkeys []string) (n
} }
} }
ret = false pass = false
new_args = make([][]byte, number*redis_cmd.keystep+len(args)-lastkey-redis_cmd.keystep) new_args = make([][]byte, number*redis_cmd.keystep+len(args)-lastkey-redis_cmd.keystep)
if number > 0 { if number > 0 {
ret = true pass = true
for i := 0; i < number; i++ { for i := 0; i < number; i++ {
for j := 0; j < redis_cmd.keystep; j++ { for j := 0; j < redis_cmd.keystep; j++ {
new_args[i*redis_cmd.keystep+j] = args[array[i]+j] new_args[i*redis_cmd.keystep+j] = args[array[i]+j]
@ -124,5 +124,6 @@ func GetMatchKeys(redis_cmd redisCommand, args [][]byte, filterkeys []string) (n
new_args[number*redis_cmd.keystep+j] = args[i] new_args[number*redis_cmd.keystep+j] = args[i]
j = j + 1 j = j + 1
} }
return return
} }

@ -374,7 +374,7 @@ func sanitizeOptions(tp string) error {
conf.Options.SenderDelayChannelSize = 32 conf.Options.SenderDelayChannelSize = 32
} }
if tp == TypeRestore || tp == TypeSync { if tp == conf.TypeRestore || tp == conf.TypeSync || tp == conf.TypeRump {
// get target redis version and set TargetReplace. // get target redis version and set TargetReplace.
for _, address := range conf.Options.TargetAddressList { for _, address := range conf.Options.TargetAddressList {
// single connection even if the target is cluster // single connection even if the target is cluster

@ -531,7 +531,7 @@ func (ds *dbSyncer) syncCommand(reader *bufio.Reader, target []string, auth_type
id := recvId.Get() // receive id id := recvId.Get() // receive id
// print debug log of receive reply // print debug log of receive reply
log.Debugf("receive reply[%v]: [%v], error: [%v]", id, reply, err) log.Debugf("receive reply-id[%v]: [%v], error:[%v]", id, reply, err)
if conf.Options.Metric == false { if conf.Options.Metric == false {
continue continue
@ -623,25 +623,28 @@ func (ds *dbSyncer) syncCommand(reader *bufio.Reader, target []string, auth_type
ds.nbypass.Incr() ds.nbypass.Incr()
// ds.SyncStat.BypassCmdCount.Incr() // ds.SyncStat.BypassCmdCount.Incr()
metric.GetMetric(ds.id).AddBypassCmdCount(1) metric.GetMetric(ds.id).AddBypassCmdCount(1)
log.Debugf("dbSyncer[%v] ignore command[%v]", ds.id, scmd)
continue continue
} }
} }
is_filter := false pass := false
if len(conf.Options.FilterKey) != 0 { if len(conf.Options.FilterKey) != 0 {
ds, ok := command.RedisCommands[scmd] cmdNode, ok := command.RedisCommands[scmd]
if ok && len(argv) > 0 { if ok && len(argv) > 0 {
new_argv, is_filter = command.GetMatchKeys(ds, argv, conf.Options.FilterKey) log.Debugf("dbSyncer[%v] filter command[%v]", ds.id, scmd)
new_argv, pass = command.GetMatchKeys(cmdNode, argv, conf.Options.FilterKey)
} else { } else {
is_filter = true pass = true
new_argv = argv new_argv = argv
} }
} else { } else {
is_filter = true pass = true
new_argv = argv new_argv = argv
} }
if bypass || ignorecmd || !is_filter { if bypass || ignorecmd || !pass {
ds.nbypass.Incr() ds.nbypass.Incr()
log.Debugf("dbSyncer[%v] filter command[%v]", ds.id, scmd)
continue continue
} }
} }

Loading…
Cancel
Save