Explorar o código

etcdctl: cherry pick of #10109 to release-3.3

Add snapshot file integrity verification in snapshot status.
Jingyi Hu %!s(int64=7) %!d(string=hai) anos
pai
achega
60d546e309
Modificáronse 1 ficheiros con 8 adicións e 0 borrados
  1. 8 0
      etcdctl/ctlv3/command/snapshot_command.go

+ 8 - 0
etcdctl/ctlv3/command/snapshot_command.go

@@ -423,6 +423,14 @@ func dbStatus(p string) dbstatus {
 	h := crc32.New(crc32.MakeTable(crc32.Castagnoli))
 	h := crc32.New(crc32.MakeTable(crc32.Castagnoli))
 
 
 	err = db.View(func(tx *bolt.Tx) error {
 	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()
 		ds.TotalSize = tx.Size()
 		c := tx.Cursor()
 		c := tx.Cursor()
 		for next, _ := c.First(); next != nil; next, _ = c.Next() {
 		for next, _ := c.First(); next != nil; next, _ = c.Next() {