From fa9d860ee01499b47f8dae6b767cda85c41bd71c Mon Sep 17 00:00:00 2001 From: lichuang Date: Wed, 20 Dec 2023 11:07:53 +0800 Subject: [PATCH 1/4] chore: fix drop share database error --- src/query/sharing/src/share_endpoint.rs | 10 +++++++--- src/query/sql/src/planner/binder/table.rs | 13 ++++++++----- .../01_sharing/01_0000_basic_sharing.result | 15 ++------------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/query/sharing/src/share_endpoint.rs b/src/query/sharing/src/share_endpoint.rs index 643828d268d9..bbb498af145b 100644 --- a/src/query/sharing/src/share_endpoint.rs +++ b/src/query/sharing/src/share_endpoint.rs @@ -141,9 +141,13 @@ impl ShareEndpointManager { match resp { Ok(resp) => { let bs = resp.into_body().bytes().await?; - let table_info_map: TableInfoMap = serde_json::from_slice(&bs)?; - - Ok(table_info_map) + match serde_json::from_slice(&bs) { + Ok(table_info_map) => Ok(table_info_map), + Err(e) => Err(ErrorCode::UnknownShareTable(format!( + "Fail to get TableInfoMap from share {:?}: {:?}", + share_name, e + ))), + } } Err(err) => Err(err.into()), } diff --git a/src/query/sql/src/planner/binder/table.rs b/src/query/sql/src/planner/binder/table.rs index bc56357f61d1..d2fb22c36c38 100644 --- a/src/query/sql/src/planner/binder/table.rs +++ b/src/query/sql/src/planner/binder/table.rs @@ -241,7 +241,7 @@ impl Binder { .await { Ok(table) => table, - Err(_) => { + Err(e) => { let mut parent = bind_context.parent.as_mut(); loop { if parent.is_none() { @@ -260,10 +260,13 @@ impl Binder { } parent = bind_context.parent.as_mut(); } - return Err(ErrorCode::UnknownTable(format!( - "Unknown table `{database}`.`{table_name}` in catalog '{catalog}'" - )) - .set_span(*span)); + if e.code() == 1025 { + return Err(ErrorCode::UnknownTable(format!( + "Unknown table `{database}`.`{table_name}` in catalog '{catalog}'" + )) + .set_span(*span)); + } + return Err(e); } }; diff --git a/tests/suites/3_stateful_sharing/01_sharing/01_0000_basic_sharing.result b/tests/suites/3_stateful_sharing/01_sharing/01_0000_basic_sharing.result index 479014f66658..1763bc8ac869 100644 --- a/tests/suites/3_stateful_sharing/01_sharing/01_0000_basic_sharing.result +++ b/tests/suites/3_stateful_sharing/01_sharing/01_0000_basic_sharing.result @@ -56,18 +56,7 @@ drop shared database and query data from share 4 5 6 -ERROR 1105 (HY000) at line 1: UnknownTable. Code: 1025, Text = error: - --> SQL:1:15 - | -1 | SELECT * FROM shared_db.t2 - | ^^^^^^^^^^^^ Unknown table `shared_db`.`t2` in catalog 'default' +ERROR 1105 (HY000): UnknownShareTable. Code: 2717, Text = Fail to get TableInfoMap from share "test_share": Error("expected value", line: 1, column: 1). +ERROR 1105 (HY000): UnknownShareTable. Code: 2717, Text = Fail to get TableInfoMap from share "test_share": Error("expected value", line: 1, column: 1). -. -ERROR 1105 (HY000) at line 1: UnknownTable. Code: 1025, Text = error: - --> SQL:1:15 - | -1 | SELECT * FROM shared_db.t2 - | ^^^^^^^^^^^^ Unknown table `shared_db`.`t2` in catalog 'default' - -. all is good From 760a653db47b092d5feff48e9d4871bb29ed3539 Mon Sep 17 00:00:00 2001 From: lichuang Date: Wed, 20 Dec 2023 17:36:36 +0800 Subject: [PATCH 2/4] chore: fix drop share database error --- src/common/exception/src/exception_code.rs | 1 + src/query/sharing/src/share_endpoint.rs | 14 ++++++++++++-- .../01_sharing/01_0000_basic_sharing.result | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/common/exception/src/exception_code.rs b/src/common/exception/src/exception_code.rs index 137caee6372c..6f605c4870c9 100644 --- a/src/common/exception/src/exception_code.rs +++ b/src/common/exception/src/exception_code.rs @@ -307,6 +307,7 @@ build_exceptions! { UnknownShareEndpointId(2716), UnknownShareTable(2717), CannotShareDatabaseCreatedFromShare(2718), + ShareStorageError(2719), // Index error codes. CreateIndexWithDropTime(2720), diff --git a/src/query/sharing/src/share_endpoint.rs b/src/query/sharing/src/share_endpoint.rs index bbb498af145b..41340121a348 100644 --- a/src/query/sharing/src/share_endpoint.rs +++ b/src/query/sharing/src/share_endpoint.rs @@ -140,11 +140,21 @@ impl ShareEndpointManager { let resp = self.client.send(req).await; match resp { Ok(resp) => { + if !resp.status().is_success() { + return Err(ErrorCode::ShareStorageError(format!( + "share {:?} storage error: HTTP status {:?}", + share_name, + match resp.status().canonical_reason() { + Some(reason) => reason.to_string(), + None => resp.status().to_string(), + } + ))); + } let bs = resp.into_body().bytes().await?; match serde_json::from_slice(&bs) { Ok(table_info_map) => Ok(table_info_map), - Err(e) => Err(ErrorCode::UnknownShareTable(format!( - "Fail to get TableInfoMap from share {:?}: {:?}", + Err(e) => Err(ErrorCode::ShareStorageError(format!( + "share {:?} storage error: deser json file error: {:?}", share_name, e ))), } diff --git a/tests/suites/3_stateful_sharing/01_sharing/01_0000_basic_sharing.result b/tests/suites/3_stateful_sharing/01_sharing/01_0000_basic_sharing.result index 1763bc8ac869..cdbeceaa24f5 100644 --- a/tests/suites/3_stateful_sharing/01_sharing/01_0000_basic_sharing.result +++ b/tests/suites/3_stateful_sharing/01_sharing/01_0000_basic_sharing.result @@ -56,7 +56,7 @@ drop shared database and query data from share 4 5 6 -ERROR 1105 (HY000): UnknownShareTable. Code: 2717, Text = Fail to get TableInfoMap from share "test_share": Error("expected value", line: 1, column: 1). -ERROR 1105 (HY000): UnknownShareTable. Code: 2717, Text = Fail to get TableInfoMap from share "test_share": Error("expected value", line: 1, column: 1). +ERROR 1105 (HY000): ShareStorageError. Code: 2719, Text = share "test_share" storage error: HTTP status "Bad Request". +ERROR 1105 (HY000): ShareStorageError. Code: 2719, Text = share "test_share" storage error: HTTP status "Bad Request". all is good From ad14e6f7672466b6bf01136346067c1b0103af05 Mon Sep 17 00:00:00 2001 From: lichuang Date: Wed, 20 Dec 2023 20:59:19 +0800 Subject: [PATCH 3/4] chore: fix drop share database error --- src/query/sql/src/planner/binder/table.rs | 2 +- .../01_sharing/01_0000_basic_sharing.result | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/query/sql/src/planner/binder/table.rs b/src/query/sql/src/planner/binder/table.rs index d2fb22c36c38..c84e5bb26b1e 100644 --- a/src/query/sql/src/planner/binder/table.rs +++ b/src/query/sql/src/planner/binder/table.rs @@ -260,7 +260,7 @@ impl Binder { } parent = bind_context.parent.as_mut(); } - if e.code() == 1025 { + if e.code() == ErrorCode::UNKNOWN_TABLE { return Err(ErrorCode::UnknownTable(format!( "Unknown table `{database}`.`{table_name}` in catalog '{catalog}'" )) diff --git a/tests/suites/3_stateful_sharing/01_sharing/01_0000_basic_sharing.result b/tests/suites/3_stateful_sharing/01_sharing/01_0000_basic_sharing.result index cdbeceaa24f5..d071ee200614 100644 --- a/tests/suites/3_stateful_sharing/01_sharing/01_0000_basic_sharing.result +++ b/tests/suites/3_stateful_sharing/01_sharing/01_0000_basic_sharing.result @@ -56,7 +56,7 @@ drop shared database and query data from share 4 5 6 -ERROR 1105 (HY000): ShareStorageError. Code: 2719, Text = share "test_share" storage error: HTTP status "Bad Request". -ERROR 1105 (HY000): ShareStorageError. Code: 2719, Text = share "test_share" storage error: HTTP status "Bad Request". +ERROR 1105 (HY000) at line 1: ShareStorageError. Code: 2719, Text = share "test_share" storage error: HTTP status "Bad Request". +ERROR 1105 (HY000) at line 1: ShareStorageError. Code: 2719, Text = share "test_share" storage error: HTTP status "Bad Request". all is good From f5f83f27fbe4132aa1e1ed73d4925ea215bce3b4 Mon Sep 17 00:00:00 2001 From: lichuang Date: Wed, 20 Dec 2023 21:25:52 +0800 Subject: [PATCH 4/4] ci --- .../3_stateful_sharing/01_sharing/01_0000_basic_sharing.result | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/suites/3_stateful_sharing/01_sharing/01_0000_basic_sharing.result b/tests/suites/3_stateful_sharing/01_sharing/01_0000_basic_sharing.result index d071ee200614..75e7a5dfe1ea 100644 --- a/tests/suites/3_stateful_sharing/01_sharing/01_0000_basic_sharing.result +++ b/tests/suites/3_stateful_sharing/01_sharing/01_0000_basic_sharing.result @@ -58,5 +58,4 @@ drop shared database and query data from share 6 ERROR 1105 (HY000) at line 1: ShareStorageError. Code: 2719, Text = share "test_share" storage error: HTTP status "Bad Request". ERROR 1105 (HY000) at line 1: ShareStorageError. Code: 2719, Text = share "test_share" storage error: HTTP status "Bad Request". - all is good