@@ -506,9 +506,10 @@ type DB struct {
506
506
// validating is set to true when validation is running.
507
507
validating bool
508
508
}
509
- fileSizeAnnotator manifest.TableAnnotator [fileSizeByBacking ]
510
509
}
511
510
511
+ fileSizeAnnotator manifest.TableAnnotator [fileSizeByBacking ]
512
+
512
513
// problemSpans keeps track of spans of keys within LSM levels where
513
514
// compactions have failed; used to avoid retrying these compactions too
514
515
// quickly.
@@ -1566,17 +1567,14 @@ func (d *DB) Close() error {
1566
1567
// Wait for all cleaning jobs to finish.
1567
1568
d .cleanupManager .Close ()
1568
1569
1569
- // Sanity check metrics.
1570
+ d .mu .Lock ()
1571
+ // Sanity check compaction metrics.
1570
1572
if invariants .Enabled {
1571
- m := d .Metrics ()
1572
- if m .Compact .NumInProgress > 0 || m .Compact .InProgressBytes > 0 {
1573
- d .mu .Lock ()
1574
- panic (fmt .Sprintf ("invalid metrics on close:\n %s" , m ))
1573
+ if d .mu .compact .compactingCount > 0 || d .mu .compact .downloadingCount > 0 || d .mu .versions .atomicInProgressBytes .Load () > 0 {
1574
+ panic ("compacting counts not 0 on close" )
1575
1575
}
1576
1576
}
1577
1577
1578
- d .mu .Lock ()
1579
-
1580
1578
// As a sanity check, ensure that there are no zombie tables or blob files.
1581
1579
// A non-zero count hints at a reference count leak.
1582
1580
if ztbls := d .mu .versions .zombieTables .Count (); ztbls > 0 {
@@ -1854,6 +1852,9 @@ func (d *DB) Metrics() *Metrics {
1854
1852
1855
1853
d .mu .Lock ()
1856
1854
vers := d .mu .versions .currentVersion ()
1855
+ vers .Ref ()
1856
+ defer vers .Unref ()
1857
+
1857
1858
* metrics = d .mu .versions .metrics
1858
1859
metrics .Compact .EstimatedDebt = d .mu .versions .picker .estimatedCompactionDebt ()
1859
1860
metrics .Compact .InProgressBytes = d .mu .versions .atomicInProgressBytes .Load ()
@@ -1936,15 +1937,6 @@ func (d *DB) Metrics() *Metrics {
1936
1937
metrics .BlobFiles .ObsoleteSize += pendingObsoleteFileStats .blobFilesAll .size
1937
1938
metrics .private .optionsFileSize = d .optionsFileSize
1938
1939
1939
- // TODO(jackson): Consider making these metrics optional.
1940
- aggProps := tablePropsAnnotator .MultiLevelAnnotation (vers .Levels [:])
1941
- metrics .Keys .RangeKeySetsCount = aggProps .NumRangeKeySets
1942
- metrics .Keys .TombstoneCount = aggProps .NumDeletions
1943
-
1944
- delBytes := deletionBytesAnnotator .MultiLevelAnnotation (vers .Levels [:])
1945
- metrics .Table .Garbage .PointDeletionsBytesEstimate = delBytes .PointDels
1946
- metrics .Table .Garbage .RangeDeletionsBytesEstimate = delBytes .RangeDels
1947
-
1948
1940
d .mu .versions .logLock ()
1949
1941
metrics .private .manifestFileSize = uint64 (d .mu .versions .manifest .Size ())
1950
1942
backingCount , backingTotalSize := d .mu .versions .latest .virtualBackings .Stats ()
@@ -1969,6 +1961,17 @@ func (d *DB) Metrics() *Metrics {
1969
1961
metrics .Table .PendingStatsCollectionCount = int64 (len (d .mu .tableStats .pending ))
1970
1962
metrics .Table .InitialStatsCollectionComplete = d .mu .tableStats .loadedInitial
1971
1963
1964
+ d .mu .Unlock ()
1965
+
1966
+ // TODO(jackson): Consider making these metrics optional.
1967
+ aggProps := tablePropsAnnotator .MultiLevelAnnotation (vers .Levels [:])
1968
+ metrics .Keys .RangeKeySetsCount = aggProps .NumRangeKeySets
1969
+ metrics .Keys .TombstoneCount = aggProps .NumDeletions
1970
+
1971
+ delBytes := deletionBytesAnnotator .MultiLevelAnnotation (vers .Levels [:])
1972
+ metrics .Table .Garbage .PointDeletionsBytesEstimate = delBytes .PointDels
1973
+ metrics .Table .Garbage .RangeDeletionsBytesEstimate = delBytes .RangeDels
1974
+
1972
1975
for i := 0 ; i < numLevels ; i ++ {
1973
1976
aggProps := tablePropsAnnotator .LevelAnnotation (vers .Levels [i ])
1974
1977
metrics .Levels [i ].Additional .ValueBlocksSize = aggProps .ValueBlocksSize
@@ -1978,8 +1981,6 @@ func (d *DB) Metrics() *Metrics {
1978
1981
blobCompressionMetrics := blobCompressionStatsAnnotator .Annotation (& vers .BlobFiles )
1979
1982
metrics .BlobFiles .Compression .MergeWith (& blobCompressionMetrics )
1980
1983
1981
- d .mu .Unlock ()
1982
-
1983
1984
metrics .BlockCache = d .opts .Cache .Metrics ()
1984
1985
metrics .FileCache , metrics .Filter = d .fileCache .Metrics ()
1985
1986
metrics .TableIters = d .fileCache .IterCount ()
0 commit comments