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

feat(storage): use mdbx_txn_reset to time out transactions #6850

Merged
merged 22 commits into from Feb 29, 2024

Conversation

shekhirin
Copy link
Collaborator

@shekhirin shekhirin commented Feb 28, 2024

Fixes #6441, #6699

  1. mdbx_txn_reset instead of mdbx_txn_abort for timing out transactions
    • The issue with mdbx_txn_abort is that it frees the transaction pointer, meaning that MDBX can re-use it for new read-only transactions.
    • It's bad because our assumption is that they're unique and we can index the internal list of active transactions by them.
    • mdbx_txn_reset releases old snapshots of the data too, hence prevents the growth of the freelist (see https://erthink.github.io/libmdbx/usage.html#autotoc_md50).
  2. Use transaction's mutex when timing out, so we're sure that if we started the process of timing out, no other parallel use of this transaction is possible
    • It's crucial, because if you try to use a transaction that was reset via mdbx_txn_reset, MDBX crashes.
  3. Do not track aborted transactions in the TxnManager
    • No need for this anymore, we rely on mdbx_txn_flags(txn_ptr) & MDBX_TXN_FINISHED == 1 now.
  4. Deny direct access to the transaction pointer, meaning all requests should go through the txn_execute method that does locking
    • See point 2.

@shekhirin shekhirin changed the title feat(storage): use mdbx_txn_reset to kill timeouted transactions feat(storage): use mdbx_txn_reset to abort timeouted transactions Feb 28, 2024
crates/storage/libmdbx-rs/src/error.rs Outdated Show resolved Hide resolved
crates/storage/libmdbx-rs/src/txn_manager.rs Outdated Show resolved Hide resolved
crates/storage/libmdbx-rs/src/txn_manager.rs Show resolved Hide resolved
crates/storage/libmdbx-rs/src/txn_manager.rs Show resolved Hide resolved
@shekhirin shekhirin added C-enhancement New feature or request A-db Related to the database labels Feb 28, 2024
@shekhirin shekhirin marked this pull request as ready for review February 28, 2024 17:15
Co-authored-by: Emilia Hane <elsaemiliaevahane@gmail.com>
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

nice find

crates/storage/libmdbx-rs/src/transaction.rs Outdated Show resolved Hide resolved
@emhane emhane mentioned this pull request Feb 29, 2024
1 task
@shekhirin shekhirin changed the title feat(storage): use mdbx_txn_reset to abort timeouted transactions feat(storage): use mdbx_txn_reset to time out transactions Feb 29, 2024
Copy link
Member

@emhane emhane left a comment

Choose a reason for hiding this comment

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

super clean interface, some test coverage missing

crates/storage/libmdbx-rs/src/transaction.rs Show resolved Hide resolved
crates/storage/libmdbx-rs/src/transaction.rs Outdated Show resolved Hide resolved
crates/storage/libmdbx-rs/src/txn_manager.rs Show resolved Hide resolved
@emhane
Copy link
Member

emhane commented Feb 29, 2024

also closes #6699 right? and makes #6798 obsolete.

Copy link
Member

@emhane emhane left a comment

Choose a reason for hiding this comment

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

super nice! one typo in a comment (see suggestion)

crates/storage/libmdbx-rs/src/txn_manager.rs Outdated Show resolved Hide resolved
Co-authored-by: Emilia Hane <elsaemiliaevahane@gmail.com>
@emhane emhane added this pull request to the merge queue Feb 29, 2024
Merged via the queue into main with commit 74dc0e3 Feb 29, 2024
29 checks passed
@emhane emhane deleted the alexey/mdbx-txn-reset branch February 29, 2024 20:56
shekhirin added a commit that referenced this pull request Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-db Related to the database C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Race condition in MDBX bindings
3 participants