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
parent
4689f21687
commit
d169651dff
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue