core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EmptyRegionApproximateSize is the region approximate size of an empty region
	// (heartbeat size <= 1MB).
	EmptyRegionApproximateSize = 1
	// ImpossibleFlowSize is an impossible flow size (such as written_bytes, read_keys, etc.)
	// It may be caused by overflow, refer to https://github.com/gottingen/tm/issues/3379.
	// They need to be filtered so as not to affect downstream.
	// (flow size >= 1024TB)
	ImpossibleFlowSize = 1 << 50

	// InitClusterRegionThreshold is a threshold which represent a new cluster.
	InitClusterRegionThreshold = 100
)
View Source
const (

	// EngineKey is the label key used to indicate engine.
	EngineKey = "engine"
	// EngineTiFlash is the tiflash value of the engine label.
	EngineTiFlash = "tiflash"
	// EngineTiKV indicates the tikv engine in metrics
	EngineTiKV = "tikv"
)

Variables

View Source
var (
	// RegionFactory returns new region.
	RegionFactory = func() *metapb.Region { return &metapb.Region{} }
	// RegionPeerFactory returns new region peer.
	RegionPeerFactory = func() *metapb.Peer { return &metapb.Peer{} }
	// RegionHeartbeatResponseFactory returns new region heartbeat response.
	RegionHeartbeatResponseFactory = func() *pdpb.RegionHeartbeatResponse { return &pdpb.RegionHeartbeatResponse{} }
	// PeerStatsFactory returns new peer stats.
	PeerStatsFactory = func() *pdpb.PeerStats { return &pdpb.PeerStats{} }

	// StoreFactory returns new store.
	StoreFactory = func() *metapb.Store { return &metapb.Store{} }
	// StoreStatsFactory returns new store stats.
	StoreStatsFactory = func() *pdpb.StoreStats { return &pdpb.StoreStats{} }

	// KeyDictionaryFactory returns new key dictionary.
	KeyDictionaryFactory = func() *encryptionpb.KeyDictionary { return &encryptionpb.KeyDictionary{} }
	// MemberFactory returns new member.
	MemberFactory = func() *pdpb.Member { return &pdpb.Member{} }
	// ClusterFactory returns new cluster.
	ClusterFactory = func() *metapb.Cluster { return &metapb.Cluster{} }
	// TimeIntervalFactory returns new time interval.
	TimeIntervalFactory = func() *pdpb.TimeInterval { return &pdpb.TimeInterval{} }
	// QueryStatsFactory returns new query stats.
	QueryStatsFactory = func() *pdpb.QueryStats { return &pdpb.QueryStats{} }
)

Functions

func CountInJointState

func CountInJointState(peers ...*metapb.Peer) int

CountInJointState count the peers are in joint state.

func DiffRegionKeyInfo

func DiffRegionKeyInfo(origin *RegionInfo, other *RegionInfo) string

DiffRegionKeyInfo return the difference of key info between two RegionInfo

func DiffRegionPeersInfo

func DiffRegionPeersInfo(origin *RegionInfo, other *RegionInfo) string

DiffRegionPeersInfo return the difference of peers info between two RegionInfo

func DistinctScore

func DistinctScore(labels []string, stores []*StoreInfo, other *StoreInfo) float64

DistinctScore returns the score that the other is distinct from the stores. A higher score means the other store is more different from the existed stores.

func EncodeToString

func EncodeToString(src []byte) []byte

EncodeToString overrides hex.EncodeToString implementation. Difference: returns []byte, not string

func GetReadQueryNum

func GetReadQueryNum(stats *pdpb.QueryStats) uint64

GetReadQueryNum returns read query num from this QueryStats

func GetWriteQueryNum

func GetWriteQueryNum(stats *pdpb.QueryStats) uint64

GetWriteQueryNum returns write query num from this QueryStats

func HexRegionKey

func HexRegionKey(key []byte) []byte

HexRegionKey converts region key to hex format. Used for formating region in logs.

func HexRegionKeyStr

func HexRegionKeyStr(key []byte) string

HexRegionKeyStr converts region key to hex format. Used for formating region in logs.

func IsAvailableForMinResolvedTS

func IsAvailableForMinResolvedTS(s *StoreInfo) bool

IsAvailableForMinResolvedTS returns if the store is available for min resolved ts.

func IsInJointState

func IsInJointState(peers ...*metapb.Peer) bool

IsInJointState judges whether the Peer is in joint state.

func IsLearner

func IsLearner(peer *metapb.Peer) bool

IsLearner judges whether the Peer's Role is Learner.

func IsLearnerOrDemotingVoter

func IsLearnerOrDemotingVoter(peer *metapb.Peer) bool

IsLearnerOrDemotingVoter judges whether peer role will become Learner. The peer is not nil and the role is equal to DemotingVoter or Learner.

func IsStoreContainLabel

func IsStoreContainLabel(store *metapb.Store, key, value string) bool

IsStoreContainLabel returns if the store contains the given label.

func IsVoter

func IsVoter(peer *metapb.Peer) bool

IsVoter judges whether the Peer's Role is Voter

func IsVoterOrIncomingVoter

func IsVoterOrIncomingVoter(peer *metapb.Peer) bool

IsVoterOrIncomingVoter judges whether peer role will become Voter. The peer is not nil and the role is equal to IncomingVoter or Voter.

func IsWitness

func IsWitness(peer *metapb.Peer) bool

IsWitness judges whether the peer is a witness peer.

func MergeLabels

func MergeLabels(origin []*metapb.StoreLabel, labels []*metapb.StoreLabel) []*metapb.StoreLabel

MergeLabels merges the passed in labels with origins, overriding duplicated ones.

func NeedTransferWitnessLeader

func NeedTransferWitnessLeader(region *RegionInfo) bool

NeedTransferWitnessLeader is used to judge if the region's leader is a witness

func RandomKindReadQuery

func RandomKindReadQuery(queryRead uint64) *pdpb.QueryStats

RandomKindReadQuery returns query stat with random query kind, only used for unit test.

func RandomKindWriteQuery

func RandomKindWriteQuery(queryWrite uint64) *pdpb.QueryStats

RandomKindWriteQuery returns query stat with random query kind, only used for unit test.

func SortedPeersEqual

func SortedPeersEqual(peersA, peersB []*metapb.Peer) bool

SortedPeersEqual judges whether two sorted `peerSlice` are equal

func SortedPeersStatsEqual

func SortedPeersStatsEqual(peersA, peersB []*pdpb.PeerStats) bool

SortedPeersStatsEqual judges whether two sorted `peerStatsSlice` are equal

func String

func String(b []byte) (s string)

String converts slice of bytes to string without copy.

func ToUpperASCIIInplace

func ToUpperASCIIInplace(s []byte) []byte

ToUpperASCIIInplace bytes.ToUpper but zero-cost

Types

type BasicCluster

type BasicCluster struct {
	Stores struct {
		*StoresInfo
		// contains filtered or unexported fields
	}

	*RegionsInfo
}

BasicCluster provides basic data member and interface for a tikv cluster.

func NewBasicCluster

func NewBasicCluster() *BasicCluster

NewBasicCluster creates a BasicCluster.

func (*BasicCluster) DeleteStore

func (bc *BasicCluster) DeleteStore(store *StoreInfo)

DeleteStore deletes a store.

func (*BasicCluster) GetFollowerStores

func (bc *BasicCluster) GetFollowerStores(region *RegionInfo) []*StoreInfo

GetFollowerStores returns all Stores that contains the region's follower peer.

func (*BasicCluster) GetLeaderStore

func (bc *BasicCluster) GetLeaderStore(region *RegionInfo) *StoreInfo

GetLeaderStore returns all Stores that contains the region's leader peer.

func (*BasicCluster) GetLeaderStoreByRegionID

func (bc *BasicCluster) GetLeaderStoreByRegionID(regionID uint64) *StoreInfo

GetLeaderStoreByRegionID returns the leader store of the given region.

func (*BasicCluster) GetMetaStores

