jenkins-bot has submitted this change and it was merged.

Change subject: Cleanups to DatabaseMysqlBase
......................................................................


Cleanups to DatabaseMysqlBase

* Avoid global methods
* Inject global variables
* Remove $wgAllDBsAreLocalhost hack

Change-Id: I54b23654def1f83518764ad697434aebfc6cef73
---
M autoload.php
M includes/DefaultSettings.php
M includes/db/DatabaseMysqlBase.php
M includes/db/loadbalancer/LBFactoryMW.php
M includes/db/loadbalancer/LBFactorySimple.php
R includes/libs/rdbms/database/DatabaseBase.php
M includes/libs/rdbms/lbfactory/LBFactory.php
7 files changed, 36 insertions(+), 34 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/autoload.php b/autoload.php
index eedf7b4..716e56d 100644
--- a/autoload.php
+++ b/autoload.php
@@ -317,7 +317,7 @@
        'DBUnexpectedError' => __DIR__ . 
'/includes/libs/rdbms/exception/DBError.php',
        'DataUpdate' => __DIR__ . '/includes/deferred/DataUpdate.php',
        'Database' => __DIR__ . '/includes/libs/rdbms/database/Database.php',
-       'DatabaseBase' => __DIR__ . '/includes/db/Database.php',
+       'DatabaseBase' => __DIR__ . 
'/includes/libs/rdbms/database/DatabaseBase.php',
        'DatabaseInstaller' => __DIR__ . 
'/includes/installer/DatabaseInstaller.php',
        'DatabaseLag' => __DIR__ . '/maintenance/lag.php',
        'DatabaseLogEntry' => __DIR__ . '/includes/logging/LogEntry.php',
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index 3ab8829..135c3e5 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -1836,13 +1836,6 @@
 $wgSQLiteDataDir = '';
 
 /**
- * Make all database connections secretly go to localhost. Fool the load 
balancer
- * thinking there is an arbitrarily large cluster of servers to connect to.
- * Useful for debugging.
- */
-$wgAllDBsAreLocalhost = false;
-
-/**
  * Shared database for multiple wikis. Commonly used for storing a user table
  * for single sign-on. The server for this database must be the same as for the
  * main database.
diff --git a/includes/db/DatabaseMysqlBase.php 
b/includes/db/DatabaseMysqlBase.php
index 06511e0..46c6678 100644
--- a/includes/db/DatabaseMysqlBase.php
+++ b/includes/db/DatabaseMysqlBase.php
@@ -46,6 +46,11 @@
        protected $sslCAPath;
        /** @var string[]|null */
        protected $sslCiphers;
+       /** @var string sql_mode value to send on connection */
+       protected $sqlMode;
+       /** @var bool Use experimental UTF-8 transmission encoding */
+       protected $utf8Mode;
+
        /** @var string|null */
        private $serverVersion = null;
 
@@ -82,6 +87,8 @@
                                $this->$var = $params[$var];
                        }
                }
