@@ -239,44 +239,12 @@ type TableMetadata struct {
239239 // BlobReferences is a list of blob files containing values that are
240240 // referenced by this sstable.
241241 BlobReferences []BlobReference
242- // BlobReferenceDepth is an upper bound on the number of blob files that a
243- // reader scanning the table would need to keep open if they only open and
244- // close referenced blob files once. In other words, it's the stack depth of
245- // blob files referenced by this sstable. If a flush or compaction rewrites
246- // an sstable's values to a new blob file, the resulting sstable has a blob
247- // reference depth of 1. When a compaction reuses blob references, the max
248- // blob reference depth of the files in each level is used, and then the
249- // depth is summed, and assigned to the output. This is a loose upper bound
250- // (assuming worst case distribution of keys in all inputs) but avoids
251- // tracking key spans for references and using key comparisons.
252- //
253- // Because the blob reference depth is the size of the working set of blob
254- // files referenced by the table, it cannot exceed the count of distinct
255- // blob file references.
256- //
257- // Example: Consider a compaction of file f0 from L0 and files f1, f2, f3
258- // from L1, where the former has blob reference depth of 1 and files f1, f2,
259- // f3 all happen to have a blob-reference-depth of 1. Say we produce many
260- // output files, one of which is f4. We are assuming here that the blobs
261- // referenced by f0 whose keys happened to be written to f4 are spread all
262- // across the key span of f4. Say keys from f1 and f2 also made their way to
263- // f4. Then we will first have keys that refer to blobs referenced by f1,f0
264- // and at some point once we move past the keys of f1, we will have keys
265- // that refer to blobs referenced by f2,f0. In some sense, we have a working
266- // set of 2 blob files at any point in time, and this is similar to the idea
267- // of level stack depth for reads -- hence we adopt the depth terminology.
268- // We want to keep this stack depth in check, since locality is important,
269- // while allowing it to be higher than 1, since otherwise we will need to
270- // rewrite blob files in every compaction (defeating the write amp benefit
271- // we are looking for). Similar to the level depth, this simplistic analysis
272- // does not take into account distribution of keys involved in the
273- // compaction and which of them have blob references. Also the locality is
274- // actually better than in this analysis because more of the keys will be
275- // from the lower level.
242+ // BlobReferenceDepth is the stack depth of blob files referenced by this
243+ // sstable. See the comment on the BlobReferenceDepth type for more details.
276244 //
277245 // INVARIANT: BlobReferenceDepth == 0 iff len(BlobReferences) == 0
278246 // INVARIANT: BlobReferenceDepth <= len(BlobReferences)
279- BlobReferenceDepth int
247+ BlobReferenceDepth BlobReferenceDepth
280248
281249 // refs is the reference count for the table, used to determine when a table
282250 // is obsolete. When a table's reference count falls to zero, the table is
@@ -970,7 +938,7 @@ func ParseTableMetadataDebug(s string) (_ *TableMetadata, err error) {
970938 p .Expect (";" )
971939 p .Expect ("depth" )
972940 p .Expect (":" )
973- m .BlobReferenceDepth = int (p .Uint64 ())
941+ m .BlobReferenceDepth = BlobReferenceDepth (p .Uint64 ())
974942 p .Expect ("]" )
975943
976944 default :
@@ -1076,7 +1044,7 @@ func (m *TableMetadata) Validate(cmp Compare, formatKey base.FormatKey) error {
10761044 // Assert that there's a nonzero blob reference depth if and only if the
10771045 // table has a nonzero count of blob references. Additionally, the file's
10781046 // blob reference depth should be bounded by the number of blob references.
1079- if (len (m .BlobReferences ) == 0 ) != (m .BlobReferenceDepth == 0 ) || m .BlobReferenceDepth > len (m .BlobReferences ) {
1047+ if (len (m .BlobReferences ) == 0 ) != (m .BlobReferenceDepth == 0 ) || m .BlobReferenceDepth > BlobReferenceDepth ( len (m .BlobReferences ) ) {
10801048 return base .CorruptionErrorf ("table %s with %d blob refs but %d blob ref depth" ,
10811049 m .FileNum , len (m .BlobReferences ), m .BlobReferenceDepth )
10821050 }
0 commit comments