Skip to content

Commit 265ebaa

Browse files
Document the 'experimental.connpool' module (#4329)
1 parent 19849b0 commit 265ebaa

File tree

2 files changed

+190
-0
lines changed

2 files changed

+190
-0
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
.. _connpool_module:
2+
3+
Module experimental.connpool
4+
============================
5+
6+
**Since:** :doc:`3.1.0 </release/3.1.0>`
7+
8+
.. important::
9+
10+
``experimental.connpool`` is an experimental module and is subject to changes.
11+
12+
The ``experimental.connpool`` module provides a set of features for connecting to remote cluster instances and for executing remote procedure calls on an instance that satisfies the specified criteria.
13+
14+
.. NOTE::
15+
16+
Note that the execution time for ``experimental.connpool`` functions depends on the number of instances and the time required to connect to each instance.
17+
18+
19+
20+
.. _connpool_module_load:
21+
22+
Loading a module
23+
----------------
24+
25+
To load the ``experimental.connpool`` module, use the ``require()`` directive:
26+
27+
.. code-block:: lua
28+
29+
local connpool = require('experimental.connpool')
30+
31+
32+
.. _connpool_module_api_reference:
33+
34+
API Reference
35+
-------------
36+
37+
.. container:: table
38+
39+
.. rst-class:: left-align-column-1
40+
.. rst-class:: left-align-column-2
41+
42+
.. list-table::
43+
:widths: 35 65
44+
45+
* - **Functions**
46+
-
47+
48+
* - :ref:`connpool.call() <connpool_module_call>`
49+
- Execute the specified function on a remote instance
50+
51+
* - :ref:`connpool.connect() <connpool_module_connect>`
52+
- Create a connection to the specified instance
53+
54+
* - :ref:`connpool.filter() <connpool_module_filter>`
55+
- Get names of instances that match the specified conditions
56+
57+
58+
59+
60+
61+
.. module:: connpool
62+
63+
.. _connpool_module_api_reference_functions:
64+
65+
Functions
66+
~~~~~~~~~
67+
68+
.. _connpool_module_call:
69+
70+
.. function:: call(func_name, args, opts)
71+
72+
Execute the specified function on a remote instance.
73+
74+
.. NOTE::
75+
76+
The function is executed on behalf of the user that maintains replication in the cluster.
77+
Ensure that this user has the ``execute`` :ref:`permission <configuration_credentials_managing_users_roles_granting_privileges>` for the function to execute.
78+
79+
:param string func_name: a name of the function to execute.
80+
:param table/nil args: function arguments.
81+
:param table/nil opts: options used to select candidates on which the function should be executed:
82+
83+
* ``labels`` -- the :ref:`labels <configuration_reference_labels>` an instance has.
84+
* ``roles`` -- the :ref:`roles <configuration_application_roles>` of an instance.
85+
* ``prefer_local`` -- whether to prefer a local or remote instance to execute ``call()`` on:
86+
87+
* if ``true`` (default), ``call()`` tries to execute the specified function on a local instance.
88+
* if ``false``, ``call()`` tries to connect to a random candidate until a connection is established.
89+
90+
* ``mode`` -- a mode that allows filtering candidates based on their read-only status. This option accepts the following values:
91+
92+
* ``nil`` (default) -- don't check the read-only status of instances.
93+
* ``ro`` -- consider only read-only instances.
94+
* ``rw`` -- consider only read-write instances.
95+
* ``prefer_ro`` -- consider read-only instances, then read-write instances.
96+
* ``prefer_rw`` -- consider read-write instances, then read-only instances.
97+
98+
* ``instances`` -- the names of instances to consider as candidates.
99+
* ``replicasets`` -- the names of replica sets whose instances are considered as candidates.
100+
* ``groups`` -- the names of groups whose instances are considered as candidates.
101+
* ``timeout`` -- a connection timeout (in seconds).
102+
* ``buffer`` -- a :ref:`buffer <buffer-module>` used to read a returned value.
103+
* ``on_push`` -- a function to execute when the client receives an out-of-band message. Learn more from :ref:`box_session-push`.
104+
* ``on_push_ctx`` -- an argument of the function executed when the client receives an out-of-band message. Learn more from :ref:`box_session-push`.
105+
* ``is_async`` -- whether to wait for the result of the call.
106+
107+
:return: a function's return value.
108+
109+
**Example**
110+
111+
In the example below, the following conditions are specified to choose an instance to execute the :ref:`vshard.storage.buckets_count <storage_api-buckets_count>` function:
112+
113+
* An instance has the ``roles.crud-storage`` role.
114+
* An instance has the ``dc`` label set to ``east``.
115+
* An instance is read-only.
116+
117+
.. code-block:: lua
118+
119+
local connpool = require('experimental.connpool')
120+
local buckets_count = connpool.call('vshard.storage.buckets_count',
121+
nil,
122+
{ roles = { 'roles.crud-storage' },
123+
labels = { dc = 'east' },
124+
mode = 'ro' }
125+
)
126+
127+
128+
.. _connpool_module_connect:
129+
130+
.. function:: connect(instance_name, opts)
131+
132+
Create a connection to the specified instance.
133+
134+
:param string instance_name: an instance name.
135+
:param table/nil opts: none, any, or all of the following parameters:
136+
137+
* ``connect_timeout`` -- a connection timeout (in seconds).
138+
* ``wait_connected`` -- whether to block the connection until it is established:
139+
140+
* if ``true`` (default), the connection is blocked until it is established.
141+
* if ``false``, the connection is returned immediately.
142+
143+
* ``fetch_schema`` -- whether to fetch schema changes from a remote instance.
144+
145+
:return: a :ref:`net.box <net_box-module>` connection.
146+
147+
**Example**
148+
149+
In the example below, ``connect()`` is used to create the active connection to ``storage-b-002``:
150+
151+
.. code-block:: lua
152+
153+
local connpool = require('experimental.connpool')
154+
local conn = connpool.connect("storage-b-002", { fetch_schema = true })
155+
156+
Once you have a connection, you can execute requests on the remote instance, for example, select data from a space using :ref:`conn.space.\<space-name\>:select() <conn-select>`.
157+
158+
159+
.. _connpool_module_filter:
160+
161+
.. function:: filter(opts)
162+
163+
Get names of instances that match the specified conditions.
164+
165+
:param table/nil opts: none, any, or all of the following parameters:
166+
167+
* ``labels`` -- the :ref:`labels <configuration_reference_labels>` an instance has.
168+
* ``roles`` -- the :ref:`roles <configuration_application_roles>` of an instance.
169+
* ``mode`` -- a mode that allows filtering candidates based on their read-only status. This option accepts the following values:
170+
171+
* ``nil`` (default) -- don't check the read-only status of instances.
172+
* ``ro`` -- consider only read-only instances.
173+
* ``rw`` -- consider only read-write instances.
174+
175+
* ``instances`` -- the names of instances to consider as candidates.
176+
* ``replicasets`` -- the names of replica sets whose instances are considered as candidates.
177+
* ``groups`` -- the names of groups whose instances are considered as candidates.
178+
179+
:return: an array of instance names.
180+
181+
**Example**
182+
183+
In the example below, ``filter()`` should return a list of instances with the ``roles.crud-storage`` role and specified label value:
184+
185+
.. code-block:: lua
186+
187+
local connpool = require('experimental.connpool')
188+
local instance_names = connpool.filter({ roles = { 'roles.crud-storage' },
189+
labels = { dc = 'east' } })

doc/reference/reference_lua/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ This reference covers Tarantool's built-in Lua modules.
3333
decimal
3434
digest
3535
errno
36+
connpool
3637
fiber
3738
fio
3839
fun

0 commit comments

Comments
 (0)