Skip to content

Commit 2627a74

Browse files
Merge pull request #2722 from Expensify/main
Update expensify_prod branch
2 parents a0b24ff + e03993b commit 2627a74

35 files changed

Lines changed: 464 additions & 1183 deletions

BedrockCommand.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,7 @@ void BedrockCommand::finalizeTimingInfo()
245245
uint64_t blockingPostProcessTotal = 0;
246246
uint64_t commitWorkerTotal = 0;
247247
uint64_t blockingCommitWorkerTotal = 0;
248-
uint64_t commitSyncTotal = 0;
249248
uint64_t queueWorkerTotal = 0;
250-
uint64_t queueSyncTotal = 0;
251249
uint64_t queueBlockingTotal = 0;
252250
uint64_t queuePageLockTotal = 0;
253251
for (const auto& entry: timingInfo) {
@@ -276,14 +274,10 @@ void BedrockCommand::finalizeTimingInfo()
276274
} else if (get<0>(entry) == BLOCKING_COMMIT_WORKER) {
277275
commitWorkerTotal += get<2>(entry) - get<1>(entry);
278276
blockingCommitWorkerTotal += get<2>(entry) - get<1>(entry);
279-
} else if (get<0>(entry) == COMMIT_SYNC) {
280-
commitSyncTotal += get<2>(entry) - get<1>(entry);
281277
} else if (get<0>(entry) == QUEUE_WORKER) {
282278
queueWorkerTotal += get<2>(entry) - get<1>(entry);
283279
} else if (get<0>(entry) == QUEUE_BLOCKING) {
284280
queueBlockingTotal += get<2>(entry) - get<1>(entry);
285-
} else if (get<0>(entry) == QUEUE_SYNC) {
286-
queueSyncTotal += get<2>(entry) - get<1>(entry);
287281
} else if (get<0>(entry) == QUEUE_PAGE_LOCK) {
288282
queuePageLockTotal += get<2>(entry) - get<1>(entry);
289283
}
@@ -293,8 +287,8 @@ void BedrockCommand::finalizeTimingInfo()
293287
uint64_t totalTime = STimeNow() - creationTime;
294288

295289
// Time that wasn't accounted for in all the other metrics.
296-
uint64_t unaccountedTime = totalTime - (prePeekTotal + peekTotal + processTotal + postProcessTotal + commitWorkerTotal + commitSyncTotal +
297-
escalationTimeUS + queueWorkerTotal + queueBlockingTotal + queueSyncTotal + queuePageLockTotal);
290+
uint64_t unaccountedTime = totalTime - (prePeekTotal + peekTotal + processTotal + postProcessTotal + commitWorkerTotal +
291+
escalationTimeUS + queueWorkerTotal + queueBlockingTotal + queuePageLockTotal);
298292

299293
uint64_t exclusiveTransactionLockTime = blockingPeekTotal + blockingProcessTotal + blockingCommitWorkerTotal;
300294
uint64_t blockingCommitThreadTime = exclusiveTransactionLockTime + blockingPrePeekTotal + blockingPostProcessTotal;
@@ -357,11 +351,9 @@ void BedrockCommand::finalizeTimingInfo()
357351
"blockingCommitThreadTime:" << blockingCommitThreadTime / 1000 << ", "
358352
"exclusiveTransactionLockTime:" << exclusiveTransactionLockTime / 1000 <<
359353
". Commit: "
360-
"worker:" << commitWorkerTotal / 1000 << ", "
361-
"sync:" << commitSyncTotal / 1000 <<
354+
"worker:" << commitWorkerTotal / 1000 <<
362355
". Queue: "
363356
"worker:" << queueWorkerTotal / 1000 << ", "
364-
"sync:" << queueSyncTotal / 1000 << ", "
365357
"blocking:" << queueBlockingTotal / 1000 << ", "
366358
"pageLock:" << queuePageLockTotal / 1000 << ", "
367359
"escalation:" << escalationTimeUS / 1000 <<

