-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Support CTRL-C or kill <connId> to kill a connection/query by implementing global connection IDs #8854
Comments
I noticed that since MySQL 5.7 connection ID becomes 64 bit: https://bugs.mysql.com/bug.php?id=65715 So it might not be a hard problem now. |
Tips to implement,
|
/pick-up-challenge |
@pingyu pick up issue success |
I don't believe this is fully fixed in MySQL 5.7. The server internally uses 64-bit, but the client APIs only expose the lower 32-bits. The fix in 5.7 is that it ensures the lower 32-bits never overlap, which is feasible only in single server context. Another way to implement this would be to use a design similar to auto_increment works (tidb servers request connection IDs in batches). A batch of 2^16 ids should last for quite a while. I am not sure what is the best way to prevent connection IDs from being reused though, it needs to be possible to have long living connections so that operations like backup are possible. |
@wwar It is already 64bit in 5.6.9:
|
Seem the connection ID in the handshake protocol is still 32 bits, see https://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::Handshake we need to take care of it, e.g. the higher 32 bits is TiDB server ID, the lower is connection ID, we can return the lower part in the handshake protocol. |
@siddontang Good catch! I further took a look at MySQL client implementation, and found that this 32-bit connection id in the handshake protocol will be finally used to send |
Thanks to all the friends and discussions here and slack. |
This pick has been automatically canceled after more than a week. |
Hi @pingyu , I tracked this issue from the PD PR. IMO, it is a bad idea to use PD's |
@SunRunAway @pingyu may you summary the tasks done so far and remaining work? I can see this issue being reopened several times and doesn't have a big picture on how we push it to finally finished. |
We separate the issue as the following tasks:
|
@pingyu Thanks for your information! I'll create TODO as subtasks for this issue to you. |
Global kill has been added, and is now enabled by default. Closing this. |
fix CI. Signed-off-by: Ping Yu <yuping@pingcap.com>
ID pools for global kill 32bit
Description
Is your feature request related to a problem? Please describe:
Currently connection ids are local to TiDB servers, which means that a
KILL x
must be directed to the correct server, and can not safely be load balanced across the cluster.This is annoying because it creates affinity to servers in a distributed architecture. It also doesn't retrofit to MySQL so well, since the
KILL x
syntax can't be supported (usingKILL TIDB x
to prevent incorrect usage).Describe the feature you'd like:
I found this note while reading the source code, and it makes a lot of sense to me. I decided to create this FR for discussion and tracking since I couldn't find an existing one open.
Since I believe the connectionID must be 32-bits for protocol compatibility, I assume that the implementation will use the first 8-16 bits for the host, and the remaining 16-24 bits for the local connectionID?
It would be nice to externalize the host portion as a pseudo
server_id
, since some functions such as UUID_SHORT depend on it being small. The pseudoserver_id
's can be recycled as TiDB servers are deployed/disappear, with pd ensuring they are unique. This address size of the pseudo server_id would limit the max number of tidb servers deployed simultaneously.Describe alternatives you've considered:
Using 8 bits for the host seems short, but actually using only 16 bits for the local connection Id is also dangerously low, if you want to make sure new connection Ids allocated do not chase the tail of old connectionIds. I will let someone smarter figure that out :-)
Teachability, Documentation, Adoption, Migration Strategy:
It makes sense to extend
SHOW PROCESSLIST
to beSHOW [GLOBAL|SESSION] PROCESSLIST
. I think the default of global makes more senseRecommended Skills
Learning Materials
The text was updated successfully, but these errors were encountered: