Skip to content

Commit

Permalink
Added the function of directly reading incrAOF files and historyAOF f…
Browse files Browse the repository at this point in the history
…iles when there is no baseAOF file available.
  • Loading branch information
hwy1314 committed Oct 27, 2023
1 parent fbe2b13 commit 0da1584
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions internal/reader/parsing_aof.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func StringNeedsRepr(s string) int {

type INFO struct {
AOFDirName string
AOFUseRDBPreamble int // TODO:not support parsing rdb preamble
AOFManifest *AOFManifest
AOFFileName string
AOFCurrentSize int64
Expand All @@ -77,7 +76,6 @@ func (aofInfo *INFO) GetAOFDirName() string {
func NewAOFFileInfo(aofFilePath string, ch chan *entry.Entry) *INFO {
return &INFO{
AOFDirName: filepath.Dir(aofFilePath),
AOFUseRDBPreamble: 0,
AOFManifest: nil,
AOFFileName: filepath.Base(aofFilePath),
AOFCurrentSize: 0,
Expand Down Expand Up @@ -438,7 +436,6 @@ type AOFManifest struct {
HistoryList *list.List
CurrBaseFileSeq int64
CurrIncrFileSeq int64
Dirty int64
}

func AOFManifestCreate() *AOFManifest {
Expand Down Expand Up @@ -554,6 +551,17 @@ func GetBaseAndIncrAppendOnlyFilesNum(am *AOFManifest) int {
return num
}

func GetHistoryAndIncrAppendOnlyFilesNum(am *AOFManifest) int {
num := 0
if am.HistoryList != nil {
num += am.HistoryList.Len()
}
if am.incrAOFList != nil {
num += am.incrAOFList.Len()
}
return num
}

func (aofInfo *INFO) LoadAppendOnlyFile(am *AOFManifest, AOFTimeStamp int64) int {
if am == nil {
log.Panicf("AOFManifest is null")
Expand Down Expand Up @@ -613,6 +621,39 @@ func (aofInfo *INFO) LoadAppendOnlyFile(am *AOFManifest, AOFTimeStamp int64) int
}
}
totalNum--
} else {
totalNum = GetHistoryAndIncrAppendOnlyFilesNum(am)
log.Infof("The BaseAOF file does not exist. Start loading the HistoryAOF and IncrAOF files.")
if am.HistoryList.Len() > 0 {
for ln := am.HistoryList.Front(); ln != nil; ln = ln.Next() {
ai := ln.Value.(*AOFInfo)
if ai.AOFFileType != AOFManifestTypeHist {
log.Panicf("The manifestType must be Hist")
}
AOFName = ai.FileName
aofInfo.UpdateLoadingFileName(AOFName)
AOFNum++
start = Ustime()
ret = aofInfo.ParsingSingleAppendOnlyFile(AOFName, AOFTimeStamp)
if ret == AOFOk || (ret == AOFTruncated) {
log.Infof("DB loaded from History File %v: %.3f seconds", AOFName, float64(Ustime()-start)/1000000)
return ret
}
if ret == AOFEmpty {
ret = AOFOk
}
if ret == AOFOpenErr || ret == AOFFailed {
if ret == AOFOpenErr {
log.Panicf("There was an error opening the AOF File.")
} else {
log.Infof("Failed to open AOF File.")
}
return ret
}
totalNum--
}
}

}

if am.incrAOFList.Len() > 0 {
Expand Down

0 comments on commit 0da1584

Please sign in to comment.