Refactor shadow WAL to use segments

This commit is contained in:
Ben Johnson
2021-07-16 15:56:31 -06:00
parent fc897b481f
commit 6eb290720b
14 changed files with 1022 additions and 838 deletions

View File

@@ -408,11 +408,6 @@ func (itr *walSegmentIterator) Next() bool {
}
itr.infos = itr.infos[:0] // otherwise clear infos
// Move to the next index unless this is the first time initializing.
if itr.infos != nil && len(itr.indexes) > 0 {
itr.indexes = itr.indexes[1:]
}
// If no indexes remain, stop iteration.
if len(itr.indexes) == 0 {
return false
@@ -420,6 +415,7 @@ func (itr *walSegmentIterator) Next() bool {
// Read segments into a cache for the current index.
index := itr.indexes[0]
itr.indexes = itr.indexes[1:]
f, err := os.Open(filepath.Join(itr.dir, litestream.FormatIndex(index)))
if err != nil {
itr.err = err
@@ -452,6 +448,9 @@ func (itr *walSegmentIterator) Next() bool {
})
}
// Ensure segments are sorted within index.
sort.Sort(litestream.WALSegmentInfoSlice(itr.infos))
if len(itr.infos) > 0 {
return true
}