func (bc *BasicCluster) GetMetaStores() []*metapb.Store

GetMetaStores gets a complete set of metapb.Store.

func (*BasicCluster) GetNonWitnessVoterStores

func (bc *BasicCluster) GetNonWitnessVoterStores(region *RegionInfo) []*StoreInfo

GetNonWitnessVoterStores returns all Stores that contains the non-witness's voter peer.

func (*BasicCluster) GetRegionStores

func (bc *BasicCluster) GetRegionStores(region *RegionInfo) []*StoreInfo

GetRegionStores returns all Stores that contains the region's peer.

func (*BasicCluster) GetStore

func (bc *BasicCluster) GetStore(storeID uint64) *StoreInfo

GetStore searches for a store by ID.

func (*BasicCluster) GetStoreCount

func (bc *BasicCluster) GetStoreCount() int

GetStoreCount returns the total count of storeInfo.

func (*BasicCluster) GetStores

func (bc *BasicCluster) GetStores() []*StoreInfo

GetStores returns all Stores in the cluster.

func (*BasicCluster) GetStoresLeaderWriteRate

func (bc *BasicCluster) GetStoresLeaderWriteRate() (storeIDs []uint64, bytesRates, keysRates []float64)

GetStoresLeaderWriteRate get total write rate of each store's leaders.

func (*BasicCluster) GetStoresWriteRate

func (bc *BasicCluster) GetStoresWriteRate() (storeIDs []uint64, bytesRates, keysRates []float64)

GetStoresWriteRate get total write rate of each store's regions.

func (*BasicCluster) PauseLeaderTransfer

func (bc *BasicCluster) PauseLeaderTransfer(storeID uint64) error

PauseLeaderTransfer prevents the store from been selected as source or target store of TransferLeader.

func (*BasicCluster) PutStore

func (bc *BasicCluster) PutStore(store *StoreInfo)

PutStore put a store.

func (*BasicCluster) ResetStoreLimit

func (bc *BasicCluster) ResetStoreLimit(storeID uint64, limitType storelimit.Type, ratePerSec ...float64)

ResetStoreLimit resets the limit for a specific store.

func (*BasicCluster) ResetStores

func (bc *BasicCluster) ResetStores()

ResetStores resets the store cache.

func (*BasicCluster) ResumeLeaderTransfer

func (bc *BasicCluster) ResumeLeaderTransfer(storeID uint64)

ResumeLeaderTransfer cleans a store's pause state. The store can be selected as source or target of TransferLeader again.

func (*BasicCluster) SlowStoreEvicted

func (bc *BasicCluster) SlowStoreEvicted(storeID uint64) error

SlowStoreEvicted marks a store as a slow store and prevents transferring leader to the store

func (*BasicCluster) SlowStoreRecovered

func (bc *BasicCluster) SlowStoreRecovered(storeID uint64)

SlowStoreRecovered cleans the evicted state of a store.

func (*BasicCluster) SlowTrendEvicted

func (bc *BasicCluster) SlowTrendEvicted(storeID uint64) error

SlowTrendEvicted marks a store as a slow store by trend and prevents transferring leader to the store

func (*BasicCluster) SlowTrendRecovered

func (bc *BasicCluster) SlowTrendRecovered(storeID uint64)

SlowTrendRecovered cleans the evicted by slow trend state of a store.

func (*BasicCluster) UpdateStoreStatus

func (bc *BasicCluster) UpdateStoreStatus(storeID uint64)

UpdateStoreStatus updates the information of the store.

type HexRegionMeta

type HexRegionMeta struct {
	*metapb.Region
}

HexRegionMeta is a region meta in the hex format. Used for formating region in logs.

func RegionToHexMeta

func RegionToHexMeta(meta *metapb.Region) HexRegionMeta

RegionToHexMeta converts a region meta's keys to hex format. Used for formating region in logs.

func (HexRegionMeta) String

func (h HexRegionMeta) String() string

type HexRegionsMeta

type HexRegionsMeta []*metapb.Region

HexRegionsMeta is a slice of regions' meta in the hex format. Used for formating region in logs.

func RegionsToHexMeta

func RegionsToHexMeta(regions []*metapb.Region) HexRegionsMeta

RegionsToHexMeta converts regions' meta keys to hex format. Used for formating region in logs.

func (HexRegionsMeta) String

func (h HexRegionsMeta) String() string

type KeyRange

type KeyRange struct {
	StartKey []byte `json:"start-key"`
	EndKey   []byte `json:"end-key"`
}

KeyRange is a key range.

func NewKeyRange

func NewKeyRange(startKey, endKey string) KeyRange

NewKeyRange create a KeyRange with the given start key and end key.

type PeerInfo

type PeerInfo struct {
	*metapb.Peer
	// contains filtered or unexported fields
}

PeerInfo provides peer information

func NewPeerInfo

func NewPeerInfo(meta *metapb.Peer, loads []float64, interval uint64) *PeerInfo

NewPeerInfo creates PeerInfo

func (*PeerInfo) GetInterval

func (p *PeerInfo) GetInterval() uint64

GetInterval returns reporting interval

func (*PeerInfo) GetLoads

func (p *PeerInfo) GetLoads() []float64

GetLoads provides loads

func (*PeerInfo) GetPeerID

func (p *PeerInfo) GetPeerID() uint64

GetPeerID provides peer id

type RegionCreateOption

type RegionCreateOption func(region *RegionInfo)

RegionCreateOption used to create region.

func AddQueryStats

func AddQueryStats(v *pdpb.QueryStats) RegionCreateOption

AddQueryStats sets the query stats for the region, it will preserve previous statistic. This func is only used for test and simulator.

func SetApproximateKeys

func SetApproximateKeys(v int64) RegionCreateOption

SetApproximateKeys sets the approximate keys for the region.

func SetApproximateSize

func SetApproximateSize(v int64) RegionCreateOption

SetApproximateSize sets the approximate size for the region.

func SetBuckets

func SetBuckets(buckets *metapb.Buckets) RegionCreateOption

SetBuckets sets the buckets for the region, only use test.

func SetCPUUsage

func SetCPUUsage(v uint64) RegionCreateOption

SetCPUUsage sets the CPU usage of the region.

func SetFromHeartbeat

func SetFromHeartbeat(fromHeartbeat bool) RegionCreateOption

SetFromHeartbeat sets if the region info comes from the region heartbeat.

func SetPeers

func SetPeers(peers []*metapb.Peer) RegionCreateOption

SetPeers sets the peers for the region.

func SetQueryStats

func SetQueryStats(v *pdpb.QueryStats) RegionCreateOption

SetQueryStats sets the query stats for the region, it will cover previous statistic. This func is only used for unit test.

func SetReadBytes

func SetReadBytes(v uint64) RegionCreateOption

SetReadBytes sets the read bytes for the region.

func SetReadKeys

func SetReadKeys(v uint64) RegionCreateOption

SetReadKeys sets the read keys for the region.

func SetReadQuery

func SetReadQuery(v uint64) RegionCreateOption

SetReadQuery sets the read query for the region, only used for unit test.

func SetRegionConfVer

func SetRegionConfVer(confVer uint64) RegionCreateOption

SetRegionConfVer sets the config version for the region.

func SetRegionVersion

func SetRegionVersion(version uint64) RegionCreateOption

SetRegionVersion sets the version for the region.

func SetReplicationStatus

SetReplicationStatus sets the region's replication status.

func SetReportInterval

func SetReportInterval(start, end uint64) RegionCreateOption

SetReportInterval sets the report interval for the region. This func is only used for test.

func SetWrittenBytes

func SetWrittenBytes(v uint64) RegionCreateOption

SetWrittenBytes sets the written bytes for the region.

func SetWrittenKeys

func SetWrittenKeys(v uint64) RegionCreateOption

SetWrittenKeys sets the written keys for the region.

func SetWrittenQuery

func SetWrittenQuery(v uint64) RegionCreateOption

SetWrittenQuery sets the write query for the region, only used for unit test.

