Merge "rdbms: make safeWaitForMasterPos() respect "waitTimeout""
[lhc/web/wiklou.git] / includes / libs / rdbms / loadbalancer / LoadBalancer.php
index 0af0e6e..04b3ea3 100644 (file)
@@ -1006,7 +1006,17 @@ class LoadBalancer implements ILoadBalancer {
                        throw new DBAccessError();
                }
 
-               if ( $domainOverride->getDatabase() !== null ) {
+               // Handle $domainOverride being a specified or an unspecified domain
+               if ( $domainOverride->getDatabase() === null ) {
+                       // Normally, an RDBMS requires a DB name specified on connection and the $server
+                       // configuration array is assumed to already specify an appropriate DB name.
+                       if ( $server['type'] === 'mysql' ) {
+                               // For MySQL, DATABASE and SCHEMA are synonyms, connections need not specify a DB,
+                               // and the DB name in $server might not exist due to legacy reasons (the default
+                               // domain used to ignore the local LB domain, even when mismatched).
+                               $server['dbname'] = null;
+                       }
+               } else {
                        $server['dbname'] = $domainOverride->getDatabase();
                        $server['schema'] = $domainOverride->getSchema();
                }
@@ -1362,7 +1372,7 @@ class LoadBalancer implements ILoadBalancer {
                $this->trxRoundId = false;
                $this->forEachOpenMasterConnection(
                        function ( IDatabase $conn ) use ( $fname, $restore ) {
-                               if ( $conn->writesOrCallbacksPending() ) {
+                               if ( $conn->writesOrCallbacksPending() || $conn->explicitTrxActive() ) {
                                        $conn->rollback( $fname, $conn::FLUSHING_ALL_PEERS );
                                }
                                if ( $restore ) {