From c48069ce8814b06a1204b3e985ba02780a9a6ca8 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Thu, 5 Oct 2017 20:34:35 +0200 Subject: [PATCH] retention grid: interva length monotonicity: exception for keep=all fixes #6 --- cmd/config_prune_grid.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cmd/config_prune_grid.go b/cmd/config_prune_grid.go index 0556e55..9af89c1 100644 --- a/cmd/config_prune_grid.go +++ b/cmd/config_prune_grid.go @@ -80,13 +80,22 @@ func parseGridPrunePolicy(e map[string]interface{}) (p *GridPrunePolicy, err err // Assert intervals are of increasing length (not necessarily required, but indicates config mistake) lastDuration := time.Duration(0) for i := range intervals { + if intervals[i].Length < lastDuration { - err = fmt.Errorf("retention grid interval length must be monotonically increasing:"+ - "interval %d is shorter than %d", i+1, i) + // If all intervals before were keep=all, this is ok + allPrevKeepCountAll := true + for j := i - 1; allPrevKeepCountAll && j >= 0; j-- { + allPrevKeepCountAll = intervals[j].KeepCount == util.RetentionGridKeepCountAll + } + if allPrevKeepCountAll { + goto isMonotonicIncrease + } + err = errors.New("retention grid interval length must be monotonically increasing") return - } else { - lastDuration = intervals[i].Length } + isMonotonicIncrease: + lastDuration = intervals[i].Length + } p.RetentionGrid = util.NewRetentionGrid(intervals)