Skip to content

Commit f8ff622

Browse files
GiedriusSAndre Branchizio
authored andcommitted
downsample: ensure consistent order (thanos-io#3843)
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 <giedriuswork@gmail.com>
1 parent d228fea commit f8ff622

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

cmd/thanos/downsample.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"os"
99
"path/filepath"
10+
"sort"
1011
"time"
1112

1213
"github.com/go-kit/kit/log"
@@ -194,7 +195,17 @@ func downsampleBucket(
194195
}
195196
}
196197

197-
for _, m := range metas {
198+
metasULIDS := make([]ulid.ULID, 0, len(metas))
199+
for k := range metas {
200+
metasULIDS = append(metasULIDS, k)
201+
}
202+
sort.Slice(metasULIDS, func(i, j int) bool {
203+
return metasULIDS[i].Compare(metasULIDS[j]) < 0
204+
})
205+
206+
for _, mk := range metasULIDS {
207+
m := metas[mk]
208+
198209
switch m.Thanos.Downsample.Resolution {
199210
case downsample.ResLevel0:
200211
missing := false

0 commit comments

Comments
 (0)