1
0
Fork 0

Merge pull request #1442 from rqlite/otoolep-cw-updates

Minor updates to WAL Compactor
master
Philip O'Toole 10 months ago committed by GitHub
commit 9f63b33377
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,15 +19,15 @@ type cFrame struct {
type cFrames []*cFrame type cFrames []*cFrame
// make cFrames sortable by offset.
func (c cFrames) Len() int { return len(c) } func (c cFrames) Len() int { return len(c) }
func (c cFrames) Less(i, j int) bool { return c[uint32(i)].Offset < c[uint32(j)].Offset } func (c cFrames) Less(i, j int) bool { return c[uint32(i)].Offset < c[uint32(j)].Offset }
func (c cFrames) Swap(i, j int) { c[uint32(i)], c[uint32(j)] = c[uint32(j)], c[uint32(i)] } func (c cFrames) Swap(i, j int) { c[uint32(i)], c[uint32(j)] = c[uint32(j)], c[uint32(i)] }
// CompactingWALScanner implements WALIterator to iterate over frames in a WAL file. // CompactingScanner implements WALIterator to iterate over frames in a WAL file.
// It also compacts the WAL file, with Next() returning the last frame for each page. // It also compacts the WAL file, with Next() returning the last valid frame for each
// This Scanner requires that the final frame in the WAL file is a committing frame. // page in the right order such that they can be written to a new WAL file. This Scanner
// It will return an error at creation time if this is not the case. // requires that the final frame in the WAL file is a committing frame. It will return an
// error at creation time if this is not the case.
type CompactingScanner struct { type CompactingScanner struct {
readSeeker io.ReadSeeker readSeeker io.ReadSeeker
walReader *Reader walReader *Reader
@ -73,7 +73,7 @@ func (c *CompactingScanner) Header() (*WALHeader, error) {
return c.header, nil return c.header, nil
} }
// Next reads the next frame from the WAL file. // Next return the next logical frame from the WAL file.
func (c *CompactingScanner) Next() (*Frame, error) { func (c *CompactingScanner) Next() (*Frame, error) {
if c.cIdx >= len(c.frames) { if c.cIdx >= len(c.frames) {
return nil, io.EOF return nil, io.EOF
@ -101,6 +101,7 @@ func (c *CompactingScanner) scan() error {
txFrames := make(map[uint32]*cFrame) txFrames := make(map[uint32]*cFrame)
frames := make(map[uint32]*cFrame) frames := make(map[uint32]*cFrame)
buf := make([]byte, c.header.PageSize) buf := make([]byte, c.header.PageSize)
for { for {
pgno, commit, err := c.walReader.ReadFrame(buf) pgno, commit, err := c.walReader.ReadFrame(buf)
if err == io.EOF { if err == io.EOF {
@ -130,7 +131,6 @@ func (c *CompactingScanner) scan() error {
} }
txFrames = make(map[uint32]*cFrame) txFrames = make(map[uint32]*cFrame)
} }
if waitingForCommit { if waitingForCommit {
return ErrOpenTransaction return ErrOpenTransaction
} }
@ -142,6 +142,5 @@ func (c *CompactingScanner) scan() error {
c.frames = append(c.frames, frame) c.frames = append(c.frames, frame)
} }
sort.Sort(c.frames) sort.Sort(c.frames)
return nil return nil
} }

Loading…
Cancel
Save