core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const EmptyResourceApproximateSize = 1

EmptyResourceApproximateSize is the resource approximate size of an empty resource (heartbeat size <= 1MB).

Variables

This section is empty.

Functions

func DiffResourceKeyInfo

func DiffResourceKeyInfo(origin *CachedResource, other *CachedResource) string

DiffResourceKeyInfo return the difference of key info between two CachedResource

func DiffResourcePeersInfo

func DiffResourcePeersInfo(origin *CachedResource, other *CachedResource) string

DiffResourcePeersInfo return the difference of peers info between two CachedResource

func DistinctScore

func DistinctScore(labels []string, containers []*CachedContainer, other *CachedContainer) float64

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

func EncodeToString

func EncodeToString(src []byte) []byte

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

func HexResourceKey

func HexResourceKey(key []byte) []byte

HexResourceKey converts resource key to hex format. Used for formating resource in logs.

func HexResourceKeyStr

func HexResourceKeyStr(key []byte) string

HexResourceKeyStr converts resource key to hex format. Used for formating resource in logs.

func String

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

String converts slice of bytes to string without copy.

func ToUpperASCIIInplace

func ToUpperASCIIInplace(s []byte) []byte

ToUpperASCIIInplace bytes.ToUpper but zero-cost

Types

type BasicCluster

type BasicCluster struct {
	sync.RWMutex
	Containers *CachedContainers
	Resources  *CachedResources
}

BasicCluster provides basic data member and interface for a storage application cluster.

func NewBasicCluster

func NewBasicCluster(factory func() metadata.Resource) *BasicCluster

NewBasicCluster creates a BasicCluster.

func (*BasicCluster) AttachAvailableFunc

func (bc *BasicCluster) AttachAvailableFunc(containerID uint64, limitType limit.Type, f func() bool)

AttachAvailableFunc attaches an available function to a specific container.

func (*BasicCluster) CheckAndPutResource

func (bc *BasicCluster) CheckAndPutResource(res *CachedResource) []*CachedResource

CheckAndPutResource checks if the resource is valid to put,if valid then put.

func (*BasicCluster) DeleteContainer

func (bc *BasicCluster) DeleteContainer(container *CachedContainer)

DeleteContainer deletes a container.

func (*BasicCluster) GetAdjacentResources

func (bc *BasicCluster) GetAdjacentResources(res *CachedResource) (*CachedResource, *CachedResource)

GetAdjacentResources returns resource's info that is adjacent with specific resource.

func (*BasicCluster) GetAverageResourceSize

func (bc *BasicCluster) GetAverageResourceSize() int64

GetAverageResourceSize returns the average resource approximate size.

func (*BasicCluster) GetContainer

func (bc *BasicCluster) GetContainer(containerID uint64) *CachedContainer

GetContainer searches for a container by ID.

func (*BasicCluster) GetContainerCount

func (bc *BasicCluster) GetContainerCount() int

GetContainerCount returns the total count of CachedContainers.

func (*BasicCluster) GetContainerFollowerCount

func (bc *BasicCluster) GetContainerFollowerCount(containerID uint64) int

GetContainerFollowerCount get the total count of a container's follower CachedResource.

func (*BasicCluster) GetContainerLeaderCount

func (bc *BasicCluster) GetContainerLeaderCount(containerID uint64) int

GetContainerLeaderCount get the total count of a container's leader CachedResource.

func (*BasicCluster) GetContainerLeaderResourceSize

func (bc *BasicCluster) GetContainerLeaderResourceSize(containerID uint64) int64

GetContainerLeaderResourceSize get total size of container's leader resources.

func (*BasicCluster) GetContainerPendingPeerCount

func (bc *BasicCluster) GetContainerPendingPeerCount(containerID uint64) int

GetContainerPendingPeerCount gets the total count of a container's resource that includes pending peer.

func (*BasicCluster) GetContainerResourceCount

func (bc *BasicCluster) GetContainerResourceCount(containerID uint64) int

GetContainerResourceCount gets the total count of a container's leader and follower CachedResource by containerID.

func (*BasicCluster) GetContainerResourceSize

func (bc *BasicCluster) GetContainerResourceSize(containerID uint64) int64

GetContainerResourceSize get total size of container's resources.

func (*BasicCluster) GetContainerResources

func (bc *BasicCluster) GetContainerResources(containerID uint64) []*CachedResource

GetContainerResources gets all CachedResource with a given containerID.

func (*BasicCluster) GetContainers

func (bc *BasicCluster) GetContainers() []*CachedContainer

GetContainers returns all Containers in the cluster.

func (*BasicCluster) GetFollowerContainers

func (bc *BasicCluster) GetFollowerContainers(res *CachedResource) []*CachedContainer

GetFollowerContainers returns all Containers that contains the resource's follower peer.

func (*BasicCluster) GetLeaderContainer

func (bc *BasicCluster) GetLeaderContainer(res *CachedResource) *CachedContainer

GetLeaderContainer returns all Containers that contains the resource's leader peer.

func (*BasicCluster) GetMetaContainers

func (bc *BasicCluster) GetMetaContainers() []metadata.Container

GetMetaContainers gets a complete set of metadata.Container.

func (*BasicCluster) GetMetaResources

func (bc *BasicCluster) GetMetaResources() []metadata.Resource

GetMetaResources gets a set of metadata.Resource from resourceMap.

func (*BasicCluster) GetOverlaps

