Skip to content

Commit 76a3659

Browse files
committed
etcdserver: add --max-ops-per-txn flag
Fixes etcd-io#7826
1 parent f75e333 commit 76a3659

File tree

6 files changed

+12
-3
lines changed

6 files changed

+12
-3
lines changed

embed/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ type Config struct {
8585
TickMs uint `json:"heartbeat-interval"`
8686
ElectionMs uint `json:"election-timeout"`
8787
QuotaBackendBytes int64 `json:"quota-backend-bytes"`
88+
MaxOpsPerTxn uint `json:"max-ops-per-txn"`
8889

8990
// clustering
9091

embed/etcd.go

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
139139
ElectionTicks: cfg.ElectionTicks(),
140140
AutoCompactionRetention: cfg.AutoCompactionRetention,
141141
QuotaBackendBytes: cfg.QuotaBackendBytes,
142+
MaxOpsPerTxn: cfg.MaxOpsPerTxn,
142143
StrictReconfigCheck: cfg.StrictReconfigCheck,
143144
ClientCertAuthEnabled: cfg.ClientTLSInfo.ClientCertAuth,
144145
AuthToken: cfg.AuthToken,

etcdmain/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ func newConfig() *config {
138138
fs.UintVar(&cfg.TickMs, "heartbeat-interval", cfg.TickMs, "Time (in milliseconds) of a heartbeat interval.")
139139
fs.UintVar(&cfg.ElectionMs, "election-timeout", cfg.ElectionMs, "Time (in milliseconds) for an election to timeout.")
140140
fs.Int64Var(&cfg.QuotaBackendBytes, "quota-backend-bytes", cfg.QuotaBackendBytes, "Raise alarms when backend size exceeds the given quota. 0 means use the default quota.")
141+
fs.UintVar(&cfg.MaxOpsPerTxn, "max-ops-per-txn", cfg.MaxOpsPerTxn, "maximum operations per txn that etcd server allows (0 is unlimited); defaults to unlimited.")
141142

142143
// clustering
143144
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.")

etcdmain/help.go

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ member flags:
6666
comma-separated whitelist of origins for CORS (cross-origin resource sharing).
6767
--quota-backend-bytes '0'
6868
raise alarms when backend size exceeds the given quota (0 defaults to low space quota).
69+
--max-ops-per-txn '0'
70+
maximum operations per txn that etcd server allows (0 is unlimited); defaults to unlimited.
6971
7072
clustering flags:
7173

etcdserver/api/v3rpc/key.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ import (
2828
var (
2929
plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdserver/api/v3rpc")
3030

31-
// Max operations per txn list. For example, Txn.Success can have at most 128 operations,
31+
// MaxOpsPerTxn is the max operations per txn.
32+
// e.g suppose maxOpsPerTxn = 128.
33+
// Txn.Success can have at most 128 operations,
3234
// and Txn.Failure can have at most 128 operations.
33-
MaxOpsPerTxn = 128
35+
MaxOpsPerTxn = 0
3436
)
3537

3638
type kvServer struct {
@@ -39,6 +41,7 @@ type kvServer struct {
3941
}
4042

4143
func NewKVServer(s *etcdserver.EtcdServer) pb.KVServer {
44+
MaxOpsPerTxn = int(s.Cfg.MaxOpsPerTxn)
4245
return &kvServer{hdr: newHeader(s), kv: s}
4346
}
4447

@@ -151,7 +154,7 @@ func checkDeleteRequest(r *pb.DeleteRangeRequest) error {
151154
}
152155

153156
func checkTxnRequest(r *pb.TxnRequest) error {
154-
if len(r.Compare) > MaxOpsPerTxn || len(r.Success) > MaxOpsPerTxn || len(r.Failure) > MaxOpsPerTxn {
157+
if (len(r.Compare) > MaxOpsPerTxn || len(r.Success) > MaxOpsPerTxn || len(r.Failure) > MaxOpsPerTxn) && MaxOpsPerTxn != 0 {
155158
return rpctypes.ErrGRPCTooManyOps
156159
}
157160

etcdserver/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type ServerConfig struct {
5454

5555
AutoCompactionRetention int
5656
QuotaBackendBytes int64
57+
MaxOpsPerTxn uint
5758

5859
StrictReconfigCheck bool
5960

0 commit comments

Comments
 (0)