Skip to content

Commit 656fdef

Browse files
Merge pull request #47528 from nextcloud/backport/47510/stable30
[stable30] fix(db): Increase log level for very slow transactions
2 parents ce0b75c + 6d23946 commit 656fdef

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

lib/private/DB/Connection.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use OCP\Diagnostics\IEventLogger;
3838
use OCP\ICacheFactory;
3939
use OCP\IDBConnection;
40+
use OCP\ILogger;
4041
use OCP\IRequestId;
4142
use OCP\PreConditionNotMetException;
4243
use OCP\Profiler\IProfiler;
@@ -818,7 +819,20 @@ public function commit() {
818819
$this->transactionBacktrace = null;
819820
$this->transactionActiveSince = null;
820821
if ($timeTook > 1) {
821-
$this->logger->debug('Transaction took ' . $timeTook . 's', ['exception' => new \Exception('Transaction took ' . $timeTook . 's')]);
822+
$logLevel = match (true) {
823+
$timeTook > 20 * 60 => ILogger::ERROR,
824+
$timeTook > 5 * 60 => ILogger::WARN,
825+
$timeTook > 10 => ILogger::INFO,
826+
default => ILogger::DEBUG,
827+
};
828+
$this->logger->log(
829+
$logLevel,
830+
'Transaction took ' . $timeTook . 's',
831+
[
832+
'exception' => new \Exception('Transaction took ' . $timeTook . 's'),
833+
'timeSpent' => $timeTook,
834+
]
835+
);
822836
}
823837
}
824838
return $result;
@@ -831,7 +845,20 @@ public function rollBack() {
831845
$this->transactionBacktrace = null;
832846
$this->transactionActiveSince = null;
833847
if ($timeTook > 1) {
834-
$this->logger->debug('Transaction rollback took longer than 1s: ' . $timeTook, ['exception' => new \Exception('Long running transaction rollback')]);
848+
$logLevel = match (true) {
849+
$timeTook > 20 * 60 => ILogger::ERROR,
850+
$timeTook > 5 * 60 => ILogger::WARN,
851+
$timeTook > 10 => ILogger::INFO,
852+
default => ILogger::DEBUG,
853+
};
854+
$this->logger->log(
855+
$logLevel,
856+
'Transaction rollback took longer than 1s: ' . $timeTook,
857+
[
858+
'exception' => new \Exception('Long running transaction rollback'),
859+
'timeSpent' => $timeTook,
860+
]
861+
);
835862
}
836863
}
837864
return $result;

0 commit comments

Comments
 (0)