github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/pkg/config/kvclient.go (about)

     1  // Copyright 2021 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package config
    15  
    16  import "github.com/pingcap/tiflow/pkg/errors"
    17  
    18  // KVClientConfig represents config for kv client
    19  type KVClientConfig struct {
    20  	EnableMultiplexing bool `toml:"enable-multiplexing" json:"enable-multiplexing"`
    21  	// how many workers will be used for a single region worker
    22  	WorkerConcurrent uint `toml:"worker-concurrent" json:"worker-concurrent"`
    23  	// how many grpc streams will be established to every TiKV node
    24  	GrpcStreamConcurrent uint `toml:"grpc-stream-concurrent" json:"grpc-stream-concurrent"`
    25  	// Advance table ResolvedTs interval.
    26  	AdvanceIntervalInMs uint `toml:"advance-interval-in-ms" json:"advance-interval-in-ms"`
    27  	// how many goroutines to maintain frontiers.
    28  	FrontierConcurrent uint `toml:"frontier-concurrent" json:"frontier-concurrent"`
    29  	// background workerpool size, the workrpool is shared by all goroutines in cdc server
    30  	WorkerPoolSize int `toml:"worker-pool-size" json:"worker-pool-size"`
    31  	// region incremental scan limit for one table in a single store
    32  	RegionScanLimit int `toml:"region-scan-limit" json:"region-scan-limit"`
    33  	// the total retry duration of connecting a region
    34  	RegionRetryDuration TomlDuration `toml:"region-retry-duration" json:"region-retry-duration"`
    35  }
    36  
    37  // ValidateAndAdjust validates and adjusts the kv client configuration
    38  func (c *KVClientConfig) ValidateAndAdjust() error {
    39  	if c.RegionScanLimit <= 0 {
    40  		return errors.ErrInvalidServerOption.GenWithStackByArgs(
    41  			"region-scan-limit should be at least 1")
    42  	}
    43  	if c.RegionRetryDuration <= 0 {
    44  		return errors.ErrInvalidServerOption.GenWithStackByArgs(
    45  			"region-scan-limit should be positive")
    46  	}
    47  	return nil
    48  }