X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2Flbfactory%2FLBFactory.php;h=64b54e47ae9605d881e11d629b259116d6419444;hb=5bad47dbb4519d6a67a2aba468fb513319311c9a;hp=919f103be15ec75b462c7af69803c6bfee89dcf5;hpb=10d1b7d12b5d097413cd507740c5c71781c2580b;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/rdbms/lbfactory/LBFactory.php b/includes/libs/rdbms/lbfactory/LBFactory.php index 919f103be1..64b54e47ae 100644 --- a/includes/libs/rdbms/lbfactory/LBFactory.php +++ b/includes/libs/rdbms/lbfactory/LBFactory.php @@ -55,7 +55,7 @@ abstract class LBFactory implements ILBFactory { /** @var BagOStuff */ protected $srvCache; /** @var BagOStuff */ - protected $memCache; + protected $memStash; /** @var WANObjectCache */ protected $wanCache; @@ -75,6 +75,11 @@ abstract class LBFactory implements ILBFactory { /** @var callable[] */ protected $replicationWaitCallbacks = []; + /** @var array[] $aliases Map of (table => (dbname, schema, prefix) map) */ + protected $tableAliases = []; + /** @var string[] Map of (index alias => index) */ + protected $indexAliases = []; + /** @var bool Whether this PHP instance is for a CLI script */ protected $cliMode; /** @var string Agent name for query profiling */ @@ -93,7 +98,7 @@ abstract class LBFactory implements ILBFactory { } $this->srvCache = isset( $conf['srvCache'] ) ? $conf['srvCache'] : new EmptyBagOStuff(); - $this->memCache = isset( $conf['memCache'] ) ? $conf['memCache'] : new EmptyBagOStuff(); + $this->memStash = isset( $conf['memStash'] ) ? $conf['memStash'] : new EmptyBagOStuff(); $this->wanCache = isset( $conf['wanCache'] ) ? $conf['wanCache'] : WANObjectCache::newEmpty(); @@ -115,10 +120,13 @@ abstract class LBFactory implements ILBFactory { $this->requestInfo = [ 'IPAddress' => isset( $_SERVER[ 'REMOTE_ADDR' ] ) ? $_SERVER[ 'REMOTE_ADDR' ] : '', 'UserAgent' => isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : '', - 'ChronologyProtection' => 'true' + 'ChronologyProtection' => 'true', + 'ChronologyPositionIndex' => isset( $_GET['cpPosIndex'] ) ? $_GET['cpPosIndex'] : null ]; - $this->cliMode = isset( $conf['cliMode'] ) ? $conf['cliMode'] : PHP_SAPI === 'cli'; + $this->cliMode = isset( $conf['cliMode'] ) + ? $conf['cliMode'] + : ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ); $this->hostname = isset( $conf['hostname'] ) ? $conf['hostname'] : gethostname(); $this->agent = isset( $conf['agent'] ) ? $conf['agent'] : ''; @@ -131,13 +139,13 @@ abstract class LBFactory implements ILBFactory { } public function shutdown( - $mode = self::SHUTDOWN_CHRONPROT_SYNC, callable $workCallback = null + $mode = self::SHUTDOWN_CHRONPROT_SYNC, callable $workCallback = null, &$cpIndex = null ) { $chronProt = $this->getChronologyProtector(); if ( $mode === self::SHUTDOWN_CHRONPROT_SYNC ) { - $this->shutdownChronologyProtector( $chronProt, $workCallback, 'sync' ); + $this->shutdownChronologyProtector( $chronProt, $workCallback, 'sync', $cpIndex ); } elseif ( $mode === self::SHUTDOWN_CHRONPROT_ASYNC ) { - $this->shutdownChronologyProtector( $chronProt, null, 'async' ); + $this->shutdownChronologyProtector( $chronProt, null, 'async', $cpIndex ); } $this->commitMasterChanges( __METHOD__ ); // sanity @@ -307,7 +315,7 @@ abstract class LBFactory implements ILBFactory { $opts += [ 'domain' => false, 'cluster' => false, - 'timeout' => 60, + 'timeout' => $this->cliMode ? 60 : 10, 'ifWritesSince' => null ]; @@ -357,7 +365,7 @@ abstract class LBFactory implements ILBFactory { $failed = []; foreach ( $lbs as $i => $lb ) { if ( $masterPositions[$i] ) { - // The DBMS may not support getMasterPos() + // The RDBMS may not support getMasterPos() if ( !$lb->waitForAll( $masterPositions[$i], $opts['timeout'] ) ) { $failed[] = $lb->getServerName( $lb->getWriterIndex() ); } @@ -435,12 +443,12 @@ abstract class LBFactory implements ILBFactory { } $this->chronProt = new ChronologyProtector( - $this->memCache, + $this->memStash, [ 'ip' => $this->requestInfo['IPAddress'], 'agent' => $this->requestInfo['UserAgent'], ], - isset( $_GET['cpPosTime'] ) ? $_GET['cpPosTime'] : null + $this->requestInfo['ChronologyPositionIndex'] ); $this->chronProt->setLogger( $this->replLogger ); @@ -464,9 +472,10 @@ abstract class LBFactory implements ILBFactory { * @param ChronologyProtector $cp * @param callable|null $workCallback Work to do instead of waiting on syncing positions * @param string $mode One of (sync, async); whether to wait on remote datacenters + * @param int|null &$cpIndex DB position key write counter; incremented on update */ protected function shutdownChronologyProtector( - ChronologyProtector $cp, $workCallback, $mode + ChronologyProtector $cp, $workCallback, $mode, &$cpIndex = null ) { // Record all the master positions needed $this->forEachLB( function ( ILoadBalancer $lb ) use ( $cp ) { @@ -474,7 +483,7 @@ abstract class LBFactory implements ILBFactory { } ); // Write them to the persistent stash. Try to do something useful by running $work // while ChronologyProtector waits for the stash write to replicate to all DCs. - $unsavedPositions = $cp->shutdown( $workCallback, $mode ); + $unsavedPositions = $cp->shutdown( $workCallback, $mode, $cpIndex ); if ( $unsavedPositions && $workCallback ) { // Invoke callback in case it did not cache the result yet $workCallback(); // work now to block for less time in waitForAll() @@ -521,6 +530,17 @@ abstract class LBFactory implements ILBFactory { if ( $this->trxRoundId !== false ) { $lb->beginMasterChanges( $this->trxRoundId ); // set DBO_TRX } + + $lb->setTableAliases( $this->tableAliases ); + $lb->setIndexAliases( $this->indexAliases ); + } + + public function setTableAliases( array $aliases ) { + $this->tableAliases = $aliases; + } + + public function setIndexAliases( array $aliases ) { + $this->indexAliases = $aliases; } public function setDomainPrefix( $prefix ) { @@ -543,7 +563,7 @@ abstract class LBFactory implements ILBFactory { $this->agent = $agent; } - public function appendPreShutdownTimeAsQuery( $url, $time ) { + public function appendShutdownCPIndexAsQuery( $url, $index ) { $usedCluster = 0; $this->forEachLB( function ( ILoadBalancer $lb ) use ( &$usedCluster ) { $usedCluster |= ( $lb->getServerCount() > 1 ); @@ -553,7 +573,7 @@ abstract class LBFactory implements ILBFactory { return $url; // no master/replica clusters touched } - return strpos( $url, '?' ) === false ? "$url?cpPosTime=$time" : "$url&cpPosTime=$time"; + return strpos( $url, '?' ) === false ? "$url?cpPosIndex=$index" : "$url&cpPosIndex=$index"; } public function setRequestInfo( array $info ) {