use same hash directories for chunked key as are used for its parent
This avoids a proliferation of hash directories when using new-style chunking, and should improve performance since chunks are accessed in sequence and so should have a common locality. Of course, when a chunked key is encrypted, its hash directories have no relation to the parent key. This commit was sponsored by Christian Kellermann.
This commit is contained in:
parent
1755c5de40
commit
8f93982df6
3 changed files with 20 additions and 2 deletions
|
@ -421,6 +421,7 @@ keyPaths key = map (keyPath key) annexHashes
|
||||||
- which do not allow using a directory "XX" when "xx" already exists.
|
- which do not allow using a directory "XX" when "xx" already exists.
|
||||||
- To support that, most repositories use the lower case hash for new data. -}
|
- To support that, most repositories use the lower case hash for new data. -}
|
||||||
type Hasher = Key -> FilePath
|
type Hasher = Key -> FilePath
|
||||||
|
|
||||||
annexHashes :: [Hasher]
|
annexHashes :: [Hasher]
|
||||||
annexHashes = [hashDirLower, hashDirMixed]
|
annexHashes = [hashDirLower, hashDirMixed]
|
||||||
|
|
||||||
|
@ -428,12 +429,12 @@ hashDirMixed :: Hasher
|
||||||
hashDirMixed k = addTrailingPathSeparator $ take 2 dir </> drop 2 dir
|
hashDirMixed k = addTrailingPathSeparator $ take 2 dir </> drop 2 dir
|
||||||
where
|
where
|
||||||
dir = take 4 $ display_32bits_as_dir =<< [a,b,c,d]
|
dir = take 4 $ display_32bits_as_dir =<< [a,b,c,d]
|
||||||
ABCD (a,b,c,d) = md5 $ md5FilePath $ key2file k
|
ABCD (a,b,c,d) = md5 $ md5FilePath $ key2file $ nonChunkKey k
|
||||||
|
|
||||||
hashDirLower :: Hasher
|
hashDirLower :: Hasher
|
||||||
hashDirLower k = addTrailingPathSeparator $ take 3 dir </> drop 3 dir
|
hashDirLower k = addTrailingPathSeparator $ take 3 dir </> drop 3 dir
|
||||||
where
|
where
|
||||||
dir = take 6 $ md5s $ md5FilePath $ key2file k
|
dir = take 6 $ md5s $ md5FilePath $ key2file $ nonChunkKey k
|
||||||
|
|
||||||
{- modified version of display_32bits_as_hex from Data.Hash.MD5
|
{- modified version of display_32bits_as_hex from Data.Hash.MD5
|
||||||
- Copyright (C) 2001 Ian Lynagh
|
- Copyright (C) 2001 Ian Lynagh
|
||||||
|
|
12
Types/Key.hs
12
Types/Key.hs
|
@ -13,6 +13,8 @@ module Types.Key (
|
||||||
stubKey,
|
stubKey,
|
||||||
key2file,
|
key2file,
|
||||||
file2key,
|
file2key,
|
||||||
|
isChunkKey,
|
||||||
|
nonChunkKey,
|
||||||
|
|
||||||
prop_idempotent_key_encode,
|
prop_idempotent_key_encode,
|
||||||
prop_idempotent_key_decode
|
prop_idempotent_key_decode
|
||||||
|
@ -47,6 +49,16 @@ stubKey = Key
|
||||||
, keyChunkNum = Nothing
|
, keyChunkNum = Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isChunkKey :: Key -> Bool
|
||||||
|
isChunkKey k = isJust (keyChunkSize k) && isJust (keyChunkNum k)
|
||||||
|
|
||||||
|
-- Gets the parent of a chunk key.
|
||||||
|
nonChunkKey :: Key -> Key
|
||||||
|
nonChunkKey k = k
|
||||||
|
{ keyChunkSize = Nothing
|
||||||
|
, keyChunkNum = Nothing
|
||||||
|
}
|
||||||
|
|
||||||
fieldSep :: Char
|
fieldSep :: Char
|
||||||
fieldSep = '-'
|
fieldSep = '-'
|
||||||
|
|
||||||
|
|
|
@ -36,3 +36,8 @@ string, but where that would normally encode the bits using the 16 characters
|
||||||
0-9a-f, this instead uses the 32 characters "0123456789zqjxkmvwgpfZQJXKMVWGPF".
|
0-9a-f, this instead uses the 32 characters "0123456789zqjxkmvwgpfZQJXKMVWGPF".
|
||||||
The first 2 letters of the resulting string are the first directory, and the
|
The first 2 letters of the resulting string are the first directory, and the
|
||||||
second 2 are the second directory.
|
second 2 are the second directory.
|
||||||
|
|
||||||
|
## chunk keys
|
||||||
|
|
||||||
|
The same hash directory is used for a chunk key as would be used for the
|
||||||
|
key that it's a chunk of.
|
||||||
|
|
Loading…
Add table
Reference in a new issue