From 6fc5fde6d73a599ea1a3e0a1eb832fb86993e9d5 Mon Sep 17 00:00:00 2001 From: fanmin shi Date: Mon, 22 May 2017 16:54:50 -0700 Subject: [PATCH] etcdserver: add --max-request-bytes flag --- embed/config.go | 9 ++++++--- embed/etcd.go | 1 + etcdmain/config.go | 1 + etcdmain/help.go | 2 ++ etcdserver/config.go | 3 +++ etcdserver/server.go | 6 ++++++ etcdserver/v3_server.go | 8 +------- 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/embed/config.go b/embed/config.go index e3926f66cb4..aba80e496cd 100644 --- a/embed/config.go +++ b/embed/config.go @@ -37,9 +37,10 @@ const ( ClusterStateFlagNew = "new" ClusterStateFlagExisting = "existing" - DefaultName = "default" - DefaultMaxSnapshots = 5 - DefaultMaxWALs = 5 + DefaultName = "default" + DefaultMaxSnapshots = 5 + DefaultMaxWALs = 5 + DefaultMaxRequestBytes = 1.5 * 1024 * 1024 DefaultListenPeerURLs = "http://localhost:2380" DefaultListenClientURLs = "http://localhost:2379" @@ -85,6 +86,7 @@ type Config struct { TickMs uint `json:"heartbeat-interval"` ElectionMs uint `json:"election-timeout"` QuotaBackendBytes int64 `json:"quota-backend-bytes"` + MaxRequestBytes uint `json:"max-request-bytes"` // clustering @@ -172,6 +174,7 @@ func NewConfig() *Config { MaxWalFiles: DefaultMaxWALs, Name: DefaultName, SnapCount: etcdserver.DefaultSnapCount, + MaxRequestBytes: DefaultMaxRequestBytes, TickMs: 100, ElectionMs: 1000, LPUrls: []url.URL{*lpurl}, diff --git a/embed/etcd.go b/embed/etcd.go index f77dee0e065..a0aec60d9d6 100644 --- a/embed/etcd.go +++ b/embed/etcd.go @@ -139,6 +139,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) { ElectionTicks: cfg.ElectionTicks(), AutoCompactionRetention: cfg.AutoCompactionRetention, QuotaBackendBytes: cfg.QuotaBackendBytes, + MaxRequestBytes: cfg.MaxRequestBytes, StrictReconfigCheck: cfg.StrictReconfigCheck, ClientCertAuthEnabled: cfg.ClientTLSInfo.ClientCertAuth, AuthToken: cfg.AuthToken, diff --git a/etcdmain/config.go b/etcdmain/config.go index b8732200ae6..018b8c89ee9 100644 --- a/etcdmain/config.go +++ b/etcdmain/config.go @@ -138,6 +138,7 @@ func newConfig() *config { fs.UintVar(&cfg.TickMs, "heartbeat-interval", cfg.TickMs, "Time (in milliseconds) of a heartbeat interval.") fs.UintVar(&cfg.ElectionMs, "election-timeout", cfg.ElectionMs, "Time (in milliseconds) for an election to timeout.") fs.Int64Var(&cfg.QuotaBackendBytes, "quota-backend-bytes", cfg.QuotaBackendBytes, "Raise alarms when backend size exceeds the given quota. 0 means use the default quota.") + fs.UintVar(&cfg.MaxRequestBytes, "max-request-bytes", cfg.MaxRequestBytes, "Maximum client request size in bytes the server will accept.") // clustering fs.Var(flags.NewURLsValue(embed.DefaultInitialAdvertisePeerURLs), "initial-advertise-peer-urls", "List of this member's peer URLs to advertise to the rest of the cluster.") diff --git a/etcdmain/help.go b/etcdmain/help.go index cd9282a3192..0580dfac354 100644 --- a/etcdmain/help.go +++ b/etcdmain/help.go @@ -66,6 +66,8 @@ member flags: comma-separated whitelist of origins for CORS (cross-origin resource sharing). --quota-backend-bytes '0' raise alarms when backend size exceeds the given quota (0 defaults to low space quota). + --max-request-bytes '1572864' + maximum client request size in bytes the server will accept. clustering flags: diff --git a/etcdserver/config.go b/etcdserver/config.go index 9c258934a1c..ef83320304d 100644 --- a/etcdserver/config.go +++ b/etcdserver/config.go @@ -55,6 +55,9 @@ type ServerConfig struct { AutoCompactionRetention int QuotaBackendBytes int64 + //MaxRequestBytes is the maximum request size to send over raft. + MaxRequestBytes uint + StrictReconfigCheck bool // ClientCertAuthEnabled is true when cert has been signed by the client CA. diff --git a/etcdserver/server.go b/etcdserver/server.go index 87602606bb9..d1f38f66145 100644 --- a/etcdserver/server.go +++ b/etcdserver/server.go @@ -83,6 +83,8 @@ const ( // maxPendingRevokes is the maximum number of outstanding expired lease revocations. maxPendingRevokes = 16 + + recommendedMaxRequestBytes = 10 * 1024 * 1024 ) var ( @@ -259,6 +261,10 @@ func NewServer(cfg *ServerConfig) (srv *EtcdServer, err error) { cl *membership.RaftCluster ) + if cfg.MaxRequestBytes > recommendedMaxRequestBytes { + plog.Warningf("MaxRequestBytes %v exceeds maximum recommended size %v", cfg.MaxRequestBytes, recommendedMaxRequestBytes) + } + if terr := fileutil.TouchDirAll(cfg.DataDir); terr != nil { return nil, fmt.Errorf("cannot access data directory: %v", terr) } diff --git a/etcdserver/v3_server.go b/etcdserver/v3_server.go index a86e0751364..4b9409a4a45 100644 --- a/etcdserver/v3_server.go +++ b/etcdserver/v3_server.go @@ -31,12 +31,6 @@ import ( ) const ( - // the max request size that raft accepts. - // TODO: make this a flag? But we probably do not want to - // accept large request which might block raft stream. User - // specify a large value might end up with shooting in the foot. - maxRequestBytes = 1.5 * 1024 * 1024 - // In the health case, there might be a small gap (10s of entries) between // the applied index and committed index. // However, if the committed entries are very heavy to apply, the gap might grow. @@ -605,7 +599,7 @@ func (s *EtcdServer) processInternalRaftRequestOnce(ctx context.Context, r pb.In return nil, err } - if len(data) > maxRequestBytes { + if len(data) > int(s.Cfg.MaxRequestBytes) { return nil, ErrRequestTooLarge }