Skip to content

Commit

Permalink
fix(tsi1/partition/test): fix data races in test code (#57) (#25338)
Browse files Browse the repository at this point in the history
* fix(tsi1/partition/test): fix data races in test code (#57)

* fix(tsi1/partition/test): fix data races in test code

This PR is like #24613 but solves it with a setter
method for MaxLogFileSize which allows unexporting that value and
MaxLogFileAge. There are actually two places locks were needed in test
code. The behavior of production code is unchanged.

(cherry picked from commit f0235c4daf4b97769db932f7346c1d3aecf57f8f)

* feat: modify error handling to be more idiomatic

closes #24042

* fix: errors.Join() filters nil errors

closes #25341
---------

Co-authored-by: Phil Bracikowski <[email protected]>
(cherry picked from commit 5c9e45f)
  • Loading branch information
devanbenz committed Sep 17, 2024
1 parent 5a59938 commit f4af211
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions tsdb/index/tsi1/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ func NewPartition(sfile *tsdb.SeriesFile, path string) *Partition {
// Only for tests!
func (p *Partition) SetMaxLogFileSize(new int64) (old int64) {
p.mu.Lock()
old = p.maxLogFileSize
p.maxLogFileSize = new
old, p.maxLogFileSize = p.maxLogFileSize, new
p.mu.Unlock()
return old
}
Expand Down Expand Up @@ -357,7 +356,7 @@ func (p *Partition) CurrentCompactionN() int {
}

// Wait will block until all compactions are finished.
// must only be called while they are disabled.
// Must only be called while they are disabled.
func (p *Partition) Wait() {
ticker := time.NewTicker(10 * time.Millisecond)
defer ticker.Stop()
Expand Down Expand Up @@ -387,15 +386,14 @@ func (p *Partition) Close() error {
}

// Close log files.
var err error
var err []error
for _, f := range p.fileSet.files {
if localErr := f.Close(); localErr != nil {
err = localErr
}
localErr := f.Close()
err = append(err, localErr)
}
p.fileSet.files = nil

return err
return errors.Join(err...)
}

// closing returns true if the partition is currently closing. It does not require
Expand Down

0 comments on commit f4af211

Please sign in to comment.