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

MySQL Handler Kill Query #5448

Merged
merged 1 commit into from
May 19, 2022

Conversation

TCeason
Copy link
Collaborator

@TCeason TCeason commented May 18, 2022

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

Summary

MySQL Client support according to "Ctrl C" interrupt a long query.
Link to discussion: #5405

Changelog

  • New Feature

Related Issues

Fixes #4871

@vercel
Copy link

vercel bot commented May 18, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
databend ✅ Ready (Inspect) Visit Preview May 19, 2022 at 8:32AM (UTC)

@mergify
Copy link
Contributor

mergify bot commented May 18, 2022

Thanks for the contribution!
I have applied any labels matching special text in your PR Changelog.

Please review the labels and make any necessary changes.

@mergify mergify bot added the pr-feature this PR introduces a new feature to the codebase label May 18, 2022
@TCeason TCeason force-pushed the ISSUE-4871/handle_mysql_kill branch from a675b5a to c571dd1 Compare May 18, 2022 14:01
@BohuTANG BohuTANG requested review from zhang2014 and sundy-li and removed request for BohuTANG May 18, 2022 14:03
@@ -63,16 +65,38 @@ impl Session {
let session_settings = Settings::try_create(&conf)?;
let ref_count = Arc::new(AtomicUsize::new(0));
let status = Arc::new(Default::default());
match typ {
SessionType::MySQL => {
let mysql_conn_id = session_mgr
Copy link
Member

Choose a reason for hiding this comment

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

It's incorrect, we must save the mysql_conn_id in fetch_add

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

saved in there: self.mysql_basic_conn_id.fetch_add(1, Ordering::Relaxed);

Maybe we can directly use session_mgr.mysql_basic_conn_id?

Copy link
Member

Choose a reason for hiding this comment

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

Must save the return value of fetch_add, see https://doc.rust-lang.org/std/sync/atomic/struct.AtomicU32.html#method.fetch_add

Otherwise, you can't ensure the load value is not changed.

@sundy-li
Copy link
Member

Maybe we can add a test with native_client ?

@TCeason TCeason force-pushed the ISSUE-4871/handle_mysql_kill branch from da493c2 to b9e58a9 Compare May 19, 2022 03:33
@TCeason
Copy link
Collaborator Author

TCeason commented May 19, 2022

Maybe we can add a test with native_client ?

Like this tests/suites/1_stateful/02_query/02_0000_kill_query.py?

time.sleep(5)
mycursor.execute("SELECT * FROM system.processes WHERE extra_info like '%select * from numbers(999999999)%' and extra_info not like '%system.processes%'")
res = mycursor.fetchone()
assert res is None
Copy link
Member

Choose a reason for hiding this comment

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

result file is empty, the test will be skipped.

@BohuTANG
Copy link
Member

02_0000_kill_query:                                                     [ FAIL ] - return code 1
, result:

Traceback (most recent call last):
  File "/home/runner/work/databend/databend/tests/helpers/uexpect.py", line 178, in read
    data += self.queue.get(timeout=timeleft)
  File "/usr/lib/python3.8/queue.py", line 178, in get
    raise Empty
_queue.Empty

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/runner/work/databend/databend/tests/helpers/uexpect.py", line 152, in expect
    data = self.read(timeout=timeleft, raise_exception=True)
  File "/home/runner/work/databend/databend/tests/helpers/uexpect.py", line 186, in read
    raise TimeoutError(timeout)
uexpect.TimeoutError: Timeout 60.000s

@TCeason TCeason force-pushed the ISSUE-4871/handle_mysql_kill branch from a1c4afe to 354b261 Compare May 19, 2022 08:30
@BohuTANG
Copy link
Member

BohuTANG commented May 19, 2022

From my test on local, the server(MySQL handler) received the kill query from the client, but databend-query select cannot be canceled:

2022-05-19T10:25:28.715810Z  INFO databend_query::servers::mysql::mysql_interactive_worker: Normal query: select sum(number) from numbers(10000000000)
2022-05-19T10:25:30.322079Z  INFO databend_query::servers::mysql::mysql_handler: MySQL connection coming: Ok(127.0.0.1:46846)
2022-05-19T10:25:30.626255Z  INFO databend_query::servers::mysql::mysql_interactive_worker: Normal query: KILL QUERY 9
2022-05-19T10:25:33.547171Z  INFO databend_query::servers::mysql::mysql_handler: MySQL connection coming: Ok(127.0.0.1:46848)
2022-05-19T10:25:33.765910Z  INFO databend_query::servers::mysql::mysql_interactive_worker: Normal query: KILL QUERY 9
2022-05-19T10:26:16.341979Z  INFO databend_query::servers::mysql::mysql_handler: MySQL connection coming: Ok(127.0.0.1:46850)
2022-05-19T10:26:16.625610Z  INFO databend_query::servers::mysql::mysql_interactive_worker: Normal query: KILL QUERY 9
2022-05-19T10:26:16.692260Z  INFO databend_query::servers::mysql::mysql_handler: MySQL connection coming: Ok(127.0.0.1:46852)
2022-05-19T10:26:16.933850Z  INFO databend_query::servers::mysql::mysql_interactive_worker: Normal query: KILL QUERY 9

@TCeason
Copy link
Collaborator Author

TCeason commented May 19, 2022

From my test on local, the server(MySQL handler) received the kill query from the client, but databend-query select cannot be canceled:

2022-05-19T10:25:28.715810Z  INFO databend_query::servers::mysql::mysql_interactive_worker: Normal query: select sum(number) from numbers(10000000000)
2022-05-19T10:25:30.322079Z  INFO databend_query::servers::mysql::mysql_handler: MySQL connection coming: Ok(127.0.0.1:46846)
2022-05-19T10:25:30.626255Z  INFO databend_query::servers::mysql::mysql_interactive_worker: Normal query: KILL QUERY 9
2022-05-19T10:25:33.547171Z  INFO databend_query::servers::mysql::mysql_handler: MySQL connection coming: Ok(127.0.0.1:46848)
2022-05-19T10:25:33.765910Z  INFO databend_query::servers::mysql::mysql_interactive_worker: Normal query: KILL QUERY 9
2022-05-19T10:26:16.341979Z  INFO databend_query::servers::mysql::mysql_handler: MySQL connection coming: Ok(127.0.0.1:46850)
2022-05-19T10:26:16.625610Z  INFO databend_query::servers::mysql::mysql_interactive_worker: Normal query: KILL QUERY 9
2022-05-19T10:26:16.692260Z  INFO databend_query::servers::mysql::mysql_handler: MySQL connection coming: Ok(127.0.0.1:46852)
2022-05-19T10:26:16.933850Z  INFO databend_query::servers::mysql::mysql_interactive_worker: Normal query: KILL QUERY 9

Actually this pr just do one thing : convert mysql_conn_id to session_id.

I do this test:

in session 1

select sum(number) from numbers(10000000000);

in session 2

root@mysqldb 21:15:57 [(none)]> show processlist;
+--------------------------------------+-------+-----------------+------+-------+----------+----------------------------------------------+--------------+------------------------+-------------------------+-------------------------+--------------------------+---------------------+
| id                                   | type  | host            | user | state | database | extra_info                                   | memory_usage | dal_metrics_read_bytes | dal_metrics_write_bytes | scan_progress_read_rows | scan_progress_read_bytes | mysql_connection_id |
+--------------------------------------+-------+-----------------+------+-------+----------+----------------------------------------------+--------------+------------------------+-------------------------+-------------------------+--------------------------+---------------------+
| 6297888a-668f-4e20-a7ce-adc8fadbed85 | MySQL | 127.0.0.1:51820 | root | Query | default  | select sum(number) from numbers(10000000000) |            0 |                      0 |                       0 |               124320000 |                994560000 |                  28 |
| 0f92fe22-0015-47ac-85c5-5463a94f9cbe | MySQL | 127.0.0.1:51814 | root | Query | default  | show processlist                             |            0 |                      0 |                       0 |                       0 |                        0 |                  25 |
| 3ac8bcbf-6a13-4859-b276-7f81570fb871 | MySQL | 127.0.0.1:51802 | root | Idle  | default  | NULL                                         |            0 |                   NULL |                    NULL |                    NULL |                     NULL |                  20 |
+--------------------------------------+-------+-----------------+------+-------+----------+----------------------------------------------+--------------+------------------------+-------------------------+-------------------------+--------------------------+---------------------+
3 rows in set (0.10 sec)
Read 3 rows, 631.00 B in 0.052 sec., 57.85 rows/sec., 11.88 KiB/sec.

root@mysqldb 21:16:26 [(none)]> kill query '6297888a-668f-4e20-a7ce-adc8fadbed85';
Query OK, 0 rows affected (0.07 sec)
Read 0 rows, 0.00 B in 0.003 sec., 0 rows/sec., 0.00 B/sec.

And then the session 1 's query looks like not exit, but if already exit.


root@mysqldb 21:16:33 [(none)]> show processlist;
+--------------------------------------+-------+-----------------+------+-------+----------+------------------+--------------+------------------------+-------------------------+-------------------------+--------------------------+---------------------+
| id                                   | type  | host            | user | state | database | extra_info       | memory_usage | dal_metrics_read_bytes | dal_metrics_write_bytes | scan_progress_read_rows | scan_progress_read_bytes | mysql_connection_id |
+--------------------------------------+-------+-----------------+------+-------+----------+------------------+--------------+------------------------+-------------------------+-------------------------+--------------------------+---------------------+
| 6297888a-668f-4e20-a7ce-adc8fadbed85 | MySQL | 127.0.0.1:51820 | root | Idle  | default  | NULL             |            0 |                   NULL |                    NULL |                    NULL |                     NULL |                  28 |
| 0f92fe22-0015-47ac-85c5-5463a94f9cbe | MySQL | 127.0.0.1:51814 | root | Query | default  | show processlist |            0 |                      0 |                       0 |                       0 |                        0 |                  25 |
| 3ac8bcbf-6a13-4859-b276-7f81570fb871 | MySQL | 127.0.0.1:51802 | root | Idle  | default  | NULL             |            0 |                   NULL |                    NULL |                    NULL |                     NULL |                  20 |
+--------------------------------------+-------+-----------------+------+-------+----------+------------------+--------------+------------------------+-------------------------+-------------------------+--------------------------+---------------------+
3 rows in set (0.17 sec)
Read 3 rows, 586.00 B in 0.094 sec., 31.86 rows/sec., 6.08 KiB/sec.

@TCeason
Copy link
Collaborator Author

TCeason commented May 19, 2022

maybe you could off the new processor.

root@mysqldb 21:19:33 [(none)]> SET enable_new_processor_framework=0;
Query OK, 0 rows affected (0.12 sec)
Read 0 rows, 0.00 B in 0.020 sec., 0 rows/sec., 0.00 B/sec.

root@mysqldb 21:19:37 [(none)]> select sum(number) from numbers(10000000000);
^C^C -- query aborted
ERROR 1152 (08S01): Code: 1043, displayText = Aborted query, because the server is shutting down or the query was killed.
root@mysqldb 21:19:40 [(none)]> 

I met a similar situation, but I haven't submitted the issue yet.

@TCeason
Copy link
Collaborator Author

TCeason commented May 19, 2022

maybe you could off the new processor.

root@mysqldb 21:19:33 [(none)]> SET enable_new_processor_framework=0;
Query OK, 0 rows affected (0.12 sec)
Read 0 rows, 0.00 B in 0.020 sec., 0 rows/sec., 0.00 B/sec.

root@mysqldb 21:19:37 [(none)]> select sum(number) from numbers(10000000000);
^C^C -- query aborted
ERROR 1152 (08S01): Code: 1043, displayText = Aborted query, because the server is shutting down or the query was killed.
root@mysqldb 21:19:40 [(none)]> 

I met a similar situation, but I haven't submitted the issue yet.

And I find if let the query in session 1 execute a long time, and kill it in session 2 the session 1 will at aborting state.

@TCeason TCeason deleted the ISSUE-4871/handle_mysql_kill branch June 9, 2022 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-review pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: MySQL handler Kill Query
4 participants