Skip to content

Commit

Permalink
enhance: Optimize GetLocalDiskSize and segment loader mutex
Browse files Browse the repository at this point in the history
Signed-off-by: bigsheeper <[email protected]>
  • Loading branch information
bigsheeper committed Dec 24, 2024
1 parent bf27f70 commit e292495
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
22 changes: 13 additions & 9 deletions internal/querynodev2/segments/disk_usage_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
6 changes: 3 additions & 3 deletions internal/querynodev2/segments/segment_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit e292495

Please sign in to comment.