Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Goutham Veeramachaneni <[email protected]>
  • Loading branch information
gouthamve committed Sep 20, 2018
1 parent 9ea6fd5 commit b38fdc9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
19 changes: 14 additions & 5 deletions wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,13 @@ func (w *SegmentWAL) run(interval time.Duration) {

// Close syncs all data and closes the underlying resources.
func (w *SegmentWAL) Close() error {
// Make sure you can call Close() multiple times.
select {
case <-w.stopc:
return nil // Already closed.
default:
}

close(w.stopc)
<-w.donec

Expand Down Expand Up @@ -1262,18 +1269,20 @@ func MigrateWAL(logger log.Logger, dir string) (err error) {
if err != nil {
return errors.Wrap(err, "open new WAL")
}
// It should've already been closed as part of the previous finalization.
// Do it once again in case of prior errors.
// Make sure the new WAL is always Closed.
defer func() {
if err != nil {
repl.Close()
return
}
err = errors.Wrap(repl.Close(), "close new WAL")
}()

w, err := OpenSegmentWAL(dir, logger, time.Minute, nil)
if err != nil {
return errors.Wrap(err, "open old WAL")
}
defer w.Close()

rdr := w.Reader()

Expand Down Expand Up @@ -1307,9 +1316,9 @@ func MigrateWAL(logger log.Logger, dir string) (err error) {
if err != nil {
return errors.Wrap(err, "write new entries")
}
if err := repl.Close(); err != nil {
return errors.Wrap(err, "close new WAL")
}
// We explicitly close even when there is a defer for Windows to be
// able to delete it. The defer is in place to close it in-case there
// are errors above.
if err := w.Close(); err != nil {
return errors.Wrap(err, "close old WAL")
}
Expand Down
5 changes: 5 additions & 0 deletions wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ func (w *WAL) Repair(origErr error) error {
if err != nil {
return errors.Wrap(err, "open segment")
}
defer f.Close()

r := NewReader(bufio.NewReader(f))

for r.Next() {
Expand All @@ -329,6 +331,9 @@ func (w *WAL) Repair(origErr error) error {
}
// We expect an error here from r.Err(), so nothing to handle.

// We explicitly close even when there is a defer for Windows to be
// able to delete it. The defer is in place to close it in-case there
// are errors above.
if err := f.Close(); err != nil {
return errors.Wrap(err, "close corrupted file")
}
Expand Down

0 comments on commit b38fdc9

Please sign in to comment.