本文整理汇总了Golang中github.com/youtube/vitess/go/vt/dbconfigs.RegisterFlags函数的典型用法代码示例。如果您正苦于以下问题:Golang RegisterFlags函数的具体用法?Golang RegisterFlags怎么用?Golang RegisterFlags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RegisterFlags函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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() {
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")
}
}
开发者ID:plobsing,项目名称:vitess,代码行数:58,代码来源:mysqlctld.go
示例3: 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
示例4: 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
示例5: main
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)
}
开发者ID:chinna1986,项目名称:vitess,代码行数:52,代码来源:mysqlctl.go
示例6: main
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()
}
开发者ID:kingpro,项目名称:vitess,代码行数:15,代码来源:main.go
示例7: main
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)
}
开发者ID:chinna1986,项目名称:vitess,代码行数:47,代码来源:vtaction.go
示例8: main
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")
}
dbconfigs.RegisterFlags(dbconfigFlags)
flag.Parse()
tabletAddr = netutil.JoinHostPort("localhost", int32(*port))
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(subFlags, flag.Args()[1:]); err != nil {
log.Error(err)
exit.Return(1)
}
return
}
}
log.Errorf("invalid action: %v", action)
exit.Return(1)
}
开发者ID:xujianhai,项目名称:vitess,代码行数:46,代码来源:mysqlctl.go
示例9: 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
示例10: main
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()
}
开发者ID:nangong92t,项目名称:go_src,代码行数:43,代码来源:vtocc.go
示例11: main
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()
}
开发者ID:haoqoo,项目名称:vitess,代码行数:62,代码来源:vtocc.go
示例12: 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
示例13: 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
示例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()
defer logutil.Flush()
dbconfigFlags := dbconfigs.AppConfig | dbconfigs.DbaConfig |
dbconfigs.FilteredConfig | dbconfigs.ReplConfig
dbconfigs.RegisterFlags(dbconfigFlags)
flag.Parse()
// We'll register this 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{})
onTermFunc := func() {
close(mysqldTerminated)
}
// Start or Init mysqld as needed.
ctx, cancel := context.WithTimeout(context.Background(), *waitTime)
tabletDir := mysqlctl.TabletDir(uint32(*tabletUID))
if _, statErr := os.Stat(tabletDir); os.IsNotExist(statErr) {
// Generate my.cnf from scratch and use it to find mysqld.
log.Infof("tablet dir (%s) doesn't exist, initializing", tabletDir)
var err error
mysqld, err = mysqlctl.CreateMysqld(uint32(*tabletUID), *mysqlSocket, int32(*mysqlPort), dbconfigFlags)
if err != nil {
log.Errorf("failed to initialize mysql config: %v", err)
exit.Return(1)
}
mysqld.OnTerm(onTermFunc)
if err := mysqld.Init(ctx, *initDBSQLFile); err != nil {
log.Errorf("failed to initialize mysql data dir and start mysqld: %v", err)
exit.Return(1)
}
} else {
// There ought to be an existing my.cnf, so use it to find mysqld.
log.Infof("tablet dir (%s) already exists, starting without init", tabletDir)
var err error
mysqld, err = mysqlctl.OpenMysqld(uint32(*tabletUID), dbconfigFlags)
if err != nil {
log.Errorf("failed to find mysql config: %v", err)
exit.Return(1)
}
mysqld.OnTerm(onTermFunc)
if err := mysqld.Start(ctx); err != nil {
log.Errorf("failed to start mysqld: %v", err)
exit.Return(1)
}
}
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")
}
}
开发者ID:jmptrader,项目名称:vitess,代码行数:78,代码来源:mysqlctld.go
示例16: main
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)
}
开发者ID:richarwu,项目名称:vitess,代码行数:61,代码来源:mysqlctl.go
示例17: main
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")
}
}
开发者ID:littleyang,项目名称:vitess,代码行数:63,代码来源:mysqlctld.go
示例18: 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
示例19: 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
注:本文中的github.com/youtube/vitess/go/vt/dbconfigs.RegisterFlags函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论