@@ -17,6 +17,7 @@ import (
17
17
"github.com/cockroachdb/pebble/internal/ascii/table"
18
18
"github.com/cockroachdb/pebble/internal/base"
19
19
"github.com/cockroachdb/pebble/internal/cache"
20
+ "github.com/cockroachdb/pebble/internal/compression"
20
21
"github.com/cockroachdb/pebble/internal/manifest"
21
22
"github.com/cockroachdb/pebble/internal/manual"
22
23
"github.com/cockroachdb/pebble/objstorage/objstorageprovider/sharedcache"
@@ -347,18 +348,6 @@ type Metrics struct {
347
348
BackingTableCount uint64
348
349
// The sum of the sizes of the BackingTableCount sstables that are backing virtual tables.
349
350
BackingTableSize uint64
350
- // The number of sstables that are compressed with an unknown compression
351
- // algorithm.
352
- CompressedCountUnknown int64
353
- // The number of sstables that are compressed with the default compression
354
- // algorithm, snappy.
355
- CompressedCountSnappy int64
356
- // The number of sstables that are compressed with zstd.
357
- CompressedCountZstd int64
358
- // The number of sstables that are compressed with minlz.
359
- CompressedCountMinLZ int64
360
- // The number of sstables that are uncompressed.
361
- CompressedCountNone int64
362
351
363
352
// Local file sizes.
364
353
Local struct {
@@ -450,6 +439,8 @@ type Metrics struct {
450
439
}
451
440
}
452
441
442
+ Compression CompressionMetrics
443
+
453
444
FileCache FileCacheMetrics
454
445
455
446
// Count of the number of open sstable iterators.
@@ -498,6 +489,46 @@ type Metrics struct {
498
489
manualMemory manual.Metrics
499
490
}
500
491
492
+ // CompressionMetrics contains compression metrics for sstables and blob files.
493
+ type CompressionMetrics struct {
494
+ // NoCompressionBytes is the total number of bytes in files that do are not
495
+ // compressed. Data can be uncompressed when 1) compression is disabled; 2)
496
+ // for certain special types of blocks; and 3) for blocks that are not
497
+ // compressible.
498
+ NoCompressionBytes uint64
499
+ // CompressedBytesWithoutStats is the total number of bytes in files that do not
500
+ // encode compression statistics (or for which there are no statistics yet).
501
+ CompressedBytesWithoutStats uint64
502
+ Snappy CompressionStatsForSetting
503
+ MinLZ CompressionStatsForSetting
504
+ Zstd CompressionStatsForSetting
505
+ }
506
+
507
+ type CompressionStatsForSetting = block.CompressionStatsForSetting
508
+
509
+ func (cm * CompressionMetrics ) Add (stats * block.CompressionStats ) {
510
+ for s , cs := range stats .All () {
511
+ switch s .Algorithm {
512
+ case compression .NoCompression :
513
+ cm .NoCompressionBytes += cs .UncompressedBytes
514
+ case compression .SnappyAlgorithm :
515
+ cm .Snappy .Add (cs )
516
+ case compression .MinLZ :
517
+ cm .MinLZ .Add (cs )
518
+ case compression .Zstd :
519
+ cm .Zstd .Add (cs )
520
+ }
521
+ }
522
+ }
523
+
524
+ func (cm * CompressionMetrics ) MergeWith (o * CompressionMetrics ) {
525
+ cm .NoCompressionBytes += o .NoCompressionBytes
526
+ cm .CompressedBytesWithoutStats += o .CompressedBytesWithoutStats
527
+ cm .Snappy .Add (o .Snappy )
528
+ cm .MinLZ .Add (o .MinLZ )
529
+ cm .Zstd .Add (o .Zstd )
530
+ }
531
+
501
532
var (
502
533
// FsyncLatencyBuckets are prometheus histogram buckets suitable for a histogram
503
534
// that records latencies for fsyncs.
@@ -751,9 +782,18 @@ var (
751
782
table .String ("range dels" , 15 , table .AlignRight , func (i keysInfo ) string { return i .rangeDels }),
752
783
)
753
784
compressionTableHeader = `COMPRESSION`
754
- compressionTable = table .Define [pair [string , int64 ]](
755
- table .String ("algorithm" , 10 , table .AlignRight , func (p pair [string , int64 ]) string { return p .k }),
756
- table .Count ("tables" , 10 , table .AlignRight , func (p pair [string , int64 ]) int64 { return p .v }),
785
+ compressionTable = table .Define [pair [string , CompressionStatsForSetting ]](
786
+ table .String ("algorithm" , 13 , table .AlignRight , func (p pair [string , CompressionStatsForSetting ]) string { return p .k }),
787
+ table .Bytes ("on disk bytes" , 13 , table .AlignRight , func (p pair [string , CompressionStatsForSetting ]) uint64 { return p .v .CompressedBytes }),
788
+ table .String ("CR" , 13 , table .AlignRight , func (p pair [string , CompressionStatsForSetting ]) string {
789
+ if p .v .UncompressedBytes == p .v .CompressedBytes {
790
+ return ""
791
+ }
792
+ if p .v .UncompressedBytes == 0 {
793
+ return "?"
794
+ }
795
+ return crhumanize .Float (p .v .CompressionRatio (), 2 /* precision */ ).String ()
796
+ }),
757
797
)
758
798
)
759
799
@@ -974,15 +1014,19 @@ func (m *Metrics) String() string {
974
1014
cur = cur .NewlineReturn ()
975
1015
976
1016
cur = cur .WriteString (compressionTableHeader ).NewlineReturn ()
977
- compressionContents := []pair [string , int64 ]{
978
- {k : "none" , v : m .Table .CompressedCountNone },
979
- {k : "snappy" , v : m .Table .CompressedCountSnappy },
980
- {k : "minlz" , v : m .Table .CompressedCountMinLZ },
981
- {k : "zstd" , v : m .Table .CompressedCountZstd },
982
- }
983
- if m .Table .CompressedCountUnknown > 0 {
984
- compressionContents = append (compressionContents , pair [string , int64 ]{k : "???" , v : m .Table .CompressedCountUnknown })
1017
+ compressionContents := []pair [string , CompressionStatsForSetting ]{
1018
+ {k : "none" , v : CompressionStatsForSetting {
1019
+ CompressedBytes : m .Compression .NoCompressionBytes ,
1020
+ UncompressedBytes : m .Compression .NoCompressionBytes ,
1021
+ }},
1022
+ {k : "snappy" , v : m .Compression .Snappy },
1023
+ {k : "minlz" , v : m .Compression .MinLZ },
1024
+ {k : "zstd" , v : m .Compression .Zstd },
1025
+ {k : "unknown" , v : CompressionStatsForSetting {CompressedBytes : m .Compression .CompressedBytesWithoutStats }},
985
1026
}
1027
+ compressionContents = slices .DeleteFunc (compressionContents , func (p pair [string , CompressionStatsForSetting ]) bool {
1028
+ return p .v .CompressedBytes == 0
1029
+ })
986
1030
compressionTable .Render (cur , table.RenderOptions {Orientation : table .Horizontally }, slices .Values (compressionContents ))
987
1031
988
1032
return wb .String ()
0 commit comments