From 6597d4e7840a02191fe1a4e4aaa852f73d9ca478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Fri, 26 Feb 2021 15:59:21 +0200 Subject: [PATCH] downsample: ensure consistent order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensure that we have a consistent order of blocks that we are going to downsample. `range` over maps doesn't enforce any particular order on purpose. This is needed for https://github.com/thanos-io/thanos/pull/3031/files. ATM in that PR before downsampling we delete all directories which do not match blocks ULIDs in the remote object storage. Ideally, we should only keep around the files of a block which we are about to downsample. It is impossible to do that properly ATM if during another iteration we'd start from a different block. Thus, let's have a consistent order. Signed-off-by: Giedrius Statkevičius --- cmd/thanos/downsample.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/thanos/downsample.go b/cmd/thanos/downsample.go index a945efcb99..7d6fbff402 100644 --- a/cmd/thanos/downsample.go +++ b/cmd/thanos/downsample.go @@ -7,6 +7,7 @@ import ( "context" "os" "path/filepath" + "sort" "time" "github.com/go-kit/kit/log" @@ -194,7 +195,17 @@ func downsampleBucket( } } - for _, m := range metas { + metasULIDS := make([]ulid.ULID, 0, len(metas)) + for k := range metas { + metasULIDS = append(metasULIDS, k) + } + sort.Slice(metasULIDS, func(i, j int) bool { + return metasULIDS[i].Compare(metasULIDS[j]) < 0 + }) + + for _, mk := range metasULIDS { + m := metas[mk] + switch m.Thanos.Downsample.Resolution { case downsample.ResLevel0: missing := false