From 39e68ef12d1eb5db136f92fe0394d5ad4657d3c1 Mon Sep 17 00:00:00 2001 From: fanmin shi Date: Tue, 26 Sep 2017 10:06:45 -0700 Subject: [PATCH] *: modify etcd flags to support finner compaction retention --- embed/config.go | 2 +- embed/etcd.go | 17 ++++++++++++++++- etcdmain/config.go | 4 ++-- etcdmain/help.go | 2 +- etcdserver/config.go | 2 +- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/embed/config.go b/embed/config.go index 8d429cb0a5c1..deae3229a2f5 100644 --- a/embed/config.go +++ b/embed/config.go @@ -81,7 +81,7 @@ type Config struct { MaxWalFiles uint `json:"max-wals"` Name string `json:"name"` SnapCount uint64 `json:"snapshot-count"` - AutoCompactionRetention int `json:"auto-compaction-retention"` + AutoCompactionRetention string `json:"auto-compaction-retention"` AutoCompactionMode string `json:"auto-compaction-mode"` // TickMs is the number of milliseconds between heartbeat ticks. diff --git a/embed/etcd.go b/embed/etcd.go index 6ceb55b79307..bae8c443a8d7 100644 --- a/embed/etcd.go +++ b/embed/etcd.go @@ -23,6 +23,7 @@ import ( "net" "net/http" "net/url" + "strconv" "sync" "time" @@ -127,6 +128,20 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) { } } + var ( + autoCompactionRetention time.Duration + h int + ) + h, err = strconv.Atoi(cfg.AutoCompactionRetention) + if err == nil { + autoCompactionRetention = time.Duration(int64(h)) * time.Hour + } else { + autoCompactionRetention, err = time.ParseDuration(cfg.AutoCompactionRetention) + if err != nil { + return nil, fmt.Errorf("error parsing AutoCompactionRetention: %v", err) + } + } + srvcfg := etcdserver.ServerConfig{ Name: cfg.Name, ClientURLs: cfg.ACUrls, @@ -145,7 +160,7 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) { PeerTLSInfo: cfg.PeerTLSInfo, TickMs: cfg.TickMs, ElectionTicks: cfg.ElectionTicks(), - AutoCompactionRetention: cfg.AutoCompactionRetention, + AutoCompactionRetention: autoCompactionRetention, AutoCompactionMode: cfg.AutoCompactionMode, QuotaBackendBytes: cfg.QuotaBackendBytes, MaxTxnOps: cfg.MaxTxnOps, diff --git a/etcdmain/config.go b/etcdmain/config.go index 614112923632..73b059d2f801 100644 --- a/etcdmain/config.go +++ b/etcdmain/config.go @@ -196,8 +196,8 @@ func newConfig() *config { // version fs.BoolVar(&cfg.printVersion, "version", false, "Print the version and exit.") - fs.IntVar(&cfg.AutoCompactionRetention, "auto-compaction-retention", 0, "Auto compaction retention for mvcc key value store. 0 means disable auto compaction.") - fs.StringVar(&cfg.AutoCompactionMode, "auto-compaction-mode", "periodic", "Interpret 'auto-compaction-retention' as hours when 'periodic', as revision numbers when 'revision'.") + fs.StringVar(&cfg.AutoCompactionRetention, "auto-compaction-retention", "0", "Auto compaction retention for mvcc key value store. 0 means disable auto compaction.") + fs.StringVar(&cfg.AutoCompactionMode, "auto-compaction-mode", "periodic", "'periodic' means hours if an integer or a duration string otherwise, 'revision' means revision numbers to retain by auto compaction") // pprof profiler via HTTP fs.BoolVar(&cfg.EnablePprof, "enable-pprof", false, "Enable runtime profiling data via HTTP server. Address is at client URL + \"/debug/pprof/\"") diff --git a/etcdmain/help.go b/etcdmain/help.go index 37a670abdd5a..58cd9cab9fde 100644 --- a/etcdmain/help.go +++ b/etcdmain/help.go @@ -99,7 +99,7 @@ clustering flags: --auto-compaction-retention '0' auto compaction retention length. 0 means disable auto compaction. --auto-compaction-mode 'periodic' - 'periodic' means hours, 'revision' means revision numbers to retain by auto compaction + 'periodic' means hours if an integer or a duration string otherwise, 'revision' means revision numbers to retain by auto compaction. --enable-v2 Accept etcd V2 client requests. diff --git a/etcdserver/config.go b/etcdserver/config.go index cac4fb010602..e35095493c13 100644 --- a/etcdserver/config.go +++ b/etcdserver/config.go @@ -51,7 +51,7 @@ type ServerConfig struct { ElectionTicks int BootstrapTimeout time.Duration - AutoCompactionRetention int + AutoCompactionRetention time.Duration AutoCompactionMode string QuotaBackendBytes int64 MaxTxnOps uint