locate

package
v2.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LabelFilterAllNode = func(_ []*metapb.StoreLabel) bool {
	return true
}

LabelFilterAllNode will select all stores.

View Source
var LabelFilterAllTiFlashNode = func(labels []*metapb.StoreLabel) bool {
	return isStoreContainLabel(labels, tikvrpc.EngineLabelKey, tikvrpc.EngineLabelTiFlash)
}

LabelFilterAllTiFlashNode will select all tiflash stores.

View Source
var LabelFilterNoTiFlashWriteNode = func(labels []*metapb.StoreLabel) bool {
	return isStoreContainLabel(labels, tikvrpc.EngineLabelKey, tikvrpc.EngineLabelTiFlash) &&
		!isStoreContainLabel(labels, tikvrpc.EngineRoleLabelKey, tikvrpc.EngineRoleWrite)
}

LabelFilterNoTiFlashWriteNode will only select stores whose label contains: <engine, tiflash>, but not contains <engine_role, write>. Normally tidb use this filter.

View Source
var LabelFilterOnlyTiFlashWriteNode = func(labels []*metapb.StoreLabel) bool {
	return isStoreContainLabel(labels, tikvrpc.EngineLabelKey, tikvrpc.EngineLabelTiFlash) &&
		isStoreContainLabel(labels, tikvrpc.EngineRoleLabelKey, tikvrpc.EngineRoleWrite)
}

LabelFilterOnlyTiFlashWriteNode will only select stores whose label contains: <engine, tiflash> and <engine_role, write>. Only used for tiflash_compute node.

Functions

func GetKeyspaceID added in v2.0.5

func GetKeyspaceID(client pd.Client, name string) (uint32, error)

GetKeyspaceID attempts to retrieve keyspace ID corresponding to the given keyspace name from PD.

func GetStoreLivenessTimeout

func GetStoreLivenessTimeout() time.Duration

GetStoreLivenessTimeout returns storeLivenessTimeout.

func IsFakeRegionError

func IsFakeRegionError(err *errorpb.Error) bool

IsFakeRegionError returns true if err is fake region error.

func LoadShuttingDown

func LoadShuttingDown() uint32

LoadShuttingDown atomically loads ShuttingDown.

func RecordRegionRequestRuntimeStats

func RecordRegionRequestRuntimeStats(stats map[tikvrpc.CmdType]*RPCRuntimeStats, cmd tikvrpc.CmdType, d time.Duration)

RecordRegionRequestRuntimeStats records request runtime stats.

func SetRegionCacheTTLSec

func SetRegionCacheTTLSec(t int64)

SetRegionCacheTTLSec sets regionCacheTTLSec to t.

func SetStoreLivenessTimeout

func SetStoreLivenessTimeout(t time.Duration)

SetStoreLivenessTimeout sets storeLivenessTimeout to t.

func StoreShuttingDown

func StoreShuttingDown(v uint32)

StoreShuttingDown atomically stores ShuttingDown into v.

Types

type AccessIndex

type AccessIndex int

AccessIndex represent the index for accessIndex array

type Bucket added in v2.0.2

type Bucket struct {
	StartKey []byte
	EndKey   []byte
}

Bucket is a single bucket of a region.

func (*Bucket) Contains added in v2.0.2

func (b *Bucket) Contains(key []byte) bool

Contains checks whether the key is in the Bucket.

type CodecPDClient

type CodecPDClient struct {
	pd.Client
	// contains filtered or unexported fields
}

CodecPDClient wraps a PD Client to decode the encoded keys in region meta.

func NewCodecPDClient added in v2.0.5

func NewCodecPDClient(mode apicodec.Mode, client pd.Client) *CodecPDClient

NewCodecPDClient creates a CodecPDClient in API v1.

func NewCodecPDClientWithKeyspace added in v2.0.5

func NewCodecPDClientWithKeyspace(mode apicodec.Mode, client pd.Client, keyspace string) (*CodecPDClient, error)

NewCodecPDClientWithKeyspace creates a CodecPDClient in API v2 with keyspace name.

func (*CodecPDClient) GetCodec added in v2.0.5

func (c *CodecPDClient) GetCodec() apicodec.Codec

GetCodec returns CodecPDClient's codec.

func (*CodecPDClient) GetPrevRegion

