Skip to content

Commit

Permalink
整理代码
Browse files Browse the repository at this point in the history
  • Loading branch information
DSKY\toney.yin committed Feb 1, 2024
1 parent 5b6296f commit 0197326
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 28 deletions.
3 changes: 2 additions & 1 deletion core/hive/src/lualog/lualog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ namespace logger {
case 6: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<6>{});
case 7: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<7>{});
case 8: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<8>{});
default: luaL_error(L, "log format args is more than 8!"); break;
case 9: return tformat(L, lvl, tag, feature, flag, vfmt, make_index_sequence<9>{});
default: luaL_error(L, "log format args is more than 9!"); break;
}
return 0;
});
Expand Down
7 changes: 7 additions & 0 deletions core/hive/src/sandbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,11 @@ function hive.load(name)
return hive[name]
end
function hive.init(name, val)
if not hive[name] then
hive[name] = val or {}
end
return hive[name]
end
)__";
21 changes: 13 additions & 8 deletions script/agent/rmsg_agent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,21 @@ function RmsgAgent:lock_msg(rmsg_type, to)
return thread_mgr:lock(sformat("RMSG:%s:%s", rmsg_type, to))
end

function RmsgAgent:list_message(rmsg_type, to)
return self.rmsgs[rmsg_type]:list_message(to)
function RmsgAgent:list_message(rmsg_type, to, page_size)
return self.rmsgs[rmsg_type]:list_message(to, page_size)
end

function RmsgAgent:safe_do_message(rmsg_type, to, do_func)
local _lock<close> = self:lock_msg(rmsg_type, to)
local records = self:list_message(rmsg_type, to)
for _, record in ipairs(records) do
do_func(record)
self:delete_message_by_uuid(rmsg_type, record.uuid, record.to)
for i = 1, 100 do
local records = self:list_message(rmsg_type, to, 100)
for _, record in ipairs(records) do
do_func(record)
self:delete_message_by_uuid(rmsg_type, record.uuid, record.to)
end
if #records < 100 then
return
end
end
end

Expand All @@ -75,8 +80,8 @@ function RmsgAgent:delete_message_by_uuid(rmsg_type, uuid, to)
return self.rmsgs[rmsg_type]:delete_message_by_uuid(uuid, to)
end

function RmsgAgent:delete_message_from_to(rmsg_type, from, to, type)
return self.rmsgs[rmsg_type]:delete_message_from_to(from, to, type)
function RmsgAgent:delete_message_from_to(rmsg_type, from, to, type, onlyone)
return self.rmsgs[rmsg_type]:delete_message_from_to(from, to, type, onlyone)
end

-- export
Expand Down
2 changes: 1 addition & 1 deletion script/basic/logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ local LOG_LEVEL = log.LOG_LEVEL
logger = {}
logfeature = {}
local title = hive.title
local monitors = _ENV.monitors or {}
local monitors = hive.init("MONITORS")
local log_func = false
local log_lvl = 1
local dispatching = false
Expand Down
14 changes: 5 additions & 9 deletions script/basic/service.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import("kernel/config_mgr.lua")
local sformat = string.format

--服务组常量
local SERVICES = _ENV.SERVICES or {}
local SERVICE_NAMES = _ENV.SERVICE_NAMES or {}
local SERVICE_HASHS = _ENV.SERVICE_HASHS or {}
local SERVICE_CONFS = _ENV.SERVICE_CONFS or {}
local SERVICES = hive.init("SERVICES")
local SERVICE_NAMES = hive.init("SERVICE_NAMES")
local SERVICE_HASHS = hive.init("SERVICE_HASHS")
local SERVICE_CONFS = hive.init("SERVICE_CONFS")

service = {}

Expand All @@ -37,10 +37,6 @@ function service.make_node(port, domain)
is_ready = false,
status = hive.service_status
}
--防止ip为空无法注册nacos
if not hive.node_info.host or hive.node_info.host == "" then
hive.node_info.host = "127.0.0.1"
end
end

