2014-07-24 20:23:36 +00:00
|
|
|
{- Chunk logs.
|
|
|
|
-
|
|
|
|
- An object can be stored in chunked for on a remote; these logs keep
|
|
|
|
- track of the chunk size used, and the number of chunks.
|
|
|
|
-
|
|
|
|
- It's possible for a single object to be stored multiple times on the
|
|
|
|
- same remote using different chunk sizes. So, while this is a MapLog, it
|
|
|
|
- is not a normal UUIDBased log. Intead, it's a map from UUID and chunk
|
|
|
|
- size to number of chunks.
|
|
|
|
-
|
|
|
|
- Format: "timestamp uuid:chunksize chunkcount"
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2014 Joey Hess <id@joeyh.name>
|
2014-07-24 20:23:36 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2014-07-24 20:23:36 +00:00
|
|
|
-}
|
|
|
|
|
2014-07-28 17:19:08 +00:00
|
|
|
module Logs.Chunk (
|
|
|
|
ChunkMethod(..),
|
|
|
|
ChunkSize,
|
|
|
|
ChunkCount,
|
|
|
|
chunksStored,
|
|
|
|
chunksRemoved,
|
|
|
|
getCurrentChunks,
|
|
|
|
) where
|
2014-07-24 20:23:36 +00:00
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2014-07-24 20:23:36 +00:00
|
|
|
import Logs
|
|
|
|
import Logs.MapLog
|
|
|
|
import qualified Annex.Branch
|
|
|
|
import Logs.Chunk.Pure
|
2015-01-28 21:17:26 +00:00
|
|
|
import qualified Annex
|
2014-07-24 20:23:36 +00:00
|
|
|
|
|
|
|
import qualified Data.Map as M
|
|
|
|
|
2014-07-28 17:19:08 +00:00
|
|
|
chunksStored :: UUID -> Key -> ChunkMethod -> ChunkCount -> Annex ()
|
|
|
|
chunksStored u k chunkmethod chunkcount = do
|
2020-12-23 19:21:33 +00:00
|
|
|
c <- currentVectorClock
|
2015-01-28 21:17:26 +00:00
|
|
|
config <- Annex.getGitConfig
|
|
|
|
Annex.Branch.change (chunkLogFile config k) $
|
2019-01-10 17:23:42 +00:00
|
|
|
buildLog . changeMapLog c (u, chunkmethod) chunkcount . parseLog
|
2014-07-24 20:23:36 +00:00
|
|
|
|
2014-07-28 17:19:08 +00:00
|
|
|
chunksRemoved :: UUID -> Key -> ChunkMethod -> Annex ()
|
|
|
|
chunksRemoved u k chunkmethod = chunksStored u k chunkmethod 0
|
2014-07-24 20:23:36 +00:00
|
|
|
|
2014-07-28 17:19:08 +00:00
|
|
|
getCurrentChunks :: UUID -> Key -> Annex [(ChunkMethod, ChunkCount)]
|
2015-01-28 21:17:26 +00:00
|
|
|
getCurrentChunks u k = do
|
|
|
|
config <- Annex.getGitConfig
|
2019-01-10 17:23:42 +00:00
|
|
|
select . parseLog <$> Annex.Branch.get (chunkLogFile config k)
|
2014-07-24 20:23:36 +00:00
|
|
|
where
|
2014-07-28 17:19:08 +00:00
|
|
|
select = filter (\(_m, ct) -> ct > 0)
|
|
|
|
. map (\((_ku, m), l) -> (m, value l))
|
2014-07-24 20:23:36 +00:00
|
|
|
. M.toList
|
2014-07-28 17:19:08 +00:00
|
|
|
. M.filterWithKey (\(ku, _m) _ -> ku == u)
|