-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quick repair increasing database size #934
Comments
Hmm. It's hard to say. Can you call |
I've noticed something similar since updating & setting quick repair: db files started growing significantly beyond the size of their content (500GB for 100MB of data in the worst case). I found that calling Here are the table & database stats for one such file before compaction:
|
Hmm, that sounds like a bug. What's the easiest way to reproduce this? |
I had already called Now it's gone back to normal size - so the large file size is not consistent. The large DB stats post integrity check were:
|
Hmm, my guess is this is another manifestation of #654 and #810. Those two look like separate issues, but actually the underlying cause is exactly the same: whenever there's an old commit that needs to be kept alive (because the commit contains a savepoint, or because it's the latest durable commit, or because it has a live read), redb becomes too conservative about freeing pages. Specifically, it fails to free pages that are both allocated and released after the commit that's being preserved, even though those pages definitely aren't reachable from it. When this happens, writes to the database continue to allocate new pages like normal but they don't free old pages, so the file grows very quickly. The issue isn't caused by quick-repair, but quick-repair exacerbates it by causing additional write traffic. Specifically, when quick-repair is enabled, each commit needs to write additional data equal to about 0.02% of the total file size, rounded up to the nearest megabyte. This data gets overwritten each time, so it doesn't normally accumulate -- but whenever you have an old commit that's being kept alive for any reason, that blocks page freeing due to the issue above! So if you (say) create a savepoint and then make a bunch of tiny commits with quick-repair enabled, each commit will cause the file to grow by at least 1 MB, and that space won't be reused until you delete the savepoint. The exact same thing happens without quick-repair if you create a savepoint and then make a bunch of commits that overwrite 1 MB of data each. Note that in @lhallam's case, the pages had already been freed by the time you ran In @SmarakNayak's case, the pages haven't been freed because the old commit that's keeping them around is still live. That's why |
Not sure if this deserves it's own issue, but I figured out the write amplification I observed was caused by This sequence of transactions results in a 500MB file for 11MB of data. Replacing
|
@lhallam can you try the latest master? |
Yes that reduces the size significantly, thank you! |
I am wondering if the fix would solve the issue I encountered today with ord. During a reorg, a rollback from savepoint was initiated and it took 2 hours to rollback and consumed a lot more of RAM on ord22 (redb 2.3.0) vs on ord19 (redb 2.0.0). Ord19 restored the savepoint in a couple of seconds, ord22 took 2 hours. |
@emilcondrea I think that's a separate issue. Restoring from a savepoint got much slower in redb 2.1.2 (due to baa86e7); it looks like this is fixed in 2.4.0 (by 51ca54c). Could you try with redb 2.4.0 and see if that helps? |
Thank you! Will give it a try |
@mconst thanks for the suggestion, tried 2.4.0 and it fixes the problem with slow restoring from savepoint |
Yay, glad to hear it's working! |
I run a fork of
ord
and have noticed that enablingquick_repair
has greatly increased my database size. My index went from 400GB -> 2+TB.My index with quick repair enabled has ~525m allocated, but ~57m leaf pages & 2m branch, whereas my index with quick repair off looks a lot more reasonable with 45m allocated, 32m lead & 1m branch. Please note they're indexed to slightly different heights so not a perfect comp.
When indexing the standard
ord
index without my extra tables, there is no size difference between turningquick_repair
on & off.Is this expected behaviour, or am I likely doing something wrong/running into some edge case?
The text was updated successfully, but these errors were encountered: