Skip to content

Commit

Permalink
compact: Refactored compaction Planner for ability to extend planners…
Browse files Browse the repository at this point in the history
…. Added compatibility tests. (#3402)

Signed-off-by: Bartlomiej Plotka <[email protected]>
  • Loading branch information
bwplotka authored Nov 4, 2020
1 parent 2ad3805 commit cb727ab
Show file tree
Hide file tree
Showing 9 changed files with 673 additions and 120 deletions.
2 changes: 1 addition & 1 deletion cmd/thanos/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func runCompact(

grouper := compact.NewDefaultGrouper(logger, bkt, conf.acceptMalformedIndex, enableVerticalCompaction, reg, blocksMarkedForDeletion, garbageCollectedBlocks)
blocksCleaner := compact.NewBlocksCleaner(logger, bkt, ignoreDeletionMarkFilter, deleteDelay, blocksCleaned, blockCleanupFailures)
compactor, err := compact.NewBucketCompactor(logger, sy, grouper, comp, compactDir, bkt, conf.compactionConcurrency)
compactor, err := compact.NewBucketCompactor(logger, sy, grouper, compact.NewTSDBBasedPlanner(logger, levels), comp, compactDir, bkt, conf.compactionConcurrency)
if err != nil {
cancel()
return errors.Wrap(err, "create bucket compactor")
Expand Down
5 changes: 2 additions & 3 deletions pkg/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestUpload(t *testing.T) {
testutil.Equals(t, 4, len(bkt.Objects()))
testutil.Equals(t, 3751, len(bkt.Objects()[path.Join(b1.String(), ChunksDirname, "000001")]))
testutil.Equals(t, 401, len(bkt.Objects()[path.Join(b1.String(), IndexFilename)]))
testutil.Equals(t, 562, len(bkt.Objects()[path.Join(b1.String(), MetaFilename)]))
testutil.Equals(t, 546, len(bkt.Objects()[path.Join(b1.String(), MetaFilename)]))

// File stats are gathered.
testutil.Equals(t, fmt.Sprintf(`{
Expand All @@ -161,7 +161,6 @@ func TestUpload(t *testing.T) {
},
"version": 1,
"thanos": {
"version": 1,
"labels": {
"ext1": "val1"
},
Expand Down Expand Up @@ -192,7 +191,7 @@ func TestUpload(t *testing.T) {
testutil.Equals(t, 4, len(bkt.Objects()))
testutil.Equals(t, 3751, len(bkt.Objects()[path.Join(b1.String(), ChunksDirname, "000001")]))
testutil.Equals(t, 401, len(bkt.Objects()[path.Join(b1.String(), IndexFilename)]))
testutil.Equals(t, 562, len(bkt.Objects()[path.Join(b1.String(), MetaFilename)]))
testutil.Equals(t, 546, len(bkt.Objects()[path.Join(b1.String(), MetaFilename)]))
}
{
// Upload with no external labels should be blocked.
Expand Down
9 changes: 5 additions & 4 deletions pkg/block/metadata/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,14 @@ func Read(dir string) (*Meta, error) {
if m.Version != TSDBVersion1 {
return nil, errors.Errorf("unexpected meta file version %d", m.Version)
}
if m.Thanos.Version == 0 {

version := m.Thanos.Version
if version == 0 {
// For compatibility.
m.Thanos.Version = ThanosVersion1
return &m, nil
version = ThanosVersion1
}

if m.Thanos.Version != ThanosVersion1 {
if version != ThanosVersion1 {
return nil, errors.Errorf("unexpected meta file Thanos section version %d", m.Version)
}
return &m, nil
Expand Down
Loading

0 comments on commit cb727ab

Please sign in to comment.