spill writes all the nodes for this bucket to dirty pages.
()
| 744 | |
| 745 | // spill writes all the nodes for this bucket to dirty pages. |
| 746 | func (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 |
nothing calls this directly
no test coverage detected