Skip to content

Commit e1b5f11

Browse files
committed
manifest: remove btree memory abuse
We currently allocate either a `leafNode` or a `node` and cast between them. This is potentially unsafe, since at times we are holding a `*node`, part of which is outside a `leafNode` object. We remove this hack by moving the children list to a separate object and having a pointer to it inside `node`. We also move the `subtreeCount` to save space, since it is not useful in the leaves (this offsets the size of the extra pointer for leaves, which are the vast majority). The separate object is still allocated together with the inner node, so this does not increase the number of allocations. Fixes #5200
1 parent bdb0b35 commit e1b5f11

File tree

5 files changed

+173
-163
lines changed

5 files changed

+173
-163
lines changed

internal/manifest/annotator.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ func (a *Annotator[T]) nodeAnnotation(n *node[*TableMetadata]) (t *T, cacheOK bo
126126
valid := true
127127

128128
for i := int16(0); i <= n.count; i++ {
129-
if !n.leaf {
130-
v, ok := a.nodeAnnotation(n.children[i])
129+
if !n.isLeaf() {
130+
v, ok := a.nodeAnnotation(n.child(i))
131131
t = a.Aggregator.Merge(v, t)
132132
valid = valid && ok
133133
}
@@ -202,7 +202,7 @@ func (a *Annotator[T]) accumulateRangeAnnotation(
202202
dst = v
203203
}
204204

205-
if !n.leaf {
205+
if !n.isLeaf() {
206206
// We will accumulate annotations from each child in the end-inclusive
207207
// range [leftChild, rightChild].
208208
leftChild, rightChild := leftItem, rightItem
@@ -219,7 +219,7 @@ func (a *Annotator[T]) accumulateRangeAnnotation(
219219

220220
for i := leftChild; i <= rightChild; i++ {
221221
dst = a.accumulateRangeAnnotation(
222-
n.children[i],
222+
n.child(int16(i)),
223223
cmp,
224224
bounds,
225225
// If this child is to the right of leftItem, then its entire
@@ -240,9 +240,9 @@ func (a *Annotator[T]) accumulateRangeAnnotation(
240240
func (a *Annotator[T]) invalidateNodeAnnotation(n *node[*TableMetadata]) {
241241
annot := a.findAnnotation(n)
242242
annot.valid.Store(false)
243-
if !n.leaf {
243+
if !n.isLeaf() {
244244
for i := int16(0); i <= n.count; i++ {
245-
a.invalidateNodeAnnotation(n.children[i])
245+
a.invalidateNodeAnnotation(n.child(i))
246246
}
247247
}
248248
}

internal/manifest/blob_metadata.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,10 @@ func (s *BlobFileSet) LookupPhysical(fileID base.BlobFileID) (*PhysicalBlobFile,
387387
}
388388
// If we've reached a lead node without finding fileID, the file is not
389389
// present.
390-
if n.leaf {
390+
if n.isLeaf() {
391391
return nil, false
392392
}
393-
n = n.children[i]
393+
n = n.child(int16(i))
394394
}
395395
return nil, false
396396
}

0 commit comments

Comments
 (0)