func WithAddPeer

func WithAddPeer(peer *metapb.Peer) RegionCreateOption

WithAddPeer adds a peer for the region.

func WithDecConfVer

func WithDecConfVer() RegionCreateOption

WithDecConfVer decreases the config version of the region.

func WithDecVersion

func WithDecVersion() RegionCreateOption

WithDecVersion decreases the version of the region.

func WithDownPeers

func WithDownPeers(downPeers []*pdpb.PeerStats) RegionCreateOption

WithDownPeers sets the down peers for the region.

func WithEndKey

func WithEndKey(key []byte) RegionCreateOption

WithEndKey sets the end key for the region.

func WithFlowRoundByDigit

func WithFlowRoundByDigit(digit int) RegionCreateOption

WithFlowRoundByDigit set the digit, which use to round to the nearest number

func WithIncConfVer

func WithIncConfVer() RegionCreateOption

WithIncConfVer increases the config version of the region.

func WithIncVersion

func WithIncVersion() RegionCreateOption

WithIncVersion increases the version of the region.

func WithInterval

func WithInterval(interval *pdpb.TimeInterval) RegionCreateOption

WithInterval sets the interval

func WithLeader

func WithLeader(leader *metapb.Peer) RegionCreateOption

WithLeader sets the leader for the region.

func WithLearners

func WithLearners(learners []*metapb.Peer) RegionCreateOption

WithLearners sets the learners for the region.

func WithNewPeerIDs

func WithNewPeerIDs(peerIDs ...uint64) RegionCreateOption

WithNewPeerIDs sets new ids for peers.

func WithNewRegionID

func WithNewRegionID(id uint64) RegionCreateOption

WithNewRegionID sets new id for the region.

func WithPendingPeers

func WithPendingPeers(pendingPeers []*metapb.Peer) RegionCreateOption

WithPendingPeers sets the pending peers for the region.

func WithRemoveStorePeer

func WithRemoveStorePeer(storeID uint64) RegionCreateOption

WithRemoveStorePeer removes the specified peer for the region.

func WithReplacePeerStore

func WithReplacePeerStore(oldStoreID, newStoreID uint64) RegionCreateOption

WithReplacePeerStore replaces a peer's storeID with another ID.

func WithRole

func WithRole(peerID uint64, role metapb.PeerRole) RegionCreateOption

WithRole changes the role.

func WithStartKey

func WithStartKey(key []byte) RegionCreateOption

WithStartKey sets the start key for the region.

func WithWitness

func WithWitness(peerID uint64) RegionCreateOption

WithWitness sets the witness for the region.

func WithWitnesses

func WithWitnesses(witnesses []*metapb.Peer) RegionCreateOption

WithWitnesses sets the witnesses for the region.

type RegionGuideFunc

type RegionGuideFunc func(region, origin *RegionInfo) (isNew, saveKV, saveCache, needSync bool)

RegionGuideFunc is a function that determines which follow-up operations need to be performed based on the origin and new region information.

func GenerateRegionGuideFunc

func GenerateRegionGuideFunc(enableLog bool) RegionGuideFunc

GenerateRegionGuideFunc is used to generate a RegionGuideFunc. Control the log output by specifying the log function. nil means do not print the log.

type RegionInfo

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

RegionInfo records detail region info. the properties are Read-Only once created except buckets. the `buckets` could be modified by the request `report buckets` with greater version.

func MergeRegions

func MergeRegions(regions []*RegionInfo) []*RegionInfo

MergeRegions merge a set of RegionInfo by regionKey. Only for test purpose.

func NewRegionInfo

func NewRegionInfo(region *metapb.Region, leader *metapb.Peer, opts ...RegionCreateOption) *RegionInfo

NewRegionInfo creates RegionInfo with region's meta and leader peer.

func NewTestRegionInfo

func NewTestRegionInfo(regionID, storeID uint64, start, end []byte, opts ...RegionCreateOption) *RegionInfo

NewTestRegionInfo creates a new RegionInfo for test purpose.

func RegionFromHeartbeat

func RegionFromHeartbeat(heartbeat *pdpb.RegionHeartbeatRequest, opts ...RegionCreateOption) *RegionInfo

RegionFromHeartbeat constructs a Region from region heartbeat.

func SplitRegions

func SplitRegions(regions []*RegionInfo) []*RegionInfo

SplitRegions split a set of RegionInfo by the middle of regionKey. Only for test purpose.

func (*RegionInfo) Clone

func (r *RegionInfo) Clone(opts ...RegionCreateOption) *RegionInfo

Clone returns a copy of current regionInfo.

func (*RegionInfo) GetApproximateKeys

func (r *RegionInfo) GetApproximateKeys() int64

GetApproximateKeys returns the approximate keys of the region.

func (*RegionInfo) GetApproximateSize

func (r *RegionInfo) GetApproximateSize() int64

GetApproximateSize returns the approximate size of the region.

func (*RegionInfo) GetBuckets

func (r *RegionInfo) GetBuckets() *metapb.Buckets

GetBuckets returns the buckets of the region.

func (*RegionInfo) GetBytesRead

func (r *RegionInfo) GetBytesRead() uint64

GetBytesRead returns the read bytes of the region.

func (*RegionInfo) GetBytesWritten

func (r *RegionInfo) GetBytesWritten() uint64

GetBytesWritten returns the written bytes of the region.

func (*RegionInfo) GetCPUUsage

func (r *RegionInfo) GetCPUUsage() uint64

GetCPUUsage returns the CPU usage of the region since the last heartbeat. The number range is [0, N * 100], where N is the number of CPU cores. However, since the TiKV basically only meters the CPU usage inside the Unified Read Pool, it should be considered as an indicator of Region read CPU overhead for now.

func (*RegionInfo) GetDiffFollowers

func (r *RegionInfo) GetDiffFollowers(other *RegionInfo) []*metapb.Peer

GetDiffFollowers returns the followers which is not located in the same store as any other followers of the another specified region.

func (*RegionInfo) GetDownLearner

func (r *RegionInfo) GetDownLearner(peerID uint64) *metapb.Peer

GetDownLearner returns the down learner with soecified peer id.

func (*RegionInfo) GetDownPeer

func (r *RegionInfo) GetDownPeer(peerID uint64) *metapb.Peer

GetDownPeer returns the down peer with specified peer id.

func (*RegionInfo) GetDownPeers

func (r *RegionInfo) GetDownPeers() []*pdpb.PeerStats

GetDownPeers returns the down peers of the region.

func (*RegionInfo) GetDownVoter

func (r *RegionInfo) GetDownVoter(peerID uint64) *metapb.Peer

GetDownVoter returns the down voter with specified peer id.

func (*RegionInfo) GetEndKey

func (r *RegionInfo) GetEndKey() []byte

GetEndKey returns the end key of the region.

func (*RegionInfo) GetFollower

func (r *RegionInfo) GetFollower() *metapb.Peer

GetFollower randomly returns a follow peer.

func (*RegionInfo) GetFollowers

func (r *RegionInfo) GetFollowers() map[uint64]*metapb.Peer

GetFollowers returns a map indicate the follow peers distributed.

func (*RegionInfo) GetID

func (r *RegionInfo) GetID() uint64

GetID returns the ID of the region.

func (*RegionInfo) GetInterval

func (r *RegionInfo) GetInterval() *pdpb.TimeInterval

GetInterval returns the interval information of the region.

func (*RegionInfo) GetKeysRead

func (r *RegionInfo) GetKeysRead() uint64

GetKeysRead returns the read keys of the region.

func (*RegionInfo) GetKeysWritten

func (r *RegionInfo) GetKeysWritten() uint64

GetKeysWritten returns the written keys of the region.

func (*RegionInfo) GetLeader

func (r *RegionInfo) GetLeader() *metapb.Peer

GetLeader returns the leader of the region.

func (*RegionInfo) GetLearners

func (r *RegionInfo) GetLearners() []*metapb.Peer

