Skip to content

Commit

Permalink
pkg/block/fetcher: fix concurrent map usage
Browse files Browse the repository at this point in the history
Fixes: thanos-io#2471

This commit fixes an issue where multiple goroutines in the block
fetcher filtering were concurrently accessing the same map. The
goroutines were concurrently writing AND reading to the shared metas
map. This commit guards this concurrent access by giving the
DeduplicateFilter struct a mutex.

Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
  • Loading branch information
squat committed Apr 20, 2020
1 parent 7c5bea6 commit ee24aea
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/block/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ var _ MetadataFilter = &DeduplicateFilter{}
// Not go-routine safe.
type DeduplicateFilter struct {
duplicateIDs []ulid.ULID
mu sync.Mutex
}

// NewDeduplicateFilter creates DeduplicateFilter.
Expand Down Expand Up @@ -603,11 +604,13 @@ func (f *DeduplicateFilter) filterForResolution(root *Node, metaSlice []*metadat

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

Expand Down

0 comments on commit ee24aea

Please sign in to comment.