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