Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Don't write empty blocks #374

Merged

Conversation

codesome
Copy link
Contributor

@codesome codesome commented Sep 8, 2018

Fixes #309
Supersedes #245

compact.go Outdated Show resolved Hide resolved
Signed-off-by: Ganesh Vernekar <[email protected]>
@codesome codesome force-pushed the dont-write-empty-blocks branch from d2d6cd1 to beb0d73 Compare September 10, 2018 10:28
@krasi-georgiev
Copy link
Contributor

LGTM

@krasi-georgiev
Copy link
Contributor

actually I just thought it will be good to add a test for this with some comments why we don't want empty blocks.

@gouthamve
Copy link
Collaborator

Yup, a test for this would be good. LGTM otherwise.

@codesome
Copy link
Contributor Author

And the test found out a bug. The compaction of head was going on in an infinite loop, but not sure why.

One workaround that I tested (which worked properly) was that, send the dir of empty block in Plan(). And in compaction delete the blocks which are empty.

Does this sound fine?

@krasi-georgiev
Copy link
Contributor

can you add the test so I can check what is happening.

Signed-off-by: Ganesh Vernekar <[email protected]>
@codesome
Copy link
Contributor Author

@krasi-georgiev I added the test case.

@krasi-georgiev
Copy link
Contributor

https://github.com/prometheus/tsdb/blob/2945db18cafdef58d9c511d4c9f223becb69ac5a/db.go#L374-L376

it never exits the loop because the head range is not reset.
so either

  1. when adding empty sample the head should not change the min/maxtime
    or
  2. when meta.Stats.NumSamples == 0 should also reset the head min/maxtime.

I think 1 makes more sense.

@gouthamve
Copy link
Collaborator

when adding empty sample the head should not change the min/maxtime

We never add "empty" sample :) We can delete samples though. It's kinda hard to set the mintime during delete.

@krasi-georgiev
Copy link
Contributor

@codesome still stuck with the test?

@codesome
Copy link
Contributor Author

@krasi-georgiev Stuck with exams 😛. I will be back on it tomorrow.

@krasi-georgiev
Copy link
Contributor

Thanks!

@codesome
Copy link
Contributor Author

codesome commented Sep 18, 2018

EDIT: You can skip this comment. Not relevant anymore.

@gouthamve @krasi-georgiev
The thing that is broken in this PR feels not straight forward to fix (will dig in more), so I have come up with this alternative approach.

https://github.com/prometheus/tsdb/compare/master...codesome:remove-empty-block-in-compact?expand=1

This allows you to write empty block during compact, but removes it immediately after. More like, empty blocks might appear during compact(), but not after it has finished. How does this look?

@krasi-georgiev
Copy link
Contributor

I would say lets spend more time in trying to fix the test.

ping me if you run out if ideas and I can also have a look.

@codesome
Copy link
Contributor Author

@krasi-georgiev Actually the test is not broken, the code is broken. I actually found a fix for it (tested, working), I will push it soon.

When number of blocks becomes 0, head is not truncated in reload(). This fixes it.

Signed-off-by: Ganesh Vernekar <[email protected]>
db_test.go Outdated Show resolved Hide resolved
With previous design if a block is not created from parent blocks, the parent block gets undeleted. This adds `Deletable` field in `BlockMetaCompaction` which helps find such parent blocks.

Signed-off-by: Ganesh Vernekar <[email protected]>
@codesome
Copy link
Contributor Author

@krasi-georgiev This is good for anther review.
/cc @gouthamve

compact.go Show resolved Hide resolved
db.go Show resolved Hide resolved
db_test.go Outdated Show resolved Hide resolved
db_test.go Outdated Show resolved Hide resolved
db_test.go Outdated Show resolved Hide resolved
db_test.go Outdated Show resolved Hide resolved
db.go Show resolved Hide resolved
db_test.go Outdated Show resolved Hide resolved
db_test.go Outdated Show resolved Hide resolved
@krasi-georgiev
Copy link
Contributor

