core

package
v2.1.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2019 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package core defines core characteristics of the server. This file uses the errcode packate to define PD specific error codes. Probably this should be a different package.

Index

Constants

View Source
const (
	// LeaderKind indicates the leader kind resource
	LeaderKind = iota
	// RegionKind indicates the region kind resource
	RegionKind
)
View Source
const EmptyRegionApproximateSize = 1

EmptyRegionApproximateSize is the region approximate size of an empty region (heartbeat size <= 1MB).

Variables

View Source
var (

	// StoreBlockedCode is an error due to requesting an operation that is invalid due to a store being in a blocked state
	StoreBlockedCode = storeStateCode.Child("state.store.blocked")

	// StoreTombstonedCode is an invalid operation was attempted on a store which is in a removed state.
	StoreTombstonedCode = storeStateCode.Child("state.store.tombstoned").SetHTTP(http.StatusGone)
)

Functions

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 MergeRegions

func MergeRegions(regions []*metapb.Region) []*metapb.Region

MergeRegions merge a set of metapb.Region by regionKey

func NewRegion

func NewRegion(start, end []byte) *metapb.Region

NewRegion create a metapb.Region

func NewStoreNotFoundErr

func NewStoreNotFoundErr(storeID uint64) errcode.ErrorCode

NewStoreNotFoundErr is for log of store not found

func SplitRegions

func SplitRegions(regions []*metapb.Region) []*metapb.Region

SplitRegions split a set of metapb.Region by the middle of regionKey

Types

type HotRegionsStat

type HotRegionsStat struct {
	TotalFlowBytes uint64      `json:"total_flow_bytes"`
	RegionsCount   int         `json:"regions_count"`
	RegionsStat    RegionsStat `json:"statistics"`
}

HotRegionsStat records all hot regions statistics

type IDAllocator

type IDAllocator interface {
	Alloc() (uint64, error)
}

IDAllocator is the allocator to generate unique ID.

type KV

type KV struct {
	KVBase
}

KV wraps all kv operations, keep it stateless.

func NewKV

func NewKV(base KVBase) *KV

NewKV creates KV instance with KVBase.

func (*KV) ClusterStatePath

func (kv *KV) ClusterStatePath(option string) string

ClusterStatePath returns the path to save an option.

func (*KV) DeleteRegion

func (kv *KV) DeleteRegion(region *metapb.Region) error

DeleteRegion deletes one region from KV.

func (*KV) LoadConfig

func (kv *KV) LoadConfig(cfg interface{}) (bool, error)

LoadConfig loads config from configPath then unmarshal it to cfg.

func (*KV) LoadGCSafePoint

func (kv *KV) LoadGCSafePoint() (uint64, error)

LoadGCSafePoint loads current GC safe point from KV.

func (*KV) LoadMeta

func (kv *KV) LoadMeta(meta *metapb.Cluster) (bool, error)

LoadMeta loads cluster meta from KV store.

func (*KV) LoadRegion

func (kv *KV) LoadRegion(regionID uint64, region *metapb.Region) (bool, error)

LoadRegion loads one regoin from KV.

func (*KV) LoadRegions

func (kv *KV) LoadRegions(regions *RegionsInfo) error

LoadRegions loads all regions from KV to RegionsInfo.

func (*KV) LoadStore

func (kv *KV) LoadStore(storeID uint64, store *metapb.Store) (bool, error)

LoadStore loads one store from KV.

func (*KV) LoadStores

func (kv *KV) LoadStores(stores *StoresInfo) error

LoadStores loads all stores from KV to StoresInfo.

func (*KV) SaveConfig

func (kv *KV) SaveConfig(cfg interface{}) error

SaveConfig stores marshalable cfg to the configPath.

func (*KV) SaveGCSafePoint

func (kv *KV) SaveGCSafePoint(safePoint uint64) error

SaveGCSafePoint saves new GC safe point to KV.

func (*KV) SaveMeta

func (kv *KV) SaveMeta(meta *metapb.Cluster) error

SaveMeta save cluster meta to KV store.

func (*KV) SaveRegion