func (bc *BasicCluster) GetOverlaps(res *CachedResource) []*CachedResource

GetOverlaps returns the resources which are overlapped with the specified resource range.

func (*BasicCluster) GetResource

func (bc *BasicCluster) GetResource(resourceID uint64) *CachedResource

GetResource searches for a resource by ID.

func (*BasicCluster) GetResourceContainers

func (bc *BasicCluster) GetResourceContainers(res *CachedResource) []*CachedContainer

GetResourceContainers returns all Containers that contains the resource's peer.

func (*BasicCluster) GetResourceCount

func (bc *BasicCluster) GetResourceCount() int

GetResourceCount gets the total count of CachedResource of resourceMap.

func (*BasicCluster) GetResources

func (bc *BasicCluster) GetResources() []*CachedResource

GetResources gets all CachedResource from resourceMap.

func (*BasicCluster) PauseLeaderTransfer

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

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

func (*BasicCluster) PreCheckPutResource

func (bc *BasicCluster) PreCheckPutResource(res *CachedResource) (*CachedResource, error)

PreCheckPutResource checks if the resource is valid to put.

func (*BasicCluster) PutContainer

func (bc *BasicCluster) PutContainer(container *CachedContainer)

PutContainer put a container.

func (*BasicCluster) PutResource

func (bc *BasicCluster) PutResource(res *CachedResource) []*CachedResource

PutResource put a resource, returns overlap resources

func (*BasicCluster) RandFollowerResource

func (bc *BasicCluster) RandFollowerResource(containerID uint64, ranges []KeyRange, opts ...ResourceOption) *CachedResource

RandFollowerResource returns a random resource that has a follower on the container.

func (*BasicCluster) RandLeaderResource

func (bc *BasicCluster) RandLeaderResource(containerID uint64, ranges []KeyRange, opts ...ResourceOption) *CachedResource

RandLeaderResource returns a random resource that has leader on the container.

func (*BasicCluster) RandLearnerResource

func (bc *BasicCluster) RandLearnerResource(containerID uint64, ranges []KeyRange, opts ...ResourceOption) *CachedResource

RandLearnerResource returns a random resource that has a learner peer on the container.

func (*BasicCluster) RandPendingResource

func (bc *BasicCluster) RandPendingResource(containerID uint64, ranges []KeyRange, opts ...ResourceOption) *CachedResource

RandPendingResource returns a random resource that has a pending peer on the container.

func (*BasicCluster) RemoveResource

func (bc *BasicCluster) RemoveResource(res *CachedResource)

RemoveResource removes CachedResource from resourceTree and resourceMap.

func (*BasicCluster) ResumeLeaderTransfer

func (bc *BasicCluster) ResumeLeaderTransfer(containerID uint64)

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

func (*BasicCluster) ScanRange

func (bc *BasicCluster) ScanRange(startKey, endKey []byte, limit int) []*CachedResource

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

func (*BasicCluster) SearchPrevResource

func (bc *BasicCluster) SearchPrevResource(resKey []byte) *CachedResource

SearchPrevResource searches previous CachedResource from resourceTree.

func (*BasicCluster) SearchResource

func (bc *BasicCluster) SearchResource(resKey []byte) *CachedResource

SearchResource searches CachedResource from resourceTree.

func (*BasicCluster) TakeContainer

func (bc *BasicCluster) TakeContainer(containerID uint64) *CachedContainer

TakeContainer returns the point of the origin CachedContainers with the specified containerID.

func (*BasicCluster) UpdateContainerStatus

func (bc *BasicCluster) UpdateContainerStatus(containerID uint64, leaderCount int, resourceCount int, pendingPeerCount int, leaderSize int64, resourceSize int64)

UpdateContainerStatus updates the information of the container.

type CachedContainer

type CachedContainer struct {
	Meta metadata.Container
	// contains filtered or unexported fields
}

CachedContainer is the container runtime info cached in the cache

func NewCachedContainer

func NewCachedContainer(meta metadata.Container, opts ...ContainerCreateOption) *CachedContainer

NewCachedContainer creates CachedContainer with meta data.

func NewTestCachedContainerWithSizeCount

func NewTestCachedContainerWithSizeCount(id uint64, resourceCount, leaderCount int, resourceSize, leaderSize int64) *CachedContainer

NewTestCachedContainerWithSizeCount is create a container with size and count.

func NewTestContainerInfoWithLabel

func NewTestContainerInfoWithLabel(id uint64, resourceCount int, labels map[string]string) *CachedContainer

NewTestContainerInfoWithLabel is create a container with specified labels.

func (*CachedContainer) AllowLeaderTransfer

func (cr *CachedContainer) AllowLeaderTransfer() bool

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

func (*CachedContainer) AvailableRatio

func (cr *CachedContainer) AvailableRatio() float64

AvailableRatio is container's freeSpace/capacity.

func (*CachedContainer) Clone

Clone creates a copy of current CachedContainer.

func (*CachedContainer) CompareLocation

func (cr *CachedContainer) CompareLocation(other *CachedContainer, labels []string) int

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

func (*CachedContainer) DownTime

func (cr *CachedContainer) DownTime() time.Duration

DownTime returns the time elapsed since last heartbeat.

func (CachedContainer) GetApplyingSnapCount

func (ss CachedContainer) GetApplyingSnapCount() uint64

GetApplyingSnapCount returns the current applying snapshot count of the container.

