Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #66 from tinyspeck/slack-cherry-pick-2018-01-23
Browse files Browse the repository at this point in the history
Slack cherry pick 2018 01 23
  • Loading branch information
demmer authored Jan 25, 2018
2 parents 53166f5 + 9a1871b commit 19cc74e
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 98 deletions.
9 changes: 1 addition & 8 deletions go/cmd/automation_server/automation_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package main

import (
"flag"
"fmt"
"net"
"os"
Expand All @@ -34,13 +33,7 @@ func init() {
}

func main() {

flag.Parse()

if *servenv.Version {
servenv.AppVersion.Print()
os.Exit(0)
}
servenv.ParseFlags("automation_server")

fmt.Println("Automation Server, listening on:", *servenv.Port)

Expand Down
8 changes: 1 addition & 7 deletions go/cmd/l2vtgate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"flag"
"math/rand"
"os"
"strings"
"time"

Expand Down Expand Up @@ -55,14 +54,9 @@ func init() {
func main() {
defer exit.Recover()

flag.Parse()
servenv.ParseFlags("l2vtgate")
servenv.Init()

if *servenv.Version {
servenv.AppVersion.Print()
os.Exit(0)
}

ts := topo.Open()
defer ts.Close()

Expand Down
7 changes: 1 addition & 6 deletions go/cmd/mysqlctld/mysqlctld.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ func main() {
// mysqlctld only starts and stops mysql, only needs dba.
dbconfigFlags := dbconfigs.DbaConfig
dbconfigs.RegisterFlags(dbconfigFlags)
flag.Parse()

if *servenv.Version {
servenv.AppVersion.Print()
os.Exit(0)
}
servenv.ParseFlags("mysqlctld")

// 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.
Expand Down
14 changes: 1 addition & 13 deletions go/cmd/vtcombo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package main

import (
"flag"
"os"
"strings"
"time"

Expand Down Expand Up @@ -67,18 +66,7 @@ func main() {
dbconfigs.FilteredConfig | dbconfigs.ReplConfig
dbconfigs.RegisterFlags(dbconfigFlags)
mysqlctl.RegisterFlags()
flag.Parse()

if *servenv.Version {
servenv.AppVersion.Print()
os.Exit(0)
}

if len(flag.Args()) > 0 {
flag.Usage()
log.Errorf("vtcombo doesn't take any positional arguments")
exit.Return(1)
}
servenv.ParseFlags("vtcombo")

// parse the input topology
tpb := &vttestpb.VTTestTopology{}
Expand Down
14 changes: 1 addition & 13 deletions go/cmd/vtctl/vtctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,7 @@ func main() {
defer exit.RecoverAll()
defer logutil.Flush()

flag.Parse()
args := flag.Args()

if *servenv.Version {
servenv.AppVersion.Print()
os.Exit(0)
}

if len(args) == 0 {
flag.Usage()
exit.Return(1)
}

args := servenv.ParseFlagsWithArgs("vtctl")
action := args[0]

startMsg := fmt.Sprintf("USER=%v SUDO_USER=%v %v", os.Getenv("USER"), os.Getenv("SUDO_USER"), strings.Join(os.Args, " "))
Expand Down
10 changes: 1 addition & 9 deletions go/cmd/vtctld/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ limitations under the License.
package main

import (
"flag"
"os"

"github.com/youtube/vitess/go/vt/servenv"
"github.com/youtube/vitess/go/vt/topo"
"github.com/youtube/vitess/go/vt/vtctld"
Expand All @@ -35,15 +32,10 @@ var (
)

func main() {
flag.Parse()
servenv.ParseFlags("vtctld")
servenv.Init()
defer servenv.Close()

if *servenv.Version {
servenv.AppVersion.Print()
os.Exit(0)
}

ts = topo.Open()
defer ts.Close()

Expand Down
15 changes: 1 addition & 14 deletions go/cmd/vtexplain/vtexplain.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"flag"
"fmt"
"io/ioutil"
"os"

log "github.com/golang/glog"
"github.com/youtube/vitess/go/exit"
Expand Down Expand Up @@ -123,19 +122,7 @@ func main() {
defer exit.RecoverAll()
defer logutil.Flush()

flag.Parse()

if *servenv.Version {
servenv.AppVersion.Print()
os.Exit(0)
}

args := flag.Args()

if len(args) != 0 {
flag.Usage()
exit.Return(1)
}
servenv.ParseFlags("vtexplain")

err := parseAndRun()
if err != nil {
Expand Down
8 changes: 1 addition & 7 deletions go/cmd/vtgate/vtgate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main
import (
"flag"
"math/rand"
"os"
"strings"
"time"

Expand Down Expand Up @@ -59,14 +58,9 @@ func init() {
func main() {
defer exit.Recover()

flag.Parse()
servenv.ParseFlags("vtgate")
servenv.Init()

if *servenv.Version {
servenv.AppVersion.Print()
os.Exit(0)
}

if initFakeZK != nil {
initFakeZK()
}
Expand Down
10 changes: 1 addition & 9 deletions go/cmd/vtgateclienttest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ limitations under the License.
package main

import (
"flag"
"os"

"github.com/youtube/vitess/go/cmd/vtgateclienttest/services"
"github.com/youtube/vitess/go/exit"
"github.com/youtube/vitess/go/vt/servenv"
Expand All @@ -36,14 +33,9 @@ func init() {
func main() {
defer exit.Recover()

flag.Parse()
servenv.ParseFlags("vtgateclienttest")
servenv.Init()

if *servenv.Version {
servenv.AppVersion.Print()
os.Exit(0)
}

// The implementation chain.
servenv.OnRun(func() {
s := services.CreateServices()
Expand Down
11 changes: 1 addition & 10 deletions go/cmd/vttablet/vttablet.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main

import (
"flag"
"os"

log "github.com/golang/glog"
"github.com/youtube/vitess/go/vt/dbconfigs"
Expand Down Expand Up @@ -52,17 +51,9 @@ func main() {
dbconfigs.FilteredConfig | dbconfigs.ReplConfig
dbconfigs.RegisterFlags(dbconfigFlags)
mysqlctl.RegisterFlags()
flag.Parse()

if *servenv.Version {
servenv.AppVersion.Print()
os.Exit(0)
}
servenv.ParseFlags("vttablet")

if len(flag.Args()) > 0 {
flag.Usage()
log.Exit("vttablet doesn't take any positional arguments")
}
if err := tabletenv.VerifyConfig(); err != nil {
log.Exitf("invalid config: %v", err)
}
Expand Down
35 changes: 35 additions & 0 deletions go/vt/servenv/servenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"net/url"
"os"
"runtime"
"strings"
"sync"
"syscall"
"time"
Expand Down Expand Up @@ -193,3 +194,37 @@ func RegisterDefaultFlags() {
func RunDefault() {
Run(*Port)
}

// ParseFlags initializes flags and handles the common case when no positional
// arguments are expected.
func ParseFlags(cmd string) {
flag.Parse()

if *Version {
AppVersion.Print()
os.Exit(0)
}

args := flag.Args()
if len(args) > 0 {
flag.Usage()
log.Exitf("%s doesn't take any positional arguments, got '%s'", cmd, strings.Join(args, " "))
}
}

// ParseFlagsWithArgs initializes flags and returns the positional arguments
func ParseFlagsWithArgs(cmd string) []string {
flag.Parse()

if *Version {
AppVersion.Print()
os.Exit(0)
}

args := flag.Args()
if len(args) == 0 {
log.Exitf("%s expected at least one positional argument", cmd)
}

return args
}
2 changes: 1 addition & 1 deletion go/vt/srvtopo/resilient_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (server *ResilientServer) WatchSrvVSchema(ctx context.Context, cell string,
} else {
for c := range changes {
// Note we forward topo.ErrNoNode as is.
callback(nil, c.Err)
callback(c.Value, c.Err)
if c.Err != nil {
log.Warningf("Error while watching vschema for cell %s (will wait 5s before retrying): %v", cell, c.Err)
break
Expand Down
2 changes: 1 addition & 1 deletion go/vt/srvtopo/resilient_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func TestWatchSrvVSchema(t *testing.T) {
// Update value, wait for it.
updatedValue := &vschemapb.SrvVSchema{
Keyspaces: map[string]*vschemapb.Keyspace{
"ks1": {},
"ks2": {},
},
}
if err := ts.UpdateSrvVSchema(ctx, "test_cell", updatedValue); err != nil {
Expand Down

0 comments on commit 19cc74e

Please sign in to comment.