Documentation
¶
Overview ¶
Package procs reads what else is running on the server.
It answers the question a session cannot answer about itself: who else is connected, what are they doing, and how long have they been doing it. The rows come from information_schema.PROCESSLIST, which both MySQL and MariaDB have — only the columns they share are read, because a listing that works on one server and not the other is worse than a shorter one.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrOwnConnection = errors.New("that connection belongs to this session")
ErrOwnConnection is returned rather than killing one of this session's own connections.
Killing the control connection takes cancellation and every catalog read with it, permanently; killing a pooled one loses whatever it was running for us. Neither is something to discover by having done it.
Functions ¶
func Kill ¶
Kill stops a connection's statement, or the connection itself.
It goes over the control connection, which is where KILL has always been sent from: a kill that had to wait behind a result streaming into the grid would be useless exactly when it was needed.
func Order ¶
func Order(ps []Process)
Order puts the connections in the order they are worth reading: what is working first, longest first within that, and the idle ones after.
A server in trouble has one statement that has been running for minutes and forty connections asleep. Sorting by time alone buries it under whichever client last held a socket open the longest.
Types ¶
type Blocked ¶
type Blocked struct {
Thread Thread
// Waited is how long this connection has been waiting for its own lock,
// and is zero at a root.
Waited time.Duration
Waiters []*Blocked
}
Blocked is one connection in the tree, with whatever is waiting on it.
type Listing ¶
type Listing struct {
Processes []Process
// Complete is false when the connected user lacks the PROCESS privilege,
// in which case the server silently returns only that user's own
// connections. A short list and a quiet server look identical, and the
// difference is the whole reason to have looked.
Complete bool
}
Listing is what the server was willing to show.
type LockTree ¶
type LockTree struct {
// Roots are the connections blocking others without waiting themselves.
Roots []*Blocked
// Supported is false when this server keeps its lock waits somewhere this
// does not know to look. An empty tree and a server that will not say look
// identical, and only one of them means nothing is stuck.
Supported bool
}
LockTree is who is waiting on whom, and whether the server would say.
type Process ¶
type Process struct {
ID uint64
User string
Host string
// DB is the schema the connection is using, empty when it has none.
DB string
// Command is what the connection is doing at protocol level — "Query",
// "Sleep", "Binlog Dump". Sleep is a connection holding nothing.
Command string
// State is the server's word for the stage a query has reached.
State string
// SQL is the statement in flight, empty when there is none.
SQL string
// Elapsed is how long the connection has been in this command.
Elapsed time.Duration
}
Process is one connection on the server.
type Stop ¶
type Stop int
Stop says how far a kill goes.
const ( // StopStatement ends the statement in flight and leaves the connection // open, which is what "make this stop" almost always means: the client // gets an error and its session survives. StopStatement Stop = iota // StopConnection ends the connection itself, and with it any transaction // it was holding — which the server rolls back. StopConnection )
type Thread ¶
type Thread struct {
ID uint64
User string
Host string
// SQL is what the connection is running now, which for a blocker is
// usually not the statement that took the lock: a transaction holds what
// it took until it ends, whatever it does in between.
SQL string
// Idle says the connection holds its locks and is running nothing at all.
// It is the most common answer to "why is everything stuck", and the one
// a list of statements cannot give.
Idle bool
}
Thread is a connection seen from a lock's point of view.