Documentation
¶
Overview ¶
Copyright 2022 PingCAP, Inc. Licensed under Apache-2.0.
Index ¶
- Constants
- Variables
- func CheckPartRegionConsistency(startKey, endKey []byte, regions []*RegionInfo) error
- func CheckRegionConsistency(startKey, endKey []byte, regions []*RegionInfo) error
- func CheckRegionEpoch(_new, _old *RegionInfo) bool
- func PdErrorCanRetry(err error) bool
- type ExponentialBackoffer
- type RegionInfo
- type Span
- type SplitClient
- type SplitHelper
- type Value
- type Valued
Constants ¶
const ( SplitRetryTimes = 32 SplitRetryInterval = 50 * time.Millisecond SplitMaxRetryInterval = time.Second SplitCheckMaxRetryTimes = 64 SplitCheckInterval = 8 * time.Millisecond SplitMaxCheckInterval = time.Second ScatterWaitMaxRetryTimes = 64 ScatterWaitInterval = 50 * time.Millisecond ScatterMaxWaitInterval = time.Second ScatterWaitUpperInterval = 180 * time.Second ScanRegionPaginationLimit = 128 RejectStoreCheckRetryTimes = 64 RejectStoreCheckInterval = 100 * time.Millisecond RejectStoreMaxCheckInterval = 2 * time.Second )
Constants for split retry machinery.
Variables ¶
var (
ScanRegionAttemptTimes = 128
)
Functions ¶
func CheckPartRegionConsistency ¶
func CheckPartRegionConsistency(startKey, endKey []byte, regions []*RegionInfo) error
CheckPartRegionConsistency only checks the continuity of regions and the first region consistency.
func CheckRegionConsistency ¶
func CheckRegionConsistency(startKey, endKey []byte, regions []*RegionInfo) error
func CheckRegionEpoch ¶
func CheckRegionEpoch(_new, _old *RegionInfo) bool
CheckRegionEpoch check region epoch.
Types ¶
type ExponentialBackoffer ¶
ExponentialBackoffer trivially retry any errors it meets. It's useful when the caller has handled the errors but only want to a more semantic backoff implementation.
func (*ExponentialBackoffer) Attempt ¶
func (b *ExponentialBackoffer) Attempt() int
Attempt returns the remain attempt times
func (*ExponentialBackoffer) NextBackoff ¶
func (b *ExponentialBackoffer) NextBackoff(error) time.Duration
NextBackoff returns a duration to wait before retrying again.
type RegionInfo ¶
type RegionInfo struct {
Region *metapb.Region
Leader *metapb.Peer
PendingPeers []*metapb.Peer
DownPeers []*metapb.Peer
}
RegionInfo includes a region and the leader of the region.
func PaginateScanRegion ¶
func PaginateScanRegion( ctx context.Context, client SplitClient, startKey, endKey []byte, limit int, ) ([]*RegionInfo, error)
PaginateScanRegion scan regions with a limit pagination and return all regions at once. It reduces max gRPC message size.
func ScanRegionsWithRetry ¶
func ScanRegionsWithRetry( ctx context.Context, client SplitClient, startKey, endKey []byte, limit int, ) ([]*RegionInfo, error)
func (*RegionInfo) ContainsInterior ¶
func (region *RegionInfo) ContainsInterior(key []byte) bool
ContainsInterior returns whether the region contains the given key, and also that the key does not fall on the boundary (start key) of the region.
type SplitClient ¶
type SplitClient interface {
// GetStore gets a store by a store id.
GetStore(ctx context.Context, storeID uint64) (*metapb.Store, error)
// GetRegion gets a region which includes a specified key.
GetRegion(ctx context.Context, key []byte) (*RegionInfo, error)
// GetRegionByID gets a region by a region id.
GetRegionByID(ctx context.Context, regionID uint64) (*RegionInfo, error)
// SplitRegion splits a region from a key, if key is not included in the region, it will return nil.
// note: the key should not be encoded
SplitRegion(ctx context.Context, regionInfo *RegionInfo, key []byte) (*RegionInfo, error)
// BatchSplitRegions splits a region from a batch of keys.
// note: the keys should not be encoded
BatchSplitRegions(ctx context.Context, regionInfo *RegionInfo, keys [][]byte) ([]*RegionInfo, error)
// BatchSplitRegionsWithOrigin splits a region from a batch of keys and return the original region and split new regions
BatchSplitRegionsWithOrigin(ctx context.Context, regionInfo *RegionInfo, keys [][]byte) (*RegionInfo, []*RegionInfo, error)
// ScatterRegion scatters a specified region.
ScatterRegion(ctx context.Context, regionInfo *RegionInfo) error
// ScatterRegions scatters regions in a batch.
ScatterRegions(ctx context.Context, regionInfo []*RegionInfo) error
// GetOperator gets the status of operator of the specified region.
GetOperator(ctx context.Context, regionID uint64) (*pdpb.GetOperatorResponse, error)
// ScanRegions gets a list of regions, starts from the region that contains key.
// Limit limits the maximum number of regions returned.
ScanRegions(ctx context.Context, key, endKey []byte, limit int) ([]*RegionInfo, error)
// GetPlacementRule loads a placement rule from PD.
GetPlacementRule(ctx context.Context, groupID, ruleID string) (pdtypes.Rule, error)
// SetPlacementRule insert or update a placement rule to PD.
SetPlacementRule(ctx context.Context, rule pdtypes.Rule) error
// DeletePlacementRule removes a placement rule from PD.
DeletePlacementRule(ctx context.Context, groupID, ruleID string) error
// SetStoresLabel add or update specified label of stores. If labelValue
// is empty, it clears the label.
SetStoresLabel(ctx context.Context, stores []uint64, labelKey, labelValue string) error
}
SplitClient is an external client used by RegionSplitter.
func NewSplitClient ¶
NewSplitClient returns a client used by RegionSplitter.
type SplitHelper ¶
type SplitHelper struct {
// contains filtered or unexported fields
}
SplitHelper represents a set of valued ranges, which doesn't overlap and union of them all is the full key space.
func NewSplitHelper ¶
func NewSplitHelper() *SplitHelper
NewSplitHelper creates a set of a subset of spans, with the full key space as initial status
func (*SplitHelper) Merge ¶
func (f *SplitHelper) Merge(val Valued)
func (*SplitHelper) Traverse ¶
func (f *SplitHelper) Traverse(m func(Valued) bool)
traverse the items in ascend order