mirror of
https://github.com/sogou/workflow.git
synced 2026-02-08 01:33:17 +08:00
Add 'fixed_conn' for WFNSParams. (#1550)
This commit is contained in:
@@ -241,7 +241,7 @@ CommMessageOut *ComplexMySQLTask::message_out()
|
||||
break;
|
||||
|
||||
case ST_FIRST_USER_REQUEST:
|
||||
if (this->is_fixed_addr())
|
||||
if (this->is_fixed_conn())
|
||||
{
|
||||
auto *target = (RouteManager::RouteTarget *)this->target;
|
||||
|
||||
@@ -717,9 +717,9 @@ bool ComplexMySQLTask::init_success()
|
||||
|
||||
if (!transaction.empty())
|
||||
{
|
||||
this->WFComplexClientTask::set_info(std::string("?maxconn=1&") +
|
||||
info + "|txn:" + transaction);
|
||||
this->set_fixed_addr(true);
|
||||
this->set_fixed_conn(true);
|
||||
this->WFComplexClientTask::set_info(info + ("|txn:" + transaction));
|
||||
}
|
||||
else
|
||||
this->WFComplexClientTask::set_info(info);
|
||||
@@ -746,7 +746,7 @@ bool ComplexMySQLTask::finish_once()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this->is_fixed_addr())
|
||||
if (this->is_fixed_conn())
|
||||
{
|
||||
if (this->state != WFT_STATE_SUCCESS || this->keep_alive_timeo == 0)
|
||||
{
|
||||
@@ -772,7 +772,7 @@ WFMySQLTask *WFTaskFactory::create_mysql_task(const std::string& url,
|
||||
|
||||
URIParser::parse(url, uri);
|
||||
task->init(std::move(uri));
|
||||
if (task->is_fixed_addr())
|
||||
if (task->is_fixed_conn())
|
||||
task->set_keep_alive(MYSQL_KEEPALIVE_TRANSACTION);
|
||||
else
|
||||
task->set_keep_alive(MYSQL_KEEPALIVE_DEFAULT);
|
||||
@@ -787,7 +787,7 @@ WFMySQLTask *WFTaskFactory::create_mysql_task(const ParsedURI& uri,
|
||||
auto *task = new ComplexMySQLTask(retry_max, std::move(callback));
|
||||
|
||||
task->init(uri);
|
||||
if (task->is_fixed_addr())
|
||||
if (task->is_fixed_conn())
|
||||
task->set_keep_alive(MYSQL_KEEPALIVE_TRANSACTION);
|
||||
else
|
||||
task->set_keep_alive(MYSQL_KEEPALIVE_DEFAULT);
|
||||
|
||||
@@ -78,6 +78,7 @@ public:
|
||||
type_ = TT_TCP;
|
||||
ssl_ctx_ = NULL;
|
||||
fixed_addr_ = false;
|
||||
fixed_conn_ = false;
|
||||
retry_max_ = retry_max;
|
||||
retry_times_ = 0;
|
||||
redirect_ = false;
|
||||
@@ -137,9 +138,13 @@ public:
|
||||
|
||||
bool is_fixed_addr() const { return this->fixed_addr_; }
|
||||
|
||||
bool is_fixed_conn() const { return this->fixed_conn_; }
|
||||
|
||||
protected:
|
||||
void set_fixed_addr(int fixed) { this->fixed_addr_ = fixed; }
|
||||
|
||||
void set_fixed_conn(int fixed) { this->fixed_conn_ = fixed; }
|
||||
|
||||
void set_info(const std::string& info)
|
||||
{
|
||||
info_.assign(info);
|
||||
@@ -174,6 +179,7 @@ protected:
|
||||
std::string info_;
|
||||
SSL_CTX *ssl_ctx_;
|
||||
bool fixed_addr_;
|
||||
bool fixed_conn_;
|
||||
bool redirect_;
|
||||
CTX ctx_;
|
||||
int retry_max_;
|
||||
@@ -322,6 +328,7 @@ WFRouterTask *WFComplexClientTask<REQ, RESP, CTX>::route()
|
||||
.info = info_.c_str(),
|
||||
.ssl_ctx = ssl_ctx_,
|
||||
.fixed_addr = fixed_addr_,
|
||||
.fixed_conn = fixed_conn_,
|
||||
.retry_times = retry_times_,
|
||||
.tracing = &tracing_,
|
||||
};
|
||||
|
||||
@@ -547,13 +547,6 @@ int RouteManager::get(enum TransportType type,
|
||||
.hostname = hostname,
|
||||
};
|
||||
|
||||
if (StringUtil::start_with(other_info, "?maxconn="))
|
||||
{
|
||||
int maxconn = atoi(other_info.c_str() + 9);
|
||||
if (maxconn > 0)
|
||||
params.max_connections = maxconn;
|
||||
}
|
||||
|
||||
entry = new RouteResultEntry;
|
||||
if (entry->init(¶ms) >= 0)
|
||||
{
|
||||
|
||||
@@ -35,6 +35,9 @@ public:
|
||||
ns_params_(*ns_params),
|
||||
ep_params_(*ep_params)
|
||||
{
|
||||
if (ns_params_.fixed_conn)
|
||||
ep_params_.max_connections = 1;
|
||||
|
||||
dns_ttl_default_ = dns_ttl_default;
|
||||
dns_ttl_min_ = dns_ttl_min;
|
||||
has_next_ = false;
|
||||
@@ -47,6 +50,9 @@ public:
|
||||
WFRouterTask(std::move(cb)),
|
||||
ns_params_(*ns_params)
|
||||
{
|
||||
if (ns_params_.fixed_conn)
|
||||
ep_params_.max_connections = 1;
|
||||
|
||||
has_next_ = false;
|
||||
in_guard_ = false;
|
||||
msg_ = NULL;
|
||||
|
||||
@@ -83,6 +83,7 @@ struct WFNSParams
|
||||
const char *info;
|
||||
SSL_CTX *ssl_ctx;
|
||||
bool fixed_addr;
|
||||
bool fixed_conn;
|
||||
int retry_times;
|
||||
WFNSTracing *tracing;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user