func (kv *KV) SaveRegion(region *metapb.Region) error

SaveRegion saves one region to KV.

func (*KV) SaveStore

func (kv *KV) SaveStore(store *metapb.Store) error

SaveStore saves one store to KV.

func (*KV) SaveStoreWeight

func (kv *KV) SaveStoreWeight(storeID uint64, leader, region float64) error

SaveStoreWeight saves a store's leader and region weight to KV.

type KVBase

type KVBase interface {
	Load(key string) (string, error)
	LoadRange(key, endKey string, limit int) ([]string, error)
	Save(key, value string) error
	Delete(key string) error
}

KVBase is an abstract interface for load/save pd cluster data.

func NewMemoryKV

func NewMemoryKV() KVBase

NewMemoryKV returns an in-memory kvBase for testing.

type MockIDAllocator

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

MockIDAllocator mocks IDAllocator and it is only used for test.

func NewMockIDAllocator

func NewMockIDAllocator() *MockIDAllocator

NewMockIDAllocator create a new MockIDAllocator

func (*MockIDAllocator) Alloc

func (alloc *MockIDAllocator) Alloc() (uint64, error)

Alloc return a new id

type PriorityLevel

type PriorityLevel int

PriorityLevel lower level means higher priority

const (
	HighPriority PriorityLevel = iota
	NormalPriority
	LowPriority
)

Built-in priority level

type RegionCreateOption

type RegionCreateOption func(region *RegionInfo)

RegionCreateOption used to create region.

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 SetPeers

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

SetPeers sets the peers for the region.

func SetReadBytes

func SetReadBytes(v uint64) RegionCreateOption

SetReadBytes sets the read bytes for the region.

func SetRegionConfVer

func SetRegionConfVer(confVer uint64) RegionCreateOption

SetRegionConfVer sets the config version for the reigon.

func SetRegionVersion

func SetRegionVersion(version uint64) RegionCreateOption

SetRegionVersion sets the version for the reigon.

func SetWrittenBytes

func SetWrittenBytes(v uint64) RegionCreateOption

SetWrittenBytes sets the written bytes for the region.

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 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 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(pengdingPeers []*metapb.Peer) RegionCreateOption

WithPendingPeers sets the pending peers for the region.

func WithPromoteLearner

func WithPromoteLearner(peerID uint64) RegionCreateOption

WithPromoteLearner promotes the learner.

func WithRemoveStorePeer

func WithRemoveStorePeer(storeID uint64) RegionCreateOption

WithRemoveStorePeer removes the specified peer for the region.

func WithStartKey

func WithStartKey(key []byte) RegionCreateOption

WithStartKey sets the start key for the region.

type RegionInfo

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

RegionInfo records detail region info. Read-Only once created.

func NewRegionInfo

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

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

func RegionFromHeartbeat

func RegionFromHeartbeat(heartbeat *pdpb.RegionHeartbeatRequest) *RegionInfo

RegionFromHeartbeat constructs a Region from region heartbeat.

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) 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) 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) 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) GetMeta

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

GetMeta returns the meta information of the region.

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) GetRegionEpoch

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

GetRegionEpoch returns the region epoch of the region.

func (*RegionInfo) GetStartKey

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

GetStartKey returns the start key 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) GetStoreVoter

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

GetStoreVoter returns the voter in specified store.

func (*RegionInfo) GetVoters

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

GetVoters returns the voters.

type RegionOption

type RegionOption func(region *RegionInfo) bool

RegionOption is used to select region.

func HealthRegion

func HealthRegion() RegionOption

HealthRegion checks if the region is healthy.

type RegionStat

type RegionStat struct {
	RegionID  uint64 `json:"region_id"`
	FlowBytes uint64 `json:"flow_bytes"`
	// HotDegree records the hot region update times
	HotDegree int `json:"hot_degree"`
	// LastUpdateTime used to calculate average write
	LastUpdateTime time.Time `json:"last_update_time"`
	StoreID        uint64    `json:"-"`
	// AntiCount used to eliminate some noise when remove region in cache
	AntiCount int
	// Version used to check the region split times
	Version uint64
	// Stats is a rolling statistics, recording some recently added records.
	Stats *RollingStats
}

