Skip to content

Commit 8215f30

Browse files
lhy1024HuSharpti-chi-bot[bot]
authored
tools/tso: add option useTSOServerProxy in pd-tso-bench (#7756)
ref #8135 Signed-off-by: lhy1024 <[email protected]> Co-authored-by: Hu# <[email protected]> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
1 parent 41e6376 commit 8215f30

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

Diff for: client/client.go

+14
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,15 @@ func WithForwardingOption(enableForwarding bool) ClientOption {
268268
}
269269
}
270270

271+
// WithTSOServerProxyOption configures the client to use TSO server proxy,
272+
// i.e., the client will send TSO requests to the API leader (the TSO server
273+
// proxy) which will forward the requests to the TSO servers.
274+
func WithTSOServerProxyOption(useTSOServerProxy bool) ClientOption {
275+
return func(c *client) {
276+
c.option.useTSOServerProxy = useTSOServerProxy
277+
}
278+
}
279+
271280
// WithMaxErrorRetry configures the client max retry times when connect meets error.
272281
func WithMaxErrorRetry(count int) ClientOption {
273282
return func(c *client) {
@@ -648,6 +657,11 @@ func (c *client) setServiceMode(newMode pdpb.ServiceMode) {
648657
c.Lock()
649658
defer c.Unlock()
650659

660+
if c.option.useTSOServerProxy {
661+
// If we are using TSO server proxy, we always use PD_SVC_MODE.
662+
newMode = pdpb.ServiceMode_PD_SVC_MODE
663+
}
664+
651665
if newMode == c.serviceMode {
652666
return
653667
}

Diff for: client/option.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ const (
5151
// It provides the ability to change some PD client's options online from the outside.
5252
type option struct {
5353
// Static options.
54-
gRPCDialOptions []grpc.DialOption
55-
timeout time.Duration
56-
maxRetryTimes int
57-
enableForwarding bool
58-
metricsLabels prometheus.Labels
59-
initMetrics bool
54+
gRPCDialOptions []grpc.DialOption
55+
timeout time.Duration
56+
maxRetryTimes int
57+
enableForwarding bool
58+
useTSOServerProxy bool
59+
metricsLabels prometheus.Labels
60+
initMetrics bool
6061

6162
// Dynamic options.
6263
dynamicOptions [dynamicOptionCount]atomic.Value

Diff for: tools/pd-tso-bench/main.go

+4
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ var (
6262
maxTSOSendIntervalMilliseconds = flag.Int("max-send-interval-ms", 0, "max tso send interval in milliseconds, 60s by default")
6363
keyspaceID = flag.Uint("keyspace-id", 0, "the id of the keyspace to access")
6464
keyspaceName = flag.String("keyspace-name", "", "the name of the keyspace to access")
65+
useTSOServerProxy = flag.Bool("use-tso-server-proxy", false, "whether send tso requests to tso server proxy instead of tso service directly")
6566
wg sync.WaitGroup
6667
)
6768

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

426427
opts := make([]pd.ClientOption, 0)
428+
if *useTSOServerProxy {
429+
opts = append(opts, pd.WithTSOServerProxyOption(true))
430+
}
427431
opts = append(opts, pd.WithGRPCDialOptions(
428432
grpc.WithKeepaliveParams(keepalive.ClientParameters{
429433
Time: keepaliveTime,

0 commit comments

Comments
 (0)