From ec32c2092c206af8237b406619df4358915dc3ad Mon Sep 17 00:00:00 2001 From: Aldo Canepa Date: Wed, 24 Jul 2024 16:39:22 -0700 Subject: [PATCH] Reduce the timeout once transaction lock is acquired --- BedrockCommand.h | 1 + BedrockCore.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/BedrockCommand.h b/BedrockCommand.h index f8a6b9645..b34111952 100644 --- a/BedrockCommand.h +++ b/BedrockCommand.h @@ -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); diff --git a/BedrockCore.cpp b/BedrockCore.cpp index 64c349ee6..e7e984e38 100644 --- a/BedrockCore.cpp +++ b/BedrockCore.cpp @@ -135,6 +135,14 @@ BedrockCore::RESULT BedrockCore::peekCommand(unique_ptr& 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);