func (c *CodecPDClient) GetPrevRegion(ctx context.Context, key []byte, opts ...pd.GetRegionOption) (*pd.Region, error)

GetPrevRegion encodes the key before send requests to pd-server and decodes the returned StartKey && EndKey from pd-server.

func (*CodecPDClient) GetRegion

func (c *CodecPDClient) GetRegion(ctx context.Context, key []byte, opts ...pd.GetRegionOption) (*pd.Region, error)

GetRegion encodes the key before send requests to pd-server and decodes the returned StartKey && EndKey from pd-server.

func (*CodecPDClient) GetRegionByID

func (c *CodecPDClient) GetRegionByID(ctx context.Context, regionID uint64, opts ...pd.GetRegionOption) (*pd.Region, error)

GetRegionByID encodes the key before send requests to pd-server and decodes the returned StartKey && EndKey from pd-server.

func (*CodecPDClient) ScanRegions

func (c *CodecPDClient) ScanRegions(ctx context.Context, startKey []byte, endKey []byte, limit int) ([]*pd.Region, error)

ScanRegions encodes the key before send requests to pd-server and decodes the returned StartKey && EndKey from pd-server.

func (*CodecPDClient) SplitRegions added in v2.0.5

func (c *CodecPDClient) SplitRegions(ctx context.Context, splitKeys [][]byte, opts ...pd.RegionsOption) (*pdpb.SplitRegionsResponse, error)

SplitRegions split regions by given split keys

type CountSlidingWindow added in v2.0.6

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

CountSlidingWindow represents the statistics on a bunch of sliding windows.

func (*CountSlidingWindow) Append added in v2.0.6

func (cnt *CountSlidingWindow) Append(value uint64) (gradient float64)

Append adds one value into this sliding windown and returns the gradient.

func (*CountSlidingWindow) Avg added in v2.0.6

func (cnt *CountSlidingWindow) Avg() uint64

Avg returns the average value of this sliding window

func (*CountSlidingWindow) Sum added in v2.0.6

func (cnt *CountSlidingWindow) Sum() uint64

Sum returns the sum value of this sliding window

type InvalidReason

type InvalidReason int32

InvalidReason is the reason why a cached region is invalidated. The region cache may take different strategies to handle different reasons. For example, when a cached region is invalidated due to no leader, region cache will always access to a different peer.

const (
	// Ok indicates the cached region is valid
	Ok InvalidReason = iota
	// NoLeader indicates it's invalidated due to no leader
	NoLeader
	// RegionNotFound indicates it's invalidated due to region not found in the store
	RegionNotFound
	// EpochNotMatch indicates it's invalidated due to epoch not match
	EpochNotMatch
	// StoreNotFound indicates it's invalidated due to store not found in PD
	StoreNotFound
	// Other indicates it's invalidated due to other reasons, e.g., the store
	// is removed from the cluster, fail to send requests to the store.
	Other
)

type KeyLocation

type KeyLocation struct {
	Region   RegionVerID
	StartKey []byte
	EndKey   []byte
	Buckets  *metapb.Buckets
}

KeyLocation is the region and range that a key is located.

func (*KeyLocation) Contains

func (l *KeyLocation) Contains(key []byte) bool

Contains checks if key is in [StartKey, EndKey).

func (*KeyLocation) GetBucketVersion added in v2.0.2

func (l *KeyLocation) GetBucketVersion() uint64

GetBucketVersion gets the bucket version of the region. If the region doesn't contain buckets, returns 0.

func (*KeyLocation) LocateBucket added in v2.0.2

func (l *KeyLocation) LocateBucket(key []byte) *Bucket

LocateBucket handles with a type of edge case of locateBucket that returns nil. There are two cases where locateBucket returns nil: Case one is that the key neither does not belong to any bucket nor does not belong to the region. Case two is that the key belongs to the region but not any bucket. LocateBucket will not return nil in the case two. Specifically, when the key is in [KeyLocation.StartKey, first Bucket key), the result returned by locateBucket will be nil as there's no bucket containing this key. LocateBucket will return Bucket{KeyLocation.StartKey, first Bucket key} as it's reasonable to assume that Bucket{KeyLocation.StartKey, first Bucket key} is a bucket belonging to the region. Key in [last Bucket key, KeyLocation.EndKey) is handled similarly.

func (*KeyLocation) String

func (l *KeyLocation) String() string

String implements fmt.Stringer interface.

type LabelFilter added in v2.0.7

type LabelFilter = func(labels []*metapb.StoreLabel) bool

LabelFilter returns false means label doesn't match, and will ignore this store.

type RPCCanceller

type RPCCanceller struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RPCCanceller is rpc send cancelFunc collector.

func NewRPCanceller

func NewRPCanceller() *RPCCanceller

NewRPCanceller creates RPCCanceller with init state.

func (*RPCCanceller) CancelAll

func (h *RPCCanceller) CancelAll()

CancelAll cancels all inflight rpc context.

func (*RPCCanceller) WithCancel

func (h *RPCCanceller) WithCancel(ctx context.Context) (context.Context, func())

WithCancel generates new context with cancel func.

type RPCCancellerCtxKey

type RPCCancellerCtxKey struct{}

RPCCancellerCtxKey is context key attach rpc send cancelFunc collector to ctx.

type RPCContext

type RPCContext struct {
	Region     RegionVerID
	Meta       *metapb.Region
	Peer       *metapb.Peer
	AccessIdx  AccessIndex
	Store      *Store
	Addr       string
	AccessMode accessMode
	ProxyStore *Store // nil means proxy is not used
	ProxyAddr  string // valid when ProxyStore is not nil
	TiKVNum    int    // Number of TiKV nodes among the region's peers. Assuming non-TiKV peers are all TiFlash peers.
	// contains filtered or unexported fields
}

RPCContext contains data that is needed to send RPC to a region.

func (*RPCContext) String

func (c *RPCContext) String() string

type RPCRuntimeStats

type RPCRuntimeStats struct {
	Count int64
	// Send region request consume time.
	Consume int64
}

RPCRuntimeStats indicates the RPC request count and consume time.

type Region

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

Region presents kv region

func (*Region) AnyStorePeer

func (r *Region) AnyStorePeer(rs *regionStore, followerStoreSeed uint32, op *storeSelectorOp) (store *Store, peer *metapb.Peer, accessIdx AccessIndex, storeIdx int)

AnyStorePeer returns a leader or follower store with the associated peer.

func (*Region) Contains

func (r *Region) Contains(key []byte) bool

Contains checks whether the key is in the region, for the maximum region endKey is empty. startKey <= key < endKey.

func (*Region) ContainsByEnd

func (r *Region) ContainsByEnd(key []byte) bool

ContainsByEnd check the region contains the greatest key that is less than key. for the maximum region endKey is empty. startKey < key <= endKey.

func (*Region) EndKey

func (r *Region) EndKey() []byte

EndKey returns EndKey.

func (*Region) FollowerStorePeer

func (r *Region) FollowerStorePeer(rs *regionStore, followerStoreSeed uint32, op *storeSelectorOp) (store *Store, peer *metapb.Peer, accessIdx AccessIndex, storeIdx int)

FollowerStorePeer returns a follower store with follower peer.

func (*Region) GetID

func (r *Region) GetID() uint64

GetID returns id.

func (*Region) GetLeaderPeerID

func (r *Region) GetLeaderPeerID() uint64

GetLeaderPeerID returns leader peer ID.

func (*Region) GetLeaderStoreID

func (r *Region) GetLeaderStoreID() uint64

GetLeaderStoreID returns the store ID of the leader region.

func (*Region) GetMeta

func (r *Region) GetMeta() *metapb.Region

GetMeta returns region meta.

func (*Region) StartKey

func (r *Region) StartKey() []byte

StartKey returns StartKey.

func (*Region) VerID

func (r *Region) VerID() RegionVerID

VerID returns the Region's RegionVerID.

func (*Region) WorkStorePeer

func (r *Region) WorkStorePeer(rs *regionStore) (store *Store, peer *metapb.Peer, accessIdx AccessIndex, storeIdx int)

WorkStorePeer returns current work store with work peer.

type RegionCache

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

RegionCache caches Regions loaded from PD. All public methods of this struct should be thread-safe, unless explicitly pointed out or the method is for testing purposes only.

func NewRegionCache

func NewRegionCache(pdClient pd.Client) *RegionCache

