diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2024-08-27 10:03:35 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2024-08-27 13:24:08 +0000 |
commit | 6d2394680cb32b1f9ddd4e75afdf3658afa4dce2 (patch) | |
tree | 5d91dd3844409d0de94cc9c2093268f498a6beaf /lib/private | |
parent | 4ea841721ed53c9ea209ed914c688c21250df265 (diff) | |
download | nextcloud-server-6d2394680cb32b1f9ddd4e75afdf3658afa4dce2.tar.gz nextcloud-server-6d2394680cb32b1f9ddd4e75afdf3658afa4dce2.zip |
fix(db): Increase log level for very slow transactions
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private')
-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 3cdd5fd06c0..ef12171e0a5 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; |