Page MenuHomePhabricator

Use closures to enclose transactions
Closed, ResolvedPublic

Description

Rather than separate $dbw->startAtomic() / $dbw->endAtomic() calls, have something like:

wfGetDB( DB_MASTER )->performTransaction( function ( $db ) {
    $db->update( .... );
    $db->delete( .... );
} );

This would allow nested transactions (among other benefits).

A special return value could be used to indicate that the transaction should be rolled back.

Ideally the same interface would allow deferred updates, too, without needing to nest closures. Perhaps by having performTransaction() take a flag which indicates whether to invoke the closure now or whether it may be deferred.

Event Timeline

ori created this task.Dec 22 2015, 5:35 AM
ori updated the task description. (Show Details)
ori raised the priority of this task from to Needs Triage.
ori assigned this task to aaron.
ori added a project: Performance-Team.
ori added a subscriber: ori.
Restricted Application added subscribers: StudiesWorld, Aklapper. · View Herald TranscriptDec 22 2015, 5:35 AM
ori updated the task description. (Show Details)Dec 22 2015, 5:38 AM
ori set Security to None.
ori updated the task description. (Show Details)
aaron added a comment.Dec 23 2015, 1:55 AM

These already allow nesting, but this could simplify some code a bit, like FileDeleteForm.

Change 260708 had a related patch set uploaded (by Aaron Schulz):
Added IDatabase::doAtomicSection() convenience method

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

Change 260708 merged by jenkins-bot:
Added IDatabase::doAtomicSection() convenience method

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

Change 263867 had a related patch set uploaded (by Aaron Schulz):
[WIP] Add AtomicSectionUpdate deferred update class

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

aaron triaged this task as Normal priority.Jan 13 2016, 5:00 PM
aaron moved this task from Inbox to Blocked on the Performance-Team board.Jan 13 2016, 11:52 PM

Change 263867 merged by Aaron Schulz:
Add AtomicSectionUpdate deferred update class

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

aaron closed this task as Resolved.Jan 15 2016, 10:37 PM
Krinkle moved this task from Blocked to Doing on the Performance-Team board.Aug 5 2016, 1:17 AM