3b46249cf285793f83d042aecb319c0413a5a3d2
[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 /**
224 * @param string $key
225 * @param mixed $casToken [optional]
226 * @return mixed
227 */
228 public function get( $key, &$casToken = null ) {
229 $values = $this->getMulti( array( $key ) );
230 if ( array_key_exists( $key, $values ) ) {
231 $casToken = $values[$key];
232 return $values[$key];
233 }
234 return false;
235 }
236
237 /**
238 * @param array $keys
239 * @return array
240 */
241 public function getMulti( array $keys ) {
242 $values = array(); // array of (key => value)
243
244 $keysByTable = array();
245 foreach ( $keys as $key ) {
246 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
247 $keysByTable[$serverIndex][$tableName][] = $key;
248 }
249
250 $this->garbageCollect(); // expire old entries if any
251
252 $dataRows = array();
253 foreach ( $keysByTable as $serverIndex => $serverKeys ) {
254 try {
255 $db = $this->getDB( $serverIndex );
256 foreach ( $serverKeys as $tableName => $tableKeys ) {
257 $res = $db->select( $tableName,
258 array( 'keyname', 'value', 'exptime' ),
259 array( 'keyname' => $tableKeys ),
260 __METHOD__,
261 // Approximate write-on-the-fly BagOStuff API via blocking.
262 // This approximation fails if a ROLLBACK happens (which is rare).
263 // We do not want to flush the TRX as that can break callers.
264 $db->trxLevel() ? array( 'LOCK IN SHARE MODE' ) : array()
265 );
266 if ( $res === false ) {
267 continue;
268 }
269 foreach ( $res as $row ) {
270 $row->serverIndex = $serverIndex;
271 $row->tableName = $tableName;
272 $dataRows[$row->keyname] = $row;
273 }
274 }
275 } catch ( DBError $e ) {
276 $this->handleReadError( $e, $serverIndex );
277 }
278 }
279
280 foreach ( $keys as $key ) {
281 if ( isset( $dataRows[$key] ) ) { // HIT?
282 $row = $dataRows[$key];
283 $this->debug( "get: retrieved data; expiry time is " . $row->exptime );
284 try {
285 $db = $this->getDB( $row->serverIndex );
286 if ( $this->isExpired( $db, $row->exptime ) ) { // MISS
287 $this->debug( "get: key has expired" );
288 } else { // HIT
289 $values[$key] = $this->unserialize( $db->decodeBlob( $row->value ) );
290 }
291 } catch ( DBQueryError $e ) {
292 $this->handleWriteError( $e, $row->serverIndex );
293 }
294 } else { // MISS
295 $this->debug( 'get: no matching rows' );
296 }
297 }
298
299 return $values;
300 }
301
302 /**
303 * @param array $data
304 * @param int $expiry
305 * @return bool
306 */
307 public function setMulti( array $data, $expiry = 0 ) {
308 $keysByTable = array();
309 foreach ( $data as $key => $value ) {
310 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
311 $keysByTable[$serverIndex][$tableName][] = $key;
312 }
313
314 $this->garbageCollect(); // expire old entries if any
315
316 $result = true;
317 $exptime = (int)$expiry;
318 foreach ( $keysByTable as $serverIndex => $serverKeys ) {
319 try {
320 $db = $this->getDB( $serverIndex );
321 } catch ( DBError $e ) {
322 $this->handleWriteError( $e, $serverIndex );
323 $result = false;
324 continue;
325 }
326
327 if ( $exptime < 0 ) {
328 $exptime = 0;
329 }
330
331 if ( $exptime == 0 ) {
332 $encExpiry = $this->getMaxDateTime( $db );
333 } else {
334 $exptime = $this->convertExpiry( $exptime );
335 $encExpiry = $db->timestamp( $exptime );
336 }
337 foreach ( $serverKeys as $tableName => $tableKeys ) {
338 $rows = array();
339 foreach ( $tableKeys as $key ) {
340 $rows[] = array(
341 'keyname' => $key,
342 'value' => $db->encodeBlob( $this->serialize( $data[$key] ) ),
343 'exptime' => $encExpiry,
344 );
345 }
346
347 try {
348 $db->replace(
349 $tableName,
350 array( 'keyname' ),
351 $rows,
352 __METHOD__
353 );
354 } catch ( DBError $e ) {
355 $this->handleWriteError( $e, $serverIndex );
356 $result = false;
357 }
358
359 }
360
361 }
362
363 return $result;
364 }
365
366 /**
367 * @param string $key
368 * @param mixed $value
369 * @param int $exptime
370 * @return bool
371 */
372 public function set( $key, $value, $exptime = 0 ) {
373 return $this->setMulti( array( $key => $value ), $exptime );
374 }
375
376 /**
377 * @param mixed $casToken
378 * @param string $key
379 * @param mixed $value
380 * @param int $exptime
381 * @return bool
382 */
383 protected function cas( $casToken, $key, $value, $exptime = 0 ) {
384 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
385 try {
386 $db = $this->getDB( $serverIndex );
387 $exptime = intval( $exptime );
388
389 if ( $exptime < 0 ) {
390 $exptime = 0;
391 }
392
393 if ( $exptime == 0 ) {
394 $encExpiry = $this->getMaxDateTime( $db );
395 } else {
396 $exptime = $this->convertExpiry( $exptime );
397 $encExpiry = $db->timestamp( $exptime );
398 }
399 // (bug 24425) use a replace if the db supports it instead of
400 // delete/insert to avoid clashes with conflicting keynames
401 $db->update(
402 $tableName,
403 array(
404 'keyname' => $key,
405 'value' => $db->encodeBlob( $this->serialize( $value ) ),
406 'exptime' => $encExpiry
407 ),
408 array(
409 'keyname' => $key,
410 'value' => $db->encodeBlob( $this->serialize( $casToken ) )
411 ),
412 __METHOD__
413 );
414 } catch ( DBQueryError $e ) {
415 $this->handleWriteError( $e, $serverIndex );
416
417 return false;
418 }
419
420 return (bool)$db->affectedRows();
421 }
422
423 /**
424 * @param string $key
425 * @return bool
426 */
427 public function delete( $key ) {
428 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
429 try {
430 $db = $this->getDB( $serverIndex );
431 $db->delete(
432 $tableName,
433 array( 'keyname' => $key ),
434 __METHOD__ );
435 } catch ( DBError $e ) {
436 $this->handleWriteError( $e, $serverIndex );
437 return false;
438 }
439
440 return true;
441 }
442
443 /**
444 * @param string $key
445 * @param int $step
446 * @return int|null
447 */
448 public function incr( $key, $step = 1 ) {
449 list( $serverIndex, $tableName ) = $this->getTableByKey( $key );
450 try {
451 $db = $this->getDB( $serverIndex );
452 $step = intval( $step );
453 $row = $db->selectRow(
454 $tableName,
455 array( 'value', 'exptime' ),
456 array( 'keyname' => $key ),
457 __METHOD__,
458 array( 'FOR UPDATE' ) );
459 if ( $row === false ) {
460 // Missing
461
462 return null;
463 }
464 $db->delete( $tableName, array( 'keyname' => $key ), __METHOD__ );
465 if ( $this->isExpired( $db, $row->exptime ) ) {
466 // Expired, do not reinsert
467
468 return null;
469 }
470
471 $oldValue = intval( $this->unserialize( $db->decodeBlob( $row->value ) ) );
472 $newValue = $oldValue + $step;
473 $db->insert( $tableName,
474 array(
475 'keyname' => $key,
476 'value' => $db->encodeBlob( $this->serialize( $newValue ) ),
477 'exptime' => $row->exptime
478 ), __METHOD__, 'IGNORE' );
479
480 if ( $db->affectedRows() == 0 ) {
481 // Race condition. See bug 28611
482 $newValue = null;
483 }
484 } catch ( DBError $e ) {
485 $this->handleWriteError( $e, $serverIndex );
486 return null;
487 }
488
489 return $newValue;
490 }
491
492 public function merge( $key, $callback, $exptime = 0, $attempts = 10 ) {
493 if ( !is_callable( $callback ) ) {
494 throw new Exception( "Got invalid callback." );
495 }
496
497 return $this->mergeViaCas( $key, $callback, $exptime, $attempts );
498 }
499
500 /**
501 * @param DatabaseBase $db
502 * @param string $exptime
503 * @return bool
504 */
505 protected function isExpired( $db, $exptime ) {
506 return $exptime != $this->getMaxDateTime( $db ) && wfTimestamp( TS_UNIX, $exptime ) < time();
507 }
508
509 /**
510 * @param DatabaseBase $db
511 * @return string
512 */
513 protected function getMaxDateTime( $db ) {
514 if ( time() > 0x7fffffff ) {
515 return $db->timestamp( 1 << 62 );
516 } else {
517 return $db->timestamp( 0x7fffffff );
518 }
519 }
520
521 protected function garbageCollect() {
522 if ( !$this->purgePeriod || $this->slaveOnly ) {
523 // Disabled
524 return;
525 }
526 // Only purge on one in every $this->purgePeriod requests.
527 if ( $this->purgePeriod !== 1 && mt_rand( 0, $this->purgePeriod - 1 ) ) {
528 return;
529 }
530 $now = time();
531 // Avoid repeating the delete within a few seconds
532 if ( $now > ( $this->lastExpireAll + 1 ) ) {
533 $this->lastExpireAll = $now;
534 $this->expireAll();
535 }
536 }
537
538 public function expireAll() {
539 $this->deleteObjectsExpiringBefore( wfTimestampNow() );
540 }
541
542 /**
543 * Delete objects from the database which expire before a certain date.
544 * @param string $timestamp
545 * @param bool|callable $progressCallback
546 * @return bool
547 */
548 public function deleteObjectsExpiringBefore( $timestamp, $progressCallback = false ) {
549 for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) {
550 try {
551 $db = $this->getDB( $serverIndex );
552 $dbTimestamp = $db->timestamp( $timestamp );
553 $totalSeconds = false;
554 $baseConds = array( 'exptime < ' . $db->addQuotes( $dbTimestamp ) );
555 for ( $i = 0; $i < $this->shards; $i++ ) {
556 $maxExpTime = false;
557 while ( true ) {
558 $conds = $baseConds;
559 if ( $maxExpTime !== false ) {
560 $conds[] = 'exptime > ' . $db->addQuotes( $maxExpTime );
561 }
562 $rows = $db->select(
563 $this->getTableNameByShard( $i ),
564 array( 'keyname', 'exptime' ),
565 $conds,
566 __METHOD__,
567 array( 'LIMIT' => 100, 'ORDER BY' => 'exptime' ) );
568 if ( $rows === false || !$rows->numRows() ) {
569 break;
570 }
571 $keys = array();
572 $row = $rows->current();
573 $minExpTime = $row->exptime;
574 if ( $totalSeconds === false ) {
575 $totalSeconds = wfTimestamp( TS_UNIX, $timestamp )
576 - wfTimestamp( TS_UNIX, $minExpTime );
577 }
578 foreach ( $rows as $row ) {
579 $keys[] = $row->keyname;
580 $maxExpTime = $row->exptime;
581 }
582
583 $db->delete(
584 $this->getTableNameByShard( $i ),
585 array(
586 'exptime >= ' . $db->addQuotes( $minExpTime ),
587 'exptime < ' . $db->addQuotes( $dbTimestamp ),
588 'keyname' => $keys
589 ),
590 __METHOD__ );
591
592 if ( $progressCallback ) {
593 if ( intval( $totalSeconds ) === 0 ) {
594 $percent = 0;
595 } else {
596 $remainingSeconds = wfTimestamp( TS_UNIX, $timestamp )
597 - wfTimestamp( TS_UNIX, $maxExpTime );
598 if ( $remainingSeconds > $totalSeconds ) {
599 $totalSeconds = $remainingSeconds;
600 }
601 $processedSeconds = $totalSeconds - $remainingSeconds;
602 $percent = ( $i + $processedSeconds / $totalSeconds )
603 / $this->shards * 100;
604 }
605 $percent = ( $percent / $this->numServers )
606 + ( $serverIndex / $this->numServers * 100 );
607 call_user_func( $progressCallback, $percent );
608 }
609 }
610 }
611 } catch ( DBError $e ) {
612 $this->handleWriteError( $e, $serverIndex );
613 return false;
614 }
615 }
616 return true;
617 }
618
619 /**
620 * Delete content of shard tables in every server.
621 * Return true if the operation is successful, false otherwise.
622 * @return bool
623 */
624 public function deleteAll() {
625 for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) {
626 try {
627 $db = $this->getDB( $serverIndex );
628 for ( $i = 0; $i < $this->shards; $i++ ) {
629 $db->delete( $this->getTableNameByShard( $i ), '*', __METHOD__ );
630 }
631 } catch ( DBError $e ) {
632 $this->handleWriteError( $e, $serverIndex );
633 return false;
634 }
635 }
636 return true;
637 }
638
639 /**
640 * Serialize an object and, if possible, compress the representation.
641 * On typical message and page data, this can provide a 3X decrease
642 * in storage requirements.
643 *
644 * @param mixed $data
645 * @return string
646 */
647 protected function serialize( &$data ) {
648 $serial = serialize( $data );
649
650 if ( function_exists( 'gzdeflate' ) ) {
651 return gzdeflate( $serial );
652 } else {
653 return $serial;
654 }
655 }
656
657 /**
658 * Unserialize and, if necessary, decompress an object.
659 * @param string $serial
660 * @return mixed
661 */
662 protected function unserialize( $serial ) {
663 if ( function_exists( 'gzinflate' ) ) {
664 MediaWiki\suppressWarnings();
665 $decomp = gzinflate( $serial );
666 MediaWiki\restoreWarnings();
667
668 if ( false !== $decomp ) {
669 $serial = $decomp;
670 }
671 }
672
673 $ret = unserialize( $serial );
674
675 return $ret;
676 }
677
678 /**
679 * Handle a DBError which occurred during a read operation.
680 *
681 * @param DBError $exception
682 * @param int $serverIndex
683 */
684 protected function handleReadError( DBError $exception, $serverIndex ) {
685 if ( $exception instanceof DBConnectionError ) {
686 $this->markServerDown( $exception, $serverIndex );
687 }
688 $this->logger->error( "DBError: {$exception->getMessage()}" );
689 if ( $exception instanceof DBConnectionError ) {
690 $this->setLastError( BagOStuff::ERR_UNREACHABLE );
691 $this->logger->debug( __METHOD__ . ": ignoring connection error" );
692 } else {
693 $this->setLastError( BagOStuff::ERR_UNEXPECTED );
694 $this->logger->debug( __METHOD__ . ": ignoring query error" );
695 }
696 }
697
698 /**
699 * Handle a DBQueryError which occurred during a write operation.
700 *
701 * @param DBError $exception
702 * @param int $serverIndex
703 */
704 protected function handleWriteError( DBError $exception, $serverIndex ) {
705 if ( $exception instanceof DBConnectionError ) {
706 $this->markServerDown( $exception, $serverIndex );
707 }
708 if ( $exception->db && $exception->db->wasReadOnlyError() ) {
709 if ( $exception->db->trxLevel() ) {
710 try {
711 $exception->db->rollback( __METHOD__ );
712 } catch ( DBError $e ) {
713 }
714 }
715 }
716
717 $this->logger->error( "DBError: {$exception->getMessage()}" );
718 if ( $exception instanceof DBConnectionError ) {
719 $this->setLastError( BagOStuff::ERR_UNREACHABLE );
720 $this->logger->debug( __METHOD__ . ": ignoring connection error" );
721 } else {
722 $this->setLastError( BagOStuff::ERR_UNEXPECTED );
723 $this->logger->debug( __METHOD__ . ": ignoring query error" );
724 }
725 }
726
727 /**
728 * Mark a server down due to a DBConnectionError exception
729 *
730 * @param DBError $exception
731 * @param int $serverIndex
732 */
733 protected function markServerDown( $exception, $serverIndex ) {
734 unset( $this->conns[$serverIndex] ); // bug T103435
735
736 if ( isset( $this->connFailureTimes[$serverIndex] ) ) {
737 if ( time() - $this->connFailureTimes[$serverIndex] >= 60 ) {
738 unset( $this->connFailureTimes[$serverIndex] );
739 unset( $this->connFailureErrors[$serverIndex] );
740 } else {
741 $this->logger->debug( __METHOD__ . ": Server #$serverIndex already down" );
742 return;
743 }
744 }
745 $now = time();
746 $this->logger->info( __METHOD__ . ": Server #$serverIndex down until " . ( $now + 60 ) );
747 $this->connFailureTimes[$serverIndex] = $now;
748 $this->connFailureErrors[$serverIndex] = $exception;
749 }
750
751 /**
752 * Create shard tables. For use from eval.php.
753 */
754 public function createTables() {
755 for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) {
756 $db = $this->getDB( $serverIndex );
757 if ( $db->getType() !== 'mysql' ) {
758 throw new MWException( __METHOD__ . ' is not supported on this DB server' );
759 }
760
761 for ( $i = 0; $i < $this->shards; $i++ ) {
762 $db->query(
763 'CREATE TABLE ' . $db->tableName( $this->getTableNameByShard( $i ) ) .
764 ' LIKE ' . $db->tableName( 'objectcache' ),
765 __METHOD__ );
766 }
767 }
768 }
769 }