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
Implement box-like API to access spaces #150
Comments
It will also be useful to perform the query on all nodes. |
One of our projects uses the following local M = {}
local function _proxy(func_name, space_name, bucket_key, ...)
local bucket_id = vshard.router.bucket_id(bucket_key)
local call_func = 'box.space.' .. space_name .. ':' .. func_name
local res, err = vshard.router.callrw(bucket_id, call_func, { ... })
if err then
return err.message
end
return res
end
function M.select(space_name, bucket_key, ...)
return _proxy('select', space_name, bucket_key, ...)
end
function M.get(space_name, bucket_key, ...)
return _proxy('get', space_name, bucket_key, ...)
end
function M.insert(space_name, bucket_key, ...)
return _proxy('insert', space_name, bucket_key, ...)
end
function M.replace(space_name, bucket_key, ...)
return _proxy('replace', space_name, bucket_key, ...)
end
function M.update(space_name, bucket_key, ...)
return _proxy('update', space_name, bucket_key, ...)
end
function M.delete(space_name, bucket_key, ...)
return _proxy('delete', space_name, bucket_key, ...)
end
function M.map_reduce_eval(code)
local cluster = vshard.router.routeall()
local result = {}
for _, replicaset in pairs(cluster) do
local master = replicaset.master
local _, res = pcall(function()
return master.conn:eval(code)
end)
result[#result + 1] = {
uuid = master.uuid,
res = res,
}
end
return result
end
return M |
@Totktonada I am not seeing any code in your proxy, especially for insert function where we need to store bucket_id in table. |
We can reduce load of tx thread on a vshard router skipping excessive decoding-encoding of lua call arguments after implementing tarantool/tarantool#3349 |
As a part of cluster box-like API, it was decided vshard should expose an API similar to box.space/netbox.space. It would look exactly like these, but with a few sharding-specific changes. Each non-select operation should get a bucket_id argument. Select() may use a bucket_id argument, or omit it and turn into a map-reduce (not sure about that though). Also each call should have a timeout, and a routing mode - 'prefer replica', 'balanced', and so on, like |
https://github.com/tarantool/crud has been solving this task for some time already. |
It is very common need to just perform simple lookups, inserts...
Those methods should work out of the box.
Api suggestion:
router:select(bucket_id, select_args)
...
Regarding fullscans (ddl without
bucket_id
), I am not sure if it should be supported.The text was updated successfully, but these errors were encountered: