Skip to content

Commit

Permalink
clientv3: add db integrity check to snapshot status
Browse files Browse the repository at this point in the history
Check database integrity in snapshot status.
  • Loading branch information
jingyih committed Sep 20, 2018
1 parent f32bc50 commit a8fa39e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 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,16 @@ 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
var 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 a8fa39e

Please sign in to comment.