func (CachedContainer) GetAvailable

func (ss CachedContainer) GetAvailable() uint64

GetAvailable returns the available size of the container.

func (CachedContainer) GetAvailableDeviation

func (ss CachedContainer) GetAvailableDeviation() uint64

GetAvailableDeviation returns approximate magnitude of available in the recent period.

func (CachedContainer) GetAvgAvailable

func (ss CachedContainer) GetAvgAvailable() uint64

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

func (CachedContainer) GetBytesRead

func (ss CachedContainer) GetBytesRead() uint64

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

func (CachedContainer) GetBytesWritten

func (ss CachedContainer) GetBytesWritten() uint64

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

func (CachedContainer) GetCapacity

func (ss CachedContainer) GetCapacity() uint64

GetCapacity returns the capacity size of the container.

func (CachedContainer) GetContainerStats

func (ss CachedContainer) GetContainerStats() *rpcpb.ContainerStats

GetContainerStats returns the statistics information of the container.

func (CachedContainer) GetKeysRead

func (ss CachedContainer) GetKeysRead() uint64

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

func (CachedContainer) GetKeysWritten

func (ss CachedContainer) GetKeysWritten() uint64

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

func (*CachedContainer) GetLabelValue

func (cr *CachedContainer) GetLabelValue(key string) string

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

func (*CachedContainer) GetLastHeartbeatTS

func (cr *CachedContainer) GetLastHeartbeatTS() time.Time

GetLastHeartbeatTS returns the last heartbeat timestamp of the container.

func (*CachedContainer) GetLeaderCount

func (cr *CachedContainer) GetLeaderCount() int

GetLeaderCount returns the leader count of the container.

func (*CachedContainer) GetLeaderSize

func (cr *CachedContainer) GetLeaderSize() int64

GetLeaderSize returns the leader size of the container.

func (*CachedContainer) GetLeaderWeight

func (cr *CachedContainer) GetLeaderWeight() float64

GetLeaderWeight returns the leader weight of the container.

func (*CachedContainer) GetPendingPeerCount

func (cr *CachedContainer) GetPendingPeerCount() int

GetPendingPeerCount returns the pending peer count of the container.

func (CachedContainer) GetReceivingSnapCount

func (ss CachedContainer) GetReceivingSnapCount() uint64

GetReceivingSnapCount returns the current receiving snapshot count of the container.

func (*CachedContainer) GetResourceCount

func (cr *CachedContainer) GetResourceCount() int

GetResourceCount returns the Resource count of the container.

func (*CachedContainer) GetResourceSize

func (cr *CachedContainer) GetResourceSize() int64

GetResourceSize returns the Resource size of the container.

func (*CachedContainer) GetResourceWeight

func (cr *CachedContainer) GetResourceWeight() float64

GetResourceWeight returns the Resource weight of the container.

func (CachedContainer) GetSendingSnapCount

func (ss CachedContainer) GetSendingSnapCount() uint64

GetSendingSnapCount returns the current sending snapshot count of the container.

func (*CachedContainer) GetStartTime

func (cr *CachedContainer) GetStartTime() time.Time

GetStartTime returns the start timestamp.

func (*CachedContainer) GetState

func (cr *CachedContainer) GetState() metapb.ContainerState

GetState returns the state of the container.

func (*CachedContainer) GetUptime

func (cr *CachedContainer) GetUptime() time.Duration

GetUptime returns the uptime.

func (CachedContainer) GetUsedSize

func (ss CachedContainer) GetUsedSize() uint64

GetUsedSize returns the used size of the container.

func (*CachedContainer) IsAvailable

func (cr *CachedContainer) IsAvailable(limitType limit.Type) bool

IsAvailable returns if the container bucket of limitation is available

func (CachedContainer) IsBusy

func (ss CachedContainer) IsBusy() bool

IsBusy returns if the container is busy.

func (*CachedContainer) IsDisconnected

func (cr *CachedContainer) IsDisconnected() bool

IsDisconnected checks if a container is disconnected, which means Prophet misses storage application's container heartbeat for a short time, maybe caused by process restart or temporary network failure.

func (*CachedContainer) IsLowSpace

func (cr *CachedContainer) IsLowSpace(lowSpaceRatio float64) bool

IsLowSpace checks if the container is lack of space.

func (*CachedContainer) IsOffline

func (cr *CachedContainer) IsOffline() bool

IsOffline checks if the container's state is Offline.

func (*CachedContainer) IsTombstone

func (cr *CachedContainer) IsTombstone() bool

IsTombstone checks if the container's state is Tombstone.

func (*CachedContainer) IsUnhealthy

func (cr *CachedContainer) IsUnhealthy() bool

IsUnhealthy checks if a container is unhealthy.

func (*CachedContainer) IsUp

func (cr *CachedContainer) IsUp() bool

IsUp checks if the container's state is Up.

func (*CachedContainer) LeaderScore

func (cr *CachedContainer) LeaderScore(policy SchedulePolicy, delta int64) float64

LeaderScore returns the container's leader score.

func (*CachedContainer) MergeLabels

func (cr *CachedContainer) MergeLabels(labels []metapb.Pair) []metapb.Pair

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

func (*CachedContainer) NeedPersist

func (cr *CachedContainer) NeedPersist() bool

NeedPersist returns if it needs to save to etcd.

func (*CachedContainer) ResourceCount

func (cr *CachedContainer) ResourceCount(kind metapb.ResourceKind) uint64

