Skip to content

Commit 6526490

Browse files
tool/logs: parse blob reference size in compaction log lines
Compaction event log lines now render a level's size as `(table + blob)` (e.g. `(4.2MB + 1.0MB)`) when the input tables reference blob files. The log parser previously assumed a single size value inside the parentheses: - The `compactionPattern` regexp required the closing paren immediately after the first size, so the `bytes` capture (used for the output size of an `compacted` line) matched nothing for the new format. - `sumInputBytes` passed the entire parenthesized contents to `unHumanize`, which only understands a single size token. This change teaches the parser about the optional `+ <size>` suffix. The regexp now accepts one or more `+`-separated sizes within the parentheses, and a new `unHumanizeSum` helper splits on `+` and sums the parts. Both the input-byte and output-byte parsing paths use it, so the reported sizes include the estimated physical size of blob references. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
1 parent 8b39409 commit 6526490

3 files changed

Lines changed: 58 additions & 9 deletions

File tree

event.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,14 @@ func (i LevelInfo) SafeFormat(w redact.SafePrinter, _ rune) {
146146
blobInfo = redact.SafeString(fmt.Sprintf(" blob%s [%s] (%s)",
147147
pluralBlob, formatBlobFileNums(i.Blobs), humanize.Bytes.Uint64(blobsTotalSize(i.Blobs))))
148148
}
149-
sizeStr := redact.Safe(humanize.Bytes.Uint64(tablesTotalSize(i.Tables)))
149+
sizeStr := humanize.Bytes.Uint64(tablesTotalSize(i.Tables)).String()
150150
if refSize := tablesTotalReferenceSize(i.Tables); refSize > 0 {
151-
sizeStr = redact.Safe(fmt.Sprintf("%s + %s",
152-
humanize.Bytes.Uint64(tablesTotalSize(i.Tables)),
153-
humanize.Bytes.Uint64(refSize)))
151+
sizeStr = fmt.Sprintf("%s + %s", sizeStr, humanize.Bytes.Uint64(refSize))
154152
}
155153
w.Printf("L%d [%s] (%s)%s Score=%.2f",
156154
redact.Safe(i.Level),
157155
redact.Safe(formatFileNums(i.Tables)),
158-
sizeStr,
156+
redact.Safe(sizeStr),
159157
blobInfo,
160158
redact.Safe(i.Score))
161159
}

tool/logs/compaction.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ var (
194194

195195
/* Start / end level */
196196
`(?P<levels>L(?P<from>\d).*?(?:.*(?:\+|->)\sL(?P<to>\d))?` +
197-
/* Bytes */
198-
`(?:.*?\((?P<bytes>[0-9.]+( [BKMGTPE]|[KMGTPE]?B))\))` +
197+
/* Bytes (optionally "table + blob references", e.g. "(4.0KB + 1.2MB)") */
198+
`(?:.*?\((?P<bytes>[0-9.]+( [BKMGTPE]|[KMGTPE]?B)( \+ [0-9.]+( [BKMGTPE]|[KMGTPE]?B))*)\))` +
199199
/* Score */
200200
`?(\s*(Score=\d+(\.\d+)))?)`,
201201
)
@@ -470,7 +470,7 @@ func parseCompactionEnd(matches []string) (compactionEnd, error) {
470470

471471
// Optionally, if we have compacted bytes.
472472
if matches[compactionPatternBytesIdx] != "" {
473-
end.writtenBytes = unHumanize(matches[compactionPatternBytesIdx])
473+
end.writtenBytes = unHumanizeSum(matches[compactionPatternBytesIdx])
474474
}
475475

476476
return end, nil
@@ -1563,6 +1563,17 @@ func unHumanize(s string) uint64 {
15631563
return uint64(val * float64(multiplier))
15641564
}
15651565

1566+
// unHumanizeSum parses a parenthesized size value, which may be a single size
1567+
// (e.g. "4.0KB") or a sum of a table size and its blob reference size (e.g.
1568+
// "4.0KB + 1.2MB"), returning the total number of bytes.
1569+
func unHumanizeSum(s string) uint64 {
1570+
var total uint64
1571+
for _, part := range strings.Split(s, "+") {
1572+
total += unHumanize(strings.TrimSpace(part))
1573+
}
1574+
return total
1575+
}
1576+
15661577
// sumInputBytes takes a string as input and returns the sum of the
15671578
// human-readable sizes, as an integer number of bytes.
15681579
func sumInputBytes(s string) (total uint64, _ error) {
@@ -1575,7 +1586,7 @@ func sumInputBytes(s string) (total uint64, _ error) {
15751586
case '(':
15761587
open = true
15771588
case ')':
1578-
total += unHumanize(b.String())
1589+
total += unHumanizeSum(b.String())
15791590
b.Reset()
15801591
open = false
15811592
default:

tool/logs/compaction_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ const (
4444

4545
flushableIngestionLine23_1 = `I230831 04:13:28.824280 3780 3@pebble/event.go:685 ⋮ [n10,s10,pebble] 365 [JOB 226] flushed 6 ingested flushables L0:024334 (1.5 K) + L0:024339 (1.0 K) + L0:024335 (1.9 K) + L0:024336 (1.1 K) + L0:024337 (1.1 K) + L0:024338 (12 K) in 0.0s (0.0s total), output rate 67 M/s`
4646
flushableIngestionLine = `I230831 04:13:28.824280 3780 3@pebble/event.go:685 ⋮ [n10,s10,pebble] 365 [JOB 226] flushed 6 ingested flushables L0:024334 (1.5KB) + L0:024339 (1.0KB) + L0:024335 (1.9KB) + L0:024336 (1.1KB) + L0:024337 (1.1KB) + L0:024338 (12KB) in 0.0s (0.0s total), output rate 67MB/s`
47+
48+
// Lines with blob reference sizes, rendered as "(table + blob)".
49+
compactionStartLineBlob = `I211215 14:26:56.012382 51831533 3@vendor/github.com/cockroachdb/pebble/compaction.go:1845 ⋮ [n5,pebble,s6] 1216510 [JOB 284925] compacting(default) L2 [442555] (4.2MB + 1.0MB) Score=1.01 + L3 [445853] (8.4MB + 2.0MB) Score=0.99; OverlappingRatio: Single 8.03, Multi 25.05;`
50+
compactionEndLineBlob = `I211215 14:26:56.318543 51831533 3@vendor/github.com/cockroachdb/pebble/compaction.go:1886 ⋮ [n5,pebble,s6] 1216554 [JOB 284925] compacted(default) L2 [442555] (4.2MB) Score=1.01 + L3 [445853] (8.4MB) Score=1.01 -> L3 [445883 445887] (13MB + 3.0MB), in 0.3s, output rate 42MB/s`
4751
)
4852

4953
func TestCompactionLogs_Regex(t *testing.T) {
@@ -193,6 +197,32 @@ func TestCompactionLogs_Regex(t *testing.T) {
193197
compactionPatternBytesIdx: "46MB",
194198
},
195199
},
200+
{
201+
name: "compaction start with blob references",
202+
re: compactionPattern,
203+
line: compactionStartLineBlob,
204+
matches: map[int]string{
205+
compactionPatternJobIdx: "284925",
206+
compactionPatternSuffixIdx: "ing",
207+
compactionPatternTypeIdx: "default",
208+
compactionPatternFromIdx: "2",
209+
compactionPatternToIdx: "3",
210+
compactionPatternLevels: "L2 [442555] (4.2MB + 1.0MB) Score=1.01 + L3 [445853] (8.4MB + 2.0MB) Score=0.99",
211+
},
212+
},
213+
{
214+
name: "compaction end with blob references",
215+
re: compactionPattern,
216+
line: compactionEndLineBlob,
217+
matches: map[int]string{
218+
compactionPatternJobIdx: "284925",
219+
compactionPatternSuffixIdx: "ed",
220+
compactionPatternTypeIdx: "default",
221+
compactionPatternFromIdx: "2",
222+
compactionPatternToIdx: "3",
223+
compactionPatternBytesIdx: "13MB + 3.0MB",
224+
},
225+
},
196226
{
197227
name: "flush start",
198228
re: flushPattern,
@@ -453,6 +483,16 @@ func TestParseInputBytes(t *testing.T) {
453483
"(10MB) + (20MB) + (30MB)",
454484
60 << 20,
455485
},
486+
// Blob reference sizes are rendered within a single set of parentheses as
487+
// "table + blob"; both are summed.
488+
{
489+
"(10MB + 5MB)",
490+
15 << 20,
491+
},
492+
{
493+
"(10MB + 5MB) + (20MB + 1MB)",
494+
36 << 20,
495+
},
456496
{
457497
"foo",
458498
0,

0 commit comments

Comments
 (0)