From e5b71c6ea4785750dbdaab6076a1bb665ee912be Mon Sep 17 00:00:00 2001 From: wangyiyang Date: Thu, 28 Mar 2019 17:57:13 +0800 Subject: [PATCH 01/10] fix log path bug --- src/redis-shake/main/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/redis-shake/main/main.go b/src/redis-shake/main/main.go index 373584f..6231db1 100644 --- a/src/redis-shake/main/main.go +++ b/src/redis-shake/main/main.go @@ -204,7 +204,7 @@ func sanitizeOptions(tp string) error { } if conf.Options.LogFile != "" { - conf.Options.LogFile = fmt.Sprintf("%s.log", conf.Options.Id) + conf.Options.LogFile = fmt.Sprintf("%s%s.log", conf.Options.LogFile, conf.Options.Id) utils.LogRotater = &logRotate.Logger{ Filename: conf.Options.LogFile, From f5ce2a09d190cf8bedcd878cde69795eacd486cf Mon Sep 17 00:00:00 2001 From: wangyiyang Date: Thu, 28 Mar 2019 18:04:42 +0800 Subject: [PATCH 02/10] fix log path bug --- src/redis-shake/main/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/redis-shake/main/main.go b/src/redis-shake/main/main.go index 6231db1..b556938 100644 --- a/src/redis-shake/main/main.go +++ b/src/redis-shake/main/main.go @@ -204,7 +204,7 @@ func sanitizeOptions(tp string) error { } if conf.Options.LogFile != "" { - conf.Options.LogFile = fmt.Sprintf("%s%s.log", conf.Options.LogFile, conf.Options.Id) + //conf.Options.LogFile = fmt.Sprintf("%s.log", conf.Options.Id) utils.LogRotater = &logRotate.Logger{ Filename: conf.Options.LogFile, From e582bdf9c8ba4448a9b1bdaab69a0e08a60d9c43 Mon Sep 17 00:00:00 2001 From: wangyiyang Date: Fri, 29 Mar 2019 17:47:16 +0800 Subject: [PATCH 03/10] add pid path --- conf/redis-shake.conf | 4 +++- src/redis-shake/common/mix.go | 9 ++++++-- src/redis-shake/configure/configure.go | 1 + src/redis-shake/main/main.go | 32 +++++++++++++------------- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/conf/redis-shake.conf b/conf/redis-shake.conf index fff9078..5d51c18 100644 --- a/conf/redis-shake.conf +++ b/conf/redis-shake.conf @@ -2,8 +2,10 @@ # id id = redis-shake -# log file,日志文件,不配置将打印到stdout +# log file,日志文件,不配置将打印到stdout (e.g. /var/log/redis-shake.log ) log_file = +# pid path,进程文件存储地址,不配置将输出到项目目录下 (e.g. /var/run/ ) +pid_path = # pprof port system_profile = 9310 diff --git a/src/redis-shake/common/mix.go b/src/redis-shake/common/mix.go index 3945d14..1ad3de8 100644 --- a/src/redis-shake/common/mix.go +++ b/src/redis-shake/common/mix.go @@ -22,8 +22,13 @@ func WritePid(id string) (err error) { return nil } -func WritePidById(id string) error { - dir, _ := os.Getwd() +func WritePidById(id string, path string) error { + var dir string + if path == "" { + dir, _ = os.Getwd() + } else { + dir = path + } pidfile := filepath.Join(dir, id) + ".pid" if err := WritePid(pidfile); err != nil { return err diff --git a/src/redis-shake/configure/configure.go b/src/redis-shake/configure/configure.go index 44437ad..bff85bb 100644 --- a/src/redis-shake/configure/configure.go +++ b/src/redis-shake/configure/configure.go @@ -40,6 +40,7 @@ type Configuration struct { SenderCount uint `config:"sender.count"` SenderDelayChannelSize uint `config:"sender.delay_channel_size"` KeepAlive uint `config:"keep_alive"` + PidPath string `config:"pid_path"` // inner variables ReplaceHashTag bool `config:"replace_hash_tag"` diff --git a/src/redis-shake/main/main.go b/src/redis-shake/main/main.go index b556938..26dce4b 100644 --- a/src/redis-shake/main/main.go +++ b/src/redis-shake/main/main.go @@ -5,36 +5,36 @@ package main import ( + "encoding/json" "flag" "fmt" + "math" + _ "net/http/pprof" "os" "os/signal" - "syscall" - "runtime/debug" - "time" + "reflect" "runtime" - "math" - _ "net/http/pprof" - "strings" + "runtime/debug" "strconv" - "encoding/json" - "reflect" + "strings" + "syscall" + "time" + "pkg/libs/log" + "redis-shake" + "redis-shake/base" "redis-shake/common" "redis-shake/configure" "redis-shake/metric" - "redis-shake" - "redis-shake/base" "redis-shake/restful" - "pkg/libs/log" "github.com/gugemichael/nimo4go" logRotate "gopkg.in/natefinch/lumberjack.v2" ) -type Exit struct {Code int} +type Exit struct{ Code int } -const( +const ( TypeDecode = "decode" TypeRestore = "restore" TypeDump = "dump" @@ -83,7 +83,7 @@ func main() { utils.Welcome() utils.StartTime = fmt.Sprintf("%v", time.Now().Format(utils.GolangSecurityTime)) - if err = utils.WritePidById(conf.Options.Id); err != nil { + if err = utils.WritePidById(conf.Options.Id, conf.Options.PidPath); err != nil { crash(fmt.Sprintf("write pid failed. %v", err), -5) } @@ -240,7 +240,7 @@ func sanitizeOptions(tp string) error { if n, err := strconv.ParseInt(conf.Options.FakeTime[1:], 10, 64); err != nil { return fmt.Errorf("parse fake_time failed[%v]", err) } else { - conf.Options.ShiftTime = time.Duration(n * int64(time.Millisecond) - time.Now().UnixNano()) + conf.Options.ShiftTime = time.Duration(n*int64(time.Millisecond) - time.Now().UnixNano()) } default: if t, err := time.Parse("2006-01-02 15:04:05", conf.Options.FakeTime); err != nil { @@ -291,7 +291,7 @@ func sanitizeOptions(tp string) error { if tp == TypeRestore || tp == TypeSync { // get target redis version and set TargetReplace. if conf.Options.TargetRedisVersion, err = utils.GetRedisVersion(conf.Options.TargetAddress, - conf.Options.TargetAuthType, conf.Options.TargetPasswordRaw); err != nil { + conf.Options.TargetAuthType, conf.Options.TargetPasswordRaw); err != nil { return fmt.Errorf("get target redis version failed[%v]", err) } else { if strings.HasPrefix(conf.Options.TargetRedisVersion, "4.") || From 5a464aafbacc6414b14876a0bb6ca7942c5a4f96 Mon Sep 17 00:00:00 2001 From: Wang Yiyang Date: Mon, 1 Apr 2019 03:26:04 +0000 Subject: [PATCH 04/10] fix README.md errors --- README.md | 6 +++--- src/github.com/kardianos/govendor | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) create mode 160000 src/github.com/kardianos/govendor diff --git a/README.md b/README.md index dcf28c4..12d11f4 100644 --- a/README.md +++ b/README.md @@ -53,11 +53,11 @@ Add tag when releasing: "release-v{version}-{date}". for example: "release-v1.0. --- Run `./bin/redis-shake.darwin64` or `redis-shake.linux64` which is built in OSX and Linux respectively.
Or you can build redis-shake yourself according to the following steps: -* git clone https://github.com/aliyun/redis-shake.git -* cd redis-shake/src/vendor +* git clone https://github.com/alibaba/RedisShake.git +* cd RedisShake/src/vendor * GOPATH=\`pwd\`/../..; govendor sync #please note: must install govendor first and then pull all dependencies: `go get -u github.com/kardianos/govendor` * cd ../../ && ./build.sh -* ./bin/collector -type=$(type_must_be_sync_dump_restore_or_decode) -conf=conf/redis-shake.conf #please note: user must modify collector.conf first to match needs. +* ./bin/redis-shake -type=$(type_must_be_sync_dump_restore_or_decode) -conf=conf/redis-shake.conf #please note: user must modify collector.conf first to match needs. # Shake series tool --- diff --git a/src/github.com/kardianos/govendor b/src/github.com/kardianos/govendor new file mode 160000 index 0000000..e079574 --- /dev/null +++ b/src/github.com/kardianos/govendor @@ -0,0 +1 @@ +Subproject commit e07957427183a9892f35634ffc9ea48dedc6bbb4 From b556ac65434ba432192208ba824d97bcec08826f Mon Sep 17 00:00:00 2001 From: vinllen Date: Wed, 3 Apr 2019 11:53:53 +0800 Subject: [PATCH 05/10] set parallel to 1 when not set --- src/redis-shake/main/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/redis-shake/main/main.go b/src/redis-shake/main/main.go index 26dce4b..94c4c8d 100644 --- a/src/redis-shake/main/main.go +++ b/src/redis-shake/main/main.go @@ -172,7 +172,9 @@ func sanitizeOptions(tp string) error { runtime.GOMAXPROCS(conf.Options.NCpu) } - if conf.Options.Parallel == 0 || conf.Options.Parallel > 1024 { + if conf.Options.Parallel == 0 { + conf.Options.Parallel = 1 + } else if conf.Options.Parallel > 1024 { return fmt.Errorf("parallel[%v] should in (0, 1024]", conf.Options.Parallel) } else { conf.Options.Parallel = int(math.Max(float64(conf.Options.Parallel), float64(conf.Options.NCpu))) From 0b4d0effa6ddec9833ac270a919d1ee6c712d62c Mon Sep 17 00:00:00 2001 From: vinllen Date: Wed, 3 Apr 2019 13:47:53 +0800 Subject: [PATCH 06/10] modify code: enable heartbeat=0 --- src/redis-shake/main/main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/redis-shake/main/main.go b/src/redis-shake/main/main.go index 94c4c8d..5b77f38 100644 --- a/src/redis-shake/main/main.go +++ b/src/redis-shake/main/main.go @@ -172,7 +172,7 @@ func sanitizeOptions(tp string) error { runtime.GOMAXPROCS(conf.Options.NCpu) } - if conf.Options.Parallel == 0 { + if conf.Options.Parallel == 0 { // not set conf.Options.Parallel = 1 } else if conf.Options.Parallel > 1024 { return fmt.Errorf("parallel[%v] should in (0, 1024]", conf.Options.Parallel) @@ -217,9 +217,9 @@ func sanitizeOptions(tp string) error { log.StdLog = log.New(utils.LogRotater, "") } - // heartbeat - if conf.Options.HeartbeatInterval <= 0 || conf.Options.HeartbeatInterval > 86400 { - return fmt.Errorf("HeartbeatInterval[%v] should in (0, 86400]", conf.Options.HeartbeatInterval) + // heartbeat, 86400 = 1 day + if conf.Options.HeartbeatInterval > 86400 { + return fmt.Errorf("HeartbeatInterval[%v] should in [0, 86400]", conf.Options.HeartbeatInterval) } if conf.Options.HeartbeatNetworkInterface == "" { conf.Options.HeartbeatIp = "127.0.0.1" From 956cabe9181b9ee3ce8c6bee97dd068a1ee83e37 Mon Sep 17 00:00:00 2001 From: vinllen Date: Wed, 3 Apr 2019 13:57:14 +0800 Subject: [PATCH 07/10] add some default settings --- src/redis-shake/main/main.go | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/redis-shake/main/main.go b/src/redis-shake/main/main.go index 5b77f38..f725153 100644 --- a/src/redis-shake/main/main.go +++ b/src/redis-shake/main/main.go @@ -39,6 +39,11 @@ const ( TypeRestore = "restore" TypeDump = "dump" TypeSync = "sync" + + defaultHttpPort = 20881 + defaultSystemPort = 20882 + defaultSenderSize = 65535 + defaultSenderCount = 1024 ) func main() { @@ -275,19 +280,32 @@ func sanitizeOptions(tp string) error { // pass, >= 0 means enable } - if conf.Options.HttpProfile <= 0 || conf.Options.HttpProfile > 65535 { - return fmt.Errorf("HttpProfile[%v] should in (0, 65535]", conf.Options.HttpProfile) + if conf.Options.HttpProfile < 0 || conf.Options.HttpProfile > 65535 { + return fmt.Errorf("HttpProfile[%v] should in [0, 65535]", conf.Options.HttpProfile) + } else if conf.Options.HttpProfile == 0 { + // set to default when not set + conf.Options.HttpProfile = defaultHttpPort } - if conf.Options.SystemProfile <= 0 || conf.Options.SystemProfile > 65535 { - return fmt.Errorf("SystemProfile[%v] should in (0, 65535]", conf.Options.SystemProfile) + + if conf.Options.SystemProfile < 0 || conf.Options.SystemProfile > 65535 { + return fmt.Errorf("SystemProfile[%v] should in [0, 65535]", conf.Options.SystemProfile) + } else if conf.Options.SystemProfile == 0 { + // set to default when not set + conf.Options.SystemProfile = defaultSystemPort } - if conf.Options.SenderSize <= 0 || conf.Options.SenderSize >= 1073741824 { - return fmt.Errorf("SenderSize[%v] should in (0, 1073741824]", conf.Options.SenderSize) + if conf.Options.SenderSize < 0 || conf.Options.SenderSize >= 1073741824 { + return fmt.Errorf("SenderSize[%v] should in [0, 1073741824]", conf.Options.SenderSize) + } else if conf.Options.SenderSize == 0 { + // set to default when not set + conf.Options.SenderSize = defaultSenderSize } - if conf.Options.SenderCount <= 0 || conf.Options.SenderCount >= 100000 { - return fmt.Errorf("SenderCount[%v] should in (0, 100000]", conf.Options.SenderCount) + if conf.Options.SenderCount < 0 || conf.Options.SenderCount >= 100000 { + return fmt.Errorf("SenderCount[%v] should in [0, 100000]", conf.Options.SenderCount) + } else if conf.Options.SenderCount == 0 { + // set to default when not set + conf.Options.SenderCount = defaultSenderCount } if tp == TypeRestore || tp == TypeSync { From 8e6c2ac36f54af62d7ea8f794e83d1c072c5f2f3 Mon Sep 17 00:00:00 2001 From: vinllen Date: Wed, 3 Apr 2019 14:05:27 +0800 Subject: [PATCH 08/10] remove src/github.com/kardianos/govendor --- src/github.com/kardianos/govendor | 1 - 1 file changed, 1 deletion(-) delete mode 160000 src/github.com/kardianos/govendor diff --git a/src/github.com/kardianos/govendor b/src/github.com/kardianos/govendor deleted file mode 160000 index e079574..0000000 --- a/src/github.com/kardianos/govendor +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e07957427183a9892f35634ffc9ea48dedc6bbb4 From beb0f2a06d5d786b5e3ee085f514307ec482f9b7 Mon Sep 17 00:00:00 2001 From: vinllen Date: Wed, 3 Apr 2019 19:18:28 +0800 Subject: [PATCH 09/10] support 5.0 rdb RDB_OPCODE_MODULE_AUX, RDB_OPCODE_IDLE and RDB_OPCODE_FREQ type --- src/pkg/rdb/loader.go | 24 ++++++++++++++++++++++-- src/pkg/rdb/reader.go | 12 +++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/pkg/rdb/loader.go b/src/pkg/rdb/loader.go index 5f84ac9..7ca4faf 100644 --- a/src/pkg/rdb/loader.go +++ b/src/pkg/rdb/loader.go @@ -157,8 +157,28 @@ func (l *Loader) NextBinEntry() (*BinEntry, error) { l.db = dbnum case rdbFlagEOF: return nil, nil - case rdbFlagOnlyValue: - fallthrough + case rdbFlagModuleAux: + // currently, ignore this filed + _, err := l.ReadLength() // module-id + if err != nil { + return nil, err + } + // skip module + if err = rdbLoadCheckModuleValue(l); err != nil { + return nil, err + } + case rdbFlagIdle: + // ignore idle because target redis doesn't support this for given key + _, err := l.ReadLength() + if err != nil { + return nil, err + } + case rdbFlagFreq: + // ignore freq because target redis doesn't support this for given key + _, err := l.readUint8() + if err != nil { + return nil, err + } default: var key []byte if l.remainMember == 0 { diff --git a/src/pkg/rdb/reader.go b/src/pkg/rdb/reader.go index 068eb94..f9a5c5e 100644 --- a/src/pkg/rdb/reader.go +++ b/src/pkg/rdb/reader.go @@ -35,13 +35,23 @@ const ( RdbTypeQuicklist = 14 RDBTypeStreamListPacks = 15 // stream - rdbFlagOnlyValue = 0xf9 + rdbFlagModuleAux = 0xf7 + rdbFlagIdle = 0xf8 + rdbFlagFreq = 0xf9 RdbFlagAUX = 0xfa rdbFlagResizeDB = 0xfb rdbFlagExpiryMS = 0xfc rdbFlagExpiry = 0xfd rdbFlagSelectDB = 0xfe rdbFlagEOF = 0xff + + // Module serialized values sub opcodes + rdbModuleOpcodeEof = 0 + rdbModuleOpcodeSint = 1 + rdbModuleOpcodeUint = 2 + rdbModuleOpcodeFloat = 3 + rdbModuleOpcodeDouble = 4 + rdbModuleOpcodeString = 5 ) const ( From 9fa0f79cca319c0485dff85137c16e35ff4791d7 Mon Sep 17 00:00:00 2001 From: vinllen Date: Wed, 3 Apr 2019 19:20:33 +0800 Subject: [PATCH 10/10] add 1.2.2 --- ChangeLog | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog b/ChangeLog index 8073bc9..f6648d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2019-04-03 Alibaba Cloud. + * version: 1.2.2 + * BUGFIX: support 5.0 rdb RDB_OPCODE_MODULE_AUX, RDB_OPCODE_IDLE and + RDB_OPCODE_FREQ type. 2019-03-27 Alibaba Cloud. * version: 1.2.1 * IMPROVE: support syncing lua script in RDB syncing.