本文整理汇总了Golang中github.com/youtube/vitess/go/vt/mysqlctl.NewMysqld函数的典型用法代码示例。如果您正苦于以下问题:Golang NewMysqld函数的具体用法?Golang NewMysqld怎么用?Golang NewMysqld使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewMysqld函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
示例2: NewServer
// NewServer starts a new unregistered TabletServer.
// You have to end it with StopService once testing is done.
func NewServer(config tabletserver.Config, connParams sqldb.ConnParams, enableRowcache bool) (*tabletserver.TabletServer, error) {
dbcfgs := dbconfigs.DBConfigs{
App: dbconfigs.DBConfig{
ConnParams: connParams,
Keyspace: "vttest",
Shard: "0",
EnableRowcache: enableRowcache,
EnableInvalidator: false,
},
}
mysqld := mysqlctl.NewMysqld(
"Dba",
"App",
&mysqlctl.Mycnf{},
&dbcfgs.Dba,
&dbcfgs.App.ConnParams,
&dbcfgs.Repl)
Target = query.Target{
Keyspace: "vttest",
Shard: "0",
TabletType: topodata.TabletType_MASTER,
}
server := tabletserver.NewTabletServer(config)
err := server.StartService(&Target, &dbcfgs, nil, mysqld)
if err != nil {
return nil, err
}
return server, nil
}
示例3: main
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)
}
示例4: enable
func (updateStream *UpdateStream) enable(dbcfgs *dbconfigs.DBConfigs) {
updateStream.actionLock.Lock()
defer updateStream.actionLock.Unlock()
if updateStream.isEnabled() {
return
}
if dbcfgs.Dba.UnixSocket == "" {
log.Errorf("Missing dba socket connection, cannot enable update stream service")
return
}
if dbcfgs.App.DbName == "" {
log.Errorf("Missing db name, cannot enable update stream service")
return
}
if updateStream.mycnf.BinLogPath == "" {
log.Errorf("Update stream service requires binlogs enabled")
return
}
updateStream.state.Set(ENABLED)
updateStream.mysqld = mysqlctl.NewMysqld(updateStream.mycnf, &dbcfgs.Dba, &dbcfgs.Repl)
updateStream.dbname = dbcfgs.App.DbName
updateStream.streams.Init()
log.Infof("Enabling update stream, dbname: %s, binlogpath: %s", updateStream.dbname, updateStream.mycnf.BinLogPath)
}
示例5: 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()
}
示例6: 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")
}
}
示例7: StartDefaultServer
// StartDefaultServer starts the default server and initializes
// all the global variables. This function should only be called
// once at the beginning of the test.
func StartDefaultServer(connParams sqldb.ConnParams, schemaOverrides []tabletserver.SchemaOverride) error {
dbcfgs := dbconfigs.DBConfigs{
App: dbconfigs.DBConfig{
ConnParams: connParams,
Keyspace: "vttest",
Shard: "0",
EnableRowcache: true,
EnableInvalidator: false,
},
}
mysqld := mysqlctl.NewMysqld(
"Dba",
"App",
&mysqlctl.Mycnf{},
&dbcfgs.Dba,
&dbcfgs.App.ConnParams,
&dbcfgs.Repl)
BaseConfig = tabletserver.DefaultQsConfig
BaseConfig.RowCache.Binary = vttest.MemcachedPath()
BaseConfig.RowCache.Socket = path.Join(os.TempDir(), "memcache.sock")
BaseConfig.RowCache.Connections = 100
BaseConfig.EnableAutoCommit = true
BaseConfig.StrictTableAcl = true
Target = query.Target{
Keyspace: "vttest",
Shard: "0",
TabletType: topodata.TabletType_MASTER,
}
DefaultServer = tabletserver.NewTabletServer(BaseConfig)
DefaultServer.Register()
err := DefaultServer.StartService(&Target, &dbcfgs, schemaOverrides, mysqld)
if err != nil {
return fmt.Errorf("could not start service: %v\n", err)
}
// Start http service.
ln, err := net.Listen("tcp", ":0")
if err != nil {
return fmt.Errorf("could not start listener: %v\n", err)
}
ServerAddress = fmt.Sprintf("http://%s", ln.Addr().String())
go http.Serve(ln, nil)
for {
time.Sleep(10 * time.Millisecond)
response, err := http.Get(fmt.Sprintf("%s/debug/vars", ServerAddress))
if err == nil {
response.Body.Close()
break
}
}
return nil
}
示例8: newMysqld
func (util *testUtils) newMysqld(dbconfigs *dbconfigs.DBConfigs) mysqlctl.MysqlDaemon {
return mysqlctl.NewMysqld(
"",
"",
mysqlctl.NewMycnf(0, 6802),
&dbconfigs.Dba,
&dbconfigs.App.ConnParams,
&dbconfigs.Repl,
)
}
示例9: 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()
}
示例10: NewActionAgent
// NewActionAgent creates a new ActionAgent and registers all the
// associated services
func NewActionAgent(
tabletAlias topo.TabletAlias,
dbcfgs *dbconfigs.DBConfigs,
mycnf *mysqlctl.Mycnf,
port, securePort int,
overridesFile string,
lockTimeout time.Duration,
) (agent *ActionAgent, err error) {
schemaOverrides := loadSchemaOverrides(overridesFile)
topoServer := topo.GetServer()
mysqld := mysqlctl.NewMysqld("Dba", mycnf, &dbcfgs.Dba, &dbcfgs.Repl)
agent = &ActionAgent{
TopoServer: topoServer,
TabletAlias: tabletAlias,
Mysqld: mysqld,
MysqlDaemon: mysqld,
DBConfigs: dbcfgs,
SchemaOverrides: schemaOverrides,
LockTimeout: lockTimeout,
done: make(chan struct{}),
History: history.New(historyLength),
lastHealthMapCount: stats.NewInt("LastHealthMapCount"),
changeItems: make(chan tabletChangeItem, 100),
}
// Start the binlog player services, not playing at start.
agent.BinlogPlayerMap = NewBinlogPlayerMap(topoServer, &dbcfgs.Filtered, mysqld)
RegisterBinlogPlayerMap(agent.BinlogPlayerMap)
// try to figure out the mysql port
mysqlPort := mycnf.MysqlPort
if mysqlPort == 0 {
// we don't know the port, try to get it from mysqld
var err error
mysqlPort, err = mysqld.GetMysqlPort()
if err != nil {
log.Warningf("Cannot get current mysql port, will use 0 for now: %v", err)
}
}
if err := agent.Start(mysqlPort, port, securePort); err != nil {
return nil, err
}
// register the RPC services from the agent
agent.registerQueryService()
// start health check if needed
agent.initHeathCheck()
return agent, nil
}
示例11: main
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)
}
示例12: 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)
}
示例13: StartServer
// StartServer starts the server and initializes
// all the global variables. This function should only be called
// once at the beginning of the test.
func StartServer(connParams sqldb.ConnParams) error {
dbcfgs := dbconfigs.DBConfigs{
App: dbconfigs.DBConfig{
ConnParams: connParams,
Keyspace: "vttest",
Shard: "0",
},
}
mysqld := mysqlctl.NewMysqld(
"Dba",
"App",
&mysqlctl.Mycnf{},
&dbcfgs.Dba,
&dbcfgs.App.ConnParams,
&dbcfgs.Repl)
BaseConfig = tabletserver.DefaultQsConfig
BaseConfig.EnableAutoCommit = true
BaseConfig.StrictTableAcl = true
Target = querypb.Target{
Keyspace: "vttest",
Shard: "0",
TabletType: topodatapb.TabletType_MASTER,
}
Server = tabletserver.NewTabletServer(BaseConfig)
Server.Register()
err := Server.StartService(Target, dbcfgs, mysqld)
if err != nil {
return fmt.Errorf("could not start service: %v\n", err)
}
// Start http service.
ln, err := net.Listen("tcp", ":0")
if err != nil {
return fmt.Errorf("could not start listener: %v\n", err)
}
ServerAddress = fmt.Sprintf("http://%s", ln.Addr().String())
go http.Serve(ln, nil)
for {
time.Sleep(10 * time.Millisecond)
response, err := http.Get(fmt.Sprintf("%s/debug/vars", ServerAddress))
if err == nil {
response.Body.Close()
break
}
}
return nil
}
示例14: newMysqld
func (util *testUtils) newMysqld(dbconfigs *dbconfigs.DBConfigs) mysqlctl.MysqlDaemon {
cnf := mysqlctl.NewMycnf(11111, 6802)
// Assigning ServerID to be different from tablet UID to make sure that there are no
// assumptions in the code that those IDs are the same.
cnf.ServerID = 22222
return mysqlctl.NewMysqld(
cnf,
&dbconfigs.Dba,
&dbconfigs.AllPrivs,
&dbconfigs.App,
&dbconfigs.Repl,
false, /* enablePublishStats */
)
}
示例15: newMysqld
func (util *testUtils) newMysqld(dbconfigs *dbconfigs.DBConfigs) mysqlctl.MysqlDaemon {
cnf := mysqlctl.NewMycnf(11111, 6802)
// Assigning ServerID to be different from tablet UID to make sure that there are no
// assumptions in the code that those IDs are the same.
cnf.ServerID = 22222
return mysqlctl.NewMysqld(
"",
"",
cnf,
&dbconfigs.Dba,
&dbconfigs.App.ConnParams,
&dbconfigs.Repl,
)
}