migrate: Avoid re-checksumming when migrating from hashE to hash backend.

This commit is contained in:
Joey Hess 2014-07-10 17:06:04 -04:00
parent 564de5e508
commit 9d71903c2f
7 changed files with 34 additions and 12 deletions

View file

@ -44,6 +44,7 @@ genBackend hash = Just Backend
, getKey = keyValue hash , getKey = keyValue hash
, fsckKey = Just $ checkKeyChecksum hash , fsckKey = Just $ checkKeyChecksum hash
, canUpgradeKey = Just needsUpgrade , canUpgradeKey = Just needsUpgrade
, fastMigrate = Just trivialMigrate
} }
genBackendE :: Hash -> Maybe Backend genBackendE :: Hash -> Maybe Backend
@ -129,6 +130,15 @@ needsUpgrade :: Key -> Bool
needsUpgrade key = "\\" `isPrefixOf` keyHash key || needsUpgrade key = "\\" `isPrefixOf` keyHash key ||
any (not . validExtension) (takeExtensions $ keyName key) any (not . validExtension) (takeExtensions $ keyName key)
{- Fast migration from hashE to hash backend. (Optimisation) -}
trivialMigrate :: Key -> Backend -> Maybe Key
trivialMigrate oldkey newbackend
| keyBackendName oldkey == name newbackend ++ "E" = Just $ oldkey
{ keyName = keyHash oldkey
, keyBackendName = name newbackend
}
| otherwise = Nothing
hashFile :: Hash -> FilePath -> Integer -> Annex String hashFile :: Hash -> FilePath -> Integer -> Annex String
hashFile hash file filesize = liftIO $ go hash hashFile hash file filesize = liftIO $ go hash
where where

View file

@ -24,6 +24,7 @@ backend = Backend
, getKey = const $ return Nothing , getKey = const $ return Nothing
, fsckKey = Nothing , fsckKey = Nothing
, canUpgradeKey = Nothing , canUpgradeKey = Nothing
, fastMigrate = Nothing
} }
{- Every unique url has a corresponding key. -} {- Every unique url has a corresponding key. -}

View file

@ -22,6 +22,7 @@ backend = Backend
, getKey = keyValue , getKey = keyValue
, fsckKey = Nothing , fsckKey = Nothing
, canUpgradeKey = Nothing , canUpgradeKey = Nothing
, fastMigrate = Nothing
} }
{- The key includes the file size, modification time, and the {- The key includes the file size, modification time, and the

View file

@ -11,7 +11,7 @@ import Common.Annex
import Command import Command
import Backend import Backend
import qualified Types.Key import qualified Types.Key
import qualified Types.Backend import Types.Backend (canUpgradeKey, fastMigrate)
import Types.KeySource import Types.KeySource
import Annex.Content import Annex.Content
import qualified Command.ReKey import qualified Command.ReKey
@ -51,8 +51,7 @@ start file key = do
upgradableKey :: Backend -> Key -> Bool upgradableKey :: Backend -> Key -> Bool
upgradableKey backend key = isNothing (Types.Key.keySize key) || backendupgradable upgradableKey backend key = isNothing (Types.Key.keySize key) || backendupgradable
where where
backendupgradable = maybe False (\a -> a key) backendupgradable = maybe False (\a -> a key) (canUpgradeKey backend)
(Types.Backend.canUpgradeKey backend)
{- Store the old backend's key in the new backend {- Store the old backend's key in the new backend
- The old backend's key is not dropped from it, because there may - The old backend's key is not dropped from it, because there may
@ -67,15 +66,22 @@ perform :: FilePath -> Key -> Backend -> Backend -> CommandPerform
perform file oldkey oldbackend newbackend = go =<< genkey perform file oldkey oldbackend newbackend = go =<< genkey
where where
go Nothing = stop go Nothing = stop
go (Just newkey) = stopUnless checkcontent $ finish newkey go (Just (newkey, knowngoodcontent))
| knowngoodcontent = finish newkey
| otherwise = stopUnless checkcontent $ finish newkey
checkcontent = Command.Fsck.checkBackend oldbackend oldkey $ Just file checkcontent = Command.Fsck.checkBackend oldbackend oldkey $ Just file
finish newkey = stopUnless (Command.ReKey.linkKey oldkey newkey) $ finish newkey = stopUnless (Command.ReKey.linkKey oldkey newkey) $
next $ Command.ReKey.cleanup file oldkey newkey next $ Command.ReKey.cleanup file oldkey newkey
genkey = do genkey = case maybe Nothing (\fm -> fm oldkey newbackend) (fastMigrate oldbackend) of
content <- calcRepo $ gitAnnexLocation oldkey Just newkey -> return $ Just (newkey, True)
let source = KeySource Nothing -> do
{ keyFilename = file content <- calcRepo $ gitAnnexLocation oldkey
, contentLocation = content let source = KeySource
, inodeCache = Nothing { keyFilename = file
} , contentLocation = content
liftM fst <$> genKey source (Just newbackend) , inodeCache = Nothing
}
v <- genKey source (Just newbackend)
return $ case v of
Just (newkey, _) -> Just (newkey, False)
_ -> Nothing

View file

@ -17,6 +17,7 @@ data BackendA a = Backend
, getKey :: KeySource -> a (Maybe Key) , getKey :: KeySource -> a (Maybe Key)
, fsckKey :: Maybe (Key -> FilePath -> a Bool) , fsckKey :: Maybe (Key -> FilePath -> a Bool)
, canUpgradeKey :: Maybe (Key -> Bool) , canUpgradeKey :: Maybe (Key -> Bool)
, fastMigrate :: Maybe (Key -> BackendA a -> Maybe Key)
} }
instance Show (BackendA a) where instance Show (BackendA a) where

1
debian/changelog vendored
View file

@ -3,6 +3,7 @@ git-annex (5.20140710) UNRELEASED; urgency=medium
* Fix minor FD leak in journal code. * Fix minor FD leak in journal code.
* direct: Fix handling of case where a work tree subdirectory cannot * direct: Fix handling of case where a work tree subdirectory cannot
be written to due to permissions. be written to due to permissions.
* migrate: Avoid re-checksumming when migrating from hashE to hash backend.
-- Joey Hess <joeyh@debian.org> Wed, 09 Jul 2014 23:29:21 -0400 -- Joey Hess <joeyh@debian.org> Wed, 09 Jul 2014 23:29:21 -0400

View file

@ -12,3 +12,5 @@ dear Joey and everybody else,
> Certianly doable, for $hashE to $hash. Probably about an hour's work. > Certianly doable, for $hashE to $hash. Probably about an hour's work.
> --[[Joey]] > --[[Joey]]
>> [[done]] --[[Joey]]