remove dead nodes when loading the cluster log
This is to avoid inserting a cluster uuid into the location log when
only dead nodes in the cluster contain the content of a key.
One reason why this is necessary is Remote.keyLocations, which excludes
dead repositories from the list. But there are probably many more.
Implementing this was challenging, because Logs.Location importing
Logs.Cluster which imports Logs.Trust which imports Remote.List resulted
in an import cycle through several other modules.
Resorted to making Logs.Location not import Logs.Cluster, and instead
it assumes that Annex.clusters gets populated when necessary before it's
called.
That's done in Annex.Startup, which is run by the git-annex command
(but not other commands) at early startup in initialized repos. Or,
is run after initialization.
Note that is Remote.Git, it is unable to import Annex.Startup, because
Remote.Git importing Logs.Cluster leads the the same import cycle.
So ensureInitialized is not passed annexStartup in there.
Other commands, like git-annex-shell currently don't run annexStartup
either.
So there are cases where Logs.Location will not see clusters. So it won't add
any cluster UUIDs when loading the log. That's ok, the only reason to do
that is to make display of where objects are located include clusters,
and to make commands like git-annex get --from treat keys as being located
in a cluster. git-annex-shell certainly does not do anything like that,
and I'm pretty sure Remote.Git (and callers to Remote.Git.onLocalRepo)
don't either.
2024-06-16 18:35:07 +00:00
|
|
|
{- git-annex startup
|
|
|
|
-
|
|
|
|
- Copyright 2010-2024 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
|
|
|
module Annex.Startup where
|
|
|
|
|
|
|
|
import Annex.Common
|
|
|
|
import qualified Annex
|
|
|
|
import Logs.Cluster
|
|
|
|
|
|
|
|
#ifndef mingw32_HOST_OS
|
|
|
|
import Control.Concurrent.STM
|
|
|
|
import System.Posix.Signals
|
|
|
|
#endif
|
|
|
|
|
|
|
|
{- Run when starting up the main git-annex program. -}
|
|
|
|
startup :: Annex ()
|
|
|
|
startup = do
|
|
|
|
startupSignals
|
|
|
|
gc <- Annex.getGitConfig
|
|
|
|
when (isinitialized gc)
|
|
|
|
startupAnnex
|
|
|
|
where
|
|
|
|
isinitialized gc = annexUUID gc /= NoUUID
|
|
|
|
&& isJust (annexVersion gc)
|
|
|
|
|
|
|
|
{- Run when starting up the main git-annex program when
|
|
|
|
- git-annex has already been initialized.
|
|
|
|
- Alternatively, run after initialization.
|
|
|
|
-}
|
|
|
|
startupAnnex :: Annex ()
|
2024-06-19 01:31:32 +00:00
|
|
|
startupAnnex = doQuietAction $
|
2024-07-31 19:54:14 +00:00
|
|
|
-- Logs.Location needs this before it is used, in order for a
|
|
|
|
-- cluster to be treated as the location of keys
|
remove dead nodes when loading the cluster log
This is to avoid inserting a cluster uuid into the location log when
only dead nodes in the cluster contain the content of a key.
One reason why this is necessary is Remote.keyLocations, which excludes
dead repositories from the list. But there are probably many more.
Implementing this was challenging, because Logs.Location importing
Logs.Cluster which imports Logs.Trust which imports Remote.List resulted
in an import cycle through several other modules.
Resorted to making Logs.Location not import Logs.Cluster, and instead
it assumes that Annex.clusters gets populated when necessary before it's
called.
That's done in Annex.Startup, which is run by the git-annex command
(but not other commands) at early startup in initialized repos. Or,
is run after initialization.
Note that is Remote.Git, it is unable to import Annex.Startup, because
Remote.Git importing Logs.Cluster leads the the same import cycle.
So ensureInitialized is not passed annexStartup in there.
Other commands, like git-annex-shell currently don't run annexStartup
either.
So there are cases where Logs.Location will not see clusters. So it won't add
any cluster UUIDs when loading the log. That's ok, the only reason to do
that is to make display of where objects are located include clusters,
and to make commands like git-annex get --from treat keys as being located
in a cluster. git-annex-shell certainly does not do anything like that,
and I'm pretty sure Remote.Git (and callers to Remote.Git.onLocalRepo)
don't either.
2024-06-16 18:35:07 +00:00
|
|
|
-- that are located in any of its nodes.
|
2024-07-31 19:54:14 +00:00
|
|
|
preLoadClusters
|
remove dead nodes when loading the cluster log
This is to avoid inserting a cluster uuid into the location log when
only dead nodes in the cluster contain the content of a key.
One reason why this is necessary is Remote.keyLocations, which excludes
dead repositories from the list. But there are probably many more.
Implementing this was challenging, because Logs.Location importing
Logs.Cluster which imports Logs.Trust which imports Remote.List resulted
in an import cycle through several other modules.
Resorted to making Logs.Location not import Logs.Cluster, and instead
it assumes that Annex.clusters gets populated when necessary before it's
called.
That's done in Annex.Startup, which is run by the git-annex command
(but not other commands) at early startup in initialized repos. Or,
is run after initialization.
Note that is Remote.Git, it is unable to import Annex.Startup, because
Remote.Git importing Logs.Cluster leads the the same import cycle.
So ensureInitialized is not passed annexStartup in there.
Other commands, like git-annex-shell currently don't run annexStartup
either.
So there are cases where Logs.Location will not see clusters. So it won't add
any cluster UUIDs when loading the log. That's ok, the only reason to do
that is to make display of where objects are located include clusters,
and to make commands like git-annex get --from treat keys as being located
in a cluster. git-annex-shell certainly does not do anything like that,
and I'm pretty sure Remote.Git (and callers to Remote.Git.onLocalRepo)
don't either.
2024-06-16 18:35:07 +00:00
|
|
|
|
|
|
|
startupSignals :: Annex ()
|
|
|
|
startupSignals = do
|
|
|
|
#ifndef mingw32_HOST_OS
|
|
|
|
av <- Annex.getRead Annex.signalactions
|
|
|
|
let propagate sig = liftIO $ installhandleronce sig av
|
|
|
|
propagate sigINT
|
|
|
|
propagate sigQUIT
|
|
|
|
propagate sigTERM
|
|
|
|
propagate sigTSTP
|
|
|
|
propagate sigCONT
|
|
|
|
propagate sigHUP
|
|
|
|
-- sigWINCH is not propagated; it should not be needed,
|
|
|
|
-- and the concurrent-output library installs its own signal
|
|
|
|
-- handler for it.
|
|
|
|
-- sigSTOP and sigKILL cannot be caught, so will not be propagated.
|
|
|
|
where
|
|
|
|
installhandleronce sig av = void $
|
|
|
|
installHandler sig (CatchOnce (gotsignal sig av)) Nothing
|
|
|
|
gotsignal sig av = do
|
|
|
|
mapM_ (\a -> a (fromIntegral sig)) =<< atomically (readTVar av)
|
|
|
|
raiseSignal sig
|
|
|
|
installhandleronce sig av
|
|
|
|
#else
|
|
|
|
return ()
|
|
|
|
#endif
|