ResourceCount returns count of leader/resource-replica in the container.

func (*CachedContainer) ResourceScore

func (cr *CachedContainer) ResourceScore(version string, highSpaceRatio, lowSpaceRatio float64, delta int64, deviation int) float64

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

func (*CachedContainer) ResourceSize

func (cr *CachedContainer) ResourceSize(kind metapb.ResourceKind) int64

ResourceSize returns size of leader/resource-replica in the container

func (*CachedContainer) ResourceWeight

func (cr *CachedContainer) ResourceWeight(kind metapb.ResourceKind) float64

ResourceWeight returns weight of leader/resource-replica in the score

func (*CachedContainer) ShallowClone

func (cr *CachedContainer) ShallowClone(opts ...ContainerCreateOption) *CachedContainer

ShallowClone creates a copy of current CachedContainer, but not clone 'Meta'.

func (*CachedContainer) StorageSize

func (cr *CachedContainer) StorageSize() uint64

StorageSize returns container's used storage size reported from your storage.

type CachedContainers

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

CachedContainers contains information about all container.

func NewCachedContainers

func NewCachedContainers() *CachedContainers

NewCachedContainers create a CachedContainer with map of containerID to CachedContainer

func (*CachedContainers) AttachAvailableFunc

func (s *CachedContainers) AttachAvailableFunc(containerID uint64, limitType limit.Type, f func() bool)

AttachAvailableFunc attaches f to a specific container.

func (*CachedContainers) DeleteContainer

func (s *CachedContainers) DeleteContainer(container *CachedContainer)

DeleteContainer deletes tombstone record form container

func (*CachedContainers) GetContainer

func (s *CachedContainers) GetContainer(containerID uint64) *CachedContainer

GetContainer returns a copy of the CachedContainer with the specified containerID.

func (*CachedContainers) GetContainerCount

func (s *CachedContainers) GetContainerCount() int

GetContainerCount returns the total count of CachedContainer.

func (*CachedContainers) GetContainers

func (s *CachedContainers) GetContainers() []*CachedContainer

GetContainers gets a complete set of CachedContainer.

func (*CachedContainers) GetMetaContainers

func (s *CachedContainers) GetMetaContainers() []metadata.Container

GetMetaContainers gets a complete set of metadata.Container

func (*CachedContainers) PauseLeaderTransfer

func (s *CachedContainers) PauseLeaderTransfer(containerID uint64) error

PauseLeaderTransfer pauses a CachedContainer with containerID.

func (*CachedContainers) ResumeLeaderTransfer

func (s *CachedContainers) ResumeLeaderTransfer(containerID uint64)

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

func (*CachedContainers) SetContainer

func (s *CachedContainers) SetContainer(container *CachedContainer)

SetContainer sets a CachedContainer with containerID.

func (*CachedContainers) SetLeaderCount

func (s *CachedContainers) SetLeaderCount(containerID uint64, leaderCount int)

SetLeaderCount sets the leader count to a CachedContainer.

func (*CachedContainers) SetLeaderSize

func (s *CachedContainers) SetLeaderSize(containerID uint64, leaderSize int64)

SetLeaderSize sets the leader size to a CachedContainer.

func (*CachedContainers) SetPendingPeerCount

func (s *CachedContainers) SetPendingPeerCount(containerID uint64, pendingPeerCount int)

SetPendingPeerCount sets the pending count to a CachedContainer.

func (*CachedContainers) SetResourceCount

func (s *CachedContainers) SetResourceCount(containerID uint64, resourceCount int)

SetResourceCount sets the resource count to a CachedContainer.

func (*CachedContainers) SetResourceSize

func (s *CachedContainers) SetResourceSize(containerID uint64, resourceSize int64)

SetResourceSize sets the resource size to a CachedContainer.

func (*CachedContainers) TakeContainer

func (s *CachedContainers) TakeContainer(containerID uint64) *CachedContainer

TakeContainer returns the point of the origin CachedContainer with the specified containerID.

func (*CachedContainers) UpdateContainerStatus

func (s *CachedContainers) UpdateContainerStatus(containerID uint64, leaderCount int, resourceCount int, pendingPeerCount int, leaderSize int64, resourceSize int64)

UpdateContainerStatus updates the information of the container.

type CachedResource

type CachedResource struct {
	Meta metadata.Resource
	// contains filtered or unexported fields
}

CachedResource resource runtime info cached in the cache

func MergeTestResources

func MergeTestResources(resources []*CachedResource) []*CachedResource

MergeTestResources merge a set of CachedResource by resourceKey

func NewCachedResource

func NewCachedResource(res metadata.Resource, leader *metapb.Peer, opts ...ResourceCreateOption) *CachedResource

NewCachedResource creates CachedResource with resource's meta and leader peer.

func NewTestCachedResource

func NewTestCachedResource(start, end []byte) *CachedResource

NewTestCachedResource creates a CachedResource for test.

func ResourceFromHeartbeat

func ResourceFromHeartbeat(heartbeat rpcpb.ResourceHeartbeatReq, meta metadata.Resource) *CachedResource

ResourceFromHeartbeat constructs a Resource from resource heartbeat.

func SplitTestResources

func SplitTestResources(resources []*CachedResource) []*CachedResource

SplitTestResources split a set of CachedResource by the middle of resourceKey

func (*CachedResource) Clone

Clone returns a copy of current CachedResource.

