Skip to content

Commit

Permalink
Merge branch 'dsilva_blockingCommandPortWhenNotCaughtUp' into dsilva_…
Browse files Browse the repository at this point in the history
…chooseSyncPeerOtherThanLeader
  • Loading branch information
danieldoglas committed Dec 24, 2024
2 parents 5ba847e + 9da7bf2 commit a16718b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions sqlitecluster/SQLiteNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,13 +1283,17 @@ void SQLiteNode::_onMESSAGE(SQLitePeer* peer, const SData& message) {
// 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 string blockReason = "COMMITS_LAGGING_BEHIND";
const int64_t currentCommitDifference = getCommitCount() - peer->commitCount;
if (peer == _leadPeer && currentCommitDifference >= 12'500 && !_blockedCommandPort) {
SINFO("Node is lagging behind, closing command port so it can catch up.");
const int64_t currentCommitDifference = peer->commitCount - getCommitCount();
if (peer == _leadPeer && currentCommitDifference >= 12'500 && !_blockedCommandPortForBeingBehind) {
SINFO("Node is behind by " + SToStr(currentCommitDifference) + " commits, closing command port so it can catch up.");
_server.blockCommandPort(blockReason);
} else if (currentCommitDifference < 1'000 && _blockedCommandPort) {
SINFO("Node is caught up enough, unblocking command port.");
_blockedCommandPortForBeingBehind = true;
} else if (currentCommitDifference < 1'000 && _blockedCommandPortForBeingBehind) {
// We'll open the command port again if we're 1k commits behind, which
// translates to ~2s of commits.
SINFO("Node is caught up enough (behind by " + SToStr(currentCommitDifference) + " commits), re-opening command port.");
_server.unblockCommandPort(blockReason);
_blockedCommandPortForBeingBehind = false;
}
// Classify and process the message
if (SIEquals(message.methodLine, "LOGIN")) {
Expand Down
2 changes: 1 addition & 1 deletion sqlitecluster/SQLiteNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class SQLiteNode : public STCPManager {
atomic<SQLiteNodeState> _state;

// Keeps track if we have closed the command port for commits fallen behind.
bool _blockedCommandPort{false};
bool _blockedCommandPortForBeingBehind{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,
Expand Down

0 comments on commit a16718b

Please sign in to comment.