Skip to content

Commit 0f31032

Browse files
[cli] [topo] Migrate topo flags to pflags (vitessio#11393)
* [cli] [topo] Migrate topo flags to pflags Signed-off-by: Rameez Sajwani <[email protected]> * fix vtorc test Signed-off-by: Rameez Sajwani <[email protected]> * feat: fix VTOrc test Signed-off-by: Manan Gupta <[email protected]> * feat: remove binaries from the list that don't need the flags Signed-off-by: Manan Gupta <[email protected]> * test: update flag help outputs Signed-off-by: Manan Gupta <[email protected]> * code review Signed-off-by: Rameez Sajwani <[email protected]> * fix import formatting Signed-off-by: Rameez Sajwani <[email protected]> Signed-off-by: Rameez Sajwani <[email protected]> Signed-off-by: Manan Gupta <[email protected]> Co-authored-by: Manan Gupta <[email protected]>
1 parent 2e05ab0 commit 0f31032

File tree

38 files changed

+154
-151
lines changed

38 files changed

+154
-151
lines changed

go/cmd/vtctldclient/command/reparents.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func commandTabletExternallyReparented(cmd *cobra.Command, args []string) error
277277
}
278278

279279
func init() {
280-
EmergencyReparentShard.Flags().DurationVar(&emergencyReparentShardOptions.WaitReplicasTimeout, "wait-replicas-timeout", *topo.RemoteOperationTimeout, "Time to wait for replicas to catch up in reparenting.")
280+
EmergencyReparentShard.Flags().DurationVar(&emergencyReparentShardOptions.WaitReplicasTimeout, "wait-replicas-timeout", topo.RemoteOperationTimeout, "Time to wait for replicas to catch up in reparenting.")
281281
EmergencyReparentShard.Flags().StringVar(&emergencyReparentShardOptions.NewPrimaryAliasStr, "new-primary", "", "Alias of a tablet that should be the new primary. If not specified, the vtctld will select the best candidate to promote.")
282282
EmergencyReparentShard.Flags().BoolVar(&emergencyReparentShardOptions.PreventCrossCellPromotion, "prevent-cross-cell-promotion", false, "Only promotes a new primary from the same cell as the previous primary.")
283283
EmergencyReparentShard.Flags().StringSliceVarP(&emergencyReparentShardOptions.IgnoreReplicaAliasStrList, "ignore-replicas", "i", nil, "Comma-separated, repeated list of replica tablet aliases to ignore during the emergency reparent.")
@@ -287,7 +287,7 @@ func init() {
287287
InitShardPrimary.Flags().BoolVar(&initShardPrimaryOptions.Force, "force", false, "Force the reparent even if the provided tablet is not writable or the shard primary.")
288288
Root.AddCommand(InitShardPrimary)
289289

290-
PlannedReparentShard.Flags().DurationVar(&plannedReparentShardOptions.WaitReplicasTimeout, "wait-replicas-timeout", *topo.RemoteOperationTimeout, "Time to wait for replicas to catch up on replication both before and after reparenting.")
290+
PlannedReparentShard.Flags().DurationVar(&plannedReparentShardOptions.WaitReplicasTimeout, "wait-replicas-timeout", topo.RemoteOperationTimeout, "Time to wait for replicas to catch up on replication both before and after reparenting.")
291291
PlannedReparentShard.Flags().StringVar(&plannedReparentShardOptions.NewPrimaryAliasStr, "new-primary", "", "Alias of a tablet that should be the new primary.")
292292
PlannedReparentShard.Flags().StringVar(&plannedReparentShardOptions.AvoidPrimaryAliasStr, "avoid-primary", "", "Alias of a tablet that should not be the primary; i.e. \"reparent to any other tablet if this one is the primary\".")
293293
Root.AddCommand(PlannedReparentShard)

go/flags/endtoend/mysqlctl.txt

-4
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,13 @@ Global flags:
103103
--port int port for the server
104104
--pprof strings enable profiling
105105
--purge_logs_interval duration how often try to remove old logs (default 1h0m0s)
106-
--remote_operation_timeout duration time to wait for a remote operation (default 30s)
107106
--replication_connect_retry duration how long to wait in between replica reconnect attempts. Only precise to the second. (default 10s)
108107
--security_policy string the name of a registered security policy to use for controlling access to URLs - empty means allow all for anyone (built-in policies: deny-all, read-only)
109108
--service_map strings comma separated list of services to enable (or disable if prefixed with '-') Example: grpc-queryservice
110109
--socket_file string Local unix socket file to listen on
111110
--stderrthreshold severity logs at or above this threshold go to stderr (default 1)
112111
--tablet_dir string The directory within the vtdataroot to store vttablet/mysql files. Defaults to being generated by the tablet uid.
113112
--tablet_uid uint Tablet UID (default 41983)
114-
--topo_global_root string the path of the global topology data in the global topology server
115-
--topo_global_server_address string the address of the global topology server
116-
--topo_implementation string the topology implementation to use
117113
-v, --v Level log level for V logs
118114
--version print binary version
119115
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging

go/flags/endtoend/mysqlctld.txt

-4
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,13 @@ Usage of mysqlctld:
9191
--port int port for the server
9292
--pprof strings enable profiling
9393
--purge_logs_interval duration how often try to remove old logs (default 1h0m0s)
94-
--remote_operation_timeout duration time to wait for a remote operation (default 30s)
9594
--replication_connect_retry duration how long to wait in between replica reconnect attempts. Only precise to the second. (default 10s)
9695
--security_policy string the name of a registered security policy to use for controlling access to URLs - empty means allow all for anyone (built-in policies: deny-all, read-only)
9796
--service_map strings comma separated list of services to enable (or disable if prefixed with '-') Example: grpc-queryservice
9897
--socket_file string Local unix socket file to listen on
9998
--stderrthreshold severity logs at or above this threshold go to stderr (default 1)
10099
--tablet_dir string The directory within the vtdataroot to store vttablet/mysql files. Defaults to being generated by the tablet uid.
101100
--tablet_uid uint Tablet UID (default 41983)
102-
--topo_global_root string the path of the global topology data in the global topology server
103-
--topo_global_server_address string the address of the global topology server
104-
--topo_implementation string the topology implementation to use
105101
-v, --v Level log level for V logs
106102
--version print binary version
107103
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging

go/flags/endtoend/vtctldclient.txt

-4
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ Flags:
108108
--logtostderr log to standard error instead of files
109109
--mysql_server_version string MySQL server version to advertise.
110110
--purge_logs_interval duration how often try to remove old logs (default 1h0m0s)
111-
--remote_operation_timeout duration time to wait for a remote operation (default 30s)
112111
--security_policy string the name of a registered security policy to use for controlling access to URLs - empty means allow all for anyone (built-in policies: deny-all, read-only)
113112
--server string server to use for connection (required)
114113
--stats_backend string The name of the registered push-based monitoring/stats backend to use
@@ -117,9 +116,6 @@ Flags:
117116
--stats_drop_variables string Variables to be dropped from the list of exported variables.
118117
--stats_emit_period duration Interval between emitting stats to all registered backends (default 1m0s)
119118
--stderrthreshold severity logs at or above this threshold go to stderr (default 1)
120-
--topo_global_root string the path of the global topology data in the global topology server
121-
--topo_global_server_address string the address of the global topology server
122-
--topo_implementation string the topology implementation to use
123119
-v, --v Level log level for V logs
124120
--version version for vtctldclient
125121
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging

go/flags/endtoend/vttestserver.txt

-8
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ Usage of vttestserver:
8888
--purge_logs_interval duration how often try to remove old logs (default 1h0m0s)
8989
--queryserver-config-transaction-timeout float query server transaction timeout (in seconds), a transaction will be killed if it takes longer than this value
9090
--rdonly_count int Rdonly tablets per shard (default 1)
91-
--remote_operation_timeout duration time to wait for a remote operation (default 30s)
9291
--replica_count int Replica tablets per shard (includes primary) (default 2)
9392
--replication_connect_retry duration how long to wait in between replica reconnect attempts. Only precise to the second. (default 10s)
9493
--rng_seed int The random number generator seed to use when initializing with random data (see also --initialize_with_random_data). Multiple runs with the same seed will result with the same initial data. (default 123)
@@ -113,13 +112,6 @@ Usage of vttestserver:
113112
--topo_consul_lock_session_checks string List of checks for consul session. (default "serfHealth")
114113
--topo_consul_lock_session_ttl string TTL for consul session.
115114
--topo_consul_watch_poll_duration duration time of the long poll for watch queries. (default 30s)
116-
--topo_etcd_lease_ttl int Lease TTL for locks and leader election. The client will use KeepAlive to keep the lease going. (default 30)
117-
--topo_etcd_tls_ca string path to the ca to use to validate the server cert when connecting to the etcd topo server
118-
--topo_etcd_tls_cert string path to the client cert to use to connect to the etcd topo server, requires topo_etcd_tls_key, enables TLS
119-
--topo_etcd_tls_key string path to the client key to use to connect to the etcd topo server, enables TLS
120-
--topo_global_root string the path of the global topology data in the global topology server
121-
--topo_global_server_address string the address of the global topology server
122-
--topo_implementation string the topology implementation to use
123115
--topo_zk_auth_file string auth to use when connecting to the zk topo server, file contents should be <scheme>:<auth>, e.g., digest:user:pass
124116
--topo_zk_base_timeout duration zk base timeout (see zk.Connect) (default 30s)
125117
--topo_zk_max_concurrency int maximum number of pending requests to send to a Zookeeper server. (default 64)

go/test/endtoend/cluster/cluster_process.go

-2
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,6 @@ func (cluster *LocalProcessCluster) StartKeyspaceLegacy(keyspace Keyspace, shard
583583
// This does not start any process and user have to explicitly start all
584584
// the required services (ex topo, vtgate, mysql and vttablet)
585585
func (cluster *LocalProcessCluster) SetupCluster(keyspace *Keyspace, shards []Shard) (err error) {
586-
587586
log.Infof("Starting keyspace: %v", keyspace.Name)
588587

589588
if !cluster.ReusingVTDATAROOT {
@@ -598,7 +597,6 @@ func (cluster *LocalProcessCluster) SetupCluster(keyspace *Keyspace, shards []Sh
598597
// Create shard
599598
for _, shard := range shards {
600599
for _, tablet := range shard.Vttablets {
601-
602600
// Setup MysqlctlProcess
603601
tablet.MysqlctlProcess = *MysqlCtlProcessInstance(tablet.TabletUID, tablet.MySQLPort, cluster.TmpDirectory)
604602
// Setup VttabletProcess

go/test/endtoend/vtorc/readtopologyinstance/main_test.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ limitations under the License.
1717
package readtopologyinstance
1818

1919
import (
20-
"flag"
2120
"fmt"
21+
"os"
2222
"testing"
2323
"time"
2424

2525
"vitess.io/vitess/go/test/endtoend/cluster"
2626
"vitess.io/vitess/go/test/endtoend/vtorc/utils"
27+
"vitess.io/vitess/go/vt/servenv"
2728
"vitess.io/vitess/go/vt/vtorc/config"
2829
"vitess.io/vitess/go/vt/vtorc/inst"
2930
"vitess.io/vitess/go/vt/vtorc/server"
3031

3132
_ "github.com/go-sql-driver/mysql"
3233
_ "github.com/mattn/go-sqlite3"
33-
3434
"github.com/stretchr/testify/assert"
3535
"github.com/stretchr/testify/require"
3636
)
@@ -42,13 +42,19 @@ func TestReadTopologyInstanceBufferable(t *testing.T) {
4242
}()
4343
keyspace := &clusterInfo.ClusterInstance.Keyspaces[0]
4444
shard0 := &keyspace.Shards[0]
45+
oldArgs := os.Args
46+
defer func() {
47+
// Restore the old args after the test
48+
os.Args = oldArgs
49+
}()
4550

46-
err := flag.Set("topo_global_server_address", clusterInfo.ClusterInstance.VtctlProcess.TopoGlobalAddress)
47-
require.NoError(t, err)
48-
err = flag.Set("topo_implementation", clusterInfo.ClusterInstance.VtctlProcess.TopoImplementation)
49-
require.NoError(t, err)
50-
err = flag.Set("topo_global_root", clusterInfo.ClusterInstance.VtctlProcess.TopoGlobalRoot)
51-
require.NoError(t, err)
51+
// Change the args such that they match how we would invoke VTOrc
52+
os.Args = []string{"vtorc",
53+
"--topo_global_server_address", clusterInfo.ClusterInstance.VtctlProcess.TopoGlobalAddress,
54+
"--topo_implementation", clusterInfo.ClusterInstance.VtctlProcess.TopoImplementation,
55+
"--topo_global_root", clusterInfo.ClusterInstance.VtctlProcess.TopoGlobalRoot,
56+
}
57+
servenv.ParseFlags("vtorc")
5258
config.Config.RecoveryPeriodBlockSeconds = 1
5359
config.Config.InstancePollSeconds = 1
5460
config.MarkConfigurationLoaded()

go/vt/discovery/tablet_picker.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func (tp *TabletPicker) GetMatchingTablets(ctx context.Context) []*topo.TabletIn
172172
// Since there is only one primary, we ignore cell and find the primary
173173
aliases := make([]*topodatapb.TabletAlias, 0)
174174
if len(tp.tabletTypes) == 1 && tp.tabletTypes[0] == topodatapb.TabletType_PRIMARY {
175-
shortCtx, cancel := context.WithTimeout(ctx, *topo.RemoteOperationTimeout)
175+
shortCtx, cancel := context.WithTimeout(ctx, topo.RemoteOperationTimeout)
176176
defer cancel()
177177
si, err := tp.ts.GetShard(shortCtx, tp.keyspace, tp.shard)
178178
if err != nil {
@@ -185,12 +185,12 @@ func (tp *TabletPicker) GetMatchingTablets(ctx context.Context) []*topo.TabletIn
185185
for _, cell := range tp.cells {
186186
// check if cell is actually an alias
187187
// non-blocking read so that this is fast
188-
shortCtx, cancel := context.WithTimeout(ctx, *topo.RemoteOperationTimeout)
188+
shortCtx, cancel := context.WithTimeout(ctx, topo.RemoteOperationTimeout)
189189
defer cancel()
190190
_, err := tp.ts.GetCellInfo(shortCtx, cell, false)
191191
if err != nil {
192192
// not a valid cell, check whether it is a cell alias
193-
shortCtx, cancel := context.WithTimeout(ctx, *topo.RemoteOperationTimeout)
193+
shortCtx, cancel := context.WithTimeout(ctx, topo.RemoteOperationTimeout)
194194
defer cancel()
195195
alias, err := tp.ts.GetCellsAlias(shortCtx, cell, false)
196196
// if we get an error, either cellAlias doesn't exist or it isn't a cell alias at all. Ignore and continue
@@ -205,7 +205,7 @@ func (tp *TabletPicker) GetMatchingTablets(ctx context.Context) []*topo.TabletIn
205205
}
206206
}
207207
for _, cell := range actualCells {
208-
shortCtx, cancel := context.WithTimeout(ctx, *topo.RemoteOperationTimeout)
208+
shortCtx, cancel := context.WithTimeout(ctx, topo.RemoteOperationTimeout)
209209
defer cancel()
210210
// match cell, keyspace and shard
211211
sri, err := tp.ts.GetShardReplication(shortCtx, cell, tp.keyspace, tp.shard)
@@ -222,7 +222,7 @@ func (tp *TabletPicker) GetMatchingTablets(ctx context.Context) []*topo.TabletIn
222222
if len(aliases) == 0 {
223223
return nil
224224
}
225-
shortCtx, cancel := context.WithTimeout(ctx, *topo.RemoteOperationTimeout)
225+
shortCtx, cancel := context.WithTimeout(ctx, topo.RemoteOperationTimeout)
226226
defer cancel()
227227
tabletMap, err := tp.ts.GetTabletMap(shortCtx, aliases)
228228
if err != nil {

go/vt/mysqlctl/builtinbackupengine.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func (be *BuiltinBackupEngine) ExecuteBackup(ctx context.Context, params BackupP
269269
// the saved replicationPosition before proceeding
270270
tmc := tmclient.NewTabletManagerClient()
271271
defer tmc.Close()
272-
remoteCtx, remoteCancel := context.WithTimeout(ctx, *topo.RemoteOperationTimeout)
272+
remoteCtx, remoteCancel := context.WithTimeout(ctx, topo.RemoteOperationTimeout)
273273
defer remoteCancel()
274274

275275
pos, err := getPrimaryPosition(remoteCtx, tmc, params.TopoServer, params.Keyspace, params.Shard)

go/vt/schemamanager/tablet_executor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ func (exec *TabletExecutor) Execute(ctx context.Context, sqls []string) *Execute
360360
}
361361
providedUUID := ""
362362

363-
rl := timer.NewRateLimiter(*topo.RemoteOperationTimeout / 4)
363+
rl := timer.NewRateLimiter(topo.RemoteOperationTimeout / 4)
364364
defer rl.Stop()
365365

366366
syncOperationExecuted := false

go/vt/topo/cell_info.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (ts *Server) DeleteCellInfo(ctx context.Context, cell string, force bool) e
163163
// local-down-topo scenario would mean we never can delete it.
164164
// (see https://github.com/vitessio/vitess/issues/8220).
165165
var cancel context.CancelFunc
166-
ctx, cancel = context.WithTimeout(context.Background(), *RemoteOperationTimeout)
166+
ctx, cancel = context.WithTimeout(context.Background(), RemoteOperationTimeout)
167167
defer cancel()
168168
default:
169169
// Context still has some time left, no need to make a new one.
@@ -207,13 +207,13 @@ func (ts *Server) ExpandCells(ctx context.Context, cells string) ([]string, erro
207207
}
208208

209209
expandCell := func(ctx context.Context, cell string) error {
210-
shortCtx, cancel := context.WithTimeout(ctx, *RemoteOperationTimeout)
210+
shortCtx, cancel := context.WithTimeout(ctx, RemoteOperationTimeout)
211211
defer cancel()
212212

213213
_, err := ts.GetCellInfo(shortCtx, cell, false /* strongRead */)
214214
if err != nil {
215215
// Not a valid cell name. Check whether it is an alias.
216-
shortCtx, cancel := context.WithTimeout(ctx, *RemoteOperationTimeout)
216+
shortCtx, cancel := context.WithTimeout(ctx, RemoteOperationTimeout)
217217
defer cancel()
218218

219219
alias, err2 := ts.GetCellsAlias(shortCtx, cell, false /* strongRead */)

go/vt/topo/consultopo/watch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (s *Server) Watch(ctx context.Context, filePath string) (*topo.WatchData, <
4848
nodePath := path.Join(s.root, filePath)
4949
options := &api.QueryOptions{}
5050

51-
initialCtx, initialCancel := context.WithTimeout(ctx, *topo.RemoteOperationTimeout)
51+
initialCtx, initialCancel := context.WithTimeout(ctx, topo.RemoteOperationTimeout)
5252
defer initialCancel()
5353

5454
pair, _, err := s.kv.Get(nodePath, options.WithContext(initialCtx))

go/vt/topo/etcd2topo/lock.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ import (
2323

2424
"github.com/spf13/pflag"
2525

26-
"vitess.io/vitess/go/vt/servenv"
27-
2826
"go.etcd.io/etcd/api/v3/mvccpb"
2927
clientv3 "go.etcd.io/etcd/client/v3"
3028

3129
"vitess.io/vitess/go/vt/log"
3230
"vitess.io/vitess/go/vt/proto/vtrpc"
31+
"vitess.io/vitess/go/vt/servenv"
3332
"vitess.io/vitess/go/vt/topo"
3433
"vitess.io/vitess/go/vt/vterrors"
3534
)
@@ -39,8 +38,7 @@ var (
3938
)
4039

4140
func init() {
42-
for _, cmd := range []string{"vttablet", "vtctl", "vtctld", "mysqlctl", "mysqlctld", "vttestserver", "vtcombo", "vtctldclient", "vtexplain", "vtgate",
43-
"vtgr", "vtorc", "vtbackup"} {
41+
for _, cmd := range topo.FlagBinaries {
4442
servenv.OnParseFor(cmd, registerEtcd2TopoLockFlags)
4543
}
4644
}

go/vt/topo/etcd2topo/server.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ import (
4040
"time"
4141

4242
"github.com/spf13/pflag"
43-
44-
"vitess.io/vitess/go/vt/servenv"
45-
4643
"go.etcd.io/etcd/client/pkg/v3/tlsutil"
4744
"google.golang.org/grpc"
4845

4946
clientv3 "go.etcd.io/etcd/client/v3"
5047

48+
"vitess.io/vitess/go/vt/servenv"
5149
"vitess.io/vitess/go/vt/topo"
5250
)
5351

@@ -82,8 +80,7 @@ type Server struct {
8280
}
8381

8482
func init() {
85-
for _, cmd := range []string{"vttablet", "vtctl", "vtctld", "mysqlctl", "mysqlctld", "vttestserver", "vtcombo", "vtctldclient", "vtexplain", "vtgate",
86-
"vtgr", "vtorc", "vtbackup"} {
83+
for _, cmd := range topo.FlagBinaries {
8784
servenv.OnParseFor(cmd, registerEtcd2TopoFlags)
8885
}
8986
topo.RegisterFactory("etcd2", Factory{})

0 commit comments

Comments
 (0)