150 if ( $type === self::EXPECTATION_REPLICAS_ONLY ) {
152 foreach ( [
'writes',
'masterConns' ] as $event ) {
153 if ( $this->expect[$event][self::FLD_LIMIT] === 0 ) {
158 $events = self::EVENT_NAMES;
161 foreach ( $events as $event ) {
162 ++$this->silenced[$event];
165 return new ScopedCallback(
function () use ( $events ) {
166 foreach ( $events as $event ) {
167 --$this->silenced[$event];
183 if ( !isset( $this->expect[$event] ) ) {
187 if ( $limit <= $this->expect[$event][self::FLD_LIMIT] ) {
189 $this->expect[$event] = [
190 self::FLD_LIMIT => $limit,
191 self::FLD_FNAME => $fname
280 $name =
"{$db} {$server} TRX#$id";
281 if ( isset( $this->dbTrxHoldingLocks[$name] ) ) {
282 $this->logger->warning(
"Nested transaction for '$name' - out of sync." );
284 $this->dbTrxHoldingLocks[$name] = [
285 'start' => $this->getCurrentTime(),
288 $this->dbTrxMethodTimes[$name] = [];
290 foreach ( $this->dbTrxHoldingLocks as $name => &$info ) {
292 $info[
'conns'][$name] = 1;
314 ?
string $serverName =
null
316 $eTime = $this->getCurrentTime();
317 $elapsed = ( $eTime - $sTime );
319 if ( $isWrite && $this->isAboveThreshold( $rowCount,
'maxAffected' ) ) {
320 $this->reportExpectationViolated(
'maxAffected', $query, $rowCount, $trxId, $serverName );
321 } elseif ( !$isWrite && $this->isAboveThreshold( $rowCount,
'readQueryRows' ) ) {
322 $this->reportExpectationViolated(
'readQueryRows', $query, $rowCount, $trxId, $serverName );
326 if ( $this->pingAndCheckThreshold(
'queries' ) ) {
327 $this->reportExpectationViolated(
'queries', $query, $this->hits[
'queries'], $trxId, $serverName );
329 if ( $isWrite && $this->pingAndCheckThreshold(
'writes' ) ) {
330 $this->reportExpectationViolated(
'writes', $query, $this->hits[
'writes'], $trxId, $serverName );
333 if ( !$isWrite && $this->isAboveThreshold( $elapsed,
'readQueryTime' ) ) {
334 $this->reportExpectationViolated(
'readQueryTime', $query, $elapsed, $trxId, $serverName );
336 if ( $isWrite && $this->isAboveThreshold( $elapsed,
'writeQueryTime' ) ) {
337 $this->reportExpectationViolated(
'writeQueryTime', $query, $elapsed, $trxId, $serverName );
340 if ( !$this->dbTrxHoldingLocks ) {
343 } elseif ( !$isWrite && $elapsed < self::EVENT_THRESHOLD_SEC ) {
348 foreach ( $this->dbTrxHoldingLocks as $name => $info ) {
349 $lastQuery = end( $this->dbTrxMethodTimes[$name] );
352 $lastEnd = $lastQuery[2];
353 if ( $sTime >= $lastEnd ) {
354 if ( ( $sTime - $lastEnd ) > self::EVENT_THRESHOLD_SEC ) {
356 $this->dbTrxMethodTimes[$name][] = [
'...delay...', $lastEnd, $sTime ];
358 $this->dbTrxMethodTimes[$name][] = [ $query, $sTime, $eTime ];
362 if ( $sTime >= $info[
'start'] ) {
363 $this->dbTrxMethodTimes[$name][] = [ $query, $sTime, $eTime ];
390 $name =
"{$db} {$server} TRX#$id";
391 if ( !isset( $this->dbTrxMethodTimes[$name] ) ) {
392 $this->logger->warning(
"Detected no transaction for '$name' - out of sync." );
399 if ( $this->isAboveThreshold( $writeTime,
'writeQueryTime' ) ) {
400 $this->reportExpectationViolated(
402 "[transaction writes to {$db} at {$server}]",
409 if ( $this->isAboveThreshold( $affected,
'maxAffected' ) ) {
410 $this->reportExpectationViolated(
412 "[transaction writes to {$db} at {$server}]",
418 $lastQuery = end( $this->dbTrxMethodTimes[$name] );
420 $now = $this->getCurrentTime();
421 $lastEnd = $lastQuery[2];
422 if ( ( $now - $lastEnd ) > self::EVENT_THRESHOLD_SEC ) {
423 $this->dbTrxMethodTimes[$name][] = [
'...delay...', $lastEnd, $now ];
427 foreach ( $this->dbTrxMethodTimes[$name] as $info ) {
428 $elapsed = ( $info[2] - $info[1] );
429 if ( $elapsed >= self::DB_LOCK_THRESHOLD_SEC ) {
436 foreach ( $this->dbTrxMethodTimes[$name] as $i => [ $query, $sTime, $end ] ) {
438 "%-2d %.3fs %s\n", $i, ( $end - $sTime ), $this->getGeneralizedSql( $query ) );
440 $this->logger->warning(
"Suboptimal transaction [{dbs}]:\n{trace}", [
441 'dbs' => implode(
', ', array_keys( $this->dbTrxHoldingLocks[$name][
'conns'] ) ),
442 'trace' => mb_substr( $trace, 0, 2000 )
445 unset( $this->dbTrxHoldingLocks[$name] );
446 unset( $this->dbTrxMethodTimes[$name] );