Our Database class has startAtomic, endAtomic, and doAtomicSection to run multiple queries that should be logically grouped even if the code is called while inside another transaction or atomic section. This works well most of the time.
But what should you do if something goes wrong in the middle of your atomic section? Roll back the whole transaction, even if the caller could recover from your failure? Don't roll back the transaction, which leaves your "atomic" section half done?
Ideally we'd roll back just the atomic section and then throw an error for the caller to deal with. Most of the time the caller will probably roll back, but for things like upsert or insertSelect it might want to deal with it better.
It turns out that SQL has a mechanism to deal with this sort of thing: savepoints. And it also turns out that all of our supported databases do, in fact, support them.
We don't want to expose savepoints directly in the public interface, but using them for atomic sections seems reasonable.