GetLearners returns the learners.

func (*RegionInfo) GetLoads

func (r *RegionInfo) GetLoads() []float64

GetLoads returns loads from region

func (*RegionInfo) GetMeta

func (r *RegionInfo) GetMeta() *metapb.Region

GetMeta returns the meta information of the region.

func (*RegionInfo) GetNonWitnessVoters

func (r *RegionInfo) GetNonWitnessVoters() map[uint64]*metapb.Peer

GetNonWitnessVoters returns a map indicate the non-witness voter peers distributed.

func (*RegionInfo) GetPeer

func (r *RegionInfo) GetPeer(peerID uint64) *metapb.Peer

GetPeer returns the peer with specified peer id.

func (*RegionInfo) GetPeers

func (r *RegionInfo) GetPeers() []*metapb.Peer

GetPeers returns the peers of the region.

func (*RegionInfo) GetPendingLearner

func (r *RegionInfo) GetPendingLearner(peerID uint64) *metapb.Peer

GetPendingLearner returns the pending learner peer with specified peer id.

func (*RegionInfo) GetPendingPeer

func (r *RegionInfo) GetPendingPeer(peerID uint64) *metapb.Peer

GetPendingPeer returns the pending peer with specified peer id.

func (*RegionInfo) GetPendingPeers

func (r *RegionInfo) GetPendingPeers() []*metapb.Peer

GetPendingPeers returns the pending peers of the region.

func (*RegionInfo) GetPendingVoter

func (r *RegionInfo) GetPendingVoter(peerID uint64) *metapb.Peer

GetPendingVoter returns the pending voter with specified peer id.

func (*RegionInfo) GetReadQueryNum

func (r *RegionInfo) GetReadQueryNum() uint64

GetReadQueryNum returns read query num from this region

func (*RegionInfo) GetRegionEpoch

func (r *RegionInfo) GetRegionEpoch() *metapb.RegionEpoch

GetRegionEpoch returns the region epoch of the region.

func (*RegionInfo) GetReplicationStatus

func (r *RegionInfo) GetReplicationStatus() *replication_modepb.RegionReplicationStatus

GetReplicationStatus returns the region's replication status.

func (*RegionInfo) GetRoundBytesRead

func (r *RegionInfo) GetRoundBytesRead() uint64

GetRoundBytesRead returns the read bytes of the region.

func (*RegionInfo) GetRoundBytesWritten

func (r *RegionInfo) GetRoundBytesWritten() uint64

GetRoundBytesWritten returns the written bytes of the region.

func (*RegionInfo) GetStartKey

func (r *RegionInfo) GetStartKey() []byte

GetStartKey returns the start key of the region.

func (*RegionInfo) GetStat

func (r *RegionInfo) GetStat() *pdpb.RegionStat

GetStat returns the statistics of the region.

func (*RegionInfo) GetStoreIDs

func (r *RegionInfo) GetStoreIDs() map[uint64]struct{}

GetStoreIDs returns a map indicate the region distributed.

func (*RegionInfo) GetStoreLearner

func (r *RegionInfo) GetStoreLearner(storeID uint64) *metapb.Peer

GetStoreLearner returns the learner peer in specified store.

func (*RegionInfo) GetStorePeer

func (r *RegionInfo) GetStorePeer(storeID uint64) *metapb.Peer

GetStorePeer returns the peer in specified store.

func (*RegionInfo) GetStorePeerApproximateKeys

func (r *RegionInfo) GetStorePeerApproximateKeys(storeID uint64) int64

GetStorePeerApproximateKeys returns the approximate keys of the peer on the specified store.

func (*RegionInfo) GetStorePeerApproximateSize

func (r *RegionInfo) GetStorePeerApproximateSize(storeID uint64) int64

GetStorePeerApproximateSize returns the approximate size of the peer on the specified store.

func (*RegionInfo) GetStoreVoter

func (r *RegionInfo) GetStoreVoter(storeID uint64) *metapb.Peer

GetStoreVoter returns the voter in specified store.

func (*RegionInfo) GetStoreWitness

func (r *RegionInfo) GetStoreWitness(storeID uint64) *metapb.Peer

GetStoreWitness returns the witness peer in specified store.

func (*RegionInfo) GetTerm

func (r *RegionInfo) GetTerm() uint64

GetTerm returns the current term of the region

func (*RegionInfo) GetVoters

func (r *RegionInfo) GetVoters() []*metapb.Peer

GetVoters returns the voters.

func (*RegionInfo) GetWitnesses

func (r *RegionInfo) GetWitnesses() []*metapb.Peer

GetWitnesses returns the witnesses.

func (*RegionInfo) GetWriteLoads

func (r *RegionInfo) GetWriteLoads() []float64

GetWriteLoads returns write loads from region

func (*RegionInfo) GetWriteQueryNum

func (r *RegionInfo) GetWriteQueryNum() uint64

GetWriteQueryNum returns write query num from this region

func (*RegionInfo) GetWriteRate

func (r *RegionInfo) GetWriteRate() (bytesRate, keysRate float64)

GetWriteRate returns the write rate of the region.

func (*RegionInfo) Inherit

func (r *RegionInfo) Inherit(origin *RegionInfo, bucketEnable bool)

Inherit inherits the buckets and region size from the parent region if bucket enabled. correct approximate size and buckets by the previous size if here exists a reported RegionInfo. See https://github.com/tikv/tikv/issues/11114

func (*RegionInfo) IsFromHeartbeat

func (r *RegionInfo) IsFromHeartbeat() bool

IsFromHeartbeat returns whether the region info is from the region heartbeat.

func (*RegionInfo) IsOversized

func (r *RegionInfo) IsOversized(maxSize int64, maxKeys int64) bool

IsOversized indicates whether the region is oversized.

func (*RegionInfo) NeedMerge

func (r *RegionInfo) NeedMerge(mergeSize int64, mergeKeys int64) bool

NeedMerge returns true if size is less than merge size and keys is less than mergeKeys.

func (*RegionInfo) UpdateBuckets

func (r *RegionInfo) UpdateBuckets(buckets, old *metapb.Buckets) bool

UpdateBuckets sets the buckets of the region.

type RegionSetInformer

type RegionSetInformer interface {
	GetRegionCount() int
	RandFollowerRegions(storeID uint64, ranges []KeyRange) []*RegionInfo
	RandLeaderRegions(storeID uint64, ranges []KeyRange) []*RegionInfo
	RandLearnerRegions(storeID uint64, ranges []KeyRange) []*RegionInfo
	RandWitnessRegions(storeID uint64, ranges []KeyRange) []*RegionInfo
	RandPendingRegions(storeID uint64, ranges []KeyRange) []*RegionInfo
	GetAverageRegionSize() int64
	GetStoreRegionCount(storeID uint64) int
	GetRegion(id uint64) *RegionInfo
	GetAdjacentRegions(region *RegionInfo) (*RegionInfo, *RegionInfo)
	ScanRegions(startKey, endKey []byte, limit int) []*RegionInfo
	GetRegionByKey(regionKey []byte) *RegionInfo
}

RegionSetInformer provides access to a shared informer of regions.

type RegionsInfo

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

RegionsInfo for export

func NewRegionsInfo

func NewRegionsInfo() *RegionsInfo

NewRegionsInfo creates RegionsInfo with tree, regions, leaders and followers

func (*RegionsInfo) AtomicCheckAndPutRegion

func (r *RegionsInfo) AtomicCheckAndPutRegion(region *RegionInfo) ([]*RegionInfo, error)

AtomicCheckAndPutRegion checks if the region is valid to put, if valid then put.

func (*RegionsInfo) CheckAndPutRegion

func (r *RegionsInfo) CheckAndPutRegion(region *RegionInfo) []*RegionInfo

CheckAndPutRegion checks if the region is valid to put, if valid then put.

func (*RegionsInfo) GetAdjacentRegions

func (r *RegionsInfo) GetAdjacentRegions(region *RegionInfo) (*RegionInfo, *RegionInfo)

