Skip to content

Commit

Permalink
ddl/ingest: add mutex to disk root (#41029) (#41030)
Browse files Browse the repository at this point in the history
close #40970
  • Loading branch information
ti-chi-bot authored Feb 3, 2023
1 parent 66b3ac8 commit cae26b3
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions ddl/ingest/disk_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
package ingest

import (
"github.com/pingcap/errors"
"sync"

lcom "github.com/pingcap/tidb/br/pkg/lightning/common"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/util/logutil"
Expand All @@ -38,6 +39,7 @@ type diskRootImpl struct {
currentUsage uint64
maxQuota uint64
bcCtx *backendCtxManager
mu sync.RWMutex
}

// NewDiskRootImpl creates a new DiskRoot.
Expand All @@ -50,22 +52,32 @@ func NewDiskRootImpl(path string, bcCtx *backendCtxManager) DiskRoot {

// CurrentUsage implements DiskRoot interface.
func (d *diskRootImpl) CurrentUsage() uint64 {
return d.currentUsage
d.mu.RLock()
usage := d.currentUsage
d.mu.RUnlock()
return usage
}

// MaxQuota implements DiskRoot interface.
func (d *diskRootImpl) MaxQuota() uint64 {
return d.maxQuota
d.mu.RLock()
quota := d.maxQuota
d.mu.RUnlock()
return quota
}

// UpdateUsageAndQuota implements DiskRoot interface.
func (d *diskRootImpl) UpdateUsageAndQuota() error {
d.currentUsage = d.bcCtx.TotalDiskUsage()
totalDiskUsage := d.bcCtx.TotalDiskUsage()
sz, err := lcom.GetStorageSize(d.path)
if err != nil {
logutil.BgLogger().Error(LitErrGetStorageQuota, zap.Error(err))
return errors.New(LitErrGetStorageQuota)
return err
}
d.maxQuota = mathutil.Min(variable.DDLDiskQuota.Load(), uint64(capacityThreshold*float64(sz.Capacity)))
maxQuota := mathutil.Min(variable.DDLDiskQuota.Load(), uint64(capacityThreshold*float64(sz.Capacity)))
d.mu.Lock()
d.currentUsage = totalDiskUsage
d.maxQuota = maxQuota
d.mu.Unlock()
return nil
}

0 comments on commit cae26b3

Please sign in to comment.