wal: release wal locks before renaming directory on init

Fixes #5852
This commit is contained in:
Anthony Romano 2016-07-02 12:14:37 -07:00
parent 7cc4596ebd
commit 5991209c2d

View File

@ -129,15 +129,22 @@ func Create(dirpath string, metadata []byte) (*WAL, error) {
return nil, err return nil, err
} }
if err := os.RemoveAll(dirpath); err != nil { // rename of directory with locked files doesn't work on windows; close
return nil, err // the WAL to release the locks so the directory can be renamed
} w.Close()
if err := os.Rename(tmpdirpath, dirpath); err != nil { if err := os.Rename(tmpdirpath, dirpath); err != nil {
return nil, err return nil, err
} }
// reopen and relock
w.fp = newFilePipeline(w.dir, segmentSizeBytes) newWAL, oerr := Open(dirpath, walpb.Snapshot{})
return w, nil 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. // Open opens the WAL at the given snap.