From 7c482623ada28a7769f630b85c5c0f4d8a6f8a37 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Mon, 7 Aug 2017 19:42:27 -0700 Subject: [PATCH] fix NoSyncFreelist reachability checking * unconditionally free freelist, if any, when committing txn * only treat freelist pages as reachable if set to valid pgid Fixes #9 --- tx.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tx.go b/tx.go index fa1fa5095..31c164654 100644 --- a/tx.go +++ b/tx.go @@ -169,6 +169,12 @@ func (tx *Tx) Commit() error { // Free the old root bucket. tx.meta.root.root = tx.root.root + // Free the freelist and allocate new pages for it. This will overestimate + // the size of the freelist but not underestimate the size (which would be bad). + if tx.meta.freelist != pgidNoFreelist { + tx.db.freelist.free(tx.meta.txid, tx.db.page(tx.meta.freelist)) + } + if !tx.db.NoFreelistSync { err := tx.commitFreelist() if err != nil { @@ -222,12 +228,6 @@ func (tx *Tx) Commit() error { func (tx *Tx) commitFreelist() error { opgid := tx.meta.pgid - - // Free the freelist and allocate new pages for it. This will overestimate - // the size of the freelist but not underestimate the size (which would be bad). - if tx.meta.freelist != pgidNoFreelist { - tx.db.freelist.free(tx.meta.txid, tx.db.page(tx.meta.freelist)) - } p, err := tx.allocate((tx.db.freelist.size() / tx.db.pageSize) + 1) if err != nil { tx.rollback() @@ -408,7 +408,7 @@ func (tx *Tx) check(ch chan error) { reachable := make(map[pgid]*page) reachable[0] = tx.page(0) // meta0 reachable[1] = tx.page(1) // meta1 - if !tx.DB().NoFreelistSync { + if tx.meta.freelist != pgidNoFreelist { for i := uint32(0); i <= tx.page(tx.meta.freelist).overflow; i++ { reachable[tx.meta.freelist+pgid(i)] = tx.page(tx.meta.freelist) }