Merge "rdbms: avoid connections on more lazy DBConnRef methods"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 22 Mar 2019 02:00:20 +0000 (02:00 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 22 Mar 2019 02:00:20 +0000 (02:00 +0000)
includes/deferred/AtomicSectionUpdate.php
includes/deferred/AutoCommitUpdate.php
includes/deferred/MWCallableUpdate.php
includes/libs/rdbms/database/DatabaseMysqlBase.php
includes/libs/rdbms/lbfactory/LBFactory.php

index 8b62989..69f09e3 100644 (file)
@@ -15,18 +15,22 @@ class AtomicSectionUpdate implements DeferrableUpdate, DeferrableCallback {
        private $callback;
 
        /**
-        * @param IDatabase $dbw
+        * @param IDatabase $dbw DB handle; update aborts if a transaction now this rolls back
         * @param string $fname Caller name (usually __METHOD__)
         * @param callable $callback
+        * @param IDatabase[] $conns Abort if a transaction now on one of these rolls back [optional]
         * @see IDatabase::doAtomicSection()
         */
-       public function __construct( IDatabase $dbw, $fname, callable $callback ) {
+       public function __construct( IDatabase $dbw, $fname, callable $callback, array $conns = [] ) {
                $this->dbw = $dbw;
                $this->fname = $fname;
                $this->callback = $callback;
-
-               if ( $this->dbw->trxLevel() ) {
-                       $this->dbw->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
+               // Register DB connections for which uncommitted changes are related to this update
+               $conns[] = $dbw;
+               foreach ( $conns as $conn ) {
+                       if ( $conn->trxLevel() ) {
+                               $conn->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
+                       }
                }
        }
 
@@ -36,6 +40,10 @@ class AtomicSectionUpdate implements DeferrableUpdate, DeferrableCallback {
                }
        }
 
+       /**
+        * @private This method is public so that it works with onTransactionResolution()
+        * @param int $trigger
+        */
        public function cancelOnRollback( $trigger ) {
                if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
                        $this->callback = null;
index 8507157..ddfd987 100644 (file)
@@ -15,17 +15,21 @@ class AutoCommitUpdate implements DeferrableUpdate, DeferrableCallback {
        private $callback;
 
        /**
-        * @param IDatabase $dbw
+        * @param IDatabase $dbw DB handle; update aborts if a transaction now this rolls back
         * @param string $fname Caller name (usually __METHOD__)
         * @param callable $callback Callback that takes (IDatabase, method name string)
+        * @param IDatabase[] $conns Abort if a transaction now on one of these rolls back [optional]
         */
-       public function __construct( IDatabase $dbw, $fname, callable $callback ) {
+       public function __construct( IDatabase $dbw, $fname, callable $callback, array $conns = [] ) {
                $this->dbw = $dbw;
                $this->fname = $fname;
                $this->callback = $callback;
-
-               if ( $this->dbw->trxLevel() ) {
-                       $this->dbw->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
+               // Register DB connections for which uncommitted changes are related to this update
+               $conns[] = $dbw;
+               foreach ( $conns as $conn ) {
+                       if ( $conn->trxLevel() ) {
+                               $conn->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
+                       }
                }
        }
 
@@ -50,6 +54,10 @@ class AutoCommitUpdate implements DeferrableUpdate, DeferrableCallback {
                }
        }
 
+       /**
+        * @private This method is public so that it works with onTransactionResolution()
+        * @param int $trigger
+        */
        public function cancelOnRollback( $trigger ) {
                if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
                        $this->callback = null;
index 9803b7a..efca406 100644 (file)
@@ -35,6 +35,10 @@ class MWCallableUpdate implements DeferrableUpdate, DeferrableCallback {
                }
        }
 
+       /**
+        * @private This method is public so that it works with onTransactionResolution()
+        * @param int $trigger
+        */
        public function cancelOnRollback( $trigger ) {
                if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
                        $this->callback = null;
index 1a406cf..25d78da 100644 (file)
@@ -486,7 +486,9 @@ abstract class DatabaseMysqlBase extends Database {
        abstract protected function mysqlError( $conn = null );
 
        protected function wasQueryTimeout( $error, $errno ) {
-               return $errno == 2062;
+               // https://dev.mysql.com/doc/refman/8.0/en/client-error-reference.html
+               // https://phabricator.wikimedia.org/T170638
+               return in_array( $errno, [ 2062, 3024 ] );
        }
 
        public function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) {
@@ -1407,7 +1409,7 @@ abstract class DatabaseMysqlBase extends Database {
                }
 
                // See https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
-               return in_array( $errno, [ 1022, 1216, 1217, 1137, 1146, 1051, 1054 ], true );
+               return in_array( $errno, [ 1022, 1062, 1216, 1217, 1137, 1146, 1051, 1054 ], true );
        }
 
        /**
index 9ec1ce1..007ac20 100644 (file)
@@ -634,7 +634,7 @@ abstract class LBFactory implements ILBFactory {
        public function setLocalDomainPrefix( $prefix ) {
                $this->localDomain = new DatabaseDomain(
                        $this->localDomain->getDatabase(),
-                       null,
+                       $this->localDomain->getSchema(),
                        $prefix
                );