@@ -6,8 +6,8 @@ package pebble
6
6
7
7
import (
8
8
"fmt"
9
+ "iter"
9
10
"math"
10
- "slices"
11
11
"strings"
12
12
"time"
13
13
"unsafe"
@@ -228,7 +228,6 @@ type Metrics struct {
228
228
RewriteCount int64
229
229
MultiLevelCount int64
230
230
BlobFileRewriteCount int64
231
- CounterLevelCount int64
232
231
// An estimate of the number of bytes that need to be compacted for the LSM
233
232
// to reach a stable state.
234
233
EstimatedDebt uint64
@@ -669,9 +668,19 @@ var (
669
668
table.Literal [* LevelMetrics ](" " ),
670
669
table .Bytes ("blobsz" , 6 , table .AlignRight , func (m * LevelMetrics ) uint64 { return m .BlobBytesFlushed + m .BlobBytesCompacted }),
671
670
)
672
- compactionKindTable = table .Define [pair [string , int64 ]](
673
- table .String ("kind" , 9 , table .AlignRight , func (p pair [string , int64 ]) string { return p .k }),
674
- table .Count ("count" , 9 , table .AlignRight , func (p pair [string , int64 ]) int64 { return p .v }),
671
+ compactionKindTable = table .Define [compactionKindsInfo ](
672
+ table .String ("kind" , 6 , table .AlignRight , func (i compactionKindsInfo ) string { return "count" }),
673
+ table .Div (),
674
+ table .String ("default" , 8 , table .AlignRight , func (i compactionKindsInfo ) string { return i .def }),
675
+ table .String ("delete" , 9 , table .AlignRight , func (i compactionKindsInfo ) string { return i .delete }),
676
+ table .String ("elision" , 9 , table .AlignRight , func (i compactionKindsInfo ) string { return i .elision }),
677
+ table .String ("copy" , 9 , table .AlignRight , func (i compactionKindsInfo ) string { return i .copy }),
678
+ table .String ("move" , 9 , table .AlignRight , func (i compactionKindsInfo ) string { return i .move }),
679
+ table .String ("read" , 9 , table .AlignRight , func (i compactionKindsInfo ) string { return i .read }),
680
+ table .String ("tomb" , 9 , table .AlignRight , func (i compactionKindsInfo ) string { return i .tombstone }),
681
+ table .String ("rewrite" , 9 , table .AlignRight , func (i compactionKindsInfo ) string { return i .rewrite }),
682
+ table .String ("multi" , 9 , table .AlignRight , func (i compactionKindsInfo ) string { return i .multilevel }),
683
+ table .String ("blob" , 9 , table .AlignRight , func (i compactionKindsInfo ) string { return i .blob }),
675
684
)
676
685
commitPipelineInfoTableTopHeader = `COMMIT PIPELINE`
677
686
commitPipelineInfoTableSubHeader = ` wals | memtables | ingestions`
@@ -709,25 +718,21 @@ var (
709
718
table .Div (),
710
719
table .String ("open" , 11 , table .AlignRight , func (i iteratorInfo ) string { return i .snapshotsOpen }),
711
720
)
712
- fileInfoTableHeader = `FILES tables | blob files | blob values`
721
+ fileInfoTableHeader = `FILES tables | blob files | blob values`
713
722
fileInfoTable = table .Define [tableAndBlobInfo ](
714
723
table .String ("stats prog" , 13 , table .AlignRight , func (i tableAndBlobInfo ) string { return i .tableInfo .stats }),
715
724
table .Div (),
716
- table .String ("backing" , 9 , table .AlignRight , func (i tableAndBlobInfo ) string { return i .tableInfo .backing }),
717
- table .Div (),
718
- table .String ("zombie" , 9 , table .AlignRight , func (i tableAndBlobInfo ) string { return i .tableInfo .zombie }),
725
+ table .String ("backing" , 10 , table .AlignRight , func (i tableAndBlobInfo ) string { return i .tableInfo .backing }),
719
726
table .Div (),
720
- table .String ("loc zomb " , 9 , table .AlignRight , func (i tableAndBlobInfo ) string { return i .tableInfo .localZombie }),
727
+ table .String ("zombie " , 21 , table .AlignRight , func (i tableAndBlobInfo ) string { return i .tableInfo .zombie }),
721
728
table .Div (),
722
- table .String ("live" , 7 , table .AlignRight , func (i tableAndBlobInfo ) string { return i .blobInfo .live }),
729
+ table .String ("live" , 10 , table .AlignRight , func (i tableAndBlobInfo ) string { return i .blobInfo .live }),
723
730
table .Div (),
724
- table .String ("zombie" , 8 , table .AlignRight , func (i tableAndBlobInfo ) string { return i .blobInfo .zombie }),
731
+ table .String ("zombie" , 10 , table .AlignRight , func (i tableAndBlobInfo ) string { return i .blobInfo .zombie }),
725
732
table .Div (),
726
733
table .String ("total" , 6 , table .AlignRight , func (i tableAndBlobInfo ) string { return i .blobInfo .total }),
727
734
table .Div (),
728
- table .String ("refed" , 6 , table .AlignRight , func (i tableAndBlobInfo ) string { return i .blobInfo .referenced }),
729
- table .Div (),
730
- table .String ("refed %" , 7 , table .AlignRight , func (i tableAndBlobInfo ) string { return i .blobInfo .referencedPercent }),
735
+ table .String ("refed" , 10 , table .AlignRight , func (i tableAndBlobInfo ) string { return i .blobInfo .referenced }),
731
736
)
732
737
cgoMemInfoTableHeader = `CGO MEMORY | block cache | memtables`
733
738
cgoMemInfoTable = table .Define [cgoMemInfo ](
@@ -769,6 +774,19 @@ var (
769
774
)
770
775
)
771
776
777
+ type compactionKindsInfo struct {
778
+ def string
779
+ delete string
780
+ elision string
781
+ copy string
782
+ move string
783
+ read string
784
+ tombstone string
785
+ rewrite string
786
+ multilevel string
787
+ blob string
788
+ }
789
+
772
790
type commitPipelineInfo struct {
773
791
files string
774
792
written string
@@ -790,18 +808,16 @@ type iteratorInfo struct {
790
808
snapshotsOpen string
791
809
}
792
810
type tableInfo struct {
793
- stats string
794
- backing string
795
- zombie string
796
- localZombie string
811
+ stats string
812
+ backing string
813
+ zombie string
797
814
}
798
815
799
816
type blobInfo struct {
800
- live string
801
- zombie string
802
- total string
803
- referenced string
804
- referencedPercent string
817
+ live string
818
+ zombie string
819
+ total string
820
+ referenced string
805
821
}
806
822
807
823
type tableAndBlobInfo struct {
@@ -834,11 +850,6 @@ type keysInfo struct {
834
850
rangeDels string
835
851
}
836
852
837
- type pair [k , v any ] struct {
838
- k k
839
- v v
840
- }
841
-
842
853
// String pretty-prints the metrics.
843
854
//
844
855
// See testdata/metrics for an example.
@@ -893,21 +904,23 @@ func (m *Metrics) String() string {
893
904
cur = cur .NewlineReturn ()
894
905
return cur
895
906
}
896
- compactionKindContents := []pair [string , int64 ]{
897
- {k : "default" , v : m .Compact .DefaultCount },
898
- {k : "delete" , v : m .Compact .DeleteOnlyCount },
899
- {k : "elision" , v : m .Compact .ElisionOnlyCount },
900
- {k : "move" , v : m .Compact .MoveCount },
901
- {k : "read" , v : m .Compact .ReadCount },
902
- {k : "tomb" , v : m .Compact .TombstoneDensityCount },
903
- {k : "rewrite" , v : m .Compact .RewriteCount },
904
- {k : "copy" , v : m .Compact .CopyCount },
905
- {k : "multi" , v : m .Compact .MultiLevelCount },
906
- {k : "blob" , v : m .Compact .BlobFileRewriteCount },
907
+
908
+ compactionKindsContents := compactionKindsInfo {
909
+ def : humanizeCount (m .Compact .DefaultCount ).String (),
910
+ delete : humanizeCount (m .Compact .DeleteOnlyCount ).String (),
911
+ elision : humanizeCount (m .Compact .ElisionOnlyCount ).String (),
912
+ copy : humanizeCount (m .Compact .CopyCount ).String (),
913
+ move : humanizeCount (m .Compact .MoveCount ).String (),
914
+ read : humanizeCount (m .Compact .ReadCount ).String (),
915
+ tombstone : humanizeCount (m .Compact .TombstoneDensityCount ).String (),
916
+ rewrite : humanizeCount (m .Compact .RewriteCount ).String (),
917
+ multilevel : humanizeCount (m .Compact .MultiLevelCount ).String (),
918
+ blob : humanizeCount (m .Compact .BlobFileRewriteCount ).String (),
907
919
}
920
+
908
921
cur = renderTableWithDivider (cur , func (cur ascii.Cursor ) ascii.Cursor {
909
- return compactionKindTable .Render (cur , table.RenderOptions {Orientation : table . Horizontally }, slices . Values ( compactionKindContents ))
910
- }, max ( compactionLevelMetricsTable .CumulativeFieldWidth , cur . Column ()) , - 1 )
922
+ return compactionKindTable .Render (cur , table.RenderOptions {}, oneItemIter ( compactionKindsContents ))
923
+ }, compactionKindTable .CumulativeFieldWidth , - 1 )
911
924
912
925
commitPipelineInfoContents := commitPipelineInfo {
913
926
// wals.
@@ -922,13 +935,10 @@ func (m *Metrics) String() string {
922
935
total : crhumanize .Count (m .WAL .BytesIn + m .WAL .BytesWritten ).String (),
923
936
flushable : fmt .Sprintf ("%s (%s)" , humanizeCount (m .Flush .AsIngestCount ), humanizeBytes (m .Flush .AsIngestBytes )),
924
937
}
925
- commitPipelineInfoIter := func (yield func (commitPipelineInfo ) bool ) {
926
- yield (commitPipelineInfoContents )
927
- }
928
938
cur = cur .WriteString (commitPipelineInfoTableTopHeader ).NewlineReturn ()
929
939
cur = cur .WriteString (commitPipelineInfoTableSubHeader )
930
940
cur = renderTableWithDivider (cur , func (cur ascii.Cursor ) ascii.Cursor {
931
- return commitPipelineInfoTable .Render (cur , table.RenderOptions {}, commitPipelineInfoIter )
941
+ return commitPipelineInfoTable .Render (cur , table.RenderOptions {}, oneItemIter ( commitPipelineInfoContents ) )
932
942
}, max (commitPipelineInfoTable .CumulativeFieldWidth , cur .Column ()), - 3 )
933
943
934
944
iteratorInfoContents := iteratorInfo {
@@ -940,13 +950,10 @@ func (m *Metrics) String() string {
940
950
sstableItersOpen : humanizeCount (m .TableIters ).String (),
941
951
snapshotsOpen : humanizeCount (m .Snapshots .Count ).String (),
942
952
}
943
- iteratorInfoIter := func (yield func (iteratorInfo ) bool ) {
944
- yield (iteratorInfoContents )
945
- }
946
953
cur = cur .WriteString (iteratorInfoTableTopHeader ).NewlineReturn ()
947
954
cur = cur .WriteString (iteratorInfoTableSubHeader )
948
955
cur = renderTableWithDivider (cur , func (cur ascii.Cursor ) ascii.Cursor {
949
- return iteratorInfoTable .Render (cur , table.RenderOptions {}, iteratorInfoIter )
956
+ return iteratorInfoTable .Render (cur , table.RenderOptions {}, oneItemIter ( iteratorInfoContents ) )
950
957
}, max (iteratorInfoTable .CumulativeFieldWidth , cur .Column ()), - 3 )
951
958
952
959
status := fmt .Sprintf ("%s pending" , humanizeCount (m .Table .PendingStatsCollectionCount ))
@@ -956,28 +963,23 @@ func (m *Metrics) String() string {
956
963
status = "all loaded"
957
964
}
958
965
tableInfoContents := tableInfo {
959
- stats : status ,
960
- backing : fmt .Sprintf ("%s (%d)" , humanizeBytes (m .Table .BackingTableSize ), m .Table .BackingTableCount ),
961
- zombie : fmt .Sprintf ("%s (%d)" , humanizeBytes (m .Table .ZombieSize ), m .Table .ZombieCount ),
962
- localZombie : humanizeBytes (m .Table .Local .ZombieSize ).String (),
966
+ stats : status ,
967
+ backing : fmt .Sprintf ("%s (%s)" , humanizeCount (m .Table .BackingTableCount ), humanizeBytes (m .Table .BackingTableSize )),
968
+ zombie : fmt .Sprintf ("%s (%s local:%s)" , humanizeCount (m .Table .ZombieCount ), humanizeBytes (m .Table .ZombieSize ), humanizeBytes (m .Table .Local .ZombieSize )),
963
969
}
964
970
blobInfoContents := blobInfo {
965
- live : fmt .Sprintf ("%s (%s)" , humanizeCount (m .BlobFiles .LiveCount ), humanizeBytes (m .BlobFiles .LiveSize )),
966
- zombie : fmt .Sprintf ("%s (%s)" , humanizeCount (m .BlobFiles .ZombieCount ), humanizeBytes (m .BlobFiles .ZombieSize )),
967
- total : humanizeBytes (m .BlobFiles .ValueSize ).String (),
968
- referenced : humanizeBytes (m .BlobFiles .ReferencedValueSize ).String (),
969
- referencedPercent : fmt .Sprintf ("%.0f%%" , percent (m .BlobFiles .ReferencedValueSize , m .BlobFiles .ValueSize )),
971
+ live : fmt .Sprintf ("%s (%s)" , humanizeCount (m .BlobFiles .LiveCount ), humanizeBytes (m .BlobFiles .LiveSize )),
972
+ zombie : fmt .Sprintf ("%s (%s)" , humanizeCount (m .BlobFiles .ZombieCount ), humanizeBytes (m .BlobFiles .ZombieSize )),
973
+ total : humanizeBytes (m .BlobFiles .ValueSize ).String (),
974
+ referenced : fmt .Sprintf ("%.0f%% (%s)" , percent (m .BlobFiles .ReferencedValueSize , m .BlobFiles .ValueSize ), humanizeBytes (m .BlobFiles .ReferencedValueSize )),
970
975
}
971
976
fileInfoContents := tableAndBlobInfo {
972
977
tableInfo : tableInfoContents ,
973
978
blobInfo : blobInfoContents ,
974
979
}
975
- fileInfoIter := func (yield func (tableAndBlobInfo ) bool ) {
976
- yield (fileInfoContents )
977
- }
978
980
cur = cur .WriteString (fileInfoTableHeader )
979
981
cur = renderTableWithDivider (cur , func (cur ascii.Cursor ) ascii.Cursor {
980
- return fileInfoTable .Render (cur , table.RenderOptions {}, fileInfoIter )
982
+ return fileInfoTable .Render (cur , table.RenderOptions {}, oneItemIter ( fileInfoContents ) )
981
983
}, max (fileInfoTable .CumulativeFieldWidth , cur .Column ()), - 2 )
982
984
983
985
var inUseTotal uint64
@@ -996,12 +998,9 @@ func (m *Metrics) String() string {
996
998
bcEnts : humanizeBytes (inUse (manual .BlockCacheEntry )).String (),
997
999
memtablesTot : humanizeBytes (inUse (manual .MemTable )).String (),
998
1000
}
999
- cgoMemInfoIter := func (yield func (cgoMemInfo ) bool ) {
1000
- yield (cgoMemInfoContents )
1001
- }
1002
1001
cur = cur .WriteString (cgoMemInfoTableHeader )
1003
1002
cur = renderTableWithDivider (cur , func (cur ascii.Cursor ) ascii.Cursor {
1004
- return cgoMemInfoTable .Render (cur , table.RenderOptions {}, cgoMemInfoIter )
1003
+ return cgoMemInfoTable .Render (cur , table.RenderOptions {}, oneItemIter ( cgoMemInfoContents ) )
1005
1004
}, max (cgoMemInfoTable .CumulativeFieldWidth , cur .Column ()), - 2 )
1006
1005
1007
1006
compactionMetricsInfoContents := compactionMetricsInfo {
@@ -1013,12 +1012,9 @@ func (m *Metrics) String() string {
1013
1012
failed : m .Compact .FailedCount ,
1014
1013
problemSpans : fmt .Sprintf ("%d%s" , m .Compact .NumProblemSpans , ifNonZero (m .Compact .NumProblemSpans , "!!" )),
1015
1014
}
1016
- compactionMetricsInfoIter := func (yield func (compactionMetricsInfo ) bool ) {
1017
- yield (compactionMetricsInfoContents )
1018
- }
1019
1015
cur = cur .WriteString (compactionInfoTableTopHeader )
1020
1016
cur = renderTableWithDivider (cur , func (cur ascii.Cursor ) ascii.Cursor {
1021
- return compactionInfoTable .Render (cur , table.RenderOptions {}, compactionMetricsInfoIter )
1017
+ return compactionInfoTable .Render (cur , table.RenderOptions {}, oneItemIter ( compactionMetricsInfoContents ) )
1022
1018
}, max (compactionInfoTable .CumulativeFieldWidth , cur .Column ()), - 2 )
1023
1019
1024
1020
keysInfoContents := keysInfo {
@@ -1028,12 +1024,9 @@ func (m *Metrics) String() string {
1028
1024
pointDels : humanizeBytes (m .Table .Garbage .PointDeletionsBytesEstimate ).String (),
1029
1025
rangeDels : humanizeBytes (m .Table .Garbage .RangeDeletionsBytesEstimate ).String (),
1030
1026
}
1031
- keysInfoIter := func (yield func (keysInfo ) bool ) {
1032
- yield (keysInfoContents )
1033
- }
1034
1027
cur = cur .WriteString (keysInfoTableTopHeader )
1035
1028
cur = renderTableWithDivider (cur , func (cur ascii.Cursor ) ascii.Cursor {
1036
- return keysInfoTable .Render (cur , table.RenderOptions {}, keysInfoIter )
1029
+ return keysInfoTable .Render (cur , table.RenderOptions {}, oneItemIter ( keysInfoContents ) )
1037
1030
}, max (keysInfoTable .CumulativeFieldWidth , cur .Column ()), - 2 )
1038
1031
cur .Offset (- 1 , 0 ).RepeatByte (max (keysInfoTable .CumulativeFieldWidth , cur .Column ()), '-' )
1039
1032
@@ -1125,3 +1118,9 @@ func humanizeCount[T crhumanize.Integer](value T) crhumanize.SafeString {
1125
1118
func humanizeBytes [T crhumanize.Integer ](value T ) crhumanize.SafeString {
1126
1119
return crhumanize .Bytes (value , crhumanize .Compact , crhumanize .OmitI )
1127
1120
}
1121
+
1122
+ func oneItemIter [T any ](v T ) iter.Seq [T ] {
1123
+ return func (yield func (T ) bool ) {
1124
+ yield (v )
1125
+ }
1126
+ }
0 commit comments