git-annex/Database/RepoSize/Handle.hs
Joey Hess f89a1b8216
remove stale live changes from reposize database
Reorganized the reposize database directory, and split up a column.

checkStaleSizeChanges needs to run before needLiveUpdate,
otherwise the process won't be holding a lock on its pid file, and
another process could go in and expire the live update it records. It
just so happens that they do get called in the correct order, since
checking balanced preferred content calls getLiveRepoSizes before
needLiveUpdate.

The 1 minute delay between checks is arbitrary, but will avoid excess
work. The downside of it is that, if a process is dropping a file and
gets interrupted, for 1 minute another process can expect a repository
will soon be smaller than it is. And so a process might send data to a
repository when a file is not really going to be dropped from it. But
note that can already happen if a drop takes some time in eg locking and
then fails. So it seems possible that live updates should only be
allowed to increase, rather than decrease the size of a repository.
2024-08-28 13:57:25 -04:00

22 lines
590 B
Haskell

{- Sqlite database used to track the sizes of repositories.
-
- Copyright 2024 Joey Hess <id@joeyh.name>
-:
- Licensed under the GNU AGPL version 3 or higher.
-}
module Database.RepoSize.Handle where
import qualified Database.Handle as H
import Utility.LockPool (LockHandle)
import Control.Concurrent
import Data.Time.Clock.POSIX
data RepoSizeHandle = RepoSizeHandle
(Maybe H.DbHandle)
-- ^ Nothing if the database was not able to be opened due to
-- permissions.
(MVar (Maybe (LockHandle, POSIXTime)))
-- ^ Live update lock and time of last check for stale live
-- updates.