Documentation
¶
Index ¶
- Constants
- Variables
- func BytesToString(numBytes int64) string
- func CompatibleParseGCTime(value string) (time.Time, error)
- func ContextWithTraceExecDetails(ctx context.Context) context.Context
- func EnableFailpoints()
- func EncodeToString(src []byte) []byte
- func EvalFailpoint(name string) (interface{}, error)
- func FormatBytes(numBytes int64) string
- func FormatDuration(d time.Duration) string
- func HexRegionKey(key []byte) []byte
- func HexRegionKeyStr(key []byte) string
- func IsInternalRequest(source string) bool
- func IsRequestSourceInternal(reqSrc *RequestSource) bool
- func RequestSourceFromCtx(ctx context.Context) string
- func ResourceGroupNameFromCtx(ctx context.Context) string
- func SetSessionID(ctx context.Context, sessionID uint64) context.Context
- func String(b []byte) (s string)
- func ToUpperASCIIInplace(s []byte) []byte
- func TraceExecDetailsEnabled(ctx context.Context) bool
- func WithInternalSourceType(ctx context.Context, source string) context.Context
- func WithRecovery(exec func(), recoverFn func(r interface{}))
- func WithResouceGroupName(ctx context.Context, groupName string) context.Context
- type CommitDetails
- func (cd *CommitDetails) Clone() *CommitDetails
- func (cd *CommitDetails) Merge(other *CommitDetails)
- func (cd *CommitDetails) MergeCommitReqDetails(reqDuration time.Duration, regionID uint64, addr string, ...)
- func (cd *CommitDetails) MergePrewriteReqDetails(reqDuration time.Duration, regionID uint64, addr string, ...)
- type ExecDetails
- type InterceptedPDClient
- func (m InterceptedPDClient) GetPrevRegion(ctx context.Context, key []byte, opts ...pd.GetRegionOption) (*pd.Region, error)
- func (m InterceptedPDClient) GetRegion(ctx context.Context, key []byte, opts ...pd.GetRegionOption) (*pd.Region, error)
- func (m InterceptedPDClient) GetRegionByID(ctx context.Context, regionID uint64, opts ...pd.GetRegionOption) (*pd.Region, error)
- func (m InterceptedPDClient) GetStore(ctx context.Context, storeID uint64) (*metapb.Store, error)
- func (m InterceptedPDClient) GetTS(ctx context.Context) (int64, int64, error)
- func (m InterceptedPDClient) GetTSAsync(ctx context.Context) pd.TSFuture
- func (m InterceptedPDClient) ScanRegions(ctx context.Context, key, endKey []byte, limit int) ([]*pd.Region, error)
- type LockKeysDetails
- type RURuntimeStats
- type RateLimit
- type ReqDetailInfo
- type RequestSource
- type RequestSourceKeyType
- type RequestSourceTypeKeyType
- type ResolveLockDetail
- type ScanDetail
- type TSSet
- type TiKVExecDetails
- type TimeDetail
- type WriteDetail
Constants ¶
const ( // InternalTxnOthers is the type of requests that consume low resources. // This reduces the size of metrics. InternalTxnOthers = "others" // InternalTxnGC is the type of GC txn. InternalTxnGC = "gc" // InternalTxnMeta is the type of the miscellaneous meta usage. InternalTxnMeta = InternalTxnOthers )
const ( // InternalRequest is the scope of internal queries InternalRequest = "internal_" // ExternalRequest is the scope of external queries ExternalRequest = "external_" // SourceUnknown keeps same with the default value(empty string) SourceUnknown = "unknown" )
const GCTimeFormat = "20060102-15:04:05.000 -0700"
GCTimeFormat is the format that gc_worker used to store times.
Variables ¶
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{} )
var RequestSourceKey = RequestSourceKeyType{}
RequestSourceKey is used as the key of request source type in context.
var RequestSourceTypeKey = RequestSourceTypeKeyType{}
RequestSourceTypeKey is used as the key of request source type in context.
var SessionID = sessionIDCtxKey{}
SessionID is the context key type to mark a session.
Functions ¶
func BytesToString ¶
BytesToString converts the memory consumption to a readable string.
func CompatibleParseGCTime ¶
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 ContextWithTraceExecDetails ¶ added in v2.0.2
ContextWithTraceExecDetails returns a context with trace-exec-details enabled
func EnableFailpoints ¶
func EnableFailpoints()
EnableFailpoints enables use of failpoints. It should be called before using client to avoid data race.
func EncodeToString ¶
EncodeToString overrides hex.EncodeToString implementation. Difference: returns []byte, not string
func EvalFailpoint ¶
EvalFailpoint injects code for testing. It is used to replace `failpoint.Inject` to make it possible to be used in a library.
func FormatBytes ¶
FormatBytes uses to format bytes, this function will prune precision before format bytes.
func FormatDuration ¶
FormatDuration uses to format duration, this function will prune precision before format duration. Pruning precision is for human readability. The prune rule is:
- if the duration was less than 1us, return the original string.
- 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 HexRegionKey ¶
HexRegionKey converts region key to hex format. Used for formating region in logs.
func HexRegionKeyStr ¶
HexRegionKeyStr converts region key to hex format. Used for formating region in logs.
func IsInternalRequest ¶ added in v2.0.6
IsInternalRequest returns the type of the request source.
func IsRequestSourceInternal ¶ added in v2.0.6
func IsRequestSourceInternal(reqSrc *RequestSource) bool
IsRequestSourceInternal checks whether the input request source type is internal type.
func RequestSourceFromCtx ¶ added in v2.0.2
RequestSourceFromCtx extract source from passed context.
func ResourceGroupNameFromCtx ¶ added in v2.0.5
ResourceGroupNameFromCtx extract resource group name from passed context, empty string is returned is the key is not set.
func SetSessionID ¶
SetSessionID sets session id into context
func ToUpperASCIIInplace ¶
ToUpperASCIIInplace bytes.ToUpper but zero-cost
func TraceExecDetailsEnabled ¶ added in v2.0.2
TraceExecDetailsEnabled checks whether trace-exec-details enabled
func WithInternalSourceType ¶ added in v2.0.2
WithInternalSourceType create context with internal source.
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
GetLatestTsTime time.Duration
PrewriteTime time.Duration
WaitPrewriteBinlogTime time.Duration
CommitTime time.Duration
LocalLatchTime time.Duration
Mu struct {
sync.Mutex
// The total backoff time used in both the prewrite and commit phases.
CommitBackoffTime int64
PrewriteBackoffTypes []string
CommitBackoffTypes []string
// The prewrite requests are executed concurrently so the slowest request information would be recorded.
SlowestPrewrite ReqDetailInfo
// It's recorded only when the commit mode is 2pc.
CommitPrimary ReqDetailInfo
}
WriteKeys int
WriteSize int
PrewriteRegionNum int32
TxnRetry int
ResolveLock ResolveLockDetail
PrewriteReqNum 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.
func (*CommitDetails) MergeCommitReqDetails ¶ added in v2.0.2
func (cd *CommitDetails) MergeCommitReqDetails(reqDuration time.Duration, regionID uint64, addr string, execDetails *kvrpcpb.ExecDetailsV2)
MergeCommitReqDetails merges commit related ExecDetailsV2 into the current CommitDetails.
func (*CommitDetails) MergePrewriteReqDetails ¶ added in v2.0.2
func (cd *CommitDetails) MergePrewriteReqDetails(reqDuration time.Duration, regionID uint64, addr string, execDetails *kvrpcpb.ExecDetailsV2)
MergePrewriteReqDetails merges prewrite related ExecDetailsV2 into the current CommitDetails.
type ExecDetails ¶
type ExecDetails struct {
BackoffCount int64
BackoffDuration int64
WaitKVRespDuration int64
WaitPDRespDuration int64
}
ExecDetails contains execution detail info.
type InterceptedPDClient ¶
InterceptedPDClient is a PD's wrapper client to record stmt detail.
func (InterceptedPDClient) GetPrevRegion ¶
func (m InterceptedPDClient) GetPrevRegion(ctx context.Context, key []byte, opts ...pd.GetRegionOption) (*pd.Region, error)
GetPrevRegion implements pd.Client#GetPrevRegion.
func (InterceptedPDClient) GetRegion ¶
func (m InterceptedPDClient) GetRegion(ctx context.Context, key []byte, opts ...pd.GetRegionOption) (*pd.Region, error)
GetRegion implements pd.Client#GetRegion.
func (InterceptedPDClient) GetRegionByID ¶
func (m InterceptedPDClient) GetRegionByID(ctx context.Context, regionID uint64, opts ...pd.GetRegionOption) (*pd.Region, error)
GetRegionByID implements pd.Client#GetRegionByID.
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
AggressiveLockNewCount int
AggressiveLockDerivedCount int
LockedWithConflictCount int
ResolveLock ResolveLockDetail
BackoffTime int64
Mu struct {
sync.Mutex
BackoffTypes []string
SlowestReqTotalTime time.Duration
SlowestRegion uint64
SlowestStoreAddr string
SlowestExecDetails TiKVExecDetails
}
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.
func (*LockKeysDetails) MergeReqDetails ¶ added in v2.0.2
func (ld *LockKeysDetails) MergeReqDetails(reqDuration time.Duration, regionID uint64, addr string, execDetails *kvrpcpb.ExecDetailsV2)
MergeReqDetails merges ExecDetailsV2 into the current LockKeysDetails.
type RURuntimeStats ¶ added in v2.0.7
type RURuntimeStats struct {
// contains filtered or unexported fields
}
RURuntimeStats is the runtime stats collector for RU.
func NewRURuntimeStats ¶ added in v2.0.7
func NewRURuntimeStats() *RURuntimeStats
NewRURuntimeStats creates a new RURuntimeStats.
func (*RURuntimeStats) Clone ¶ added in v2.0.7
func (rs *RURuntimeStats) Clone() *RURuntimeStats
Clone implements the RuntimeStats interface.
func (*RURuntimeStats) Merge ¶ added in v2.0.7
func (rs *RURuntimeStats) Merge(other *RURuntimeStats)
Merge implements the RuntimeStats interface.
func (*RURuntimeStats) String ¶ added in v2.0.7
func (rs *RURuntimeStats) String() string
String implements fmt.Stringer interface.
func (*RURuntimeStats) Update ¶ added in v2.0.7
func (rs *RURuntimeStats) Update(consumption *rmpb.Consumption)
Update updates the RU runtime stats with the given consumption info.
type RateLimit ¶
type RateLimit struct {
// contains filtered or unexported fields
}
RateLimit wraps a fix sized channel to control concurrency.
func NewRateLimit ¶
NewRateLimit creates a limit controller with capacity n.
func (*RateLimit) GetCapacity ¶
GetCapacity returns the token capacity.
type ReqDetailInfo ¶ added in v2.0.2
type ReqDetailInfo struct {
ReqTotalTime time.Duration
Region uint64
StoreAddr string
ExecDetails TiKVExecDetails
}
ReqDetailInfo contains diagnose information about `TiKVExecDetails`, region, store and backoff.
type RequestSource ¶ added in v2.0.2
RequestSource contains the source label of the request, used for tracking resource consuming.
func (*RequestSource) GetRequestSource ¶ added in v2.0.2
func (r *RequestSource) GetRequestSource() string
GetRequestSource gets the request_source field of the request.
func (*RequestSource) SetRequestSourceInternal ¶ added in v2.0.2
func (r *RequestSource) SetRequestSourceInternal(internal bool)
SetRequestSourceInternal sets the scope of the request source.
func (*RequestSource) SetRequestSourceType ¶ added in v2.0.2
func (r *RequestSource) SetRequestSourceType(tp string)
SetRequestSourceType sets the type of the request source.
type RequestSourceKeyType ¶ added in v2.0.2
type RequestSourceKeyType struct{}
RequestSourceKeyType is a dummy type to avoid naming collision in context.
type RequestSourceTypeKeyType ¶ added in v2.0.2
type RequestSourceTypeKeyType struct{}
RequestSourceTypeKeyType is a dummy type to avoid naming collision in context.
type ResolveLockDetail ¶ added in v2.0.2
type ResolveLockDetail struct {
// ResolveLockTime is the total duration of resolving lock.
ResolveLockTime int64
}
ResolveLockDetail contains the resolve lock detail information.
func (*ResolveLockDetail) Merge ¶ added in v2.0.2
func (rd *ResolveLockDetail) Merge(resolveLock *ResolveLockDetail)
Merge merges resolve lock detail details into self.
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
// Number of bytes of user key-value pairs scanned from the storage, i.e.
// total size of data returned from MVCC layer.
ProcessedKeysSize 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
// RocksdbBlockReadDuration is the total time used for block reads.
RocksdbBlockReadDuration time.Duration
// GetSnapshotDuration is the time spent getting an engine snapshot.
GetSnapshotDuration time.Duration
ResolveLock *ResolveLockDetail
}
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 TiKVExecDetails ¶ added in v2.0.2
type TiKVExecDetails struct {
TimeDetail *TimeDetail
ScanDetail *ScanDetail
WriteDetail *WriteDetail
}
TiKVExecDetails is the detail execution information at TiKV side.
func NewTiKVExecDetails ¶ added in v2.0.2
func NewTiKVExecDetails(pb *kvrpcpb.ExecDetailsV2) TiKVExecDetails
NewTiKVExecDetails creates a TiKVExecDetails from a kvproto ExecDetailsV2.
func (*TiKVExecDetails) String ¶ added in v2.0.2
func (ed *TiKVExecDetails) String() string
type TimeDetail ¶
type TimeDetail struct {
// 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.
ProcessTime time.Duration
// Cpu wall time elapsed that task is waiting in queue.
SuspendTime time.Duration
// Off-cpu wall time elapsed in TiKV side. Usually this includes queue waiting time and
// other kind of waits in series.
WaitTime time.Duration
// KvReadWallTime is the time used in KV Scan/Get.
KvReadWallTime time.Duration
// TotalRPCWallTime is Total wall clock time spent on this RPC in TiKV.
TotalRPCWallTime time.Duration
}
TimeDetail contains coprocessor time detail information.
func (*TimeDetail) MergeFromTimeDetail ¶
func (td *TimeDetail) MergeFromTimeDetail(timeDetailV2 *kvrpcpb.TimeDetailV2, 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.
type WriteDetail ¶ added in v2.0.2
type WriteDetail struct {
// StoreBatchWaitDuration is the wait duration in the store loop.
StoreBatchWaitDuration time.Duration
// ProposeSendWaitDuration is the duration before sending proposal to peers.
ProposeSendWaitDuration time.Duration
// PersistLogDuration is the total time spent on persisting the log.
PersistLogDuration time.Duration
// RaftDbWriteLeaderWaitDuration is the wait time until the Raft log write leader begins to write.
RaftDbWriteLeaderWaitDuration time.Duration
// RaftDbSyncLogDuration is the time spent on synchronizing the Raft log to the disk.
RaftDbSyncLogDuration time.Duration
// RaftDbWriteMemtableDuration is the time spent on writing the Raft log to the Raft memtable.
RaftDbWriteMemtableDuration time.Duration
// CommitLogDuration is the time waiting for peers to confirm the proposal (counting from the instant when the leader sends the proposal message).
CommitLogDuration time.Duration
// ApplyBatchWaitDuration is the wait duration in the apply loop.
ApplyBatchWaitDuration time.Duration
// ApplyLogDuration is the total time spend to applying the log.
ApplyLogDuration time.Duration
// ApplyMutexLockDuration is the wait time until the KV RocksDB lock is acquired.
ApplyMutexLockDuration time.Duration
// ApplyWriteLeaderWaitDuration is the wait time until becoming the KV RocksDB write leader.
ApplyWriteLeaderWaitDuration time.Duration
// ApplyWriteWalDuration is the time spent on writing the KV DB WAL to the disk.
ApplyWriteWalDuration time.Duration
// ApplyWriteMemtableNanos is the time spent on writing to the memtable of the KV RocksDB.
ApplyWriteMemtableDuration time.Duration
}
WriteDetail contains the detailed time breakdown of a write operation.
func (*WriteDetail) Merge ¶ added in v2.0.2
func (wd *WriteDetail) Merge(writeDetail *WriteDetail)
Merge merges another WriteDetail protobuf into self.
func (*WriteDetail) MergeFromWriteDetailPb ¶ added in v2.0.2
func (wd *WriteDetail) MergeFromWriteDetailPb(pb *kvrpcpb.WriteDetail)
MergeFromWriteDetailPb merges WriteDetail protobuf into the current WriteDetail
func (*WriteDetail) String ¶ added in v2.0.2
func (wd *WriteDetail) String() string