MediaWiki REL1_30
SqlBagOStuff.php
Go to the documentation of this file.
1<?php
29use \MediaWiki\MediaWikiServices;
30use \Wikimedia\WaitConditionLoop;
31use \Wikimedia\Rdbms\TransactionProfiler;
33
39class SqlBagOStuff extends BagOStuff {
41 protected $serverInfos;
43 protected $serverTags;
45 protected $numServers;
47 protected $lastExpireAll = 0;
49 protected $purgePeriod = 100;
51 protected $shards = 1;
53 protected $tableName = 'objectcache';
55 protected $replicaOnly = false;
57 protected $syncTimeout = 3;
58
60 protected $separateMainLB;
62 protected $conns;
64 protected $connFailureTimes = [];
66 protected $connFailureErrors = [];
67
104 public function __construct( $params ) {
105 parent::__construct( $params );
106
109
110 if ( isset( $params['servers'] ) ) {
111 $this->serverInfos = [];
112 $this->serverTags = [];
113 $this->numServers = count( $params['servers'] );
114 $index = 0;
115 foreach ( $params['servers'] as $tag => $info ) {
116 $this->serverInfos[$index] = $info;
117 if ( is_string( $tag ) ) {
118 $this->serverTags[$index] = $tag;
119 } else {
120 $this->serverTags[$index] = isset( $info['host'] ) ? $info['host'] : "#$index";
121 }
122 ++$index;
123 }
124 } elseif ( isset( $params['server'] ) ) {
125 $this->serverInfos = [ $params['server'] ];
126 $this->numServers = count( $this->serverInfos );
127 } else {
128 // Default to using the main wiki's database servers
129 $this->serverInfos = false;
130 $this->numServers = 1;
132 }
133 if ( isset( $params['purgePeriod'] ) ) {
134 $this->purgePeriod = intval( $params['purgePeriod'] );
135 }
136 if ( isset( $params['tableName'] ) ) {
137 $this->tableName = $params['tableName'];
138 }
139 if ( isset( $params['shards'] ) ) {
140 $this->shards = intval( $params['shards'] );
141 }
142 if ( isset( $params['syncTimeout'] ) ) {
143 $this->syncTimeout = $params['syncTimeout'];
144 }
145 $this->replicaOnly = !empty( $params['slaveOnly'] );
146 }
147
155 protected function getDB( $serverIndex ) {
156 if ( !isset( $this->conns[$serverIndex] ) ) {
157 if ( $serverIndex >= $this->numServers ) {
158 throw new MWException( __METHOD__ . ": Invalid server index \"$serverIndex\"" );
159 }
160
161 # Don't keep timing out trying to connect for each call if the DB is down
162 if ( isset( $this->connFailureErrors[$serverIndex] )
163 && ( time() - $this->connFailureTimes[$serverIndex] ) < 60
164 ) {
165 throw $this->connFailureErrors[$serverIndex];
166 }
167
168 if ( $this->serverInfos ) {
169 // Use custom database defined by server connection info
170 $info = $this->serverInfos[$serverIndex];
171 $type = isset( $info['type'] ) ? $info['type'] : 'mysql';
172 $host = isset( $info['host'] ) ? $info['host'] : '[unknown]';
173 $this->logger->debug( __CLASS__ . ": connecting to $host" );
174 // Use a blank trx profiler to ignore expections as this is a cache
175 $info['trxProfiler'] = new TransactionProfiler();
176 $db = Database::factory( $type, $info );
177 $db->clearFlag( DBO_TRX ); // auto-commit mode
178 } else {
179 // Use the main LB database
180 $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
181 $index = $this->replicaOnly ? DB_REPLICA : DB_MASTER;
182 if ( $lb->getServerType( $lb->getWriterIndex() ) !== 'sqlite' ) {
183 // Keep a separate connection to avoid contention and deadlocks
184 $db = $lb->getConnection( $index, [], false, $lb::CONN_TRX_AUTO );
185 // @TODO: Use a blank trx profiler to ignore expections as this is a cache
186 } else {
187 // However, SQLite has the opposite behavior due to DB-level locking.
188 // Stock sqlite MediaWiki installs use a separate sqlite cache DB instead.
189 $db = $lb->getConnection( $index );
190 }
191 }
192
193 $this->logger->debug( sprintf( "Connection %s will be used for SqlBagOStuff", $db ) );
194 $this->conns[$serverIndex] = $db;
195 }
196
197 return $this->conns[$serverIndex];
198 }
199
205 protected function getTableByKey( $key ) {
206 if ( $this->shards > 1 ) {
207 $hash = hexdec( substr( md5( $key ), 0, 8 ) ) & 0x7fffffff;
208 $tableIndex = $hash % $this->shards;
209 } else {
210 $tableIndex = 0;
211 }
212 if ( $this->numServers > 1 ) {
213 $sortedServers = $this->serverTags;
214 ArrayUtils::consistentHashSort( $sortedServers, $key );
215 reset( $sortedServers );
216 $serverIndex = key( $sortedServers );
217 } else {
218 $serverIndex = 0;
219 }
220 return [ $serverIndex, $this->getTableNameByShard( $tableIndex ) ];
221 }
222
228 protected function getTableNameByShard( $index ) {
229 if ( $this->shards > 1 ) {
230 $decimals = strlen( $this->shards - 1 );
231 return $this->tableName .
232 sprintf( "%0{$decimals}d", $index );
233 } else {
234 return $this->tableName;
235 }
236 }
237
238 protected function doGet( $key, $flags = 0 ) {
239 $casToken = null;
240
241 return $this->getWithToken( $key, $casToken, $flags );
242 }
243
244 protected function getWithToken( $key, &$casToken, $flags = 0 ) {
245 $values = $this->getMulti( [ $key ] );
246 if ( array_key_exists( $key, $values ) ) {
247 $casToken = $values[$key];
248 return $values[$key];
249 }
250 return false;
251 }
252
253 public function getMulti( array $keys, $flags = 0 ) {
254 $values = []; // array of (key => value)
255
256 $keysByTable = [];
257 foreach ( $keys as $key ) {
258 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
259 $keysByTable[$serverIndex][$tableName][] = $key;
260 }
261
262 $this->garbageCollect(); // expire old entries if any
263
264 $dataRows = [];
265 foreach ( $keysByTable as $serverIndex => $serverKeys ) {
266 try {
267 $db = $this->getDB( $serverIndex );
268 foreach ( $serverKeys as $tableName => $tableKeys ) {
269 $res = $db->select( $tableName,
270 [ 'keyname', 'value', 'exptime' ],
271 [ 'keyname' => $tableKeys ],
272 __METHOD__,
273 // Approximate write-on-the-fly BagOStuff API via blocking.
274 // This approximation fails if a ROLLBACK happens (which is rare).
275 // We do not want to flush the TRX as that can break callers.
276 $db->trxLevel() ? [ 'LOCK IN SHARE MODE' ] : []
277 );
278 if ( $res === false ) {
279 continue;
280 }
281 foreach ( $res as $row ) {
282 $row->serverIndex = $serverIndex;
283 $row->tableName = $tableName;
284 $dataRows[$row->keyname] = $row;
285 }
286 }
287 } catch ( DBError $e ) {
288 $this->handleReadError( $e, $serverIndex );
289 }
290 }
291
292 foreach ( $keys as $key ) {
293 if ( isset( $dataRows[$key] ) ) { // HIT?
294 $row = $dataRows[$key];
295 $this->debug( "get: retrieved data; expiry time is " . $row->exptime );
296 $db = null;
297 try {
298 $db = $this->getDB( $row->serverIndex );
299 if ( $this->isExpired( $db, $row->exptime ) ) { // MISS
300 $this->debug( "get: key has expired" );
301 } else { // HIT
302 $values[$key] = $this->unserialize( $db->decodeBlob( $row->value ) );
303 }
304 } catch ( DBQueryError $e ) {
305 $this->handleWriteError( $e, $db, $row->serverIndex );
306 }
307 } else { // MISS
308 $this->debug( 'get: no matching rows' );
309 }
310 }
311
312 return $values;
313 }
314
315 public function setMulti( array $data, $expiry = 0 ) {
316 $keysByTable = [];
317 foreach ( $data as $key => $value ) {
318 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
319 $keysByTable[$serverIndex][$tableName][] = $key;
320 }
321
322 $this->garbageCollect(); // expire old entries if any
323
324 $result = true;
325 $exptime = (int)$expiry;
326 foreach ( $keysByTable as $serverIndex => $serverKeys ) {
327 $db = null;
328 try {
329 $db = $this->getDB( $serverIndex );
330 } catch ( DBError $e ) {
331 $this->handleWriteError( $e, $db, $serverIndex );
332 $result = false;
333 continue;
334 }
335
336 if ( $exptime < 0 ) {
337 $exptime = 0;
338 }
339
340 if ( $exptime == 0 ) {
341 $encExpiry = $this->getMaxDateTime( $db );
342 } else {
343 $exptime = $this->convertExpiry( $exptime );
344 $encExpiry = $db->timestamp( $exptime );
345 }
346 foreach ( $serverKeys as $tableName => $tableKeys ) {
347 $rows = [];
348 foreach ( $tableKeys as $key ) {
349 $rows[] = [
350 'keyname' => $key,
351 'value' => $db->encodeBlob( $this->serialize( $data[$key] ) ),
352 'exptime' => $encExpiry,
353 ];
354 }
355
356 try {
357 $db->replace(
359 [ 'keyname' ],
360 $rows,
361 __METHOD__
362 );
363 } catch ( DBError $e ) {
364 $this->handleWriteError( $e, $db, $serverIndex );
365 $result = false;
366 }
367
368 }
369
370 }
371
372 return $result;
373 }
374
375 public function set( $key, $value, $exptime = 0, $flags = 0 ) {
376 $ok = $this->setMulti( [ $key => $value ], $exptime );
377 if ( ( $flags & self::WRITE_SYNC ) == self::WRITE_SYNC ) {
378 $ok = $this->waitForReplication() && $ok;
379 }
380
381 return $ok;
382 }
383
384 protected function cas( $casToken, $key, $value, $exptime = 0 ) {
385 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
386 $db = null;
387 try {
388 $db = $this->getDB( $serverIndex );
389 $exptime = intval( $exptime );
390
391 if ( $exptime < 0 ) {
392 $exptime = 0;
393 }
394
395 if ( $exptime == 0 ) {
396 $encExpiry = $this->getMaxDateTime( $db );
397 } else {
398 $exptime = $this->convertExpiry( $exptime );
399 $encExpiry = $db->timestamp( $exptime );
400 }
401 // (T26425) use a replace if the db supports it instead of
402 // delete/insert to avoid clashes with conflicting keynames
403 $db->update(
405 [
406 'keyname' => $key,
407 'value' => $db->encodeBlob( $this->serialize( $value ) ),
408 'exptime' => $encExpiry
409 ],
410 [
411 'keyname' => $key,
412 'value' => $db->encodeBlob( $this->serialize( $casToken ) )
413 ],
414 __METHOD__
415 );
416 } catch ( DBQueryError $e ) {
417 $this->handleWriteError( $e, $db, $serverIndex );
418
419 return false;
420 }
421
422 return (bool)$db->affectedRows();
423 }
424
425 public function delete( $key ) {
426 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
427 $db = null;
428 try {
429 $db = $this->getDB( $serverIndex );
430 $db->delete(
432 [ 'keyname' => $key ],
433 __METHOD__ );
434 } catch ( DBError $e ) {
435 $this->handleWriteError( $e, $db, $serverIndex );
436 return false;
437 }
438
439 return true;
440 }
441
442 public function incr( $key, $step = 1 ) {
443 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
444 $db = null;
445 try {
446 $db = $this->getDB( $serverIndex );
447 $step = intval( $step );
448 $row = $db->selectRow(
450 [ 'value', 'exptime' ],
451 [ 'keyname' => $key ],
452 __METHOD__,
453 [ 'FOR UPDATE' ] );
454 if ( $row === false ) {
455 // Missing
456
457 return null;
458 }
459 $db->delete( $tableName, [ 'keyname' => $key ], __METHOD__ );
460 if ( $this->isExpired( $db, $row->exptime ) ) {
461 // Expired, do not reinsert
462
463 return null;
464 }
465
466 $oldValue = intval( $this->unserialize( $db->decodeBlob( $row->value ) ) );
467 $newValue = $oldValue + $step;
468 $db->insert( $tableName,
469 [
470 'keyname' => $key,
471 'value' => $db->encodeBlob( $this->serialize( $newValue ) ),
472 'exptime' => $row->exptime
473 ], __METHOD__, 'IGNORE' );
474
475 if ( $db->affectedRows() == 0 ) {
476 // Race condition. See T30611
477 $newValue = null;
478 }
479 } catch ( DBError $e ) {
480 $this->handleWriteError( $e, $db, $serverIndex );
481 return null;
482 }
483
484 return $newValue;
485 }
486
487 public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
488 $ok = $this->mergeViaCas( $key, $callback, $exptime, $attempts );
489 if ( ( $flags & self::WRITE_SYNC ) == self::WRITE_SYNC ) {
490 $ok = $this->waitForReplication() && $ok;
491 }
492
493 return $ok;
494 }
495
496 public function changeTTL( $key, $expiry = 0 ) {
497 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
498 $db = null;
499 try {
500 $db = $this->getDB( $serverIndex );
501 $db->update(
503 [ 'exptime' => $db->timestamp( $this->convertExpiry( $expiry ) ) ],
504 [ 'keyname' => $key, 'exptime > ' . $db->addQuotes( $db->timestamp( time() ) ) ],
505 __METHOD__
506 );
507 if ( $db->affectedRows() == 0 ) {
508 return false;
509 }
510 } catch ( DBError $e ) {
511 $this->handleWriteError( $e, $db, $serverIndex );
512 return false;
513 }
514
515 return true;
516 }
517
523 protected function isExpired( $db, $exptime ) {
524 return $exptime != $this->getMaxDateTime( $db ) && wfTimestamp( TS_UNIX, $exptime ) < time();
525 }
526
531 protected function getMaxDateTime( $db ) {
532 if ( time() > 0x7fffffff ) {
533 return $db->timestamp( 1 << 62 );
534 } else {
535 return $db->timestamp( 0x7fffffff );
536 }
537 }
538
539 protected function garbageCollect() {
540 if ( !$this->purgePeriod || $this->replicaOnly ) {
541 // Disabled
542 return;
543 }
544 // Only purge on one in every $this->purgePeriod requests.
545 if ( $this->purgePeriod !== 1 && mt_rand( 0, $this->purgePeriod - 1 ) ) {
546 return;
547 }
548 $now = time();
549 // Avoid repeating the delete within a few seconds
550 if ( $now > ( $this->lastExpireAll + 1 ) ) {
551 $this->lastExpireAll = $now;
552 $this->expireAll();
553 }
554 }
555
556 public function expireAll() {
558 }
559
566 public function deleteObjectsExpiringBefore( $timestamp, $progressCallback = false ) {
567 for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) {
568 $db = null;
569 try {
570 $db = $this->getDB( $serverIndex );
571 $dbTimestamp = $db->timestamp( $timestamp );
572 $totalSeconds = false;
573 $baseConds = [ 'exptime < ' . $db->addQuotes( $dbTimestamp ) ];
574 for ( $i = 0; $i < $this->shards; $i++ ) {
575 $maxExpTime = false;
576 while ( true ) {
577 $conds = $baseConds;
578 if ( $maxExpTime !== false ) {
579 $conds[] = 'exptime >= ' . $db->addQuotes( $maxExpTime );
580 }
581 $rows = $db->select(
582 $this->getTableNameByShard( $i ),
583 [ 'keyname', 'exptime' ],
584 $conds,
585 __METHOD__,
586 [ 'LIMIT' => 100, 'ORDER BY' => 'exptime' ] );
587 if ( $rows === false || !$rows->numRows() ) {
588 break;
589 }
590 $keys = [];
591 $row = $rows->current();
592 $minExpTime = $row->exptime;
593 if ( $totalSeconds === false ) {
594 $totalSeconds = wfTimestamp( TS_UNIX, $timestamp )
595 - wfTimestamp( TS_UNIX, $minExpTime );
596 }
597 foreach ( $rows as $row ) {
598 $keys[] = $row->keyname;
599 $maxExpTime = $row->exptime;
600 }
601
602 $db->delete(
603 $this->getTableNameByShard( $i ),
604 [
605 'exptime >= ' . $db->addQuotes( $minExpTime ),
606 'exptime < ' . $db->addQuotes( $dbTimestamp ),
607 'keyname' => $keys
608 ],
609 __METHOD__ );
610
611 if ( $progressCallback ) {
612 if ( intval( $totalSeconds ) === 0 ) {
613 $percent = 0;
614 } else {
615 $remainingSeconds = wfTimestamp( TS_UNIX, $timestamp )
616 - wfTimestamp( TS_UNIX, $maxExpTime );
617 if ( $remainingSeconds > $totalSeconds ) {
618 $totalSeconds = $remainingSeconds;
619 }
620 $processedSeconds = $totalSeconds - $remainingSeconds;
621 $percent = ( $i + $processedSeconds / $totalSeconds )
622 / $this->shards * 100;
623 }
624 $percent = ( $percent / $this->numServers )
625 + ( $serverIndex / $this->numServers * 100 );
626 call_user_func( $progressCallback, $percent );
627 }
628 }
629 }
630 } catch ( DBError $e ) {
631 $this->handleWriteError( $e, $db, $serverIndex );
632 return false;
633 }
634 }
635 return true;
636 }
637
643 public function deleteAll() {
644 for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) {
645 $db = null;
646 try {
647 $db = $this->getDB( $serverIndex );
648 for ( $i = 0; $i < $this->shards; $i++ ) {
649 $db->delete( $this->getTableNameByShard( $i ), '*', __METHOD__ );
650 }
651 } catch ( DBError $e ) {
652 $this->handleWriteError( $e, $db, $serverIndex );
653 return false;
654 }
655 }
656 return true;
657 }
658
667 protected function serialize( &$data ) {
668 $serial = serialize( $data );
669
670 if ( function_exists( 'gzdeflate' ) ) {
671 return gzdeflate( $serial );
672 } else {
673 return $serial;
674 }
675 }
676
682 protected function unserialize( $serial ) {
683 if ( function_exists( 'gzinflate' ) ) {
684 MediaWiki\suppressWarnings();
685 $decomp = gzinflate( $serial );
686 MediaWiki\restoreWarnings();
687
688 if ( false !== $decomp ) {
689 $serial = $decomp;
690 }
691 }
692
693 $ret = unserialize( $serial );
694
695 return $ret;
696 }
697
704 protected function handleReadError( DBError $exception, $serverIndex ) {
705 if ( $exception instanceof DBConnectionError ) {
706 $this->markServerDown( $exception, $serverIndex );
707 }
708 $this->logger->error( "DBError: {$exception->getMessage()}" );
709 if ( $exception instanceof DBConnectionError ) {
711 $this->logger->debug( __METHOD__ . ": ignoring connection error" );
712 } else {
714 $this->logger->debug( __METHOD__ . ": ignoring query error" );
715 }
716 }
717
726 protected function handleWriteError( DBError $exception, IDatabase $db = null, $serverIndex ) {
727 if ( !$db ) {
728 $this->markServerDown( $exception, $serverIndex );
729 } elseif ( $db->wasReadOnlyError() ) {
730 if ( $db->trxLevel() && $this->usesMainDB() ) {
731 // Errors like deadlocks and connection drops already cause rollback.
732 // For consistency, we have no choice but to throw an error and trigger
733 // complete rollback if the main DB is also being used as the cache DB.
734 throw $exception;
735 }
736 }
737
738 $this->logger->error( "DBError: {$exception->getMessage()}" );
739 if ( $exception instanceof DBConnectionError ) {
741 $this->logger->debug( __METHOD__ . ": ignoring connection error" );
742 } else {
744 $this->logger->debug( __METHOD__ . ": ignoring query error" );
745 }
746 }
747
754 protected function markServerDown( DBError $exception, $serverIndex ) {
755 unset( $this->conns[$serverIndex] ); // bug T103435
756
757 if ( isset( $this->connFailureTimes[$serverIndex] ) ) {
758 if ( time() - $this->connFailureTimes[$serverIndex] >= 60 ) {
759 unset( $this->connFailureTimes[$serverIndex] );
760 unset( $this->connFailureErrors[$serverIndex] );
761 } else {
762 $this->logger->debug( __METHOD__ . ": Server #$serverIndex already down" );
763 return;
764 }
765 }
766 $now = time();
767 $this->logger->info( __METHOD__ . ": Server #$serverIndex down until " . ( $now + 60 ) );
768 $this->connFailureTimes[$serverIndex] = $now;
769 $this->connFailureErrors[$serverIndex] = $exception;
770 }
771
775 public function createTables() {
776 for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) {
777 $db = $this->getDB( $serverIndex );
778 if ( $db->getType() !== 'mysql' ) {
779 throw new MWException( __METHOD__ . ' is not supported on this DB server' );
780 }
781
782 for ( $i = 0; $i < $this->shards; $i++ ) {
783 $db->query(
784 'CREATE TABLE ' . $db->tableName( $this->getTableNameByShard( $i ) ) .
785 ' LIKE ' . $db->tableName( 'objectcache' ),
786 __METHOD__ );
787 }
788 }
789 }
790
794 protected function usesMainDB() {
795 return !$this->serverInfos;
796 }
797
798 protected function waitForReplication() {
799 if ( !$this->usesMainDB() ) {
800 // Custom DB server list; probably doesn't use replication
801 return true;
802 }
803
804 $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
805 if ( $lb->getServerCount() <= 1 ) {
806 return true; // no replica DBs
807 }
808
809 // Main LB is used; wait for any replica DBs to catch up
810 $masterPos = $lb->getMasterPos();
811
812 $loop = new WaitConditionLoop(
813 function () use ( $lb, $masterPos ) {
814 return $lb->waitForAll( $masterPos, 1 );
815 },
818 );
819
820 return ( $loop->invoke() === $loop::CONDITION_REACHED );
821 }
822}
serialize()
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
interface is intended to be more or less compatible with the PHP memcached client.
Definition BagOStuff.php:47
const ERR_UNEXPECTED
Definition BagOStuff.php:80
convertExpiry( $exptime)
Convert an optionally relative time to an absolute time.
callable[] $busyCallbacks
Definition BagOStuff.php:71
debug( $text)
setLastError( $err)
Set the "last error" registry.
mergeViaCas( $key, $callback, $exptime=0, $attempts=10)
const ERR_UNREACHABLE
Definition BagOStuff.php:79
MediaWiki exception.
Class to store objects in the database.
getDB( $serverIndex)
Get a connection to the specified database.
doGet( $key, $flags=0)
string[] $serverTags
(server index => tag/host name)
LoadBalancer null $separateMainLB
createTables()
Create shard tables.
getTableByKey( $key)
Get the server index and table name for a given key.
getMulti(array $keys, $flags=0)
Get an associative array containing the item for each of the keys that have items.
array[] $serverInfos
(server index => server config)
deleteAll()
Delete content of shard tables in every server.
__construct( $params)
Constructor.
getWithToken( $key, &$casToken, $flags=0)
isExpired( $db, $exptime)
changeTTL( $key, $expiry=0)
Reset the TTL on a key if it exists.
handleWriteError(DBError $exception, IDatabase $db=null, $serverIndex)
Handle a DBQueryError which occurred during a write operation.
array $connFailureTimes
UNIX timestamps.
array $connFailureErrors
Exceptions.
deleteObjectsExpiringBefore( $timestamp, $progressCallback=false)
Delete objects from the database which expire before a certain date.
cas( $casToken, $key, $value, $exptime=0)
Check and set an item.
merge( $key, callable $callback, $exptime=0, $attempts=10, $flags=0)
Merge changes into the existing cache value (possibly creating a new one)
serialize(&$data)
Serialize an object and, if possible, compress the representation.
markServerDown(DBError $exception, $serverIndex)
Mark a server down due to a DBConnectionError exception.
unserialize( $serial)
Unserialize and, if necessary, decompress an object.
string $tableName
getTableNameByShard( $index)
Get the table name for a given shard index.
incr( $key, $step=1)
Increase stored value of $key by $value while preserving its TTL.
handleReadError(DBError $exception, $serverIndex)
Handle a DBError which occurred during a read operation.
setMulti(array $data, $expiry=0)
Batch insertion.
Database error base class.
Definition DBError.php:30
Relational database abstraction object.
Definition Database.php:45
Database connection, tracking, load balancing, and transaction manager for a cluster.
Helper class that detects high-contention DB queries via profiling calls.
$res
Definition database.txt:21
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
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
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:26
namespace being checked & $result
Definition hooks.txt:2293
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
Definition hooks.txt:2746
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition hooks.txt:2805
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:1975
returning false will NOT prevent logging $e
Definition hooks.txt:2146
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:40
const DB_REPLICA
Definition defines.php:25
const DB_MASTER
Definition defines.php:26
const DBO_TRX
Definition defines.php:12
$params