BedrockCommand.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ class BedrockCommand : public SQLiteCommand {
1515
PROCESS,
1616
POSTPROCESS,
1717
COMMIT_WORKER,
18-
COMMIT_SYNC,
1918
QUEUE_WORKER,
20-
QUEUE_SYNC,
2119
QUEUE_BLOCKING,
2220
QUEUE_PAGE_LOCK,
2321

@@ -42,6 +40,12 @@ class BedrockCommand : public SQLiteCommand {
4240
static const uint64_t DEFAULT_TIMEOUT_FORGET = 60'000 * 60; // 1 hour for `connection: forget` commands.
4341
static const uint64_t DEFAULT_PROCESS_TIMEOUT = 5'000; // 5 seconds.
4442

43+
// How long a command named in `-synchronousCommands` may hold the blocking commit thread. That thread owns the
44+
// commit lock for its whole transaction, and SQLiteNode::_changeState waits on the same lock with no timeout, so
45+
// this also bounds how long a node state change can be stalled. It has to stay well under the 30 second peer
46+
// receive timeout that would otherwise cost us the leader.
47+
static const uint64_t SYNCHRONOUS_COMMAND_TIMEOUT = 20'000; // 20 seconds.
48+
4549
// Constructor to initialize via a request object (by move).
4650
BedrockCommand(SQLiteCommand&& baseCommand, BedrockPlugin* plugin, bool escalateImmediately_ = false);
4751

@@ -306,6 +310,11 @@ class BedrockCommand : public SQLiteCommand {
306310
// in `process` instead of peek, as it will always be escalated to leader
307311
const bool escalateImmediately;
308312

313+
// True if this command was named in `-synchronousCommands`. Such commands run on the blocking commit thread, so
314+
// they're serialized against each other and against every other write, and they get SYNCHRONOUS_COMMAND_TIMEOUT
315+
// rather than the shorter DEFAULT_PROCESS_TIMEOUT that thread otherwise imposes.
316+
bool isSynchronous = false;
317+
309318
// Setting this to `true` will cause this command to abort immediately, even in the middle of a slow database query.
310319
// NOTE: currently, this will not abort from every case where a command could be stuck, but only in DB queries.
311320
atomic<bool> shouldAbort = false;

BedrockCore.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ BedrockCore::RESULT BedrockCore::peekCommand(unique_ptr<BedrockCommand>& command
167167
STHROW("501 Failed to begin " + (exclusive ? "exclusive"s : "shared"s) + " transaction");
168168
}
169169

170-
if (exclusive && command->writeConsistency != SQLiteNode::QUORUM) {
171-
decreaseCommandTimeout(command, BedrockCommand::DEFAULT_PROCESS_TIMEOUT);
170+
if (exclusive) {
171+
decreaseCommandTimeout(command, command->isSynchronous ? BedrockCommand::SYNCHRONOUS_COMMAND_TIMEOUT
172+
: BedrockCommand::DEFAULT_PROCESS_TIMEOUT);
172173
}
173174

174175
// We start the timer here to avoid including the time spent acquiring the lock _sharedData.commitLock
@@ -269,8 +270,9 @@ BedrockCore::RESULT BedrockCore::processCommand(unique_ptr<BedrockCommand>& comm
269270
STHROW("501 Failed to begin " + (exclusive ? "exclusive"s : "shared"s) + " transaction");
270271
}
271272

272-
if (exclusive && command->writeConsistency != SQLiteNode::QUORUM) {
273-
decreaseCommandTimeout(command, BedrockCommand::DEFAULT_PROCESS_TIMEOUT);
273+
if (exclusive) {
274+
decreaseCommandTimeout(command, command->isSynchronous ? BedrockCommand::SYNCHRONOUS_COMMAND_TIMEOUT
275+
: BedrockCommand::DEFAULT_PROCESS_TIMEOUT);
274276
}
275277
}
276278

0 commit comments

Comments
 (0)