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

Merged
merged 3 commits into from
Sep 25, 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
52 changes: 31 additions & 21 deletions sqlitecluster/SQLiteNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,28 +689,38 @@ bool SQLiteNode::update() {
SQLitePeer* freshestPeer = nullptr;
SQLitePeer* currentLeader = nullptr;
for (auto peer : _peerList) {
// Make sure we're a full peer
if (!peer->permaFollower) {
// Verify we're logged in
++numFullPeers;
if (peer->loggedIn) {
// Verify we're still fresh
++numLoggedInFullPeers;
if (!freshestPeer || peer->commitCount > freshestPeer->commitCount)
freshestPeer = peer;

// See if it's the highest priority
if (!highestPriorityPeer || peer->priority > highestPriorityPeer->priority)
highestPriorityPeer = peer;

// See if it is currently the leader (or standing up/down)
if (peer->state == SQLiteNodeState::STANDINGUP || peer->state == SQLiteNodeState::LEADING || peer->state == SQLiteNodeState::STANDINGDOWN) {
// Found the current leader
if (currentLeader)
PHMMM("Multiple peers trying to stand up (also '" << currentLeader->name
<< "'), let's hope they sort it out.");
currentLeader = peer;
if (peer->permaFollower) {
// Permafollowers are treated as ineligible for leader, etc.
continue;
}

if (_forkedFrom.count(peer->name)) {
// Forked nodes are treated as ineligible for leader, etc.
SHMMM("Not counting forked peer " << peer->name << " for freshest, highestPriority, or currentLeader.");
continue;
}

// Verify we're logged in
++numFullPeers;
if (peer->loggedIn) {
// Verify we're still fresh
++numLoggedInFullPeers;
if (!freshestPeer || peer->commitCount > freshestPeer->commitCount) {
freshestPeer = peer;
}

// See if it's the highest priority
if (!highestPriorityPeer || peer->priority > highestPriorityPeer->priority) {
highestPriorityPeer = peer;
}

// See if it is currently the leader (or standing up/down)
if (peer->state == SQLiteNodeState::STANDINGUP || peer->state == SQLiteNodeState::LEADING || peer->state == SQLiteNodeState::STANDINGDOWN) {
// Found the current leader
if (currentLeader) {
PHMMM("Multiple peers trying to stand up (also '" << currentLeader->name << "'), let's hope they sort it out.");
}
currentLeader = peer;
}
}
}
Expand Down