Documentation ¶
Index ¶
- Constants
- func CheckRegionsLeftCover(regions []*metapb.Region, span tablepb.Span) bool
- func CutRegionsLeftCoverSpan(regions []*metapb.Region, spanToCover tablepb.Span) []*metapb.Region
- type LockRangeResult
- type LockedRangeState
- type LockedRangeStatistic
- type RangeLock
- func (l *RangeLock) IterAll(action func(regionID uint64, state *LockedRangeState)) (r RangeLockStatistics)
- func (l *RangeLock) IterForTest(...)
- func (l *RangeLock) Len() int
- func (l *RangeLock) LockRange(ctx context.Context, startKey, endKey []byte, regionID, version uint64) LockRangeResult
- func (l *RangeLock) ResolvedTs() uint64
- func (l *RangeLock) Stop() (drained bool)
- func (l *RangeLock) UnlockRange(startKey, endKey []byte, regionID, version uint64, resolvedTs ...uint64) (drained bool)
- type RangeLockStatistics
- type UnLockRangeStatistic
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 ¶
This section is empty.
Functions ¶
func CheckRegionsLeftCover ¶
CheckRegionsLeftCover checks whether the regions cover the left part of given span
func CutRegionsLeftCoverSpan ¶
CutRegionsLeftCoverSpan processes a list of regions to remove those that do not cover the specified span or are discontinuous with the previous region. It returns a new slice containing only the continuous regions that cover the span.
Types ¶
type LockRangeResult ¶
type LockRangeResult struct { Status int LockedRangeState *LockedRangeState WaitFn func() LockRangeResult // RetryRanges is only used when Status is LockRangeStatusStale. // It contains the ranges that should be retried to lock. RetryRanges []tablepb.Span }
LockRangeResult represents the result of LockRange method of RangeLock. If Status is LockRangeStatusSuccess:
- LockedRangeState is for recording real-time state changes of the locked range. Its ResolvedTs is the minimum resolvedTs of the 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 LockedRangeState ¶
LockedRangeState is used to access the real-time state changes of a locked range.
type LockedRangeStatistic ¶
type LockedRangeStatistic struct { RegionID uint64 ResolvedTs uint64 Initialized bool Created time.Time }
LockedRangeStatistic represents a locked range.
type RangeLock ¶
type RangeLock struct {
// contains filtered or unexported fields
}
RangeLock is used to ensure that a table's same range is only requested once at a time. Before sending a region request to TiKV, the client should lock the region's range to avoid sending another request to the same region. After stopping the table or removing the region, the client should unlock the range. It also helps calculate the resolvedTs ts of the table it belongs to. Note(dongmen): A table has one RangeLock, and within that RangeLock, there are multiple regionLocks for each region.
func NewRangeLock ¶
func NewRangeLock( id uint64, startKey, endKey []byte, startTs uint64, changefeedLogInfo string, ) *RangeLock
NewRangeLock creates a new RangeLock.
func (*RangeLock) IterAll ¶
func (l *RangeLock) IterAll( action func(regionID uint64, state *LockedRangeState), ) (r RangeLockStatistics)
IterAll iterates all locked ranges in the RangeLock and performs the action on each locked range. It also returns some statistics of the RangeLock.
func (*RangeLock) IterForTest ¶
func (l *RangeLock) IterForTest( action func(regionID, version uint64, state *LockedRangeState, span tablepb.Span), )
IterForTest iterates all locked ranges in the RangeLock and performs the action on each locked range. It is used for testing only.
func (*RangeLock) LockRange ¶
func (l *RangeLock) LockRange( ctx context.Context, startKey, endKey []byte, regionID, version uint64, ) LockRangeResult
LockRange locks a range with specified version.
func (*RangeLock) ResolvedTs ¶
ResolvedTs calculates and returns the minimum resolvedTs of all ranges in the RangeLock.
func (*RangeLock) UnlockRange ¶
func (l *RangeLock) UnlockRange( startKey, endKey []byte, regionID, version uint64, resolvedTs ...uint64, ) (drained bool)
UnlockRange unlocks a range and update resolvedTs of the range to specified value. If it returns true it means it is stopped and all ranges are unlocked correctly.
type RangeLockStatistics ¶
type RangeLockStatistics struct { LockedRegionCount int // UnLockedRanges represents the unlocked ranges in the table. // If UnLockedRanges isn't empty, it implies that some regions were not captured at the time. // These regions could have been split, merged, transferred, or temporarily unavailable. UnLockedRanges []UnLockRangeStatistic FastestRegion LockedRangeStatistic SlowestRegion LockedRangeStatistic }
RangeLockStatistics represents some statistics of a RangeLock.
type UnLockRangeStatistic ¶
UnLockRangeStatistic represents a range that is unlocked.