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
, fsckKey = Just $ checkKeyChecksum hash
, canUpgradeKey = Just needsUpgrade
, fastMigrate = Just trivialMigrate
}
genBackendE :: Hash -> Maybe Backend
@ -129,6 +130,15 @@ needsUpgrade :: Key -> Bool
needsUpgrade key = "\\" `isPrefixOf` keyHash 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 file filesize = liftIO $ go hash
where

View file

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

View file

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

View file

@ -11,7 +11,7 @@ import Common.Annex
import Command
import Backend
import qualified Types.Key
import qualified Types.Backend
import Types.Backend (canUpgradeKey, fastMigrate)
import Types.KeySource
import Annex.Content
import qualified Command.ReKey
@ -51,8 +51,7 @@ start file key = do
upgradableKey :: Backend -> Key -> Bool
upgradableKey backend key = isNothing (Types.Key.keySize key) || backendupgradable
where
backendupgradable = maybe False (\a -> a key)
(Types.Backend.canUpgradeKey backend)
backendupgradable = maybe False (\a -> a key) (canUpgradeKey backend)
{- Store the old backend's key in the new backend
- 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
where
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
finish newkey = stopUnless (Command.ReKey.linkKey oldkey newkey) $
next $ Command.ReKey.cleanup file oldkey newkey
genkey = do
content <- calcRepo $ gitAnnexLocation oldkey
let source = KeySource
{ keyFilename = file
, contentLocation = content
, inodeCache = Nothing
}
liftM fst <$> genKey source (Just newbackend)
genkey = case maybe Nothing (\fm -> fm oldkey newbackend) (fastMigrate oldbackend) of
Just newkey -> return $ Just (newkey, True)
Nothing -> do
content <- calcRepo $ gitAnnexLocation oldkey
let source = KeySource
{ keyFilename = file
, contentLocation = content
, 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)
, fsckKey :: Maybe (Key -> FilePath -> a Bool)
, canUpgradeKey :: Maybe (Key -> Bool)
, fastMigrate :: Maybe (Key -> BackendA a -> Maybe Key)
}
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.
* direct: Fix handling of case where a work tree subdirectory cannot
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

View file

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