From e292495883c4286b7bab54f634146bb1c3d05366 Mon Sep 17 00:00:00 2001 From: bigsheeper Date: Mon, 23 Dec 2024 10:56:16 +0800 Subject: [PATCH] enhance: Optimize GetLocalDiskSize and segment loader mutex Signed-off-by: bigsheeper --- .../segments/disk_usage_fetcher.go | 22 +++++++++++-------- .../querynodev2/segments/segment_loader.go | 6 ++--- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/internal/querynodev2/segments/disk_usage_fetcher.go b/internal/querynodev2/segments/disk_usage_fetcher.go index 5bd41ee17585d..b1beb89aad3fe 100644 --- a/internal/querynodev2/segments/disk_usage_fetcher.go +++ b/internal/querynodev2/segments/disk_usage_fetcher.go @@ -30,30 +30,34 @@ import ( ) type diskUsageFetcher struct { - ctx context.Context - path string - diskUsage *atomic.Int64 + ctx context.Context + path string + usage *atomic.Int64 + err *atomic.Error } func NewDiskUsageFetcher(ctx context.Context) *diskUsageFetcher { return &diskUsageFetcher{ - ctx: ctx, - path: paramtable.Get().LocalStorageCfg.Path.GetValue(), - diskUsage: atomic.NewInt64(0), + ctx: ctx, + path: paramtable.Get().LocalStorageCfg.Path.GetValue(), + usage: atomic.NewInt64(0), + err: atomic.NewError(nil), } } -func (d *diskUsageFetcher) GetDiskUsage() int64 { - return d.diskUsage.Load() +func (d *diskUsageFetcher) GetDiskUsage() (int64, error) { + return d.usage.Load(), d.err.Load() } func (d *diskUsageFetcher) fetch() { diskUsage, err := GetLocalUsedSize(d.ctx, d.path) if err != nil { log.Warn("failed to get disk usage", zap.Error(err)) + d.err.Store(err) return } - d.diskUsage.Store(diskUsage) + d.usage.Store(diskUsage) + d.err.Store(nil) metrics.QueryNodeDiskUsedSize.WithLabelValues(fmt.Sprint(paramtable.GetNodeID())).Set(float64(diskUsage) / 1024 / 1024) // in MB log.Ctx(d.ctx).WithRateGroup("diskUsageFetcher", 1, 300). RatedInfo(300, "querynode disk usage", zap.Int64("size", diskUsage), zap.Int64("nodeID", paramtable.GetNodeID())) diff --git a/internal/querynodev2/segments/segment_loader.go b/internal/querynodev2/segments/segment_loader.go index 8b107a01e6047..0c27ea5ea6287 100644 --- a/internal/querynodev2/segments/segment_loader.go +++ b/internal/querynodev2/segments/segment_loader.go @@ -848,9 +848,9 @@ func (loader *segmentLoader) requestResource(ctx context.Context, infos ...*quer memoryUsage := hardware.GetUsedMemoryCount() totalMemory := hardware.GetMemoryCount() - diskUsage := loader.duf.GetDiskUsage() - if diskUsage == 0 { - return requestResourceResult{}, errors.New("get local used size failed") + diskUsage, err := loader.duf.GetDiskUsage() + if err != nil { + return requestResourceResult{}, errors.Wrap(err, "get local used size failed") } diskCap := paramtable.Get().QueryNodeCfg.DiskCapacityLimit.GetAsUint64()