domain

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2023 License: Apache-2.0 Imports: 83 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PlanReplayerConfigFile indicates config file path for plan replayer
	PlanReplayerConfigFile = "config.toml"
	// PlanReplayerMetaFile meta file path for plan replayer
	PlanReplayerMetaFile = "meta.txt"
	// PlanReplayerVariablesFile indicates for session variables file path for plan replayer
	PlanReplayerVariablesFile = "variables.toml"
	// PlanReplayerTiFlashReplicasFile indicates for table tiflash replica file path for plan replayer
	PlanReplayerTiFlashReplicasFile = "table_tiflash_replica.txt"
	// PlanReplayerSessionBindingFile indicates session binding file path for plan replayer
	PlanReplayerSessionBindingFile = "session_bindings.sql"
	// PlanReplayerGlobalBindingFile indicates global binding file path for plan replayer
	PlanReplayerGlobalBindingFile = "global_bindings.sql"
)
View Source
const (
	// ResultSucc means schemaValidator's check is passing.
	ResultSucc checkResult = iota
	// ResultFail means schemaValidator's check is fail.
	ResultFail
	// ResultUnknown means schemaValidator doesn't know the check would be success or fail.
	ResultUnknown
)

Variables

View Source
var (
	// ErrInfoSchemaExpired returns the error that information schema is out of date.
	ErrInfoSchemaExpired = dbterror.ClassDomain.NewStd(errno.ErrInfoSchemaExpired)
	// ErrInfoSchemaChanged returns the error that information schema is changed.
	ErrInfoSchemaChanged = dbterror.ClassDomain.NewStdErr(errno.ErrInfoSchemaChanged,
		mysql.Message(errno.MySQLErrName[errno.ErrInfoSchemaChanged].Raw+". "+kv.TxnRetryableMark, nil))
)
View Source
var (
	// SchemaOutOfDateRetryInterval is the backoff time before retrying.
	SchemaOutOfDateRetryInterval = atomicutil.NewDuration(500 * time.Millisecond)
	// SchemaOutOfDateRetryTimes is the max retry count when the schema is out of date.
	SchemaOutOfDateRetryTimes = atomicutil.NewInt32(10)
)

Functions

func BindDomain

func BindDomain(ctx sessionctx.Context, domain *Domain)

BindDomain binds domain to context.

func CheckPlanReplayerTaskExists

func CheckPlanReplayerTaskExists(ctx context.Context, sctx sessionctx.Context, sqlDigest, planDigest string) (bool, error)

CheckPlanReplayerTaskExists checks whether plan replayer capture task exists already

func DisableDumpHistoricalStats4Test

func DisableDumpHistoricalStats4Test()

DisableDumpHistoricalStats4Test disable historical dump worker for test

func DisablePlanReplayerBackgroundJob4Test

func DisablePlanReplayerBackgroundJob4Test()

DisablePlanReplayerBackgroundJob4Test disable plan replayer handle for test

func DumpPlanReplayerInfo

func DumpPlanReplayerInfo(ctx context.Context, sctx sessionctx.Context,
	task *PlanReplayerDumpTask) (err error)

DumpPlanReplayerInfo will dump the information about sqls. The files will be organized into the following format:

|-meta.txt
|-schema
|	 |-db1.table1.schema.txt
|	 |-db2.table2.schema.txt
|	 |-....
|-view
| 	 |-db1.view1.view.txt
|	 |-db2.view2.view.txt
|	 |-....
|-stats
|   |-stats1.json
|   |-stats2.json
|   |-....
|-config.toml
|-table_tiflash_replica.txt
|-variables.toml
|-bindings.sql
|-sql
|   |-sql1.sql
|   |-sql2.sql
|	 |-....
|_explain
    |-explain1.txt
    |-explain2.txt
    |-....

func GeneratePlanReplayerFile

func GeneratePlanReplayerFile() (*os.File, string, error)

GeneratePlanReplayerFile generates plan replayer file

func GetOptimizerTraceDirName

func GetOptimizerTraceDirName() string

GetOptimizerTraceDirName returns optimizer trace directory path. The path is related to the process id.

func GetPlanReplayerDirName

func GetPlanReplayerDirName() string

GetPlanReplayerDirName returns plan replayer directory path. The path is related to the process id.

Types

type Domain

type Domain struct {
	SchemaValidator SchemaValidator
	// contains filtered or unexported fields
}

Domain represents a storage space. Different domains can use the same database name. Multiple domains can be used in parallel without synchronization.

