-
Notifications
You must be signed in to change notification settings - Fork 577
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
refactor(meta): simplify stream job table/source id assignment #19171
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,7 @@ use risingwave_common::types::DataType; | |
use risingwave_common::util::column_index_mapping::ColIndexMapping; | ||
use risingwave_connector::sink::catalog::SinkId; | ||
use risingwave_meta::manager::{EventLogManagerRef, MetadataManager}; | ||
use risingwave_meta::rpc::ddl_controller::fill_table_stream_graph_info; | ||
use risingwave_meta::rpc::metrics::MetaMetrics; | ||
use risingwave_pb::catalog::table::OptionalAssociatedSourceId; | ||
use risingwave_pb::catalog::{Comment, CreateType, Secret, Table}; | ||
use risingwave_pb::common::worker_node::State; | ||
use risingwave_pb::common::WorkerType; | ||
|
@@ -84,27 +82,28 @@ impl DdlServiceImpl { | |
} | ||
} | ||
|
||
fn extract_replace_table_info(change: ReplaceTablePlan) -> ReplaceTableInfo { | ||
let job_type = change.get_job_type().unwrap_or_default(); | ||
let mut source = change.source; | ||
let mut fragment_graph = change.fragment_graph.unwrap(); | ||
let mut table = change.table.unwrap(); | ||
if let Some(OptionalAssociatedSourceId::AssociatedSourceId(source_id)) = | ||
table.optional_associated_source_id | ||
{ | ||
source.as_mut().unwrap().id = source_id; | ||
fill_table_stream_graph_info(&mut source, &mut table, job_type, &mut fragment_graph); | ||
} | ||
let table_col_index_mapping = change | ||
.table_col_index_mapping | ||
Comment on lines
-87
to
-99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some work is done in |
||
fn extract_replace_table_info( | ||
ReplaceTablePlan { | ||
table, | ||
fragment_graph, | ||
table_col_index_mapping, | ||
source, | ||
job_type, | ||
}: ReplaceTablePlan, | ||
) -> ReplaceTableInfo { | ||
let table = table.unwrap(); | ||
let col_index_mapping = table_col_index_mapping | ||
.as_ref() | ||
.map(ColIndexMapping::from_protobuf); | ||
|
||
let stream_job = StreamingJob::Table(source, table, job_type); | ||
ReplaceTableInfo { | ||
streaming_job: stream_job, | ||
fragment_graph, | ||
col_index_mapping: table_col_index_mapping, | ||
streaming_job: StreamingJob::Table( | ||
source, | ||
table, | ||
TableJobType::try_from(job_type).unwrap(), | ||
), | ||
fragment_graph: fragment_graph.unwrap(), | ||
col_index_mapping, | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ use risingwave_common::secret::SecretEncryption; | |
use risingwave_common::system_param::reader::SystemParamsRead; | ||
use risingwave_common::util::column_index_mapping::ColIndexMapping; | ||
use risingwave_common::util::stream_graph_visitor::{ | ||
visit_fragment, visit_stream_node, visit_stream_node_cont_mut, | ||
visit_stream_node, visit_stream_node_cont_mut, | ||
}; | ||
use risingwave_common::{bail, hash, must_match}; | ||
use risingwave_connector::error::ConnectorError; | ||
|
@@ -40,11 +40,9 @@ use risingwave_meta_model::{ | |
ConnectionId, DatabaseId, FunctionId, IndexId, ObjectId, SchemaId, SecretId, SinkId, SourceId, | ||
SubscriptionId, TableId, UserId, ViewId, | ||
}; | ||
use risingwave_pb::catalog::source::OptionalAssociatedTableId; | ||
use risingwave_pb::catalog::table::OptionalAssociatedSourceId; | ||
use risingwave_pb::catalog::{ | ||
Comment, Connection, CreateType, Database, Function, PbSink, PbSource, PbTable, Schema, Secret, | ||
Sink, Source, Subscription, Table, View, | ||
Comment, Connection, CreateType, Database, Function, PbSink, Schema, Secret, Sink, Source, | ||
Subscription, Table, View, | ||
}; | ||
use risingwave_pb::ddl_service::alter_owner_request::Object; | ||
use risingwave_pb::ddl_service::{ | ||
|
@@ -903,7 +901,7 @@ impl DdlController { | |
pub async fn create_streaming_job( | ||
&self, | ||
mut streaming_job: StreamingJob, | ||
mut fragment_graph: StreamFragmentGraphProto, | ||
fragment_graph: StreamFragmentGraphProto, | ||
affected_table_replace_info: Option<ReplaceTableInfo>, | ||
) -> MetaResult<NotificationVersion> { | ||
let ctx = StreamContext::from_protobuf(fragment_graph.get_ctx().unwrap()); | ||
|
@@ -918,24 +916,6 @@ impl DdlController { | |
.await?; | ||
let job_id = streaming_job.id(); | ||
|
||
match &mut streaming_job { | ||
StreamingJob::Table(src, table, job_type) => { | ||
// If we're creating a table with connector, we should additionally fill its ID first. | ||
fill_table_stream_graph_info(src, table, *job_type, &mut fragment_graph); | ||
} | ||
StreamingJob::Source(src) => { | ||
// set the inner source id of source node. | ||
for fragment in fragment_graph.fragments.values_mut() { | ||
visit_fragment(fragment, |node_body| { | ||
if let NodeBody::Source(source_node) = node_body { | ||
source_node.source_inner.as_mut().unwrap().source_id = src.id; | ||
} | ||
}); | ||
} | ||
} | ||
_ => {} | ||
Comment on lines
-921
to
-936
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do it in |
||
} | ||
|
||
tracing::debug!( | ||
id = job_id, | ||
definition = streaming_job.definition(), | ||
|
@@ -1951,51 +1931,3 @@ impl DdlController { | |
.await | ||
} | ||
} | ||
|
||
/// Fill in necessary information for `Table` stream graph. | ||
/// e.g., fill source id for table with connector, fill external table id for CDC table. | ||
pub fn fill_table_stream_graph_info( | ||
source: &mut Option<PbSource>, | ||
table: &mut PbTable, | ||
table_job_type: TableJobType, | ||
fragment_graph: &mut PbStreamFragmentGraph, | ||
) { | ||
let mut source_count = 0; | ||
for fragment in fragment_graph.fragments.values_mut() { | ||
visit_fragment(fragment, |node_body| { | ||
if let NodeBody::Source(source_node) = node_body { | ||
if source_node.source_inner.is_none() { | ||
// skip empty source for dml node | ||
return; | ||
} | ||
|
||
// If we're creating a table with connector, we should additionally fill its ID first. | ||
if let Some(source) = source { | ||
source_node.source_inner.as_mut().unwrap().source_id = source.id; | ||
source_count += 1; | ||
|
||
assert_eq!( | ||
source_count, 1, | ||
"require exactly 1 external stream source when creating table with a connector" | ||
); | ||
|
||
// Fill in the correct table id for source. | ||
source.optional_associated_table_id = | ||
Some(OptionalAssociatedTableId::AssociatedTableId(table.id)); | ||
// Fill in the correct source id for mview. | ||
table.optional_associated_source_id = | ||
Some(OptionalAssociatedSourceId::AssociatedSourceId(source.id)); | ||
} | ||
} | ||
|
||
// fill table id for cdc backfill | ||
if let NodeBody::StreamCdcScan(node) = node_body | ||
&& table_job_type == TableJobType::SharedCdcSource | ||
{ | ||
if let Some(table_desc) = node.cdc_table_desc.as_mut() { | ||
table_desc.table_id = table.id; | ||
} | ||
} | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's strange not to set
optional_associated_table_id
here.Note: for replace table, the
Source
catalog here were both created again. It looks error-prone, but do not intend to change it.