server

package
v0.0.0-...-b827c1a Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Copyright © 2020 Marvin

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	Version   = "None"
	BuildTS   = "None"
	GitHash   = "None"
	GitBranch = "None"
)

版本信息

Functions

func AnalyzeTableStats

func AnalyzeTableStats(workerID int, task AnalyzeTask) error

func ClearTableStatsDumpFile

func ClearTableStatsDumpFile(schemaName, tableName, statsOutdir string, statsGCDays int) error

func GetAppVersion

func GetAppVersion(version bool)

func RecordAppVersion

func RecordAppVersion(app string, logger *zap.Logger, cfg *config.Config)

版本信息输出重定向到日志

func RenderAlertTemplateMSG

func RenderAlertTemplateMSG(rows []WaitStatsTable) string

func Run

func Run(mysqlCfg *config.Config) error

func StatsTableAnalyzeConcurrencyRule

func StatsTableAnalyzeConcurrencyRule(tableName string, statsComplexRuleMap map[string]map[string]int, analyzeDefaultTimeout int) ([]string, int)

表统计信息收集以及超时

func StatsTableAnalyzeSamplerateRule

func StatsTableAnalyzeSamplerateRule(tableName, dbVersion string,
	smallTableSamplerate, mediumTableSamplerate, bigTableSamplerate string,
	statsRuleSamplerateMap map[string]string, tableRowsTotalMap map[string]float64) string

表采样率

func StatsTableBackupOutdirRule

func StatsTableBackupOutdirRule(tableName string, statsOutdirRuleMap map[string]string, statsDefaultOutdir string) string

表统计信息备份目录

func StatsTableDumpFile

func StatsTableDumpFile(workerID int, host string, statusPort int, schemaName, tableName, partitionName, filePath string) error

func StatsTableHealthyRule

func StatsTableHealthyRule(tableName string, tableHealthyMap, statsRuleHealthyMap map[string]float64) bool

表健康度规则

func StatsTableModifyCountRule

func StatsTableModifyCountRule(tableName string, tableModifyMap, statsRuleModifyMap map[string]float64) bool

func StatsTableModifyZeroRule

func StatsTableModifyZeroRule(tableName string, tableModifyMap map[string]float64) bool

表 modify_count 规则

Types

type AnalyzeTask

type AnalyzeTask struct {
	Host           string
	Port           int
	StatusPort     int
	DBVersion      string
	RunningUser    string
	SchemaName     string
	TableName      string
	PartitionName  string
	RowCounts      float64
	StatsOutdir    string
	StatsGCDays    int
	AnalyzeTimeout int
	AnalyzeSQL     []string
	Engine         *Engine `json:"-"`
}

func AnalyzeTableAdjust

func AnalyzeTableAdjust(engine *Engine, mysqlCfg *config.Config, needTables []string) ([]AnalyzeTask, error)

func AnalyzeTaskFilter

func AnalyzeTaskFilter(mysqlCfg *config.Config, engine *Engine) ([]AnalyzeTask, error)

func (*AnalyzeTask) String

func (t *AnalyzeTask) String() string

type BaseModel

type BaseModel struct {
	CreatedAt string `gorm:"type:timestamp;not null;comment:'创建时间'" json:"createdAt"`
	UpdatedAt string `gorm:"type:timestamp;not null;comment:'更新时间'" json:"updatedAt"`
}

func (*BaseModel) BeforeCreate

func (v *BaseModel) BeforeCreate(db *gorm.DB) (err error)

func (*BaseModel) BeforeUpdate

func (v *BaseModel) BeforeUpdate(db *gorm.DB) (err error)

type Email

type Email struct {
	Receivers []string
	Subject   string
	Msg       string
}

func NewEmail

func NewEmail(receivers []string, subject, msg string) *Email

func (*Email) SendEmail

func (e *Email) SendEmail(sendCfg config.AlertConfig) error

type Engine

type Engine struct {
	TiDB   *sql.DB
	GormDB *gorm.DB
}

func NewMySQLEngineDB

func NewMySQLEngineDB(mysqlCfg *config.Config) (*Engine, error)

func (*Engine) GetMySQLDBALLTables

func (e *Engine) GetMySQLDBALLTables(metaSchema string) ([]string, error)

func (*Engine) GetMySQLDBPartitionTables

