Skip to content

Commit ff4ea51

Browse files
authored
vttest: add gateway-initial-tablet-timeout flag to enable faster startup (#18887)
Signed-off-by: Armand Parajon <[email protected]>
1 parent b8a9fa1 commit ff4ea51

File tree

7 files changed

+46
-9
lines changed

7 files changed

+46
-9
lines changed

go/cmd/vttestserver/cli/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ func New() (cmd *cobra.Command) {
224224

225225
utils.SetFlagDurationVar(cmd.Flags(), &config.VtgateTabletRefreshInterval, "tablet-refresh-interval", 10*time.Second, "Interval at which vtgate refreshes tablet information from topology server.")
226226

227+
utils.SetFlagDurationVar(cmd.Flags(), &config.VtgateGatewayInitialTabletTimeout, "gateway-initial-tablet-timeout", 30*time.Second, "At startup, the tabletGateway will wait up to this duration to get at least one tablet per keyspace/shard/tablet type")
228+
227229
cmd.Flags().BoolVar(&doCreateTCPUser, "initialize-with-vt-dba-tcp", false, "If this flag is enabled, MySQL will be initialized with an additional user named vt_dba_tcp, who will have access via TCP/IP connection.")
228230

229231
utils.SetFlagBoolVar(cmd.Flags(), &config.NoScatter, "no-scatter", false, "when set to true, the planner will fail instead of producing a plan that includes scatter queries")

go/cmd/vttestserver/cli/main_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,21 @@ func TestCanGetKeyspaces(t *testing.T) {
254254
assertGetKeyspaces(ctx, t, clusterInstance)
255255
}
256256

257+
func TestGatewayInitialTabletTimeout(t *testing.T) {
258+
conf := config
259+
defer resetConfig(conf)
260+
261+
// Start cluster with custom gateway tablet timeout and verify it starts successfully
262+
cluster, err := startCluster("--gateway-initial-tablet-timeout=1s")
263+
require.NoError(t, err)
264+
defer cluster.TearDown()
265+
266+
// Verify the cluster is functional by getting keyspaces
267+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
268+
defer cancel()
269+
assertGetKeyspaces(ctx, t, cluster)
270+
}
271+
257272
func TestExternalTopoServerConsul(t *testing.T) {
258273
conf := config
259274
defer resetConfig(conf)

go/flags/endtoend/vtcombo.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ Flags:
132132
--external-topo-server Should vtcombo use an external topology server instead of starting its own in-memory topology server. If true, vtcombo will use the flags defined in topo/server.go to open topo server
133133
--foreign-key-mode string This is to provide how to handle foreign key constraint in create/alter table. Valid values are: allow, disallow (default "allow")
134134
--gate-query-cache-memory int gate server query cache size in bytes, maximum amount of memory to be cached. vtgate analyzes every incoming query and generate a query plan, these plans are being cached in a lru cache. This config controls the capacity of the lru cache. (default 33554432)
135+
--gateway-initial-tablet-timeout duration At startup, the tabletGateway will wait up to this duration to get at least one tablet per keyspace/shard/tablet type (default 30s)
135136
--gc-check-interval duration Interval between garbage collection checks (default 1h0m0s)
136137
--gc-purge-check-interval duration Interval between purge discovery checks (default 1m0s)
137138
--grpc-auth-mode string Which auth plugin implementation to use (eg: static)

go/flags/endtoend/vttestserver.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Flags:
4343
--external-topo-implementation string the topology implementation to use for vtcombo process
4444
--extra-my-cnf string extra files to add to the config, separated by ':'
4545
--foreign-key-mode string This is to provide how to handle foreign key constraint in create/alter table. Valid values are: allow, disallow (default "allow")
46+
--gateway-initial-tablet-timeout duration At startup, the tabletGateway will wait up to this duration to get at least one tablet per keyspace/shard/tablet type (default 30s)
4647
--grpc-auth-mode string Which auth plugin implementation to use (eg: static)
4748
--grpc-auth-mtls-allowed-substrings string List of substrings of at least one of the client certificate names (separated by colon).
4849
--grpc-auth-static-client-creds string When using grpc_static_auth in the server, this file provides the credentials to use to authenticate with server.

go/vt/vtgate/tabletgateway.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,23 @@ var (
6868
logCollations = logutil.NewThrottledLogger("CollationInconsistent", 1*time.Minute)
6969
)
7070

71+
func registerTabletGatewayFlags(fs *pflag.FlagSet) {
72+
utils.SetFlagStringVar(fs, &CellsToWatch, "cells-to-watch", "", "comma-separated list of cells for watching tablets")
73+
utils.SetFlagDurationVar(fs, &initialTabletTimeout, "gateway-initial-tablet-timeout", 30*time.Second, "At startup, the tabletGateway will wait up to this duration to get at least one tablet per keyspace/shard/tablet type")
74+
fs.IntVar(&retryCount, "retry-count", 2, "retry count")
75+
fs.BoolVar(&balancerEnabled, "enable-balancer", false, "(DEPRECATED: use --vtgate-balancer-mode instead) Enable the tablet balancer to evenly spread query load for a given tablet type")
76+
fs.StringVar(&balancerModeFlag, "vtgate-balancer-mode", "", fmt.Sprintf("Tablet balancer mode (options: %s). Defaults to 'cell' which shuffles tablets in the local cell.", strings.Join(balancer.GetAvailableModeNames(), ", ")))
77+
fs.StringSliceVar(&balancerVtgateCells, "balancer-vtgate-cells", []string{}, "Comma-separated list of cells that contain vttablets. For 'prefer-cell' mode, this is required. For 'random' mode, this is optional and filters tablets to those cells.")
78+
fs.StringSliceVar(&balancerKeyspaces, "balancer-keyspaces", []string{}, "Comma-separated list of keyspaces for which to use the balancer (optional). If empty, applies to all keyspaces.")
79+
}
80+
81+
func registerVtcomboTabletGatewayFlags(fs *pflag.FlagSet) {
82+
utils.SetFlagDurationVar(fs, &initialTabletTimeout, "gateway-initial-tablet-timeout", 30*time.Second, "At startup, the tabletGateway will wait up to this duration to get at least one tablet per keyspace/shard/tablet type")
83+
}
84+
7185
func init() {
72-
servenv.OnParseFor("vtgate", func(fs *pflag.FlagSet) {
73-
utils.SetFlagStringVar(fs, &CellsToWatch, "cells-to-watch", "", "comma-separated list of cells for watching tablets")
74-
utils.SetFlagDurationVar(fs, &initialTabletTimeout, "gateway-initial-tablet-timeout", 30*time.Second, "At startup, the tabletGateway will wait up to this duration to get at least one tablet per keyspace/shard/tablet type")
75-
fs.IntVar(&retryCount, "retry-count", 2, "retry count")
76-
fs.BoolVar(&balancerEnabled, "enable-balancer", false, "(DEPRECATED: use --vtgate-balancer-mode instead) Enable the tablet balancer to evenly spread query load for a given tablet type")
77-
fs.StringVar(&balancerModeFlag, "vtgate-balancer-mode", "", fmt.Sprintf("Tablet balancer mode (options: %s). Defaults to 'cell' which shuffles tablets in the local cell.", strings.Join(balancer.GetAvailableModeNames(), ", ")))
78-
fs.StringSliceVar(&balancerVtgateCells, "balancer-vtgate-cells", []string{}, "Comma-separated list of cells that contain vttablets. For 'prefer-cell' mode, this is required. For 'random' mode, this is optional and filters tablets to those cells.")
79-
fs.StringSliceVar(&balancerKeyspaces, "balancer-keyspaces", []string{}, "Comma-separated list of keyspaces for which to use the balancer (optional). If empty, applies to all keyspaces.")
80-
})
86+
servenv.OnParseFor("vtgate", registerTabletGatewayFlags)
87+
servenv.OnParseFor("vtcombo", registerVtcomboTabletGatewayFlags)
8188
}
8289

8390
// TabletGateway implements the Gateway interface.

go/vt/vttest/local_cluster.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ type Config struct {
160160

161161
VtgateTabletRefreshInterval time.Duration
162162

163+
// Gateway initial tablet timeout - how long VTGate waits for tablets at startup
164+
VtgateGatewayInitialTabletTimeout time.Duration
165+
163166
// Set the planner to fail on scatter queries
164167
NoScatter bool
165168
}

go/vt/vttest/vtprocess.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,14 @@ func VtcomboProcess(environment Environment, args *Config, mysql MySQLManager) (
279279
vt.ExtraArgs = append(vt.ExtraArgs, fmt.Sprintf("--tablet-refresh-interval=%v", args.VtgateTabletRefreshInterval))
280280
}
281281

282+
// If gateway initial tablet timeout is not defined then we will give it value of 30s (vtcombo default).
283+
// Setting it to a lower value will reduce the time VTGate waits for tablets at startup.
284+
if args.VtgateGatewayInitialTabletTimeout <= 0 {
285+
vt.ExtraArgs = append(vt.ExtraArgs, fmt.Sprintf("--gateway-initial-tablet-timeout=%v", 30*time.Second))
286+
} else {
287+
vt.ExtraArgs = append(vt.ExtraArgs, fmt.Sprintf("--gateway-initial-tablet-timeout=%v", args.VtgateGatewayInitialTabletTimeout))
288+
}
289+
282290
vt.ExtraArgs = append(vt.ExtraArgs, QueryServerArgs...)
283291
vt.ExtraArgs = append(vt.ExtraArgs, environment.VtcomboArguments()...)
284292

0 commit comments

Comments
 (0)