Skip to content

Commit

Permalink
Delete data automatically when using the --disable-ledger flag
Browse files Browse the repository at this point in the history
This is need when the database is restored from a snapshot and then
`db-sync` is run with `--disable-ledger`.
  • Loading branch information
kderme authored and erikd committed Jun 27, 2022
1 parent af36a3a commit 37cd6f0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cardano-db-sync/app/cardano-db-sync.hs
Expand Up @@ -103,7 +103,7 @@ pPGPassSource =
pExtended :: Parser Bool
pExtended =
Opt.flag True False
( Opt.long "no-epoch-table"
( Opt.long "disable-epoch"
<> Opt.help "Makes epoch table remain empty"
)

Expand Down
3 changes: 3 additions & 0 deletions cardano-db-sync/src/Cardano/DbSync/Sync.hs
Expand Up @@ -132,6 +132,9 @@ runSyncNode metricsSetters trce iomgr aop snEveryFollowing snEveryLagging dbConn
-- If the DB is empty it will be inserted, otherwise it will be validated (to make
-- sure we are on the right chain).
lift $ Db.runIohkLogging trce $ withPostgresqlConn dbConnString $ \backend -> do
liftIO $ unless (enpHasLedger enp) $ do
logInfo trce "Migrating to a no ledger schema"
Db.noLedgerMigrations backend trce
lift $ orDie renderSyncNodeError $ insertValidateGenesisDist trce backend (dncNetworkName enc) genCfg (useShelleyInit enc)
liftIO $ epochStartup (enpExtended enp) trce backend

Expand Down
11 changes: 10 additions & 1 deletion cardano-db/src/Cardano/Db/Migration.hs
Expand Up @@ -16,6 +16,7 @@ module Cardano.Db.Migration
, validateMigrations
, hashMigrations
, renderMigrationValidateError
, noLedgerMigrations
) where

import Control.Exception (SomeException, handle)
Expand Down Expand Up @@ -43,6 +44,7 @@ import Data.Time.Format (defaultTimeLocale, formatTime, iso8601DateFor
import Database.Persist.Sql (Single (..), SqlBackend, SqlPersistT, entityVal,
getMigration, rawExecute, rawSql, selectFirst)

import Cardano.BM.Trace (Trace)
import Cardano.Crypto.Hash (Blake2b_256, ByteString, Hash, hashToStringAsHex, hashWith)
import Cardano.Db.Migration.Haskell
import Cardano.Db.Migration.Version
Expand Down Expand Up @@ -283,4 +285,11 @@ isOfficialMigrationFile fn =
case takeWhile isDigit . drop 1 $ dropWhile (/= '-') str of
stage -> fromMaybe 0 $ readMaybe stage


noLedgerMigrations :: SqlBackend -> Trace IO Text -> IO ()
noLedgerMigrations backend trce = do
void $ runDbIohkLogging backend trce $ do
rawExecute "update redeemer set fee = null" []
rawExecute "delete from reward" []
rawExecute "delete from epoch_stake" []
rawExecute "delete from ada_pots" []
rawExecute "delete from epoch_param" []
8 changes: 7 additions & 1 deletion doc/configuration.md
Expand Up @@ -40,8 +40,14 @@ delete from ada_pots;
delete from epoch_param;
```

### --disable-cache
### --disable-cache : Experimental

This disables the application level caches of db-sync. It reduces memory usage by a bit, but
increases sync time. Usually this flag is not worth it, unless there are some pretty big memory
issues.

## --disable-epoch : Experimental

With this option the epoch table is left empty. Mostly left for historical reasons, since it
provides a negligible improvement in sync time.

0 comments on commit 37cd6f0

Please sign in to comment.