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: flownode use Inserter to write to database #4323

Merged
merged 11 commits into from
Jul 9, 2024

Conversation

discord9
Copy link
Contributor

@discord9 discord9 commented Jul 9, 2024

I hereby agree to the terms of the GreptimeDB CLA.

flownode now use Inserter/Deleter to write to database, hence removing need to specify frontend addr and such

  • add RemoteFrontendInvoker and it's builder to build a frontend invoker
  • call inovker to set it for flownode

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 error handling and context management in standalone mode with new invoker setup.
    • Improved frontend invocation setup through build_frontend_invoker.
  • Refactor

    • Reorganized frontend server connection and initialization processes.
    • Updated several object instantiations to use cloned parameters for improved stability.
  • Bug Fixes

    • Addressed issues in the FlowWorkerManager to handle shutdown signals more effectively.
  • Documentation

    • Revised method and struct definitions to clarify new frontend invoker and error handling procedures.

@discord9 discord9 requested review from zhongzc, waynexia, MichaelScofield and a team as code owners July 9, 2024 06:23
Copy link
Contributor

coderabbitai bot commented Jul 9, 2024

Walkthrough

The recent changes introduce significant refactoring and new features for handling invocations in Flownode and flow modules. Specifically, these updates involve importing new dependencies, improving error handling, reorganizing the frontend connection setup, and incorporating clone operations for various manager objects. This enhances code modularity and robustness, particularly in initializing and managing frontend and backend components.

Changes

File Path Change Summary
tests-integration/.../standalone.rs Added imports for error handling, and modified object instantiation with cloning and additional parameters.
src/cmd/src/flownode.rs Reorganized frontend server setup, introduced build_frontend_invoker function, and refined error types.
src/cmd/src/standalone.rs Imported RemoteFrontendInvoker, modified error handling, and updated datanode and frontend instantiation.
src/flow/src/adapter.rs Removed frontend_addr in FlownodeOptions, made query_engine public, and refined the FlowWorkerManager methods.
src/flow/src/server.rs Introduced new imports, added FrontendInvoker struct, implemented related methods, and updated query engine management.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant StartCommand
    participant CacheRegistry
    participant CatalogManager
    participant DDLTaskExecutor
    participant FlowWorkerManager
    participant FrontendInvoker

    User->>StartCommand: Initiates StartCommand
    StartCommand->>CacheRegistry: Clones cache registry
    StartCommand->>CatalogManager: Clones catalog manager
    StartCommand->>DDLTaskExecutor: Clones DDL task executor
    StartCommand->>FlowWorkerManager: Creates and initializes with invoker
    FlowWorkerManager->>FrontendInvoker: Uses FrontendInvoker for setup
    StartCommand->>User: Returns initialized components
Loading

Poem

