From 03ae1861c70fffa5df8f3d231bc53e94271d885f Mon Sep 17 00:00:00 2001 From: clinx Date: Thu, 16 Oct 2025 17:07:44 +0800 Subject: [PATCH] feat(falsh): check file size limits for warm up task with: #1000383519 Signed-off-by: clinx --- master/flash_node.go | 14 +++++++++----- proto/distributed_cache.go | 2 ++ remotecache/flashnode/manual_scanner.go | 11 +++++++++++ remotecache/flashnode/serve_http.go | 9 +++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/master/flash_node.go b/master/flash_node.go index 80ff26293..1d1a9949a 100644 --- a/master/flash_node.go +++ b/master/flash_node.go @@ -278,17 +278,21 @@ func (m *Server) createFlashNodeManualTask(w http.ResponseWriter, r *http.Reques sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()}) return } + + // Validate file size limits + if req.ManualTaskConfig.MinFileSizeLimit > req.ManualTaskConfig.MaxFileSizeLimit { + err = fmt.Errorf("MinFileSizeLimit(%d) cannot be greater than MaxFileSizeLimit(%d)", + req.ManualTaskConfig.MinFileSizeLimit, req.ManualTaskConfig.MaxFileSizeLimit) + sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()}) + return + } + var vol *Vol if vol, err = m.cluster.getVol(req.VolName); err != nil { sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeVolNotExists, Msg: err.Error()}) return } - if !vol.remoteCacheEnable { - err = fmt.Errorf("distribute cache of vol[%v] unavailable", vol.Name) - sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeInvalidCfg, Msg: err.Error()}) - return - } if m.cluster.flashNodeTopo == nil || !m.cluster.flashNodeTopo.CheckForActiveNode() { err = fmt.Errorf("no available distributed cache nodes") sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeInvalidCfg, Msg: err.Error()}) diff --git a/proto/distributed_cache.go b/proto/distributed_cache.go index e3578ab1b..6175d5380 100644 --- a/proto/distributed_cache.go +++ b/proto/distributed_cache.go @@ -520,6 +520,8 @@ type ManualTaskConfig struct { TraverseFileConcurrency int HandlerFileConcurrency int TotalFileSizeLimit int64 + MinFileSizeLimit int64 + MaxFileSizeLimit int64 } type ManualTaskStatistics struct { diff --git a/remotecache/flashnode/manual_scanner.go b/remotecache/flashnode/manual_scanner.go index 68fb6f374..454813838 100644 --- a/remotecache/flashnode/manual_scanner.go +++ b/remotecache/flashnode/manual_scanner.go @@ -308,6 +308,17 @@ func (s *ManualScanner) warmUp(i *proto.ScanItem) error { log.LogInfof("skip warmUp, size=0, inode(%v)", i.Inode) return nil } + + // Check file size limits + config := s.manualTask.ManualTaskConfig + if config.MinFileSizeLimit > 0 && int64(i.Size) < config.MinFileSizeLimit { + log.LogInfof("skip warmUp, file size(%d) below MinFileSizeLimit(%d), inode(%v)", i.Size, config.MinFileSizeLimit, i.Inode) + return nil + } + if config.MaxFileSizeLimit > 0 && int64(i.Size) > config.MaxFileSizeLimit { + log.LogInfof("skip warmUp, file size(%d) above MaxFileSizeLimit(%d), inode(%v)", i.Size, config.MaxFileSizeLimit, i.Inode) + return nil + } _, _, extents, err = s.mw.GetExtents(i.Inode, false, false, false) if err != nil { log.LogWarnf("warmUp: mw GetExtents fail, inode(%v) err: %v ", i.Inode, err) diff --git a/remotecache/flashnode/serve_http.go b/remotecache/flashnode/serve_http.go index caf369161..7b083c8c1 100644 --- a/remotecache/flashnode/serve_http.go +++ b/remotecache/flashnode/serve_http.go @@ -67,6 +67,15 @@ func (f *FlashNode) handleSubmitTask(w http.ResponseWriter, r *http.Request) { return } log.LogInfof("submit mannual task with http arg:%+v", &req) + + // Validate file size limits + if req.ManualTaskConfig.MinFileSizeLimit > req.ManualTaskConfig.MaxFileSizeLimit { + err = fmt.Errorf("MinFileSizeLimit(%d) cannot be greater than MaxFileSizeLimit(%d)", + req.ManualTaskConfig.MinFileSizeLimit, req.ManualTaskConfig.MaxFileSizeLimit) + replyErr(w, r, proto.ErrCodeParamError, err.Error(), nil) + return + } + start := time.Now() req.StartTime = &start req.UpdateTime = &start