Skip to content

Commit f7d5db2

Browse files
authored
ddl/ingest: add mutex to disk root (#41029)
close #40970
1 parent ddd0810 commit f7d5db2

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

ddl/ingest/disk_root.go

+17-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package ingest
1616

1717
import (
18+
"sync"
19+
1820
lcom "github.com/pingcap/tidb/br/pkg/lightning/common"
1921
"github.com/pingcap/tidb/sessionctx/variable"
2022
"github.com/pingcap/tidb/util/logutil"
@@ -37,6 +39,7 @@ type diskRootImpl struct {
3739
currentUsage uint64
3840
maxQuota uint64
3941
bcCtx *backendCtxManager
42+
mu sync.RWMutex
4043
}
4144

4245
// NewDiskRootImpl creates a new DiskRoot.
@@ -49,22 +52,32 @@ func NewDiskRootImpl(path string, bcCtx *backendCtxManager) DiskRoot {
4952

5053
// CurrentUsage implements DiskRoot interface.
5154
func (d *diskRootImpl) CurrentUsage() uint64 {
52-
return d.currentUsage
55+
d.mu.RLock()
56+
usage := d.currentUsage
57+
d.mu.RUnlock()
58+
return usage
5359
}
5460

5561
// MaxQuota implements DiskRoot interface.
5662
func (d *diskRootImpl) MaxQuota() uint64 {
57-
return d.maxQuota
63+
d.mu.RLock()
64+
quota := d.maxQuota
65+
d.mu.RUnlock()
66+
return quota
5867
}
5968

6069
// UpdateUsageAndQuota implements DiskRoot interface.
6170
func (d *diskRootImpl) UpdateUsageAndQuota() error {
62-
d.currentUsage = d.bcCtx.TotalDiskUsage()
71+
totalDiskUsage := d.bcCtx.TotalDiskUsage()
6372
sz, err := lcom.GetStorageSize(d.path)
6473
if err != nil {
6574
logutil.BgLogger().Error(LitErrGetStorageQuota, zap.Error(err))
6675
return err
6776
}
68-
d.maxQuota = mathutil.Min(variable.DDLDiskQuota.Load(), uint64(capacityThreshold*float64(sz.Capacity)))
77+
maxQuota := mathutil.Min(variable.DDLDiskQuota.Load(), uint64(capacityThreshold*float64(sz.Capacity)))
78+
d.mu.Lock()
79+
d.currentUsage = totalDiskUsage
80+
d.maxQuota = maxQuota
81+
d.mu.Unlock()
6982
return nil
7083
}

0 commit comments

Comments
 (0)