RegionStat records each hot region's statistics

func NewRegionStat

func NewRegionStat(region *RegionInfo, flowBytes uint64, antiCount int) *RegionStat

NewRegionStat returns a RegionStat.

type RegionStats

type RegionStats struct {
	Count            int              `json:"count"`
	EmptyCount       int              `json:"empty_count"`
	StorageSize      int64            `json:"storage_size"`
	StorageKeys      int64            `json:"storage_keys"`
	StoreLeaderCount map[uint64]int   `json:"store_leader_count"`
	StorePeerCount   map[uint64]int   `json:"store_peer_count"`
	StoreLeaderSize  map[uint64]int64 `json:"store_leader_size"`
	StoreLeaderKeys  map[uint64]int64 `json:"store_leader_keys"`
	StorePeerSize    map[uint64]int64 `json:"store_peer_size"`
	StorePeerKeys    map[uint64]int64 `json:"store_peer_keys"`
}

RegionStats records a list of regions' statistics and distribution status.

func (*RegionStats) Observe

func (s *RegionStats) Observe(r *RegionInfo)

Observe adds a region's statistics into RegionStats.

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) AddRegion

func (r *RegionsInfo) AddRegion(region *RegionInfo) []*metapb.Region

AddRegion adds RegionInfo to regionTree and regionMap, also update leaders and followers by region peers

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, regionID uint64) *RegionInfo

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

func (*RegionsInfo) GetLeader

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

GetLeader return 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) []*metapb.Region

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

func (*RegionsInfo) GetRegion

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

GetRegion returns the RegionInfo with regionID

func (*RegionsInfo) GetRegionCount

func (r *RegionsInfo) GetRegionCount() int

GetRegionCount gets the total count of RegionInfo of regionMap

func (*RegionsInfo) GetRegionStats

func (r *RegionsInfo) GetRegionStats(startKey, endKey []byte) *RegionStats

GetRegionStats scans regions that inside range [startKey, endKey) and sums up their statistics.

func (*RegionsInfo) GetRegions

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

GetRegions gets all RegionInfo from regionMap

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) 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 and follower 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) Length

func (r *RegionsInfo) Length() int

Length returns the RegionsInfo length

func (*RegionsInfo) RandFollowerRegion

func (r *RegionsInfo) RandFollowerRegion(storeID uint64, opts ...RegionOption) *RegionInfo

RandFollowerRegion get a store's follower region by random

func (*RegionsInfo) RandLeaderRegion

func (r *RegionsInfo) RandLeaderRegion(storeID uint64, opts ...RegionOption) *RegionInfo

RandLeaderRegion get a store's leader region by random

func (*RegionsInfo) RandRegion

func (r *RegionsInfo) RandRegion(opts ...RegionOption) *RegionInfo

RandRegion get a region by random

func (*RegionsInfo) RemoveRegion

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

RemoveRegion removes RegionInfo from regionTree and regionMap

func (*RegionsInfo) ScanRange

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

ScanRange scans region with start key, until number greater than limit.

func (*RegionsInfo) SearchPrevRegion

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

SearchPrevRegion searches previous RegionInfo from regionTree

func (*RegionsInfo) SearchRegion

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

SearchRegion searches RegionInfo from regionTree

func (*RegionsInfo) SetRegion

func (r *RegionsInfo) SetRegion(region *RegionInfo) []*metapb.Region

SetRegion sets the RegionInfo with regionID

func (*RegionsInfo) TreeLength

func (r *RegionsInfo) TreeLength() int

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

type RegionsStat

type RegionsStat []RegionStat

RegionsStat is a list of a group region state type

func (RegionsStat) Len

func (m RegionsStat) Len() int

func (RegionsStat) Less

func (m RegionsStat) Less(i, j int) bool

func (RegionsStat) Swap

func (m RegionsStat) Swap(i, j int)

type ResourceKind

type ResourceKind int

ResourceKind distinguishes different kinds of resources.

func (ResourceKind) String

func (k ResourceKind) String() string

type RollingStats

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

RollingStats provides rolling statistics with specified window size. There are window size records for calculating.

func NewRollingStats

func NewRollingStats(size int) *RollingStats

NewRollingStats returns a RollingStats.

func (*RollingStats) Add

func (r *RollingStats) Add(n float64)

Add adds an element.

func (*RollingStats) Median

func (r *RollingStats) Median() float64

Median returns the median of the records. it can be used to filter noise. References: https://en.wikipedia.org/wiki/Median_filter.

type RollingStoreStats

type RollingStoreStats struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RollingStoreStats are multiple sets of recent historical records with specified windows size.

func (*RollingStoreStats) GetBytesReadRate

func (r *RollingStoreStats) GetBytesReadRate() float64

GetBytesReadRate returns the bytes read rate.

func (*RollingStoreStats) GetBytesWriteRate

func (r *RollingStoreStats) GetBytesWriteRate() float64

GetBytesWriteRate returns the bytes write rate.

func (*RollingStoreStats) GetKeysReadRate

func (r *RollingStoreStats) GetKeysReadRate() float64

GetKeysReadRate returns the keys read rate.

func (*RollingStoreStats) GetKeysWriteRate

func (r *RollingStoreStats) GetKeysWriteRate() float64

GetKeysWriteRate returns the keys write rate.

func (*RollingStoreStats) Observe

func (r *RollingStoreStats) Observe(stats *pdpb.StoreStats)

Observe records current statistics.

type StoreBlockedErr

type StoreBlockedErr StoreErr

StoreBlockedErr has a Code() of StoreBlockedCode

func (StoreBlockedErr) Code

func (e StoreBlockedErr) Code() errcode.Code

Code returns StoreBlockedCode

func (StoreBlockedErr) Error

func (e StoreBlockedErr) Error() string

type StoreErr

type StoreErr struct {
	StoreID uint64 `json:"storeId"`
}

StoreErr can be newtyped or embedded in your own error

type StoreHotRegionInfos

type StoreHotRegionInfos struct {
	AsPeer   StoreHotRegionsStat `json:"as_peer"`
	AsLeader StoreHotRegionsStat `json:"as_leader"`
}

StoreHotRegionInfos : used to get human readable description for hot regions.

type StoreHotRegionsStat

type StoreHotRegionsStat map[uint64]*HotRegionsStat

StoreHotRegionsStat used to record the hot region statistics group by store

type StoreInfo

type StoreInfo struct {
	*metapb.Store
	Stats *pdpb.StoreStats

	LeaderCount       int
	RegionCount       int
	LeaderSize        int64
	RegionSize        int64
	PendingPeerCount  int
	LastHeartbeatTS   time.Time
	LeaderWeight      float64
	RegionWeight      float64
	RollingStoreStats *RollingStoreStats
	// contains filtered or unexported fields
}

StoreInfo contains information about a store.

func NewStoreInfo

func NewStoreInfo(store *metapb.Store) *StoreInfo

NewStoreInfo creates StoreInfo with meta data.

func (*StoreInfo) AvailableRatio

func (s *StoreInfo) AvailableRatio() float64

AvailableRatio is store's freeSpace/capacity.

func (*StoreInfo) Block

func (s *StoreInfo) Block()

Block stops balancer from selecting the store.

func (*StoreInfo) Clone

func (s *StoreInfo) Clone() *StoreInfo

Clone creates a copy of current StoreInfo.

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) GetLabelValue

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

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

func (*StoreInfo) GetStartTS

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

GetStartTS returns the start timestamp.

func (*StoreInfo) GetUptime

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

GetUptime returns the uptime.

func (*StoreInfo) IsBlocked

func (s *StoreInfo) IsBlocked() bool

IsBlocked returns if the store is blocked.

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) IsLowSpace

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

IsLowSpace checks if the store is lack of space.

func (*StoreInfo) IsOffline

func (s *StoreInfo) IsOffline() bool

IsOffline checks if the store's state is Offline.

func (*StoreInfo) IsTombstone

func (s *StoreInfo) IsTombstone() bool

IsTombstone checks if the store's state is Tombstone.

