Merge pull request #47510 from nextcloud/fix/db/slow-transactions-higher-log-level

fix(db): Increase log level for very slow transactions
pull/47507/head
Joas Schilling 2024-08-27 10:30:52 +07:00 committed by GitHub
commit ead3f66379
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 29 additions and 2 deletions

@ -28,6 +28,7 @@ use OC\SystemConfig;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Diagnostics\IEventLogger;
use OCP\IDBConnection;
use OCP\ILogger;
use OCP\IRequestId;
use OCP\PreConditionNotMetException;
use OCP\Profiler\IProfiler;
@ -719,7 +720,20 @@ class Connection extends PrimaryReadReplicaConnection {
$this->transactionBacktrace = null;
$this->transactionActiveSince = null;
if ($timeTook > 1) {
$this->logger->debug('Transaction took ' . $timeTook . 's', ['exception' => new \Exception('Transaction took ' . $timeTook . 's')]);
$logLevel = match (true) {
$timeTook > 20 * 60 => ILogger::ERROR,
$timeTook > 5 * 60 => ILogger::WARN,
$timeTook > 10 => ILogger::INFO,
default => ILogger::DEBUG,
};
$this->logger->log(
$logLevel,
'Transaction took ' . $timeTook . 's',
[
'exception' => new \Exception('Transaction took ' . $timeTook . 's'),
'timeSpent' => $timeTook,
]
);
}
}
return $result;
@ -732,7 +746,20 @@ class Connection extends PrimaryReadReplicaConnection {
$this->transactionBacktrace = null;
$this->transactionActiveSince = null;
if ($timeTook > 1) {
$this->logger->debug('Transaction rollback took longer than 1s: ' . $timeTook, ['exception' => new \Exception('Long running transaction rollback')]);
$logLevel = match (true) {
$timeTook > 20 * 60 => ILogger::ERROR,
$timeTook > 5 * 60 => ILogger::WARN,
$timeTook > 10 => ILogger::INFO,
default => ILogger::DEBUG,
};
$this->logger->log(
$logLevel,
'Transaction rollback took longer than 1s: ' . $timeTook,
[
'exception' => new \Exception('Long running transaction rollback'),
'timeSpent' => $timeTook,
]
);
}
}
return $result;