From 698b07b074dc554578ecddd138972702f46d0879 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Mon, 7 Apr 2014 16:24:51 -0600 Subject: Add nested buckets. This commit adds the ability to create buckets inside of other buckets. It also replaces the buckets page with a root bucket. Fixes #56. --- freelist.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'freelist.go') diff --git a/freelist.go b/freelist.go index cb58a54..ebe2810 100644 --- a/freelist.go +++ b/freelist.go @@ -62,6 +62,8 @@ func (f *freelist) free(txid txid, p *page) { ids = append(ids, p.id+pgid(i)) } f.pending[txid] = ids + + // DEBUG ONLY: f.check() } // release moves all page ids for a transaction id (or older) to the freelist. @@ -109,6 +111,29 @@ func (f *freelist) write(p *page) { copy(((*[maxAllocSize]pgid)(unsafe.Pointer(&p.ptr)))[:], ids) } +// check verifies there are no double free pages. +// This is slow so it should only be used while debugging. +// If errors are found then a panic invoked. +/* +func (f *freelist) check() { + var lookup = make(map[pgid]txid) + for _, id := range f.ids { + if _, ok := lookup[id]; ok { + panic(fmt.Sprintf("page %d already freed", id)) + } + lookup[id] = 0 + } + for txid, m := range f.pending { + for _, id := range m { + if _, ok := lookup[id]; ok { + panic(fmt.Sprintf("tx %d: page %d already freed in tx %d", txid, id, lookup[id])) + } + lookup[id] = txid + } + } +} +*/ + type reverseSortedPgids []pgid func (s reverseSortedPgids) Len() int { return len(s) } -- cgit v1.2.3