Merge pull request #839 from molecula/rbf-fix-checkpoint

Remove tx before issuing checkpoint.
This commit is contained in:
Ben Johnson 2020-09-14 12:56:03 -06:00 committed by GitHub
commit 343c446b7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View file

@ -800,6 +800,8 @@ func (db *DB) removeTx(tx *Tx) error {
db.mu.Lock()
defer db.mu.Unlock()
delete(tx.db.txs, tx)
// Write pages from WAL to DB.
// TODO(bbj): Move this to an async goroutine.
if tx.writable {
@ -808,8 +810,6 @@ func (db *DB) removeTx(tx *Tx) error {
}
}
delete(tx.db.txs, tx)
// Disassociate from db.
tx.db = nil

View file

@ -92,14 +92,25 @@ func TestDB_Recovery(t *testing.T) {
}
// Add one additional bit in a second transaction.
if tx, err := db.Begin(true); err != nil {
tx0, err := db.Begin(true)
if err != nil {
t.Fatal(err)
} else if _, err := tx.Add("x", uint64(len(a))); err != nil {
t.Fatal(err)
} else if err := tx.Commit(); err != nil {
} else if _, err := tx0.Add("x", uint64(len(a))); err != nil {
t.Fatal(err)
}
// Start a read-only transaction so the write tx does not checkpoint the WAL.
tx1, err := db.Begin(false)
if err != nil {
t.Fatal(err)
}
// Commit write transaction.
if err := tx0.Commit(); err != nil {
t.Fatal(err)
}
tx1.Rollback()
// Close database & truncate WAL to remove commit page & bitmap data page.
segment := db.ActiveWALSegment()
if err := db.Close(); err != nil {