From 422f867f6ba72be27dc0c1a2374f0bcc3a540dd7 Mon Sep 17 00:00:00 2001 From: Jingyi Hu Date: Wed, 19 Sep 2018 17:31:44 -0700 Subject: [PATCH] clientv3: add integrity check in snapshot status Add snapshot file integrity check in snapshot status. If the file is corrupted, return with error message. --- clientv3/snapshot/v3_snapshot.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/clientv3/snapshot/v3_snapshot.go b/clientv3/snapshot/v3_snapshot.go index d806e2a6d8c..70f8c3a8d4a 100644 --- a/clientv3/snapshot/v3_snapshot.go +++ b/clientv3/snapshot/v3_snapshot.go @@ -25,6 +25,7 @@ import ( "os" "path/filepath" "reflect" + "strings" "time" "go.etcd.io/etcd/clientv3" @@ -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() {