Skip to content

Commit

Permalink
etcdserver: add --max-ops-per-txn flag
Browse files Browse the repository at this point in the history
Fixes #7826
  • Loading branch information
fanminshi committed May 24, 2017
1 parent f75e333 commit 76a3659
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions embed/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions etcdmain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
2 changes: 2 additions & 0 deletions etcdmain/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 6 additions & 3 deletions etcdserver/api/v3rpc/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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}
}

Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions etcdserver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type ServerConfig struct {

AutoCompactionRetention int
QuotaBackendBytes int64
MaxOpsPerTxn uint

StrictReconfigCheck bool

Expand Down

0 comments on commit 76a3659

Please sign in to comment.