26use Psr\Log\LoggerInterface;
27use Psr\Log\LoggerAwareInterface;
28use Psr\Log\NullLogger;
65 'readQueryTime' => INF,
66 'writeQueryTime' => INF
107 $this->expect[$event] = isset( $this->expect[$event] )
108 ? min( $this->expect[$event],
$value )
110 if ( $this->expect[$event] ==
$value ) {
111 $this->expectBy[$event] =
$fname;
125 foreach ( $expects
as $event =>
$value ) {
136 foreach ( $this->hits
as &$val ) {
140 foreach ( $this->expect
as &$val ) {
144 $this->expectBy = [];
158 if ( $this->hits[
'conns']++ >= $this->expect[
'conns'] ) {
160 'conns',
"[connect to $server ($db)]", $this->hits[
'conns'] );
162 if ( $isMaster && $this->hits[
'masterConns']++ >= $this->expect[
'masterConns'] ) {
164 'masterConns',
"[connect to $server ($db)]", $this->hits[
'masterConns'] );
178 $name =
"{$server} ({$db}) (TRX#$id)";
179 if ( isset( $this->dbTrxHoldingLocks[
$name] ) ) {
180 $this->logger->info(
"Nested transaction for '$name' - out of sync." );
182 $this->dbTrxHoldingLocks[
$name] = [
183 'start' => microtime(
true ),
186 $this->dbTrxMethodTimes[
$name] = [];
188 foreach ( $this->dbTrxHoldingLocks
as $name => &$info ) {
190 $info[
'conns'][
$name] = 1;
205 $eTime = microtime(
true );
206 $elapsed = ( $eTime - $sTime );
208 if ( $isWrite && $n > $this->expect[
'maxAffected'] ) {
210 "Query affected $n row(s):\n" .
$query .
"\n" .
211 (
new RuntimeException() )->getTraceAsString() );
215 if ( $this->hits[
'queries']++ >= $this->expect[
'queries'] ) {
218 if ( $isWrite && $this->hits[
'writes']++ >= $this->expect[
'writes'] ) {
222 if ( !$isWrite && $elapsed > $this->expect[
'readQueryTime'] ) {
225 if ( $isWrite && $elapsed > $this->expect[
'writeQueryTime'] ) {
229 if ( !$this->dbTrxHoldingLocks ) {
232 } elseif ( !$isWrite && $elapsed < $this->eventThreshold ) {
237 foreach ( $this->dbTrxHoldingLocks
as $name => $info ) {
238 $lastQuery = end( $this->dbTrxMethodTimes[
$name] );
241 $lastEnd = $lastQuery[2];
242 if ( $sTime >= $lastEnd ) {
243 if ( ( $sTime - $lastEnd ) > $this->eventThreshold ) {
245 $this->dbTrxMethodTimes[
$name][] = [
'...delay...', $lastEnd, $sTime ];
247 $this->dbTrxMethodTimes[
$name][] = [
$query, $sTime, $eTime ];
251 if ( $sTime >= $info[
'start'] ) {
252 $this->dbTrxMethodTimes[
$name][] = [
$query, $sTime, $eTime ];
272 $name =
"{$server} ({$db}) (TRX#$id)";
273 if ( !isset( $this->dbTrxMethodTimes[
$name] ) ) {
274 $this->logger->info(
"Detected no transaction for '$name' - out of sync." );
281 if ( $writeTime > $this->expect[
'writeQueryTime'] ) {
284 "[transaction $id writes to {$server} ({$db})]",
290 if ( $affected > $this->expect[
'maxAffected'] ) {
293 "[transaction $id writes to {$server} ({$db})]",
298 $lastQuery = end( $this->dbTrxMethodTimes[
$name] );
300 $now = microtime(
true );
301 $lastEnd = $lastQuery[2];
302 if ( ( $now - $lastEnd ) > $this->eventThreshold ) {
303 $this->dbTrxMethodTimes[
$name][] = [
'...delay...', $lastEnd, $now ];
307 foreach ( $this->dbTrxMethodTimes[
$name]
as $info ) {
308 $elapsed = ( $info[2] - $info[1] );
309 if ( $elapsed >= $this->dbLockThreshold ) {
316 foreach ( $this->dbTrxMethodTimes[
$name]
as $i => $info ) {
318 $trace .= sprintf(
"%d\t%.6f\t%s\n", $i, ( $end - $sTime ),
$query );
320 $this->logger->info(
"Sub-optimal transaction on DB(s) [{dbs}]: \n{trace}", [
321 'dbs' => implode(
', ', array_keys( $this->dbTrxHoldingLocks[
$name][
'conns'] ) ),
325 unset( $this->dbTrxHoldingLocks[
$name] );
326 unset( $this->dbTrxMethodTimes[
$name] );
335 if ( $this->silenced ) {
340 "Expectation ({measure} <= {max}) by {by} not met (actual: {actual}):\n{query}\n" .
341 (
new RuntimeException() )->getTraceAsString(),
344 'max' => $this->expect[
$expect],
345 'by' => $this->expectBy[
$expect],
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
the array() calling protocol came about after MediaWiki 1.4rc1.
Allows to change the fields on the form that will be generated $name
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php