func (*CachedResource) GetApproximateKeys

func (r *CachedResource) GetApproximateKeys() int64

GetApproximateKeys returns the approximate keys of the resource.

func (*CachedResource) GetApproximateSize

func (r *CachedResource) GetApproximateSize() int64

GetApproximateSize returns the approximate size of the resource.

func (*CachedResource) GetBytesRead

func (r *CachedResource) GetBytesRead() uint64

GetBytesRead returns the read bytes of the resource.

func (*CachedResource) GetBytesWritten

func (r *CachedResource) GetBytesWritten() uint64

GetBytesWritten returns the written bytes of the resource.

func (*CachedResource) GetContainerIDs

func (r *CachedResource) GetContainerIDs() map[uint64]struct{}

GetContainerIDs returns a map indicate the resource distributed.

func (*CachedResource) GetContainerLearner

func (r *CachedResource) GetContainerLearner(containerID uint64) (metapb.Peer, bool)

GetContainerLearner returns the learner peer in specified container.

func (*CachedResource) GetContainerPeer

func (r *CachedResource) GetContainerPeer(containerID uint64) (metapb.Peer, bool)

GetContainerPeer returns the peer in specified container.

func (*CachedResource) GetContainerVoter

func (r *CachedResource) GetContainerVoter(containerID uint64) (metapb.Peer, bool)

GetContainerVoter returns the voter in specified container.

func (*CachedResource) GetDiffFollowers

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

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

func (*CachedResource) GetDownLearner

func (r *CachedResource) GetDownLearner(peerID uint64) (metapb.Peer, bool)

GetDownLearner returns the down learner with soecified peer id.

func (*CachedResource) GetDownPeer

func (r *CachedResource) GetDownPeer(peerID uint64) (metapb.Peer, bool)

GetDownPeer returns the down peer with specified peer id.

func (*CachedResource) GetDownPeers

func (r *CachedResource) GetDownPeers() []metapb.PeerStats

GetDownPeers returns the down peers of the resource.

func (*CachedResource) GetDownVoter

func (r *CachedResource) GetDownVoter(peerID uint64) (metapb.Peer, bool)

GetDownVoter returns the down voter with specified peer id.

func (*CachedResource) GetEndKey

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

GetEndKey returns the end key of the resource.

func (*CachedResource) GetFollower

func (r *CachedResource) GetFollower() (metapb.Peer, bool)

GetFollower randomly returns a follow peer.

func (*CachedResource) GetFollowers

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

GetFollowers returns a map indicate the follow peers distributed.

func (*CachedResource) GetInterval

func (r *CachedResource) GetInterval() *rpcpb.TimeInterval

GetInterval returns the interval information of the resource.

func (*CachedResource) GetKeysRead

func (r *CachedResource) GetKeysRead() uint64

GetKeysRead returns the read keys of the resource.

func (*CachedResource) GetKeysWritten

func (r *CachedResource) GetKeysWritten() uint64

GetKeysWritten returns the written keys of the resource.

func (*CachedResource) GetLeader

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

GetLeader returns the leader of the resource.

func (*CachedResource) GetLearners

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

GetLearners returns the learners.

func (*CachedResource) GetPeer

func (r *CachedResource) GetPeer(peerID uint64) (metapb.Peer, bool)

GetPeer returns the peer with specified peer id.

func (*CachedResource) GetPendingLearner

func (r *CachedResource) GetPendingLearner(peerID uint64) (metapb.Peer, bool)

GetPendingLearner returns the pending learner peer with specified peer id.

func (*CachedResource) GetPendingPeer

func (r *CachedResource) GetPendingPeer(peerID uint64) (metapb.Peer, bool)

GetPendingPeer returns the pending peer with specified peer id.

func (*CachedResource) GetPendingPeers

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

GetPendingPeers returns the pending peers of the resource.

func (*CachedResource) GetPendingVoter

func (r *CachedResource) GetPendingVoter(peerID uint64) (metapb.Peer, bool)

GetPendingVoter returns the pending voter with specified peer id.

func (*CachedResource) GetStartKey

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

GetStartKey returns the start key of the resource.

func (*CachedResource) GetStat

func (r *CachedResource) GetStat() *metapb.ResourceStat

GetStat returns the statistics of the resource.

func (*CachedResource) GetTerm

func (r *CachedResource) GetTerm() uint64

GetTerm returns the current term of the resource

func (*CachedResource) GetVoters

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

GetVoters returns the voters.

type CachedResources

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

CachedResources for export

func NewCachedResources

func NewCachedResources(factory func() metadata.Resource) *CachedResources

NewCachedResources creates CachedResources with tree, resources, leaders and followers

func (*CachedResources) AddResource

func (r *CachedResources) AddResource(res *CachedResource) []*CachedResource

AddResource adds CachedResource to resourceTree and resourceMap, also update leaders and followers by resource peers

func (*CachedResources) GetAdjacentResources

func (r *CachedResources) GetAdjacentResources(res *CachedResource) (*CachedResource, *CachedResource)

GetAdjacentResources returns resource's info that is adjacent with specific resource

func (*CachedResources) GetAverageResourceSize

func (r *CachedResources) GetAverageResourceSize() int64

GetAverageResourceSize returns the average resource approximate size.

func (*CachedResources) GetContainerFollowerCount

func (r *CachedResources) GetContainerFollowerCount(containerID uint64) int

GetContainerFollowerCount get the total count of a container's follower CachedResource

