Documentation
¶
Index ¶
- Constants
- Variables
- func CheckRegionsLeftCover(regions []*metapb.Region, span ComparableSpan) bool
- func EndCompare(lhs []byte, rhs []byte) int
- func IsSubSpan(sub ComparableSpan, parents ...ComparableSpan) bool
- func KeyInSpan(k []byte, span ComparableSpan) bool
- func KeyInSpans(k []byte, spans []ComparableSpan) bool
- func StartCompare(lhs []byte, rhs []byte) int
- func ToComparableKey(key []byte) []byte
- type ComparableSpan
- type LockRangeResult
- type RangeTsMap
- type RegionRangeLock
- type Span
Constants ¶
const ( // LockRangeStatusSuccess means a LockRange operation succeeded. LockRangeStatusSuccess = 0 // LockRangeStatusWait means a LockRange operation is blocked and should wait for it being finished. LockRangeStatusWait = 1 // LockRangeStatusStale means a LockRange operation is rejected because of the range's version is stale. LockRangeStatusStale = 2 // LockRangeStatusCancel means a LockRange operation is cancelled. LockRangeStatusCancel = 3 )
Variables ¶
var UpperBoundKey = []byte{255, 255, 255, 255, 255}
UpperBoundKey represents the maximum value.
Functions ¶
func CheckRegionsLeftCover ¶
func CheckRegionsLeftCover(regions []*metapb.Region, span ComparableSpan) bool
CheckRegionsLeftCover checks whether the regions cover the left part of given span
func EndCompare ¶
EndCompare compares two end keys. Nil means Positive infinity The result will be 0 if lhs==rhs, -1 if lhs < rhs, and +1 if lhs > rhs
func IsSubSpan ¶
func IsSubSpan(sub ComparableSpan, parents ...ComparableSpan) bool
IsSubSpan returns true if the sub span is parents spans
func KeyInSpan ¶
func KeyInSpan(k []byte, span ComparableSpan) bool
KeyInSpan check if k in the span range.
func KeyInSpans ¶
func KeyInSpans(k []byte, spans []ComparableSpan) bool
KeyInSpans check if k in the range of spans.
func StartCompare ¶
StartCompare compares two start keys. Nil means Negative infinity The result will be 0 if lhs==rhs, -1 if lhs < rhs, and +1 if lhs > rhs
func ToComparableKey ¶
ToComparableKey returns a memcomparable key.
Types ¶
type ComparableSpan ¶
type ComparableSpan Span
ComparableSpan represents an arbitrary kv range which is comparable
func Intersect ¶
func Intersect(lhs ComparableSpan, rhs ComparableSpan) (span ComparableSpan, err error)
Intersect return the intersect part of lhs and rhs span. Return error if there's no intersect part
func ToComparableSpan ¶
func ToComparableSpan(span Span) ComparableSpan
ToComparableSpan returns a memcomparable span
func (ComparableSpan) Clone ¶
func (s ComparableSpan) Clone() ComparableSpan
Clone clones a ComparableSpan
func (ComparableSpan) Hack ¶
func (s ComparableSpan) Hack() ComparableSpan
Hack will set End as UpperBoundKey if End is Nil.
func (ComparableSpan) String ¶
func (s ComparableSpan) String() string
String returns a string that encodes ComparableSpan in hex format.
type LockRangeResult ¶
type LockRangeResult struct { Status int CheckpointTs uint64 WaitFn func() LockRangeResult RetryRanges []ComparableSpan }
LockRangeResult represents the result of LockRange method of RegionRangeLock. If Status is LockRangeStatusSuccess, the CheckpointTs field will be the minimal checkpoint ts among the locked range. If Status is LockRangeStatusWait, it means the lock cannot be acquired immediately. WaitFn must be invoked to continue waiting and acquiring the lock. If Status is LockRangeStatusStale, it means the LockRange request is stale because there's already a overlapping locked range, whose version is greater or equals to the requested one.
type RangeTsMap ¶
type RangeTsMap struct {
// contains filtered or unexported fields
}
RangeTsMap represents a map from key range to a timestamp. It supports range set and calculating min value among a a specified range.
func NewRangeTsMap ¶
func NewRangeTsMap(startKey, endKey []byte, startTs uint64) *RangeTsMap
NewRangeTsMap creates a RangeTsMap.
func (*RangeTsMap) GetMin ¶
func (m *RangeTsMap) GetMin(startKey, endKey []byte) uint64
GetMin gets the min ts value among the given range. endKey must be greater than startKey.
func (*RangeTsMap) Set ¶
func (m *RangeTsMap) Set(startKey, endKey []byte, ts uint64)
Set sets the corresponding ts of the given range to the specified value.
type RegionRangeLock ¶
type RegionRangeLock struct {
// contains filtered or unexported fields
}
RegionRangeLock is specifically used for kv client to manage exclusive region ranges. Acquiring lock will be blocked if part of its range is already locked. It also manages checkpoint ts of all ranges. The ranges are marked by a version number, which should comes from the Region's Epoch version. The version is used to compare which range is new and which is old if two ranges are overlapping.
func NewRegionRangeLock ¶
func NewRegionRangeLock(startKey, endKey []byte, startTs uint64) *RegionRangeLock
NewRegionRangeLock creates a new RegionRangeLock.
func (*RegionRangeLock) LockRange ¶
func (l *RegionRangeLock) LockRange(ctx context.Context, startKey, endKey []byte, regionID, version uint64) LockRangeResult
LockRange locks a range with specified version.
func (*RegionRangeLock) UnlockRange ¶
func (l *RegionRangeLock) UnlockRange(startKey, endKey []byte, regionID, version uint64, checkpointTs uint64)
UnlockRange unlocks a range and update checkpointTs of the range to specivied value.