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
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
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
|
|
|
|
|
|
|
import Common.Annex
|
|
|
|
import Logs
|
|
|
|
import Logs.MapLog
|
|
|
|
import qualified Annex.Branch
|
|
|
|
import Logs.Chunk.Pure
|
|
|
|
|
|
|
|
import qualified Data.Map as M
|
|
|
|
import Data.Time.Clock.POSIX
|
|
|
|
|
2014-07-28 17:19:08 +00:00
|
|
|
chunksStored :: UUID -> Key -> ChunkMethod -> ChunkCount -> Annex ()
|
|
|
|
chunksStored u k chunkmethod chunkcount = do
|
2014-07-24 20:23:36 +00:00
|
|
|
ts <- liftIO getPOSIXTime
|
|
|
|
Annex.Branch.change (chunkLogFile k) $
|
2014-07-28 17:19:08 +00:00
|
|
|
showLog . changeMapLog ts (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)]
|
2014-07-24 20:23:36 +00:00
|
|
|
getCurrentChunks u k = select . parseLog <$> Annex.Branch.get (chunkLogFile k)
|
|
|
|
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)
|