Skip to content

Commit

Permalink
panicking when a write txn tries to free a page which was allocated b…
Browse files Browse the repository at this point in the history
…y itself

Signed-off-by: Benjamin Wang <benjamin.ahrtr@gmail.com>
  • Loading branch information
ahrtr committed Jul 9, 2024
1 parent 46d9b10 commit def4a9e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions freelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ func (f *freelist) free(txid common.Txid, p *common.Page) {
f.pending[txid] = txp
}
allocTxid, ok := f.allocs[p.Id()]
common.Verify(func() {
if allocTxid == txid {
panic(fmt.Sprintf("free: freed page (%d) was allocated by the same transaction (%d)", p.Id(), txid))
}
})
if ok {
delete(f.allocs, p.Id())
} else if p.IsFreelistPage() {
Expand Down Expand Up @@ -191,7 +196,6 @@ func (f *freelist) rollback(txid common.Txid) {
if txp == nil {
return
}
var m common.Pgids
for i, pgid := range txp.ids {
delete(f.cache, pgid)
tx := txp.alloctx[i]
Expand All @@ -202,13 +206,12 @@ func (f *freelist) rollback(txid common.Txid) {
// Pending free aborted; restore page back to alloc list.
f.allocs[pgid] = tx
} else {
// Freed page was allocated by this txn; OK to throw away.
m = append(m, pgid)
// A writing TXN should never free a page which was allocated by itself.
panic(fmt.Sprintf("rollback: freed page (%d) was allocated by the same transaction (%d)", pgid, txid))
}
}
// Remove pages from pending list and mark as free if allocated by txid.
delete(f.pending, txid)
f.mergeSpans(m)
}

// freed returns whether a given page is in the free list.
Expand Down

0 comments on commit def4a9e

Please sign in to comment.