take maxsize into account for balanced preferred content

This is very innefficient, it will need to be optimised not to
calculate the sizes of repos every time.

Also, fixed a bug in balancedPicker that caused it to pick a too high
index when some repos were excluded due to being full.
This commit is contained in:
Joey Hess 2024-08-13 11:00:20 -04:00
parent b201792391
commit 745bc5c547
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 60 additions and 11 deletions

View file

@ -17,6 +17,9 @@ import Annex.Content
import Annex.WorkTree
import Annex.UUID
import Annex.Magic
import Annex.RepoSize
import Types.RepoSize
import Logs.MaxSize
import Annex.Link
import Types.Link
import Logs.Trust
@ -590,14 +593,24 @@ limitBalanced mu getgroupmap groupname = do
limitFullyBalanced :: Maybe UUID -> Annex GroupMap -> MkLimit Annex
limitFullyBalanced mu getgroupmap groupname = Right $ MatchFiles
{ matchAction = const $ checkKey $ \key -> do
{ matchAction = \notpresent -> checkKey $ \key -> do
gm <- getgroupmap
let groupmembers = fromMaybe S.empty $
M.lookup g (uuidsByGroup gm)
-- TODO free space checking
return $ case (mu, M.lookup g (balancedPickerByGroup gm)) of
(Just u, Just picker) -> u == picker groupmembers key
_ -> False
maxsizes <- getMaxSizes
-- XXX do not calc this every time!
sizemap <- calcRepoSizes
let hasspace u = case (M.lookup u maxsizes, M.lookup u sizemap) of
(Just (MaxSize maxsize), Just (RepoSize reposize)) ->
reposize + fromMaybe 0 (fromKey keySize key)
<= maxsize
_ -> True
let candidates = S.filter hasspace groupmembers
return $ if S.null candidates
then False
else case (mu, M.lookup g (balancedPickerByGroup gm)) of
(Just u, Just picker) -> u == picker candidates key
_ -> False
, matchNeedsFileName = False
, matchNeedsFileContent = False
, matchNeedsKey = True