From 3faed211e535729a9dc36198a8aab8799099d0f3 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Mon, 26 Nov 2018 15:50:26 -0800 Subject: [PATCH] *: add flags to setup backend related config --- Documentation/op-guide/configuration.md | 10 ++++++++++ embed/config.go | 4 ++++ embed/etcd.go | 4 +++- etcdmain/config.go | 2 ++ etcdmain/help.go | 4 ++++ etcdserver/backend.go | 12 ++++++++++++ etcdserver/config.go | 5 +++++ 7 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Documentation/op-guide/configuration.md b/Documentation/op-guide/configuration.md index e8f92f490..ed72e2354 100644 --- a/Documentation/op-guide/configuration.md +++ b/Documentation/op-guide/configuration.md @@ -82,6 +82,16 @@ To start etcd automatically using custom settings at startup in Linux, using a [ + default: 0 + env variable: ETCD_QUOTA_BACKEND_BYTES +### --backend-batch-limit ++ BackendBatchLimit is the maximum operations before commit the backend transaction. ++ default: 0 ++ env variable: ETCD_BACKEND_BATCH_LIMIT + +### --backend-batch-interval ++ BackendBatchInterval is the maximum time before commit the backend transaction. ++ default: 0 ++ env variable: ETCD_BACKEND_BATCH_INTERVAL + ### --max-txn-ops + Maximum number of operations permitted in a transaction. + default: 128 diff --git a/embed/config.go b/embed/config.go index a7d50d042..10cab6e66 100644 --- a/embed/config.go +++ b/embed/config.go @@ -165,6 +165,10 @@ type Config struct { // See https://github.com/etcd-io/etcd/issues/9333 for more detail. InitialElectionTickAdvance bool `json:"initial-election-tick-advance"` + // BackendBatchInterval is the maximum time before commit the backend transaction. + BackendBatchInterval time.Duration `json:"backend-batch-interval"` + // BackendBatchLimit is the maximum operations before commit the backend transaction. + BackendBatchLimit int `json:"backend-batch-limit"` QuotaBackendBytes int64 `json:"quota-backend-bytes"` MaxTxnOps uint `json:"max-txn-ops"` MaxRequestBytes uint `json:"max-request-bytes"` diff --git a/embed/etcd.go b/embed/etcd.go index e4e17fb2d..d61692a3a 100644 --- a/embed/etcd.go +++ b/embed/etcd.go @@ -43,7 +43,7 @@ import ( "go.etcd.io/etcd/version" "github.com/coreos/pkg/capnslog" - "github.com/grpc-ecosystem/go-grpc-prometheus" + grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" "github.com/soheilhy/cmux" "go.uber.org/zap" "google.golang.org/grpc" @@ -181,6 +181,8 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) { AutoCompactionRetention: autoCompactionRetention, AutoCompactionMode: cfg.AutoCompactionMode, QuotaBackendBytes: cfg.QuotaBackendBytes, + BackendBatchLimit: cfg.BackendBatchLimit, + BackendBatchInterval: cfg.BackendBatchInterval, MaxTxnOps: cfg.MaxTxnOps, MaxRequestBytes: cfg.MaxRequestBytes, StrictReconfigCheck: cfg.StrictReconfigCheck, diff --git a/etcdmain/config.go b/etcdmain/config.go index 6d86e5710..045ab33de 100644 --- a/etcdmain/config.go +++ b/etcdmain/config.go @@ -155,6 +155,8 @@ func newConfig() *config { fs.UintVar(&cfg.ec.ElectionMs, "election-timeout", cfg.ec.ElectionMs, "Time (in milliseconds) for an election to timeout.") fs.BoolVar(&cfg.ec.InitialElectionTickAdvance, "initial-election-tick-advance", cfg.ec.InitialElectionTickAdvance, "Whether to fast-forward initial election ticks on boot for faster election.") fs.Int64Var(&cfg.ec.QuotaBackendBytes, "quota-backend-bytes", cfg.ec.QuotaBackendBytes, "Raise alarms when backend size exceeds the given quota. 0 means use the default quota.") + fs.DurationVar(&cfg.ec.BackendBatchInterval, "backend-batch-interval", cfg.ec.BackendBatchInterval, "BackendBatchInterval is the maximum time before commit the backend transaction.") + fs.IntVar(&cfg.ec.BackendBatchLimit, "backend-batch-limit", cfg.ec.BackendBatchLimit, "BackendBatchLimit is the maximum operations before commit the backend transaction.") fs.UintVar(&cfg.ec.MaxTxnOps, "max-txn-ops", cfg.ec.MaxTxnOps, "Maximum number of operations permitted in a transaction.") fs.UintVar(&cfg.ec.MaxRequestBytes, "max-request-bytes", cfg.ec.MaxRequestBytes, "Maximum client request size in bytes the server will accept.") fs.DurationVar(&cfg.ec.GRPCKeepAliveMinTime, "grpc-keepalive-min-time", cfg.ec.GRPCKeepAliveMinTime, "Minimum interval duration that a client should wait before pinging server.") diff --git a/etcdmain/help.go b/etcdmain/help.go index 6ce1f06e2..21d6e72c9 100644 --- a/etcdmain/help.go +++ b/etcdmain/help.go @@ -69,6 +69,10 @@ Member: Maximum number of wal files to retain (0 is unlimited). --quota-backend-bytes '0' Raise alarms when backend size exceeds the given quota (0 defaults to low space quota). + --backend-batch-interval '' + BackendBatchInterval is the maximum time before commit the backend transaction. + --backend-batch-limit '0' + BackendBatchLimit is the maximum operations before commit the backend transaction. --max-txn-ops '128' Maximum number of operations permitted in a transaction. --max-request-bytes '1572864' diff --git a/etcdserver/backend.go b/etcdserver/backend.go index f22147c6c..a5f4ffa75 100644 --- a/etcdserver/backend.go +++ b/etcdserver/backend.go @@ -31,6 +31,18 @@ import ( func newBackend(cfg ServerConfig) backend.Backend { bcfg := backend.DefaultBackendConfig() bcfg.Path = cfg.backendPath() + if cfg.BackendBatchLimit != 0 { + bcfg.BatchLimit = cfg.BackendBatchLimit + if cfg.Logger != nil { + cfg.Logger.Info("setting backend batch limit", zap.Int("batch limit", cfg.BackendBatchLimit)) + } + } + if cfg.BackendBatchInterval != 0 { + bcfg.BatchInterval = cfg.BackendBatchInterval + if cfg.Logger != nil { + cfg.Logger.Info("setting backend batch interval", zap.Duration("batch interval", cfg.BackendBatchInterval)) + } + } bcfg.Logger = cfg.Logger if cfg.QuotaBackendBytes > 0 && cfg.QuotaBackendBytes != DefaultQuotaBytes { // permit 10% excess over quota for disarm diff --git a/etcdserver/config.go b/etcdserver/config.go index 7ce88cfaf..5bf10ea4d 100644 --- a/etcdserver/config.go +++ b/etcdserver/config.go @@ -55,6 +55,11 @@ type ServerConfig struct { MaxSnapFiles uint MaxWALFiles uint + // BackendBatchInterval is the maximum time before commit the backend transaction. + BackendBatchInterval time.Duration + // BackendBatchLimit is the maximum operations before commit the backend transaction. + BackendBatchLimit int + InitialPeerURLsMap types.URLsMap InitialClusterToken string NewCluster bool