@@ -226,6 +226,9 @@ type Engine struct {
226226
227227 // muDigest ensures only one goroutine can generate a digest at a time.
228228 muDigest sync.RWMutex
229+
230+ // TarStreamBufferSize is the size used for our buffer windows within the tar package.
231+ TarStreamBufferSize uint64
229232}
230233
231234// NewEngine returns a new instance of Engine.
@@ -285,6 +288,8 @@ func NewEngine(id uint64, idx tsdb.Index, path string, walPath string, sfile *ts
285288 optimizedCompactionLimiter : opt .OptimizedCompactionLimiter ,
286289 Scheduler : newScheduler (stats , opt .CompactionLimiter .Capacity ()),
287290 seriesIDSets : opt .SeriesIDSets ,
291+
292+ TarStreamBufferSize : opt .Config .TarStreamBufferSize ,
288293 }
289294
290295 // Feature flag to enable per-series type checking, by default this is off and
@@ -993,13 +998,13 @@ func (e *Engine) Backup(w io.Writer, basePath string, since time.Time) error {
993998 }
994999 }()
9951000
996- return intar .Stream (w , path , basePath , intar .SinceFilterTarFile (since ))
1001+ return intar .Stream (w , path , basePath , e . TarStreamBufferSize , intar .SinceFilterTarFile (since ))
9971002}
9981003
999- func (e * Engine ) timeStampFilterTarFile (start , end time.Time ) func (f os.FileInfo , shardRelativePath , fullPath string , tw * tar.Writer ) error {
1000- return func (fi os.FileInfo , shardRelativePath , fullPath string , tw * tar.Writer ) error {
1004+ func (e * Engine ) timeStampFilterTarFile (start , end time.Time ) func (f os.FileInfo , shardRelativePath , fullPath string , tw * tar.Writer , bufSize uint64 ) error {
1005+ return func (fi os.FileInfo , shardRelativePath , fullPath string , tw * tar.Writer , bufSize uint64 ) error {
10011006 if ! strings .HasSuffix (fi .Name (), ".tsm" ) {
1002- return intar .StreamFile (fi , shardRelativePath , fullPath , tw )
1007+ return intar .StreamFile (fi , shardRelativePath , fullPath , tw , e . TarStreamBufferSize )
10031008 }
10041009
10051010 f , err := os .Open (fullPath )
@@ -1013,7 +1018,7 @@ func (e *Engine) timeStampFilterTarFile(start, end time.Time) func(f os.FileInfo
10131018
10141019 // Grab the tombstone file if one exists.
10151020 if ts := r .TombstoneStats (); ts .TombstoneExists {
1016- return intar .StreamFile (fi , shardRelativePath , filepath .Base (ts .Path ), tw )
1021+ return intar .StreamFile (fi , shardRelativePath , filepath .Base (ts .Path ), tw , e . TarStreamBufferSize )
10171022 }
10181023
10191024 min , max := r .TimeRange ()
@@ -1041,7 +1046,7 @@ func (e *Engine) timeStampFilterTarFile(start, end time.Time) func(f os.FileInfo
10411046
10421047 // the TSM file is 100% inside the range, so we can just write it without scanning each block
10431048 if min >= start .UnixNano () && max <= end .UnixNano () {
1044- if err := intar .StreamFile (fi , shardRelativePath , fullPath , tw ); err != nil {
1049+ if err := intar .StreamFile (fi , shardRelativePath , fullPath , tw , bufSize ); err != nil {
10451050 return err
10461051 }
10471052 }
@@ -1061,7 +1066,7 @@ func (e *Engine) Export(w io.Writer, basePath string, start time.Time, end time.
10611066 }
10621067 }()
10631068
1064- return intar .Stream (w , path , basePath , e .timeStampFilterTarFile (start , end ))
1069+ return intar .Stream (w , path , basePath , e .TarStreamBufferSize , e . timeStampFilterTarFile (start , end ))
10651070}
10661071
10671072func (e * Engine ) filterFileToBackup (r * TSMReader , fi os.FileInfo , shardRelativePath , fullPath string , start , end int64 , tw * tar.Writer ) error {
@@ -1116,7 +1121,7 @@ func (e *Engine) filterFileToBackup(r *TSMReader, fi os.FileInfo, shardRelativeP
11161121 return err
11171122 }
11181123
1119- return intar .StreamRenameFile (tmpFi , fi .Name (), shardRelativePath , path , tw )
1124+ return intar .StreamRenameFile (tmpFi , fi .Name (), shardRelativePath , path , tw , e . TarStreamBufferSize )
11201125}
11211126
11221127// Restore reads a tar archive generated by Backup().
0 commit comments