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

Exclude blocks in last active window from compaction #411

Merged
merged 1 commit into from
Dec 15, 2020
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
15 changes: 14 additions & 1 deletion tempodb/compaction_block_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ func newTimeWindowBlockSelector(blocklist []*encoding.BlockMeta, maxCompactionRa
MaxCompactionObjects: maxCompactionObjects,
}

activeWindow := twbs.windowForTime(time.Now().Add(-activeWindowDuration))

// exclude blocks that fall in last window from active -> inactive cut-over
// blocks in this window will not be compacted in order to avoid
// ownership conflicts where two compactors process the same block
// at the same time as it transitions from last active window to first inactive window.
var newBlocks []*encoding.BlockMeta
for _, b := range twbs.blocklist {
if twbs.windowForBlock(b) != activeWindow {
newBlocks = append(newBlocks, b)
}
}
twbs.blocklist = newBlocks

// sort by compaction window, level, and then size
sort.Slice(twbs.blocklist, func(i, j int) bool {
bi := twbs.blocklist[i]
Expand All @@ -84,7 +98,6 @@ func newTimeWindowBlockSelector(blocklist []*encoding.BlockMeta, maxCompactionRa
wi := twbs.windowForBlock(bi)
wj := twbs.windowForBlock(bj)

activeWindow := twbs.windowForTime(time.Now().Add(-activeWindowDuration))
if activeWindow <= wi && activeWindow <= wj {
// inside active window. sort by: compaction lvl -> window -> size
// we should always choose the smallest two blocks whos compaction lvl and windows match
Expand Down
17 changes: 16 additions & 1 deletion tempodb/compaction_block_selector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,21 @@ func TestTimeWindowBlockSelectorBlocksToCompact(t *testing.T) {
expectedSecond: nil,
expectedHash2: "",
},
{
name: "doesn't select blocks in last active window",
blocklist: []*encoding.BlockMeta{
{
BlockID: uuid.MustParse("00000000-0000-0000-0000-000000000001"),
EndTime: now.Add(-activeWindowDuration),
CompactionLevel: 0,
},
{
BlockID: uuid.MustParse("00000000-0000-0000-0000-000000000002"),
EndTime: now.Add(-activeWindowDuration),
CompactionLevel: 0,
},
},
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -569,7 +584,7 @@ func TestTimeWindowBlockSelectorBlocksToCompact(t *testing.T) {

func TestTimeWindowBlockSelectorSort(t *testing.T) {
now := time.Now()
timeWindow := 12 * time.Hour
timeWindow := time.Hour

tests := []struct {
name string
Expand Down