spanz

package
v0.0.0-...-b2a4f9a Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 18 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// JobTableID is the id of `tidb_ddl_job`.
	JobTableID = ddl.JobTableID
	// JobHistoryID is the id of `tidb_ddl_history`
	JobHistoryID = ddl.HistoryTableID
)

Variables

View Source
var UpperBoundKey = []byte{255, 255, 255, 255, 255}

UpperBoundKey represents the maximum value.

Functions

func ArrayToSpan

func ArrayToSpan(in []tablepb.TableID) []tablepb.Span

ArrayToSpan converts an array of TableID to an array of Span.

func EndCompare

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

EndCompare compares two end keys. The result will be 0 if lhs==rhs, -1 if lhs < rhs, and +1 if lhs > rhs

func GetAllDDLSpan

func GetAllDDLSpan() []tablepb.Span

GetAllDDLSpan return all cdc interested spans for DDL.

func GetTableRange

func GetTableRange(tableID int64) (startKey, endKey []byte)

GetTableRange returns the span to watch for the specified table Note that returned keys are not in memcomparable format.

func HackSpan

func HackSpan(span tablepb.Span) tablepb.Span

HackSpan will set End as UpperBoundKey if End is Nil.

func HashTableSpan

func HashTableSpan(span tablepb.Span, slots int) int

HashTableSpan hashes the given span to a slot offset.

func HexKey

func HexKey(key []byte) string

HexKey returns a hex string generated from the key.

func Intersect

func Intersect(lhs tablepb.Span, rhs tablepb.Span) (span tablepb.Span, err error)

Intersect return to intersect part of lhs and rhs span. Return error if there's no intersect part

func IsSubSpan

func IsSubSpan(sub tablepb.Span, parents ...tablepb.Span) bool

IsSubSpan returns true if the sub span is parents spans

func KeyInSpan

func KeyInSpan(k tablepb.Key, span tablepb.Span) bool

KeyInSpan check if k in the span range.

func Sort

func Sort(spans []tablepb.Span)

Sort sorts a slice of Span.

func StartCompare

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

StartCompare compares two start keys. The result will be 0 if lhs==rhs, -1 if lhs < rhs, and +1 if lhs > rhs

func TableIDToComparableRange

func TableIDToComparableRange(tableID tablepb.TableID) (start, end tablepb.Span)

TableIDToComparableRange returns a range of a table, start and end are encoded in Comparable format.

func TableIDToComparableSpan

func TableIDToComparableSpan(tableID tablepb.TableID) tablepb.Span

TableIDToComparableSpan converts a TableID to a Span whose StartKey and EndKey are encoded in Comparable format.

func ToComparableKey

func ToComparableKey(key []byte) tablepb.Key

ToComparableKey returns a memcomparable key. See: https://github.com/facebook/mysql-5.6/wiki/MyRocks-record-format

func ToSpan

func ToSpan(startKey, endKey []byte) tablepb.Span

ToSpan returns a span, keys are encoded in memcomparable format. See: https://github.com/facebook/mysql-5.6/wiki/MyRocks-record-format

Types

type BtreeMap

type BtreeMap[T any] struct {
	// contains filtered or unexported fields
}

BtreeMap is a specialized btree map that map a Span to a value.

func NewBtreeMap

func NewBtreeMap[T any]() *BtreeMap[T]

NewBtreeMap returns a new BtreeMap.

func NewBtreeMapWithDegree

func NewBtreeMapWithDegree[T any](degree int) *BtreeMap[T]

NewBtreeMapWithDegree returns a new BtreeMap with the given degree.

func (*BtreeMap[T]) Ascend

func (m *BtreeMap[T]) Ascend(iterator ItemIterator[T])

Ascend calls the iterator for every value in the tree within the range [first, last], until iterator returns false.

func (*BtreeMap[T]) AscendRange

func (m *BtreeMap[T]) AscendRange(start, end tablepb.Span, iterator ItemIterator[T])

AscendRange calls the iterator for every value in the tree within the range [start, end), until iterator returns false.

func (*BtreeMap[T]) Delete

func (m *BtreeMap[T]) Delete(span tablepb.Span) (T, bool)

Delete removes an item equal to the passed in item from the tree, returning it. If no such item exists, returns (zeroValue, false).

func (*BtreeMap[T]) FindHoles

func (m *BtreeMap[T]) FindHoles(start, end tablepb.Span) ([]tablepb.Span, []tablepb.Span)

