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:
parent
f89a1b8216
commit
d876e06e35
2 changed files with 13 additions and 6 deletions
|
@ -57,7 +57,7 @@ getLiveRepoSizes quiet = do
|
||||||
go sizemap = do
|
go sizemap = do
|
||||||
h <- Db.getRepoSizeHandle
|
h <- Db.getRepoSizeHandle
|
||||||
checkStaleSizeChanges h
|
checkStaleSizeChanges h
|
||||||
liveoffsets <- liftIO $ Db.liveRepoOffsets h
|
liveoffsets <- liftIO $ Db.liveRepoOffsets h wantlivesizechange
|
||||||
let calc u (RepoSize size, SizeOffset startoffset) =
|
let calc u (RepoSize size, SizeOffset startoffset) =
|
||||||
case M.lookup u liveoffsets of
|
case M.lookup u liveoffsets of
|
||||||
Nothing -> RepoSize size
|
Nothing -> RepoSize size
|
||||||
|
@ -65,6 +65,13 @@ getLiveRepoSizes quiet = do
|
||||||
size + (offset - startoffset)
|
size + (offset - startoffset)
|
||||||
return $ M.mapWithKey calc sizemap
|
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
|
{- Fills an empty Annex.reposizes MVar with current information
|
||||||
- from the git-annex branch, supplimented with journalled but
|
- from the git-annex branch, supplimented with journalled but
|
||||||
- not yet committed information.
|
- not yet committed information.
|
||||||
|
|
|
@ -353,7 +353,7 @@ recordedRepoOffsets (RepoSizeHandle (Just h) _) =
|
||||||
recordedRepoOffsets (RepoSizeHandle Nothing _) = pure mempty
|
recordedRepoOffsets (RepoSizeHandle Nothing _) = pure mempty
|
||||||
|
|
||||||
{- Gets the offsets to sizes of Repos, including all live changes that
|
{- 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,
|
- This does not necessarily include all changes that have been made,
|
||||||
- only ones that had startingLiveSizeChange called for them will be
|
- 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
|
- This is only expensive when there are a lot of live changes happening at
|
||||||
- the same time.
|
- the same time.
|
||||||
-}
|
-}
|
||||||
liveRepoOffsets :: RepoSizeHandle -> IO (M.Map UUID SizeOffset)
|
liveRepoOffsets :: RepoSizeHandle -> (SizeChange -> Bool) -> IO (M.Map UUID SizeOffset)
|
||||||
liveRepoOffsets (RepoSizeHandle (Just h) _) = H.queryDb h $ do
|
liveRepoOffsets (RepoSizeHandle (Just h) _) wantedsizechange = H.queryDb h $ do
|
||||||
sizechanges <- getSizeChanges
|
sizechanges <- getSizeChanges
|
||||||
livechanges <- getLiveSizeChangesMap
|
livechanges <- getLiveSizeChangesMap
|
||||||
let us = S.toList $ S.fromList $
|
let us = S.toList $ S.fromList $
|
||||||
|
@ -390,7 +390,7 @@ liveRepoOffsets (RepoSizeHandle (Just h) _) = H.queryDb h $ do
|
||||||
filterM (nonredundantlivechange livechangesbykey u)
|
filterM (nonredundantlivechange livechangesbykey u)
|
||||||
(fromMaybe [] $ M.lookup u livechanges)
|
(fromMaybe [] $ M.lookup u livechanges)
|
||||||
let sizechange = foldl'
|
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))
|
(fromMaybe 0 (M.lookup u sizechanges))
|
||||||
livechanges'
|
livechanges'
|
||||||
return (u, SizeOffset sizechange)
|
return (u, SizeOffset sizechange)
|
||||||
|
@ -411,4 +411,4 @@ liveRepoOffsets (RepoSizeHandle (Just h) _) = H.queryDb h $ do
|
||||||
filter (\(sc', cid') -> cid /= cid' && sc' == AddingKey)
|
filter (\(sc', cid') -> cid /= cid' && sc' == AddingKey)
|
||||||
(fromMaybe [] $ M.lookup k livechangesbykey)
|
(fromMaybe [] $ M.lookup k livechangesbykey)
|
||||||
competinglivechanges _ _ AddingKey _ = []
|
competinglivechanges _ _ AddingKey _ = []
|
||||||
liveRepoOffsets (RepoSizeHandle Nothing _) = pure mempty
|
liveRepoOffsets (RepoSizeHandle Nothing _) _ = pure mempty
|
||||||
|
|
Loading…
Reference in a new issue