Skip to content

Commit

Permalink
Merge branch 'master' into bot/update-owners-1723456948376
Browse files Browse the repository at this point in the history
  • Loading branch information
cfzjywxk authored Aug 16, 2024
2 parents 0b3507c + c810ed8 commit eb941f7
Show file tree
Hide file tree
Showing 10 changed files with 431 additions and 83 deletions.
16 changes: 16 additions & 0 deletions config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ const (
DefGrpcInitialWindowSize = 1 << 27 // 128MiB
DefGrpcInitialConnWindowSize = 1 << 27 // 128MiB
DefMaxConcurrencyRequestLimit = math.MaxInt64
DefBatchPolicy = BatchPolicyStandard
)

const (
// BatchPolicyBasic is the basic batch policy whose behavior is consistent with versions before v8.3.0.
BatchPolicyBasic = "basic"
// BatchPolicyStandard dynamically batches requests based the arrival time intervals of recent requests.
BatchPolicyStandard = "standard"
// BatchPolicyPositive always performs additional batching.
BatchPolicyPositive = "positive"
// BatchPolicyCustom allows users to customize the internal batch options.
BatchPolicyCustom = "custom"
)

// TiKVClient is the config for tikv client.
Expand All @@ -72,6 +84,9 @@ type TiKVClient struct {
// CommitTimeout is the max time which command 'commit' will wait.
CommitTimeout string `toml:"commit-timeout" json:"commit-timeout"`
AsyncCommit AsyncCommit `toml:"async-commit" json:"async-commit"`

// BatchPolicy is the policy for batching requests.
BatchPolicy string `toml:"batch-policy" json:"batch-policy"`
// MaxBatchSize is the max batch size when calling batch commands API.
MaxBatchSize uint `toml:"max-batch-size" json:"max-batch-size"`
// If TiKV load is greater than this, TiDB will wait for a while to avoid little batch.
Expand Down Expand Up @@ -153,6 +168,7 @@ func DefaultTiKVClient() TiKVClient {
AllowedClockDrift: 500 * time.Millisecond,
},

BatchPolicy: DefBatchPolicy,
MaxBatchSize: 128,
OverloadThreshold: 200,
MaxBatchWaitTime: 0,
Expand Down
6 changes: 3 additions & 3 deletions config/retry/backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestBackoffErrorType(t *testing.T) {
assert.Nil(t, err)
// 6ms sleep at most in total
for i := 0; i < 2; i++ {
err = b.Backoff(BoMaxDataNotReady, errors.New("data not ready"))
err = b.Backoff(BoMaxRegionNotInitialized, errors.New("region not initialized"))
assert.Nil(t, err)
}
// 100ms sleep at most in total
Expand Down Expand Up @@ -88,15 +88,15 @@ func TestBackoffDeepCopy(t *testing.T) {
b := NewBackofferWithVars(context.TODO(), 4, nil)
// 700 ms sleep in total and the backoffer will return an error next time.
for i := 0; i < 3; i++ {
err = b.Backoff(BoMaxDataNotReady, errors.New("data not ready"))
err = b.Backoff(BoMaxRegionNotInitialized, errors.New("region not initialized"))
assert.Nil(t, err)
}
bForked, cancel := b.Fork()
defer cancel()
bCloned := b.Clone()
for _, b := range []*Backoffer{bForked, bCloned} {
err = b.Backoff(BoTiKVRPC, errors.New("tikv rpc"))
assert.ErrorIs(t, err, BoMaxDataNotReady.err)
assert.ErrorIs(t, err, BoMaxRegionNotInitialized.err)
}
}

Expand Down
1 change: 0 additions & 1 deletion config/retry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ var (
BoTxnNotFound = NewConfig("txnNotFound", &metrics.BackoffHistogramEmpty, NewBackoffFnCfg(2, 500, NoJitter), tikverr.ErrResolveLockTimeout)
BoStaleCmd = NewConfig("staleCommand", &metrics.BackoffHistogramStaleCmd, NewBackoffFnCfg(2, 1000, NoJitter), tikverr.ErrTiKVStaleCommand)
BoMaxTsNotSynced = NewConfig("maxTsNotSynced", &metrics.BackoffHistogramEmpty, NewBackoffFnCfg(2, 500, NoJitter), tikverr.ErrTiKVMaxTimestampNotSynced)
BoMaxDataNotReady = NewConfig("dataNotReady", &metrics.BackoffHistogramDataNotReady, NewBackoffFnCfg(2, 2000, NoJitter), tikverr.ErrRegionDataNotReady)
BoMaxRegionNotInitialized = NewConfig("regionNotInitialized", &metrics.BackoffHistogramEmpty, NewBackoffFnCfg(2, 1000, NoJitter), tikverr.ErrRegionNotInitialized)
BoIsWitness = NewConfig("isWitness", &metrics.BackoffHistogramIsWitness, NewBackoffFnCfg(1000, 10000, EqualJitter), tikverr.ErrIsWitness)
// TxnLockFast's `base` load from vars.BackoffLockFast when create BackoffFn.
Expand Down
4 changes: 2 additions & 2 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ func (a *connArray) Init(addr string, security config.Security, idleNotify *uint
allowBatch := (cfg.TiKVClient.MaxBatchSize > 0) && enableBatch
if allowBatch {
a.batchConn = newBatchConn(uint(len(a.v)), cfg.TiKVClient.MaxBatchSize, idleNotify)
a.pendingRequests = metrics.TiKVBatchPendingRequests.WithLabelValues(a.target)
a.batchSize = metrics.TiKVBatchRequests.WithLabelValues(a.target)
a.batchConn.initMetrics(a.target)
}
keepAlive := cfg.TiKVClient.GrpcKeepAliveTime
keepAliveTimeout := cfg.TiKVClient.GrpcKeepAliveTimeout
Expand Down Expand Up @@ -365,6 +364,7 @@ func (a *connArray) Init(addr string, security config.Security, idleNotify *uint
dialTimeout: a.dialTimeout,
tryLock: tryLock{sync.NewCond(new(sync.Mutex)), false},
eventListener: eventListener,
metrics: &a.metrics,
}
batchClient.maxConcurrencyRequestLimit.Store(cfg.TiKVClient.MaxConcurrencyRequestLimit)
a.batchCommandsClients = append(a.batchCommandsClients, batchClient)
Expand Down
Loading

0 comments on commit eb941f7

Please sign in to comment.