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
- Variables
- func DiffRegionKeyInfo(origin *RegionInfo, other *RegionInfo) string
- func DiffRegionPeersInfo(origin *RegionInfo, other *RegionInfo) string
- func DistinctScore(labels []string, stores []*StoreInfo, other *StoreInfo) float64
- func EncodeToString(src []byte) []byte
- func HexRegionKey(key []byte) []byte
- func HexRegionKeyStr(key []byte) string
- func NewStoreNotFoundErr(storeID uint64) errcode.ErrorCode
- func String(b []byte) (s string)
- func ToUpperASCIIInplace(s []byte) []byte
- type BasicCluster
- func (bc *BasicCluster) AttachAvailableFunc(storeID uint64, f func() bool)
- func (bc *BasicCluster) BlockStore(storeID uint64) error
- func (bc *BasicCluster) CheckAndPutRegion(region *RegionInfo) []*RegionInfo
- func (bc *BasicCluster) DeleteStore(store *StoreInfo)
- func (bc *BasicCluster) GetAdjacentRegions(region *RegionInfo) (*RegionInfo, *RegionInfo)
- func (bc *BasicCluster) GetAverageRegionSize() int64
- func (bc *BasicCluster) GetFollowerStores(region *RegionInfo) []*StoreInfo
- func (bc *BasicCluster) GetLeaderStore(region *RegionInfo) *StoreInfo
- func (bc *BasicCluster) GetMetaRegions() []*metapb.Region
- func (bc *BasicCluster) GetMetaStores() []*metapb.Store
- func (bc *BasicCluster) GetOverlaps(region *RegionInfo) []*RegionInfo
- func (bc *BasicCluster) GetRegion(regionID uint64) *RegionInfo
- func (bc *BasicCluster) GetRegionCount() int
- func (bc *BasicCluster) GetRegionStores(region *RegionInfo) []*StoreInfo
- func (bc *BasicCluster) GetRegions() []*RegionInfo
- func (bc *BasicCluster) GetStore(storeID uint64) *StoreInfo
- func (bc *BasicCluster) GetStoreCount() int
- func (bc *BasicCluster) GetStoreFollowerCount(storeID uint64) int
- func (bc *BasicCluster) GetStoreLeaderCount(storeID uint64) int
- func (bc *BasicCluster) GetStoreLeaderRegionSize(storeID uint64) int64
- func (bc *BasicCluster) GetStorePendingPeerCount(storeID uint64) int
- func (bc *BasicCluster) GetStoreRegionCount(storeID uint64) int
- func (bc *BasicCluster) GetStoreRegionSize(storeID uint64) int64
- func (bc *BasicCluster) GetStoreRegions(storeID uint64) []*RegionInfo
- func (bc *BasicCluster) GetStores() []*StoreInfo
- func (bc *BasicCluster) Length() int
- func (bc *BasicCluster) PreCheckPutRegion(region *RegionInfo) (*RegionInfo, error)
- func (bc *BasicCluster) PutRegion(region *RegionInfo) []*RegionInfo
- func (bc *BasicCluster) PutStore(store *StoreInfo)
- func (bc *BasicCluster) RandFollowerRegion(storeID uint64, ranges []KeyRange, opts ...RegionOption) *RegionInfo
- func (bc *BasicCluster) RandLeaderRegion(storeID uint64, ranges []KeyRange, opts ...RegionOption) *RegionInfo
- func (bc *BasicCluster) RandLearnerRegion(storeID uint64, ranges []KeyRange, opts ...RegionOption) *RegionInfo
- func (bc *BasicCluster) RandPendingRegion(storeID uint64, ranges []KeyRange, opts ...RegionOption) *RegionInfo
- func (bc *BasicCluster) RemoveRegion(region *RegionInfo)
- func (bc *BasicCluster) ScanRange(startKey, endKey []byte, limit int) []*RegionInfo
- func (bc *BasicCluster) SearchPrevRegion(regionKey []byte) *RegionInfo
- func (bc *BasicCluster) SearchRegion(regionKey []byte) *RegionInfo
- func (bc *BasicCluster) TakeStore(storeID uint64) *StoreInfo
- func (bc *BasicCluster) UnblockStore(storeID uint64)
- func (bc *BasicCluster) UpdateStoreStatus(storeID uint64, leaderCount int, regionCount int, pendingPeerCount int, ...)
- type HexRegionMeta
- type HexRegionsMeta
- type KeyRange
- type KeyType
- type PriorityLevel
- type RegionCreateOption
- func SetApproximateKeys(v int64) RegionCreateOption
- func SetApproximateSize(v int64) RegionCreateOption
- func SetPeers(peers []*metapb.Peer) RegionCreateOption
- func SetReadBytes(v uint64) RegionCreateOption
- func SetReadKeys(v uint64) RegionCreateOption
- func SetRegionConfVer(confVer uint64) RegionCreateOption
- func SetRegionVersion(version uint64) RegionCreateOption
- func SetReportInterval(v uint64) RegionCreateOption
- func SetWrittenBytes(v uint64) RegionCreateOption
- func SetWrittenKeys(v uint64) RegionCreateOption
- func WithAddPeer(peer *metapb.Peer) RegionCreateOption
- func WithDecConfVer() RegionCreateOption
- func WithDecVersion() RegionCreateOption
- func WithDownPeers(downPeers []*pdpb.PeerStats) RegionCreateOption
- func WithEndKey(key []byte) RegionCreateOption
- func WithIncConfVer() RegionCreateOption
- func WithIncVersion() RegionCreateOption
- func WithLeader(leader *metapb.Peer) RegionCreateOption
- func WithLearners(learners []*metapb.Peer) RegionCreateOption
- func WithNewPeerIds(peerIds ...uint64) RegionCreateOption
- func WithNewRegionID(id uint64) RegionCreateOption
- func WithPendingPeers(pengdingPeers []*metapb.Peer) RegionCreateOption
- func WithPromoteLearner(peerID uint64) RegionCreateOption
- func WithRemoveStorePeer(storeID uint64) RegionCreateOption
- func WithReplacePeerStore(oldStoreID, newStoreID uint64) RegionCreateOption
- func WithStartKey(key []byte) RegionCreateOption
- type RegionInfo
- func MergeRegions(regions []*RegionInfo) []*RegionInfo
- func NewRegionInfo(region *metapb.Region, leader *metapb.Peer, opts ...RegionCreateOption) *RegionInfo
- func NewTestRegionInfo(start, end []byte) *RegionInfo
- func RegionFromHeartbeat(heartbeat *pdpb.RegionHeartbeatRequest) *RegionInfo
- func SplitRegions(regions []*RegionInfo) []*RegionInfo
- func (r *RegionInfo) Clone(opts ...RegionCreateOption) *RegionInfo
- func (r *RegionInfo) GetApproximateKeys() int64
- func (r *RegionInfo) GetApproximateSize() int64
- func (r *RegionInfo) GetBytesRead() uint64
- func (r *RegionInfo) GetBytesWritten() uint64
- func (r *RegionInfo) GetDiffFollowers(other *RegionInfo) []*metapb.Peer
- func (r *RegionInfo) GetDownLearner(peerID uint64) *metapb.Peer
- func (r *RegionInfo) GetDownPeer(peerID uint64) *metapb.Peer
- func (r *RegionInfo) GetDownPeers() []*pdpb.PeerStats
- func (r *RegionInfo) GetDownVoter(peerID uint64) *metapb.Peer
- func (r *RegionInfo) GetEndKey() []byte
- func (r *RegionInfo) GetFollower() *metapb.Peer
- func (r *RegionInfo) GetFollowers() map[uint64]*metapb.Peer
- func (r *RegionInfo) GetID() uint64
- func (r *RegionInfo) GetInterval() *pdpb.TimeInterval
- func (r *RegionInfo) GetKeysRead() uint64
- func (r *RegionInfo) GetKeysWritten() uint64
- func (r *RegionInfo) GetLeader() *metapb.Peer
- func (r *RegionInfo) GetLearners() []*metapb.Peer
- func (r *RegionInfo) GetMeta() *metapb.Region
- func (r *RegionInfo) GetPeer(peerID uint64) *metapb.Peer
- func (r *RegionInfo) GetPeers() []*metapb.Peer
- func (r *RegionInfo) GetPendingLearner(peerID uint64) *metapb.Peer
- func (r *RegionInfo) GetPendingPeer(peerID uint64) *metapb.Peer
- func (r *RegionInfo) GetPendingPeers() []*metapb.Peer
- func (r *RegionInfo) GetPendingVoter(peerID uint64) *metapb.Peer
- func (r *RegionInfo) GetRegionEpoch() *metapb.RegionEpoch
- func (r *RegionInfo) GetStartKey() []byte
- func (r *RegionInfo) GetStat() *pdpb.RegionStat
- func (r *RegionInfo) GetStoreIds() map[uint64]struct{}
- func (r *RegionInfo) GetStoreLearner(storeID uint64) *metapb.Peer
- func (r *RegionInfo) GetStorePeer(storeID uint64) *metapb.Peer
- func (r *RegionInfo) GetStoreVoter(storeID uint64) *metapb.Peer
- func (r *RegionInfo) GetVoters() []*metapb.Peer
- type RegionOption
- type RegionSetInformer
- type RegionStorage
- type RegionsInfo
- func (r *RegionsInfo) AddRegion(region *RegionInfo) []*RegionInfo
- func (r *RegionsInfo) GetAdjacentRegions(region *RegionInfo) (*RegionInfo, *RegionInfo)
- func (r *RegionsInfo) GetAverageRegionSize() int64
- func (r *RegionsInfo) GetFollower(storeID uint64, region *RegionInfo) *RegionInfo
- func (r *RegionsInfo) GetLeader(storeID uint64, region *RegionInfo) *RegionInfo
- func (r *RegionsInfo) GetMetaRegions() []*metapb.Region
- func (r *RegionsInfo) GetOverlaps(region *RegionInfo) []*RegionInfo
- 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) GetStoreFollowerRegionSize(storeID uint64) int64
- func (r *RegionsInfo) GetStoreLeaderCount(storeID uint64) int
- func (r *RegionsInfo) GetStoreLeaderRegionSize(storeID uint64) int64
- func (r *RegionsInfo) GetStoreLearnerCount(storeID uint64) int
- func (r *RegionsInfo) GetStoreLearnerRegionSize(storeID uint64) int64
- func (r *RegionsInfo) GetStorePendingPeerCount(storeID uint64) int
- func (r *RegionsInfo) GetStoreRegionCount(storeID uint64) int
- func (r *RegionsInfo) GetStoreRegionSize(storeID uint64) int64
- func (r *RegionsInfo) GetStoreRegions(storeID uint64) []*RegionInfo
- func (r *RegionsInfo) Length() int
- func (r *RegionsInfo) RandFollowerRegion(storeID uint64, ranges []KeyRange) *RegionInfo
- func (r *RegionsInfo) RandFollowerRegions(storeID uint64, ranges []KeyRange, n int) []*RegionInfo
- func (r *RegionsInfo) RandLeaderRegion(storeID uint64, ranges []KeyRange) *RegionInfo
- func (r *RegionsInfo) RandLeaderRegions(storeID uint64, ranges []KeyRange, n int) []*RegionInfo
- func (r *RegionsInfo) RandLearnerRegion(storeID uint64, ranges []KeyRange) *RegionInfo
- func (r *RegionsInfo) RandLearnerRegions(storeID uint64, ranges []KeyRange, n int) []*RegionInfo
- func (r *RegionsInfo) RandPendingRegion(storeID uint64, ranges []KeyRange) *RegionInfo
- func (r *RegionsInfo) RandPendingRegions(storeID uint64, ranges []KeyRange, n int) []*RegionInfo
- func (r *RegionsInfo) RemoveRegion(region *RegionInfo)
- func (r *RegionsInfo) ScanRange(startKey, endKey []byte, limit int) []*RegionInfo
- func (r *RegionsInfo) ScanRangeWithIterator(startKey []byte, iterator func(region *RegionInfo) bool)
- func (r *RegionsInfo) SearchPrevRegion(regionKey []byte) *RegionInfo
- func (r *RegionsInfo) SearchRegion(regionKey []byte) *RegionInfo
- func (r *RegionsInfo) SetRegion(region *RegionInfo) []*RegionInfo
- func (r *RegionsInfo) TreeLength() int
- type ResourceKind
- type ScheduleKind
- type SchedulePolicy
- type Storage
- func (s *Storage) Close() error
- func (s *Storage) ClusterStatePath(option string) string
- func (s *Storage) DeleteRegion(region *metapb.Region) error
- func (s *Storage) DeleteRule(ruleKey string) error
- func (s *Storage) DeleteStore(store *metapb.Store) error
- func (s *Storage) Flush() error
- func (s *Storage) GetRegionStorage() *RegionStorage
- func (s *Storage) LoadAllScheduleConfig() ([]string, []string, error)
- func (s *Storage) LoadComponentsConfig(cfg interface{}) (bool, error)
- func (s *Storage) LoadConfig(cfg interface{}) (bool, error)
- func (s *Storage) LoadGCSafePoint() (uint64, error)
- func (s *Storage) LoadMeta(meta *metapb.Cluster) (bool, error)
- func (s *Storage) LoadRegion(regionID uint64, region *metapb.Region) (bool, error)
- func (s *Storage) LoadRegions(f func(region *RegionInfo) []*RegionInfo) error
- func (s *Storage) LoadRegionsOnce(f func(region *RegionInfo) []*RegionInfo) error
- func (s *Storage) LoadReplicateStatus(mode string, status interface{}) (bool, error)
- func (s *Storage) LoadRules(f func(k, v string)) (bool, error)
- func (s *Storage) LoadScheduleConfig(scheduleName string) (string, error)
- func (s *Storage) LoadStore(storeID uint64, store *metapb.Store) (bool, error)
- func (s *Storage) LoadStores(f func(store *StoreInfo)) error
- func (s *Storage) RemoveScheduleConfig(scheduleName string) error
- func (s *Storage) SaveComponentsConfig(cfg interface{}) error
- func (s *Storage) SaveConfig(cfg interface{}) error
- func (s *Storage) SaveGCSafePoint(safePoint uint64) error
- func (s *Storage) SaveMeta(meta *metapb.Cluster) error
- func (s *Storage) SaveRegion(region *metapb.Region) error
- func (s *Storage) SaveReplicateStatus(mode string, status interface{}) error
- func (s *Storage) SaveRule(ruleKey string, rules interface{}) error
- func (s *Storage) SaveScheduleConfig(scheduleName string, data []byte) error
- func (s *Storage) SaveStore(store *metapb.Store) error
- func (s *Storage) SaveStoreWeight(storeID uint64, leader, region float64) error
- func (s *Storage) SetRegionStorage(regionStorage *RegionStorage) *Storage
- func (s *Storage) SwitchToDefaultStorage()
- func (s *Storage) SwitchToRegionStorage()
- type StoreBlockedErr
- type StoreCreateOption
- func SetAvailableFunc(f func() bool) StoreCreateOption
- func SetLastHeartbeatTS(lastHeartbeatTS time.Time) StoreCreateOption
- func SetLastPersistTime(lastPersist time.Time) StoreCreateOption
- func SetLeaderCount(leaderCount int) StoreCreateOption
- func SetLeaderSize(leaderSize int64) StoreCreateOption
- func SetLeaderWeight(leaderWeight float64) StoreCreateOption
- func SetPendingPeerCount(pendingPeerCount int) StoreCreateOption
- func SetRegionCount(regionCount int) StoreCreateOption
- func SetRegionSize(regionSize int64) StoreCreateOption
- func SetRegionWeight(regionWeight float64) StoreCreateOption
- func SetStoreAddress(address, statusAddress, peerAddress string) StoreCreateOption
- func SetStoreBlock() StoreCreateOption
- func SetStoreLabels(labels []*metapb.StoreLabel) StoreCreateOption
- func SetStoreStartTime(startTs int64) StoreCreateOption
- func SetStoreState(state metapb.StoreState) StoreCreateOption
- func SetStoreStats(stats *pdpb.StoreStats) StoreCreateOption
- func SetStoreUnBlock() StoreCreateOption
- func SetStoreVersion(githash, version string) StoreCreateOption
- type StoreErr
- type StoreInfo
- func (s *StoreInfo) Clone(opts ...StoreCreateOption) *StoreInfo
- func (s *StoreInfo) CompareLocation(other *StoreInfo, labels []string) int
- func (s *StoreInfo) DownTime() time.Duration
- func (s *StoreInfo) GetAddress() string
- func (s *StoreInfo) GetApplyingSnapCount() uint32
- func (s *StoreInfo) GetAvailable() uint64
- func (s *StoreInfo) GetBytesRead() uint64
- func (s *StoreInfo) GetBytesWritten() uint64
- func (s *StoreInfo) GetCapacity() uint64
- func (s *StoreInfo) GetID() uint64
- func (s *StoreInfo) GetKeysRead() uint64
- func (s *StoreInfo) GetKeysWritten() uint64
- func (s *StoreInfo) GetLabelValue(key string) string
- func (s *StoreInfo) GetLabels() []*metapb.StoreLabel
- func (s *StoreInfo) GetLastHeartbeatTS() time.Time
- func (s *StoreInfo) GetLeaderCount() int
- func (s *StoreInfo) GetLeaderSize() int64
- func (s *StoreInfo) GetLeaderWeight() float64
- func (s *StoreInfo) GetMeta() *metapb.Store
- func (s *StoreInfo) GetPendingPeerCount() int
- func (s *StoreInfo) GetReceivingSnapCount() uint32
- func (s *StoreInfo) GetRegionCount() int
- func (s *StoreInfo) GetRegionSize() int64
- func (s *StoreInfo) GetRegionWeight() float64
- func (s *StoreInfo) GetSendingSnapCount() uint32
- func (s *StoreInfo) GetSpaceThreshold(spaceRatio, spaceThreshold float64) float64
- func (s *StoreInfo) GetStartTime() time.Time
- func (s *StoreInfo) GetState() metapb.StoreState
- func (s *StoreInfo) GetStoreStats() *pdpb.StoreStats
- func (s *StoreInfo) GetUptime() time.Duration
- func (s *StoreInfo) GetUsedSize() uint64
- func (s *StoreInfo) GetVersion() string
- func (s *StoreInfo) IsAvailable() bool
- func (s *StoreInfo) IsBlocked() bool
- func (s *StoreInfo) IsBusy() bool
- func (s *StoreInfo) IsDisconnected() bool
- func (s *StoreInfo) IsLowSpace(lowSpaceRatio float64) bool
- func (s *StoreInfo) IsOffline() bool
- func (s *StoreInfo) IsTombstone() bool
- func (s *StoreInfo) IsUnhealth() bool
- func (s *StoreInfo) IsUp() bool
- func (s *StoreInfo) LeaderScore(policy SchedulePolicy, delta int64) float64
- func (s *StoreInfo) MergeLabels(labels []*metapb.StoreLabel) []*metapb.StoreLabel
- func (s *StoreInfo) NeedPersist() bool
- func (s *StoreInfo) RegionScore(highSpaceRatio, lowSpaceRatio float64, delta int64) float64
- func (s *StoreInfo) ResourceCount(kind ResourceKind) uint64
- func (s *StoreInfo) ResourceScore(scheduleKind ScheduleKind, highSpaceRatio, lowSpaceRatio float64, delta int64) float64
- func (s *StoreInfo) ResourceSize(kind ResourceKind) int64
- func (s *StoreInfo) ResourceWeight(kind ResourceKind) float64
- func (s *StoreInfo) StorageSize() uint64
- type StoreSetController
- type StoreSetInformer
- type StoreTombstonedErr
- type StoresInfo
- func (s *StoresInfo) AttachAvailableFunc(storeID uint64, f func() bool)
- func (s *StoresInfo) BlockStore(storeID uint64) errcode.ErrorCode
- func (s *StoresInfo) DeleteStore(store *StoreInfo)
- 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) SetLeaderCount(storeID uint64, leaderCount int)
- func (s *StoresInfo) SetLeaderSize(storeID uint64, leaderSize int64)
- func (s *StoresInfo) SetPendingPeerCount(storeID uint64, pendingPeerCount int)
- func (s *StoresInfo) SetRegionCount(storeID uint64, regionCount int)
- func (s *StoresInfo) SetRegionSize(storeID uint64, regionSize int64)
- func (s *StoresInfo) SetStore(store *StoreInfo)
- func (s *StoresInfo) TakeStore(storeID uint64) *StoreInfo
- func (s *StoresInfo) UnblockStore(storeID uint64)
- func (s *StoresInfo) UpdateStoreStatus(storeID uint64, leaderCount int, regionCount int, pendingPeerCount int, ...)
Constants ¶
const EmptyRegionApproximateSize = 1
EmptyRegionApproximateSize is the region approximate size of an empty region (heartbeat size <= 1MB).
Variables ¶
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) )
var ErrRegionIsStale = func(region *metapb.Region, origin *metapb.Region) error { return errors.Errorf("region is stale: region %v origin %v", region, origin) }
ErrRegionIsStale is error info for region is stale.
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 DistinctScore ¶
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 ¶
EncodeToString overrides hex.EncodeToString implementation. Difference: returns []byte, not string
func HexRegionKey ¶
HexRegionKey converts region key to hex format. Used for formating region in logs.
func HexRegionKeyStr ¶
HexRegionKeyStr converts region key to hex format. Used for formating region in logs.
func NewStoreNotFoundErr ¶
NewStoreNotFoundErr is for log of store not found
func ToUpperASCIIInplace ¶
ToUpperASCIIInplace bytes.ToUpper but zero-cost
Types ¶
type BasicCluster ¶
type BasicCluster struct { sync.RWMutex Stores *StoresInfo Regions *RegionsInfo }
BasicCluster provides basic data member and interface for a tikv cluster.
func (*BasicCluster) AttachAvailableFunc ¶
func (bc *BasicCluster) AttachAvailableFunc(storeID uint64, f func() bool)
AttachAvailableFunc attaches an available function to a specific store.
func (*BasicCluster) BlockStore ¶
func (bc *BasicCluster) BlockStore(storeID uint64) error
BlockStore stops balancer from selecting the store.
func (*BasicCluster) CheckAndPutRegion ¶
func (bc *BasicCluster) CheckAndPutRegion(region *RegionInfo) []*RegionInfo
CheckAndPutRegion checks if the region is valid to put,if valid then put.
func (*BasicCluster) DeleteStore ¶
func (bc *BasicCluster) DeleteStore(store *StoreInfo)
DeleteStore deletes a store.
func (*BasicCluster) GetAdjacentRegions ¶
func (bc *BasicCluster) GetAdjacentRegions(region *RegionInfo) (*RegionInfo, *RegionInfo)
GetAdjacentRegions returns region's info that is adjacent with specific region.
func (*BasicCluster) GetAverageRegionSize ¶
func (bc *BasicCluster) GetAverageRegionSize() int64
GetAverageRegionSize returns the average region approximate size.
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) GetMetaRegions ¶
func (bc *BasicCluster) GetMetaRegions() []*metapb.Region
GetMetaRegions gets a set of metapb.Region from regionMap.
func (*BasicCluster) GetMetaStores ¶
func (bc *BasicCluster) GetMetaStores() []*metapb.Store
GetMetaStores gets a complete set of metapb.Store.
func (*BasicCluster) GetOverlaps ¶
func (bc *BasicCluster) GetOverlaps(region *RegionInfo) []*RegionInfo
GetOverlaps returns the regions which are overlapped with the specified region range.
func (*BasicCluster) GetRegion ¶
func (bc *BasicCluster) GetRegion(regionID uint64) *RegionInfo
GetRegion searches for a region by ID.
func (*BasicCluster) GetRegionCount ¶
func (bc *BasicCluster) GetRegionCount() int
GetRegionCount gets the total count of RegionInfo of regionMap.
func (*BasicCluster) GetRegionStores ¶
func (bc *BasicCluster) GetRegionStores(region *RegionInfo) []*StoreInfo
GetRegionStores returns all Stores that contains the region's peer.
func (*BasicCluster) GetRegions ¶
func (bc *BasicCluster) GetRegions() []*RegionInfo
GetRegions gets all RegionInfo from regionMap.
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) GetStoreFollowerCount ¶
func (bc *BasicCluster) GetStoreFollowerCount(storeID uint64) int
GetStoreFollowerCount get the total count of a store's follower RegionInfo.
func (*BasicCluster) GetStoreLeaderCount ¶
func (bc *BasicCluster) GetStoreLeaderCount(storeID uint64) int
GetStoreLeaderCount get the total count of a store's leader RegionInfo.
func (*BasicCluster) GetStoreLeaderRegionSize ¶
func (bc *BasicCluster) GetStoreLeaderRegionSize(storeID uint64) int64
GetStoreLeaderRegionSize get total size of store's leader regions.
func (*BasicCluster) GetStorePendingPeerCount ¶
func (bc *BasicCluster) GetStorePendingPeerCount(storeID uint64) int
GetStorePendingPeerCount gets the total count of a store's region that includes pending peer.
func (*BasicCluster) GetStoreRegionCount ¶
func (bc *BasicCluster) GetStoreRegionCount(storeID uint64) int
GetStoreRegionCount gets the total count of a store's leader and follower RegionInfo by storeID.
func (*BasicCluster) GetStoreRegionSize ¶
func (bc *BasicCluster) GetStoreRegionSize(storeID uint64) int64
GetStoreRegionSize get total size of store's regions.
func (*BasicCluster) GetStoreRegions ¶
func (bc *BasicCluster) GetStoreRegions(storeID uint64) []*RegionInfo
GetStoreRegions gets all RegionInfo with a given storeID.
func (*BasicCluster) GetStores ¶
func (bc *BasicCluster) GetStores() []*StoreInfo
GetStores returns all Stores in the cluster.
func (*BasicCluster) Length ¶
func (bc *BasicCluster) Length() int
Length returns the RegionsInfo length.
func (*BasicCluster) PreCheckPutRegion ¶
func (bc *BasicCluster) PreCheckPutRegion(region *RegionInfo) (*RegionInfo, error)
PreCheckPutRegion checks if the region is valid to put.
func (*BasicCluster) PutRegion ¶
func (bc *BasicCluster) PutRegion(region *RegionInfo) []*RegionInfo
PutRegion put a region.
func (*BasicCluster) PutStore ¶
func (bc *BasicCluster) PutStore(store *StoreInfo)
PutStore put a store.
func (*BasicCluster) RandFollowerRegion ¶
func (bc *BasicCluster) RandFollowerRegion(storeID uint64, ranges []KeyRange, opts ...RegionOption) *RegionInfo
RandFollowerRegion returns a random region that has a follower on the store.
func (*BasicCluster) RandLeaderRegion ¶
func (bc *BasicCluster) RandLeaderRegion(storeID uint64, ranges []KeyRange, opts ...RegionOption) *RegionInfo
RandLeaderRegion returns a random region that has leader on the store.
func (*BasicCluster) RandLearnerRegion ¶
func (bc *BasicCluster) RandLearnerRegion(storeID uint64, ranges []KeyRange, opts ...RegionOption) *RegionInfo
RandLearnerRegion returns a random region that has a learner peer on the store.
func (*BasicCluster) RandPendingRegion ¶
func (bc *BasicCluster) RandPendingRegion(storeID uint64, ranges []KeyRange, opts ...RegionOption) *RegionInfo
RandPendingRegion returns a random region that has a pending peer on the store.
func (*BasicCluster) RemoveRegion ¶
func (bc *BasicCluster) RemoveRegion(region *RegionInfo)
RemoveRegion removes RegionInfo from regionTree and regionMap.
func (*BasicCluster) ScanRange ¶
func (bc *BasicCluster) 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 (*BasicCluster) SearchPrevRegion ¶
func (bc *BasicCluster) SearchPrevRegion(regionKey []byte) *RegionInfo
SearchPrevRegion searches previous RegionInfo from regionTree.
func (*BasicCluster) SearchRegion ¶
func (bc *BasicCluster) SearchRegion(regionKey []byte) *RegionInfo
SearchRegion searches RegionInfo from regionTree.
func (*BasicCluster) TakeStore ¶
func (bc *BasicCluster) TakeStore(storeID uint64) *StoreInfo
TakeStore returns the point of the origin StoreInfo with the specified storeID.
func (*BasicCluster) UnblockStore ¶
func (bc *BasicCluster) UnblockStore(storeID uint64)
UnblockStore allows balancer to select the store.
func (*BasicCluster) UpdateStoreStatus ¶
func (bc *BasicCluster) UpdateStoreStatus(storeID uint64, leaderCount int, regionCount int, pendingPeerCount int, leaderSize int64, regionSize int64)
UpdateStoreStatus updates the information of the store.
type HexRegionMeta ¶
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 ¶
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 ¶
KeyRange is a key range.
func NewKeyRange ¶
NewKeyRange create a KeyRange with the given start key and end key.
type KeyType ¶
type KeyType int
KeyType distinguishes different kinds of key types
func StringToKeyType ¶
StringToKeyType creates a key type with string.
type PriorityLevel ¶
type PriorityLevel int
PriorityLevel lower level means higher priority
const ( LowPriority PriorityLevel = iota NormalPriority HighPriority )
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 SetReadKeys ¶
func SetReadKeys(v uint64) RegionCreateOption
SetReadKeys sets the read keys 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 SetReportInterval ¶
func SetReportInterval(v uint64) RegionCreateOption
SetReportInterval sets the report interval for the region.
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 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 WithReplacePeerStore ¶
func WithReplacePeerStore(oldStoreID, newStoreID uint64) RegionCreateOption
WithReplacePeerStore replaces a peer's storeID with another ID.
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 MergeRegions ¶
func MergeRegions(regions []*RegionInfo) []*RegionInfo
MergeRegions merge a set of RegionInfo by regionKey
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(start, end []byte) *RegionInfo
NewTestRegionInfo creates a RegionInfo for test.
func RegionFromHeartbeat ¶
func RegionFromHeartbeat(heartbeat *pdpb.RegionHeartbeatRequest) *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
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) 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) 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) 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) 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.
type RegionSetInformer ¶
type RegionSetInformer interface { RandFollowerRegion(storeID uint64, ranges []KeyRange, opts ...RegionOption) *RegionInfo RandLeaderRegion(storeID uint64, ranges []KeyRange, opts ...RegionOption) *RegionInfo RandLearnerRegion(storeID uint64, ranges []KeyRange, opts ...RegionOption) *RegionInfo RandPendingRegion(storeID uint64, ranges []KeyRange, opts ...RegionOption) *RegionInfo GetAverageRegionSize() int64 GetStoreRegionCount(storeID uint64) int GetRegion(id uint64) *RegionInfo GetAdjacentRegions(region *RegionInfo) (*RegionInfo, *RegionInfo) ScanRegions(startKey, endKey []byte, limit int) []*RegionInfo }
RegionSetInformer provides access to a shared informer of regions.
type RegionStorage ¶
RegionStorage is used to save regions.
func NewRegionStorage ¶
func NewRegionStorage(ctx context.Context, path string) (*RegionStorage, error)
NewRegionStorage returns a region storage that is used to save regions.
func (*RegionStorage) FlushRegion ¶
func (s *RegionStorage) FlushRegion() error
FlushRegion saves the cache region to region storage.
func (*RegionStorage) SaveRegion ¶
func (s *RegionStorage) SaveRegion(region *metapb.Region) error
SaveRegion saves one region to storage.
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) []*RegionInfo
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, region *RegionInfo) *RegionInfo
GetFollower return follower RegionInfo by storeID and regionID(now only used in test)
func (*RegionsInfo) GetLeader ¶
func (r *RegionsInfo) GetLeader(storeID uint64, region *RegionInfo) *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) []*RegionInfo
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) 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, ranges []KeyRange) *RegionInfo
RandFollowerRegion randomly gets a store's follower region.
func (*RegionsInfo) RandFollowerRegions ¶
func (r *RegionsInfo) RandFollowerRegions(storeID uint64, ranges []KeyRange, n int) []*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, n int) []*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, n int) []*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, n int) []*RegionInfo
RandPendingRegions randomly gets a store's n regions with a pending peer.
func (*RegionsInfo) RemoveRegion ¶
func (r *RegionsInfo) RemoveRegion(region *RegionInfo)
RemoveRegion removes RegionInfo from regionTree and regionMap
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) 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) []*RegionInfo
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 ResourceKind ¶
type ResourceKind int
ResourceKind distinguishes different kinds of resources.
const ( // LeaderKind indicates the leader kind resource LeaderKind ResourceKind = iota // RegionKind indicates the region kind resource RegionKind )
func (ResourceKind) String ¶
func (k ResourceKind) String() string
type ScheduleKind ¶
type ScheduleKind struct { Resource ResourceKind Policy SchedulePolicy }
ScheduleKind distinguishes resources and schedule policy.
func NewScheduleKind ¶
func NewScheduleKind(Resource ResourceKind, Policy SchedulePolicy) ScheduleKind
NewScheduleKind creates a schedule kind with resource kind and schedule policy.
type SchedulePolicy ¶
type SchedulePolicy int
SchedulePolicy distinguishes different kinds of schedule policies.
const ( // ByCount indicates that balance by count ByCount SchedulePolicy = iota // BySize indicates that balance by size BySize )
func StringToSchedulePolicy ¶
func StringToSchedulePolicy(input string) SchedulePolicy
StringToSchedulePolicy creates a schedule policy with string.
func (SchedulePolicy) String ¶
func (k SchedulePolicy) String() string
type Storage ¶
Storage wraps all kv operations, keep it stateless.
func NewStorage ¶
NewStorage creates Storage instance with Base.
func (*Storage) ClusterStatePath ¶
ClusterStatePath returns the path to save an option.
func (*Storage) DeleteRegion ¶
DeleteRegion deletes one region from storage.
func (*Storage) DeleteRule ¶
DeleteRule removes a rule from storage.
func (*Storage) DeleteStore ¶
DeleteStore deletes one store from storage.
func (*Storage) GetRegionStorage ¶
func (s *Storage) GetRegionStorage() *RegionStorage
GetRegionStorage gets the region storage.
func (*Storage) LoadAllScheduleConfig ¶
LoadAllScheduleConfig loads all schedulers' config.
func (*Storage) LoadComponentsConfig ¶
LoadComponentsConfig loads config from componentsConfigPath then unmarshal it to cfg.
func (*Storage) LoadConfig ¶
LoadConfig loads config from configPath then unmarshal it to cfg.
func (*Storage) LoadGCSafePoint ¶
LoadGCSafePoint loads current GC safe point from storage.
func (*Storage) LoadRegion ¶
LoadRegion loads one regoin from storage.
func (*Storage) LoadRegions ¶
func (s *Storage) LoadRegions(f func(region *RegionInfo) []*RegionInfo) error
LoadRegions loads all regions from storage to RegionsInfo.
func (*Storage) LoadRegionsOnce ¶
func (s *Storage) LoadRegionsOnce(f func(region *RegionInfo) []*RegionInfo) error
LoadRegionsOnce loads all regions from storage to RegionsInfo.Only load one time from regionStorage.
func (*Storage) LoadReplicateStatus ¶
LoadReplicateStatus loads replicate status by mode.
func (*Storage) LoadScheduleConfig ¶
LoadScheduleConfig loads the config of scheduler.
func (*Storage) LoadStores ¶
LoadStores loads all stores from storage to StoresInfo.
func (*Storage) RemoveScheduleConfig ¶
RemoveScheduleConfig remvoes the config of scheduler.
func (*Storage) SaveComponentsConfig ¶
SaveComponentsConfig stores marshalable cfg to the componentsConfigPath.
func (*Storage) SaveConfig ¶
SaveConfig stores marshalable cfg to the configPath.
func (*Storage) SaveGCSafePoint ¶
SaveGCSafePoint saves new GC safe point to storage.
func (*Storage) SaveRegion ¶
SaveRegion saves one region to storage.
func (*Storage) SaveReplicateStatus ¶
SaveReplicateStatus stores replicate status by mode.
func (*Storage) SaveScheduleConfig ¶
SaveScheduleConfig saves the config of scheduler.
func (*Storage) SaveStoreWeight ¶
SaveStoreWeight saves a store's leader and region weight to storage.
func (*Storage) SetRegionStorage ¶
func (s *Storage) SetRegionStorage(regionStorage *RegionStorage) *Storage
SetRegionStorage sets the region storage.
func (*Storage) SwitchToDefaultStorage ¶
func (s *Storage) SwitchToDefaultStorage()
SwitchToDefaultStorage switches to the to default storage.
func (*Storage) SwitchToRegionStorage ¶
func (s *Storage) SwitchToRegionStorage()
SwitchToRegionStorage switches to the region storage.
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 StoreCreateOption ¶
type StoreCreateOption func(region *StoreInfo)
StoreCreateOption is used to create store.
func SetAvailableFunc ¶
func SetAvailableFunc(f func() bool) StoreCreateOption
SetAvailableFunc sets a customize function for the store. The function f returns true if the store limit is not exceeded.
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 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 SetStoreBlock ¶
func SetStoreBlock() StoreCreateOption
SetStoreBlock stops balancer from selecting the store.
func SetStoreLabels ¶
func SetStoreLabels(labels []*metapb.StoreLabel) StoreCreateOption
SetStoreLabels sets the labels for the store.
func SetStoreStartTime ¶
func SetStoreStartTime(startTs int64) StoreCreateOption
SetStoreStartTime sets the start timestamp for the store.
func SetStoreState ¶
func SetStoreState(state metapb.StoreState) StoreCreateOption
SetStoreState sets the state for the store.
func SetStoreStats ¶
func SetStoreStats(stats *pdpb.StoreStats) StoreCreateOption
SetStoreStats sets the statistics information for the store.
func SetStoreUnBlock ¶
func SetStoreUnBlock() StoreCreateOption
SetStoreUnBlock allows balancer to select the store.
func SetStoreVersion ¶
func SetStoreVersion(githash, version string) StoreCreateOption
SetStoreVersion sets the version for the store.
type StoreErr ¶
type StoreErr struct {
StoreID uint64 `json:"storeId"`
}
StoreErr can be newtyped or embedded in your own error
type StoreInfo ¶
type StoreInfo struct {
// contains filtered or unexported fields
}
StoreInfo contains information about a store.
func NewStoreInfo ¶
func NewStoreInfo(store *metapb.Store, opts ...StoreCreateOption) *StoreInfo
NewStoreInfo creates StoreInfo with meta data.
func NewStoreInfoWithLabel ¶
NewStoreInfoWithLabel is create a store with specified labels.
func NewStoreInfoWithSizeCount ¶
func NewStoreInfoWithSizeCount(id uint64, regionCount, leaderCount int, regionSize, leaderSize int64) *StoreInfo
NewStoreInfoWithSizeCount is create a store with size and count.
func (*StoreInfo) Clone ¶
func (s *StoreInfo) Clone(opts ...StoreCreateOption) *StoreInfo
Clone creates a copy of current StoreInfo.
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) GetAddress ¶
GetAddress returns the address of the store.
func (*StoreInfo) GetApplyingSnapCount ¶
GetApplyingSnapCount returns the current applying snapshot count of the store.
func (*StoreInfo) GetAvailable ¶
GetAvailable returns the available size of the store.
func (*StoreInfo) GetBytesRead ¶
GetBytesRead returns the bytes read for the store during this period.
func (*StoreInfo) GetBytesWritten ¶
GetBytesWritten returns the bytes written for the store during this period.
func (*StoreInfo) GetCapacity ¶
GetCapacity returns the capacity size of the store.
func (*StoreInfo) GetKeysRead ¶
GetKeysRead returns the keys read for the store during this period.
func (*StoreInfo) GetKeysWritten ¶
GetKeysWritten returns the keys written for the store during this period.
func (*StoreInfo) GetLabelValue ¶
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 ¶
GetLastHeartbeatTS returns the last heartbeat timestamp of the store.
func (*StoreInfo) GetLeaderCount ¶
GetLeaderCount returns the leader count of the store.
func (*StoreInfo) GetLeaderSize ¶
GetLeaderSize returns the leader size of the store.
func (*StoreInfo) GetLeaderWeight ¶
GetLeaderWeight returns the leader weight of the store.
func (*StoreInfo) GetPendingPeerCount ¶
GetPendingPeerCount returns the pending peer count of the store.
func (*StoreInfo) GetReceivingSnapCount ¶
GetReceivingSnapCount returns the current receiving snapshot count of the store.
func (*StoreInfo) GetRegionCount ¶
GetRegionCount returns the Region count of the store.
func (*StoreInfo) GetRegionSize ¶
GetRegionSize returns the Region size of the store.
func (*StoreInfo) GetRegionWeight ¶
GetRegionWeight returns the Region weight of the store.
func (*StoreInfo) GetSendingSnapCount ¶
GetSendingSnapCount returns the current sending snapshot count of the store.
func (*StoreInfo) GetSpaceThreshold ¶
GetSpaceThreshold returns the threshold of low/high space in MB.
func (*StoreInfo) GetStartTime ¶
GetStartTime returns the start timestamp.
func (*StoreInfo) GetState ¶
func (s *StoreInfo) GetState() metapb.StoreState
GetState returns the state of the store.
func (*StoreInfo) GetStoreStats ¶
func (s *StoreInfo) GetStoreStats() *pdpb.StoreStats
GetStoreStats returns the statistics information of the store.
func (*StoreInfo) GetUsedSize ¶
GetUsedSize returns the used size of the store.
func (*StoreInfo) GetVersion ¶
GetVersion returns the version of the store.
func (*StoreInfo) IsAvailable ¶
IsAvailable returns if the store bucket of limitation is available
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) IsUnhealth ¶
IsUnhealth checks if a store is unhealth.
func (*StoreInfo) LeaderScore ¶
func (s *StoreInfo) LeaderScore(policy SchedulePolicy, delta int64) float64
LeaderScore returns the store's leader score.
func (*StoreInfo) MergeLabels ¶
func (s *StoreInfo) MergeLabels(labels []*metapb.StoreLabel) []*metapb.StoreLabel
MergeLabels merges the passed in labels with origins, overriding duplicated ones.
func (*StoreInfo) NeedPersist ¶
NeedPersist returns if it needs to save to etcd.
func (*StoreInfo) RegionScore ¶
RegionScore returns the store's region score.
func (*StoreInfo) ResourceCount ¶
func (s *StoreInfo) ResourceCount(kind ResourceKind) uint64
ResourceCount returns count of leader/region in the store.
func (*StoreInfo) ResourceScore ¶
func (s *StoreInfo) ResourceScore(scheduleKind ScheduleKind, highSpaceRatio, lowSpaceRatio float64, delta int64) float64
ResourceScore returns 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 ¶
StorageSize returns store's used storage size reported from tikv.
type StoreSetController ¶
type StoreSetController interface { BlockStore(id uint64) error UnblockStore(id uint64) AttachAvailableFunc(id uint64, f func() bool) }
StoreSetController is used to control stores' status.
type StoreSetInformer ¶
type StoreSetInformer interface { GetStores() []*StoreInfo GetStore(id uint64) *StoreInfo GetRegionStores(region *RegionInfo) []*StoreInfo GetFollowerStores(region *RegionInfo) []*StoreInfo GetLeaderStore(region *RegionInfo) *StoreInfo }
StoreSetInformer provides access to a shared informer of stores.
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) AttachAvailableFunc ¶
func (s *StoresInfo) AttachAvailableFunc(storeID uint64, f func() bool)
AttachAvailableFunc attaches f to a specific store.
func (*StoresInfo) BlockStore ¶
func (s *StoresInfo) BlockStore(storeID uint64) errcode.ErrorCode
BlockStore blocks a StoreInfo with storeID.
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) 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) TakeStore ¶
func (s *StoresInfo) TakeStore(storeID uint64) *StoreInfo
TakeStore returns the point of the origin StoreInfo with the specified storeID.
func (*StoresInfo) UnblockStore ¶
func (s *StoresInfo) UnblockStore(storeID uint64)
UnblockStore unblocks a StoreInfo with storeID.
func (*StoresInfo) UpdateStoreStatus ¶
func (s *StoresInfo) UpdateStoreStatus(storeID uint64, leaderCount int, regionCount int, pendingPeerCount int, leaderSize int64, regionSize int64)
UpdateStoreStatus updates the information of the store.