MediaWiki  1.23.13
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  if ( $res === false ) {
233  continue;
234  }
235  foreach ( $res as $row ) {
236  $row->serverIndex = $serverIndex;
237  $row->tableName = $tableName;
238  $dataRows[$row->keyname] = $row;
239  }
240  }
241  } catch ( DBError $e ) {
242  $this->handleReadError( $e, $serverIndex );
243  }
244  }
245 
246  foreach ( $keys as $key ) {
247  if ( isset( $dataRows[$key] ) ) { // HIT?
248  $row = $dataRows[$key];
249  $this->debug( "get: retrieved data; expiry time is " . $row->exptime );
250  try {
251  $db = $this->getDB( $row->serverIndex );
252  if ( $this->isExpired( $db, $row->exptime ) ) { // MISS
253  $this->debug( "get: key has expired, deleting" );
254  $db->commit( __METHOD__, 'flush' );
255  # Put the expiry time in the WHERE condition to avoid deleting a
256  # newly-inserted value
257  $db->delete( $row->tableName,
258  array( 'keyname' => $key, 'exptime' => $row->exptime ),
259  __METHOD__ );
260  $db->commit( __METHOD__, 'flush' );
261  $values[$key] = false;
262  } else { // HIT
263  $values[$key] = $this->unserialize( $db->decodeBlob( $row->value ) );
264  }
265  } catch ( DBQueryError $e ) {
266  $this->handleWriteError( $e, $row->serverIndex );
267  }
268  } else { // MISS
269  $values[$key] = false;
270  $this->debug( 'get: no matching rows' );
271  }
272  }
273 
274  return $values;
275  }
276 
283  public function set( $key, $value, $exptime = 0 ) {
284  list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
285  try {
286  $db = $this->getDB( $serverIndex );
287  $exptime = intval( $exptime );
288 
289  if ( $exptime < 0 ) {
290  $exptime = 0;
291  }
292 
293  if ( $exptime == 0 ) {
294  $encExpiry = $this->getMaxDateTime( $db );
295  } else {
296  if ( $exptime < 3.16e8 ) { # ~10 years
297  $exptime += time();
298  }
299 
300  $encExpiry = $db->timestamp( $exptime );
301  }
302  $db->commit( __METHOD__, 'flush' );
303  // (bug 24425) use a replace if the db supports it instead of
304  // delete/insert to avoid clashes with conflicting keynames
305  $db->replace(
306  $tableName,
307  array( 'keyname' ),
308  array(
309  'keyname' => $key,
310  'value' => $db->encodeBlob( $this->serialize( $value ) ),
311  'exptime' => $encExpiry
312  ), __METHOD__ );
313  $db->commit( __METHOD__, 'flush' );
314  } catch ( DBError $e ) {
315  $this->handleWriteError( $e, $serverIndex );
316  return false;
317  }
318 
319  return true;
320  }
321 
329  public function cas( $casToken, $key, $value, $exptime = 0 ) {
330  list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
331  try {
332  $db = $this->getDB( $serverIndex );
333  $exptime = intval( $exptime );
334 
335  if ( $exptime < 0 ) {
336  $exptime = 0;
337  }
338 
339  if ( $exptime == 0 ) {
340  $encExpiry = $this->getMaxDateTime( $db );
341  } else {
342  if ( $exptime < 3.16e8 ) { # ~10 years
343  $exptime += time();
344  }
345  $encExpiry = $db->timestamp( $exptime );
346  }
347  $db->commit( __METHOD__, 'flush' );
348  // (bug 24425) use a replace if the db supports it instead of
349  // delete/insert to avoid clashes with conflicting keynames
350  $db->update(
351  $tableName,
352  array(
353  'keyname' => $key,
354  'value' => $db->encodeBlob( $this->serialize( $value ) ),
355  'exptime' => $encExpiry
356  ),
357  array(
358  'keyname' => $key,
359  'value' => $db->encodeBlob( $this->serialize( $casToken ) )
360  ),
361  __METHOD__
362  );
363  $db->commit( __METHOD__, 'flush' );
364  } catch ( DBQueryError $e ) {
365  $this->handleWriteError( $e, $serverIndex );
366 
367  return false;
368  }
369 
370  return (bool)$db->affectedRows();
371  }
372 
378  public function delete( $key, $time = 0 ) {
379  list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
380  try {
381  $db = $this->getDB( $serverIndex );
382  $db->commit( __METHOD__, 'flush' );
383  $db->delete(
384  $tableName,
385  array( 'keyname' => $key ),
386  __METHOD__ );
387  $db->commit( __METHOD__, 'flush' );
388  } catch ( DBError $e ) {
389  $this->handleWriteError( $e, $serverIndex );
390  return false;
391  }
392 
393  return true;
394  }
395 
401  public function incr( $key, $step = 1 ) {
402  list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
403  try {
404  $db = $this->getDB( $serverIndex );
405  $step = intval( $step );
406  $db->commit( __METHOD__, 'flush' );
407  $row = $db->selectRow(
408  $tableName,
409  array( 'value', 'exptime' ),
410  array( 'keyname' => $key ),
411  __METHOD__,
412  array( 'FOR UPDATE' ) );
413  if ( $row === false ) {
414  // Missing
415  $db->commit( __METHOD__, 'flush' );
416 
417  return null;
418  }
419  $db->delete( $tableName, array( 'keyname' => $key ), __METHOD__ );
420  if ( $this->isExpired( $db, $row->exptime ) ) {
421  // Expired, do not reinsert
422  $db->commit( __METHOD__, 'flush' );
423 
424  return null;
425  }
426 
427  $oldValue = intval( $this->unserialize( $db->decodeBlob( $row->value ) ) );
428  $newValue = $oldValue + $step;
429  $db->insert( $tableName,
430  array(
431  'keyname' => $key,
432  'value' => $db->encodeBlob( $this->serialize( $newValue ) ),
433  'exptime' => $row->exptime
434  ), __METHOD__, 'IGNORE' );
435 
436  if ( $db->affectedRows() == 0 ) {
437  // Race condition. See bug 28611
438  $newValue = null;
439  }
440  $db->commit( __METHOD__, 'flush' );
441  } catch ( DBError $e ) {
442  $this->handleWriteError( $e, $serverIndex );
443  return null;
444  }
445 
446  return $newValue;
447  }
448 
453  protected function isExpired( $db, $exptime ) {
454  return $exptime != $this->getMaxDateTime( $db ) && wfTimestamp( TS_UNIX, $exptime ) < time();
455  }
456 
460  protected function getMaxDateTime( $db ) {
461  if ( time() > 0x7fffffff ) {
462  return $db->timestamp( 1 << 62 );
463  } else {
464  return $db->timestamp( 0x7fffffff );
465  }
466  }
467 
468  protected function garbageCollect() {
469  if ( !$this->purgePeriod ) {
470  // Disabled
471  return;
472  }
473  // Only purge on one in every $this->purgePeriod requests.
474  if ( $this->purgePeriod !== 1 && mt_rand( 0, $this->purgePeriod - 1 ) ) {
475  return;
476  }
477  $now = time();
478  // Avoid repeating the delete within a few seconds
479  if ( $now > ( $this->lastExpireAll + 1 ) ) {
480  $this->lastExpireAll = $now;
481  $this->expireAll();
482  }
483  }
484 
485  public function expireAll() {
487  }
488 
495  public function deleteObjectsExpiringBefore( $timestamp, $progressCallback = false ) {
496  for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) {
497  try {
498  $db = $this->getDB( $serverIndex );
499  $dbTimestamp = $db->timestamp( $timestamp );
500  $totalSeconds = false;
501  $baseConds = array( 'exptime < ' . $db->addQuotes( $dbTimestamp ) );
502  for ( $i = 0; $i < $this->shards; $i++ ) {
503  $maxExpTime = false;
504  while ( true ) {
505  $conds = $baseConds;
506  if ( $maxExpTime !== false ) {
507  $conds[] = 'exptime > ' . $db->addQuotes( $maxExpTime );
508  }
509  $rows = $db->select(
510  $this->getTableNameByShard( $i ),
511  array( 'keyname', 'exptime' ),
512  $conds,
513  __METHOD__,
514  array( 'LIMIT' => 100, 'ORDER BY' => 'exptime' ) );
515  if ( $rows === false || !$rows->numRows() ) {
516  break;
517  }
518  $keys = array();
519  $row = $rows->current();
520  $minExpTime = $row->exptime;
521  if ( $totalSeconds === false ) {
522  $totalSeconds = wfTimestamp( TS_UNIX, $timestamp )
523  - wfTimestamp( TS_UNIX, $minExpTime );
524  }
525  foreach ( $rows as $row ) {
526  $keys[] = $row->keyname;
527  $maxExpTime = $row->exptime;
528  }
529 
530  $db->commit( __METHOD__, 'flush' );
531  $db->delete(
532  $this->getTableNameByShard( $i ),
533  array(
534  'exptime >= ' . $db->addQuotes( $minExpTime ),
535  'exptime < ' . $db->addQuotes( $dbTimestamp ),
536  'keyname' => $keys
537  ),
538  __METHOD__ );
539  $db->commit( __METHOD__, 'flush' );
540 
541  if ( $progressCallback ) {
542  if ( intval( $totalSeconds ) === 0 ) {
543  $percent = 0;
544  } else {
545  $remainingSeconds = wfTimestamp( TS_UNIX, $timestamp )
546  - wfTimestamp( TS_UNIX, $maxExpTime );
547  if ( $remainingSeconds > $totalSeconds ) {
548  $totalSeconds = $remainingSeconds;
549  }
550  $percent = ( $i + $remainingSeconds / $totalSeconds )
551  / $this->shards * 100;
552  }
553  $percent = ( $percent / $this->numServers )
554  + ( $serverIndex / $this->numServers * 100 );
555  call_user_func( $progressCallback, $percent );
556  }
557  }
558  }
559  } catch ( DBError $e ) {
560  $this->handleWriteError( $e, $serverIndex );
561  return false;
562  }
563  }
564  return true;
565  }
566 
567  public function deleteAll() {
568  for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) {
569  try {
570  $db = $this->getDB( $serverIndex );
571  for ( $i = 0; $i < $this->shards; $i++ ) {
572  $db->commit( __METHOD__, 'flush' );
573  $db->delete( $this->getTableNameByShard( $i ), '*', __METHOD__ );
574  $db->commit( __METHOD__, 'flush' );
575  }
576  } catch ( DBError $e ) {
577  $this->handleWriteError( $e, $serverIndex );
578  return false;
579  }
580  }
581  return true;
582  }
583 
592  protected function serialize( &$data ) {
593  $serial = serialize( $data );
594 
595  if ( function_exists( 'gzdeflate' ) ) {
596  return gzdeflate( $serial );
597  } else {
598  return $serial;
599  }
600  }
601 
607  protected function unserialize( $serial ) {
608  if ( function_exists( 'gzinflate' ) ) {
610  $decomp = gzinflate( $serial );
612 
613  if ( false !== $decomp ) {
614  $serial = $decomp;
615  }
616  }
617 
618  $ret = unserialize( $serial );
619 
620  return $ret;
621  }
622 
626  protected function handleReadError( DBError $exception, $serverIndex ) {
627  if ( $exception instanceof DBConnectionError ) {
628  $this->markServerDown( $exception, $serverIndex );
629  }
630  wfDebugLog( 'SQLBagOStuff', "DBError: {$exception->getMessage()}" );
631  if ( $exception instanceof DBConnectionError ) {
633  wfDebug( __METHOD__ . ": ignoring connection error\n" );
634  } else {
636  wfDebug( __METHOD__ . ": ignoring query error\n" );
637  }
638  }
639 
643  protected function handleWriteError( DBError $exception, $serverIndex ) {
644  if ( $exception instanceof DBConnectionError ) {
645  $this->markServerDown( $exception, $serverIndex );
646  }
647  if ( $exception->db && $exception->db->wasReadOnlyError() ) {
648  try {
649  $exception->db->rollback( __METHOD__ );
650  } catch ( DBError $e ) {}
651  }
652  wfDebugLog( 'SQLBagOStuff', "DBError: {$exception->getMessage()}" );
653  if ( $exception instanceof DBConnectionError ) {
655  wfDebug( __METHOD__ . ": ignoring connection error\n" );
656  } else {
658  wfDebug( __METHOD__ . ": ignoring query error\n" );
659  }
660  }
661 
665  protected function markServerDown( $exception, $serverIndex ) {
666  if ( isset( $this->connFailureTimes[$serverIndex] ) ) {
667  if ( time() - $this->connFailureTimes[$serverIndex] >= 60 ) {
668  unset( $this->connFailureTimes[$serverIndex] );
669  unset( $this->connFailureErrors[$serverIndex] );
670  } else {
671  wfDebug( __METHOD__ . ": Server #$serverIndex already down\n" );
672  return;
673  }
674  }
675  $now = time();
676  wfDebug( __METHOD__ . ": Server #$serverIndex down until " . ( $now + 60 ) . "\n" );
677  $this->connFailureTimes[$serverIndex] = $now;
678  $this->connFailureErrors[$serverIndex] = $exception;
679  }
680 
684  public function createTables() {
685  for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) {
686  $db = $this->getDB( $serverIndex );
687  if ( $db->getType() !== 'mysql' ) {
688  throw new MWException( __METHOD__ . ' is not supported on this DB server' );
689  }
690 
691  for ( $i = 0; $i < $this->shards; $i++ ) {
692  $db->commit( __METHOD__, 'flush' );
693  $db->query(
694  'CREATE TABLE ' . $db->tableName( $this->getTableNameByShard( $i ) ) .
695  ' LIKE ' . $db->tableName( 'objectcache' ),
696  __METHOD__ );
697  $db->commit( __METHOD__, 'flush' );
698  }
699  }
700  }
701 }
702 
706 class MediaWikiBagOStuff extends SqlBagOStuff { }
SqlBagOStuff\__construct
__construct( $params)
Constructor.
Definition: SqlBagOStuff.php:74
SqlBagOStuff\createTables
createTables()
Create shard tables.
Definition: SqlBagOStuff.php:683
SqlBagOStuff\markServerDown
markServerDown( $exception, $serverIndex)
Mark a server down due to a DBConnectionError exception.
Definition: SqlBagOStuff.php:664
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:591
SqlBagOStuff\$shards
$shards
Definition: SqlBagOStuff.php:40
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3706
$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:2530
SqlBagOStuff\incr
incr( $key, $step=1)
Definition: SqlBagOStuff.php:400
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:1087
$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:2434
BagOStuff\debug
debug( $text)
Definition: BagOStuff.php:339
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1358
$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:642
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:484
MWException
MediaWiki exception.
Definition: MWException.php:26
SqlBagOStuff\deleteAll
deleteAll()
Definition: SqlBagOStuff.php:566
DBQueryError
Definition: DatabaseError.php:306
wfRestoreWarnings
wfRestoreWarnings()
Restore error level to previous value.
Definition: GlobalFunctions.php:2464
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:625
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:328
SqlBagOStuff\isExpired
isExpired( $db, $exptime)
Definition: SqlBagOStuff.php:452
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:2561
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:980
SqlBagOStuff\garbageCollect
garbageCollect()
Definition: SqlBagOStuff.php:467
$value
$value
Definition: styleTest.css.php:45
SqlBagOStuff\unserialize
unserialize( $serial)
Unserialize and, if necessary, decompress an object.
Definition: SqlBagOStuff.php:606
SqlBagOStuff\deleteObjectsExpiringBefore
deleteObjectsExpiringBefore( $timestamp, $progressCallback=false)
Delete objects from the database which expire before a certain date.
Definition: SqlBagOStuff.php:494
$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:2702
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:3725
TS_UNIX
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
Definition: GlobalFunctions.php:2473
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:459
$keys
$keys
Definition: testCompression.php:63
SqlBagOStuff\$connFailureTimes
$connFailureTimes
Definition: SqlBagOStuff.php:43
SqlBagOStuff\getMulti
getMulti(array $keys)
Definition: SqlBagOStuff.php:211
MediaWikiBagOStuff
Backwards compatibility alias.
Definition: SqlBagOStuff.php:705
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
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:1632
SqlBagOStuff\getTableNameByShard
getTableNameByShard( $index)
Get the table name for a given shard index.
Definition: SqlBagOStuff.php:183
$type
$type
Definition: testCompression.php:46