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: add build info for flow heartbeat task #4228

Merged

Conversation

fengjiachun
Copy link
Collaborator

@fengjiachun fengjiachun commented Jun 28, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

What's changed and what's your intention?

  1. refactor load region stats to avoid resizing of vec
  2. add build info for flow heartbeat task

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.

Summary by CodeRabbit

  • New Features

    • Enhanced heartbeat reporting with additional node information and start time metrics.
  • Improvements

    • Improved logging for heartbeat tasks.
    • Optimized region statistics loading for performance.
  • Refactor

    • Simplified asynchronous handling in region disk usage.
    • Introduced new method for creating heartbeat requests with enhanced error handling.

@fengjiachun fengjiachun requested review from zhongzc, waynexia and a team as code owners June 28, 2024 09:28
@fengjiachun fengjiachun requested review from discord9 and WenyXu and removed request for a team, waynexia, zhongzc and discord9 June 28, 2024 09:29
Copy link
Contributor

coderabbitai bot commented Jun 28, 2024

Walkthrough

The provided changes streamline logging, refactor code for better readability and efficiency, and make structural modifications in the Datanode and HeartbeatTask implementations across various files. Additionally, a workspace entry is added in the Cargo.toml, and asynchronous behavior in region disk usage is removed for performance enhancements.

Changes

Files Change Summary
src/datanode/src/datanode.rs Removed an await statement after calling close() on heartbeat_task.
src/datanode/src/heartbeat.rs Modified logging capitalization, refactored load_region_stats, added NodeInfo, and updated methods for HeartbeatTask.
src/datanode/src/region_server.rs Changed the signature of region_disk_usage to be synchronous by removing async.
src/flow/Cargo.toml Added a new workspace entry common-version.workspace.
src/frontend/src/heartbeat.rs Modified build_node_info to return Option<NodeInfo> and added create_heartbeat_request with new parameters and logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Datanode
    participant HeartbeatTask
    User->>Datanode: Initiates closing of heartbeat_task
    Datanode->>HeartbeatTask: Sends close request without awaiting
    Note right of Datanode: Improves performance

    Note over HeartbeatTask: Start time tracking is added
    HeartbeatTask->>HeartbeatTask: Initialize start_time_ms

    Note over HeartbeatTask: Changed build_node_info to return Optional<NodeInfo>
    HeartbeatTask->>HeartbeatTask: create_heartbeat_request(message, peer, start_time_ms)
    Note right of HeartbeatTask: Handles new parameters and error handling
Loading

Poem

The Datanode is swift, responsive and bright,
Logging more clearly, through the endless night.
As heartbeats are tracked in a careful chase,
New fields added, for an accurate pace.
Region disk usage with no async delay,
Efficiency shines in the workflow today.
With Cargo workspace, all things in array.


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 testing code for this file.
    • 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 generate unit testing code 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 and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @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.

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 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.
  • 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.

@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Jun 28, 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.

Actionable comments posted: 2

Outside diff range and nitpick comments (1)
src/datanode/src/heartbeat.rs (1)

Line range hint 248-329: Refactor suggestion for load_region_stats method.

The method has been refactored to use a more functional style with map, which improves readability and efficiency. However, consider handling the case where region_disk_usage might return None more gracefully.

-                approximate_bytes: region_server.region_disk_usage(stat.region_id).unwrap_or(0),
+                approximate_bytes: region_server.region_disk_usage(stat.region_id).unwrap_or_default(),

This change ensures that if region_disk_usage returns None, it defaults to 0 without causing a panic.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ef935a1 and 5536258.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (6)
  • src/datanode/src/datanode.rs (1 hunks)
  • src/datanode/src/heartbeat.rs (3 hunks)
  • src/datanode/src/region_server.rs (1 hunks)
  • src/flow/Cargo.toml (1 hunks)
  • src/flow/src/heartbeat.rs (6 hunks)
  • src/frontend/src/heartbeat.rs (2 hunks)
Files skipped from review due to trivial changes (2)
  • src/datanode/src/datanode.rs
  • src/flow/Cargo.toml
Additional comments not posted (7)
src/frontend/src/heartbeat.rs (2)

135-142: Enhancement in build_node_info method.

The method now returns Option<NodeInfo>, which allows for better error handling by calling methods. The inclusion of start_time_ms is aligned with the PR's goal to add build information. Ensure that all callers handle the None case appropriately.


166-174: Usage of create_heartbeat_request in heartbeat report loop.

The method is correctly used to create heartbeat requests based on conditions. This dynamic creation based on message availability is a good use of Rust's pattern matching and option handling. Ensure that the None case for the sender being dropped is adequately handled in the system's overall error management strategy.

src/flow/src/heartbeat.rs (2)

111-117: Enhancement in build_node_info method.

This method now returns Option<NodeInfo>, which allows for better error handling. The inclusion of start_time_ms aligns with the PR's objectives. Ensure that all callers handle the None case appropriately.


142-149: Usage of create_heartbeat_request in heartbeat report loop.

The method is used correctly to create heartbeat requests based on message availability. This dynamic creation is a good application of Rust's pattern matching and option handling. Ensure that the None case for the sender being dropped is adequately handled.

src/datanode/src/heartbeat.rs (2)

161-161: Added tracing in handle_response method.

The addition of a trace log before handling a heartbeat response is a good practice for debugging and monitoring. Ensure that the logging level and message are appropriate for the operation's importance and frequency.


332-332: Proper handling in close method.

The method now properly checks if the heartbeat task is already closed before proceeding. This is a good practice to prevent errors from multiple closures. Ensure that any resources are properly cleaned up after closure.

src/datanode/src/region_server.rs (1)

293-293: Updated region_disk_usage method.

The method has been updated to remove its asynchronous nature, which simplifies the interface and potentially improves performance by reducing overhead. Ensure that all callers have been updated to handle this synchronous method appropriately.

src/frontend/src/heartbeat.rs Show resolved Hide resolved
src/flow/src/heartbeat.rs Show resolved Hide resolved
Copy link

codecov bot commented Jun 28, 2024

Codecov Report

Attention: Patch coverage is 49.12281% with 29 lines in your changes missing coverage. Please review.

Project coverage is 84.57%. Comparing base (b6585e3) to head (5536258).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4228      +/-   ##
==========================================
- Coverage   84.89%   84.57%   -0.32%     
==========================================
  Files        1040     1045       +5     
  Lines      183506   184274     +768     
==========================================
+ Hits       155789   155852      +63     
- Misses      27717    28422     +705     

Copy link
Contributor

@killme2008 killme2008 left a comment

Choose a reason for hiding this comment

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

LGTM

@WenyXu WenyXu added this pull request to the merge queue Jul 1, 2024
Merged via the queue into GreptimeTeam:main with commit 214fd38 Jul 1, 2024
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required This change does not impact docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants