Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ install-testing: build
mkdir -p "$${PREFIX}/web/vtctld2"
cp -R web/vtctld2/app "$${PREFIX}/web/vtctld2"

grpcvtctldclient: go/vt/proto/vtctlservice/vtctlservice.pb.go
make -C go/vt/vtctl/grpcvtctldclient

parser:
make -C go/vt/sqlparser

Expand Down
2 changes: 1 addition & 1 deletion examples/local/scripts/vtctld-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ vtctld \
-cell $cell \
-workflow_manager_init \
-workflow_manager_use_election \
-service_map 'grpc-vtctl' \
-service_map 'grpc-vtctl,grpc-vtctld' \
-backup_storage_implementation file \
-file_backup_storage_root $VTDATAROOT/backups \
-log_dir $VTDATAROOT/tmp \
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ require (
github.com/coreos/bbolt v1.3.2 // indirect
github.com/coreos/etcd v3.3.10+incompatible
github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/corpix/uarand v0.1.1 // indirect
github.com/evanphx/json-patch v4.5.0+incompatible
github.com/go-sql-driver/mysql v1.5.0
Expand All @@ -29,7 +28,7 @@ require (
github.com/golang/snappy v0.0.1
github.com/google/go-cmp v0.4.0
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/gorilla/websocket v1.4.0
github.com/gorilla/websocket v1.4.2
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/hashicorp/consul/api v1.5.0
Expand Down Expand Up @@ -70,11 +69,9 @@ require (
github.com/tchap/go-patricia v0.0.0-20160729071656-dd168db6051b
github.com/tebeka/selenium v0.9.9
github.com/tinylib/msgp v1.1.1 // indirect
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
github.com/uber-go/atomic v1.4.0 // indirect
github.com/uber/jaeger-client-go v2.16.0+incompatible
github.com/uber/jaeger-lib v2.0.0+incompatible // indirect
github.com/ugorji/go v1.1.7 // indirect
github.com/z-division/go-zookeeper v0.0.0-20190128072838-6d7457066b9b
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975
golang.org/x/lint v0.0.0-20190409202823-959b441ac422
Expand Down
61 changes: 57 additions & 4 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go/cmd/vtctlclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
)

// The default values used by these flags cannot be taken from wrangler and
// actionnode modules, as we do't want to depend on them at all.
// actionnode modules, as we don't want to depend on them at all.
var (
actionTimeout = flag.Duration("action_timeout", time.Hour, "timeout for the total command")
server = flag.String("server", "", "server to use for connection")
Expand Down
30 changes: 30 additions & 0 deletions go/cmd/vtctld/plugin_grpcvtctldserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright 2019 The Vitess Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"vitess.io/vitess/go/vt/servenv"
"vitess.io/vitess/go/vt/vtctl/grpcvtctldserver"
)

func init() {
servenv.OnRun(func() {
if servenv.GRPCCheckServiceMap("vtctld") {
grpcvtctldserver.StartServer(servenv.GRPCServer, ts)
}
})
}
98 changes: 98 additions & 0 deletions go/cmd/vtctldclient/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
Copyright 2020 The Vitess Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"encoding/json"
"fmt"

"github.com/spf13/cobra"

vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
)

var (
findAllShardsInKeyspaceCmd = &cobra.Command{
Use: "FindAllShardsInKeyspace keyspace",
Aliases: []string{"findallshardsinkeyspace"},
Args: cobra.ExactArgs(1),
RunE: commandFindAllShardsInKeyspace,
}
getKeyspaceCmd = &cobra.Command{
Use: "GetKeyspace keyspace",
Aliases: []string{"getkeyspace"},
Args: cobra.ExactArgs(1),
RunE: commandGetKeyspace,
}
getKeyspacesCmd = &cobra.Command{
Use: "GetKeyspaces",
Aliases: []string{"getkeyspaces"},
Args: cobra.NoArgs,
RunE: commandGetKeyspaces,
}
)

func commandFindAllShardsInKeyspace(cmd *cobra.Command, args []string) error {
ks := cmd.Flags().Arg(0)
resp, err := client.FindAllShardsInKeyspace(commandCtx, &vtctldatapb.FindAllShardsInKeyspaceRequest{
Keyspace: ks,
})

if err != nil {
return err
}

data, err := json.Marshal(&resp)
if err != nil {
return err
}

fmt.Printf("%s\n", data)
return nil
}

func commandGetKeyspace(cmd *cobra.Command, args []string) error {
ks := cmd.Flags().Arg(0)
resp, err := client.GetKeyspace(commandCtx, &vtctldatapb.GetKeyspaceRequest{
Keyspace: ks,
})

if err != nil {
return err
}

fmt.Printf("%+v\n", resp.Keyspace)

return nil
}

func commandGetKeyspaces(cmd *cobra.Command, args []string) error {
resp, err := client.GetKeyspaces(commandCtx, &vtctldatapb.GetKeyspacesRequest{})
if err != nil {
return err
}

fmt.Printf("%+v\n", resp.Keyspaces)

return nil
}

func init() {
rootCmd.AddCommand(findAllShardsInKeyspaceCmd)
rootCmd.AddCommand(getKeyspaceCmd)
rootCmd.AddCommand(getKeyspacesCmd)
}
96 changes: 96 additions & 0 deletions go/cmd/vtctldclient/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
Copyright 2020 The Vitess Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"context"
"errors"
"flag"
"io"
"os"
"time"

"github.com/spf13/cobra"

"vitess.io/vitess/go/exit"
"vitess.io/vitess/go/trace"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/vtctl/vtctldclient"
)

var (
client vtctldclient.VtctldClient
traceCloser io.Closer
commandCtx context.Context
commandCancel func()

server string
actionTimeout time.Duration

// We use cobra to make subcommands easier to manage. And do a hack below
// in main to grab the rest of the flags globally scattered to make sure we
// pick up things like common servenv flags, tracing flags, etc. Refer to
// commands.go for all of the subcommands.
rootCmd = &cobra.Command{
// We use PersistentPreRun to set up the tracer, grpc client, and
// command context for every command.
PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
traceCloser = trace.StartTracing("vtctldclient")
if server == "" {
err = errors.New("please specify -server <vtctld_host:vtctld_port> to specify the vtctld server to connect to")
log.Error(err)
return err
}

client, err = vtctldclient.New("grpc", server)

commandCtx, commandCancel = context.WithTimeout(context.Background(), actionTimeout)
return err
},
// Similarly, PersistentPostRun cleans up the resources spawned by
// PersistentPreRun.
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
commandCancel()
err := client.Close()
trace.LogErrorsWhenClosing(traceCloser)
return err
},
TraverseChildren: true,
}
)

func main() {
defer exit.Recover()

// Grab all those global flags across the codebase and shove 'em on in.
rootCmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
// Attach our local flags
rootCmd.PersistentFlags().StringVar(&server, "server", "", "server to use for connection")
rootCmd.PersistentFlags().DurationVar(&actionTimeout, "action_timeout", time.Hour, "timeout for the total command")

// hack to get rid of an "ERROR: logging before flag.Parse"
args := os.Args[:]
os.Args = os.Args[:1]
flag.Parse()
os.Args = args

// back to your regularly scheduled cobra programming
if err := rootCmd.Execute(); err != nil {
log.Error(err)
exit.Return(1)
}
}
23 changes: 23 additions & 0 deletions go/cmd/vtctldclient/plugin_grpcvtctldclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright 2020 The Vitess Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

// Imports and register the gRPC vtctld client.

import (
_ "vitess.io/vitess/go/vt/vtctl/grpcvtctldclient"
)
Loading