Skip to content

Commit e90488e

Browse files
craig[bot]aa-joshi
andcommitted
Merge #148073
148073: cli(debug.zip): update makeTableIterator func to read per line r=aa-joshi a=aa-joshi Previously, we are reading debug.zip files' row with max buffer size of `5MB`. However, we obsereved that few debug.zip file contains row data >10MB. This would result in debug.zip Datadog upload failure. To address this, this patch reads file per line without any buffer constraints. Epic: none Part of: CRDB-51110 Release note: None Co-authored-by: Akshay Joshi <[email protected]>
2 parents 0d98c7a + 233b70c commit e90488e

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

pkg/cli/zip_upload_table_dumps.go

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -317,23 +317,41 @@ func processTableDump(
317317

318318
// makeTableIterator returns the headers slice and an iterator
319319
func makeTableIterator(f io.Reader) ([]string, func(func(string) error) error) {
320-
scanner := bufio.NewScanner(f)
321-
322-
// some of the rows can be very large, bigger than the bufio.MaxTokenSize
323-
// (65kb). So, we need to increase the buffer size and split by lines while
324-
// scanning.
325-
scanner.Buffer(nil, 5<<20) // 5 MB
326-
scanner.Split(bufio.ScanLines)
327-
328-
scanner.Scan() // scan the first line to get the headers
329-
return strings.Split(scanner.Text(), "\t"), func(fn func(string) error) error {
330-
for scanner.Scan() {
331-
if err := fn(scanner.Text()); err != nil {
320+
reader := bufio.NewReader(f)
321+
322+
// Read first line for headers
323+
headerLine, err := reader.ReadString('\n')
324+
if err != nil && err != io.EOF {
325+
return nil, func(func(string) error) error { return err }
326+
}
327+
328+
// Trim the newline character if present
329+
headerLine = strings.TrimSuffix(headerLine, "\n")
330+
headers := strings.Split(headerLine, "\t")
331+
332+
return headers, func(fn func(string) error) error {
333+
for {
334+
line, err := reader.ReadString('\n')
335+
if err != nil {
336+
if err == io.EOF {
337+
// Process any remaining content before EOF
338+
if line != "" {
339+
if err := fn(strings.TrimSuffix(line, "\n")); err != nil {
340+
return err
341+
}
342+
}
343+
break
344+
}
332345
return err
333346
}
334-
}
335347

336-
return scanner.Err()
348+
// Trim the newline character
349+
line = strings.TrimSuffix(line, "\n")
350+
if err := fn(line); err != nil {
351+
return err
352+
}
353+
}
354+
return nil
337355
}
338356
}
339357

0 commit comments

Comments
 (0)