Implement net.replicaset base API
This module is designed for simple net.box-like access to a replicaset. Internally the module holds a connection to each replica of the replicaset and subscribes to ro/rw status of each replica. That allows to decide which instance can execute ro/rw/leader request. That's a MVP so only part of the design document is implemented. Only `call_leader` method is implemented. No additional options of connection are implemented (except those which are accepted by net.box.connect). Having that the implementation is in internal namespace. The common usage is quite simple: ``` local net_replicaset = require('internal.net.replicaset') local opts = { name = <optional replicaset name> instances = { [<instance_name>] = { endpoint = <URI to connect to, including credentials>, reconnect_timeout = <..> -- optional reconnect timeout. } }, reconnect_timeout = <..> -- optional default for all instances. } local rs = net_replicaset.connect(opts) -- this method is similar to net.box.call but is called on leader. -- NO_WRITEABLE and MORE_THAN_ONE_WRITEABLE may be thrown. -- Only two options are supported now - timeout and is_async. local info = rs:call_leader(func_name, args, opts) -- also similar to net.box. rs:close() ``` If cluster config 3.0 is used then connect by name can be used: ``` -- options now has only reconnect_timeout as described above. -- REPLICASET_NOT_FOUND error may be thrown. local rs = net_replicaset.connect(replicaset_name, options) ``` Part of #9823 NO_DOC=internal NO_CHANGELOG=internal
Showing
- src/box/CMakeLists.txt 1 addition, 0 deletionssrc/box/CMakeLists.txt
- src/box/errcode.h 3 additions, 0 deletionssrc/box/errcode.h
- src/box/lua/init.c 2 additions, 0 deletionssrc/box/lua/init.c
- src/box/lua/net_replicaset.lua 273 additions, 0 deletionssrc/box/lua/net_replicaset.lua
- test/box-luatest/gh_9823_net_replicaset_test.lua 218 additions, 0 deletionstest/box-luatest/gh_9823_net_replicaset_test.lua
- test/box/error.result 3 additions, 0 deletionstest/box/error.result
Loading
Please register or sign in to comment