MCPcopy
hub / github.com/etcd-io/bbolt / node

Method node

bucket.go:863–901  ·  bucket.go::Bucket.node

node creates a node from a page and associates it with a given parent.

(pgId common.Pgid, parent *node)

Source from the content-addressed store, hash-verified

861
862// node creates a node from a page and associates it with a given parent.
863func (b *Bucket) node(pgId common.Pgid, parent *node) *node {
864 common.Assert(b.nodes != nil, "nodes map expected")
865
866 // Retrieve node if it's already been created.
867 if n := b.nodes[pgId]; n != nil {
868 return n
869 }
870
871 // Otherwise create a node and cache it.
872 n := &node{bucket: b, parent: parent}
873 if parent == nil {
874 b.rootNode = n
875 } else {
876 parent.children = append(parent.children, n)
877 }
878
879 // Use the inline page if this is an inline bucket.
880 var p = b.page
881 if p == nil {
882 p = b.tx.page(pgId)
883 } else {
884 // if p isn't nil, then it's an inline bucket.
885 // The pgId must be 0 in this case.
886 common.Verify(func() {
887 if pgId != 0 {
888 panic(fmt.Sprintf("assertion failed: The page ID (%d) isn't 0 for an inline bucket", pgId))
889 }
890 })
891 }
892
893 // Read the page into the node and cache it.
894 n.read(p)
895 b.nodes[pgId] = n
896
897 // Update statistics.
898 b.tx.stats.IncNodeCount(1)
899
900 return n
901}
902
903// free recursively frees all pages in the bucket.
904func (b *Bucket) free() {

Callers 11

SetSequenceMethod · 0.95
NextSequenceMethod · 0.95
childAtMethod · 0.45
rebalanceMethod · 0.45
CreateBucketMethod · 0.45
DeleteBucketMethod · 0.45
MoveBucketMethod · 0.45
PutMethod · 0.45
DeleteMethod · 0.45
spillMethod · 0.45

Calls 5

readMethod · 0.95
AssertFunction · 0.92
VerifyFunction · 0.92
IncNodeCountMethod · 0.80
pageMethod · 0.45

Tested by

no test coverage detected