NewRegionCache creates a RegionCache.

func (*RegionCache) BatchLoadRegionsFromKey

func (c *RegionCache) BatchLoadRegionsFromKey(bo *retry.Backoffer, startKey []byte, count int) ([]byte, error)

BatchLoadRegionsFromKey loads at most given numbers of regions to the RegionCache, from the given startKey. Returns the endKey of the last loaded region. If some of the regions has no leader, their entries in RegionCache will not be updated.

func (*RegionCache) BatchLoadRegionsWithKeyRange

func (c *RegionCache) BatchLoadRegionsWithKeyRange(bo *retry.Backoffer, startKey []byte, endKey []byte, count int) (regions []*Region, err error)

BatchLoadRegionsWithKeyRange loads at most given numbers of regions to the RegionCache, within the given key range from the startKey to endKey. Returns the loaded regions.

func (*RegionCache) Close

func (c *RegionCache) Close()

Close releases region cache's resource.

func (*RegionCache) GetAllStores added in v2.0.4

func (c *RegionCache) GetAllStores() []*Store

GetAllStores gets TiKV and TiFlash stores.

func (*RegionCache) GetAllValidTiFlashStores

func (c *RegionCache) GetAllValidTiFlashStores(id RegionVerID, currentStore *Store, labelFilter LabelFilter) []uint64

GetAllValidTiFlashStores returns the store ids of all valid TiFlash stores, the store id of currentStore is always the first one

func (*RegionCache) GetCachedRegionWithRLock

func (c *RegionCache) GetCachedRegionWithRLock(regionID RegionVerID) (r *Region)

GetCachedRegionWithRLock returns region with lock.

func (*RegionCache) GetStoresByType

func (c *RegionCache) GetStoresByType(typ tikvrpc.EndpointType) []*Store

GetStoresByType gets stores by type `typ` TODO: revise it by get store by closure.

func (*RegionCache) GetTiFlashComputeStores added in v2.0.2

func (c *RegionCache) GetTiFlashComputeStores(bo *retry.Backoffer) (res []*Store, err error)

GetTiFlashComputeStores returns all stores with lable <engine, tiflash_compute>.

func (*RegionCache) GetTiFlashRPCContext

func (c *RegionCache) GetTiFlashRPCContext(bo *retry.Backoffer, id RegionVerID, loadBalance bool, labelFilter LabelFilter) (*RPCContext, error)

GetTiFlashRPCContext returns RPCContext for a region must access flash store. If it returns nil, the region must be out of date and already dropped from cache or not flash store found. `loadBalance` is an option. For batch cop, it is pointless and might cause try the failed store repeatly.

func (*RegionCache) GetTiFlashStores

func (c *RegionCache) GetTiFlashStores(labelFilter LabelFilter) []*Store

GetTiFlashStores returns the information of all tiflash nodes.

func (*RegionCache) GetTiKVRPCContext

func (c *RegionCache) GetTiKVRPCContext(bo *retry.Backoffer, id RegionVerID, replicaRead kv.ReplicaReadType, followerStoreSeed uint32, opts ...StoreSelectorOption) (*RPCContext, error)

GetTiKVRPCContext returns RPCContext for a region. If it returns nil, the region must be out of date and already dropped from cache.

func (*RegionCache) GroupKeysByRegion

func (c *RegionCache) GroupKeysByRegion(bo *retry.Backoffer, keys [][]byte, filter func(key, regionStartKey []byte) bool) (map[RegionVerID][][]byte, RegionVerID, error)

GroupKeysByRegion separates keys into groups by their belonging Regions. Specially it also returns the first key's region which may be used as the 'PrimaryLockKey' and should be committed ahead of others. filter is used to filter some unwanted keys.

func (*RegionCache) InvalidateCachedRegion

func (c *RegionCache) InvalidateCachedRegion(id RegionVerID)

InvalidateCachedRegion removes a cached Region.

func (*RegionCache) InvalidateCachedRegionWithReason

func (c *RegionCache) InvalidateCachedRegionWithReason(id RegionVerID, reason InvalidReason)

InvalidateCachedRegionWithReason removes a cached Region with the reason why it's invalidated.

func (*RegionCache) InvalidateTiFlashComputeStores added in v2.0.2

