Skip to content

Commit afb4d60

Browse files
committed
block: minor change to CompressionRatio()
Return 0 if there is no data. This won't make a difference to Pebble, but it enables usage from CRDB when populating metrics.
1 parent d57c0ac commit afb4d60

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

sstable/block/compression_stats.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ type CompressionStatsForSetting struct {
3838
UncompressedBytes uint64
3939
}
4040

41-
// CompressionRatio returns the compression ratio for the setting.
41+
// CompressionRatio returns the compression ratio for the setting. Returns 0 if
42+
// the stats are empty.
4243
func (cs CompressionStatsForSetting) CompressionRatio() float64 {
44+
if cs.CompressedBytes == 0 {
45+
return 0
46+
}
4347
return float64(cs.UncompressedBytes) / float64(cs.CompressedBytes)
4448
}
4549

0 commit comments

Comments
 (0)