util

package
v2.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 16 Imported by: 54

Documentation

Index

Constants

View Source
const GCTimeFormat = "20060102-15:04:05 -0700"

GCTimeFormat is the format that gc_worker used to store times.

Variables

View Source
var (
	// CommitDetailCtxKey presents CommitDetail info key in context.
	CommitDetailCtxKey = commitDetailCtxKeyType{}

	// LockKeysDetailCtxKey presents LockKeysDetail info key in context.
	LockKeysDetailCtxKey = lockKeysDetailCtxKeyType{}

	// ExecDetailsKey presents ExecDetail info key in context.
	ExecDetailsKey = execDetailsCtxKeyType{}
)
View Source
var SessionID = sessionIDCtxKey{}

SessionID is the context key type to mark a session.

Functions

func BytesToString

func BytesToString(numBytes int64) string

BytesToString converts the memory consumption to a readable string.

func CompatibleParseGCTime

func CompatibleParseGCTime(value string) (time.Time, error)

CompatibleParseGCTime parses a string with `GCTimeFormat` and returns a time.Time. If `value` can't be parsed as that format, truncate to last space and try again. This function is only useful when loading times that saved by gc_worker. We have changed the format that gc_worker saves time (removed the last field), but when loading times it should be compatible with the old format.

func EvalFailpoint

func EvalFailpoint(name string) (interface{}, error)

EvalFailpoint injects code for testing. It is used to replace `failpoint.Inject` to make it possible to be used in a library.

func FormatBytes

func FormatBytes(numBytes int64) string

FormatBytes uses to format bytes, this function will prune precision before format bytes.

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration uses to format duration, this function will prune precision before format duration. Pruning precision is for human readability. The prune rule is:

  1. if the duration was less than 1us, return the original string.
  2. readable value >=10, keep 1 decimal, otherwise, keep 2 decimal. such as: 9.412345ms -> 9.41ms 10.412345ms -> 10.4ms 5.999s -> 6s 100.45µs -> 100.5µs

func SetSessionID

func SetSessionID(ctx context.Context, sessionID uint64) context.Context

SetSessionID sets session id into context

func WithRecovery

func WithRecovery(exec func(), recoverFn func(r interface{}))

WithRecovery wraps goroutine startup call with force recovery. it will dump current goroutine stack into log if catch any recover result.

exec:      execute logic function.
recoverFn: handler will be called after recover and before dump stack, passing `nil` means noop.

Types

type CommitDetails

type CommitDetails struct {
	GetCommitTsTime        time.Duration
	PrewriteTime           time.Duration
	WaitPrewriteBinlogTime time.Duration
	CommitTime             time.Duration
	LocalLatchTime         time.Duration
	Mu                     struct {
		sync.Mutex
		CommitBackoffTime int64
		BackoffTypes      []string
	}
	ResolveLockTime   int64
	WriteKeys         int
	WriteSize         int
	PrewriteRegionNum int32
	TxnRetry          int
}

CommitDetails contains commit detail information.

func (*CommitDetails) Clone

func (cd *CommitDetails) Clone() *CommitDetails

Clone returns a deep copy of itself.

func (*CommitDetails) Merge

func (cd *CommitDetails) Merge(other *CommitDetails)

Merge merges commit details into itself.

type ExecDetails

type ExecDetails struct {
	BackoffCount       int64
	BackoffDuration    int64
	WaitKVRespDuration int64
	WaitPDRespDuration int64
}

ExecDetails contains execution detail info.

type InterceptedPDClient

type InterceptedPDClient struct {
	pd.Client
}

InterceptedPDClient is a PD's wrapper client to record stmt detail.

func (InterceptedPDClient) GetPrevRegion

func (m InterceptedPDClient) GetPrevRegion(ctx context.Context, key []byte) (*pd.Region, error)

GetPrevRegion implements pd.Client#GetPrevRegion.

func (InterceptedPDClient) GetRegion

func (m InterceptedPDClient) GetRegion(ctx context.Context, key []byte) (*pd.Region, error)

GetRegion implements pd.Client#GetRegion.

func (InterceptedPDClient) GetRegionByID

func (m InterceptedPDClient) GetRegionByID(ctx context.Context, regionID uint64) (*pd.Region, error)

GetRegionByID implements pd.Client#GetRegionByID.

func (InterceptedPDClient) GetStore

func (m InterceptedPDClient) GetStore(ctx context.Context, storeID uint64) (*metapb.Store, error)

GetStore implements pd.Client#GetStore.

func (InterceptedPDClient) GetTS

GetTS implements pd.Client#GetTS.

func (InterceptedPDClient) GetTSAsync

func (m InterceptedPDClient) GetTSAsync(ctx context.Context) pd.TSFuture

GetTSAsync implements pd.Client#GetTSAsync.

func (InterceptedPDClient) ScanRegions

func (m InterceptedPDClient) ScanRegions(ctx context.Context, key, endKey []byte, limit int) ([]*pd.Region, error)

ScanRegions implements pd.Client#ScanRegions.

type LockKeysDetails

type LockKeysDetails struct {
	TotalTime       time.Duration
	RegionNum       int32
	LockKeys        int32
	ResolveLockTime int64
	BackoffTime     int64
	Mu              struct {
		sync.Mutex
		BackoffTypes []string
	}
	LockRPCTime  int64
	LockRPCCount int64
	RetryCount   int
}

LockKeysDetails contains pessimistic lock keys detail information.

func (*LockKeysDetails) Clone

func (ld *LockKeysDetails) Clone() *LockKeysDetails

Clone returns a deep copy of itself.

func (*LockKeysDetails) Merge

func (ld *LockKeysDetails) Merge(lockKey *LockKeysDetails)

Merge merges lock keys execution details into self.

type RateLimit

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

RateLimit wraps a fix sized channel to control concurrency.

func NewRateLimit

func NewRateLimit(n int) *RateLimit

NewRateLimit creates a limit controller with capacity n.

func (*RateLimit) GetCapacity

func (r *RateLimit) GetCapacity() int

GetCapacity returns the token capacity.

func (*RateLimit) GetToken

func (r *RateLimit) GetToken(done <-chan struct{}) (exit bool)

GetToken acquires a token.

func (*RateLimit) PutToken

func (r *RateLimit) PutToken()

PutToken puts a token back.

type ScanDetail

type ScanDetail struct {
	// TotalKeys is the approximate number of MVCC keys meet during scanning. It includes
	// deleted versions, but does not include RocksDB tombstone keys.
	TotalKeys int64
	// ProcessedKeys is the number of user keys scanned from the storage.
	// It does not include deleted version or RocksDB tombstone keys.
	// For Coprocessor requests, it includes keys that has been filtered out by Selection.
	ProcessedKeys int64
	// RocksdbDeleteSkippedCount is the total number of deletes and single deletes skipped over during
	// iteration, i.e. how many RocksDB tombstones are skipped.
	RocksdbDeleteSkippedCount uint64
	// RocksdbKeySkippedCount it the total number of internal keys skipped over during iteration.
	RocksdbKeySkippedCount uint64
	// RocksdbBlockCacheHitCount is the total number of RocksDB block cache hits.
	RocksdbBlockCacheHitCount uint64
	// RocksdbBlockReadCount is the total number of block reads (with IO).
	RocksdbBlockReadCount uint64
	// RocksdbBlockReadByte is the total number of bytes from block reads.
	RocksdbBlockReadByte uint64
}

ScanDetail contains coprocessor scan detail information.

func (*ScanDetail) Merge

func (sd *ScanDetail) Merge(scanDetail *ScanDetail)

Merge merges scan detail execution details into self.

func (*ScanDetail) MergeFromScanDetailV2

func (sd *ScanDetail) MergeFromScanDetailV2(scanDetail *kvrpcpb.ScanDetailV2)

MergeFromScanDetailV2 merges scan detail from pb into itself.

func (*ScanDetail) String

func (sd *ScanDetail) String() string

String implements the fmt.Stringer interface.

type TSSet

type TSSet struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TSSet is a set of timestamps.

func NewTSSet

func NewTSSet(capacity int) *TSSet

NewTSSet creates a set to store timestamps.

func (*TSSet) GetAll

func (s *TSSet) GetAll() []uint64

GetAll returns all timestamps in the set.

func (*TSSet) Put

func (s *TSSet) Put(tss ...uint64)

Put puts timestamps into the map.

type TimeDetail

type TimeDetail struct {
	// WaitWallTimeMs is the off-cpu wall time which is elapsed in TiKV side. Usually this includes queue waiting time and
	// other kind of waitings in series.
	ProcessTime time.Duration
	// Off-cpu and on-cpu wall time elapsed to actually process the request payload. It does not
	// include `wait_wall_time`.
	// This field is very close to the CPU time in most cases. Some wait time spend in RocksDB
	// cannot be excluded for now, like Mutex wait time, which is included in this field, so that
	// this field is called wall time instead of CPU time.
	WaitTime time.Duration
	// KvReadWallTimeMs is the time used in KV Scan/Get.
	KvReadWallTimeMs time.Duration
}

TimeDetail contains coprocessor time detail information.

func (*TimeDetail) MergeFromTimeDetail

func (td *TimeDetail) MergeFromTimeDetail(timeDetail *kvrpcpb.TimeDetail)

MergeFromTimeDetail merges time detail from pb into itself.

func (*TimeDetail) String

func (td *TimeDetail) String() string

String implements the fmt.Stringer interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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