procs

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 8 Imported by: 0

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

View Source
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

func Kill(ctx context.Context, conn *db.Conn, id uint64, stop Stop) error

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.

func Tree

func Tree(waits []Wait) []*Blocked

Tree turns the pairs into who-waits-on-whom.

A flat list of pairs is what the server gives and what a DBA then has to correlate by hand — and the thing worth finding is the connection at the bottom that waits on nothing, because that is the one to deal with.

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.

func List

func List(ctx context.Context, conn *db.Conn) (Listing, error)

List reads the server's connections, longest-running first.

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.

func LockWaits

func LockWaits(ctx context.Context, conn *db.Conn) (LockTree, error)

LockWaits reads who is waiting on whom.

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.

func (Process) Working

func (p Process) Working() bool

Working reports whether the connection is doing something rather than holding a socket open.

It is the difference between a server that is busy and one that merely has clients, and it decides nothing on its own — the caller shows both.

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
)

func (Stop) String

func (s Stop) String() string

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.

type Wait

type Wait struct {
	Waiter  Thread
	Blocker Thread
	Waited  time.Duration
}

Wait is one connection waiting on another.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL