Documentation ¶
Index ¶
- Variables
- func DiffRegionKeyInfo(origin *RegionInfo, other *RegionInfo) string
- func DiffRegionPeersInfo(origin *RegionInfo, other *RegionInfo) string
- func MergeRegions(regions []*metapb.Region) []*metapb.Region
- func NewRegion(start, end []byte) *metapb.Region
- func SplitRegions(regions []*metapb.Region) []*metapb.Region
- type HotRegionsStat
- type IDAllocator
- type KV
- func (kv *KV) ClusterStatePath(option string) string
- func (kv *KV) LoadConfig(cfg interface{}) (bool, error)
- func (kv *KV) LoadMeta(meta *metapb.Cluster) (bool, error)
- func (kv *KV) LoadRegion(regionID uint64, region *metapb.Region) (bool, error)
- func (kv *KV) LoadRegions(regions *RegionsInfo, rangeLimit int) error
- func (kv *KV) LoadStore(storeID uint64, store *metapb.Store) (bool, error)
- func (kv *KV) LoadStores(stores *StoresInfo, rangeLimit int) error
- func (kv *KV) SaveConfig(cfg interface{}) error
- func (kv *KV) SaveMeta(meta *metapb.Cluster) error
- func (kv *KV) SaveRegion(region *metapb.Region) error
- func (kv *KV) SaveStore(store *metapb.Store) error
- func (kv *KV) SaveStoreWeight(storeID uint64, leader, region float64) error
- type KVBase
- type RegionInfo
- func (r *RegionInfo) Clone() *RegionInfo
- func (r *RegionInfo) GetDownPeer(peerID uint64) *metapb.Peer
- func (r *RegionInfo) GetFollower() *metapb.Peer
- func (r *RegionInfo) GetFollowers() map[uint64]*metapb.Peer
- func (r *RegionInfo) GetPeer(peerID uint64) *metapb.Peer
- func (r *RegionInfo) GetPendingPeer(peerID uint64) *metapb.Peer
- func (r *RegionInfo) GetStoreIds() map[uint64]struct{}
- func (r *RegionInfo) GetStorePeer(storeID uint64) *metapb.Peer
- func (r *RegionInfo) RemoveStorePeer(storeID uint64)
- type RegionStat
- type RegionsInfo
- func (r *RegionsInfo) AddRegion(region *RegionInfo)
- func (r *RegionsInfo) GetFollower(storeID uint64, regionID uint64) *RegionInfo
- func (r *RegionsInfo) GetLeader(storeID uint64, regionID uint64) *RegionInfo
- func (r *RegionsInfo) GetMetaRegions() []*metapb.Region
- func (r *RegionsInfo) GetRegion(regionID uint64) *RegionInfo
- func (r *RegionsInfo) GetRegionCount() int
- func (r *RegionsInfo) GetRegions() []*RegionInfo
- func (r *RegionsInfo) GetStoreFollowerCount(storeID uint64) int
- func (r *RegionsInfo) GetStoreLeaderCount(storeID uint64) int
- func (r *RegionsInfo) GetStoreRegionCount(storeID uint64) int
- func (r *RegionsInfo) Length() int
- func (r *RegionsInfo) RandFollowerRegion(storeID uint64) *RegionInfo
- func (r *RegionsInfo) RandLeaderRegion(storeID uint64) *RegionInfo
- func (r *RegionsInfo) RandRegion() *RegionInfo
- func (r *RegionsInfo) RemoveRegion(region *RegionInfo)
- func (r *RegionsInfo) SearchRegion(regionKey []byte) *RegionInfo
- func (r *RegionsInfo) SetRegion(region *RegionInfo)
- func (r *RegionsInfo) TreeLength() int
- type RegionsStat
- type ResourceKind
- type StoreHotRegionInfos
- type StoreHotRegionsStat
- type StoreInfo
- func (s *StoreInfo) AvailableRatio() float64
- func (s *StoreInfo) Block()
- func (s *StoreInfo) Clone() *StoreInfo
- func (s *StoreInfo) CompareLocation(other *StoreInfo, labels []string) int
- func (s *StoreInfo) DownTime() time.Duration
- func (s *StoreInfo) GetLabelValue(key string) string
- func (s *StoreInfo) GetStartTS() time.Time
- func (s *StoreInfo) GetUptime() time.Duration
- func (s *StoreInfo) IsBlocked() bool
- func (s *StoreInfo) IsDisconnected() bool
- func (s *StoreInfo) IsLowSpace() bool
- func (s *StoreInfo) IsOffline() bool
- func (s *StoreInfo) IsTombstone() bool
- func (s *StoreInfo) IsUp() bool
- func (s *StoreInfo) LeaderScore() float64
- func (s *StoreInfo) MergeLabels(labels []*metapb.StoreLabel)
- func (s *StoreInfo) RegionScore() float64
- func (s *StoreInfo) ResourceCount(kind ResourceKind) uint64
- func (s *StoreInfo) ResourceScore(kind ResourceKind) float64
- func (s *StoreInfo) StorageSize() uint64
- func (s *StoreInfo) Unblock()
- type StoresInfo
- func (s *StoresInfo) BlockStore(storeID uint64) error
- func (s *StoresInfo) GetMetaStores() []*metapb.Store
- func (s *StoresInfo) GetStore(storeID uint64) *StoreInfo
- func (s *StoresInfo) GetStoreCount() int
- func (s *StoresInfo) GetStores() []*StoreInfo
- func (s *StoresInfo) GetStoresReadStat() map[uint64]uint64
- func (s *StoresInfo) GetStoresWriteStat() map[uint64]uint64
- func (s *StoresInfo) SetLeaderCount(storeID uint64, leaderCount int)
- func (s *StoresInfo) SetRegionCount(storeID uint64, regionCount int)
- func (s *StoresInfo) SetStore(store *StoreInfo)
- func (s *StoresInfo) TotalReadBytes() uint64
- func (s *StoresInfo) TotalWrittenBytes() uint64
- func (s *StoresInfo) UnblockStore(storeID uint64)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrStoreNotFound is for log of store no found ErrStoreNotFound = func(storeID uint64) error { return errors.Errorf("store %v not found", storeID) } // ErrStoreIsBlocked is for log of store is blocked ErrStoreIsBlocked = func(storeID uint64) error { return errors.Errorf("store %v is blocked", storeID) } )
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 ¶
MergeRegions merge a set of metapb.Region by 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 ¶
IDAllocator is the allocator to generate unique ID.
type KV ¶
type KV struct {
KVBase
}
KV wraps all kv operations, keep it stateless.
func (*KV) ClusterStatePath ¶
ClusterStatePath returns the path to save an option.
func (*KV) LoadConfig ¶
LoadConfig loads config from configPath then unmarshal it to cfg.
func (*KV) LoadRegion ¶
LoadRegion loads one regoin from KV.
func (*KV) LoadRegions ¶
func (kv *KV) LoadRegions(regions *RegionsInfo, rangeLimit int) error
LoadRegions loads all regions from KV to RegionsInfo.
func (*KV) LoadStores ¶
func (kv *KV) LoadStores(stores *StoresInfo, rangeLimit int) error
LoadStores loads all stores from KV to StoresInfo.
func (*KV) SaveConfig ¶
SaveConfig stores marshalable cfg to the configPath.
func (*KV) SaveRegion ¶
SaveRegion saves one region 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 }
KVBase is an abstract interface for load/save pd cluster data.
type RegionInfo ¶
type RegionInfo struct { *metapb.Region Leader *metapb.Peer DownPeers []*pdpb.PeerStats PendingPeers []*metapb.Peer WrittenBytes uint64 ReadBytes uint64 }
RegionInfo records detail region info.
func NewRegionInfo ¶
func NewRegionInfo(region *metapb.Region, leader *metapb.Peer) *RegionInfo
NewRegionInfo creates RegionInfo with region's meta and leader peer.
func (*RegionInfo) Clone ¶
func (r *RegionInfo) Clone() *RegionInfo
Clone returns a copy of current regionInfo.
func (*RegionInfo) GetDownPeer ¶
func (r *RegionInfo) GetDownPeer(peerID uint64) *metapb.Peer
GetDownPeer returns the down peers with specified peer id.
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) GetPeer ¶
func (r *RegionInfo) GetPeer(peerID uint64) *metapb.Peer
GetPeer returns the 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) GetStoreIds ¶
func (r *RegionInfo) GetStoreIds() map[uint64]struct{}
GetStoreIds returns a map indicate the region distributed.
func (*RegionInfo) GetStorePeer ¶
func (r *RegionInfo) GetStorePeer(storeID uint64) *metapb.Peer
GetStorePeer returns the peer in specified store.
func (*RegionInfo) RemoveStorePeer ¶
func (r *RegionInfo) RemoveStorePeer(storeID uint64)
RemoveStorePeer removes the peer in specified store.
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 }
RegionStat records each hot region's statistics
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)
AddRegion add RegionInfo to regionTree and regionMap, also update leadres and followers by region peers
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 get a set of metapb.Region from regionMap
func (*RegionsInfo) GetRegion ¶
func (r *RegionsInfo) GetRegion(regionID uint64) *RegionInfo
GetRegion return the RegionInfo with regionID
func (*RegionsInfo) GetRegionCount ¶
func (r *RegionsInfo) GetRegionCount() int
GetRegionCount get the total count of RegionInfo of regionMap
func (*RegionsInfo) GetRegions ¶
func (r *RegionsInfo) GetRegions() []*RegionInfo
GetRegions get a set of 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) GetStoreLeaderCount ¶
func (r *RegionsInfo) GetStoreLeaderCount(storeID uint64) int
GetStoreLeaderCount get the total count of a store's leader RegionInfo
func (*RegionsInfo) GetStoreRegionCount ¶
func (r *RegionsInfo) GetStoreRegionCount(storeID uint64) int
GetStoreRegionCount get the total count of a store's leader and follower RegionInfo by storeID
func (*RegionsInfo) Length ¶
func (r *RegionsInfo) Length() int
Length return the RegionsInfo length
func (*RegionsInfo) RandFollowerRegion ¶
func (r *RegionsInfo) RandFollowerRegion(storeID uint64) *RegionInfo
RandFollowerRegion get a store's follower region by random
func (*RegionsInfo) RandLeaderRegion ¶
func (r *RegionsInfo) RandLeaderRegion(storeID uint64) *RegionInfo
RandLeaderRegion get a store's leader region by random
func (*RegionsInfo) RandRegion ¶
func (r *RegionsInfo) RandRegion() *RegionInfo
RandRegion get a region by random
func (*RegionsInfo) RemoveRegion ¶
func (r *RegionsInfo) RemoveRegion(region *RegionInfo)
RemoveRegion remove RegionInfo from regionTree and regionMap
func (*RegionsInfo) SearchRegion ¶
func (r *RegionsInfo) SearchRegion(regionKey []byte) *RegionInfo
SearchRegion search RegionInfo from regionTree
func (*RegionsInfo) SetRegion ¶
func (r *RegionsInfo) SetRegion(region *RegionInfo)
SetRegion set the RegionInfo with regionID
func (*RegionsInfo) TreeLength ¶
func (r *RegionsInfo) TreeLength() int
TreeLength return 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.
const ( // UnKnownKind indicates the unknown kind resource UnKnownKind ResourceKind = iota // AdminKind indicates that specify by admin AdminKind // LeaderKind indicates the leader kind resource LeaderKind // RegionKind indicates the region kind resource RegionKind // PriorityKind indicates the priority kind resource PriorityKind // OtherKind indicates the other kind resource OtherKind )
func ParseResourceKind ¶
func ParseResourceKind(name string) ResourceKind
ParseResourceKind convert string to ResourceKind
func (ResourceKind) String ¶
func (k ResourceKind) String() string
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 LastHeartbeatTS time.Time LeaderWeight float64 RegionWeight float64 // contains filtered or unexported fields }
StoreInfo contains information about a store.
func NewStoreInfo ¶
NewStoreInfo creates StoreInfo with meta data.
func (*StoreInfo) AvailableRatio ¶
AvailableRatio is store's freeSpace/capacity.
func (*StoreInfo) Block ¶
func (s *StoreInfo) Block()
Block stops balancer from selecting the store.
func (*StoreInfo) CompareLocation ¶
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) GetLabelValue ¶
GetLabelValue returns a label's value (if exists).
func (*StoreInfo) GetStartTS ¶
GetStartTS returns the start timestamp.
func (*StoreInfo) IsDisconnected ¶
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 ¶
IsLowSpace checks if the store is lack of space.
func (*StoreInfo) IsTombstone ¶
IsTombstone checks if the store's state is Tombstone.
func (*StoreInfo) LeaderScore ¶
LeaderScore returns the store's leader score: leaderCount / 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 ¶
RegionScore returns the store's region score: regionCount / regionWeight.
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) float64
ResourceScore reutrns score of leader/region in the store.
func (*StoreInfo) StorageSize ¶
StorageSize returns store's used storage size reported from tikv.
type StoresInfo ¶
type StoresInfo struct {
// contains filtered or unexported fields
}
StoresInfo is a map of storeID to StoreInfo
func NewStoresInfo ¶
func NewStoresInfo() *StoresInfo
NewStoresInfo create a StoresInfo with map of storeID to StoreInfo
func (*StoresInfo) BlockStore ¶
func (s *StoresInfo) BlockStore(storeID uint64) error
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 return a StoreInfo with 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) GetStoresReadStat ¶
func (s *StoresInfo) GetStoresReadStat() map[uint64]uint64
GetStoresReadStat return the read stat of all StoreInfo
func (*StoresInfo) GetStoresWriteStat ¶
func (s *StoresInfo) GetStoresWriteStat() map[uint64]uint64
GetStoresWriteStat return the 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) SetRegionCount ¶
func (s *StoresInfo) SetRegionCount(storeID uint64, regionCount int)
SetRegionCount set the region count to a storeInfo
func (*StoresInfo) SetStore ¶
func (s *StoresInfo) SetStore(store *StoreInfo)
SetStore set a StoreInfo with storeID
func (*StoresInfo) TotalReadBytes ¶
func (s *StoresInfo) TotalReadBytes() uint64
TotalReadBytes return the total read bytes of all StoreInfo
func (*StoresInfo) TotalWrittenBytes ¶
func (s *StoresInfo) TotalWrittenBytes() uint64
TotalWrittenBytes return the total written bytes of all StoreInfo
func (*StoresInfo) UnblockStore ¶
func (s *StoresInfo) UnblockStore(storeID uint64)
UnblockStore unblock a StoreInfo with storeID