FindHoles returns an array of Span that are not covered in the range [start, end). Note: * Table ID is not set in returned holes. * Returned slice is read only and will be changed on next FindHoles.

func (*BtreeMap[T]) Get

func (m *BtreeMap[T]) Get(span tablepb.Span) (T, bool)

Get looks for the key item in the tree, returning it. It returns (zeroValue, false) if unable to find that item.

func (*BtreeMap[T]) GetV

func (m *BtreeMap[T]) GetV(span tablepb.Span) T

GetV looks for the key item in the tree, returning it. It returns zeroValue if unable to find that item.

func (*BtreeMap[T]) Has

func (m *BtreeMap[T]) Has(span tablepb.Span) bool

Has returns true if the given key is in the tree.

func (*BtreeMap[T]) Len

func (m *BtreeMap[T]) Len() int

Len returns the number of items currently in the tree.

func (*BtreeMap[T]) ReplaceOrInsert

func (m *BtreeMap[T]) ReplaceOrInsert(span tablepb.Span, value T) (T, bool)

ReplaceOrInsert adds the given item to the tree. If an item in the tree already equals the given one, it is removed from the tree and returned, and the second return value is true. Otherwise, (zeroValue, false)

nil cannot be added to the tree (will panic).

type HashMap

type HashMap[T any] struct {
	// contains filtered or unexported fields
}

HashMap is a specialized hash map that map a Span to a value.

func NewHashMap

func NewHashMap[T any]() *HashMap[T]

NewHashMap returns a new HashMap.

func (*HashMap[T]) Delete

func (m *HashMap[T]) Delete(span tablepb.Span)

Delete removes an item whose key equals to the span.

func (*HashMap[T]) Get

func (m *HashMap[T]) Get(span tablepb.Span) (T, bool)

Get looks for the key item in the map, returning it. It returns (zeroValue, false) if unable to find that item.

func (*HashMap[T]) GetV

func (m *HashMap[T]) GetV(span tablepb.Span) T

GetV looks for the key item in the map, returning it. It returns zeroValue if unable to find that item.

func (*HashMap[T]) Has

func (m *HashMap[T]) Has(span tablepb.Span) bool

Has returns true if the given key is in the map.

func (*HashMap[T]) Len

func (m *HashMap[T]) Len() int

Len returns the number of items currently in the map.

func (*HashMap[T]) Range

func (m *HashMap[T]) Range(iterator ItemIterator[T])

Range calls the iterator for every value in the map until iterator returns false.

func (*HashMap[T]) ReplaceOrInsert

func (m *HashMap[T]) ReplaceOrInsert(span tablepb.Span, value T)

ReplaceOrInsert adds the given item to the map.

type ItemIterator

type ItemIterator[T any] func(span tablepb.Span, value T) bool

ItemIterator allows callers of Ascend to iterate in-order over portions of the tree. Similar to btree.ItemIterator. Note: The span must not be mutated.

type Set

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

Set maintains a set of Span.

func NewSet

func NewSet() *Set

NewSet creates a Set.

func (*Set) Add

func (s *Set) Add(span tablepb.Span)

Add adds a span to Set.

func (*Set) Contain

func (s *Set) Contain(span tablepb.Span) bool

Contain checks whether a Span is in Set.

func (*Set) Keys

func (s *Set) Keys() []tablepb.Span

Keys returns a collection of Span.

func (*Set) Remove

func (s *Set) Remove(span tablepb.Span)

Remove removes a span from a Set.

func (*Set) Size

func (s *Set) Size() int

Size returns the size of Set.

type SyncMap

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

SyncMap is thread-safe map, its key is tablepb.Span.

func (*SyncMap) Delete

func (m *SyncMap) Delete(key tablepb.Span)

Delete deletes the value for a key.

func (*SyncMap) Load

func (m *SyncMap) Load(key tablepb.Span) (value any, ok bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*SyncMap) LoadAndDelete

func (m *SyncMap) LoadAndDelete(key tablepb.Span) (value any, loaded bool)

LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.

func (*SyncMap) LoadOrStore

func (m *SyncMap) LoadOrStore(key tablepb.Span, value any) (actual any, loaded bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*SyncMap) Range

func (m *SyncMap) Range(f func(span tablepb.Span, value any) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

func (*SyncMap) Store

func (m *SyncMap) Store(key tablepb.Span, value any)

Store sets the value for a key.

Jump to

Keyboard shortcuts

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