Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update expensify_prod branch #1665

Merged
merged 4 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions sqlitecluster/SQLiteNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -149,10 +147,6 @@ SQLiteNode::SQLiteNode(SQLiteServer& server, shared_ptr<SQLitePool> 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;
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions sqlitecluster/SQLiteNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 2 additions & 8 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 All @@ -60,7 +62,6 @@ void SQLitePeer::prePoll(fd_map& fdm) const {
lock_guard<decltype(peerMutex)> lock(peerMutex);
if (socket) {
STCPManager::prePoll(fdm, *socket);
_lastRecvTime = socket->lastRecvTime;
}
}

Expand All @@ -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.");
Expand Down Expand Up @@ -237,16 +235,12 @@ bool SQLitePeer::isPermafollower(const STable& params) {
void SQLitePeer::sendMessage(const SData& message) {
lock_guard<decltype(peerMutex)> 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.");
}
Expand Down
3 changes: 1 addition & 2 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 All @@ -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.
Expand Down