feat: Update Stream to accept a bufSize for tar CopyBuffer window#26964
Merged
devanbenz merged 13 commits intomaster-1.xfrom Dec 23, 2025
Merged
feat: Update Stream to accept a bufSize for tar CopyBuffer window#26964devanbenz merged 13 commits intomaster-1.xfrom
devanbenz merged 13 commits intomaster-1.xfrom
Conversation
gwossum
reviewed
Nov 7, 2025
Comment on lines
+170
to
+174
| # The size of tar buffer window size in bytes while running tar | ||
| # streaming operations such as renaming and copying tar files during backups. | ||
| # The default value is 1MB. This should only change if backups are having performance issues | ||
| # and you understand that this value is a heuristic that may need to be tweaked. | ||
| # tar-stream-buffer-size = 1048576 |
Member
There was a problem hiding this comment.
It looks like the tar buffer size is only used in the backup code paths. If this is correct, I wonder if backup-stream-buffer-size would be a better name.
gwossum
reviewed
Nov 7, 2025
Member
gwossum
left a comment
There was a problem hiding this comment.
io.CopyN did some additional error checking that io.CopyBuffer does not. We should probably do the error checking ourselves now.
gwossum
reviewed
Nov 7, 2025
Member
gwossum
left a comment
There was a problem hiding this comment.
I think we're throwing away the error now.
gwossum
reviewed
Nov 7, 2025
pkg/tar/stream.go
Outdated
| if err != nil { | ||
| return err | ||
| } else if bytesWritten != h.Size { | ||
| return fmt.Errorf("error while copying buffer, expected %d bytes but wrote %d", h.Size, bytesWritten) |
Member
There was a problem hiding this comment.
Maybe add the method the error occurred in so we can track it down if needed.
davidby-influx
requested changes
Nov 17, 2025
tsdb/config.go
Outdated
| } | ||
|
|
||
| if c.TarStreamBufferSize <= 0 { | ||
| return fmt.Errorf("tar-stream-buffer-size cannot be zero and must be non-negative") |
Contributor
There was a problem hiding this comment.
Put the erroneous value in the error with a %d to help debug problems.
devanbenz
added a commit
that referenced
this pull request
Jan 2, 2026
…6964) `io.Copy` & `io.CopyN` uses a default window size of 32KB during copy `Copy(N)` calls `copyBuffer` with `buf` set to `nil` https://cs.opensource.google/go/go/+/refs/tags/go1.25.4:src/io/io.go;l=387-389 When `buf` is `nil` go will set the default buffer size to 32KB https://cs.opensource.google/go/go/+/refs/tags/go1.25.4:src/io/io.go;l=418 This PR replaces `io.CopyN` with `io.CopyBuffer` in `tar.Stream`. It also adds a new configuration value `tar-stream-buffer-size` which can be adjusted to allow for larger or smaller tar buffer sizes to be used during backup operations. It is suggested to keep the default as is, while testing different buffer sizes to be used with `CopyBuffer` I found that `1MB` was the best performance-wise. (cherry picked from commit abd617f)
devanbenz
added a commit
that referenced
this pull request
Jan 2, 2026
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.
io.Copy&io.CopyNuses a default window size of 32KB during copyCopy(N)callscopyBufferwithbufset tonilhttps://cs.opensource.google/go/go/+/refs/tags/go1.25.4:src/io/io.go;l=387-389
When
bufisnilgo will set the default buffer size to 32KBhttps://cs.opensource.google/go/go/+/refs/tags/go1.25.4:src/io/io.go;l=418
This PR replaces
io.CopyNwithio.CopyBufferintar.Stream. It also adds a new configuration valuetar-stream-buffer-sizewhich can be adjusted to allow for larger or smaller tar buffer sizes to be used during backup operations.It is suggested to keep the default as is, while testing different buffer sizes to be used with
CopyBufferI found that1MBwas the best performance-wise.