function service.init()
Expand All @@ -66,7 +62,7 @@ function service.init()
hive.service_name = service_name
hive.service_id = service_id
hive.name = service.id2nick(hive.id)
hive.host = environ.get("HIVE_HOST_IP")
hive.host = environ.get("HIVE_HOST_IP", "127.0.0.1")
hive.mode = SERVICE_CONFS[service_id].mode
hive.rely_router = SERVICE_CONFS[service_id].rely_router
hive.safe_stop = SERVICE_CONFS[service_id].safe_stop
Expand Down
4 changes: 2 additions & 2 deletions script/feature/worker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ local function init_mainloop()
update_mgr = hive.get("update_mgr")
end

function hive.init()
function hive.main()
--核心加载
init_core()
--初始化基础模块
Expand Down Expand Up @@ -89,7 +89,7 @@ function hive.startup(entry)
--初始化随机种子
math.randomseed(hive.now_ms)
--初始化hive
hive.init()
hive.main()
--启动服务器
entry()
end
Expand Down
4 changes: 2 additions & 2 deletions script/kernel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ local function init_mainloop()
scheduler = hive.get("scheduler")
end

function hive.init()
function hive.main()
--核心加载
init_core()
--初始化基础模块
Expand Down Expand Up @@ -96,7 +96,7 @@ function hive.startup(entry)
--初始化随机种子
math.randomseed(hive.now_ms)
--初始化hive
hive.init()
hive.main()
--启动服务器
entry()
hive.after_start()
Expand Down
3 changes: 3 additions & 0 deletions script/network/net_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ function NetServer:on_socket_accept(session)
session.set_timeout(self.timeout)
-- 绑定call回调
session.on_call_pb = function(recv_len, cmd_id, flag, session_id, seq_id, data)
if session.disable then
return -2
end
if seq_id ~= session.seq_id and seq_id ~= 0xff then
log_warn("[NetServer][on_socket_accept] seq_id:{} != cur:{},ip:{}", seq_id, session.seq_id, session.ip)
return -1
Expand Down
8 changes: 4 additions & 4 deletions script/store/reliable_msg.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ function ReliableMsg:len_message(to)
end

-- 查询未处理消息列表
function ReliableMsg:list_message(to)
function ReliableMsg:list_message(to, page_size)
local query = { self.table_name, { to = to, deal_time = 0 }, { _id = 0, ttl = 0 }, { time = 1 } }
local ok, code, result = mongo_agent:find(query, to, self.db_name)
local ok, code, result = mongo_agent:find(query, to, self.db_name, page_size)
if check_success(code, ok) then
return result
end
Expand Down Expand Up @@ -103,13 +103,13 @@ function ReliableMsg:delete_message_by_uuid(uuid, to)
return mongo_agent:delete({ self.table_name, { uuid = uuid, to = to }, true }, hive.id, self.db_name)
end

function ReliableMsg:delete_message_from_to(from, to, type)
function ReliableMsg:delete_message_from_to(from, to, type, onlyone)
log_info("[ReliableMsg][delete_message_from_to] delete message from:{},to:{},type:{}", from, to, type)
local selector = { from = from, to = to }
if type then
selector["type"] = type
end
return mongo_agent:delete({ self.table_name, selector }, hive.id, self.db_name)
return mongo_agent:delete({ self.table_name, selector, onlyone }, hive.id, self.db_name)
end

-- 发送消息
Expand Down
6 changes: 5 additions & 1 deletion server/monitor/monitor_mgr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ end
-- 检测失活
function MonitorMgr:check_lost_node()
for _, v in pairs(self.monitor_lost_nodes) do
log_err("[MonitorMgr][check_lost_node] lost service:{},please fast to repair!!!!!", v)
if hive.is_publish then
log_err("[MonitorMgr][check_lost_node] lost service:{},please fast to repair!!!!!", v)
else
log_warn("[MonitorMgr][check_lost_node] lost service:{},please fast to repair!!!!!", v)
end
end
end

Expand Down

0 comments on commit 0197326

Please sign in to comment.