Skip to content

Commit

Permalink
addressing comment
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldoglas committed Dec 23, 2024
1 parent a7dffc0 commit 0434c8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 13 additions & 1 deletion sqlitecluster/SQLiteNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,19 @@ void SQLiteNode::_onMESSAGE(SQLitePeer* peer, const SData& message) {
peer->commandAddress = message["commandAddress"];
}
peer->setCommit(message.calcU64("CommitCount"), message["Hash"]);


// We check the commit difference with 12,500 commits behind because that
// represents ~30s of commits. If we're behind, let's close the command port
// so we can catch up with the cluster before processing new commands.
const int64_t currentCommitDifference = message.calcU64("NewCount") - getCommitCount();
const string blockReason = "COMMITS_LAGGING_BEHIND";
if (currentCommitDifference > 12'500 && !_blockedCommandPort) {
SINFO("Node is lagging behind, closing command port so it can catch up.");
_server.blockCommandPort(blockReason);
} else if (currentCommitDifference < 10'000 && _blockedCommandPort) {
SINFO("Node is caught up enough, unblocking command port.");
_server.unblockCommandPort(blockReason);
}
// Classify and process the message
if (SIEquals(message.methodLine, "LOGIN")) {
// LOGIN: This is the first message sent to and received from a new peer. It communicates the current state of
Expand Down
4 changes: 3 additions & 1 deletion sqlitecluster/SQLiteNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,9 @@ class SQLiteNode : public STCPManager {
// Our current State.
atomic<SQLiteNodeState> _state;

atomic<bool> _blockedCommandPort{false};
// Keeps track if we have closed the command port for commits fallen behind.
bool _blockedCommandPort{false};

// This is an integer that increments every time we change states. This is useful for responses to state changes
// (i.e., approving standup) to verify that the messages we're receiving are relevant to the current state change,
// and not stale responses to old changes.
Expand Down

0 comments on commit 0434c8b

Please sign in to comment.