func (c *RegionCache) InvalidateTiFlashComputeStores()

InvalidateTiFlashComputeStores set needReload be true, and will refresh tiflash_compute store cache next time.

func (*RegionCache) InvalidateTiFlashComputeStoresIfGRPCError added in v2.0.2

func (c *RegionCache) InvalidateTiFlashComputeStoresIfGRPCError(err error) bool

InvalidateTiFlashComputeStoresIfGRPCError will invalid cache if is GRPC error. For now, only consider GRPC unavailable error.

func (*RegionCache) ListRegionIDsInKeyRange

func (c *RegionCache) ListRegionIDsInKeyRange(bo *retry.Backoffer, startKey, endKey []byte) (regionIDs []uint64, err error)

ListRegionIDsInKeyRange lists ids of regions in [start_key,end_key].

func (*RegionCache) LoadRegionsInKeyRange

func (c *RegionCache) LoadRegionsInKeyRange(bo *retry.Backoffer, startKey, endKey []byte) (regions []*Region, err error)

LoadRegionsInKeyRange lists regions in [start_key,end_key].

func (*RegionCache) LocateEndKey

func (c *RegionCache) LocateEndKey(bo *retry.Backoffer, key []byte) (*KeyLocation, error)

LocateEndKey searches for the region and range that the key is located. Unlike LocateKey, start key of a region is exclusive and end key is inclusive.

func (*RegionCache) LocateKey

func (c *RegionCache) LocateKey(bo *retry.Backoffer, key []byte) (*KeyLocation, error)

LocateKey searches for the region and range that the key is located.

func (*RegionCache) LocateRegionByID

func (c *RegionCache) LocateRegionByID(bo *retry.Backoffer, regionID uint64) (*KeyLocation, error)

LocateRegionByID searches for the region with ID.

func (*RegionCache) OnRegionEpochNotMatch

func (c *RegionCache) OnRegionEpochNotMatch(bo *retry.Backoffer, ctx *RPCContext, currentRegions []*metapb.Region) (bool, error)

OnRegionEpochNotMatch removes the old region and inserts new regions into the cache. It returns whether retries the request because it's possible the region epoch is ahead of TiKV's due to slow appling.

func (*RegionCache) OnSendFail

func (c *RegionCache) OnSendFail(bo *retry.Backoffer, ctx *RPCContext, scheduleReload bool, err error)

OnSendFail handles send request fail logic.

func (*RegionCache) OnSendFailForTiFlash

func (c *RegionCache) OnSendFailForTiFlash(bo *retry.Backoffer, store *Store, region RegionVerID, prev *metapb.Region, scheduleReload bool, err error, skipSwitchPeerLog bool)

OnSendFailForTiFlash handles send request fail logic for tiflash.

func (*RegionCache) PDClient

func (c *RegionCache) PDClient() pd.Client

PDClient returns the pd.Client in RegionCache.

func (*RegionCache) SetPDClient

func (c *RegionCache) SetPDClient(client pd.Client)

SetPDClient replaces pd client,for testing only

func (*RegionCache) SetRegionCacheStore

func (c *RegionCache) SetRegionCacheStore(id uint64, addr string, peerAddr string, storeType tikvrpc.EndpointType, state uint64, labels []*metapb.StoreLabel)

SetRegionCacheStore is used to set a store in region cache, for testing only

func (*RegionCache) TryLocateKey added in v2.0.7

func (c *RegionCache) TryLocateKey(key []byte) *KeyLocation

TryLocateKey searches for the region and range that the key is located, but return nil when region miss or invalid.

func (*RegionCache) UpdateBucketsIfNeeded added in v2.0.2

func (c *RegionCache) UpdateBucketsIfNeeded(regionID RegionVerID, latestBucketsVer uint64)

UpdateBucketsIfNeeded queries PD to update the buckets of the region in the cache if the latestBucketsVer is newer than the cached one.

func (*RegionCache) UpdateLeader

func (c *RegionCache) UpdateLeader(regionID RegionVerID, leader *metapb.Peer, currentPeerIdx AccessIndex)

UpdateLeader update some region cache with newer leader info.

type RegionRequestRuntimeStats

type RegionRequestRuntimeStats struct {
	Stats map[tikvrpc.CmdType]*RPCRuntimeStats
}

