Skip to content

Commit

Permalink
indexheader: fix a racy access to the internals of LazyBinaryReader
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Varankin <vladimir.varankin@grafana.com>
Co-authored-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
  • Loading branch information
narqo and dimitarvdimitrov committed Jun 18, 2024
1 parent 968e334 commit 5ff5ffb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/storegateway/indexheader/lazy_binary_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func NewLazyBinaryReader(
logger: logger,
filepath: path,
metrics: metrics,
usedAt: atomic.NewInt64(time.Now().UnixNano()),
usedAt: atomic.NewInt64(0),
onClosed: onClosed,
readerFactory: readerFactory,
blockID: id,
Expand Down
5 changes: 3 additions & 2 deletions pkg/storegateway/indexheader/reader_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ func (p *ReaderPool) LoadedBlocks() map[ulid.ULID]int64 {

blocks := make(map[ulid.ULID]int64, len(p.lazyReaders))
for r := range p.lazyReaders {
if r.reader != nil {
blocks[r.blockID] = r.usedAt.Load() / int64(time.Millisecond)
usedAt := r.usedAt.Load()
if usedAt != 0 {
blocks[r.blockID] = usedAt / int64(time.Millisecond)
}
}

Expand Down

0 comments on commit 5ff5ffb

Please sign in to comment.