Skip to content

Commit

Permalink
Fix retain_at_least
Browse files Browse the repository at this point in the history
Reviewed By: pepeiborra, iamirzhan

Differential Revision: D66097112

fbshipit-source-id: 3ebad2b35b664ab2fe05ad8641a006dbe88b8b53
  • Loading branch information
Simon Marlow authored and facebook-github-bot committed Nov 19, 2024
1 parent 57e70ea commit 98f8618
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions glean/db/Glean/Database/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ data Config = Config
, cfgEnableRecursion :: Bool
-- ^ Enable experimental support for recursion
, cfgFilterAvailableDBs :: [Repo] -> IO [Repo]
-- ^ Filter out DBs not currently available in the server tier
-- ^ Filter out DBs not currently available on some other server
, cfgTracer :: Tracer GleanTrace
, cfgDebug :: DebugFlags
}
Expand Down Expand Up @@ -203,7 +203,7 @@ instance Default Config where
, cfgDatabaseLogger = Some NullGleanDatabaseLogger
, cfgBackupBackends = HashMap.fromList [("mock", Backup.Mock.mock)]
, cfgEnableRecursion = False
, cfgFilterAvailableDBs = return
, cfgFilterAvailableDBs = const $ return []
, cfgTracer = mempty
, cfgDebug = def
}
Expand Down Expand Up @@ -447,7 +447,7 @@ options = do
, cfgServerLogger = cfgServerLogger def
, cfgDatabaseLogger = cfgDatabaseLogger def
, cfgBackupBackends = cfgBackupBackends def
, cfgFilterAvailableDBs = return
, cfgFilterAvailableDBs = const $ return []
, cfgTracer = mempty
, cfgSchemaId = Nothing
, .. }
Expand Down
15 changes: 12 additions & 3 deletions glean/db/Glean/Database/Retention.hs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,16 @@ dbRetentionForRepo ServerConfig.Retention{..} t isAvailableM dbs dbIndex = do
(ifSet deleteIncompleteIfOlder $ \secs ->
(not . isComplete) &&& isOlderThan secs)

-- ensure we have retain_at_least DBs from the available set
atLeast <- takeFilterM
-- implements retain_at_least
atLeast =
take retainAtLeast $
filter (isComplete &&& hasDependencies) sorted

-- Ensure we have retain_at_least DBs available somewhere. This
-- prevents us deleting an older DB before the newer one has been
-- restored. The isAvailable check ensures that we don't keep an old
-- DB on this server when the newer one is on another server.
atLeastAvailable <- takeFilterM
retainAtLeast
(isComplete &&& hasDependencies &&&> isAvailable)
-- bound the search since isAvailable is expensive
Expand All @@ -265,7 +273,8 @@ dbRetentionForRepo ServerConfig.Retention{..} t isAvailableM dbs dbIndex = do
-- delete DBs according to the deletion policy, and keep retain_at_most
let atMost = maybe id take retainAtMost (filter (not . delete) sorted)

return $ uniqBy (comparing itemRepo) (atLeast ++ atMost)
return $ uniqBy (comparing itemRepo) $
atLeast ++ atLeastAvailable ++ atMost

missingDependencies :: DbIndex -> Item -> Bool
missingDependencies dbIndex item = any isNothing (dependencies dbIndex item)
Expand Down

0 comments on commit 98f8618

Please sign in to comment.