@@ -20,6 +20,7 @@ import (
2020
2121 "github.com/pingcap/kvproto/pkg/coprocessor"
2222 "github.com/pingcap/kvproto/pkg/kvrpcpb"
23+ "github.com/tikv/client-go/v2/config"
2324 "github.com/tikv/client-go/v2/kv"
2425 "github.com/tikv/client-go/v2/tikvrpc"
2526 "github.com/tikv/client-go/v2/util"
@@ -53,15 +54,28 @@ func toPDAccessLocationType(accessType kv.AccessLocationType) controller.AccessL
5354 }
5455}
5556
56- // MakeRequestInfo extracts the relevant information from a BatchRequest.
57- func MakeRequestInfo (req * tikvrpc.Request ) * RequestInfo {
58- var bypass bool
57+ // reqTypeAnalyze is the type of analyze coprocessor request.
58+ // ref: https://github.com/pingcap/tidb/blob/ee4eac2ccb83e1ea653b8131d9a43495019cb5ac/pkg/kv/kv.go#L340
59+ const reqTypeAnalyze = 104
60+
61+ func shouldBypass (req * tikvrpc.Request ) bool {
5962 requestSource := req .Context .GetRequestSource ()
60- if len (requestSource ) > 0 {
61- if strings .Contains (requestSource , util .InternalRequestPrefix + util .InternalTxnOthers ) {
62- bypass = true
63- }
63+ // Check both coprocessor request type and the request source to ensure the request is an internal analyze request.
64+ // Internal analyze request may consume a lot of resources, bypass it to avoid affecting the user experience.
65+ // This bypass currently only works with NextGen.
66+ if config .NextGen && (req .BatchCop ().GetTp () == reqTypeAnalyze || req .Cop ().GetTp () == reqTypeAnalyze ) &&
67+ strings .Contains (requestSource , util .InternalTxnStats ) {
68+ return true
6469 }
70+ // Some internal requests should be bypassed, which may affect the user experience.
71+ // For example, the `alter user password` request completely bypasses resource control.
72+ // Although it does not consume many resources, it can still impact the user experience.
73+ return strings .Contains (requestSource , util .InternalRequestPrefix + util .InternalTxnOthers )
74+ }
75+
76+ // MakeRequestInfo extracts the relevant information from a BatchRequest.
77+ func MakeRequestInfo (req * tikvrpc.Request ) * RequestInfo {
78+ bypass := shouldBypass (req )
6579 storeID := req .Context .GetPeer ().GetStoreId ()
6680 if ! req .IsTxnWriteRequest () && ! req .IsRawWriteRequest () {
6781 return & RequestInfo {
0 commit comments