Skip to content

Commit

Permalink
add feature about flush db before sync
Browse files Browse the repository at this point in the history
  • Loading branch information
jjz921024 authored and suxb201 committed Dec 21, 2023
1 parent 536d7da commit aa04746
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/redis-shake/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func main() {
// create status
status.Init(theReader, theWriter)

if config.Opt.Advanced.EmptyDBBeforeSync {
theWriter.Flush()
}

log.Infof("start syncing...")

ch := theReader.StartRead()
Expand Down
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type AdvancedOptions struct {
TargetRedisProtoMaxBulkLen uint64 `mapstructure:"target_redis_proto_max_bulk_len" default:"512000000"`

AwsPSync string `mapstructure:"aws_psync" default:""` // 10.0.0.1:6379@nmfu2sl5osync,10.0.0.1:6379@xhma21xfkssync

EmptyDBBeforeSync bool `mapstructure:"empty_db_before_sync" default:"false"`
}

type ModuleOptions struct {
Expand Down
1 change: 1 addition & 0 deletions internal/writer/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ import (
type Writer interface {
status.Statusable
Write(entry *entry.Entry)
Flush()
Close()
}
6 changes: 6 additions & 0 deletions internal/writer/redis_cluster_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ func NewRedisClusterWriter(opts *RedisWriterOptions) Writer {
return rw
}

func (r *RedisClusterWriter) Flush() {
for _, writer := range r.writers {
writer.Flush()
}
}

func (r *RedisClusterWriter) Close() {
for _, writer := range r.writers {
writer.Close()
Expand Down
7 changes: 7 additions & 0 deletions internal/writer/redis_standalone_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ func NewRedisStandaloneWriter(opts *RedisWriterOptions) Writer {
return rw
}

func (w *redisStandaloneWriter) Flush() {
reply := w.client.DoWithStringReply("FLUSHALL")
if reply != "OK" {
log.Panicf("flush failed with reply: %s", reply)
}
}

func (w *redisStandaloneWriter) Close() {
close(w.chWaitReply)
w.chWg.Wait()
Expand Down
6 changes: 6 additions & 0 deletions shake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ target_redis_proto_max_bulk_len = 512_000_000
# If the source is Elasticache or MemoryDB, you can set this item.
aws_psync = "" # example: aws_psync = "10.0.0.1:6379@nmfu2sl5osync,10.0.0.1:6379@xhma21xfkssync"

# destination will delete itself entire database before fetching files
# from source during full synchronization.
# This option is similar redis replicas RDB diskless load option:
# repl-diskless-load on-empty-db
empty_db_before_sync = false

[module]
# The data format for BF.LOADCHUNK is not compatible in different versions. v2.6.3 <=> 20603
target_mbbloom_version = 20603

0 comments on commit aa04746

Please sign in to comment.