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(sql-backend): support table replace for sql-backend #14415

Merged
merged 37 commits into from
Jan 16, 2024

Conversation

yezizp2012
Copy link
Member

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

What's changed and what's your intention?

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • 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.

@yezizp2012 yezizp2012 changed the title feat: support table replace for sql-backend feat(sql-backend): support table replace for sql-backend Jan 8, 2024
@yezizp2012 yezizp2012 force-pushed the feat/support-v2-throttle-rate branch from a9d54d4 to 8aecb4b Compare January 9, 2024 07:58
@yezizp2012 yezizp2012 force-pushed the feat/support-v2-replace branch from dd8e14e to ede0956 Compare January 9, 2024 08:09
Base automatically changed from feat/support-v2-throttle-rate to main January 11, 2024 08:33
@yezizp2012 yezizp2012 marked this pull request as ready for review January 11, 2024 08:55
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.

Added some comments for better review.

@@ -187,10 +187,28 @@ impl From<PbTable> for ActiveModel {
let table_type = pb_table.table_type();
let handle_pk_conflict_behavior = pb_table.handle_pk_conflict_behavior();

let fragment_id = if pb_table.fragment_id == u32::MAX - 1 {
Copy link
Member Author

Choose a reason for hiding this comment

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

These are some workaround to determinate wether it's new created or not.

Copy link
Member

Choose a reason for hiding this comment

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

IIUC, this is the placeholder ID. Can we extract a constant as it's not intuitive?

}

// 2. create streaming object for new replace table.
let obj_id = Self::create_streaming_job_obj(
Copy link
Member Author

Choose a reason for hiding this comment

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

Here we still use a dummy id that represents a new streaming job to achieve table replacement. The dummy streaming job will alway be Foreground, so that if recovery encountered and the replacement is not completed it will be cleaned.

.await?;

// 3. record dependency for new replace table.
ObjectDependency::insert(object_dependency::ActiveModel {
Copy link
Member Author

Choose a reason for hiding this comment

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

Record the dependency info for replacement, so that the table is not allowed to be dropped during replacement. The record will be deleted cascade when the dummy job is removed after finish or recovery.

let table = table::ActiveModel::from(table).update(&txn).await?;

// 1. replace old fragments/actors with new ones.
Fragment::delete_many()
Copy link
Member Author

Choose a reason for hiding this comment

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

Delete old fragments and actors and move the new ones from dummy job to it.


// TODO: remove cache upstream fragment/actor ids and derive them from `actor_dispatcher` table.
let mut to_update_fragment_ids = HashSet::new();
for merge_update in merge_updates {
Copy link
Member Author

Choose a reason for hiding this comment

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

Update merge information in downstream fragments and actors.

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.

rubber stamp

@@ -187,10 +187,28 @@ impl From<PbTable> for ActiveModel {
let table_type = pb_table.table_type();
let handle_pk_conflict_behavior = pb_table.handle_pk_conflict_behavior();

let fragment_id = if pb_table.fragment_id == u32::MAX - 1 {
Copy link
Member

Choose a reason for hiding this comment

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

IIUC, this is the placeholder ID. Can we extract a constant as it's not intuitive?

@yezizp2012 yezizp2012 requested a review from a team as a code owner January 16, 2024 08:58
@yezizp2012 yezizp2012 enabled auto-merge January 16, 2024 09:00
@yezizp2012 yezizp2012 added this pull request to the merge queue Jan 16, 2024
Merged via the queue into main with commit ae348ab Jan 16, 2024
27 checks passed
@yezizp2012 yezizp2012 deleted the feat/support-v2-replace branch January 16, 2024 09:52
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.

2 participants