本文整理汇总了Golang中github.com/youtube/vitess/go/vt/servenv.Close函数的典型用法代码示例。如果您正苦于以下问题:Golang Close函数的具体用法?Golang Close怎么用?Golang Close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Close函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
flag.Parse()
args := flag.Args()
installSignalHandlers()
servenv.Init()
defer servenv.Close()
ts := topo.GetServer()
defer topo.CloseServers()
// the logger will be replaced when we start a job
wr = wrangler.New(logutil.NewConsoleLogger(), ts, 30*time.Second, 30*time.Second)
if len(args) == 0 {
// interactive mode, initialize the web UI to chose a command
initInteractiveMode()
} else {
// single command mode, just runs it
runCommand(args)
}
initStatusHandling()
servenv.RunDefault()
}
开发者ID:nangong92t,项目名称:go_src,代码行数:25,代码来源:vtworker.go
示例2: main
func main() {
flag.Parse()
servenv.Init()
defer servenv.Close()
unmarshalFile(*dbConfigFile, &dbconfig)
log.Infof("dbconfig: %s\n", dbconfig)
unmarshalFile(*overridesFile, &schemaOverrides)
data, _ := json.MarshalIndent(schemaOverrides, "", " ")
log.Infof("schemaOverrides: %s\n", data)
ts.InitQueryService()
ts.AllowQueries(dbconfig, schemaOverrides, ts.LoadCustomRules())
servenv.ServeRPC()
log.Infof("starting vtocc %v", *port)
s := proc.ListenAndServe(fmt.Sprintf("%v", *port))
// A SIGUSR1 means that we're restarting
if s == syscall.SIGUSR1 {
// Give some time for the other process
// to pick up the listeners
time.Sleep(5 * time.Millisecond)
ts.DisallowQueries(true)
} else {
ts.DisallowQueries(false)
}
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:31,代码来源:vtocc.go
示例3: 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
示例4: main
func main() {
flag.Parse()
servenv.Init()
defer servenv.Close()
keyRange, err := key.ParseKeyRangeParts(*start, *end)
if err != nil {
log.Fatalf("Invalid key range: %v", err)
}
if *dbConfigFile == "" {
log.Fatalf("Cannot start without db-config-file")
}
dbConfig, err := readDbConfig(*dbConfigFile)
if err != nil {
log.Fatalf("Cannot read db config file: %v", err)
}
var t []string
if *tables != "" {
t = strings.Split(*tables, ",")
for i, table := range t {
t[i] = strings.TrimSpace(table)
}
}
interrupted := make(chan struct{})
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGTERM)
go func() {
for _ = range c {
close(interrupted)
}
}()
var vtClient mysqlctl.VtClient
vtClient = mysqlctl.NewDbClient(dbConfig)
err = vtClient.Connect()
if err != nil {
log.Fatalf("error in initializing dbClient: %v", err)
}
brs, err := mysqlctl.ReadStartPosition(vtClient, uint32(*uid))
if err != nil {
log.Fatalf("Cannot read start position from db: %v", err)
}
if *debug {
vtClient = mysqlctl.NewDummyVtClient()
}
blp, err := mysqlctl.NewBinlogPlayer(vtClient, keyRange, uint32(*uid), brs, t, *txnBatch, time.Duration(*maxTxnInterval)*time.Second, *execDdl)
if err != nil {
log.Fatalf("error in initializing binlog player: %v", err)
}
err = blp.ApplyBinlogEvents(interrupted)
if err != nil {
log.Errorf("Error in applying binlog events, err %v", err)
}
log.Infof("vt_binlog_player done")
}
开发者ID:CERN-Stage-3,项目名称:vitess,代码行数:58,代码来源:vt_binlog_player.go
示例5: main
// zkocc: a proxy for zk
func main() {
flag.Parse()
servenv.Init()
defer servenv.Close()
servenv.ServeRPC()
zkr := zkocc.NewZkReader(*resolveLocal, flag.Args())
zk.RegisterZkReader(zkr)
topo.RegisterTopoReader(&TopoReader{zkr: zkr})
proc.ListenAndServe(fmt.Sprintf("%v", *port))
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:14,代码来源:zkocc.go
示例6: 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
示例7: main
func main() {
flag.Parse()
servenv.Init()
defer servenv.Close()
ts = topo.GetServer()
defer topo.CloseServers()
// Init the vtctld core
vtctld.InitVtctld(ts)
// Start schema manager service.
initSchema()
// And run the server.
servenv.RunDefault()
}
开发者ID:CowLeo,项目名称:vitess,代码行数:17,代码来源:main.go
示例8: main
func main() {
defer exit.Recover()
flag.Parse()
args := flag.Args()
servenv.Init()
defer servenv.Close()
ts := topo.GetServer()
defer topo.CloseServers()
wi = worker.NewInstance(ts, *cell, *commandDisplayInterval)
wi.InstallSignalHandlers()
wi.InitStatusHandling()
if len(args) == 0 {
// In interactive mode, initialize the web UI to choose a command.
wi.InitInteractiveMode()
} else {
// In single command mode, just run it.
worker, done, err := wi.RunCommand(context.Background(), args, nil /*custom wrangler*/, true /*runFromCli*/)
if err != nil {
log.Error(err)
exit.Return(1)
}
// Run the subsequent, blocking wait asynchronously.
go func() {
if err := wi.WaitForCommand(worker, done); err != nil {
log.Error(err)
logutil.Flush()
// We cannot use exit.Return() here because we are in a different go routine now.
os.Exit(1)
}
logutil.Flush()
os.Exit(0)
}()
}
servenv.RunDefault()
}
开发者ID:dumbunny,项目名称:vitess,代码行数:41,代码来源:vtworker.go
示例9: main
func main() {
flag.Parse()
args := flag.Args()
installSignalHandlers()
servenv.Init()
defer servenv.Close()
ts := topo.GetServer()
defer topo.CloseServers()
wr := wrangler.New(ts, 30*time.Second, 30*time.Second)
if len(args) == 0 {
// interactive mode, initialize the web UI to chose a command
initInteractiveMode(wr)
} else {
runCommand(wr, args)
}
initStatusHandling()
servenv.RunDefault()
}
开发者ID:kingpro,项目名称:vitess,代码行数:23,代码来源:vtworker.go
示例10: main
func main() {
flag.Parse()
servenv.Init()
defer servenv.Close()
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)
}
binlogServer := mysqlctl.NewBinlogServer(mycnf)
mysqlctl.EnableBinlogServerService(binlogServer, *dbname)
proto.RegisterBinlogServer(binlogServer)
rpcwrap.RegisterAuthenticated(binlogServer)
servenv.ServeRPC()
proc.ListenAndServe(fmt.Sprintf("%v", *port))
mysqlctl.DisableBinlogServerService(binlogServer)
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:24,代码来源:vt_binlog_server.go
示例11: main
func main() {
flag.Parse()
servenv.Init()
defer servenv.Close()
templateLoader = NewTemplateLoader(*templateDir, dummyTemplate, *debug)
ts = topo.GetServer()
defer topo.CloseServers()
wr := wrangler.New(logutil.NewConsoleLogger(), ts, 30*time.Second, 30*time.Second)
actionRepo = NewActionRepository(ts)
// keyspace actions
actionRepo.RegisterKeyspaceAction("ValidateKeyspace",
func(wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidateKeyspace(keyspace, false)
})
actionRepo.RegisterKeyspaceAction("ValidateSchemaKeyspace",
func(wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidateSchemaKeyspace(keyspace, nil, false)
})
actionRepo.RegisterKeyspaceAction("ValidateVersionKeyspace",
func(wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidateVersionKeyspace(keyspace)
})
actionRepo.RegisterKeyspaceAction("ValidatePermissionsKeyspace",
func(wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidatePermissionsKeyspace(keyspace)
})
// shard actions
actionRepo.RegisterShardAction("ValidateShard",
func(wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidateShard(keyspace, shard, false)
})
actionRepo.RegisterShardAction("ValidateSchemaShard",
func(wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidateSchemaShard(keyspace, shard, nil, false)
})
actionRepo.RegisterShardAction("ValidateVersionShard",
func(wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidateVersionShard(keyspace, shard)
})
actionRepo.RegisterShardAction("ValidatePermissionsShard",
func(wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidatePermissionsShard(keyspace, shard)
})
// tablet actions
actionRepo.RegisterTabletAction("RpcPing", "",
func(wr *wrangler.Wrangler, tabletAlias topo.TabletAlias, r *http.Request) (string, error) {
return "", wr.ActionInitiator().RpcPing(tabletAlias, 10*time.Second)
})
actionRepo.RegisterTabletAction("ScrapTablet", acl.ADMIN,
func(wr *wrangler.Wrangler, tabletAlias topo.TabletAlias, r *http.Request) (string, error) {
// refuse to scrap tablets that are not spare
ti, err := wr.TopoServer().GetTablet(tabletAlias)
if err != nil {
return "", err
}
if ti.Type != topo.TYPE_SPARE {
return "", fmt.Errorf("Can only scrap spare tablets")
}
actionPath, err := wr.Scrap(tabletAlias, false, false)
if err != nil {
return "", err
}
return "", wr.WaitForCompletion(actionPath)
})
actionRepo.RegisterTabletAction("ScrapTabletForce", acl.ADMIN,
func(wr *wrangler.Wrangler, tabletAlias topo.TabletAlias, r *http.Request) (string, error) {
// refuse to scrap tablets that are not spare
ti, err := wr.TopoServer().GetTablet(tabletAlias)
if err != nil {
return "", err
}
if ti.Type != topo.TYPE_SPARE {
return "", fmt.Errorf("Can only scrap spare tablets")
}
_, err = wr.Scrap(tabletAlias, true, false)
return "", err
})
actionRepo.RegisterTabletAction("DeleteTablet", acl.ADMIN,
func(wr *wrangler.Wrangler, tabletAlias topo.TabletAlias, r *http.Request) (string, error) {
return "", wr.DeleteTablet(tabletAlias)
})
// toplevel index
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
templateLoader.ServeTemplate("index.html", indexContent, w, r)
//.........这里部分代码省略.........
开发者ID:chinna1986,项目名称:vitess,代码行数:101,代码来源:vtctld.go
示例12: main
func main() {
flag.Parse()
servenv.Init()
defer servenv.Close()
templateLoader = NewTemplateLoader(*templateDir, *debug)
ts = topo.GetServer()
defer topo.CloseServers()
actionRepo = NewActionRepository(ts)
// keyspace actions
actionRepo.RegisterKeyspaceAction("ValidateKeyspace",
func(ctx context.Context, wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidateKeyspace(ctx, keyspace, false)
})
actionRepo.RegisterKeyspaceAction("ValidateSchemaKeyspace",
func(ctx context.Context, wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidateSchemaKeyspace(ctx, keyspace, nil, false)
})
actionRepo.RegisterKeyspaceAction("ValidateVersionKeyspace",
func(ctx context.Context, wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidateVersionKeyspace(ctx, keyspace)
})
actionRepo.RegisterKeyspaceAction("ValidatePermissionsKeyspace",
func(ctx context.Context, wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidatePermissionsKeyspace(ctx, keyspace)
})
// shard actions
actionRepo.RegisterShardAction("ValidateShard",
func(ctx context.Context, wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidateShard(ctx, keyspace, shard, false)
})
actionRepo.RegisterShardAction("ValidateSchemaShard",
func(ctx context.Context, wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidateSchemaShard(ctx, keyspace, shard, nil, false)
})
actionRepo.RegisterShardAction("ValidateVersionShard",
func(ctx context.Context, wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidateVersionShard(ctx, keyspace, shard)
})
actionRepo.RegisterShardAction("ValidatePermissionsShard",
func(ctx context.Context, wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidatePermissionsShard(ctx, keyspace, shard)
})
// tablet actions
actionRepo.RegisterTabletAction("Ping", "",
func(ctx context.Context, wr *wrangler.Wrangler, tabletAlias *pb.TabletAlias, r *http.Request) (string, error) {
ti, err := wr.TopoServer().GetTablet(ctx, tabletAlias)
if err != nil {
return "", err
}
return "", wr.TabletManagerClient().Ping(ctx, ti)
})
actionRepo.RegisterTabletAction("RefreshState", acl.ADMIN,
func(ctx context.Context, wr *wrangler.Wrangler, tabletAlias *pb.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 *pb.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 *pb.TabletAlias, r *http.Request) (string, error) {
return "", wr.ReloadSchema(ctx, tabletAlias)
})
// keyspace actions
http.HandleFunc("/keyspace_actions", func(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
httpErrorf(w, r, "cannot parse form: %s", err)
return
}
action := r.FormValue("action")
if action == "" {
http.Error(w, "no action provided", http.StatusBadRequest)
return
}
keyspace := r.FormValue("keyspace")
if keyspace == "" {
http.Error(w, "no keyspace provided", http.StatusBadRequest)
return
}
ctx := context.Background()
//.........这里部分代码省略.........
开发者ID:hadmagic,项目名称:vitess,代码行数:101,代码来源:vtctld.go
示例13: main
func main() {
flag.Parse()
servenv.Init()
defer servenv.Close()
templateLoader = NewTemplateLoader(*templateDir, dummyTemplate, *debug)
ts := topo.GetServer()
defer topo.CloseServers()
wr := wrangler.New(ts, 30*time.Second, 30*time.Second)
actionRepo = NewActionRepository(wr)
// keyspace actions
actionRepo.RegisterKeyspaceAction("ValidateKeyspace",
func(wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidateKeyspace(keyspace, false)
})
actionRepo.RegisterKeyspaceAction("ValidateSchemaKeyspace",
func(wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidateSchemaKeyspace(keyspace, false)
})
actionRepo.RegisterKeyspaceAction("ValidateVersionKeyspace",
func(wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidateVersionKeyspace(keyspace)
})
actionRepo.RegisterKeyspaceAction("ValidatePermissionsKeyspace",
func(wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidatePermissionsKeyspace(keyspace)
})
// shard actions
actionRepo.RegisterShardAction("ValidateShard",
func(wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidateShard(keyspace, shard, false)
})
actionRepo.RegisterShardAction("ValidateSchemaShard",
func(wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidateSchemaShard(keyspace, shard, false)
})
actionRepo.RegisterShardAction("ValidateVersionShard",
func(wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidateVersionShard(keyspace, shard)
})
actionRepo.RegisterShardAction("ValidatePermissionsShard",
func(wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidatePermissionsShard(keyspace, shard)
})
// tablet actions
actionRepo.RegisterTabletAction("RpcPing",
func(wr *wrangler.Wrangler, tabletAlias topo.TabletAlias, r *http.Request) (string, error) {
return "", wr.ActionInitiator().RpcPing(tabletAlias, 10*time.Second)
})
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
templateLoader.ServeTemplate("index.html", indexContent, w, r)
})
http.HandleFunc("/keyspace_actions", func(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
httpError(w, "cannot parse form: %s", err)
return
}
action := r.FormValue("action")
if action == "" {
http.Error(w, "no action provided", http.StatusBadRequest)
return
}
keyspace := r.FormValue("keyspace")
if keyspace == "" {
http.Error(w, "no keyspace provided", http.StatusBadRequest)
return
}
result := actionRepo.ApplyKeyspaceAction(action, keyspace, r)
templateLoader.ServeTemplate("action.html", result, w, r)
})
http.HandleFunc("/shard_actions", func(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
httpError(w, "cannot parse form: %s", err)
return
}
action := r.FormValue("action")
if action == "" {
http.Error(w, "no action provided", http.StatusBadRequest)
return
}
keyspace := r.FormValue("keyspace")
if keyspace == "" {
http.Error(w, "no keyspace provided", http.StatusBadRequest)
return
}
//.........这里部分代码省略.........
开发者ID:rjammala,项目名称:vitess,代码行数:101,代码来源:vtctld.go
示例14: main
func main() {
flag.Parse()
servenv.Init()
defer servenv.Close()
templateLoader = NewTemplateLoader(*templateDir, dummyTemplate, *debug)
ts := topo.GetServer()
defer topo.CloseServers()
wr := wrangler.New(ts, 30*time.Second, 30*time.Second)
actionRepo = NewActionRepository(wr)
// keyspace actions
actionRepo.RegisterKeyspaceAction("ValidateKeyspace",
func(wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidateKeyspace(keyspace, false)
})
actionRepo.RegisterKeyspaceAction("ValidateSchemaKeyspace",
func(wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidateSchemaKeyspace(keyspace, false)
})
actionRepo.RegisterKeyspaceAction("ValidateVersionKeyspace",
func(wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidateVersionKeyspace(keyspace)
})
actionRepo.RegisterKeyspaceAction("ValidatePermissionsKeyspace",
func(wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidatePermissionsKeyspace(keyspace)
})
// shard actions
actionRepo.RegisterShardAction("ValidateShard",
func(wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidateShard(keyspace, shard, false)
})
actionRepo.RegisterShardAction("ValidateSchemaShard",
func(wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidateSchemaShard(keyspace, shard, false)
})
actionRepo.RegisterShardAction("ValidateVersionShard",
func(wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidateVersionShard(keyspace, shard)
})
actionRepo.RegisterShardAction("ValidatePermissionsShard",
func(wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidatePermissionsShard(keyspace, shard)
})
// tablet actions
actionRepo.RegisterTabletAction("RpcPing",
func(wr *wrangler.Wrangler, tabletAlias topo.TabletAlias, r *http.Request) (string, error) {
return "", wr.ActionInitiator().RpcPing(tabletAlias, 10*time.Second)
})
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
templateLoader.ServeTemplate("index.html", indexContent, w, r)
})
http.HandleFunc("/keyspace_actions", func(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
httpError(w, "cannot parse form: %s", err)
return
}
action := r.FormValue("action")
if action == "" {
http.Error(w, "no action provided", http.StatusBadRequest)
return
}
keyspace := r.FormValue("keyspace")
if keyspace == "" {
http.Error(w, "no keyspace provided", http.StatusBadRequest)
return
}
result := actionRepo.ApplyKeyspaceAction(action, keyspace, r)
templateLoader.ServeTemplate("action.html", result, w, r)
})
http.HandleFunc("/shard_actions", func(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
httpError(w, "cannot parse form: %s", err)
return
}
action := r.FormValue("action")
if action == "" {
http.Error(w, "no action provided", http.StatusBadRequest)
return
}
keyspace := r.FormValue("keyspace")
if keyspace == "" {
http.Error(w, "no keyspace provided", http.StatusBadRequest)
return
}
//.........这里部分代码省略.........
开发者ID:CERN-Stage-3,项目名称:vitess,代码行数:101,代码来源:vtctld.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() {
dbConfigsFile, dbCredentialsFile := dbconfigs.RegisterCommonFlags()
flag.Parse()
servenv.Init()
defer servenv.Close()
tabletAlias := vttablet.TabletParamToTabletAlias(*tabletPath)
if *mycnfFile == "" {
*mycnfFile = mysqlctl.MycnfFile(tabletAlias.Uid)
}
mycnf, err := mysqlctl.ReadMycnf(*mycnfFile)
if err != nil {
log.Fatalf("mycnf read failed: %v", err)
}
dbcfgs, err := dbconfigs.Init(mycnf.SocketFile, *dbConfigsFile, *dbCredentialsFile)
if err != nil {
log.Warning(err)
}
ts.InitQueryService()
mysqlctl.RegisterUpdateStreamService(mycnf)
// Depends on both query and updateStream.
ts.RegisterCacheInvalidator()
// Depends on both query and updateStream.
if err := vttablet.InitAgent(tabletAlias, dbcfgs, mycnf, *dbConfigsFile, *dbCredentialsFile, *port, *securePort, *mycnfFile, *overridesFile); err != nil {
log.Fatal(err)
}
servenv.ServeRPC()
vttablet.HttpHandleSnapshots(mycnf, tabletAlias.Uid)
l, err := proc.Listen(fmt.Sprintf("%v", *port))
if err != nil {
log.Fatal(err)
}
go http.Serve(l, nil)
if *securePort != 0 {
log.Infof("listening on secure port %v", *securePort)
vttablet.SecureServe(fmt.Sprintf(":%d", *securePort), *cert, *key, *caCert)
}
log.Infof("started vttablet %v", *port)
s := proc.Wait()
// A SIGUSR1 means that we're restarting
if s == syscall.SIGUSR1 {
// Give some time for the other process
// to pick up the listeners
log.Info("Exiting on SIGUSR1")
time.Sleep(5 * time.Millisecond)
ts.DisallowQueries(true)
} else {
log.Info("Exiting on SIGTERM")
ts.DisallowQueries(false)
}
mysqlctl.DisableUpdateStreamService()
topo.CloseServers()
vttablet.CloseAgent()
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:67,代码来源:vttablet.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() {
flag.Parse()
servenv.Init()
defer servenv.Close()
ts = topo.GetServer()
defer topo.CloseServers()
actionRepo = NewActionRepository(ts)
// keyspace actions
actionRepo.RegisterKeyspaceAction("ValidateKeyspace",
func(ctx context.Context, wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidateKeyspace(ctx, keyspace, false)
})
actionRepo.RegisterKeyspaceAction("ValidateSchemaKeyspace",
func(ctx context.Context, wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidateSchemaKeyspace(ctx, keyspace, nil, false)
})
actionRepo.RegisterKeyspaceAction("ValidateVersionKeyspace",
func(ctx context.Context, wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidateVersionKeyspace(ctx, keyspace)
})
actionRepo.RegisterKeyspaceAction("ValidatePermissionsKeyspace",
func(ctx context.Context, wr *wrangler.Wrangler, keyspace string, r *http.Request) (string, error) {
return "", wr.ValidatePermissionsKeyspace(ctx, keyspace)
})
// shard actions
actionRepo.RegisterShardAction("ValidateShard",
func(ctx context.Context, wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidateShard(ctx, keyspace, shard, false)
})
actionRepo.RegisterShardAction("ValidateSchemaShard",
func(ctx context.Context, wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidateSchemaShard(ctx, keyspace, shard, nil, false)
})
actionRepo.RegisterShardAction("ValidateVersionShard",
func(ctx context.Context, wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidateVersionShard(ctx, keyspace, shard)
})
actionRepo.RegisterShardAction("ValidatePermissionsShard",
func(ctx context.Context, wr *wrangler.Wrangler, keyspace, shard string, r *http.Request) (string, error) {
return "", wr.ValidatePermissionsShard(ctx, keyspace, shard)
})
// tablet actions
actionRepo.RegisterTabletAction("Ping", "",
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().Ping(ctx, ti)
})
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))
})
//.........这里部分代码省略.........
开发者ID:BobbWu,项目名称:vitess,代码行数:101,代码来源:vtctld.go
注:本文中的github.com/youtube/vitess/go/vt/servenv.Close函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论