Skip to content

Commit 9fe23c1

Browse files
committed
Document new 'config' API
1 parent 0714fe3 commit 9fe23c1

File tree

1 file changed

+78
-4
lines changed

1 file changed

+78
-4
lines changed

doc/reference/reference_lua/config.rst

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,17 @@ API Reference
4646
-
4747

4848
* - :ref:`config:get() <config_api_reference_get>`
49-
- Get a configuration applied to the current instance
49+
- Get a configuration applied to the specified instance
5050

5151
* - :ref:`config:info() <config_api_reference_info>`
5252
- Get the current instance's state in regard to configuration
5353

54+
* - :ref:`config:instance_uri() <config_api_reference_instance_uri>`
55+
- Get a URI of the specified instance
56+
57+
* - :ref:`config:instances() <config_api_reference_instances>`
58+
- List all instances of the cluster
59+
5460
* - :ref:`config:reload() <config_api_reference_reload>`
5561
- Reload the current instance's configuration
5662

@@ -83,12 +89,19 @@ config API
8389

8490
.. _config_api_reference_get:
8591

86-
.. method:: get([param])
92+
.. method:: get([param, opts])
8793

88-
Get a configuration applied to the current instance.
89-
Optionally, you can pass a configuration option name to get its value.
94+
Get a configuration applied to the current or remote instance.
95+
Note that there is the following difference between getting a configuration for the current and remote instance:
96+
97+
- For the current instance, ``get()`` returns an instance configuration taking into account all configuration sources, including environment variables.
98+
- For a remote instance, ``get()`` takes into account only cluster configuration. This means that environment variables are ignored.
9099

91100
:param string param: a configuration option name
101+
:param table opts: options to pass. The following options are available:
102+
103+
- ``instance`` (since :doc:`3.1.0 </release/3.1.0>`) -- a name of a remote instance whose configuration should be obtained
104+
92105
:return: an instance configuration
93106

94107
**Examples:**
@@ -206,6 +219,67 @@ config API
206219
...
207220
208221
222+
.. _config_api_reference_instances:
223+
224+
.. method:: instances()
225+
226+
**Since:** :doc:`3.1.0 </release/3.1.0>`
227+
228+
List all instances of the cluster.
229+
230+
:return: a table containing information about instances
231+
232+
The returned table uses instance names as the keys and contains the following information for each instance:
233+
234+
- ``instance_name`` -- an instance name
235+
- ``replicaset_name`` -- a name of the replica set the instance belongs to
236+
- ``group_name`` -- a name of the group the instance belongs to
237+
238+
**Example**
239+
240+
The example below shows how to use ``instances()`` to get the names of all instances in the cluster, create a connection to each instance using the :ref:`connpool <connpool_module>` module, and log connection URIs:
241+
242+
.. code-block:: lua
243+
244+
local config = require('config')
245+
for instance_name in pairs(config:instances()) do
246+
local connpool = require('experimental.connpool')
247+
local conn = connpool.connect(instance_name)
248+
local log = require('log')
249+
log.info(string.format("Connection URI for '%s': %s:%s", instance_name, conn.host, conn.port))
250+
end
251+
252+
253+
.. _config_api_reference_instance_uri:
254+
255+
.. method:: instance_uri([uri_type, opts])
256+
257+
**Since:** :doc:`3.1.0 </release/3.1.0>`
258+
259+
Get a URI of the current or remote instance.
260+
261+
:param string uri_type: a URI type. There are two types are supported:
262+
263+
- ``peer`` -- a URI used to advertise the instance to other cluster members.
264+
- ``sharding`` -- a URI used to advertise the current instance to a router and rebalancer.
265+
266+
See also: :ref:`configuration_reference_iproto_advertise`
267+
268+
:param table opts: options to pass. The following options are available:
269+
270+
- ``instance`` -- a name of a remote instance whose URI should be obtained
271+
272+
:return: an instance URI
273+
274+
**Example**
275+
276+
The example below shows how to get a URI used to advertise ``storage-b-003`` to other cluster members:
277+
278+
.. code-block:: lua
279+
280+
require('config'):instance_uri('peer', { instance = 'storage-b-003' })
281+
282+
209283
.. _config_api_reference_reload:
210284

211285
.. method:: reload()

0 commit comments

Comments
 (0)