func (*CachedResources) GetContainerFollowerResourceSize

func (r *CachedResources) GetContainerFollowerResourceSize(containerID uint64) int64

GetContainerFollowerResourceSize get total size of container's follower resources

func (*CachedResources) GetContainerLeaderCount

func (r *CachedResources) GetContainerLeaderCount(containerID uint64) int

GetContainerLeaderCount get the total count of a container's leader CachedResource

func (*CachedResources) GetContainerLeaderResourceSize

func (r *CachedResources) GetContainerLeaderResourceSize(containerID uint64) int64

GetContainerLeaderResourceSize get total size of container's leader resources

func (*CachedResources) GetContainerLearnerCount

func (r *CachedResources) GetContainerLearnerCount(containerID uint64) int

GetContainerLearnerCount get the total count of a container's learner CachedResource

func (*CachedResources) GetContainerLearnerResourceSize

func (r *CachedResources) GetContainerLearnerResourceSize(containerID uint64) int64

GetContainerLearnerResourceSize get total size of container's learner resources

func (*CachedResources) GetContainerPendingPeerCount

func (r *CachedResources) GetContainerPendingPeerCount(containerID uint64) int

GetContainerPendingPeerCount gets the total count of a container's resource that includes pending peer

func (*CachedResources) GetContainerResourceCount

func (r *CachedResources) GetContainerResourceCount(containerID uint64) int

GetContainerResourceCount gets the total count of a container's leader, follower and learner CachedResource by containerID

func (*CachedResources) GetContainerResourceSize

func (r *CachedResources) GetContainerResourceSize(containerID uint64) int64

GetContainerResourceSize get total size of container's resources

func (*CachedResources) GetContainerResources

func (r *CachedResources) GetContainerResources(containerID uint64) []*CachedResource

GetContainerResources gets all CachedResource with a given containerID

func (*CachedResources) GetFollower

func (r *CachedResources) GetFollower(containerID uint64, res *CachedResource) *CachedResource

GetFollower return follower CachedResource by containerID and resourceID(now only used in test)

func (*CachedResources) GetLeader

func (r *CachedResources) GetLeader(containerID uint64, res *CachedResource) *CachedResource

GetLeader return leader CachedResource by containerID and resourceID(now only used in test)

func (*CachedResources) GetMetaResources

func (r *CachedResources) GetMetaResources() []metadata.Resource

GetMetaResources gets a set of metadata.Resource from resourceMap

func (*CachedResources) GetOverlaps

func (r *CachedResources) GetOverlaps(res *CachedResource) []*CachedResource

GetOverlaps returns the resources which are overlapped with the specified resource range.

func (*CachedResources) GetResource

func (r *CachedResources) GetResource(resourceID uint64) *CachedResource

GetResource returns the CachedResource with resourceID

func (*CachedResources) GetResourceCount

func (r *CachedResources) GetResourceCount() int

GetResourceCount gets the total count of CachedResource of resourceMap

func (*CachedResources) GetResources

func (r *CachedResources) GetResources() []*CachedResource

GetResources gets all CachedResource from resourceMap

func (*CachedResources) Length

func (r *CachedResources) Length() int

Length returns the resourcesInfo length

func (*CachedResources) RandFollowerResource

func (r *CachedResources) RandFollowerResource(containerID uint64, ranges []KeyRange) *CachedResource

RandFollowerResource randomly gets a container's follower resource.

func (*CachedResources) RandFollowerResources

func (r *CachedResources) RandFollowerResources(containerID uint64, ranges []KeyRange, n int) []*CachedResource

RandFollowerResources randomly gets a container's n follower resources.

func (*CachedResources) RandLeaderResource

func (r *CachedResources) RandLeaderResource(containerID uint64, ranges []KeyRange) *CachedResource

RandLeaderResource randomly gets a container's leader resource.

func (*CachedResources) RandLeaderResources

func (r *CachedResources) RandLeaderResources(containerID uint64, ranges []KeyRange, n int) []*CachedResource

RandLeaderResources randomly gets a container's n leader resources.

func (*CachedResources) RandLearnerResource

func (r *CachedResources) RandLearnerResource(containerID uint64, ranges []KeyRange) *CachedResource

RandLearnerResource randomly gets a container's learner resource.

func (*CachedResources) RandLearnerResources

func (r *CachedResources) RandLearnerResources(containerID uint64, ranges []KeyRange, n int) []*CachedResource

RandLearnerResources randomly gets a container's n learner resources.

func (*CachedResources) RandPendingResource

func (r *CachedResources) RandPendingResource(containerID uint64, ranges []KeyRange) *CachedResource

RandPendingResource randomly gets a container's resource with a pending peer.

func (*CachedResources) RandPendingResources

func (r *CachedResources) RandPendingResources(containerID uint64, ranges []KeyRange, n int) []*CachedResource

RandPendingResources randomly gets a container's n resources with a pending peer.

func (*CachedResources) RemoveResource

func (r *CachedResources) RemoveResource(res *CachedResource)

RemoveResource removes CachedResource from resourceTree and resourceMap

func (*CachedResources) ScanRange

func (r *CachedResources) ScanRange(startKey, endKey []byte, limit int) []*CachedResource

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

func (*CachedResources) ScanRangeWithIterator

func (r *CachedResources) ScanRangeWithIterator(startKey []byte, iterator func(res *CachedResource) bool)

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

