Skip to content

Commit

Permalink
Merge pull request #1551 from Expensify/cole_use_pool
Browse files Browse the repository at this point in the history
Use a handle from the existing pool instead of a new one
  • Loading branch information
danieldoglas authored Jul 31, 2023
2 parents 880f247 + 04dc044 commit f883da1
Showing 1 changed file with 11 additions and 11 deletions.
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

0 comments on commit f883da1

Please sign in to comment.