X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/recherche.php?a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2FChronologyProtector.php;h=8121654e3309df8d49fab5c240e132055dbc8005;hb=0cb2a09b6d0c7318e49d5ef7c5989e9005a625ff;hp=0daa4ed3b2a85c5422f11657bda15440a9f69ee5;hpb=856bf52037a00c47c8123488dcf01bd3a1071f36;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/rdbms/ChronologyProtector.php b/includes/libs/rdbms/ChronologyProtector.php index 0daa4ed3b2..8121654e33 100644 --- a/includes/libs/rdbms/ChronologyProtector.php +++ b/includes/libs/rdbms/ChronologyProtector.php @@ -28,7 +28,6 @@ use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use Wikimedia\WaitConditionLoop; use BagOStuff; -use DBMasterPos; /** * Class for ensuring a consistent ordering of events as seen by the user, despite replication. @@ -62,9 +61,9 @@ class ChronologyProtector implements LoggerAwareInterface { /** @var float[] Map of (DB master name => 1) */ protected $shutdownTouchDBs = []; - /** @var integer Seconds to store positions */ + /** @var int Seconds to store positions */ const POSITION_TTL = 60; - /** @var integer Max time to wait for positions to appear */ + /** @var int Max time to wait for positions to appear */ const POS_WAIT_TIMEOUT = 5; /** @@ -76,7 +75,7 @@ class ChronologyProtector implements LoggerAwareInterface { public function __construct( BagOStuff $store, array $client, $posTime = null ) { $this->store = $store; $this->clientId = md5( $client['ip'] . "\n" . $client['agent'] ); - $this->key = $store->makeGlobalKey( __CLASS__, $this->clientId ); + $this->key = $store->makeGlobalKey( __CLASS__, $this->clientId, 'v1' ); $this->waitForPosTime = $posTime; $this->logger = new NullLogger(); } @@ -120,7 +119,10 @@ class ChronologyProtector implements LoggerAwareInterface { $this->initPositions(); $masterName = $lb->getServerName( $lb->getWriterIndex() ); - if ( !empty( $this->startupPositions[$masterName] ) ) { + if ( + isset( $this->startupPositions[$masterName] ) && + $this->startupPositions[$masterName] instanceof DBMasterPos + ) { $pos = $this->startupPositions[$masterName]; $this->logger->info( __METHOD__ . ": LB for '$masterName' set to pos $pos\n" ); $lb->waitFor( $pos ); @@ -299,8 +301,9 @@ class ChronologyProtector implements LoggerAwareInterface { $min = null; foreach ( $data['positions'] as $pos ) { - /** @var DBMasterPos $pos */ - $min = $min ? min( $pos->asOfTime(), $min ) : $pos->asOfTime(); + if ( $pos instanceof DBMasterPos ) { + $min = $min ? min( $pos->asOfTime(), $min ) : $pos->asOfTime(); + } } return $min; @@ -312,15 +315,17 @@ class ChronologyProtector implements LoggerAwareInterface { * @return array */ private static function mergePositions( $curValue, array $shutdownPositions ) { - /** @var $curPositions DBMasterPos[] */ + /** @var DBMasterPos[] $curPositions */ if ( $curValue === false ) { $curPositions = $shutdownPositions; } else { $curPositions = $curValue['positions']; // Use the newest positions for each DB master foreach ( $shutdownPositions as $db => $pos ) { - if ( !isset( $curPositions[$db] ) - || $pos->asOfTime() > $curPositions[$db]->asOfTime() + if ( + !isset( $curPositions[$db] ) || + !( $curPositions[$db] instanceof DBMasterPos ) || + $pos->asOfTime() > $curPositions[$db]->asOfTime() ) { $curPositions[$db] = $pos; }