Skip to content

Commit

Permalink
add start up check for disk quota
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta committed Apr 20, 2023
1 parent a755259 commit 31db2ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ddl/ingest/backend_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ func newLitBackendCtxMgr(path string, memQuota uint64) BackendCtxMgr {
LitMemRoot = mgr.memRoot
LitDiskRoot = mgr.diskRoot
LitDiskRoot.UpdateUsage()
err := LitDiskRoot.StartupCheck()
if err != nil {
logutil.BgLogger().Warn("[ddl-ingest] ingest backfill may not be available", zap.Error(err))
}
return mgr
}

Expand Down
16 changes: 16 additions & 0 deletions ddl/ingest/disk_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type DiskRoot interface {
ShouldImport() bool
UsageInfo() string
PreCheckUsage() error
StartupCheck() error
}

const capacityThreshold = 0.9
Expand Down Expand Up @@ -103,6 +104,21 @@ func (d *diskRootImpl) PreCheckUsage() error {
return nil
}

// StartupCheck implements DiskRoot interface.
func (d *diskRootImpl) StartupCheck() error {
sz, err := lcom.GetStorageSize(d.path)
if err != nil {
return errors.Trace(err)
}
quota := variable.DDLDiskQuota.Load()
if sz.Available < quota {
sortPath := ConfigSortPath()
return errors.Errorf("the available disk space(%d) in %s should be greater than @@tidb_ddl_disk_quota(%d)",
sz.Available, sortPath, quota)
}
return nil
}

// RiskOfDiskFull checks if the disk has less than 10% space.
func RiskOfDiskFull(available, capacity uint64) bool {
return float64(available) < (1-capacityThreshold)*float64(capacity)
Expand Down

0 comments on commit 31db2ff

Please sign in to comment.