diff --git a/go/flags/endtoend/topo2topo.txt b/go/flags/endtoend/topo2topo.txt index c003c3584f3..07eb7cd52ab 100644 --- a/go/flags/endtoend/topo2topo.txt +++ b/go/flags/endtoend/topo2topo.txt @@ -22,6 +22,8 @@ Flags: --from_root string topology server root to copy data from --from_server string topology server address to copy data from --grpc_enable_tracing Enable gRPC tracing. + --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 topo2topo diff --git a/go/flags/endtoend/vtbackup.txt b/go/flags/endtoend/vtbackup.txt index 7fda67f6f13..4bb12efd56b 100644 --- a/go/flags/endtoend/vtbackup.txt +++ b/go/flags/endtoend/vtbackup.txt @@ -142,6 +142,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 vtbackup diff --git a/go/flags/endtoend/vtcombo.txt b/go/flags/endtoend/vtcombo.txt index 4dd5fd0ad75..935d946d804 100644 --- a/go/flags/endtoend/vtcombo.txt +++ b/go/flags/endtoend/vtcombo.txt @@ -152,6 +152,8 @@ Flags: --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/vtctlclient.txt b/go/flags/endtoend/vtctlclient.txt index e7402c0eefd..8dad870565c 100644 --- a/go/flags/endtoend/vtctlclient.txt +++ b/go/flags/endtoend/vtctlclient.txt @@ -17,6 +17,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 6f71ad50237..402c12d9c0f 100644 --- a/go/flags/endtoend/vtctld.txt +++ b/go/flags/endtoend/vtctld.txt @@ -77,6 +77,8 @@ Flags: --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 0e0c91fbf7d..6e98dc2f262 100644 --- a/go/flags/endtoend/vtctldclient.txt +++ b/go/flags/endtoend/vtctldclient.txt @@ -128,6 +128,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 77a6bab4462..1b6b911ddae 100644 --- a/go/flags/endtoend/vtgate.txt +++ b/go/flags/endtoend/vtgate.txt @@ -89,6 +89,8 @@ Flags: --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/vtgateclienttest.txt b/go/flags/endtoend/vtgateclienttest.txt index 6b69941fc79..b62a54edea8 100644 --- a/go/flags/endtoend/vtgateclienttest.txt +++ b/go/flags/endtoend/vtgateclienttest.txt @@ -34,6 +34,8 @@ Flags: --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/vtorc.txt b/go/flags/endtoend/vtorc.txt index 68df2b9d0ce..7e2e6cfaf40 100644 --- a/go/flags/endtoend/vtorc.txt +++ b/go/flags/endtoend/vtorc.txt @@ -46,6 +46,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 vtorc diff --git a/go/flags/endtoend/vttablet.txt b/go/flags/endtoend/vttablet.txt index be12786fc32..568c0a4a201 100644 --- a/go/flags/endtoend/vttablet.txt +++ b/go/flags/endtoend/vttablet.txt @@ -183,6 +183,8 @@ Flags: --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 dc35adb1d8c..d7fd7d46ce8 100644 --- a/go/flags/endtoend/vttestserver.txt +++ b/go/flags/endtoend/vttestserver.txt @@ -63,6 +63,8 @@ Flags: --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 3ffbd2e69fd..c8009bd0731 100644 --- a/go/vt/grpcclient/client.go +++ b/go/vt/grpcclient/client.go @@ -112,11 +112,12 @@ func RegisterGRPCDialOptions(grpcDialOptionsFunc func(opts []grpc.DialOption) ([ // failFast is a non-optional parameter because callers are required to specify // what that should be. func DialContext(ctx context.Context, target string, failFast FailFast, opts ...grpc.DialOption) (*grpc.ClientConn, error) { - 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 7013b95b95a..e5a780472b7 100644 --- a/go/vt/grpccommon/options.go +++ b/go/vt/grpccommon/options.go @@ -28,6 +28,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 // enablePrometheus sets a flag to enable grpc client/server grpc monitoring. enablePrometheus bool ) @@ -39,6 +43,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(&grpc.EnableTracing, "grpc_enable_tracing", grpc.EnableTracing, "Enable gRPC tracing.") fs.BoolVar(&enablePrometheus, "grpc_prometheus", enablePrometheus, "Enable gRPC monitoring with Prometheus.") } @@ -53,6 +59,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 22191d2e587..beade271565 100644 --- a/go/vt/servenv/grpc_server.go +++ b/go/vt/servenv/grpc_server.go @@ -232,10 +232,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 gRPCEnableOrcaMetrics { GRPCServerMetricsRecorder = orca.NewServerMetricsRecorder()