MediaWiki  1.23.1
SqlBagOStuff.php
Go to the documentation of this file.
1 <?php
29 class SqlBagOStuff extends BagOStuff {
33  var $lb;
34 
38  var $conns;
39  var $lastExpireAll = 0;
40  var $purgePeriod = 100;
41  var $shards = 1;
42  var $tableName = 'objectcache';
43 
44  protected $connFailureTimes = array(); // UNIX timestamps
45  protected $connFailureErrors = array(); // exceptions
46 
75  public function __construct( $params ) {
76  if ( isset( $params['servers'] ) ) {
77  $this->serverInfos = $params['servers'];
78  $this->numServers = count( $this->serverInfos );
79  $this->serverNames = array();
80  foreach ( $this->serverInfos as $i => $info ) {
81  $this->serverNames[$i] = isset( $info['host'] ) ? $info['host'] : "#$i";
82  }
83  } elseif ( isset( $params['server'] ) ) {
84  $this->serverInfos = array( $params['server'] );
85  $this->numServers = count( $this->serverInfos );
86  } else {
87  $this->serverInfos = false;
88  $this->numServers = 1;
89  }
90  if ( isset( $params['purgePeriod'] ) ) {
91  $this->purgePeriod = intval( $params['purgePeriod'] );
92  }
93  if ( isset( $params['tableName'] ) ) {
94  $this->tableName = $params['tableName'];
95  }
96  if ( isset( $params['shards'] ) ) {
97  $this->shards = intval( $params['shards'] );
98  }
99  }
100 
107  protected function getDB( $serverIndex ) {
108  global $wgDebugDBTransactions;
109 
110  if ( !isset( $this->conns[$serverIndex] ) ) {
111  if ( $serverIndex >= $this->numServers ) {
112  throw new MWException( __METHOD__ . ": Invalid server index \"$serverIndex\"" );
113  }
114 
115  # Don't keep timing out trying to connect for each call if the DB is down
116  if ( isset( $this->connFailureErrors[$serverIndex] )
117  && ( time() - $this->connFailureTimes[$serverIndex] ) < 60
118  ) {
119  throw $this->connFailureErrors[$serverIndex];
120  }
121 
122  # If server connection info was given, use that
123  if ( $this->serverInfos ) {
124  if ( $wgDebugDBTransactions ) {
125  wfDebug( "Using provided serverInfo for SqlBagOStuff\n" );
126  }
127  $info = $this->serverInfos[$serverIndex];
128  $type = isset( $info['type'] ) ? $info['type'] : 'mysql';
129  $host = isset( $info['host'] ) ? $info['host'] : '[unknown]';
130  wfDebug( __CLASS__ . ": connecting to $host\n" );
131  $db = DatabaseBase::factory( $type, $info );
132  $db->clearFlag( DBO_TRX );
133  } else {
134  /*
135  * We must keep a separate connection to MySQL in order to avoid deadlocks
136  * However, SQLite has an opposite behavior. And PostgreSQL needs to know
137  * if we are in transaction or no
138  */
139  if ( wfGetDB( DB_MASTER )->getType() == 'mysql' ) {
140  $this->lb = wfGetLBFactory()->newMainLB();
141  $db = $this->lb->getConnection( DB_MASTER );
142  $db->clearFlag( DBO_TRX ); // auto-commit mode
143  } else {
144  $db = wfGetDB( DB_MASTER );
145  }
146  }
147  if ( $wgDebugDBTransactions ) {
148  wfDebug( sprintf( "Connection %s will be used for SqlBagOStuff\n", $db ) );
149  }
150  $this->conns[$serverIndex] = $db;
151  }
152 
153  return $this->conns[$serverIndex];
154  }
155 
161  protected function getTableByKey( $key ) {
162  if ( $this->shards > 1 ) {
163  $hash = hexdec( substr( md5( $key ), 0, 8 ) ) & 0x7fffffff;
164  $tableIndex = $hash % $this->shards;
165  } else {
166  $tableIndex = 0;
167  }
168  if ( $this->numServers > 1 ) {
169  $sortedServers = $this->serverNames;
170  ArrayUtils::consistentHashSort( $sortedServers, $key );
171  reset( $sortedServers );
172  $serverIndex = key( $sortedServers );
173  } else {
174  $serverIndex = 0;
175  }
176  return array( $serverIndex, $this->getTableNameByShard( $tableIndex ) );
177  }
178 
184  protected function getTableNameByShard( $index ) {
185  if ( $this->shards > 1 ) {
186  $decimals = strlen( $this->shards - 1 );
187  return $this->tableName .
188  sprintf( "%0{$decimals}d", $index );
189  } else {
190  return $this->tableName;
191  }
192  }
193 
199  public function get( $key, &$casToken = null ) {
200  $values = $this->getMulti( array( $key ) );
201  if ( array_key_exists( $key, $values ) ) {
202  $casToken = $values[$key];
203  return $values[$key];
204  }
205  return false;
206  }
207 
212  public function getMulti( array $keys ) {
213  $values = array(); // array of (key => value)
214 
215  $keysByTable = array();
216  foreach ( $keys as $key ) {
217  list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
218  $keysByTable[$serverIndex][$tableName][] = $key;
219  }
220 
221  $this->garbageCollect(); // expire old entries if any
222 
223  $dataRows = array();
224  foreach ( $keysByTable as $serverIndex => $serverKeys ) {
225  try {
226  $db = $this->getDB( $serverIndex );
227  foreach ( $serverKeys as $tableName => $tableKeys ) {
228  $res = $db->select( $tableName,
229  array( 'keyname', 'value', 'exptime' ),
230  array( 'keyname' => $tableKeys ),
231  __METHOD__ );
232  foreach ( $res as $row ) {
233  $row->serverIndex = $serverIndex;
234  $row->tableName = $tableName;
235  $dataRows[$row->keyname] = $row;
236  }
237  }
238  } catch ( DBError $e ) {
239  $this->handleReadError( $e, $serverIndex );
240  }
241  }
242 
243  foreach ( $keys as $key ) {
244  if ( isset( $dataRows[$key] ) ) { // HIT?
245  $row = $dataRows[$key];
246  $this->debug( "get: retrieved data; expiry time is " . $row->exptime );
247  try {
248  $db = $this->getDB( $row->serverIndex );
249  if ( $this->isExpired( $db, $row->exptime ) ) { // MISS
250  $this->debug( "get: key has expired, deleting" );
251  $db->commit( __METHOD__, 'flush' );
252  # Put the expiry time in the WHERE condition to avoid deleting a
253  # newly-inserted value
254  $db->delete( $row->tableName,
255  array( 'keyname' => $key, 'exptime' => $row->exptime ),
256  __METHOD__ );
257  $db->commit( __METHOD__, 'flush' );
258  $values[$key] = false;
259  } else { // HIT
260  $values[$key] = $this->unserialize( $db->decodeBlob( $row->value ) );
261  }
262  } catch ( DBQueryError $e ) {
263  $this->handleWriteError( $e, $row->serverIndex );
264  }
265  } else { // MISS
266  $values[$key] = false;
267  $this->debug( 'get: no matching rows' );
268  }
269  }
270 
271  return $values;
272  }
273 
280  public function set( $key, $value, $exptime = 0 ) {
281  list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
282  try {
283  $db = $this->getDB( $serverIndex );
284  $exptime = intval( $exptime );
285 
286  if ( $exptime < 0 ) {
287  $exptime = 0;
288  }
289 
290  if ( $exptime == 0 ) {
291  $encExpiry = $this->getMaxDateTime( $db );
292  } else {
293  if ( $exptime < 3.16e8 ) { # ~10 years
294  $exptime += time();
295  }
296 
297  $encExpiry = $db->timestamp( $exptime );
298  }
299  $db->commit( __METHOD__, 'flush' );
300  // (bug 24425) use a replace if the db supports it instead of
301  // delete/insert to avoid clashes with conflicting keynames
302  $db->replace(
303  $tableName,
304  array( 'keyname' ),
305  array(
306  'keyname' => $key,
307  'value' => $db->encodeBlob( $this->serialize( $value ) ),
308  'exptime' => $encExpiry
309  ), __METHOD__ );
310  $db->commit( __METHOD__, 'flush' );
311  } catch ( DBError $e ) {
312  $this->handleWriteError( $e, $serverIndex );
313  return false;
314  }
315 
316  return true;
317  }
318 
326  public function cas( $casToken, $key, $value, $exptime = 0 ) {
327  list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
328  try {
329  $db = $this->getDB( $serverIndex );
330  $exptime = intval( $exptime );
331 
332  if ( $exptime < 0 ) {
333  $exptime = 0;
334  }
335 
336  if ( $exptime == 0 ) {
337  $encExpiry = $this->getMaxDateTime( $db );
338  } else {
339  if ( $exptime < 3.16e8 ) { # ~10 years
340  $exptime += time();
341  }
342  $encExpiry = $db->timestamp( $exptime );
343  }
344  $db->commit( __METHOD__, 'flush' );
345  // (bug 24425) use a replace if the db supports it instead of
346  // delete/insert to avoid clashes with conflicting keynames
347  $db->update(
348  $tableName,
349  array(
350  'keyname' => $key,
351  'value' => $db->encodeBlob( $this->serialize( $value ) ),
352  'exptime' => $encExpiry
353  ),
354  array(
355  'keyname' => $key,
356  'value' => $db->encodeBlob( $this->serialize( $casToken ) )
357  ),
358  __METHOD__
359  );
360  $db->commit( __METHOD__, 'flush' );
361  } catch ( DBQueryError $e ) {
362  $this->handleWriteError( $e, $serverIndex );
363 
364  return false;
365  }
366 
367  return (bool)$db->affectedRows();
368  }
369 
375  public function delete( $key, $time = 0 ) {
376  list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
377  try {
378  $db = $this->getDB( $serverIndex );
379  $db->commit( __METHOD__, 'flush' );
380  $db->delete(
381  $tableName,
382  array( 'keyname' => $key ),
383  __METHOD__ );
384  $db->commit( __METHOD__, 'flush' );
385  } catch ( DBError $e ) {
386  $this->handleWriteError( $e, $serverIndex );
387  return false;
388  }
389 
390  return true;
391  }
392 
398  public function incr( $key, $step = 1 ) {
399  list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
400  try {
401  $db = $this->getDB( $serverIndex );
402  $step = intval( $step );
403  $db->commit( __METHOD__, 'flush' );
404  $row = $db->selectRow(
405  $tableName,
406  array( 'value', 'exptime' ),
407  array( 'keyname' => $key ),
408  __METHOD__,
409  array( 'FOR UPDATE' ) );
410  if ( $row === false ) {
411  // Missing
412  $db->commit( __METHOD__, 'flush' );
413 
414  return null;
415  }
416  $db->delete( $tableName, array( 'keyname' => $key ), __METHOD__ );
417  if ( $this->isExpired( $db, $row->exptime ) ) {
418  // Expired, do not reinsert
419  $db->commit( __METHOD__, 'flush' );
420 
421  return null;
422  }
423 
424  $oldValue = intval( $this->unserialize( $db->decodeBlob( $row->value ) ) );
425  $newValue = $oldValue + $step;
426  $db->insert( $tableName,
427  array(
428  'keyname' => $key,
429  'value' => $db->encodeBlob( $this->serialize( $newValue ) ),
430  'exptime' => $row->exptime
431  ), __METHOD__, 'IGNORE' );
432 
433  if ( $db->affectedRows() == 0 ) {
434  // Race condition. See bug 28611
435  $newValue = null;
436  }
437  $db->commit( __METHOD__, 'flush' );
438  } catch ( DBError $e ) {
439  $this->handleWriteError( $e, $serverIndex );
440  return null;
441  }
442 
443  return $newValue;
444  }
445 
450  protected function isExpired( $db, $exptime ) {
451  return $exptime != $this->getMaxDateTime( $db ) && wfTimestamp( TS_UNIX, $exptime ) < time();
452  }
453 
457  protected function getMaxDateTime( $db ) {
458  if ( time() > 0x7fffffff ) {
459  return $db->timestamp( 1 << 62 );
460  } else {
461  return $db->timestamp( 0x7fffffff );
462  }
463  }
464 
465  protected function garbageCollect() {
466  if ( !$this->purgePeriod ) {
467  // Disabled
468  return;
469  }
470  // Only purge on one in every $this->purgePeriod requests.
471  if ( $this->purgePeriod !== 1 && mt_rand( 0, $this->purgePeriod - 1 ) ) {
472  return;
473  }
474  $now = time();
475  // Avoid repeating the delete within a few seconds
476  if ( $now > ( $this->lastExpireAll + 1 ) ) {
477  $this->lastExpireAll = $now;
478  $this->expireAll();
479  }
480  }
481 
482  public function expireAll() {
484  }
485 
492  public function deleteObjectsExpiringBefore( $timestamp, $progressCallback = false ) {
493  for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) {
494  try {
495  $db = $this->getDB( $serverIndex );
496  $dbTimestamp = $db->timestamp( $timestamp );
497  $totalSeconds = false;
498  $baseConds = array( 'exptime < ' . $db->addQuotes( $dbTimestamp ) );
499  for ( $i = 0; $i < $this->shards; $i++ ) {
500  $maxExpTime = false;
501  while ( true ) {
502  $conds = $baseConds;
503  if ( $maxExpTime !== false ) {
504  $conds[] = 'exptime > ' . $db->addQuotes( $maxExpTime );
505  }
506  $rows = $db->select(
507  $this->getTableNameByShard( $i ),
508  array( 'keyname', 'exptime' ),
509  $conds,
510  __METHOD__,
511  array( 'LIMIT' => 100, 'ORDER BY' => 'exptime' ) );
512  if ( !$rows->numRows() ) {
513  break;
514  }
515  $keys = array();
516  $row = $rows->current();
517  $minExpTime = $row->exptime;
518  if ( $totalSeconds === false ) {
519  $totalSeconds = wfTimestamp( TS_UNIX, $timestamp )
520  - wfTimestamp( TS_UNIX, $minExpTime );
521  }
522  foreach ( $rows as $row ) {
523  $keys[] = $row->keyname;
524  $maxExpTime = $row->exptime;
525  }
526 
527  $db->commit( __METHOD__, 'flush' );
528  $db->delete(
529  $this->getTableNameByShard( $i ),
530  array(
531  'exptime >= ' . $db->addQuotes( $minExpTime ),
532  'exptime < ' . $db->addQuotes( $dbTimestamp ),
533  'keyname' => $keys
534  ),
535  __METHOD__ );
536  $db->commit( __METHOD__, 'flush' );
537 
538  if ( $progressCallback ) {
539  if ( intval( $totalSeconds ) === 0 ) {
540  $percent = 0;
541  } else {
542  $remainingSeconds = wfTimestamp( TS_UNIX, $timestamp )
543  - wfTimestamp( TS_UNIX, $maxExpTime );
544  if ( $remainingSeconds > $totalSeconds ) {
545  $totalSeconds = $remainingSeconds;
546  }
547  $percent = ( $i + $remainingSeconds / $totalSeconds )
548  / $this->shards * 100;
549  }
550  $percent = ( $percent / $this->numServers )
551  + ( $serverIndex / $this->numServers * 100 );
552  call_user_func( $progressCallback, $percent );
553  }
554  }
555  }
556  } catch ( DBError $e ) {
557  $this->handleWriteError( $e, $serverIndex );
558  return false;
559  }
560  }
561  return true;
562  }
563 
564  public function deleteAll() {
565  for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) {
566  try {
567  $db = $this->getDB( $serverIndex );
568  for ( $i = 0; $i < $this->shards; $i++ ) {
569  $db->commit( __METHOD__, 'flush' );
570  $db->delete( $this->getTableNameByShard( $i ), '*', __METHOD__ );
571  $db->commit( __METHOD__, 'flush' );
572  }
573  } catch ( DBError $e ) {
574  $this->handleWriteError( $e, $serverIndex );
575  return false;
576  }
577  }
578  return true;
579  }
580 
589  protected function serialize( &$data ) {
590  $serial = serialize( $data );
591 
592  if ( function_exists( 'gzdeflate' ) ) {
593  return gzdeflate( $serial );
594  } else {
595  return $serial;
596  }
597  }
598 
604  protected function unserialize( $serial ) {
605  if ( function_exists( 'gzinflate' ) ) {
607  $decomp = gzinflate( $serial );
609 
610  if ( false !== $decomp ) {
611  $serial = $decomp;
612  }
613  }
614 
615  $ret = unserialize( $serial );
616 
617  return $ret;
618  }
619 
623  protected function handleReadError( DBError $exception, $serverIndex ) {
624  if ( $exception instanceof DBConnectionError ) {
625  $this->markServerDown( $exception, $serverIndex );
626  }
627  wfDebugLog( 'SQLBagOStuff', "DBError: {$exception->getMessage()}" );
628  if ( $exception instanceof DBConnectionError ) {
630  wfDebug( __METHOD__ . ": ignoring connection error\n" );
631  } else {
633  wfDebug( __METHOD__ . ": ignoring query error\n" );
634  }
635  }
636 
640  protected function handleWriteError( DBError $exception, $serverIndex ) {
641  if ( $exception instanceof DBConnectionError ) {
642  $this->markServerDown( $exception, $serverIndex );
643  }
644  if ( $exception->db && $exception->db->wasReadOnlyError() ) {
645  try {
646  $exception->db->rollback( __METHOD__ );
647  } catch ( DBError $e ) {}
648  }
649  wfDebugLog( 'SQLBagOStuff', "DBError: {$exception->getMessage()}" );
650  if ( $exception instanceof DBConnectionError ) {
652  wfDebug( __METHOD__ . ": ignoring connection error\n" );
653  } else {
655  wfDebug( __METHOD__ . ": ignoring query error\n" );
656  }
657  }
658 
662  protected function markServerDown( $exception, $serverIndex ) {
663  if ( isset( $this->connFailureTimes[$serverIndex] ) ) {
664  if ( time() - $this->connFailureTimes[$serverIndex] >= 60 ) {
665  unset( $this->connFailureTimes[$serverIndex] );
666  unset( $this->connFailureErrors[$serverIndex] );
667  } else {
668  wfDebug( __METHOD__ . ": Server #$serverIndex already down\n" );
669  return;
670  }
671  }
672  $now = time();
673  wfDebug( __METHOD__ . ": Server #$serverIndex down until " . ( $now + 60 ) . "\n" );
674  $this->connFailureTimes[$serverIndex] = $now;
675  $this->connFailureErrors[$serverIndex] = $exception;
676  }
677 
681  public function createTables() {
682  for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) {
683  $db = $this->getDB( $serverIndex );
684  if ( $db->getType() !== 'mysql' ) {
685  throw new MWException( __METHOD__ . ' is not supported on this DB server' );
686  }
687 
688  for ( $i = 0; $i < $this->shards; $i++ ) {
689  $db->commit( __METHOD__, 'flush' );
690  $db->query(
691  'CREATE TABLE ' . $db->tableName( $this->getTableNameByShard( $i ) ) .
692  ' LIKE ' . $db->tableName( 'objectcache' ),
693  __METHOD__ );
694  $db->commit( __METHOD__, 'flush' );
695  }
696  }
697  }
698 }
699 
703 class MediaWikiBagOStuff extends SqlBagOStuff { }
SqlBagOStuff\__construct
__construct( $params)
Constructor.
Definition: SqlBagOStuff.php:74
SqlBagOStuff\createTables
createTables()
Create shard tables.
Definition: SqlBagOStuff.php:680
SqlBagOStuff\markServerDown
markServerDown( $exception, $serverIndex)
Mark a server down due to a DBConnectionError exception.
Definition: SqlBagOStuff.php:661
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1358
ArrayUtils\consistentHashSort
static consistentHashSort(&$array, $key, $separator="\000")
Sort the given array in a pseudo-random order which depends only on the given key and each element va...
Definition: ArrayUtils.php:49
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
BagOStuff\ERR_UNREACHABLE
const ERR_UNREACHABLE
Definition: BagOStuff.php:51
SqlBagOStuff\serialize
serialize(&$data)
Serialize an object and, if possible, compress the representation.
Definition: SqlBagOStuff.php:588
SqlBagOStuff\$shards
$shards
Definition: SqlBagOStuff.php:40
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3650
$timestamp
if( $limit) $timestamp
Definition: importImages.php:104
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:2483
SqlBagOStuff\incr
incr( $key, $step=1)
Definition: SqlBagOStuff.php:397
wfDebugLog
wfDebugLog( $logGroup, $text, $dest='all')
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Definition: GlobalFunctions.php:1040
$ret
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret
Definition: hooks.txt:1530
wfSuppressWarnings
wfSuppressWarnings( $end=false)
Reference-counted warning suppression.
Definition: GlobalFunctions.php:2387
BagOStuff\debug
debug( $text)
Definition: BagOStuff.php:339
$params
$params
Definition: styleTest.css.php:40
BagOStuff
interface is intended to be more or less compatible with the PHP memcached client.
Definition: BagOStuff.php:43
SqlBagOStuff\$connFailureErrors
$connFailureErrors
Definition: SqlBagOStuff.php:44
SqlBagOStuff\$numServers
$numServers
Definition: SqlBagOStuff.php:36
SqlBagOStuff\getTableByKey
getTableByKey( $key)
Get the server index and table name for a given key.
Definition: SqlBagOStuff.php:160
SqlBagOStuff\handleWriteError
handleWriteError(DBError $exception, $serverIndex)
Handle a DBQueryError which occurred during a write operation.
Definition: SqlBagOStuff.php:639
SqlBagOStuff\$lb
LoadBalancer $lb
Definition: SqlBagOStuff.php:32
key
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add in any and then calling but I prefer the flexibility This should also do the output encoding The system allocates a global one in $wgOut Title Represents the title of an and does all the work of translating among various forms such as plain database key
Definition: design.txt:25
SqlBagOStuff\$conns
$conns
Definition: SqlBagOStuff.php:37
SqlBagOStuff\$serverInfos
$serverInfos
Definition: SqlBagOStuff.php:34
SqlBagOStuff\expireAll
expireAll()
Definition: SqlBagOStuff.php:481
MWException
MediaWiki exception.
Definition: MWException.php:26
SqlBagOStuff\deleteAll
deleteAll()
Definition: SqlBagOStuff.php:563
DBQueryError
Definition: DatabaseError.php:306
wfRestoreWarnings
wfRestoreWarnings()
Restore error level to previous value.
Definition: GlobalFunctions.php:2417
SqlBagOStuff\getDB
getDB( $serverIndex)
Get a connection to the specified database.
Definition: SqlBagOStuff.php:106
tableName
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like please read the documentation for tableName() and addQuotes(). You will need both of them. ------------------------------------------------------------------------ Basic query optimisation ------------------------------------------------------------------------ MediaWiki developers who need to write DB queries should have some understanding of databases and the performance issues associated with them. Patches containing unacceptably slow features will not be accepted. Unindexed queries are generally not welcome in MediaWiki
SqlBagOStuff\handleReadError
handleReadError(DBError $exception, $serverIndex)
Handle a DBError which occurred during a read operation.
Definition: SqlBagOStuff.php:622
SqlBagOStuff\$serverNames
$serverNames
Definition: SqlBagOStuff.php:35
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
SqlBagOStuff\cas
cas( $casToken, $key, $value, $exptime=0)
Definition: SqlBagOStuff.php:325
SqlBagOStuff\isExpired
isExpired( $db, $exptime)
Definition: SqlBagOStuff.php:449
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:2514
DBConnectionError
Definition: DatabaseError.php:98
DatabaseBase\factory
static factory( $dbType, $p=array())
Given a DB type, construct the name of the appropriate child class of DatabaseBase.
Definition: Database.php:808
list
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
Definition: deferred.txt:11
DBError
Database error base class.
Definition: DatabaseError.php:28
LoadBalancer
Database load balancing object.
Definition: LoadBalancer.php:30
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:933
SqlBagOStuff\garbageCollect
garbageCollect()
Definition: SqlBagOStuff.php:464
$value
$value
Definition: styleTest.css.php:45
SqlBagOStuff\unserialize
unserialize( $serial)
Unserialize and, if necessary, decompress an object.
Definition: SqlBagOStuff.php:603
SqlBagOStuff\deleteObjectsExpiringBefore
deleteObjectsExpiringBefore( $timestamp, $progressCallback=false)
Delete objects from the database which expire before a certain date.
Definition: SqlBagOStuff.php:491
$hash
return false to override stock group addition can be modified try getUserPermissionsErrors userCan checks are continued by internal code can override on output return false to not delete it return false to override the default password checks & $hash
Definition: hooks.txt:2697
SqlBagOStuff
Class to store objects in the database.
Definition: SqlBagOStuff.php:29
SqlBagOStuff\$tableName
$tableName
Definition: SqlBagOStuff.php:41
SqlBagOStuff\$purgePeriod
$purgePeriod
Definition: SqlBagOStuff.php:39
wfGetLBFactory
& wfGetLBFactory()
Get the load balancer factory object.
Definition: GlobalFunctions.php:3669
TS_UNIX
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
Definition: GlobalFunctions.php:2426
as
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
Definition: distributors.txt:9
SqlBagOStuff\getMaxDateTime
getMaxDateTime( $db)
Definition: SqlBagOStuff.php:456
$keys
$keys
Definition: testCompression.php:63
SqlBagOStuff\$connFailureTimes
$connFailureTimes
Definition: SqlBagOStuff.php:43
$e
if( $useReadline) $e
Definition: eval.php:66
SqlBagOStuff\getMulti
getMulti(array $keys)
Definition: SqlBagOStuff.php:211
MediaWikiBagOStuff
Backwards compatibility alias.
Definition: SqlBagOStuff.php:702
BagOStuff\setLastError
setLastError( $err)
Set the "last error" registry.
Definition: BagOStuff.php:332
$res
$res
Definition: database.txt:21
BagOStuff\ERR_UNEXPECTED
const ERR_UNEXPECTED
Definition: BagOStuff.php:52
DBO_TRX
const DBO_TRX
Definition: Defines.php:42
SqlBagOStuff\$lastExpireAll
$lastExpireAll
Definition: SqlBagOStuff.php:38
SqlBagOStuff\getTableNameByShard
getTableNameByShard( $index)
Get the table name for a given shard index.
Definition: SqlBagOStuff.php:183
$type
$type
Definition: testCompression.php:46