Documentation ¶
Index ¶
- type CachedRegion
- type CodecPDClient
- type KeyLocation
- type RPCContext
- type Region
- type RegionCache
- func (c *RegionCache) ClearStoreByID(id uint64)
- func (c *RegionCache) DropRegion(id RegionVerID)
- func (c *RegionCache) DropStoreOnSendRequestFail(ctx *RPCContext, err error)
- func (c *RegionCache) GetRPCContext(bo *retry.Backoffer, id RegionVerID) (*RPCContext, error)
- func (c *RegionCache) GetStoreAddr(bo *retry.Backoffer, id uint64) (string, error)
- func (c *RegionCache) GroupKeysByRegion(bo *retry.Backoffer, keys [][]byte) (map[RegionVerID][][]byte, RegionVerID, error)
- func (c *RegionCache) ListRegionIDsInKeyRange(bo *retry.Backoffer, startKey, endKey []byte) (regionIDs []uint64, err error)
- func (c *RegionCache) LocateKey(bo *retry.Backoffer, key []byte) (*KeyLocation, error)
- func (c *RegionCache) LocateRegionByID(bo *retry.Backoffer, regionID uint64) (*KeyLocation, error)
- func (c *RegionCache) OnRegionStale(ctx *RPCContext, newRegions []*metapb.Region) error
- func (c *RegionCache) PDClient() pd.Client
- func (c *RegionCache) ReloadStoreAddr(bo *retry.Backoffer, id uint64) (string, error)
- func (c *RegionCache) UpdateLeader(regionID RegionVerID, leaderStoreID uint64)
- type RegionVerID
- type Store
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 ¶
CodecPDClient wraps a PD Client to decode the encoded keys in region meta.
func (*CodecPDClient) GetPrevRegion ¶
GetPrevRegion encodes the key before send requests to pd-server and decodes the returned StartKey && EndKey from pd-server.
func (*CodecPDClient) GetRegion ¶
GetRegion encodes the key before send requests to pd-server and decodes the returned StartKey && EndKey from pd-server.
func (*CodecPDClient) GetRegionByID ¶
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 ¶
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 ¶
Contains checks whether the key is in the region, for the maximum region endKey is empty. startKey <= key < endKey.
func (*Region) GetContext ¶
GetContext constructs kvprotopb.Context from region info.
func (*Region) SwitchPeer ¶
SwitchPeer switches current peer to the one on specific store. It returns false if no peer matches the storeID.
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 ¶
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 ¶
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.