diff options
author | Joey Hess <joey@kitenet.net> | 2011-03-15 23:58:27 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-03-15 23:58:27 -0400 |
commit | dd5448eb075c3774aa173cb9f2e4344ce62b3e13 (patch) | |
tree | f79857b2a8923f6353b7a29daaec7c1d37ac8687 | |
parent | 6c412fb9f55155b0b7bf58d578e51640514ec562 (diff) |
added 2 level hashing
This means there can be 1024 subdirs, each with up to 1024 sub-subdirs.
So with hundreds of millions of annexed objects, each leaf directory will
have only a few files on average.
-rw-r--r-- | LocationLog.hs | 5 | ||||
-rw-r--r-- | Locations.hs | 16 |
2 files changed, 12 insertions, 9 deletions
diff --git a/LocationLog.hs b/LocationLog.hs index f778df386..a939af825 100644 --- a/LocationLog.hs +++ b/LocationLog.hs @@ -123,11 +123,6 @@ logNow s u = do now <- getPOSIXTime return $ LogLine now s u -{- Returns the filename of the log file for a given key. -} -logFile :: Git.Repo -> Key -> String -logFile repo key = - gitStateDir repo ++ keyFile key ++ ".log" - {- Returns a list of repository UUIDs that, according to the log, have - the value of a key. -} keyLocations :: Git.Repo -> Key -> IO [UUID] diff --git a/Locations.hs b/Locations.hs index 9ffcd9f42..b2d31a1bf 100644 --- a/Locations.hs +++ b/Locations.hs @@ -19,6 +19,7 @@ module Locations ( gitAnnexBadDir, gitAnnexUnusedLog, isLinkToAnnex, + logFile, prop_idempotent_fileKey ) where @@ -66,7 +67,7 @@ objectDir = addTrailingPathSeparator $ annexDir </> "objects" {- Annexed file's location relative to the .git directory. -} annexLocation :: Key -> FilePath -annexLocation key = objectDir </> f </> f +annexLocation key = objectDir </> hashDir key </> f </> f where f = keyFile key @@ -109,6 +110,11 @@ gitAnnexUnusedLog r = gitAnnexDir r </> "unused" isLinkToAnnex :: FilePath -> Bool isLinkToAnnex s = ("/.git/" ++ objectDir) `isInfixOf` s +{- The filename of the log file for a given key. -} +logFile :: Git.Repo -> Key -> String +logFile repo key = + gitStateDir repo ++ hashDir key ++ keyFile key ++ ".log" + {- Converts a key into a filename fragment. - - Escape "/" in the key name, to keep a flat tree of files and avoid @@ -137,11 +143,13 @@ prop_idempotent_fileKey :: String -> Bool prop_idempotent_fileKey s = Just k == fileKey (keyFile k) where k = stubKey { keyName = s, keyBackendName = "test" } -{- Given a filename, generates a short directory name to put it in, +{- Given a key, generates a short directory name to put it in, - to do hashing to protect against filesystems that dislike having - many items in a single directory. -} -hashDir :: FilePath -> FilePath -hashDir s = take 2 $ abcd_to_dir $ md5 (Str s) +hashDir :: Key -> FilePath +hashDir k = addTrailingPathSeparator $ take 2 dir </> drop 2 dir + where + dir = take 4 $ abcd_to_dir $ md5 $ Str $ show k abcd_to_dir :: ABCD -> String abcd_to_dir (ABCD (a,b,c,d)) = concat $ map display_32bits_as_dir [a,b,c,d] |