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 #1552

Merged
merged 2 commits into from
Jul 31, 2023
Merged
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
22 changes: 11 additions & 11 deletions sqlitecluster/SQLiteNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ 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 @@ -154,10 +150,6 @@ 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 @@ -1823,8 +1815,16 @@ void SQLiteNode::_changeState(SQLiteNodeState newState) {
_localCommitNotifier.notifyThrough(_db.getCommitCount());

if (newState != _state) {
// First, we notify all plugins about the state change
_server.notifyStateChangeToPlugins(*pluginDB, newState);
{
// We get a new 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.
SQLiteScopedHandle dbScope(*_dbPool, _dbPool->getIndex());
SQLite& pluginDB = dbScope.db();

// First, we notify all plugins about the state change
_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