Skip to content

fix: database cannot resize on jmt write#7244

Merged
SWvheerden merged 1 commit intotari-project:developmentfrom
SWvheerden:sw_fix_resize
Jun 23, 2025
Merged

fix: database cannot resize on jmt write#7244
SWvheerden merged 1 commit intotari-project:developmentfrom
SWvheerden:sw_fix_resize

Conversation

@SWvheerden
Copy link
Copy Markdown
Collaborator

@SWvheerden SWvheerden commented Jun 23, 2025

Description

fix error handling to allow the jmt to resize the database

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling to automatically resize the database when certain storage errors occur, reducing the likelihood of write failures. Users may experience fewer interruptions related to database size limits.

fix error handling to allow the jmt to resize the database
@SWvheerden SWvheerden requested a review from a team as a code owner June 23, 2025 10:44
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jun 23, 2025

Walkthrough

The change updates the internal error handling logic in the write method of the LMDBDatabase implementation. It now recognizes and processes database resize requests that originate from Jellyfish Merkle Tree errors, performing a resize and retrying the transaction as needed. Other errors are logged and returned as before.

Changes

File(s) Change Summary
base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs Enhanced error handling in the write method to process resize requests from JMT errors.

Suggested reviewers

  • stringhandler

Poem

A burrow of code, a database grows,
Sometimes it needs more room, as everyone knows.
Now even the Merkle trees get their say,
If they need more space, we clear the way!
With logs and a hop, we handle the squeeze,
Making LMDB run with rabbit-like ease. 🐇💾

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs (1)

2045-2067: LGTM! The fix correctly handles JMT-originated resize requests.

This change effectively addresses the PR objective by ensuring that database resize requests originating from Jellyfish Merkle Tree operations are properly handled. The downcast pattern and error handling logic are sound.

However, consider refactoring the duplicated resize logic into a helper function to improve maintainability:

+    fn perform_database_resize(
+        &self,
+        size_that_could_not_be_written: usize,
+        resize_count: usize,
+    ) -> Result<(), ChainStorageError> {
+        info!(
+            target: LOG_TARGET,
+            "Database resize required (resized {} time(s) in this transaction)",
+            resize_count + 1
+        );
+        unsafe {
+            LMDBStore::resize(&self.env, &self.env_config, size_that_could_not_be_written)
+        }
+    }

 // Then replace both resize blocks with:
-                    info!(
-                        target: LOG_TARGET,
-                        "Database resize required (resized {} time(s) in this transaction)",
-                        i + 1
-                    );
-                    unsafe {
-                        LMDBStore::resize(&self.env, &self.env_config, size_that_could_not_be_written)?;
-                    }
+                    self.perform_database_resize(size_that_could_not_be_written, i)?;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 255bb1b and cf92310.

📒 Files selected for processing (1)
  • base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Cucumber tests / Base Layer
  • GitHub Check: Cucumber tests / FFI
  • GitHub Check: ci
  • GitHub Check: cargo check with stable
  • GitHub Check: test (nextnet, nextnet)
  • GitHub Check: test (testnet, esmeralda)
  • GitHub Check: test (mainnet, stagenet)

@github-actions
Copy link
Copy Markdown

Test Results (CI)

    3 files    126 suites   41m 20s ⏱️
1 351 tests 1 350 ✅ 0 💤 1 ❌
4 051 runs  4 050 ✅ 0 💤 1 ❌

For more details on these failures, see this check.

Results for commit cf92310.

@github-actions
Copy link
Copy Markdown

Test Results (Integration tests)

 2 files  + 2  1 errors  1 suites  +1   15m 18s ⏱️ + 15m 18s
 8 tests + 8  7 ✅ +7  0 💤 ±0  1 ❌ +1 
10 runs  +10  7 ✅ +7  0 💤 ±0  3 ❌ +3 

For more details on these parsing errors and failures, see this check.

Results for commit cf92310. ± Comparison against base commit 255bb1b.

@SWvheerden SWvheerden merged commit 1df5cfe into tari-project:development Jun 23, 2025
13 of 16 checks passed
@SWvheerden SWvheerden deleted the sw_fix_resize branch June 23, 2025 15:49
sdbondi added a commit to sdbondi/tari that referenced this pull request Jun 24, 2025
* development:
  fix: remove long timeout in interactive_tx till tx is persisted into db (tari-project#7252)
  chore: new release v4.6.1-pre.0 (tari-project#7248)
  fix: minotari_merge_mining_proxy returns Tari block hash even if submit_to_origin is disabled (tari-project#7242)
  chore(ci): windows binary audit fix and more code-signing verification (tari-project#7245)
  fix: database cannot resize on jmt write (tari-project#7244)
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