diff --git a/etcdctl/ctlv3/command/ep_command.go b/etcdctl/ctlv3/command/ep_command.go index a1534b4df686..0b2067c3e633 100644 --- a/etcdctl/ctlv3/command/ep_command.go +++ b/etcdctl/ctlv3/command/ep_command.go @@ -85,9 +85,11 @@ func epHealthCommandFunc(cmd *cobra.Command, args []string) { ka := keepAliveTimeFromCmd(cmd) kat := keepAliveTimeoutFromCmd(cmd) auth := authCfgFromCmd(cmd) + maxCallSendMsgSize := maxSendBytesFromCmd(cmd) + maxCallRecvMsgSize := maxRecvBytesFromCmd(cmd) cfgs := []*v3.Config{} for _, ep := range endpointsFromCluster(cmd) { - cfg, err := newClientCfg([]string{ep}, dt, ka, kat, sec, auth) + cfg, err := newClientCfg([]string{ep}, dt, ka, kat, sec, auth, maxCallSendMsgSize, maxCallRecvMsgSize) if err != nil { ExitWithError(ExitBadArgs, err) } diff --git a/etcdctl/ctlv3/command/global.go b/etcdctl/ctlv3/command/global.go index ce607e82a0a5..5f182e7ef7ca 100644 --- a/etcdctl/ctlv3/command/global.go +++ b/etcdctl/ctlv3/command/global.go @@ -46,6 +46,9 @@ type GlobalFlags struct { KeepAliveTime time.Duration KeepAliveTimeout time.Duration + MaxCallSendMsgSize int + MaxCallRecvMsgSize int + TLS transport.TLSInfo OutputFormat string @@ -93,12 +96,14 @@ func initDisplayFromCmd(cmd *cobra.Command) { } type clientConfig struct { - endpoints []string - dialTimeout time.Duration - keepAliveTime time.Duration - keepAliveTimeout time.Duration - scfg *secureCfg - acfg *authCfg + endpoints []string + dialTimeout time.Duration + keepAliveTime time.Duration + keepAliveTimeout time.Duration + maxCallSendMsgSize int + maxCallRecvMsgSize int + scfg *secureCfg + acfg *authCfg } func clientConfigFromCmd(cmd *cobra.Command) *clientConfig { @@ -127,6 +132,8 @@ func clientConfigFromCmd(cmd *cobra.Command) *clientConfig { cfg.dialTimeout = dialTimeoutFromCmd(cmd) cfg.keepAliveTime = keepAliveTimeFromCmd(cmd) cfg.keepAliveTimeout = keepAliveTimeoutFromCmd(cmd) + cfg.maxCallSendMsgSize = maxSendBytesFromCmd(cmd) + cfg.maxCallRecvMsgSize = maxRecvBytesFromCmd(cmd) cfg.scfg = secureCfgFromCmd(cmd) cfg.acfg = authCfgFromCmd(cmd) @@ -141,7 +148,7 @@ func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client { } func (cc *clientConfig) mustClient() *clientv3.Client { - cfg, err := newClientCfg(cc.endpoints, cc.dialTimeout, cc.keepAliveTime, cc.keepAliveTimeout, cc.scfg, cc.acfg) + cfg, err := newClientCfg(cc.endpoints, cc.dialTimeout, cc.keepAliveTime, cc.keepAliveTimeout, cc.scfg, cc.acfg, cc.maxCallSendMsgSize, cc.maxCallRecvMsgSize) if err != nil { ExitWithError(ExitBadArgs, err) } @@ -154,7 +161,7 @@ func (cc *clientConfig) mustClient() *clientv3.Client { return client } -func newClientCfg(endpoints []string, dialTimeout, keepAliveTime, keepAliveTimeout time.Duration, scfg *secureCfg, acfg *authCfg) (*clientv3.Config, error) { +func newClientCfg(endpoints []string, dialTimeout, keepAliveTime, keepAliveTimeout time.Duration, scfg *secureCfg, acfg *authCfg, maxCallSendMsgSize int, maxCallRecvMsgSize int) (*clientv3.Config, error) { // set tls if any one tls option set var cfgtls *transport.TLSInfo tlsinfo := transport.TLSInfo{} @@ -183,6 +190,8 @@ func newClientCfg(endpoints []string, dialTimeout, keepAliveTime, keepAliveTimeo DialTimeout: dialTimeout, DialKeepAliveTime: keepAliveTime, DialKeepAliveTimeout: keepAliveTimeout, + MaxCallSendMsgSize: maxCallSendMsgSize, + MaxCallRecvMsgSize: maxCallRecvMsgSize, } if cfgtls != nil { @@ -249,6 +258,22 @@ func keepAliveTimeoutFromCmd(cmd *cobra.Command) time.Duration { return keepAliveTimeout } +func maxSendBytesFromCmd(cmd *cobra.Command) int { + maxSendBytes, err := cmd.Flags().GetInt("max-send-bytes") + if err != nil { + ExitWithError(ExitError, err) + } + return maxSendBytes +} + +func maxRecvBytesFromCmd(cmd *cobra.Command) int { + maxRecvBytes, err := cmd.Flags().GetInt("max-recv-bytes") + if err != nil { + ExitWithError(ExitError, err) + } + return maxRecvBytes +} + func secureCfgFromCmd(cmd *cobra.Command) *secureCfg { cert, key, cacert := keyAndCertFromCmd(cmd) insecureTr := insecureTransportFromCmd(cmd) diff --git a/etcdctl/ctlv3/ctl.go b/etcdctl/ctlv3/ctl.go index 8692084cfcdf..4e12c9750b7c 100644 --- a/etcdctl/ctlv3/ctl.go +++ b/etcdctl/ctlv3/ctl.go @@ -16,6 +16,7 @@ package ctlv3 import ( + "math" "time" "github.com/coreos/etcd/etcdctl/ctlv3/command" @@ -55,6 +56,8 @@ func init() { rootCmd.PersistentFlags().DurationVar(&globalFlags.CommandTimeOut, "command-timeout", defaultCommandTimeOut, "timeout for short running command (excluding dial timeout)") rootCmd.PersistentFlags().DurationVar(&globalFlags.KeepAliveTime, "keepalive-time", defaultKeepAliveTime, "keepalive time for client connections") rootCmd.PersistentFlags().DurationVar(&globalFlags.KeepAliveTimeout, "keepalive-timeout", defaultKeepAliveTimeOut, "keepalive timeout for client connections") + rootCmd.PersistentFlags().IntVar(&globalFlags.MaxCallSendMsgSize, "max-send-bytes", 1.5*1024*1024, "client-side message send limits in bytes (default value is 1.5 MiB)") + rootCmd.PersistentFlags().IntVar(&globalFlags.MaxCallRecvMsgSize, "max-recv-bytes", math.MaxInt32, "client-side message receive limits in bytes (default value is math.MaxInt32)") // TODO: secure by default when etcd enables secure gRPC by default. rootCmd.PersistentFlags().BoolVar(&globalFlags.Insecure, "insecure-transport", true, "disable transport security for client connections")