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(meta): initialization and modeling for sql-backend based meta store #12454

Merged
merged 38 commits into from
Sep 27, 2023

Conversation

yezizp2012
Copy link
Member

@yezizp2012 yezizp2012 commented Sep 20, 2023

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

Related #12449 , this is the very first step of sql-backend based meta store. In this PR, we have modeled and initialized the existing entities except those related to hummock, and implemented some controller logic based on these models, such as SystemParamsController, CatalogController, etc. For other models, you can refer to their implementation to gradually replace other managers.

I added a README.md doc under model_v2 to introduce the steps of defining relations and changes of new model and generate of related files. Cc @zwang28, you can refer to this to model hummock metadata.

Close #12475.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

github-actions[bot]

This comment was marked as resolved.

@yezizp2012 yezizp2012 force-pushed the feat/sql-backend-meta branch 2 times, most recently from 66a9b0d to db605b8 Compare September 20, 2023 07:35
Copy link
Member Author

@yezizp2012 yezizp2012 left a comment

Choose a reason for hiding this comment

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

Add some comments for better review and as well as guidance on how to modeling and initialization.

@@ -0,0 +1,51 @@
// Copyright 2023 RisingWave Labs
Copy link
Member Author

Choose a reason for hiding this comment

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

Defined all models under model_v2 directory.

pub mod worker_property;

#[derive(Clone, Debug, PartialEq, FromJsonQueryResult, Eq, Serialize, Deserialize, Default)]
pub struct I32Array(pub Vec<i32>);
Copy link
Member Author

Choose a reason for hiding this comment

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

Define I32Array struct which can be used in other models. Since only PostgreSQL supports array type, we will define the field as Json and use I32Array instead in the model.

use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "String(None)")]
pub enum WorkerType {
Copy link
Member Author

Choose a reason for hiding this comment

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

Define enum for model field and store as string in table.


#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
Copy link
Member Author

Choose a reason for hiding this comment

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

Initial version of sql backend, defined tables, foreign keys, indexes and some initial data.

Copy link
Member

Choose a reason for hiding this comment

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

May I ask if this file was generated by sea-orm, or was hand-written?

Copy link
Member

Choose a reason for hiding this comment

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

The migration file itself is generated by sea-orm, but the detailed migration logic is hand-written.

That sounds okay since we don't have to maintain this migration file anymore. 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

The migration file itself is generated by sea-orm, but the detailed migration logic is hand-written.

That sounds okay since we don't have to maintain this migration file anymore. 😄

Yes, we only need to add some new migration file to include any data correctness, table schema change etc in it, then the system will upgrade automatically. The file won't be too complicate for each version I believe.

.boolean()
.not_null(),
)
.foreign_key(
Copy link
Member Author

Choose a reason for hiding this comment

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

For SQLite, foreign key can only be defined along with the table.

)
.col(ColumnDef::new(Fragment::StreamNode).json().not_null())
.col(ColumnDef::new(Fragment::VnodeMapping).json())
.col(ColumnDef::new(Fragment::StateTableIds).json())
Copy link
Member Author

Choose a reason for hiding this comment

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

For example, defines json type here and derived to array in the model of table fragment.

}

#[derive(DeriveIden)]
enum Cluster {
Copy link
Member Author

Choose a reason for hiding this comment

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

Define each table as enum and use it in migration.

@@ -352,12 +378,31 @@ pub async fn start_service_as_election_leader(
mut svc_shutdown_rx: WatchReceiver<()>,
) -> MetaResult<()> {
tracing::info!("Defining leader services");
if let Some(sql_store) = &meta_store_sql {
Copy link
Member Author

Choose a reason for hiding this comment

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

Check and do auto upgrade when meta starts. It will run any migration plans if found in this version. It will ignore if all plans are applied already.

@codecov
Copy link

codecov bot commented Sep 21, 2023

Codecov Report

Merging #12454 (bea7128) into main (0126304) will increase coverage by 0.03%.
Report is 1 commits behind head on main.
The diff coverage is 73.94%.

@@            Coverage Diff             @@
##             main   #12454      +/-   ##
==========================================
+ Coverage   69.37%   69.41%   +0.03%     
==========================================
  Files        1440     1469      +29     
  Lines      238947   240650    +1703     
==========================================
+ Hits       165762   167038    +1276     
- Misses      73185    73612     +427     
Flag Coverage Δ
rust 69.41% <73.94%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/meta/src/model_v2/migration/src/lib.rs 100.00% <100.00%> (ø)
src/meta/src/model_v2/migration/src/main.rs 0.00% <0.00%> (ø)
src/meta/src/model_v2/mod.rs 0.00% <0.00%> (ø)
src/meta/src/model_v2/system_parameter.rs 50.00% <50.00%> (ø)
src/common/src/system_param/mod.rs 84.13% <50.00%> (ø)
src/meta/src/model_v2/cluster.rs 0.00% <0.00%> (ø)
src/meta/src/model_v2/election_leader.rs 0.00% <0.00%> (ø)
src/meta/src/model_v2/election_member.rs 0.00% <0.00%> (ø)
src/meta/src/model_v2/object_dependency.rs 0.00% <0.00%> (ø)
src/meta/src/lib.rs 0.00% <0.00%> (ø)
... and 25 more

... and 14 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@shanicky shanicky left a comment

Choose a reason for hiding this comment

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

LGTM, we need more test in the future

@BugenZhao
Copy link
Member

Will review later. 🥵

Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

🥵🚀🤯

src/common/src/system_param/mod.rs Show resolved Hide resolved
src/meta/src/controller/catalog.rs Show resolved Hide resolved
src/meta/src/controller/catalog.rs Show resolved Hide resolved
src/meta/src/model_v2/actor.rs Show resolved Hide resolved

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
Copy link
Member

Choose a reason for hiding this comment

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

May I ask if this file was generated by sea-orm, or was hand-written?

src/meta/src/controller/catalog.rs Outdated Show resolved Hide resolved
src/meta/src/controller/catalog.rs Show resolved Hide resolved
@BugenZhao
Copy link
Member

BugenZhao commented Sep 25, 2023

BTW, have we investigated diesel ORM or directly using sqlx? What's the comparison between them?

@yezizp2012
Copy link
Member Author

BTW, have we investigated diesel ORM or directly using sqlx? What's the comparison between them?

diesel is non-async right now. Using sea-orm is to be compatible with different backends and avoid writing duplicate logic for different backends.

@BugenZhao
Copy link
Member

BTW, have we investigated diesel ORM or directly using sqlx? What's the comparison between them?

diesel is non-async right now. Using sea-orm is to be compatible with different backends and avoid writing duplicate logic for different backends.

I see.

  • diesel-async is experimental, where sqlite is not supported.
  • Although sqlx supports any driver, it doesn't seem to handle the dialects between different systems.

@BugenZhao BugenZhao requested a review from fuyufjh September 26, 2023 06:47
Copy link
Member

@fuyufjh fuyufjh left a comment

Choose a reason for hiding this comment

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

Generally LGTM

src/meta/src/controller/catalog.rs Show resolved Hide resolved
src/meta/src/controller/system_param.rs Show resolved Hide resolved
Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

LGTM!!!!!!!!

@yezizp2012 yezizp2012 added this pull request to the merge queue Sep 27, 2023
Merged via the queue into main with commit 6f9c5c2 Sep 27, 2023
7 of 8 checks passed
@yezizp2012 yezizp2012 deleted the feat/sql-backend-meta branch September 27, 2023 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(meta): modeling, Initialization and auto upgrade for sql meta store
4 participants