Skip to content

LedgerDB.V2: make sure to actually close handles #1516

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

amesgen
Copy link
Member

@amesgen amesgen commented May 19, 2025

Closes #1515

The first three commits add a regression test by enrichting the existing LedgerDB state machine test, making sure that

  total number of all opened handles
- total number of closed handles
= states on the LedgerSeq in the end

The fourth commit then fixes the bug, causing the regression test to succeed.

Note that this bug fix reveals another bug (causing the mock-test failure for LeaderSchedule.simple convergence), which is in turn fixed by #1513.

Comment on lines +157 to +166
closeDiscarded = do
closePruned
-- Do /not/ close the anchor of @toClose@, as that is also the
-- tip of @olddb'@ which will be used in @newdb@.
case toClose of
AS.Empty _ -> pure ()
_ AS.:< closeOld' -> closeLedgerSeq (LedgerSeq closeOld')
-- Finally, close the anchor of @lseq@ (which is a duplicate of
-- the head of @olddb'@).
close $ tables $ AS.anchor lseq
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is correct, but it is rather non-obvious.

It would be "nicer" if newdb would use the anchor state of lseq instead of the head state of olddb' (but we would need a special purpose AS.join for this as this isn't possible in general when the anchor is "strictly smaller" than the element type). In that case, we could simply write

closeDiscarded = closePruned *> closeLedgerSeq (LedgerSeq closeOld)

instead of what I have here.

@amesgen amesgen force-pushed the amesgen/v2-ledgerseq-close branch from 8da1177 to 0dcd9c5 Compare May 20, 2025 15:09
@amesgen amesgen force-pushed the amesgen/v2-ledgerseq-close branch from 0dcd9c5 to 981971e Compare May 20, 2025 15:14
Copy link
Contributor

@jasagredo jasagredo left a comment

Choose a reason for hiding this comment

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

Very nice catch, Alex. The fix looks very reasonable.

amesgen added 4 commits May 28, 2025 13:58
@amesgen amesgen force-pushed the amesgen/v2-ledgerseq-close branch from 981971e to 0c5b137 Compare May 28, 2025 12:00
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.

LedgerDB V2: handles aren't closed in the common case
2 participants