1
0
Fork 0

Add BoltDB stats

master
Philip O'Toole 3 years ago
parent 47f924deb1
commit 0e34dc49ca

@ -23,6 +23,7 @@ require (
github.com/mkideal/log v1.0.0 // indirect
github.com/mkideal/pkg v0.1.3
github.com/rqlite/go-sqlite3 v1.22.0
github.com/rqlite/raft-boltdb v0.0.0-20210905150853-a32fad654b56
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect

@ -249,6 +249,8 @@ github.com/rqlite/go-sqlite3 v1.21.0 h1:YTeeVH5olioCnR8WzdL1qcmM8lN5xfYZ++E2YGI3
github.com/rqlite/go-sqlite3 v1.21.0/go.mod h1:ml55MVv28UP7V8zrxILd2EsrI6Wfsz76YSskpg08Ut4=
github.com/rqlite/go-sqlite3 v1.22.0 h1:twqvKzylJXG62Qe0rcqdy5ClGhc0YRc2vvA3nEXwmes=
github.com/rqlite/go-sqlite3 v1.22.0/go.mod h1:ml55MVv28UP7V8zrxILd2EsrI6Wfsz76YSskpg08Ut4=
github.com/rqlite/raft-boltdb v0.0.0-20210905150853-a32fad654b56 h1:+Yz+URskt+++ekvKiGWxKtfV9poY/JXtIvpadf8snv0=
github.com/rqlite/raft-boltdb v0.0.0-20210905150853-a32fad654b56/go.mod h1:X1tXZi6gr5ZI1OIBVZxYv9zCiXeLi9Znjiolz5BqNE8=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=

@ -4,7 +4,7 @@ import (
"fmt"
"github.com/hashicorp/raft"
"github.com/hashicorp/raft-boltdb"
"github.com/rqlite/raft-boltdb"
)
// Log is an object that can return information about the Raft log.
@ -59,3 +59,8 @@ func (l *Log) LastCommandIndex() (uint64, error) {
}
return 0, nil
}
// Stats returns stats about the BoltDB database.
func (l *Log) Stats() raftboltdb.Stats {
return l.BoltStore.Stats()
}

@ -6,7 +6,7 @@ import (
"testing"
"github.com/hashicorp/raft"
"github.com/hashicorp/raft-boltdb"
"github.com/rqlite/raft-boltdb"
)
func Test_LogNewEmpty(t *testing.T) {
@ -40,7 +40,6 @@ func Test_LogNewEmpty(t *testing.T) {
if lci != 0 {
t.Fatalf("got wrong value for last command index of not empty log: %d", lci)
}
}
func Test_LogNewExistNotEmpty(t *testing.T) {
@ -225,6 +224,29 @@ func Test_LogLastCommandIndexNotExist(t *testing.T) {
}
}
func Test_LogStats(t *testing.T) {
path := mustTempFile()
defer os.Remove(path)
// Write some entries directory to the BoltDB Raft store.
bs, err := raftboltdb.NewBoltStore(path)
if err != nil {
t.Fatalf("failed to create bolt store: %s", err)
}
for i := 4; i > 0; i-- {
if err := bs.StoreLog(&raft.Log{
Index: uint64(i),
}); err != nil {
t.Fatalf("failed to write entry to raft log: %s", err)
}
}
_ = bs.Stats()
if err := bs.Close(); err != nil {
t.Fatalf("failed to close bolt db: %s", err)
}
}
// mustTempFile returns a path to a temporary file in directory dir. It is up to the
// caller to remove the file once it is no longer needed.
func mustTempFile() string {

@ -560,6 +560,7 @@ func (s *Store) Stats() (map[string]interface{}, error) {
if err != nil {
return nil, err
}
raftStats["bolt"] = s.boltStore.Stats()
dirSz, err := dirSize(s.raftDir)
if err != nil {

Loading…
Cancel
Save