Skip to content

Commit

Permalink
Reduce the timeout once transaction lock is acquired
Browse files Browse the repository at this point in the history
  • Loading branch information
aldo-expensify committed Jul 24, 2024
1 parent c75eca6 commit ec32c20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions BedrockCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class BedrockCommand : public SQLiteCommand {
static const uint64_t DEFAULT_TIMEOUT = 110'000; // 110 seconds, so clients can have a 2 minutes timeout.
static const uint64_t DEFAULT_TIMEOUT_FORGET = 60'000 * 60; // 1 hour for `connection: forget` commands.
static const uint64_t DEFAULT_PROCESS_TIMEOUT = 30'000; // 30 seconds.
static const uint64_t DEFAULT_BLOCKING_TRANSACTION_COMMIT_LOCK_TIMEOUT = 10'000; // 10 seconds.

// Constructor to initialize via a request object (by move).
BedrockCommand(SQLiteCommand&& baseCommand, BedrockPlugin* plugin, bool escalateImmediately_ = false);
Expand Down
8 changes: 8 additions & 0 deletions BedrockCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ BedrockCore::RESULT BedrockCore::peekCommand(unique_ptr<BedrockCommand>& command
if (!_db.beginTransaction(exclusive ? SQLite::TRANSACTION_TYPE::EXCLUSIVE : SQLite::TRANSACTION_TYPE::SHARED)) {
STHROW("501 Failed to begin " + (exclusive ? "exclusive"s : "shared"s) + " transaction");
}
if (exclusive) {
const int64_t oldTimeout = command->timeout();
const int64_t newTimeout = STimeNow() + BedrockCommand::DEFAULT_BLOCKING_TRANSACTION_COMMIT_LOCK_TIMEOUT;
if (newTimeout < oldTimeout) {
SINFO("Reducing blocking commit command timeout from " << STIMESTAMP(oldTimeout) << " to " << STIMESTAMP(newTimeout));
_db.setTimeout(newTimeout);
}
}

// We start the timer here to avoid including the time spent acquiring the lock _sharedData.commitLock
AutoTimer timer(command, exclusive ? BedrockCommand::BLOCKING_PEEK : BedrockCommand::PEEK);
Expand Down

0 comments on commit ec32c20

Please sign in to comment.