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

feat(store/v2): Implement State Migration #19327

Merged
merged 15 commits into from
Feb 13, 2024
Merged

Conversation

cool-develope
Copy link
Contributor

@cool-develope cool-develope commented Feb 1, 2024

Description

Closes: #19326

  • Create the migration manager
  • Add the CreateMigration staff in the snapshots manager for the state migration

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features
    • Introduced a comprehensive migration system for transitioning state data from store/v1 to store/v2, including in-memory message handling for migration without disk I/O.
  • Improvements
    • Enhanced error handling in state commitment operations.
  • Tests
    • Added a new test suite for validating the functionality and correctness of the migration manager.
  • Dependencies
    • Added a dependency on a new module to support synchronization features.

@cool-develope cool-develope requested a review from a team as a code owner February 1, 2024 15:38
Copy link
Contributor

coderabbitai bot commented Feb 1, 2024

Warning

Rate Limit Exceeded

@cool-develope has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 29 minutes and 14 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 6be6a17 and 139aef5.

Walkthrough

This update introduces a comprehensive migration framework to transition the entire state from store/v1 to store/v2, ensuring data integrity and consistency. It includes a migration manager for handling the migration process, a migration stream for state transfer, and enhancements to snapshot management and error handling. The changes aim to facilitate a smooth migration process, aligning with the objectives of migrating state data to new backends without loss or corruption and verifying the integrity of the migrated data.

Changes

File(s) Change Summary
store/go.mod Added golang.org/x/sync module at version v0.5.0.
store/migration/manager.go, stream.go Introduced Manager type for migration process from store/v1 to store/v2, and MigrationStream type for handling state transfer.
store/proof/proof.go Updated import from errorsmod to errors package for error handling.
store/snapshots/manager.go, stream.go Extended with methods for creating migration snapshots and introduced WriteCloser interface for streaming.

Assessment against linked issues