RegionRequestRuntimeStats records the runtime stats of send region requests.

func NewRegionRequestRuntimeStats

func NewRegionRequestRuntimeStats() RegionRequestRuntimeStats

NewRegionRequestRuntimeStats returns a new RegionRequestRuntimeStats.

func (*RegionRequestRuntimeStats) Clone

Clone returns a copy of itself.

func (*RegionRequestRuntimeStats) Merge

Merge merges other RegionRequestRuntimeStats.

func (*RegionRequestRuntimeStats) String

func (r *RegionRequestRuntimeStats) String() string

String implements fmt.Stringer interface.

type RegionRequestSender

type RegionRequestSender struct {
	RegionRequestRuntimeStats
	// contains filtered or unexported fields
}

RegionRequestSender sends KV/Cop requests to tikv server. It handles network errors and some region errors internally.

Typically, a KV/Cop request is bind to a region, all keys that are involved in the request should be located in the region. The sending process begins with looking for the address of leader store's address of the target region from cache, and the request is then sent to the destination tikv server over TCP connection. If region is updated, can be caused by leader transfer, region split, region merge, or region balance, tikv server may not able to process request and send back a RegionError. RegionRequestSender takes care of errors that does not relevant to region range, such as 'I/O timeout', 'NotLeader', and 'ServerIsBusy'. If fails to send the request to all replicas, a fake rregion error may be returned. Caller which receives the error should retry the request.

For other region errors, since region range have changed, the request may need to split, so we simply return the error to caller.

func NewRegionRequestSender

func NewRegionRequestSender(regionCache *RegionCache, client client.Client) *RegionRequestSender

NewRegionRequestSender creates a new sender.

func (*RegionRequestSender) GetClient

func (s *RegionRequestSender) GetClient() client.Client

GetClient returns the RPC client.

func (*RegionRequestSender) GetRPCError

func (s *RegionRequestSender) GetRPCError() error

GetRPCError returns the RPC error.

func (*RegionRequestSender) GetRegionCache

func (s *RegionRequestSender) GetRegionCache() *RegionCache

GetRegionCache returns the region cache.

func (*RegionRequestSender) GetStoreAddr

func (s *RegionRequestSender) GetStoreAddr() string

GetStoreAddr returns the dest store address.

func (*RegionRequestSender) NeedReloadRegion

func (s *RegionRequestSender) NeedReloadRegion(ctx *RPCContext) (need bool)

NeedReloadRegion checks is all peers has sent failed, if so need reload.

func (*RegionRequestSender) SendReq

func (s *RegionRequestSender) SendReq(
	bo *retry.Backoffer, req *tikvrpc.Request, regionID RegionVerID, timeout time.Duration,
) (*tikvrpc.Response, int, error)

SendReq sends a request to tikv server. If fails to send the request to all replicas, a fake region error may be returned. Caller which receives the error should retry the request. It also returns the times of retries in RPC layer. A positive retryTimes indicates a possible undetermined error.

func (*RegionRequestSender) SendReqCtx

func (s *RegionRequestSender) SendReqCtx(
	bo *retry.Backoffer,
	req *tikvrpc.Request,
	regionID RegionVerID,
	timeout time.Duration,
	et tikvrpc.EndpointType,
	opts ...StoreSelectorOption,
) (
	resp *tikvrpc.Response,
	rpcCtx *RPCContext,
	retryTimes int,
	err error,
)

SendReqCtx sends a request to tikv server and return response and RPCCtx of this RPC.

func (*RegionRequestSender) SetRPCError

func (s *RegionRequestSender) SetRPCError(err error)

SetRPCError rewrite the rpc error.

func (*RegionRequestSender) SetStoreAddr

func (s *RegionRequestSender) SetStoreAddr(addr string)

SetStoreAddr specifies the dest store address.

type RegionVerID

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

RegionVerID is a unique ID that can identify a Region at a specific version.

func NewRegionVerID

func NewRegionVerID(id, confVer, ver uint64) RegionVerID

NewRegionVerID creates a region ver id, which used for invalidating regions.

func (*RegionVerID) Equals

func (r *RegionVerID) Equals(another RegionVerID) bool

Equals checks whether the RegionVerID equals to another one

func (*RegionVerID) GetConfVer

