supports twemproxy

v4
vinllen 5 years ago
parent 185b8a832e
commit 71f7d7c506
  1. 3
      conf/redis-shake.conf
  2. 20
      src/redis-shake/configure/configure.go
  3. 29
      src/redis-shake/main/main.go

@ -98,6 +98,9 @@ target.tls_enable = false
# 如果是decode或者dump,这个参数表示输出的rdb前缀,比如输入有3个db,那么dump分别是: # 如果是decode或者dump,这个参数表示输出的rdb前缀,比如输入有3个db,那么dump分别是:
# ${output_rdb}.0, ${output_rdb}.1, ${output_rdb}.2 # ${output_rdb}.0, ${output_rdb}.1, ${output_rdb}.2
target.rdb.output = local_dump target.rdb.output = local_dump
# some redis proxy like twemproxy doesn't support to fetch version, so please set it here.
# e.g., target.version = 4.0
target.version =
# use for expire key, set the time gap when source and target timestamp are not the same. # use for expire key, set the time gap when source and target timestamp are not the same.
# 用于处理过期的键值,当迁移两端不一致的时候,目的端需要加上这个值 # 用于处理过期的键值,当迁移两端不一致的时候,目的端需要加上这个值

@ -15,7 +15,6 @@ type Configuration struct {
SourceAddress string `config:"source.address"` SourceAddress string `config:"source.address"`
SourcePasswordRaw string `config:"source.password_raw"` SourcePasswordRaw string `config:"source.password_raw"`
SourcePasswordEncoding string `config:"source.password_encoding"` SourcePasswordEncoding string `config:"source.password_encoding"`
SourceVersion uint `config:"source.version"`
SourceAuthType string `config:"source.auth_type"` SourceAuthType string `config:"source.auth_type"`
SourceTLSEnable bool `config:"source.tls_enable"` SourceTLSEnable bool `config:"source.tls_enable"`
SourceRdbInput []string `config:"source.rdb.input"` SourceRdbInput []string `config:"source.rdb.input"`
@ -24,12 +23,12 @@ type Configuration struct {
TargetAddress string `config:"target.address"` TargetAddress string `config:"target.address"`
TargetPasswordRaw string `config:"target.password_raw"` TargetPasswordRaw string `config:"target.password_raw"`
TargetPasswordEncoding string `config:"target.password_encoding"` TargetPasswordEncoding string `config:"target.password_encoding"`
TargetVersion uint `config:"target.version"`
TargetDBString string `config:"target.db"` TargetDBString string `config:"target.db"`
TargetAuthType string `config:"target.auth_type"` TargetAuthType string `config:"target.auth_type"`
TargetType string `config:"target.type"` TargetType string `config:"target.type"`
TargetTLSEnable bool `config:"target.tls_enable"` TargetTLSEnable bool `config:"target.tls_enable"`
TargetRdbOutput string `config:"target.rdb.output"` TargetRdbOutput string `config:"target.rdb.output"`
TargetVersion string `config:"target.version"`
FakeTime string `config:"fake_time"` FakeTime string `config:"fake_time"`
Rewrite bool `config:"rewrite"` Rewrite bool `config:"rewrite"`
FilterDBWhitelist []string `config:"filter.db.whitelist"` FilterDBWhitelist []string `config:"filter.db.whitelist"`
@ -67,15 +66,14 @@ type Configuration struct {
/*---------------------------------------------------------*/ /*---------------------------------------------------------*/
// generated variables // generated variables
SourceAddressList []string // source address list SourceAddressList []string // source address list
TargetAddressList []string // target address list TargetAddressList []string // target address list
HeartbeatIp string // heartbeat ip HeartbeatIp string // heartbeat ip
ShiftTime time.Duration // shift ShiftTime time.Duration // shift
TargetRedisVersion string // to_redis_version TargetReplace bool // to_replace
TargetReplace bool // to_replace TargetDB int // int type
TargetDB int // int type Version string // version
Version string // version Type string // input mode -type=xxx
Type string // input mode -type=xxx
} }
var Options Configuration var Options Configuration

@ -409,21 +409,24 @@ func sanitizeOptions(tp string) error {
} }
if tp == conf.TypeRestore || tp == conf.TypeSync || tp == conf.TypeRump { if tp == conf.TypeRestore || tp == conf.TypeSync || tp == conf.TypeRump {
// get target redis version and set TargetReplace. if conf.Options.TargetVersion == "" {
for _, address := range conf.Options.TargetAddressList { // get target redis version and set TargetReplace.
// single connection even if the target is cluster for _, address := range conf.Options.TargetAddressList {
if v, err := utils.GetRedisVersion(address, conf.Options.TargetAuthType, // single connection even if the target is cluster
conf.Options.TargetPasswordRaw, conf.Options.TargetTLSEnable); err != nil { if v, err := utils.GetRedisVersion(address, conf.Options.TargetAuthType,
return fmt.Errorf("get target redis version failed[%v]", err) conf.Options.TargetPasswordRaw, conf.Options.TargetTLSEnable); err != nil {
} else if conf.Options.TargetRedisVersion != "" && conf.Options.TargetRedisVersion != v { return fmt.Errorf("get target redis version failed[%v]", err)
return fmt.Errorf("target redis version is different: [%v %v]", conf.Options.TargetRedisVersion, v) } else if conf.Options.TargetVersion != "" && conf.Options.TargetVersion != v {
} else { return fmt.Errorf("target redis version is different: [%v %v]", conf.Options.TargetVersion, v)
conf.Options.TargetRedisVersion = v } else {
conf.Options.TargetVersion = v
}
} }
} }
if strings.HasPrefix(conf.Options.TargetRedisVersion, "4.") ||
strings.HasPrefix(conf.Options.TargetRedisVersion, "3.") || if strings.HasPrefix(conf.Options.TargetVersion, "4.") ||
strings.HasPrefix(conf.Options.TargetRedisVersion, "5.") { strings.HasPrefix(conf.Options.TargetVersion, "3.") ||
strings.HasPrefix(conf.Options.TargetVersion, "5.") {
conf.Options.TargetReplace = true conf.Options.TargetReplace = true
} else { } else {
conf.Options.TargetReplace = false conf.Options.TargetReplace = false

Loading…
Cancel
Save