From abd9ff5ca6fe866224f243c931844f050fb4952c Mon Sep 17 00:00:00 2001 From: tangenta Date: Wed, 14 Jun 2023 16:37:08 +0800 Subject: [PATCH] ddl/ingest: prevent update disk usage too frequently (#44668) close pingcap/tidb#44584 --- ddl/ingest/disk_root.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ddl/ingest/disk_root.go b/ddl/ingest/disk_root.go index a1f8881970e4e..dcbb9a38d3c2e 100644 --- a/ddl/ingest/disk_root.go +++ b/ddl/ingest/disk_root.go @@ -17,6 +17,7 @@ package ingest import ( "fmt" "sync" + "sync/atomic" "github.com/pingcap/errors" lcom "github.com/pingcap/tidb/br/pkg/lightning/common" @@ -44,6 +45,7 @@ type diskRootImpl struct { bcUsed uint64 bcCtx *litBackendCtxMgr mu sync.RWMutex + updating atomic.Bool } // NewDiskRootImpl creates a new DiskRoot. @@ -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) @@ -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