Page MenuHomePhabricator

Allow Database atomic sections to roll back the section without rolling back the whole transaction
Closed, ResolvedPublic

Description

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.

Event Timeline

Anomie triaged this task as Low priority.Mar 1 2018, 8:42 PM
Anomie created this task.

Change 420219 had a related patch set uploaded (by Anomie; owner: Anomie):
[mediawiki/core@master] rdbms: Add IDatabase::cancelAtomic()

https://gerrit.wikimedia.org/r/420219

Change 420219 merged by jenkins-bot:
[mediawiki/core@master] rdbms: Add IDatabase::cancelAtomic()

https://gerrit.wikimedia.org/r/420219

Anomie claimed this task.