diff --git a/go/cmd/vtgateproxy/vtgateproxy b/go/cmd/vtgateproxy/vtgateproxy new file mode 100755 index 00000000000..692c79406bc Binary files /dev/null and b/go/cmd/vtgateproxy/vtgateproxy differ diff --git a/go/flags/endtoend/vtbackup.txt b/go/flags/endtoend/vtbackup.txt index 0e0f909224d..4702c3e3845 100644 --- a/go/flags/endtoend/vtbackup.txt +++ b/go/flags/endtoend/vtbackup.txt @@ -78,6 +78,8 @@ Usage of vtbackup: --grpc_initial_window_size int gRPC initial window size --grpc_keepalive_time duration After a duration of this time, if the client doesn't see any activity, it pings the server to see if the transport is still alive. (default 10s) --grpc_keepalive_timeout duration After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that the connection is closed. (default 10s) + --grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size. + --grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size. --grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216) --grpc_prometheus Enable gRPC monitoring with Prometheus. -h, --help display usage and exit diff --git a/go/flags/endtoend/vtctlclient.txt b/go/flags/endtoend/vtctlclient.txt index 9f9aa042a2d..a3bef6b2280 100644 --- a/go/flags/endtoend/vtctlclient.txt +++ b/go/flags/endtoend/vtctlclient.txt @@ -10,6 +10,8 @@ Usage of vtctlclient: --grpc_initial_window_size int gRPC initial window size --grpc_keepalive_time duration After a duration of this time, if the client doesn't see any activity, it pings the server to see if the transport is still alive. (default 10s) --grpc_keepalive_timeout duration After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that the connection is closed. (default 10s) + --grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size. + --grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size. --grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216) --grpc_prometheus Enable gRPC monitoring with Prometheus. -h, --help display usage and exit diff --git a/go/flags/endtoend/vtctld.txt b/go/flags/endtoend/vtctld.txt index c792a89a18c..4e4d4aafb5e 100644 --- a/go/flags/endtoend/vtctld.txt +++ b/go/flags/endtoend/vtctld.txt @@ -47,6 +47,8 @@ Usage of vtctld: --grpc_key string server private key to use for gRPC connections, requires grpc_cert, enables TLS --grpc_max_connection_age duration Maximum age of a client connection before GoAway is sent. (default 2562047h47m16.854775807s) --grpc_max_connection_age_grace duration Additional grace period after grpc_max_connection_age, after which connections are forcibly closed. (default 2562047h47m16.854775807s) + --grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size. + --grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size. --grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216) --grpc_port int Port to listen on for gRPC calls. If zero, do not listen. --grpc_prometheus Enable gRPC monitoring with Prometheus. diff --git a/go/flags/endtoend/vtctldclient.txt b/go/flags/endtoend/vtctldclient.txt index 10a421569ff..54f2dd8de3f 100644 --- a/go/flags/endtoend/vtctldclient.txt +++ b/go/flags/endtoend/vtctldclient.txt @@ -98,6 +98,8 @@ Flags: --grpc_initial_window_size int gRPC initial window size --grpc_keepalive_time duration After a duration of this time, if the client doesn't see any activity, it pings the server to see if the transport is still alive. (default 10s) --grpc_keepalive_timeout duration After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that the connection is closed. (default 10s) + --grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size. + --grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size. --grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216) --grpc_prometheus Enable gRPC monitoring with Prometheus. -h, --help help for vtctldclient diff --git a/go/flags/endtoend/vtgate.txt b/go/flags/endtoend/vtgate.txt index df662d655f1..50ca4b56dd2 100644 --- a/go/flags/endtoend/vtgate.txt +++ b/go/flags/endtoend/vtgate.txt @@ -54,6 +54,8 @@ Usage of vtgate: --grpc_key string server private key to use for gRPC connections, requires grpc_cert, enables TLS --grpc_max_connection_age duration Maximum age of a client connection before GoAway is sent. (default 2562047h47m16.854775807s) --grpc_max_connection_age_grace duration Additional grace period after grpc_max_connection_age, after which connections are forcibly closed. (default 2562047h47m16.854775807s) + --grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size. + --grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size. --grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216) --grpc_port int Port to listen on for gRPC calls. If zero, do not listen. --grpc_prometheus Enable gRPC monitoring with Prometheus. diff --git a/go/flags/endtoend/vtgr.txt b/go/flags/endtoend/vtgr.txt index d6c3e029b9c..8030856ad7f 100644 --- a/go/flags/endtoend/vtgr.txt +++ b/go/flags/endtoend/vtgr.txt @@ -17,6 +17,8 @@ Usage of vtgr: --grpc_initial_window_size int gRPC initial window size --grpc_keepalive_time duration After a duration of this time, if the client doesn't see any activity, it pings the server to see if the transport is still alive. (default 10s) --grpc_keepalive_timeout duration After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that the connection is closed. (default 10s) + --grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size. + --grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size. --grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216) --grpc_prometheus Enable gRPC monitoring with Prometheus. -h, --help display usage and exit diff --git a/go/flags/endtoend/vtorc.txt b/go/flags/endtoend/vtorc.txt index 9eff17163d6..ada6e265186 100644 --- a/go/flags/endtoend/vtorc.txt +++ b/go/flags/endtoend/vtorc.txt @@ -16,6 +16,8 @@ Usage of vtorc: --grpc_initial_window_size int gRPC initial window size --grpc_keepalive_time duration After a duration of this time, if the client doesn't see any activity, it pings the server to see if the transport is still alive. (default 10s) --grpc_keepalive_timeout duration After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that the connection is closed. (default 10s) + --grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size. + --grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size. --grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216) --grpc_prometheus Enable gRPC monitoring with Prometheus. -h, --help display usage and exit diff --git a/go/flags/endtoend/vttablet.txt b/go/flags/endtoend/vttablet.txt index 941df99ba04..b406c5b03e0 100644 --- a/go/flags/endtoend/vttablet.txt +++ b/go/flags/endtoend/vttablet.txt @@ -134,6 +134,8 @@ Usage of vttablet: --grpc_key string server private key to use for gRPC connections, requires grpc_cert, enables TLS --grpc_max_connection_age duration Maximum age of a client connection before GoAway is sent. (default 2562047h47m16.854775807s) --grpc_max_connection_age_grace duration Additional grace period after grpc_max_connection_age, after which connections are forcibly closed. (default 2562047h47m16.854775807s) + --grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size. + --grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size. --grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216) --grpc_port int Port to listen on for gRPC calls. If zero, do not listen. --grpc_prometheus Enable gRPC monitoring with Prometheus. diff --git a/go/flags/endtoend/vttestserver.txt b/go/flags/endtoend/vttestserver.txt index cf9e7361fec..a5ebcb7cc82 100644 --- a/go/flags/endtoend/vttestserver.txt +++ b/go/flags/endtoend/vttestserver.txt @@ -47,6 +47,8 @@ Usage of vttestserver: --grpc_key string server private key to use for gRPC connections, requires grpc_cert, enables TLS --grpc_max_connection_age duration Maximum age of a client connection before GoAway is sent. (default 2562047h47m16.854775807s) --grpc_max_connection_age_grace duration Additional grace period after grpc_max_connection_age, after which connections are forcibly closed. (default 2562047h47m16.854775807s) + --grpc_max_message_recv_size int Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size. + --grpc_max_message_send_size int Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size. --grpc_max_message_size int Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'. (default 16777216) --grpc_port int Port to listen on for gRPC calls. If zero, do not listen. --grpc_prometheus Enable gRPC monitoring with Prometheus. diff --git a/go/vt/grpcclient/client.go b/go/vt/grpcclient/client.go index be239518bf9..0bbe8a3142b 100644 --- a/go/vt/grpcclient/client.go +++ b/go/vt/grpcclient/client.go @@ -110,11 +110,12 @@ func Dial(target string, failFast FailFast, opts ...grpc.DialOption) (*grpc.Clie // what that should be. func DialContext(ctx context.Context, target string, failFast FailFast, opts ...grpc.DialOption) (*grpc.ClientConn, error) { grpccommon.EnableTracingOpt() - msgSize := grpccommon.MaxMessageSize() + maxSendSize := grpccommon.MaxMessageSendSize() + maxRecvSize := grpccommon.MaxMessageRecvSize() newopts := []grpc.DialOption{ grpc.WithDefaultCallOptions( - grpc.MaxCallRecvMsgSize(msgSize), - grpc.MaxCallSendMsgSize(msgSize), + grpc.MaxCallRecvMsgSize(maxRecvSize), + grpc.MaxCallSendMsgSize(maxSendSize), grpc.WaitForReady(bool(!failFast)), ), } diff --git a/go/vt/grpccommon/options.go b/go/vt/grpccommon/options.go index ae9bea0172d..9d8e348ccb8 100644 --- a/go/vt/grpccommon/options.go +++ b/go/vt/grpccommon/options.go @@ -30,6 +30,10 @@ var ( // accept. Larger messages will be rejected. // Note: We're using 16 MiB as default value because that's the default in MySQL maxMessageSize = 16 * 1024 * 1024 + // These options override maxMessageSize if > 0, allowing us to control the max + // size sending independently from receiving. + maxMsgRecvSize = 0 + maxMsgSendSize = 0 // enableTracing sets a flag to enable grpc client/server tracing. enableTracing bool // enablePrometheus sets a flag to enable grpc client/server grpc monitoring. @@ -43,6 +47,8 @@ var ( // command-line arguments. func RegisterFlags(fs *pflag.FlagSet) { fs.IntVar(&maxMessageSize, "grpc_max_message_size", maxMessageSize, "Maximum allowed RPC message size. Larger messages will be rejected by gRPC with the error 'exceeding the max size'.") + fs.IntVar(&maxMsgSendSize, "grpc_max_message_send_size", maxMsgSendSize, "Maximum allowed RPC message size when sending. If 0, defaults to grpc_max_message_size.") + fs.IntVar(&maxMsgRecvSize, "grpc_max_message_recv_size", maxMsgRecvSize, "Maximum allowed RPC message size when receiving. If 0, defaults to grpc_max_message_size.") fs.BoolVar(&enableTracing, "grpc_enable_tracing", enableTracing, "Enable gRPC tracing.") fs.BoolVar(&enablePrometheus, "grpc_prometheus", enablePrometheus, "Enable gRPC monitoring with Prometheus.") } @@ -70,6 +76,20 @@ func MaxMessageSize() int { return maxMessageSize } +func MaxMessageRecvSize() int { + if maxMsgRecvSize > 0 { + return maxMsgRecvSize + } + return MaxMessageSize() +} + +func MaxMessageSendSize() int { + if maxMsgSendSize > 0 { + return maxMsgSendSize + } + return MaxMessageSize() +} + func init() { stats.NewString("GrpcVersion").Set(grpc.Version) } diff --git a/go/vt/servenv/grpc_server.go b/go/vt/servenv/grpc_server.go index 97749bf7efc..1eff867a104 100644 --- a/go/vt/servenv/grpc_server.go +++ b/go/vt/servenv/grpc_server.go @@ -207,10 +207,12 @@ func createGRPCServer() { // grpc: received message length XXXXXXX exceeding the max size 4194304 // Note: For gRPC 1.0.0 it's sufficient to set the limit on the server only // because it's not enforced on the client side. - msgSize := grpccommon.MaxMessageSize() - log.Infof("Setting grpc max message size to %d", msgSize) - opts = append(opts, grpc.MaxRecvMsgSize(msgSize)) - opts = append(opts, grpc.MaxSendMsgSize(msgSize)) + + maxSendSize := grpccommon.MaxMessageSendSize() + maxRecvSize := grpccommon.MaxMessageRecvSize() + log.Infof("Setting grpc server max message sizes to %d (sending), %d (receiving)", maxSendSize, maxRecvSize) + opts = append(opts, grpc.MaxRecvMsgSize(maxRecvSize)) + opts = append(opts, grpc.MaxSendMsgSize(maxSendSize)) if gRPCInitialConnWindowSize != 0 { log.Infof("Setting grpc server initial conn window size to %d", int32(gRPCInitialConnWindowSize))