use live reposizes in balanced preferred content
This commit is contained in:
parent
d7813876a0
commit
23d44aa4aa
4 changed files with 35 additions and 21 deletions
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
module Annex.RepoSize (
|
module Annex.RepoSize (
|
||||||
getRepoSizes,
|
getRepoSizes,
|
||||||
|
getLiveRepoSizes,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Annex.Common
|
import Annex.Common
|
||||||
|
@ -29,7 +30,11 @@ import Control.Concurrent.Async
|
||||||
import qualified Data.Map.Strict as M
|
import qualified Data.Map.Strict as M
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
|
|
||||||
{- Gets the repo size map. Cached for speed. -}
|
{- Gets the repo size map. Cached for speed.
|
||||||
|
-
|
||||||
|
- Note that this is the size of all repositories as of the first time it
|
||||||
|
- was called. It does not update while git-annex is running.
|
||||||
|
-}
|
||||||
getRepoSizes :: Bool -> Annex (M.Map UUID RepoSize)
|
getRepoSizes :: Bool -> Annex (M.Map UUID RepoSize)
|
||||||
getRepoSizes quiet = do
|
getRepoSizes quiet = do
|
||||||
rsv <- Annex.getRead Annex.reposizes
|
rsv <- Annex.getRead Annex.reposizes
|
||||||
|
@ -39,14 +44,29 @@ getRepoSizes quiet = do
|
||||||
return sizemap
|
return sizemap
|
||||||
Nothing -> calcRepoSizes quiet rsv
|
Nothing -> calcRepoSizes quiet rsv
|
||||||
|
|
||||||
|
{- Like getRepoSizes, but with live updates. -}
|
||||||
|
getLiveRepoSizes :: Bool -> Annex (M.Map UUID RepoSize)
|
||||||
|
getLiveRepoSizes quiet = do
|
||||||
|
h <- Db.getRepoSizeHandle
|
||||||
|
liftIO (Db.estimateLiveRepoSizes h) >>= \case
|
||||||
|
Just (m, annexbranchsha) -> return m
|
||||||
|
Nothing -> do
|
||||||
|
-- Db.estimateLiveRepoSizes needs the
|
||||||
|
-- reposizes to be calculated first.
|
||||||
|
m <- getRepoSizes quiet
|
||||||
|
liftIO (Db.estimateLiveRepoSizes h) >>= \case
|
||||||
|
Just (m', annexbranchsha) -> return m'
|
||||||
|
Nothing -> return m
|
||||||
|
|
||||||
{- 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.
|
||||||
-}
|
-}
|
||||||
calcRepoSizes :: Bool -> MVar (Maybe (M.Map UUID RepoSize)) -> Annex (M.Map UUID RepoSize)
|
calcRepoSizes :: Bool -> MVar (Maybe (M.Map UUID RepoSize)) -> Annex (M.Map UUID RepoSize)
|
||||||
calcRepoSizes quiet rsv = bracket setup cleanup $ \h -> go h `onException` failed
|
calcRepoSizes quiet rsv = go `onException` failed
|
||||||
where
|
where
|
||||||
go h = do
|
go = do
|
||||||
|
h <- Db.getRepoSizeHandle
|
||||||
(oldsizemap, moldbranchsha) <- liftIO $ Db.getRepoSizes h
|
(oldsizemap, moldbranchsha) <- liftIO $ Db.getRepoSizes h
|
||||||
!sizemap <- case moldbranchsha of
|
!sizemap <- case moldbranchsha of
|
||||||
Nothing -> calculatefromscratch h
|
Nothing -> calculatefromscratch h
|
||||||
|
@ -70,10 +90,6 @@ calcRepoSizes quiet rsv = bracket setup cleanup $ \h -> go h `onException` faile
|
||||||
liftIO $ Db.setRepoSizes h sizemap branchsha
|
liftIO $ Db.setRepoSizes h sizemap branchsha
|
||||||
calcJournalledRepoSizes sizemap branchsha
|
calcJournalledRepoSizes sizemap branchsha
|
||||||
|
|
||||||
setup = Db.getRepoSizeHandle
|
|
||||||
|
|
||||||
cleanup _ = return ()
|
|
||||||
|
|
||||||
failed = do
|
failed = do
|
||||||
liftIO $ putMVar rsv (Just M.empty)
|
liftIO $ putMVar rsv (Just M.empty)
|
||||||
return M.empty
|
return M.empty
|
||||||
|
|
|
@ -12,7 +12,6 @@ module Command.MaxSize where
|
||||||
import Command
|
import Command
|
||||||
import qualified Remote
|
import qualified Remote
|
||||||
import Annex.RepoSize
|
import Annex.RepoSize
|
||||||
import Types.RepoSize
|
|
||||||
import Logs.MaxSize
|
import Logs.MaxSize
|
||||||
import Logs.Trust
|
import Logs.Trust
|
||||||
import Utility.DataUnits
|
import Utility.DataUnits
|
||||||
|
|
|
@ -25,7 +25,7 @@ module Database.RepoSize (
|
||||||
closeDb,
|
closeDb,
|
||||||
getRepoSizes,
|
getRepoSizes,
|
||||||
setRepoSizes,
|
setRepoSizes,
|
||||||
getLiveRepoSizes,
|
estimateLiveRepoSizes,
|
||||||
startingLiveSizeChange,
|
startingLiveSizeChange,
|
||||||
successfullyFinishedLiveSizeChange,
|
successfullyFinishedLiveSizeChange,
|
||||||
removeStaleLiveSizeChange,
|
removeStaleLiveSizeChange,
|
||||||
|
@ -291,10 +291,9 @@ getRecentChange u k = do
|
||||||
- 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.
|
||||||
-}
|
-}
|
||||||
getLiveRepoSizes :: RepoSizeHandle -> IO (Maybe (M.Map UUID RepoSize, Sha))
|
estimateLiveRepoSizes :: RepoSizeHandle -> IO (Maybe (M.Map UUID RepoSize, Sha))
|
||||||
getLiveRepoSizes (RepoSizeHandle (Just h)) = H.queryDb h $ do
|
estimateLiveRepoSizes (RepoSizeHandle (Just h)) = H.queryDb h $ do
|
||||||
getAnnexBranchCommit >>= \case
|
getAnnexBranchCommit >>= \case
|
||||||
Nothing -> return Nothing
|
|
||||||
Just annexbranchsha -> do
|
Just annexbranchsha -> do
|
||||||
sizechanges <- getSizeChanges
|
sizechanges <- getSizeChanges
|
||||||
livechanges <- getLiveSizeChanges
|
livechanges <- getLiveSizeChanges
|
||||||
|
@ -302,6 +301,7 @@ getLiveRepoSizes (RepoSizeHandle (Just h)) = H.queryDb h $ do
|
||||||
m <- M.fromList <$> forM reposizes
|
m <- M.fromList <$> forM reposizes
|
||||||
(go sizechanges livechanges)
|
(go sizechanges livechanges)
|
||||||
return (Just (m, annexbranchsha))
|
return (Just (m, annexbranchsha))
|
||||||
|
Nothing -> return Nothing
|
||||||
where
|
where
|
||||||
go
|
go
|
||||||
:: M.Map UUID FileSize
|
:: M.Map UUID FileSize
|
||||||
|
@ -350,4 +350,4 @@ getLiveRepoSizes (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 _ = []
|
||||||
getLiveRepoSizes (RepoSizeHandle Nothing) = return Nothing
|
estimateLiveRepoSizes (RepoSizeHandle Nothing) = return Nothing
|
||||||
|
|
15
Limit.hs
15
Limit.hs
|
@ -599,9 +599,9 @@ limitFullyBalanced :: Maybe UUID -> Annex GroupMap -> MkLimit Annex
|
||||||
limitFullyBalanced = limitFullyBalanced' "fullybalanced"
|
limitFullyBalanced = limitFullyBalanced' "fullybalanced"
|
||||||
|
|
||||||
limitFullyBalanced' :: String -> Maybe UUID -> Annex GroupMap -> MkLimit Annex
|
limitFullyBalanced' :: String -> Maybe UUID -> Annex GroupMap -> MkLimit Annex
|
||||||
limitFullyBalanced' = limitFullyBalanced'' $ \lu n key candidates -> do
|
limitFullyBalanced' = limitFullyBalanced'' $ \n key candidates -> do
|
||||||
maxsizes <- getMaxSizes
|
maxsizes <- getMaxSizes
|
||||||
sizemap <- getRepoSizes False
|
sizemap <- getLiveRepoSizes False
|
||||||
threshhold <- annexFullyBalancedThreshhold <$> Annex.getGitConfig
|
threshhold <- annexFullyBalancedThreshhold <$> Annex.getGitConfig
|
||||||
let toofull u =
|
let toofull u =
|
||||||
case (M.lookup u maxsizes, M.lookup u sizemap) of
|
case (M.lookup u maxsizes, M.lookup u sizemap) of
|
||||||
|
@ -633,7 +633,7 @@ repoHasSpace keysize inrepo (RepoSize reposize) (MaxSize maxsize)
|
||||||
reposize + keysize <= maxsize
|
reposize + keysize <= maxsize
|
||||||
|
|
||||||
limitFullyBalanced''
|
limitFullyBalanced''
|
||||||
:: (LiveUpdate -> Int -> Key -> S.Set UUID -> Annex (S.Set UUID))
|
:: (Int -> Key -> S.Set UUID -> Annex (S.Set UUID))
|
||||||
-> String
|
-> String
|
||||||
-> Maybe UUID
|
-> Maybe UUID
|
||||||
-> Annex GroupMap
|
-> Annex GroupMap
|
||||||
|
@ -651,7 +651,7 @@ limitFullyBalanced'' filtercandidates termname mu getgroupmap want =
|
||||||
getgroupmap (toGroup s) n want
|
getgroupmap (toGroup s) n want
|
||||||
|
|
||||||
limitFullyBalanced'''
|
limitFullyBalanced'''
|
||||||
:: (LiveUpdate -> Int -> Key -> S.Set UUID -> Annex (S.Set UUID))
|
:: (Int -> Key -> S.Set UUID -> Annex (S.Set UUID))
|
||||||
-> String
|
-> String
|
||||||
-> Maybe UUID
|
-> Maybe UUID
|
||||||
-> Annex GroupMap
|
-> Annex GroupMap
|
||||||
|
@ -663,8 +663,7 @@ limitFullyBalanced''' filtercandidates termname mu getgroupmap g n want = Right
|
||||||
gm <- getgroupmap
|
gm <- getgroupmap
|
||||||
let groupmembers = fromMaybe S.empty $
|
let groupmembers = fromMaybe S.empty $
|
||||||
M.lookup g (uuidsByGroup gm)
|
M.lookup g (uuidsByGroup gm)
|
||||||
-- TODO locking for liveupdate
|
candidates <- filtercandidates n key groupmembers
|
||||||
candidates <- filtercandidates lu n key groupmembers
|
|
||||||
let wanted = if S.null candidates
|
let wanted = if S.null candidates
|
||||||
then False
|
then False
|
||||||
else case (mu, M.lookup g (balancedPickerByGroup gm)) of
|
else case (mu, M.lookup g (balancedPickerByGroup gm)) of
|
||||||
|
@ -690,9 +689,9 @@ limitFullySizeBalanced :: Maybe UUID -> Annex GroupMap -> MkLimit Annex
|
||||||
limitFullySizeBalanced = limitFullySizeBalanced' "fullysizebalanced"
|
limitFullySizeBalanced = limitFullySizeBalanced' "fullysizebalanced"
|
||||||
|
|
||||||
limitFullySizeBalanced' :: String -> Maybe UUID -> Annex GroupMap -> MkLimit Annex
|
limitFullySizeBalanced' :: String -> Maybe UUID -> Annex GroupMap -> MkLimit Annex
|
||||||
limitFullySizeBalanced' = limitFullyBalanced'' $ \lu n key candidates -> do
|
limitFullySizeBalanced' = limitFullyBalanced'' $ \n key candidates -> do
|
||||||
maxsizes <- getMaxSizes
|
maxsizes <- getMaxSizes
|
||||||
sizemap <- getRepoSizes False
|
sizemap <- getLiveRepoSizes False
|
||||||
filterCandidatesFullySizeBalanced maxsizes sizemap n key candidates
|
filterCandidatesFullySizeBalanced maxsizes sizemap n key candidates
|
||||||
|
|
||||||
filterCandidatesFullySizeBalanced
|
filterCandidatesFullySizeBalanced
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue