remove git-annex branch read cache

This cache prevented noticing changes made by another process.

The case I just ran into involved the assistant dropping a file, which
cached its presence info. Then the same file was downloaded again,
but the assistant didn't know its presence info had changed.

I don't see a way to keep this cache. Will instead rely on the OS level
file cache, for files in the journal. May need to add more higher-level
caching of info that it's ok to have a potentially stale copy of,
although much of git-annex already does so.
This commit is contained in:
Joey Hess 2012-10-19 14:25:15 -04:00
parent f4c3a45da0
commit 3417c55189
3 changed files with 9 additions and 32 deletions

View file

@ -147,7 +147,6 @@ updateTo pairs = do
then updateIndex branchref then updateIndex branchref
else commitBranch branchref merge_desc else commitBranch branchref merge_desc
(nub $ fullname:refs) (nub $ fullname:refs)
invalidateCache
liftIO cleanjournal liftIO cleanjournal
{- Gets the content of a file, which may be in the journal, or committed {- Gets the content of a file, which may be in the journal, or committed
@ -168,20 +167,16 @@ getStale :: FilePath -> Annex String
getStale = get' True getStale = get' True
get' :: Bool -> FilePath -> Annex String get' :: Bool -> FilePath -> Annex String
get' staleok file = fromcache =<< getCache file get' staleok file = fromjournal =<< getJournalFile file
where where
fromcache (Just content) = return content fromjournal (Just content) = return content
fromcache Nothing = fromjournal =<< getJournalFile file
fromjournal (Just content) = cache content
fromjournal Nothing fromjournal Nothing
| staleok = withIndex frombranch | staleok = withIndex frombranch
| otherwise = do | otherwise = do
update update
withIndex $ frombranch >>= cache frombranch
frombranch = L.unpack <$> catFile fullname file frombranch = withIndex $
cache content = do L.unpack <$> catFile fullname file
setCache file content
return content
{- Applies a function to modifiy the content of a file. {- Applies a function to modifiy the content of a file.
- -
@ -191,11 +186,9 @@ get' staleok file = fromcache =<< getCache file
change :: FilePath -> (String -> String) -> Annex () change :: FilePath -> (String -> String) -> Annex ()
change file a = lockJournal $ a <$> getStale file >>= set file change file a = lockJournal $ a <$> getStale file >>= set file
{- Records new content of a file into the journal and cache. -} {- Records new content of a file into the journal -}
set :: FilePath -> String -> Annex () set :: FilePath -> String -> Annex ()
set file content = do set file content = setJournalFile file content
setJournalFile file content
setCache file content
{- Stages the journal, and commits staged changes to the branch. -} {- Stages the journal, and commits staged changes to the branch. -}
commit :: String -> Annex () commit :: String -> Annex ()

View file

@ -1,6 +1,6 @@
{- git-annex branch state management {- git-annex branch state management
- -
- Runtime state about the git-annex branch, including a small read cache. - Runtime state about the git-annex branch.
- -
- Copyright 2011-2012 Joey Hess <joey@kitenet.net> - Copyright 2011-2012 Joey Hess <joey@kitenet.net>
- -
@ -22,22 +22,6 @@ setState state = Annex.changeState $ \s -> s { Annex.branchstate = state }
changeState :: (BranchState -> BranchState) -> Annex () changeState :: (BranchState -> BranchState) -> Annex ()
changeState changer = setState =<< changer <$> getState changeState changer = setState =<< changer <$> getState
setCache :: FilePath -> String -> Annex ()
setCache file content = changeState $ \s -> s
{ cachedFile = Just file, cachedContent = content}
getCache :: FilePath -> Annex (Maybe String)
getCache file = from <$> getState
where
from state
| cachedFile state == Just file =
Just $ cachedContent state
| otherwise = Nothing
invalidateCache :: Annex ()
invalidateCache = changeState $ \s -> s
{ cachedFile = Nothing, cachedContent = "" }
{- Runs an action to check that the index file exists, if it's not been {- Runs an action to check that the index file exists, if it's not been
- checked before in this run of git-annex. -} - checked before in this run of git-annex. -}
checkIndexOnce :: Annex () -> Annex () checkIndexOnce :: Annex () -> Annex ()

View file

@ -1,4 +1,4 @@
{- management of the git-annex journal and cache {- management of the git-annex journal
- -
- The journal is used to queue up changes before they are committed to the - The journal is used to queue up changes before they are committed to the
- git-annex branch. Amoung other things, it ensures that if git-annex is - git-annex branch. Amoung other things, it ensures that if git-annex is