func GetDomain

func GetDomain(ctx sessionctx.Context) *Domain

GetDomain gets domain from context.

func NewDomain

func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duration, idxUsageSyncLease time.Duration, dumpFileGcLease time.Duration, factory pools.Factory) *Domain

NewDomain creates a new domain. Should not create multiple domains for the same store.

func NewMockDomain

func NewMockDomain() *Domain

NewMockDomain is only used for test

func (*Domain) BindHandle

func (do *Domain) BindHandle() *bindinfo.BindHandle

BindHandle returns domain's bindHandle.

func (*Domain) Close

func (do *Domain) Close()

Close closes the Domain and release its resource.

func (*Domain) CreateStatsHandle

func (do *Domain) CreateStatsHandle(ctx, initStatsCtx sessionctx.Context) error

CreateStatsHandle is used only for test.

func (*Domain) DDL

func (do *Domain) DDL() ddl.DDL

DDL gets DDL from domain.

func (*Domain) DumpFileGcCheckerLoop

func (do *Domain) DumpFileGcCheckerLoop()

DumpFileGcCheckerLoop creates a goroutine that handles `exit` and `gc`.

func (*Domain) EtcdClient

func (do *Domain) EtcdClient() *clientv3.Client

EtcdClient export for test.

func (*Domain) ExpensiveQueryHandle

func (do *Domain) ExpensiveQueryHandle() *expensivequery.Handle

ExpensiveQueryHandle returns the expensive query handle.

func (*Domain) ExpiredTimeStamp4PC

func (do *Domain) ExpiredTimeStamp4PC() types.Time

ExpiredTimeStamp4PC gets expiredTimeStamp4PC from domain.

func (*Domain) FetchAnalyzeExec

func (do *Domain) FetchAnalyzeExec(need int) []sessionctx.Context

FetchAnalyzeExec get needed exec for analyze

func (*Domain) GetEtcdClient

func (do *Domain) GetEtcdClient() *clientv3.Client

GetEtcdClient returns the etcd client.

func (*Domain) GetGlobalConfigSyncer

func (do *Domain) GetGlobalConfigSyncer() *globalconfigsync.GlobalConfigSyncer

GetGlobalConfigSyncer exports for testing.

func (*Domain) GetGlobalVar

func (do *Domain) GetGlobalVar(name string) (string, error)

GetGlobalVar gets an individual global var from the sysvar cache.

func (*Domain) GetHistoricalStatsWorker

func (do *Domain) GetHistoricalStatsWorker() *HistoricalStatsWorker

GetHistoricalStatsWorker gets historical workers

func (*Domain) GetPDClient

func (do *Domain) GetPDClient() pd.Client

GetPDClient returns the PD client.

func (*Domain) GetPlanReplayerHandle

func (do *Domain) GetPlanReplayerHandle() *planReplayerHandle

GetPlanReplayerHandle returns plan replayer handle

func (*Domain) GetScope

func (do *Domain) GetScope(status string) variable.ScopeFlag

GetScope gets the status variables scope.

func (*Domain) GetSessionCache

func (do *Domain) GetSessionCache() (map[string]string, error)

GetSessionCache gets a copy of the session sysvar cache. The intention is to copy it directly to the systems[] map on creating a new session.

func (*Domain) GetSnapshotInfoSchema

func (do *Domain) GetSnapshotInfoSchema(snapshotTS uint64) (infoschema.InfoSchema, error)

GetSnapshotInfoSchema gets a snapshot information schema.

func (*Domain) GetSnapshotMeta

func (do *Domain) GetSnapshotMeta(startTS uint64) (*meta.Meta, error)

GetSnapshotMeta gets a new snapshot meta at startTS.

func (*Domain) InfoCache

func (do *Domain) InfoCache() *infoschema.InfoCache

InfoCache export for test.

func (*Domain) InfoSchema

func (do *Domain) InfoSchema() infoschema.InfoSchema

InfoSchema gets the latest information schema from domain.

func (*Domain) InfoSyncer

func (do *Domain) InfoSyncer() *infosync.InfoSyncer

InfoSyncer gets infoSyncer from domain.

func (*Domain) Init

func (do *Domain) Init(
	ddlLease time.Duration,
	sysExecutorFactory func(*Domain) (pools.Resource, error),
	ddlInjector func(ddl.DDL) *schematracker.Checker,
) error

Init initializes a domain.

func (*Domain) IsLostConnectionToPD

func (do *Domain) IsLostConnectionToPD() bool