func (e *Engine) GetMySQLDBPartitionTables(metaSchema string) ([]string, []string, error)

func (*Engine) GetMySQLDBVersion

func (e *Engine) GetMySQLDBVersion() (string, error)

func (*Engine) GetStatsAnalyzeRuleTableALLRows

func (e *Engine) GetStatsAnalyzeRuleTableALLRows() (map[string]map[string]int, map[string]string, map[string]string, error)

func (*Engine) GetStatsTriggerRuleTableALLRows

func (e *Engine) GetStatsTriggerRuleTableALLRows() (map[string]float64, map[string]float64, error)

func (*Engine) GetTableStatsHealthy

func (e *Engine) GetTableStatsHealthy() (map[string]float64, error)

func (*Engine) GetTableStatsMeta

func (e *Engine) GetTableStatsMeta() (map[string]float64, map[string]float64, map[string]float64, error)

func (*Engine) GetWaitStatsTableALLRows

func (e *Engine) GetWaitStatsTableALLRows() ([]string, []string, []WaitStatsTable, error)

func (*Engine) InitMySQLEngineDB

func (e *Engine) InitMySQLEngineDB() error

func (*Engine) KillAnalyzeTimeoutSQL

func (e *Engine) KillAnalyzeTimeoutSQL(runningUser string, analyzeTimeout int, runningMatchingSQL string) error

func (*Engine) Query

func (e *Engine) Query(querySQL string) ([]string, []map[string]string, error)

func (*Engine) RunAnalyzeTask

func (e *Engine) RunAnalyzeTask(workerID int, task AnalyzeTask) error

func (*Engine) UpsertSingleTableStatsHealthy

func (e *Engine) UpsertSingleTableStatsHealthy(workerID int, schemaName, tableName, partitionTable, status string) error

func (*Engine) UpsertSingleTableStatsHistograms

func (e *Engine) UpsertSingleTableStatsHistograms(workerID int, schemaName, tableName, partitionTable, status string) error

func (*Engine) UpsertSingleTableStatsMeta

func (e *Engine) UpsertSingleTableStatsMeta(workerID int, schemaName, tableName, partitionTable, status string) error

type Job

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

func NewScheduleJob

func NewScheduleJob(workers int) *Job

func (*Job) Close

func (j *Job) Close()

func (*Job) Push

func (j *Job) Push(analyzeTasks []AnalyzeTask)

func (*Job) Run

func (j *Job) Run()

func (*Job) Wait

func (j *Job) Wait() error

type StatsAnalyzeRule

type StatsAnalyzeRule struct {
	ID                uint   `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SchemaName        string `gorm:"not null;index:idx_schema_table,unique;comment:'数据库名'" json:"schema_name"`
	TableName         string `gorm:"not null;index:idx_schema_table,unique;comment:'数据表名'" json:"table_name"`
	PartitionName     string `gorm:"not null;index:idx_schema_table,unique;comment:'分区名'" json:"partition_name"`
	BuildStatsThread  int    `gorm:"comment:'tidb_build_stats_concurrency 参数设置'" json:"build_stats_thread"`
	DistsqlScanThread int    `gorm:"comment:'tidb_distsql_scan_concurrency 参数设置'" json:"distsql_scan_thread"`
	SerialScanThread  int    `gorm:"comment:'tidb_index_serial_scan_concurrency 参数设置'" json:"serial_scan_thread"`
	SampleRate        string `gorm:"comment:'采样率 v5.3 版本以上支持'" json:"sample_rate"`
	AnalyzeTimeout    int    `gorm:"comment:'收集超时设置'" json:"analyze_timeout"`
	StatsOutdir       string `gorm:"comment:'统计信息备份目录'" json:"stats_outdir"`
	BaseModel
}

type StatsHealthy

type StatsHealthy struct {
	ID            uint   `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SchemaName    string `gorm:"not null;index:idx_schema_table,unique;comment:'数据库名'" json:"schema_name"`
	TableName     string `gorm:"not null;index:idx_schema_table,unique;comment:'数据表名'" json:"table_name"`
	PartitionName string `gorm:"index:idx_schema_table,unique;comment:'分区表名'" json:"partition_name"`
	Healthy       string `gorm:"not null;comment:'表健康度'" json:"healthy"`
	BaseModel
}

type StatsHealthyAfter

type StatsHealthyAfter struct {
	StatsHealthy
}

