locate

package
v0.0.0-...-7f29674 Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CachedRegion

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

CachedRegion encapsulates {Region, TTL}

type CodecPDClient

type CodecPDClient struct {
	pd.Client
}

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

func (*CodecPDClient) GetPrevRegion

func (c *CodecPDClient) GetPrevRegion(ctx context.Context, key []byte) (*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) (*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) (*pd.Region, error)

GetRegionByID decodes the returned StartKey && EndKey from pd-server.

type KeyLocation

type KeyLocation struct {
	Region   RegionVerID
	StartKey []byte
	EndKey   []byte
}

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

type RPCContext

type RPCContext struct {
	Region RegionVerID
	Meta   *metapb.Region
	Peer   *metapb.Peer
	Addr   string
}

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

func (*RPCContext) GetStoreID

func (c *RPCContext) GetStoreID() uint64

GetStoreID returns StoreID.

type Region

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

Region stores region's meta and its leader 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) EndKey

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

EndKey returns EndKey.

func (*Region) GetContext

func (r *Region) GetContext() *kvrpcpb.Context

GetContext constructs kvprotopb.Context from region info.

func (*Region) GetID

func (r *Region) GetID() uint64

GetID returns id.

func (*Region) StartKey

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

StartKey returns StartKey.

func (*Region) SwitchPeer

func (r *Region) SwitchPeer(storeID uint64) bool

SwitchPeer switches current peer to the one on specific store. It returns false if no peer matches the storeID.

func (*Region) VerID

func (r *Region) VerID() RegionVerID

VerID returns the Region's RegionVerID.

type RegionCache

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

RegionCache caches Regions loaded from PD.

func NewRegionCache

func NewRegionCache(pdClient pd.Client, conf *config.RegionCache) *RegionCache

NewRegionCache creates a RegionCache.

func (*RegionCache) ClearStoreByID

func (c *RegionCache) ClearStoreByID(id uint64)

ClearStoreByID clears store from cache with storeID.

func (*RegionCache) DropRegion

func (c *RegionCache) DropRegion(id RegionVerID)

DropRegion removes a cached Region.

func (*RegionCache) DropStoreOnSendRequestFail

func (c *RegionCache) DropStoreOnSendRequestFail(ctx *RPCContext, err error)

DropStoreOnSendRequestFail is used for clearing cache when a tikv server does not respond.

func (*RegionCache) GetRPCContext

func (c *RegionCache) GetRPCContext(bo *retry.Backoffer, id RegionVerID) (*RPCContext, error)

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

func (*RegionCache) GetStoreAddr

func (c *RegionCache) GetStoreAddr(bo *retry.Backoffer, id uint64) (string, error)

GetStoreAddr returns a tikv server's address by its storeID. It checks cache first, sends request to pd server when necessary.

func (*RegionCache) GroupKeysByRegion

func (c *RegionCache) GroupKeysByRegion(bo *retry.Backoffer, keys [][]byte) (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.

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

func (c *RegionCache) OnRegionStale(ctx *RPCContext, newRegions []*metapb.Region) error

OnRegionStale removes the old region and inserts new regions into the cache.

func (*RegionCache) PDClient

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

PDClient returns the pd.Client in RegionCache.

func (*RegionCache) ReloadStoreAddr

func (c *RegionCache) ReloadStoreAddr(bo *retry.Backoffer, id uint64) (string, error)

ReloadStoreAddr reloads store's address.

func (*RegionCache) UpdateLeader

func (c *RegionCache) UpdateLeader(regionID RegionVerID, leaderStoreID uint64)

UpdateLeader update some region cache with newer leader info.

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 (*RegionVerID) GetID

func (r *RegionVerID) GetID() uint64

GetID returns the id of the region

type Store

type Store struct {
	ID   uint64
	Addr string
}

Store contains a tikv server's address.

Jump to

Keyboard shortcuts

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