IsLostConnectionToPD indicates lost connection to PD or not.

func (*Domain) LoadAndUpdateStatsLoop

func (do *Domain) LoadAndUpdateStatsLoop(ctxs []sessionctx.Context, initStatsCtx sessionctx.Context) error

LoadAndUpdateStatsLoop loads and updates stats info.

func (*Domain) LoadBindInfoLoop

func (do *Domain) LoadBindInfoLoop(ctxForHandle sessionctx.Context, ctxForEvolve sessionctx.Context) error

LoadBindInfoLoop create a goroutine loads BindInfo in a loop, it should be called only once in BootstrapSession.

func (*Domain) LoadPrivilegeLoop

func (do *Domain) LoadPrivilegeLoop(sctx sessionctx.Context) error

LoadPrivilegeLoop create a goroutine loads privilege tables in a loop, it should be called only once in BootstrapSession.

func (*Domain) LoadSigningCertLoop

func (do *Domain) LoadSigningCertLoop(signingCert, signingKey string)

LoadSigningCertLoop loads the signing cert periodically to make sure it's fresh new.

func (*Domain) LoadSysVarCacheLoop

func (do *Domain) LoadSysVarCacheLoop(ctx sessionctx.Context) error

LoadSysVarCacheLoop create a goroutine loads sysvar cache in a loop, it should be called only once in BootstrapSession.

func (*Domain) LogSlowQuery

func (do *Domain) LogSlowQuery(query *SlowQueryInfo)

LogSlowQuery keeps topN recent slow queries in domain.

func (*Domain) MemoryUsageAlarmHandle

func (do *Domain) MemoryUsageAlarmHandle() *memoryusagealarm.Handle

MemoryUsageAlarmHandle returns the memory usage alarm handle.

func (*Domain) MockInfoCacheAndLoadInfoSchema

func (do *Domain) MockInfoCacheAndLoadInfoSchema(is infoschema.InfoSchema)

MockInfoCacheAndLoadInfoSchema only used in unit tests.

func (*Domain) MustGetPartitionAt

func (do *Domain) MustGetPartitionAt(t *testing.T, dbName, tableName string, idx int) int64

MustGetPartitionAt returns the partition ID. Only used in unit tests.

func (*Domain) MustGetTableID

func (do *Domain) MustGetTableID(t *testing.T, dbName, tableName string) int64

MustGetTableID returns the table ID. Only used in unit tests.

func (*Domain) MustGetTableInfo

func (do *Domain) MustGetTableInfo(t *testing.T, dbName, tableName string) *model.TableInfo

MustGetTableInfo returns the table info. Only used in unit tests.

func (*Domain) NotifyGlobalConfigChange

func (do *Domain) NotifyGlobalConfigChange(name, value string)

NotifyGlobalConfigChange notify global config syncer to store the global config into PD.

func (*Domain) NotifyUpdatePrivilege

func (do *Domain) NotifyUpdatePrivilege() error

NotifyUpdatePrivilege updates privilege key in etcd, TiDB client that watches the key will get notification.

func (*Domain) NotifyUpdateSysVarCache

func (do *Domain) NotifyUpdateSysVarCache(updateLocal bool)

NotifyUpdateSysVarCache updates the sysvar cache key in etcd, which other TiDB clients are subscribed to for updates. For the caller, the cache is also built synchronously so that the effect is immediate.

func (*Domain) PrivilegeHandle

func (do *Domain) PrivilegeHandle() *privileges.Handle

PrivilegeHandle returns the MySQLPrivilege.

func (*Domain) ReleaseAnalyzeExec

func (do *Domain) ReleaseAnalyzeExec(sctxs []sessionctx.Context)

ReleaseAnalyzeExec returned extra exec for Analyze

func (*Domain) Reload

func (do *Domain) Reload() error

Reload reloads InfoSchema. It's public in order to do the test.

func (*Domain) ServerID

func (do *Domain) ServerID() uint64

ServerID gets serverID.

func (*Domain) ServerMemoryLimitHandle

func (do *Domain) ServerMemoryLimitHandle() *servermemorylimit.Handle

ServerMemoryLimitHandle returns the expensive query handle.

func (*Domain) SetDDL

func (do *Domain) SetDDL(d ddl.DDL)

SetDDL sets DDL to domain, it's only used in tests.

func (*Domain) SetExpiredTimeStamp4PC

func (do *Domain) SetExpiredTimeStamp4PC(time types.Time)

