Skip to content

Commit

Permalink
clientv3: add database integrity check in snapshot status
Browse files Browse the repository at this point in the history
Add database integrity check in snapshot status. If database is
corrupted, return with error message.
  • Loading branch information
jingyih committed Sep 20, 2018
1 parent f32bc50 commit d6984c0
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions clientv3/snapshot/v3_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"path/filepath"
"reflect"
"strings"
"time"

"go.etcd.io/etcd/clientv3"
Expand Down Expand Up @@ -166,6 +167,18 @@ func (s *v3Manager) Status(dbPath string) (ds Status, err error) {
h := crc32.New(crc32.MakeTable(crc32.Castagnoli))

if err = db.View(func(tx *bolt.Tx) error {
// check database integrity first
var (
count int
db_err_strings []string
)
for db_err := range tx.Check() {
db_err_strings = append(db_err_strings, db_err.Error())
count++
}
if count > 0 {
return fmt.Errorf("database corrupted! %d errors found.\n"+strings.Join(db_err_strings, "\n"), count)
}
ds.TotalSize = tx.Size()
c := tx.Cursor()
for next, _ := c.First(); next != nil; next, _ = c.Next() {
Expand Down

0 comments on commit d6984c0

Please sign in to comment.