Skip to content

Commit

Permalink
embed: fix compaction runtime err (#11787)
Browse files Browse the repository at this point in the history
Handle negative value input which currently gives a runtime error.
  • Loading branch information
spzala authored Apr 15, 2020
1 parent 3faa06e commit 1166b1f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions embed/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,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},
Expand Down
2 changes: 1 addition & 1 deletion embed/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,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))
Expand Down

0 comments on commit 1166b1f

Please sign in to comment.