Documentation ¶
Index ¶
- Constants
- Variables
- func ExecRCRestrictedSQL(sysSessionPool util.SessionPool, sql string, params []any) ([]chunk.Row, error)
- type Checker
- func (r *Checker) BeforeCopRequest(req *tikvrpc.Request) error
- func (r *Checker) BeforeExecutor() (string, error)
- func (r *Checker) CheckAction() rmpb.RunawayAction
- func (r *Checker) CheckRuleKillAction() (string, bool)
- func (r *Checker) CheckThresholds(ruDetail *util.RUDetails, processKeys int64, err error) error
- func (r *Checker) ResetTotalProcessedKeys()
- type Manager
- func (rm *Manager) AddRunawayWatch(record *QuarantineRecord) (uint64, error)
- func (rm *Manager) AddWatch(record *QuarantineRecord)
- func (rm *Manager) DeriveChecker(resourceGroupName, originalSQL, sqlDigest, planDigest string, ...) *Checker
- func (rm *Manager) GetWatchList() []*QuarantineRecord
- func (rm *Manager) IsSyncerInitialized() bool
- func (rm *Manager) MarkSyncerInitialized()
- func (rm *Manager) RemoveRunawayWatch(recordID int64) error
- func (rm *Manager) RunawayRecordFlushLoop()
- func (rm *Manager) RunawayWatchSyncLoop()
- func (rm *Manager) Stop()
- func (rm *Manager) UpdateNewAndDoneWatch() error
- type QuarantineRecord
- type Record
Constants ¶
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 ¶
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 ¶
BeforeCopRequest checks runaway and modifies the request if necessary before sending coprocessor request.
func (*Checker) BeforeExecutor ¶
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 ¶
CheckRuleKillAction checks whether the query should be killed according to the group settings.
func (*Checker) CheckThresholds ¶
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 ¶
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 ¶
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) UpdateNewAndDoneWatch ¶
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.