From 64afbb0b938e343c1c4cbc61bf78a3a02124093e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 16 Jun 2024 15:07:48 -0400 Subject: [PATCH] don't count clusters as copies, continued Handled limitCopies, as well as everything using fromNumCopies and fromMinCopies. This should be everything, probably. Note that, git-annex info displays a count of repositories, which still includes cluster. I think that's ok. It would be possible to filter out clusters there, but to the user they're pretty much just another repository. The numcopies displayed by eg `git-annex info .` does not include clusters. --- Annex/Drop.hs | 2 +- Annex/NumCopies.hs | 10 ++++++++-- Command/Drop.hs | 2 +- Command/Fsck.hs | 2 +- Limit.hs | 5 +++-- doc/todo/git-annex_proxies.mdwn | 6 +----- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Annex/Drop.hs b/Annex/Drop.hs index f59d6f17d6..ccbc18e6e1 100644 --- a/Annex/Drop.hs +++ b/Annex/Drop.hs @@ -58,7 +58,7 @@ handleDropsFrom locs rs reason fromhere key afile si preverified runner = do getcopies fs = do (untrusted, have) <- trustPartition UnTrusted locs (numcopies, mincopies) <- getSafestNumMinCopies' afile key fs - return (length have, numcopies, mincopies, S.fromList untrusted) + return (numCopiesCount have, numcopies, mincopies, S.fromList untrusted) {- Check that we have enough copies still to drop the content. - When the remote being dropped from is untrusted, it was not diff --git a/Annex/NumCopies.hs b/Annex/NumCopies.hs index e8dc720b20..4d680c8411 100644 --- a/Annex/NumCopies.hs +++ b/Annex/NumCopies.hs @@ -20,6 +20,7 @@ module Annex.NumCopies ( defaultNumCopies, numCopiesCheck, numCopiesCheck', + numCopiesCheck'', numCopiesCount, verifyEnoughCopiesToDrop, verifiableCopies, @@ -199,12 +200,17 @@ numCopiesCheck file key vs = do numCopiesCheck' :: RawFilePath -> (Int -> Int -> v) -> [UUID] -> Annex v numCopiesCheck' file vs have = do - needed <- fromNumCopies . fst <$> getFileNumMinCopies file + needed <- fst <$> getFileNumMinCopies file let nhave = numCopiesCount have explain (ActionItemTreeFile file) $ Just $ UnquotedString $ "has " ++ show nhave ++ " " ++ pluralCopies nhave ++ ", and the configured annex.numcopies is " ++ show needed - return $ nhave `vs` needed + return $ numCopiesCheck'' have vs needed + +numCopiesCheck'' :: [UUID] -> (Int -> Int -> v) -> NumCopies -> v +numCopiesCheck'' have vs needed = + let nhave = numCopiesCount have + in nhave `vs` fromNumCopies needed {- When a key is logged as present in a node of the cluster, - the cluster's UUID will also be in the list, but is not a diff --git a/Command/Drop.hs b/Command/Drop.hs index 2fcb5d6ebb..14702a94c0 100644 --- a/Command/Drop.hs +++ b/Command/Drop.hs @@ -253,7 +253,7 @@ checkDropAuto automode mremote afile key a = uuid <- getUUID let remoteuuid = fromMaybe uuid $ Remote.uuid <$> mremote locs' <- trustExclude UnTrusted $ filter (/= remoteuuid) locs - if length locs' >= fromNumCopies numcopies + if numCopiesCheck'' locs' (>=) numcopies then a numcopies mincopies else stop | otherwise = a numcopies mincopies diff --git a/Command/Fsck.hs b/Command/Fsck.hs index f08d09f89f..0acb018718 100644 --- a/Command/Fsck.hs +++ b/Command/Fsck.hs @@ -573,7 +573,7 @@ checkKeyNumCopies key afile numcopies = do locs <- loggedLocations key (untrustedlocations, otherlocations) <- trustPartition UnTrusted locs (deadlocations, safelocations) <- trustPartition DeadTrusted otherlocations - let present = length safelocations + let present = numCopiesCount safelocations if present < fromNumCopies numcopies then ifM (checkDead key) ( do diff --git a/Limit.hs b/Limit.hs index 5a343a547f..252b3dd493 100644 --- a/Limit.hs +++ b/Limit.hs @@ -408,7 +408,7 @@ limitCopies want = case splitc ':' want of go' n good notpresent key = do us <- filter (`S.notMember` notpresent) <$> (filterM good =<< Remote.keyLocations key) - return $ length us >= n + return $ numCopiesCount us >= n checktrust checker u = checker <$> lookupTrust u checkgroup g u = S.member g <$> lookupGroups u parsetrustspec s @@ -442,7 +442,8 @@ limitLackingCopies desc approx want = case readish want of MatchingUserInfo {} -> approxNumCopies us <- filter (`S.notMember` notpresent) <$> (trustExclude UnTrusted =<< Remote.keyLocations key) - return $ fromNumCopies numcopies - length us >= needed + let vs nhave numcopies' = numcopies' - nhave >= needed + return $ numCopiesCheck'' us vs numcopies approxNumCopies = fromMaybe defaultNumCopies <$> getGlobalNumCopies {- Match keys that are unused. diff --git a/doc/todo/git-annex_proxies.mdwn b/doc/todo/git-annex_proxies.mdwn index ff317303f0..78fe15361c 100644 --- a/doc/todo/git-annex_proxies.mdwn +++ b/doc/todo/git-annex_proxies.mdwn @@ -48,11 +48,7 @@ For June's work on [[design/passthrough_proxy]], implementation plan: * Omit cluster UUIDs when constructing drop proofs, since lockcontent will always fail on a cluster. (done) -* Don't count cluster UUID as a copy. (Including in `whereis` display.) - - Work in progress. fromNumCopies is sometimes used to get a - number that is compared with a list of UUIDs. And limitCopies doesn't - use numcopies machinery +* Don't count cluster UUID as a copy. (done) * Basic proxying to special remote support (non-streaming). -- 2.39.5