Skip to content

Commit 2073105

Browse files
Merge pull request #2053 from Expensify/flo_onyxTables
Don't page lock on onyx tables
2 parents 956e9f1 + 4a1382c commit 2073105

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

BedrockCommand.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ const string& BedrockCommand::getName() const {
5757
return defaultPluginName;
5858
}
5959

60+
const BedrockPlugin* BedrockCommand::getPlugin() const {
61+
return _plugin;
62+
}
63+
6064
int64_t BedrockCommand::_getTimeout(const SData& request, const uint64_t scheduledTime) {
6165
// Timeout is the default, unless explicitly supplied, or if Connection: forget is set.
6266
int64_t timeout = DEFAULT_TIMEOUT;

BedrockCommand.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class BedrockCommand : public SQLiteCommand {
8585
// Return the name of the plugin for this command.
8686
const string& getName() const;
8787

88+
const BedrockPlugin* getPlugin() const;
89+
8890
// Take all of the HTTPS requests attached to this object, and serialize them to a string.
8991
string serializeHTTPSRequests();
9092

@@ -99,7 +101,7 @@ class BedrockCommand : public SQLiteCommand {
99101
}
100102

101103
// Bedrock will call this before writing to the database after it has prepared a transaction for each plugin to allow it to
102-
// enable a handler function for prepare If a plugin would like to perform operations after prepare but before commit, this should
104+
// enable a handler function for prepare If a plugin would like to perform operations after prepare but before commit, this should
103105
// return true, and it should set the prepareHandler it would like to use.
104106
virtual bool shouldEnableOnPrepareNotification(const SQLite& db, void (**onPrepareHandler)(SQLite& _db, int64_t tableID)) {
105107
return false;

BedrockPlugin.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@ bool BedrockPlugin::preventAttach() {
6969
void BedrockPlugin::timerFired(SStopwatch* timer) {}
7070

7171
void BedrockPlugin::upgradeDatabase(SQLite& db) {}
72+
73+
bool BedrockPlugin::shouldLockCommitPageOnTableConflict(const string& tableName) const {
74+
return true;
75+
}

BedrockPlugin.h

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class BedrockPlugin {
7878
// Called when the sync thread is finishing, before destroying DB handles.
7979
virtual void serverStopping() {}
8080

81+
// Should a conflict on the given tableName result in locking the associated database page when we try to commit again?
82+
virtual bool shouldLockCommitPageOnTableConflict(const string& tableName) const;
83+
8184
// Map of plugin names to functions that will return a new plugin of the given type.
8285
static map<string, function<BedrockPlugin*(BedrockServer&)>> g_registeredPluginList;
8386

BedrockServer.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1049,9 +1049,10 @@ void BedrockServer::runCommand(unique_ptr<BedrockCommand>&& _command, bool isBlo
10491049
lastConflictTable = db.getLastConflictTable();
10501050

10511051
// Journals are always chosen at the time of commit. So in case there was a conflict on the journal in
1052-
// the previous commit, the chances are very low (1/192) that we'll choose the same journal, thus, we
1052+
// the previous commit, the chances are very low that we'll choose the same journal, thus, we
10531053
// don't need to lock our next commit on this page conflict.
1054-
if (!SStartsWith(lastConflictTable, "journal")) {
1054+
// Plugins may define other tables on which we should not lock our next commit.
1055+
if (!SStartsWith(lastConflictTable, "journal") && (command->getPlugin() == nullptr || command->getPlugin()->shouldLockCommitPageOnTableConflict(lastConflictTable))) {
10551056
lastConflictPage = db.getLastConflictPage();
10561057
}
10571058
}

0 commit comments

Comments
 (0)