Skip to content

Commit

Permalink
[VEP-4, phase 1] Flag cleanup in go/cmd (vitessio#9896)
Browse files Browse the repository at this point in the history
* [vttestserver] tidy imports

Signed-off-by: Andrew Mason <[email protected]>

* [vttestserver] fix flags

Signed-off-by: Andrew Mason <[email protected]>

* [vttlstest] fix flags in usage message

Signed-off-by: Andrew Mason <[email protected]>

* [vtclient] fix flags

Signed-off-by: Andrew Mason <[email protected]>

* [vttablet] tidy imports

Signed-off-by: Andrew Mason <[email protected]>

* [vttablet] fix flags in error messages

Signed-off-by: Andrew Mason <[email protected]>

* [mysqlctl] fix flags in usage strings

Signed-off-by: Andrew Mason <[email protected]>

* [vtbackup] fix flags in error strings

Signed-off-by: Andrew Mason <[email protected]>

* [vtbench] fix flags in example comments

Signed-off-by: Andrew Mason <[email protected]>

* [vtclient] fix flags in usage strings

Signed-off-by: Andrew Mason <[email protected]>

* [vtexplain] fix flags in usage

Signed-off-by: Andrew Mason <[email protected]>

* [vtctldclient] fix flags and some usages while here

Signed-off-by: Andrew Mason <[email protected]>

* Need to update tests in vt/vttest as well for tests to pass

Signed-off-by: Andrew Mason <[email protected]>

* No double dash needed for `vtctlclient`, only for `vtctl` directly, apparently

Signed-off-by: Andrew Mason <[email protected]>
  • Loading branch information
Andrew Mason authored Mar 17, 2022
1 parent 81e0853 commit 0fb472e
Show file tree
Hide file tree
Showing 18 changed files with 166 additions and 165 deletions.
8 changes: 4 additions & 4 deletions go/cmd/mysqlctl/mysqlctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,17 +203,17 @@ type command struct {
}

var commands = []command{
{"init", initCmd, "[-wait_time=5m] [-init_db_sql_file=]",
{"init", initCmd, "[--wait_time=5m] [--init_db_sql_file=]",
"Initializes the directory structure and starts mysqld"},
{"init_config", initConfigCmd, "",
"Initializes the directory structure, creates my.cnf file, but does not start mysqld"},
{"reinit_config", reinitConfigCmd, "",
"Reinitializes my.cnf file with new server_id"},
{"teardown", teardownCmd, "[-wait_time=5m] [-force]",
{"teardown", teardownCmd, "[--wait_time=5m] [--force]",
"Shuts mysqld down, and removes the directory"},
{"start", startCmd, "[-wait_time=5m]",
{"start", startCmd, "[--wait_time=5m]",
"Starts mysqld on an already 'init'-ed directory"},
{"shutdown", shutdownCmd, "[-wait_time=5m]",
{"shutdown", shutdownCmd, "[--wait_time=5m]",
"Shuts down mysqld, does not remove any file"},

{"position", positionCmd,
Expand Down
6 changes: 3 additions & 3 deletions go/cmd/vtbackup/vtbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func takeBackup(ctx context.Context, topoServer *topo.Server, backupStorage back
case mysqlctl.ErrNoBackup:
// There is no backup found, but we may be taking the initial backup of a shard
if !*allowFirstBackup {
return fmt.Errorf("no backup found; not starting up empty since -initial_backup flag was not enabled")
return fmt.Errorf("no backup found; not starting up empty since --initial_backup flag was not enabled")
}
restorePos = mysql.Position{}
default:
Expand Down Expand Up @@ -634,14 +634,14 @@ func shouldBackup(ctx context.Context, topoServer *topo.Server, backupStorage ba

// We need at least one backup so we can restore first, unless the user explicitly says we don't
if len(backups) == 0 && !*allowFirstBackup {
return false, fmt.Errorf("no existing backups to restore from; backup is not possible since -initial_backup flag was not enabled")
return false, fmt.Errorf("no existing backups to restore from; backup is not possible since --initial_backup flag was not enabled")
}
if lastBackup == nil {
if *allowFirstBackup {
// There's no complete backup, but we were told to take one from scratch anyway.
return true, nil
}
return false, fmt.Errorf("no complete backups to restore from; backup is not possible since -initial_backup flag was not enabled")
return false, fmt.Errorf("no complete backups to restore from; backup is not possible since --initial_backup flag was not enabled")
}

// Has it been long enough since the last complete backup to need a new one?
Expand Down
46 changes: 23 additions & 23 deletions go/cmd/vtbench/vtbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,36 @@ import (
Mysql protocol to vtgate:
vtbench \
-protocol mysql \
-host vtgate-host.my.domain \
-port 15306 \
-user db_username \
-db-credentials-file ./vtbench_db_creds.json \
-db @replica \
-sql "select * from loadtest_table where id=123456789" \
-threads 10 \
-count 10
--protocol mysql \
--host vtgate-host.my.domain \
--port 15306 \
--user db_username \
--db-credentials-file ./vtbench_db_creds.json \
--db @replica \
--sql "select * from loadtest_table where id=123456789" \
--threads 10 \
--count 10
GRPC to vtgate:
vtbench \
-protocol grpc-vtgate \
-host vtgate-host.my.domain \
-port 15999 \
-db @replica \
--protocol grpc-vtgate \
--host vtgate-host.my.domain \
--port 15999 \
--db @replica \
$VTTABLET_GRPC_ARGS \
-sql "select * from loadtest_table where id=123456789" \
-threads 10 \
-count 10
--sql "select * from loadtest_table where id=123456789" \
--threads 10 \
--count 10
GRPC to vttablet:
vtbench \
-protocol grpc-vttablet \
-host tablet-loadtest-00-80.my.domain \
-port 15999 \
-db loadtest/00-80@replica \
-sql "select * from loadtest_table where id=123456789" \
-threads 10 \
-count 10
--protocol grpc-vttablet \
--host tablet-loadtest-00-80.my.domain \
--port 15999 \
--db loadtest/00-80@replica \
--sql "select * from loadtest_table where id=123456789" \
--threads 10 \
--count 10
*/

Expand Down
4 changes: 2 additions & 2 deletions go/cmd/vtclient/vtclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ in the form of :v1, :v2, etc.
Examples:
$ vtclient -server vtgate:15991 "SELECT * FROM messages"
$ vtclient --server vtgate:15991 "SELECT * FROM messages"
$ vtclient -server vtgate:15991 -target '@primary' -bind_variables '[ 12345, 1, "msg 12345" ]' "INSERT INTO messages (page,time_created_ns,message) VALUES (:v1, :v2, :v3)"
$ vtclient --server vtgate:15991 --target '@primary' --bind_variables '[ 12345, 1, "msg 12345" ]' "INSERT INTO messages (page,time_created_ns,message) VALUES (:v1, :v2, :v3)"
`
server = flag.String("server", "", "vtgate server to connect to")
Expand Down
12 changes: 6 additions & 6 deletions go/cmd/vtclient/vtclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,27 @@ func TestVtclient(t *testing.T) {
args: []string{"SELECT * FROM table1"},
},
{
args: []string{"-target", "@primary", "-bind_variables", `[ 1, 100 ]`,
args: []string{"--target", "@primary", "--bind_variables", `[ 1, 100 ]`,
"INSERT INTO table1 (id, i) VALUES (:v1, :v2)"},
rowsAffected: 1,
},
{
args: []string{"-target", "@primary",
args: []string{"--target", "@primary",
"UPDATE table1 SET i = (i + 1)"},
rowsAffected: 1,
},
{
args: []string{"-target", "@primary",
args: []string{"--target", "@primary",
"SELECT * FROM table1"},
rowsAffected: 1,
},
{
args: []string{"-target", "@primary", "-bind_variables", `[ 1 ]`,
args: []string{"--target", "@primary", "--bind_variables", `[ 1 ]`,
"DELETE FROM table1 WHERE id = :v1"},
rowsAffected: 1,
},
{
args: []string{"-target", "@primary",
args: []string{"--target", "@primary",
"SELECT * FROM table1"},
rowsAffected: 0,
},
Expand All @@ -124,7 +124,7 @@ func TestVtclient(t *testing.T) {
for _, q := range queries {
// Run main function directly and not as external process. To achieve this,
// overwrite os.Args which is used by flag.Parse().
os.Args = []string{"vtclient_test.go", "-server", vtgateAddr}
os.Args = []string{"vtclient_test.go", "--server", vtgateAddr}
os.Args = append(os.Args, q.args...)

results, err := run()
Expand Down
4 changes: 2 additions & 2 deletions go/cmd/vtctldclient/command/legacy_shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ LegacyVtctlCommand -- help # displays help for supported legacy vtctl commands
# before the first flag argument, like in the first example. The double dash may
# be used, however, at any point after the "LegacyVtctlCommand" string, as in
# the second example.
LegacyVtctlCommand AddCellInfo -- -server_address "localhost:1234" -root "/vitess/cell1"
LegacyVtctlCommand -- AddCellInfo -server_address "localhost:5678" -root "/vitess/cell1"`),
LegacyVtctlCommand AddCellInfo -- --server_address "localhost:1234" --root "/vitess/cell1"
LegacyVtctlCommand -- AddCellInfo --server_address "localhost:5678" --root "/vitess/cell1"`),
}
)

Expand Down
2 changes: 1 addition & 1 deletion go/cmd/vtctldclient/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var (
}
)

var errNoServer = errors.New("please specify -server <vtctld_host:vtctld_port> to specify the vtctld server to connect to")
var errNoServer = errors.New("please specify --server <vtctld_host:vtctld_port> to specify the vtctld server to connect to")

// ensureServerArg validates that --server was passed to the CLI.
func ensureServerArg() error {
Expand Down
14 changes: 8 additions & 6 deletions go/cmd/vtctldclient/command/vschemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ import (
var (
// GetVSchema makes a GetVSchema gRPC call to a vtctld.
GetVSchema = &cobra.Command{
Use: "GetVSchema keyspace",
Args: cobra.ExactArgs(1),
RunE: commandGetVSchema,
Use: "GetVSchema <keyspace>",
Short: "Prints a JSON representation of a keyspace's topo record.",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
RunE: commandGetVSchema,
}
// ApplyVSchema makes an ApplyVSchema gRPC call to a vtctld.
ApplyVSchema = &cobra.Command{
Use: "ApplyVSchema {-vschema=<vschema> || -vschema-file=<vschema file> || -sql=<sql> || -sql-file=<sql file>} [-cells=c1,c2,...] [-skip-rebuild] [-dry-run] <keyspace>",
Args: cobra.ExactArgs(1),
Use: "ApplyVSchema {--vschema=<vschema> || --vschema-file=<vschema file> || --sql=<sql> || --sql-file=<sql file>} [--cells=c1,c2,...] [--skip-rebuild] [--dry-run] <keyspace>",
Short: "Applies the VTGate routing schema to the provided keyspace. Shows the result after application.",
DisableFlagsInUseLine: true,
Args: cobra.ExactArgs(1),
RunE: commandApplyVSchema,
Short: "Applies the VTGate routing schema to the provided keyspace. Shows the result after application.",
}
)

Expand Down
2 changes: 1 addition & 1 deletion go/cmd/vtexplain/vtexplain.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (
vschemaFileFlag = flag.String("vschema-file", "", "Identifies the VTGate routing schema file")
ksShardMapFlag = flag.String("ks-shard-map", "", "JSON map of keyspace name -> shard name -> ShardReference object. The inner map is the same as the output of FindAllShardsInKeyspace")
ksShardMapFileFlag = flag.String("ks-shard-map-file", "", "File containing json blob of keyspace name -> shard name -> ShardReference object")
numShards = flag.Int("shards", 2, "Number of shards per keyspace. Passing -ks-shard-map/-ks-shard-map-file causes this flag to be ignored.")
numShards = flag.Int("shards", 2, "Number of shards per keyspace. Passing --ks-shard-map/--ks-shard-map-file causes this flag to be ignored.")
executionMode = flag.String("execution-mode", "multi", "The execution mode to simulate -- must be set to multi, legacy-autocommit, or twopc")
replicationMode = flag.String("replication-mode", "ROW", "The replication mode to simulate -- must be set to either ROW or STATEMENT")
normalize = flag.Bool("normalize", false, "Whether to enable vtgate normalization")
Expand Down
13 changes: 7 additions & 6 deletions go/cmd/vttablet/vttablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import (
"flag"
"os"

rice "github.com/GeertJohan/go.rice"

"vitess.io/vitess/go/vt/binlog"
"vitess.io/vitess/go/vt/dbconfigs"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/mysqlctl"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/tableacl"
"vitess.io/vitess/go/vt/tableacl/simpleacl"
Expand All @@ -40,7 +41,7 @@ import (
"vitess.io/vitess/go/vt/vttablet/tabletserver/tabletenv"
"vitess.io/vitess/go/yaml2"

rice "github.com/GeertJohan/go.rice"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
)

var (
Expand All @@ -65,11 +66,11 @@ func main() {
servenv.Init()

if *tabletPath == "" {
log.Exit("-tablet-path required")
log.Exit("--tablet-path required")
}
tabletAlias, err := topoproto.ParseTabletAlias(*tabletPath)
if err != nil {
log.Exitf("failed to parse -tablet-path: %v", err)
log.Exitf("failed to parse --tablet-path: %v", err)
}

// config and mycnf initializations are intertwined.
Expand All @@ -92,7 +93,7 @@ func main() {
}
tablet, err := tabletmanager.BuildTabletFromInput(tabletAlias, int32(*servenv.Port), gRPCPort, mysqld.GetVersionString(), config.DB)
if err != nil {
log.Exitf("failed to parse -tablet-path: %v", err)
log.Exitf("failed to parse --tablet-path: %v", err)
}
tm = &tabletmanager.TabletManager{
BatchCtx: context.Background(),
Expand All @@ -106,7 +107,7 @@ func main() {
MetadataManager: &mysqlctl.MetadataManager{},
}
if err := tm.Start(tablet, config.Healthcheck.IntervalSeconds.Get()); err != nil {
log.Exitf("failed to parse -tablet-path or initialize DB credentials: %v", err)
log.Exitf("failed to parse --tablet-path or initialize DB credentials: %v", err)
}
servenv.OnClose(func() {
// Close the tm so that our topo entry gets pruned properly and any
Expand Down
7 changes: 4 additions & 3 deletions go/cmd/vttestserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ import (
"google.golang.org/protobuf/encoding/prototext"

"vitess.io/vitess/go/vt/log"
vttestpb "vitess.io/vitess/go/vt/proto/vttest"
"vitess.io/vitess/go/vt/vttest"

vttestpb "vitess.io/vitess/go/vt/proto/vttest"
)

type topoFlags struct {
Expand Down Expand Up @@ -87,8 +88,8 @@ func init() {
"If this flag is set, the MySQL data directory is not cleaned up"+
" when LocalCluster.TearDown() is called. This is useful for running"+
" vttestserver as a database container in local developer environments. Note"+
" that db migration files (-schema_dir option) and seeding of"+
" random data (-initialize_with_random_data option) will only run during"+
" that db migration files (--schema_dir option) and seeding of"+
" random data (--initialize_with_random_data option) will only run during"+
" cluster startup if the data directory does not already exist. vschema"+
" migrations are run every time the cluster starts, since persistence"+
" for the topology server has not been implemented yet")
Expand Down
Loading

0 comments on commit 0fb472e

Please sign in to comment.