SetExpiredTimeStamp4PC sets the expiredTimeStamp4PC from domain.

func (*Domain) SetOnClose

func (do *Domain) SetOnClose(onClose func())

SetOnClose used to set do.onClose func.

func (*Domain) SetStatsUpdating

func (do *Domain) SetStatsUpdating(val bool)

SetStatsUpdating sets the value of stats updating.

func (*Domain) SetupAnalyzeExec

func (do *Domain) SetupAnalyzeExec(ctxs []sessionctx.Context)

SetupAnalyzeExec setups exec for Analyze Executor

func (*Domain) SetupDumpFileGCChecker

func (do *Domain) SetupDumpFileGCChecker(ctx sessionctx.Context)

SetupDumpFileGCChecker setup sctx

func (*Domain) SetupHistoricalStatsWorker

func (do *Domain) SetupHistoricalStatsWorker(ctx sessionctx.Context)

SetupHistoricalStatsWorker setups worker

func (*Domain) SetupPlanReplayerHandle

func (do *Domain) SetupPlanReplayerHandle(collectorSctx, dumperSctx sessionctx.Context)

SetupPlanReplayerHandle setup plan replayer handle

func (*Domain) ShowSlowQuery

func (do *Domain) ShowSlowQuery(showSlow *ast.ShowSlow) []*SlowQueryInfo

ShowSlowQuery returns the slow queries.

func (*Domain) StartHistoricalStatsWorker

func (do *Domain) StartHistoricalStatsWorker()

StartHistoricalStatsWorker start historical workers running

func (*Domain) StartLoadStatsSubWorkers

func (do *Domain) StartLoadStatsSubWorkers(ctxList []sessionctx.Context)

StartLoadStatsSubWorkers starts sub workers with new sessions to load stats concurrently.

func (*Domain) StartPlanReplayerHandle

func (do *Domain) StartPlanReplayerHandle()

StartPlanReplayerHandle start plan replayer handle job

func (*Domain) StartTTLJobManager

func (do *Domain) StartTTLJobManager()

StartTTLJobManager creates and starts the ttl job manager

func (*Domain) StatsHandle

func (do *Domain) StatsHandle() *handle.Handle

StatsHandle returns the statistic handle.

func (*Domain) StatsUpdating

func (do *Domain) StatsUpdating() bool

StatsUpdating checks if the stats worker is updating.

func (*Domain) StopAutoAnalyze

func (do *Domain) StopAutoAnalyze()

StopAutoAnalyze stops (*Domain).autoAnalyzeWorker to launch new auto analyze jobs.

func (*Domain) Store

func (do *Domain) Store() kv.Storage

Store gets KV store from domain.

func (*Domain) SysProcTracker

func (do *Domain) SysProcTracker() sessionctx.SysProcTracker

SysProcTracker returns the system processes tracker.

func (*Domain) SysSessionPool

func (do *Domain) SysSessionPool() *sessionPool

SysSessionPool returns the system session pool.

func (*Domain) TTLJobManager

func (do *Domain) TTLJobManager() *ttlworker.JobManager

TTLJobManager returns the ttl job manager on this domain

func (*Domain) TelemetryReportLoop

func (do *Domain) TelemetryReportLoop(ctx sessionctx.Context)

TelemetryReportLoop create a goroutine that reports usage data in a loop, it should be called only once in BootstrapSession.

func (*Domain) TelemetryRotateSubWindowLoop

func (do *Domain) TelemetryRotateSubWindowLoop(ctx sessionctx.Context)

TelemetryRotateSubWindowLoop create a goroutine that rotates the telemetry window regularly.

func (*Domain) UpdateTableStatsLoop

func (do *Domain) UpdateTableStatsLoop(ctx, initStatsCtx sessionctx.Context) error

UpdateTableStatsLoop creates a goroutine loads stats info and updates stats info in a loop. It will also start a goroutine to analyze tables automatically. It should be called only once in BootstrapSession.

type HistoricalStatsWorker

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

HistoricalStatsWorker indicates for dump historical stats

func (*HistoricalStatsWorker) DumpHistoricalStats

func (w *HistoricalStatsWorker) DumpHistoricalStats(tableID int64, statsHandle *handle.Handle) error

DumpHistoricalStats dump stats by given tableID

func (*HistoricalStatsWorker) GetOneHistoricalStatsTable

func (w *HistoricalStatsWorker) GetOneHistoricalStatsTable() int64

GetOneHistoricalStatsTable gets one tableID from channel, only used for test

