Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 749adb4

Browse files
authored
Make PROCESSLIST and KILL compatible with MySQL (#722)
Make PROCESSLIST and KILL compatible with MySQL
2 parents 20edc31 + f88a1de commit 749adb4

File tree

6 files changed

+15
-32
lines changed

6 files changed

+15
-32
lines changed

server/handler.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (h *Handler) handleKill(conn *mysql.Conn, query string) (bool, error) {
164164
return false, nil
165165
}
166166

167-
id, err := strconv.ParseUint(s[2], 10, 64)
167+
id, err := strconv.ParseUint(s[2], 10, 32)
168168
if err != nil {
169169
return false, err
170170
}
@@ -181,15 +181,10 @@ func (h *Handler) handleKill(conn *mysql.Conn, query string) (bool, error) {
181181
// - KILL CONNECTION is the same as KILL with no modifier:
182182
// It terminates the connection associated with the given processlist_id,
183183
// after terminating any statement the connection is executing.
184-
if s[1] == "query" {
185-
logrus.Infof("kill query: id %d", id)
186-
h.e.Catalog.Kill(id)
187-
} else {
188-
connID, ok := h.e.Catalog.KillConnection(id)
189-
if !ok {
190-
return false, errConnectionNotFound.New(connID)
191-
}
192-
logrus.Infof("kill connection: id %d, pid: %d", connID, id)
184+
connID := uint32(id)
185+
h.e.Catalog.Kill(connID)
186+
if s[1] != "query" {
187+
logrus.Infof("kill connection: id %d", connID)
193188

194189
h.mu.Lock()
195190
c, ok := h.c[connID]

server/handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func TestHandlerKill(t *testing.T) {
203203
ctx1, err = handler.e.Catalog.AddProcess(ctx1, sql.QueryProcess, "SELECT 1")
204204
require.NoError(err)
205205

206-
err = handler.ComQuery(conn2, "KILL "+fmt.Sprint(ctx1.Pid()), func(res *sqltypes.Result) error {
206+
err = handler.ComQuery(conn2, "KILL "+fmt.Sprint(ctx1.ID()), func(res *sqltypes.Result) error {
207207
return nil
208208
})
209209
require.NoError(err)

sql/plan/processlist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (p *ShowProcessList) RowIter(ctx *sql.Context) (sql.RowIter, error) {
8989
sort.Strings(status)
9090

9191
rows[i] = process{
92-
id: int64(proc.Pid),
92+
id: int64(proc.Connection),
9393
user: proc.User,
9494
time: int64(proc.Seconds()),
9595
state: strings.Join(status, ", "),

sql/plan/processlist_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestShowProcessList(t *testing.T) {
4545

4646
expected := []sql.Row{
4747
{int64(1), "foo", addr, "foo", "query", int64(0), "a(4/5), b(2/6)", "SELECT foo"},
48-
{int64(2), "foo", addr, "foo", "create_index", int64(0), "foo(1/2)", "SELECT bar"},
48+
{int64(1), "foo", addr, "foo", "create_index", int64(0), "foo(1/2)", "SELECT bar"},
4949
}
5050

5151
require.ElementsMatch(expected, rows)

sql/processlist.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"sync"
77
"time"
88

9+
"github.com/sirupsen/logrus"
910
"gopkg.in/src-d/go-errors.v1"
1011
)
1112

@@ -155,31 +156,18 @@ func (pl *ProcessList) AddProgressItem(pid uint64, name string, total int64) {
155156
}
156157
}
157158

158-
// Kill terminates a process if it exists.
159-
func (pl *ProcessList) Kill(pid uint64) {
160-
pl.Done(pid)
161-
}
162-
163-
// KillConnection terminates the connection associated with the given processlist_id,
164-
// after terminating any statement the connection is executing.
165-
func (pl *ProcessList) KillConnection(pid uint64) (uint32, bool) {
159+
// Kill terminates all queries for a given connection
160+
func (pl *ProcessList) Kill(connID uint32) {
166161
pl.mu.Lock()
167162
defer pl.mu.Unlock()
168163

169-
p, ok := pl.procs[pid]
170-
if !ok {
171-
return 0, false
172-
}
173-
174-
connID := p.Connection
175-
for id, proc := range pl.procs {
164+
for pid, proc := range pl.procs {
176165
if proc.Connection == connID {
166+
logrus.Infof("kill query: pid %d", pid)
177167
proc.Done()
178-
delete(pl.procs, id)
168+
delete(pl.procs, pid)
179169
}
180170
}
181-
182-
return connID, ok
183171
}
184172

185173
// Done removes the finished process with the given pid from the process list.

sql/processlist_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func TestKillConnection(t *testing.T) {
113113
}
114114
}
115115

116-
pl.KillConnection(1)
116+
pl.Kill(1)
117117
require.Len(t, pl.procs, 1)
118118

119119
// Odds should have been killed

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy