Cleanups to DatabaseMysqlBase
[lhc/web/wiklou.git] / includes / libs / rdbms / lbfactory / LBFactory.php
1 <?php
2 /**
3 * Generator and manager of database load balancing objects
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 Database
22 */
23
24 use Psr\Log\LoggerInterface;
25
26 /**
27 * An interface for generating database load balancers
28 * @ingroup Database
29 */
30 abstract class LBFactory {
31 /** @var ChronologyProtector */
32 protected $chronProt;
33 /** @var TransactionProfiler */
34 protected $trxProfiler;
35 /** @var LoggerInterface */
36 protected $replLogger;
37 /** @var LoggerInterface */
38 protected $connLogger;
39 /** @var LoggerInterface */
40 protected $queryLogger;
41 /** @var LoggerInterface */
42 protected $perfLogger;
43 /** @var callable Error logger */
44 protected $errorLogger;
45 /** @var BagOStuff */
46 protected $srvCache;
47 /** @var BagOStuff */
48 protected $memCache;
49 /** @var WANObjectCache */
50 protected $wanCache;
51
52 /** @var string Local domain */
53 protected $localDomain;
54 /** @var string Local hostname of the app server */
55 protected $hostname;
56 /** @var mixed */
57 protected $ticket;
58 /** @var string|bool String if a requested DBO_TRX transaction round is active */
59 protected $trxRoundId = false;
60 /** @var string|bool Reason all LBs are read-only or false if not */
61 protected $readOnlyReason = false;
62 /** @var callable[] */
63 protected $replicationWaitCallbacks = [];
64
65 /** @var bool Whether this PHP instance is for a CLI script */
66 protected $cliMode;
67 /** @var string Agent name for query profiling */
68 protected $agent;
69
70 const SHUTDOWN_NO_CHRONPROT = 0; // don't save DB positions at all
71 const SHUTDOWN_CHRONPROT_ASYNC = 1; // save DB positions, but don't wait on remote DCs
72 const SHUTDOWN_CHRONPROT_SYNC = 2; // save DB positions, waiting on all DCs
73
74 private static $loggerFields =
75 [ 'replLogger', 'connLogger', 'queryLogger', 'perfLogger' ];
76
77 /**
78 * @TODO: document base params here
79 * @param array $conf
80 */
81 public function __construct( array $conf ) {
82 $this->localDomain = isset( $conf['localDomain'] ) ? $conf['localDomain'] : '';
83
84 if ( isset( $conf['readOnlyReason'] ) && is_string( $conf['readOnlyReason'] ) ) {
85 $this->readOnlyReason = $conf['readOnlyReason'];
86 }
87
88 $this->srvCache = isset( $conf['srvCache'] ) ? $conf['srvCache'] : new EmptyBagOStuff();
89 $this->memCache = isset( $conf['memCache'] ) ? $conf['memCache'] : new EmptyBagOStuff();
90 $this->wanCache = isset( $conf['wanCache'] )
91 ? $conf['wanCache']
92 : WANObjectCache::newEmpty();
93
94 foreach ( self::$loggerFields as $key ) {
95 $this->$key = isset( $conf[$key] ) ? $conf[$key] : new \Psr\Log\NullLogger();
96 }
97 $this->errorLogger = isset( $conf['errorLogger'] )
98 ? $conf['errorLogger']
99 : function ( Exception $e ) {
100 trigger_error( E_WARNING, get_class( $e ) . ': ' . $e->getMessage() );
101 };
102 $this->hostname = isset( $conf['hostname'] )
103 ? $conf['hostname']
104 : gethostname();
105
106 $this->chronProt = isset( $conf['chronProt'] )
107 ? $conf['chronProt']
108 : $this->newChronologyProtector();
109 $this->trxProfiler = isset( $conf['trxProfiler'] )
110 ? $conf['trxProfiler']
111 : new TransactionProfiler();
112
113 $this->ticket = mt_rand();
114 $this->cliMode = isset( $params['cliMode'] ) ? $params['cliMode'] : PHP_SAPI === 'cli';
115 $this->agent = isset( $params['agent'] ) ? $params['agent'] : '';
116 }
117
118 /**
119 * Disables all load balancers. All connections are closed, and any attempt to
120 * open a new connection will result in a DBAccessError.
121 * @see LoadBalancer::disable()
122 */
123 public function destroy() {
124 $this->shutdown( self::SHUTDOWN_NO_CHRONPROT );
125 $this->forEachLBCallMethod( 'disable' );
126 }
127
128 /**
129 * Create a new load balancer object. The resulting object will be untracked,
130 * not chronology-protected, and the caller is responsible for cleaning it up.
131 *
132 * @param bool|string $domain Wiki ID, or false for the current wiki
133 * @return ILoadBalancer
134 */
135 abstract public function newMainLB( $domain = false );
136
137 /**
138 * Get a cached (tracked) load balancer object.
139 *
140 * @param bool|string $domain Wiki ID, or false for the current wiki
141 * @return ILoadBalancer
142 */
143 abstract public function getMainLB( $domain = false );
144
145 /**
146 * Create a new load balancer for external storage. The resulting object will be
147 * untracked, not chronology-protected, and the caller is responsible for
148 * cleaning it up.
149 *
150 * @param string $cluster External storage cluster, or false for core
151 * @param bool|string $domain Wiki ID, or false for the current wiki
152 * @return ILoadBalancer
153 */
154 abstract protected function newExternalLB( $cluster, $domain = false );
155
156 /**
157 * Get a cached (tracked) load balancer for external storage
158 *
159 * @param string $cluster External storage cluster, or false for core
160 * @param bool|string $domain Wiki ID, or false for the current wiki
161 * @return ILoadBalancer
162 */
163 abstract public function getExternalLB( $cluster, $domain = false );
164
165 /**
166 * Execute a function for each tracked load balancer
167 * The callback is called with the load balancer as the first parameter,
168 * and $params passed as the subsequent parameters.
169 *
170 * @param callable $callback
171 * @param array $params
172 */
173 abstract public function forEachLB( $callback, array $params = [] );
174
175 /**
176 * Prepare all tracked load balancers for shutdown
177 * @param integer $mode One of the class SHUTDOWN_* constants
178 * @param callable|null $workCallback Work to mask ChronologyProtector writes
179 */
180 public function shutdown(
181 $mode = self::SHUTDOWN_CHRONPROT_SYNC, callable $workCallback = null
182 ) {
183 if ( $mode === self::SHUTDOWN_CHRONPROT_SYNC ) {
184 $this->shutdownChronologyProtector( $this->chronProt, $workCallback, 'sync' );
185 } elseif ( $mode === self::SHUTDOWN_CHRONPROT_ASYNC ) {
186 $this->shutdownChronologyProtector( $this->chronProt, null, 'async' );
187 }
188
189 $this->commitMasterChanges( __METHOD__ ); // sanity
190 }
191
192 /**
193 * Call a method of each tracked load balancer
194 *
195 * @param string $methodName
196 * @param array $args
197 */
198 protected function forEachLBCallMethod( $methodName, array $args = [] ) {
199 $this->forEachLB(
200 function ( ILoadBalancer $loadBalancer, $methodName, array $args ) {
201 call_user_func_array( [ $loadBalancer, $methodName ], $args );
202 },
203 [ $methodName, $args ]
204 );
205 }
206
207 /**
208 * Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshot
209 *
210 * @param string $fname Caller name
211 * @since 1.28
212 */
213 public function flushReplicaSnapshots( $fname = __METHOD__ ) {
214 $this->forEachLBCallMethod( 'flushReplicaSnapshots', [ $fname ] );
215 }
216
217 /**
218 * Commit on all connections. Done for two reasons:
219 * 1. To commit changes to the masters.
220 * 2. To release the snapshot on all connections, master and replica DB.
221 * @param string $fname Caller name
222 * @param array $options Options map:
223 * - maxWriteDuration: abort if more than this much time was spent in write queries
224 */
225 public function commitAll( $fname = __METHOD__, array $options = [] ) {
226 $this->commitMasterChanges( $fname, $options );
227 $this->forEachLBCallMethod( 'commitAll', [ $fname ] );
228 }
229
230 /**
231 * Flush any master transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set)
232 *
233 * The DBO_TRX setting will be reverted to the default in each of these methods:
234 * - commitMasterChanges()
235 * - rollbackMasterChanges()
236 * - commitAll()
237 *
238 * This allows for custom transaction rounds from any outer transaction scope.
239 *
240 * @param string $fname
241 * @throws DBTransactionError
242 * @since 1.28
243 */
244 public function beginMasterChanges( $fname = __METHOD__ ) {
245 if ( $this->trxRoundId !== false ) {
246 throw new DBTransactionError(
247 null,
248 "$fname: transaction round '{$this->trxRoundId}' already started."
249 );
250 }
251 $this->trxRoundId = $fname;
252 // Set DBO_TRX flags on all appropriate DBs
253 $this->forEachLBCallMethod( 'beginMasterChanges', [ $fname ] );
254 }
255
256 /**
257 * Commit changes on all master connections
258 * @param string $fname Caller name
259 * @param array $options Options map:
260 * - maxWriteDuration: abort if more than this much time was spent in write queries
261 * @throws Exception
262 */
263 public function commitMasterChanges( $fname = __METHOD__, array $options = [] ) {
264 if ( $this->trxRoundId !== false && $this->trxRoundId !== $fname ) {
265 throw new DBTransactionError(
266 null,
267 "$fname: transaction round '{$this->trxRoundId}' still running."
268 );
269 }
270 // Run pre-commit callbacks and suppress post-commit callbacks, aborting on failure
271 $this->forEachLBCallMethod( 'finalizeMasterChanges' );
272 $this->trxRoundId = false;
273 // Perform pre-commit checks, aborting on failure
274 $this->forEachLBCallMethod( 'approveMasterChanges', [ $options ] );
275 // Log the DBs and methods involved in multi-DB transactions
276 $this->logIfMultiDbTransaction();
277 // Actually perform the commit on all master DB connections and revert DBO_TRX
278 $this->forEachLBCallMethod( 'commitMasterChanges', [ $fname ] );
279 // Run all post-commit callbacks
280 /** @var Exception $e */
281 $e = null; // first callback exception
282 $this->forEachLB( function ( ILoadBalancer $lb ) use ( &$e ) {
283 $ex = $lb->runMasterPostTrxCallbacks( IDatabase::TRIGGER_COMMIT );
284 $e = $e ?: $ex;
285 } );
286 // Commit any dangling DBO_TRX transactions from callbacks on one DB to another DB
287 $this->forEachLBCallMethod( 'commitMasterChanges', [ $fname ] );
288 // Throw any last post-commit callback error
289 if ( $e instanceof Exception ) {
290 throw $e;
291 }
292 }
293
294 /**
295 * Rollback changes on all master connections
296 * @param string $fname Caller name
297 * @since 1.23
298 */
299 public function rollbackMasterChanges( $fname = __METHOD__ ) {
300 $this->trxRoundId = false;
301 $this->forEachLBCallMethod( 'suppressTransactionEndCallbacks' );
302 $this->forEachLBCallMethod( 'rollbackMasterChanges', [ $fname ] );
303 // Run all post-rollback callbacks
304 $this->forEachLB( function ( ILoadBalancer $lb ) {
305 $lb->runMasterPostTrxCallbacks( IDatabase::TRIGGER_ROLLBACK );
306 } );
307 }
308
309 /**
310 * Log query info if multi DB transactions are going to be committed now
311 */
312 private function logIfMultiDbTransaction() {
313 $callersByDB = [];
314 $this->forEachLB( function ( ILoadBalancer $lb ) use ( &$callersByDB ) {
315 $masterName = $lb->getServerName( $lb->getWriterIndex() );
316 $callers = $lb->pendingMasterChangeCallers();
317 if ( $callers ) {
318 $callersByDB[$masterName] = $callers;
319 }
320 } );
321
322 if ( count( $callersByDB ) >= 2 ) {
323 $dbs = implode( ', ', array_keys( $callersByDB ) );
324 $msg = "Multi-DB transaction [{$dbs}]:\n";
325 foreach ( $callersByDB as $db => $callers ) {
326 $msg .= "$db: " . implode( '; ', $callers ) . "\n";
327 }
328 $this->queryLogger->info( $msg );
329 }
330 }
331
332 /**
333 * Determine if any master connection has pending changes
334 * @return bool
335 * @since 1.23
336 */
337 public function hasMasterChanges() {
338 $ret = false;
339 $this->forEachLB( function ( ILoadBalancer $lb ) use ( &$ret ) {
340 $ret = $ret || $lb->hasMasterChanges();
341 } );
342
343 return $ret;
344 }
345
346 /**
347 * Detemine if any lagged replica DB connection was used
348 * @return bool
349 * @since 1.28
350 */
351 public function laggedReplicaUsed() {
352 $ret = false;
353 $this->forEachLB( function ( ILoadBalancer $lb ) use ( &$ret ) {
354 $ret = $ret || $lb->laggedReplicaUsed();
355 } );
356
357 return $ret;
358 }
359
360 /**
361 * Determine if any master connection has pending/written changes from this request
362 * @param float $age How many seconds ago is "recent" [defaults to LB lag wait timeout]
363 * @return bool
364 * @since 1.27
365 */
366 public function hasOrMadeRecentMasterChanges( $age = null ) {
367 $ret = false;
368 $this->forEachLB( function ( ILoadBalancer $lb ) use ( $age, &$ret ) {
369 $ret = $ret || $lb->hasOrMadeRecentMasterChanges( $age );
370 } );
371 return $ret;
372 }
373
374 /**
375 * Waits for the replica DBs to catch up to the current master position
376 *
377 * Use this when updating very large numbers of rows, as in maintenance scripts,
378 * to avoid causing too much lag. Of course, this is a no-op if there are no replica DBs.
379 *
380 * By default this waits on all DB clusters actually used in this request.
381 * This makes sense when lag being waiting on is caused by the code that does this check.
382 * In that case, setting "ifWritesSince" can avoid the overhead of waiting for clusters
383 * that were not changed since the last wait check. To forcefully wait on a specific cluster
384 * for a given wiki, use the 'wiki' parameter. To forcefully wait on an "external" cluster,
385 * use the "cluster" parameter.
386 *
387 * Never call this function after a large DB write that is *still* in a transaction.
388 * It only makes sense to call this after the possible lag inducing changes were committed.
389 *
390 * @param array $opts Optional fields that include:
391 * - wiki : wait on the load balancer DBs that handles the given wiki
392 * - cluster : wait on the given external load balancer DBs
393 * - timeout : Max wait time. Default: ~60 seconds
394 * - ifWritesSince: Only wait if writes were done since this UNIX timestamp
395 * @throws DBReplicationWaitError If a timeout or error occured waiting on a DB cluster
396 * @since 1.27
397 */
398 public function waitForReplication( array $opts = [] ) {
399 $opts += [
400 'wiki' => false,
401 'cluster' => false,
402 'timeout' => 60,
403 'ifWritesSince' => null
404 ];
405
406 // Figure out which clusters need to be checked
407 /** @var ILoadBalancer[] $lbs */
408 $lbs = [];
409 if ( $opts['cluster'] !== false ) {
410 $lbs[] = $this->getExternalLB( $opts['cluster'] );
411 } elseif ( $opts['wiki'] !== false ) {
412 $lbs[] = $this->getMainLB( $opts['wiki'] );
413 } else {
414 $this->forEachLB( function ( ILoadBalancer $lb ) use ( &$lbs ) {
415 $lbs[] = $lb;
416 } );
417 if ( !$lbs ) {
418 return; // nothing actually used
419 }
420 }
421
422 // Get all the master positions of applicable DBs right now.
423 // This can be faster since waiting on one cluster reduces the
424 // time needed to wait on the next clusters.
425 $masterPositions = array_fill( 0, count( $lbs ), false );
426 foreach ( $lbs as $i => $lb ) {
427 if ( $lb->getServerCount() <= 1 ) {
428 // Bug 27975 - Don't try to wait for replica DBs if there are none
429 // Prevents permission error when getting master position
430 continue;
431 } elseif ( $opts['ifWritesSince']
432 && $lb->lastMasterChangeTimestamp() < $opts['ifWritesSince']
433 ) {
434 continue; // no writes since the last wait
435 }
436 $masterPositions[$i] = $lb->getMasterPos();
437 }
438
439 // Run any listener callbacks *after* getting the DB positions. The more
440 // time spent in the callbacks, the less time is spent in waitForAll().
441 foreach ( $this->replicationWaitCallbacks as $callback ) {
442 $callback();
443 }
444
445 $failed = [];
446 foreach ( $lbs as $i => $lb ) {
447 if ( $masterPositions[$i] ) {
448 // The DBMS may not support getMasterPos()
449 if ( !$lb->waitForAll( $masterPositions[$i], $opts['timeout'] ) ) {
450 $failed[] = $lb->getServerName( $lb->getWriterIndex() );
451 }
452 }
453 }
454
455 if ( $failed ) {
456 throw new DBReplicationWaitError(
457 "Could not wait for replica DBs to catch up to " .
458 implode( ', ', $failed )
459 );
460 }
461 }
462
463 /**
464 * Add a callback to be run in every call to waitForReplication() before waiting
465 *
466 * Callbacks must clear any transactions that they start
467 *
468 * @param string $name Callback name
469 * @param callable|null $callback Use null to unset a callback
470 * @since 1.28
471 */
472 public function setWaitForReplicationListener( $name, callable $callback = null ) {
473 if ( $callback ) {
474 $this->replicationWaitCallbacks[$name] = $callback;
475 } else {
476 unset( $this->replicationWaitCallbacks[$name] );
477 }
478 }
479
480 /**
481 * Get a token asserting that no transaction writes are active
482 *
483 * @param string $fname Caller name (e.g. __METHOD__)
484 * @return mixed A value to pass to commitAndWaitForReplication()
485 * @since 1.28
486 */
487 public function getEmptyTransactionTicket( $fname ) {
488 if ( $this->hasMasterChanges() ) {
489 $this->queryLogger->error( __METHOD__ . ": $fname does not have outer scope." );
490 return null;
491 }
492
493 return $this->ticket;
494 }
495
496 /**
497 * Convenience method for safely running commitMasterChanges()/waitForReplication()
498 *
499 * This will commit and wait unless $ticket indicates it is unsafe to do so
500 *
501 * @param string $fname Caller name (e.g. __METHOD__)
502 * @param mixed $ticket Result of getEmptyTransactionTicket()
503 * @param array $opts Options to waitForReplication()
504 * @throws DBReplicationWaitError
505 * @since 1.28
506 */
507 public function commitAndWaitForReplication( $fname, $ticket, array $opts = [] ) {
508 if ( $ticket !== $this->ticket ) {
509 $this->perfLogger->error( __METHOD__ . ": $fname does not have outer scope." );
510 return;
511 }
512
513 // The transaction owner and any caller with the empty transaction ticket can commit
514 // so that getEmptyTransactionTicket() callers don't risk seeing DBTransactionError.
515 if ( $this->trxRoundId !== false && $fname !== $this->trxRoundId ) {
516 $this->queryLogger->info( "$fname: committing on behalf of {$this->trxRoundId}." );
517 $fnameEffective = $this->trxRoundId;
518 } else {
519 $fnameEffective = $fname;
520 }
521
522 $this->commitMasterChanges( $fnameEffective );
523 $this->waitForReplication( $opts );
524 // If a nested caller committed on behalf of $fname, start another empty $fname
525 // transaction, leaving the caller with the same empty transaction state as before.
526 if ( $fnameEffective !== $fname ) {
527 $this->beginMasterChanges( $fnameEffective );
528 }
529 }
530
531 /**
532 * @param string $dbName DB master name (e.g. "db1052")
533 * @return float|bool UNIX timestamp when client last touched the DB or false if not recent
534 * @since 1.28
535 */
536 public function getChronologyProtectorTouched( $dbName ) {
537 return $this->chronProt->getTouched( $dbName );
538 }
539
540 /**
541 * Disable the ChronologyProtector for all load balancers
542 *
543 * This can be called at the start of special API entry points
544 *
545 * @since 1.27
546 */
547 public function disableChronologyProtection() {
548 $this->chronProt->setEnabled( false );
549 }
550
551 /**
552 * @return ChronologyProtector
553 */
554 protected function newChronologyProtector() {
555 $chronProt = new ChronologyProtector(
556 $this->memCache,
557 [
558 'ip' => isset( $_SERVER[ 'REMOTE_ADDR' ] ) ? $_SERVER[ 'REMOTE_ADDR' ] : '',
559 'agent' => isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : ''
560 ],
561 isset( $_GET['cpPosTime'] ) ? $_GET['cpPosTime'] : null
562 );
563 $chronProt->setLogger( $this->replLogger );
564 if ( $this->cliMode ) {
565 $chronProt->setEnabled( false );
566 }
567
568 return $chronProt;
569 }
570
571 /**
572 * Get and record all of the staged DB positions into persistent memory storage
573 *
574 * @param ChronologyProtector $cp
575 * @param callable|null $workCallback Work to do instead of waiting on syncing positions
576 * @param string $mode One of (sync, async); whether to wait on remote datacenters
577 */
578 protected function shutdownChronologyProtector(
579 ChronologyProtector $cp, $workCallback, $mode
580 ) {
581 // Record all the master positions needed
582 $this->forEachLB( function ( ILoadBalancer $lb ) use ( $cp ) {
583 $cp->shutdownLB( $lb );
584 } );
585 // Write them to the persistent stash. Try to do something useful by running $work
586 // while ChronologyProtector waits for the stash write to replicate to all DCs.
587 $unsavedPositions = $cp->shutdown( $workCallback, $mode );
588 if ( $unsavedPositions && $workCallback ) {
589 // Invoke callback in case it did not cache the result yet
590 $workCallback(); // work now to block for less time in waitForAll()
591 }
592 // If the positions failed to write to the stash, at least wait on local datacenter
593 // replica DBs to catch up before responding. Even if there are several DCs, this increases
594 // the chance that the user will see their own changes immediately afterwards. As long
595 // as the sticky DC cookie applies (same domain), this is not even an issue.
596 $this->forEachLB( function ( ILoadBalancer $lb ) use ( $unsavedPositions ) {
597 $masterName = $lb->getServerName( $lb->getWriterIndex() );
598 if ( isset( $unsavedPositions[$masterName] ) ) {
599 $lb->waitForAll( $unsavedPositions[$masterName] );
600 }
601 } );
602 }
603
604 /**
605 * Base parameters to LoadBalancer::__construct()
606 * @return array
607 */
608 final protected function baseLoadBalancerParams() {
609 return [
610 'localDomain' => $this->localDomain,
611 'readOnlyReason' => $this->readOnlyReason,
612 'srvCache' => $this->srvCache,
613 'wanCache' => $this->wanCache,
614 'trxProfiler' => $this->trxProfiler,
615 'queryLogger' => $this->queryLogger,
616 'connLogger' => $this->connLogger,
617 'replLogger' => $this->replLogger,
618 'errorLogger' => $this->errorLogger,
619 'hostname' => $this->hostname,
620 'cliMode' => $this->cliMode,
621 'agent' => $this->agent
622 ];
623 }
624
625 /**
626 * @param ILoadBalancer $lb
627 */
628 protected function initLoadBalancer( ILoadBalancer $lb ) {
629 if ( $this->trxRoundId !== false ) {
630 $lb->beginMasterChanges( $this->trxRoundId ); // set DBO_TRX
631 }
632 }
633
634 /**
635 * Set a new table prefix for the existing local domain ID for testing
636 *
637 * @param string $prefix
638 * @since 1.28
639 */
640 public function setDomainPrefix( $prefix ) {
641 list( $dbName, ) = explode( '-', $this->localDomain, 2 );
642 $this->localDomain = "{$dbName}-{$prefix}";
643
644 $this->forEachLB( function( LoadBalancer $lb ) use ( $prefix ) {
645 $lb->setDomainPrefix( $prefix );
646 } );
647 }
648
649 /**
650 * Close all open database connections on all open load balancers.
651 * @since 1.28
652 */
653 public function closeAll() {
654 $this->forEachLBCallMethod( 'closeAll', [] );
655 }
656
657 /**
658 * @param string $agent Agent name for query profiling
659 * @since 1.28
660 */
661 public function setAgentName( $agent ) {
662 $this->agent = $agent;
663 }
664 }