From 76a365937b7f96c8f57e6f2b1c39e68cc17b889a Mon Sep 17 00:00:00 2001 From: fanmin shi Date: Tue, 23 May 2017 17:50:20 -0700 Subject: [PATCH] etcdserver: add --max-ops-per-txn flag Fixes #7826 --- embed/config.go | 1 + embed/etcd.go | 1 + etcdmain/config.go | 1 + etcdmain/help.go | 2 ++ etcdserver/api/v3rpc/key.go | 9 ++++++--- etcdserver/config.go | 1 + 6 files changed, 12 insertions(+), 3 deletions(-) diff --git a/embed/config.go b/embed/config.go index e3926f66cb4c..8a9d36b82864 100644 --- a/embed/config.go +++ b/embed/config.go @@ -85,6 +85,7 @@ type Config struct { TickMs uint `json:"heartbeat-interval"` ElectionMs uint `json:"election-timeout"` QuotaBackendBytes int64 `json:"quota-backend-bytes"` + MaxOpsPerTxn uint `json:"max-ops-per-txn"` // clustering diff --git a/embed/etcd.go b/embed/etcd.go index f77dee0e0656..5cbaaf44ea12 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, + MaxOpsPerTxn: cfg.MaxOpsPerTxn, StrictReconfigCheck: cfg.StrictReconfigCheck, ClientCertAuthEnabled: cfg.ClientTLSInfo.ClientCertAuth, AuthToken: cfg.AuthToken, diff --git a/etcdmain/config.go b/etcdmain/config.go index b8732200ae60..33ae670490d1 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.MaxOpsPerTxn, "max-ops-per-txn", cfg.MaxOpsPerTxn, "maximum operations per txn that etcd server allows (0 is unlimited); defaults to unlimited.") // 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 cd9282a3192d..cdec46baa4e5 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-ops-per-txn '0' + maximum operations per txn that etcd server allows (0 is unlimited); defaults to unlimited. clustering flags: diff --git a/etcdserver/api/v3rpc/key.go b/etcdserver/api/v3rpc/key.go index 8acae5983c06..639235565414 100644 --- a/etcdserver/api/v3rpc/key.go +++ b/etcdserver/api/v3rpc/key.go @@ -28,9 +28,11 @@ import ( var ( plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver/api/v3rpc") - // Max operations per txn list. For example, Txn.Success can have at most 128 operations, + // MaxOpsPerTxn is the max operations per txn. + // e.g suppose maxOpsPerTxn = 128. + // Txn.Success can have at most 128 operations, // and Txn.Failure can have at most 128 operations. - MaxOpsPerTxn = 128 + MaxOpsPerTxn = 0 ) type kvServer struct { @@ -39,6 +41,7 @@ type kvServer struct { } func NewKVServer(s *etcdserver.EtcdServer) pb.KVServer { + MaxOpsPerTxn = int(s.Cfg.MaxOpsPerTxn) return &kvServer{hdr: newHeader(s), kv: s} } @@ -151,7 +154,7 @@ func checkDeleteRequest(r *pb.DeleteRangeRequest) error { } func checkTxnRequest(r *pb.TxnRequest) error { - if len(r.Compare) > MaxOpsPerTxn || len(r.Success) > MaxOpsPerTxn || len(r.Failure) > MaxOpsPerTxn { + if (len(r.Compare) > MaxOpsPerTxn || len(r.Success) > MaxOpsPerTxn || len(r.Failure) > MaxOpsPerTxn) && MaxOpsPerTxn != 0 { return rpctypes.ErrGRPCTooManyOps } diff --git a/etcdserver/config.go b/etcdserver/config.go index 9c258934a1c0..2a609a995319 100644 --- a/etcdserver/config.go +++ b/etcdserver/config.go @@ -54,6 +54,7 @@ type ServerConfig struct { AutoCompactionRetention int QuotaBackendBytes int64 + MaxOpsPerTxn uint StrictReconfigCheck bool