core

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

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

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

LoadConfig loads config from configPath then unmarshal it to cfg.

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, rangeLimit int) 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, rangeLimit int) 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) 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
}

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

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() 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) IsUp

func (s *StoreInfo) IsUp() bool

IsUp checks if the store's state is Up.

func (*StoreInfo) LeaderScore

func (s *StoreInfo) LeaderScore() float64

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

func (s *StoreInfo) RegionScore() float64

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

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

Jump to

Keyboard shortcuts

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