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_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
try {
|
try {
|
||||||
return vfset(buf, fmt, ap);
|
Buffer* result = vfset(buf, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return result;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
return nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer* Segment::vfset(Buffer* buf, const char* fmt, va_list ap)
|
Buffer* Segment::vfset(Buffer* buf, const char* fmt, va_list ap)
|
||||||
|
|||||||
@ -75,6 +75,11 @@ struct StandaloneServerPoolConf : public ServerPoolConf
|
|||||||
std::vector<ServerGroupConf> groups;
|
std::vector<ServerGroupConf> groups;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// SentinelServerPool uses the same configuration structure as StandaloneServerPool
|
||||||
|
struct SentinelServerPoolConf : public StandaloneServerPoolConf
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
struct ReadPolicyConf
|
struct ReadPolicyConf
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|||||||
@ -143,6 +143,14 @@ ConnectConnection* ConnectConnectionPool::getPrivateConnection(int db)
|
|||||||
}
|
}
|
||||||
if (c->fd() < 0) {
|
if (c->fd() < 0) {
|
||||||
if (mServ->fail()) {
|
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 nullptr;
|
||||||
}
|
}
|
||||||
c->reopen();
|
c->reopen();
|
||||||
@ -155,7 +163,18 @@ ConnectConnection* ConnectConnectionPool::getPrivateConnection(int db)
|
|||||||
ccl.push_back(c);
|
ccl.push_back(c);
|
||||||
return nullptr;
|
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)
|
void ConnectConnectionPool::putPrivateConnection(ConnectConnection* s)
|
||||||
|
|||||||
@ -670,7 +670,9 @@ bool Handler::preHandleRequest(Request* req, const String& key)
|
|||||||
int db = -1;
|
int db = -1;
|
||||||
if (key.toInt(db)) {
|
if (key.toInt(db)) {
|
||||||
if (db >= 0 && db < mProxy->serverPool()->dbNum()) {
|
if (db >= 0 && db < mProxy->serverPool()->dbNum()) {
|
||||||
c->setDb(db);
|
if (c) {
|
||||||
|
c->setDb(db);
|
||||||
|
}
|
||||||
directResponse(req, Response::Ok);
|
directResponse(req, Response::Ok);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1507,26 +1509,32 @@ void Handler::innerResponse(ConnectConnection* s, Request* req, Response* res)
|
|||||||
break;
|
break;
|
||||||
case Command::AuthServ:
|
case Command::AuthServ:
|
||||||
if (!res->isOk()) {
|
if (!res->isOk()) {
|
||||||
s->setStatus(ConnectConnection::LogicError);
|
if (s) {
|
||||||
addPostEvent(s, Multiplexor::ErrorEvent);
|
s->setStatus(ConnectConnection::LogicError);
|
||||||
logWarn("h %d s %s %d auth fail",
|
addPostEvent(s, Multiplexor::ErrorEvent);
|
||||||
id(), s->peer(), s->fd());
|
logWarn("h %d s %s %d auth fail",
|
||||||
|
id(), s->peer(), s->fd());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Command::Readonly:
|
case Command::Readonly:
|
||||||
if (!res->isOk()) {
|
if (!res->isOk()) {
|
||||||
s->setStatus(ConnectConnection::LogicError);
|
if (s) {
|
||||||
addPostEvent(s, Multiplexor::ErrorEvent);
|
s->setStatus(ConnectConnection::LogicError);
|
||||||
logWarn("h %d s %s %d readonly fail",
|
addPostEvent(s, Multiplexor::ErrorEvent);
|
||||||
id(), s->peer(), s->fd());
|
logWarn("h %d s %s %d readonly fail",
|
||||||
|
id(), s->peer(), s->fd());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Command::SelectServ:
|
case Command::SelectServ:
|
||||||
if (!res->isOk()) {
|
if (!res->isOk()) {
|
||||||
s->setStatus(ConnectConnection::LogicError);
|
if (s) {
|
||||||
addPostEvent(s, Multiplexor::ErrorEvent);
|
s->setStatus(ConnectConnection::LogicError);
|
||||||
logWarn("h %d s %s %d db select %d fail",
|
addPostEvent(s, Multiplexor::ErrorEvent);
|
||||||
id(), s->peer(), s->fd(), s->db());
|
logWarn("h %d s %s %d db select %d fail",
|
||||||
|
id(), s->peer(), s->fd(), s->db());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Command::ClusterNodes:
|
case Command::ClusterNodes:
|
||||||
@ -1537,18 +1545,22 @@ void Handler::innerResponse(ConnectConnection* s, Request* req, Response* res)
|
|||||||
break;
|
break;
|
||||||
case Command::UnwatchServ:
|
case Command::UnwatchServ:
|
||||||
if (!res->isOk()) {
|
if (!res->isOk()) {
|
||||||
s->setStatus(ConnectConnection::LogicError);
|
if (s) {
|
||||||
addPostEvent(s, Multiplexor::ErrorEvent);
|
s->setStatus(ConnectConnection::LogicError);
|
||||||
logWarn("h %d s %s %d unwatch fail",
|
addPostEvent(s, Multiplexor::ErrorEvent);
|
||||||
id(), s->peer(), s->fd(), s->db());
|
logWarn("h %d s %s %d unwatch fail",
|
||||||
|
id(), s->peer(), s->fd(), s->db());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Command::DiscardServ:
|
case Command::DiscardServ:
|
||||||
if (!res->isOk()) {
|
if (!res->isOk()) {
|
||||||
s->setStatus(ConnectConnection::LogicError);
|
if (s) {
|
||||||
addPostEvent(s, Multiplexor::ErrorEvent);
|
s->setStatus(ConnectConnection::LogicError);
|
||||||
logWarn("h %d s %s %d discard fail",
|
addPostEvent(s, Multiplexor::ErrorEvent);
|
||||||
id(), s->peer(), s->fd(), s->db());
|
logWarn("h %d s %s %d discard fail",
|
||||||
|
id(), s->peer(), s->fd(), s->db());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -1574,7 +1586,7 @@ bool Handler::redirect(ConnectConnection* c, Request* req, Response* res, bool m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto p = static_cast<ClusterServerPool*>(mProxy->serverPool());
|
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) {
|
if (!serv) {
|
||||||
logDebug("h %d req %ld %s redirect to %s can't get server",
|
logDebug("h %d req %ld %s redirect to %s can't get server",
|
||||||
id(), req->id(), (moveOrAsk ? "MOVE" : "ASK"), addr.data());
|
id(), req->id(), (moveOrAsk ? "MOVE" : "ASK"), addr.data());
|
||||||
|
|||||||
@ -109,7 +109,9 @@ RequestParser::Status RequestParser::parse(Buffer* buf, int& pos, bool split)
|
|||||||
break;
|
break;
|
||||||
case InlineCmd:
|
case InlineCmd:
|
||||||
if (isspace(ch)) {
|
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();
|
parseCmd();
|
||||||
mArgCnt = 1;
|
mArgCnt = 1;
|
||||||
if (ch == '\n') {
|
if (ch == '\n') {
|
||||||
@ -119,7 +121,8 @@ RequestParser::Status RequestParser::parse(Buffer* buf, int& pos, bool split)
|
|||||||
}
|
}
|
||||||
mState = InlineArgBegin;
|
mState = InlineArgBegin;
|
||||||
} else {
|
} else {
|
||||||
if (mArgLen < Const::MaxCmdLen) {
|
// Only write if within bounds
|
||||||
|
if (mArgLen >= 0 && mArgLen < Const::MaxCmdLen) {
|
||||||
mCmd[mArgLen] = tolower(ch);
|
mCmd[mArgLen] = tolower(ch);
|
||||||
}
|
}
|
||||||
++mArgLen;
|
++mArgLen;
|
||||||
@ -238,7 +241,8 @@ RequestParser::Status RequestParser::parse(Buffer* buf, int& pos, bool split)
|
|||||||
mCmd[Const::MaxCmdLen - 1] = '\0';
|
mCmd[Const::MaxCmdLen - 1] = '\0';
|
||||||
ch == '\r' ? mState = CmdBodyLF : error = __LINE__;
|
ch == '\r' ? mState = CmdBodyLF : error = __LINE__;
|
||||||
} else {
|
} else {
|
||||||
if (mArgBodyCnt < Const::MaxCmdLen) {
|
// Only write if within bounds
|
||||||
|
if (mArgBodyCnt >= 0 && mArgBodyCnt < Const::MaxCmdLen) {
|
||||||
mCmd[mArgBodyCnt] = ch;
|
mCmd[mArgBodyCnt] = ch;
|
||||||
}
|
}
|
||||||
++mArgBodyCnt;
|
++mArgBodyCnt;
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "ServerGroup.h"
|
#include "ServerGroup.h"
|
||||||
#include "Handler.h"
|
#include "Handler.h"
|
||||||
|
#include "Conf.h"
|
||||||
#include "SentinelServerPool.h"
|
#include "SentinelServerPool.h"
|
||||||
|
|
||||||
SentinelServerPool::SentinelServerPool(Proxy* p):
|
SentinelServerPool::SentinelServerPool(Proxy* p):
|
||||||
|
|||||||
@ -20,7 +20,8 @@ public:
|
|||||||
{
|
{
|
||||||
Unknown,
|
Unknown,
|
||||||
Cluster,
|
Cluster,
|
||||||
Standalone
|
Standalone,
|
||||||
|
Sentinel
|
||||||
};
|
};
|
||||||
static const int DefaultServerRetryTimeout = 10000000;
|
static const int DefaultServerRetryTimeout = 10000000;
|
||||||
static const int DefaultRefreshInterval = 1000000;
|
static const int DefaultRefreshInterval = 1000000;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user