GetAdjacentRegions returns region's info that is adjacent with specific region

func (*RegionsInfo) GetAverageRegionSize

func (r *RegionsInfo) GetAverageRegionSize() int64

GetAverageRegionSize returns the average region approximate size.

func (*RegionsInfo) GetFollower

func (r *RegionsInfo) GetFollower(storeID uint64, region *RegionInfo) *RegionInfo

GetFollower returns follower RegionInfo by storeID and regionID (now only used in test)

func (*RegionsInfo) GetLeader

func (r *RegionsInfo) GetLeader(storeID uint64, region *RegionInfo) *RegionInfo

GetLeader returns leader RegionInfo by storeID and regionID (now only used in test)

func (*RegionsInfo) GetMetaRegions

func (r *RegionsInfo) GetMetaRegions() []*metapb.Region

GetMetaRegions gets a set of metapb.Region from regionMap

func (*RegionsInfo) GetOverlaps

func (r *RegionsInfo) GetOverlaps(region *RegionInfo) []*regionItem

GetOverlaps returns the regions which are overlapped with the specified region range.

func (*RegionsInfo) GetPrevRegionByKey

func (r *RegionsInfo) GetPrevRegionByKey(regionKey []byte) *RegionInfo

GetPrevRegionByKey searches previous RegionInfo from regionTree

func (*RegionsInfo) GetRangeCount

func (r *RegionsInfo) GetRangeCount(startKey, endKey []byte) int

GetRangeCount returns the number of regions that overlap with the range [startKey, endKey).

func (*RegionsInfo) GetRangeHoles

func (r *RegionsInfo) GetRangeHoles() [][]string

GetRangeHoles returns all range holes, i.e the key ranges without any region info.

func (*RegionsInfo) GetRegion

func (r *RegionsInfo) GetRegion(regionID uint64) *RegionInfo

GetRegion returns the RegionInfo with regionID

func (*RegionsInfo) GetRegionByKey

func (r *RegionsInfo) GetRegionByKey(regionKey []byte) *RegionInfo

GetRegionByKey searches RegionInfo from regionTree

func (*RegionsInfo) GetRegionCount

func (r *RegionsInfo) GetRegionCount() int

GetRegionCount gets the total count of RegionInfo of regionMap

func (*RegionsInfo) GetRegionSizeByRange

func (r *RegionsInfo) GetRegionSizeByRange(startKey, endKey []byte) int64

GetRegionSizeByRange scans regions intersecting [start key, end key), returns the total region size of this range.

func (*RegionsInfo) GetRegions

func (r *RegionsInfo) GetRegions() []*RegionInfo

GetRegions gets all RegionInfo from regionMap

func (*RegionsInfo) GetRelevantRegions

func (r *RegionsInfo) GetRelevantRegions(region *RegionInfo) (origin *RegionInfo, overlaps []*regionItem)

GetRelevantRegions returns the relevant regions for a given region.

func (*RegionsInfo) GetStoreFollowerCount

func (r *RegionsInfo) GetStoreFollowerCount(storeID uint64) int

GetStoreFollowerCount get the total count of a store's follower RegionInfo

func (*RegionsInfo) GetStoreFollowerRegionSize

func (r *RegionsInfo) GetStoreFollowerRegionSize(storeID uint64) int64

GetStoreFollowerRegionSize get total size of store's follower regions

func (*RegionsInfo) GetStoreLeaderCount

func (r *RegionsInfo) GetStoreLeaderCount(storeID uint64) int

GetStoreLeaderCount get the total count of a store's leader RegionInfo

func (*RegionsInfo) GetStoreLeaderRegionSize

func (r *RegionsInfo) GetStoreLeaderRegionSize(storeID uint64) int64

GetStoreLeaderRegionSize get total size of store's leader regions

func (*RegionsInfo) GetStoreLeaderWriteRate

func (r *RegionsInfo) GetStoreLeaderWriteRate(storeID uint64) (bytesRate, keysRate float64)

GetStoreLeaderWriteRate get total write rate of store's leaders

func (*RegionsInfo) GetStoreLearnerCount

func (r *RegionsInfo) GetStoreLearnerCount(storeID uint64) int

GetStoreLearnerCount get the total count of a store's learner RegionInfo

func (*RegionsInfo) GetStoreLearnerRegionSize

func (r *RegionsInfo) GetStoreLearnerRegionSize(storeID uint64) int64

GetStoreLearnerRegionSize get total size of store's learner regions

func (*RegionsInfo) GetStorePendingPeerCount

func (r *RegionsInfo) GetStorePendingPeerCount(storeID uint64) int

GetStorePendingPeerCount gets the total count of a store's region that includes pending peer

func (*RegionsInfo) GetStoreRegionCount

func (r *RegionsInfo) GetStoreRegionCount(storeID uint64) int

GetStoreRegionCount gets the total count of a store's leader, follower and learner RegionInfo by storeID

func (*RegionsInfo) GetStoreRegionSize

func (r *RegionsInfo) GetStoreRegionSize(storeID uint64) int64

GetStoreRegionSize get total size of store's regions

func (*RegionsInfo) GetStoreRegions

func (r *RegionsInfo) GetStoreRegions(storeID uint64) []*RegionInfo

GetStoreRegions gets all RegionInfo with a given storeID

func (*RegionsInfo) GetStoreStats

func (r *RegionsInfo) GetStoreStats(storeID uint64) (leader, region, witness, learner, pending int, leaderSize, regionSize int64)

GetStoreStats returns the store stats.

func (*RegionsInfo) GetStoreWitnessCount

func (r *RegionsInfo) GetStoreWitnessCount(storeID uint64) int

GetStoreWitnessCount get the total count of a store's witness RegionInfo

func (*RegionsInfo) GetStoreWriteRate

func (r *RegionsInfo) GetStoreWriteRate(storeID uint64) (bytesRate, keysRate float64)

GetStoreWriteRate get total write rate of store's regions

func (*RegionsInfo) PreCheckPutRegion

func (r *RegionsInfo) PreCheckPutRegion(region *RegionInfo) (*RegionInfo, []*regionItem, error)

PreCheckPutRegion checks if the region is valid to put.

func (*RegionsInfo) PutRegion

func (r *RegionsInfo) PutRegion(region *RegionInfo) []*RegionInfo

PutRegion put a region.

func (*RegionsInfo) RandFollowerRegion

func (r *RegionsInfo) RandFollowerRegion(storeID uint64, ranges []KeyRange) *RegionInfo

RandFollowerRegion randomly gets a store's follower region.

func (*RegionsInfo) RandFollowerRegions

func (r *RegionsInfo) RandFollowerRegions(storeID uint64, ranges []KeyRange) []*RegionInfo

RandFollowerRegions randomly gets a store's n follower regions.

func (*RegionsInfo) RandLeaderRegion

func (r *RegionsInfo) RandLeaderRegion(storeID uint64, ranges []KeyRange) *RegionInfo

RandLeaderRegion randomly gets a store's leader region.

func (*RegionsInfo) RandLeaderRegions

func (r *RegionsInfo) RandLeaderRegions(storeID uint64, ranges []KeyRange) []*RegionInfo

RandLeaderRegions randomly gets a store's n leader regions.

func (*RegionsInfo) RandLearnerRegion

func (r *RegionsInfo) RandLearnerRegion(storeID uint64, ranges []KeyRange) *RegionInfo

RandLearnerRegion randomly gets a store's learner region.

func (*RegionsInfo) RandLearnerRegions

func (r *RegionsInfo) RandLearnerRegions(storeID uint64, ranges []KeyRange) []*RegionInfo

RandLearnerRegions randomly gets a store's n learner regions.

func (*RegionsInfo) RandPendingRegion

func (r *RegionsInfo) RandPendingRegion(storeID uint64, ranges []KeyRange) *RegionInfo

RandPendingRegion randomly gets a store's region with a pending peer.

func (*RegionsInfo) RandPendingRegions

