【问题标题】:Space that is available at all Tarantool nodes (vshard)所有 Tarantool 节点 (vshard) 上的可用空间
【发布时间】:2021-02-19 05:04:16
【问题描述】:

我将 Tarantool 与 vshard 模块一起使用。设置 bucket_id 时,数据将分布在整个集群中。每个节点都有自己的一组 bucket_id。如何创建一个空间,以便在每个节点(字典)上都可以完全访问它?

【问题讨论】:

    标签: tarantool


    【解决方案1】:

    我使用下面的 sn-p 在所有存储上运行一个函数(可能有更好的方法)。

    假设我们有一个关于存储的函数:

    local function putMyData(rows)
        box.atomic(function()
            for _, row in ipairs(rows)
                box.mySpace:put(row)
            end
        end)
    end
    
    box.schema.func.create("putMyData", { if_not_exists = true })
    box.schema.role.grant("public", "execute", "function", "putMyData", { if_not_exists = true })
    rawset(_G, "putMyData", putMyData)
    
    

    那么可以使用下面的helper来调用函数:

    local function callAll(mode, fnName, args, resHandler, timeoutSec)
        local replicaSets, err = vshard.router.routeall()
        if err ~= nil then
            error(err)
        end
    
        local count = 0
        for _, _ in pairs(replicaSets) do
            count = count + 1
        end
    
        local channel = fiber.channel(count)
    
        local method
        if mode == "read" then
            method = "callbro"
        else
            method = "callrw"
        end
    
        for _, replicaSet in pairs(replicaSets) do
            fiber.create(
                function()
                    local res, fErr = replicaSet[method](replicaSet,
                        fnName, args, { timeout = timeoutSec or opts.timeout })
                    channel:put({ res = res, err = fErr })
                end)
        end
    
        local results = { }
    
        for i = 1, count do
            local val = channel:get()
            if val.err ~= nil then
                error(val.err)
            end
    
            if resHandler == nil then
                results[i] = val.res
            else
                resHandler(val.res, results)
            end
        end
    
        return results
    end
    
    

    【讨论】:

      猜你喜欢
      • 2020-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-15
      • 2021-05-07
      • 2014-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多