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.
This commit is contained in:
Joey Hess 2024-06-16 14:35:07 -04:00
parent 36c6d8da69
commit 780367200b
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
18 changed files with 137 additions and 67 deletions

View file

@ -17,6 +17,7 @@ import qualified BuildInfo
import Utility.HumanTime
import Assistant.Install
import Remote.List
import Annex.Startup
import Control.Concurrent.Async
@ -63,7 +64,7 @@ start o
stop
| otherwise = do
liftIO ensureInstalled
ensureInitialized remoteList
ensureInitialized startupAnnex remoteList
Command.Watch.start True (daemonOptions o) (startDelayOption o)
startNoRepo :: AssistantOptions -> IO ()

View file

@ -16,6 +16,7 @@ import Git.Types
import Remote.GCrypt (coreGCryptId)
import qualified CmdLine.GitAnnexShell.Fields as Fields
import CmdLine.GitAnnexShell.Checks
import Annex.Startup
cmd :: Command
cmd = noCommit $ dontCheck repoExists $
@ -47,7 +48,7 @@ findOrGenUUID = do
else ifM (Annex.Branch.hasSibling <||> (isJust <$> Fields.getField Fields.autoInit))
( do
liftIO checkNotReadOnly
initialize Nothing Nothing
initialize startupAnnex Nothing Nothing
getUUID
, return NoUUID
)

View file

@ -12,6 +12,7 @@ module Command.Init where
import Command
import Annex.Init
import Annex.Version
import Annex.Startup
import Types.RepoVersion
import qualified Annex.SpecialRemote
@ -77,7 +78,7 @@ perform os = do
Just v | v /= wantversion ->
giveup $ "This repository is already a initialized with version " ++ show (fromRepoVersion v) ++ ", not changing to requested version."
_ -> noop
initialize
initialize startupAnnex
(if null (initDesc os) then Nothing else Just (initDesc os))
(initVersion os)
unless (noAutoEnable os)

View file

@ -10,6 +10,7 @@ module Command.Reinit where
import Command
import Annex.Init
import Annex.UUID
import Annex.Startup
import qualified Remote
import qualified Annex.SpecialRemote
@ -36,6 +37,6 @@ perform s = do
then return $ toUUID s
else Remote.nameToUUID s
storeUUID u
checkInitializeAllowed $ initialize' Nothing
checkInitializeAllowed $ initialize' startupAnnex Nothing
Annex.SpecialRemote.autoEnable
next $ return True

View file

@ -11,6 +11,7 @@ import Command
import Upgrade
import Annex.Version
import Annex.Init
import Annex.Startup
cmd :: Command
cmd = dontCheck
@ -46,6 +47,6 @@ start (UpgradeOptions { autoOnly = True }) =
start _ =
starting "upgrade" (ActionItemOther Nothing) (SeekInput []) $ do
whenM (isNothing <$> getVersion) $ do
initialize Nothing Nothing
initialize startupAnnex Nothing Nothing
r <- upgrade False latestVersion
next $ return r