From e2c44bf656bd632490c2a882021117f76e1ce064 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 24 Jul 2014 16:23:36 -0400 Subject: implement chunk logs Slightly tricky as they are not normal UUIDBased logs, but are instead maps from (uuid, chunksize) to chunkcount. This commit was sponsored by Frank Thomas. --- Logs.hs | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) (limited to 'Logs.hs') diff --git a/Logs.hs b/Logs.hs index c9d58157a5..ff7b7dcf06 100644 --- a/Logs.hs +++ b/Logs.hs @@ -14,6 +14,7 @@ import Types.Key data LogVariety = UUIDBasedLog | NewUUIDBasedLog + | ChunkLog Key | PresenceLog Key | OtherLog deriving (Show) @@ -24,6 +25,7 @@ getLogVariety :: FilePath -> Maybe LogVariety getLogVariety f | f `elem` topLevelUUIDBasedLogs = Just UUIDBasedLog | isRemoteStateLog f = Just NewUUIDBasedLog + | isChunkLog f = ChunkLog <$> chunkLogFileKey f | isMetaDataLog f || f `elem` otherLogs = Just OtherLog | otherwise = PresenceLog <$> firstJust (presenceLogs f) @@ -133,6 +135,25 @@ remoteStateLogExt = ".log.rmt" isRemoteStateLog :: FilePath -> Bool isRemoteStateLog path = remoteStateLogExt `isSuffixOf` path +{- The filename of the chunk log for a given key. -} +chunkLogFile :: Key -> FilePath +chunkLogFile key = hashDirLower key keyFile key ++ chunkLogExt + +chunkLogFileKey :: FilePath -> Maybe Key +chunkLogFileKey path + | ext == chunkLogExt = fileKey base + | otherwise = Nothing + where + file = takeFileName path + (base, ext) = splitAt (length file - extlen) file + extlen = length chunkLogExt + +chunkLogExt :: String +chunkLogExt = ".log.cnk" + +isChunkLog :: FilePath -> Bool +isChunkLog path = chunkLogExt `isSuffixOf` path + {- The filename of the metadata log for a given key. -} metaDataLogFile :: Key -> FilePath metaDataLogFile key = hashDirLower key keyFile key ++ metaDataLogExt @@ -146,20 +167,23 @@ isMetaDataLog path = metaDataLogExt `isSuffixOf` path prop_logs_sane :: Key -> Bool prop_logs_sane dummykey = and [ isNothing (getLogVariety "unknown") - , expect isUUIDBasedLog (getLogVariety uuidLog) - , expect isPresenceLog (getLogVariety $ locationLogFile dummykey) - , expect isPresenceLog (getLogVariety $ urlLogFile dummykey) - , expect isNewUUIDBasedLog (getLogVariety $ remoteStateLogFile dummykey) - , expect isOtherLog (getLogVariety $ metaDataLogFile dummykey) - , expect isOtherLog (getLogVariety $ numcopiesLog) + , expect gotUUIDBasedLog (getLogVariety uuidLog) + , expect gotPresenceLog (getLogVariety $ locationLogFile dummykey) + , expect gotPresenceLog (getLogVariety $ urlLogFile dummykey) + , expect gotNewUUIDBasedLog (getLogVariety $ remoteStateLogFile dummykey) + , expect gotChunkLog (getLogVariety $ chunkLogFile dummykey) + , expect gotOtherLog (getLogVariety $ metaDataLogFile dummykey) + , expect gotOtherLog (getLogVariety $ numcopiesLog) ] where expect = maybe False - isUUIDBasedLog UUIDBasedLog = True - isUUIDBasedLog _ = False - isNewUUIDBasedLog NewUUIDBasedLog = True - isNewUUIDBasedLog _ = False - isPresenceLog (PresenceLog k) = k == dummykey - isPresenceLog _ = False - isOtherLog OtherLog = True - isOtherLog _ = False + gotUUIDBasedLog UUIDBasedLog = True + gotUUIDBasedLog _ = False + gotNewUUIDBasedLog NewUUIDBasedLog = True + gotNewUUIDBasedLog _ = False + gotChunkLog (ChunkLog k) = k == dummykey + gotChunkLog _ = False + gotPresenceLog (PresenceLog k) = k == dummykey + gotPresenceLog _ = False + gotOtherLog OtherLog = True + gotOtherLog _ = False -- cgit v1.2.3