runaway

package
v1.1.0-beta.0...-3c40731 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ManualSource shows the item added manually.
	ManualSource = "manual"

	// MaxWaitDuration is the max duration to wait for acquiring token buckets.
	MaxWaitDuration = time.Second * 30
)

Variables

View Source
var NullTime time.Time

NullTime is a zero time.Time.

Functions

func ExecRCRestrictedSQL

func ExecRCRestrictedSQL(sysSessionPool util.SessionPool, sql string, params []any) ([]chunk.Row, error)

ExecRCRestrictedSQL is used to execute a restricted SQL which related to resource control.

Types

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker is used to check if the query is runaway.

func NewChecker

func NewChecker(
	manager *Manager,
	resourceGroupName string, settings *rmpb.RunawaySettings,
	originalSQL, sqlDigest, planDigest string, startTime time.Time,
) *Checker

NewChecker creates a new RunawayChecker.

func (*Checker) BeforeCopRequest

func (r *Checker) BeforeCopRequest(req *tikvrpc.Request) error

BeforeCopRequest checks runaway and modifies the request if necessary before sending coprocessor request.

func (*Checker) BeforeExecutor

func (r *Checker) BeforeExecutor() (string, error)

BeforeExecutor checks whether query is in watch list before executing and after compiling.

func (*Checker) CheckAction

func (r *Checker) CheckAction() rmpb.RunawayAction

CheckAction is used to check current action of the query. It's safe to call this method concurrently.

func (*Checker) CheckRuleKillAction

func (r *Checker) CheckRuleKillAction() (string, bool)

CheckRuleKillAction checks whether the query should be killed according to the group settings.

func (*Checker) CheckThresholds

func (r *Checker) CheckThresholds(ruDetail *util.RUDetails, processKeys int64, err error) error

CheckThresholds checks error after receiving coprocessor response.

func (*Checker) ResetTotalProcessedKeys

func (r *Checker) ResetTotalProcessedKeys()

ResetTotalProcessedKeys resets the current total processed keys.

type Manager

type Manager struct {

	// activeGroup is used to manage the active runaway watches of resource group
	ActiveGroup map[string]int64
	ActiveLock  sync.RWMutex
	MetricsMap  generic.SyncMap[string, prometheus.Counter]

	ResourceGroupCtl *rmclient.ResourceGroupsController
	// contains filtered or unexported fields
}

Manager is used to detect and record runaway queries.

func NewRunawayManager

func NewRunawayManager(resourceGroupCtl *rmclient.ResourceGroupsController, serverAddr string,
	pool util.SessionPool, exit chan struct{}, infoCache *infoschema.InfoCache, ddl ddl.DDL) *Manager

NewRunawayManager creates a new Manager.

func (*Manager) AddRunawayWatch

func (rm *Manager) AddRunawayWatch(record *QuarantineRecord) (uint64, error)

AddRunawayWatch is used to add runaway watch item manually.

func (*Manager) AddWatch

func (rm *Manager) AddWatch(record *QuarantineRecord)

AddWatch is used to add watch items from system table.

func (*Manager) DeriveChecker

func (rm *Manager) DeriveChecker(resourceGroupName, originalSQL, sqlDigest, planDigest string, startTime time.Time) *Checker

DeriveChecker derives a RunawayChecker from the given resource group

func (*Manager) GetWatchList

func (rm *Manager) GetWatchList() []*QuarantineRecord

GetWatchList is used to get all watch items.

func (*Manager) IsSyncerInitialized

func (rm *Manager) IsSyncerInitialized() bool

IsSyncerInitialized is only used for test.

func (*Manager) MarkSyncerInitialized

func (rm *Manager) MarkSyncerInitialized()

MarkSyncerInitialized is used to mark the syncer is initialized.

func (*Manager) RemoveRunawayWatch

func (rm *Manager) RemoveRunawayWatch(recordID int64) error

RemoveRunawayWatch is used to remove runaway watch item manually.

func (*Manager) RunawayRecordFlushLoop

func (rm *Manager) RunawayRecordFlushLoop()

RunawayRecordFlushLoop is used to flush runaway records.

func (*Manager) RunawayWatchSyncLoop

func (rm *Manager) RunawayWatchSyncLoop()

RunawayWatchSyncLoop is used to sync runaway watch records.

func (*Manager) Stop

func (rm *Manager) Stop()

Stop stops the watchList which is a ttlCache.

func (*Manager) UpdateNewAndDoneWatch

func (rm *Manager) UpdateNewAndDoneWatch() error

UpdateNewAndDoneWatch is used to update new and done watch items.

type QuarantineRecord

type QuarantineRecord struct {
	ID                int64
	ResourceGroupName string
	// startTime and endTime are in UTC.
	StartTime   time.Time
	EndTime     time.Time
	Watch       rmpb.RunawayWatchType
	WatchText   string
	Source      string
	ExceedCause string
	// Action-related fields.
	Action          rmpb.RunawayAction
	SwitchGroupName string
}

QuarantineRecord is used to save records which will be inserted into mysql.tidb_runaway_watch.

func (*QuarantineRecord) GetActionString

func (r *QuarantineRecord) GetActionString() string

GetActionString returns the action string.

func (*QuarantineRecord) GetExceedCause

func (r *QuarantineRecord) GetExceedCause() string

GetExceedCause returns the exceed cause.

type Record

type Record struct {
	ResourceGroupName string
	StartTime         time.Time
	Match             string
	Action            string
	SampleText        string
	SQLDigest         string
	PlanDigest        string
	Source            string
	ExceedCause       string
	// Repeats is used to avoid inserting the same record multiple times.
	// It records the number of times after flushing the record(10s) to the table or len(map) exceeds the threshold(1024).
	// We only consider `resource_group_name`, `sql_digest`, `plan_digest` and `match_type` when comparing records.
	// default value is 1.
	Repeats int
}

Record is used to save records which will be inserted into mysql.tidb_runaway_queries.

Jump to

Keyboard shortcuts

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