Skip to content

Commit

Permalink
Merge pull request #2012 from Expensify/john-log-open-transactions
Browse files Browse the repository at this point in the history
Handle open transactions monitoring on nodes
  • Loading branch information
tylerkaraszewski authored Dec 11, 2024
2 parents 477c766 + 9473d76 commit 5e04561
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion sqlitecluster/SQLite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,10 @@ bool SQLite::beginTransaction(TRANSACTION_TYPE type) {
// Reset before the query, as it's possible the query sets these.
_autoRolledBack = false;

SINFO("[concurrent] Beginning transaction");
// We actively track transaction counts incrementing and decrementing to log the number of active open transactions at any given moment.
_sharedData.openTransactionCount++;

SINFO("[concurrent] Beginning transaction - open transaction count: " << (_sharedData.openTransactionCount));
uint64_t before = STimeNow();
_insideTransaction = !SQuery(_db, "starting db transaction", "BEGIN CONCURRENT");

Expand Down Expand Up @@ -805,6 +808,8 @@ int SQLite::commit(const string& description, function<void()>* preCheckpointCal
_mutexLocked = false;
_queryCache.clear();

_sharedData.openTransactionCount--;

if (preCheckpointCallback != nullptr) {
(*preCheckpointCallback)();
}
Expand Down Expand Up @@ -860,6 +865,8 @@ void SQLite::rollback() {
_rollbackElapsed += STimeNow() - before;
}

_sharedData.openTransactionCount--;

// Finally done with this.
_insideTransaction = false;
_uncommittedHash.clear();
Expand Down Expand Up @@ -1185,6 +1192,7 @@ string SQLite::getLastConflictTable() const {
SQLite::SharedData::SharedData() :
nextJournalCount(0),
_commitEnabled(true),
openTransactionCount(0),
_commitLockTimer("commit lock timer", {
{"EXCLUSIVE", chrono::steady_clock::duration::zero()},
{"SHARED", chrono::steady_clock::duration::zero()},
Expand Down
3 changes: 3 additions & 0 deletions sqlitecluster/SQLite.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ class SQLite {
// If set to false, this prevents any thread from being able to commit to the DB.
atomic<bool> _commitEnabled;

// This variable is used to monitor the number of open transactions on the whole server.
atomic<int64_t> openTransactionCount;

SPerformanceTimer _commitLockTimer;

// We use this flag to prevent to threads running checkpoints t the same time.
Expand Down

0 comments on commit 5e04561

Please sign in to comment.