Skip to content

Commit

Permalink
br: use atomic for failedFilesCount (#52046)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturmelanchyk authored Mar 25, 2024
1 parent b2a9a56 commit c3fa89a
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions br/pkg/checkpoint/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"math/rand"
"strings"
"sync"
"sync/atomic"
"time"

"github.com/pingcap/errors"
Expand Down Expand Up @@ -846,27 +847,18 @@ func removeCheckpointData(ctx context.Context, s storage.ExternalStorage, subDir
zap.Int64("remove-size", removeSize),
)

maxFailedFilesNum := 16
failedFilesCount := struct {
lock sync.Mutex
count int
}{
count: 0,
}
maxFailedFilesNum := int64(16)
var failedFilesCount atomic.Int64
pool := utils.NewWorkerPool(4, "checkpoint remove worker")
eg, gCtx := errgroup.WithContext(ctx)
for _, filename := range removedFileNames {
name := filename
pool.ApplyOnErrorGroup(eg, func() error {
if err := s.DeleteFile(gCtx, name); err != nil {
log.Warn("failed to remove the file", zap.String("filename", name), zap.Error(err))
failedFilesCount.lock.Lock()
failedFilesCount.count += 1
if failedFilesCount.count >= maxFailedFilesNum {
failedFilesCount.lock.Unlock()
if failedFilesCount.Add(1) >= maxFailedFilesNum {
return errors.Annotate(err, "failed to delete too many files")
}
failedFilesCount.lock.Unlock()
}
return nil
})
Expand Down

0 comments on commit c3fa89a

Please sign in to comment.