@@ -51,6 +51,7 @@ use databend_common_meta_api::serialize_struct;
5151use databend_common_meta_api:: util:: IdempotentKVTxnSender ;
5252use databend_common_meta_app:: KeyWithTenant ;
5353use databend_common_meta_app:: app_error:: AppError ;
54+ use databend_common_meta_app:: app_error:: TableEngineMismatch ;
5455use databend_common_meta_app:: data_mask:: CreateDatamaskReq ;
5556use databend_common_meta_app:: data_mask:: DataMaskNameIdent ;
5657use databend_common_meta_app:: data_mask:: DatamaskMeta ;
@@ -318,6 +319,8 @@ impl SchemaApiTestSuite {
318319 + ' static ,
319320 {
320321 self . table_commit_table_meta ( & b. build ( ) . await ) . await ?;
322+ self . table_commit_table_meta_engine_mismatch ( & b. build ( ) . await )
323+ . await ?;
321324 self . concurrent_commit_table_meta ( b. clone ( ) ) . await ?;
322325 self . database_drop_out_of_retention_time_history ( & b. build ( ) . await )
323326 . await ?;
@@ -2634,11 +2637,11 @@ impl SchemaApiTestSuite {
26342637 table_properties : None ,
26352638 table_partition : None ,
26362639 } ;
2640+ let expected = KVAppError :: AppError ( AppError :: from ( TableEngineMismatch :: new (
2641+ table, "JSON" , "STREAM" ,
2642+ ) ) ) ;
26372643 let err = mt. create_table ( mismatched_req. clone ( ) ) . await . unwrap_err ( ) ;
2638- assert ! ( matches!(
2639- err,
2640- KVAppError :: AppError ( AppError :: TableEngineMismatch ( _) )
2641- ) ) ;
2644+ assert_eq ! ( err, expected) ;
26422645 assert_eq ! ( table_id, get_kv_u64_data( mt, & key_dbid_tbname) . await ?) ;
26432646 assert_eq ! ( "JSON" , util. get_table_by_name( table) . await ?. meta. engine) ;
26442647
@@ -2648,10 +2651,7 @@ impl SchemaApiTestSuite {
26482651 as_dropped_req. as_dropped = true ;
26492652 as_dropped_req. table_meta . drop_on = Some ( Utc :: now ( ) ) ;
26502653 let err = mt. create_table ( as_dropped_req) . await . unwrap_err ( ) ;
2651- assert ! ( matches!(
2652- err,
2653- KVAppError :: AppError ( AppError :: TableEngineMismatch ( _) )
2654- ) ) ;
2654+ assert_eq ! ( err, expected) ;
26552655 assert_eq ! ( table_id, get_kv_u64_data( mt, & key_dbid_tbname) . await ?) ;
26562656 }
26572657
@@ -6523,6 +6523,88 @@ impl SchemaApiTestSuite {
65236523 Ok ( ( ) )
65246524 }
65256525
6526+ async fn table_commit_table_meta_engine_mismatch < MT > ( & self , mt : & MT ) -> anyhow:: Result < ( ) >
6527+ where MT : kvapi:: KVApi < Error = MetaError > + DatabaseApi + TableApi {
6528+ let tenant_name = "table_commit_table_meta_engine_mismatch" ;
6529+ let db_name = "db" ;
6530+ let table_name = "table" ;
6531+ let mut util = DbTableHarness :: new ( mt, tenant_name, db_name, table_name, "JSON" ) ;
6532+ util. create_db ( ) . await ?;
6533+ let ( previous_table_id, previous_meta) = util. create_table ( ) . await ?;
6534+
6535+ let mut replacement_meta = previous_meta. clone ( ) ;
6536+ replacement_meta. drop_on = Some ( Utc :: now ( ) ) ;
6537+ let create_req = CreateTableReq {
6538+ create_option : CreateOption :: CreateOrReplace ,
6539+ catalog_name : Some ( "default" . to_string ( ) ) ,
6540+ name_ident : TableNameIdent {
6541+ tenant : util. tenant ( ) ,
6542+ db_name : db_name. to_string ( ) ,
6543+ table_name : table_name. to_string ( ) ,
6544+ } ,
6545+ table_meta : replacement_meta,
6546+ as_dropped : true ,
6547+ materialized_view : None ,
6548+ table_properties : None ,
6549+ table_partition : None ,
6550+ } ;
6551+ let create_reply = mt. create_table ( create_req. clone ( ) ) . await ?;
6552+ assert_eq ! ( create_reply. prev_table_id, Some ( previous_table_id) ) ;
6553+
6554+ let previous_tbid = TableId :: new ( previous_table_id) ;
6555+ let mut changed_previous_meta = previous_meta;
6556+ changed_previous_meta. engine = "STREAM" . to_string ( ) ;
6557+ upsert_test_data ( mt, & previous_tbid, serialize_struct ( & changed_previous_meta) ) . await ?;
6558+
6559+ let dbid_tbname = DBIdTableName {
6560+ db_id : create_reply. db_id ,
6561+ table_name : table_name. to_string ( ) ,
6562+ } ;
6563+ let history_ident = TableIdHistoryIdent {
6564+ database_id : create_reply. db_id ,
6565+ table_name : table_name. to_string ( ) ,
6566+ } ;
6567+ let orphan_history_ident = TableIdHistoryIdent {
6568+ database_id : create_reply. db_id ,
6569+ table_name : create_reply. orphan_table_name . clone ( ) . unwrap ( ) ,
6570+ } ;
6571+ let replacement_tbid = TableId :: new ( create_reply. table_id ) ;
6572+
6573+ let name_before = mt. get_pb ( & dbid_tbname) . await ?;
6574+ let history_before = mt. get_pb ( & history_ident) . await ?;
6575+ let orphan_history_before = mt. get_pb ( & orphan_history_ident) . await ?;
6576+ let previous_before = mt. get_pb ( & previous_tbid) . await ?;
6577+ let replacement_before = mt. get_pb ( & replacement_tbid) . await ?;
6578+
6579+ let err = mt
6580+ . commit_table_meta ( CommitTableMetaReq {
6581+ name_ident : create_req. name_ident ,
6582+ db_id : create_reply. db_id ,
6583+ table_id : create_reply. table_id ,
6584+ prev_table_id : create_reply. prev_table_id ,
6585+ orphan_table_name : create_reply. orphan_table_name ,
6586+ } )
6587+ . await
6588+ . unwrap_err ( ) ;
6589+ assert_eq ! (
6590+ err,
6591+ KVAppError :: AppError ( AppError :: from( TableEngineMismatch :: new(
6592+ table_name, "STREAM" , "JSON"
6593+ ) ) )
6594+ ) ;
6595+
6596+ assert_eq ! ( mt. get_pb( & dbid_tbname) . await ?, name_before) ;
6597+ assert_eq ! ( mt. get_pb( & history_ident) . await ?, history_before) ;
6598+ assert_eq ! (
6599+ mt. get_pb( & orphan_history_ident) . await ?,
6600+ orphan_history_before
6601+ ) ;
6602+ assert_eq ! ( mt. get_pb( & previous_tbid) . await ?, previous_before) ;
6603+ assert_eq ! ( mt. get_pb( & replacement_tbid) . await ?, replacement_before) ;
6604+
6605+ Ok ( ( ) )
6606+ }
6607+
65266608 async fn concurrent_commit_table_meta <
65276609 B : kvapi:: ApiBuilder < MT > ,
65286610 MT : kvapi:: KVApi < Error = MetaError > + DatabaseApi + TableApi + ' static ,
0 commit comments