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 */
/** @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: <IP>, agent: <user-agent>)
+ * @param array[] $client Map of (ip: <IP>, agent: <user-agent> [, clientId: <hash>] )
* @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();
}
$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
[
'cpPosIndex' => $this->waitForPosIndex,
'waitTimeMs' => $waitedMs
- ]
+ ] + $this->clientLogInfo
);
} else {
$this->logger->warning(
'cpPosIndex' => $this->waitForPosIndex,
'indexReached' => $indexReached,
'waitTimeMs' => $waitedMs
- ]
+ ] + $this->clientLogInfo
);
}
} else {
*/
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 (
}
}
- $cpIndex = isset( $curValue['writeIndex'] ) ? $curValue['writeIndex'] : 0;
+ $cpIndex = $curValue['writeIndex'] ?? 0;
return [
'positions' => $curPositions,