func (r *RegionVerID) GetConfVer() uint64

GetConfVer returns the conf ver of the region's epoch

func (*RegionVerID) GetID

func (r *RegionVerID) GetID() uint64

GetID returns the id of the region

func (*RegionVerID) GetVer

func (r *RegionVerID) GetVer() uint64

GetVer returns the version of the region's epoch

func (*RegionVerID) String

func (r *RegionVerID) String() string

String formats the RegionVerID to string

type SlowScoreStat added in v2.0.6

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

SlowScoreStat represents the statistics on business of Store.

type SortedRegions added in v2.0.2

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

SortedRegions is a sorted btree.

func NewSortedRegions added in v2.0.2

func NewSortedRegions(btreeDegree int) *SortedRegions

NewSortedRegions returns a new SortedRegions.

func (*SortedRegions) AscendGreaterOrEqual added in v2.0.2

func (s *SortedRegions) AscendGreaterOrEqual(startKey, endKey []byte, limit int) (regions []*Region)

AscendGreaterOrEqual returns all items that are greater than or equal to the key.

func (*SortedRegions) Clear added in v2.0.2

func (s *SortedRegions) Clear()

Clear removes all items from the btree.

func (*SortedRegions) DescendLessOrEqual added in v2.0.2

func (s *SortedRegions) DescendLessOrEqual(key []byte, isEndKey bool, ts int64) (r *Region)

DescendLessOrEqual returns all items that are less than or equal to the key.

func (*SortedRegions) ReplaceOrInsert added in v2.0.2

func (s *SortedRegions) ReplaceOrInsert(cachedRegion *Region) *Region

ReplaceOrInsert inserts a new item into the btree.

func (*SortedRegions) ValidRegionsInBtree added in v2.0.2

func (s *SortedRegions) ValidRegionsInBtree(ts int64) (len int)

ValidRegionsInBtree returns the number of valid regions in the btree.

type Store

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

Store contains a kv process's address.

func (*Store) EstimatedWaitTime added in v2.0.7

func (s *Store) EstimatedWaitTime() time.Duration

EstimatedWaitTime returns an optimistic estimation of how long a request will wait in the store. It's calculated by subtracting the time since the last update from the wait time returned from TiKV.

func (*Store) GetAddr

func (s *Store) GetAddr() string

GetAddr returns the address of the store

func (*Store) GetLabelValue added in v2.0.3

func (s *Store) GetLabelValue(key string) (string, bool)

GetLabelValue returns the value of the label

func (*Store) GetPeerAddr added in v2.0.4

func (s *Store) GetPeerAddr() string

GetPeerAddr returns the peer address of the store

func (*Store) IsLabelsMatch

func (s *Store) IsLabelsMatch(labels []*metapb.StoreLabel) bool

IsLabelsMatch return whether the store's labels match the target labels

func (*Store) IsSameLabels

func (s *Store) IsSameLabels(labels []*metapb.StoreLabel) bool

IsSameLabels returns whether the store have the same labels with target labels

func (*Store) IsStoreMatch added in v2.0.7

func (s *Store) IsStoreMatch(stores []uint64) bool

IsStoreMatch returns whether the store's id match the target ids.

func (*Store) IsTiFlash

func (s *Store) IsTiFlash() bool

IsTiFlash returns true if the storeType is TiFlash

func (*Store) StoreID

func (s *Store) StoreID() uint64

StoreID returns storeID.

type StoreSelectorOption

type StoreSelectorOption func(*storeSelectorOp)

StoreSelectorOption configures storeSelectorOp.

func WithLeaderOnly

func WithLeaderOnly() StoreSelectorOption

WithLeaderOnly indicates selecting stores with leader only.

func WithMatchLabels

func WithMatchLabels(labels []*metapb.StoreLabel) StoreSelectorOption

WithMatchLabels indicates selecting stores with matched labels.

func WithMatchStores added in v2.0.7

func WithMatchStores(stores []uint64) StoreSelectorOption

WithMatchStores indicates selecting stores with matched store ids.

func WithPerferLeader added in v2.0.6

func WithPerferLeader() StoreSelectorOption

WithPerferLeader indicates selecting stores with leader as priority until leader unaccessible.

Jump to

Keyboard shortcuts

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