Skip to content

Commit 518b3cb

Browse files
committed
internal/manifest: dont put backing into rewrite heap if it is external
These virtual tables need to be materialized separately and shouldn't be chosen through a virtual sst rewrite compaction.
1 parent 21b9fb5 commit 518b3cb

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

internal/manifest/virtual_backings.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ func MakeVirtualBackings() VirtualBackings {
9191
type backingWithMetadata struct {
9292
backing *TableBacking
9393

94+
// isLocal is true if the backing's fileNum is local to the file system.
95+
isLocal bool
96+
9497
// protectionCount is used by Protect to temporarily prevent a backing from
9598
// being reported as unused.
9699
protectionCount int32
@@ -114,12 +117,13 @@ func (bm *backingWithMetadata) referencedDataPct() float64 {
114117
//
115118
// The added backing is unused until it is associated with a table via AddTable
116119
// or protected via Protect.
117-
func (bv *VirtualBackings) AddAndRef(backing *TableBacking) {
120+
func (bv *VirtualBackings) AddAndRef(backing *TableBacking, isLocal bool) {
118121
// We take a reference on the backing because in case of protected backings
119122
// (see Protect), we might be the only ones holding on to a backing.
120123
backing.Ref()
121124
bm := &backingWithMetadata{
122125
backing: backing,
126+
isLocal: isLocal,
123127
virtualTables: make(map[base.TableNum]tableAndLevel),
124128
heapIndex: -1,
125129
}
@@ -167,10 +171,12 @@ func (bv *VirtualBackings) AddTable(m *TableMetadata, level int) {
167171
level: level,
168172
}
169173
// Update candidates heap.
170-
if v.heapIndex == -1 {
171-
heap.Push(&bv.rewriteCandidates, v)
172-
} else {
173-
heap.Fix(&bv.rewriteCandidates, v.heapIndex)
174+
if v.isLocal {
175+
if v.heapIndex == -1 {
176+
heap.Push(&bv.rewriteCandidates, v)
177+
} else {
178+
heap.Fix(&bv.rewriteCandidates, v.heapIndex)
179+
}
174180
}
175181
}
176182

@@ -323,6 +329,9 @@ func (bv *VirtualBackings) String() string {
323329
v := bv.m[n]
324330
fmt.Fprintf(&buf, " %s: size=%d refBlobValueSize=%d useCount=%d protectionCount=%d virtualizedSize=%d",
325331
n, v.backing.Size, v.backing.ReferencedBlobValueSizeTotal, len(v.virtualTables), v.protectionCount, v.virtualizedSize)
332+
if !v.isLocal {
333+
fmt.Fprintf(&buf, " (external)")
334+
}
326335
tableNums := slices.Sorted(maps.Keys(v.virtualTables))
327336
fmt.Fprintf(&buf, " tables: %v\n", tableNums)
328337
}

internal/manifest/virtual_backings_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestVirtualBackings(t *testing.T) {
3737
DiskFileNum: n,
3838
Size: size,
3939
ReferencedBlobValueSizeTotal: blobValueSize,
40-
})
40+
}, true /* local */)
4141

4242
case "remove":
4343
bv.Remove(n)

version_set.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ func (vs *versionSet) load(
317317
// Populate the virtual backings for virtual sstables since we have finished
318318
// version edit accumulation.
319319
for _, b := range bve.AddedFileBacking {
320-
vs.latest.virtualBackings.AddAndRef(b)
320+
isLocal := objstorage.IsLocalTable(provider, b.DiskFileNum)
321+
vs.latest.virtualBackings.AddAndRef(b, isLocal)
321322
}
322323

323324
for l, addedLevel := range bve.AddedTables {
@@ -865,8 +866,8 @@ func getZombieTablesAndUpdateVirtualBackings(
865866
// When a virtual table moves between levels we RemoveTable() then AddTable(),
866867
// which works out.
867868
for _, b := range ve.CreatedBackingTables {
868-
virtualBackings.AddAndRef(b)
869869
isLocal, localFileDelta := sizeIfLocal(b, provider)
870+
virtualBackings.AddAndRef(b, isLocal)
870871
localLiveDelta.size += localFileDelta
871872
if isLocal {
872873
localLiveDelta.count++

0 commit comments

Comments
 (0)