X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=blobdiff_plain;f=includes%2Flibs%2Frdbms%2FChronologyProtector.php;h=45179cc8351b3da81238756f02944127a1842a4e;hb=6cce704da1335078aa98838e7a7da9eeb4e46b67;hp=8b21ede813a4cd95154ca76c5d0f507109cd75f8;hpb=5123888304ecb6f7f768fba569ec86ad79b344f1;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/libs/rdbms/ChronologyProtector.php b/includes/libs/rdbms/ChronologyProtector.php index 8b21ede813..45179cc835 100644 --- a/includes/libs/rdbms/ChronologyProtector.php +++ b/includes/libs/rdbms/ChronologyProtector.php @@ -43,6 +43,8 @@ class ChronologyProtector implements LoggerAwareInterface { protected $key; /** @var string Hash of client parameters */ protected $clientId; + /** @var string[] Map of client information fields for logging */ + protected $clientLogInfo; /** @var int|null Expected minimum index of the last write to the position store */ protected $waitForPosIndex; /** @var int Max seconds to wait on positions to appear */ @@ -64,21 +66,30 @@ class ChronologyProtector implements LoggerAwareInterface { /** @var int Seconds to store positions */ const POSITION_TTL = 60; /** @var int Seconds to store position write index cookies (safely less than POSITION_TTL) */ - const POSITION_COOKIE_TTL = 60; + const POSITION_COOKIE_TTL = 10; /** @var int Max time to wait for positions to appear */ const POS_STORE_WAIT_TIMEOUT = 5; /** * @param BagOStuff $store - * @param array[] $client Map of (ip: , agent: ) + * @param array[] $client Map of (ip: , agent: [, clientId: ] ) * @param int|null $posIndex Write counter index [optional] * @since 1.27 */ public function __construct( BagOStuff $store, array $client, $posIndex = null ) { $this->store = $store; - $this->clientId = md5( $client['ip'] . "\n" . $client['agent'] ); + $this->clientId = isset( $client['clientId'] ) + ? $client['clientId'] + : md5( $client['ip'] . "\n" . $client['agent'] ); $this->key = $store->makeGlobalKey( __CLASS__, $this->clientId, 'v2' ); $this->waitForPosIndex = $posIndex; + + $this->clientLogInfo = [ + 'clientIP' => $client['ip'], + 'clientAgent' => $client['agent'], + 'clientId' => $client['clientId'] ?? null + ]; + $this->logger = new NullLogger(); } @@ -86,6 +97,14 @@ class ChronologyProtector implements LoggerAwareInterface { $this->logger = $logger; } + /** + * @return string Client ID hash + * @since 1.32 + */ + public function getClientId() { + return $this->clientId; + } + /** * @param bool $enabled Whether to no-op all method calls * @since 1.27 @@ -298,7 +317,7 @@ class ChronologyProtector implements LoggerAwareInterface { [ 'cpPosIndex' => $this->waitForPosIndex, 'waitTimeMs' => $waitedMs - ] + ] + $this->clientLogInfo ); } else { $this->logger->warning( @@ -307,7 +326,7 @@ class ChronologyProtector implements LoggerAwareInterface { 'cpPosIndex' => $this->waitForPosIndex, 'indexReached' => $indexReached, 'waitTimeMs' => $waitedMs - ] + ] + $this->clientLogInfo ); } } else { @@ -330,7 +349,7 @@ class ChronologyProtector implements LoggerAwareInterface { */ protected function mergePositions( $curValue, array $shutdownPositions, &$cpIndex = null ) { /** @var DBMasterPos[] $curPositions */ - $curPositions = isset( $curValue['positions'] ) ? $curValue['positions'] : []; + $curPositions = $curValue['positions'] ?? []; // Use the newest positions for each DB master foreach ( $shutdownPositions as $db => $pos ) { if ( @@ -342,7 +361,7 @@ class ChronologyProtector implements LoggerAwareInterface { } } - $cpIndex = isset( $curValue['writeIndex'] ) ? $curValue['writeIndex'] : 0; + $cpIndex = $curValue['writeIndex'] ?? 0; return [ 'positions' => $curPositions,