util

package
v0.0.0-...-a345a4b Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// APIV2RawKeyPrefix is prefix of raw key in API V2.
	APIV2RawKeyPrefix = []byte{'r', 0, 0, 0}
	// APIV2RawEndKey is max key of raw key in API V2.
	APIV2RawEndKey = []byte{'r', 0, 0, 1}
)
View Source
var FailpointBuild = isFailpointBuild()

FailpointBuild is ture if this is a failpoint build

Functions

func CaptureAddrFromCtx

func CaptureAddrFromCtx(ctx context.Context) string

CaptureAddrFromCtx returns a capture ID stored in the specified context. It returns an empty string if there's no valid capture ID found.

func ChangefeedIDFromCtx

func ChangefeedIDFromCtx(ctx context.Context) string

ChangefeedIDFromCtx returns a changefeedID stored in the specified context. It returns an empty string if there's no valid changefeed ID found.

func ConvertToUTF8

func ConvertToUTF8(strBytes []byte, origEncoding string) string

func DecodeV2Key

func DecodeV2Key(key []byte) ([]byte, error)

func EncodeKeySpan

func EncodeKeySpan(format, start, end string) ([]byte, []byte, error)

EncodeKeySpan parse user input key and encode them to apiv2 format.

func EncodeV2Key

func EncodeV2Key(key []byte) []byte

EncodeV2Key encode a user key into API V2 format.

func EncodeV2Range

func EncodeV2Range(start, end []byte) ([]byte, []byte)

EncodeV2Range encode a range into API V2 format. TODO: resue code in client-go

func GetLocalTimezone

func GetLocalTimezone() (*time.Location, error)

GetLocalTimezone returns the timezone in local system

func GetTimezone

func GetTimezone(name string) (tz *time.Location, err error)

GetTimezone returns the timezone specified by the name

func HandleErr

func HandleErr(ctx context.Context, errCh <-chan error, errFn func(error))

HandleErr receives error from an error channel, until the context is Done

func HandleErrWithErrGroup

func HandleErrWithErrGroup(ctx context.Context, errCh <-chan error, errFn func(error)) *errgroup.Group

HandleErrWithErrGroup creates a `errgroup.Group` and calls `HandleErr` within the error group

func IsOwnerFromCtx

func IsOwnerFromCtx(ctx context.Context) bool

IsOwnerFromCtx returns true if this capture is owner

func KVStorageFromCtx

func KVStorageFromCtx(ctx context.Context) (tikv.Storage, error)

KVStorageFromCtx returns a tikv store

func KeySpanInfoFromCtx

func KeySpanInfoFromCtx(ctx context.Context) (uint64, string)

KeySpanInfoFromCtx returns a kyspan ID & name

func MonitorCancelLatency

func MonitorCancelLatency(ctx context.Context, identifier string) func()

MonitorCancelLatency monitors the latency from ctx being cancelled and the returned function being called

func ParseKey

func ParseKey(format, key string) ([]byte, error)

ParseKey parse key by given format. TODO: same code with br/pkg/utils/key.go, need make them common.

func PutCaptureAddrInCtx

func PutCaptureAddrInCtx(ctx context.Context, captureAddr string) context.Context

PutCaptureAddrInCtx returns a new child context with the specified capture ID stored.

func PutChangefeedIDInCtx

func PutChangefeedIDInCtx(ctx context.Context, changefeedID string) context.Context

PutChangefeedIDInCtx returns a new child context with the specified changefeed ID stored.

func PutEventFilterInCtx

func PutEventFilterInCtx(ctx context.Context, filter *KvFilter) context.Context

func PutKVStorageInCtx

func PutKVStorageInCtx(ctx context.Context, store tikv.Storage) context.Context

PutKVStorageInCtx returns a new child context with the given tikv store

func PutKeySpanInfoInCtx

func PutKeySpanInfoInCtx(ctx context.Context, keyspanID uint64, keyspanName string) context.Context

PutKeySpanInfoInCtx returns a new child context with the specified keyspan ID and name stored.

func PutTimezoneInCtx

func PutTimezoneInCtx(ctx context.Context, timezone *time.Location) context.Context

PutTimezoneInCtx returns a new child context with the given timezone

func SetOwnerInCtx

func SetOwnerInCtx(ctx context.Context) context.Context

SetOwnerInCtx returns a new child context with the owner flag set.

func TimezoneFromCtx

func TimezoneFromCtx(ctx context.Context) *time.Location

TimezoneFromCtx returns a timezone

func ValidKeyFormat

func ValidKeyFormat(format, start, end string) error

func WaitSomething

func WaitSomething(nRetry int, waitTime time.Duration, fn func() bool) bool

WaitSomething waits for something done with `true`, it retrys for nRetry times at most

func ZapFieldCapture

func ZapFieldCapture(ctx context.Context) zap.Field

ZapFieldCapture returns a zap field containing capture address TODO: log redact for capture address

func ZapFieldChangefeed

func ZapFieldChangefeed(ctx context.Context) zap.Field

ZapFieldChangefeed returns a zap field containing changefeed id

Types

type Covering

type Covering []Range

Covering represents a non-overlapping, but possibly non-contiguous, set of intervals.

func (Covering) Len

func (c Covering) Len() int

func (Covering) Less

func (c Covering) Less(i, j int) bool

func (Covering) Swap

func (c Covering) Swap(i, j int)

type Flag

type Flag uint64

Flag is a uint64 flag to show a 64 bit mask

func (*Flag) Add

func (f *Flag) Add(flags ...Flag)

Add add flags

func (*Flag) Clear

func (f *Flag) Clear()

Clear clear all flags

func (*Flag) HasAll

func (f *Flag) HasAll(flags ...Flag) bool

HasAll means has all flags

func (*Flag) HasOne

func (f *Flag) HasOne(flags ...Flag) bool

HasOne means has one of the flags

func (*Flag) Remove

func (f *Flag) Remove(flags ...Flag)

Remove remove flags

type KvFilter

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

func CreateFilter

func CreateFilter(conf *KvFilterConfig) *KvFilter

func EventFilterFromCtx

func EventFilterFromCtx(ctx context.Context) *KvFilter

func (*KvFilter) EventMatch

func (f *KvFilter) EventMatch(entry *cdcpb.Event_Row) (bool, error)

Key of entry is expected to be in RawKV APIv2 format. Return error if not.

type KvFilterConfig

type KvFilterConfig struct {
	// Binary data is specified in escaped format, e.g. \x00\x01
	KeyPrefix    string `toml:"key-prefix" json:"key-prefix"`
	KeyPattern   string `toml:"key-pattern" json:"key-pattern"`
	ValuePattern string `toml:"value-pattern" json:"value-pattern"`
}

func (*KvFilterConfig) Validate

func (c *KvFilterConfig) Validate() error

type Range

type Range struct {
	Start   []byte
	End     []byte
	Payload interface{}
}

Range is an interval with a payload.

func OverlapCoveringMerge

func OverlapCoveringMerge(coverings []Covering) []Range

OverlapCoveringMerge returns the set of intervals covering every range in the input such that no output range crosses an input endpoint. The payloads are returned as a `[]interface{}` and in the same order as they are in coverings.

Example:

covering 1: [1, 2) -> 'a', [3, 4) -> 'b', [6, 7) -> 'c'
covering 2: [1, 5) -> 'd'
output: [1, 2) -> 'ad', [2, 3) -> `d`, [3, 4) -> 'bd', [4, 5) -> 'd', [6, 7) -> 'c'

The input is mutated (sorted). It is also assumed (and not checked) to be valid (e.g. non-overlapping intervals in each covering).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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