@@ -7,9 +7,10 @@ import (
77
88// NodePointer is a pointer to a Node, which may be either in-memory, on-disk or both.
99type NodePointer struct {
10- mem atomic.Pointer [MemNode ]
11- fileIdx uint32 // absolute index in file, 1-based, zero means we don't have an offset
12- id NodeID
10+ mem atomic.Pointer [MemNode ]
11+ changeset * Changeset
12+ fileIdx uint32 // absolute index in file, 1-based, zero means we don't have an offset
13+ id NodeID
1314}
1415
1516// NewNodePointer creates a new NodePointer pointing to the given in-memory node.
@@ -19,13 +20,23 @@ func NewNodePointer(memNode *MemNode) *NodePointer {
1920 return n
2021}
2122
22- // Resolve resolves the NodePointer to a Node, loading from memory or disk as necessary.
23+ // Resolve resolves the NodePointer to a Node, loading from memory or disk as necessary
24+ // as well as a Pin which MUST be unpinned after the caller is done using the node.
25+ // Resolve will ALWAYS return a valid Pin even if there is an error. For clarity and
26+ // consistency it is recommended to introduce a defer pin.Unpin() immediately after
27+ // calling Resolve and BEFORE checking the error return value like this:
28+ //
29+ // node, pin, err := nodePointer.Resolve()
30+ // defer pin.Unpin()
31+ // if err != nil {
32+ // // handle error
33+ // }
2334func (p * NodePointer ) Resolve () (Node , Pin , error ) {
2435 mem := p .mem .Load ()
2536 if mem != nil {
2637 return mem , NoopPin {}, nil
2738 }
28- panic ( " not implemented: loading from disk" )
39+ return nil , NoopPin {}, fmt . Errorf ( "node not in memory and on- disk loading will be implemented in a future PR " )
2940}
3041
3142// String implements the fmt.Stringer interface.
0 commit comments