lets also update the comment for the Compactor interface

// Compact runs compaction against the provided directories. Must
// only be called concurrently with results of Plan().
// Compaction resulting in an empty block marks all parents as deletable in its meta data..
Compact(dest string, dirs ...string) (ulid.ULID, error)
``

db.go Outdated Show resolved Hide resolved
block.go Outdated Show resolved Hide resolved
Signed-off-by: Ganesh Vernekar <[email protected]>
@codesome codesome force-pushed the dont-write-empty-blocks branch from 98b38fd to 7623f3e Compare September 21, 2018 07:51
Krasi Georgiev added 2 commits January 16, 2019 14:49
db_test.go Outdated Show resolved Hide resolved
db_test.go Outdated Show resolved Hide resolved
db_test.go Outdated Show resolved Hide resolved
db_test.go Outdated Show resolved Hide resolved
db_test.go Outdated Show resolved Hide resolved
Signed-off-by: Ganesh Vernekar <[email protected]>
@codesome
Copy link
Contributor Author

Was not able to address this yet: #374 (comment), rest all reviews have been addressed.

codesome and others added 9 commits January 16, 2019 21:42
Signed-off-by: Ganesh Vernekar <[email protected]>
Signed-off-by: Ganesh Vernekar <[email protected]>
Signed-off-by: Krasi Georgiev <[email protected]>
nit
Signed-off-by: Krasi Georgiev <[email protected]>
Signed-off-by: Krasi Georgiev <[email protected]>
Signed-off-by: Ganesh Vernekar <[email protected]>
@codesome
Copy link
Contributor Author

ping @krasi-georgiev @gouthamve

@krasi-georgiev
Copy link
Contributor

LGTM

Copy link
Collaborator

@gouthamve gouthamve left a comment

Choose a reason for hiding this comment

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

I see that this could break compactions in subtle ways if the wrong ranges are compacted together. Should return only one block for rewriting tombstones.

compact.go Outdated Show resolved Hide resolved
compact.go Outdated Show resolved Hide resolved
compact.go Outdated Show resolved Hide resolved
Signed-off-by: Krasi Georgiev <[email protected]>
@krasi-georgiev
Copy link
Contributor

all done

@krasi-georgiev krasi-georgiev merged commit 1a9d08a into prometheus-junkyard:master Jan 18, 2019
@codesome codesome deleted the dont-write-empty-blocks branch January 18, 2019 11:03
radeklesniewski pushed a commit to SabreOSS/tsdb that referenced this pull request Jan 18, 2019
* Dont write empty blocks when a compaction results in a block with no samples.

Signed-off-by: Ganesh Vernekar <[email protected]>
mikkeloscar added a commit to zalando-incubator/kubernetes-on-aws that referenced this pull request Apr 7, 2019
https://github.com/prometheus/prometheus/releases

Some of these changes seem to be interesting enough to update

[ENHANCEMENT] Query performance improvements. prometheus-junkyard/tsdb#531
[BUGFIX] Scrape: catch errors when creating HTTP clients #5182. Adds new metrics: prometheus_target_scrape_pools_*
deprecating the flag storage.tsdb.retention -> use storage.tsdb.retention.time
[FEATURE] Add subqueries to PromQL.
[ENHANCEMENT] Kubernetes SD: Add service external IP and external name to the discovery metadata. #4940
[ENHANCEMENT] Add metric for number of rule groups loaded. #5090
BUGFIX] Make sure the retention period does not overflow. #5112
[BUGFIX] Make sure the blocks do not get very large. #5112
[BUGFIX] Do not generate blocks with no samples. prometheus-junkyard/tsdb#374
[BUGFIX] Reintroduce metric for WAL corruptions. prometheus-junkyard/tsdb#473

Signed-off-by: Mikkel Oscar Lyderik Larsen <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants