-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
client: support requests with source label #506
Conversation
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
// InternalTxnGC is the type of GC txn. | ||
InternalTxnGC = "gc" | ||
// InternalTxnMeta is the type of the miscellaneous meta usage. | ||
InternalTxnMeta = InternalTxnOthers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some sources are client's inner types and applications use client can give their specified types. Also the types are aliased to reduce the metrics.
internal/client/client.go
Outdated
v = metrics.TiKVSendReqHistogram.WithLabelValues(reqType, storeID, strconv.FormatBool(staleRead)) | ||
sendReqHistCache.Store(key, v) | ||
counter = metrics.TiKVSendReqCounter.WithLabelValues(reqType, storeID, strconv.FormatBool(staleRead), counterKey.requestSource) | ||
sendReqCounterCache.Store(histKey, hist) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another metric I've considered is the "request time"(similar to "db time"). The sum duration of requests by all labels.
txnkv/txnlock/lock_resolver.go
Outdated
@@ -327,16 +334,16 @@ func (lr *LockResolver) BatchResolveLocks(bo *retry.Backoffer, locks []*Lock, lo | |||
// commit status. | |||
// 3) Send `ResolveLock` cmd to the lock's region to resolve all locks belong to | |||
// the same transaction. | |||
func (lr *LockResolver) ResolveLocks(bo *retry.Backoffer, callerStartTS uint64, locks []*Lock) (int64, error) { | |||
ttl, _, _, err := lr.resolveLocks(bo, callerStartTS, locks, false, false) | |||
func (lr *LockResolver) ResolveLocks(bo *retry.Backoffer, callerStartTS uint64, locks []*Lock, detail *util.ResolveLockDetail) (int64, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could it be more friendly to client-go users to add a new function ResolveLocksWithDetail
instead of modifying the original interface?
if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil { | ||
span1 := span.Tracer().StartSpan("tikvSnapshot.get", opentracing.ChildOf(span.Context())) | ||
defer span1.Finish() | ||
opentracing.ContextWithSpan(ctx, span1) | ||
} | ||
if _, err := util.EvalFailpoint("snapshot-get-cache-fail"); err == nil { | ||
if bo.GetCtx().Value("TestSnapshotCache") != nil { | ||
s.mu.RUnlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this change for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the unnecessary unlock and lock in line 526 and 540, but we still need to unlock when panic in the failpoint, unless the mutex will be locked and block all the future usage.
util/execdetails.go
Outdated
|
||
// ResolveLockDetail contains the resolve lock detail information. | ||
type ResolveLockDetail struct { | ||
*RequestSource |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks a bit weird to include this in xxxDetail
. Can we just pass it by Context
?
Signed-off-by: you06 <you1474600@gmail.com>
Signed-off-by: you06 <you1474600@gmail.com>
tikv/split_region.go
Outdated
@@ -88,6 +88,7 @@ func (s *KVStore) splitBatchRegionsReq(bo *Backoffer, keys [][]byte, scatter boo | |||
zap.Uint64("first batch, region ID", batches[0].RegionID.GetID()), | |||
zap.String("first split key", kv.StrKey(batches[0].Keys[0]))) | |||
} | |||
bo.SetCtx(util.WithInternalSourceType(bo.GetCtx(), util.InternalTxnMeta)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should add this. SplitRegion
may be called during prewrite and I think its source should equal to the source of that prewrite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest lgtm
txnkv/txnlock/lock_resolver.go
Outdated
callerStartTS := opts.CallerStartTS | ||
locks := opts.Locks | ||
detail := opts.Detail | ||
forRead := opts.ForRead | ||
lite := opts.Lite |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe writing them in one line is simpler?
callerStartTS, locks, detail, forRead, lite := opts.CallerStartTS, opts.Locks, opts.Detail, opts.ForRead, opts.Lite
txnkv/txnlock/lock_resolver.go
Outdated
@@ -988,7 +1048,7 @@ func (lr *LockResolver) resolveRegionLocks(bo *retry.Backoffer, l *Lock, region | |||
return nil | |||
} | |||
|
|||
func (lr *LockResolver) resolveLock(bo *retry.Backoffer, l *Lock, status TxnStatus, lite bool, cleanRegions map[locate.RegionVerID]struct{}) error { | |||
func (lr *LockResolver) resolveLock(bo *retry.Backoffer, l *Lock, status TxnStatus, lite bool, cleanRegions map[locate.RegionVerID]struct{}, async bool) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is async
used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used for recording resolve details with different types. Removed because the further details are not included in this PR.
Signed-off-by: you06 <you1474600@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ref pingcap/tidb#33963
TiDB sends requests to TiKV in a way that mixes internal and external queries, this PR divides them and sets the tag for requests.