Skip to content

Commit

Permalink
add restore aof py test
Browse files Browse the repository at this point in the history
  • Loading branch information
bug-superman committed Oct 15, 2023
1 parent 8f221ce commit c5bac8b
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 103 deletions.
7 changes: 4 additions & 3 deletions cmd/redis-shake/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"RedisShake/internal/function"
"RedisShake/internal/log"
"RedisShake/internal/reader"
"RedisShake/internal/reader/aof_reader"
"RedisShake/internal/status"
"RedisShake/internal/utils"
"RedisShake/internal/writer"
Expand Down Expand Up @@ -60,14 +61,14 @@ func main() {
}
theReader = reader.NewRDBReader(opts)
log.Infof("create RdbReader: %v", opts.Filepath)
} else if v.IsSet("aof_reader") {
opts := new(reader.AOFReaderOptions)
} else if v.IsSet("aof_reader") {
opts := new(aof_reader.AOFReaderOptions)
defaults.SetDefaults(opts)
err := v.UnmarshalKey("aof_reader", opts)
if err != nil {
log.Panicf("failed to read the AOFReader config entry. err: %v", err)
}
theReader = reader.NewAOFReader(opts)
theReader = aof_reader.NewAOFReader(opts)
log.Infof("create AOFReader: %v", opts.Filepath)
} else {
log.Panicf("no reader config entry found")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package reader

import (
"RedisShake/internal/aof"
"os"
"RedisShake/internal/reader"
"path/filepath"

"RedisShake/internal/entry"
Expand Down Expand Up @@ -48,7 +48,7 @@ func (r *aofReader) StatusConsistent() bool {
return r.stat.AOFFileSentBytes == r.stat.AOFFileSizeBytes
}

func NewAOFReader(opts *AOFReaderOptions) Reader {
func NewAOFReader(opts *AOFReaderOptions) reader.Reader {
log.Infof("NewAOFReader: path=[%s]", opts.Filepath)
absolutePath, err := filepath.Abs(opts.Filepath)
if err != nil {
Expand Down Expand Up @@ -81,29 +81,19 @@ func (r *aofReader) StartRead() chan *entry.Entry {
manifestInfo := aofFileInfo.AOFManifest
if manifestInfo == nil { // load single aof file
log.Infof("start send single AOF path=[%s]", r.path)
fi, err := os.Stat(r.path)
if err != nil {
log.Panicf("NewAOFReader: os.Stat error:%s", err.Error())
}
log.Infof("the file stat:%v", fi)
aofLoader := aof.NewLoader(r.path, r.ch)
ret := aofLoader.LoadSingleAppendOnlyFile(r.stat.AOFTimestamp)
if ret == AOFOK || ret == AOFTruncated {
if ret == AOFOk || ret == AOFTruncated {
log.Infof("The AOF File was successfully loaded")
} else {
log.Infof("There was an error opening the AOF File.")
}
log.Infof("Send single AOF finished. path=[%s]", r.path)
close(r.ch)
} else {
log.Infof("start send multi-part AOF path=[%s]", r.path)
_, err := os.Stat(r.path)
if err != nil {
log.Panicf("NewAOFReader: os.Stat error:%s", err.Error())
}
aofLoader := NewAOFFileInfo(r.path, r.ch)
ret := aofLoader.LoadAppendOnlyFile(manifestInfo, r.ch, r.stat.AOFTimestamp, r.stat.FilterDangerousCommands)
if ret == AOFOK || ret == AOFTruncated {
if ret == AOFOk || ret == AOFTruncated {
log.Infof("The AOF File was successfully loaded")
} else {
log.Infof("There was an error opening the AOF File.")
Expand Down
Loading

0 comments on commit c5bac8b

Please sign in to comment.