Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skynet mysql.lua query 执行超长文本(16MB) #1700

Open
ugpu opened this issue Feb 7, 2023 · 3 comments
Open

skynet mysql.lua query 执行超长文本(16MB) #1700

ugpu opened this issue Feb 7, 2023 · 3 comments

Comments

@ugpu
Copy link

ugpu commented Feb 7, 2023

_compose_query 好像不支持超长文本打包, 比如文本超过16MB strpack(string.pack)会报错, 修改了下 不得行. 是否有其他大佬修改过 有相关案例提供吗?

@terry8210
Copy link

如果确实16M限制,可以分开多个字段存储。

@ugpu
Copy link
Author

ugpu commented Feb 7, 2023

如果确实16M限制,可以分开多个字段存储。
目前具体情况是这样的, 原有业务的确不应该 insert 如此长的数据. 但是设计已经产生, 业务逻辑升级优化的确是正确做法.
但是目前还是想改动这个 query, 支持 多行/多表数据 一次性投递到 mysql.
根据mysql的协议是支持的:
在源码中 socketchannel.lua channel:request(request, response, padding) 接口 padding就是拆分下来的消息包, 投递到mysql,mysql按照协议分包接收后 执行. 但是我已经拆分了, 且按照mysql的协议 依次在 mysql.lua中使 《self.packet_no》产生了消息ID递增, 重新填装了每个包的大小. 修改案例伪代码如下, 不知道为什么会出错? 现在完全和mysql协议对接不上.

local function _compose_query(self, query)
self.packet_no = -1
local cmd_packet = COM_QUERY .. query
local package_max_size = 8 * 1024 * 1024
local size = #cmd_packet
if size >= package_max_size then

    --拆包处理
    DEBUG("size = ", size)
    DEBUG("package_max_size = ", package_max_size)
    local pack_size = package_max_size
    local rreq = string.sub(cmd_packet, 1, pack_size)
    local ssize = #rreq
    local request_pack = _compose_packet(self, rreq)
    local req_tbl = {}
    table.insert(req_tbl, request_pack)
    size = size - pack_size
    local offset = pack_size
    while true do
        self.packet_no = self.packet_no + 1
        pack_size = package_max_size
        if pack_size > size then
            pack_size = size
        end
        

        rreq = string.sub(cmd_packet, offset + 1, offset + pack_size)
        ssize = #rreq
        rreq = COM_QUERY .. rreq
        table.insert(req_tbl, _compose_packet(self, rreq))
        offset = offset + pack_size

        size = size - ssize
        if size <= 0 then
            DEBUG("END size = ", size)
            break
        end
    end

    return request_pack, req_tbl
end

return _compose_packet(self, cmd_packet)

end

@aceyin
Copy link

aceyin commented Feb 13, 2023

之前也遇到类似问题, 但这个不太好解决, 和 mysql 的 max_packet_size 等参数要同步
不然 lua 层面设的大, 但 mysql-server 小, 发到mysql那边也会报错。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants