mirror of https://github.com/tikv/client-go.git
feat(resourcecontrol): refine request bypass logic for internal analyze and system requests (#1772)
ref tidbcloud/cloud-storage-engine#3703 Signed-off-by: JmPotato <github@ipotato.me> Co-authored-by: glorv <glorvs@163.com>
This commit is contained in:
parent
f8d9bebb31
commit
7793c676c4
|
|
@ -161,9 +161,6 @@ func getResourceControlInfo(ctx context.Context, req *tikvrpc.Request) (
|
||||||
if rcInterceptor == nil {
|
if rcInterceptor == nil {
|
||||||
return "", nil, nil
|
return "", nil, nil
|
||||||
}
|
}
|
||||||
// bypass some internal requests and it's may influence user experience. For example, the
|
|
||||||
// request of `alter user password`, totally bypasses the resource control. it's not cost
|
|
||||||
// many resources, but it's may influence the user experience.
|
|
||||||
// If the resource group has background jobs, we should not record consumption and wait for it.
|
// If the resource group has background jobs, we should not record consumption and wait for it.
|
||||||
// Background jobs will record and report in tikv side.
|
// Background jobs will record and report in tikv side.
|
||||||
resourceControlInterceptor := *rcInterceptor
|
resourceControlInterceptor := *rcInterceptor
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
|
|
||||||
"github.com/pingcap/kvproto/pkg/coprocessor"
|
"github.com/pingcap/kvproto/pkg/coprocessor"
|
||||||
"github.com/pingcap/kvproto/pkg/kvrpcpb"
|
"github.com/pingcap/kvproto/pkg/kvrpcpb"
|
||||||
|
"github.com/tikv/client-go/v2/config"
|
||||||
"github.com/tikv/client-go/v2/kv"
|
"github.com/tikv/client-go/v2/kv"
|
||||||
"github.com/tikv/client-go/v2/tikvrpc"
|
"github.com/tikv/client-go/v2/tikvrpc"
|
||||||
"github.com/tikv/client-go/v2/util"
|
"github.com/tikv/client-go/v2/util"
|
||||||
|
|
@ -53,15 +54,28 @@ func toPDAccessLocationType(accessType kv.AccessLocationType) controller.AccessL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reqTypeAnalyze is the type of analyze coprocessor request.
|
||||||
|
// ref: https://github.com/pingcap/tidb/blob/ee4eac2ccb83e1ea653b8131d9a43495019cb5ac/pkg/kv/kv.go#L340
|
||||||
|
const reqTypeAnalyze = 104
|
||||||
|
|
||||||
|
func shouldBypass(req *tikvrpc.Request) bool {
|
||||||
|
requestSource := req.Context.GetRequestSource()
|
||||||
|
// Check both coprocessor request type and the request source to ensure the request is an internal analyze request.
|
||||||
|
// Internal analyze request may consume a lot of resources, bypass it to avoid affecting the user experience.
|
||||||
|
// This bypass currently only works with NextGen.
|
||||||
|
if config.NextGen && (req.BatchCop().GetTp() == reqTypeAnalyze || req.Cop().GetTp() == reqTypeAnalyze) &&
|
||||||
|
strings.Contains(requestSource, util.InternalTxnStats) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// Some internal requests should be bypassed, which may affect the user experience.
|
||||||
|
// For example, the `alter user password` request completely bypasses resource control.
|
||||||
|
// Although it does not consume many resources, it can still impact the user experience.
|
||||||
|
return strings.Contains(requestSource, util.InternalRequestPrefix+util.InternalTxnOthers)
|
||||||
|
}
|
||||||
|
|
||||||
// MakeRequestInfo extracts the relevant information from a BatchRequest.
|
// MakeRequestInfo extracts the relevant information from a BatchRequest.
|
||||||
func MakeRequestInfo(req *tikvrpc.Request) *RequestInfo {
|
func MakeRequestInfo(req *tikvrpc.Request) *RequestInfo {
|
||||||
var bypass bool
|
bypass := shouldBypass(req)
|
||||||
requestSource := req.Context.GetRequestSource()
|
|
||||||
if len(requestSource) > 0 {
|
|
||||||
if strings.Contains(requestSource, util.InternalRequestPrefix+util.InternalTxnOthers) {
|
|
||||||
bypass = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
storeID := req.Context.GetPeer().GetStoreId()
|
storeID := req.Context.GetPeer().GetStoreId()
|
||||||
if !req.IsTxnWriteRequest() && !req.IsRawWriteRequest() {
|
if !req.IsTxnWriteRequest() && !req.IsRawWriteRequest() {
|
||||||
return &RequestInfo{
|
return &RequestInfo{
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,8 @@ const (
|
||||||
InternalTxnGC = "gc"
|
InternalTxnGC = "gc"
|
||||||
// InternalTxnMeta is the type of the miscellaneous meta usage.
|
// InternalTxnMeta is the type of the miscellaneous meta usage.
|
||||||
InternalTxnMeta = InternalTxnOthers
|
InternalTxnMeta = InternalTxnOthers
|
||||||
|
// InternalTxnStats is the type of statistics txn.
|
||||||
|
InternalTxnStats = "stats"
|
||||||
)
|
)
|
||||||
|
|
||||||
// explicit source types.
|
// explicit source types.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue