-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
compact/main: verify compacted and downsampled blocks #194
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -533,8 +533,28 @@ func (cg *Group) Compact(ctx context.Context, comp tsdb.Compactor) (ulid.ULID, e | |
cg.metrics.compactionDuration.Observe(time.Since(begin).Seconds()) | ||
|
||
return id, err | ||
} | ||
|
||
// HaltError is a type wrapper for errors that should halt any further progress on compactions. | ||
type HaltError struct { | ||
err error | ||
} | ||
|
||
func halt(err error) HaltError { | ||
return HaltError{err: err} | ||
} | ||
|
||
func (e HaltError) Error() string { | ||
return e.err.Error() | ||
} | ||
|
||
// IsHaltError returns true if the base error is a HaltError. | ||
func IsHaltError(err error) bool { | ||
_, ok1 := errors.Cause(err).(HaltError) | ||
_, ok2 := errors.Cause(err).(*HaltError) | ||
return ok1 || ok2 | ||
} | ||
|
||
func (cg *Group) compact(ctx context.Context, comp tsdb.Compactor) (id ulid.ULID, err error) { | ||
// Planning a compaction works purely based on the meta.json files in our group's dir. | ||
cg.mtx.Lock() | ||
|
@@ -547,6 +567,27 @@ func (cg *Group) compact(ctx context.Context, comp tsdb.Compactor) (id ulid.ULID | |
if len(plan) == 0 { | ||
return id, nil | ||
} | ||
// Due to #183 we verify that none of the blocks in the plan have overlapping sources. | ||
// This is one potential source of how we could end up with duplicated chunks. | ||
uniqueSources := map[ulid.ULID]struct{}{} | ||
|
||
for _, pdir := range plan { | ||
meta, err := block.ReadMetaFile(pdir) | ||
if err != nil { | ||
return id, errors.Wrapf(err, "read meta from %s", pdir) | ||
} | ||
for _, s := range meta.Compaction.Sources { | ||
if _, ok := uniqueSources[s]; ok { | ||
return id, halt(errors.Errorf("overlapping sources detected for plan %v", plan)) | ||
} | ||
uniqueSources[s] = struct{}{} | ||
} | ||
// Ensure all input blocks are valid. | ||
if err := block.VerifyIndex(filepath.Join(pdir, "index")); err != nil { | ||
return id, errors.Wrapf(halt(err), "invalid plan block %s", pdir) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} | ||
|
||
// Once we have a plan we need to download the actual data. We don't touch | ||
// the main directory but use an intermediate one instead. | ||
wdir := filepath.Join(cg.dir, "tmp") | ||
|
@@ -594,6 +635,11 @@ func (cg *Group) compact(ctx context.Context, comp tsdb.Compactor) (id ulid.ULID | |
return id, errors.Wrap(err, "write new meta") | ||
} | ||
|
||
// Ensure the output block is valid. | ||
if err := block.VerifyIndex(filepath.Join(bdir, "index")); err != nil { | ||
return id, errors.Wrapf(halt(err), "invalid result block %s", bdir) | ||
} | ||
|
||
begin = time.Now() | ||
|
||
if err := objstore.UploadDir(ctx, cg.bkt, bdir, id.String()); err != nil { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally see the reason here, but I feel like this need to be automated a little bit.. I can see cases when people will start it and don't have (or remember to have) alert for halted compactor.. And from orchestration point of view it will be seen as healthy..
Not sure what is the best way to handle it, maybe halting that as an option? (configured by flag) or maybe just return error and fail everything. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a debugging point of view this is the best course of action I think. Remember that it should[tm] not happen to begin with. But if it did and we just exit with an error, we'll get rescheduled and debugging gets harder.
A less severe alternative would be marking ourselves as unhealthy. But in that case k8s will also just kill us eventually and reschedule.
I get that it's a bit of a dirty approach. But we do log an error and we are setting a respective metric.
Once we are fully confident that the issue is resolved we can maybe just exit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure I understand it, but let's hide it behind some debug flag then.