diff --git a/rbf/tx.go b/rbf/tx.go index 16e5505d0..98bd999d4 100644 --- a/rbf/tx.go +++ b/rbf/tx.go @@ -1660,15 +1660,13 @@ func (tx *Tx) writeBitmapWALPage(pgno uint32, page []byte) (walID int64, err err } func (tx *Tx) ensureWritableWALSegment() error { + // Ignore if we still have space in the write cache. writeCacheSize := int64(len(tx.wcache)) if len(tx.segments) != 0 && activeWALSegment(tx.segments).Size()+writeCacheSize < MaxWALSegmentFileSize { return nil } - return tx.addWALSegment() -} -// addWALSegment appends a new, writable segment and closing an existing segments for write. -func (tx *Tx) addWALSegment() error { + // Flush write cache out to file before adding new segment. if err := tx.flushWALWriter(); err != nil { return err } diff --git a/rbf/wal.go b/rbf/wal.go index 3a26c3bf6..bb9b53157 100644 --- a/rbf/wal.go +++ b/rbf/wal.go @@ -122,9 +122,9 @@ func (s *WALSegment) ReadWALPage(walID int64) ([]byte, error) { } func walSegmentByPath(segments []WALSegment, path string) *WALSegment { - for _, segment := range segments { - if segment.Path == path { - return &segment + for i := range segments { + if segments[i].Path == path { + return &segments[i] } } return nil @@ -247,6 +247,13 @@ func truncateWALAfter(segments []WALSegment, walID int64) ([]WALSegment, error) return newSegments, nil } +func DumpWALSegments(segments []WALSegment) { + fmt.Printf("WAL (%d segments)\n", len(segments)) + for i, s := range segments { + fmt.Printf("[%d] WALIDs=(%d-%d) PageN=%d\n", i, s.MinWALID, s.MaxWALID(), s.PageN) + } +} + // FormatWALSegmentPath returns a path for a WAL segment using a WAL ID. func FormatWALSegmentPath(walID int64) string { return fmt.Sprintf("%016x.wal", walID)