type StatsHealthyBefore

type StatsHealthyBefore struct {
	StatsHealthy
}

type StatsHistograms

type StatsHistograms struct {
	ID            uint   `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SchemaName    string `gorm:"not null;index:idx_schema_table,unique;comment:'数据库名'" json:"schema_name"`
	TableName     string `gorm:"not null;index:idx_schema_table,unique;comment:'数据表名'" json:"table_name"`
	PartitionName string `gorm:"index:idx_schema_table,unique;comment:'分区表名'" json:"partition_name"`
	ColumnName    string `gorm:"not null;comment:'字段名'" json:"column_name"`
	IsIndex       string `gorm:"not null;comment:'是否索引'" json:"is_index"`
	UpdateTime    string `gorm:"not null;comment:'统计信息更新时间'" json:"update_time"`
	DistinctCount string `gorm:"not null;comment:'唯一值数'" json:"distinct_count"`
	NullCount     string `gorm:"not null;comment:'Null 值数'" json:"null_count"`
	AvgColSize    string `gorm:"not null;comment:'平均字段大小'" json:"avg_col_size"`
	Correlation   string `gorm:"not null;comment:'correlation 值'" json:"correlation"`
	BaseModel
}

type StatsHistogramsAfter

type StatsHistogramsAfter struct {
	StatsHistograms
}

type StatsHistogramsBefore

type StatsHistogramsBefore struct {
	StatsHistograms
}

type StatsMeta

type StatsMeta struct {
	ID            uint   `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SchemaName    string `gorm:"not null;index:idx_schema_table,unique;comment:'数据库名'" json:"schema_name"`
	TableName     string `gorm:"not null;index:idx_schema_table,unique;comment:'数据表名'" json:"table_name"`
	PartitionName string `gorm:"index:idx_schema_table,unique;comment:'分区表名'" json:"partition_name"`
	UpdateTime    string `gorm:"not null;comment:'统计信息更新时间'" json:"update_time"`
	ModifyCount   string `gorm:"not null;comment:'唯一值数'" json:"modify_count"`
	RowCount      string `gorm:"not null;comment:'Null 值数'" json:"row_count"`
	BaseModel
}

type StatsMetaAfter

type StatsMetaAfter struct {
	StatsMeta
}

type StatsMetaBefore

type StatsMetaBefore struct {
	StatsMeta
}

type StatsTriggerRule

type StatsTriggerRule struct {
	ID            uint    `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SchemaName    string  `gorm:"not null;index:idx_schema_table,unique;comment:'数据库名'" json:"schema_name"`
	TableName     string  `gorm:"not null;index:idx_schema_table,unique;comment:'数据表名'" json:"table_name"`
	PartitionName string  `gorm:"not null;index:idx_schema_table,unique;comment:'分区名'" json:"partition_name"`
	StatsHealthy  float64 `gorm:"not null;comment:'表健康度阈值'" json:"server_addr"`
	StatsModify   float64 `gorm:"not null;comment:'表 modify_count 阈值'" json:"db_version"`
	BaseModel
}

type WaitStatsTable

type WaitStatsTable struct {
	ID             uint    `gorm:"primary_key;autoIncrement;comment:'自增编号'" json:"id"`
	SchemaName     string  `gorm:"not null;index:idx_schema_table,unique;comment:'数据库名'" json:"schema_name"`
	TableName      string  `gorm:"not null;index:idx_schema_table,unique;comment:'数据表名'" json:"table_name"`
	PartitionName  string  `gorm:"not null;index:idx_schema_table,unique;comment:'分区名'" json:"partition_name"`
	ServerAddr     string  `gorm:"not null;comment:'数据库地址'" json:"server_addr"`
	DBVersion      string  `gorm:"not null;comment:'数据库版本'" json:"db_version"`
	AnalyzeSQL     string  `gorm:"not null;comment:'收集 SQL'" json:"analyze_sql"`
	AnalyzeTimeout int     `gorm:"not null;comment:'收集超时设置'" json:"analyze_timeout"`
	RowCounts      float64 `gorm:"not null;comment:'表行数'" json:"row_counts"`
	StatsOutdir    string  `gorm:"not null;comment:'统计信息备份目录'" json:"stats_outdir"`
	BaseModel
}

统计信息

Jump to

Keyboard shortcuts

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