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