diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c7b0ca1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +src/*.o +.idea/ +.vscode/ +src/predixy diff --git a/src/ConnectConnectionPool.cpp b/src/ConnectConnectionPool.cpp index e4ea3e1..d2843e0 100644 --- a/src/ConnectConnectionPool.cpp +++ b/src/ConnectConnectionPool.cpp @@ -59,6 +59,7 @@ ConnectConnection* ConnectConnectionPool::getShareConnection(int db) return c; } +// func ini entah dipanggil oleh siapa ConnectConnection* ConnectConnectionPool::getPrivateConnection(int db) { FuncCallTimer(); diff --git a/src/Handler.cpp b/src/Handler.cpp index 6633a02..5ebf860 100644 --- a/src/Handler.cpp +++ b/src/Handler.cpp @@ -121,6 +121,7 @@ int Handler::checkServerTimeout(long timeout) if (auto req = s->frontRequest()) { long elapsed = now - req->createTime(); if (elapsed >= timeout) { + logError("ibk: SET_STATUS TIMEOUT ERROR: %d",Connection::TimeoutError); s->setStatus(Connection::TimeoutError); addPostEvent(s, Multiplexor::ErrorEvent); mWaitConnectConns.remove(s); @@ -241,7 +242,7 @@ void Handler::postConnectConnectionEvent() if (finished) { ret = mEventLoop->delEvent(s, Multiplexor::WriteEvent); } else { - ret = mEventLoop->addEvent(s, Multiplexor::WriteEvent); + ret = mEventLoop->addEvent(s, Multiplexor::WriteEvent); // ibk: add to the epoll } if (!ret) { s->setStatus(Multiplexor::ErrorEvent); @@ -259,7 +260,7 @@ void Handler::postConnectConnectionEvent() case Socket::EventError: { Server* serv = s->server(); - serv->incrFail(); // increase fail counter only for EventError + serv->incrFail(); // ibk:increase fail counter only for EventError, mark as failed if exceed threshold if (serv->fail()) { logNotice("server %s mark failure", serv->addr().data()); } @@ -498,6 +499,9 @@ int Handler::checkClientTimeout(long timeout) return num; } +// when entering this function, predixy already split multi keys command into multiple commands +// e.g. client send : mget a b +// this func will receive `mget a` and `mget b` void Handler::handleRequest(Request* req) { FuncCallTimer(); @@ -533,6 +537,7 @@ void Handler::handleRequest(Request* req) if (s->isShared()) { mConnPool[serv->id()]->incrPendRequests(); } + // ibk: these three lines only add the event in the corresponding queues s->send(this, req); addPostEvent(s, Multiplexor::WriteEvent); postHandleRequest(req, s); @@ -1368,6 +1373,7 @@ void Handler::innerResponse(ConnectConnection* s, Request* req, Response* res) if (s && res->isPong()) { Server* serv = s->server(); if (serv->fail()) { + logError("ibk: MARK SERVER NOT FAIL BASED ON THE PING"); serv->setFail(false); // if server respond to ping, mark fail as false. TODO: add for other case like loading logNotice("h %d s %s %d mark server alive", id(), s->peer(), s->fd()); diff --git a/src/Server.h b/src/Server.h index 328d5ab..fe5132d 100644 --- a/src/Server.h +++ b/src/Server.h @@ -106,6 +106,7 @@ public: } void setFail(bool v) { + logError("ibk: SET setFail:%d", v); mFail = v; } bool online() const @@ -114,6 +115,7 @@ public: } void setOnline(bool v) { + logError("[ibk: SET_ONLINE SetOnline:%d", v); mOnline = v; } bool updating() const diff --git a/src/ServerGroup.cpp b/src/ServerGroup.cpp index e5d088c..527a62a 100644 --- a/src/ServerGroup.cpp +++ b/src/ServerGroup.cpp @@ -69,6 +69,7 @@ Server* ServerGroup::getServer(Handler* h, Request* req) const return serv; } +// ibk:get the server for the read operation Server* ServerGroup::getReadServer(Handler* h) const { FuncCallTimer(); @@ -80,9 +81,10 @@ Server* ServerGroup::getReadServer(Handler* h) const int dprior = 0; int pendRequests = INT_MAX; int cnt = mServs.size(); + for (int i = 0; i < cnt; ++i) { Server* s = mServs[i]; - if (!s->online()) { + if (!s->online()) { // make sure it is online continue; } int rp = 0; @@ -94,6 +96,8 @@ Server* ServerGroup::getReadServer(Handler* h) const if (rp <= 0) { continue; } + // ibk: if it is fail: + // - put into deadServs list and use another server if (s->fail()) { if (rp > dprior) { dprior = rp; diff --git a/src/Socket.h b/src/Socket.h index 07508fd..556f765 100644 --- a/src/Socket.h +++ b/src/Socket.h @@ -20,6 +20,7 @@ #include #include #include "Exception.h" +#include "Logger.h" class Socket { @@ -82,6 +83,7 @@ public: const char* statusStr() const; void setStatus(int st) { + logError("ibk: SET_STATUS setStatus %d", st); mStatus = st; } int getEvent() const