本文整理汇总了Golang中github.com/youtube/vitess/go/vt/servenv.OnClose函数的典型用法代码示例。如果您正苦于以下问题:Golang OnClose函数的具体用法?Golang OnClose怎么用?Golang OnClose使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OnClose函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
}
开发者ID:rudyLi,项目名称:vitess,代码行数:33,代码来源:vtocc.go
示例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)
}
开发者ID:CERN-Stage-3,项目名称:vitess,代码行数:28,代码来源:vt_binlog_server.go
示例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)
}
}
开发者ID:dumbunny,项目名称:vitess,代码行数:26,代码来源:workflow.go
示例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)
}
开发者ID:nimishzynga,项目名称:vitess,代码行数:27,代码来源:vtocc.go
示例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()
}
开发者ID:richarwu,项目名称:vitess,代码行数:54,代码来源:main.go
示例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()
}
开发者ID:jackwanger,项目名称:cloud-base,代码行数:52,代码来源:vttablet.go
示例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()
}
开发者ID:haolei,项目名称:vitess,代码行数:45,代码来源:vttablet.go
示例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)
}
开发者ID:CERN-Stage-3,项目名称:vitess,代码行数:43,代码来源:vttablet.go
示例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)
}
开发者ID:rjammala,项目名称:vitess,代码行数:22,代码来源:vtocc.go
示例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() })
}
}
开发者ID:littleyang,项目名称:vitess,代码行数:37,代码来源:schema.go
示例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()
}
开发者ID:zhaoyta,项目名称:vitess,代码行数:89,代码来源:vttablet.go
示例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()
}
开发者ID:shawnps,项目名称:vitess,代码行数:75,代码来源:main.go
示例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()
}
开发者ID:hadmagic,项目名称:vitess,代码行数:101,代码来源:vtctld.go
示例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()
}
开发者ID:jmptrader,项目名称:vitess,代码行数:69,代码来源:main.go
示例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()
}
开发者ID:dumbunny,项目名称:vitess,代码行数:96,代码来源:vttablet.go
示例16: main
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
//.........这里部分代码省略.........
开发者ID:dumbunny,项目名称:vitess,代码行数:101,代码来源:main.go
示例17: main
//.........这里部分代码省略.........
actionRepo.RegisterTabletAction("RefreshState", acl.ADMIN,
func(ctx context.Context, wr *wrangler.Wrangler, tabletAlias *topodatapb.TabletAlias, r *http.Request) (string, error) {
ti, err := wr.TopoServer().GetTablet(ctx, tabletAlias)
if err != nil {
return "", err
}
return "", wr.TabletManagerClient().RefreshState(ctx, ti)
})
actionRepo.RegisterTabletAction("DeleteTablet", acl.ADMIN,
func(ctx context.Context, wr *wrangler.Wrangler, tabletAlias *topodatapb.TabletAlias, r *http.Request) (string, error) {
return "", wr.DeleteTablet(ctx, tabletAlias, false, false)
})
actionRepo.RegisterTabletAction("ReloadSchema", acl.ADMIN,
func(ctx context.Context, wr *wrangler.Wrangler, tabletAlias *topodatapb.TabletAlias, r *http.Request) (string, error) {
return "", wr.ReloadSchema(ctx, tabletAlias)
})
// Anything unrecognized gets redirected to the main app page.
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, appPrefix, http.StatusFound)
})
// Serve the static files for the vtctld web app.
http.HandleFunc(appPrefix, func(w http.ResponseWriter, r *http.Request) {
// Strip the prefix.
parts := strings.SplitN(r.URL.Path, "/", 3)
if len(parts) != 3 {
http.NotFound(w, r)
return
}
rest := parts[2]
if rest == "" {
rest = "index.html"
}
http.ServeFile(w, r, path.Join(*webDir, rest))
})
// Serve the REST API for the vtctld web app.
initAPI(context.Background(), ts, actionRepo)
// redirects for explorers
http.HandleFunc("/explorers/redirect", func(w http.ResponseWriter, r *http.Request) {
if explorer == nil {
http.Error(w, "no explorer configured", http.StatusInternalServerError)
return
}
if err := r.ParseForm(); err != nil {
httpErrorf(w, r, "cannot parse form: %s", err)
return
}
target, err := handleExplorerRedirect(context.Background(), ts, r)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
http.Redirect(w, r, target, http.StatusFound)
})
// Start schema manager service.
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()
}
开发者ID:BobbWu,项目名称:vitess,代码行数:101,代码来源:vtctld.go
注:本文中的github.com/youtube/vitess/go/vt/servenv.OnClose函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论