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

Make PROCESSLIST and KILL compatible with MySQL #722

Merged
merged 2 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (h *Handler) handleKill(conn *mysql.Conn, query string) (bool, error) {
return false, nil
}

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

h.mu.Lock()
c, ok := h.c[connID]
Expand Down
2 changes: 1 addition & 1 deletion server/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func TestHandlerKill(t *testing.T) {
ctx1, err = handler.e.Catalog.AddProcess(ctx1, sql.QueryProcess, "SELECT 1")
require.NoError(err)

err = handler.ComQuery(conn2, "KILL "+fmt.Sprint(ctx1.Pid()), func(res *sqltypes.Result) error {
err = handler.ComQuery(conn2, "KILL "+fmt.Sprint(ctx1.ID()), func(res *sqltypes.Result) error {
return nil
})
require.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion sql/plan/processlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (p *ShowProcessList) RowIter(ctx *sql.Context) (sql.RowIter, error) {
sort.Strings(status)

rows[i] = process{
id: int64(proc.Pid),
id: int64(proc.Connection),
user: proc.User,
time: int64(proc.Seconds()),
state: strings.Join(status, ", "),
Expand Down
2 changes: 1 addition & 1 deletion sql/plan/processlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestShowProcessList(t *testing.T) {

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

require.ElementsMatch(expected, rows)
Expand Down
24 changes: 6 additions & 18 deletions sql/processlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"
"time"

"github.com/sirupsen/logrus"
"gopkg.in/src-d/go-errors.v1"
)

Expand Down Expand Up @@ -155,31 +156,18 @@ func (pl *ProcessList) AddProgressItem(pid uint64, name string, total int64) {
}
}

// Kill terminates a process if it exists.
func (pl *ProcessList) Kill(pid uint64) {
pl.Done(pid)
}

// KillConnection terminates the connection associated with the given processlist_id,
// after terminating any statement the connection is executing.
func (pl *ProcessList) KillConnection(pid uint64) (uint32, bool) {
// Kill terminates all queries for a given connection
func (pl *ProcessList) Kill(connID uint32) {
pl.mu.Lock()
defer pl.mu.Unlock()

p, ok := pl.procs[pid]
if !ok {
return 0, false
}

connID := p.Connection
for id, proc := range pl.procs {
for pid, proc := range pl.procs {
if proc.Connection == connID {
logrus.Infof("kill query: pid %d", pid)
proc.Done()
delete(pl.procs, id)
delete(pl.procs, pid)
}
}

return connID, ok
}

// Done removes the finished process with the given pid from the process list.
Expand Down
2 changes: 1 addition & 1 deletion sql/processlist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestKillConnection(t *testing.T) {
}
}

pl.KillConnection(1)
pl.Kill(1)
require.Len(t, pl.procs, 1)

// Odds should have been killed
Expand Down
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