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: provide a simple way to create metaclient #4257

Merged
merged 3 commits into from
Jul 3, 2024

Conversation

fengjiachun
Copy link
Collaborator

@fengjiachun fengjiachun commented Jul 3, 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?

As the title and @coderabbitai said.

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

  • Refactor

    • Renamed function calls from new_metasrv_client to new_meta_client across several modules.
    • Updated various imports and declarations to use MetaClientRef instead of MetaClient.
    • Introduced MetaClientType enum and create_meta_client function to support different meta client configurations.
  • New Features

    • Added a new MetaClientInit error variant for enhanced error handling.
  • Bug Fixes

    • Modified error handling and status code management to accommodate the new MetaClientInit error variant.

Copy link
Contributor

coderabbitai bot commented Jul 3, 2024

Walkthrough

The change focuses on refactoring and renaming functions related to MetaClient across several Rust modules. Key adjustments include altering function names, updating client types to MetaClientRef, and introducing enums and functions for more flexible meta client creation. The error handling is also expanded to accommodate new variants.

Changes

Files Change Summary
src/cmd/src/datanode.rs, src/cmd/src/flownode.rs Renamed new_metasrv_client function calls to new_meta_client in implementation of StartCommand.
.../src/datanode.rs Updated usage from MetaClient to MetaClientRef in Datanode.
src/cmd/src/error.rs Added MetaClientInit variant to Error enum and updated status_code method.
src/cmd/src/frontend.rs Added MetaClientType and reorganized client creation and error handling.
src/flow/src/heartbeat.rs Renamed and refactored new_metasrv_client to new_meta_client; updated function implementation and imports.
src/frontend/src/instance.rs Replaced older client initialization logic with create_meta_client; updated imports accordingly.
src/meta-client/src/lib.rs Added MetaClientType enum and create_meta_client function for flexible client creation.
tests-integration/src/cluster.rs Modified MetaKvBackend client declaration to remove Arc.
.../examples/lock.rs Transitioned functions to use MetaClientRef instead of MetaClient; introduced Arc wrapper for meta_client.
src/meta-client/src/client.rs Removed Clone trait implementation from MetaClient struct.

Poem

In the heart of code's labyrinthine groove,
Functions morph and clients prove,
Meta's echo, refined and clear,
Under rabbit’s guidance, no longer unclear. 🐇✨
Enums rise, old errors cease to be,
Hopping through logic, bugs set free.
In Rust's fields, we code with glee!

Tip

AI model upgrade

gpt-4o model for reviews and chat is now live

OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our Discord Community to provide any feedback or to report any issues.


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.

@fengjiachun fengjiachun requested a review from WenyXu July 3, 2024 04:08
@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Jul 3, 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: 1

Outside diff range and nitpick comments (1)
src/frontend/src/instance.rs (1)

135-135: Add documentation for the cluster_id variable.

The cluster_id variable is currently set to 0 with a TODO comment. It would be helpful to add documentation explaining why it's reserved and when it should be enabled.

let cluster_id = 0; // TODO: jeremy: It is currently a reserved field and has not been enabled. 
// This variable is reserved for future use when cluster ID functionality is implemented.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0f4b9e5 and a7997c8.

Files selected for processing (6)
  • src/cmd/src/datanode.rs (1 hunks)
  • src/cmd/src/flownode.rs (1 hunks)
  • src/datanode/src/heartbeat.rs (3 hunks)
  • src/flow/src/heartbeat.rs (2 hunks)
  • src/frontend/src/instance.rs (2 hunks)
  • src/meta-client/src/lib.rs (2 hunks)
Additional comments not posted (9)
src/meta-client/src/lib.rs (3)

17-22: Imports look good.

The import statements for ChannelConfig, ChannelManager, and MetaClientBuilder are necessary for building and configuring the meta client.


63-68: Enum MetaClientType is well-defined.

The MetaClientType enum correctly differentiates between the types of meta clients and includes necessary member IDs.


70-114: Function create_meta_client is well-structured.

The create_meta_client function correctly utilizes the MetaClientType enum to create and configure meta clients. The use of ChannelConfig and ChannelManager is appropriate.

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

32-32: Imports look good.

The import statements for MetaClientOptions and MetaClientType are necessary for creating and configuring the meta client.


238-249: Function new_meta_client is well-structured.

The new_meta_client function correctly utilizes the create_meta_client function to create a meta client for the flownode.

src/cmd/src/flownode.rs (1)

229-229: Function call to new_meta_client is correct.

The new_meta_client function call correctly passes the necessary parameters to create a meta client for the flownode.

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

28-29: Imports look good.

The import statements for MetaClientOptions and MetaClientType are necessary for creating and configuring the meta client.


345-357: Function new_meta_client is well-structured.

The new_meta_client function correctly utilizes the create_meta_client function to create a meta client for the datanode.

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

286-286: Function call to new_meta_client is correct.

The new_meta_client function call correctly passes the necessary parameters to create a meta client for the datanode.

src/frontend/src/instance.rs Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jul 3, 2024

Codecov Report

Attention: Patch coverage is 4.68750% with 61 lines in your changes missing coverage. Please review.

Project coverage is 84.71%. Comparing base (11cf9c8) to head (41cecd3).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4257      +/-   ##
==========================================
- Coverage   84.97%   84.71%   -0.26%     
==========================================
  Files        1054     1054              
  Lines      187154   187120      -34     