func (r *RegionsInfo) RandPendingRegions(storeID uint64, ranges []KeyRange) []*RegionInfo

RandPendingRegions randomly gets a store's n regions with a pending peer.

func (*RegionsInfo) RandWitnessRegion

func (r *RegionsInfo) RandWitnessRegion(storeID uint64, ranges []KeyRange) *RegionInfo

RandWitnessRegion randomly gets a store's witness region.

func (*RegionsInfo) RandWitnessRegions

func (r *RegionsInfo) RandWitnessRegions(storeID uint64, ranges []KeyRange) []*RegionInfo

RandWitnessRegions randomly gets a store's n witness regions.

func (*RegionsInfo) RemoveRegion

func (r *RegionsInfo) RemoveRegion(region *RegionInfo)

RemoveRegion removes RegionInfo from regionTree and regionMap

func (*RegionsInfo) RemoveRegionFromSubTree

func (r *RegionsInfo) RemoveRegionFromSubTree(region *RegionInfo)

RemoveRegionFromSubTree removes RegionInfo from regionSubTrees

func (*RegionsInfo) RemoveRegionIfExist

func (r *RegionsInfo) RemoveRegionIfExist(id uint64)

RemoveRegionIfExist removes RegionInfo from regionTree and regionMap if exists.

func (*RegionsInfo) ResetRegionCache

func (r *RegionsInfo) ResetRegionCache()

ResetRegionCache resets the regions info.

func (*RegionsInfo) ScanRange

func (r *RegionsInfo) ScanRange(startKey, endKey []byte, limit int) []*RegionInfo

ScanRange scans regions intersecting [start key, end key), returns at most `limit` regions. limit <= 0 means no limit.

func (*RegionsInfo) ScanRangeWithIterator

func (r *RegionsInfo) ScanRangeWithIterator(startKey []byte, iterator func(region *RegionInfo) bool)

ScanRangeWithIterator scans from the first region containing or behind start key, until iterator returns false.

func (*RegionsInfo) SetRegion

func (r *RegionsInfo) SetRegion(region *RegionInfo) (*RegionInfo, []*RegionInfo, bool)

SetRegion sets the RegionInfo to regionTree and regionMap and return the update info of subtree.

func (*RegionsInfo) TreeLen

func (r *RegionsInfo) TreeLen() int

TreeLen returns the RegionsInfo tree length(now only used in test)

func (*RegionsInfo) UpdateSubTree

func (r *RegionsInfo) UpdateSubTree(region, origin *RegionInfo, overlaps []*RegionInfo, rangeChanged bool)

UpdateSubTree updates the subtree.

type StoreCreateOption

type StoreCreateOption func(store *StoreInfo)

StoreCreateOption is used to create store.

func OfflineStore

func OfflineStore(physicallyDestroyed bool) StoreCreateOption

OfflineStore offline a store

func PauseLeaderTransfer

func PauseLeaderTransfer() StoreCreateOption

PauseLeaderTransfer prevents the store from been selected as source or target store of TransferLeader.

func ResetStoreLimit

func ResetStoreLimit(limitType storelimit.Type, ratePerSec ...float64) StoreCreateOption

ResetStoreLimit resets the store limit for a store.

func ResumeLeaderTransfer

func ResumeLeaderTransfer() StoreCreateOption

ResumeLeaderTransfer cleans a store's pause state. The store can be selected as source or target of TransferLeader again.

func SetLastAwakenTime

func SetLastAwakenTime(lastAwaken time.Time) StoreCreateOption

SetLastAwakenTime sets last awaken time for the store.

func SetLastHeartbeatTS

func SetLastHeartbeatTS(lastHeartbeatTS time.Time) StoreCreateOption

SetLastHeartbeatTS sets the time of last heartbeat for the store.

func SetLastPersistTime

func SetLastPersistTime(lastPersist time.Time) StoreCreateOption

SetLastPersistTime updates the time of last persistent.

func SetLeaderCount

func SetLeaderCount(leaderCount int) StoreCreateOption

SetLeaderCount sets the leader count for the store.

func SetLeaderSize

func SetLeaderSize(leaderSize int64) StoreCreateOption

SetLeaderSize sets the leader size for the store.

func SetLeaderWeight

func SetLeaderWeight(leaderWeight float64) StoreCreateOption

SetLeaderWeight sets the leader weight for the store.

func SetLearnerCount

func SetLearnerCount(learnerCount int) StoreCreateOption

SetLearnerCount sets the learner count for the store.

func SetMinResolvedTS

func SetMinResolvedTS(minResolvedTS uint64) StoreCreateOption

SetMinResolvedTS sets min resolved ts for the store.

func SetNewStoreStats

func SetNewStoreStats(stats *pdpb.StoreStats) StoreCreateOption

SetNewStoreStats sets the raw statistics information for the store.

func SetPendingPeerCount

func SetPendingPeerCount(pendingPeerCount int) StoreCreateOption

SetPendingPeerCount sets the pending peer count for the store.

func SetRegionCount

func SetRegionCount(regionCount int) StoreCreateOption

SetRegionCount sets the Region count for the store.

func SetRegionSize

func SetRegionSize(regionSize int64) StoreCreateOption

SetRegionSize sets the Region size for the store.

func SetRegionWeight

func SetRegionWeight(regionWeight float64) StoreCreateOption

SetRegionWeight sets the Region weight for the store.

func SetStoreAddress

func SetStoreAddress(address, statusAddress, peerAddress string) StoreCreateOption

SetStoreAddress sets the address for the store.

func SetStoreDeployPath

func SetStoreDeployPath(deployPath string) StoreCreateOption

SetStoreDeployPath sets the deploy path for the store.

func SetStoreLabels

func SetStoreLabels(labels []*metapb.StoreLabel) StoreCreateOption

SetStoreLabels sets the labels for the store.

func SetStoreLimit

func SetStoreLimit(limit storelimit.StoreLimit) StoreCreateOption

SetStoreLimit set the store for a store, it may switch the store limit mode.

func SetStoreStartTime

func SetStoreStartTime(startTS int64) StoreCreateOption

SetStoreStartTime sets the start timestamp for the store.

func SetStoreStats

func SetStoreStats(stats *pdpb.StoreStats) StoreCreateOption

SetStoreStats sets the statistics information for the store.

func SetStoreVersion

func SetStoreVersion(githash, version string) StoreCreateOption

SetStoreVersion sets the version for the store.

func SetWitnessCount

func SetWitnessCount(witnessCount int) StoreCreateOption

SetWitnessCount sets the witness count for the store.

func SlowStoreEvicted

func SlowStoreEvicted() StoreCreateOption

SlowStoreEvicted marks a store as a slow store and prevents transferring leader to the store

func SlowStoreRecovered

func SlowStoreRecovered() StoreCreateOption

SlowStoreRecovered cleans the evicted state of a store.

func SlowTrendEvicted

func SlowTrendEvicted() StoreCreateOption

SlowTrendEvicted marks a store as a slow store by trend and prevents transferring leader to the store

func SlowTrendRecovered

func SlowTrendRecovered() StoreCreateOption

SlowTrendRecovered cleans the evicted by slow trend state of a store.

func TombstoneStore

func TombstoneStore() StoreCreateOption

TombstoneStore set a store to tombstone.

func UpStore

func UpStore() StoreCreateOption

UpStore up a store

type StoreInfo

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

StoreInfo contains information about a store. NOTE: This type is exported by HTTP API. Please pay more attention when modifying it.

func NewStoreInfo

func NewStoreInfo(store *metapb.Store, opts ...StoreCreateOption) *StoreInfo

NewStoreInfo creates StoreInfo with meta data.

func NewStoreInfoWithLabel

func NewStoreInfoWithLabel(id uint64, labels map[string]string) *StoreInfo

NewStoreInfoWithLabel is create a store with specified labels. only for test purpose.

func (*StoreInfo) AllowLeaderTransfer

func (s *StoreInfo) AllowLeaderTransfer() bool

