mirror of
https://github.com/joyieldInc/predixy.git
synced 2026-02-05 01:42:24 +08:00
Fix critical lint issues and Linux build errors
This commit is contained in:
parent
23315178f0
commit
ce5c3419c3
@ -199,12 +199,13 @@ Buffer* Segment::fset(Buffer* buf, const char* fmt, ...)
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
try {
|
||||
return vfset(buf, fmt, ap);
|
||||
Buffer* result = vfset(buf, fmt, ap);
|
||||
va_end(ap);
|
||||
return result;
|
||||
} catch (...) {
|
||||
va_end(ap);
|
||||
throw;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Buffer* Segment::vfset(Buffer* buf, const char* fmt, va_list ap)
|
||||
|
||||
@ -75,6 +75,11 @@ struct StandaloneServerPoolConf : public ServerPoolConf
|
||||
std::vector<ServerGroupConf> groups;
|
||||
};
|
||||
|
||||
// SentinelServerPool uses the same configuration structure as StandaloneServerPool
|
||||
struct SentinelServerPoolConf : public StandaloneServerPoolConf
|
||||
{
|
||||
};
|
||||
|
||||
struct ReadPolicyConf
|
||||
{
|
||||
std::string name;
|
||||
|
||||
@ -143,6 +143,14 @@ ConnectConnection* ConnectConnectionPool::getPrivateConnection(int db)
|
||||
}
|
||||
if (c->fd() < 0) {
|
||||
if (mServ->fail()) {
|
||||
// Free the connection if it was newly created before returning
|
||||
if (needInit) {
|
||||
ConnectConnectionAlloc::destroy(c);
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(mStatsMtx);
|
||||
--mStats.connections;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
c->reopen();
|
||||
@ -155,7 +163,18 @@ ConnectConnection* ConnectConnectionPool::getPrivateConnection(int db)
|
||||
ccl.push_back(c);
|
||||
return nullptr;
|
||||
}
|
||||
return mServ->fail() ? nullptr : c;
|
||||
if (mServ->fail()) {
|
||||
// Free the connection if it was newly created before returning
|
||||
if (needInit) {
|
||||
ConnectConnectionAlloc::destroy(c);
|
||||
{
|
||||
std::lock_guard<std::mutex> lck(mStatsMtx);
|
||||
--mStats.connections;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
void ConnectConnectionPool::putPrivateConnection(ConnectConnection* s)
|
||||
|
||||
@ -670,7 +670,9 @@ bool Handler::preHandleRequest(Request* req, const String& key)
|
||||
int db = -1;
|
||||
if (key.toInt(db)) {
|
||||
if (db >= 0 && db < mProxy->serverPool()->dbNum()) {
|
||||
if (c) {
|
||||
c->setDb(db);
|
||||
}
|
||||
directResponse(req, Response::Ok);
|
||||
return true;
|
||||
}
|
||||
@ -1507,27 +1509,33 @@ void Handler::innerResponse(ConnectConnection* s, Request* req, Response* res)
|
||||
break;
|
||||
case Command::AuthServ:
|
||||
if (!res->isOk()) {
|
||||
if (s) {
|
||||
s->setStatus(ConnectConnection::LogicError);
|
||||
addPostEvent(s, Multiplexor::ErrorEvent);
|
||||
logWarn("h %d s %s %d auth fail",
|
||||
id(), s->peer(), s->fd());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Command::Readonly:
|
||||
if (!res->isOk()) {
|
||||
if (s) {
|
||||
s->setStatus(ConnectConnection::LogicError);
|
||||
addPostEvent(s, Multiplexor::ErrorEvent);
|
||||
logWarn("h %d s %s %d readonly fail",
|
||||
id(), s->peer(), s->fd());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Command::SelectServ:
|
||||
if (!res->isOk()) {
|
||||
if (s) {
|
||||
s->setStatus(ConnectConnection::LogicError);
|
||||
addPostEvent(s, Multiplexor::ErrorEvent);
|
||||
logWarn("h %d s %s %d db select %d fail",
|
||||
id(), s->peer(), s->fd(), s->db());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Command::ClusterNodes:
|
||||
case Command::SentinelSentinels:
|
||||
@ -1537,19 +1545,23 @@ void Handler::innerResponse(ConnectConnection* s, Request* req, Response* res)
|
||||
break;
|
||||
case Command::UnwatchServ:
|
||||
if (!res->isOk()) {
|
||||
if (s) {
|
||||
s->setStatus(ConnectConnection::LogicError);
|
||||
addPostEvent(s, Multiplexor::ErrorEvent);
|
||||
logWarn("h %d s %s %d unwatch fail",
|
||||
id(), s->peer(), s->fd(), s->db());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Command::DiscardServ:
|
||||
if (!res->isOk()) {
|
||||
if (s) {
|
||||
s->setStatus(ConnectConnection::LogicError);
|
||||
addPostEvent(s, Multiplexor::ErrorEvent);
|
||||
logWarn("h %d s %s %d discard fail",
|
||||
id(), s->peer(), s->fd(), s->db());
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -1574,7 +1586,7 @@ bool Handler::redirect(ConnectConnection* c, Request* req, Response* res, bool m
|
||||
}
|
||||
}
|
||||
auto p = static_cast<ClusterServerPool*>(mProxy->serverPool());
|
||||
Server* serv = p->redirect(addr, c->server());
|
||||
Server* serv = p->redirect(addr, c ? c->server() : nullptr);
|
||||
if (!serv) {
|
||||
logDebug("h %d req %ld %s redirect to %s can't get server",
|
||||
id(), req->id(), (moveOrAsk ? "MOVE" : "ASK"), addr.data());
|
||||
|
||||
@ -109,7 +109,9 @@ RequestParser::Status RequestParser::parse(Buffer* buf, int& pos, bool split)
|
||||
break;
|
||||
case InlineCmd:
|
||||
if (isspace(ch)) {
|
||||
mCmd[mArgLen < Const::MaxCmdLen ? mArgLen : Const::MaxCmdLen - 1] = '\0';
|
||||
// Ensure we don't write out of bounds
|
||||
int idx = (mArgLen >= 0 && mArgLen < Const::MaxCmdLen) ? mArgLen : Const::MaxCmdLen - 1;
|
||||
mCmd[idx] = '\0';
|
||||
parseCmd();
|
||||
mArgCnt = 1;
|
||||
if (ch == '\n') {
|
||||
@ -119,7 +121,8 @@ RequestParser::Status RequestParser::parse(Buffer* buf, int& pos, bool split)
|
||||
}
|
||||
mState = InlineArgBegin;
|
||||
} else {
|
||||
if (mArgLen < Const::MaxCmdLen) {
|
||||
// Only write if within bounds
|
||||
if (mArgLen >= 0 && mArgLen < Const::MaxCmdLen) {
|
||||
mCmd[mArgLen] = tolower(ch);
|
||||
}
|
||||
++mArgLen;
|
||||
@ -238,7 +241,8 @@ RequestParser::Status RequestParser::parse(Buffer* buf, int& pos, bool split)
|
||||
mCmd[Const::MaxCmdLen - 1] = '\0';
|
||||
ch == '\r' ? mState = CmdBodyLF : error = __LINE__;
|
||||
} else {
|
||||
if (mArgBodyCnt < Const::MaxCmdLen) {
|
||||
// Only write if within bounds
|
||||
if (mArgBodyCnt >= 0 && mArgBodyCnt < Const::MaxCmdLen) {
|
||||
mCmd[mArgBodyCnt] = ch;
|
||||
}
|
||||
++mArgBodyCnt;
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#include "Logger.h"
|
||||
#include "ServerGroup.h"
|
||||
#include "Handler.h"
|
||||
#include "Conf.h"
|
||||
#include "SentinelServerPool.h"
|
||||
|
||||
SentinelServerPool::SentinelServerPool(Proxy* p):
|
||||
|
||||
@ -20,7 +20,8 @@ public:
|
||||
{
|
||||
Unknown,
|
||||
Cluster,
|
||||
Standalone
|
||||
Standalone,
|
||||
Sentinel
|
||||
};
|
||||
static const int DefaultServerRetryTimeout = 10000000;
|
||||
static const int DefaultRefreshInterval = 1000000;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user