Skip to content

feat(db): use write buffer to speed up state migrations#5588

Merged
hanabi1224 merged 4 commits intomainfrom
hm/db-write-buffer
Apr 22, 2025
Merged

feat(db): use write buffer to speed up state migrations#5588
hanabi1224 merged 4 commits intomainfrom
hm/db-write-buffer

Conversation

@hanabi1224
Copy link
Copy Markdown
Contributor

@hanabi1224 hanabi1224 commented Apr 21, 2025

Summary of changes

As discussed on slack, this PR implements write buffer to speed up state migrations

On my laptop, nv25 mainnet upgrade takes 5m with 10k buffer, and 22m without buffer.

➜  forest git:(main) ✗ forest-tool shed migrate-state --chain mainnet 25 bafy2bzacebb44z6iy77lzpkdxosxk5c2rxtyststp6ukvbknfokswi4czrr3i
Migrating... state_root: bafy2bzaced5lda3j6wpzmgglta47xcxdmnxhanxyiugdme4bl3fdieiaot6go, epoch: 4878799
2025-04-21T11:47:32.422007Z  INFO forest::state_migration::common::state_migration: Processed 100000 actors
...
2025-04-21T11:51:27.950242Z  INFO forest::state_migration::common::state_migration: Processed 3500000 actors
2025-04-21T11:51:31.553214Z  INFO forest::state_migration::common::state_migration: Processing deferred migrations
2025-04-21T11:51:32.293837Z  INFO forest::state_migration::common::state_migration: Processed 3536266 deferred migrations
Done. old_state: bafy2bzaced5lda3j6wpzmgglta47xcxdmnxhanxyiugdme4bl3fdieiaot6go, new_state: bafy2bzacebigaxkbsthgjskbkl37fnt7c4nndqx2vbg223f6dyy6scu6izxye, took: 5m 4s 90ms 552us 64ns
➜  forest git:(main) ✗ forest-tool shed migrate-state --chain mainnet --db-write-buffer 0 25 bafy2bzacebb44z6iy77lzpkdxosxk5c2rxtyststp6ukvbknfokswi4czrr3i
Migrating... state_root: bafy2bzaced5lda3j6wpzmgglta47xcxdmnxhanxyiugdme4bl3fdieiaot6go, epoch: 4878799
2025-04-21T11:54:08.232087Z  INFO forest::state_migration::common::state_migration: Processed 100000 actors
...
2025-04-21T12:13:50.095542Z  INFO forest::state_migration::common::state_migration: Processed 3500000 actors
2025-04-21T12:13:59.860449Z  INFO forest::state_migration::common::state_migration: Processing deferred migrations
2025-04-21T12:14:00.364377Z  INFO forest::state_migration::common::state_migration: Processed 3536266 deferred migrations
Done. old_state: bafy2bzaced5lda3j6wpzmgglta47xcxdmnxhanxyiugdme4bl3fdieiaot6go, new_state: bafy2bzacebigaxkbsthgjskbkl37fnt7c4nndqx2vbg223f6dyy6scu6izxye, took: 22m 29s 894ms 378us 539ns

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

@hanabi1224 hanabi1224 marked this pull request as ready for review April 21, 2025 12:36
@hanabi1224 hanabi1224 requested a review from a team as a code owner April 21, 2025 12:36
@hanabi1224 hanabi1224 requested review from elmattic and sudo-shashank and removed request for a team April 21, 2025 12:36
Comment thread src/state_migration/mod.rs Outdated

impl<DB: Blockstore> BlockstoreWithWriteBuffer<DB> {
pub fn new(inner: DB) -> Self {
Self::new_with_capacity(inner, 10000)
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.

Let's have it configurable so that operators with more memory in their box can potentially increase this. It'd be great to note how much memory increase should one expect with every 10k buffer increment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread src/state_migration/mod.rs Outdated
Ok(None)
}

pub struct BlockstoreWithWriteBuffer<DB: Blockstore> {
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.

The code is straightforward, but it'd still be great to have some coverage there, especially given that locking mechanisms are involved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread src/state_migration/mod.rs Outdated
@hanabi1224 hanabi1224 added this pull request to the merge queue Apr 22, 2025
Merged via the queue into main with commit 286c214 Apr 22, 2025
45 checks passed
@hanabi1224 hanabi1224 deleted the hm/db-write-buffer branch April 22, 2025 12:28
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.

4 participants