本文整理汇总了Golang中github.com/youtube/vitess/go/vt/servenv.OnClose函数的典型用法代码示例。如果您正苦于以下问题:Golang OnClose函数的具体用法?Golang OnClose怎么用?Golang OnClose使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OnClose函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
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()
}
示例2: main
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)
}
示例3: initWorkflowManager
func initWorkflowManager(ts topo.Server) {
if *workflowManagerInit {
// Register the Topo Validators
topovalidator.RegisterKeyspaceValidator()
topovalidator.RegisterShardValidator()
topovalidator.Register()
// Create the WorkflowManager.
vtctl.WorkflowManager = workflow.NewManager(ts)
// Register the long polling and websocket handlers.
vtctl.WorkflowManager.HandleHTTPLongPolling(apiPrefix + "workflow")
vtctl.WorkflowManager.HandleHTTPWebSocket(apiPrefix + "workflow")
// FIXME(alainjobart) look at a flag to use master
// election here.
ctx, cancel := context.WithCancel(context.Background())
go vtctl.WorkflowManager.Run(ctx)
// Running cancel on Close will cancel the context of
// any running workflow inside vtctld. They may still
// checkpoint if they want to. We will wait for them
// all to exit properly before returning from Close().
servenv.OnClose(cancel)
}
}
示例4: main
func main() {
defaultDBConfig := dbconfigs.DefaultDBConfigs.App
defaultDBConfig.Host = "localhost"
dbconfigs.RegisterAppFlags(defaultDBConfig)
flag.Parse()
servenv.Init()
dbConfig, err := dbconfigs.InitApp("")
if err != nil {
log.Fatalf("Cannot initialize App dbconfig: %v", err)
}
unmarshalFile(*overridesFile, &schemaOverrides)
data, _ := json.MarshalIndent(schemaOverrides, "", " ")
log.Infof("schemaOverrides: %s\n", data)
ts.InitQueryService()
ts.AllowQueries(dbConfig, schemaOverrides, ts.LoadCustomRules())
log.Infof("starting vtocc %v", *port)
servenv.OnClose(func() {
time.Sleep(5 * time.Millisecond)
ts.DisallowQueries()
})
servenv.Run(*port)
}
示例5: main
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()
}
示例6: main
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()
}
示例7: main
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()
}
示例8: main
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)
}
示例9: main
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)
}
示例10: initSchema
func initSchema() {
// Start schema manager service if needed.
if *schemaChangeDir != "" {
interval := 60
if *schemaChangeCheckInterval > 0 {
interval = *schemaChangeCheckInterval
}
timer := timer.NewTimer(time.Duration(interval) * time.Second)
controllerFactory, err :=
schemamanager.GetControllerFactory(*schemaChangeController)
if err != nil {
log.Fatalf("unable to get a controller factory, error: %v", err)
}
timer.Start(func() {
controller, err := controllerFactory(map[string]string{
schemamanager.SchemaChangeDirName: *schemaChangeDir,
schemamanager.SchemaChangeUser: *schemaChangeUser,
})
if err != nil {
log.Errorf("failed to get controller, error: %v", err)
return
}
ctx := context.Background()
err = schemamanager.Run(
ctx,
controller,
schemamanager.NewTabletExecutor(
tmclient.NewTabletManagerClient(), ts),
)
if err != nil {
log.Errorf("Schema change failed, error: %v", err)
}
})
servenv.OnClose(func() { timer.Stop() })
}
}
示例11: main
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()
}
示例12: main
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()
}
示例13: main
//.........这里部分代码省略.........
httpErrorf(w, r, "error getting shard: %v", err)
return
}
w.Write(result)
})
cellShardTabletsCache := newCellShardTabletsCache(ts)
http.HandleFunc("/json/CellShardTablets", func(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
httpErrorf(w, r, "cannot parse form: %s", err)
return
}
cell := r.FormValue("cell")
if cell == "" {
http.Error(w, "no cell provided", http.StatusBadRequest)
return
}
keyspace := r.FormValue("keyspace")
if keyspace == "" {
http.Error(w, "no keyspace provided", http.StatusBadRequest)
return
}
shard := r.FormValue("shard")
if shard == "" {
http.Error(w, "no shard provided", http.StatusBadRequest)
return
}
ctx := context.Background()
result, err := cellShardTabletsCache.Get(ctx, cell+"/"+keyspace+"/"+shard)
if err != nil {
httpErrorf(w, r, "error getting shard: %v", err)
return
}
w.Write(result)
})
// flush all data and will force a full client reload
http.HandleFunc("/json/flush", func(w http.ResponseWriter, r *http.Request) {
knownCellsCache.Flush()
keyspacesCache.Flush()
keyspaceCache.Flush()
shardNamesCache.Flush()
shardCache.Flush()
cellShardTabletsCache.Flush()
})
http.HandleFunc("/json/schema-manager", func(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
httpErrorf(w, r, "cannot parse form: %s", err)
return
}
sqlStr := r.FormValue("data")
keyspace := r.FormValue("keyspace")
executor := schemamanager.NewTabletExecutor(
tmclient.NewTabletManagerClient(),
ts)
ctx := context.Background()
schemamanager.Run(
ctx,
schemamanager.NewUIController(sqlStr, keyspace, w),
executor,
)
})
if *schemaChangeDir != "" {
interval := 60
if *schemaChangeCheckInterval > 0 {
interval = *schemaChangeCheckInterval
}
timer := timer.NewTimer(time.Duration(interval) * time.Second)
controllerFactory, err :=
schemamanager.GetControllerFactory(*schemaChangeController)
if err != nil {
log.Fatalf("unable to get a controller factory, error: %v", err)
}
timer.Start(func() {
controller, err := controllerFactory(map[string]string{
schemamanager.SchemaChangeDirName: *schemaChangeDir,
schemamanager.SchemaChangeUser: *schemaChangeUser,
})
if err != nil {
log.Errorf("failed to get controller, error: %v", err)
return
}
ctx := context.Background()
err = schemamanager.Run(
ctx,
controller,
schemamanager.NewTabletExecutor(
tmclient.NewTabletManagerClient(), ts),
)
if err != nil {
log.Errorf("Schema change failed, error: %v", err)
}
})
servenv.OnClose(func() { timer.Stop() })
}
servenv.RunDefault()
}
示例14: main
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()
}
示例15: main
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()
}