Skip to content

Commit

Permalink
config: move storage check after initializeTempDir (#16257) (#16462)
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored Apr 21, 2020
1 parent 6827a48 commit 5b3fcb7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
15 changes: 0 additions & 15 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/sys/storage"
tracing "github.com/uber/jaeger-client-go/config"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -868,20 +867,6 @@ func (c *Config) Valid() error {
}
}

// check capacity and the quota when OOMUseTmpStorage is enabled
if c.OOMUseTmpStorage {
if c.TempStorageQuota < 0 {
// means unlimited, do nothing
} else {
capacityByte, err := storage.GetTargetDirectoryCapacity(c.TempStoragePath)
if err != nil {
return err
} else if capacityByte > uint64(c.TempStorageQuota) {
return fmt.Errorf("value of [temp-storage-quota](%d byte) exceeds the capacity(%d byte) of the [%s] directory", c.TempStorageQuota, capacityByte, c.TempStoragePath)
}
}
}

// test log level
l := zap.NewAtomicLevel()
return l.UnmarshalText([]byte(c.Log.Level))
Expand Down
17 changes: 17 additions & 0 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import (
"github.com/pingcap/tidb/util/signal"
"github.com/pingcap/tidb/util/storeutil"
"github.com/pingcap/tidb/util/sys/linux"
storageSys "github.com/pingcap/tidb/util/sys/storage"
"github.com/pingcap/tidb/util/systimemon"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/push"
Expand Down Expand Up @@ -168,6 +169,7 @@ func main() {
if config.GetGlobalConfig().OOMUseTmpStorage {
config.GetGlobalConfig().UpdateTempStoragePath()
initializeTempDir()
checkTempStorageQuota()
}
setGlobalVars()
setCPUAffinity()
Expand Down Expand Up @@ -232,6 +234,21 @@ func initializeTempDir() {
}
}

func checkTempStorageQuota() {
// check capacity and the quota when OOMUseTmpStorage is enabled
c := config.GetGlobalConfig()
if c.TempStorageQuota < 0 {
// means unlimited, do nothing
} else {
capacityByte, err := storageSys.GetTargetDirectoryCapacity(c.TempStoragePath)
if err != nil {
log.Fatal(err.Error())
} else if capacityByte < uint64(c.TempStorageQuota) {
log.Fatal(fmt.Sprintf("value of [temp-storage-quota](%d byte) exceeds the capacity(%d byte) of the [%s] directory", c.TempStorageQuota, capacityByte, c.TempStoragePath))
}
}
}

func setCPUAffinity() {
if affinityCPU == nil || len(*affinityCPU) == 0 {
return
Expand Down

0 comments on commit 5b3fcb7

Please sign in to comment.