Skip to content

Commit 4e07f33

Browse files
danieldoglasclaude
andcommitted
Track max _totalTransactionElapsed across transactions in a command
When a command runs multiple transactions (e.g., peek then process), _totalTransactionElapsed was only storing the last transaction's time. This meant slow transactions in earlier phases were silently lost in timing logs. Use max() in both rollback and commit so the highest transaction time is preserved. Reset the counter at command boundaries (start of peekCommand) so it doesn't carry over between commands on the same shared db handle. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 41c5773 commit 4e07f33

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

BedrockCore.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ BedrockCore::RESULT BedrockCore::peekCommand(unique_ptr<BedrockCommand>& command
142142
try {
143143
SDEBUG("Peeking at '" << request.methodLine << "' with priority: " << command->priority);
144144
command->peekCount++;
145+
_db.resetMaxTransactionElapsed();
145146
_db.setTimeout(_getRemainingTime(command, false));
146147
_db.setAbortRef(command->shouldAbort);
147148

@@ -240,6 +241,7 @@ BedrockCore::RESULT BedrockCore::processCommand(unique_ptr<BedrockCommand>& comm
240241
try {
241242
SDEBUG("Processing '" << request.methodLine << "'");
242243
command->processCount++;
244+
_db.resetMaxTransactionElapsed();
243245
_db.setTimeout(_getRemainingTime(command, true));
244246
_db.setAbortRef(command->shouldAbort);
245247
if (!_db.insideTransaction()) {

sqlitecluster/SQLite.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ int SQLite::commit(const string& description, const string& commandName, functio
936936

937937
_commitElapsed += STimeNow() - before;
938938
_commitLockElapsed += _sharedData._commitLockTimer.stop();
939-
_totalTransactionElapsed = _transactionTimer.stop();
939+
_totalTransactionElapsed = max(_totalTransactionElapsed, _transactionTimer.stop());
940940
_sharedData.incrementCommit(_uncommittedHash);
941941
_insideTransaction = false;
942942
_uncommittedHash.clear();
@@ -1019,8 +1019,10 @@ void SQLite::rollback(const string& commandName)
10191019
{
10201020
// Make sure we're actually inside a transaction
10211021
if (_insideTransaction) {
1022-
// Store the total transaction time only if we were inside one.
1023-
_totalTransactionElapsed = _transactionTimer.stop();
1022+
// Store the highest transaction time across all transactions in this command.
1023+
// We use max() because a single command may run multiple transactions (e.g., peek then process),
1024+
// and we want to capture the longest one rather than just the last.
1025+
_totalTransactionElapsed = max(_totalTransactionElapsed, _transactionTimer.stop());
10241026

10251027
// Cancel this transaction
10261028
if (_autoRolledBack) {

sqlitecluster/SQLite.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,13 @@ class SQLite {
210210
// Cancels the current transaction and rolls it back.
211211
void rollback(const string& commandName = "");
212212

213+
// Resets the max transaction elapsed time. Call this at command boundaries to avoid
214+
// carrying over timing from a previous command on the same db handle.
215+
void resetMaxTransactionElapsed()
216+
{
217+
_totalTransactionElapsed = 0;
218+
}
219+
213220
// Returns the total number of changes on this database
214221
int getChangeCount()
215222
{

0 commit comments

Comments
 (0)