Refactor transactions

Created on 4 June 2023, over 1 year ago
Updated 3 September 2023, about 1 year ago

Problem/Motivation

The code managing database transaction is very complex - part of it sits in the Connection class, part of it in the Transaction class, and there's back and forth of calls between the two objects.

This makes hard to implement transaction management in contrib database drivers if they need to deviate from the core implementation. Also when looking at Add transaction-related events to the Database API Needs work , it's complicated to find the right places to dispatch events.

Proposed resolution

Disentangle the transaction management code, introducing a transaction manager that does all the client operations and deals with the calls stack; reduce code in Connection and Transaction to a minimum i.e. calls to the manager's methods.

In the course of that, fix 📌 Add a test for Connection::addRootTransactionEndCallback Closed: duplicate

Deprecate something (???)

Remaining tasks

Review by committers if something we want.
Identify if anything needs to be deprecated.
Change Record
Final Review

User interface changes

NA

API changes

This methods wil be deprecated:
Drupal\Core\Database\Connection::transactionDepth()
Drupal\Core\Database\Connection::rollBack()
Drupal\Core\Database\Connection::pushTransaction()
Drupal\Core\Database\Connection::addPostTransactionCallback()
Drupal\Core\Database\Connection::commit()

New methods:
Drupal\Core\Database\Connection::transactionManager()->stackDepth();
Drupal\Core\Database\Connection::transactionManager()->rollback();
Drupal\Core\Database\Connection::transactionManager()->startTransaction();
Drupal\Core\Database\Connection::transactionManager()->addPostTransactionCallback()

Data model changes

None

Release notes snippet

TBD

📌 Task
Status

Fixed

Version

11.0 🔥

Component
Database 

Last updated 1 minute ago

  • Maintained by
  • 🇳🇱Netherlands @daffie
Created by

🇮🇹Italy mondrake 🇮🇹

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024