@@ -32,50 +32,40 @@ type BlobReference struct {
32
32
// blob file for which there exists a reference in the sstable. Note that if
33
33
// any of the referencing tables are virtualized tables, the ValueSize may
34
34
// be approximate.
35
- //
36
- // INVARIANT: ValueSize <= Metadata.ValueSize
37
35
ValueSize uint64
38
-
39
- // OriginalMetadata is the metadata for the original physical blob file. It
40
- // is non-nil for blob references contained within active Versions. It is
41
- // expected to initially be nil when decoding a version edit as a part of
42
- // manfiest replay. When the version edit is accumulated into a bulk version
43
- // edit, the metadata is populated.
44
- //
45
- // The OriginalMetadata describes the physical blob file that existed when
46
- // the reference was originally created. The original physical blob file may
47
- // no longer exist. The BlobReference.FileID should be translated using a
48
- // Version's BlobFileSet.
49
- //
50
- // TODO(jackson): We should either remove the OriginalMetadata from the
51
- // BlobReference or use it to infer when a blob file has definitely NOT been
52
- // replaced and a lookup in Version.BlobFileSet is unnecessary.
53
- OriginalMetadata * PhysicalBlobFile
54
- }
55
-
56
- // EstimatedPhysicalSize returns an estimate of the physical size of the blob
57
- // reference, in bytes. It's calculated by scaling the blob file's physical size
58
- // according to the ValueSize of the blob reference relative to the total
59
- // ValueSize of the blob file.
60
- func (br * BlobReference ) EstimatedPhysicalSize () uint64 {
36
+ // EstimatedPhysicalSize is an estimate of the physical size of the blob
37
+ // reference, in bytes. It's calculated by scaling the blob file's physical
38
+ // size according to the ValueSize of the blob reference relative to the
39
+ // total ValueSize of the blob file.
40
+ EstimatedPhysicalSize uint64
41
+ }
42
+
43
+ // MakeBlobReference creates a BlobReference from the given file ID, value size,
44
+ // and physical blob file.
45
+ func MakeBlobReference (
46
+ fileID base.BlobFileID , valueSize uint64 , phys * PhysicalBlobFile ,
47
+ ) BlobReference {
61
48
if invariants .Enabled {
62
- if br .ValueSize > br .OriginalMetadata .ValueSize {
49
+ switch {
50
+ case valueSize > phys .ValueSize :
63
51
panic (errors .AssertionFailedf ("pebble: blob reference value size %d is greater than the blob file's value size %d" ,
64
- br .ValueSize , br .OriginalMetadata .ValueSize ))
65
- }
66
- if br .ValueSize == 0 {
67
- panic (errors .AssertionFailedf ("pebble: blob reference value size %d is zero" , br .ValueSize ))
68
- }
69
- if br .OriginalMetadata .ValueSize == 0 {
70
- panic (errors .AssertionFailedf ("pebble: blob file value size %d is zero" , br .OriginalMetadata .ValueSize ))
52
+ valueSize , phys .ValueSize ))
53
+ case valueSize == 0 :
54
+ panic (errors .AssertionFailedf ("pebble: blob reference value size %d is zero" , valueSize ))
55
+ case phys .ValueSize == 0 :
56
+ panic (errors .AssertionFailedf ("pebble: blob file value size %d is zero" , phys .ValueSize ))
71
57
}
72
58
}
73
- // br.ValueSize
74
- // Reference size = ----------------------------- × br.OriginalMetadata.Size
75
- // br.OriginalMetadata.ValueSize
76
- //
77
- // We perform the multiplication first to avoid floating point arithmetic.
78
- return (br .ValueSize * br .OriginalMetadata .Size ) / br .OriginalMetadata .ValueSize
59
+ return BlobReference {
60
+ FileID : fileID ,
61
+ ValueSize : valueSize ,
62
+ // valueSize
63
+ // Reference size = ----------------- × phys.Size
64
+ // phys.ValueSize
65
+ //
66
+ // We perform the multiplication first to avoid floating point arithmetic.
67
+ EstimatedPhysicalSize : (valueSize * phys .Size ) / phys .ValueSize ,
68
+ }
79
69
}
80
70
81
71
// BlobFileMetadata encapsulates a blob file ID used to identify a particular
@@ -475,7 +465,7 @@ type currentBlobFile struct {
475
465
// referencing table number. This would likely be more memory efficient,
476
466
// reduce overall number of pointers to chase and suffer fewer allocations
477
467
// (and we can pool the B-Tree nodes to further reduce allocs)
478
- references map [* TableMetadata ]struct {}
468
+ references map [base. TableNum ]struct {}
479
469
// referencedValueSize is the sum of the length of uncompressed values in
480
470
// this blob file that are still live.
481
471
referencedValueSize uint64
@@ -491,7 +481,7 @@ func (s *CurrentBlobFileSet) Init(bve *BulkVersionEdit) {
491
481
for blobFileID , pbf := range bve .BlobFiles .Added {
492
482
s .files [blobFileID ] = & currentBlobFile {
493
483
metadata : BlobFileMetadata {FileID : blobFileID , Physical : pbf },
494
- references : make (map [* TableMetadata ]struct {}),
484
+ references : make (map [base. TableNum ]struct {}),
495
485
}
496
486
s .stats .Count ++
497
487
s .stats .PhysicalSize += pbf .Size
@@ -506,7 +496,7 @@ func (s *CurrentBlobFileSet) Init(bve *BulkVersionEdit) {
506
496
if ! ok {
507
497
panic (errors .AssertionFailedf ("pebble: referenced blob file %d not found" , ref .FileID ))
508
498
}
509
- cbf .references [table ] = struct {}{}
499
+ cbf .references [table . TableNum ] = struct {}{}
510
500
cbf .referencedValueSize += ref .ValueSize
511
501
s .stats .ReferencedValueSize += ref .ValueSize
512
502
s .stats .ReferencesCount ++
@@ -559,7 +549,7 @@ func (s *CurrentBlobFileSet) ApplyAndUpdateVersionEdit(ve *VersionEdit) error {
559
549
}
560
550
561
551
blobFileID := m .FileID
562
- cbf := & currentBlobFile {references : make (map [* TableMetadata ]struct {})}
552
+ cbf := & currentBlobFile {references : make (map [base. TableNum ]struct {})}
563
553
cbf .metadata = BlobFileMetadata {FileID : blobFileID , Physical : m .Physical }
564
554
s .files [blobFileID ] = cbf
565
555
s .stats .Count ++
@@ -577,7 +567,7 @@ func (s *CurrentBlobFileSet) ApplyAndUpdateVersionEdit(ve *VersionEdit) error {
577
567
if ! ok {
578
568
return errors .AssertionFailedf ("pebble: referenced blob file %d not found" , ref .FileID )
579
569
}
580
- cbf .references [e .Meta ] = struct {}{}
570
+ cbf .references [e .Meta . TableNum ] = struct {}{}
581
571
cbf .referencedValueSize += ref .ValueSize
582
572
s .stats .ReferencedValueSize += ref .ValueSize
583
573
s .stats .ReferencesCount ++
@@ -600,13 +590,15 @@ func (s *CurrentBlobFileSet) ApplyAndUpdateVersionEdit(ve *VersionEdit) error {
600
590
return errors .AssertionFailedf ("pebble: referenced value size %d for blob file %s is greater than the referenced value size %d" ,
601
591
ref .ValueSize , cbf .metadata .FileID , cbf .referencedValueSize )
602
592
}
603
- if _ , ok := cbf .references [meta ]; ! ok {
604
- return errors .AssertionFailedf ("pebble: deleted table %s's reference to blob file %d not known" ,
593
+ if _ , ok := cbf .references [meta . TableNum ]; ! ok {
594
+ return errors .AssertionFailedf ("pebble: deleted table %s's reference to blob file %s not known" ,
605
595
meta .TableNum , ref .FileID )
606
596
}
607
597
}
608
598
609
- // Decrement the stats for this reference.
599
+ // Decrement the stats for this reference. We decrement even if the
600
+ // table is being moved, because we incremented the stats when we
601
+ // iterated over the version edit's new tables.
610
602
cbf .referencedValueSize -= ref .ValueSize
611
603
s .stats .ReferencedValueSize -= ref .ValueSize
612
604
s .stats .ReferencesCount --
@@ -619,7 +611,7 @@ func (s *CurrentBlobFileSet) ApplyAndUpdateVersionEdit(ve *VersionEdit) error {
619
611
continue
620
612
}
621
613
// Remove the reference of this table to this blob file.
622
- delete (cbf .references , meta )
614
+ delete (cbf .references , meta . TableNum )
623
615
624
616
// If there are no more references to the blob file, remove it from
625
617
// the set and add the removal of the blob file to the version edit.
0 commit comments