mirror of
https://github.com/versity/scoutfs.git
synced 2026-09-10 18:16:10 +00:00
Btree merging attempted to build an rbtree of the input roots with only one version of an item present in the rbtree at a time. It really messed this up by completely dropping an input root when a root with a newer version of its item tried to take its place in the rbtree. What it should have done is advance to the next item in the older root, which itself could have required advancing some other older root. Dropping the root entirely is catastrophically wrong because it hides the rest of the items in the root from merging. This has been manifesting as occasional mysterious item loss during tests where memory pressure, item update patterns, and merging all lined up just so. This fixes the problem by more clearly keeping the next item in each root in the rbtree. We sort by newest to oldest version so that once we merge the most recent version of an item its easy to skip all the older versions of the items in the next rbtree entries for the rest of the input roots. While we're at it we work with references to the static cached input btree blocks. The old code was a first pass that used an expensive btree walk per item and copied the value payload. Signed-off-by: Zach Brown <zab@versity.com>