1
0
Fork 0

Add low-level WAL scan and compaction metrics

master
Philip O'Toole 8 months ago
parent 434e46def7
commit 2cd930d5c7

@ -1,3 +1,7 @@
## 8.18.6 (unreleased)
### Implementation changes and bug fixes
- [PR #1656](https://github.com/rqlite/rqlite/pull/1656): Add low-level WAL compaction timings and metrics.
## 8.18.5 (January 30th 2024)
### Implementation changes and bug fixes
- [PR #1646](https://github.com/rqlite/rqlite/pull/1646): Expose BUSY TIMEOUT on /status.

@ -3,9 +3,11 @@ package wal
import (
"encoding/binary"
"errors"
"expvar"
"fmt"
"io"
"sort"
"time"
)
var (
@ -77,9 +79,11 @@ func NewCompactingScanner(r io.ReadSeeker, fullScan bool) (*CompactingScanner, e
header: hdr,
fullScan: fullScan,
}
startT := time.Now()
if err := s.scan(); err != nil {
return nil, err
}
stats.Get(compactScanDuration).(*expvar.Int).Set(time.Since(startT).Milliseconds())
return s, nil
}
@ -115,6 +119,7 @@ func (c *CompactingScanner) Next() (*Frame, error) {
// Bytes returns a byte slice containing the entire contents of the compacted WAL file.
// The byte slice is suitable for writing to a new WAL file.
func (c *CompactingScanner) Bytes() ([]byte, error) {
startT := time.Now()
pageSz := int(c.header.PageSize)
buf := make([]byte, WALHeaderSize+(len(c.frames)*WALFrameHeaderSize)+len(c.frames)*pageSz)
c.header.Copy(buf)
@ -157,6 +162,8 @@ func (c *CompactingScanner) Bytes() ([]byte, error) {
frmHdr += WALFrameHeaderSize + pageSz
}
stats.Get(compactLoadDuration).(*expvar.Int).Set(time.Since(startT).Milliseconds())
stats.Get(compactLoadPageCount).(*expvar.Int).Set(int64(len(c.frames)))
return buf, nil
}

@ -2,6 +2,7 @@ package wal
import (
"encoding/binary"
"expvar"
"fmt"
"io"
)
@ -14,6 +15,28 @@ const (
WALSupportedVersion = 3007000
)
const (
compactScanDuration = "compact_index_duration_ms"
compactLoadDuration = "compact_load_duration_ms"
compactLoadPageCount = "compact_load_page_count"
)
// stats captures stats for the DB layer.
var stats *expvar.Map
func init() {
stats = expvar.NewMap("wal")
ResetStats()
}
// ResetStats resets the expvar stats for this module. Mostly for test purposes.
func ResetStats() {
stats.Init()
stats.Add(compactScanDuration, 0)
stats.Add(compactLoadDuration, 0)
stats.Add(compactLoadPageCount, 0)
}
// Reader wraps an io.Reader and parses SQLite WAL frames.
//
// This reader verifies the salt & checksum integrity while it reads. It does

Loading…
Cancel
Save