AllowLeaderTransfer returns if the store is allowed to be selected as source or target of transfer leader.

func (*StoreInfo) AvailableRatio

func (s *StoreInfo) AvailableRatio() float64

AvailableRatio is store's freeSpace/capacity.

func (*StoreInfo) Clone

func (s *StoreInfo) Clone(opts ...StoreCreateOption) *StoreInfo

Clone creates a copy of current StoreInfo.

func (StoreInfo) CloneStoreStats

func (ss StoreInfo) CloneStoreStats() *pdpb.StoreStats

CloneStoreStats returns the statistics information cloned from the store.

func (*StoreInfo) CompareLocation

func (s *StoreInfo) CompareLocation(other *StoreInfo, labels []string) int

CompareLocation compares 2 stores' labels and returns at which level their locations are different. It returns -1 if they are at the same location.

func (*StoreInfo) DownTime

func (s *StoreInfo) DownTime() time.Duration

DownTime returns the time elapsed since last heartbeat.

func (*StoreInfo) EvictedAsSlowStore

func (s *StoreInfo) EvictedAsSlowStore() bool

EvictedAsSlowStore returns if the store should be evicted as a slow store.

func (*StoreInfo) Feedback

func (s *StoreInfo) Feedback(e float64)

Feedback is used to update the store's limit.

func (*StoreInfo) GetAddress

func (s *StoreInfo) GetAddress() string

GetAddress returns the address of the store.

func (StoreInfo) GetAvailable

func (ss StoreInfo) GetAvailable() uint64

GetAvailable returns the available size of the store.

func (StoreInfo) GetAvgAvailable

func (ss StoreInfo) GetAvgAvailable() uint64

GetAvgAvailable returns available size after the spike changes has been smoothed.

func (StoreInfo) GetBytesRead

func (ss StoreInfo) GetBytesRead() uint64

GetBytesRead returns the bytes read for the store during this period.

func (StoreInfo) GetBytesWritten

func (ss StoreInfo) GetBytesWritten() uint64

GetBytesWritten returns the bytes written for the store during this period.

func (StoreInfo) GetCapacity

func (ss StoreInfo) GetCapacity() uint64

GetCapacity returns the capacity size of the store.

func (*StoreInfo) GetID

func (s *StoreInfo) GetID() uint64

GetID returns the ID of the store.

func (StoreInfo) GetKeysRead

func (ss StoreInfo) GetKeysRead() uint64

GetKeysRead returns the keys read for the store during this period.

func (StoreInfo) GetKeysWritten

func (ss StoreInfo) GetKeysWritten() uint64

GetKeysWritten returns the keys written for the store during this period.

func (*StoreInfo) GetLabelValue

func (s *StoreInfo) GetLabelValue(key string) string

GetLabelValue returns a label's value (if exists).

func (*StoreInfo) GetLabels

func (s *StoreInfo) GetLabels() []*metapb.StoreLabel

GetLabels returns the labels of the store.

func (*StoreInfo) GetLastHeartbeatTS

func (s *StoreInfo) GetLastHeartbeatTS() time.Time

GetLastHeartbeatTS returns the last heartbeat timestamp of the store.

func (*StoreInfo) GetLeaderCount

func (s *StoreInfo) GetLeaderCount() int

GetLeaderCount returns the leader count of the store.

func (*StoreInfo) GetLeaderSize

func (s *StoreInfo) GetLeaderSize() int64

GetLeaderSize returns the leader size of the store.

func (*StoreInfo) GetLeaderWeight

func (s *StoreInfo) GetLeaderWeight() float64

GetLeaderWeight returns the leader weight of the store.

func (*StoreInfo) GetLearnerCount

func (s *StoreInfo) GetLearnerCount() int

GetLearnerCount returns the learner count of the store.

func (*StoreInfo) GetMeta

func (s *StoreInfo) GetMeta() *metapb.Store

GetMeta returns the meta information of the store.

func (*StoreInfo) GetMinResolvedTS

func (s *StoreInfo) GetMinResolvedTS() uint64

GetMinResolvedTS returns min resolved ts.

func (*StoreInfo) GetNodeState

func (s *StoreInfo) GetNodeState() metapb.NodeState

GetNodeState returns the state of the node.

func (*StoreInfo) GetPendingPeerCount

func (s *StoreInfo) GetPendingPeerCount() int

GetPendingPeerCount returns the pending peer count of the store.

func (StoreInfo) GetReceivingSnapCount

func (ss StoreInfo) GetReceivingSnapCount() uint32

GetReceivingSnapCount returns the current receiving snapshot count of the store.

func (*StoreInfo) GetRegionCount

func (s *StoreInfo) GetRegionCount() int

GetRegionCount returns the Region count of the store.

func (*StoreInfo) GetRegionSize

func (s *StoreInfo) GetRegionSize() int64

GetRegionSize returns the Region size of the store.

func (*StoreInfo) GetRegionWeight

func (s *StoreInfo) GetRegionWeight() float64

GetRegionWeight returns the Region weight of the store.

func (StoreInfo) GetSendingSnapCount

func (ss StoreInfo) GetSendingSnapCount() uint32

GetSendingSnapCount returns the current sending snapshot count of the store.

func (*StoreInfo) GetSlowScore

func (s *StoreInfo) GetSlowScore() uint64

GetSlowScore returns the slow score of the store.

func (*StoreInfo) GetSlowTrend

func (s *StoreInfo) GetSlowTrend() *pdpb.SlowTrend

GetSlowTrend returns the slow trend information of the store.

func (*StoreInfo) GetStartTime

func (s *StoreInfo) GetStartTime() time.Time

GetStartTime returns the start timestamp.

func (*StoreInfo) GetState

func (s *StoreInfo) GetState() metapb.StoreState

GetState returns the state of the store.

func (*StoreInfo) GetStatusAddress

func (s *StoreInfo) GetStatusAddress() string

GetStatusAddress returns the http address of the store.

func (*StoreInfo) GetStoreLimit

func (s *StoreInfo) GetStoreLimit() storelimit.StoreLimit

GetStoreLimit return the limit of a specific store.

func (StoreInfo) GetStoreStats

func (ss StoreInfo) GetStoreStats() *pdpb.StoreStats

GetStoreStats returns the statistics information of the store.

func (*StoreInfo) GetUptime

func (s *StoreInfo) GetUptime() time.Duration

GetUptime returns the uptime.

func (StoreInfo) GetUsedSize

func (ss StoreInfo) GetUsedSize() uint64

GetUsedSize returns the used size of the store.

func (*StoreInfo) GetVersion

func (s *StoreInfo) GetVersion() string

GetVersion returns the version of the store.

func (*StoreInfo) GetWitnessCount

func (s *StoreInfo) GetWitnessCount() int

GetWitnessCount returns the witness count of the store.

func (*StoreInfo) IsAvailable

func (s *StoreInfo) IsAvailable(limitType storelimit.Type, level constant.PriorityLevel) bool

IsAvailable returns if the store bucket of limitation is available

func (StoreInfo) IsBusy

func (ss StoreInfo) IsBusy() bool

IsBusy returns if the store is busy.

func (*StoreInfo) IsDisconnected

func (s *StoreInfo) IsDisconnected() bool

IsDisconnected checks if a store is disconnected, which means PD misses tikv's store heartbeat for a short time, maybe caused by process restart or temporary network failure.

func (*StoreInfo) IsEvictedAsSlowTrend

func (s *StoreInfo) IsEvictedAsSlowTrend() bool

IsEvictedAsSlowTrend returns if the store should be evicted as a slow store by trend.

func (*StoreInfo) IsLowSpace

func (s *StoreInfo) IsLowSpace(lowSpaceRatio float64) bool

IsLowSpace checks if the store is lack of space. Not check if region count less than InitClusterRegionThreshold and available space more than initialMinSpace

func (*StoreInfo) IsPhysicallyDestroyed

func (s *StoreInfo) IsPhysicallyDestroyed() bool

