From 6e40957a6c3e9b028f5c73885c039b5c78d003cd Mon Sep 17 00:00:00 2001 From: Yicheng Qin Date: Thu, 5 Jun 2014 12:03:44 -0700 Subject: [PATCH] fix(log): truncate file and reset offset correctly If we need to truncate the file because of a decoding error then seek back to the last known good entry. --- log.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/log.go b/log.go index 114c254..a08af09 100644 --- a/log.go +++ b/log.go @@ -168,9 +168,10 @@ func (l *Log) open(path string) error { if err == io.EOF { debugln("open.log.append: finish ") } else { - if err = os.Truncate(path, readBytes); err != nil { + if err = l.file.Truncate(readBytes); err != nil { return fmt.Errorf("raft.Log: Unable to recover: %v", err) } + l.file.Seek(readBytes, os.SEEK_SET) } break }