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

Implement box-like API to access spaces #150

Open
Khatskevich opened this issue Aug 22, 2018 · 6 comments
Open

Implement box-like API to access spaces #150

Khatskevich opened this issue Aug 22, 2018 · 6 comments
Labels
cluster api feature A new functionality
Milestone

Comments

@Khatskevich
Copy link
Contributor

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.

@Gerold103 Gerold103 changed the title Introduce ddl api for vshard Expose netbox space API to vshard Aug 22, 2018
@mtrempoltsev
Copy link

It will also be useful to perform the query on all nodes.

@Gerold103 Gerold103 added this to the wishlist milestone Sep 20, 2018
@Gerold103 Gerold103 added the feature A new functionality label Sep 20, 2018
@Totktonada
Copy link
Member

One of our projects uses the following router_proxy module as workaround:

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

@chetandhembre
Copy link

@Totktonada I am not seeing any code in your proxy, especially for insert function where we need to store bucket_id in table.
My question is are you sending bucket_id from client while inserting row or your converting bucket_key to bucket_id in server side lua code?

@Totktonada
Copy link
Member

We can reduce load of tx thread on a vshard router skipping excessive decoding-encoding of lua call arguments after implementing tarantool/tarantool#3349

@Gerold103 Gerold103 changed the title Expose netbox space API to vshard Implement box-like API to access spaces Nov 2, 2020
@Gerold103
Copy link
Collaborator

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 vshard.router.callbro/callbre/.... The API endpoint is going to be vbox. It not only will provide bucket-safe methods taking into account all bucket referencing stuff, but will also collect, merge, and expose cluster schema. It will fetch schema from each storage, compare them, and expose the set of sharded spaces on routers. It will expose only the spaces having the same schema on all storages, and will maintain that space set up to date. I will probably send an RFC with proper API description later.

@akudiyar
Copy link

akudiyar commented Dec 5, 2021

https://github.com/tarantool/crud has been solving this task for some time already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cluster api feature A new functionality
Projects
None yet
Development

No branches or pull requests

6 participants