32 use Wikimedia\RequestTimeout\CriticalSectionProvider;
50 MainConfigNames::DBcompress,
51 MainConfigNames::DBDefaultGroup,
52 MainConfigNames::DBmwschema,
53 MainConfigNames::DBname,
54 MainConfigNames::DBpassword,
55 MainConfigNames::DBport,
56 MainConfigNames::DBprefix,
57 MainConfigNames::DBserver,
58 MainConfigNames::DBservers,
59 MainConfigNames::DBssl,
60 MainConfigNames::DBtype,
61 MainConfigNames::DBuser,
62 MainConfigNames::DebugDumpSql,
63 MainConfigNames::DebugLogFile,
64 MainConfigNames::DebugToolbar,
65 MainConfigNames::ExternalServers,
66 MainConfigNames::SQLiteDataDir,
67 MainConfigNames::SQLMode,
88 CriticalSectionProvider $csProvider
96 $options->
get( MainConfigNames::DBname ),
97 $options->
get( MainConfigNames::DBmwschema ),
98 $options->
get( MainConfigNames::DBprefix )
100 'profiler' =>
static function ( $section ) {
104 'replLogger' => LoggerFactory::getInstance(
'DBReplication' ),
105 'queryLogger' => LoggerFactory::getInstance(
'DBQuery' ),
106 'connLogger' => LoggerFactory::getInstance(
'DBConnection' ),
107 'perfLogger' => LoggerFactory::getInstance(
'DBPerformance' ),
108 'errorLogger' => [ MWExceptionHandler::class,
'logException' ],
109 'deprecationLogger' => [ static::class,
'logDeprecation' ],
110 'cliMode' => $options->
get(
'CommandLineMode' ),
111 'readOnlyReason' => $readOnlyMode->
getReason(),
112 'defaultGroup' => $options->
get( MainConfigNames::DBDefaultGroup ),
113 'criticalSectionProvider' => $csProvider
120 if ( $lbConf[
'class'] === Wikimedia\Rdbms\LBFactorySimple::class ) {
121 if ( isset( $lbConf[
'servers'] ) ) {
123 } elseif ( is_array( $options->
get( MainConfigNames::DBservers ) ) ) {
124 $lbConf[
'servers'] = [];
125 foreach ( $options->
get( MainConfigNames::DBservers ) as $i => $server ) {
131 'host' => $options->
get( MainConfigNames::DBserver ),
132 'user' => $options->
get( MainConfigNames::DBuser ),
133 'password' => $options->
get( MainConfigNames::DBpassword ),
134 'dbname' => $options->
get( MainConfigNames::DBname ),
135 'type' => $options->
get( MainConfigNames::DBtype ),
141 $server[
'flags'] |= $options->
get( MainConfigNames::DBssl ) ?
DBO_SSL : 0;
142 $server[
'flags'] |= $options->
get( MainConfigNames::DBcompress ) ?
DBO_COMPRESS : 0;
144 $lbConf[
'servers'] = [ $server ];
146 if ( !isset( $lbConf[
'externalClusters'] ) ) {
147 $lbConf[
'externalClusters'] = $options->
get( MainConfigNames::ExternalServers );
150 $serversCheck = $lbConf[
'servers'];
151 } elseif ( $lbConf[
'class'] === Wikimedia\Rdbms\LBFactoryMulti::class ) {
152 if ( isset( $lbConf[
'serverTemplate'] ) ) {
153 if ( in_array( $lbConf[
'serverTemplate'][
'type'], $typesWithSchema,
true ) ) {
154 $lbConf[
'serverTemplate'][
'schema'] = $options->
get( MainConfigNames::DBmwschema );
156 $lbConf[
'serverTemplate'][
'sqlMode'] = $options->
get( MainConfigNames::SQLMode );
157 $serversCheck = [ $lbConf[
'serverTemplate'] ];
163 $options->
get( MainConfigNames::DBname ),
164 $options->
get( MainConfigNames::DBprefix )
167 $lbConf[
'cpStash'] = $cpStash;
168 $lbConf[
'srvCache'] = $srvCache;
169 $lbConf[
'wanCache'] = $wanCache;
178 return [
'postgres' ];
187 if ( $server[
'type'] ===
'sqlite' ) {
188 $httpMethod = $_SERVER[
'REQUEST_METHOD'] ??
null;
192 $isHttpRead = in_array( $httpMethod, [
'GET',
'HEAD',
'OPTIONS',
'TRACE' ] );
197 if ( $request->hasHeader(
'Promise-Non-Write-API-Action' ) ) {
202 'dbDirectory' => $options->
get( MainConfigNames::SQLiteDataDir ),
203 'trxMode' => $isHttpRead ?
'DEFERRED' :
'IMMEDIATE'
205 } elseif ( $server[
'type'] ===
'postgres' ) {
206 $server += [
'port' => $options->
get( MainConfigNames::DBport ) ];
209 if ( in_array( $server[
'type'], self::getDbTypesWithSchemas(),
true ) ) {
210 $server += [
'schema' => $options->
get( MainConfigNames::DBmwschema ) ];
214 if ( $options->
get( MainConfigNames::DebugDumpSql )
215 || $options->
get( MainConfigNames::DebugLogFile )
216 || $options->
get( MainConfigNames::DebugToolbar )
220 $server[
'flags'] = $flags;
223 'tablePrefix' => $options->
get( MainConfigNames::DBprefix ),
224 'sqlMode' => $options->
get( MainConfigNames::SQLMode ),
236 foreach ( $servers as $server ) {
237 $type = $server[
'type'] ??
null;
238 $srvDB = $server[
'dbname'] ??
null;
239 $srvTP = $server[
'tablePrefix'] ??
'';
241 if (
$type ===
'mysql' ) {
244 if ( $srvDB !==
null && $srvDB !== $ldDB ) {
247 } elseif (
$type ===
'postgres' ) {
248 if ( $srvTP !==
'' ) {
253 if ( $srvTP !==
'' && $srvTP !== $ldTP ) {
265 $e =
new UnexpectedValueException(
266 "\$wgDBprefix is set to '$prefix' but the database type is '$dbType'. " .
267 "MediaWiki does not support using a table prefix with this RDBMS type."
279 $e =
new UnexpectedValueException(
280 "\$wgDBservers has dbname='$srvDB' but \$wgDBname='$ldDB'. " .
281 "Set \$wgDBname to the database used by this wiki project. " .
282 "There is rarely a need to set 'dbname' in \$wgDBservers. " .
283 "Cross-wiki database access, use of WikiMap::getCurrentWikiDbDomain(), " .
284 "use of Database::getDomainId(), and other features are not reliable when " .
285 "\$wgDBservers does not match the local wiki database/prefix."
297 $e =
new UnexpectedValueException(
298 "\$wgDBservers has tablePrefix='$srvTP' but \$wgDBprefix='$ldTP'. " .
299 "Set \$wgDBprefix to the table prefix used by this wiki project. " .
300 "There is rarely a need to set 'tablePrefix' in \$wgDBservers. " .
301 "Cross-wiki database access, use of WikiMap::getCurrentWikiDbDomain(), " .
302 "use of Database::getDomainId(), and other features are not reliable when " .
303 "\$wgDBservers does not match the local wiki database/prefix."
319 'LBFactory_Single' => Wikimedia\Rdbms\LBFactorySingle::class,
320 'LBFactory_Simple' => Wikimedia\Rdbms\LBFactorySimple::class,
321 'LBFactory_Multi' => Wikimedia\Rdbms\LBFactoryMulti::class,
323 'LBFactorySingle' => Wikimedia\Rdbms\LBFactorySingle::class,
324 'LBFactorySimple' => Wikimedia\Rdbms\LBFactorySimple::class,
325 'LBFactoryMulti' => Wikimedia\Rdbms\LBFactoryMulti::class
328 $class = $config[
'class'];
329 return $compat[$class] ?? $class;
339 $rawLocalDomain = strlen( $domain->getTablePrefix() )
340 ?
"{$domain->getDatabase()}-{$domain->getTablePrefix()}"
341 : (string)$domain->getDatabase();
383 $reqStart = (int)( $_SERVER[
'REQUEST_TIME_FLOAT'] ?? time() );
384 $cpPosInfo = LBFactory::getCPInfoFromCookieValue(
386 $req->getCookie(
'cpPosIndex',
'' ),
388 $reqStart - ChronologyProtector::POSITION_COOKIE_TTL
391 'IPAddress' => $req->getIP(),
392 'UserAgent' => $req->getHeader(
'User-Agent' ),
393 'ChronologyProtection' => $req->getHeader(
'MediaWiki-Chronology-Protection' ),
394 'ChronologyPositionIndex' => $req->getInt(
'cpPosIndex', $cpPosInfo[
'index'] ),
395 'ChronologyClientId' => $cpPosInfo[
'clientId']
396 ?? $req->getHeader(
'MediaWiki-Chronology-Client-Id' )
399 if ( $config->
get(
'CommandLineMode' ) ) {
405 static function () use ( $stats, $config ) {
413 $lbFactory->
getMainLB()->setTransactionListener(
415 static function ( $trigger ) use ( $stats, $config ) {
416 if ( $trigger === IDatabase::TRIGGER_COMMIT ) {
433 if ( isset( self::$loggedDeprecations[$msg] ) ) {
436 self::$loggedDeprecations[$msg] =
true;
wfGetCaller( $level=2)
Get the name of the function which called this function wfGetCaller( 1 ) is the function with the wfG...
Class representing a cache/ephemeral data store.
static tryOpportunisticExecute( $mode='run')
Consume and execute all pending updates unless an update is already in progress or the LBFactory serv...
static sendRawDeprecated( $msg, $sendToLog=true, $callerFunc='')
Send a raw deprecation message to the log and the debug toolbar, without filtering of duplicate messa...
static output(Throwable $e, $mode, Throwable $eNew=null)
MediaWiki-specific class for generating database load balancers.
static setDomainAliases(ILBFactory $lbFactory)
static logDeprecation( $msg)
Log a database deprecation warning.
static assertValidServerConfigs(array $servers, $ldDB, $ldTP)
const APPLY_DEFAULT_CONFIG_OPTIONS
static applyDefaultConfig(array $lbConf, ServiceOptions $options, ConfiguredReadOnlyMode $readOnlyMode, BagOStuff $cpStash, BagOStuff $srvCache, WANObjectCache $wanCache, CriticalSectionProvider $csProvider)
static getDbTypesWithSchemas()
static initServerInfo(array $server, ServiceOptions $options)
static array $loggedDeprecations
Cache of already-logged deprecation messages.
static reportMismatchedPrefixes( $srvTP, $ldTP)
static getLBFactoryClass(array $config)
Decide which LBFactory class to use.
static reportMismatchedDBs( $srvDB, $ldDB)
static applyGlobalState(ILBFactory $lbFactory, Config $config, IBufferingStatsdDataFactory $stats)
Apply global state from the current web request or other PHP process.
static reportIfPrefixSet( $prefix, $dbType)
A class containing constants representing the names of configuration variables.
static instance()
Singleton.
Group all the pieces relevant to the context of a request into one instance.
Multi-datacenter aware caching interface.
Class to handle database/schema/prefix specifications for IDatabase.
Interface for configuration instances.
get( $name)
Get a configuration variable such as "Sitename" or "UploadMaintenance.".
MediaWiki adaptation of StatsdDataFactory that provides buffering functionality.