fix(vlog): upgrade discardStats to RWMutex and secure Iterate read path (#19431)#2309
Open
HarshalPatel1972 wants to merge 1 commit into
Open
fix(vlog): upgrade discardStats to RWMutex and secure Iterate read path (#19431)#2309HarshalPatel1972 wants to merge 1 commit into
HarshalPatel1972 wants to merge 1 commit into
Conversation
|
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Fixes #19431
This PR resolves a high-frequency data race and associated memory log truncation leak within the Value Log garbage collection subsystem (
discardStats).Technical Root Cause
The
discardStatsstruct embeds a standardsync.Mutexguarding internal state tracking arrays and maps. While execution boundaries likeUpdateandMaxDiscardcorrectly acquire exclusive ownership vialf.Lock(), the exportedIteratemethod completely lacked synchronization.Under intense concurrent write workloads combined with background telemetry, metrics collection, or CLI debugging cycles, external calls to
Iteratewould traverself.nextEmptySlotand slice elements concurrently while a garbage collection thread or compaction task was executing an un-synchronizedUpdate(which triggers slice mutation and sorting operations viasort.Sort). This led to runtime data races, stale memory tracking offsets, and occasionally missing log truncation windows, leaving old value log (vlog) files stranded on disk.Resolution Strategy
sync.MutexinsidediscardStatsout for a high-performancesync.RWMutex.func (lf *discardStats) Iterate(...)with shared read-locks (lf.RLock()/defer lf.RUnlock()). This allows infinite concurrent telemetry readers to safely scan statistics without blocking each other or starving the system.lf.Lock()/defer lf.Unlock()boundaries insideUpdateto cleanly isolate mutations and sorting operations.Testing & Regression
TestDiscardStats_ConcurrentRacewithindiscard_test.go.Updateframes, alongside 20 worker goroutines executing overlappingIterateread scans.go test -race -v ./...), returning 100% clean thread safety boundaries.Checklist