2016-09-14 11:34:17 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Generator of database load balancing objects.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Database
|
|
|
|
|
*/
|
|
|
|
|
|
2019-04-10 15:03:54 +00:00
|
|
|
use MediaWiki\Config\ServiceOptions;
|
2016-09-14 11:34:17 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2017-02-06 22:32:49 +00:00
|
|
|
use Wikimedia\Rdbms\DatabaseDomain;
|
2016-09-14 11:34:17 +00:00
|
|
|
|
|
|
|
|
/**
|
2016-09-30 21:06:02 +00:00
|
|
|
* MediaWiki-specific class for generating database load balancers
|
2016-09-14 11:34:17 +00:00
|
|
|
* @ingroup Database
|
|
|
|
|
*/
|
2016-09-30 21:06:02 +00:00
|
|
|
abstract class MWLBFactory {
|
2018-04-05 16:13:08 +00:00
|
|
|
|
|
|
|
|
/** @var array Cache of already-logged deprecation messages */
|
|
|
|
|
private static $loggedDeprecations = [];
|
|
|
|
|
|
2019-04-10 15:03:54 +00:00
|
|
|
/**
|
|
|
|
|
* @var array
|
|
|
|
|
* @since 1.34
|
|
|
|
|
*/
|
2019-10-08 18:33:31 +00:00
|
|
|
public const APPLY_DEFAULT_CONFIG_OPTIONS = [
|
2019-04-10 15:03:54 +00:00
|
|
|
'DBcompress',
|
|
|
|
|
'DBDefaultGroup',
|
|
|
|
|
'DBmwschema',
|
|
|
|
|
'DBname',
|
|
|
|
|
'DBpassword',
|
|
|
|
|
'DBport',
|
|
|
|
|
'DBprefix',
|
|
|
|
|
'DBserver',
|
|
|
|
|
'DBservers',
|
|
|
|
|
'DBssl',
|
|
|
|
|
'DBtype',
|
|
|
|
|
'DBuser',
|
|
|
|
|
'DebugDumpSql',
|
2019-05-07 00:01:03 +00:00
|
|
|
'DebugLogFile',
|
2019-04-10 15:03:54 +00:00
|
|
|
'ExternalServers',
|
|
|
|
|
'SQLiteDataDir',
|
|
|
|
|
'SQLMode',
|
|
|
|
|
];
|
|
|
|
|
|
2016-09-14 11:34:17 +00:00
|
|
|
/**
|
2016-09-18 01:50:56 +00:00
|
|
|
* @param array $lbConf Config for LBFactory::__construct()
|
2019-04-10 15:03:54 +00:00
|
|
|
* @param ServiceOptions $options
|
2017-04-10 05:34:30 +00:00
|
|
|
* @param ConfiguredReadOnlyMode $readOnlyMode
|
2019-08-28 14:23:19 +00:00
|
|
|
* @param BagOStuff $srvCache
|
2019-03-22 07:17:36 +00:00
|
|
|
* @param BagOStuff $mainStash
|
|
|
|
|
* @param WANObjectCache $wanCache
|
2016-09-15 18:52:55 +00:00
|
|
|
* @return array
|
2019-07-04 06:29:06 +00:00
|
|
|
* @internal For use with service wiring
|
2016-09-15 18:52:55 +00:00
|
|
|
*/
|
2019-03-22 07:17:36 +00:00
|
|
|
public static function applyDefaultConfig(
|
|
|
|
|
array $lbConf,
|
2019-04-10 15:03:54 +00:00
|
|
|
ServiceOptions $options,
|
2019-03-22 07:17:36 +00:00
|
|
|
ConfiguredReadOnlyMode $readOnlyMode,
|
2019-08-28 14:23:19 +00:00
|
|
|
BagOStuff $srvCache,
|
2019-03-22 07:17:36 +00:00
|
|
|
BagOStuff $mainStash,
|
|
|
|
|
WANObjectCache $wanCache
|
2017-04-10 05:34:30 +00:00
|
|
|
) {
|
2019-10-08 18:33:31 +00:00
|
|
|
$options->assertRequiredOptions( self::APPLY_DEFAULT_CONFIG_OPTIONS );
|
2019-04-10 15:03:54 +00:00
|
|
|
|
2016-09-15 20:51:31 +00:00
|
|
|
global $wgCommandLineMode;
|
2016-09-15 09:21:21 +00:00
|
|
|
|
2019-04-09 21:45:36 +00:00
|
|
|
$typesWithSchema = self::getDbTypesWithSchemas();
|
2016-11-17 21:59:20 +00:00
|
|
|
|
2016-09-18 01:50:56 +00:00
|
|
|
$lbConf += [
|
|
|
|
|
'localDomain' => new DatabaseDomain(
|
2019-04-10 15:03:54 +00:00
|
|
|
$options->get( 'DBname' ),
|
|
|
|
|
$options->get( 'DBmwschema' ),
|
|
|
|
|
$options->get( 'DBprefix' )
|
2016-09-18 01:50:56 +00:00
|
|
|
),
|
2019-03-13 18:11:18 +00:00
|
|
|
'profiler' => function ( $section ) {
|
|
|
|
|
return Profiler::instance()->scopedProfileIn( $section );
|
|
|
|
|
},
|
2016-09-14 11:34:17 +00:00
|
|
|
'trxProfiler' => Profiler::instance()->getTransactionProfiler(),
|
|
|
|
|
'replLogger' => LoggerFactory::getInstance( 'DBReplication' ),
|
2016-09-16 20:57:56 +00:00
|
|
|
'queryLogger' => LoggerFactory::getInstance( 'DBQuery' ),
|
|
|
|
|
'connLogger' => LoggerFactory::getInstance( 'DBConnection' ),
|
2016-09-14 11:34:17 +00:00
|
|
|
'perfLogger' => LoggerFactory::getInstance( 'DBPerformance' ),
|
2016-09-15 18:52:55 +00:00
|
|
|
'errorLogger' => [ MWExceptionHandler::class, 'logException' ],
|
2018-04-05 16:13:08 +00:00
|
|
|
'deprecationLogger' => [ static::class, 'logDeprecation' ],
|
2016-09-15 18:52:55 +00:00
|
|
|
'cliMode' => $wgCommandLineMode,
|
2016-09-18 01:50:56 +00:00
|
|
|
'hostname' => wfHostname(),
|
2017-04-10 05:34:30 +00:00
|
|
|
'readOnlyReason' => $readOnlyMode->getReason(),
|
2019-04-10 15:03:54 +00:00
|
|
|
'defaultGroup' => $options->get( 'DBDefaultGroup' ),
|
2016-09-14 11:34:17 +00:00
|
|
|
];
|
2016-09-18 01:50:56 +00:00
|
|
|
|
2019-03-26 06:09:32 +00:00
|
|
|
$serversCheck = [];
|
2017-02-24 03:39:03 +00:00
|
|
|
// When making changes here, remember to also specify MediaWiki-specific options
|
|
|
|
|
// for Database classes in the relevant Installer subclass.
|
|
|
|
|
// Such as MysqlInstaller::openConnection and PostgresInstaller::openConnectionWithParams.
|
2018-01-13 00:02:09 +00:00
|
|
|
if ( $lbConf['class'] === Wikimedia\Rdbms\LBFactorySimple::class ) {
|
2016-09-18 01:50:56 +00:00
|
|
|
if ( isset( $lbConf['servers'] ) ) {
|
2019-04-09 21:45:36 +00:00
|
|
|
// Server array is already explicitly configured
|
2019-04-10 15:03:54 +00:00
|
|
|
} elseif ( is_array( $options->get( 'DBservers' ) ) ) {
|
2019-03-26 06:09:32 +00:00
|
|
|
$lbConf['servers'] = [];
|
2019-04-10 15:03:54 +00:00
|
|
|
foreach ( $options->get( 'DBservers' ) as $i => $server ) {
|
|
|
|
|
$lbConf['servers'][$i] = self::initServerInfo( $server, $options );
|
2016-09-18 01:50:56 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2019-04-09 21:45:36 +00:00
|
|
|
$server = self::initServerInfo(
|
|
|
|
|
[
|
2019-04-10 15:03:54 +00:00
|
|
|
'host' => $options->get( 'DBserver' ),
|
|
|
|
|
'user' => $options->get( 'DBuser' ),
|
|
|
|
|
'password' => $options->get( 'DBpassword' ),
|
|
|
|
|
'dbname' => $options->get( 'DBname' ),
|
|
|
|
|
'type' => $options->get( 'DBtype' ),
|
2019-04-09 21:45:36 +00:00
|
|
|
'load' => 1
|
|
|
|
|
],
|
2019-04-10 15:03:54 +00:00
|
|
|
$options
|
2019-04-09 21:45:36 +00:00
|
|
|
);
|
|
|
|
|
|
2019-04-10 15:03:54 +00:00
|
|
|
$server['flags'] |= $options->get( 'DBssl' ) ? DBO_SSL : 0;
|
|
|
|
|
$server['flags'] |= $options->get( 'DBcompress' ) ? DBO_COMPRESS : 0;
|
2019-04-09 21:45:36 +00:00
|
|
|
|
2016-09-18 01:50:56 +00:00
|
|
|
$lbConf['servers'] = [ $server ];
|
|
|
|
|
}
|
2016-09-19 22:13:43 +00:00
|
|
|
if ( !isset( $lbConf['externalClusters'] ) ) {
|
2019-04-10 15:03:54 +00:00
|
|
|
$lbConf['externalClusters'] = $options->get( 'ExternalServers' );
|
2016-09-18 01:50:56 +00:00
|
|
|
}
|
2019-03-26 06:09:32 +00:00
|
|
|
|
|
|
|
|
$serversCheck = $lbConf['servers'];
|
2018-01-13 00:02:09 +00:00
|
|
|
} elseif ( $lbConf['class'] === Wikimedia\Rdbms\LBFactoryMulti::class ) {
|
2016-09-18 01:50:56 +00:00
|
|
|
if ( isset( $lbConf['serverTemplate'] ) ) {
|
2016-11-17 21:59:20 +00:00
|
|
|
if ( in_array( $lbConf['serverTemplate']['type'], $typesWithSchema, true ) ) {
|
2019-04-10 15:03:54 +00:00
|
|
|
$lbConf['serverTemplate']['schema'] = $options->get( 'DBmwschema' );
|
2016-11-17 21:59:20 +00:00
|
|
|
}
|
2019-04-10 15:03:54 +00:00
|
|
|
$lbConf['serverTemplate']['sqlMode'] = $options->get( 'SQLMode' );
|
2016-09-18 01:50:56 +00:00
|
|
|
}
|
2019-04-09 21:45:36 +00:00
|
|
|
$serversCheck = [ $lbConf['serverTemplate'] ] ?? [];
|
2016-09-18 01:50:56 +00:00
|
|
|
}
|
|
|
|
|
|
2019-07-04 06:29:06 +00:00
|
|
|
self::assertValidServerConfigs(
|
|
|
|
|
$serversCheck,
|
|
|
|
|
$options->get( 'DBname' ),
|
|
|
|
|
$options->get( 'DBprefix' )
|
|
|
|
|
);
|
2019-04-09 21:45:36 +00:00
|
|
|
|
2019-08-28 14:23:19 +00:00
|
|
|
$lbConf = self::injectObjectCaches( $lbConf, $srvCache, $mainStash, $wanCache );
|
2019-03-22 07:17:36 +00:00
|
|
|
|
|
|
|
|
return $lbConf;
|
|
|
|
|
}
|
2017-08-17 03:13:35 +00:00
|
|
|
|
2019-04-09 21:45:36 +00:00
|
|
|
/**
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
private static function getDbTypesWithSchemas() {
|
2019-08-15 12:21:55 +00:00
|
|
|
return [ 'postgres' ];
|
2019-04-09 21:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $server
|
2019-04-10 15:03:54 +00:00
|
|
|
* @param ServiceOptions $options
|
2019-04-09 21:45:36 +00:00
|
|
|
* @return array
|
|
|
|
|
*/
|
2019-04-10 15:03:54 +00:00
|
|
|
private static function initServerInfo( array $server, ServiceOptions $options ) {
|
2019-04-09 21:45:36 +00:00
|
|
|
if ( $server['type'] === 'sqlite' ) {
|
|
|
|
|
$httpMethod = $_SERVER['REQUEST_METHOD'] ?? null;
|
|
|
|
|
// T93097: hint for how file-based databases (e.g. sqlite) should go about locking.
|
|
|
|
|
// See https://www.sqlite.org/lang_transaction.html
|
|
|
|
|
// See https://www.sqlite.org/lockingv3.html#shared_lock
|
|
|
|
|
$isHttpRead = in_array( $httpMethod, [ 'GET', 'HEAD', 'OPTIONS', 'TRACE' ] );
|
|
|
|
|
$server += [
|
2019-04-10 15:03:54 +00:00
|
|
|
'dbDirectory' => $options->get( 'SQLiteDataDir' ),
|
2019-04-09 21:45:36 +00:00
|
|
|
'trxMode' => $isHttpRead ? 'DEFERRED' : 'IMMEDIATE'
|
|
|
|
|
];
|
|
|
|
|
} elseif ( $server['type'] === 'postgres' ) {
|
|
|
|
|
$server += [
|
2019-04-10 15:03:54 +00:00
|
|
|
'port' => $options->get( 'DBport' ),
|
2019-04-09 21:45:36 +00:00
|
|
|
// Work around the reserved word usage in MediaWiki schema
|
|
|
|
|
'keywordTableMap' => [ 'user' => 'mwuser', 'text' => 'pagecontent' ]
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( in_array( $server['type'], self::getDbTypesWithSchemas(), true ) ) {
|
2019-04-10 15:03:54 +00:00
|
|
|
$server += [ 'schema' => $options->get( 'DBmwschema' ) ];
|
2019-04-09 21:45:36 +00:00
|
|
|
}
|
|
|
|
|
|
rdbms: Restore debug toolbar "Queries" feature
This broke after e0cc49ce3971e19, due to the field 'master'
being removed from the log context. The LegacyLogger logic
forwarding these messages to MWDebug (for the debug toolbar)
however, was dependant on.
Users of debug toolbar experienced a silent failure because the
logic in question is very tolerant of missing fields. This is
because it uses those fields to distinguish the 'sql' messages
from channel=DBQuery from other messages in the same channel.
Making that less fragile is outside the scope of this commit.
This commit:
* Restore the basic functionality by making sure MWDebug::query()
gets called again for DBQuery messages.
* Remove the code relating to the 'master' field as this no longer
exists in RDBMS. It also wasn't used anywhere (to be used,
it would need to be read by mediawiki.debug/debug.js).
* Remove unexpanded "{method}" and "{runtime}" noise in the debug
toolbar text. This was introduced by he conversion to PSR-3
logging.. These fields are already rendered separately by
the toolbar and should not be part of the "SQL" column.
To do this, we need to log the $sql bit as its own key, so
I've made this a context field as well.
* Reduce the condition logic in LegacyLogger to only looking for
'DBQuery' and 'sql'. This way, if it breaks again it will
still call the logic within and emit E_NOTICE instead, which
would help detect the issue (and still fallback to at least
showing the queries). Unlike before this commit where it took
quite some time to figure out why it wasn't working.
* The above fixes still weren't enough to get queries to show
up in the Debug toolbar for me. Turns out, this was because
my local setup (mediawiki-docker-dev) uses a master-replica
set up. The setup doesn't use any custom LBFactory config,
just plain $wgDBservers. The logic for turning these plain
settings into LBFactory (in MWLBFactory.php) does kick in,
and does run (unlike if I had custom wgLBFactoryConf).
But, the DBO_DEBUG flag didn't make it through because of
the += operator preferring any pre-existing value my setup
has, which is just `DBO_DEFAULT`.
Merging 'flags' keys seems unsafe in general, but adding
DBO_DEBUG based on $wgDebugDumpSql seems innocent and doesn't
affect other behaviour (it's a case of DWIM).
Bug: T231742
Change-Id: I122bb1a65620a7ae4e1943136c975b63524a5111
2019-10-05 01:56:12 +00:00
|
|
|
$flags = $server['flags'] ?? DBO_DEFAULT;
|
|
|
|
|
if ( $options->get( 'DebugDumpSql' ) || $options->get( 'DebugLogFile' ) ) {
|
|
|
|
|
$flags |= DBO_DEBUG;
|
|
|
|
|
}
|
|
|
|
|
$server['flags'] = $flags;
|
2019-04-09 21:45:36 +00:00
|
|
|
|
|
|
|
|
$server += [
|
2019-04-10 15:03:54 +00:00
|
|
|
'tablePrefix' => $options->get( 'DBprefix' ),
|
|
|
|
|
'sqlMode' => $options->get( 'SQLMode' ),
|
2019-04-09 21:45:36 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return $server;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-22 07:17:36 +00:00
|
|
|
/**
|
|
|
|
|
* @param array $lbConf
|
|
|
|
|
* @param BagOStuff $sCache
|
|
|
|
|
* @param BagOStuff $mStash
|
|
|
|
|
* @param WANObjectCache $wCache
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2019-04-09 21:45:36 +00:00
|
|
|
private static function injectObjectCaches(
|
2019-03-22 07:17:36 +00:00
|
|
|
array $lbConf, BagOStuff $sCache, BagOStuff $mStash, WANObjectCache $wCache
|
|
|
|
|
) {
|
2019-08-28 14:23:19 +00:00
|
|
|
// Fallback if APC style caching is not an option
|
|
|
|
|
if ( $sCache instanceof EmptyBagOStuff ) {
|
|
|
|
|
$sCache = new HashBagOStuff( [ 'maxKeys' => 100 ] );
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-14 11:34:17 +00:00
|
|
|
// Use APC/memcached style caching, but avoids loops with CACHE_DB (T141804)
|
|
|
|
|
if ( $sCache->getQoS( $sCache::ATTR_EMULATION ) > $sCache::QOS_EMULATION_SQL ) {
|
2016-09-18 01:50:56 +00:00
|
|
|
$lbConf['srvCache'] = $sCache;
|
2016-09-14 11:34:17 +00:00
|
|
|
}
|
2017-08-17 03:13:35 +00:00
|
|
|
if ( $mStash->getQoS( $mStash::ATTR_EMULATION ) > $mStash::QOS_EMULATION_SQL ) {
|
|
|
|
|
$lbConf['memStash'] = $mStash;
|
2016-09-14 11:34:17 +00:00
|
|
|
}
|
|
|
|
|
if ( $wCache->getQoS( $wCache::ATTR_EMULATION ) > $wCache::QOS_EMULATION_SQL ) {
|
2016-09-18 01:50:56 +00:00
|
|
|
$lbConf['wanCache'] = $wCache;
|
2016-09-16 03:33:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-18 01:50:56 +00:00
|
|
|
return $lbConf;
|
2016-09-14 11:34:17 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-22 07:17:36 +00:00
|
|
|
/**
|
2019-03-26 06:09:32 +00:00
|
|
|
* @param array $servers
|
2019-05-22 19:50:52 +00:00
|
|
|
* @param string $ldDB Local domain database name
|
|
|
|
|
* @param string $ldTP Local domain prefix
|
2019-03-26 06:09:32 +00:00
|
|
|
*/
|
2019-04-10 15:03:54 +00:00
|
|
|
private static function assertValidServerConfigs( array $servers, $ldDB, $ldTP ) {
|
2019-03-26 06:09:32 +00:00
|
|
|
foreach ( $servers as $server ) {
|
|
|
|
|
$type = $server['type'] ?? null;
|
|
|
|
|
$srvDB = $server['dbname'] ?? null; // server DB
|
|
|
|
|
$srvTP = $server['tablePrefix'] ?? ''; // server table prefix
|
|
|
|
|
|
|
|
|
|
if ( $type === 'mysql' ) {
|
|
|
|
|
// A DB name is not needed to connect to mysql; 'dbname' is useless.
|
|
|
|
|
// This field only defines the DB to use for unspecified DB domains.
|
|
|
|
|
if ( $srvDB !== null && $srvDB !== $ldDB ) {
|
|
|
|
|
self::reportMismatchedDBs( $srvDB, $ldDB );
|
|
|
|
|
}
|
|
|
|
|
} elseif ( $type === 'postgres' ) {
|
|
|
|
|
if ( $srvTP !== '' ) {
|
|
|
|
|
self::reportIfPrefixSet( $srvTP, $type );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $srvTP !== '' && $srvTP !== $ldTP ) {
|
|
|
|
|
self::reportMismatchedPrefixes( $srvTP, $ldTP );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $prefix Table prefix
|
|
|
|
|
* @param string $dbType Database type
|
|
|
|
|
*/
|
|
|
|
|
private static function reportIfPrefixSet( $prefix, $dbType ) {
|
|
|
|
|
$e = new UnexpectedValueException(
|
|
|
|
|
"\$wgDBprefix is set to '$prefix' but the database type is '$dbType'. " .
|
|
|
|
|
"MediaWiki does not support using a table prefix with this RDBMS type."
|
|
|
|
|
);
|
|
|
|
|
MWExceptionRenderer::output( $e, MWExceptionRenderer::AS_PRETTY );
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-03-22 07:17:36 +00:00
|
|
|
* @param string $srvDB Server config database
|
|
|
|
|
* @param string $ldDB Local DB domain database
|
|
|
|
|
*/
|
|
|
|
|
private static function reportMismatchedDBs( $srvDB, $ldDB ) {
|
|
|
|
|
$e = new UnexpectedValueException(
|
|
|
|
|
"\$wgDBservers has dbname='$srvDB' but \$wgDBname='$ldDB'. " .
|
|
|
|
|
"Set \$wgDBname to the database used by this wiki project. " .
|
|
|
|
|
"There is rarely a need to set 'dbname' in \$wgDBservers. " .
|
2019-03-29 21:56:18 +00:00
|
|
|
"Cross-wiki database access, use of WikiMap::getCurrentWikiDbDomain(), " .
|
|
|
|
|
"use of Database::getDomainId(), and other features are not reliable when " .
|
2019-03-22 07:17:36 +00:00
|
|
|
"\$wgDBservers does not match the local wiki database/prefix."
|
|
|
|
|
);
|
|
|
|
|
MWExceptionRenderer::output( $e, MWExceptionRenderer::AS_PRETTY );
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $srvTP Server config table prefix
|
|
|
|
|
* @param string $ldTP Local DB domain database
|
|
|
|
|
*/
|
|
|
|
|
private static function reportMismatchedPrefixes( $srvTP, $ldTP ) {
|
|
|
|
|
$e = new UnexpectedValueException(
|
|
|
|
|
"\$wgDBservers has tablePrefix='$srvTP' but \$wgDBprefix='$ldTP'. " .
|
|
|
|
|
"Set \$wgDBprefix to the table prefix used by this wiki project. " .
|
|
|
|
|
"There is rarely a need to set 'tablePrefix' in \$wgDBservers. " .
|
2019-03-29 21:56:18 +00:00
|
|
|
"Cross-wiki database access, use of WikiMap::getCurrentWikiDbDomain(), " .
|
|
|
|
|
"use of Database::getDomainId(), and other features are not reliable when " .
|
2019-03-22 07:17:36 +00:00
|
|
|
"\$wgDBservers does not match the local wiki database/prefix."
|
|
|
|
|
);
|
|
|
|
|
MWExceptionRenderer::output( $e, MWExceptionRenderer::AS_PRETTY );
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-14 11:34:17 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the LBFactory class to use and the load balancer configuration.
|
|
|
|
|
*
|
|
|
|
|
* @todo instead of this, use a ServiceContainer for managing the different implementations.
|
|
|
|
|
*
|
|
|
|
|
* @param array $config (e.g. $wgLBFactoryConf)
|
|
|
|
|
* @return string Class name
|
2019-07-04 06:29:06 +00:00
|
|
|
* @internal For use with service wiring
|
2016-09-14 11:34:17 +00:00
|
|
|
*/
|
|
|
|
|
public static function getLBFactoryClass( array $config ) {
|
|
|
|
|
// For configuration backward compatibility after removing
|
|
|
|
|
// underscores from class names in MediaWiki 1.23.
|
|
|
|
|
$bcClasses = [
|
|
|
|
|
'LBFactory_Simple' => 'LBFactorySimple',
|
|
|
|
|
'LBFactory_Single' => 'LBFactorySingle',
|
|
|
|
|
'LBFactory_Multi' => 'LBFactoryMulti'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$class = $config['class'];
|
|
|
|
|
|
|
|
|
|
if ( isset( $bcClasses[$class] ) ) {
|
|
|
|
|
$class = $bcClasses[$class];
|
|
|
|
|
wfDeprecated(
|
|
|
|
|
'$wgLBFactoryConf must be updated. See RELEASE-NOTES for details',
|
|
|
|
|
'1.23'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-26 18:27:37 +00:00
|
|
|
// For configuration backward compatibility after moving classes to namespaces (1.29)
|
|
|
|
|
$compat = [
|
|
|
|
|
'LBFactorySingle' => Wikimedia\Rdbms\LBFactorySingle::class,
|
|
|
|
|
'LBFactorySimple' => Wikimedia\Rdbms\LBFactorySimple::class,
|
|
|
|
|
'LBFactoryMulti' => Wikimedia\Rdbms\LBFactoryMulti::class
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if ( isset( $compat[$class] ) ) {
|
|
|
|
|
$class = $compat[$class];
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-14 11:34:17 +00:00
|
|
|
return $class;
|
|
|
|
|
}
|
2018-02-17 22:09:02 +00:00
|
|
|
|
2018-04-05 16:13:08 +00:00
|
|
|
/**
|
|
|
|
|
* Log a database deprecation warning
|
|
|
|
|
* @param string $msg Deprecation message
|
2019-07-04 06:29:06 +00:00
|
|
|
* @internal For use with service wiring
|
2018-04-05 16:13:08 +00:00
|
|
|
*/
|
|
|
|
|
public static function logDeprecation( $msg ) {
|
|
|
|
|
global $wgDevelopmentWarnings;
|
|
|
|
|
|
|
|
|
|
if ( isset( self::$loggedDeprecations[$msg] ) ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
self::$loggedDeprecations[$msg] = true;
|
|
|
|
|
|
|
|
|
|
if ( $wgDevelopmentWarnings ) {
|
|
|
|
|
trigger_error( $msg, E_USER_DEPRECATED );
|
|
|
|
|
}
|
|
|
|
|
wfDebugLog( 'deprecated', $msg, 'private' );
|
|
|
|
|
}
|
2016-09-14 11:34:17 +00:00
|
|
|
}
|