mirror of
https://github.com/cubefs/cubefs.git
synced 2026-08-02 02:00:56 +00:00
fix(flashnode): modify the name of the cache size and ratio configuration item.
close:#22963423 Signed-off-by: shuqiang-zheng <zhengshuqiang@oppo.com>
This commit is contained in:
parent
f883980012
commit
ca2eb33605
@ -171,18 +171,21 @@ func showFlashNodesView(flashNodeViewInfos []*proto.FlashNodeViewInfo, showStat
|
||||
continue
|
||||
}
|
||||
|
||||
hitRate, evicts, limit := "N/A", "N/A", "N/A"
|
||||
hitRate, evicts, limit, maxAlloc, hasAlloc, num := "N/A", "N/A", "N/A", "N/A", "N/A", "N/A"
|
||||
if fn.IsActive && fn.IsEnable {
|
||||
if stat, e := client.Addr(addr2Prof(fn.Addr)).FlashNode().Stat(); e == nil {
|
||||
hitRate = fmt.Sprintf("%.2f%%", stat.CacheStatus.HitRate*100)
|
||||
evicts = strconv.Itoa(stat.CacheStatus.Evicts)
|
||||
limit = strconv.FormatUint(stat.NodeLimit, 10)
|
||||
maxAlloc = strconv.FormatInt(stat.CacheStatus.MaxAlloc, 10)
|
||||
hasAlloc = strconv.FormatInt(stat.CacheStatus.HasAlloc, 10)
|
||||
num = strconv.Itoa(stat.CacheStatus.Num)
|
||||
} else {
|
||||
stdoutln(e)
|
||||
}
|
||||
}
|
||||
tbl = tbl.append(arow(fn.ZoneName, fn.ID, fn.Addr, formatYesNo(fn.IsActive), formatYesNo(fn.IsEnable),
|
||||
fn.FlashGroupID, formatTimeToString(fn.ReportTime), hitRate, evicts, limit))
|
||||
fn.FlashGroupID, formatTimeToString(fn.ReportTime), hitRate, evicts, limit, maxAlloc, hasAlloc, num))
|
||||
}
|
||||
return tbl
|
||||
}
|
||||
|
||||
@ -1285,7 +1285,7 @@ var (
|
||||
hybridCloudStorageTableHeader = fmt.Sprintf(hybridCloudStorageTablePattern,
|
||||
"STORAGE CLASS", "INODE COUNT", "USED SIZE", "QUOTA")
|
||||
formatFlashNodeSimpleViewTableTitle = arow("Zone", "ID", "Address", "Active", "Enable", "FlashGroupID", "ReportTime")
|
||||
formatFlashNodeViewTableTitle = append(formatFlashNodeSimpleViewTableTitle[:], "HitRate", "Evicts", "Limit")
|
||||
formatFlashNodeViewTableTitle = append(formatFlashNodeSimpleViewTableTitle[:], "HitRate", "Evicts", "Limit", "MaxAlloc", "HasAlloc", "Num")
|
||||
formatFlashGroupViewTile = arow("ID", "Weight", "Slots", "Status", "FlashNodeCount")
|
||||
)
|
||||
|
||||
|
||||
@ -114,15 +114,6 @@ func NewCacheEngine(dataDir string, totalSize int64, maxUseRatio float64,
|
||||
s.readSourceFunc = readFunc
|
||||
s.closeCh = make(chan struct{})
|
||||
|
||||
if _, err = os.Stat(dataDir); err != nil {
|
||||
if !os.IsNotExist(err.(*os.PathError)) {
|
||||
return nil, fmt.Errorf("stat tmpfs directory failed: %s", err.Error())
|
||||
}
|
||||
if err = os.MkdirAll(dataDir, 0o755); err != nil {
|
||||
return nil, fmt.Errorf("NewCacheEngine [%v] err[%v]", dataDir, err)
|
||||
}
|
||||
}
|
||||
|
||||
if s.enableTmpfs {
|
||||
log.LogInfof("CacheEngine enableTmpfs, doMount.")
|
||||
if err = s.doMount(); err != nil {
|
||||
|
||||
@ -17,6 +17,7 @@ package cachengine
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
@ -41,6 +42,12 @@ func randTestData(size int) (data []byte) {
|
||||
}
|
||||
|
||||
func TestEngineNew(t *testing.T) {
|
||||
if _, err := os.Stat(testTmpFS); err != nil {
|
||||
require.Equal(t, true, os.IsNotExist(err.(*os.PathError)))
|
||||
err = os.MkdirAll(testTmpFS, 0o755)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
ce, err := NewCacheEngine(testTmpFS, 200*util.MB, DefaultCacheMaxUsedRatio, 1024, 1024, proto.DefaultCacheTTLSec, DefaultExpireTime, nil, enabledTmpfs())
|
||||
require.NoError(t, err)
|
||||
defer func() { require.NoError(t, ce.Stop()) }()
|
||||
@ -52,6 +59,12 @@ func TestEngineNew(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEngineOverFlow(t *testing.T) {
|
||||
if _, err := os.Stat(testTmpFS); err != nil {
|
||||
require.Equal(t, true, os.IsNotExist(err.(*os.PathError)))
|
||||
err = os.MkdirAll(testTmpFS, 0o755)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
ce, err := NewCacheEngine(testTmpFS, util.GB, 1.1, 1024, 1024, proto.DefaultCacheTTLSec, DefaultExpireTime, nil, enabledTmpfs())
|
||||
require.NoError(t, err)
|
||||
defer func() { require.NoError(t, ce.Stop()) }()
|
||||
@ -111,6 +124,12 @@ func TestEngineOverFlow(t *testing.T) {
|
||||
func TestEngineTTL(t *testing.T) {
|
||||
lruCap := 10
|
||||
inode, fixedOffset, version := uint64(1), uint64(1024), uint32(112358796)
|
||||
if _, err := os.Stat(testTmpFS); err != nil {
|
||||
require.Equal(t, true, os.IsNotExist(err.(*os.PathError)))
|
||||
err = os.MkdirAll(testTmpFS, 0o755)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
ce, err := NewCacheEngine(testTmpFS, util.GB, DefaultCacheMaxUsedRatio, lruCap, lruCap, proto.DefaultCacheTTLSec, DefaultExpireTime, nil, enabledTmpfs())
|
||||
require.NoError(t, err)
|
||||
defer func() { require.NoError(t, ce.Stop()) }()
|
||||
@ -149,6 +168,12 @@ func TestEngineTTL(t *testing.T) {
|
||||
|
||||
func TestEngineLru(t *testing.T) {
|
||||
lruCap := 10
|
||||
if _, err := os.Stat(testTmpFS); err != nil {
|
||||
require.Equal(t, true, os.IsNotExist(err.(*os.PathError)))
|
||||
err = os.MkdirAll(testTmpFS, 0o755)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
ce, err := NewCacheEngine(testTmpFS, util.GB, DefaultCacheMaxUsedRatio, lruCap, lruCap, proto.DefaultCacheTTLSec, DefaultExpireTime, nil, enabledTmpfs())
|
||||
require.NoError(t, err)
|
||||
ce.Start()
|
||||
|
||||
@ -17,8 +17,10 @@ package flashnode
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
@ -57,8 +59,8 @@ const (
|
||||
const (
|
||||
LogDir = "logDir"
|
||||
Stat = "stat"
|
||||
cfgMemTotal = "memTotal"
|
||||
cfgMemPercent = "memPercent"
|
||||
cfgCacheTotal = "cacheTotal"
|
||||
cfgCachePercent = "cachePercent"
|
||||
cfgLruCapacity = "lruCapacity"
|
||||
cfgLruFhCapacity = "lruFileHandleCapacity"
|
||||
cfgLoadCacheBlockTTL = "loadCacheBlockTTL"
|
||||
@ -147,9 +149,7 @@ func (f *FlashNode) start(cfg *config.Config) (err error) {
|
||||
return
|
||||
}
|
||||
f.stopCh = make(chan struct{})
|
||||
if f.dataPath == "" {
|
||||
f.dataPath = DefaultDataPath
|
||||
}
|
||||
|
||||
if err = f.register(); err != nil {
|
||||
return
|
||||
}
|
||||
@ -200,22 +200,46 @@ func (f *FlashNode) parseConfig(cfg *config.Config) (err error) {
|
||||
f.readRps = _defaultReadBurst
|
||||
}
|
||||
|
||||
mem := cfg.GetInt64(cfgMemTotal)
|
||||
if mem <= 0 {
|
||||
percent := cfg.GetFloat(cfgMemPercent)
|
||||
f.enableTmpfs = !cfg.GetBool(cfgDisableTmpfs)
|
||||
f.dataPath = cfg.GetString(cfgDataPath)
|
||||
if f.dataPath == "" {
|
||||
f.dataPath = DefaultDataPath
|
||||
}
|
||||
if _, err = os.Stat(f.dataPath); err != nil {
|
||||
if !os.IsNotExist(err.(*os.PathError)) {
|
||||
return errors.NewErrorf("stat cache directory failed: %s", err.Error())
|
||||
}
|
||||
if err = os.MkdirAll(f.dataPath, 0o755); err != nil {
|
||||
return errors.NewErrorf("mkdir cache directory [%v] err[%v]", f.dataPath, err)
|
||||
}
|
||||
}
|
||||
cacheTotal := cfg.GetInt64(cfgCacheTotal)
|
||||
if cacheTotal <= 0 {
|
||||
percent := cfg.GetFloat(cfgCachePercent)
|
||||
if percent <= 1e-2 || percent > 0.8 {
|
||||
return errors.NewErrorf("recommended to physical memory %s=0.8 %.2f", cfgMemPercent, percent)
|
||||
return errors.NewErrorf("recommended to physical memory %s=0.8 %.2f", cfgCachePercent, percent)
|
||||
}
|
||||
total, _, err := util.GetMemInfo()
|
||||
if err != nil {
|
||||
return errors.NewErrorf("get physical memory %v", err)
|
||||
if f.enableTmpfs {
|
||||
total, _, err := util.GetMemInfo()
|
||||
if err != nil {
|
||||
return errors.NewErrorf("get physical memory %v", err)
|
||||
}
|
||||
cacheTotal = int64(float64(total) * percent)
|
||||
} else {
|
||||
stat := syscall.Statfs_t{}
|
||||
err := syscall.Statfs(f.dataPath, &stat)
|
||||
if err != nil {
|
||||
return errors.NewErrorf("get disk size, err:%v", err)
|
||||
}
|
||||
total := int64(stat.Blocks) * int64(stat.Bsize)
|
||||
cacheTotal = int64(float64(total) * percent)
|
||||
}
|
||||
mem = int64(float64(total) * percent)
|
||||
}
|
||||
if mem < 32*(1<<20) {
|
||||
return errors.NewErrorf("low physical memory %d", mem)
|
||||
if cacheTotal < 32*(1<<20) {
|
||||
return errors.NewErrorf("low physical cacheSpace %d", cacheTotal)
|
||||
}
|
||||
f.total = uint64(mem)
|
||||
|
||||
f.total = uint64(cacheTotal)
|
||||
lruCapacity := cfg.GetInt(cfgLruCapacity)
|
||||
if lruCapacity <= 0 {
|
||||
lruCapacity = _defaultLRUCapacity
|
||||
@ -232,8 +256,6 @@ func (f *FlashNode) parseConfig(cfg *config.Config) (err error) {
|
||||
}
|
||||
f.loadCacheBlockTTL = loadCacheBlockTTL
|
||||
f.lowerHitRate = cfg.GetFloat(cfgLowerHitRate)
|
||||
f.enableTmpfs = !cfg.GetBool(cfgDisableTmpfs)
|
||||
f.dataPath = cfg.GetString(cfgDataPath)
|
||||
|
||||
log.LogInfof("[parseConfig] load listen[%s].", f.listen)
|
||||
log.LogInfof("[parseConfig] load zoneName[%s].", f.zoneName)
|
||||
|
||||
@ -127,9 +127,9 @@ func testConfig(t *testing.T) {
|
||||
for _, lines := range [][]string{
|
||||
{fmt.Sprintf("\"listen\":\"%d\"", flashPort), `"listen":""`, `"listen":" "`},
|
||||
{`"zoneName":"zone",`, `"zoneName":"",`},
|
||||
{`"readRps":0,`, `"readRps":-1,"memPercent":0.001,`},
|
||||
{``, `"memPercent":0.9,`, `"memPercent":0.001,`},
|
||||
{`"memPercent":0.2,`, `"memTotal":1024,`},
|
||||
{`"readRps":0,`, `"readRps":-1,"cachePercent":0.001,`},
|
||||
{``, `"cachePercent":0.9,`, `"cachePercent":0.001,`},
|
||||
{`"cachePercent":0.2,`, `"cacheTotal":1024,`},
|
||||
{`"disableTmpfs": true,`},
|
||||
{fmt.Sprintf("\"masterAddr\":[\"%s\"],", masterAddr), `"masterAddr":[],`},
|
||||
} {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user