Skip to content

Avoid large blocks on forced compaction of blocks ingester #3344

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

Merged
merged 10 commits into from
Oct 27, 2020

Conversation

codesome
Copy link
Contributor

@codesome codesome commented Oct 14, 2020

What this PR does:

Creates smaller blocks out of Head during idle and forced compaction.

Which issue(s) this PR fixes:
Fixes #3308

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]
Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Thanks @codesome ! Good work, LGTM. I left few minor comments, mostly design. I would also be glad if you could add a unit test: we already have TestIngester_flushing and, if I'm not missing anything, could be easy to add another test case where you push samples spanning over different days and make sure it generates 2 output blocks.

Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
@pull-request-size pull-request-size bot added size/L and removed size/M labels Oct 21, 2020
Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
@codesome
Copy link
Contributor Author

PR is ready for another review. I have added a unit test and refactored the code as discussed.

@codesome codesome force-pushed the flush-smaller-blocks branch from 3071f3b to b76dda5 Compare October 21, 2020 12:43
Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
@codesome codesome force-pushed the flush-smaller-blocks branch from b76dda5 to e11b137 Compare October 21, 2020 13:13
Copy link
Contributor

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

LGTM with some nits.

Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
@pstibrany
Copy link
Contributor

Based on offline discussion with @codesome, I've removed compaction mutex, since it's not needed.

Additionally, I've replaced u.db.Compact() call with a for-loop, since during head compaction (in if block), we could receive more data spanning 2 blocks again, which would again create bigger block in last head compact call. Using for-loop fixes that.

@codesome
Copy link
Contributor Author

codesome commented Oct 27, 2020

> Using for-loop fixes that.

Actually it does not, it's similar to calling a Compact(). Once you exit the loop here, you can still get more samples after that.

Additionally, a brute force loop might end up creating unaligned block since it is not aligning them like TSDB does (this brings one more thing that we will need to duplicate other checks that TSDB does and keep them in sync, maintenance burden?).

I propose keeping the Compact() call and instead rely on this for no samples during force flushing.

Copy link
Contributor Author

@codesome codesome left a comment

Choose a reason for hiding this comment

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

LGTM! This is more robust against what Peter mentioned above. Ignore my previous comment.

Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Good job! LGTM, thanks! I just left a couple of minor nits.

},

action: func(t *testing.T, i *Ingester, m *shipperMock) {
// Pushing 5 samples, spanning over 3 days.
Copy link
Contributor

Choose a reason for hiding this comment

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

spanning over 3 days

Aren't they over 2 days? However I believe the test would be even stronger if samples would span 3 days and you would expect 3 blocks in output.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

However I believe the test would be even stronger if samples would span 3 days and you would expect 3 blocks in output.

It will depend on the actual samples, because by default it will try to create 2h blocks and not over a day. So a test of creating smaller blocks + breaking the block when it spans 2 day might be fine. I will update the test and maybe have 3 days itself anyway.

Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
@pstibrany pstibrany merged commit c84e4aa into cortexproject:master Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 participants