aboutsummaryrefslogtreecommitdiff
path: root/freelist.go
diff options
context:
space:
mode:
Diffstat (limited to 'freelist.go')
-rw-r--r--freelist.go25
1 files changed, 25 insertions, 0 deletions
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) }