Skip to content

Commit 0975be2

Browse files
authored
fix(sql-backend): clean up dirty source catalogs for failed table with connectors and recovery (#15110)
1 parent 16ae65b commit 0975be2

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/meta/model_v2/migration/src/m20230908_072257_init.rs

+8
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,14 @@ impl MigrationTrait for Migration {
519519
.to(Connection::Table, Connection::ConnectionId)
520520
.to_owned(),
521521
)
522+
.foreign_key(
523+
&mut ForeignKey::create()
524+
.name("FK_source_optional_associated_table_id")
525+
.from(Source::Table, Source::OptionalAssociatedTableId)
526+
.to(Object::Table, Object::Oid)
527+
.on_delete(ForeignKeyAction::Cascade)
528+
.to_owned(),
529+
)
522530
.to_owned(),
523531
)
524532
.await?;

src/meta/src/controller/catalog.rs

+1
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ impl CatalogController {
468468
.clone()
469469
.into_iter()
470470
.chain(state_table_ids.clone().into_iter())
471+
.chain(associated_source_ids.clone().into_iter())
471472
.collect();
472473

473474
let res = Object::delete_many()

src/meta/src/controller/streaming_job.rs

+11
Original file line numberDiff line numberDiff line change
@@ -401,13 +401,24 @@ impl CatalogController {
401401
.all(&txn)
402402
.await?;
403403

404+
let associated_source_id: Option<SourceId> = Table::find_by_id(job_id)
405+
.select_only()
406+
.column(table::Column::OptionalAssociatedSourceId)
407+
.filter(table::Column::OptionalAssociatedSourceId.is_not_null())
408+
.into_tuple()
409+
.one(&txn)
410+
.await?;
411+
404412
Object::delete_by_id(job_id).exec(&txn).await?;
405413
if !internal_table_ids.is_empty() {
406414
Object::delete_many()
407415
.filter(object::Column::Oid.is_in(internal_table_ids))
408416
.exec(&txn)
409417
.await?;
410418
}
419+
if let Some(source_id) = associated_source_id {
420+
Object::delete_by_id(source_id).exec(&txn).await?;
421+
}
411422
txn.commit().await?;
412423

413424
Ok(true)

0 commit comments

Comments
 (0)