@@ -60,6 +60,7 @@ import Glean.Database.Open
6060import Glean.Database.Trace
6161import Glean.Database.Types
6262import Glean.Database.Schema
63+ import Glean.Database.Storage
6364import Glean.Logger
6465import Glean.RTS.Foreign.Ownership (getOwnershipStats , showOwnershipStats )
6566import Glean.ServerConfig.Types (DatabaseBackupPolicy (.. ))
@@ -241,16 +242,17 @@ doBackup env@Env{..} repo prefix site =
241242 hasExcludeProperty repo (metaProperties meta) config_retention
242243 atomically $ notify envListener $ BackupStarted repo
243244 say logInfo " starting"
244- withOpenDatabaseStorage env repo $ \ _storage OpenDB {.. } -> do
245+ withOpenDatabase env repo $ \ OpenDB {.. } -> do
245246 say logInfo " packing"
246247 stats <- mapMaybe
247248 (\ (pid,stats) -> (,stats) . predicateRef <$> lookupPid pid odbSchema)
248249 <$> Storage. predicateStats odbHandle
249250 ownershipStats <- do
250251 maybeOwnership <- readTVarIO odbOwnership
251252 mapM getOwnershipStats maybeOwnership
253+ withStorageFor env repo meta $ \ storage -> do
252254
253- Backend. Data {.. } <- withScratchDirectory envStorage repo $ \ scratch ->
255+ Backend. Data {.. } <- withScratchDirectory storage repo $ \ scratch ->
254256 Storage. backup odbHandle scratch $ \ path Data {dataSize} -> do
255257 say logInfo " uploading"
256258 let policy = ServerConfig. databaseBackupPolicy_repos config_backup
@@ -313,7 +315,8 @@ doRestore env@Env{..} repo meta
313315 case config_restore_timeout of
314316 Just seconds -> void . timeout (fromIntegral seconds * 1000000 )
315317 Nothing -> id
316- maybeTimeout $ restore site size `catch` handler
318+ withStorageFor env repo meta $ \ storage ->
319+ maybeTimeout $ restore site storage size `catch` handler storage
317320
318321 -- NOTE: No point in adding the repo to the sinbin if there was
319322 -- an exception, the handler removed it from the list of known DBs
@@ -330,10 +333,10 @@ doRestore env@Env{..} repo meta
330333 where
331334 say log s = log $ inRepo repo $ " restore: " ++ s
332335
333- restore :: Site s => s -> Maybe Int64 -> IO ()
334- restore site bytes = traceMsg envTracer (GleanTraceDownload repo) $ do
336+ restore :: ( Storage st , Site s ) => s -> st -> Maybe Int64 -> IO ()
337+ restore site storage bytes = traceMsg envTracer (GleanTraceDownload repo) $ do
335338 atomically $ notify envListener $ RestoreStarted repo
336- mbFreeBytes <- (Just <$> Storage. getFreeCapacity envStorage )
339+ mbFreeBytes <- (Just <$> Storage. getFreeCapacity storage )
337340 `catch` \ (_ :: IOException ) -> return Nothing
338341 case (mbFreeBytes, bytes) of
339342 (Just freeBytes, Just size) -> do
@@ -345,7 +348,7 @@ doRestore env@Env{..} repo meta
345348 neededBytes freeBytes
346349 _ -> return ()
347350
348- withScratchDirectory envStorage repo $ \ scratch -> do
351+ withScratchDirectory storage repo $ \ scratch -> do
349352 say logInfo " starting"
350353 say logInfo " downloading"
351354 let scratch_restore = scratch </> " restore"
@@ -356,14 +359,15 @@ doRestore env@Env{..} repo meta
356359 say logInfo " restoring"
357360 createDirectoryIfMissing True scratch_restore
358361 traceMsg envTracer GleanTraceStorageRestore $
359- Storage. restore envStorage repo scratch_restore scratch_file
362+ Storage. restore storage repo scratch_restore scratch_file
360363 say logInfo " adding"
361364 traceMsg envTracer GleanTraceFinishRestore $
362365 Catalog. finishRestoring envCatalog repo
363366 atomically $ notify envListener $ RestoreFinished repo
364367 say logInfo " finished"
365368
366- handler exc = do
369+ handler :: Storage s => s -> SomeException -> IO ()
370+ handler storage exc = do
367371 failed <- atomically $ do
368372 failed <- Catalog. exists envCatalog [Restoring ] repo
369373 when failed $ do
@@ -372,7 +376,7 @@ doRestore env@Env{..} repo meta
372376 return failed
373377 when failed $ do
374378 say logError $ " failed: " ++ show exc
375- swallow $ Storage. safeRemoveForcibly envStorage repo
379+ swallow $ Storage. safeRemoveForcibly storage repo
376380 rethrowAsync exc
377381
378382
0 commit comments