khonsulabs / nebari

A pure Rust database implementation using an append-only B-Tree file format.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add "Session ID" to transaction log entries

ecton opened this issue · comments

While fixing some edge cases in 9e799b9, I thought of another edge case. I believe it's one that we should care about: Imagine if you roll a transaction back, the trees might have some data referencing the rolled back transaction. Next, close the database, and reopen the database. Push a transaction using different trees, and then open the other tree. Because the unused transaction id wasn't persisted to disk, the new transaction is assigned the same id as the abandoned transaction.

One fix would be to write all transactions to the log, but that seems wasteful. Another approach would be to add another piece of data that is incremented once per log-file open which is checked alongside the transaction id to ensure that the transaction ID came from the same session that successfully wrote it.

This would avoid writing data for all dropped transactions, but it might require updating the root headers depending on how its implemented.