mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
embed: fix revision-based compaction with default value
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
parent
4aa0320439
commit
83d1c3d5ec
@ -157,3 +157,13 @@ func TestAutoCompactionModeInvalid(t *testing.T) {
|
||||
t.Errorf("expected non-nil error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAutoCompactionModeParse(t *testing.T) {
|
||||
dur, err := parseCompactionRetention("revision", "1")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if dur != 1 {
|
||||
t.Fatalf("AutoCompactionRetention expected 1, got %d", dur)
|
||||
}
|
||||
}
|
||||
|
@ -134,22 +134,13 @@ func StartEtcd(inCfg *Config) (e *Etcd, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
autoCompactionRetention time.Duration
|
||||
h int
|
||||
)
|
||||
// AutoCompactionRetention defaults to "0" if not set.
|
||||
if len(cfg.AutoCompactionRetention) == 0 {
|
||||
cfg.AutoCompactionRetention = "0"
|
||||
}
|
||||
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)
|
||||
}
|
||||
autoCompactionRetention, err := parseCompactionRetention(cfg.AutoCompactionMode, cfg.AutoCompactionRetention)
|
||||
if err != nil {
|
||||
return e, err
|
||||
}
|
||||
|
||||
srvcfg := etcdserver.ServerConfig{
|
||||
@ -562,3 +553,22 @@ func (e *Etcd) errHandler(err error) {
|
||||
case e.errc <- err:
|
||||
}
|
||||
}
|
||||
|
||||
func parseCompactionRetention(mode, retention string) (ret time.Duration, err error) {
|
||||
h, err := strconv.Atoi(retention)
|
||||
if err == nil {
|
||||
switch mode {
|
||||
case CompactorModeRevision:
|
||||
ret = time.Duration(int64(h))
|
||||
case CompactorModePeriodic:
|
||||
ret = time.Duration(int64(h)) * time.Hour
|
||||
}
|
||||
} else {
|
||||
// periodic compaction
|
||||
ret, err = time.ParseDuration(retention)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("error parsing CompactionRetention: %v", err)
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user