1
0
Fork 0

Record size of snapshot persist

master
Philip O'Toole 1 year ago
parent ca48ba845e
commit 86f3fda86e

@ -1,6 +1,7 @@
package snapshot
import (
"expvar"
"fmt"
"io"
"os"
@ -38,7 +39,8 @@ func (s *Snapshot) Persist(sink raft.SnapshotSink) error {
}
defer stream.Close()
_, err = io.Copy(sink, stream)
n, err := io.Copy(sink, stream)
stats.Get(persistSize).(*expvar.Int).Set(n)
return err
}

@ -3,6 +3,7 @@ package snapshot
import (
"encoding/json"
"errors"
"expvar"
"fmt"
"io"
"log"
@ -19,6 +20,11 @@ import (
"github.com/rqlite/rqlite/db"
)
func init() {
stats = expvar.NewMap("snapshot")
ResetStats()
}
const (
minSnapshotRetain = 2
@ -32,6 +38,10 @@ const (
tmpSuffix = ".tmp"
)
const (
persistSize = "persist_size"
)
var (
// ErrRetainCountTooLow is returned when the retain count is too low.
ErrRetainCountTooLow = errors.New("retain count must be >= 2")
@ -43,6 +53,15 @@ var (
ErrSnapshotBaseMissing = errors.New("snapshot base SQLite file missing")
)
// stats captures stats for the Store.
var stats *expvar.Map
// ResetStats resets the expvar stats for this module. Mostly for test purposes.
func ResetStats() {
stats.Init()
stats.Add(persistSize, 0)
}
// Meta represents the metadata for a snapshot.
type Meta struct {
raft.SnapshotMeta

Loading…
Cancel
Save