Skip to content

Commit df83d9d

Browse files
authored
Merge pull request #792 from ahrtr/freelist_rollback_20240709
Panicking when a write txn tries to free a page which was allocated by itself
2 parents 49c7697 + da1c83c commit df83d9d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

internal/freelist/shared.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ func (t *shared) Free(txid common.Txid, p *common.Page) {
6565
t.pending[txid] = txp
6666
}
6767
allocTxid, ok := t.allocs[p.Id()]
68+
common.Verify(func() {
69+
if allocTxid == txid {
70+
panic(fmt.Sprintf("free: freed page (%d) was allocated by the same transaction (%d)", p.Id(), txid))
71+
}
72+
})
6873
if ok {
6974
delete(t.allocs, p.Id())
7075
}
@@ -87,7 +92,6 @@ func (t *shared) Rollback(txid common.Txid) {
8792
if txp == nil {
8893
return
8994
}
90-
var m common.Pgids
9195
for i, pgid := range txp.ids {
9296
delete(t.cache, pgid)
9397
tx := txp.alloctx[i]
@@ -98,13 +102,12 @@ func (t *shared) Rollback(txid common.Txid) {
98102
// Pending free aborted; restore page back to alloc list.
99103
t.allocs[pgid] = tx
100104
} else {
101-
// Freed page was allocated by this txn; OK to throw away.
102-
m = append(m, pgid)
105+
// A writing TXN should never free a page which was allocated by itself.
106+
panic(fmt.Sprintf("rollback: freed page (%d) was allocated by the same transaction (%d)", pgid, txid))
103107
}
104108
}
105109
// Remove pages from pending list and mark as free if allocated by txid.
106110
delete(t.pending, txid)
107-
t.mergeSpans(m)
108111
}
109112

110113
func (t *shared) AddReadonlyTXID(tid common.Txid) {

0 commit comments

Comments
 (0)