Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Implement apply() atomicity on MVCC level #2012
In order to provide apply() atomicity, memtable::apply() needs to have strong exception guarantees. Currently it's implemented on mutation_partition::apply() level by using reversible merging (see reversibly_mergeable.hh), which basically works by swapping atoms between source and destination. If merging fails in the middle, the atoms are swapped back.
We could implement this more efficiently now that we have MVCC, by only requiring mutation_partition::apply() to have weak exception guarantees, such that in case of failure the source and destination still commute to the same result (x' + y' = x + y). Such guarantees are simpler and more efficient to provide than reversible merging (no extra allocations, we just std::move() atoms).
We first allocate a new version entry. Then std::move the source mutation into it. If that succeeds, the mutation is logically already applied. Then we merge that version with the previous version. Even if that fails, logical state is unaffected because the two versions still commute to the same value due to exception guarantees.
The allocation of temporary version object could be avoided in the success path by some form of pooling.