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