Make DeferredUpdates avoid running during LBFactory::commitMasterChanges
[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 namespace Wikimedia\Rdbms;
25
26 use Psr\Log\LoggerInterface;
27 use Wikimedia\ScopedCallback;
28 use BagOStuff;
29 use EmptyBagOStuff;
30 use WANObjectCache;
31 use Exception;
32 use RuntimeException;
33 use LogicException;
34
35 /**
36 * An interface for generating database load balancers
37 * @ingroup Database
38 */
39 abstract class LBFactory implements ILBFactory {
40 /** @var ChronologyProtector */
41 protected $chronProt;
42 /** @var object|string Class name or object With profileIn/profileOut methods */
43 protected $profiler;
44 /** @var TransactionProfiler */
45 protected $trxProfiler;
46 /** @var LoggerInterface */
47 protected $replLogger;
48 /** @var LoggerInterface */
49 protected $connLogger;
50 /** @var LoggerInterface */
51 protected $queryLogger;
52 /** @var LoggerInterface */
53 protected $perfLogger;
54 /** @var callable Error logger */
55 protected $errorLogger;
56 /** @var callable Deprecation logger */
57 protected $deprecationLogger;
58 /** @var BagOStuff */
59 protected $srvCache;
60 /** @var BagOStuff */
61 protected $memStash;
62 /** @var WANObjectCache */
63 protected $wanCache;
64
65 /** @var DatabaseDomain Local domain */
66 protected $localDomain;
67 /** @var string Local hostname of the app server */
68 protected $hostname;
69 /** @var array Web request information about the client */
70 protected $requestInfo;
71
72 /** @var mixed */
73 protected $ticket;
74 /** @var string|bool String if a requested DBO_TRX transaction round is active */
75 protected $trxRoundId = false;
76 /** @var string|bool Reason all LBs are read-only or false if not */
77 protected $readOnlyReason = false;
78 /** @var callable[] */
79 protected $replicationWaitCallbacks = [];
80
81 /** @var array[] $aliases Map of (table => (dbname, schema, prefix) map) */
82 protected $tableAliases = [];
83 /** @var string[] Map of (index alias => index) */
84 protected $indexAliases = [];
85
86 /** @var bool Whether this PHP instance is for a CLI script */
87 protected $cliMode;
88 /** @var string Agent name for query profiling */
89 protected $agent;
90
91 /** @var string One of the ROUND_* class constants */
92 private $trxRoundStage = self::ROUND_CURSORY;
93
94 const ROUND_CURSORY = 'cursory';
95 const ROUND_BEGINNING = 'within-begin';
96 const ROUND_COMMITTING = 'within-commit';
97 const ROUND_ROLLING_BACK = 'within-rollback';
98
99 private static $loggerFields =
100 [ 'replLogger', 'connLogger', 'queryLogger', 'perfLogger' ];
101
102 public function __construct( array $conf ) {
103 $this->localDomain = isset( $conf['localDomain'] )
104 ? DatabaseDomain::newFromId( $conf['localDomain'] )
105 : DatabaseDomain::newUnspecified();
106
107 if ( isset( $conf['readOnlyReason'] ) && is_string( $conf['readOnlyReason'] ) ) {
108 $this->readOnlyReason = $conf['readOnlyReason'];
109 }
110
111 $this->srvCache = isset( $conf['srvCache'] ) ? $conf['srvCache'] : new EmptyBagOStuff();
112 $this->memStash = isset( $conf['memStash'] ) ? $conf['memStash'] : new EmptyBagOStuff();
113 $this->wanCache = isset( $conf['wanCache'] )
114 ? $conf['wanCache']
115 : WANObjectCache::newEmpty();
116
117 foreach ( self::$loggerFields as $key ) {
118 $this->$key = isset( $conf[$key] ) ? $conf[$key] : new \Psr\Log\NullLogger();
119 }
120 $this->errorLogger = isset( $conf['errorLogger'] )
121 ? $conf['errorLogger']
122 : function ( Exception $e ) {
123 trigger_error( get_class( $e ) . ': ' . $e->getMessage(), E_USER_WARNING );
124 };
125 $this->deprecationLogger = isset( $conf['deprecationLogger'] )
126 ? $conf['deprecationLogger']
127 : function ( $msg ) {
128 trigger_error( $msg, E_USER_DEPRECATED );
129 };
130
131 $this->profiler = isset( $conf['profiler'] ) ? $conf['profiler'] : null;
132 $this->trxProfiler = isset( $conf['trxProfiler'] )
133 ? $conf['trxProfiler']
134 : new TransactionProfiler();
135
136 $this->requestInfo = [
137 'IPAddress' => isset( $_SERVER[ 'REMOTE_ADDR' ] ) ? $_SERVER[ 'REMOTE_ADDR' ] : '',
138 'UserAgent' => isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '',
139 'ChronologyProtection' => 'true',
140 'ChronologyPositionIndex' => isset( $_GET['cpPosIndex'] ) ? $_GET['cpPosIndex'] : null
141 ];
142
143 $this->cliMode = isset( $conf['cliMode'] )
144 ? $conf['cliMode']
145 : ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' );
146 $this->hostname = isset( $conf['hostname'] ) ? $conf['hostname'] : gethostname();
147 $this->agent = isset( $conf['agent'] ) ? $conf['agent'] : '';
148
149 $this->ticket = mt_rand();
150 }
151
152 public function destroy() {
153 $this->shutdown( self::SHUTDOWN_NO_CHRONPROT );
154 $this->forEachLBCallMethod( 'disable' );
155 }
156
157 public function shutdown(
158 $mode = self::SHUTDOWN_CHRONPROT_SYNC, callable $workCallback = null, &$cpIndex = null
159 ) {
160 $chronProt = $this->getChronologyProtector();
161 if ( $mode === self::SHUTDOWN_CHRONPROT_SYNC ) {
162 $this->shutdownChronologyProtector( $chronProt, $workCallback, 'sync', $cpIndex );
163 } elseif ( $mode === self::SHUTDOWN_CHRONPROT_ASYNC ) {
164 $this->shutdownChronologyProtector( $chronProt, null, 'async', $cpIndex );
165 }
166
167 $this->commitMasterChanges( __METHOD__ ); // sanity
168 }
169
170 /**
171 * @see ILBFactory::newMainLB()
172 * @param bool $domain
173 * @return LoadBalancer
174 */
175 abstract public function newMainLB( $domain = false );
176
177 /**
178 * @see ILBFactory::getMainLB()
179 * @param bool $domain
180 * @return LoadBalancer
181 */
182 abstract public function getMainLB( $domain = false );
183
184 /**
185 * @see ILBFactory::newExternalLB()
186 * @param string $cluster
187 * @return LoadBalancer
188 */
189 abstract public function newExternalLB( $cluster );
190
191 /**
192 * @see ILBFactory::getExternalLB()
193 * @param string $cluster
194 * @return LoadBalancer
195 */
196 abstract public function getExternalLB( $cluster );
197
198 /**
199 * Call a method of each tracked load balancer
200 *
201 * @param string $methodName
202 * @param array $args
203 */
204 protected function forEachLBCallMethod( $methodName, array $args = [] ) {
205 $this->forEachLB(
206 function ( ILoadBalancer $loadBalancer, $methodName, array $args ) {
207 call_user_func_array( [ $loadBalancer, $methodName ], $args );
208 },
209 [ $methodName, $args ]
210 );
211 }
212
213 public function flushReplicaSnapshots( $fname = __METHOD__ ) {
214 $this->forEachLBCallMethod( 'flushReplicaSnapshots', [ $fname ] );
215 }
216
217 final public function commitAll( $fname = __METHOD__, array $options = [] ) {
218 $this->commitMasterChanges( $fname, $options );
219 $this->forEachLBCallMethod( 'commitAll', [ $fname ] );
220 }
221
222 final public function beginMasterChanges( $fname = __METHOD__ ) {
223 $this->assertTransactionRoundStage( self::ROUND_CURSORY );
224 $this->trxRoundStage = self::ROUND_BEGINNING;
225 if ( $this->trxRoundId !== false ) {
226 throw new DBTransactionError(
227 null,
228 "$fname: transaction round '{$this->trxRoundId}' already started."
229 );
230 }
231 $this->trxRoundId = $fname;
232 // Set DBO_TRX flags on all appropriate DBs
233 $this->forEachLBCallMethod( 'beginMasterChanges', [ $fname ] );
234 $this->trxRoundStage = self::ROUND_CURSORY;
235 }
236
237 final public function commitMasterChanges( $fname = __METHOD__, array $options = [] ) {
238 $this->assertTransactionRoundStage( self::ROUND_CURSORY );
239 $this->trxRoundStage = self::ROUND_COMMITTING;
240 if ( $this->trxRoundId !== false && $this->trxRoundId !== $fname ) {
241 throw new DBTransactionError(
242 null,
243 "$fname: transaction round '{$this->trxRoundId}' still running."
244 );
245 }
246 /** @noinspection PhpUnusedLocalVariableInspection */
247 $scope = $this->getScopedPHPBehaviorForCommit(); // try to ignore client aborts
248 // Run pre-commit callbacks and suppress post-commit callbacks, aborting on failure
249 $this->forEachLBCallMethod( 'finalizeMasterChanges' );
250 $this->trxRoundId = false;
251 // Perform pre-commit checks, aborting on failure
252 $this->forEachLBCallMethod( 'approveMasterChanges', [ $options ] );
253 // Log the DBs and methods involved in multi-DB transactions
254 $this->logIfMultiDbTransaction();
255 // Actually perform the commit on all master DB connections and revert DBO_TRX
256 $this->forEachLBCallMethod( 'commitMasterChanges', [ $fname ] );
257 // Run all post-commit callbacks until new ones stop getting added
258 $e = null; // first callback exception
259 do {
260 $this->forEachLB( function ( ILoadBalancer $lb ) use ( &$e ) {
261 $ex = $lb->runMasterTransactionIdleCallbacks();
262 $e = $e ?: $ex;
263 } );
264 } while ( $this->hasMasterChanges() );
265 // Run all listener callbacks once
266 $this->forEachLB( function ( ILoadBalancer $lb ) use ( &$e ) {
267 $ex = $lb->runMasterTransactionListenerCallbacks();
268 $e = $e ?: $ex;
269 } );
270 $this->trxRoundStage = self::ROUND_CURSORY;
271 // Throw any last post-commit callback error
272 if ( $e instanceof Exception ) {
273 throw $e;
274 }
275 }
276
277 final public function rollbackMasterChanges( $fname = __METHOD__ ) {
278 $this->trxRoundStage = self::ROUND_ROLLING_BACK;
279 $this->trxRoundId = false;
280 $this->forEachLBCallMethod( 'rollbackMasterChanges', [ $fname ] );
281 $this->forEachLBCallMethod( 'runMasterTransactionIdleCallbacks' );
282 $this->forEachLBCallMethod( 'runMasterTransactionListenerCallbacks' );
283 $this->trxRoundStage = self::ROUND_CURSORY;
284 }
285
286 public function hasTransactionRound() {
287 return ( $this->trxRoundId !== false );
288 }
289
290 public function isReadyForRoundOperations() {
291 return ( $this->trxRoundStage === self::ROUND_CURSORY );
292 }
293
294 /**
295 * Log query info if multi DB transactions are going to be committed now
296 */
297 private function logIfMultiDbTransaction() {
298 $callersByDB = [];
299 $this->forEachLB( function ( ILoadBalancer $lb ) use ( &$callersByDB ) {
300 $masterName = $lb->getServerName( $lb->getWriterIndex() );
301 $callers = $lb->pendingMasterChangeCallers();
302 if ( $callers ) {
303 $callersByDB[$masterName] = $callers;
304 }
305 } );
306
307 if ( count( $callersByDB ) >= 2 ) {
308 $dbs = implode( ', ', array_keys( $callersByDB ) );
309 $msg = "Multi-DB transaction [{$dbs}]:\n";
310 foreach ( $callersByDB as $db => $callers ) {
311 $msg .= "$db: " . implode( '; ', $callers ) . "\n";
312 }
313 $this->queryLogger->info( $msg );
314 }
315 }
316
317 public function hasMasterChanges() {
318 $ret = false;
319 $this->forEachLB( function ( ILoadBalancer $lb ) use ( &$ret ) {
320 $ret = $ret || $lb->hasMasterChanges();
321 } );
322
323 return $ret;
324 }
325
326 public function laggedReplicaUsed() {
327 $ret = false;
328 $this->forEachLB( function ( ILoadBalancer $lb ) use ( &$ret ) {
329 $ret = $ret || $lb->laggedReplicaUsed();
330 } );
331
332 return $ret;
333 }
334
335 public function hasOrMadeRecentMasterChanges( $age = null ) {
336 $ret = false;
337 $this->forEachLB( function ( ILoadBalancer $lb ) use ( $age, &$ret ) {
338 $ret = $ret || $lb->hasOrMadeRecentMasterChanges( $age );
339 } );
340 return $ret;
341 }
342
343 public function waitForReplication( array $opts = [] ) {
344 $opts += [
345 'domain' => false,
346 'cluster' => false,
347 'timeout' => $this->cliMode ? 60 : 10,
348 'ifWritesSince' => null
349 ];
350
351 if ( $opts['domain'] === false && isset( $opts['wiki'] ) ) {
352 $opts['domain'] = $opts['wiki']; // b/c
353 }
354
355 // Figure out which clusters need to be checked
356 /** @var ILoadBalancer[] $lbs */
357 $lbs = [];
358 if ( $opts['cluster'] !== false ) {
359 $lbs[] = $this->getExternalLB( $opts['cluster'] );
360 } elseif ( $opts['domain'] !== false ) {
361 $lbs[] = $this->getMainLB( $opts['domain'] );
362 } else {
363 $this->forEachLB( function ( ILoadBalancer $lb ) use ( &$lbs ) {
364 $lbs[] = $lb;
365 } );
366 if ( !$lbs ) {
367 return; // nothing actually used
368 }
369 }
370
371 // Get all the master positions of applicable DBs right now.
372 // This can be faster since waiting on one cluster reduces the
373 // time needed to wait on the next clusters.
374 $masterPositions = array_fill( 0, count( $lbs ), false );
375 foreach ( $lbs as $i => $lb ) {
376 if ( $lb->getServerCount() <= 1 ) {
377 // T29975 - Don't try to wait for replica DBs if there are none
378 // Prevents permission error when getting master position
379 continue;
380 } elseif ( $opts['ifWritesSince']
381 && $lb->lastMasterChangeTimestamp() < $opts['ifWritesSince']
382 ) {
383 continue; // no writes since the last wait
384 }
385 $masterPositions[$i] = $lb->getMasterPos();
386 }
387
388 // Run any listener callbacks *after* getting the DB positions. The more
389 // time spent in the callbacks, the less time is spent in waitForAll().
390 foreach ( $this->replicationWaitCallbacks as $callback ) {
391 $callback();
392 }
393
394 $failed = [];
395 foreach ( $lbs as $i => $lb ) {
396 if ( $masterPositions[$i] ) {
397 // The RDBMS may not support getMasterPos()
398 if ( !$lb->waitForAll( $masterPositions[$i], $opts['timeout'] ) ) {
399 $failed[] = $lb->getServerName( $lb->getWriterIndex() );
400 }
401 }
402 }
403
404 if ( $failed ) {
405 throw new DBReplicationWaitError(
406 null,
407 "Could not wait for replica DBs to catch up to " .
408 implode( ', ', $failed )
409 );
410 }
411 }
412
413 public function setWaitForReplicationListener( $name, callable $callback = null ) {
414 if ( $callback ) {
415 $this->replicationWaitCallbacks[$name] = $callback;
416 } else {
417 unset( $this->replicationWaitCallbacks[$name] );
418 }
419 }
420
421 public function getEmptyTransactionTicket( $fname ) {
422 if ( $this->hasMasterChanges() ) {
423 $this->queryLogger->error( __METHOD__ . ": $fname does not have outer scope.\n" .
424 ( new RuntimeException() )->getTraceAsString() );
425
426 return null;
427 }
428
429 return $this->ticket;
430 }
431
432 final public function commitAndWaitForReplication( $fname, $ticket, array $opts = [] ) {
433 if ( $ticket !== $this->ticket ) {
434 $this->perfLogger->error( __METHOD__ . ": $fname does not have outer scope.\n" .
435 ( new RuntimeException() )->getTraceAsString() );
436
437 return;
438 }
439
440 // The transaction owner and any caller with the empty transaction ticket can commit
441 // so that getEmptyTransactionTicket() callers don't risk seeing DBTransactionError.
442 if ( $this->trxRoundId !== false && $fname !== $this->trxRoundId ) {
443 $this->queryLogger->info( "$fname: committing on behalf of {$this->trxRoundId}." );
444 $fnameEffective = $this->trxRoundId;
445 } else {
446 $fnameEffective = $fname;
447 }
448
449 $this->commitMasterChanges( $fnameEffective );
450 $this->waitForReplication( $opts );
451 // If a nested caller committed on behalf of $fname, start another empty $fname
452 // transaction, leaving the caller with the same empty transaction state as before.
453 if ( $fnameEffective !== $fname ) {
454 $this->beginMasterChanges( $fnameEffective );
455 }
456 }
457
458 public function getChronologyProtectorTouched( $dbName ) {
459 return $this->getChronologyProtector()->getTouched( $dbName );
460 }
461
462 public function disableChronologyProtection() {
463 $this->getChronologyProtector()->setEnabled( false );
464 }
465
466 /**
467 * @return ChronologyProtector
468 */
469 protected function getChronologyProtector() {
470 if ( $this->chronProt ) {
471 return $this->chronProt;
472 }
473
474 $this->chronProt = new ChronologyProtector(
475 $this->memStash,
476 [
477 'ip' => $this->requestInfo['IPAddress'],
478 'agent' => $this->requestInfo['UserAgent'],
479 ],
480 $this->requestInfo['ChronologyPositionIndex']
481 );
482 $this->chronProt->setLogger( $this->replLogger );
483
484 if ( $this->cliMode ) {
485 $this->chronProt->setEnabled( false );
486 } elseif ( $this->requestInfo['ChronologyProtection'] === 'false' ) {
487 // Request opted out of using position wait logic. This is useful for requests
488 // done by the job queue or background ETL that do not have a meaningful session.
489 $this->chronProt->setWaitEnabled( false );
490 }
491
492 $this->replLogger->debug( __METHOD__ . ': using request info ' .
493 json_encode( $this->requestInfo, JSON_PRETTY_PRINT ) );
494
495 return $this->chronProt;
496 }
497
498 /**
499 * Get and record all of the staged DB positions into persistent memory storage
500 *
501 * @param ChronologyProtector $cp
502 * @param callable|null $workCallback Work to do instead of waiting on syncing positions
503 * @param string $mode One of (sync, async); whether to wait on remote datacenters
504 * @param int|null &$cpIndex DB position key write counter; incremented on update
505 */
506 protected function shutdownChronologyProtector(
507 ChronologyProtector $cp, $workCallback, $mode, &$cpIndex = null
508 ) {
509 // Record all the master positions needed
510 $this->forEachLB( function ( ILoadBalancer $lb ) use ( $cp ) {
511 $cp->shutdownLB( $lb );
512 } );
513 // Write them to the persistent stash. Try to do something useful by running $work
514 // while ChronologyProtector waits for the stash write to replicate to all DCs.
515 $unsavedPositions = $cp->shutdown( $workCallback, $mode, $cpIndex );
516 if ( $unsavedPositions && $workCallback ) {
517 // Invoke callback in case it did not cache the result yet
518 $workCallback(); // work now to block for less time in waitForAll()
519 }
520 // If the positions failed to write to the stash, at least wait on local datacenter
521 // replica DBs to catch up before responding. Even if there are several DCs, this increases
522 // the chance that the user will see their own changes immediately afterwards. As long
523 // as the sticky DC cookie applies (same domain), this is not even an issue.
524 $this->forEachLB( function ( ILoadBalancer $lb ) use ( $unsavedPositions ) {
525 $masterName = $lb->getServerName( $lb->getWriterIndex() );
526 if ( isset( $unsavedPositions[$masterName] ) ) {
527 $lb->waitForAll( $unsavedPositions[$masterName] );
528 }
529 } );
530 }
531
532 /**
533 * Base parameters to LoadBalancer::__construct()
534 * @return array
535 */
536 final protected function baseLoadBalancerParams() {
537 return [
538 'localDomain' => $this->localDomain,
539 'readOnlyReason' => $this->readOnlyReason,
540 'srvCache' => $this->srvCache,
541 'wanCache' => $this->wanCache,
542 'profiler' => $this->profiler,
543 'trxProfiler' => $this->trxProfiler,
544 'queryLogger' => $this->queryLogger,
545 'connLogger' => $this->connLogger,
546 'replLogger' => $this->replLogger,
547 'errorLogger' => $this->errorLogger,
548 'deprecationLogger' => $this->deprecationLogger,
549 'hostname' => $this->hostname,
550 'cliMode' => $this->cliMode,
551 'agent' => $this->agent,
552 'chronologyCallback' => function ( ILoadBalancer $lb ) {
553 // Defer ChronologyProtector construction in case setRequestInfo() ends up
554 // being called later (but before the first connection attempt) (T192611)
555 $this->getChronologyProtector()->initLB( $lb );
556 }
557 ];
558 }
559
560 /**
561 * @param ILoadBalancer $lb
562 */
563 protected function initLoadBalancer( ILoadBalancer $lb ) {
564 if ( $this->trxRoundId !== false ) {
565 $lb->beginMasterChanges( $this->trxRoundId ); // set DBO_TRX
566 }
567
568 $lb->setTableAliases( $this->tableAliases );
569 $lb->setIndexAliases( $this->indexAliases );
570 }
571
572 public function setTableAliases( array $aliases ) {
573 $this->tableAliases = $aliases;
574 }
575
576 public function setIndexAliases( array $aliases ) {
577 $this->indexAliases = $aliases;
578 }
579
580 public function setDomainPrefix( $prefix ) {
581 $this->localDomain = new DatabaseDomain(
582 $this->localDomain->getDatabase(),
583 null,
584 $prefix
585 );
586
587 $this->forEachLB( function ( ILoadBalancer $lb ) use ( $prefix ) {
588 $lb->setDomainPrefix( $prefix );
589 } );
590 }
591
592 public function closeAll() {
593 $this->forEachLBCallMethod( 'closeAll', [] );
594 }
595
596 public function setAgentName( $agent ) {
597 $this->agent = $agent;
598 }
599
600 public function appendShutdownCPIndexAsQuery( $url, $index ) {
601 $usedCluster = 0;
602 $this->forEachLB( function ( ILoadBalancer $lb ) use ( &$usedCluster ) {
603 $usedCluster |= ( $lb->getServerCount() > 1 );
604 } );
605
606 if ( !$usedCluster ) {
607 return $url; // no master/replica clusters touched
608 }
609
610 return strpos( $url, '?' ) === false ? "$url?cpPosIndex=$index" : "$url&cpPosIndex=$index";
611 }
612
613 public function setRequestInfo( array $info ) {
614 if ( $this->chronProt ) {
615 throw new LogicException( 'ChronologyProtector already initialized.' );
616 }
617
618 $this->requestInfo = $info + $this->requestInfo;
619 }
620
621 /**
622 * @param string $stage
623 */
624 private function assertTransactionRoundStage( $stage ) {
625 if ( $this->trxRoundStage !== $stage ) {
626 throw new DBTransactionError(
627 null,
628 "Transaction round stage must be '$stage' (not '{$this->trxRoundStage}')"
629 );
630 }
631 }
632
633 /**
634 * Make PHP ignore user aborts/disconnects until the returned
635 * value leaves scope. This returns null and does nothing in CLI mode.
636 *
637 * @return ScopedCallback|null
638 */
639 final protected function getScopedPHPBehaviorForCommit() {
640 if ( PHP_SAPI != 'cli' ) { // https://bugs.php.net/bug.php?id=47540
641 $old = ignore_user_abort( true ); // avoid half-finished operations
642 return new ScopedCallback( function () use ( $old ) {
643 ignore_user_abort( $old );
644 } );
645 }
646
647 return null;
648 }
649
650 function __destruct() {
651 $this->destroy();
652 }
653 }
654
655 class_alias( LBFactory::class, 'LBFactory' );