fix: ensure temp files removed on failed compaction (#26070) (#26071)

Add more robust temporary file removal
on a failed compaction. Don't halt on
a failed removal, and don't assume a
failed compaction won't generate
temporary files.

closes https://github.com/influxdata/influxdb/issues/26068

(cherry picked from commit ba95c9b0f0)

closes https://github.com/influxdata/influxdb/issues/26069
pull/26080/head
davidby-influx 2025-02-26 14:03:10 -08:00 committed by GitHub
parent 4689f21687
commit d169651dff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 6 deletions

View File

@ -1007,7 +1007,7 @@ func (c *Compactor) CompactFull(tsmFiles []string, logger *zap.Logger) ([]string
c.mu.RUnlock()
if !enabled {
if err := c.removeTmpFiles(files); err != nil {
if err := c.RemoveTmpFiles(files); err != nil {
return nil, err
}
return nil, errCompactionsDisabled
@ -1039,7 +1039,7 @@ func (c *Compactor) CompactFast(tsmFiles []string, logger *zap.Logger) ([]string
c.mu.RUnlock()
if !enabled {
if err := c.removeTmpFiles(files); err != nil {
if err := c.RemoveTmpFiles(files); err != nil {
return nil, err
}
return nil, errCompactionsDisabled
@ -1049,15 +1049,16 @@ func (c *Compactor) CompactFast(tsmFiles []string, logger *zap.Logger) ([]string
}
// removeTmpFiles is responsible for cleaning up a compaction that
// RemoveTmpFiles is responsible for cleaning up a compaction that
// was started, but then abandoned before the temporary files were dealt with.
func (c *Compactor) removeTmpFiles(files []string) error {
func (c *Compactor) RemoveTmpFiles(files []string) error {
var errs []error
for _, f := range files {
if err := os.Remove(f); err != nil {
return fmt.Errorf("error removing temp compaction file: %v", err)
errs = append(errs, fmt.Errorf("error removing temp compaction file %s: %w", f, err))
}
}
return nil
return errors.Join(errs...)
}
// writeNewFiles writes from the iterator into new TSM files, rotating

View File

@ -2224,6 +2224,11 @@ func (s *compactionStrategy) compactGroup() {
}
if err != nil {
defer func(fs []string) {
if removeErr := s.compactor.RemoveTmpFiles(fs); removeErr != nil {
log.Warn("Unable to remove temporary file(s)", zap.Error(removeErr))
}
}(files)
_, inProgress := err.(errCompactionInProgress)
if err == errCompactionsDisabled || inProgress {
log.Info("Aborted compaction", zap.Error(err))