From 05c441f92f273caf40ab0f80405d4f351c2f5f14 Mon Sep 17 00:00:00 2001 From: "Sahdev P. Zala" Date: Wed, 15 Apr 2020 11:29:01 -0400 Subject: [PATCH] embed: fix compaction runtime err Handle negative value input which currently gives a runtime error. --- embed/config_test.go | 2 ++ embed/etcd.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/embed/config_test.go b/embed/config_test.go index eacf181ba34..bb94fec0aee 100644 --- a/embed/config_test.go +++ b/embed/config_test.go @@ -178,9 +178,11 @@ func TestAutoCompactionModeParse(t *testing.T) { {"revision", "1", false, 1}, {"revision", "1h", false, time.Hour}, {"revision", "a", true, 0}, + {"revision", "-1", true, 0}, // periodic {"periodic", "1", false, time.Hour}, {"periodic", "a", true, 0}, + {"revision", "-1", true, 0}, // err mode {"errmode", "1", false, 0}, {"errmode", "1h", false, time.Hour}, diff --git a/embed/etcd.go b/embed/etcd.go index 75a635b6abd..86bf7c97eeb 100644 --- a/embed/etcd.go +++ b/embed/etcd.go @@ -812,7 +812,7 @@ func (e *Etcd) GetLogger() *zap.Logger { func parseCompactionRetention(mode, retention string) (ret time.Duration, err error) { h, err := strconv.Atoi(retention) - if err == nil { + if err == nil && h >= 0 { switch mode { case CompactorModeRevision: ret = time.Duration(int64(h))