Skip to content
Snippets Groups Projects
Commit 1f27ae04 authored by Aleksandr Lyapunov's avatar Aleksandr Lyapunov Committed by Aleksandr Lyapunov
Browse files

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
parent 96476a0f
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment