Skip to content

Commit b43325e

Browse files
committed
restoreDatabaseFromSite: populate metaBackup
This fixes the following problem: ``` $ glean create --db-root /tmp/g --db test/0 --finish $ glean backup --db-root /tmp/g test/0 mock:/tmp/b $ glean delete --db-root /tmp/g --db test/0 $ glean restore --db-root /tmp/g mock:/tmp/b/test.0 I20260107 10:30:07.484591 574661 Env.hs:65] Using schema from dir:/home/simon/.cabal/store/ghc-9.4.7/glean-0.2.0.0-l-db-b1c66a68faaa1c60cea64cb6e1de59f08ce55ddbe40247f16da611febd4a042d/share/glean/schema/source I20260107 10:30:07.612099 574661 Restore.hs:197] Restoring from mock:/tmp/b/test.0 error: didE20260107 10:30:07.612265 574665 Backup.hs:324] test/0: restore: missing location not find database locator mock:/tmp/b/test.0 ``` `doRestore` expects to find the locator in `metaBackup`, but when we restore a database using `glean restore`, the entry point is `restoreDatabaseFromSite`, which gets the `Meta` from `Backup.inspect`, which may not populate `metaBackup`. Furthermore it would be hard for `Backup.inspect` to populate this field because it would have to reconstruct the backup locator, which `restoreDatabaseFromSite` already has. So we just populate `metaBackup` in `restoreDatabaseFromSite`.
1 parent 23fe3b8 commit b43325e

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

glean/db/Glean/Database/Restore.hs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ module Glean.Database.Restore (
1313
) where
1414

1515
import Control.Exception hiding(handle)
16+
import Data.Maybe
1617
import qualified Data.Set as Set
1718
import Data.Text (Text)
1819

1920
import Util.STM
2021

2122
import qualified Glean.Database.Backup.Backend as Backup
2223
import qualified Glean.Database.Backup.Locator as Backup
24+
import Glean.Database.Meta
2325
import qualified Glean.Database.Catalog as Catalog
2426
import Glean.Database.Types
2527
import qualified Glean.ServerConfig.Types as ServerConfig
@@ -66,7 +68,7 @@ restoreDatabase :: Env -> Text -> IO ()
6668
restoreDatabase env loc
6769
| Just (_, site, repo) <-
6870
Backup.fromRepoLocator (envBackupBackends env) loc =
69-
atomically =<< restoreDatabaseFromSite env site repo
71+
atomically =<< restoreDatabaseFromSite env site repo loc
7072
| otherwise = throwIO $
7173
Thrift.InvalidLocator $ "invalid locator '" <> loc <> "'"
7274

@@ -75,7 +77,15 @@ restoreDatabaseFromSite
7577
=> Env
7678
-> site
7779
-> Repo
80+
-> Text
7881
-> IO (STM ())
79-
restoreDatabaseFromSite Env{..} site repo = do
82+
restoreDatabaseFromSite Env{..} site repo loc = do
8083
props <- Backup.inspect site repo
81-
return $ Catalog.startRestoring envCatalog repo props
84+
-- doRestore expects to find the location in metaBackup, but
85+
-- Backup.inspect is not required to populate this so we fill it
86+
-- in if it's missing.
87+
let props'
88+
| isNothing (metaBackup props) =
89+
props { metaBackup = Just loc }
90+
| otherwise = props
91+
return $ Catalog.startRestoring envCatalog repo props'

0 commit comments

Comments
 (0)