Merge pull request #20 from alibaba/bugfix-1.2.2

Bugfix 1.2.2
v4
Vinllen Chen 6 years ago committed by GitHub
commit 1a96a7e10c
  1. 4
      ChangeLog
  2. 6
      README.md
  3. 4
      conf/redis-shake.conf
  4. 24
      src/pkg/rdb/loader.go
  5. 12
      src/pkg/rdb/reader.go
  6. 9
      src/redis-shake/common/mix.go
  7. 1
      src/redis-shake/configure/configure.go
  8. 78
      src/redis-shake/main/main.go

@ -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. 2019-03-27 Alibaba Cloud.
* version: 1.2.1 * version: 1.2.1
* IMPROVE: support syncing lua script in RDB syncing. * IMPROVE: support syncing lua script in RDB syncing.

@ -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.<br> Run `./bin/redis-shake.darwin64` or `redis-shake.linux64` which is built in OSX and Linux respectively.<br>
Or you can build redis-shake yourself according to the following steps: Or you can build redis-shake yourself according to the following steps:
* git clone https://github.com/aliyun/redis-shake.git * git clone https://github.com/alibaba/RedisShake.git
* cd redis-shake/src/vendor * 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` * 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 * 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 # Shake series tool
--- ---

@ -2,8 +2,10 @@
# id # id
id = redis-shake id = redis-shake
# log file,日志文件,不配置将打印到stdout # log file,日志文件,不配置将打印到stdout (e.g. /var/log/redis-shake.log )
log_file = log_file =
# pid path,进程文件存储地址,不配置将输出到项目目录下 (e.g. /var/run/ )
pid_path =
# pprof port # pprof port
system_profile = 9310 system_profile = 9310

@ -157,8 +157,28 @@ func (l *Loader) NextBinEntry() (*BinEntry, error) {
l.db = dbnum l.db = dbnum
case rdbFlagEOF: case rdbFlagEOF:
return nil, nil return nil, nil
case rdbFlagOnlyValue: case rdbFlagModuleAux:
fallthrough // 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: default:
var key []byte var key []byte
if l.remainMember == 0 { if l.remainMember == 0 {

@ -35,13 +35,23 @@ const (
RdbTypeQuicklist = 14 RdbTypeQuicklist = 14
RDBTypeStreamListPacks = 15 // stream RDBTypeStreamListPacks = 15 // stream
rdbFlagOnlyValue = 0xf9 rdbFlagModuleAux = 0xf7
rdbFlagIdle = 0xf8
rdbFlagFreq = 0xf9
RdbFlagAUX = 0xfa RdbFlagAUX = 0xfa
rdbFlagResizeDB = 0xfb rdbFlagResizeDB = 0xfb
rdbFlagExpiryMS = 0xfc rdbFlagExpiryMS = 0xfc
rdbFlagExpiry = 0xfd rdbFlagExpiry = 0xfd
rdbFlagSelectDB = 0xfe rdbFlagSelectDB = 0xfe
rdbFlagEOF = 0xff rdbFlagEOF = 0xff
// Module serialized values sub opcodes
rdbModuleOpcodeEof = 0
rdbModuleOpcodeSint = 1
rdbModuleOpcodeUint = 2
rdbModuleOpcodeFloat = 3
rdbModuleOpcodeDouble = 4
rdbModuleOpcodeString = 5
) )
const ( const (

@ -22,8 +22,13 @@ func WritePid(id string) (err error) {
return nil return nil
} }
func WritePidById(id string) error { func WritePidById(id string, path string) error {
dir, _ := os.Getwd() var dir string
if path == "" {
dir, _ = os.Getwd()
} else {
dir = path
}
pidfile := filepath.Join(dir, id) + ".pid" pidfile := filepath.Join(dir, id) + ".pid"
if err := WritePid(pidfile); err != nil { if err := WritePid(pidfile); err != nil {
return err return err

@ -40,6 +40,7 @@ type Configuration struct {
SenderCount uint `config:"sender.count"` SenderCount uint `config:"sender.count"`
SenderDelayChannelSize uint `config:"sender.delay_channel_size"` SenderDelayChannelSize uint `config:"sender.delay_channel_size"`
KeepAlive uint `config:"keep_alive"` KeepAlive uint `config:"keep_alive"`
PidPath string `config:"pid_path"`
// inner variables // inner variables
ReplaceHashTag bool `config:"replace_hash_tag"` ReplaceHashTag bool `config:"replace_hash_tag"`

@ -5,40 +5,45 @@
package main package main
import ( import (
"encoding/json"
"flag" "flag"
"fmt" "fmt"
"math"
_ "net/http/pprof"
"os" "os"
"os/signal" "os/signal"
"syscall" "reflect"
"runtime/debug"
"time"
"runtime" "runtime"
"math" "runtime/debug"
_ "net/http/pprof"
"strings"
"strconv" "strconv"
"encoding/json" "strings"
"reflect" "syscall"
"time"
"pkg/libs/log"
"redis-shake"
"redis-shake/base"
"redis-shake/common" "redis-shake/common"
"redis-shake/configure" "redis-shake/configure"
"redis-shake/metric" "redis-shake/metric"
"redis-shake"
"redis-shake/base"
"redis-shake/restful" "redis-shake/restful"
"pkg/libs/log"
"github.com/gugemichael/nimo4go" "github.com/gugemichael/nimo4go"
logRotate "gopkg.in/natefinch/lumberjack.v2" logRotate "gopkg.in/natefinch/lumberjack.v2"
) )
type Exit struct {Code int} type Exit struct{ Code int }
const( const (
TypeDecode = "decode" TypeDecode = "decode"
TypeRestore = "restore" TypeRestore = "restore"
TypeDump = "dump" TypeDump = "dump"
TypeSync = "sync" TypeSync = "sync"
defaultHttpPort = 20881
defaultSystemPort = 20882
defaultSenderSize = 65535
defaultSenderCount = 1024
) )
func main() { func main() {
@ -83,7 +88,7 @@ func main() {
utils.Welcome() utils.Welcome()
utils.StartTime = fmt.Sprintf("%v", time.Now().Format(utils.GolangSecurityTime)) 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) crash(fmt.Sprintf("write pid failed. %v", err), -5)
} }
@ -172,7 +177,9 @@ func sanitizeOptions(tp string) error {
runtime.GOMAXPROCS(conf.Options.NCpu) runtime.GOMAXPROCS(conf.Options.NCpu)
} }
if conf.Options.Parallel == 0 || conf.Options.Parallel > 1024 { 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) return fmt.Errorf("parallel[%v] should in (0, 1024]", conf.Options.Parallel)
} else { } else {
conf.Options.Parallel = int(math.Max(float64(conf.Options.Parallel), float64(conf.Options.NCpu))) conf.Options.Parallel = int(math.Max(float64(conf.Options.Parallel), float64(conf.Options.NCpu)))
@ -204,7 +211,7 @@ func sanitizeOptions(tp string) error {
} }
if conf.Options.LogFile != "" { if conf.Options.LogFile != "" {
conf.Options.LogFile = fmt.Sprintf("%s.log", conf.Options.Id) //conf.Options.LogFile = fmt.Sprintf("%s.log", conf.Options.Id)
utils.LogRotater = &logRotate.Logger{ utils.LogRotater = &logRotate.Logger{
Filename: conf.Options.LogFile, Filename: conf.Options.LogFile,
@ -215,9 +222,9 @@ func sanitizeOptions(tp string) error {
log.StdLog = log.New(utils.LogRotater, "") log.StdLog = log.New(utils.LogRotater, "")
} }
// heartbeat // heartbeat, 86400 = 1 day
if conf.Options.HeartbeatInterval <= 0 || conf.Options.HeartbeatInterval > 86400 { if conf.Options.HeartbeatInterval > 86400 {
return fmt.Errorf("HeartbeatInterval[%v] should in (0, 86400]", conf.Options.HeartbeatInterval) return fmt.Errorf("HeartbeatInterval[%v] should in [0, 86400]", conf.Options.HeartbeatInterval)
} }
if conf.Options.HeartbeatNetworkInterface == "" { if conf.Options.HeartbeatNetworkInterface == "" {
conf.Options.HeartbeatIp = "127.0.0.1" conf.Options.HeartbeatIp = "127.0.0.1"
@ -240,7 +247,7 @@ func sanitizeOptions(tp string) error {
if n, err := strconv.ParseInt(conf.Options.FakeTime[1:], 10, 64); err != nil { if n, err := strconv.ParseInt(conf.Options.FakeTime[1:], 10, 64); err != nil {
return fmt.Errorf("parse fake_time failed[%v]", err) return fmt.Errorf("parse fake_time failed[%v]", err)
} else { } 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: default:
if t, err := time.Parse("2006-01-02 15:04:05", conf.Options.FakeTime); err != nil { if t, err := time.Parse("2006-01-02 15:04:05", conf.Options.FakeTime); err != nil {
@ -273,25 +280,38 @@ func sanitizeOptions(tp string) error {
// pass, >= 0 means enable // pass, >= 0 means enable
} }
if conf.Options.HttpProfile <= 0 || conf.Options.HttpProfile > 65535 { if conf.Options.HttpProfile < 0 || conf.Options.HttpProfile > 65535 {
return fmt.Errorf("HttpProfile[%v] should in (0, 65535]", conf.Options.HttpProfile) 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 { if conf.Options.SenderSize < 0 || conf.Options.SenderSize >= 1073741824 {
return fmt.Errorf("SenderSize[%v] should in (0, 1073741824]", conf.Options.SenderSize) 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 { if conf.Options.SenderCount < 0 || conf.Options.SenderCount >= 100000 {
return fmt.Errorf("SenderCount[%v] should in (0, 100000]", conf.Options.SenderCount) 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 { if tp == TypeRestore || tp == TypeSync {
// get target redis version and set TargetReplace. // get target redis version and set TargetReplace.
if conf.Options.TargetRedisVersion, err = utils.GetRedisVersion(conf.Options.TargetAddress, 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) return fmt.Errorf("get target redis version failed[%v]", err)
} else { } else {
if strings.HasPrefix(conf.Options.TargetRedisVersion, "4.") || if strings.HasPrefix(conf.Options.TargetRedisVersion, "4.") ||

Loading…
Cancel
Save