take lock in checkLogFile and calcLogFile

move: Fix openFile crash with -J

This does make them a bit slower, although usually the log file is not
very big, so even when it's being rewritten, they will not block for
long taking the lock. Still, little slowdowns may add up when moving a lot
file files.

A less expensive fix would be to use something lower level than openFile
that does not check if the file is already open for write by another
thread. But GHC does not seem to provide anything convenient; even mkFD
checks for a writing thread.

fullLines is no longer necessary since these functions no longer will
read the file while it's being written.

Sponsored-by: Dartmouth College's DANDI project
This commit is contained in:
Joey Hess 2022-10-07 13:19:17 -04:00
parent 85dbc21c1c
commit 4a42c69092
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 48 additions and 45 deletions

View file

@ -379,10 +379,9 @@ logMove srcuuid destuuid deststartedwithcopy key a = go =<< setup
-- Only log when there was no copy.
unless deststartedwithcopy $
appendLogFile logf lckf logline
return logf
return (logf, lckf)
cleanup logf = do
lck <- fromRepo gitAnnexMoveLock
cleanup (logf, lckf) =
-- This buffers the log file content in memory.
-- The log file length is limited to the number of
-- concurrent jobs, times the number of times a move
@ -390,18 +389,17 @@ logMove srcuuid destuuid deststartedwithcopy key a = go =<< setup
-- That could grow without bounds given enough time,
-- so the log is also truncated to the most recent
-- 100 items.
modifyLogFile logf lck
modifyLogFile logf lckf
(filter (/= logline) . reverse . take 100 . reverse)
go logf
go fs@(logf, lckf)
-- Only need to check log when there is a copy.
| deststartedwithcopy = do
wasnocopy <- checkLogFile (fromRawFilePath logf)
(== logline)
wasnocopy <- checkLogFile logf lckf (== logline)
if wasnocopy
then go' logf False
else go' logf deststartedwithcopy
| otherwise = go' logf deststartedwithcopy
then go' fs False
else go' fs deststartedwithcopy
| otherwise = go' fs deststartedwithcopy
go' logf deststartedwithcopy' = a $
DestStartedWithCopy deststartedwithcopy' (cleanup logf)
go' fs deststartedwithcopy' = a $
DestStartedWithCopy deststartedwithcopy' (cleanup fs)