Skip to content

Commit

Permalink
ffldb: close block files before deleting them
Browse files Browse the repository at this point in the history
The block files may be open when deleteFile is called.  This resulted in
files not being deleted and erroring out on windows.  Properly closing
the files closing the files avoids this error.
  • Loading branch information
kcalvinalvin committed Jul 1, 2024
1 parent d881c68 commit c8611df
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions database/ffldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,19 @@ func (tx *transaction) writePendingAndCommit() error {
// We do this first before doing any of the writes as we can't undo
// deletions of files.
for _, fileNum := range tx.pendingDelFileNums {
blockFile := tx.db.store.openBlockFiles[fileNum]
if blockFile != nil {
// Close the old file under the write lock for the file in case
// any readers are currently reading from it so it's not closed
// out from under them.
blockFile.Lock()
_ = blockFile.file.Close()
blockFile.Unlock()

delete(tx.db.store.openBlockFiles, fileNum)
delete(tx.db.store.fileNumToLRUElem, fileNum)
}

err := tx.db.store.deleteFileFunc(fileNum)
if err != nil {
// Nothing we can do if we fail to delete blocks besides
Expand Down

0 comments on commit c8611df

Please sign in to comment.