Skip to content

Commit

Permalink
Merge pull request #47510 from nextcloud/fix/db/slow-transactions-hig…
Browse files Browse the repository at this point in the history
…her-log-level

fix(db): Increase log level for very slow transactions
  • Loading branch information
nickvergessen authored Aug 27, 2024
2 parents b8ab7b7 + bdcfe5b commit ead3f66
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 @@ -28,6 +28,7 @@
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;
Expand Down Expand Up @@ -719,7 +720,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 @@ -732,7 +746,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 ead3f66

Please sign in to comment.