Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1847 - add logging to Rollbacks #1877

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Cmdv
Copy link
Contributor

@Cmdv Cmdv commented Oct 10, 2024

Description

This fixes #1597 #1847

Adding some login to rollbacks for a clearer picture of what is happening.
Also refactored code and moved functionality to cardano-db/ library.

SCR-20241022-gfn

Checklist

  • Commit sequence broadly makes sense
  • Commits have useful messages
  • New tests are added if needed and existing tests are updated
  • Any changes are noted in the changelog
  • Code is formatted with fourmolu on version 0.10.1.0 (which can be run with scripts/fourmolize.sh)
  • Self-reviewed the diff

Migrations

  • The pr causes a breaking change of type a,b or c
  • If there is a breaking change, the pr includes a database migration and/or a fix process for old values, so that upgrade is possible
  • Resyncing and running the migrations provided will result in the same database semantically

If there is a breaking change, especially a big one, please add a justification here. Please elaborate
more what the migration achieves, what it cannot achieve or why a migration is not possible.

deleteEpochLogs <- deleteUsingEpochNo epochN
(deleteBlockCount, blockDeleteLogs) <- deleteTablesAfterBlockId blockId mTxId minIds
whenJust mIsConsumedTxOut $ \_ -> do
querySetNullTxOut trce txOutTableType mTxId
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we include this in the delete logs summary?
Instead of whenJust here, you could define and use whenJustDefault. For inspiration, we have similar utilitis in Cardano.DbSync.Util.whenDefault,whenMaybe

@@ -102,106 +131,230 @@ deleteBlocksBlockId trce txOutTableType blockId = do
CMinIdsWrapper (MinIds m1 m2 m3) -> isJust m1 && isJust m2 && isJust m3
VMinIdsWrapper (MinIds m1 m2 m3) -> isJust m1 && isJust m2 && isJust m3

-- (MinIds m1 m2 m3) isJust m1 && isJust m2 && isJust m3
mkRollbackSummary :: [(Text, Int64)] -> Text
mkRollbackSummary logs = "\n ----------------------- Rollback Summary: ----------------------- \n" <> formattedLog
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this become a bit less verbose? For example we could split out logs with 0 deletes and print them in a single row
Count 0: TableA, TableB ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated logs see PR description for updated screenshot

queryBlockSlotNo :: MonadIO m => Word64 -> ReaderT SqlBackend m (Maybe BlockId)
pure $ convertBlockQuery (listToMaybe res)

queryBlockSlotNo :: MonadIO m => Word64 -> ReaderT SqlBackend m (Maybe (BlockId, Word64))
queryBlockSlotNo slotNo = do
res <- select $ do
blk <- from $ table @Block
where_ (blk ^. BlockSlotNo ==. just (val slotNo))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we change the behaviour here, so that it deletes all blocks with greater or equal slot_no?
Currently it finds blocks with the provided slot_no and only if there is one it deletes it and everythiong after it. This is a bit counter-intuitive.

@Cmdv Cmdv marked this pull request as ready for review October 22, 2024 10:55
@Cmdv Cmdv requested a review from a team as a code owner October 22, 2024 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using cardano-db-sync --rollback-to-slot after consumed-tx-out is bugged
2 participants