avoid flushing keys db queue after each Annex action
The flush was only done Annex.run' to make sure that the queue was flushed before git-annex exits. But, doing it there means that as soon as one change gets queued, it gets flushed soon after, which contributes to excessive writes to the database, slowing git-annex down. (This does not yet speed git-annex up, but it is a stepping stone to doing so.) Database queues do not autoflush when garbage collected, so have to be flushed explicitly. I don't think it's possible to make them autoflush (except perhaps if git-annex sqitched to using ResourceT..). The comment in Database.Keys.closeDb used to be accurate, since the automatic flushing did mean that all writes reached the database even when closeDb was not called. But now, closeDb or flushDb needs to be called before stopping using an Annex state. So, removed that comment. In Remote.Git, change to using quiesce everywhere that it used to use stopCoProcesses. This means that uses on onLocal in there are just as slow as before. I considered only calling closeDb on the local git remotes when git-annex exits. But, the reason that Remote.Git calls stopCoProcesses in each onLocal is so as not to leave git processes running that have files open on the remote repo, when it's on removable media. So, it seemed to make sense to also closeDb after each one, since sqlite may also keep files open. Although that has not seemed to cause problems with removable media so far. It was also just easier to quiesce in each onLocal than once at the end. This does likely leave performance on the floor, so could be revisited. In Annex.Content.saveState, there was no reason to close the db, flushing it is enough. The rest of the changes are from auditing for Annex.new, and making sure that quiesce is called, after any action that might possibly need it. After that audit, I'm pretty sure that the change to Annex.run' is safe. The only concern might be that this does let more changes get queued for write to the db, and if git-annex is interrupted, those will be lost. But interrupting git-annex can obviously already prevent it from writing the most recent change to the db, so it must recover from such lost data... right? Sponsored-by: Dartmouth College's Datalad project
This commit is contained in:
parent
b312b2a30b
commit
ba7ecbc6a9
11 changed files with 49 additions and 32 deletions
|
@ -1,6 +1,6 @@
|
|||
{- Sqlite database of information about Keys
|
||||
-
|
||||
- Copyright 2015-2021 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2015-2022 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -12,6 +12,7 @@
|
|||
module Database.Keys (
|
||||
DbHandle,
|
||||
closeDb,
|
||||
flushDb,
|
||||
addAssociatedFile,
|
||||
getAssociatedFiles,
|
||||
getAssociatedFilesIncluding,
|
||||
|
@ -143,14 +144,16 @@ openDb forwrite _ = do
|
|||
|
||||
{- Closes the database if it was open. Any writes will be flushed to it.
|
||||
-
|
||||
- This does not normally need to be called; the database will auto-close
|
||||
- when the handle is garbage collected. However, this can be used to
|
||||
- force a re-read of the database, in case another process has written
|
||||
- data to it.
|
||||
- This does not prevent further use of the database; it will be re-opened
|
||||
- as necessary.
|
||||
-}
|
||||
closeDb :: Annex ()
|
||||
closeDb = liftIO . closeDbHandle =<< Annex.getRead Annex.keysdbhandle
|
||||
|
||||
{- Flushes any queued writes to the database. -}
|
||||
flushDb :: Annex ()
|
||||
flushDb = liftIO . flushDbQueue =<< Annex.getRead Annex.keysdbhandle
|
||||
|
||||
addAssociatedFile :: Key -> TopFilePath -> Annex ()
|
||||
addAssociatedFile k f = runWriterIO $ SQL.addAssociatedFile k f
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue