meta: commit new chunks in write order#7016
Open
davies wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent observed “zero-filled regions” during concurrent reads of a file that is actively being appended to, by enforcing a commit ordering constraint across newly growing chunks in pkg/vfs (close #5038).
Changes:
- Track whether a slice contributes to file growth (
growing) and whether it has been committed (committed). - Introduce cross-chunk commit dependencies so a new chunk’s first slice waits for the prior growing slice to commit before writing metadata.
- Add a per-file condition variable (
commitcond) to coordinate commit ordering across chunk commit goroutines.
Comments suppressed due to low confidence (1)
pkg/vfs/writer.go:307
- Finding the dependency for a new chunk scans the entire
f.chunksmap (and then scanslastChunk.slices) while holding the file lock. With many buffered chunks/slices this can become O(n²) during sequential appends. Consider tracking the last in-progress/growing slice (or last uncommitted chunk index) onfileWriterand updating it whens.growingis set/committed, so settings.depis O(1). Also, the inner loop variablecshadows the outerc(chunkWriter), which makes this block harder to follow; renaming the inner variable would improve readability.
if uint64(indx)*meta.ChunkSize >= f.length {
// first slice of a new chunk, try to find the last slice of the last chunk as dependency
var lastChunk *chunkWriter
for i, c := range f.chunks {
if i < indx && (lastChunk == nil || i > lastChunk.indx) {
lastChunk = c
}
}
if lastChunk != nil {
var lastSlice *sliceWriter
for _, s := range lastChunk.slices {
if s.growing {
lastSlice = s
}
}
s.dep = lastSlice
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+200
to
+202
| for s.dep != nil && !s.dep.committed { | ||
| f.commitcond.WaitWithTimeout(time.Millisecond * 100) | ||
| } |
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.
close #5038