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

Feature/migrate modification history #2260

Open
wants to merge 7 commits into
base: feature/version-modifications-history
Choose a base branch
from

Conversation

acerone85
Copy link
Contributor

Linked Issues/PRs

Closes #2095

Description

  • Builds on top of Versioned Storage for Modifications History #2233, which defines the migration functions for the modifications history
  • Defines rocksdb specific handles for the combined database (available only when the feature "rocksdb" is specified), which are necessary to access the functions for performing the migration
  • Spins 4 blocking tasks, one for each database, to perform the migration in parallel with the startup of the Fuel service

Questions:

  • Do we want to handle graceful shutdown of the migration service?
  • How do we test this over a large amount of data?

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

After merging, notify other teams

[Add or remove entries as needed]

CHANGELOG.md Outdated Show resolved Hide resolved
bin/fuel-core/src/cli/run.rs Outdated Show resolved Hide resolved
crates/fuel-core/src/state/historical_rocksdb.rs Outdated Show resolved Hide resolved
Comment on lines 640 to 637
while let Err(e) =
rocks_db.migrate_modifications_history_at_height(height)
{
tracing::warn!("Could not migrate modifications history at height {height}: {e:?}. Trying again.")
}
}
}
rocks_db.complete_migration();
Copy link
Contributor

Choose a reason for hiding this comment

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

In case of Err we will just warn in log and continue with next entry, and then call complete_migration();.

I'm wondering if this leaves some entries not migrated? And if this is acceptable outcome.

I may be lacking some context, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good question. I also lack context to answer, probably @xgreenx knows

Copy link
Contributor Author

@acerone85 acerone85 Sep 30, 2024

Choose a reason for hiding this comment

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

Ah, I missed the point of your question. The rationale behind the loop is because I don't know whether we use pessmiistic or optimistic concurrency control, e.g. whether the migration transaction aborts in case of conflict. In the latter case, we need to retry the transaction. But if we employ pessimistic concurrency control then the loop is not necessary

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need to skip failed entry and continue. But with changes that I asked from #2233 (comment), you will not have cases where error can occur.

crates/fuel-core/src/state/historical_rocksdb.rs Outdated Show resolved Hide resolved
@acerone85 acerone85 force-pushed the feature/migrate-modification-history branch from a29e3a8 to e671b0c Compare September 30, 2024 13:44
@acerone85 acerone85 force-pushed the feature/version-modifications-history branch from 910186c to fe3e453 Compare September 30, 2024 15:55
@acerone85 acerone85 force-pushed the feature/migrate-modification-history branch 2 times, most recently from 5c70a37 to a3ecd66 Compare September 30, 2024 17:01
// TODO: Handle graceful shutdown of migration processes
#[cfg(feature = "rocksdb")]
{
let on_chain_migration_handle = combined_database
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the HistoricalRocksDB should be responsible for launching the migration on construction.

@@ -329,10 +352,14 @@ where
fn rollback_block_to(&self, height_to_rollback: u64) -> StorageResult<()> {
let mut storage_transaction = self.db.read_transaction();

let modifications_history_migration_in_progress = self
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like would be nice to have a getter for this field=)

Comment on lines 640 to 637
while let Err(e) =
rocks_db.migrate_modifications_history_at_height(height)
{
tracing::warn!("Could not migrate modifications history at height {height}: {e:?}. Trying again.")
}
}
}
rocks_db.complete_migration();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need to skip failed entry and continue. But with changes that I asked from #2233 (comment), you will not have cases where error can occur.

@acerone85 acerone85 force-pushed the feature/version-modifications-history branch from 8d4bd59 to 9e6247a Compare October 1, 2024 17:45
@acerone85 acerone85 force-pushed the feature/migrate-modification-history branch 2 times, most recently from 943f60c to 0ff920e Compare October 1, 2024 19:01
@acerone85 acerone85 force-pushed the feature/version-modifications-history branch from 9e6247a to f787cf6 Compare October 2, 2024 14:04
@acerone85 acerone85 force-pushed the feature/migrate-modification-history branch 2 times, most recently from 8ac1bf0 to db2ffc5 Compare October 2, 2024 15:50
@acerone85 acerone85 force-pushed the feature/version-modifications-history branch from f787cf6 to 308c34a Compare October 3, 2024 15:57
@acerone85 acerone85 force-pushed the feature/migrate-modification-history branch from 7c1e835 to e1bc889 Compare October 3, 2024 15:57
@acerone85 acerone85 force-pushed the feature/version-modifications-history branch from 308c34a to 3c9eff4 Compare October 3, 2024 16:45
@acerone85 acerone85 force-pushed the feature/migrate-modification-history branch 4 times, most recently from a3f9c25 to 4e7e614 Compare October 10, 2024 15:35
@acerone85 acerone85 self-assigned this Oct 14, 2024
ConflictPolicy::Overwrite,
Changes::default(),
);

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can add assert here? It's not crucial, but helps a bit with the clarity of the flow.

        let v1_changes = historical_rocks_db
            .db
            .iter_all::<ModificationsHistoryV1<OnChain>>(None)
            .count();
        let v2_changes = historical_rocks_db
            .db
            .iter_all::<ModificationsHistoryV2<OnChain>>(None)
            .count();
        assert_eq!(v1_changes, 0);
        assert_eq!(v2_changes, 100);

.rollback_last_block()
{
// If rolling back fails, then cumulative changes are not being committed to rocksDB.
// We flush them the DB to keep the migration going.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit:
Looks like an incomplete comment.

historical_rocksdb: Arc<InnerHistoricalRocksDB<Description>>,
) {
historical_rocksdb.is_migration_in_progress().then(|| {
tokio::task::spawn_blocking(move || {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there currently a way to gracefully interrupt this migration, if need be?

@acerone85 acerone85 force-pushed the feature/migrate-modification-history branch from db51eeb to dbc1786 Compare October 31, 2024 15:37
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