diff --git a/sqlitecluster/SQLiteNode.cpp b/sqlitecluster/SQLiteNode.cpp index 588369913..ff6172389 100644 --- a/sqlitecluster/SQLiteNode.cpp +++ b/sqlitecluster/SQLiteNode.cpp @@ -61,8 +61,6 @@ SQLiteNode* SQLiteNode::KILLABLE_SQLITE_NODE{0}; -bool SQLiteNode::IS_DB2_RNO = false; - // Initializations for static vars. const uint64_t SQLiteNode::RECV_TIMEOUT{STIME_US_PER_S * 30}; @@ -149,10 +147,6 @@ SQLiteNode::SQLiteNode(SQLiteServer& server, shared_ptr dbPool, cons _stateTimeout(STimeNow() + firstTimeout), _syncPeer(nullptr) { - if (_name == "auth.db2.rno") { - IS_DB2_RNO = true; - } - KILLABLE_SQLITE_NODE = this; SASSERT(_originalPriority >= 0); onPrepareHandlerEnabled = false; @@ -2631,18 +2625,15 @@ void SQLiteNode::postPoll(fd_map& fdm, uint64_t& nextActivity) { break; case SQLitePeer::PeerPostPollStatus::OK: { + auto lastRecvTime = peer->lastRecvTime(); auto now = STimeNow(); - if (IS_DB2_RNO && peer->state != SQLiteNodeState::LEADING) { - SINFO("Peer " << peer->name << " lastSent: " << (now - peer->lastSendTime()) << "us ago, lastRecv'ed: " << (now - peer->lastRecvTime()) << "us ago. (raw lastRecvTime: " - << peer->lastSendTime() << ", raw lastSendTime: " << peer->lastRecvTime() << ")"); - } - auto lastActivityTime = max(peer->lastSendTime(), peer->lastRecvTime()); - if (lastActivityTime && now - lastActivityTime > SQLiteNode::RECV_TIMEOUT - 5 * STIME_US_PER_S) { - SINFO("Close to timeout (" << (now - lastActivityTime) << "us since last activity), sending PING to peer '" << peer->name << "'"); - _sendPING(peer); - } else { - if (IS_DB2_RNO && peer->state != SQLiteNodeState::LEADING) { - SINFO("Not close to timeout for peer " << peer->name << ", lastActivityTime: " << lastActivityTime << ", now: " << now); + 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 { diff --git a/sqlitecluster/SQLiteNode.h b/sqlitecluster/SQLiteNode.h index 522cba31c..1244f0cfa 100644 --- a/sqlitecluster/SQLiteNode.h +++ b/sqlitecluster/SQLiteNode.h @@ -68,8 +68,6 @@ class SQLiteNode : public STCPManager { FAILED }; - static bool IS_DB2_RNO; - // Write consistencies available enum ConsistencyLevel { ASYNC, // Fully asynchronous write, no follower approval required. diff --git a/sqlitecluster/SQLitePeer.cpp b/sqlitecluster/SQLitePeer.cpp index 8832d14ae..4b8a12bc1 100644 --- a/sqlitecluster/SQLitePeer.cpp +++ b/sqlitecluster/SQLitePeer.cpp @@ -22,6 +22,7 @@ SQLitePeer::SQLitePeer(const string& name_, const string& host_, const STable& p subscribed(false), transactionResponse(Response::NONE), version(), + lastPingTime(0), hash() { } @@ -46,6 +47,7 @@ void SQLitePeer::reset() { subscribed = false; transactionResponse = Response::NONE; version = ""; + lastPingTime = 0, setCommit(0, ""); } @@ -60,7 +62,6 @@ void SQLitePeer::prePoll(fd_map& fdm) const { lock_guard lock(peerMutex); if (socket) { STCPManager::prePoll(fdm, *socket); - _lastRecvTime = socket->lastRecvTime; } } @@ -72,9 +73,6 @@ SQLitePeer::PeerPostPollStatus SQLitePeer::postPoll(fd_map& fdm, uint64_t& nextA // We have a socket; process based on its state switch (socket->state.load()) { case STCPManager::Socket::CONNECTED: { - if (SQLiteNode::IS_DB2_RNO && state != SQLiteNodeState::LEADING && _lastRecvTime != socket->lastRecvTime) { - SINFO("Updated last recv time from peer " << name); - } // socket->lastRecvTime is always set, it's initialized to STimeNow() at creation. if (socket->lastRecvTime + SQLiteNode::RECV_TIMEOUT < STimeNow()) { SHMMM("Connection with peer '" << name << "' timed out."); @@ -237,16 +235,12 @@ bool SQLitePeer::isPermafollower(const STable& params) { void SQLitePeer::sendMessage(const SData& message) { lock_guard lock(peerMutex); if (socket) { - uint64_t lastSendTime = socket->lastSendTime; size_t bytesSent = 0; if (socket->send(message.serialize(), &bytesSent)) { SINFO("No error sending " << message.methodLine << " to peer " << name << " (" << bytesSent << " bytes actually sent)."); } else { SHMMM("Error sending " << message.methodLine << " to peer " << name << "."); } - if (SQLiteNode::IS_DB2_RNO && state != SQLiteNodeState::LEADING && lastSendTime != socket->lastSendTime) { - SINFO("Updated last send time to peer " << name); - } } else { SINFO("Tried to send " << message.methodLine << " to peer " << name << ", but not available."); } diff --git a/sqlitecluster/SQLitePeer.h b/sqlitecluster/SQLitePeer.h index ff436b590..cb3e07ff3 100644 --- a/sqlitecluster/SQLitePeer.h +++ b/sqlitecluster/SQLitePeer.h @@ -86,6 +86,7 @@ class SQLitePeer { atomic subscribed; atomic transactionResponse; atomic version; + atomic lastPingTime; private: // For initializing the permafollower value from the params list. @@ -99,8 +100,6 @@ class SQLitePeer { // Not named with an underscore because it's only sort-of private (see friend class declaration above). STCPManager::Socket* socket = nullptr; - - mutable uint64_t _lastRecvTime = 0; }; // serialization for Responses.