func main() { dbconfigs.RegisterFlags() flag.Parse() servenv.Init() dbConfigs, err := dbconfigs.Init("") if err != nil { log.Fatalf("Cannot initialize App dbconfig: %v", err) } if *enableRowcache { dbConfigs.App.EnableRowcache = true if *enableInvalidator { dbConfigs.App.EnableInvalidator = true } } mycnf := &mysqlctl.Mycnf{BinLogPath: *binlogPath} mysqld := mysqlctl.NewMysqld(mycnf, &dbConfigs.Dba, &dbConfigs.Repl) unmarshalFile(*overridesFile, &schemaOverrides) data, _ := json.MarshalIndent(schemaOverrides, "", " ") log.Infof("schemaOverrides: %s\n", data) ts.InitQueryService() ts.AllowQueries(&dbConfigs.App, schemaOverrides, ts.LoadCustomRules(), mysqld) log.Infof("starting vtocc %v", *servenv.Port) servenv.OnClose(func() { time.Sleep(5 * time.Millisecond) ts.DisallowQueries() }) servenv.Run() }
func main() { dbConfigsFile, dbCredentialsFile := dbconfigs.RegisterCommonFlags() flag.Parse() relog.Info("started vtaction %v", os.Args) rpc.HandleHTTP() jsonrpc.ServeHTTP() jsonrpc.ServeRPC() bsonrpc.ServeHTTP() bsonrpc.ServeRPC() logFile, err := os.OpenFile(*logFilename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666) if err != nil { relog.Fatal("Can't open log file: %v", err) } relog.SetOutput(logFile) relog.SetPrefix(fmt.Sprintf("vtaction [%v] ", os.Getpid())) if err := relog.SetLevelByName(*logLevel); err != nil { relog.Fatal("%v", err) } relog.HijackLog(nil) relog.HijackStdio(logFile, logFile) mycnf, mycnfErr := mysqlctl.ReadMycnf(*mycnfFile) if mycnfErr != nil { relog.Fatal("mycnf read failed: %v", mycnfErr) } relog.Debug("mycnf: %v", jscfg.ToJson(mycnf)) dbcfgs, cfErr := dbconfigs.Init(mycnf.SocketFile, *dbConfigsFile, *dbCredentialsFile) if err != nil { relog.Fatal("%s", cfErr) } mysqld := mysqlctl.NewMysqld(mycnf, dbcfgs.Dba, dbcfgs.Repl) topoServer := topo.GetServer() defer topo.CloseServers() actor := tabletmanager.NewTabletActor(mysqld, topoServer) // we delegate out startup to the micromanagement server so these actions // will occur after we have obtained our socket. bindAddr := fmt.Sprintf(":%v", *port) httpServer := &http.Server{Addr: bindAddr} go func() { if err := httpServer.ListenAndServe(); err != nil { relog.Error("httpServer.ListenAndServe err: %v", err) } }() actionErr := actor.HandleAction(*actionNode, *action, *actionGuid, *force) if actionErr != nil { relog.Fatal("action error: %v", actionErr) } relog.Info("finished vtaction %v", os.Args) }
// CreateMysqld returns a Mysqld object to use for working with a MySQL // installation that hasn't been set up yet. This will generate a new my.cnf // from scratch and use that to call NewMysqld(). func CreateMysqld(tabletUID uint32, mysqlSocket string, mysqlPort int32, dbconfigFlags dbconfigs.DBConfigFlag) (*Mysqld, error) { mycnf := NewMycnf(tabletUID, mysqlPort) // Choose a random MySQL server-id, since this is a fresh data dir. // We don't want to use the tablet UID as the MySQL server-id, // because reusing server-ids is not safe. // // For example, if a tablet comes back with an empty data dir, it will restore // from backup and then connect to the master. But if this tablet has the same // server-id as before, and if this tablet was recently a master, then it can // lose data by skipping binlog events due to replicate-same-server-id=FALSE, // which is the default setting. if err := mycnf.RandomizeMysqlServerID(); err != nil { return nil, fmt.Errorf("couldn't generate random MySQL server_id: %v", err) } if mysqlSocket != "" { mycnf.SocketFile = mysqlSocket } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, dbconfigFlags) if err != nil { return nil, fmt.Errorf("couldn't Init dbconfigs: %v", err) } return NewMysqld(mycnf, &dbcfgs.Dba, &dbcfgs.AllPrivs, &dbcfgs.App, &dbcfgs.Repl, true /* enablePublishStats */), nil }
func main() { dbConfigsFile, dbCredentialsFile := dbconfigs.RegisterCommonFlags() flag.Parse() servenv.Init() if *mycnfFile == "" { log.Fatalf("Please specify the path for mycnf file.") } mycnf, err := mysqlctl.ReadMycnf(*mycnfFile) if err != nil { log.Fatalf("Error reading mycnf file %v", *mycnfFile) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, *dbConfigsFile, *dbCredentialsFile) if err != nil { log.Warning(err) } mysqld := mysqlctl.NewMysqld(mycnf, dbcfgs.Dba, dbcfgs.Repl) binlogServer := mysqlctl.NewBinlogServer(mysqld) mysqlctl.EnableBinlogServerService(binlogServer, *dbname) proto.RegisterBinlogServer(binlogServer) rpcwrap.RegisterAuthenticated(binlogServer) servenv.OnClose(func() { mysqlctl.DisableBinlogServerService(binlogServer) }) servenv.Run(*port) }
func main() { defer exit.Recover() defer logutil.Flush() dbconfigs.RegisterFlags() flag.Parse() mycnf := mysqlctl.NewMycnf(uint32(*tabletUid), *mysqlPort) if *mysqlSocket != "" { mycnf.SocketFile = *mysqlSocket } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile) if err != nil { log.Errorf("%v", err) exit.Return(255) } mysqld = mysqlctl.NewMysqld("Dba", mycnf, &dbcfgs.Dba, &dbcfgs.Repl) // Register OnTerm handler before mysqld starts, so we get notified if mysqld // dies on its own without us (or our RPC client) telling it to. mysqldTerminated := make(chan struct{}) mysqld.OnTerm(func() { close(mysqldTerminated) }) // Start or Init mysqld as needed. if _, err = os.Stat(mycnf.DataDir); os.IsNotExist(err) { log.Infof("mysql data dir (%s) doesn't exist, initializing", mycnf.DataDir) mysqld.Init(*waitTime, *bootstrapArchive, *skipSchema) } else { log.Infof("mysql data dir (%s) already exists, starting without init", mycnf.DataDir) mysqld.Start(*waitTime) } servenv.Init() defer servenv.Close() // Take mysqld down with us on SIGTERM before entering lame duck. servenv.OnTerm(func() { log.Infof("mysqlctl received SIGTERM, shutting down mysqld first") mysqld.Shutdown(false, 0) }) // Start RPC server and wait for SIGTERM. mysqlctldTerminated := make(chan struct{}) go func() { servenv.RunDefault() close(mysqlctldTerminated) }() select { case <-mysqldTerminated: log.Infof("mysqld shut down on its own, exiting mysqlctld") case <-mysqlctldTerminated: log.Infof("mysqlctld shut down gracefully") } }
func main() { defer exit.Recover() // flag parsing flags := dbconfigs.AppConfig | dbconfigs.DbaConfig | dbconfigs.FilteredConfig | dbconfigs.ReplConfig dbconfigs.RegisterFlags(flags) mysqlctl.RegisterFlags() flag.Parse() if len(flag.Args()) > 0 { flag.Usage() log.Errorf("vtcombo doesn't take any positional arguments") exit.Return(1) } // register topo server topo.RegisterServer("fakezk", zktopo.NewServer(fakezk.NewConn())) ts := topo.GetServerByName("fakezk") servenv.Init() // database configs mycnf, err := mysqlctl.NewMycnfFromFlags(0) if err != nil { log.Errorf("mycnf read failed: %v", err) exit.Return(1) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, flags) if err != nil { log.Warning(err) } mysqld := mysqlctl.NewMysqld("Dba", "App", mycnf, &dbcfgs.Dba, &dbcfgs.App.ConnParams, &dbcfgs.Repl) // tablets configuration and init binlog.RegisterUpdateStreamService(mycnf) initTabletMap(ts, *topology, mysqld, dbcfgs, mycnf) // vtgate configuration and init resilientSrvTopoServer := vtgate.NewResilientSrvTopoServer(ts, "ResilientSrvTopoServer") healthCheck := discovery.NewHealthCheck(30*time.Second /*connTimeoutTotal*/, 1*time.Millisecond /*retryDelay*/) vtgate.Init(healthCheck, ts, resilientSrvTopoServer, nil /*schema*/, cell, 1*time.Millisecond /*retryDelay*/, 2 /*retryCount*/, 30*time.Second /*connTimeoutTotal*/, 10*time.Second /*connTimeoutPerConn*/, 365*24*time.Hour /*connLife*/, 0 /*maxInFlight*/, "" /*testGateway*/) servenv.OnTerm(func() { // FIXME(alainjobart) stop vtgate, all tablets // qsc.DisallowQueries() // agent.Stop() }) servenv.OnClose(func() { // We will still use the topo server during lameduck period // to update our state, so closing it in OnClose() topo.CloseServers() }) servenv.RunDefault() }
func main() { flag.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s [global parameters] command [command parameters]\n", os.Args[0]) fmt.Fprintf(os.Stderr, "\nThe global optional parameters are:\n") flag.PrintDefaults() fmt.Fprintf(os.Stderr, "\nThe commands are listed below. Use '%s <command> -h' for more help.\n\n", os.Args[0]) for _, cmd := range commands { fmt.Fprintf(os.Stderr, " %s", cmd.name) if cmd.params != "" { fmt.Fprintf(os.Stderr, " %s", cmd.params) } fmt.Fprintf(os.Stderr, "\n") } fmt.Fprintf(os.Stderr, "\n") } dbConfigsFile, dbCredentialsFile := dbconfigs.RegisterCommonFlags() flag.Parse() if err := relog.SetLevelByName(*logLevel); err != nil { relog.Fatal("%v", err) } tabletAddr = fmt.Sprintf("%v:%v", "localhost", *port) mycnf := mysqlctl.NewMycnf(uint32(*tabletUid), *mysqlPort, mysqlctl.VtReplParams{}) if *mysqlSocket != "" { mycnf.SocketFile = *mysqlSocket } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, *dbConfigsFile, *dbCredentialsFile) if err != nil { relog.Fatal("%v", err) } mysqld := mysqlctl.NewMysqld(mycnf, dbcfgs.Dba, dbcfgs.Repl) action := flag.Arg(0) for _, cmd := range commands { if cmd.name == action { subFlags := flag.NewFlagSet(action, flag.ExitOnError) subFlags.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s %s %s\n\n", os.Args[0], cmd.name, cmd.params) fmt.Fprintf(os.Stderr, "%s\n\n", cmd.help) subFlags.PrintDefaults() } cmd.method(mysqld, subFlags, flag.Args()[1:]) return } } relog.Fatal("invalid action: %v", action) }
func main() { dbconfigs.RegisterFlags() mysqlctl.RegisterFlags() flag.Parse() if len(flag.Args()) > 0 { flag.Usage() log.Fatalf("vttablet doesn't take any positional arguments") } servenv.Init() if *tabletPath == "" { log.Fatalf("tabletPath required") } tabletAlias := tabletParamToTabletAlias(*tabletPath) mycnf, err := mysqlctl.NewMycnfFromFlags(tabletAlias.Uid) if err != nil { log.Fatalf("mycnf read failed: %v", err) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile) if err != nil { log.Warning(err) } dbcfgs.App.EnableRowcache = *enableRowcache if *tableAclConfig != "" { tableacl.Init(*tableAclConfig) } tabletserver.InitQueryService() binlog.RegisterUpdateStreamService(mycnf) // Depends on both query and updateStream. agent, err = tabletmanager.NewActionAgent(tabletAlias, dbcfgs, mycnf, *servenv.Port, *servenv.SecurePort, *overridesFile) if err != nil { log.Fatal(err) } tabletmanager.HttpHandleSnapshots(mycnf, tabletAlias.Uid) servenv.OnTerm(func() { tabletserver.DisallowQueries() binlog.DisableUpdateStreamService() agent.Stop() }) servenv.OnClose(func() { // We will still use the topo server during lameduck period // to update our state, so closing it in OnClose() topo.CloseServers() }) servenv.RunDefault() }
func main() { defer logutil.Flush() flag.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s [global parameters] command [command parameters]\n", os.Args[0]) fmt.Fprintf(os.Stderr, "\nThe global optional parameters are:\n") flag.PrintDefaults() fmt.Fprintf(os.Stderr, "\nThe commands are listed below. Use '%s <command> -h' for more help.\n\n", os.Args[0]) for _, cmd := range commands { fmt.Fprintf(os.Stderr, " %s", cmd.name) if cmd.params != "" { fmt.Fprintf(os.Stderr, " %s", cmd.params) } fmt.Fprintf(os.Stderr, "\n") } fmt.Fprintf(os.Stderr, "\n") } dbconfigs.RegisterFlags() flag.Parse() tabletAddr = fmt.Sprintf("%v:%v", "localhost", *port) mycnf := mysqlctl.NewMycnf(uint32(*tabletUid), *mysqlPort) if *mysqlSocket != "" { mycnf.SocketFile = *mysqlSocket } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile) if err != nil { log.Fatalf("%v", err) } mysqld := mysqlctl.NewMysqld("Dba", mycnf, &dbcfgs.Dba, &dbcfgs.Repl) defer mysqld.Close() action := flag.Arg(0) for _, cmd := range commands { if cmd.name == action { subFlags := flag.NewFlagSet(action, flag.ExitOnError) subFlags.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s %s %s\n\n", os.Args[0], cmd.name, cmd.params) fmt.Fprintf(os.Stderr, "%s\n\n", cmd.help) subFlags.PrintDefaults() } cmd.method(mysqld, subFlags, flag.Args()[1:]) return } } log.Fatalf("invalid action: %v", action) }
// OpenMysqld returns a Mysqld object to use for working with a MySQL // installation that already exists. This will look for an existing my.cnf file // and use that to call NewMysqld(). func OpenMysqld(tabletUID uint32, dbconfigFlags dbconfigs.DBConfigFlag) (*Mysqld, error) { mycnf, err := ReadMycnf(mycnfFile(tabletUID)) if err != nil { return nil, fmt.Errorf("couldn't read my.cnf file: %v", err) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, dbconfigFlags) if err != nil { return nil, fmt.Errorf("couldn't Init dbconfigs: %v", err) } return NewMysqld(mycnf, &dbcfgs.Dba, &dbcfgs.AllPrivs, &dbcfgs.App, &dbcfgs.Repl, true /* enablePublishStats */), nil }
// OpenMysqld returns a Mysqld object to use for working with a MySQL // installation that already exists. This will look for an existing my.cnf file // and use that to call NewMysqld(). func OpenMysqld(tabletUID uint32, dbconfigFlags dbconfigs.DBConfigFlag) (*Mysqld, error) { mycnf, err := ReadMycnf(mycnfFile(tabletUID)) if err != nil { return nil, fmt.Errorf("couldn't read my.cnf file: %v", err) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, dbconfigFlags) if err != nil { return nil, fmt.Errorf("couldn't Init dbconfigs: %v", err) } return NewMysqld("Dba", "App", mycnf, &dbcfgs.Dba, &dbcfgs.App.ConnParams, &dbcfgs.Repl), nil }
func main() { dbconfigs.RegisterFlags() flag.Parse() dbcfgs, err := dbconfigs.Init(*mysqlSocketFile) if err != nil { log.Fatalf("Failed to init dbconfigs: %v", err) } pc := primecache.NewPrimeCache(dbcfgs, *relayLogsPath) pc.WorkerCount = *workerCount pc.SleepDuration = *sleepDuration pc.Loop() }
func main() { dbconfigs.RegisterFlags() mysqlctl.RegisterFlags() flag.Parse() servenv.Init() defer servenv.Close() log.Infof("started vtaction %v", os.Args) servenv.ServeRPC() mycnf, mycnfErr := mysqlctl.NewMycnfFromFlags(0) if mycnfErr != nil { log.Fatalf("mycnf read failed: %v", mycnfErr) } log.V(6).Infof("mycnf: %v", jscfg.ToJson(mycnf)) dbcfgs, cfErr := dbconfigs.Init(mycnf.SocketFile) if cfErr != nil { log.Fatalf("%s", cfErr) } mysqld := mysqlctl.NewMysqld("Dba", mycnf, &dbcfgs.Dba, &dbcfgs.Repl) defer mysqld.Close() topoServer := topo.GetServer() defer topo.CloseServers() actor := actor.NewTabletActor(mysqld, mysqld, topoServer, topo.TabletAlias{}) // we delegate out startup to the micromanagement server so these actions // will occur after we have obtained our socket. bindAddr := fmt.Sprintf(":%v", *servenv.Port) httpServer := &http.Server{Addr: bindAddr} go func() { if err := httpServer.ListenAndServe(); err != nil { log.Errorf("httpServer.ListenAndServe err: %v", err) } }() actionErr := actor.HandleAction(*actionNode, *action, *actionGuid, *force) if actionErr != nil { log.Fatalf("action error: %v", actionErr) } log.Infof("finished vtaction %v", os.Args) }
func main() { dbconfigs.RegisterFlags() flag.Parse() servenv.Init() if *tabletPath == "" { log.Fatalf("tabletPath required") } tabletAlias := vttablet.TabletParamToTabletAlias(*tabletPath) if *mycnfFile == "" { *mycnfFile = mysqlctl.MycnfFile(tabletAlias.Uid) } mycnf, err := mysqlctl.ReadMycnf(*mycnfFile) if err != nil { log.Fatalf("mycnf read failed: %v", err) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile) if err != nil { log.Warning(err) } dbcfgs.App.EnableRowcache = *enableRowcache ts.InitQueryService() binlog.RegisterUpdateStreamService(mycnf) // Depends on both query and updateStream. agent, err = vttablet.InitAgent(tabletAlias, dbcfgs, mycnf, *servenv.Port, *servenv.SecurePort, *overridesFile) if err != nil { log.Fatal(err) } vttablet.HttpHandleSnapshots(mycnf, tabletAlias.Uid) servenv.OnClose(func() { time.Sleep(5 * time.Millisecond) ts.DisallowQueries() binlog.DisableUpdateStreamService() topo.CloseServers() agent.Stop() }) servenv.Run() }
func main() { dbConfigsFile, dbCredentialsFile := dbconfigs.RegisterCommonFlags() flag.Parse() servenv.Init() tabletAlias := vttablet.TabletParamToTabletAlias(*tabletPath) if *mycnfFile == "" { *mycnfFile = mysqlctl.MycnfFile(tabletAlias.Uid) } mycnf, err := mysqlctl.ReadMycnf(*mycnfFile) if err != nil { log.Fatalf("mycnf read failed: %v", err) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, *dbConfigsFile, *dbCredentialsFile) if err != nil { log.Warning(err) } ts.InitQueryService() mysqlctl.RegisterUpdateStreamService(mycnf) // Depends on both query and updateStream. ts.RegisterCacheInvalidator() // Depends on both query and updateStream. if err := vttablet.InitAgent(tabletAlias, dbcfgs, mycnf, *dbConfigsFile, *dbCredentialsFile, *port, *securePort, *mycnfFile, *overridesFile); err != nil { log.Fatal(err) } vttablet.HttpHandleSnapshots(mycnf, tabletAlias.Uid) servenv.OnClose(func() { time.Sleep(5 * time.Millisecond) ts.DisallowQueries() mysqlctl.DisableUpdateStreamService() topo.CloseServers() vttablet.CloseAgent() }) servenv.RunSecure(*port, *securePort, *cert, *key, *caCert) }
func main() { dbconfigs.RegisterFlags() flag.Parse() if len(flag.Args()) > 0 { flag.Usage() log.Fatalf("vtocc doesn't take any positional arguments") } servenv.Init() dbConfigs, err := dbconfigs.Init("") if err != nil { log.Fatalf("Cannot initialize App dbconfig: %v", err) } if *enableRowcache { dbConfigs.App.EnableRowcache = true if *enableInvalidator { dbConfigs.App.EnableInvalidator = true } } mycnf := &mysqlctl.Mycnf{BinLogPath: *binlogPath} mysqld := mysqlctl.NewMysqld("Dba", mycnf, &dbConfigs.Dba, &dbConfigs.Repl) unmarshalFile(*overridesFile, &schemaOverrides) data, _ := json.MarshalIndent(schemaOverrides, "", " ") log.Infof("schemaOverrides: %s\n", data) if *tableAclConfig != "" { tableacl.Init(*tableAclConfig) } tabletserver.InitQueryService() err = tabletserver.AllowQueries(&dbConfigs.App, schemaOverrides, tabletserver.LoadCustomRules(), mysqld, true) if err != nil { return } log.Infof("starting vtocc %v", *servenv.Port) servenv.OnTerm(func() { tabletserver.DisallowQueries() mysqld.Close() }) servenv.RunDefault() }
func main() { dbCredentialsFile := dbconfigs.RegisterAppFlags(DefaultDBConfig) flag.Parse() servenv.Init() dbConfigs, _ := dbconfigs.Init("", *dbCredentialsFile) unmarshalFile(*overridesFile, &schemaOverrides) data, _ := json.MarshalIndent(schemaOverrides, "", " ") log.Infof("schemaOverrides: %s\n", data) ts.InitQueryService() ts.AllowQueries(dbConfigs.App, schemaOverrides, ts.LoadCustomRules()) log.Infof("starting vtocc %v", *port) servenv.OnClose(func() { time.Sleep(5 * time.Millisecond) ts.DisallowQueries() }) servenv.Run(*port) }
func main() { defer exit.Recover() flags := dbconfigs.AppConfig | dbconfigs.DbaConfig | dbconfigs.FilteredConfig | dbconfigs.ReplConfig dbconfigs.RegisterFlags(flags) mysqlctl.RegisterFlags() flag.Parse() tabletserver.Init() if len(flag.Args()) > 0 { flag.Usage() log.Errorf("vttablet doesn't take any positional arguments") exit.Return(1) } servenv.Init() if *tabletPath == "" { log.Errorf("tabletPath required") exit.Return(1) } tabletAlias, err := topoproto.ParseTabletAlias(*tabletPath) if err != nil { log.Error(err) exit.Return(1) } mycnf, err := mysqlctl.NewMycnfFromFlags(tabletAlias.Uid) if err != nil { log.Errorf("mycnf read failed: %v", err) exit.Return(1) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, flags) if err != nil { log.Warning(err) } dbcfgs.App.EnableRowcache = *enableRowcache // creates and registers the query service qsc := tabletserver.NewServer() qsc.Register() binlog.RegisterUpdateStreamService(mycnf) if *tableAclConfig != "" { tableacl.Register("simpleacl", &simpleacl.Factory{}) tableacl.Init( *tableAclConfig, func() { qsc.ClearQueryPlanCache() }, ) } else if *enforceTableACLConfig { log.Error("table acl config has to be specified with table-acl-config flag because enforce-tableacl-config is set.") exit.Return(1) } // Create mysqld and register the health reporter (needs to be done // before initializing the agent, so the initial health check // done by the agent has the right reporter) mysqld := mysqlctl.NewMysqld("Dba", "App", mycnf, &dbcfgs.Dba, &dbcfgs.App.ConnParams, &dbcfgs.Repl) registerHealthReporter(mysqld) // Depends on both query and updateStream. gRPCPort := int32(0) if servenv.GRPCPort != nil { gRPCPort = int32(*servenv.GRPCPort) } agent, err = tabletmanager.NewActionAgent(context.Background(), mysqld, qsc, tabletAlias, dbcfgs, mycnf, int32(*servenv.Port), gRPCPort, *overridesFile, *lockTimeout) if err != nil { log.Error(err) exit.Return(1) } servenv.OnRun(func() { addStatusParts(qsc) }) servenv.OnTerm(func() { qsc.StopService() binlog.DisableUpdateStreamService() agent.Stop() }) servenv.OnClose(func() { // We will still use the topo server during lameduck period // to update our state, so closing it in OnClose() topo.CloseServers() }) servenv.RunDefault() }
func main() { defer exit.Recover() // flag parsing flags := dbconfigs.AppConfig | dbconfigs.DbaConfig | dbconfigs.FilteredConfig | dbconfigs.ReplConfig dbconfigs.RegisterFlags(flags) mysqlctl.RegisterFlags() flag.Parse() if len(flag.Args()) > 0 { flag.Usage() log.Errorf("vtcombo doesn't take any positional arguments") exit.Return(1) } // register topo server zkconn := fakezk.NewConn() topo.RegisterServer("fakezk", zktopo.NewServer(zkconn)) ts = topo.GetServerByName("fakezk") servenv.Init() tabletserver.Init() // database configs mycnf, err := mysqlctl.NewMycnfFromFlags(0) if err != nil { log.Errorf("mycnf read failed: %v", err) exit.Return(1) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, flags) if err != nil { log.Warning(err) } mysqld := mysqlctl.NewMysqld("Dba", "App", mycnf, &dbcfgs.Dba, &dbcfgs.App.ConnParams, &dbcfgs.Repl) servenv.OnClose(mysqld.Close) // tablets configuration and init initTabletMap(ts, *topology, mysqld, dbcfgs, mycnf) // vschema var schema *planbuilder.Schema if *vschema != "" { schema, err = planbuilder.LoadFile(*vschema) if err != nil { log.Error(err) exit.Return(1) } log.Infof("v3 is enabled: loaded schema from file") } // vtgate configuration and init resilientSrvTopoServer := vtgate.NewResilientSrvTopoServer(ts, "ResilientSrvTopoServer") healthCheck := discovery.NewHealthCheck(30*time.Second /*connTimeoutTotal*/, 1*time.Millisecond /*retryDelay*/, 1*time.Minute /*healthCheckTimeout*/) tabletTypesToWait := []topodatapb.TabletType{ topodatapb.TabletType_MASTER, topodatapb.TabletType_REPLICA, topodatapb.TabletType_RDONLY, } vtgate.Init(healthCheck, ts, resilientSrvTopoServer, schema, cell, 1*time.Millisecond /*retryDelay*/, 2 /*retryCount*/, 30*time.Second /*connTimeoutTotal*/, 10*time.Second /*connTimeoutPerConn*/, 365*24*time.Hour /*connLife*/, tabletTypesToWait, 0 /*maxInFlight*/, "" /*testGateway*/) // vtctld configuration and init vtctld.InitVtctld(ts) vtctld.HandleExplorer("zk", zktopo.NewZkExplorer(zkconn)) servenv.OnTerm(func() { // FIXME(alainjobart): stop vtgate }) servenv.OnClose(func() { log.Infof("Total count of new connections to MySQL: %v", expvar.Get("mysql-new-connection-count")) // We will still use the topo server during lameduck period // to update our state, so closing it in OnClose() topo.CloseServers() }) servenv.RunDefault() }
func main() { dbConfigsFile, dbCredentialsFile := dbconfigs.RegisterCommonFlags() flag.Parse() servenv.Init() defer servenv.Close() tabletAlias := vttablet.TabletParamToTabletAlias(*tabletPath) if *mycnfFile == "" { *mycnfFile = mysqlctl.MycnfFile(tabletAlias.Uid) } mycnf, err := mysqlctl.ReadMycnf(*mycnfFile) if err != nil { log.Fatalf("mycnf read failed: %v", err) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, *dbConfigsFile, *dbCredentialsFile) if err != nil { log.Warning(err) } ts.InitQueryService() mysqlctl.RegisterUpdateStreamService(mycnf) // Depends on both query and updateStream. ts.RegisterCacheInvalidator() // Depends on both query and updateStream. if err := vttablet.InitAgent(tabletAlias, dbcfgs, mycnf, *dbConfigsFile, *dbCredentialsFile, *port, *securePort, *mycnfFile, *overridesFile); err != nil { log.Fatal(err) } servenv.ServeRPC() vttablet.HttpHandleSnapshots(mycnf, tabletAlias.Uid) l, err := proc.Listen(fmt.Sprintf("%v", *port)) if err != nil { log.Fatal(err) } go http.Serve(l, nil) if *securePort != 0 { log.Infof("listening on secure port %v", *securePort) vttablet.SecureServe(fmt.Sprintf(":%d", *securePort), *cert, *key, *caCert) } log.Infof("started vttablet %v", *port) s := proc.Wait() // A SIGUSR1 means that we're restarting if s == syscall.SIGUSR1 { // Give some time for the other process // to pick up the listeners log.Info("Exiting on SIGUSR1") time.Sleep(5 * time.Millisecond) ts.DisallowQueries(true) } else { log.Info("Exiting on SIGTERM") ts.DisallowQueries(false) } mysqlctl.DisableUpdateStreamService() topo.CloseServers() vttablet.CloseAgent() }
func main() { defer exit.Recover() // flag parsing flags := dbconfigs.AppConfig | dbconfigs.DbaConfig | dbconfigs.FilteredConfig | dbconfigs.ReplConfig dbconfigs.RegisterFlags(flags) mysqlctl.RegisterFlags() flag.Parse() if len(flag.Args()) > 0 { flag.Usage() log.Errorf("vtcombo doesn't take any positional arguments") exit.Return(1) } // set discoverygateway flag to default value flag.Set("cells_to_watch", cell) // register topo server zkconn := fakezk.NewConn() topo.RegisterServer("fakezk", zktopo.NewServer(zkconn)) ts = topo.GetServerByName("fakezk") servenv.Init() tabletserver.Init() // database configs mycnf, err := mysqlctl.NewMycnfFromFlags(0) if err != nil { log.Errorf("mycnf read failed: %v", err) exit.Return(1) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, flags) if err != nil { log.Warning(err) } mysqld := mysqlctl.NewMysqld("Dba", "App", mycnf, &dbcfgs.Dba, &dbcfgs.App.ConnParams, &dbcfgs.Repl) servenv.OnClose(mysqld.Close) // tablets configuration and init if err := initTabletMap(ts, *protoTopo, mysqld, dbcfgs, *schemaDir, mycnf); err != nil { log.Errorf("initTabletMapProto failed: %v", err) exit.Return(1) } // vtgate configuration and init resilientSrvTopoServer := vtgate.NewResilientSrvTopoServer(ts, "ResilientSrvTopoServer") healthCheck := discovery.NewHealthCheck(30*time.Second /*connTimeoutTotal*/, 1*time.Millisecond /*retryDelay*/, 1*time.Hour /*healthCheckTimeout*/) tabletTypesToWait := []topodatapb.TabletType{ topodatapb.TabletType_MASTER, topodatapb.TabletType_REPLICA, topodatapb.TabletType_RDONLY, } vtgate.Init(context.Background(), healthCheck, ts, resilientSrvTopoServer, cell, 2 /*retryCount*/, tabletTypesToWait) // vtctld configuration and init vtctld.InitVtctld(ts) vtctld.HandleExplorer("zk", zktopo.NewZkExplorer(zkconn)) servenv.OnTerm(func() { // FIXME(alainjobart): stop vtgate }) servenv.OnClose(func() { // We will still use the topo server during lameduck period // to update our state, so closing it in OnClose() topo.CloseServers() }) servenv.RunDefault() }
func main() { defer exit.Recover() flags := dbconfigs.AppConfig | dbconfigs.DbaConfig | dbconfigs.FilteredConfig | dbconfigs.ReplConfig dbconfigs.RegisterFlags(flags) flag.Parse() if len(flag.Args()) > 0 { flag.Usage() log.Errorf("vtocc doesn't take any positional arguments") exit.Return(1) } servenv.Init() dbConfigs, err := dbconfigs.Init("", flags) if err != nil { log.Errorf("Cannot initialize App dbconfig: %v", err) exit.Return(1) } if *enableRowcache { dbConfigs.App.EnableRowcache = true if *enableInvalidator { dbConfigs.App.EnableInvalidator = true } } mycnf := &mysqlctl.Mycnf{BinLogPath: *binlogPath} mysqld := mysqlctl.NewMysqld("Dba", "App", mycnf, &dbConfigs.Dba, &dbConfigs.App.ConnParams, &dbConfigs.Repl) if err := unmarshalFile(*overridesFile, &schemaOverrides); err != nil { log.Error(err) exit.Return(1) } data, _ := json.MarshalIndent(schemaOverrides, "", " ") log.Infof("schemaOverrides: %s\n", data) if *tableAclConfig != "" { tableacl.Register("simpleacl", &simpleacl.Factory{}) tableacl.Init(*tableAclConfig) } qsc := tabletserver.NewQueryServiceControl() tabletserver.InitQueryService(qsc) // Query service can go into NOT_SERVING state if mysql goes down. // So, continuously retry starting the service. So, it tries to come // back up if it went down. go func() { for { _ = qsc.AllowQueries(nil, dbConfigs, schemaOverrides, mysqld) time.Sleep(30 * time.Second) } }() log.Infof("starting vtocc %v", *servenv.Port) servenv.OnRun(func() { addStatusParts(qsc) }) servenv.OnTerm(func() { qsc.DisallowQueries() mysqld.Close() }) servenv.RunDefault() }
func main() { defer exit.Recover() defer logutil.Flush() flag.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s [global parameters] command [command parameters]\n", os.Args[0]) fmt.Fprintf(os.Stderr, "\nThe global optional parameters are:\n") flag.PrintDefaults() fmt.Fprintf(os.Stderr, "\nThe commands are listed below. Use '%s <command> -h' for more help.\n\n", os.Args[0]) for _, cmd := range commands { fmt.Fprintf(os.Stderr, " %s", cmd.name) if cmd.params != "" { fmt.Fprintf(os.Stderr, " %s", cmd.params) } fmt.Fprintf(os.Stderr, "\n") } fmt.Fprintf(os.Stderr, "\n") } flags := dbconfigs.AppConfig | dbconfigs.DbaConfig | dbconfigs.FilteredConfig | dbconfigs.ReplConfig dbconfigs.RegisterFlags(flags) flag.Parse() tabletAddr = netutil.JoinHostPort("localhost", int32(*port)) mycnf := mysqlctl.NewMycnf(uint32(*tabletUID), int32(*mysqlPort)) if *mysqlSocket != "" { mycnf.SocketFile = *mysqlSocket } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, flags) if err != nil { log.Errorf("%v", err) exit.Return(1) } mysqld := mysqlctl.NewMysqld("Dba", "App", mycnf, &dbcfgs.Dba, &dbcfgs.App.ConnParams, &dbcfgs.Repl) defer mysqld.Close() action := flag.Arg(0) for _, cmd := range commands { if cmd.name == action { subFlags := flag.NewFlagSet(action, flag.ExitOnError) subFlags.Usage = func() { fmt.Fprintf(os.Stderr, "Usage: %s %s %s\n\n", os.Args[0], cmd.name, cmd.params) fmt.Fprintf(os.Stderr, "%s\n\n", cmd.help) subFlags.PrintDefaults() } if err := cmd.method(mysqld, subFlags, flag.Args()[1:]); err != nil { log.Error(err) exit.Return(1) } return } } log.Errorf("invalid action: %v", action) exit.Return(1) }
func main() { defer exit.Recover() defer logutil.Flush() flags := dbconfigs.AppConfig | dbconfigs.DbaConfig | dbconfigs.FilteredConfig | dbconfigs.ReplConfig dbconfigs.RegisterFlags(flags) flag.Parse() mycnf := mysqlctl.NewMycnf(uint32(*tabletUID), int32(*mysqlPort)) if *mysqlSocket != "" { mycnf.SocketFile = *mysqlSocket } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, flags) if err != nil { log.Errorf("%v", err) exit.Return(255) } mysqld = mysqlctl.NewMysqld("Dba", "App", mycnf, &dbcfgs.Dba, &dbcfgs.App.ConnParams, &dbcfgs.Repl) // Register OnTerm handler before mysqld starts, so we get notified if mysqld // dies on its own without us (or our RPC client) telling it to. mysqldTerminated := make(chan struct{}) mysqld.OnTerm(func() { close(mysqldTerminated) }) // Start or Init mysqld as needed. ctx, cancel := context.WithTimeout(context.Background(), *waitTime) if _, err = os.Stat(mycnf.DataDir); os.IsNotExist(err) { log.Infof("mysql data dir (%s) doesn't exist, initializing", mycnf.DataDir) mysqld.Init(ctx, *initDBSQLFile) } else { log.Infof("mysql data dir (%s) already exists, starting without init", mycnf.DataDir) mysqld.Start(ctx) } cancel() servenv.Init() defer servenv.Close() // Take mysqld down with us on SIGTERM before entering lame duck. servenv.OnTerm(func() { log.Infof("mysqlctl received SIGTERM, shutting down mysqld first") ctx := context.Background() mysqld.Shutdown(ctx, false) }) // Start RPC server and wait for SIGTERM. mysqlctldTerminated := make(chan struct{}) go func() { servenv.RunDefault() close(mysqlctldTerminated) }() select { case <-mysqldTerminated: log.Infof("mysqld shut down on its own, exiting mysqlctld") case <-mysqlctldTerminated: log.Infof("mysqlctld shut down gracefully") } }
func main() { dbConfigsFile, dbCredentialsFile := dbconfigs.RegisterCommonFlags() flag.Parse() if err := servenv.Init("vttablet"); err != nil { relog.Fatal("Error in servenv.Init: %s", err) } tabletAlias := tabletParamToTabletAlias(*tabletPath) mycnf := readMycnf(tabletAlias.Uid) dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, *dbConfigsFile, *dbCredentialsFile) if err != nil { relog.Warning("%s", err) } dbcfgs.App.Memcache = *rowcache if err := jscfg.ReadJson(*overridesFile, &schemaOverrides); err != nil { relog.Warning("%s", err) } else { data, _ := json.MarshalIndent(schemaOverrides, "", " ") relog.Info("schemaOverrides: %s\n", data) } initQueryService(dbcfgs) initUpdateStreamService(mycnf) ts.RegisterCacheInvalidator() // depends on both query and updateStream err = initAgent(tabletAlias, dbcfgs, mycnf, *dbConfigsFile, *dbCredentialsFile) // depends on both query and updateStream if err != nil { relog.Fatal("%s", err) } rpc.HandleHTTP() // NOTE(szopa): Changing credentials requires a server // restart. if *authConfig != "" { if err := auth.LoadCredentials(*authConfig); err != nil { relog.Error("could not load authentication credentials, not starting rpc servers: %v", err) } serveAuthRPC() } serveRPC() // make a list of paths we can serve HTTP traffic from. // we don't resolve them here to real paths, as they might not exits yet snapshotDir := mysqlctl.SnapshotDir(tabletAlias.Uid) allowedPaths := []string{ path.Join(vtenv.VtDataRoot(), "data"), mysqlctl.TabletDir(tabletAlias.Uid), snapshotDir, mycnf.DataDir, mycnf.InnodbDataHomeDir, mycnf.InnodbLogGroupHomeDir, } // NOTE: trailing slash in pattern means we handle all paths with this prefix http.Handle(mysqlctl.SnapshotURLPath+"/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { handleSnapshot(w, r, snapshotDir, allowedPaths) })) // we delegate out startup to the micromanagement server so these actions // will occur after we have obtained our socket. umgmt.SetLameDuckPeriod(float32(*lameDuckPeriod)) umgmt.SetRebindDelay(float32(*rebindDelay)) umgmt.AddStartupCallback(func() { umgmt.StartHttpServer(fmt.Sprintf(":%v", *port)) if *securePort != 0 { relog.Info("listening on secure port %v", *securePort) umgmt.StartHttpsServer(fmt.Sprintf(":%v", *securePort), *cert, *key, *caCert) } }) umgmt.AddStartupCallback(func() { c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGTERM) go func() { for sig := range c { umgmt.SigTermHandler(sig) } }() }) relog.Info("started vttablet %v", *port) umgmtSocket := fmt.Sprintf("/tmp/vttablet-%08x-umgmt.sock", *port) if umgmtErr := umgmt.ListenAndServe(umgmtSocket); umgmtErr != nil { relog.Error("umgmt.ListenAndServe err: %v", umgmtErr) } relog.Info("done") }
func main() { dbConfigsFile, dbCredentialsFile := dbconfigs.RegisterCommonFlags() flag.Parse() if err := servenv.Init("vttablet"); err != nil { relog.Fatal("Error in servenv.Init: %s", err) } tabletAlias := tabletParamToTabletAlias(*tabletPath) mycnf := readMycnf(tabletAlias.Uid) dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, *dbConfigsFile, *dbCredentialsFile) if err != nil { relog.Warning("%s", err) } initQueryService(dbcfgs) initUpdateStreamService(mycnf) ts.RegisterCacheInvalidator() // depends on both query and updateStream err = vttablet.InitAgent(tabletAlias, dbcfgs, mycnf, *dbConfigsFile, *dbCredentialsFile, *port, *securePort, *mycnfFile, *customrules, *overridesFile) // depends on both query and updateStream if err != nil { relog.Fatal("%s", err) } rpc.HandleHTTP() // NOTE(szopa): Changing credentials requires a server // restart. if *authConfig != "" { if err := auth.LoadCredentials(*authConfig); err != nil { relog.Error("could not load authentication credentials, not starting rpc servers: %v", err) } serveAuthRPC() } serveRPC() vttablet.HttpHandleSnapshots(mycnf, tabletAlias.Uid) // we delegate out startup to the micromanagement server so these actions // will occur after we have obtained our socket. umgmt.SetLameDuckPeriod(float32(*lameDuckPeriod)) umgmt.SetRebindDelay(float32(*rebindDelay)) umgmt.AddStartupCallback(func() { umgmt.StartHttpServer(fmt.Sprintf(":%v", *port)) if *securePort != 0 { relog.Info("listening on secure port %v", *securePort) umgmt.StartHttpsServer(fmt.Sprintf(":%v", *securePort), *cert, *key, *caCert) } }) umgmt.AddStartupCallback(func() { c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGTERM) go func() { for sig := range c { umgmt.SigTermHandler(sig) } }() }) relog.Info("started vttablet %v", *port) umgmtSocket := fmt.Sprintf("/tmp/vttablet-%08x-umgmt.sock", *port) if umgmtErr := umgmt.ListenAndServe(umgmtSocket); umgmtErr != nil { relog.Error("umgmt.ListenAndServe err: %v", umgmtErr) } relog.Info("done") }
func main() { defer exit.Recover() flags := dbconfigs.AppConfig | dbconfigs.AllPrivsConfig | dbconfigs.DbaConfig | dbconfigs.FilteredConfig | dbconfigs.ReplConfig dbconfigs.RegisterFlags(flags) mysqlctl.RegisterFlags() flag.Parse() tabletserver.Init() if len(flag.Args()) > 0 { flag.Usage() log.Errorf("vttablet doesn't take any positional arguments") exit.Return(1) } servenv.Init() if *tabletPath == "" { log.Errorf("tabletPath required") exit.Return(1) } tabletAlias, err := topoproto.ParseTabletAlias(*tabletPath) if err != nil { log.Error(err) exit.Return(1) } mycnf, err := mysqlctl.NewMycnfFromFlags(tabletAlias.Uid) if err != nil { log.Errorf("mycnf read failed: %v", err) exit.Return(1) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, flags) if err != nil { log.Warning(err) } // creates and registers the query service qsc := tabletserver.NewServer() servenv.OnRun(func() { qsc.Register() addStatusParts(qsc) }) servenv.OnClose(func() { // We now leave the queryservice running during lameduck, // so stop it in OnClose(), after lameduck is over. qsc.StopService() }) if *tableAclConfig != "" { // To override default simpleacl, other ACL plugins must set themselves to be default ACL factory tableacl.Register("simpleacl", &simpleacl.Factory{}) } else if *enforceTableACLConfig { log.Error("table acl config has to be specified with table-acl-config flag because enforce-tableacl-config is set.") exit.Return(1) } // tabletacl.Init loads ACL from file if *tableAclConfig is not empty err = tableacl.Init( *tableAclConfig, func() { qsc.ClearQueryPlanCache() }, ) if err != nil { log.Errorf("Fail to initialize Table ACL: %v", err) if *enforceTableACLConfig { log.Error("Need a valid initial Table ACL when enforce-tableacl-config is set, exiting.") exit.Return(1) } } // Create mysqld and register the health reporter (needs to be done // before initializing the agent, so the initial health check // done by the agent has the right reporter) mysqld := mysqlctl.NewMysqld(mycnf, &dbcfgs.Dba, &dbcfgs.AllPrivs, &dbcfgs.App, &dbcfgs.Repl, true /* enablePublishStats */) servenv.OnClose(mysqld.Close) // Depends on both query and updateStream. gRPCPort := int32(0) if servenv.GRPCPort != nil { gRPCPort = int32(*servenv.GRPCPort) } agent, err = tabletmanager.NewActionAgent(context.Background(), mysqld, qsc, tabletAlias, dbcfgs, mycnf, int32(*servenv.Port), gRPCPort) if err != nil { log.Error(err) exit.Return(1) } servenv.OnClose(func() { // We will still use the topo server during lameduck period // to update our state, so closing it in OnClose() topo.CloseServers() }) servenv.RunDefault() }
func main() { defer exit.Recover() // flag parsing flags := dbconfigs.AppConfig | dbconfigs.AllPrivsConfig | dbconfigs.DbaConfig | dbconfigs.FilteredConfig | dbconfigs.ReplConfig dbconfigs.RegisterFlags(flags) mysqlctl.RegisterFlags() flag.Parse() if len(flag.Args()) > 0 { flag.Usage() log.Errorf("vtcombo doesn't take any positional arguments") exit.Return(1) } // parse the input topology tpb := &vttestpb.VTTestTopology{} if err := proto.UnmarshalText(*protoTopo, tpb); err != nil { log.Errorf("cannot parse topology: %v", err) exit.Return(1) } // default cell to "test" if unspecified if len(tpb.Cells) == 0 { tpb.Cells = append(tpb.Cells, "test") } // set discoverygateway flag to default value flag.Set("cells_to_watch", strings.Join(tpb.Cells, ",")) // vtctld UI requires the cell flag flag.Set("cell", tpb.Cells[0]) flag.Set("enable_realtime_stats", "true") flag.Set("log_dir", "$VTDATAROOT/tmp") // create zk client config file config := path.Join(os.Getenv("VTDATAROOT"), "vt_0000000001/tmp/test-zk-client-conf.json") cellmap := make(map[string]string) for _, cell := range tpb.Cells { cellmap[cell] = "localhost" } b, err := json.Marshal(cellmap) if err != nil { log.Errorf("failed to marshal json: %v", err) } f, err := os.Create(config) if err != nil { log.Errorf("failed to create zk config file: %v", err) } defer f.Close() _, err = f.WriteString(string(b[:])) if err != nil { log.Errorf("failed to write to zk config file: %v", err) } os.Setenv("ZK_CLIENT_CONFIG", config) // register topo server zkconn := fakezk.NewConn() topo.RegisterServer("fakezk", zktopo.NewServer(zkconn)) ts = topo.GetServerByName("fakezk") servenv.Init() tabletserver.Init() // database configs mycnf, err := mysqlctl.NewMycnfFromFlags(0) if err != nil { log.Errorf("mycnf read failed: %v", err) exit.Return(1) } dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, flags) if err != nil { log.Warning(err) } mysqld := mysqlctl.NewMysqld(mycnf, &dbcfgs.Dba, &dbcfgs.AllPrivs, &dbcfgs.App, &dbcfgs.Repl, true /* enablePublishStats */) servenv.OnClose(mysqld.Close) // tablets configuration and init if err := initTabletMap(ts, tpb, mysqld, dbcfgs, *schemaDir, mycnf); err != nil { log.Errorf("initTabletMapProto failed: %v", err) exit.Return(1) } // vtgate configuration and init resilientSrvTopoServer := vtgate.NewResilientSrvTopoServer(ts, "ResilientSrvTopoServer") healthCheck := discovery.NewHealthCheck(30*time.Second /*connTimeoutTotal*/, 1*time.Millisecond /*retryDelay*/, 1*time.Hour /*healthCheckTimeout*/) tabletTypesToWait := []topodatapb.TabletType{ topodatapb.TabletType_MASTER, topodatapb.TabletType_REPLICA, topodatapb.TabletType_RDONLY, } vtgate.Init(context.Background(), healthCheck, ts, resilientSrvTopoServer, tpb.Cells[0], 2 /*retryCount*/, tabletTypesToWait) // vtctld configuration and init vtctld.InitVtctld(ts) vtctld.HandleExplorer("zk", zktopo.NewZkExplorer(zkconn)) servenv.OnTerm(func() { // FIXME(alainjobart): stop vtgate }) servenv.OnClose(func() { // We will still use the topo server during lameduck period // to update our state, so closing it in OnClose() topo.CloseServers() }) servenv.RunDefault() }