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 #6924

Merged
merged 8 commits into from
Mar 3, 2024

Conversation

shekhirin
Copy link
Collaborator

@shekhirin shekhirin commented Mar 1, 2024

DO NOT MERGE: running on Mainnet and Holesky over the weekends

Ref #6850, attempt number two.

Fixes several things:

  1. Replaced a usage of MDBX_TXN_FINISHED flag with one atomic bool
    // Importantly, we can't rely on `MDBX_TXN_FINISHED` flag to check if the transaction is timed
    // out using `mdbx_txn_reset`, because MDBX uses it in other cases too.
    fn is_timed_out(&self) -> bool {
    self.timed_out.load(std::sync::atomic::Ordering::SeqCst)
    }
  2. Try locking the TransactionPtr mutex first, log on failure, then lock again in a blocking way
    fn lock(&self) -> MutexGuard<'_, ()> {
    if let Some(lock) = self.lock.try_lock() {
    lock
    } else {
    tracing::warn!(
    target: "libmdbx",
    txn = %self.txn as usize,
    backtrace = %std::backtrace::Backtrace::force_capture(),
    "Transaction lock is already acquired, blocking..."
    );
    self.lock.lock()
    }
    }
  3. Move a bunch of txn_execute usages back to their original places 75fa00c
  4. Do not ignore mdbx_result errors on Drop, unwrap() instead.

@shekhirin shekhirin added C-enhancement New feature or request A-db Related to the database labels Mar 1, 2024
@shekhirin shekhirin marked this pull request as ready for review March 1, 2024 22:43
crates/storage/libmdbx-rs/src/transaction.rs Outdated Show resolved Hide resolved
crates/storage/libmdbx-rs/src/transaction.rs Outdated Show resolved Hide resolved
Co-authored-by: Emilia Hane <elsaemiliaevahane@gmail.com>
Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

lgtm

@shekhirin shekhirin added this pull request to the merge queue Mar 3, 2024
Merged via the queue into main with commit 3e54d94 Mar 3, 2024
29 checks passed
@shekhirin shekhirin deleted the alexey/mdbx-txn-reset-2 branch March 3, 2024 20:12
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.

3 participants