fix(client): optimize bcache switch names and debug logs.#22814877

Signed-off-by: baihailong <baihailong@oppo.com>
This commit is contained in:
baihailong 2024-11-22 14:38:25 +08:00 committed by AmazingChi
parent 7b8801af4e
commit 2015d02b78
5 changed files with 20 additions and 15 deletions

View File

@ -230,7 +230,6 @@ func NewSuper(opt *proto.MountOptions) (s *Super, err error) {
ReadRate: opt.ReadRate,
WriteRate: opt.WriteRate,
BcacheEnable: opt.EnableBcache,
BcacheOnlyForCold: opt.BcacheOnlyForCold,
BcacheDir: opt.BcacheDir,
MaxStreamerLimit: opt.MaxStreamerLimit,
VerReadSeq: opt.VerReadSeq,
@ -252,7 +251,8 @@ func NewSuper(opt *proto.MountOptions) (s *Super, err error) {
VolCacheDpStorageClass: s.cacheDpStorageClass,
OnForbiddenMigration: s.mw.ForbiddenMigration,
OnGetInodeInfo: s.InodeGet,
OnGetInodeInfo: s.InodeGet,
BcacheOnlyForNotSSD: opt.BcacheOnlyForNotSSD,
}
s.ec, err = stream.NewExtentClient(extentConfig)

View File

@ -532,7 +532,7 @@ func main() {
defer super.Close()
syslog.Printf("enable bcache %v", opt.EnableBcache)
syslog.Printf("bcache only for cold %v", opt.BcacheOnlyForCold)
syslog.Printf("bcache only for not ssd %v", opt.BcacheOnlyForNotSSD)
if cfg.GetString(exporter.ConfigKeyPushAddr) == "" {
pushAddr, err := getPushAddrFromMaster(opt.Master)
@ -946,7 +946,7 @@ func parseMountOption(cfg *config.Config) (*proto.MountOptions, error) {
opt.EnableBcache = true
}
opt.BcacheOnlyForCold = GlobalMountOptions[proto.BcacheOnlyForCold].GetBool()
opt.BcacheOnlyForNotSSD = GlobalMountOptions[proto.BcacheOnlyForNotSSD].GetBool()
if opt.Rdonly {
verReadSeq := GlobalMountOptions[proto.SnapshotReadVerSeq].GetInt64()

View File

@ -78,7 +78,7 @@ const (
DisableMountSubtype
StreamRetryTimeOut
BufferChanSize
BcacheOnlyForCold
BcacheOnlyForNotSSD
MaxMountOption
)
@ -175,7 +175,7 @@ func InitMountOptions(opts []MountOption) {
opts[SnapshotReadVerSeq] = MountOption{"snapshotReadSeq", "Snapshot read seq", "", int64(0)} // default false
opts[DisableMountSubtype] = MountOption{"disableMountSubtype", "Disable Mount Subtype", "", false}
opts[StreamRetryTimeOut] = MountOption{"streamRetryTimeout", "max stream retry timeout, s", "", int64(0)}
opts[BcacheOnlyForCold] = MountOption{"enableBcacheOnlyForCold", "Enable block cache only for cold data", "", false}
opts[BcacheOnlyForNotSSD] = MountOption{"enableBcacheOnlyForNotSSD", "Enable block cache only for not ssd", "", false}
for i := 0; i < MaxMountOption; i++ {
flag.StringVar(&opts[i].cmdlineValue, opts[i].keyword, "", opts[i].description)
@ -318,7 +318,7 @@ type MountOptions struct {
CacheThreshold int
EbsBlockSize int
EnableBcache bool
BcacheOnlyForCold bool
BcacheOnlyForNotSSD bool
BcacheDir string
BcacheFilterFiles string
BcacheCheckIntervalS int64

View File

@ -129,7 +129,6 @@ type ExtentConfig struct {
ReadRate int64
WriteRate int64
BcacheEnable bool
BcacheOnlyForCold bool
BcacheDir string
MaxStreamerLimit int64
VerReadSeq uint64
@ -153,7 +152,8 @@ type ExtentConfig struct {
VolAllowedStorageClass []uint32
VolCacheDpStorageClass uint32
OnGetInodeInfo GetInodeInfoFunc
OnGetInodeInfo GetInodeInfoFunc
BcacheOnlyForNotSSD bool
}
type MultiVerMgr struct {
@ -176,7 +176,6 @@ type ExtentClient struct {
volumeType int
volumeName string
bcacheEnable bool
bcacheOnlyForCold bool
bcacheDir string
BcacheHealth bool
preload bool
@ -198,6 +197,7 @@ type ExtentClient struct {
forbiddenMigration ForbiddenMigrationFunc
CacheDpStorageClass uint32
getInodeInfo GetInodeInfoFunc
bcacheOnlyForNotSSD bool
}
func (client *ExtentClient) UidIsLimited(uid uint32) bool {
@ -315,7 +315,7 @@ retry:
client.evictBcache = config.OnEvictBcache
client.volumeName = config.Volume
client.bcacheEnable = config.BcacheEnable
client.bcacheOnlyForCold = config.BcacheOnlyForCold
client.bcacheOnlyForNotSSD = config.BcacheOnlyForNotSSD
client.bcacheDir = config.BcacheDir
client.multiVerMgr.verReadSeq = client.dataWrapper.GetReadVerSeq()
client.BcacheHealth = true

View File

@ -205,8 +205,8 @@ func (s *Streamer) read(data []byte, offset int, size int, storageClass uint32)
}
// skip hole,ek is not nil,read block cache firstly
log.LogDebugf("Stream read: ino(%v) req(%v) s.client.bcacheEnable(%v) s.client.bcacheOnlyForCold(%v) s.needBCache(%v)",
s.inode, req, s.client.bcacheEnable, s.client.bcacheOnlyForCold, s.needBCache)
log.LogDebugf("Stream read: ino(%v) req(%v) s.client.bcacheEnable(%v) s.client.bcacheOnlyForNotSSD(%v) s.needBCache(%v)",
s.inode, req, s.client.bcacheEnable, s.client.bcacheOnlyForNotSSD, s.needBCache)
cacheKey := util.GenerateRepVolKey(s.client.volumeName, s.inode, req.ExtentKey.PartitionId, req.ExtentKey.ExtentId, req.ExtentKey.FileOffset)
if s.client.bcacheEnable && s.needBCache && filesize <= bcache.MaxFileSize {
inodeInfo, err := s.client.getInodeInfo(s.inode)
@ -214,7 +214,9 @@ func (s *Streamer) read(data []byte, offset int, size int, storageClass uint32)
log.LogErrorf("Streamer read: getInodeInfo failed. ino(%v) req(%v) err(%v)", s.inode, req, err)
return 0, err
}
if !s.client.bcacheOnlyForCold || (s.client.bcacheOnlyForCold && inodeInfo.StorageClass != proto.StorageClass_Replica_SSD) {
if !s.client.bcacheOnlyForNotSSD || (s.client.bcacheOnlyForNotSSD && inodeInfo.StorageClass != proto.StorageClass_Replica_SSD) {
log.LogDebugf("Streamer read from bcache, ino(%v) storageClass(%v) s.client.bcacheEnable(%v) bcacheOnlyForNotSSD(%v)",
s.inode, proto.StorageClassString(inodeInfo.StorageClass), s.client.bcacheEnable, s.client.bcacheOnlyForNotSSD)
offset := req.FileOffset - int(req.ExtentKey.FileOffset)
if s.client.loadBcache != nil {
readBytes, err = s.client.loadBcache(cacheKey, req.Data, uint64(offset), uint32(req.Size))
@ -228,6 +230,9 @@ func (s *Streamer) read(data []byte, offset int, size int, storageClass uint32)
}
}
log.LogDebugf("TRACE Stream read. miss blockCache cacheKey(%v) loadBcache(%v)", cacheKey, s.client.loadBcache)
} else {
log.LogDebugf("Streamer not read from bcache, ino(%v) storageClass(%v) s.client.bcacheEnable(%v) bcacheOnlyForNotSSD(%v)",
s.inode, proto.StorageClassString(inodeInfo.StorageClass), s.client.bcacheEnable, s.client.bcacheOnlyForNotSSD)
}
}
@ -252,7 +257,7 @@ func (s *Streamer) read(data []byte, offset int, size int, storageClass uint32)
// limit big block cache
if s.exceedBlockSize(req.ExtentKey.Size) && atomic.LoadInt32(&s.client.inflightL1BigBlock) > 10 {
// do nothing
} else if !s.client.bcacheOnlyForCold || (s.client.bcacheOnlyForCold && inodeInfo.StorageClass != proto.StorageClass_Replica_SSD) {
} else if !s.client.bcacheOnlyForNotSSD || (s.client.bcacheOnlyForNotSSD && inodeInfo.StorageClass != proto.StorageClass_Replica_SSD) {
select {
case s.pendingCache <- bcacheKey{cacheKey: cacheKey, extentKey: req.ExtentKey, storageClass: storageClass}:
if s.exceedBlockSize(req.ExtentKey.Size) {