You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Below is a summary of compliance checks for this PR:
Security Compliance
⚪
Resource handle leak
Description: The RSS refresh path creates a process handle only once and never closes it, which may leak OS resources if process.NewProcess allocates handles that require explicit closure. resource_throttler.go [184-198]
The memory cost estimation for merges relies on an arbitrary multiplier that was doubled. Instead of adjusting this "magic number," a more robust, principled estimation model should be developed based on an analysis of memory consumption during merges.
funcEstimateMergeSize(objs iter.Seq[*objectio.ObjectStats]) int {
estSize:=0totalSize:=0forobj:=rangeobjs {
// ... various estimationstotalSize+=int(obj.OriginSize()) /2
}
// leave some margin for gcestSize+=totalSize/3*2returnestSize
}
After:
funcEstimateMergeSize(objs iter.Seq[*objectio.ObjectStats]) int {
// A principled model based on deeper analysis of memory consumption.// This would replace arbitrary multipliers with calculations based on:// - Sort key data types and sizes// - Number of objects and rows// - Compression ratios// - Observed peak memory usage from previous mergesestSize:=PrincipledMemoryEstimation(objs)
returnestSize
}
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies a heuristic-based change and proposes a more robust, principled architectural improvement, which would significantly enhance system stability and resource management.
Medium
Possible issue
Fix race conditions in throttling logic
Fix two race conditions in the specializedForMerge logic. Use an atomic CompareAndSwap for the debouncing logic to prevent concurrent RSS refreshes, and ensure thread-safe initialization of m.proc.
if m.options.specializedForMerge {
now := time.Now().UnixNano()
- if time.Duration(now-m.mergeAvailDebounce.Load()) > time.Second {- m.mergeAvailDebounce.Store(now)- if m.proc == nil {- m.proc, _ = process.NewProcess(int32(os.Getpid()))- }-- if info, err := m.proc.MemoryInfo(); err == nil {- rss = int64(info.RSS)- m.rss.Store(rss)+ last := m.mergeAvailDebounce.Load()+ if time.Duration(now-last) > time.Second {+ if m.mergeAvailDebounce.CompareAndSwap(last, now) {+ if m.proc == nil {+ // Should be initialized in NewMemThrottler, but as a fallback:+ m.proc, _ = process.NewProcess(int32(os.Getpid()))+ }+ if m.proc != nil {+ if info, err := m.proc.MemoryInfo(); err == nil {+ newRss := int64(info.RSS)+ m.rss.Store(newRss)+ rss = newRss+ }+ }
}
}
-- return max(0, limit-rss-reserved)+ return max(0, limit-m.rss.Load()-reserved)
}
Apply / Chat
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies two race conditions in newly added code and proposes a valid fix using an atomic CompareAndSwap, which improves the correctness and robustness of the concurrent logic.
Medium
General
Optimize object sorting and filtering logic
Optimize object processing by filtering the objList for valid small objects first, and then sorting the much smaller, filtered list. This improves efficiency and avoids side effects from sorting the input slice in place.
objs := make([]*objectio.ObjectStats, 0, stats.Count)
- typ := objList[0].SortKeyZoneMap().GetType()- scale := objList[0].SortKeyZoneMap().GetScale()- if typ != types.T_any {- sort.Slice(objList, func(i, j int) bool {- return compute.Compare(- objList[i].SortKeyZoneMap().GetMinBuf(),- objList[j].SortKeyZoneMap().GetMinBuf(),- typ,- scale,- scale,- ) < 0- })- }
for _, obj := range objList {
if IsValidLayerZeroSmallObj(obj, opts) {
objs = append(objs, obj)
}
}
+ if len(objs) > 0 {+ typ := objs[0].SortKeyZoneMap().GetType()+ scale := objs[0].SortKeyZoneMap().GetScale()+ if typ != types.T_any {+ sort.Slice(objs, func(i, j int) bool {+ return compute.Compare(+ objs[i].SortKeyZoneMap().GetMinBuf(),+ objs[j].SortKeyZoneMap().GetMinBuf(),+ typ,+ scale,+ scale,+ ) < 0+ })+ }+ }+
Apply / Chat
Suggestion importance[1-10]: 6
__
Why: The suggestion correctly points out that sorting before filtering is inefficient and proposes an improved logic that filters first, which is a valid performance optimization and also avoids modifying the input slice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
What type of PR is this?
Which issue(s) this PR fixes:
issue #22638
What this PR does / why we need it:
PR Type
Enhancement, Bug fix
Description
Refresh RSS memory usage periodically for merge scheduling
Improve memory cost estimation with larger safety margin
Sort layer zero objects by sort key for better merge efficiency
Rename option to clarify specialized merge memory handling
Diagram Walkthrough
File Walkthrough
resource_throttler.go
Add debounced RSS refresh for merge memory trackingpkg/common/rscthrottler/resource_throttler.go
mergeAvailDebouncefield to debounce RSS refresh operationslimitIsTheBossoption tospecializedForMergefor claritymerge
max()helperscheduler.go
Update merge scheduler for new memory optionpkg/vm/engine/tae/db/merge/scheduler.go
WithSpecializedForMerge()optionPrintUsage()call from heartbeat handlerRefresh()call for periodic memory refreshstatLayerZero.go
Sort layer zero objects by sort keypkg/vm/engine/tae/db/merge/statLayerZero.go
sort,types, andcomputepackagesT_anytask.go
Increase merge size estimation safety marginpkg/vm/engine/tae/mergesort/task.go
estimation