Skip to content

Commit c6892f1

Browse files
committed
Fix errors on table close with ongoing merges
The merging run finalise was closing input runs before aborting the ongoing merge. When nothing else was holding the input runs open (like the levels cache) then this was resulting in trying to delete the run files while the run readers (in the merge) still had their own open file handles for the same files. This resulted in test failures with the MockFS and would have also failed on Windows filesystems (which do not allow deleting files where there are still open file handles).
1 parent 9607654 commit c6892f1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Database/LSMTree/Internal/MergingRun.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,13 @@ unsafeNew mergeNumRuns mergeNumEntries knownCompleted state = do
218218
CompletedMerge r ->
219219
releaseRef r
220220
OngoingMerge rs m -> do
221-
V.forM_ rs releaseRef
221+
-- The RunReaders in the Merge keep their own file handles to the
222+
-- run kopsFile open. We must close these handles *before* we release
223+
-- the runs themselves, which will close and delete the files.
224+
-- Otherwise we would be removing files that still have open handles
225+
-- (which does not work on Windows, and is caught by the MockFS).
222226
Merge.abort m
227+
V.forM_ rs releaseRef
223228

224229
-- | Create references to the runs that should be queried for lookups.
225230
-- In particular, if the merge is not complete, these are the input runs.

0 commit comments

Comments
 (0)