helper

package
v3.1.0-fork Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2020 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FrameItem

type FrameItem struct {
	DBName      string   `json:"db_name"`
	TableName   string   `json:"table_name"`
	TableID     int64    `json:"table_id"`
	IsRecord    bool     `json:"is_record"`
	RecordID    int64    `json:"record_id,omitempty"`
	IndexName   string   `json:"index_name,omitempty"`
	IndexID     int64    `json:"index_id,omitempty"`
	IndexValues []string `json:"index_values,omitempty"`
}

FrameItem includes a index's or record's meta data with table's info.

func NewFrameItemFromRegionKey

func NewFrameItemFromRegionKey(key []byte) (frame *FrameItem, err error)

NewFrameItemFromRegionKey creates a FrameItem with region's startKey or endKey, returns err when key is illegal.

type Helper

type Helper struct {
	Store       tikv.Storage
	RegionCache *tikv.RegionCache
}

Helper is a middleware to get some information from tikv/pd. It can be used for TiDB's http api or mem table.

func NewHelper

func NewHelper(store tikv.Storage) *Helper

NewHelper get a Helper from Storage

func (*Helper) FetchHotRegion

func (h *Helper) FetchHotRegion(rw string) (map[uint64]RegionMetric, error)

FetchHotRegion fetches the hot region information from PD's http api.

func (*Helper) FetchRegionTableIndex

func (h *Helper) FetchRegionTableIndex(metrics map[uint64]RegionMetric, allSchemas []*model.DBInfo) ([]HotTableIndex, error)

FetchRegionTableIndex constructs a map that maps a table to its hot region information by the given raw hot RegionMetric metrics.

func (*Helper) FindTableIndexOfRegion

func (h *Helper) FindTableIndexOfRegion(allSchemas []*model.DBInfo, hotRange *RegionFrameRange) *FrameItem

FindTableIndexOfRegion finds what table is involved in this hot region. And constructs the new frame item for future use.

func (*Helper) GetMvccByEncodedKey

func (h *Helper) GetMvccByEncodedKey(encodedKey kv.Key) (*kvrpcpb.MvccGetByKeyResponse, error)

GetMvccByEncodedKey get the MVCC value by the specific encoded key.

func (*Helper) GetRegionInfoByID

func (h *Helper) GetRegionInfoByID(regionID uint64) (*RegionInfo, error)

GetRegionInfoByID gets the region information of the region ID by using PD's api.

func (*Helper) GetRegionsInfo

func (h *Helper) GetRegionsInfo() (*RegionsInfo, error)

GetRegionsInfo gets the region information of current store by using PD's api.

func (*Helper) GetRegionsTableInfo

func (h *Helper) GetRegionsTableInfo(regionsInfo *RegionsInfo, schemas []*model.DBInfo) map[int64][]TableInfo

GetRegionsTableInfo returns a map maps region id to its tables or indices. Assuming tables or indices key ranges never intersect. Regions key ranges can intersect.

func (*Helper) GetStoresStat

func (h *Helper) GetStoresStat() (*StoresStat, error)

GetStoresStat gets the TiKV store information by accessing PD's api.

func (*Helper) ScrapeHotInfo

func (h *Helper) ScrapeHotInfo(rw string, allSchemas []*model.DBInfo) ([]HotTableIndex, error)

ScrapeHotInfo gets the needed hot region information by the url given.

type HotRegionsStat

type HotRegionsStat struct {
	RegionsStat []RegionStat `json:"statistics"`
}

HotRegionsStat records echo store's hot region. it's the response of PD.

type HotTableIndex

type HotTableIndex struct {
	RegionID     uint64        `json:"region_id"`
	RegionMetric *RegionMetric `json:"region_metric"`
	DbName       string        `json:"db_name"`
	TableName    string        `json:"table_name"`
	TableID      int64         `json:"table_id"`
	IndexName    string        `json:"index_name"`
	IndexID      int64         `json:"index_id"`
}

HotTableIndex contains region and its table/index info.

type RegionEpoch

type RegionEpoch struct {
	ConfVer int64 `json:"conf_ver"`
	Version int64 `json:"version"`
}

RegionEpoch stores the information about its epoch.

type RegionFrameRange

type RegionFrameRange struct {
	First *FrameItem // start frame of the region
	Last  *FrameItem // end frame of the region
	// contains filtered or unexported fields
}

RegionFrameRange contains a frame range info which the region covered.

func NewRegionFrameRange

func NewRegionFrameRange(region *tikv.KeyLocation) (idxRange *RegionFrameRange, err error)

NewRegionFrameRange init a NewRegionFrameRange with region info.

func (*RegionFrameRange) GetIndexFrame

func (r *RegionFrameRange) GetIndexFrame(tableID, indexID int64, dbName, tableName, indexName string) *FrameItem