func (*CachedResources) SearchPrevResource

func (r *CachedResources) SearchPrevResource(resKey []byte) *CachedResource

SearchPrevResource searches previous CachedResource from resourceTree

func (*CachedResources) SearchResource

func (r *CachedResources) SearchResource(resKey []byte) *CachedResource

SearchResource searches CachedResource from resourceTree

func (*CachedResources) SetResource

func (r *CachedResources) SetResource(res *CachedResource) []*CachedResource

SetResource sets the CachedResource with resourceID

func (*CachedResources) TreeLength

func (r *CachedResources) TreeLength() int

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

type ContainerCreateOption

type ContainerCreateOption func(container *CachedContainer)

ContainerCreateOption is used to create container.

func AttachAvailableFunc

func AttachAvailableFunc(limitType limit.Type, f func() bool) ContainerCreateOption

AttachAvailableFunc attaches a customize function for the container. The function f returns true if the container limit is not exceeded.

func PauseLeaderTransfer

func PauseLeaderTransfer() ContainerCreateOption

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

func ResumeLeaderTransfer

func ResumeLeaderTransfer() ContainerCreateOption

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

func SetContainerAddress

func SetContainerAddress(address, shardAddress string) ContainerCreateOption

SetContainerAddress sets the address for the container.

func SetContainerDeployPath

func SetContainerDeployPath(deployPath string) ContainerCreateOption

SetContainerDeployPath sets the deploy path for the container.

func SetContainerLabels

func SetContainerLabels(labels []metapb.Pair) ContainerCreateOption

SetContainerLabels sets the labels for the container.

func SetContainerStartTime

func SetContainerStartTime(startTS int64) ContainerCreateOption

SetContainerStartTime sets the start timestamp for the container.

func SetContainerState

func SetContainerState(state metapb.ContainerState) ContainerCreateOption

SetContainerState sets the state for the container.

func SetContainerStats

func SetContainerStats(stats *rpcpb.ContainerStats) ContainerCreateOption

SetContainerStats sets the statistics information for the container.

func SetContainerVersion

func SetContainerVersion(githash, version string) ContainerCreateOption

SetContainerVersion sets the version for the container.

func SetLastHeartbeatTS

func SetLastHeartbeatTS(lastHeartbeatTS time.Time) ContainerCreateOption

SetLastHeartbeatTS sets the time of last heartbeat for the container.

func SetLastPersistTime

func SetLastPersistTime(lastPersist time.Time) ContainerCreateOption

SetLastPersistTime updates the time of last persistent.

func SetLeaderCount

func SetLeaderCount(leaderCount int) ContainerCreateOption

SetLeaderCount sets the leader count for the container.

func SetLeaderSize

func SetLeaderSize(leaderSize int64) ContainerCreateOption

SetLeaderSize sets the leader size for the container.

func SetLeaderWeight

func SetLeaderWeight(leaderWeight float64) ContainerCreateOption

SetLeaderWeight sets the leader weight for the container.

func SetPendingPeerCount

func SetPendingPeerCount(pendingPeerCount int) ContainerCreateOption

SetPendingPeerCount sets the pending peer count for the container.

func SetResourceCount

func SetResourceCount(resourceCount int) ContainerCreateOption

SetResourceCount sets the Resource count for the container.

func SetResourceSize

func SetResourceSize(resourceSize int64) ContainerCreateOption

SetResourceSize sets the Resource size for the container.

func SetResourceWeight

func SetResourceWeight(resourceWeight float64) ContainerCreateOption

SetResourceWeight sets the Resource weight for the container.

type ContainerSetController

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

	AttachAvailableFunc(id uint64, limitType limit.Type, f func() bool)
}

ContainerSetController is used to control containers' status.

type ContainerSetInformer

type ContainerSetInformer interface {
	GetContainers() []*CachedContainer
	GetContainer(id uint64) *CachedContainer

	GetResourceContainers(res *CachedResource) []*CachedContainer
	GetFollowerContainers(res *CachedResource) []*CachedContainer
	GetLeaderContainer(res *CachedResource) *CachedContainer
}

ContainerSetInformer provides access to a shared informer of containers.

type HexResourceMeta

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

HexResourceMeta is a resource meta in the hex format. Used for formating resource in logs.

func ResourceToHexMeta

func ResourceToHexMeta(meta metadata.Resource) HexResourceMeta

ResourceToHexMeta converts a resource meta's keys to hex format. Used for formating resource in logs.

func (HexResourceMeta) String

func (h HexResourceMeta) String() string

type HexResourcesMeta

type HexResourcesMeta []metadata.Resource

HexResourcesMeta is a slice of resources' meta in the hex format. Used for formating resource in logs.

func ResourcesToHexMeta

func ResourcesToHexMeta(resources []metadata.Resource) HexResourcesMeta

ResourcesToHexMeta converts resources' meta keys to hex format. Used for formating resource in logs.

func (HexResourcesMeta) String

func (h HexResourcesMeta) String() string

type KeyRange

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

KeyRange is a key range.

func NewKeyRange

func NewKeyRange(startKey, endKey string) KeyRange

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

type KeyType

type KeyType int

KeyType distinguishes different kinds of key types

const (
	// Table indicates that the key is table key
	Table KeyType = iota
	// Raw indicates that the key is raw key.
	Raw
	// Txn indicates that the key is txn key.
	Txn
)

func StringToKeyType

func StringToKeyType(input string) KeyType

