From 3a1f39fbdf3a1ac61261831dc59dec36e7604106 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 31 Jul 2024 15:54:14 -0400 Subject: [PATCH] Avoid loading cluster log at startup This fixes a problem with datalad's test suite, where loading the cluster log happened to cause the git-annex branch commits to take a different shape, with an additional commit. It's also faster though, since many commands don't need the cluster log. Just fill Annex.clusters with a thunk. Sponsored-by: the NIH-funded NICEMAN (ReproNim TR&D3) project --- Annex.hs | 2 +- Annex/Startup.hs | 6 +++--- CHANGELOG | 6 ++++++ Logs/Cluster.hs | 10 ++++++++-- Logs/Location.hs | 2 +- ..._in_beh__58___addurls_creates_multiple_commits.mdwn | 2 ++ ...comment_3_c69b5193324e79df335d8a4a5cc3c338._comment | 9 +++++++++ 7 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 doc/bugs/change_in_beh__58___addurls_creates_multiple_commits/comment_3_c69b5193324e79df335d8a4a5cc3c338._comment diff --git a/Annex.hs b/Annex.hs index 63557bb92c..eaba4703cf 100644 --- a/Annex.hs +++ b/Annex.hs @@ -197,7 +197,7 @@ data AnnexState = AnnexState , preferredcontentmap :: Maybe (FileMatcherMap Annex) , requiredcontentmap :: Maybe (FileMatcherMap Annex) , remoteconfigmap :: Maybe (M.Map UUID RemoteConfig) - , clusters :: Maybe Clusters + , clusters :: Maybe (Annex Clusters) , forcetrust :: TrustMap , trustmap :: Maybe TrustMap , groupmap :: Maybe GroupMap diff --git a/Annex/Startup.hs b/Annex/Startup.hs index e9c2457a03..c9ae3f3364 100644 --- a/Annex/Startup.hs +++ b/Annex/Startup.hs @@ -35,10 +35,10 @@ startup = do -} startupAnnex :: Annex () startupAnnex = doQuietAction $ - -- Logs.Location needs clusters to be loaded before it is used, - -- in order for a cluster to be treated as the location of keys + -- Logs.Location needs this before it is used, in order for a + -- cluster to be treated as the location of keys -- that are located in any of its nodes. - void loadClusters + preLoadClusters startupSignals :: Annex () startupSignals = do diff --git a/CHANGELOG b/CHANGELOG index 900954478b..54a2bacc37 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +git-annex (10.20240732) UNRELEASED; urgency=medium + + * Avoid loading cluster log at startup. + + -- Joey Hess Wed, 31 Jul 2024 15:52:03 -0400 + git-annex (10.20240731) upstream; urgency=medium * New HTTP API that is equivilant to the P2P protocol. diff --git a/Logs/Cluster.hs b/Logs/Cluster.hs index 8ee0dc975a..677a845925 100644 --- a/Logs/Cluster.hs +++ b/Logs/Cluster.hs @@ -11,6 +11,7 @@ module Logs.Cluster ( module Types.Cluster, getClusters, loadClusters, + preLoadClusters, recordCluster, ) where @@ -24,7 +25,12 @@ import qualified Data.Map as M import qualified Data.Set as S getClusters :: Annex Clusters -getClusters = maybe loadClusters return =<< Annex.getState Annex.clusters +getClusters = maybe loadClusters id =<< Annex.getState Annex.clusters + +{- This works around a module dependency loop. -} +preLoadClusters :: Annex () +preLoadClusters = Annex.changeState $ \s -> + s { Annex.clusters = Just loadClusters } {- Loads the clusters and caches it for later. - @@ -37,5 +43,5 @@ loadClusters = do dead <- (S.fromList . map ClusterNodeUUID) <$> trustGet DeadTrusted clusters <- getClustersWith (M.map (`S.difference` dead)) - Annex.changeState $ \s -> s { Annex.clusters = Just clusters } + Annex.changeState $ \s -> s { Annex.clusters = Just (pure clusters) } return clusters diff --git a/Logs/Location.hs b/Logs/Location.hs index 3172d38153..b360340281 100644 --- a/Logs/Location.hs +++ b/Logs/Location.hs @@ -252,4 +252,4 @@ overLocationLogs' iv discarder keyaction = do -- Cannot import Logs.Cluster due to a cycle. -- Annex.clusters gets populated when starting up git-annex. getClusters :: Annex Clusters -getClusters = fromMaybe noClusters <$> Annex.getState Annex.clusters +getClusters = maybe (pure noClusters) id =<< Annex.getState Annex.clusters diff --git a/doc/bugs/change_in_beh__58___addurls_creates_multiple_commits.mdwn b/doc/bugs/change_in_beh__58___addurls_creates_multiple_commits.mdwn index 2b9d5c5905..2ce9dc1851 100644 --- a/doc/bugs/change_in_beh__58___addurls_creates_multiple_commits.mdwn +++ b/doc/bugs/change_in_beh__58___addurls_creates_multiple_commits.mdwn @@ -186,3 +186,5 @@ add-archive-content(ok): /home/yoh/.tmp/datalad_temp_tree_rsua9kmg (dataset) [[!meta author=yoh]] [[!tag projects/repronim]] + +> [[fixed|done]] --[[Joey]] diff --git a/doc/bugs/change_in_beh__58___addurls_creates_multiple_commits/comment_3_c69b5193324e79df335d8a4a5cc3c338._comment b/doc/bugs/change_in_beh__58___addurls_creates_multiple_commits/comment_3_c69b5193324e79df335d8a4a5cc3c338._comment new file mode 100644 index 0000000000..99e10b9f41 --- /dev/null +++ b/doc/bugs/change_in_beh__58___addurls_creates_multiple_commits/comment_3_c69b5193324e79df335d8a4a5cc3c338._comment @@ -0,0 +1,9 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 3""" + date="2024-07-31T19:50:38Z" + content=""" +Aha! I found a way around the dependency loop. + +This is fixed. +"""]]