1

I have cluster with several replicasets. I want to call some stored function on all nodes without calculate bucket_id, and after to map results. How should I do it?

Gennady
  • 352
  • 2
  • 12

2 Answers2

3

You can use module cartridge.rpc function get_candidates for getting all nodes with some role, which you want to call and after to use module cartridge.pool function map_call for calling your function and mapping results. This function available from 1.2.0-17 version of cartridge. So your code could be like this:

local cartridge = require('cartridge')
local nodes = cartridge.rpc_get_candidates('my_role_name', { leaders_only = true, healthy_only = true })
local pool = require('cartridge.pool')
local results, err = pool.map_call('_G.my_function_name', { func_args }, { uri_list = nodes, timeout = 10 })
if (err ~= nil) then
    #your error handling#
end

All function response will be saved to results variable and mapped for every URI. All errors will be saved to err variable as map with keys: line, class_name, err, file, suberrors, str

Gennady
  • 352
  • 2
  • 12
2

Another proposal.

If you use vshard and want to perform map-reduce over storages:

    local replicaset, err = vshard.router.routeall()
    for _, replica in pairs(replicaset) do
        local _, err = replica:callrw('function', { args })
        if err ~= nil then
            return nil, err
        end
    end
Oleg Babin
  • 409
  • 3
  • 9