StringToKeyType creates a key type with string.

func (KeyType) String

func (k KeyType) String() string

type PriorityLevel

type PriorityLevel int

PriorityLevel lower level means higher priority

const (
	LowPriority PriorityLevel = iota
	NormalPriority
	HighPriority
)

Built-in priority level

type ResourceCreateOption

type ResourceCreateOption func(res *CachedResource)

ResourceCreateOption used to create resource.

func SetApproximateKeys

func SetApproximateKeys(v int64) ResourceCreateOption

SetApproximateKeys sets the approximate keys for the resource.

func SetApproximateSize

func SetApproximateSize(v int64) ResourceCreateOption

SetApproximateSize sets the approximate size for the resource.

func SetPeers

func SetPeers(peers []metapb.Peer) ResourceCreateOption

SetPeers sets the peers for the resource.

func SetReadBytes

func SetReadBytes(v uint64) ResourceCreateOption

SetReadBytes sets the read bytes for the resource.

func SetReadKeys

func SetReadKeys(v uint64) ResourceCreateOption

SetReadKeys sets the read keys for the resource.

func SetReportInterval

func SetReportInterval(v uint64) ResourceCreateOption

SetReportInterval sets the report interval for the resource.

func SetResourceConfVer

func SetResourceConfVer(confVer uint64) ResourceCreateOption

SetResourceConfVer sets the config version for the resource.

func SetResourceVersion

func SetResourceVersion(version uint64) ResourceCreateOption

SetResourceVersion sets the version for the resource.

func SetWrittenBytes

func SetWrittenBytes(v uint64) ResourceCreateOption

SetWrittenBytes sets the written bytes for the resource.

func SetWrittenKeys

func SetWrittenKeys(v uint64) ResourceCreateOption

SetWrittenKeys sets the written keys for the resource.

func WithAddPeer

func WithAddPeer(peer metapb.Peer) ResourceCreateOption

WithAddPeer adds a peer for the resource.

func WithDecConfVer

func WithDecConfVer() ResourceCreateOption

WithDecConfVer decreases the config version of the resource.

func WithDecVersion

func WithDecVersion() ResourceCreateOption

WithDecVersion decreases the version of the resource.

func WithDownPeers

func WithDownPeers(downPeers []metapb.PeerStats) ResourceCreateOption

WithDownPeers sets the down peers for the resource.

func WithEndKey

func WithEndKey(key []byte) ResourceCreateOption

WithEndKey sets the end key for the resource.

func WithIncConfVer

func WithIncConfVer() ResourceCreateOption

WithIncConfVer increases the config version of the resource.

func WithIncVersion

func WithIncVersion() ResourceCreateOption

WithIncVersion increases the version of the resource.

func WithLeader

func WithLeader(leader *metapb.Peer) ResourceCreateOption

WithLeader sets the leader for the resource.

func WithLearners

func WithLearners(learners []metapb.Peer) ResourceCreateOption

WithLearners sets the learners for the resource.

func WithNewPeerIds

func WithNewPeerIds(peerIDs ...uint64) ResourceCreateOption

WithNewPeerIds sets new ids for peers.

func WithNewResourceID

func WithNewResourceID(id uint64) ResourceCreateOption

WithNewResourceID sets new id for the resource.

func WithPendingPeers

func WithPendingPeers(pendingPeers []metapb.Peer) ResourceCreateOption

WithPendingPeers sets the pending peers for the resource.

func WithPromoteLearner

func WithPromoteLearner(peerID uint64) ResourceCreateOption

WithPromoteLearner promotes the learner.

func WithRemoveContainerPeer

func WithRemoveContainerPeer(containerID uint64) ResourceCreateOption

WithRemoveContainerPeer removes the specified peer for the resource.

func WithReplacePeerContainer

func WithReplacePeerContainer(oldContainerID, newContainerID uint64) ResourceCreateOption

WithReplacePeerContainer replaces a peer's containerID with another ID.

func WithStartKey

func WithStartKey(key []byte) ResourceCreateOption

WithStartKey sets the start key for the resource.

type ResourceOption

type ResourceOption func(res *CachedResource) bool

ResourceOption is used to select resource.

type ResourceSetInformer

type ResourceSetInformer interface {
	GetResourceCount() int
	RandFollowerResource(containerID uint64, ranges []KeyRange, opts ...ResourceOption) *CachedResource
	RandLeaderResource(containerID uint64, ranges []KeyRange, opts ...ResourceOption) *CachedResource
	RandLearnerResource(containerID uint64, ranges []KeyRange, opts ...ResourceOption) *CachedResource
	RandPendingResource(containerID uint64, ranges []KeyRange, opts ...ResourceOption) *CachedResource
	GetAverageResourceSize() int64
	GetContainerResourceCount(containerID uint64) int
	GetResource(id uint64) *CachedResource
	GetAdjacentResources(res *CachedResource) (*CachedResource, *CachedResource)
	ScanResources(startKey, endKey []byte, limit int) []*CachedResource
	GetResourceByKey(resKey []byte) *CachedResource
}

ResourceSetInformer provides access to a shared informer of resources.

type ScheduleKind

type ScheduleKind struct {
	ResourceKind metapb.ResourceKind
	Policy       SchedulePolicy
}

ScheduleKind distinguishes resources and schedule policy.

func NewScheduleKind

func NewScheduleKind(kind metapb.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

Jump to

Keyboard shortcuts

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