func (*HistoricalStatsWorker) SendTblToDumpHistoricalStats

func (w *HistoricalStatsWorker) SendTblToDumpHistoricalStats(tableID int64)

SendTblToDumpHistoricalStats send tableID to worker to dump historical stats

type PlanReplayerDumpTask

type PlanReplayerDumpTask struct {
	PlanReplayerTaskKey

	// tmp variables stored during the query
	EncodePlan func(*stmtctx.StatementContext, bool) (string, string)
	TblStats   map[int64]interface{}

	// variables used to dump the plan
	SessionBindings []*bindinfo.BindRecord
	EncodedPlan     string
	SessionVars     *variable.SessionVars
	JSONTblStats    map[int64]*handle.JSONTable
	ExecStmts       []ast.StmtNode
	Analyze         bool

	FileName string
	Zf       *os.File
}

PlanReplayerDumpTask wrap the params for plan replayer dump

type PlanReplayerStatusRecord

type PlanReplayerStatusRecord struct {
	SQLDigest    string
	PlanDigest   string
	OriginSQL    string
	Token        string
	FailedReason string
}

PlanReplayerStatusRecord indicates record in mysql.plan_replayer_status

type PlanReplayerTaskKey

type PlanReplayerTaskKey struct {
	SQLDigest  string
	PlanDigest string
}

PlanReplayerTaskKey indicates key of a plan replayer task

type SchemaChecker

type SchemaChecker struct {
	SchemaValidator
	// contains filtered or unexported fields
}

SchemaChecker is used for checking schema-validity.

func NewSchemaChecker

func NewSchemaChecker(do *Domain, schemaVer int64, relatedTableIDs []int64, needCheckSchema bool) *SchemaChecker

NewSchemaChecker creates a new schema checker.

func (*SchemaChecker) Check

Check checks the validity of the schema version.

func (*SchemaChecker) CheckBySchemaVer

func (s *SchemaChecker) CheckBySchemaVer(txnTS uint64, startSchemaVer tikv.SchemaVer) (*transaction.RelatedSchemaChange, error)

CheckBySchemaVer checks if the schema version valid or not at txnTS.

type SchemaValidator

type SchemaValidator interface {
	// Update the schema validator, add a new item, delete the expired deltaSchemaInfos.
	// The latest schemaVer is valid within leaseGrantTime plus lease duration.
	// Add the changed table IDs to the new schema information,
	// which is produced when the oldSchemaVer is updated to the newSchemaVer.
	Update(leaseGrantTime uint64, oldSchemaVer, newSchemaVer int64, change *transaction.RelatedSchemaChange)
	// Check is it valid for a transaction to use schemaVer and related tables, at timestamp txnTS.
	Check(txnTS uint64, schemaVer int64, relatedPhysicalTableIDs []int64, needCheckSchema bool) (*transaction.RelatedSchemaChange, checkResult)
	// Stop stops checking the valid of transaction.
	Stop()
	// Restart restarts the schema validator after it is stopped.
	Restart()
	// Reset resets SchemaValidator to initial state.
	Reset()
	// IsStarted indicates whether SchemaValidator is started.
	IsStarted() bool
}

SchemaValidator is the interface for checking the validity of schema version.

func NewSchemaValidator

func NewSchemaValidator(lease time.Duration, do *Domain) SchemaValidator

NewSchemaValidator returns a SchemaValidator structure.

type SlowQueryInfo

type SlowQueryInfo struct {
	SQL        string
	Start      time.Time
	Duration   time.Duration
	Detail     execdetails.ExecDetails
	ConnID     uint64
	TxnTS      uint64
	User       string
	DB         string
	TableIDs   string
	IndexNames string
	Digest     string
	Internal   bool
	Succ       bool
}

SlowQueryInfo is a struct to record slow query info.

type SysProcesses

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

SysProcesses holds the sys processes infos

func (*SysProcesses) GetSysProcessList

func (s *SysProcesses) GetSysProcessList() map[uint64]*util.ProcessInfo

GetSysProcessList gets list of system ProcessInfo

func (*SysProcesses) KillSysProcess

func (s *SysProcesses) KillSysProcess(id uint64)

KillSysProcess kills sys process with specified ID

func (*SysProcesses) Track

func (s *SysProcesses) Track(id uint64, proc sessionctx.Context) error

Track tracks the sys process into procMap

func (*SysProcesses) UnTrack

func (s *SysProcesses) UnTrack(id uint64)

UnTrack removes the sys process from procMap

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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