efficient but unsafe journal file append

This is only for checking performance, it's not safe.

Sponsored-by: Dartmouth College's DANDI project
This commit is contained in:
Joey Hess 2022-07-18 13:47:56 -04:00
parent 2e6e9876e3
commit de18d92de6
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 14 additions and 8 deletions

View file

@ -414,7 +414,7 @@ data ChangeOrAppend t = Change t | Append t
-} -}
changeOrAppend :: Journalable content => RegardingUUID -> RawFilePath -> (L.ByteString -> ChangeOrAppend content) -> Annex () changeOrAppend :: Journalable content => RegardingUUID -> RawFilePath -> (L.ByteString -> ChangeOrAppend content) -> Annex ()
changeOrAppend ru file f = lockJournal $ \jl -> do changeOrAppend ru file f = lockJournal $ \jl -> do
oldc <- getToChange jl ru file oldc <- getToChange ru file
case f oldc of case f oldc of
Change newc -> set jl ru file newc Change newc -> set jl ru file newc
Append toappend -> append jl ru file oldc toappend Append toappend -> append jl ru file oldc toappend

View file

@ -92,21 +92,27 @@ setJournalFile _jl ru file content = withOtherTmp $ \tmp -> do
-- exists -- exists
write `catchIO` (const (createAnnexDirectory jd >> write)) write `catchIO` (const (createAnnexDirectory jd >> write))
{- Appends content to a journal file. {- Appends content to a journal file.
- -
- TODO: Inefficient! -} - The oldcontent is whatever is in the git-annex branch.
- When the journal file does not yet exist, the oldcontent
- is first written to the journal file.
-
- TODO: Unsafe! Does not append atomically. -}
appendJournalFile :: Journalable content => JournalLocked -> RegardingUUID -> RawFilePath -> L.ByteString -> content -> Annex () appendJournalFile :: Journalable content => JournalLocked -> RegardingUUID -> RawFilePath -> L.ByteString -> content -> Annex ()
appendJournalFile _jl ru file oldcontent toappend = withOtherTmp $ \tmp -> do appendJournalFile _jl ru file oldcontent toappend = do
jd <- fromRepo =<< ifM (regardingPrivateUUID ru) jd <- fromRepo =<< ifM (regardingPrivateUUID ru)
( return gitAnnexPrivateJournalDir ( return gitAnnexPrivateJournalDir
, return gitAnnexJournalDir , return gitAnnexJournalDir
) )
let jfile = journalFile file let jfile = fromRawFilePath $ jd P.</> journalFile file
let tmpfile = tmp P.</> jfile let write = liftIO $ ifM (doesFileExist jfile)
let write = liftIO $ do ( withFile jfile AppendMode $ \h ->
withFile (fromRawFilePath tmpfile) WriteMode $ \h -> do writeJournalHandle h toappend
, withFile jfile WriteMode $ \h -> do
writeJournalHandle h oldcontent writeJournalHandle h oldcontent
writeJournalHandle h toappend writeJournalHandle h toappend
)
write `catchIO` (const (createAnnexDirectory jd >> write)) write `catchIO` (const (createAnnexDirectory jd >> write))
data JournalledContent data JournalledContent