Skip to content

Commit 75a7327

Browse files
tangentati-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#41029
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
1 parent 66b3ac8 commit 75a7327

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

ddl/ingest/disk_root.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
package ingest
1616

1717
import (
18+
<<<<<<< HEAD
1819
"github.com/pingcap/errors"
20+
=======
21+
"sync"
22+
23+
>>>>>>> f7d5db24b3 (ddl/ingest: add mutex to disk root (#41029))
1924
lcom "github.com/pingcap/tidb/br/pkg/lightning/common"
2025
"github.com/pingcap/tidb/sessionctx/variable"
2126
"github.com/pingcap/tidb/util/logutil"
@@ -38,6 +43,7 @@ type diskRootImpl struct {
3843
currentUsage uint64
3944
maxQuota uint64
4045
bcCtx *backendCtxManager
46+
mu sync.RWMutex
4147
}
4248

4349
// NewDiskRootImpl creates a new DiskRoot.
@@ -50,22 +56,32 @@ func NewDiskRootImpl(path string, bcCtx *backendCtxManager) DiskRoot {
5056

5157
// CurrentUsage implements DiskRoot interface.
5258
func (d *diskRootImpl) CurrentUsage() uint64 {
53-
return d.currentUsage
59+
d.mu.RLock()
60+
usage := d.currentUsage
61+
d.mu.RUnlock()
62+
return usage
5463
}
5564

5665
// MaxQuota implements DiskRoot interface.
5766
func (d *diskRootImpl) MaxQuota() uint64 {
58-
return d.maxQuota
67+
d.mu.RLock()
68+
quota := d.maxQuota
69+
d.mu.RUnlock()
70+
return quota
5971
}
6072

6173
// UpdateUsageAndQuota implements DiskRoot interface.
6274
func (d *diskRootImpl) UpdateUsageAndQuota() error {
63-
d.currentUsage = d.bcCtx.TotalDiskUsage()
75+
totalDiskUsage := d.bcCtx.TotalDiskUsage()
6476
sz, err := lcom.GetStorageSize(d.path)
6577
if err != nil {
6678
logutil.BgLogger().Error(LitErrGetStorageQuota, zap.Error(err))
6779
return errors.New(LitErrGetStorageQuota)
6880
}
69-
d.maxQuota = mathutil.Min(variable.DDLDiskQuota.Load(), uint64(capacityThreshold*float64(sz.Capacity)))
81+
maxQuota := mathutil.Min(variable.DDLDiskQuota.Load(), uint64(capacityThreshold*float64(sz.Capacity)))
82+
d.mu.Lock()
83+
d.currentUsage = totalDiskUsage
84+
d.maxQuota = maxQuota
85+
d.mu.Unlock()
7086
return nil
7187
}

0 commit comments

Comments
 (0)