err on the side of larger repository size

When a live update is removing a key, it might fail. So only count those
once they have succeeded. When a live update is adding a key, count it
immediately to avoid over-filling a repo.

This also makes the 1 minute delay between stale live changes checks
more defensible, because a stale live change can only cause us to err
more on the side of caution.
This commit is contained in:
Joey Hess 2024-08-28 14:13:12 -04:00
parent f89a1b8216
commit d876e06e35
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 13 additions and 6 deletions

View file

@ -57,7 +57,7 @@ getLiveRepoSizes quiet = do
go sizemap = do
h <- Db.getRepoSizeHandle
checkStaleSizeChanges h
liveoffsets <- liftIO $ Db.liveRepoOffsets h
liveoffsets <- liftIO $ Db.liveRepoOffsets h wantlivesizechange
let calc u (RepoSize size, SizeOffset startoffset) =
case M.lookup u liveoffsets of
Nothing -> RepoSize size
@ -65,6 +65,13 @@ getLiveRepoSizes quiet = do
size + (offset - startoffset)
return $ M.mapWithKey calc sizemap
-- When a live update is in progress, only count it
-- when it makes a repository larger. Better to err on the side
-- of repositories being too large than assume that drops will
-- always succeed.
wantlivesizechange AddingKey = True
wantlivesizechange RemovingKey = False
{- Fills an empty Annex.reposizes MVar with current information
- from the git-annex branch, supplimented with journalled but
- not yet committed information.

View file

@ -353,7 +353,7 @@ recordedRepoOffsets (RepoSizeHandle (Just h) _) =
recordedRepoOffsets (RepoSizeHandle Nothing _) = pure mempty
{- Gets the offsets to sizes of Repos, including all live changes that
- are happening now.
- are happening now whose SizeChange matches the provided function.
-
- This does not necessarily include all changes that have been made,
- only ones that had startingLiveSizeChange called for them will be
@ -372,8 +372,8 @@ recordedRepoOffsets (RepoSizeHandle Nothing _) = pure mempty
- This is only expensive when there are a lot of live changes happening at
- the same time.
-}
liveRepoOffsets :: RepoSizeHandle -> IO (M.Map UUID SizeOffset)
liveRepoOffsets (RepoSizeHandle (Just h) _) = H.queryDb h $ do
liveRepoOffsets :: RepoSizeHandle -> (SizeChange -> Bool) -> IO (M.Map UUID SizeOffset)
liveRepoOffsets (RepoSizeHandle (Just h) _) wantedsizechange = H.queryDb h $ do
sizechanges <- getSizeChanges
livechanges <- getLiveSizeChangesMap
let us = S.toList $ S.fromList $
@ -390,7 +390,7 @@ liveRepoOffsets (RepoSizeHandle (Just h) _) = H.queryDb h $ do
filterM (nonredundantlivechange livechangesbykey u)
(fromMaybe [] $ M.lookup u livechanges)
let sizechange = foldl'
(\t (k, sc) -> updateRollingTotal t sc k)
(\t (k, sc) -> if wantedsizechange sc then updateRollingTotal t sc k else t)
(fromMaybe 0 (M.lookup u sizechanges))
livechanges'
return (u, SizeOffset sizechange)
@ -411,4 +411,4 @@ liveRepoOffsets (RepoSizeHandle (Just h) _) = H.queryDb h $ do
filter (\(sc', cid') -> cid /= cid' && sc' == AddingKey)
(fromMaybe [] $ M.lookup k livechangesbykey)
competinglivechanges _ _ AddingKey _ = []
liveRepoOffsets (RepoSizeHandle Nothing _) = pure mempty
liveRepoOffsets (RepoSizeHandle Nothing _) _ = pure mempty