Skip to content

Commit

Permalink
Reduce mutex operations in DeduplicateFilter
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Berkley <nberkley@tripadvisor.com>
  • Loading branch information
nberkley committed Dec 17, 2021
1 parent d8249fe commit 5a5165f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/block/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,29 +642,33 @@ func (f *DeduplicateFilter) filterGroup(metaSlice []*metadata.Meta, metas map[ul
})

var coveringSet []*metadata.Meta
var duplicates []ulid.ULID
childLoop:
for _, child := range metaSlice {
childSources := child.Compaction.Sources
id := child.ULID
for _, parent := range coveringSet {
parentSources := parent.Compaction.Sources

// child's sources are present in parent's sources, filter it out.
if contains(parentSources, childSources) {
f.mu.Lock()
if metas[id] != nil {
f.duplicateIDs = append(f.duplicateIDs, id)
}
synced.WithLabelValues(duplicateMeta).Inc()
delete(metas, id)
f.mu.Unlock()
duplicates = append(duplicates, child.ULID)
continue childLoop
}
}

// Child's sources not covered by any member of coveringSet, add it to coveringSet
coveringSet = append(coveringSet, child)
}

f.mu.Lock()
for _, duplicate := range duplicates {
if metas[duplicate] != nil {
f.duplicateIDs = append(f.duplicateIDs, duplicate)
}
synced.WithLabelValues(duplicateMeta).Inc()
delete(metas, duplicate)
}
f.mu.Unlock()
}

// DuplicateIDs returns slice of block ids that are filtered out by DeduplicateFilter.
Expand Down

0 comments on commit 5a5165f

Please sign in to comment.