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

Improve node and services closing #1554

Merged
merged 6 commits into from
Feb 27, 2024
Merged

Improve node and services closing #1554

merged 6 commits into from
Feb 27, 2024

Conversation

tzdybal
Copy link
Member

@tzdybal tzdybal commented Feb 22, 2024

Overview

Resolves #1552
Resolves #1553

Checklist

  • New and updated code has appropriate documentation
  • New and updated code has new and/or updated testing
  • Required CI checks are passing
  • Visual proof for any user facing features like CLI or documentation updates
  • Linked issues closed with keywords

Summary by CodeRabbit

  • New Features

    • Introduced a safe closure mechanism for data storage to enhance system reliability.
  • Bug Fixes

    • Improved error reporting in block submission processes for clearer understanding of operations.
    • Refined the sequence of service shutdowns for more predictable application behavior.
  • Tests

    • Enhanced full node integration tests with simplified context handling and ensured clean-up post-execution.
  • Refactor

    • Adjusted the order of operations in service shutdown methods for better error handling and control flow.
    • Updated test cases to better manage the lifecycle of data storage, ensuring accurate state after restarts.

@tzdybal tzdybal self-assigned this Feb 22, 2024
Copy link
Contributor

coderabbitai bot commented Feb 22, 2024

Walkthrough

The recent changes focus on improving the clean shutdown process of the full node and its associated services by introducing a Close method for safely closing the Store, adjusting the stopping sequence of services, and refining error handling. These modifications aim to prevent data inconsistencies and enhance the clarity and efficiency of shutdown operations.

Changes

File Pattern Change Summary
store/store.go, store/types.go Added Close method to Store interface and its implementation in DefaultStore.
block/...sync.go, node/full.go Adjusted order of stopping services and improved error handling during shutdown.
block/manager.go Updated error messaging for clarity in block submission to the DA layer.
...full_node_integration_test.go Simplified context handling and ensured cleanup after tests with deferred node stops.
store/store_test.go Enhanced lifecycle management in tests, including store reopening and state assertion.

Assessment against linked issues

Objective Addressed Explanation
Add Close method to the Store interface and implement it (#1552)
Improve closing sequence and error handling in services (#1553)
Ensure clean closure of underlying store when FullNode is closed (#1553)
Simplify usage of errors.Join in closing sequences (#1553) The provided summary does not explicitly mention the simplification of errors.Join usage, but improvements in error handling suggest partial addressal.

🐇✨
Changes afoot in the land of code,
Where data sleeps in its humble abode.
A rabbit hopped, with a fix in mind,
To close and clean, and leave no bind.
"Goodnight," it whispered, with a gentle tap,
Ensuring the node could take its nap.
🌙💤

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.

@tzdybal tzdybal added T:bug Something isn't working T:code-hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity. labels Feb 22, 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 UI

Commits Files that changed from the base of the PR and between 8736541 and bc987c0.
Files selected for processing (7)
  • block/block_sync.go (1 hunks)
  • block/header_sync.go (1 hunks)
  • node/full.go (1 hunks)
  • node/full_node_integration_test.go (1 hunks)
  • store/store.go (1 hunks)
  • store/store_test.go (1 hunks)
  • store/types.go (1 hunks)
Additional comments: 8
store/types.go (1)
  • 44-45: The addition of the Close method to the Store interface is a necessary and well-implemented change to support clean shutdown processes. This aligns with the objectives of the PR and follows Go's idiomatic practices for resource management.
store/store_test.go (1)
  • 132-165: The modifications to the TestRestart test case are well-designed to test the new Close method's functionality in the store. Creating a temporary directory for the KV store, properly closing and reopening the store, and asserting the expected height after reopening are all crucial steps that have been correctly implemented. The use of require.NoError for error handling is appropriate for ensuring the test stops immediately if an error occurs.
store/store.go (1)
  • 42-45: The implementation of the Close method in the DefaultStore struct is correctly done, effectively delegating the close operation to the underlying datastore's Close method. This ensures that the datastore is properly closed, aligning with the objectives of enabling a clean shutdown process for the store.
block/block_sync.go (1)
  • 224-228: The modifications to the Stop method in the BlockSyncService, including adjusting the order of stopping services and placing the blockStore.Stop call at the end, are well-thought-out changes that contribute to a cleaner and more orderly shutdown process. The use of errors.Join for error aggregation during the shutdown is a good practice that enhances error handling.
block/header_sync.go (1)
  • 221-225: The modifications to the Stop method, specifically the use of errors.Join for error aggregation, are well-implemented. This approach enhances the readability and maintainability of the error handling logic during the shutdown sequence of the HeaderSyncService. Good job on ensuring a clean and orderly shutdown process.
node/full.go (1)
  • 414-425: The adjustments made to the OnStop method, including the incorporation of p2pClient.Close() and Store.Close() into the error aggregation process, are commendable. These changes ensure a more thorough and clean shutdown process for the FullNode, capturing any errors encountered during resource release. Well done on enhancing the reliability of the shutdown sequence.
node/full_node_integration_test.go (2)
  • 97-98: The simplification of context handling by using a single background context (context.Background()) for both the aggregator and client nodes is a positive change for readability and maintainability. However, it's important to ensure that this change aligns with the intended test behavior, especially regarding asynchronous operations that might require cancellation or timeouts.
  • 101-105: Adding deferred node stops (defer func() { for _, n := range nodes { assert.NoError(n.Stop()) } }()) is a good practice to ensure proper cleanup after test execution. This change helps prevent potential resource leaks and ensures that each node is stopped regardless of how the test exits (e.g., due to an assertion failure or panic). It's a significant improvement in test reliability and resource management.

@tzdybal tzdybal removed the T:code-hygiene General cleanup and restructuring of code to provide clarity, flexibility, and modularity. label Feb 22, 2024
Manav-Aggarwal
Manav-Aggarwal previously approved these changes Feb 23, 2024
@gupadhyaya gupadhyaya self-requested a review February 23, 2024 09:40
gupadhyaya
gupadhyaya previously approved these changes Feb 23, 2024
@tzdybal tzdybal added this pull request to the merge queue Feb 23, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 23, 2024
block/block_sync.go Outdated Show resolved Hide resolved
block/header_sync.go Outdated Show resolved Hide resolved
node/full.go Show resolved Hide resolved
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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d85a8f9 and f82160b.
Files selected for processing (8)
  • block/block_sync.go (1 hunks)
  • block/header_sync.go (1 hunks)
  • block/manager.go (2 hunks)
  • node/full.go (1 hunks)
  • node/full_node_integration_test.go (1 hunks)
  • store/store.go (1 hunks)
  • store/store_test.go (1 hunks)
  • store/types.go (1 hunks)
Files skipped from review as they are similar to previous changes (7)
  • block/block_sync.go
  • block/header_sync.go
  • node/full.go
  • node/full_node_integration_test.go
  • store/store.go
  • store/store_test.go
  • store/types.go

block/manager.go Outdated Show resolved Hide resolved
Manav-Aggarwal
Manav-Aggarwal previously approved these changes Feb 24, 2024
block/manager.go Outdated Show resolved Hide resolved
node/full_node_integration_test.go Outdated Show resolved Hide resolved
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 UI

Commits Files that changed from the base of the PR and between f82160b and bf29762.
Files selected for processing (2)
  • block/manager.go (2 hunks)
  • node/full_node_integration_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • block/manager.go
  • node/full_node_integration_test.go

Manav-Aggarwal
Manav-Aggarwal previously approved these changes Feb 26, 2024
Copy link
Member

@Manav-Aggarwal Manav-Aggarwal left a comment

Choose a reason for hiding this comment

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

LGTM

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 UI

Commits Files that changed from the base of the PR and between 8b1d230 and cb0602f.
Files selected for processing (8)
  • block/block_sync.go (1 hunks)
  • block/header_sync.go (1 hunks)
  • block/manager.go (2 hunks)
  • node/full.go (1 hunks)
  • node/full_node_integration_test.go (1 hunks)
  • store/store.go (1 hunks)
  • store/store_test.go (1 hunks)
  • store/types.go (1 hunks)
Files skipped from review as they are similar to previous changes (8)
  • block/block_sync.go
  • block/header_sync.go
  • block/manager.go
  • node/full.go
  • node/full_node_integration_test.go
  • store/store.go
  • store/store_test.go
  • store/types.go

block/header_sync.go Outdated Show resolved Hide resolved
@gupadhyaya gupadhyaya self-requested a review February 26, 2024 23:18
gupadhyaya
gupadhyaya previously approved these changes Feb 26, 2024
`Close` method was introduced in `Store` interface and implemented in `DefaultSore`. `TestRestart` was updated to use `Close`. It needs to use on-disk KV because it's not possible close and re-open in-memory KV.
Additionally, this commit ensures that Store is closed by Full Node.

The error handling in the stop methods of the Full Node, BlockSyncService, and HeaderSyncService has been refactored. The methods now join and handle the potential errors from closing their services in a more streamlined way. This change simplifies the error handling model and enhances code readability.
The shutdown sequence in the full node was rearranged to ensure proper closure of all services. Instead of immediately cancelling all node tasks and waiting for their termination, the update takes care of shutting down all sub services first before invoking cancellation and thread management wait. Furthermore, the clean-up process in the full node integration test was adjusted to delay node stoppage until after the state testing is done. This is to ensure that the store remains accessible for testing purposes.
The block manager error message is modified to reflect the failed submission attempt more accurately. Rather than stating the total number of blocks and the submitted amount, the error message now includes the number of remaining blocks after the submission attempt. This gives a clearer understanding of the submission state at the point of failure.
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 UI

Commits Files that changed from the base of the PR and between 8a337c4 and c0b3caa.
Files selected for processing (8)
  • block/block_sync.go (1 hunks)
  • block/header_sync.go (1 hunks)
  • block/manager.go (2 hunks)
  • node/full.go (1 hunks)
  • node/full_node_integration_test.go (1 hunks)
  • store/store.go (1 hunks)
  • store/store_test.go (1 hunks)
  • store/types.go (1 hunks)
Files skipped from review as they are similar to previous changes (8)
  • block/block_sync.go
  • block/header_sync.go
  • block/manager.go
  • node/full.go
  • node/full_node_integration_test.go
  • store/store.go
  • store/store_test.go
  • store/types.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 UI

Commits Files that changed from the base of the PR and between 8a337c4 and 8ced59d.
Files selected for processing (8)
  • block/block_sync.go (1 hunks)
  • block/header_sync.go (1 hunks)
  • block/manager.go (2 hunks)
  • node/full.go (1 hunks)
  • node/full_node_integration_test.go (1 hunks)
  • store/store.go (1 hunks)
  • store/store_test.go (1 hunks)
  • store/types.go (1 hunks)
Files skipped from review as they are similar to previous changes (8)
  • block/block_sync.go
  • block/header_sync.go
  • block/manager.go
  • node/full.go
  • node/full_node_integration_test.go
  • store/store.go
  • store/store_test.go
  • store/types.go

@tzdybal tzdybal added this pull request to the merge queue Feb 27, 2024
Merged via the queue into main with commit 9b17117 Feb 27, 2024
18 checks passed
@tzdybal tzdybal deleted the tzdybal/closing branch February 27, 2024 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T:bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Improve closing sequence of full node and header/block sync services No clean way to close Store
4 participants