Use camel case for variable names in Article.php
[lhc/web/wiklou.git] / includes / objectcache / SqlBagOStuff.php
1 <?php
2 /**
3 * Object caching using a SQL database.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Cache
22 */
23
24 /**
25 * Class to store objects in the database
26 *
27 * @ingroup Cache
28 */
29 class SqlBagOStuff extends BagOStuff {
30 protected $serverInfos;
31
32 /** @var array */
33 protected $serverNames;
34
35 /** @var int */
36 protected $numServers;
37
38 /** @var array */
39 protected $conns;
40
41 /** @var int */
42 protected $lastExpireAll = 0;
43
44 /** @var int */
45 protected $purgePeriod = 100;
46
47 /** @var int */
48 protected $shards = 1;
49
50 /** @var string */
51 protected $tableName = 'objectcache';
52
53 /** @var array UNIX timestamps */
54 protected $connFailureTimes = array();
55
56 /** @var array Exceptions */
57 protected $connFailureErrors = array();
58
59 /**
60 * Constructor. Parameters are:
61 * - server: A server info structure in the format required by each
62 * element in $wgDBServers.
63 *
64 * - servers: An array of server info structures describing a set of
65 * database servers to distribute keys to. If this is
66 * specified, the "server" option will be ignored.
67 *
68 * - purgePeriod: The average number of object cache requests in between
69 * garbage collection operations, where expired entries
70 * are removed from the database. Or in other words, the
71 * reciprocal of the probability of purging on any given
72 * request. If this is set to zero, purging will never be
73 * done.
74 *
75 * - tableName: The table name to use, default is "objectcache".
76 *
77 * - shards: The number of tables to use for data storage on each server.
78 * If this is more than 1, table names will be formed in the style
79 * objectcacheNNN where NNN is the shard index, between 0 and
80 * shards-1. The number of digits will be the minimum number
81 * required to hold the largest shard index. Data will be
82 * distributed across all tables by key hash. This is for
83 * MySQL bugs 61735 and 61736.
84 *
85 * @param array $params
86 */
87 public function __construct( $params ) {
88 if ( isset( $params['servers'] ) ) {
89 $this->serverInfos = $params['servers'];
90 $this->numServers = count( $this->serverInfos );
91 $this->serverNames = array();
92 foreach ( $this->serverInfos as $i => $info ) {
93 $this->serverNames[$i] = isset( $info['host'] ) ? $info['host'] : "#$i";
94 }
95 } elseif ( isset( $params['server'] ) ) {
96 $this->serverInfos = array( $params['server'] );
97 $this->numServers = count( $this->serverInfos );
98 } else {
99 $this->serverInfos = false;
100 $this->numServers = 1;
101 }
102 if ( isset( $params['purgePeriod'] ) ) {
103 $this->purgePeriod = intval( $params['purgePeriod'] );
104 }
105 if ( isset( $params['tableName'] ) ) {
106 $this->tableName = $params['tableName'];
107 }
108 if ( isset( $params['shards'] ) ) {
109 $this->shards = intval( $params['shards'] );
110 }
111 }
112
113 /**
114 * Get a connection to the specified database
115 *
116 * @param int $serverIndex
117 * @return DatabaseBase
118 */
119 protected function getDB( $serverIndex ) {
120 global $wgDebugDBTransactions;
121
122 if ( !isset( $this->conns[$serverIndex] ) ) {
123 if ( $serverIndex >= $this->numServers ) {
124 throw new MWException( __METHOD__ . ": Invalid server index \"$serverIndex\"" );
125 }
126
127 # Don't keep timing out trying to connect for each call if the DB is down
128 if ( isset( $this->connFailureErrors[$serverIndex] )
129 && ( time() - $this->connFailureTimes[$serverIndex] ) < 60
130 ) {
131 throw $this->connFailureErrors[$serverIndex];
132 }
133
134 # If server connection info was given, use that
135 if ( $this->serverInfos ) {
136 if ( $wgDebugDBTransactions ) {
137 wfDebug( "Using provided serverInfo for SqlBagOStuff\n" );
138 }
139 $info = $this->serverInfos[$serverIndex];
140 $type = isset( $info['type'] ) ? $info['type'] : 'mysql';
141 $host = isset( $info['host'] ) ? $info['host'] : '[unknown]';
142 wfDebug( __CLASS__ . ": connecting to $host\n" );
143 $db = DatabaseBase::factory( $type, $info );
144 $db->clearFlag( DBO_TRX );
145 } else {
146 // We must keep a separate connection to MySQL in order to avoid deadlocks
147 // However, SQLite has an opposite behavior.
148 // @todo get this trick to work on PostgreSQL too
149 if ( wfGetDB( DB_MASTER )->getType() == 'mysql' ) {
150 $lb = wfGetLBFactory()->newMainLB();
151 $db = $lb->getConnection( DB_MASTER );
152 $db->clearFlag( DBO_TRX ); // auto-commit mode
153 } else {
154 $db = wfGetDB( DB_MASTER );
155 }
156 }
157 if ( $wgDebugDBTransactions ) {
158 wfDebug( sprintf( "Connection %s will be used for SqlBagOStuff\n", $db ) );
159 }
160 $this->conns[$serverIndex] = $db;
161 }
162
163 return $this->conns[$serverIndex];
164 }
165
166 /**
167 * Get the server index and table name for a given key
168 * @param string $key
169 * @return array Server index and table name
170 */
171 protected function getTableByKey( $key ) {
172 if ( $this->shards > 1 ) {
173 $hash = hexdec( substr( md5( $key ), 0, 8 ) ) & 0x7fffffff;
174 $tableIndex = $hash % $this->shards;
175 } else {
176 $tableIndex = 0;
177 }
178 if ( $this->numServers > 1 ) {
179 $sortedServers = $this->serverNames;
180 ArrayUtils::consistentHashSort( $sortedServers, $key );
181 reset( $sortedServers );
182 $serverIndex = key( $sortedServers );
183 } else {
184 $serverIndex = 0;
185 }
186 return array( $serverIndex, $this->getTableNameByShard( $tableIndex ) );
187 }
188
189 /**
190 * Get the table name for a given shard index
191 * @param int $index
192 * @return string
193 */
194 protected function getTableNameByShard( $index ) {
195 if ( $this->shards > 1 ) {
196 $decimals = strlen( $this->shards - 1 );
197 return $this->tableName .
198 sprintf( "%0{$decimals}d", $index );
199 } else {
200 return $this->tableName;
201 }
202 }
203
204 /**
205 * @param string $key
206 * @param mixed $casToken [optional]
207 * @return mixed
208 */
209 public function get( $key, &$casToken = null ) {
210 $values = $this->getMulti( array( $key ) );
211 if ( array_key_exists( $key, $values ) ) {
212 $casToken = $values[$key];
213 return $values[$key];
214 }
215 return false;
216 }
217
218 /**
219 * @param array $keys
220 * @return array
221 */
222 public function getMulti( array $keys ) {
223 $values = array(); // array of (key => value)
224
225 $keysByTable = array();
226 foreach ( $keys as $key ) {
227 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
228 $keysByTable[$serverIndex][$tableName][] = $key;
229 }
230
231 $this->garbageCollect(); // expire old entries if any
232
233 $dataRows = array();
234 foreach ( $keysByTable as $serverIndex => $serverKeys ) {
235 try {
236 $db = $this->getDB( $serverIndex );
237 foreach ( $serverKeys as $tableName => $tableKeys ) {
238 $res = $db->select( $tableName,
239 array( 'keyname', 'value', 'exptime' ),
240 array( 'keyname' => $tableKeys ),
241 __METHOD__,
242 // Approximate write-on-the-fly BagOStuff API via blocking.
243 // This approximation fails if a ROLLBACK happens (which is rare).
244 // We do not want to flush the TRX as that can break callers.
245 $db->trxLevel() ? array( 'LOCK IN SHARE MODE' ) : array()
246 );
247 if ( $res === false ) {
248 continue;
249 }
250 foreach ( $res as $row ) {
251 $row->serverIndex = $serverIndex;
252 $row->tableName = $tableName;
253 $dataRows[$row->keyname] = $row;
254 }
255 }
256 } catch ( DBError $e ) {
257 $this->handleReadError( $e, $serverIndex );
258 }
259 }
260
261 foreach ( $keys as $key ) {
262 if ( isset( $dataRows[$key] ) ) { // HIT?
263 $row = $dataRows[$key];
264 $this->debug( "get: retrieved data; expiry time is " . $row->exptime );
265 try {
266 $db = $this->getDB( $row->serverIndex );
267 if ( $this->isExpired( $db, $row->exptime ) ) { // MISS
268 $this->debug( "get: key has expired, deleting" );
269 # Put the expiry time in the WHERE condition to avoid deleting a
270 # newly-inserted value
271 $db->delete( $row->tableName,
272 array( 'keyname' => $key, 'exptime' => $row->exptime ),
273 __METHOD__ );
274 } else { // HIT
275 $values[$key] = $this->unserialize( $db->decodeBlob( $row->value ) );
276 }
277 } catch ( DBQueryError $e ) {
278 $this->handleWriteError( $e, $row->serverIndex );
279 }
280 } else { // MISS
281 $this->debug( 'get: no matching rows' );
282 }
283 }
284
285 return $values;
286 }
287
288 /**
289 * @param array $data
290 * @param int $expiry
291 * @return bool
292 */
293 public function setMulti( array $data, $expiry = 0 ) {
294 $keysByTable = array();
295 foreach ( $data as $key => $value ) {
296 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
297 $keysByTable[$serverIndex][$tableName][] = $key;
298 }
299
300 $this->garbageCollect(); // expire old entries if any
301
302 $result = true;
303 $exptime = (int)$expiry;
304 foreach ( $keysByTable as $serverIndex => $serverKeys ) {
305 try {
306 $db = $this->getDB( $serverIndex );
307 } catch ( DBError $e ) {
308 $this->handleWriteError( $e, $serverIndex );
309 $result = false;
310 continue;
311 }
312
313 if ( $exptime < 0 ) {
314 $exptime = 0;
315 }
316
317 if ( $exptime == 0 ) {
318 $encExpiry = $this->getMaxDateTime( $db );
319 } else {
320 if ( $exptime < 3.16e8 ) { # ~10 years
321 $exptime += time();
322 }
323 $encExpiry = $db->timestamp( $exptime );
324 }
325 foreach ( $serverKeys as $tableName => $tableKeys ) {
326 $rows = array();
327 foreach ( $tableKeys as $key ) {
328 $rows[] = array(
329 'keyname' => $key,
330 'value' => $db->encodeBlob( $this->serialize( $data[$key] ) ),
331 'exptime' => $encExpiry,
332 );
333 }
334
335 try {
336 $db->replace(
337 $tableName,
338 array( 'keyname' ),
339 $rows,
340 __METHOD__
341 );
342 } catch ( DBError $e ) {
343 $this->handleWriteError( $e, $serverIndex );
344 $result = false;
345 }
346
347 }
348
349 }
350
351 return $result;
352 }
353
354
355
356 /**
357 * @param string $key
358 * @param mixed $value
359 * @param int $exptime
360 * @return bool
361 */
362 public function set( $key, $value, $exptime = 0 ) {
363 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
364 try {
365 $db = $this->getDB( $serverIndex );
366 $exptime = intval( $exptime );
367
368 if ( $exptime < 0 ) {
369 $exptime = 0;
370 }
371
372 if ( $exptime == 0 ) {
373 $encExpiry = $this->getMaxDateTime( $db );
374 } else {
375 if ( $exptime < 3.16e8 ) { # ~10 years
376 $exptime += time();
377 }
378
379 $encExpiry = $db->timestamp( $exptime );
380 }
381 // (bug 24425) use a replace if the db supports it instead of
382 // delete/insert to avoid clashes with conflicting keynames
383 $db->replace(
384 $tableName,
385 array( 'keyname' ),
386 array(
387 'keyname' => $key,
388 'value' => $db->encodeBlob( $this->serialize( $value ) ),
389 'exptime' => $encExpiry
390 ), __METHOD__ );
391 } catch ( DBError $e ) {
392 $this->handleWriteError( $e, $serverIndex );
393 return false;
394 }
395
396 return true;
397 }
398
399 /**
400 * @param mixed $casToken
401 * @param string $key
402 * @param mixed $value
403 * @param int $exptime
404 * @return bool
405 */
406 public function cas( $casToken, $key, $value, $exptime = 0 ) {
407 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
408 try {
409 $db = $this->getDB( $serverIndex );
410 $exptime = intval( $exptime );
411
412 if ( $exptime < 0 ) {
413 $exptime = 0;
414 }
415
416 if ( $exptime == 0 ) {
417 $encExpiry = $this->getMaxDateTime( $db );
418 } else {
419 if ( $exptime < 3.16e8 ) { # ~10 years
420 $exptime += time();
421 }
422 $encExpiry = $db->timestamp( $exptime );
423 }
424 // (bug 24425) use a replace if the db supports it instead of
425 // delete/insert to avoid clashes with conflicting keynames
426 $db->update(
427 $tableName,
428 array(
429 'keyname' => $key,
430 'value' => $db->encodeBlob( $this->serialize( $value ) ),
431 'exptime' => $encExpiry
432 ),
433 array(
434 'keyname' => $key,
435 'value' => $db->encodeBlob( $this->serialize( $casToken ) )
436 ),
437 __METHOD__
438 );
439 } catch ( DBQueryError $e ) {
440 $this->handleWriteError( $e, $serverIndex );
441
442 return false;
443 }
444
445 return (bool)$db->affectedRows();
446 }
447
448 /**
449 * @param string $key
450 * @param int $time
451 * @return bool
452 */
453 public function delete( $key, $time = 0 ) {
454 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
455 try {
456 $db = $this->getDB( $serverIndex );
457 $db->delete(
458 $tableName,
459 array( 'keyname' => $key ),
460 __METHOD__ );
461 } catch ( DBError $e ) {
462 $this->handleWriteError( $e, $serverIndex );
463 return false;
464 }
465
466 return true;
467 }
468
469 /**
470 * @param string $key
471 * @param int $step
472 * @return int|null
473 */
474 public function incr( $key, $step = 1 ) {
475 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
476 try {
477 $db = $this->getDB( $serverIndex );
478 $step = intval( $step );
479 $row = $db->selectRow(
480 $tableName,
481 array( 'value', 'exptime' ),
482 array( 'keyname' => $key ),
483 __METHOD__,
484 array( 'FOR UPDATE' ) );
485 if ( $row === false ) {
486 // Missing
487
488 return null;
489 }
490 $db->delete( $tableName, array( 'keyname' => $key ), __METHOD__ );
491 if ( $this->isExpired( $db, $row->exptime ) ) {
492 // Expired, do not reinsert
493
494 return null;
495 }
496
497 $oldValue = intval( $this->unserialize( $db->decodeBlob( $row->value ) ) );
498 $newValue = $oldValue + $step;
499 $db->insert( $tableName,
500 array(
501 'keyname' => $key,
502 'value' => $db->encodeBlob( $this->serialize( $newValue ) ),
503 'exptime' => $row->exptime
504 ), __METHOD__, 'IGNORE' );
505
506 if ( $db->affectedRows() == 0 ) {
507 // Race condition. See bug 28611
508 $newValue = null;
509 }
510 } catch ( DBError $e ) {
511 $this->handleWriteError( $e, $serverIndex );
512 return null;
513 }
514
515 return $newValue;
516 }
517
518 /**
519 * @param string $exptime
520 * @return bool
521 */
522 protected function isExpired( $db, $exptime ) {
523 return $exptime != $this->getMaxDateTime( $db ) && wfTimestamp( TS_UNIX, $exptime ) < time();
524 }
525
526 /**
527 * @param DatabaseBase $db
528 * @return string
529 */
530 protected function getMaxDateTime( $db ) {
531 if ( time() > 0x7fffffff ) {
532 return $db->timestamp( 1 << 62 );
533 } else {
534 return $db->timestamp( 0x7fffffff );
535 }
536 }
537
538 protected function garbageCollect() {
539 if ( !$this->purgePeriod ) {
540 // Disabled
541 return;
542 }
543 // Only purge on one in every $this->purgePeriod requests.
544 if ( $this->purgePeriod !== 1 && mt_rand( 0, $this->purgePeriod - 1 ) ) {
545 return;
546 }
547 $now = time();
548 // Avoid repeating the delete within a few seconds
549 if ( $now > ( $this->lastExpireAll + 1 ) ) {
550 $this->lastExpireAll = $now;
551 $this->expireAll();
552 }
553 }
554
555 public function expireAll() {
556 $this->deleteObjectsExpiringBefore( wfTimestampNow() );
557 }
558
559 /**
560 * Delete objects from the database which expire before a certain date.
561 * @param string $timestamp
562 * @param bool|callable $progressCallback
563 * @return bool
564 */
565 public function deleteObjectsExpiringBefore( $timestamp, $progressCallback = false ) {
566 for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) {
567 try {
568 $db = $this->getDB( $serverIndex );
569 $dbTimestamp = $db->timestamp( $timestamp );
570 $totalSeconds = false;
571 $baseConds = array( 'exptime < ' . $db->addQuotes( $dbTimestamp ) );
572 for ( $i = 0; $i < $this->shards; $i++ ) {
573 $maxExpTime = false;
574 while ( true ) {
575 $conds = $baseConds;
576 if ( $maxExpTime !== false ) {
577 $conds[] = 'exptime > ' . $db->addQuotes( $maxExpTime );
578 }
579 $rows = $db->select(
580 $this->getTableNameByShard( $i ),
581 array( 'keyname', 'exptime' ),
582 $conds,
583 __METHOD__,
584 array( 'LIMIT' => 100, 'ORDER BY' => 'exptime' ) );
585 if ( $rows === false || !$rows->numRows() ) {
586 break;
587 }
588 $keys = array();
589 $row = $rows->current();
590 $minExpTime = $row->exptime;
591 if ( $totalSeconds === false ) {
592 $totalSeconds = wfTimestamp( TS_UNIX, $timestamp )
593 - wfTimestamp( TS_UNIX, $minExpTime );
594 }
595 foreach ( $rows as $row ) {
596 $keys[] = $row->keyname;
597 $maxExpTime = $row->exptime;
598 }
599
600 $db->delete(
601 $this->getTableNameByShard( $i ),
602 array(
603 'exptime >= ' . $db->addQuotes( $minExpTime ),
604 'exptime < ' . $db->addQuotes( $dbTimestamp ),
605 'keyname' => $keys
606 ),
607 __METHOD__ );
608
609 if ( $progressCallback ) {
610 if ( intval( $totalSeconds ) === 0 ) {
611 $percent = 0;
612 } else {
613 $remainingSeconds = wfTimestamp( TS_UNIX, $timestamp )
614 - wfTimestamp( TS_UNIX, $maxExpTime );
615 if ( $remainingSeconds > $totalSeconds ) {
616 $totalSeconds = $remainingSeconds;
617 }
618 $percent = ( $i + $remainingSeconds / $totalSeconds )
619 / $this->shards * 100;
620 }
621 $percent = ( $percent / $this->numServers )
622 + ( $serverIndex / $this->numServers * 100 );
623 call_user_func( $progressCallback, $percent );
624 }
625 }
626 }
627 } catch ( DBError $e ) {
628 $this->handleWriteError( $e, $serverIndex );
629 return false;
630 }
631 }
632 return true;
633 }
634
635 public function deleteAll() {
636 for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) {
637 try {
638 $db = $this->getDB( $serverIndex );
639 for ( $i = 0; $i < $this->shards; $i++ ) {
640 $db->delete( $this->getTableNameByShard( $i ), '*', __METHOD__ );
641 }
642 } catch ( DBError $e ) {
643 $this->handleWriteError( $e, $serverIndex );
644 return false;
645 }
646 }
647 return true;
648 }
649
650 /**
651 * Serialize an object and, if possible, compress the representation.
652 * On typical message and page data, this can provide a 3X decrease
653 * in storage requirements.
654 *
655 * @param mixed $data
656 * @return string
657 */
658 protected function serialize( &$data ) {
659 $serial = serialize( $data );
660
661 if ( function_exists( 'gzdeflate' ) ) {
662 return gzdeflate( $serial );
663 } else {
664 return $serial;
665 }
666 }
667
668 /**
669 * Unserialize and, if necessary, decompress an object.
670 * @param string $serial
671 * @return mixed
672 */
673 protected function unserialize( $serial ) {
674 if ( function_exists( 'gzinflate' ) ) {
675 wfSuppressWarnings();
676 $decomp = gzinflate( $serial );
677 wfRestoreWarnings();
678
679 if ( false !== $decomp ) {
680 $serial = $decomp;
681 }
682 }
683
684 $ret = unserialize( $serial );
685
686 return $ret;
687 }
688
689 /**
690 * Handle a DBError which occurred during a read operation.
691 *
692 * @param DBError $exception
693 * @param int $serverIndex
694 */
695 protected function handleReadError( DBError $exception, $serverIndex ) {
696 if ( $exception instanceof DBConnectionError ) {
697 $this->markServerDown( $exception, $serverIndex );
698 }
699 wfDebugLog( 'SQLBagOStuff', "DBError: {$exception->getMessage()}" );
700 if ( $exception instanceof DBConnectionError ) {
701 $this->setLastError( BagOStuff::ERR_UNREACHABLE );
702 wfDebug( __METHOD__ . ": ignoring connection error\n" );
703 } else {
704 $this->setLastError( BagOStuff::ERR_UNEXPECTED );
705 wfDebug( __METHOD__ . ": ignoring query error\n" );
706 }
707 }
708
709 /**
710 * Handle a DBQueryError which occurred during a write operation.
711 *
712 * @param DBError $exception
713 * @param int $serverIndex
714 */
715 protected function handleWriteError( DBError $exception, $serverIndex ) {
716 if ( $exception instanceof DBConnectionError ) {
717 $this->markServerDown( $exception, $serverIndex );
718 }
719 if ( $exception->db && $exception->db->wasReadOnlyError() ) {
720 try {
721 $exception->db->rollback( __METHOD__ );
722 } catch ( DBError $e ) {
723 }
724 }
725 wfDebugLog( 'SQLBagOStuff', "DBError: {$exception->getMessage()}" );
726 if ( $exception instanceof DBConnectionError ) {
727 $this->setLastError( BagOStuff::ERR_UNREACHABLE );
728 wfDebug( __METHOD__ . ": ignoring connection error\n" );
729 } else {
730 $this->setLastError( BagOStuff::ERR_UNEXPECTED );
731 wfDebug( __METHOD__ . ": ignoring query error\n" );
732 }
733 }
734
735 /**
736 * Mark a server down due to a DBConnectionError exception
737 *
738 * @param DBError $exception
739 * @param int $serverIndex
740 */
741 protected function markServerDown( $exception, $serverIndex ) {
742 if ( isset( $this->connFailureTimes[$serverIndex] ) ) {
743 if ( time() - $this->connFailureTimes[$serverIndex] >= 60 ) {
744 unset( $this->connFailureTimes[$serverIndex] );
745 unset( $this->connFailureErrors[$serverIndex] );
746 } else {
747 wfDebug( __METHOD__ . ": Server #$serverIndex already down\n" );
748 return;
749 }
750 }
751 $now = time();
752 wfDebug( __METHOD__ . ": Server #$serverIndex down until " . ( $now + 60 ) . "\n" );
753 $this->connFailureTimes[$serverIndex] = $now;
754 $this->connFailureErrors[$serverIndex] = $exception;
755 }
756
757 /**
758 * Create shard tables. For use from eval.php.
759 */
760 public function createTables() {
761 for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) {
762 $db = $this->getDB( $serverIndex );
763 if ( $db->getType() !== 'mysql' ) {
764 throw new MWException( __METHOD__ . ' is not supported on this DB server' );
765 }
766
767 for ( $i = 0; $i < $this->shards; $i++ ) {
768 $db->query(
769 'CREATE TABLE ' . $db->tableName( $this->getTableNameByShard( $i ) ) .
770 ' LIKE ' . $db->tableName( 'objectcache' ),
771 __METHOD__ );
772 }
773 }
774 }
775 }
776
777 /**
778 * Backwards compatibility alias
779 */
780 class MediaWikiBagOStuff extends SqlBagOStuff {
781 }