Skip to content

Commit a1f06e0

Browse files
committed
feat: validate table name match in undrop procedure
Add a guard in `UndropTableProcedure::on_prepare()` to check that the dropped table name matches the undrop task name, returning `TableNotFound` on mismatch. This prevents undropping a table by a different name when only the table ID is known. - `src/common/meta/src/ddl/undrop_table.rs` — add table-name validation - `src/common/meta/src/ddl/tests/drop_table.rs` — add test for name mismatch Signed-off-by: Lei, HUANG <ratuthomm@gmail.com>
1 parent 6d755ad commit a1f06e0

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

src/common/meta/src/ddl/tests/drop_table.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,37 @@ async fn test_undrop_table_fails_when_live_name_exists() {
757757
assert_matches!(err, Error::TableAlreadyExists { .. });
758758
}
759759

760+
#[tokio::test]
761+
async fn test_undrop_table_fails_when_task_name_mismatches_table_id() {
762+
let node_manager = Arc::new(MockDatanodeManager::new(NaiveDatanodeHandler));
763+
let mut ddl_context = new_ddl_context(node_manager);
764+
ddl_context.soft_drop_enabled = true;
765+
let table_id = 1024;
766+
let task = test_create_table_task("foo", table_id);
767+
ddl_context
768+
.table_metadata_manager
769+
.create_table_metadata(
770+
task.table_info.clone(),
771+
TableRouteValue::physical(vec![]),
772+
HashMap::new(),
773+
)
774+
.await
775+
.unwrap();
776+
let mut drop_procedure = DropTableProcedure::new(
777+
new_drop_table_task("foo", table_id, false),
778+
ddl_context.clone(),
779+
);
780+
execute_procedure_until_done(&mut drop_procedure).await;
781+
782+
let mut procedure = UndropTableProcedure::new(
783+
new_undrop_table_task("bar", table_id),
784+
ddl_context,
785+
);
786+
let err = procedure.on_prepare().await.unwrap_err();
787+
788+
assert_eq!(err.status_code(), StatusCode::TableNotFound);
789+
}
790+
760791
#[tokio::test]
761792
async fn test_purge_dropped_table_drops_regions_and_deletes_tombstone() {
762793
let (tx, mut rx) = mpsc::channel(8);

src/common/meta/src/ddl/undrop_table.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ impl UndropTableProcedure {
9494
.with_context(|| error::TableNotFoundSnafu {
9595
table_name: table_ref.to_string(),
9696
})?;
97+
ensure!(
98+
dropped_table.table_name == self.data.task.table_name(),
99+
error::TableNotFoundSnafu {
100+
table_name: table_ref.to_string()
101+
}
102+
);
97103
self.data.table_name = Some(dropped_table.table_name.clone());
98104
self.data.table_route_value = Some(dropped_table.table_route_value.clone());
99105
self.data.region_wal_options = dropped_table.region_wal_options;

0 commit comments

Comments
 (0)