Go to the documentation of this file.
41 public const APPLY_DEFAULT_CONFIG_OPTIONS = [
54 'DBWindowsAuthentication',
88 $options->
get(
'DBname' ),
89 $options->
get(
'DBmwschema' ),
90 $options->
get(
'DBprefix' )
92 'profiler' =>
function ( $section ) {
96 'replLogger' => LoggerFactory::getInstance(
'DBReplication' ),
97 'queryLogger' => LoggerFactory::getInstance(
'DBQuery' ),
98 'connLogger' => LoggerFactory::getInstance(
'DBConnection' ),
99 'perfLogger' => LoggerFactory::getInstance(
'DBPerformance' ),
100 'errorLogger' => [ MWExceptionHandler::class,
'logException' ],
101 'deprecationLogger' => [ static::class,
'logDeprecation' ],
104 'readOnlyReason' => $readOnlyMode->
getReason(),
105 'defaultGroup' => $options->
get(
'DBDefaultGroup' ),
112 if ( $lbConf[
'class'] ===
Wikimedia\Rdbms\LBFactorySimple::class ) {
113 if ( isset( $lbConf[
'servers'] ) ) {
115 } elseif ( is_array( $options->
get(
'DBservers' ) ) ) {
116 $lbConf[
'servers'] = [];
117 foreach ( $options->
get(
'DBservers' ) as $i => $server ) {
123 'host' => $options->
get(
'DBserver' ),
124 'user' => $options->
get(
'DBuser' ),
125 'password' => $options->
get(
'DBpassword' ),
126 'dbname' => $options->
get(
'DBname' ),
127 'type' => $options->
get(
'DBtype' ),
133 $server[
'flags'] |= $options->
get(
'DBssl' ) ?
DBO_SSL : 0;
136 $lbConf[
'servers'] = [ $server ];
138 if ( !isset( $lbConf[
'externalClusters'] ) ) {
139 $lbConf[
'externalClusters'] = $options->
get(
'ExternalServers' );
142 $serversCheck = $lbConf[
'servers'];
143 } elseif ( $lbConf[
'class'] ===
Wikimedia\Rdbms\LBFactoryMulti::class ) {
144 if ( isset( $lbConf[
'serverTemplate'] ) ) {
145 if ( in_array( $lbConf[
'serverTemplate'][
'type'], $typesWithSchema,
true ) ) {
146 $lbConf[
'serverTemplate'][
'schema'] = $options->
get(
'DBmwschema' );
148 $lbConf[
'serverTemplate'][
'sqlMode'] = $options->
get(
'SQLMode' );
150 $serversCheck = [ $lbConf[
'serverTemplate'] ] ?? [];
155 $options->
get(
'DBname' ),
156 $options->
get(
'DBprefix' )
168 return [
'postgres' ];
177 if ( $server[
'type'] ===
'sqlite' ) {
178 $httpMethod = $_SERVER[
'REQUEST_METHOD'] ??
null;
182 $isHttpRead = in_array( $httpMethod, [
'GET',
'HEAD',
'OPTIONS',
'TRACE' ] );
184 'dbDirectory' => $options->
get(
'SQLiteDataDir' ),
185 'trxMode' => $isHttpRead ?
'DEFERRED' :
'IMMEDIATE'
187 } elseif ( $server[
'type'] ===
'postgres' ) {
189 'port' => $options->
get(
'DBport' ),
191 'keywordTableMap' => [
'user' =>
'mwuser',
'text' =>
'pagecontent' ]
195 if ( in_array( $server[
'type'], self::getDbTypesWithSchemas(),
true ) ) {
196 $server += [
'schema' => $options->
get(
'DBmwschema' ) ];
200 if ( $options->
get(
'DebugDumpSql' ) || $options->
get(
'DebugLogFile' ) ) {
203 $server[
'flags'] = $flags;
206 'tablePrefix' => $options->
get(
'DBprefix' ),
207 'sqlMode' => $options->
get(
'SQLMode' ),
229 if ( $sCache->
getQoS( $sCache::ATTR_EMULATION ) > $sCache::QOS_EMULATION_SQL ) {
230 $lbConf[
'srvCache'] = $sCache;
232 if ( $mStash->
getQoS( $mStash::ATTR_EMULATION ) > $mStash::QOS_EMULATION_SQL ) {
233 $lbConf[
'memStash'] = $mStash;
235 if ( $wCache->
getQoS( $wCache::ATTR_EMULATION ) > $wCache::QOS_EMULATION_SQL ) {
236 $lbConf[
'wanCache'] = $wCache;
248 foreach ( $servers as $server ) {
249 $type = $server[
'type'] ??
null;
250 $srvDB = $server[
'dbname'] ??
null;
251 $srvTP = $server[
'tablePrefix'] ??
'';
253 if (
$type ===
'mysql' ) {
256 if ( $srvDB !==
null && $srvDB !== $ldDB ) {
259 } elseif (
$type ===
'postgres' ) {
260 if ( $srvTP !==
'' ) {
265 if ( $srvTP !==
'' && $srvTP !== $ldTP ) {
276 $e =
new UnexpectedValueException(
277 "\$wgDBprefix is set to '$prefix' but the database type is '$dbType'. " .
278 "MediaWiki does not support using a table prefix with this RDBMS type."
289 $e =
new UnexpectedValueException(
290 "\$wgDBservers has dbname='$srvDB' but \$wgDBname='$ldDB'. " .
291 "Set \$wgDBname to the database used by this wiki project. " .
292 "There is rarely a need to set 'dbname' in \$wgDBservers. " .
293 "Cross-wiki database access, use of WikiMap::getCurrentWikiDbDomain(), " .
294 "use of Database::getDomainId(), and other features are not reliable when " .
295 "\$wgDBservers does not match the local wiki database/prefix."
306 $e =
new UnexpectedValueException(
307 "\$wgDBservers has tablePrefix='$srvTP' but \$wgDBprefix='$ldTP'. " .
308 "Set \$wgDBprefix to the table prefix used by this wiki project. " .
309 "There is rarely a need to set 'tablePrefix' in \$wgDBservers. " .
310 "Cross-wiki database access, use of WikiMap::getCurrentWikiDbDomain(), " .
311 "use of Database::getDomainId(), and other features are not reliable when " .
312 "\$wgDBservers does not match the local wiki database/prefix."
331 'LBFactory_Simple' =>
'LBFactorySimple',
332 'LBFactory_Single' =>
'LBFactorySingle',
333 'LBFactory_Multi' =>
'LBFactoryMulti'
336 $class = $config[
'class'];
338 if ( isset( $bcClasses[$class] ) ) {
339 $class = $bcClasses[$class];
341 '$wgLBFactoryConf must be updated. See RELEASE-NOTES for details',
348 'LBFactorySingle' => Wikimedia\Rdbms\LBFactorySingle::class,
349 'LBFactorySimple' => Wikimedia\Rdbms\LBFactorySimple::class,
350 'LBFactoryMulti' => Wikimedia\Rdbms\LBFactoryMulti::class
353 if ( isset( $compat[$class] ) ) {
354 $class = $compat[$class];
368 if ( isset( self::$loggedDeprecations[$msg] ) ) {
371 self::$loggedDeprecations[$msg] =
true;
374 trigger_error( $msg, E_USER_DEPRECATED );
MediaWiki-specific class for generating database load balancers.
static reportMismatchedDBs( $srvDB, $ldDB)
Simple store for keeping values in an associative array for the current process.
A BagOStuff object with no objects in it.
static instance()
Singleton.
static initServerInfo(array $server, ServiceOptions $options)
static assertValidServerConfigs(array $servers, $ldDB, $ldTP)
wfHostname()
Fetch server name for use in error reporting etc.
Class representing a cache/ephemeral data store.
static logDeprecation( $msg)
Log a database deprecation warning.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
static reportMismatchedPrefixes( $srvTP, $ldTP)
static array $loggedDeprecations
Cache of already-logged deprecation messages.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
global $wgCommandLineMode
static applyDefaultConfig(array $lbConf, ServiceOptions $options, ConfiguredReadOnlyMode $readOnlyMode, BagOStuff $srvCache, BagOStuff $mainStash, WANObjectCache $wanCache)
static getLBFactoryClass(array $config)
Returns the LBFactory class to use and the load balancer configuration.
Multi-datacenter aware caching interface.
$wgDevelopmentWarnings
If set to true MediaWiki will throw notices for some possible error conditions and for deprecated fun...
static output( $e, $mode, $eNew=null)
static injectObjectCaches(array $lbConf, BagOStuff $sCache, BagOStuff $mStash, WANObjectCache $wCache)
Class to handle database/schema/prefix specifications for IDatabase.
static getDbTypesWithSchemas()
static reportIfPrefixSet( $prefix, $dbType)