Skip to content

Commit

Permalink
clientv3: add integrity check in snapshot status
Browse files Browse the repository at this point in the history
Add snapshot file integrity check in snapshot status. If the file is
corrupted, return with error message.
  • Loading branch information
jingyih committed Sep 20, 2018
1 parent f32bc50 commit 422f867
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 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,14 @@ 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 snapshot file integrity first
var dbErrStrings []string
for dbErr := range tx.Check() {
dbErrStrings = append(dbErrStrings, dbErr.Error())
}
if len(dbErrStrings) > 0 {
return fmt.Errorf("snapshot file integrity check failed. %d errors found.\n"+strings.Join(dbErrStrings, "\n"), len(dbErrStrings))
}
ds.TotalSize = tx.Size()
c := tx.Cursor()
for next, _ := c.First(); next != nil; next, _ = c.Next() {
Expand Down

0 comments on commit 422f867

Please sign in to comment.