Skip to content

Commit

Permalink
Merge pull request #2065 from Expensify/main
Browse files Browse the repository at this point in the history
Update expensify_prod branch
  • Loading branch information
danieldoglas authored Jan 15, 2025
2 parents 27ff9f4 + 65b880e commit 4e2a3de
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 16 deletions.
2 changes: 0 additions & 2 deletions BedrockServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,8 +1038,6 @@ void BedrockServer::runCommand(unique_ptr<BedrockCommand>&& _command, bool isBlo
// loop and send it to followers. NOTE: we don't check for null here, that should be
// impossible inside a worker thread.
_syncNode->notifyCommit();
SINFO("Committed leader transaction #" << transactionID << "(" << transactionHash << "). Command: '" << command->request.methodLine << "', blocking: "
<< (isBlocking ? "true" : "false"));
_conflictManager.recordTables(command->request.methodLine, db.getTablesUsed());
// So we must still be leading, and at this point our commit has succeeded, let's
// mark it as complete. We add the currentCommit count here as well.
Expand Down
1 change: 0 additions & 1 deletion libstuff/libstuff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2722,7 +2722,6 @@ int SQuery(sqlite3* db, const char* e, const string& sql, SQResult& result, int6

// But we log for commit conflicts as well, to keep track of how often this happens with this experimental feature.
if (extErr == SQLITE_BUSY_SNAPSHOT) {
SHMMM("[concurrent] commit conflict.");
return extErr;
}
return error;
Expand Down
16 changes: 3 additions & 13 deletions sqlitecluster/SQLite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ bool SQLite::beginTransaction(TRANSACTION_TYPE type) {
// 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));
SINFO("Beginning transaction - open transaction count: " << (_sharedData.openTransactionCount));
uint64_t before = STimeNow();
_insideTransaction = !SQuery(_db, "starting db transaction", "BEGIN CONCURRENT");

Expand Down Expand Up @@ -663,7 +663,7 @@ bool SQLite::prepare(uint64_t* transactionID, string* transactionhash) {
SQResult journalLookupResult;
SASSERT(!SQuery(_db, "getting commit min", "SELECT MIN(id) FROM " + _journalName, journalLookupResult));
uint64_t minJournalEntry = journalLookupResult.size() ? SToUInt64(journalLookupResult[0][0]) : 0;

// Note that this can change before we hold the lock on _sharedData.commitLock, but it doesn't matter yet, as we're only
// using it to truncate the journal. We'll reset this value once we acquire that lock.
uint64_t commitCount = _sharedData.commitCount;
Expand All @@ -677,13 +677,9 @@ bool SQLite::prepare(uint64_t* transactionID, string* transactionhash) {
// where this journal in particular has accumulated a large backlog.
static const size_t deleteLimit = 10;
if (minJournalEntry < oldestCommitToKeep) {
auto startUS = STimeNow();
shared_lock<shared_mutex> lock(_sharedData.writeLock);
string query = "DELETE FROM " + _journalName + " WHERE id < " + SQ(oldestCommitToKeep) + " LIMIT " + SQ(deleteLimit);
SASSERT(!SQuery(_db, "Deleting oldest journal rows", query));
size_t deletedCount = sqlite3_changes(_db);
SINFO("Removed " << deletedCount << " rows from journal " << _journalName << ", oldestToKeep: " << oldestCommitToKeep << ", count:"
<< commitCount << ", limit: " << _maxJournalSize << ", in " << (STimeNow() - startUS) << "us.");
}

// We lock this here, so that we can guarantee the order in which commits show up in the database.
Expand Down Expand Up @@ -771,9 +767,6 @@ int SQLite::commit(const string& description, function<void()>* preCheckpointCal
result = SQuery(_db, "committing db transaction", "COMMIT");
_lastConflictPage = _conflictPage;
_lastConflictTable = _conflictTable;
if (_lastConflictPage) {
SINFO(format("part of last conflict page: {}, conflict table: {}", _conflictPage, _conflictTable));
}

// If there were conflicting commits, will return SQLITE_BUSY_SNAPSHOT
SASSERT(result == SQLITE_OK || result == SQLITE_BUSY_SNAPSHOT);
Expand Down Expand Up @@ -834,7 +827,7 @@ int SQLite::commit(const string& description, function<void()>* preCheckpointCal
_lastConflictPage = 0;
_lastConflictTable = "";
} else {
SINFO("Commit failed, waiting for rollback.");
// The commit failed, we will rollback.
}

// if we got SQLITE_BUSY_SNAPSHOT, then we're *still* holding commitLock, and it will need to be unlocked by
Expand Down Expand Up @@ -883,9 +876,6 @@ void SQLite::rollback() {
// Finally done with this.
_insideTransaction = false;
_uncommittedHash.clear();
if (_uncommittedQuery.size()) {
SINFO("Rollback successful.");
}
_uncommittedQuery.clear();

// Only unlock the mutex if we've previously locked it. We can call `rollback` to cancel a transaction without
Expand Down

0 comments on commit 4e2a3de

Please sign in to comment.