From a5d596b67061aa3799688bf8e0684f6153661f1d Mon Sep 17 00:00:00 2001 From: vinllen Date: Mon, 22 Apr 2019 11:00:34 +0800 Subject: [PATCH 1/3] polish code --- 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 b2c6d4d..757fd7b 100644 --- a/src/redis-shake/main/main.go +++ b/src/redis-shake/main/main.go @@ -54,7 +54,7 @@ func main() { // argument options configuration := flag.String("conf", "", "configuration path") - tp := flag.String("type", "", "run type: decode, restore, dump, sync") + tp := flag.String("type", "", "run type: decode, restore, dump, sync, rump") version := flag.Bool("version", false, "show version") flag.Parse() From 4c242c88dec05f8b00a60abe6093c28c192e8874 Mon Sep 17 00:00:00 2001 From: vinllen Date: Mon, 22 Apr 2019 17:26:11 +0800 Subject: [PATCH 2/3] add debug log of sending and receiving command --- src/redis-shake/common/common.go | 6 ++++++ src/redis-shake/main/main.go | 10 +++++----- src/redis-shake/sync.go | 20 +++++++++++++++++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/redis-shake/common/common.go b/src/redis-shake/common/common.go index b0907cd..98f0794 100644 --- a/src/redis-shake/common/common.go +++ b/src/redis-shake/common/common.go @@ -15,6 +15,12 @@ const ( // GolangSecurityTime = "2006-01-02 15:04:05" ReaderBufferSize = bytesize.MB * 32 WriterBufferSize = bytesize.MB * 8 + + LogLevelNone = "none" + LogLevelError = "error" + LogLevelWarn = "warn" + LogLevelInfo = "info" + LogLevelAll = "all" ) var ( diff --git a/src/redis-shake/main/main.go b/src/redis-shake/main/main.go index 757fd7b..e206619 100644 --- a/src/redis-shake/main/main.go +++ b/src/redis-shake/main/main.go @@ -230,17 +230,17 @@ func sanitizeOptions(tp string) error { // set log level var logDeepLevel log.LogLevel switch conf.Options.LogLevel { - case "none": + case utils.LogLevelNone: logDeepLevel = log.LEVEL_NONE - case "error": + case utils.LogLevelError: logDeepLevel = log.LEVEL_ERROR - case "warn": + case utils.LogLevelWarn: logDeepLevel = log.LEVEL_WARN case "": fallthrough - case "info": + case utils.LogLevelInfo: logDeepLevel = log.LEVEL_INFO - case "all": + case utils.LogLevelAll: logDeepLevel = log.LEVEL_DEBUG default: return fmt.Errorf("invalid log level[%v]", conf.Options.LogLevel) diff --git a/src/redis-shake/sync.go b/src/redis-shake/sync.go index a91f0df..51b8cdf 100644 --- a/src/redis-shake/sync.go +++ b/src/redis-shake/sync.go @@ -361,6 +361,11 @@ func (cmd *CmdSync) SyncCommand(reader *bufio.Reader, target, auth_type, passwd var sendId, recvId atomic2.Int64 go func() { + if conf.Options.Psync == false { + log.Warn("GetFakeSlaveOffset not enable when psync == false") + return + } + srcConn := utils.OpenRedisConnWithTimeout(conf.Options.SourceAddress, conf.Options.SourceAuthType, conf.Options.SourcePasswordRaw, time.Duration(10)*time.Minute, time.Duration(10)*time.Minute) ticker := time.NewTicker(10 * time.Second) @@ -395,7 +400,11 @@ func (cmd *CmdSync) SyncCommand(reader *bufio.Reader, target, auth_type, passwd go func() { var node *delayNode for { - _, err := c.Receive() + reply, err := c.Receive() + + // print debug log of receive reply + log.Debugf("receive reply: [%v], error: [%v]", reply, err) + if conf.Options.Metric == false { continue } @@ -465,6 +474,15 @@ func (cmd *CmdSync) SyncCommand(reader *bufio.Reader, target, auth_type, passwd metric.MetricVar.AddPullCmdCount(1) if scmd != "ping" { + // print debug log of send command + if conf.Options.LogLevel == utils.LogLevelAll { + strArgv := make([]string, len(argv)) + for i, ele := range argv { + strArgv[i] = string(ele) + } + log.Debugf("send command: [%s %v]", scmd, strArgv) + } + if strings.EqualFold(scmd, "select") { if len(argv) != 1 { log.Panicf("select command len(args) = %d", len(argv)) From 600aff8e7c3aa8c7a1d844549b90cf67f1813aa1 Mon Sep 17 00:00:00 2001 From: vinllen Date: Mon, 22 Apr 2019 17:28:55 +0800 Subject: [PATCH 3/3] add debug log of sending and receiving command2 --- src/redis-shake/sync.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/redis-shake/sync.go b/src/redis-shake/sync.go index 51b8cdf..dab1e45 100644 --- a/src/redis-shake/sync.go +++ b/src/redis-shake/sync.go @@ -24,6 +24,7 @@ import ( "redis-shake/base" "redis-shake/heartbeat" "redis-shake/metric" + "unsafe" ) type delayNode struct { @@ -478,7 +479,7 @@ func (cmd *CmdSync) SyncCommand(reader *bufio.Reader, target, auth_type, passwd if conf.Options.LogLevel == utils.LogLevelAll { strArgv := make([]string, len(argv)) for i, ele := range argv { - strArgv[i] = string(ele) + strArgv[i] = *(*string)(unsafe.Pointer(&ele)) } log.Debugf("send command: [%s %v]", scmd, strArgv) }