Skip to content

Commit

Permalink
Merge pull request #1962 from Expensify/main
Browse files Browse the repository at this point in the history
Update expensify_prod branch
  • Loading branch information
justinpersaud authored Nov 18, 2024
2 parents b93ce05 + ffe0358 commit 6eca37a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions sqlitecluster/SQLiteNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,12 @@ int SQLiteNode::getPriority() const {
}

void SQLiteNode::setShutdownPriority() {
SINFO("Setting priority to 1, will stop leading if required.");
SINFO("Setting priority to 1.");
unique_lock<decltype(_stateMutex)> uniqueLock(_stateMutex);
_priority = 1;

if (_state == SQLiteNodeState::LEADING) {
_changeState(SQLiteNodeState::STANDINGDOWN);
SINFO("Will stop leading.");
} else {
SData state("STATE");
state["StateChangeCount"] = to_string(_stateChangeCount);
Expand Down Expand Up @@ -591,6 +591,7 @@ bool SQLiteNode::update() {
// If no peers, we're the leader, unless we're shutting down.
if (_peerList.empty()) {
SHMMM("No peers configured, jumping to LEADING");
_priority = _originalPriority;
_changeState(SQLiteNodeState::LEADING);

// Run `update` again immediately.
Expand Down Expand Up @@ -1124,7 +1125,9 @@ bool SQLiteNode::update() {
// Check to see if we should stand down. We'll finish any outstanding commits before we actually do.
if (_state == SQLiteNodeState::LEADING) {
string standDownReason;
if (_isShuttingDown) {
if (_priority == 1) {
standDownReason = "Priority changed to 1, standing down.";
} else if (_isShuttingDown) {
// Graceful shutdown. Set priority 1 and stand down so we'll re-connect to the new leader and finish
// up our commands.
standDownReason = "Shutting down, setting priority 1 and STANDINGDOWN.";
Expand Down

0 comments on commit 6eca37a

Please sign in to comment.