regionspan

package
v0.0.0-...-1b33b2a Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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

func EndCompare(lhs []byte, rhs []byte) int

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

func StartCompare(lhs []byte, rhs []byte) int

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

func ToComparableKey(key []byte) []byte

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.

type Span

type Span struct {
	Start []byte
	End   []byte
}

Span represents an arbitrary kv range

func (Span) Hack

func (s Span) Hack() Span

Hack will set End as UpperBoundKey if End is Nil.

func (Span) ID

func (s Span) ID() uint64

func (Span) Name

func (s Span) Name() string

func (Span) String

func (s Span) String() string

String returns a string that encodes Span in hex format.

Jump to

Keyboard shortcuts

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