Skip to content

Commit

Permalink
Merge pull request #47528 from nextcloud/backport/47510/stable30
Browse files Browse the repository at this point in the history
[stable30] fix(db): Increase log level for very slow transactions
  • Loading branch information
AndyScherzinger authored Aug 28, 2024
2 parents ce0b75c + 6d23946 commit 656fdef
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions lib/private/DB/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\Diagnostics\IEventLogger;
use OCP\ICacheFactory;
use OCP\IDBConnection;
use OCP\ILogger;
use OCP\IRequestId;
use OCP\PreConditionNotMetException;
use OCP\Profiler\IProfiler;
Expand Down Expand Up @@ -818,7 +819,20 @@ public function commit() {
$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;
Expand All @@ -831,7 +845,20 @@ public function rollBack() {
$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;
Expand Down

0 comments on commit 656fdef

Please sign in to comment.