implement fullbalanced=group:N

Rebalancing this when it gets into a suboptimal situation will need
further work.
This commit is contained in:
Joey Hess 2024-08-20 13:50:47 -04:00
parent d4b2f8201d
commit 476d223bce
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 28 additions and 15 deletions

View file

@ -592,7 +592,19 @@ limitBalanced mu getgroupmap groupname = do
}
limitFullyBalanced :: Maybe UUID -> Annex GroupMap -> MkLimit Annex
limitFullyBalanced mu getgroupmap groupname = Right $ MatchFiles
limitFullyBalanced mu getgroupmap want =
case splitc ':' want of
[g] -> go g 1
[g, n] -> maybe
(Left "bad number for fullybalanced")
(go g)
(readish n)
_ -> Left "bad value for fullybalanced"
where
go s n = limitFullyBalanced' mu getgroupmap (toGroup s) n want
limitFullyBalanced' :: Maybe UUID -> Annex GroupMap -> Group -> Int -> MkLimit Annex
limitFullyBalanced' mu getgroupmap g n want = Right $ MatchFiles
{ matchAction = const $ checkKey $ \key -> do
gm <- getgroupmap
let groupmembers = fromMaybe S.empty $
@ -611,16 +623,14 @@ limitFullyBalanced mu getgroupmap groupname = Right $ MatchFiles
return $ if S.null candidates
then False
else case (mu, M.lookup g (balancedPickerByGroup gm)) of
(Just u, Just picker) -> u == picker candidates key
(Just u, Just picker) -> u == picker candidates key n
_ -> False
, matchNeedsFileName = False
, matchNeedsFileContent = False
, matchNeedsKey = True
, matchNeedsLocationLog = False
, matchDesc = "fullybalanced" =? groupname
, matchDesc = "fullybalanced" =? want
}
where
g = toGroup groupname
{- Adds a limit to skip files not using a specified key-value backend. -}
addInBackend :: String -> Annex ()