==========================================
- Hits       159033   158523     -510     
- Misses      28121    28597     +476     

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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a7997c8 and db94781.

Files selected for processing (10)
  • src/cmd/src/datanode.rs (2 hunks)
  • src/cmd/src/error.rs (2 hunks)
  • src/cmd/src/flownode.rs (2 hunks)
  • src/cmd/src/frontend.rs (2 hunks)
  • src/datanode/src/datanode.rs (3 hunks)
  • src/datanode/src/heartbeat.rs (6 hunks)
  • src/flow/src/heartbeat.rs (2 hunks)
  • src/frontend/src/instance.rs (2 hunks)
  • src/meta-client/src/lib.rs (2 hunks)
  • tests-integration/src/cluster.rs (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • src/cmd/src/datanode.rs
  • src/cmd/src/flownode.rs
  • src/datanode/src/heartbeat.rs
  • src/frontend/src/instance.rs
Additional comments not posted (7)
src/meta-client/src/lib.rs (2)

64-69: Enum MetaClientType looks good.

The enum MetaClientType is well-defined and follows Rust's best practices.


73-117: Ensure proper error handling and logging in create_meta_client.

The function is well-structured, but it would be beneficial to verify that all potential errors are properly handled and logged.

src/cmd/src/error.rs (1)

343-348: Error variant MetaClientInit looks good.

The error variant MetaClientInit is well-defined and follows Rust's best practices.

tests-integration/src/cluster.rs (1)

321-324: Ensure consistent usage of MetaClientRef.

The update to use MetaClientRef looks correct. Verify that the MetaClientRef usage is consistent across the codebase.

Verification successful

Consistent usage of MetaClientRef verified.

The MetaClientRef is used consistently across the codebase in the following locations:

  • src/datanode/src/heartbeat.rs
  • src/datanode/src/datanode.rs
  • src/meta-client/src/lib.rs

The type alias MetaClientRef is defined as Arc<client::MetaClient>, ensuring a consistent reference type across the codebase.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify consistent usage of `MetaClientRef`.

# Test: Search for `MetaClientRef` usage.
rg --type rust 'MetaClientRef'

Length of output: 591

src/datanode/src/datanode.rs (3)

37-37: Import of MetaClientRef looks good.

The import is necessary for the subsequent changes that utilize MetaClientRef instead of MetaClient.


158-158: Update of meta_client field to use MetaClientRef looks good.

This change aligns with the new approach of using MetaClientRef and is necessary for the new initialization logic.


174-174: Update of with_meta_client method to use MetaClientRef looks good.

This change is consistent with the previous updates and necessary for the correct initialization of MetaClientRef.

src/cmd/src/frontend.rs 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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between db94781 and 41cecd3.

Files selected for processing (2)
  • src/meta-client/examples/lock.rs (6 hunks)
  • src/meta-client/src/client.rs (1 hunks)
Additional comments not posted (7)
src/meta-client/examples/lock.rs (5)

Line range hint 53-75: LGTM!

The function run_normal correctly uses the MetaClientRef type for meta_client.


Line range hint 76-91: LGTM!

The function run_multi_thread correctly uses the MetaClientRef type for meta_client.


Line range hint 92-107: LGTM!

The function run_multi_thread_with_one_timeout correctly uses the MetaClientRef type for meta_client.


Line range hint 108-132: LGTM!

The function run_with_timeout correctly uses the MetaClientRef type for meta_client.


44-44: Ensure correct usage of MetaClientRef.

The meta_client is now an Arc<MetaClientRef>. Verify that all usages of meta_client correctly handle the Arc type.

Verification successful

Ensure correct usage of MetaClientRef.

The meta_client is correctly handled as Arc<MetaClientRef> in the relevant files.

  • src/meta-client/examples/lock.rs: The meta_client is wrapped in Arc and passed as MetaClientRef to various functions.
  • src/meta-client/src/lib.rs: The meta_client is returned as Arc<MetaClientRef> from the create_meta_client function.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify correct usage of `meta_client` as `Arc<MetaClientRef>`.

# Test: Search for `meta_client` usage. Expect: Correct handling of `Arc<MetaClientRef>`.
rg --type rust $'meta_client'

Length of output: 18626



Script:

#!/bin/bash
# Extract the relevant code snippets from the files of interest

# Extract code from src/meta-client/examples/lock.rs
echo "Code from src/meta-client/examples/lock.rs:"
rg --context 5 'meta_client' src/meta-client/examples/lock.rs

# Extract code from src/meta-client/src/lib.rs
echo -e "\nCode from src/meta-client/src/lib.rs:"
rg --context 5 'meta_client' src/meta-client/src/lib.rs

Length of output: 5009

src/meta-client/src/client.rs (2)

216-216: LGTM!

The MetaClient struct has been updated to remove the Clone trait, which is consistent with the changes to use MetaClientRef.


216-216: Ensure correct handling of MetaClientRef in all methods.

Verify that all methods in the MetaClient implementations correctly handle the MetaClientRef type.

@fengjiachun fengjiachun added this pull request to the merge queue Jul 3, 2024
Merged via the queue into GreptimeTeam:main with commit ddf2e6a Jul 3, 2024
52 checks passed
@fengjiachun fengjiachun deleted the feat/create-meta-clients branch July 3, 2024 08:28
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