@@ -48,6 +48,9 @@ type ThroughputMetric = base.ThroughputMetric
4848// file system.
4949type SecondaryCacheMetrics = sharedcache.Metrics
5050
51+ // AllLevelMetrics contains LevelMetrics for each level.
52+ type AllLevelMetrics [manifest .NumLevels ]LevelMetrics
53+
5154// LevelMetrics holds per-level metrics such as the number of files and total
5255// size of the files, and compaction related metrics.
5356type LevelMetrics struct {
@@ -200,82 +203,11 @@ var categoryGet = block.RegisterCategory("pebble-get", block.LatencySensitiveQoS
200203// metrics reflect those operations.
201204type Metrics struct {
202205 BlockCache CacheMetrics
203-
204- Compact struct {
205- // The total number of compactions, and per-compaction type counts.
206- Count int64
207- DefaultCount int64
208- DeleteOnlyCount int64
209- ElisionOnlyCount int64
210- CopyCount int64
211- MoveCount int64
212- ReadCount int64
213- TombstoneDensityCount int64
214- RewriteCount int64
215- MultiLevelCount int64
216- BlobFileRewriteCount int64
217- VirtualRewriteCount int64
218- // An estimate of the number of bytes that need to be compacted for the LSM
219- // to reach a stable state.
220- EstimatedDebt uint64
221- // Number of bytes present in sstables being written by in-progress
222- // compactions. This value will be zero if there are no in-progress
223- // compactions.
224- InProgressBytes int64
225- // Number of compactions that are in-progress.
226- NumInProgress int64
227- // Number of compactions that were cancelled.
228- CancelledCount int64
229- // CancelledBytes the number of bytes written by compactions that were
230- // cancelled.
231- CancelledBytes int64
232- // Total number of compactions that hit an error.
233- FailedCount int64
234- // NumProblemSpans is the current (instantaneous) count of "problem spans"
235- // which temporarily block compactions.
236- NumProblemSpans int
237- // MarkedFiles is a count of files that are marked for
238- // compaction. Such files are compacted in a rewrite compaction
239- // when no other compactions are picked.
240- MarkedFiles int
241- // Duration records the cumulative duration of all compactions since the
242- // database was opened.
243- Duration time.Duration
244- }
245-
246- Ingest struct {
247- // The total number of ingestions
248- Count uint64
249- // The number of excise operations during ingestion
250- ExciseIngestCount int64
251- }
252-
253- Flush struct {
254- // The total number of flushes.
255- Count int64
256- // TODO(sumeer): the IdleDuration in this metric is flawed. It only
257- // measures idle duration when a flush finishes, representing the idleness
258- // before the start of a flush. So computing deltas over this metric over
259- // some time interval D may observe the sum of IdleDuration+WorkDuration
260- // to be either much smaller or much larger than D.
261- WriteThroughput ThroughputMetric
262- // Number of flushes that are in-progress. In the current implementation
263- // this will always be zero or one.
264- NumInProgress int64
265- // AsIngestCount is a monotonically increasing counter of flush operations
266- // handling ingested tables.
267- AsIngestCount uint64
268- // AsIngestCount is a monotonically increasing counter of tables ingested as
269- // flushables.
270- AsIngestTableCount uint64
271- // AsIngestBytes is a monotonically increasing counter of the bytes flushed
272- // for flushables that originated as ingestion operations.
273- AsIngestBytes uint64
274- }
275-
276- Filter FilterMetrics
277-
278- Levels [numLevels ]LevelMetrics
206+ Compact CompactMetrics
207+ Ingest IngestMetrics
208+ Flush FlushMetrics
209+ Filter FilterMetrics
210+ Levels AllLevelMetrics
279211
280212 MemTable struct {
281213 // The number of bytes allocated by memtables and large (flushable)
@@ -293,16 +225,7 @@ type Metrics struct {
293225 ZombieCount int64
294226 }
295227
296- Keys struct {
297- // The approximate count of internal range key set keys in the database.
298- RangeKeySetsCount uint64
299- // The approximate count of internal tombstones (DEL, SINGLEDEL and
300- // RANGEDEL key kinds) within the database.
301- TombstoneCount uint64
302- // A cumulative total number of missized DELSIZED keys encountered by
303- // compactions since the database was opened.
304- MissizedTombstonesCount uint64
305- }
228+ Keys KeysMetrics
306229
307230 Snapshots struct {
308231 // The number of currently open snapshots.
@@ -454,6 +377,92 @@ type Metrics struct {
454377 manualMemory manual.Metrics
455378}
456379
380+ // CompactMetrics contains metric related to compaction activity.
381+ type CompactMetrics struct {
382+ // The total number of compactions, and per-compaction type counts.
383+ Count int64
384+ DefaultCount int64
385+ DeleteOnlyCount int64
386+ ElisionOnlyCount int64
387+ CopyCount int64
388+ MoveCount int64
389+ ReadCount int64
390+ TombstoneDensityCount int64
391+ RewriteCount int64
392+ MultiLevelCount int64
393+ BlobFileRewriteCount int64
394+ VirtualRewriteCount int64
395+ // An estimate of the number of bytes that need to be compacted for the LSM
396+ // to reach a stable state.
397+ EstimatedDebt uint64
398+ // Number of bytes present in sstables being written by in-progress
399+ // compactions. This value will be zero if there are no in-progress
400+ // compactions.
401+ InProgressBytes int64
402+ // Number of compactions that are in-progress.
403+ NumInProgress int64
404+ // Number of compactions that were cancelled.
405+ CancelledCount int64
406+ // CancelledBytes the number of bytes written by compactions that were
407+ // cancelled.
408+ CancelledBytes int64
409+ // Total number of compactions that hit an error.
410+ FailedCount int64
411+ // NumProblemSpans is the current (instantaneous) count of "problem spans"
412+ // which temporarily block compactions.
413+ NumProblemSpans int
414+ // MarkedFiles is a count of files that are marked for
415+ // compaction. Such files are compacted in a rewrite compaction
416+ // when no other compactions are picked.
417+ MarkedFiles int
418+ // Duration records the cumulative duration of all compactions since the
419+ // database was opened.
420+ Duration time.Duration
421+ }
422+
423+ // IngestMetrics contains metrics related to ingestions.
424+ type IngestMetrics struct {
425+ // The total number of ingestions
426+ Count uint64
427+ // The number of excise operations during ingestion
428+ ExciseIngestCount int64
429+ }
430+
431+ // FlushMetrics contains metrics related to flush activity.
432+ type FlushMetrics struct {
433+ // The total number of flushes.
434+ Count int64
435+ // TODO(sumeer): the IdleDuration in this metric is flawed. It only
436+ // measures idle duration when a flush finishes, representing the idleness
437+ // before the start of a flush. So computing deltas over this metric over
438+ // some time interval D may observe the sum of IdleDuration+WorkDuration
439+ // to be either much smaller or much larger than D.
440+ WriteThroughput ThroughputMetric
441+ // Number of flushes that are in-progress. In the current implementation
442+ // this will always be zero or one.
443+ NumInProgress int64
444+ // AsIngestCount is a monotonically increasing counter of flush operations
445+ // handling ingested tables.
446+ AsIngestCount uint64
447+ // AsIngestCount is a monotonically increasing counter of tables ingested as
448+ // flushables.
449+ AsIngestTableCount uint64
450+ // AsIngestBytes is a monotonically increasing counter of the bytes flushed
451+ // for flushables that originated as ingestion operations.
452+ AsIngestBytes uint64
453+ }
454+
455+ type KeysMetrics struct {
456+ // The approximate count of internal range key set keys in the database.
457+ RangeKeySetsCount uint64
458+ // The approximate count of internal tombstones (DEL, SINGLEDEL and
459+ // RANGEDEL key kinds) within the database.
460+ TombstoneCount uint64
461+ // A cumulative total number of missized DELSIZED keys encountered by
462+ // compactions since the database was opened.
463+ MissizedTombstonesCount uint64
464+ }
465+
457466// CompressionMetrics contains compression metrics for sstables or blob files.
458467type CompressionMetrics struct {
459468 // NoCompressionBytes is the total number of bytes in files that do are not
@@ -566,18 +575,7 @@ func (m *Metrics) ReadAmp() int {
566575
567576// Total returns the sum of the per-level metrics and WAL metrics.
568577func (m * Metrics ) Total () LevelMetrics {
569- var total LevelMetrics
570- for level := 0 ; level < numLevels ; level ++ {
571- l := & m .Levels [level ]
572- total .Add (l )
573- }
574- // Compute total bytes-in as the bytes written to the WAL + bytes ingested.
575- total .TableBytesIn = m .WAL .BytesWritten + total .TablesIngested .Bytes
576- // Add the total bytes-in to the total bytes-flushed. This is to account for
577- // the bytes written to the log and bytes written externally and then
578- // ingested.
579- total .TablesFlushed .Bytes += total .TableBytesIn
580- return total
578+ return m .Levels .Total (m .WAL .BytesWritten )
581579}
582580
583581// RemoteTablesTotal returns the total number of remote tables and their total
@@ -934,14 +932,14 @@ func (m *Metrics) String() string {
934932 cur = cur .WriteString (levelMetricsTableTopHeader ).NewlineReturn ()
935933 cur = levelMetricsTable .Render (cur , table.RenderOptions {
936934 HorizontalDividers : table .MakeHorizontalDividers (0 , - 1 ),
937- }, slices .Collect (m .LevelMetricsIter ( ))... )
935+ }, slices .Collect (m .Levels . Iter ( m . WAL . BytesWritten ))... )
938936 cur = cur .NewlineReturn ()
939937
940938 // Compaction level metrics.
941939 cur = cur .WriteString (levelCompactionMetricsTableTopHeader ).NewlineReturn ()
942940 cur = compactionLevelMetricsTable .Render (cur , table.RenderOptions {
943941 HorizontalDividers : table .MakeHorizontalDividers (0 , - 1 ),
944- }, slices .Collect (m .LevelMetricsIter ( ))... )
942+ }, slices .Collect (m .Levels . Iter ( m . WAL . BytesWritten ))... )
945943
946944 cur = cur .NewlineReturn ()
947945 cur = compactionKindTable .Render (cur , table.RenderOptions {
@@ -1139,18 +1137,6 @@ func (m *Metrics) String() string {
11391137 return wb .String ()
11401138}
11411139
1142- func (m * Metrics ) LevelMetricsString () string {
1143- wb := ascii .Make (128 /* width */ , 80 /* height */ )
1144-
1145- // LSM level metrics.
1146- cur := wb .At (0 , 0 )
1147- cur = cur .WriteString (levelMetricsTableTopHeader ).NewlineReturn ()
1148- levelMetricsTable .Render (cur , table.RenderOptions {
1149- HorizontalDividers : table .MakeHorizontalDividers (0 , - 1 ),
1150- }, slices .Collect (m .LevelMetricsIter ())... )
1151- return wb .String ()
1152- }
1153-
11541140func ifNonZero [T constraints.Integer ](v T , s string ) string {
11551141 if v > 0 {
11561142 return s
@@ -1205,25 +1191,52 @@ func (m *Metrics) StringForTests() string {
12051191 return redact .StringWithoutMarkers (& mCopy )
12061192}
12071193
1208- // LevelMetricsIter returns an iterator over all level metrics - including the
1209- // total for all levels.
1210- func (m * Metrics ) LevelMetricsIter () iter.Seq [* LevelMetrics ] {
1194+ // Total returns the sum of the per-level metrics and WAL metrics.
1195+ func (lm * AllLevelMetrics ) Total (walBytesWritten uint64 ) LevelMetrics {
1196+ var total LevelMetrics
1197+ for level := range lm {
1198+ total .Add (& lm [level ])
1199+ }
1200+ // Compute total bytes-in as the bytes written to the WAL + bytes ingested.
1201+ total .TableBytesIn = walBytesWritten + total .TablesIngested .Bytes
1202+ // Add the total bytes-in to the total bytes-flushed. This is to account for
1203+ // the bytes written to the log and bytes written externally and then
1204+ // ingested.
1205+ total .TablesFlushed .Bytes += total .TableBytesIn
1206+ return total
1207+ }
1208+
1209+ // Iter returns an iterator over all level metrics - including the total for all
1210+ // levels.
1211+ func (lm * AllLevelMetrics ) Iter (walBytesWritten uint64 ) iter.Seq [* LevelMetrics ] {
12111212 return func (yield func (* LevelMetrics ) bool ) {
1212- for i := range m . Levels {
1213- lvlMetric := m . Levels [i ]
1213+ for i := range lm {
1214+ lvlMetric := lm [i ]
12141215 if lvlMetric .Score == 0 {
12151216 lvlMetric .Score = math .NaN ()
12161217 }
12171218 if ! yield (& lvlMetric ) {
12181219 break
12191220 }
12201221 }
1221- t := m .Total ()
1222+ t := lm .Total (walBytesWritten )
12221223 t .Score , t .FillFactor , t .CompensatedFillFactor = math .NaN (), math .NaN (), math .NaN ()
12231224 yield (& t )
12241225 }
12251226}
12261227
1228+ func (lm * AllLevelMetrics ) String () string {
1229+ wb := ascii .Make (128 /* width */ , 80 /* height */ )
1230+
1231+ // LSM level metrics.
1232+ cur := wb .At (0 , 0 )
1233+ cur = cur .WriteString (levelMetricsTableTopHeader ).NewlineReturn ()
1234+ levelMetricsTable .Render (cur , table.RenderOptions {
1235+ HorizontalDividers : table .MakeHorizontalDividers (0 , - 1 ),
1236+ }, slices .Collect (lm .Iter (0 ))... )
1237+ return wb .String ()
1238+ }
1239+
12271240// levelMetricsDelta accumulates incremental ("delta") level metric updates
12281241// (e.g. from compactions or flushes).
12291242type levelMetricsDelta [manifest .NumLevels ]* LevelMetrics
@@ -1235,10 +1248,10 @@ func (m *levelMetricsDelta) level(level int) *LevelMetrics {
12351248 return m [level ]
12361249}
12371250
1238- func (m * Metrics ) updateLevelMetrics (updates levelMetricsDelta ) {
1251+ func (lm * AllLevelMetrics ) update (updates levelMetricsDelta ) {
12391252 for i , u := range updates {
12401253 if u != nil {
1241- m . Levels [i ].Add (u )
1254+ lm [i ].Add (u )
12421255 }
12431256 }
12441257}
0 commit comments