@@ -501,9 +501,12 @@ type DB struct {
501
501
// annotators contains various instances of manifest.Annotator which
502
502
// should be protected from concurrent access.
503
503
annotators struct {
504
- totalSize * manifest.Annotator [uint64 ]
505
- remoteSize * manifest.Annotator [uint64 ]
506
- externalSize * manifest.Annotator [uint64 ]
504
+ // totalFileSize is the sum of the size of all files in the
505
+ // database. This includes local, remote, and external sstables --
506
+ // along with blob files.
507
+ totalFileSize * manifest.Annotator [uint64 ]
508
+ remoteSize * manifest.Annotator [uint64 ]
509
+ externalSize * manifest.Annotator [uint64 ]
507
510
}
508
511
}
509
512
@@ -2375,24 +2378,30 @@ func (d *DB) SSTables(opts ...SSTablesOption) ([][]SSTableInfo, error) {
2375
2378
return destLevels , nil
2376
2379
}
2377
2380
2378
- // makeFileSizeAnnotator returns an annotator that computes the total size of
2379
- // files that meet some criteria defined by filter.
2381
+ // makeFileSizeAnnotator returns an annotator that computes the total
2382
+ // storage size of files that meet some criteria defined by filter. When
2383
+ // applicable, this includes both the sstable size and the size of any
2384
+ // referenced blob files.
2380
2385
func (d * DB ) makeFileSizeAnnotator (filter func (f * tableMetadata ) bool ) * manifest.Annotator [uint64 ] {
2381
2386
return & manifest.Annotator [uint64 ]{
2382
2387
Aggregator : manifest.SumAggregator {
2383
2388
AccumulateFunc : func (f * tableMetadata ) (uint64 , bool ) {
2384
2389
if filter (f ) {
2385
- return f .Size , true
2390
+ return f .Size + f . EstimatedReferenceSize () , true
2386
2391
}
2387
2392
return 0 , true
2388
2393
},
2389
2394
AccumulatePartialOverlapFunc : func (f * tableMetadata , bounds base.UserKeyBounds ) uint64 {
2390
2395
if filter (f ) {
2391
- size , err := d .fileCache .estimateSize (f , bounds .Start , bounds .End .Key )
2396
+ overlappingFileSize , err := d .fileCache .estimateSize (f , bounds .Start , bounds .End .Key )
2392
2397
if err != nil {
2393
2398
return 0
2394
2399
}
2395
- return size
2400
+ overlapFraction := float64 (overlappingFileSize ) / float64 (f .Size )
2401
+ // Scale the blob reference size proportionally to the file
2402
+ // overlap from the bounds to approximate only the blob
2403
+ // references that overlap with the requested bounds.
2404
+ return overlappingFileSize + uint64 (float64 (f .EstimatedReferenceSize ())* overlapFraction )
2396
2405
}
2397
2406
return 0
2398
2407
},
@@ -2438,9 +2447,10 @@ func (d *DB) EstimateDiskUsageByBackingType(
2438
2447
readState := d .loadReadState ()
2439
2448
defer readState .unref ()
2440
2449
2441
- totalSize = * d .mu .annotators .totalSize .VersionRangeAnnotation (readState .current , bounds )
2450
+ totalSize = * d .mu .annotators .totalFileSize .VersionRangeAnnotation (readState .current , bounds )
2442
2451
remoteSize = * d .mu .annotators .remoteSize .VersionRangeAnnotation (readState .current , bounds )
2443
2452
externalSize = * d .mu .annotators .externalSize .VersionRangeAnnotation (readState .current , bounds )
2453
+
2444
2454
return
2445
2455
}
2446
2456
0 commit comments