[D7] Add ability to register rootEndTransaction callbacks during transactions

Created on 4 October 2018, about 6 years ago
Updated 15 April 2024, 6 months ago

Over in #2966607: Invalidating 'node_list' and other broad cache tags early in a transaction severely increases lock wait time and probability of deadlock , discussion is being done regarding implementing a way to avoid deadlocks caused by invalidating cache tags. The same functionality will be needed on D7 to support the d8cache module.

📌 Task
Status

Needs review

Version

7.0 ⚰️

Component
Database 

Last updated 5 days ago

  • Maintained by
  • 🇳🇱Netherlands @daffie
Created by

🇺🇸United States bdragon

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    In DatabaseConnection, the patch adds this code.

    +  /**
    +   * Do the actual commit, invoke pre-commit callbacks.
    +   *
    +   * @internal
    +   */
    +  protected function doCommit() {
    +    $success = $this->connection->commit();
    +    $this->executeRootTransactionEndCallbacks($success);
    +
    +    if (!$success) {
    +      throw new DatabaseTransactionCommitFailedException();
    +    }
    +  }

    In DatabaseConnection_mysql, the code is changed as follows.

       protected function doCommit() {
         if ($this->connection->inTransaction()) {
    -      return $this->connection->commit();
    +      $success = parent::doCommit();
         }
         else {
           // In PHP 8.0 a PDOException is thrown when a commit is attempted with no
           // transaction active. In previous PHP versions this failed silently.
    -      return TRUE;
    +      $success = TRUE;
    +      // Allow callbacks to perform their own cleanup.
    +      $this->executeRootTransactionEndCallbacks($success);
         }
    +    return $success;
       }
    

    $success = parent::doCommit(); would just set $success to NULL, since DatabaseConnection::doCommit() does not return any value.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update 6 months ago
    2,179 pass
  • Pipeline finished with Success
    6 months ago
    Total: 252s
    #147341
Production build 0.71.5 2024