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

Add read-only stats() to ReadTransaction for concurrent access #962

Open
mvdnbrk opened this issue Mar 19, 2025 · 1 comment
Open

Add read-only stats() to ReadTransaction for concurrent access #962

mvdnbrk opened this issue Mar 19, 2025 · 1 comment

Comments

@mvdnbrk
Copy link

mvdnbrk commented Mar 19, 2025

Description:
In Redb v2.4.0, stats() is only available on WriteTransaction, requiring an exclusive lock via begin_write(). This prevents concurrent read-only operations when another process (e.g., a server) holds the database, causing errors like Database already open. Cannot acquire lock. in downstream projects like ord.

Use Case:
In ord v0.22.2 (src/index.rs:568), info() uses:

let stats = self.database.begin_write()?.stats()?;
let rtx = self.database.begin_read()?;

when the ord server runs (e.g., ./ord server), running ord index info fails with:

error: failed to open index: Database already open. Cannot acquire lock.

This happens because begin_write() conflicts with the server’s lock, even though stats() is a read-only operation.

Adding stats() method to ReadTransaction would allow read-only access to database stats without requiring an exclusive lock.

@cberner
Copy link
Owner

cberner commented Mar 20, 2025

stats() access state that is only available in write transaction -- the page allocation stats -- so unfortunately this can't be added to read-only transactions

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

No branches or pull requests

2 participants