From d876e06e35b15a1fdf9d7383d79cd010f5348521 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 28 Aug 2024 14:13:12 -0400 Subject: [PATCH] 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. --- Annex/RepoSize.hs | 9 ++++++++- Database/RepoSize.hs | 10 +++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Annex/RepoSize.hs b/Annex/RepoSize.hs index 8da005e2a8..680a6e897b 100644 --- a/Annex/RepoSize.hs +++ b/Annex/RepoSize.hs @@ -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. diff --git a/Database/RepoSize.hs b/Database/RepoSize.hs index 1fbee8f660..73a1d06700 100644 --- a/Database/RepoSize.hs +++ b/Database/RepoSize.hs @@ -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