Skip to content

Commit

Permalink
Address another data race
Browse files Browse the repository at this point in the history
  • Loading branch information
simonswine committed Feb 8, 2023
1 parent 83f111e commit 960d100
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pkg/phlaredb/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ func (h *Head) Close() error {

// Flush closes the head and writes data to disk
func (h *Head) Flush(ctx context.Context) error {
if len(h.profiles.slice) == 0 {
if h.profiles.empty() {
level.Info(h.logger).Log("msg", "head empty - no block written")
return os.RemoveAll(h.headPath)
}
Expand Down
10 changes: 1 addition & 9 deletions pkg/phlaredb/head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,7 @@ func TestHead_Concurrent_Ingest_Querying(t *testing.T) {

}

// flusher
wg.Add(1)
go func() {
defer wg.Done()
<-time.After(100 * time.Millisecond)
t.Log("flushing")
require.NoError(t, head.Flush(ctx))
t.Log("flushed")
}()
// TODO: We need to test if flushing misses out on ingested profiles

wg.Wait()

Expand Down
9 changes: 9 additions & 0 deletions pkg/phlaredb/profile_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ func (s *profileStore) prepareFile(path string) (closer io.Closer, err error) {
return file, err
}

func (s *profileStore) empty() bool {
s.lock.RLock()
defer s.lock.RUnlock()
if len(s.slice) == 0 {
return true
}
return false
}

// cutRowGroups gets called, when a patrticular row group has been finished and it will flush it to disk. The caller of cutRowGroups should be holding the write lock.
// TODO: write row groups asynchronously
func (s *profileStore) cutRowGroup() (err error) {
Expand Down

0 comments on commit 960d100

Please sign in to comment.