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