Home / Input Output / cardano-db-sync
10 commits this week Sep 19, 2022 - Sep 26, 2022
Avoid Rollbacks during restart
Currently when there is a restart, db-sync goes back to the latest on disk ledger snapshot. It also deletes all data in the db back to this point as it maintains the property that ledger and db are always at the same point. However in most cases deleting the db is unnecessary and db-sync has to reinsert all the deleted data.

With this pr we change the property: now that the db tip point is never behind the ledger. So on a relatively long rollback received from the chainsync server, db-sync won't delete any db-blocks. It will apply each new block to the ledger state and it will check if the block is already in the db. If it's already there it just goes to the next block. If it's not, it first cleans up the db for any existing blocks with greater or equal BlockNo and then inserts the block. After that the initial property, ledger and db at the same point, is restored.

As an optimization, when db-sync doesn't do a full rollback, ie doesn't delete the db, it will change its ConsistentLevel to DBAheadOfLedger. When the consistency between ledger and db is restored it will change the level back to Consistent. The query I mentioned above only happens with DBAheadOfLedger, so in the normal syncing case no additional queries are executed.