Skip to content

Commit cb31369

Browse files
committed
internal/manifest: genericize btree
Convert the B-Tree used for organizing and reference counting TableMetadata into a generic collection. This is in preparation for storing blob file metadata in a B-Tree for copy-on-write reference counting. The iterator type is left specialized to *TableMetadata because we will not need arbitrary iteration over the blob file B-Tree. We can consider eventually using an alternative B-Tree implementation, like the one in the btreemap package, but we would need to introduce support for copy-on-write reference counting. The existing table metadata B-Tree implementation supports the reference counting semantics we need.
1 parent 8099786 commit cb31369

File tree

7 files changed

+183
-161
lines changed

7 files changed

+183
-161
lines changed

internal/manifest/annotator.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ type annotation struct {
7979
valid atomic.Bool
8080
}
8181

82-
func (a *Annotator[T]) findExistingAnnotation(n *node) *annotation {
82+
func (a *Annotator[T]) findExistingAnnotation(n *node[*TableMetadata]) *annotation {
8383
n.annotMu.RLock()
8484
defer n.annotMu.RUnlock()
8585
for i := range n.annot {
@@ -92,7 +92,7 @@ func (a *Annotator[T]) findExistingAnnotation(n *node) *annotation {
9292

9393
// findAnnotation finds this Annotator's annotation on a node, creating
9494
// one if it doesn't already exist.
95-
func (a *Annotator[T]) findAnnotation(n *node) *annotation {
95+
func (a *Annotator[T]) findAnnotation(n *node[*TableMetadata]) *annotation {
9696
if a := a.findExistingAnnotation(n); a != nil {
9797
return a
9898
}
@@ -111,7 +111,7 @@ func (a *Annotator[T]) findAnnotation(n *node) *annotation {
111111
// nodeAnnotation computes this annotator's annotation of this node across all
112112
// files in the node's subtree. The second return value indicates whether the
113113
// annotation is stable and thus cacheable.
114-
func (a *Annotator[T]) nodeAnnotation(n *node) (t *T, cacheOK bool) {
114+
func (a *Annotator[T]) nodeAnnotation(n *node[*TableMetadata]) (t *T, cacheOK bool) {
115115
annot := a.findAnnotation(n)
116116
// If the annotation is already marked as valid, we can return it without
117117
// recomputing anything.
@@ -153,7 +153,7 @@ func (a *Annotator[T]) nodeAnnotation(n *node) (t *T, cacheOK bool) {
153153
// files in the node's subtree which overlap with the range defined by bounds.
154154
// The computed annotation is accumulated into a.scratch.
155155
func (a *Annotator[T]) accumulateRangeAnnotation(
156-
n *node,
156+
n *node[*TableMetadata],
157157
cmp base.Compare,
158158
bounds base.UserKeyBounds,
159159
// fullyWithinLowerBound and fullyWithinUpperBound indicate whether this
@@ -237,7 +237,7 @@ func (a *Annotator[T]) accumulateRangeAnnotation(
237237

238238
// InvalidateAnnotation removes any existing cached annotations from this
239239
// annotator from a node's subtree.
240-
func (a *Annotator[T]) invalidateNodeAnnotation(n *node) {
240+
func (a *Annotator[T]) invalidateNodeAnnotation(n *node[*TableMetadata]) {
241241
annot := a.findAnnotation(n)
242242
annot.valid.Store(false)
243243
if !n.leaf {

0 commit comments

Comments
 (0)