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

Method spill

bucket.go:746–802  ·  view source on GitHub ↗

spill writes all the nodes for this bucket to dirty pages.

()

Source from the content-addressed store, hash-verified

744
745// spill writes all the nodes for this bucket to dirty pages.
746func (b *Bucket) spill() error {
747 // Spill all child buckets first.
748 for name, child := range b.buckets {
749 // If the child bucket is small enough and it has no child buckets then
750 // write it inline into the parent bucket's page. Otherwise spill it
751 // like a normal bucket and make the parent value a pointer to the page.
752 var value []byte
753 if child.inlineable() {
754 child.free()
755 value = child.write()
756 } else {
757 if err := child.spill(); err != nil {
758 return err
759 }
760
761 // Update the child bucket header in this bucket.
762 value = make([]byte, unsafe.Sizeof(common.InBucket{}))
763 var bucket = (*common.InBucket)(unsafe.Pointer(&value[0]))
764 *bucket = *child.InBucket
765 }
766
767 // Skip writing the bucket if there are no materialized nodes.
768 if child.rootNode == nil {
769 continue
770 }
771
772 // Update parent node.
773 var c = b.Cursor()
774 k, _, flags := c.seek([]byte(name))
775 if !bytes.Equal([]byte(name), k) {
776 panic(fmt.Sprintf("misplaced bucket header: %x -> %x", []byte(name), k))
777 }
778 if flags&common.BucketLeafFlag == 0 {
779 panic(fmt.Sprintf("unexpected bucket header flag: %x", flags))
780 }
781 c.node().put([]byte(name), []byte(name), value, 0, common.BucketLeafFlag)
782 }
783
784 // Ignore if there's not a materialized root node.
785 if b.rootNode == nil {
786 return nil
787 }
788
789 // Spill nodes.
790 if err := b.rootNode.spill(); err != nil {
791 return err
792 }
793 b.rootNode = b.rootNode.root()
794
795 // Update the root node for this bucket.
796 if b.rootNode.pgid >= b.tx.meta.Pgid() {
797 panic(fmt.Sprintf("pgid (%d) above high water mark (%d)", b.rootNode.pgid, b.tx.meta.Pgid()))
798 }
799 b.SetRootPage(b.rootNode.pgid)
800
801 return nil
802}
803

Callers

nothing calls this directly

Calls 10

CursorMethod · 0.95
inlineableMethod · 0.80
seekMethod · 0.80
putMethod · 0.80
rootMethod · 0.80
SetRootPageMethod · 0.80
freeMethod · 0.45
writeMethod · 0.45
nodeMethod · 0.45
PgidMethod · 0.45

Tested by

no test coverage detected