|
|
@@ -301,6 +301,18 @@ func (w *WAL) ReadAll() (metadata []byte, state raftpb.HardState, ents []raftpb.
|
|
|
state.Reset()
|
|
|
return nil, state, nil, err
|
|
|
}
|
|
|
+ // decodeRecord() will return io.EOF if it detects a zero record,
|
|
|
+ // but this zero record may be followed by non-zero records from
|
|
|
+ // a torn write. Overwriting some of these non-zero records, but
|
|
|
+ // not all, will cause CRC errors on WAL open. Since the records
|
|
|
+ // were never fully synced to disk in the first place, it's safe
|
|
|
+ // to zero them out to avoid any CRC errors from new writes.
|
|
|
+ if _, err = w.tail().Seek(w.decoder.lastOffset(), os.SEEK_SET); err != nil {
|
|
|
+ return nil, state, nil, err
|
|
|
+ }
|
|
|
+ if err = fileutil.ZeroToEnd(w.tail().File); err != nil {
|
|
|
+ return nil, state, nil, err
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
err = nil
|
|
|
@@ -319,7 +331,6 @@ func (w *WAL) ReadAll() (metadata []byte, state raftpb.HardState, ents []raftpb.
|
|
|
|
|
|
if w.tail() != nil {
|
|
|
// create encoder (chain crc with the decoder), enable appending
|
|
|
- _, err = w.tail().Seek(w.decoder.lastOffset(), os.SEEK_SET)
|
|
|
w.encoder = newEncoder(w.tail(), w.decoder.lastCRC())
|
|
|
}
|
|
|
w.decoder = nil
|