Skip to content

Commit

Permalink
tools/tso: add option useTSOServerProxy in pd-tso-bench (#7756)
Browse files Browse the repository at this point in the history
ref #8135

Signed-off-by: lhy1024 <admin@liudos.us>

Co-authored-by: Hu# <jinhao.hu@pingcap.com>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 21, 2024
1 parent 41e6376 commit 8215f30
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
14 changes: 14 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ func WithForwardingOption(enableForwarding bool) ClientOption {
}
}

// WithTSOServerProxyOption configures the client to use TSO server proxy,
// i.e., the client will send TSO requests to the API leader (the TSO server
// proxy) which will forward the requests to the TSO servers.
func WithTSOServerProxyOption(useTSOServerProxy bool) ClientOption {
return func(c *client) {
c.option.useTSOServerProxy = useTSOServerProxy
}
}

// WithMaxErrorRetry configures the client max retry times when connect meets error.
func WithMaxErrorRetry(count int) ClientOption {
return func(c *client) {
Expand Down Expand Up @@ -648,6 +657,11 @@ func (c *client) setServiceMode(newMode pdpb.ServiceMode) {
c.Lock()
defer c.Unlock()

if c.option.useTSOServerProxy {
// If we are using TSO server proxy, we always use PD_SVC_MODE.
newMode = pdpb.ServiceMode_PD_SVC_MODE
}

if newMode == c.serviceMode {
return
}
Expand Down
13 changes: 7 additions & 6 deletions client/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ const (
// It provides the ability to change some PD client's options online from the outside.
type option struct {
// Static options.
gRPCDialOptions []grpc.DialOption
timeout time.Duration
maxRetryTimes int
enableForwarding bool
metricsLabels prometheus.Labels
initMetrics bool
gRPCDialOptions []grpc.DialOption
timeout time.Duration
maxRetryTimes int
enableForwarding bool
useTSOServerProxy bool
metricsLabels prometheus.Labels
initMetrics bool

// Dynamic options.
dynamicOptions [dynamicOptionCount]atomic.Value
Expand Down
4 changes: 4 additions & 0 deletions tools/pd-tso-bench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var (
maxTSOSendIntervalMilliseconds = flag.Int("max-send-interval-ms", 0, "max tso send interval in milliseconds, 60s by default")
keyspaceID = flag.Uint("keyspace-id", 0, "the id of the keyspace to access")
keyspaceName = flag.String("keyspace-name", "", "the name of the keyspace to access")
useTSOServerProxy = flag.Bool("use-tso-server-proxy", false, "whether send tso requests to tso server proxy instead of tso service directly")
wg sync.WaitGroup
)

Expand Down Expand Up @@ -424,6 +425,9 @@ func createPDClient(ctx context.Context) (pd.Client, error) {
)

opts := make([]pd.ClientOption, 0)
if *useTSOServerProxy {
opts = append(opts, pd.WithTSOServerProxyOption(true))
}
opts = append(opts, pd.WithGRPCDialOptions(
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: keepaliveTime,
Expand Down

0 comments on commit 8215f30

Please sign in to comment.