Code Monkey home page Code Monkey logo

Comments (3)

terry8210 avatar terry8210 commented on July 19, 2024 1

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

from skynet.

aceyin avatar aceyin commented on July 19, 2024 1

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

from skynet.

ugpu avatar ugpu commented on July 19, 2024

如果确实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

from skynet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.