@@ -48,40 +48,67 @@ func (d *DB) EstimateDiskUsageByBackingType(
48
48
readState := d .loadReadState ()
49
49
defer readState .unref ()
50
50
51
- totalSize = * d .mu .annotators . totalFileSize .VersionRangeAnnotation (readState .current , bounds )
52
- remoteSize = * d . mu . annotators . remoteSize . VersionRangeAnnotation ( readState . current , bounds )
53
- externalSize = * d . mu . annotators . externalSize . VersionRangeAnnotation ( readState . current , bounds )
51
+ sizes := d .mu .fileSizeAnnotator .VersionRangeAnnotation (readState .current , bounds )
52
+ return sizes . totalSize , sizes . remoteSize , sizes . externalSize , nil
53
+ }
54
54
55
- return
55
+ // fileSizeByBacking contains the estimated file size for LSM data within some
56
+ // bounds. It is broken down by backing type. The file size refers to both the
57
+ // sstable size and an estimate of the referenced blob sizes.
58
+ type fileSizeByBacking struct {
59
+ // totalSize is the estimated size of all files for the given bounds.
60
+ totalSize uint64
61
+ // remoteSize is the estimated size of remote files for the given bounds.
62
+ remoteSize uint64
63
+ // externalSize is the estimated size of external files for the given bounds.
64
+ externalSize uint64
56
65
}
57
66
58
- // makeFileSizeAnnotator returns an annotator that computes the total
59
- // storage size of files that meet some criteria defined by filter. When
60
- // applicable, this includes both the sstable size and the size of any
61
- // referenced blob files.
62
- func (d * DB ) makeFileSizeAnnotator (
63
- filter func (f * manifest.TableMetadata ) bool ,
64
- ) * manifest.TableAnnotator [uint64 ] {
65
- return manifest.NewTableAnnotator [uint64 ](manifest.SumAggregator {
66
- AccumulateFunc : func (f * manifest.TableMetadata ) (uint64 , bool ) {
67
- if filter (f ) {
68
- return f .Size + f .EstimatedReferenceSize (), true
69
- }
70
- return 0 , true
67
+ func (d * DB ) singleFileSizeByBacking (
68
+ fileSize uint64 , t * manifest.TableMetadata ,
69
+ ) (_ fileSizeByBacking , ok bool ) {
70
+ res := fileSizeByBacking {
71
+ totalSize : fileSize ,
72
+ }
73
+
74
+ objMeta , err := d .objProvider .Lookup (base .FileTypeTable , t .TableBacking .DiskFileNum )
75
+ if err != nil {
76
+ return res , false
77
+ }
78
+ if objMeta .IsRemote () {
79
+ res .remoteSize += fileSize
80
+ if objMeta .IsExternal () {
81
+ res .externalSize += fileSize
82
+ }
83
+ }
84
+ return res , true
85
+ }
86
+
87
+ // makeFileSizeAnnotator returns an annotator that computes the storage size of
88
+ // files. When applicable, this includes both the sstable size and the size of
89
+ // any referenced blob files.
90
+ func (d * DB ) makeFileSizeAnnotator () * manifest.TableAnnotator [fileSizeByBacking ] {
91
+ return manifest.NewTableAnnotator [fileSizeByBacking ](manifest.SumAggregator [fileSizeByBacking ]{
92
+ AddFunc : func (src , dst * fileSizeByBacking ) {
93
+ dst .totalSize += src .totalSize
94
+ dst .remoteSize += src .remoteSize
95
+ dst .externalSize += src .externalSize
96
+ },
97
+ AccumulateFunc : func (f * manifest.TableMetadata ) (v fileSizeByBacking , cacheOK bool ) {
98
+ return d .singleFileSizeByBacking (f .Size + f .EstimatedReferenceSize (), f )
71
99
},
72
- AccumulatePartialOverlapFunc : func (f * manifest.TableMetadata , bounds base.UserKeyBounds ) uint64 {
73
- if filter (f ) {
74
- overlappingFileSize , err := d .fileCache .estimateSize (f , bounds .Start , bounds .End .Key )
75
- if err != nil {
76
- return 0
77
- }
78
- overlapFraction := float64 (overlappingFileSize ) / float64 (f .Size )
79
- // Scale the blob reference size proportionally to the file
80
- // overlap from the bounds to approximate only the blob
81
- // references that overlap with the requested bounds.
82
- return overlappingFileSize + uint64 (float64 (f .EstimatedReferenceSize ())* overlapFraction )
100
+ AccumulatePartialOverlapFunc : func (f * manifest.TableMetadata , bounds base.UserKeyBounds ) fileSizeByBacking {
101
+ overlappingFileSize , err := d .fileCache .estimateSize (f , bounds .Start , bounds .End .Key )
102
+ if err != nil {
103
+ return fileSizeByBacking {}
83
104
}
84
- return 0
105
+ overlapFraction := float64 (overlappingFileSize ) / float64 (f .Size )
106
+ // Scale the blob reference size proportionally to the file
107
+ // overlap from the bounds to approximate only the blob
108
+ // references that overlap with the requested bounds.
109
+ size := overlappingFileSize + uint64 (float64 (f .EstimatedReferenceSize ())* overlapFraction )
110
+ res , _ := d .singleFileSizeByBacking (size , f )
111
+ return res
85
112
},
86
113
})
87
114
}
0 commit comments