diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2024-08-27 10:30:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-27 10:30:52 +0200 |
commit | ead3f66379f35e42c2d5433eeca911b61a9cd968 (patch) | |
tree | 41c052ce46d3f17edfcc9bd2efe95467a483a610 | |
parent | b8ab7b7e556d7bc71597a2ca716652b80174719d (diff) | |
parent | bdcfe5b8a94e6c4b89e3aaf133b6900af817236d (diff) | |
download | nextcloud-server-ead3f66379f35e42c2d5433eeca911b61a9cd968.tar.gz nextcloud-server-ead3f66379f35e42c2d5433eeca911b61a9cd968.zip |
Merge pull request #47510 from nextcloud/fix/db/slow-transactions-higher-log-level
fix(db): Increase log level for very slow transactions
-rw-r--r-- | lib/private/DB/Connection.php | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index ac594a5ed0d..9aeba16fb24 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -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; |