add rdb checksum check

v4
vinllen 5 years ago
parent 2b1ece6662
commit efef7e13ae
  1. 16
      src/redis-shake/common/utils.go
  2. 22
      src/redis-shake/main/main.go

@ -923,6 +923,22 @@ func GetRedisVersion(target, authType, auth string, tlsEnable bool) (string, err
} }
} }
func GetRDBChecksum(target, authType, auth string, tlsEnable bool) (string, error) {
c := OpenRedisConn([]string{target}, authType, auth, false, tlsEnable)
defer c.Close()
content, err := c.Do("config", "get", "rdbchecksum")
if err != nil {
return "", err
}
conentList := content.([]interface{})
if len(conentList) != 2 {
return "", fmt.Errorf("return length != 2, return: %v", conentList)
}
return string(conentList[1].([]byte)), nil
}
func CheckHandleNetError(err error) bool { func CheckHandleNetError(err error) bool {
if err == io.EOF { if err == io.EOF {
return true return true

@ -434,6 +434,8 @@ func sanitizeOptions(tp string) error {
* set 1 if target is target version can't be fetched just like twemproxy. * set 1 if target is target version can't be fetched just like twemproxy.
*/ */
conf.Options.BigKeyThreshold = 1 conf.Options.BigKeyThreshold = 1
log.Warnf("target version[%v] given, set big_key_threshold = 1. see #173",
conf.Options.TargetVersion, conf.Options.SourceVersion)
} }
if strings.HasPrefix(conf.Options.TargetVersion, "4.") || if strings.HasPrefix(conf.Options.TargetVersion, "4.") ||
@ -463,6 +465,8 @@ func sanitizeOptions(tp string) error {
// compare version. see github issue #173. // compare version. see github issue #173.
if ret := utils.CompareVersion(conf.Options.SourceVersion, conf.Options.TargetVersion, 2); ret != 0 && ret != 1 { if ret := utils.CompareVersion(conf.Options.SourceVersion, conf.Options.TargetVersion, 2); ret != 0 && ret != 1 {
// target version is smaller than source version, or unknown // target version is smaller than source version, or unknown
log.Warnf("target version[%v] < source version[%v], set big_key_threshold = 1. see #173",
conf.Options.TargetVersion, conf.Options.SourceVersion)
conf.Options.BigKeyThreshold = 1 conf.Options.BigKeyThreshold = 1
} }
} }
@ -492,6 +496,24 @@ func sanitizeOptions(tp string) error {
//} //}
} }
// check rdbchecksum
if tp == conf.TypeDump || (tp == conf.TypeSync || tp == conf.TypeRump) && conf.Options.BigKeyThreshold > 1 {
for _, address := range conf.Options.SourceAddressList {
check, err := utils.GetRDBChecksum(address, conf.Options.SourceAuthType,
conf.Options.SourcePasswordRaw, conf.Options.SourceTLSEnable)
if err != nil {
// ignore
log.Warnf("fetch source rdb[%v] checksum failed[%v], ignore", address, err)
continue
}
log.Infof("source rdb[%v] checksum[%v]", address, check)
if check == "no" {
return fmt.Errorf("source rdb[%v] checksum should be open[config set rdbchecksum yes]", address)
}
}
}
return nil return nil
} }

Loading…
Cancel
Save