Skip to content

Commit

Permalink
bypass internal others request
Browse files Browse the repository at this point in the history
Signed-off-by: nolouch <[email protected]>
  • Loading branch information
nolouch committed Jul 12, 2023
1 parent f04046a commit 8a21727
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions internal/client/client_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ func buildResourceControlInterceptor(
// Build the interceptor.
interceptFn := func(next interceptor.RPCInterceptorFunc) interceptor.RPCInterceptorFunc {
return func(target string, req *tikvrpc.Request) (*tikvrpc.Response, error) {
// 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 reqInfo.Bypass() {
return next(target, req)
}
consumption, penalty, err := resourceControlInterceptor.OnRequestWait(ctx, resourceGroupName, reqInfo)
if err != nil {
return nil, err
Expand Down
21 changes: 20 additions & 1 deletion internal/resourcecontrol/resource_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ package resourcecontrol

import (
"reflect"
"strings"
"time"

"github.com/pingcap/kvproto/pkg/coprocessor"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
"github.com/tikv/client-go/v2/internal/logutil"
"github.com/tikv/client-go/v2/tikvrpc"
"github.com/tikv/client-go/v2/util"
"go.uber.org/zap"
)

Expand All @@ -34,6 +36,9 @@ type RequestInfo struct {
writeBytes int64
storeID uint64
replicaNumber int64
// bypass indicates whether the request should be bypassed.
// some internal request should be bypassed, such as Privilege request.
bypass bool
}

// MakeRequestInfo extracts the relevant information from a BatchRequest.
Expand All @@ -43,6 +48,8 @@ func MakeRequestInfo(req *tikvrpc.Request) *RequestInfo {
}

var writeBytes int64
var requestSource string
var bypass bool
switch r := req.Req.(type) {
case *kvrpcpb.PrewriteRequest:
for _, m := range r.Mutations {
Expand All @@ -52,12 +59,19 @@ func MakeRequestInfo(req *tikvrpc.Request) *RequestInfo {
for _, l := range r.Secondaries {
writeBytes += int64(len(l))
}
requestSource = r.GetContext().GetRequestSource()
case *kvrpcpb.CommitRequest:
for _, k := range r.Keys {
writeBytes += int64(len(k))
}
requestSource = r.GetContext().GetRequestSource()
}
return &RequestInfo{writeBytes: writeBytes, storeID: req.Context.Peer.StoreId, replicaNumber: req.ReplicaNumber}
if len(requestSource) > 0 {
if strings.Contains(requestSource, util.InternalRequest+"_"+util.InternalTxnOthers) {
bypass = true
}
}
return &RequestInfo{writeBytes: writeBytes, storeID: req.Context.Peer.StoreId, replicaNumber: req.ReplicaNumber, bypass: bypass}
}

// IsWrite returns whether the request is a write request.
Expand All @@ -75,6 +89,11 @@ func (req *RequestInfo) ReplicaNumber() int64 {
return req.replicaNumber
}

// Bypass returns whether the request should be bypassed.
func (req *RequestInfo) Bypass() bool {
return req.bypass
}

func (req *RequestInfo) StoreID() uint64 {
return req.storeID
}
Expand Down

0 comments on commit 8a21727

Please sign in to comment.