Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compactor: add function to remove no compact marker #6917

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/storage/tsdb/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,12 @@ func MarkForNoCompact(ctx context.Context, logger log.Logger, bkt objstore.Bucke
level.Info(logger).Log("msg", "block has been marked for no compaction", "block", id)
return nil
}

func DeleteNoCompactMarker(ctx context.Context, logger log.Logger, bkt objstore.Bucket, id ulid.ULID) error {
m := path.Join(id.String(), NoCompactMarkFilename)
if err := bkt.Delete(ctx, m); err != nil {
return errors.Wrapf(err, "deletion of no-compaction marker for block %s has failed", id.String())
}
level.Info(logger).Log("msg", "no-compaction marker has been deleted; block can be compacted in the future", "block", id)
return nil
}
50 changes: 50 additions & 0 deletions pkg/storage/tsdb/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,56 @@ func TestMarkForNoCompact(t *testing.T) {
}
}

func TestUnMarkForNoCompact(t *testing.T) {
testutil.VerifyNoLeak(t)
ctx := context.Background()
tmpDir := t.TempDir()
for tname, tcase := range map[string]struct {
setupTest func(t testing.TB, id ulid.ULID, bkt objstore.Bucket)
expectedError func(id ulid.ULID) error
}{
"unmark existing block should succeed": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should were add a test case for unmarking a block which doesn't exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second test "unmark non-existing block should fail", is this what you want?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crap, this was written in autopilot. I meant write a test which tries to unmark a block which doesn't have a marker

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 will add it in the next PR

setupTest: func(t testing.TB, id ulid.ULID, bkt objstore.Bucket) {
// upload blocks and no-compact marker
err := Upload(ctx, log.NewNopLogger(), bkt, path.Join(tmpDir, id.String()), nil)
require.NoError(t, err)
m, err := json.Marshal(NoCompactMark{
ID: id,
NoCompactTime: time.Now().Unix(),
Version: NoCompactMarkVersion1,
})
require.NoError(t, err)
require.NoError(t, bkt.Upload(ctx, path.Join(id.String(), NoCompactMarkFilename), bytes.NewReader(m)))
},
expectedError: func(_ ulid.ULID) error {
return nil
},
},
"unmark non-existing block should fail": {
setupTest: func(t testing.TB, id ulid.ULID, bkt objstore.Bucket) {},
expectedError: func(id ulid.ULID) error {
return errors.Errorf("deletion of no-compaction marker for block %s has failed: inmem: object not found", id.String())
},
},
} {
t.Run(tname, func(t *testing.T) {
bkt := objstore.NewInMemBucket()
id, err := CreateBlock(ctx, tmpDir, fiveLabels,
100, 0, 1000, labels.FromStrings("ext1", "val1"))
require.NoError(t, err)
tcase.setupTest(t, id, bkt)
err = DeleteNoCompactMarker(ctx, log.NewNopLogger(), bkt, id)
if expErr := tcase.expectedError(id); expErr != nil {
require.EqualError(t, err, expErr.Error())
} else {
require.NoError(t, err)
_, ok := bkt.Objects()[path.Join(id.String(), NoCompactMarkFilename)]
require.False(t, ok)
}
})
}
}

func TestUploadCleanup(t *testing.T) {
testutil.VerifyNoLeak(t)

Expand Down
Loading