From a96185e8b69725985e48926b7b28747ddbbfe9b6 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Mon, 2 Jun 2014 15:26:58 -0600 Subject: Allow split nodes to be merged with the next node. This commit changes the node.split() functionality to check if the next node has available space and, if so, it will merge the newly split keys into the next node. Previously, keys could be continually put into the left side of a split causing that first half to split off small right side nodes. This was especially problematic with databases with a high fill percent. --- freelist.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'freelist.go') diff --git a/freelist.go b/freelist.go index a236079..2fa4a94 100644 --- a/freelist.go +++ b/freelist.go @@ -70,12 +70,14 @@ func (f *freelist) allocate(n int) pgid { // free releases a page and its overflow for a given transaction id. // If the page is already free then a panic will occur. func (f *freelist) free(txid txid, p *page) { + warn("free:", txid, p.id, p.overflow) _assert(p.id > 1, "cannot free page 0 or 1: %d", p.id) // Verify that page is not already free. minid, maxid := p.id, p.id+pgid(p.overflow) for _, id := range f.ids { if id >= minid && id <= maxid { + warn(" ‡", id, "|", minid, maxid) panic(fmt.Sprintf("page %d already freed in tx", id)) } } @@ -90,6 +92,9 @@ func (f *freelist) free(txid txid, p *page) { // Free page and all its overflow pages. var ids = f.pending[txid] for i := 0; i < int(p.overflow+1); i++ { + if p.id+pgid(i) == 55 { + warn(" •", txid, p.id+pgid(i)) + } ids = append(ids, p.id+pgid(i)) } f.pending[txid] = ids -- cgit v1.2.3