-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: fully clean up partially opened TSI #23430
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"github.com/influxdata/influxdb/tsdb" | ||
"github.com/influxdata/influxql" | ||
"go.uber.org/zap" | ||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
// IndexName is the name of the index. | ||
|
@@ -252,7 +253,7 @@ func (i *Index) SeriesIDSet() *tsdb.SeriesIDSet { | |
} | ||
|
||
// Open opens the index. | ||
func (i *Index) Open() error { | ||
func (i *Index) Open() (rErr error) { | ||
i.mu.Lock() | ||
defer i.mu.Unlock() | ||
|
||
|
@@ -277,33 +278,21 @@ func (i *Index) Open() error { | |
i.partitions[j] = p | ||
} | ||
|
||
defer i.cleanUpFail(&rErr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we want to defer this only after the As I understand it, the partition type assumes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix pushed. |
||
|
||
// Open all the Partitions in parallel. | ||
partitionN := len(i.partitions) | ||
n := i.availableThreads() | ||
|
||
// Store results. | ||
errC := make(chan error, partitionN) | ||
|
||
// Run fn on each partition using a fixed number of goroutines. | ||
var pidx uint32 // Index of maximum Partition being worked on. | ||
for k := 0; k < n; k++ { | ||
go func(k int) { | ||
for { | ||
idx := int(atomic.AddUint32(&pidx, 1) - 1) // Get next partition to work on. | ||
if idx >= partitionN { | ||
return // No more work. | ||
} | ||
err := i.partitions[idx].Open() | ||
errC <- err | ||
} | ||
}(k) | ||
g := new(errgroup.Group) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't fully agree (edit: with the linked article) but it is nice to use the pattern where it fits. |
||
g.SetLimit(n) | ||
for idx := 0; idx < partitionN; idx++ { | ||
g.Go(i.partitions[idx].Open) | ||
} | ||
|
||
// Check for error | ||
for i := 0; i < partitionN; i++ { | ||
if err := <-errC; err != nil { | ||
return err | ||
} | ||
err := g.Wait() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Refresh cached sketches. | ||
|
@@ -319,6 +308,18 @@ func (i *Index) Open() error { | |
return nil | ||
} | ||
|
||
func (i *Index) cleanUpFail(err *error) { | ||
if nil != *err { | ||
for _, p := range i.partitions { | ||
if (p != nil) && p.IsOpen() { | ||
if e := p.Close(); e != nil { | ||
i.logger.Warn("Failed to clean up partition") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Compact requests a compaction of partitions. | ||
func (i *Index) Compact() { | ||
i.mu.Lock() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