Merge pull request #5855 from heyitsanthony/fix-windows-wal-init

wal: release wal locks before renaming directory on init
release-3.1
Anthony Romano 2016-07-03 19:21:23 -07:00 committed by GitHub
commit b566ca225c
1 changed files with 13 additions and 6 deletions

View File

@ -129,15 +129,22 @@ func Create(dirpath string, metadata []byte) (*WAL, error) {
return nil, err
}
if err := os.RemoveAll(dirpath); err != nil {
return nil, err
}
// 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
}
w.fp = newFilePipeline(w.dir, segmentSizeBytes)
return w, 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
}
return newWAL, nil
}
// Open opens the WAL at the given snap.