GetIndexFrame returns the indnex frame of a table. If the table's indices are not covered by this frame range, it returns nil.

func (*RegionFrameRange) GetRecordFrame

func (r *RegionFrameRange) GetRecordFrame(tableID int64, dbName, tableName string) *FrameItem

GetRecordFrame returns the record frame of a table. If the table's records are not covered by this frame range, it returns nil.

type RegionInfo

type RegionInfo struct {
	ID              int64            `json:"id"`
	StartKey        string           `json:"start_key"`
	EndKey          string           `json:"end_key"`
	Epoch           RegionEpoch      `json:"epoch"`
	Peers           []RegionPeer     `json:"peers"`
	Leader          RegionPeer       `json:"leader"`
	DownPeers       []RegionPeerStat `json:"down_peers"`
	PendingPeers    []RegionPeer     `json:"pending_peers"`
	WrittenBytes    int64            `json:"written_bytes"`
	ReadBytes       int64            `json:"read_bytes"`
	ApproximateSize int64            `json:"approximate_size"`
	ApproximateKeys int64            `json:"approximate_keys"`
}

RegionInfo stores the information of one region.

type RegionMetric

type RegionMetric struct {
	FlowBytes    uint64 `json:"flow_bytes"`
	MaxHotDegree int    `json:"max_hot_degree"`
	Count        int    `json:"region_count"`
}

RegionMetric presents the final metric output entry.

type RegionPeer

type RegionPeer struct {
	ID        int64 `json:"id"`
	StoreID   int64 `json:"store_id"`
	IsLearner bool  `json:"is_learner"`
}

RegionPeer stores information of one peer.

type RegionPeerStat

type RegionPeerStat struct {
	RegionPeer
	DownSec int64 `json:"down_seconds"`
}

RegionPeerStat stores one field `DownSec` which indicates how long it's down than `RegionPeer`.

type RegionStat

type RegionStat struct {
	RegionID  uint64  `json:"region_id"`
	FlowBytes float64 `json:"flow_bytes"`
	HotDegree int     `json:"hot_degree"`
}

RegionStat records each hot region's statistics it's the response of PD.

type RegionsInfo

type RegionsInfo struct {
	Count   int64        `json:"count"`
	Regions []RegionInfo `json:"regions"`
}

RegionsInfo stores the information of regions.

type StoreBaseStat

type StoreBaseStat struct {
	ID             int64        `json:"id"`
	Address        string       `json:"address"`
	State          int64        `json:"state"`
	StateName      string       `json:"state_name"`
	Version        string       `json:"version"`
	Labels         []StoreLabel `json:"labels"`
	StatusAddress  string       `json:"status_address"`
	GitHash        string       `json:"git_hash"`
	StartTimestamp int64        `json:"start_timestamp"`
}

StoreBaseStat stores the basic information of one store.

type StoreDetailStat

type StoreDetailStat struct {
	Capacity        string    `json:"capacity"`
	Available       string    `json:"available"`
	LeaderCount     int64     `json:"leader_count"`
	LeaderWeight    float64   `json:"leader_weight"`
	LeaderScore     float64   `json:"leader_score"`
	LeaderSize      int64     `json:"leader_size"`
	RegionCount     int64     `json:"region_count"`
	RegionWeight    float64   `json:"region_weight"`
	RegionScore     float64   `json:"region_score"`
	RegionSize      int64     `json:"region_size"`
	StartTs         time.Time `json:"start_ts"`
	LastHeartbeatTs time.Time `json:"last_heartbeat_ts"`
	Uptime          string    `json:"uptime"`
}

StoreDetailStat stores the detail information of one store.

type StoreHotRegionInfos

type StoreHotRegionInfos struct {
	AsPeer   map[uint64]*HotRegionsStat `json:"as_peer"`
	AsLeader map[uint64]*HotRegionsStat `json:"as_leader"`
}

StoreHotRegionInfos records all hog region stores. it's the response of PD.

type StoreLabel

type StoreLabel struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

StoreLabel stores the information of one store label.

type StoreStat

type StoreStat struct {
	Store  StoreBaseStat   `json:"store"`
	Status StoreDetailStat `json:"status"`
}

StoreStat stores information of one store.

type StoresStat

type StoresStat struct {
	Count  int         `json:"count"`
	Stores []StoreStat `json:"stores"`
}

StoresStat stores all information get from PD's api.

type TableInfo

type TableInfo struct {
	DB      *model.DBInfo
	Table   *model.TableInfo
	IsIndex bool
	Index   *model.IndexInfo
}

TableInfo stores the information of a table or an index

type TblIndex

type TblIndex struct {
	DbName    string
	TableName string
	TableID   int64
	IndexName string
	IndexID   int64
}

TblIndex stores the things to index one table.

Jump to

Keyboard shortcuts

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