-
Notifications
You must be signed in to change notification settings - Fork 76
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
add more log for easy debug & track connection state #92
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,18 +164,15 @@ void Connection::close() { | |
|
||
bool Connection::tryReconnect() { | ||
if (!m_alive) { | ||
time_t now; | ||
time(&now); | ||
time_t now = time(NULL); | ||
if (now >= m_deadUntil) { | ||
int rv = this->connect(); | ||
if (rv == 0) { | ||
if (m_deadUntil > 0) { | ||
log_info("Connection %s is back to live at %lu", m_name, now); | ||
} | ||
log_info_if(m_deadUntil > 0, "[I: %p] %s is back to live at %lu", this, m_name, now); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tclh123 https://github.com/douban/libmc/blob/master/src/Connection.cpp#L49-L52 m_name is "host:port" or alias。it's readable。but when need to debug & track reconnecting,pointer address is useful。 |
||
m_deadUntil = 0; | ||
} else { | ||
m_deadUntil = now + m_retryTimeout; | ||
// log_info("%s is still dead", m_name); | ||
log_info("[I: %p] %s is still dead", this, m_name); | ||
} | ||
} | ||
} | ||
|
@@ -188,14 +185,16 @@ void Connection::markDead(const char* reason, int delay) { | |
m_deadUntil += delay; // check after `delay` seconds, default 0 | ||
this->close(); | ||
if (strcmp(reason, keywords::kCONN_QUIT) != 0) { | ||
log_warn("Connection %s is dead(reason: %s, delay: %d), next check at %lu", | ||
m_name, reason, delay, m_deadUntil); | ||
log_warn("[I: %p] %s is dead(reason: %s, delay: %d), next check at %lu", | ||
this, m_name, reason, delay, m_deadUntil); | ||
#ifndef NDEBUG | ||
std::queue<struct iovec>* q = m_parser.getRequestKeys(); | ||
if (!q->empty()) { | ||
log_warn("%s: first request key: %.*s", m_name, | ||
log_debug("[I: %p] %s first request key: %.*s", this, m_name, | ||
static_cast<int>(q->front().iov_len), | ||
static_cast<char*>(q->front().iov_base)); | ||
} | ||
#endif | ||
} | ||
} | ||
} | ||
|
@@ -209,6 +208,7 @@ void Connection::takeBuffer(const char* const buf, size_t buf_len) { | |
} | ||
|
||
void Connection::addRequestKey(const char* const key, const size_t len) { | ||
log_debug("[I: %p] %s add request key: %.*s", this, m_name, static_cast<int>(len), key); | ||
m_parser.addRequestKey(key, len); | ||
} | ||
|
||
|
@@ -261,7 +261,8 @@ ssize_t Connection::recv() { | |
size_t bufferSizeAvailable = m_buffer_reader->prepareWriteBlock(bufferSize); | ||
char* writePtr = m_buffer_reader->getWritePtr(); | ||
ssize_t bufferSizeActual = ::recv(m_socketFd, writePtr, bufferSizeAvailable, 0); | ||
// log_info("%p recv(%lu) %.*s", this, bufferSizeActual, (int)bufferSizeActual, writePtr); | ||
log_debug("[I: %p] %s recv(%lu)", this, m_name, bufferSizeActual); | ||
// log_debug("[I: %p] %.*s", (int)bufferSizeActual, writePtr); | ||
if (bufferSizeActual > 0) { | ||
m_buffer_reader->commitWrite(bufferSizeActual); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICS, it's no need to add log here, because the user can get
rv
andclient
outside.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tclh123 also because pointer address。