Skip to content

Commit

Permalink
Merge pull request #764 from rqlite/dir-size
Browse files Browse the repository at this point in the history
Add total Raft directory size to Store stats
  • Loading branch information
otoolep committed Feb 7, 2021
2 parents d095c22 + b579e5c commit 80fcc6b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
29 changes: 25 additions & 4 deletions store/store.go
Expand Up @@ -290,16 +290,16 @@ func (s *Store) Open(enableBootstrap bool) error {

// Close closes the store. If wait is true, waits for a graceful shutdown.
func (s *Store) Close(wait bool) error {
if err := s.db.Close(); err != nil {
return err
}
f := s.raft.Shutdown()
if wait {
if e := f.(raft.Future); e.Error() != nil {
return e.Error()
}
}
// Only shutdown Bolt when Raft is done with it.
// Only shutdown Bolt and SQLite when Raft is done.
if err := s.db.Close(); err != nil {
return err
}
if err := s.boltStore.Close(); err != nil {
return err
}
Expand Down Expand Up @@ -498,6 +498,11 @@ func (s *Store) Stats() (map[string]interface{}, error) {
return nil, err
}

dirSz, err := dirSize(s.raftDir)
if err != nil {
return nil, err
}

status := map[string]interface{}{
"node_id": s.raftID,
"raft": raftStats,
Expand All @@ -516,6 +521,7 @@ func (s *Store) Stats() (map[string]interface{}, error) {
"metadata": s.meta,
"nodes": nodes,
"dir": s.raftDir,
"dir_size": dirSz,
"sqlite3": dbStatus,
"db_conf": s.dbConf,
}
Expand Down Expand Up @@ -1421,3 +1427,18 @@ func pathExists(p string) bool {
}
return true
}

// dirSize returns the total size of all files in the given directory
func dirSize(path string) (int64, error) {
var size int64
err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
size += info.Size()
}
return err
})
return size, err
}
2 changes: 1 addition & 1 deletion system_test/helpers.go
Expand Up @@ -54,7 +54,7 @@ func (n *Node) Close(graceful bool) error {

// Deprovision shuts down and removes all resources associated with the node.
func (n *Node) Deprovision() {
n.Store.Close(false)
n.Store.Close(true)
n.Service.Close()
os.RemoveAll(n.Dir)
}
Expand Down

0 comments on commit 80fcc6b

Please sign in to comment.