repository: cleanup(): close segment before unlinking

On Windows, trying to delete a file that is already open raises an exception.

Docs:
https://docs.python.org/3/library/os.html#os.remove
This commit is contained in:
Rayyan Ansari 2022-11-10 17:59:16 +00:00
parent 62341673c1
commit 2a8cacf517
1 changed files with 2 additions and 3 deletions

View File

@ -1448,13 +1448,12 @@ class LoggedIO:
def cleanup(self, transaction_id):
"""Delete segment files left by aborted transactions"""
self.close_segment()
self.segment = transaction_id + 1
count = 0
for segment, filename in self.segment_iterator(reverse=True):
if segment > transaction_id:
if segment in self.fds:
del self.fds[segment]
safe_unlink(filename)
self.delete_segment(segment)
count += 1
else:
break