99a126bebb
The idea is that upon a merge of the git-annex branch, or a commit to the git-annex branch, the reposize database will be updated. So it should always accurately reflect the location log sizes, but it will often be behind the actual current sizes. Annex.reposizes will start with the value from the database, and get updated with each transfer, so it will reflect a process's best understanding of the current sizes. When there are multiple processes all transferring to the same repo, Annex.reposize will not reflect transfers made by the other processes since the current process started. So when using balanced preferred content, it may make suboptimal choices, including trying to transfer content to the repo when another process has already filled it up. But this is the same as if there are multiple processes running on ifferent machines, so is acceptable. The reposize will eventually get an accurate value reflecting changes made by other processes or in other repos.
49 lines
1.3 KiB
Haskell
49 lines
1.3 KiB
Haskell
{- git-annex maxsize log
|
|
-
|
|
- Copyright 2024 Joey Hess <id@joeyh.name>
|
|
-
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
-}
|
|
|
|
module Logs.MaxSize (
|
|
MaxSize(..),
|
|
getMaxSizes,
|
|
recordMaxSize,
|
|
) where
|
|
|
|
import qualified Annex
|
|
import Annex.Common
|
|
import Types.RepoSize
|
|
import Logs
|
|
import Logs.UUIDBased
|
|
import Logs.MapLog
|
|
import qualified Annex.Branch
|
|
|
|
import qualified Data.Map as M
|
|
import Data.ByteString.Builder
|
|
import qualified Data.Attoparsec.ByteString as A
|
|
|
|
getMaxSizes :: Annex (M.Map UUID MaxSize)
|
|
getMaxSizes = maybe loadMaxSizes return =<< Annex.getState Annex.maxsizes
|
|
|
|
loadMaxSizes :: Annex (M.Map UUID MaxSize)
|
|
loadMaxSizes = do
|
|
maxsizes <- M.map value . fromMapLog . parseLogNew parseMaxSize
|
|
<$> Annex.Branch.get maxSizeLog
|
|
Annex.changeState $ \s -> s { Annex.maxsizes = Just maxsizes }
|
|
return maxsizes
|
|
|
|
recordMaxSize :: UUID -> MaxSize -> Annex ()
|
|
recordMaxSize uuid maxsize = do
|
|
c <- currentVectorClock
|
|
Annex.Branch.change (Annex.Branch.RegardingUUID [uuid]) maxSizeLog $
|
|
(buildLogNew buildMaxSize)
|
|
. changeLog c uuid maxsize
|
|
. parseLogNew parseMaxSize
|
|
|
|
buildMaxSize :: MaxSize -> Builder
|
|
buildMaxSize (MaxSize n) = byteString (encodeBS (show n))
|
|
|
|
parseMaxSize :: A.Parser MaxSize
|
|
parseMaxSize = maybe (fail "maxsize parse failed") (pure . MaxSize)
|
|
. readish . decodeBS =<< A.takeByteString
|