Objective Addressed Explanation
Develop a process to migrate the entire state at a specified height to the new store/v2 backends (#19326)
Ensure seamless transition and data integrity during the migration process (#19326)
Implement mechanisms to handle potential data inconsistencies or errors during the migration (#19326) The specific mechanisms for handling data inconsistencies or errors are not explicitly mentioned in the provided summary.
Test the migration process thoroughly to validate its effectiveness and reliability (#19326) While tests for the migration manager are introduced, it's not explicitly stated if thorough testing covering effectiveness and reliability has been conducted.
Document the migration process for future reference and troubleshooting (#19326) The summary does not mention the creation of documentation, which is essential for future reference and troubleshooting.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit-tests for this file.
  • 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 generate unit tests for this file.
    • @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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

github-actions bot commented Feb 1, 2024

@cool-develope your pull request is missing a changelog!

Copy link
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.

Review Status

Actionable comments generated: 7

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between d70eadb and 4e7e68d.
Files selected for processing (7)
  • store/go.mod (1 hunks)
  • store/migration/manager.go (1 hunks)
  • store/migration/manager_test.go (1 hunks)
  • store/migration/stream.go (1 hunks)
  • store/proof/proof.go (3 hunks)
  • store/snapshots/manager.go (1 hunks)
  • store/snapshots/stream.go (1 hunks)
Additional comments: 11
store/migration/manager.go (2)
  • 18-25: The struct Manager is well-defined with clear responsibilities for managing the migration process. The inclusion of both snapshot managers and snapshotter interfaces for storage and commit operations ensures modularity and separation of concerns.
  • 28-34: The constructor NewManager correctly initializes the Manager struct. It adheres to best practices by taking dependencies as arguments, which facilitates testing and decoupling.
store/migration/stream.go (2)
  • 15-21: The MigrationStream struct is well-designed, encapsulating the necessary fields for managing the migration stream. The use of a channel for buffering and an atomic value for error handling is appropriate for concurrent operations.
  • 41-45: The CloseWithError method properly stores the error and closes the channel. This approach for error handling in a concurrent environment is appropriate.
store/go.mod (1)
  • 23-23: The addition of golang.org/x/sync at version v0.5.0 is appropriate for the concurrent features used in the migration process. Ensure that this version is compatible with other dependencies to avoid conflicts.
store/snapshots/stream.go (2)
  • 22-27: The introduction of the WriteCloser interface with a CloseWithError method is a good design choice. It extends protoio.WriteCloser and enhances error handling capabilities during the migration process.
  • 22-27: The CloseWithError method in the StreamWriter struct correctly delegates error handling to the chunkWriter, ensuring that errors are propagated through the stream pipeline. This is a good practice for managing errors in complex I/O operations.
store/proof/proof.go (4)
  • 103-103: The replacement of errorsmod with the standard errors package for error wrapping within the CommitmentOp function is a good simplification. This change streamlines error handling across the migration process.
  • 112-112: The use of errors.Wrapf from the standard errors package for detailed error messages enhances the readability and debuggability of the code. This is a good practice for error handling.
  • 118-118: Consistent use of errors.Wrapf for error handling in the CommitmentOp function maintains code readability and helps in pinpointing the source of errors during the migration process.
  • 122-122: The validation of arguments length in the CommitmentOp function is crucial for ensuring the function is called with the correct data. The detailed error message provided helps in troubleshooting potential issues.

Comment on lines 236 to 258
// CreateMigration creates a migration snapshot and writes it to the given writer.
// It is used to migrate the state from the original store to the store/v2.
func (m *Manager) CreateMigration(height uint64, protoWriter WriteCloser) error {
if m == nil {
return errorsmod.Wrap(store.ErrLogic, "Snapshot Manager is nil")
}

err := m.begin(opSnapshot)
if err != nil {
return err
}
defer m.end()

go func() {
if err := m.commitSnapshotter.Snapshot(height, protoWriter); err != nil {
protoWriter.CloseWithError(err)
return
}
protoWriter.Close()
}()

return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The CreateMigration method is a significant addition, facilitating the creation of a migration snapshot for state migration. It correctly handles the migration process asynchronously, which is essential for performance. However, the method lacks detailed error handling and logging for the asynchronous operation. Consider adding logging for the start and completion of the migration process, as well as error logging.

+		m.logger.Info("Starting migration snapshot creation", "height", height)
+			m.logger.Error("Failed to create migration snapshot", "height", height, "error", err)
+		m.logger.Info("Completed migration snapshot creation", "height", height)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// CreateMigration creates a migration snapshot and writes it to the given writer.
// It is used to migrate the state from the original store to the store/v2.
func (m *Manager) CreateMigration(height uint64, protoWriter WriteCloser) error {
if m == nil {
return errorsmod.Wrap(store.ErrLogic, "Snapshot Manager is nil")
}
err := m.begin(opSnapshot)
if err != nil {
return err
}
defer m.end()
go func() {
if err := m.commitSnapshotter.Snapshot(height, protoWriter); err != nil {
protoWriter.CloseWithError(err)
return
}
protoWriter.Close()
}()
return nil
}
// CreateMigration creates a migration snapshot and writes it to the given writer.
// It is used to migrate the state from the original store to the store/v2.
func (m *Manager) CreateMigration(height uint64, protoWriter WriteCloser) error {
if m == nil {
return errorsmod.Wrap(store.ErrLogic, "Snapshot Manager is nil")
}
err := m.begin(opSnapshot)
if err != nil {
return err
}
defer m.end()
go func() {
m.logger.Info("Starting migration snapshot creation", "height", height)
if err := m.commitSnapshotter.Snapshot(height, protoWriter); err != nil {
protoWriter.CloseWithError(err)
m.logger.Error("Failed to create migration snapshot", "height", height, "error", err)
return
}
protoWriter.Close()
m.logger.Info("Completed migration snapshot creation", "height", height)
}()
return nil
}

@cool-develope cool-develope changed the title feat (store/v2): Implement the state migration feat(store/v2): Implement the state migration Feb 1, 2024
@alexanderbez alexanderbez changed the title feat(store/v2): Implement the state migration feat(store/v2): Implement State Migration Feb 1, 2024
Copy link
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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 4e7e68d and 80c183e.
Files selected for processing (3)
  • store/migration/manager.go (1 hunks)
  • store/migration/stream.go (1 hunks)
  • store/snapshots/manager.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • store/migration/manager.go
  • store/migration/stream.go
  • store/snapshots/manager.go

Copy link
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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 80c183e and d949ac7.
Files selected for processing (1)
  • store/migration/stream.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • store/migration/stream.go

Copy link
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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between d949ac7 and 0ab9208.
Files selected for processing (1)
  • store/migration/stream.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • store/migration/stream.go

@kocubinski
Copy link
Member

kocubinski commented Feb 12, 2024

Some thoughts from reviewing on our team call this morning:

  • Migration could take awhile, consider crash/resume support by storing one (or both) of a) store key migrated, b) deterministic export index reached (in the case of iavl v0/v1 this is post-order node index)
  • Pruning must be halted while migration is in process, ensure this is handled.
  • Consider a no-op path for SC migration when migrating an SSC store (iavl v0/v1) -> SS and SC.
  • Consider publishing entrypoint and CLI for running migration to store v2, or elsewhere if we don't want that code in this repo.

@alexanderbez
Copy link
Contributor

I do think we should evaluate resuming halted migrations, but should be done in a separate PR as to make review slightly easier.

Copy link
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.

Review Status

Actionable comments generated: 0

Configuration used: .coderabbit.yml

Commits Files that changed from the base of the PR and between 0ab9208 and 6be6a17.
Files selected for processing (1)
  • store/migration/stream.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • store/migration/stream.go

@cool-develope
Copy link
Contributor Author

I do think we should evaluate resuming halted migrations, but should be done in a separate PR as to make review slightly easier.

yeah, I've added them to TODOs here #18603

@cool-develope cool-develope added this pull request to the merge queue Feb 13, 2024
Merged via the queue into main with commit 92eb6de Feb 13, 2024
61 of 62 checks passed
@cool-develope cool-develope deleted the store/migration_init branch February 13, 2024 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement the process to migrate the whole state at the given height to the new store/v2 backends
4 participants