func (*StoreInfo) IsUnhealth

func (s *StoreInfo) IsUnhealth() bool

IsUnhealth checks if a store is unhealth.

func (*StoreInfo) IsUp

func (s *StoreInfo) IsUp() bool

IsUp checks if the store's state is Up.

func (*StoreInfo) LeaderScore

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

LeaderScore returns the store's leader score: leaderSize / leaderWeight.

func (*StoreInfo) MergeLabels

func (s *StoreInfo) MergeLabels(labels []*metapb.StoreLabel)

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

func (*StoreInfo) RegionScore

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

RegionScore returns the store's region score.

func (*StoreInfo) ResourceCount

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

ResourceCount reutrns count of leader/region in the store.

func (*StoreInfo) ResourceScore

func (s *StoreInfo) ResourceScore(kind ResourceKind, highSpaceRatio, lowSpaceRatio float64, delta int64) float64

ResourceScore reutrns score of leader/region in the store.

func (*StoreInfo) ResourceSize

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

ResourceSize returns size of leader/region in the store

func (*StoreInfo) ResourceWeight

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

ResourceWeight returns weight of leader/region in the score

func (*StoreInfo) StorageSize

func (s *StoreInfo) StorageSize() uint64

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

func (*StoreInfo) Unblock

func (s *StoreInfo) Unblock()

Unblock allows balancer to select the store.

type StoreTombstonedErr

type StoreTombstonedErr StoreErr

StoreTombstonedErr is an invalid operation was attempted on a store which is in a removed state.

func (StoreTombstonedErr) Code

func (e StoreTombstonedErr) Code() errcode.Code

Code returns StoreTombstonedCode

func (StoreTombstonedErr) Error

func (e StoreTombstonedErr) Error() string

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) BlockStore

func (s *StoresInfo) BlockStore(storeID uint64) errcode.ErrorCode

BlockStore block a StoreInfo with storeID

func (*StoresInfo) GetMetaStores

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

GetMetaStores get 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 return the total count of storeInfo

func (*StoresInfo) GetStores

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

GetStores get a complete set of StoreInfo

func (*StoresInfo) GetStoresBytesReadStat

func (s *StoresInfo) GetStoresBytesReadStat() map[uint64]uint64

GetStoresBytesReadStat returns the bytes read stat of all StoreInfo.

func (*StoresInfo) GetStoresBytesWriteStat

func (s *StoresInfo) GetStoresBytesWriteStat() map[uint64]uint64

GetStoresBytesWriteStat returns the bytes write stat of all StoreInfo.

func (*StoresInfo) GetStoresKeysReadStat

func (s *StoresInfo) GetStoresKeysReadStat() map[uint64]uint64

GetStoresKeysReadStat returns the bytes read stat of all StoreInfo.

func (*StoresInfo) GetStoresKeysWriteStat

func (s *StoresInfo) GetStoresKeysWriteStat() map[uint64]uint64

GetStoresKeysWriteStat returns the keys write stat of all StoreInfo.

func (*StoresInfo) SetLeaderCount

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

SetLeaderCount set the leader count to a storeInfo

func (*StoresInfo) SetLeaderSize

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

SetLeaderSize set the leader count 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 set the region count to a storeInfo

func (*StoresInfo) SetRegionSize

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

SetRegionSize set the region count to a storeInfo

func (*StoresInfo) SetStore

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

SetStore sets a StoreInfo with storeID.

func (*StoresInfo) TakeStore

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

TakeStore returns the point of the origin StoreInfo with the specified storeID.

func (*StoresInfo) TotalBytesReadRate

func (s *StoresInfo) TotalBytesReadRate() float64

TotalBytesReadRate returns the total read bytes rate of all StoreInfo.

func (*StoresInfo) TotalBytesWriteRate

func (s *StoresInfo) TotalBytesWriteRate() float64

TotalBytesWriteRate returns the total written bytes rate of all StoreInfo.

func (*StoresInfo) UnblockStore

func (s *StoresInfo) UnblockStore(storeID uint64)

UnblockStore unblock a StoreInfo with storeID

Jump to

Keyboard shortcuts

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