分服逻辑ok
This commit is contained in:
parent
668074da06
commit
5706ff6992
@ -96,6 +96,7 @@ void App::Init(int argc, char* argv[])
|
|||||||
f8::MsgQueue::Instance()->Init();
|
f8::MsgQueue::Instance()->Init();
|
||||||
f8::TGLog::Instance()->Init(a8::Format(PROJ_NAME_FMT, {GAME_ID}), false);
|
f8::TGLog::Instance()->Init(a8::Format(PROJ_NAME_FMT, {GAME_ID}), false);
|
||||||
JsonDataMgr::Instance()->Init();
|
JsonDataMgr::Instance()->Init();
|
||||||
|
LoadSeparateChannelConfig();
|
||||||
uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id);
|
uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id);
|
||||||
GGListener::Instance()->Init();
|
GGListener::Instance()->Init();
|
||||||
GSMgr::Instance()->Init();
|
GSMgr::Instance()->Init();
|
||||||
@ -113,6 +114,14 @@ void App::Init(int argc, char* argv[])
|
|||||||
SavePerfLog();
|
SavePerfLog();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
a8::Timer::Instance()->AddRepeatTimer(1000 * 60 * 5,
|
||||||
|
a8::XParams(),
|
||||||
|
[] (const a8::XParams& param)
|
||||||
|
{
|
||||||
|
App::Instance()->LoadSeparateChannelConfig();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::UnInit()
|
void App::UnInit()
|
||||||
@ -465,3 +474,36 @@ a8::XParams* App::GetContext(long long context_id)
|
|||||||
auto itr = context_hash_.find(context_id);
|
auto itr = context_hash_.find(context_id);
|
||||||
return itr != context_hash_.end() ? &(itr->second) : nullptr;
|
return itr != context_hash_.end() ? &(itr->second) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool App::IsSeparateChannel(int channel)
|
||||||
|
{
|
||||||
|
return separate_channel_hash_.find(channel) != separate_channel_hash_.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void App::LoadSeparateChannelConfig()
|
||||||
|
{
|
||||||
|
std::string data;
|
||||||
|
a8::ReadStringFromFile("../config/separate_channels.csv", data);
|
||||||
|
std::vector<std::string> strings;
|
||||||
|
a8::Split(data, strings, ',');
|
||||||
|
separate_channel_hash_.clear();
|
||||||
|
for (std::string& str : strings) {
|
||||||
|
int channel = a8::XValue(str);
|
||||||
|
if (channel != 0) {
|
||||||
|
separate_channel_hash_.insert(channel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a8::UdpLog::Instance()->Info("LoadSeparateChannelConfig channelids:",
|
||||||
|
{
|
||||||
|
GetSeparateChannelConfigData()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string App::GetSeparateChannelConfigData()
|
||||||
|
{
|
||||||
|
std::string data;
|
||||||
|
for (int channel : separate_channel_hash_) {
|
||||||
|
data += a8::XValue(channel).GetString() + ",";
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
@ -32,6 +32,9 @@ public:
|
|||||||
a8::XParams* AddContext(long long context_id);
|
a8::XParams* AddContext(long long context_id);
|
||||||
void DelContext(long long context_id);
|
void DelContext(long long context_id);
|
||||||
a8::XParams* GetContext(long long context_id);
|
a8::XParams* GetContext(long long context_id);
|
||||||
|
bool IsSeparateChannel(int channel);
|
||||||
|
void LoadSeparateChannelConfig();
|
||||||
|
std::string GetSeparateChannelConfigData();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void QuickExecute(int delta_time);
|
void QuickExecute(int delta_time);
|
||||||
@ -78,6 +81,7 @@ private:
|
|||||||
IMMsgNode* im_bot_node_ = nullptr;
|
IMMsgNode* im_bot_node_ = nullptr;
|
||||||
IMMsgNode* im_work_node_ = nullptr;
|
IMMsgNode* im_work_node_ = nullptr;
|
||||||
|
|
||||||
|
std::set<int> separate_channel_hash_;
|
||||||
std::map<long long, a8::XParams> context_hash_;
|
std::map<long long, a8::XParams> context_hash_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "GGListener.h"
|
#include "GGListener.h"
|
||||||
|
|
||||||
|
#include "framework/cpp/utils.h"
|
||||||
|
|
||||||
void GSMgr::Init()
|
void GSMgr::Init()
|
||||||
{
|
{
|
||||||
a8::Timer::Instance()->AddRepeatTimer(1000 * 2,
|
a8::Timer::Instance()->AddRepeatTimer(1000 * 2,
|
||||||
@ -24,6 +26,7 @@ void GSMgr::UnInit()
|
|||||||
|
|
||||||
void GSMgr::_SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_RequestTargetServer& msg)
|
void GSMgr::_SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_RequestTargetServer& msg)
|
||||||
{
|
{
|
||||||
|
int channel = f8::ExtractChannelIdFromAccountId(msg.account_id());
|
||||||
ss::SS_MS_ResponseTargetServer respmsg;
|
ss::SS_MS_ResponseTargetServer respmsg;
|
||||||
respmsg.set_context_id(msg.context_id());
|
respmsg.set_context_id(msg.context_id());
|
||||||
if (msg.is_reconnect()) {
|
if (msg.is_reconnect()) {
|
||||||
@ -41,7 +44,7 @@ void GSMgr::_SS_WSP_RequestTargetServer(f8::MsgHdr& hdr, const ss::SS_WSP_Reques
|
|||||||
respmsg.set_host(node->ip);
|
respmsg.set_host(node->ip);
|
||||||
respmsg.set_port(node->port);
|
respmsg.set_port(node->port);
|
||||||
} else {
|
} else {
|
||||||
node = AllocNode();
|
node = AllocNode(channel);
|
||||||
if (node) {
|
if (node) {
|
||||||
respmsg.set_host(node->ip);
|
respmsg.set_host(node->ip);
|
||||||
respmsg.set_port(node->port);
|
respmsg.set_port(node->port);
|
||||||
@ -70,6 +73,7 @@ void GSMgr::___GSReport(f8::JsonHttpRequest* request)
|
|||||||
int room_num = request->request.Get("room_num");
|
int room_num = request->request.Get("room_num");
|
||||||
int instance_id = request->request.Get("instance_id");
|
int instance_id = request->request.Get("instance_id");
|
||||||
int node_id = request->request.Get("node_id");
|
int node_id = request->request.Get("node_id");
|
||||||
|
int channel = request->request.Get("channel");
|
||||||
bool servicing = request->request.Get("servicing");
|
bool servicing = request->request.Get("servicing");
|
||||||
std::string key = ip + ":" + a8::XValue(port).GetString();
|
std::string key = ip + ":" + a8::XValue(port).GetString();
|
||||||
|
|
||||||
@ -86,6 +90,7 @@ void GSMgr::___GSReport(f8::JsonHttpRequest* request)
|
|||||||
RearrangeNode();
|
RearrangeNode();
|
||||||
}
|
}
|
||||||
itr->second.alive_count = alive_count;
|
itr->second.alive_count = alive_count;
|
||||||
|
itr->second.channel = channel;
|
||||||
itr->second.last_active_tick = a8::XGetTickCount();
|
itr->second.last_active_tick = a8::XGetTickCount();
|
||||||
} else {
|
} else {
|
||||||
GSNode gs;
|
GSNode gs;
|
||||||
@ -99,6 +104,7 @@ void GSMgr::___GSReport(f8::JsonHttpRequest* request)
|
|||||||
gs.ip = ip;
|
gs.ip = ip;
|
||||||
gs.port = port;
|
gs.port = port;
|
||||||
gs.servicing = servicing;
|
gs.servicing = servicing;
|
||||||
|
gs.channel = channel;
|
||||||
gs.last_active_tick = a8::XGetTickCount();
|
gs.last_active_tick = a8::XGetTickCount();
|
||||||
node_key_hash_[key] = gs;
|
node_key_hash_[key] = gs;
|
||||||
node_sorted_list_.push_back(&node_key_hash_[key]);
|
node_sorted_list_.push_back(&node_key_hash_[key]);
|
||||||
@ -168,23 +174,38 @@ GSNode* GSMgr::GetNodeByNodeKey(const std::string& node_key)
|
|||||||
return itr != node_key_hash_.end() ? &itr->second : nullptr;
|
return itr != node_key_hash_.end() ? &itr->second : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
GSNode* GSMgr::AllocNode()
|
GSNode* GSMgr::AllocNode(int channel)
|
||||||
{
|
{
|
||||||
if (node_sorted_list_.empty()) {
|
std::vector<GSNode*>* sorted_nodes = &node_sorted_list_;
|
||||||
return nullptr;
|
std::vector<GSNode*> spec_nodes;
|
||||||
|
if (App::Instance()->IsSeparateChannel(channel)) {
|
||||||
|
for (GSNode* node : node_sorted_list_) {
|
||||||
|
if (spec_nodes.size() >= 2) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
size_t rnd = std::min((size_t)2, node_sorted_list_.size());
|
if (node->channel == channel) {
|
||||||
|
spec_nodes.push_back(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sorted_nodes = &spec_nodes;
|
||||||
|
}
|
||||||
|
if (!sorted_nodes->empty()) {
|
||||||
|
size_t rnd = std::min((size_t)2, sorted_nodes->size());
|
||||||
int idx = rand() % rnd;
|
int idx = rand() % rnd;
|
||||||
while (idx >= 0) {
|
while (idx >= 0) {
|
||||||
if (node_sorted_list_[idx]->servicing) {
|
if (sorted_nodes->at(idx)->servicing) {
|
||||||
return node_sorted_list_[idx];
|
return sorted_nodes->at(idx);
|
||||||
}
|
}
|
||||||
--idx;
|
--idx;
|
||||||
}
|
}
|
||||||
a8::UdpLog::Instance()->Warning("节点分配失败 node_sorted_list.size:%d node_list.size:%d",
|
}
|
||||||
|
a8::UdpLog::Instance()->Warning
|
||||||
|
("节点分配失败 node_sorted_list.size:%d node_list.size:%d sorted_node.size:%d channel:%d",
|
||||||
{
|
{
|
||||||
node_sorted_list_.size(),
|
node_sorted_list_.size(),
|
||||||
node_key_hash_.size()
|
node_key_hash_.size(),
|
||||||
|
sorted_nodes->size(),
|
||||||
|
channel
|
||||||
});
|
});
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ struct GSNode
|
|||||||
std::string ip;
|
std::string ip;
|
||||||
int port = 0;
|
int port = 0;
|
||||||
bool servicing = false;
|
bool servicing = false;
|
||||||
|
int channel = 0;
|
||||||
long long last_active_tick = 0;
|
long long last_active_tick = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ class GSMgr : public a8::Singleton<GSMgr>
|
|||||||
private:
|
private:
|
||||||
GSNode* GetNodeByTeamId(const std::string& team_id);
|
GSNode* GetNodeByTeamId(const std::string& team_id);
|
||||||
GSNode* GetNodeByNodeKey(const std::string& node_key);
|
GSNode* GetNodeByNodeKey(const std::string& node_key);
|
||||||
GSNode* AllocNode();
|
GSNode* AllocNode(int channel);
|
||||||
void RearrangeNode();
|
void RearrangeNode();
|
||||||
void ClearTimeOutNode();
|
void ClearTimeOutNode();
|
||||||
|
|
||||||
|
@ -19,16 +19,25 @@ static void _GMOpsSelfChecking(f8::JsonHttpRequest* request)
|
|||||||
|
|
||||||
static void _GMOpsReload(f8::JsonHttpRequest* request)
|
static void _GMOpsReload(f8::JsonHttpRequest* request)
|
||||||
{
|
{
|
||||||
|
App::Instance()->LoadSeparateChannelConfig();
|
||||||
request->resp_xobj->SetVal("errcode", 0);
|
request->resp_xobj->SetVal("errcode", 0);
|
||||||
request->resp_xobj->SetVal("errmsg", "");
|
request->resp_xobj->SetVal("errmsg", "");
|
||||||
a8::UdpLog::Instance()->Warning("reload config files", {});
|
a8::UdpLog::Instance()->Warning("reload config files", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _GMOpsShowConfig(f8::JsonHttpRequest* request)
|
||||||
|
{
|
||||||
|
request->resp_xobj->SetVal("errcode", 0);
|
||||||
|
request->resp_xobj->SetVal("errmsg", "");
|
||||||
|
request->resp_xobj->SetVal("separate_channels", App::Instance()->GetSeparateChannelConfigData());
|
||||||
|
}
|
||||||
|
|
||||||
void HandlerMgr::Init()
|
void HandlerMgr::Init()
|
||||||
{
|
{
|
||||||
RegisterNetMsgHandlers();
|
RegisterNetMsgHandlers();
|
||||||
RegisterGMMsgHandler("Ops@selfChecking", _GMOpsSelfChecking);
|
RegisterGMMsgHandler("Ops@selfChecking", _GMOpsSelfChecking);
|
||||||
RegisterGMMsgHandler("Ops@reload", _GMOpsReload);
|
RegisterGMMsgHandler("Ops@reload", _GMOpsReload);
|
||||||
|
RegisterGMMsgHandler("Ops@showConfig", _GMOpsShowConfig);
|
||||||
RegisterGMMsgHandler("GS@report", [] (f8::JsonHttpRequest* request)
|
RegisterGMMsgHandler("GS@report", [] (f8::JsonHttpRequest* request)
|
||||||
{
|
{
|
||||||
GSMgr::Instance()->___GSReport(request);
|
GSMgr::Instance()->___GSReport(request);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user