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

1843 - limit cache when close to tip #1886

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Cmdv
Copy link
Contributor

@Cmdv Cmdv commented Oct 29, 2024

Description

This fixes #1843

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.

@Cmdv Cmdv force-pushed the 1843-limit-cache-at-tip branch 3 times, most recently from c3e80f5 to 73a8fa6 Compare November 1, 2024 21:37
@Cmdv Cmdv marked this pull request as ready for review November 12, 2024 17:41
@Cmdv Cmdv requested a review from a team as a code owner November 12, 2024 17:41
Copy link
Contributor

@kderme kderme left a comment

Choose a reason for hiding this comment

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

optimiseCaches requires fixing.
Also optomise is sometimes used instead of optimise. Using reduce instead of optimise would also make it more specific, since the cache is reduced.
Finally, using patterns as suggested could reduce the cases.

cardano-db-sync/src/Cardano/DbSync/Cache.hs Show resolved Hide resolved
-- cPools, cPrevBlock, Cstats, cEpoch
pure c
else pure c
optimiseCaches c = pure c
Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly you can pattern match on a ActiveCache False cache, to avoid this duplicate pure c case.

atomically $
writeTVar (cStake ci) stakeCache'
pure $ Right stakeAddrsId
NoCache -> mapLeft (,bs) <$> resolveStakeAddress bs
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
NoCache -> mapLeft (,bs) <$> resolveStakeAddress bs
ActiveCache False ci -> do
...
_ -> mapLeft (,bs) <$> resolveStakeAddress bs

Merge the 2 states together

Copy link
Contributor Author

@Cmdv Cmdv Nov 26, 2024

Choose a reason for hiding this comment

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

They need to be different states because when ActiveCache False ci we still want to use cPools, cPrevBlock, Cstats, cEpoch caches. But when No Cache we don't use caches at all.
changed it to:

case cache of
    NoCache -> mapLeft (,bs) <$> resolveStakeAddress bs
    ActiveCache True _ -> mapLeft (,bs) <$> resolveStakeAddress bs
    ActiveCache False ci -> do
    ...

Copy link
Contributor

Choose a reason for hiding this comment

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

When it's True, we don't need though. I think this is equivalent.

case cache of
    ActiveCache False ci -> do
      ...
    _ -> mapLeft (,bs) <$> resolveStakeAddress bs

-- Update cache.
liftIO $ atomically $ modifyTVar (cTxIds cacheInternal) $ FIFO.insert txIdLedger txId
-- Return ID after updating cache.
ActiveCache isCacheOptomised cacheInternal -> do
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ActiveCache isCacheOptomised cacheInternal -> do
ActiveCache False cacheInternal -> do
...
_ -> DB.queryTxId txHash

Same, merge the 2 states together

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.

Disable or limit caches when db-sync reaches the tip of the chain
2 participants