Skip to content

Commit

Permalink
Ping more reliably
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerkaraszewski committed Mar 7, 2024
1 parent 029b03e commit 5b557a2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
14 changes: 10 additions & 4 deletions sqlitecluster/SQLiteNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2625,10 +2625,16 @@ void SQLiteNode::postPoll(fd_map& fdm, uint64_t& nextActivity) {
break;
case SQLitePeer::PeerPostPollStatus::OK:
{
auto lastActivityTime = max(peer->lastSendTime(), peer->lastRecvTime());
if (lastActivityTime && STimeNow() - lastActivityTime > SQLiteNode::RECV_TIMEOUT - 5 * STIME_US_PER_S) {
SINFO("Close to timeout (" << (STimeNow() - lastActivityTime) << "us since last activity), sending PING to peer '" << peer->name << "'");
_sendPING(peer);
auto lastRecvTime = peer->lastRecvTime();
auto now = STimeNow();
auto elapsed = (now - lastRecvTime);
if (lastRecvTime && elapsed > SQLiteNode::RECV_TIMEOUT - 5 * STIME_US_PER_S) {
// Ping the peer (unless it's been less that 1 second since the last ping).
if (now > (peer->lastPingTime + 1'000'000)) {
SINFO("Close to timeout (" << elapsed << "us since last activity), sending PING to peer '" << peer->name << "'");
peer->lastPingTime = now;
_sendPING(peer);
}
}
try {
size_t messagesDeqeued = 0;
Expand Down
2 changes: 2 additions & 0 deletions sqlitecluster/SQLitePeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SQLitePeer::SQLitePeer(const string& name_, const string& host_, const STable& p
subscribed(false),
transactionResponse(Response::NONE),
version(),
lastPingTime(0),
hash()
{ }

Expand All @@ -46,6 +47,7 @@ void SQLitePeer::reset() {
subscribed = false;
transactionResponse = Response::NONE;
version = "";
lastPingTime = 0,
setCommit(0, "");
}

Expand Down
1 change: 1 addition & 0 deletions sqlitecluster/SQLitePeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class SQLitePeer {
atomic<bool> subscribed;
atomic<Response> transactionResponse;
atomic<string> version;
atomic<uint64_t> lastPingTime;

private:
// For initializing the permafollower value from the params list.
Expand Down

0 comments on commit 5b557a2

Please sign in to comment.