temporarily remove cached keys database connection
The problem is that shutdown is not always called, particularly in the test suite. So, a database connection would be opened, possibly some changes queued, and then not shut down. One way this can happen is when using Annex.eval or Annex.run with a new state. A better fix might be to make both of them call Keys.shutdown (and be sure to do it even if the annex action threw an error). Complication: Sometimes they're run reusing an existing state, so shutting down a database connection could cause problems for other users of that same state. I think this would need a MVar holding the database handle, so it could be emptied once shut down, and another user of the database connection could then start up a new one if it got shut down. But, what if 2 threads were concurrently using the same database handle and one shut it down while the other was writing to it? Urgh. Might have to go that route eventually to get the database access to run fast enough. For now, a quick fix to get the test suite happier, at the expense of speed.
This commit is contained in:
parent
622da992f8
commit
38a23928e9
3 changed files with 1 additions and 24 deletions
3
Annex.hs
3
Annex.hs
|
@ -60,7 +60,6 @@ import Types.NumCopies
|
||||||
import Types.LockCache
|
import Types.LockCache
|
||||||
import Types.DesktopNotify
|
import Types.DesktopNotify
|
||||||
import Types.CleanupActions
|
import Types.CleanupActions
|
||||||
import qualified Database.Keys.Types
|
|
||||||
#ifdef WITH_QUVI
|
#ifdef WITH_QUVI
|
||||||
import Utility.Quvi (QuviVersion)
|
import Utility.Quvi (QuviVersion)
|
||||||
#endif
|
#endif
|
||||||
|
@ -135,7 +134,6 @@ data AnnexState = AnnexState
|
||||||
, desktopnotify :: DesktopNotify
|
, desktopnotify :: DesktopNotify
|
||||||
, workers :: [Either AnnexState (Async AnnexState)]
|
, workers :: [Either AnnexState (Async AnnexState)]
|
||||||
, concurrentjobs :: Maybe Int
|
, concurrentjobs :: Maybe Int
|
||||||
, keysdbhandle :: Maybe Database.Keys.Types.DbHandle
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newState :: GitConfig -> Git.Repo -> AnnexState
|
newState :: GitConfig -> Git.Repo -> AnnexState
|
||||||
|
@ -181,7 +179,6 @@ newState c r = AnnexState
|
||||||
, desktopnotify = mempty
|
, desktopnotify = mempty
|
||||||
, workers = []
|
, workers = []
|
||||||
, concurrentjobs = Nothing
|
, concurrentjobs = Nothing
|
||||||
, keysdbhandle = Nothing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{- Makes an Annex state object for the specified git repo.
|
{- Makes an Annex state object for the specified git repo.
|
||||||
|
|
|
@ -17,7 +17,6 @@ import System.Posix.Signals
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import qualified Annex
|
import qualified Annex
|
||||||
import Annex.Content
|
import Annex.Content
|
||||||
import qualified Database.Keys
|
|
||||||
|
|
||||||
{- Actions to perform each time ran. -}
|
{- Actions to perform each time ran. -}
|
||||||
startup :: Annex ()
|
startup :: Annex ()
|
||||||
|
@ -33,5 +32,4 @@ shutdown :: Bool -> Annex ()
|
||||||
shutdown nocommit = do
|
shutdown nocommit = do
|
||||||
saveState nocommit
|
saveState nocommit
|
||||||
sequence_ =<< M.elems <$> Annex.getState Annex.cleanup
|
sequence_ =<< M.elems <$> Annex.getState Annex.cleanup
|
||||||
Database.Keys.shutdown
|
|
||||||
liftIO reapZombies -- zombies from long-running git processes
|
liftIO reapZombies -- zombies from long-running git processes
|
||||||
|
|
|
@ -14,7 +14,6 @@ module Database.Keys (
|
||||||
DbHandle,
|
DbHandle,
|
||||||
openDb,
|
openDb,
|
||||||
closeDb,
|
closeDb,
|
||||||
shutdown,
|
|
||||||
addAssociatedFile,
|
addAssociatedFile,
|
||||||
getAssociatedFiles,
|
getAssociatedFiles,
|
||||||
getAssociatedKey,
|
getAssociatedKey,
|
||||||
|
@ -84,24 +83,7 @@ closeDb :: DbHandle -> IO ()
|
||||||
closeDb (DbHandle h) = H.closeDb h
|
closeDb (DbHandle h) = H.closeDb h
|
||||||
|
|
||||||
withDbHandle :: (H.DbHandle -> IO a) -> Annex a
|
withDbHandle :: (H.DbHandle -> IO a) -> Annex a
|
||||||
withDbHandle a = do
|
withDbHandle a = bracket openDb (liftIO . closeDb) (\(DbHandle h) -> liftIO (a h))
|
||||||
(DbHandle h) <- dbHandle
|
|
||||||
liftIO $ a h
|
|
||||||
|
|
||||||
dbHandle :: Annex DbHandle
|
|
||||||
dbHandle = maybe startup return =<< Annex.getState Annex.keysdbhandle
|
|
||||||
where
|
|
||||||
startup = do
|
|
||||||
h <- openDb
|
|
||||||
Annex.changeState $ \s -> s { Annex.keysdbhandle = Just h }
|
|
||||||
return h
|
|
||||||
|
|
||||||
shutdown :: Annex ()
|
|
||||||
shutdown = maybe noop go =<< Annex.getState Annex.keysdbhandle
|
|
||||||
where
|
|
||||||
go h = do
|
|
||||||
Annex.changeState $ \s -> s { Annex.keysdbhandle = Nothing }
|
|
||||||
liftIO $ closeDb h
|
|
||||||
|
|
||||||
addAssociatedFile :: Key -> FilePath -> Annex ()
|
addAssociatedFile :: Key -> FilePath -> Annex ()
|
||||||
addAssociatedFile k f = withDbHandle $ \h -> H.queueDb h (\_ _ -> pure True) $ do
|
addAssociatedFile k f = withDbHandle $ \h -> H.queueDb h (\_ _ -> pure True) $ do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue