Skip to content

Commit dd873af

Browse files
authored
Allow EXPERIMENTAL tablet type in init-tablet-type (vitessio#20067) (#856)
Signed-off-by: Eduardo Ortega <5791035+ejortegau@users.noreply.github.com>
1 parent 835e9f1 commit dd873af

4 files changed

Lines changed: 18 additions & 8 deletions

File tree

go/flags/endtoend/vtcombo.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Flags:
181181
--init_db_name_override string (init parameter) override the name of the db used by vttablet. Without this flag, the db name defaults to vt_<keyspacename>
182182
--init_keyspace string (init parameter) keyspace to use for this tablet
183183
--init_shard string (init parameter) shard to use for this tablet
184-
--init_tablet_type string (init parameter) the tablet type to use for this tablet. Can be REPLICA, RDONLY, or SPARE. The default is REPLICA.
184+
--init_tablet_type string (init parameter) tablet type to use for this tablet. Valid values are: REPLICA, RDONLY, EXPERIMENTAL and SPARE. The default is REPLICA.
185185
--init_tags StringMap (init parameter) comma separated list of key:value pairs used to tag the tablet
186186
--init_timeout duration (init parameter) timeout to use for the init phase. (default 1m0s)
187187
--jaeger-agent-host string host and port to send spans to. if empty, no tracing will be done

go/flags/endtoend/vttablet.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ Flags:
209209
--init_db_name_override string (init parameter) override the name of the db used by vttablet. Without this flag, the db name defaults to vt_<keyspacename>
210210
--init_keyspace string (init parameter) keyspace to use for this tablet
211211
--init_shard string (init parameter) shard to use for this tablet
212-
--init_tablet_type string (init parameter) the tablet type to use for this tablet. Can be REPLICA, RDONLY, or SPARE. The default is REPLICA.
212+
--init_tablet_type string (init parameter) tablet type to use for this tablet. Valid values are: REPLICA, RDONLY, EXPERIMENTAL and SPARE. The default is REPLICA.
213213
--init_tags StringMap (init parameter) comma separated list of key:value pairs used to tag the tablet
214214
--init_timeout duration (init parameter) timeout to use for the init phase. (default 1m0s)
215215
--jaeger-agent-host string host and port to send spans to. if empty, no tracing will be done

go/vt/vttablet/tabletmanager/tm_init.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func registerInitFlags(fs *pflag.FlagSet) {
105105
fs.StringVar(&tabletHostname, "tablet_hostname", tabletHostname, "if not empty, this hostname will be assumed instead of trying to resolve it")
106106
fs.StringVar(&initKeyspace, "init_keyspace", initKeyspace, "(init parameter) keyspace to use for this tablet")
107107
fs.StringVar(&initShard, "init_shard", initShard, "(init parameter) shard to use for this tablet")
108-
fs.StringVar(&initTabletType, "init_tablet_type", initTabletType, "(init parameter) the tablet type to use for this tablet. Can be REPLICA, RDONLY, or SPARE. The default is REPLICA.")
108+
fs.StringVar(&initTabletType, "init_tablet_type", initTabletType, "(init parameter) tablet type to use for this tablet. Valid values are: REPLICA, RDONLY, EXPERIMENTAL and SPARE. The default is REPLICA.")
109109
fs.BoolVar(&initTabletTypeLookup, "init-tablet-type-lookup", initTabletTypeLookup, "(Experimental, init parameter) if enabled, uses tablet alias to look up the tablet type from the existing topology record on restart and use that instead of init_tablet_type. This allows tablets to maintain their changed roles (e.g., RDONLY/DRAINED) across restarts. If disabled or if no topology record exists, init_tablet_type will be used.")
110110
fs.StringVar(&initDbNameOverride, "init_db_name_override", initDbNameOverride, "(init parameter) override the name of the db used by vttablet. Without this flag, the db name defaults to vt_<keyspacename>")
111111
fs.StringVar(&skipBuildInfoTags, "vttablet_skip_buildinfo_tags", skipBuildInfoTags, "comma-separated list of buildinfo tags to skip from merging with --init_tags. each tag is either an exact match or a regular expression of the form '/regexp/'.")
@@ -254,9 +254,9 @@ func BuildTabletFromInput(alias *topodatapb.TabletAlias, port, grpcPort int32, d
254254
return nil, err
255255
}
256256
switch tabletType {
257-
case topodatapb.TabletType_SPARE, topodatapb.TabletType_REPLICA, topodatapb.TabletType_RDONLY:
257+
case topodatapb.TabletType_SPARE, topodatapb.TabletType_REPLICA, topodatapb.TabletType_RDONLY, topodatapb.TabletType_EXPERIMENTAL:
258258
default:
259-
return nil, fmt.Errorf("invalid init_tablet_type %v; can only be REPLICA, RDONLY or SPARE", tabletType)
259+
return nil, fmt.Errorf("invalid init_tablet_type %v; can only be REPLICA, RDONLY, EXPERIMENTAL or SPARE", tabletType)
260260
}
261261

262262
buildTags, err := getBuildTags(servenv.AppVersion.ToStringMap(), skipBuildInfoTags)

go/vt/vttablet/tabletmanager/tm_init_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,19 @@ func TestStartBuildTabletFromInput(t *testing.T) {
123123
_, err = BuildTabletFromInput(alias, port, grpcport, nil, collations.MySQL8())
124124
assert.Contains(t, err.Error(), "unknown TabletType bad")
125125

126-
initTabletType = "primary"
127-
_, err = BuildTabletFromInput(alias, port, grpcport, nil, collations.MySQL8())
128-
assert.Contains(t, err.Error(), "invalid init_tablet_type PRIMARY")
126+
for _, invalidType := range []string{"primary", "backup", "restore", "drained"} {
127+
initTabletType = invalidType
128+
_, err = BuildTabletFromInput(alias, port, grpcport, nil, collations.MySQL8())
129+
require.Error(t, err, "expected tablet type %q to be invalid", invalidType)
130+
assert.Contains(t, err.Error(), "invalid init_tablet_type")
131+
}
132+
133+
for _, validType := range []string{"replica", "rdonly", "spare", "experimental"} {
134+
initTabletType = validType
135+
gotTablet, err = BuildTabletFromInput(alias, port, grpcport, nil, collations.MySQL8())
136+
require.NoError(t, err, "expected tablet type %q to be valid", validType)
137+
assert.NotNil(t, gotTablet)
138+
}
129139
}
130140

131141
func TestBuildTabletFromInputWithBuildTags(t *testing.T) {

0 commit comments

Comments
 (0)