In code's vast field, managed flow,
Frontend whispers, backend glows.
Clones and invokers, tasks align,
Robust paths in error's decline.
With rabbit's hop, improvements show,
In tech’s embrace, we smoothly go. 🚀🐇


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 Jul 9, 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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1a9314a and dc16971.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (8)
  • src/cmd/Cargo.toml (2 hunks)
  • src/cmd/src/flownode.rs (4 hunks)
  • src/cmd/src/standalone.rs (5 hunks)
  • src/flow/Cargo.toml (1 hunks)
  • src/flow/src/error.rs (2 hunks)
  • src/flow/src/lib.rs (1 hunks)
  • src/flow/src/server.rs (4 hunks)
  • src/meta-client/src/client.rs (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/meta-client/src/client.rs
Additional comments not posted (18)
src/flow/src/lib.rs (1)

41-44: LGTM! Verify consistency of exported entities.

The added exports align with the new functionality introduced in the PR. Ensure that the names are consistently used across the codebase and correctly spelled.

src/flow/Cargo.toml (1)

50-51: LGTM! Verify necessity of added dependencies.

The added dependencies for operator and partition align with the new functionality introduced in the PR. Ensure that these dependencies are necessary and used in the codebase.

src/cmd/Cargo.toml (1)

Line range hint 19-32:
LGTM! Verify necessity of added dependencies.

The added dependencies for api and common-frontend align with the new functionality introduced in the PR. Ensure that these dependencies are necessary and used in the codebase.

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

193-199: LGTM! Verify necessity of added error variant.

The added error variant CacheRequired aligns with the new functionality introduced in the PR. Ensure that this error variant is necessary and used in the codebase.


226-226: LGTM! Verify necessity of added status code handling.

The added status code handling for CacheRequired aligns with the new functionality introduced in the PR. Ensure that this status code handling is necessary and used in the codebase.

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

29-29: New imports approved.

The newly added imports build_frontend_invoker, FlownodeBuilder, and FlownodeInstance are necessary for the subsequent changes and are correctly integrated.


38-38: New error variant import approved.

The newly added error variant StartFlownodeSnafu is necessary for the subsequent changes and is correctly integrated.


284-285: Creation and initialization of table_metadata_manager approved.

The table_metadata_manager is correctly created and initialized, ensuring proper metadata management.


309-309: Addition of catalog_manager in FlownodeBuilder approved.

The catalog_manager is correctly cloned and passed to FlownodeBuilder, ensuring proper catalog management.


315-325: Invoker creation and setting approved.

The build_frontend_invoker method is correctly called to create an invoker, which is then set using set_frontend_invoker. Error handling is appropriately managed with StartFlownodeSnafu.

Ensure that all function calls to build_frontend_invoker and set_frontend_invoker are correctly handled in the codebase.

src/flow/src/server.rs (4)

20-51: New imports approved.

The newly added imports are necessary for the subsequent changes and are correctly integrated.


327-331: Definition of RemoteFrondendInvoker struct approved.

The RemoteFrondendInvoker struct is correctly defined with necessary fields for inserter, deleter, and statement_executor.


333-372: Implementation of RemoteFrondendInvoker methods approved.

The RemoteFrondendInvoker methods new, row_inserts, and row_deletes are correctly implemented and handle errors appropriately.


374-438: Definition of build_frontend_invoker function approved.

The build_frontend_invoker function is correctly defined with necessary parameters for catalog_manager, kv_backend, layered_cache_registry, and procedure_executor.

src/cmd/src/standalone.rs (4)

47-47: New imports approved.

The newly added imports build_frontend_invoker and FlownodeBuilder are necessary for the subsequent changes and are correctly integrated.


69-69: New error variant import approved.

The newly added error variant StartFlownodeSnafu is necessary for the subsequent changes and is correctly integrated.


451-455: Instantiation and initialization of datanode approved.

The datanode is correctly instantiated and initialized using DatanodeBuilder.


526-536: Invoker creation and setting approved.

The build_frontend_invoker method is correctly called to create an invoker, which is then set using set_frontend_invoker. Error handling is appropriately managed with StartFlownodeSnafu.

Ensure that all function calls to build_frontend_invoker and set_frontend_invoker are correctly handled in the codebase.

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 dc16971 and ed3ad0e.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (7)
  • config/config.md (1 hunks)
  • config/flownode.example.toml (1 hunks)
  • src/cmd/src/flownode.rs (6 hunks)
  • src/cmd/src/standalone.rs (5 hunks)
  • src/flow/src/adapter.rs (2 hunks)
  • src/flow/src/lib.rs (1 hunks)
  • src/flow/src/server.rs (4 hunks)
Files skipped from review due to trivial changes (2)
  • config/flownode.example.toml
  • src/flow/src/adapter.rs
Files skipped from review as they are similar to previous changes (3)
  • src/cmd/src/standalone.rs
  • src/flow/src/lib.rs
  • src/flow/src/server.rs
Additional comments not posted (5)
src/cmd/src/flownode.rs (4)

29-29: LGTM! Import statements are correctly added.

The new imports are necessary for the new functionality introduced in the file.


38-38: LGTM! Error handling is correctly updated.

The new error variant StartFlownodeSnafu is necessary for handling errors during the start of the flownode.


276-277: LGTM! table_metadata_manager initialization is correctly added.

The initialization of table_metadata_manager is necessary for managing table metadata.


307-317: LGTM! Invoker setup is correctly added.

The setup of RemoteFrondendInvoker is necessary for the new functionality.

However, ensure that the RemoteFrondendInvoker is properly tested and integrated with the rest of the system.

config/config.md (1)

Line range hint 1-1:
LGTM! Configuration changes are correctly updated.

The removal of frontend_addr is in line with the changes introduced in the PR.

However, ensure that all references to frontend_addr are removed from the documentation.

Copy link

codecov bot commented Jul 9, 2024

Codecov Report

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

Project coverage is 84.89%. Comparing base (7fe3f49) to head (390b20c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4323      +/-   ##
==========================================
- Coverage   85.17%   84.89%   -0.28%     
==========================================
  Files        1061     1060       -1     
  Lines      188392   188643     +251     
==========================================
- Hits       160469   160157     -312     
- Misses      27923    28486     +563     

@WenyXu WenyXu mentioned this pull request Jul 9, 2024
3 tasks
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 ed3ad0e and ba188a3.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (10)
  • src/cmd/src/flownode.rs (6 hunks)
  • src/cmd/src/standalone.rs (9 hunks)
  • src/common/frontend/src/lib.rs (1 hunks)
  • src/flow/Cargo.toml (2 hunks)
  • src/flow/src/adapter.rs (10 hunks)
  • src/flow/src/lib.rs (2 hunks)
  • src/flow/src/server.rs (7 hunks)
  • src/frontend/src/instance.rs (2 hunks)
  • tests-integration/src/standalone.rs (3 hunks)
  • tests/runner/src/env.rs (1 hunks)
Files skipped from review due to trivial changes (2)
  • src/common/frontend/src/lib.rs
  • tests/runner/src/env.rs
Files skipped from review as they are similar to previous changes (4)
  • src/cmd/src/standalone.rs
  • src/flow/Cargo.toml
  • src/flow/src/lib.rs
  • src/flow/src/server.rs
Additional comments not posted (12)
tests-integration/src/standalone.rs (3)

19-19: LGTM!

The addition of StartFlownodeSnafu for error handling is appropriate.


212-215: LGTM!

The instantiation of instance with additional parameters (cache_registry, catalog_manager, ddl_task_executor) is appropriate and aligns with the new FrontendInvoker setup.


222-235: LGTM!

The construction of invoker and its usage in flow_worker_manager is a necessary addition for the new mechanism where FrontendInvoker handles frontend interactions.

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

29-29: LGTM!

The new imports related to FlownodeBuilder, FlownodeInstance, and FrontendInvoker are necessary for the new functionality.


38-38: LGTM!

The addition of StartFlownodeSnafu for error handling is appropriate.


Line range hint 276-318:
LGTM!

The instantiation of table_metadata_manager, flownode_builder, and the construction of invoker are necessary for the new mechanism where FrontendInvoker handles frontend interactions.

src/frontend/src/instance.rs (3)

Line range hint 68-68:
LGTM!

The removal of the FrontendInvoker import aligns with the new mechanism.


Line range hint 68-68:
LGTM!

The removal of the FrontendInvoker implementation for Instance is appropriate given the new mechanism.


Line range hint 68-68:
LGTM!

The removal of the row_inserts and row_deletes methods is appropriate given the new mechanism.

src/flow/src/adapter.rs (3)

44-45: LGTM!

The new imports related to tokio::sync::broadcast and tokio::sync::RwLock are necessary for the new functionality.


122-125: LGTM!

The addition of frontend_invoker to the FlowWorkerManager struct is necessary for the new mechanism where FrontendInvoker handles frontend interactions.


137-137: LGTM!

The new method set_frontend_invoker is crucial for setting the FrontendInvoker in the new mechanism.

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

Outside diff range and nitpick comments (1)
config/config.md (1)

Line range hint 4-4:
Add documentation for Inserter and Deleter usage in flownode.

The PR summary indicates changes to enable flownode to use Inserter and Deleter for database operations. Ensure the documentation reflects these changes.

Do you want me to generate the documentation or open a GitHub issue to track this task?

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ba188a3 and e517863.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (14)
  • config/config.md (1 hunks)
  • config/flownode.example.toml (1 hunks)
  • src/cmd/src/flownode.rs (6 hunks)
  • src/cmd/src/standalone.rs (9 hunks)
  • src/common/frontend/src/lib.rs (1 hunks)
  • src/flow/Cargo.toml (2 hunks)
  • src/flow/src/adapter.rs (10 hunks)
  • src/flow/src/error.rs (2 hunks)
  • src/flow/src/lib.rs (2 hunks)
  • src/flow/src/server.rs (7 hunks)
  • src/frontend/src/instance.rs (2 hunks)
  • src/meta-client/src/client.rs (1 hunks)
  • tests-integration/src/standalone.rs (3 hunks)
  • tests/runner/src/env.rs (1 hunks)
Files skipped from review as they are similar to previous changes (7)
  • src/common/frontend/src/lib.rs
  • src/flow/Cargo.toml
  • src/flow/src/adapter.rs
  • src/flow/src/error.rs
  • src/flow/src/lib.rs
  • tests-integration/src/standalone.rs
  • tests/runner/src/env.rs
Additional comments not posted (15)
src/cmd/src/flownode.rs (4)

29-29: Import statement for FrontendInvoker looks good.

The import is correctly added.


276-278: Initialization of TableMetadataManager looks good.

The initialization is correctly implemented.


301-318: Building and setting up FrontendInvoker looks good.

The code correctly builds and sets up FrontendInvoker with necessary components.

Ensure that FrontendInvoker is correctly integrated and utilized in the rest of the codebase.


307-318: Setting FrontendInvoker to flow_worker_manager looks good.

The code correctly sets FrontendInvoker to flow_worker_manager.

Ensure proper error handling and testing for this integration.

src/flow/src/server.rs (4)

20-21: Import statements for RowDeleteRequests and RowInsertRequests look good.

The import statements are correctly added.


276-284: Building FlowWorkerManager looks good.

The code correctly builds FlowWorkerManager.

Ensure proper error handling and testing for this integration.


Line range hint 307-318: Setting FrontendInvoker to flow_worker_manager looks good.

The code correctly sets FrontendInvoker to flow_worker_manager.

Ensure proper error handling and testing for this integration.


329-432: Implementation of FrontendInvoker looks good.

The implementation of FrontendInvoker and its methods is comprehensive and appears correct.

Ensure thorough testing and proper error handling for this implementation.

src/frontend/src/instance.rs (1)

Line range hint 329-432: Implementation of FrontendInvoker looks good.

The implementation of FrontendInvoker and its methods is comprehensive and appears correct.

Ensure thorough testing and proper error handling for this implementation.

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

108-108: Approve the addition of enable_procedure to flownode default options.

The change ensures that the flownode has procedures enabled by default, aligning with the PR objectives.

src/cmd/src/standalone.rs (5)

47-47: Approve the addition of FrontendInvoker import.

The import is necessary for the changes introduced in the PR.


70-72: Approve the addition of StartFlownodeSnafu error variant.

The error variant is necessary for handling errors related to starting the flownode.


219-220: Approve the addition of flow_worker_manager field and TODO comment.

The new field is necessary for managing flow workers in the instance, and the TODO comment indicates future work.


253-255: Approve the addition of code to start the flow worker manager.

The added code ensures that the flow worker manager runs in the background when the instance starts.


274-282: Approve the addition of code to send a shutdown signal to the flow worker manager.

The added code ensures that the flow worker manager is properly shut down when the instance stops.

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 e517863 and 0a58a69.

Files selected for processing (4)
  • src/cmd/src/flownode.rs (6 hunks)
  • src/cmd/src/standalone.rs (9 hunks)
  • src/flow/src/adapter.rs (10 hunks)
  • tests-integration/src/standalone.rs (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/flow/src/adapter.rs
  • tests-integration/src/standalone.rs
Additional comments not posted (8)
src/cmd/src/flownode.rs (4)

29-29: Imports look good.

The added imports FlownodeBuilder, FlownodeInstance, and FrontendInvoker are necessary for the new functionality.


38-38: Error handling update is appropriate.

The inclusion of StartFlownodeSnafu in error handling is consistent with the new functionality.


276-277: Instantiation and initialization of table_metadata_manager is correct.

The code correctly sets up and initializes the table_metadata_manager with proper error handling.


307-318: Instantiation and setting of FrontendInvoker is correct.

The code correctly instantiates FrontendInvoker using build_from and sets it for the flow_worker_manager.

src/cmd/src/standalone.rs (4)

47-47: Imports look good.

The added imports FlowWorkerManager, FlownodeBuilder, and FrontendInvoker are necessary for the new functionality.


70-72: Error handling update is appropriate.

The inclusion of StartFlownodeSnafu and ShutdownFlownodeSnafu in error handling is consistent with the new functionality.


219-221: Instantiation of flow_worker_manager and flow_shutdown is correct.

The code correctly sets up and initializes the flow_worker_manager and flow_shutdown in the Instance struct.


542-552: Instantiation and setting of FrontendInvoker is correct.

The code correctly instantiates FrontendInvoker using build_from and sets it for the flow_worker_manager.

Copy link
Collaborator

@fengjiachun fengjiachun left a comment

Choose a reason for hiding this comment

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

Rest 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.

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 0a58a69 and 390b20c.

Files selected for processing (5)
  • src/cmd/src/flownode.rs (6 hunks)
  • src/cmd/src/standalone.rs (9 hunks)
  • src/flow/src/adapter.rs (10 hunks)
  • src/flow/src/server.rs (7 hunks)
  • tests-integration/src/standalone.rs (3 hunks)
Files skipped from review as they are similar to previous changes (5)
  • src/cmd/src/flownode.rs
  • src/cmd/src/standalone.rs
  • src/flow/src/adapter.rs
  • src/flow/src/server.rs
  • tests-integration/src/standalone.rs

@discord9 discord9 added this pull request to the merge queue Jul 9, 2024
Merged via the queue into GreptimeTeam:main with commit 1ddf19d Jul 9, 2024
63 checks passed
@discord9 discord9 deleted the flow_comp_fe branch July 9, 2024 11:01
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.

4 participants