Skip to content

Commit

Permalink
wal: release wal locks before renaming directory on init
Browse files Browse the repository at this point in the history
Fixes #5852
  • Loading branch information
Anthony Romano committed Jul 2, 2016
1 parent 7cc4596 commit 5991209
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,22 @@ func Create(dirpath string, metadata []byte) (*WAL, error) {
return nil, err
}

if err := os.RemoveAll(dirpath); err != nil {
// rename of directory with locked files doesn't work on windows; close
// the WAL to release the locks so the directory can be renamed
w.Close()
if err := os.Rename(tmpdirpath, dirpath); err != nil {
return nil, err
}
if err := os.Rename(tmpdirpath, dirpath); err != nil {
// reopen and relock
newWAL, oerr := Open(dirpath, walpb.Snapshot{})
if oerr != nil {
return nil, oerr
}
if _, _, _, err := newWAL.ReadAll(); err != nil {
newWAL.Close()
return nil, err
}

w.fp = newFilePipeline(w.dir, segmentSizeBytes)
return w, nil
return newWAL, nil
}

// Open opens the WAL at the given snap.
Expand Down

0 comments on commit 5991209

Please sign in to comment.