+               $this->sqlMode = isset( $params['sqlMode'] ) ? 
$params['sqlMode'] : '';
+               $this->utf8Mode = !empty( $params['utf8Mode'] );
        }
 
        /**
@@ -100,13 +107,9 @@
         * @return bool
         */
        function open( $server, $user, $password, $dbName ) {
-               global $wgAllDBsAreLocalhost, $wgSQLMode;
-
                # Close/unset connection handle
                $this->close();
 
-               # Debugging hack -- fake cluster
-               $realServer = $wgAllDBsAreLocalhost ? 'localhost' : $server;
                $this->mServer = $server;
                $this->mUser = $user;
                $this->mPassword = $password;
@@ -114,7 +117,7 @@
 
                $this->installErrorHandler();
                try {
-                       $this->mConn = $this->mysqlConnect( $realServer );
+                       $this->mConn = $this->mysqlConnect( $this->mServer );
                } catch ( Exception $ex ) {
                        $this->restoreErrorHandler();
                        throw $ex;
@@ -126,14 +129,14 @@
                        if ( !$error ) {
                                $error = $this->lastError();
                        }
-                       wfLogDBError(
+                       $this->queryLogger->error(
                                "Error connecting to {db_server}: {error}",
                                $this->getLogContext( [
                                        'method' => __METHOD__,
                                        'error' => $error,
                                ] )
                        );
-                       wfDebug( "DB connection error\n" .
+                       $this->queryLogger->debug( "DB connection error\n" .
                                "Server: $server, User: $user, Password: " .
                                substr( $password, 0, 3 ) . "..., error: " . 
$error . "\n" );
 
@@ -145,14 +148,14 @@
                        $success = $this->selectDB( $dbName );
                        MediaWiki\restoreWarnings();
                        if ( !$success ) {
-                               wfLogDBError(
+                               $this->queryLogger->error(
                                        "Error selecting database {db_name} on 
server {db_server}",
                                        $this->getLogContext( [
                                                'method' => __METHOD__,
                                        ] )
                                );
-                               wfDebug( "Error selecting database $dbName on 
server {$this->mServer} " .
-                                       "from client host " . wfHostname() . 
"\n" );
+                               $this->queryLogger->debug(
+                                       "Error selecting database $dbName on 
server {$this->mServer}" );
 
                                $this->reportConnectionError( "Error selecting 
database $dbName" );
                        }
@@ -166,8 +169,8 @@
                // Abstract over any insane MySQL defaults
                $set = [ 'group_concat_max_len = 262144' ];
                // Set SQL mode, default is turning them all off, can be 
overridden or skipped with null
-               if ( is_string( $wgSQLMode ) ) {
-                       $set[] = 'sql_mode = ' . $this->addQuotes( $wgSQLMode );
+               if ( is_string( $this->sqlMode ) ) {
+                       $set[] = 'sql_mode = ' . $this->addQuotes( 
$this->sqlMode );
                }
                // Set any custom settings defined by site config
                // (e.g. 
https://dev.mysql.com/doc/refman/4.1/en/innodb-parameters.html)
@@ -183,7 +186,7 @@
                        // Use doQuery() to avoid opening implicit transactions 
(DBO_TRX)
                        $success = $this->doQuery( 'SET ' . implode( ', ', $set 
) );
                        if ( !$success ) {
-                               wfLogDBError(
+                               $this->queryLogger->error(
                                        'Error setting MySQL variables on 
server {db_server} (check $wgSQLMode)',
                                        $this->getLogContext( [
                                                'method' => __METHOD__,
@@ -204,9 +207,7 @@
         * @return bool
         */
        protected function connectInitCharset() {
-               global $wgDBmysql5;
-
-               if ( $wgDBmysql5 ) {
+               if ( $this->utf8Mode ) {
                        // Tell the server we're communicating with it in UTF-8.
                        // This may engage various charset conversions.
                        return $this->mysqlSetCharset( 'utf8' );
@@ -657,7 +658,7 @@
                        // Standard method: use master server ID (works with 
stock pt-heartbeat)
                        $masterInfo = $this->getMasterServerInfo();
                        if ( !$masterInfo ) {
-                               wfLogDBError(
+                               $this->queryLogger->error(
                                        "Unable to query master of {db_server} 
for server ID",
                                        $this->getLogContext( [
                                                'method' => __METHOD__
@@ -680,7 +681,7 @@
                        return max( $nowUnix - $timeUnix, 0.0 );
                }
 
-               wfLogDBError(
+               $this->queryLogger->error(
                        "Unable to find pt-heartbeat row for {db_server}",
                        $this->getLogContext( [
                                'method' => __METHOD__
@@ -984,7 +985,7 @@
                        return true;
                }
 
-               wfDebug( __METHOD__ . " failed to acquire lock\n" );
+               $this->queryLogger->debug( __METHOD__ . " failed to acquire 
lock\n" );
 
                return false;
        }
@@ -1006,7 +1007,7 @@
                        return true;
                }
 
-               wfDebug( __METHOD__ . " failed to release lock\n" );
+               $this->queryLogger->debug( __METHOD__ . " failed to release 
lock\n" );
 
                return false;
        }
diff --git a/includes/db/loadbalancer/LBFactoryMW.php 
b/includes/db/loadbalancer/LBFactoryMW.php
index 2fb48c7..49d0624 100644
--- a/includes/db/loadbalancer/LBFactoryMW.php
+++ b/includes/db/loadbalancer/LBFactoryMW.php
@@ -37,7 +37,7 @@
         * @TODO: inject objects via dependency framework
         */
        public function __construct( array $conf ) {
-               global $wgCommandLineMode;
+               global $wgCommandLineMode, $wgSQLMode, $wgDBmysql5;
 
                $defaults = [
                        'localDomain' => wfWikiID(),
@@ -66,6 +66,11 @@
                $this->agent = isset( $params['agent'] ) ? $params['agent'] : 
'';
                $this->cliMode = isset( $params['cliMode'] ) ? 
$params['cliMode'] : $wgCommandLineMode;
 
+               if ( isset( $conf['serverTemplate'] ) ) { // LBFactoryMulti
+                       $conf['serverTemplate']['sqlMode'] = $wgSQLMode;
+                       $conf['serverTemplate']['utf8Mode'] = $wgDBmysql5;
+               }
+
                parent::__construct( $conf + $defaults );
        }
 
diff --git a/includes/db/loadbalancer/LBFactorySimple.php 
b/includes/db/loadbalancer/LBFactorySimple.php
index 09533eb..d937ddb 100644
--- a/includes/db/loadbalancer/LBFactorySimple.php
+++ b/includes/db/loadbalancer/LBFactorySimple.php
@@ -46,7 +46,7 @@
         * @return LoadBalancer
         */
        public function newMainLB( $wiki = false ) {
-               global $wgDBservers, $wgDBprefix, $wgDBmwschema;
+               global $wgDBservers, $wgDBprefix, $wgDBmwschema, $wgSQLMode, 
$wgDBmysql5;
 
                if ( is_array( $wgDBservers ) ) {
                        $servers = $wgDBservers;
@@ -59,7 +59,9 @@
                                $server += [
                                        'schema' => $wgDBmwschema,
                                        'tablePrefix' => $wgDBprefix,
-                                       'flags' => DBO_DEFAULT
+                                       'flags' => DBO_DEFAULT,
+                                       'sqlMode' => $wgSQLMode,
+                                       'utf8Mode' => $wgDBmysql5
                                ];
                        }
                } else {
@@ -87,7 +89,9 @@
                                'type' => $wgDBtype,
                                'load' => 1,
                                'flags' => $flags,
-                               'master' => true
+                               'master' => true,
+                               'sqlMode' => $wgSQLMode,
+                               'utf8Mode' => $wgDBmysql5
                        ] ];
                }
 
diff --git a/includes/db/Database.php 
b/includes/libs/rdbms/database/DatabaseBase.php
similarity index 100%
rename from includes/db/Database.php
rename to includes/libs/rdbms/database/DatabaseBase.php
diff --git a/includes/libs/rdbms/lbfactory/LBFactory.php 
b/includes/libs/rdbms/lbfactory/LBFactory.php
index e011ff0..49fac6a 100644
--- a/includes/libs/rdbms/lbfactory/LBFactory.php
+++ b/includes/libs/rdbms/lbfactory/LBFactory.php
@@ -445,8 +445,7 @@
                $failed = [];
                foreach ( $lbs as $i => $lb ) {
                        if ( $masterPositions[$i] ) {
-                               // The DBMS may not support getMasterPos() or 
the whole
-                               // load balancer might be fake (e.g. 
$wgAllDBsAreLocalhost).
+                               // The DBMS may not support getMasterPos()
                                if ( !$lb->waitForAll( $masterPositions[$i], 
$opts['timeout'] ) ) {
                                        $failed[] = $lb->getServerName( 
$lb->getWriterIndex() );
                                }

-- 
To view, visit https://gerrit.wikimedia.org/r/311084
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I54b23654def1f83518764ad697434aebfc6cef73
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Parent5446 <tylerro...@gmail.com>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to