cberner / redb

An embedded key-value database in pure Rust
https://www.redb.org
Apache License 2.0
3.38k stars 157 forks source link

Don't mark the region tracker page as allocated #899

Closed mconst closed 4 days ago

mconst commented 1 week ago

When writing the allocator state table, it's better not to include the region tracker page as one of the allocated pages. Instead, we should allocate the region tracker page during quick-repair after loading the rest of the allocator state, exactly like we do for full repair.

This avoids an unlikely corruption that could happen for databases larger than 4 TB, if we crash on shutdown after writing out a new region tracker page number but before clearing the recovery_required bit. It also means that in the future, when we drop support for the old allocator state format, we'll be able to get rid of the region tracker page entirely instead of having to keep around some of the allocation code for compatibility.

mconst commented 4 days ago

Okay, I think this is ready. Sorry for the delay! The first two commits are fixes for preexisting region-tracker bugs I ran into; the last one is the main change.

cberner commented 4 days ago

Ah nice, ya I like this! I think this conflicted with your other PR that I just merged. Can you rebase and I'll merge this one too?

mconst commented 4 days ago

Oh yeah, sorry about that! Here's the rebased version.