Skip to content

Commit

Permalink
ddl/ingest: prevent update disk usage too frequently (#44668)
Browse files Browse the repository at this point in the history
close #44584
  • Loading branch information
tangenta authored Jun 14, 2023
1 parent d1b4d03 commit abd9ff5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ddl/ingest/disk_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package ingest
import (
"fmt"
"sync"
"sync/atomic"

"github.com/pingcap/errors"
lcom "github.com/pingcap/tidb/br/pkg/lightning/common"
Expand Down Expand Up @@ -44,6 +45,7 @@ type diskRootImpl struct {
bcUsed uint64
bcCtx *litBackendCtxMgr
mu sync.RWMutex
updating atomic.Bool
}

// NewDiskRootImpl creates a new DiskRoot.
Expand All @@ -56,6 +58,9 @@ func NewDiskRootImpl(path string, bcCtx *litBackendCtxMgr) DiskRoot {

// UpdateUsage implements DiskRoot interface.
func (d *diskRootImpl) UpdateUsage() {
if !d.updating.CompareAndSwap(false, true) {
return
}
bcUsed := d.bcCtx.TotalDiskUsage()
var capacity, used uint64
sz, err := lcom.GetStorageSize(d.path)
Expand All @@ -64,6 +69,7 @@ func (d *diskRootImpl) UpdateUsage() {
} else {
capacity, used = sz.Capacity, sz.Capacity-sz.Available
}
d.updating.Store(false)
d.mu.Lock()
d.bcUsed = bcUsed
d.capacity = capacity
Expand Down

0 comments on commit abd9ff5

Please sign in to comment.