@@ -54,11 +54,14 @@ var (
5454 tlsMountPath string
5555 tlsFromEnv bool
5656 insecureSkipVerify bool
57+
58+ // Flags for PD region API access
59+ pdEndpointsStr string
5760)
5861
5962//nolint:mnd,errcheck
6063func main () {
61- flag .StringVar (& action , "action" , "ping" , "ping, workload, import" )
64+ flag .StringVar (& action , "action" , "ping" , "ping, workload, import, pd-region " )
6265 flag .StringVar (& host , "host" , "" , "host" )
6366 flag .StringVar (& port , "port" , "4000" , "port" )
6467 flag .StringVar (& user , "user" , "root" , "db user" )
@@ -85,53 +88,71 @@ func main() {
8588 flag .BoolVar (& tlsFromEnv , "tls-from-env" , false , "load TLS certificates from environment variables" )
8689 flag .BoolVar (& insecureSkipVerify , "tls-insecure-skip-verify" , false , "skip TLS certificate verification" )
8790
88- flag .Parse ()
91+ // Flags for PD region API access
92+ flag .StringVar (& pdEndpointsStr , "pd-endpoints" , "" , "comma-separated PD endpoints for pd-region action" )
8993
90- // enable "cleartext client side plugin" for `tidb_auth_token`.
91- // ref: https://github.com/go-sql-driver/mysql?tab=readme-ov-file#allowcleartextpasswords
92- params := []string {
93- "charset=utf8mb4" ,
94- "allowCleartextPasswords=true" ,
95- "timeout=5s" ,
96- }
94+ flag .Parse ()
9795
98- // Setup TLS if enabled
99- if enableTLS {
100- tlsConfigName , err := setupTLSConfig ( )
101- if err != nil {
102- panic ( fmt . Errorf ( "failed to setup TLS config: %w" , err ) )
96+ // Parse PD endpoints for pd-region action
97+ if action == "pd-region" && pdEndpointsStr != "" {
98+ pdEndpoints = strings . Split ( pdEndpointsStr , "," )
99+ for i , endpoint := range pdEndpoints {
100+ pdEndpoints [ i ] = strings . TrimSpace ( endpoint )
103101 }
104- params = append (params , fmt .Sprintf ("tls=%s" , tlsConfigName ))
105102 }
106103
107- db , err := sql .Open ("mysql" , fmt .Sprintf ("%s:%s@(%s:%s)/test?%s" , user , password , host , port , strings .Join (params , "&" )))
108- if err != nil {
109- panic (err )
110- }
111- defer db .Close ()
112-
113104 switch action {
114- case "ping " :
115- if err := Ping ( db ); err != nil {
105+ case "pd-region " :
106+ if err := PDRegionAccess ( ); err != nil {
116107 panic (err )
117108 }
118- case "workload" :
119- if err := Workload (db ); err != nil {
120- panic (err )
109+ default :
110+ // enable "cleartext client side plugin" for `tidb_auth_token`.
111+ // ref: https://github.com/go-sql-driver/mysql?tab=readme-ov-file#allowcleartextpasswords
112+ params := []string {
113+ "charset=utf8mb4" ,
114+ "allowCleartextPasswords=true" ,
115+ "timeout=5s" ,
121116 }
122- case "import" :
123- importCfg := ImportDataConfig {
124- DB : db ,
125- BatchSize : batchSize ,
126- TotalRows : totalRows ,
127- TableName : importTable ,
128- SplitRegionCount : splitRegionCount ,
117+
118+ // Setup TLS if enabled
119+ if enableTLS {
120+ tlsConfigName , err := setupTLSConfig ()
121+ if err != nil {
122+ panic (fmt .Errorf ("failed to setup TLS config: %w" , err ))
123+ }
124+ params = append (params , fmt .Sprintf ("tls=%s" , tlsConfigName ))
129125 }
130- if err := ImportData (importCfg ); err != nil {
126+
127+ db , err := sql .Open ("mysql" , fmt .Sprintf ("%s:%s@(%s:%s)/test?%s" , user , password , host , port , strings .Join (params , "&" )))
128+ if err != nil {
131129 panic (err )
132130 }
133- default :
134- panic ("unknown action: " + action )
131+ defer db .Close ()
132+
133+ switch action {
134+ case "ping" :
135+ if err := Ping (db ); err != nil {
136+ panic (err )
137+ }
138+ case "workload" :
139+ if err := Workload (db ); err != nil {
140+ panic (err )
141+ }
142+ case "import" :
143+ importCfg := ImportDataConfig {
144+ DB : db ,
145+ BatchSize : batchSize ,
146+ TotalRows : totalRows ,
147+ TableName : importTable ,
148+ SplitRegionCount : splitRegionCount ,
149+ }
150+ if err := ImportData (importCfg ); err != nil {
151+ panic (err )
152+ }
153+ default :
154+ panic ("unknown action: " + action )
155+ }
135156 }
136157
137158 fmt .Println ("workload is done" )
0 commit comments