IsPhysicallyDestroyed checks if the store's physically destroyed.

func (*StoreInfo) IsPreparing

func (s *StoreInfo) IsPreparing() bool

IsPreparing checks if the store's state is preparing.

func (*StoreInfo) IsRemoved

func (s *StoreInfo) IsRemoved() bool

IsRemoved checks if the store's state is removed.

func (*StoreInfo) IsRemoving

func (s *StoreInfo) IsRemoving() bool

IsRemoving checks if the store's state is removing.

func (*StoreInfo) IsServing

func (s *StoreInfo) IsServing() bool

IsServing checks if the store's state is serving.

func (*StoreInfo) IsSlow

func (s *StoreInfo) IsSlow() bool

IsSlow checks if the slow score reaches the threshold.

func (*StoreInfo) IsTiFlash

func (s *StoreInfo) IsTiFlash() bool

IsTiFlash returns true if the store is tiflash.

func (*StoreInfo) IsUnhealthy

func (s *StoreInfo) IsUnhealthy() bool

IsUnhealthy checks if a store is unhealthy.

func (*StoreInfo) IsUp

func (s *StoreInfo) IsUp() bool

IsUp returns true if store is serving or preparing.

func (*StoreInfo) LeaderScore

func (s *StoreInfo) LeaderScore(policy constant.SchedulePolicy, delta int64) float64

LeaderScore returns the store's leader score.

func (*StoreInfo) LimitVersion

func (s *StoreInfo) LimitVersion() string

LimitVersion returns the limit version of the store.

func (*StoreInfo) NeedAwakenStore

func (s *StoreInfo) NeedAwakenStore() bool

NeedAwakenStore checks whether all hibernated regions in this store should be awaken or not.

func (*StoreInfo) NeedPersist

func (s *StoreInfo) NeedPersist() bool

NeedPersist returns if it needs to save to etcd.

func (*StoreInfo) RegionScore

func (s *StoreInfo) RegionScore(version string, highSpaceRatio, lowSpaceRatio float64, delta int64) float64

RegionScore returns the store's region score. Deviation It is used to control the direction of the deviation considered when calculating the region score. It is set to -1 when it is the source store of balance, 1 when it is the target, and 0 in the rest of cases.

func (*StoreInfo) ResourceCount

func (s *StoreInfo) ResourceCount(kind constant.ResourceKind) uint64

ResourceCount returns count of leader/region in the store.

func (*StoreInfo) ResourceSize

func (s *StoreInfo) ResourceSize(kind constant.ResourceKind) int64

ResourceSize returns size of leader/region in the store

func (*StoreInfo) ResourceWeight

func (s *StoreInfo) ResourceWeight(kind constant.ResourceKind) float64

ResourceWeight returns weight of leader/region in the score

func (*StoreInfo) ShallowClone

func (s *StoreInfo) ShallowClone(opts ...StoreCreateOption) *StoreInfo

ShallowClone creates a copy of current StoreInfo, but not clone 'meta'.

func (*StoreInfo) StorageSize

func (s *StoreInfo) StorageSize() uint64

StorageSize returns store's used storage size reported from tikv.

func (*StoreInfo) WitnessScore

func (s *StoreInfo) WitnessScore(delta int64) float64

WitnessScore returns the store's witness score.

type StoreSetController

type StoreSetController interface {
	PauseLeaderTransfer(id uint64) error
	ResumeLeaderTransfer(id uint64)

	SlowStoreEvicted(id uint64) error
	SlowStoreRecovered(id uint64)
	SlowTrendEvicted(id uint64) error
	SlowTrendRecovered(id uint64)
}

StoreSetController is used to control stores' status.

type StoreSetInformer

type StoreSetInformer interface {
	GetStores() []*StoreInfo
	GetStore(id uint64) *StoreInfo

	GetRegionStores(region *RegionInfo) []*StoreInfo
	GetNonWitnessVoterStores(region *RegionInfo) []*StoreInfo
	GetFollowerStores(region *RegionInfo) []*StoreInfo
	GetLeaderStore(region *RegionInfo) *StoreInfo
}

StoreSetInformer provides access to a shared informer of stores.

type StoresInfo

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

StoresInfo contains information about all stores.

func NewStoresInfo

func NewStoresInfo() *StoresInfo

NewStoresInfo create a StoresInfo with map of storeID to StoreInfo

func (*StoresInfo) DeleteStore

func (s *StoresInfo) DeleteStore(store *StoreInfo)

DeleteStore deletes tombstone record form store

func (*StoresInfo) GetMetaStores

func (s *StoresInfo) GetMetaStores() []*metapb.Store

GetMetaStores gets a complete set of metapb.Store.

func (*StoresInfo) GetStore

func (s *StoresInfo) GetStore(storeID uint64) *StoreInfo

GetStore returns a copy of the StoreInfo with the specified storeID.

func (*StoresInfo) GetStoreCount

func (s *StoresInfo) GetStoreCount() int

GetStoreCount returns the total count of storeInfo.

func (*StoresInfo) GetStores

func (s *StoresInfo) GetStores() []*StoreInfo

GetStores gets a complete set of StoreInfo.

func (*StoresInfo) PauseLeaderTransfer

func (s *StoresInfo) PauseLeaderTransfer(storeID uint64) error

PauseLeaderTransfer pauses a StoreInfo with storeID.

func (*StoresInfo) ResetStoreLimit

func (s *StoresInfo) ResetStoreLimit(storeID uint64, limitType storelimit.Type, ratePerSec ...float64)

ResetStoreLimit resets the limit for a specific store.

func (*StoresInfo) ResumeLeaderTransfer

func (s *StoresInfo) ResumeLeaderTransfer(storeID uint64)

ResumeLeaderTransfer cleans a store's pause state. The store can be selected as source or target of TransferLeader again.

func (*StoresInfo) SetLeaderCount

func (s *StoresInfo) SetLeaderCount(storeID uint64, leaderCount int)

SetLeaderCount sets the leader count to a storeInfo.

func (*StoresInfo) SetLeaderSize

func (s *StoresInfo) SetLeaderSize(storeID uint64, leaderSize int64)

SetLeaderSize sets the leader size to a storeInfo.

func (*StoresInfo) SetPendingPeerCount

func (s *StoresInfo) SetPendingPeerCount(storeID uint64, pendingPeerCount int)

SetPendingPeerCount sets the pending count to a storeInfo.

func (*StoresInfo) SetRegionCount

func (s *StoresInfo) SetRegionCount(storeID uint64, regionCount int)

SetRegionCount sets the region count to a storeInfo.

func (*StoresInfo) SetRegionSize

func (s *StoresInfo) SetRegionSize(storeID uint64, regionSize int64)

SetRegionSize sets the region size to a storeInfo.

func (*StoresInfo) SetStore

func (s *StoresInfo) SetStore(store *StoreInfo)

SetStore sets a StoreInfo with storeID.

func (*StoresInfo) SlowStoreEvicted

func (s *StoresInfo) SlowStoreEvicted(storeID uint64) error

SlowStoreEvicted marks a store as a slow store and prevents transferring leader to the store

func (*StoresInfo) SlowStoreRecovered

func (s *StoresInfo) SlowStoreRecovered(storeID uint64)

SlowStoreRecovered cleans the evicted state of a store.

func (*StoresInfo) SlowTrendEvicted

func (s *StoresInfo) SlowTrendEvicted(storeID uint64) error

SlowTrendEvicted marks a store as a slow trend and prevents transferring leader to the store

func (*StoresInfo) SlowTrendRecovered

func (s *StoresInfo) SlowTrendRecovered(storeID uint64)

SlowTrendRecovered cleans the evicted by trend state of a store.

func (*StoresInfo) UpdateStoreStatus

func (s *StoresInfo) UpdateStoreStatus(storeID uint64, leaderCount, regionCount, witnessCount, learnerCount, pendingPeerCount int, leaderSize int64, regionSize int64)

UpdateStoreStatus updates the information of the store.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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