Skip to content

Introduce static_write_txn - #373

Open
Paraworker wants to merge 2 commits into
meilisearch:mainfrom
Paraworker:main
Open

Introduce static_write_txn#373
Paraworker wants to merge 2 commits into
meilisearch:mainfrom
Paraworker:main

Conversation

@Paraworker

Copy link
Copy Markdown

Pull Request

What does this PR do?

  • Adds Env::static_write_txn and EncryptedEnv::static_write_txn, mirroring the existing static_read_txn API. These constructors consume the env (self) and return an
    RwTxn<'static> whose lifetime is no longer tied to a borrowed Env, letting callers hold a write txn without keeping a separate Env reference alive.
  • Implementation in heed/src/txn.rs mirrors RwTxn::static_read_txn: begins an mdb_txn_begin write transaction and stores the env as Cow::Owned inside RoTxnInner
    so the env cannot be closed while the txn lives.
  • Updates the write_txn rustdoc on both Env and EncryptedEnv to cross-reference the new static_write_txn.

PR checklist

Please check if your PR fulfills the following requirements:

  • Did you use any AI tool while implementing this PR (code, tests, docs, etc.)? If yes, disclose it in the PR description and describe what it was used for. AI usage is allowed when it is disclosed.
    • Used Claude Code to explore the repo structure and locate the existing static_read_txn implementation, then mirrored its shape for static_write_txn (env consumed by value, Cow::Owned env handle, 'static lifetime on the returned txn). Final code and docs were reviewed by hand.
  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

@Kerollmops Kerollmops left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hello @Paraworker,

Thanks for the changes. Looks good to me. I would just like you to clean a bit the codebase.

Thank you very much 🌵

Comment thread heed/src/txn.rs
Comment on lines 281 to +289
pub(crate) fn new<T>(env: &'p Env<T>) -> Result<RwTxn<'p>> {
Self::begin(Cow::Borrowed(&env.inner))
}

pub(crate) fn static_write_txn<T>(env: Env<T>) -> Result<RwTxn<'static>> {
Self::begin(Cow::Owned(env.inner))
}

fn begin(env: Cow<'_, Arc<EnvInner>>) -> Result<RwTxn<'_>> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would you mind changing a bit the naming and doing the same naming changes for the RoTxn struct, please?

  • static_read_txn becomes from_owned_env
  • static_write_txn becomes from_owned_env
  • apply the same technique to provide a Cow as a parameter to the begin method for the RoTxn too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Changed as suggested.

@Paraworker
Paraworker force-pushed the main branch 2 times, most recently from 5a0872c to 8fde86c Compare July 10, 2026 08:29
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.

2 participants