Skip to content

Commit

Permalink
etcdserver: make the wal repairing logic clear
Browse files Browse the repository at this point in the history
  • Loading branch information
xiang90 committed Mar 30, 2015
1 parent 684ebd9 commit 0b9a318
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions etcdserver/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,22 @@ func readWAL(waldir string, snap walpb.Snapshot) (w *wal.WAL, id, cid types.ID,
wmetadata []byte
)

for i := 0; i < 2; i++ {
repaired := false
for {
if w, err = wal.Open(waldir, snap); err != nil {
log.Fatalf("etcdserver: open wal error: %v", err)
}
if wmetadata, st, ents, err = w.ReadAll(); err != nil {
w.Close()
if i != 0 || err != io.ErrUnexpectedEOF {
log.Fatalf("etcdserver: read wal error: %v", err)
// we can only repair ErrUnexpectedEOF and we never repair twice.
if repaired || err != io.ErrUnexpectedEOF {
log.Fatalf("etcdserver: read wal error (%v) and cannot be repaired", err)
}
if !wal.Repair(waldir) {
log.Fatalf("etcdserver: WAL error (%v) cannot be repaired", err)
} else {
log.Printf("etcdserver: repaired WAL error (%v)", err)
repaired = true
}
continue
}
Expand Down

0 comments on commit 0b9a318

Please sign in to comment.