Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update expensify_prod branch #1545

Merged
merged 3 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion sqlitecluster/SQLiteNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ SQLiteNode::SQLiteNode(SQLiteServer& server, shared_ptr<SQLitePool> dbPool, cons
{
SASSERT(_originalPriority >= 0);
onPrepareHandlerEnabled = false;

// We create a copy of the database handle here so that the sync node can operate on its handle and the plugin gets
// its own handle to operate on. This avoids conflicts where the sync thread and the plugin are trying to both run
// queries at the same time. This also avoids the need to create any share locking between the two.
pluginDB = new SQLite(_db);
SINFO("[NOTIFY] setting commit count to: " << _db.getCommitCount());
_localCommitNotifier.notifyThrough(_db.getCommitCount());

Expand All @@ -149,6 +154,10 @@ SQLiteNode::~SQLiteNode() {
for (SQLitePeer* peer : _peerList) {
delete peer;
}

if (pluginDB != nullptr) {
delete pluginDB;
}
}

void SQLiteNode::_replicate(SQLitePeer* peer, SData command, size_t sqlitePoolIndex, uint64_t threadAttemptStartTimestamp) {
Expand Down Expand Up @@ -1815,7 +1824,7 @@ void SQLiteNode::_changeState(SQLiteNodeState newState) {

if (newState != _state) {
// First, we notify all plugins about the state change
_server.notifyStateChangeToPlugins(_db, newState);
_server.notifyStateChangeToPlugins(*pluginDB, newState);

// If we were following, and now we're not, we give up an any replications.
if (_state == SQLiteNodeState::FOLLOWING) {
Expand Down
4 changes: 4 additions & 0 deletions sqlitecluster/SQLiteNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,8 @@ class SQLiteNode : public STCPManager {
// while we're online.
// In the event that this list becomes longer than half the cluster size, the node kills itself and logs that it's in an unrecoverable state.
set<string> _forkedFrom;

// A pointer to a SQLite instance that is passed to plugin's stateChanged function. This prevents plugins from operating on the same handle that
// the sync node is when they run queries in stateChanged.
SQLite* pluginDB;
};