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

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

Loading…
Cancel
Save