Skip to content

Commit

Permalink
Cleanup failed segment before flushing. (#2606)
Browse files Browse the repository at this point in the history
* Cleanup failed segment before flushing a new one.

* Do not create a segment if there's no profile to flush

* Uses a temp dir for the test to avoid left-over.

* remove unrelated change

* Update pkg/phlaredb/profile_store.go

Co-authored-by: Christian Simon <simon@swine.de>

---------

Co-authored-by: Christian Simon <simon@swine.de>
  • Loading branch information
cyriltovena and simonswine committed Oct 30, 2023
1 parent 58df86d commit e572d26
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/phlaredb/profile_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ func (s *profileStore) cutRowGroup(count int) (err error) {
s.path,
fmt.Sprintf("%s.%d%s", s.persister.Name(), s.rowsFlushed, block.ParquetSuffix),
)

// Removes the file if it exists. This can happen if the previous
// cut attempt failed.
if err := os.Remove(path); err == nil {
level.Warn(s.logger).Log("msg", "deleting row group segment of a failed previous attempt", "path", path)
}
f, err := s.prepareFile(path)
if err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions pkg/phlaredb/profile_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,15 @@ func TestProfileStore_Querying(t *testing.T) {
)
})
}

func TestRemoveFailedSegment(t *testing.T) {
store := newProfileStore(testContext(t))
dir := t.TempDir()
require.NoError(t, store.Init(dir, defaultParquetConfig, contextHeadMetrics(context.Background())))
// fake a failed segment
_, err := os.Create(dir + "/profiles.0.parquet")
require.NoError(t, store.ingest(context.Background(), []schemav1.InMemoryProfile{{}}, phlaremodel.LabelsFromStrings(), "memory"))
require.NoError(t, err)
err = store.cutRowGroup(1)
require.NoError(t, err)
}

0 comments on commit e572d26

Please sign in to comment.