Skip to content
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: refactor error message return for drop table and set options #14078

Merged
merged 13 commits into from Dec 20, 2023

Conversation

JackTan25
Copy link
Collaborator

@JackTan25 JackTan25 commented Dec 19, 2023

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

There are bad code written by before unexpectedly. We should process the error correctly. For alter option and drop table, when they can't get table, if the error is not unknown table, we should return the true error message,

mysql> show tables;
Empty set (0.21 sec)
Read 0 rows, 0.00 B in 0.042 sec., 0 rows/sec., 0.00 B/sec.

mysql> drop table t1;
ERROR 1105 (HY000): UnknownTable. Code: 1025, Text = Unknown table `default`.`t1` in catalog 'default'.
mysql> drop table if exists t1;
Query OK, 0 rows affected (0.01 sec)

mysql> alter table t1 set options(block_per_segment = 500);
ERROR 1105 (HY000): UnknownTable. Code: 1025, Text = Unknown table `default`.`t1` in catalog 'default'.
## close databend-meta
mysql> drop table if exists t1;
ERROR 1105 (HY000): MetaServiceError. Code: 2001, Text = failed to handshake with meta-service: when sending handshake rpc, cause: tonic::status::Status: status: Unavailable, message: "error trying to connect: tcp connect error: Connection refused (os error 61)", details: [], metadata: MetadataMap { headers: {} } source: transport error source: error trying to connect: tcp connect error: Connection refused (os error 61) source: tcp connect error: Connection refused (os error 61) source: Connection refused (os error 61)
(while
mysql> drop table t1;
ERROR 1105 (HY000): MetaServiceError. Code: 2001, Text = failed to handshake with meta-service: when sending handshake rpc, cause: tonic::status::Status: status: Unavailable, message: "error trying to connect: tcp connect error: Connection refused (os error 61)", details: [], metadata: MetadataMap { headers: {} } source: transport error source: error trying to connect: tcp connect error: Connection refused (os error 61) source: tcp connect error: Connection refused (os error 61) source: Connection refused (os error 61)
(while
mysql> alter table t1 set options(block_per_segment = 500);
ERROR 1105 (HY000): MetaServiceError. Code: 2001, Text = failed to handshake with meta-service: when sending handshake rpc, cause: tonic::status::Status: status: Unavailable, message: "error trying to connect: tcp connect error: Connection refused (os error 61)", details: [], metadata: MetadataMap { headers: {} } source: transport error source: error trying to connect: tcp connect error: Connection refused (os error 61) source: tcp connect error: Connection refused (os error 61) source: Connection refused (os error 61)
(while

Fixes #[Link the issue here]
#14072 #14071

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - just refactor little code

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@github-actions github-actions bot added the pr-refactor this PR changes the code base without new features or bugfix label Dec 19, 2023
@JackTan25 JackTan25 changed the title refactor: remove bad code refactor: refactor error message return for drop table and set options Dec 19, 2023
Copy link
Member

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @dantengsky and @JackTan25)


src/query/service/src/interpreters/interpreter_table_drop.rs line 61 at r1 (raw file):

            Err(error) => {
                // UnknownTable Code
                if error.code() == 1025 {

Do not use integer literal, use a named const or something people understand

@JackTan25 JackTan25 marked this pull request as ready for review December 19, 2023 17:11
Copy link
Member

@drmingdrmer drmingdrmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 4 files at r4, all commit messages.
Reviewable status: 2 of 8 files reviewed, 5 unresolved discussions (waiting on @dantengsky, @JackTan25, and @ZhiHanZ)


src/query/service/src/interpreters/interpreter_table_drop.rs line 62 at r4 (raw file):

                if (error.code() == ErrorCode::UNKNOWN_TABLE
                    || error.code() == ErrorCode::UNKNOWN_CATALOG
                    || error.code() == ErrorCode::UNKNOWN_DATABASE)

get_table() also returns business errors such as: WrongShare, WrongShareObject, UnknownTableId. These errors should be caught too.

return Err(KVAppError::AppError(AppError::WrongShare(WrongShare::new(

WrongShareObject::new(table_name.to_string_key()),

UnknownTableId::new(*id, "get_table_names_by_ids"),

@drmingdrmer
Copy link
Member

@JackTan25
Copy link
Collaborator Author

please see https://github.com/datafuselabs/databend/pull/14078/files#diff-4bba49bb358f77b13cd8e8f9fb64f654d0112ff6c0ba5f5b2bfb72d498cc99afR67 @drmingdrmer

I see. What should I be concerned about? 🤔

I just express that we can return the error to fronted end.

@dantengsky dantengsky added this pull request to the merge queue Dec 20, 2023
Merged via the queue into datafuselabs:main with commit 923f589 Dec 20, 2023
74 of 75 checks passed
@drmingdrmer
Copy link
Member

please see https://github.com/datafuselabs/databend/pull/14078/files#diff-4bba49bb358f77b13cd8e8f9fb64f654d0112ff6c0ba5f5b2bfb72d498cc99afR67 @drmingdrmer

I see. What should I be concerned about? 🤔

I just express that we can return the error to fronted end.

You caught these 3 errors:

 if (error.code() == ErrorCode::UNKNOWN_TABLE
                    || error.code() == ErrorCode::UNKNOWN_CATALOG
                    || error.code() == ErrorCode::UNKNOWN_DATABASE)

But get_table() will also returns : WrongShare, WrongShareObject, UnknownTableId errors.

Why do you have to deal with UNKNOWN_TABLE, UNKNOWN_CATALOG and UNKNOWN_DATABASE but do not deal with the former three?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-refactor this PR changes the code base without new features or bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants