feat(flashnode): modify the upper limit of cachePercent and the defaultMaxUseRatio of lru.

close:#23080181

Signed-off-by: shuqiang-zheng <zhengshuqiang@oppo.com>
This commit is contained in:
shuqiang-zheng 2025-02-27 15:48:48 +08:00 committed by zhumingze1108
parent f2d2a663a6
commit 3cdea7d89f
3 changed files with 43 additions and 11 deletions

View File

@ -29,6 +29,8 @@ import (
"syscall"
"time"
"github.com/cubefs/cubefs/util/auditlog"
"github.com/cubefs/cubefs/sdk/master"
"github.com/cubefs/cubefs/util/atomicutil"
@ -45,7 +47,7 @@ const (
DefaultExpireTime = 60 * 60
InitFileName = "flash.init"
DefaultCacheDirName = "cache"
DefaultCacheMaxUsedRatio = 0.9
DefaultCacheMaxUsedRatio = 0.95
DefaultEnableTmpfs = true
LRUCacheBlockCacheType = 0
@ -171,11 +173,6 @@ func NewCacheEngine(memDataDir string, totalMemSize int64, maxUseRatio float64,
return file.Close()
})
log.LogInfof("CacheEngine enableTmpfs, doMount.")
if err = s.doMount(); err != nil {
return
}
if _, err = os.Stat(fullPath); err != nil {
if !os.IsNotExist(err.(*os.PathError)) {
return
@ -187,6 +184,11 @@ func NewCacheEngine(memDataDir string, totalMemSize int64, maxUseRatio float64,
}
}
log.LogInfof("CacheEngine enableTmpfs, doMount.")
if err = s.doMount(); err != nil {
return
}
return
}
@ -874,9 +876,10 @@ func (c *CacheEngine) DoInactiveDisk(dataPath string) {
}
func (c *CacheEngine) doInactiveFlashNode() (err error) {
msg := fmt.Sprintf("do inactive flashnode(%v)", c.localAddr)
log.LogWarnf(msg)
return c.mc.NodeAPI().SetFlashNode(c.localAddr, false)
err = c.mc.NodeAPI().SetFlashNode(c.localAddr, false)
log.LogWarnf("do inactive flashNode(%v), err(%v)", c.localAddr, err)
auditlog.LogFlashNodeOp("DoInactiveFlashNode", fmt.Sprintf("do inactive flashnode(%v)", c.localAddr), err)
return
}
func (c *CacheEngine) triggerCacheError(key string, dataPath string) {

View File

@ -206,8 +206,8 @@ func (f *FlashNode) parseConfig(cfg *config.Config) (err error) {
f.enableTmpfs = !cfg.GetBool(cfgDisableTmpfs)
percent := cfg.GetFloat(cfgCachePercent)
if percent <= 1e-2 || percent > 0.8 {
return errors.NewErrorf("recommended to physical memory %s=0.8 %.2f", cfgCachePercent, percent)
if percent <= 1e-2 || percent > 1.0 {
percent = 1.0
}
lruCapacity := cfg.GetInt(cfgLruCapacity)
if lruCapacity <= 0 {

View File

@ -785,6 +785,15 @@ func LogDataNodeOp(op, msg string, err error) {
gAdt.formatDataNodeLog(op, msg, err)
}
func LogFlashNodeOp(op, msg string, err error) {
gAdtMutex.RLock()
defer gAdtMutex.RUnlock()
if gAdt == nil {
return
}
gAdt.formatFlashNodeLog(op, msg, err)
}
func (a *Audit) formatDataNodeLog(op, msg string, err error) {
if entry := a.formatDataNodeAudit(op, msg, err); entry != "" {
if a.prefix != nil {
@ -804,3 +813,23 @@ func (a *Audit) formatDataNodeAudit(op, msg string, err error) (str string) {
str = fmt.Sprintf("%v, %v, %v, ERR: %v", a.formatCommonHeader(), op, msg, errStr)
return
}
func (a *Audit) formatFlashNodeLog(op, msg string, err error) {
if entry := a.formatFlashNodeAudit(op, msg, err); entry != "" {
if a.prefix != nil {
entry = fmt.Sprintf("%s%s", a.prefix.String(), entry)
}
a.AddLog(entry)
}
}
func (a *Audit) formatFlashNodeAudit(op, msg string, err error) (str string) {
var errStr string
if err != nil {
errStr = err.Error()
} else {
errStr = "nil"
}
str = fmt.Sprintf("%v, %v, %v, ERR: %v", a.formatCommonHeader(), op, msg, errStr)
return
}