Browse Source

wal: repair decoder needs to update its crc

Xiang Li 10 years ago
parent
commit
3e9a033cd2
1 changed files with 14 additions and 0 deletions
  1. 14 0
      wal/repair.go

+ 14 - 0
wal/repair.go

@@ -43,6 +43,17 @@ func Repair(dirpath string) bool {
 		switch err {
 		case nil:
 			n += 8 + rec.Size()
+			// update crc of the decoder when necessary
+			switch rec.Type {
+			case crcType:
+				crc := decoder.crc.Sum32()
+				// current crc of decoder must match the crc of the record.
+				// do no need to match 0 crc, since the decoder is a new one at this case.
+				if crc != 0 && rec.Validate(crc) != nil {
+					return false
+				}
+				decoder.updateCRC(rec.Crc)
+			}
 			continue
 		case io.EOF:
 			return true
@@ -74,6 +85,9 @@ func Repair(dirpath string) bool {
 				return false
 			}
 			return true
+		default:
+			log.Printf("wal: could not repair error (%v)", err)
+			return false
 		}
 	}
 }