You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This patch adds documentation for the `config.storage_client` module.
The module allows one to connect to a remote config.storage cluster and
use it as a key-value storage.
Examples for working both with Tarantool config.storage server API and
Tarantool config.storage client API are provided side by side since they
share quite the same API.
The examples on connecting to a config.storage instance via iproto has
been changed to an example on connecting to multiple config.storage
instances using the config.storage client.
Copy file name to clipboardExpand all lines: doc/platform/configuration/configuration_etcd.rst
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -260,6 +260,8 @@ In the example below, the following options are specified:
260
260
- ``timeout`` specifies the interval (in seconds) to perform the status check of a configuration storage.
261
261
- ``reconnect_after`` specifies how much time to wait (in seconds) before reconnecting to a configuration storage.
262
262
263
+
You might use :ref:`config.storage_client <config_storage_client_api_reference>` API for connecting and controlling a remote config.storage cluster.
264
+
263
265
You can find the full example here: `config_storage <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/config_storage>`_.
The ``config`` module provides the ability to work with an instance's configuration.
9
9
For example, you can determine whether the current instance is up and running without errors after applying the :ref:`cluster's configuration <configuration_overview>`.
10
10
11
-
By using the ``config.storage`` :ref:`role <configuration_application_roles>`, you can set up a Tarantool-based :ref:`centralized configuration storage <configuration_etcd>` and interact with this storage using the ``config`` module API.
12
-
11
+
By using the ``config.storage`` :ref:`role <configuration_application_roles>`, you can set up a Tarantool-based :ref:`centralized configuration storage <configuration_etcd>` and interact with this storage using the ``config`` module API. ``config.storage_client`` allows to connect to such storages and to interact with them from other Tarantool instances.
The ``config.storage`` API allows you to interact with a Tarantool-based :ref:`centralized configuration storage <configuration_etcd>`.
383
+
The ``config.storage`` and ``config.storage_client`` API allows you to interact with Tarantool-based :ref:`centralized configuration storage <configuration_etcd>`.
384
+
385
+
.. class:: config.storage
386
+
387
+
If you configure a replicaset as :ref:`Tarantool-based centralized configuration storage <centralized_configuration_storage_tarantool_configure>` by specifying a ``config.storage`` role (see :ref:`configuring roles <configuration_reference_roles>`) the ``config.storage`` object provides ``<config.storage server>`` methods to interact with a key-value storage, see Server API examples below.
355
388
356
-
.. module:: config.storage
389
+
.. _config_storage_client_api_reference:
357
390
358
-
.. _config_storage_api_reference_put:
391
+
.. class:: config.storage_client
359
392
360
-
.. function:: put(path, value)
393
+
The ``config.storage_client`` API allows you to connect to a remote replica set :ref:`configured as a Tarantool-based centralized configuration storage <configuration_etcd>` and interact with it as a key-value storage, see Client API examples below.
361
394
362
-
Put a value by the specified path.
395
+
.. _config_storage_client_api_reference_connect:
363
396
364
-
:param string path: a path to put the value by
365
-
:param string value: a value to put
397
+
.. function:: connect(endpoints[, options])
366
398
367
-
:return: a table containing the following fields:
399
+
Connect to a remote config.storage cluster.
368
400
369
-
* ``revision``: a revision after performing the operation
401
+
:param table endpoints: table of config.storage instance URIs
The example below shows how to connect to a specific config.storage cluster:
374
409
375
-
The example below shows how to read a configuration stored in the ``source.yaml`` file using the :ref:`fio module <fio-module>` API and put this configuration by the ``/myapp/config/all`` path:
The example below shows how to connect to a config storage cluster configured as the :ref:`centralized configuration storage <configuration_etcd>` in the :ref:`config.storage <configuration_reference_config_storage>` option:
382
417
383
-
Example on GitHub: `tarantool_config_storage <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/tarantool_config_storage>`_
:start-after: function connect_to_configured_storage
421
+
:end-at: config.storage_client.connect
422
+
:dedent:
384
423
424
+
Examples on GitHub: `config_storage <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/config_storage>`_
Get a value stored by the specified path or prefix.
431
+
Put a value by the specified path.
391
432
392
-
:param string path: a path or prefix to get a value by; prefixes end with ``/``
433
+
:param string path: a path to put the value by
434
+
:param string value: a value to put
393
435
394
-
:return: a table containing the following fields:
436
+
:return: a table containing the following fields:
395
437
396
-
* ``data``: a table containing the information about the value:
438
+
* ``revision``: a revision after performing the operation
397
439
398
-
* ``path``: a path
399
-
* ``mod_revision``: the last revision at which this value was modified
400
-
* ``value:``: a value
440
+
:rtype: table
401
441
402
-
* ``revision``: a revision after performing the operation
442
+
**Server API example:**
403
443
404
-
:rtype: table
444
+
The example below shows how to read a configuration stored in the ``source.yaml`` file using the :ref:`fio module <fio-module>` API and put this configuration by the ``/myapp/config/all`` path:
The example below shows how to get a configuration stored by the ``/myapp/config/all`` path:
452
+
Examples on GitHub: `tarantool_config_storage <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/tarantool_config_storage>`_
This example shows how to get all configurations stored by the ``/myapp/`` prefix:
456
+
The example below shows how to read a configuration stored in the ``source.yaml`` file using the :ref:`fio module <fio-module>` API and put this configuration by the ``/myapp/config/all`` path:
Example on GitHub: `tarantool_config_storage<https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/tarantool_config_storage>`_
464
+
Examples on GitHub: `config_storage<https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/config_storage>`_
425
465
426
-
.. _config_storage_api_reference_delete:
466
+
.. _config_storage_object_api_reference_get:
427
467
428
-
.. function:: delete(path)
468
+
.. function:: <config.storage server>.get(path)
469
+
.. function:: <config.storage client>:get(path)
429
470
430
-
Delete a value stored by the specified path or prefix.
471
+
Get a value stored by the specified path or prefix.
431
472
432
-
:param string path: a path or prefix to delete the value by; prefixes end with ``/``
473
+
:param string path: a path or prefix to get a value by; prefixes end with ``/``
433
474
434
-
:return: a table containing the following fields:
475
+
:return: a table containing the following fields:
435
476
436
-
* ``data``: a table containing the information about the value:
477
+
* ``data``: a table containing the information about the value:
437
478
438
-
* ``path``: a path
439
-
* ``mod_revision``: the last revision at which this value was modified
440
-
* ``value:``: a value
479
+
* ``path``: a path
480
+
* ``mod_revision``: the last revision at which this value was modified
481
+
* ``value:``: a value
441
482
442
-
* ``revision``: a revision after performing the operation
483
+
* ``revision``: a revision after performing the operation
443
484
444
-
:rtype: table
485
+
:rtype: table
445
486
446
-
**Examples:**
487
+
**Server API examples:**
447
488
448
-
The example below shows how to delete a configuration stored by the ``/myapp/config/all`` path:
489
+
The example below shows how to get a configuration stored by the ``/myapp/config/all`` path:
Example on GitHub: `tarantool_config_storage <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/tarantool_config_storage>`_
505
+
Examples on GitHub: `tarantool_config_storage <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/tarantool_config_storage>`_
465
506
507
+
**Client API examples:**
466
508
467
-
.. _config_storage_api_reference_info:
509
+
The example below shows how to get a configuration stored by the ``/myapp/config/all`` path on a remote config.storage cluster:
* ``status``: a connection status, which can be one of the following:
525
+
Examples on GitHub: `config_storage <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/config_storage>`_
476
526
477
-
* ``connected``: if any instance from the quorum is available to the current instance
478
-
* ``disconnected``: if the current instance doesn't have a connection with the quorum
Examples on GitHub: `tarantool_config_storage <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/tarantool_config_storage>`_
509
567
510
-
* ``responses``: the list of responses for all operations
511
-
* ``is_success``: a boolean value indicating whether the predicate is evaluated to ``true``
568
+
**Client API examples:**
512
569
513
-
* ``revision``: a revision after performing the operation
570
+
The example below shows how to delete a configuration stored by the ``/myapp/config/all`` path:
Examples on GitHub: `config_storage <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/config_storage>`_
587
+
588
+
.. _config_storage_object_api_reference_info:
589
+
590
+
.. function:: <config.storage server>.info()
591
+
.. function:: <config.storage client>:info()
592
+
593
+
Get information about an instance's connection state.
594
+
595
+
:return: a table containing the following fields:
596
+
597
+
* ``status``: a connection status, which can be one of the following:
598
+
599
+
* ``connected``: if any instance from the quorum is available to the current instance
600
+
* ``disconnected``: if the current instance doesn't have a connection with the quorum
Examples on GitHub: `tarantool_config_storage <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/tarantool_config_storage>`_
Examples on GitHub: `config_storage <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/config_storage>`_
Show whether there is an active connection to a config.storage cluster.
665
+
666
+
:return: true if connected, false on failure.
667
+
:rtype: boolean
668
+
669
+
.. _config_storage_client_api_reference_close:
670
+
671
+
.. function:: <config.storage client>:close()
672
+
673
+
Close existing connection to a config.storage cluster. Connection objects are destroyed by the Lua garbage collector, just like any other objects in Lua, so an explicit destruction is not mandatory. However, since ``close()`` is a system call, it is good programming practice to close a connection explicitly when it is no longer needed, to avoid lengthy stalls of the garbage collector.
674
+
675
+
Note connection to the config.storage will be re-established automatically if one of the remote config.storage client methods is called.
Define a trigger for execution when the established connection to a config.storage cluster instance is closed. This also includes the cases when the config.storage client loses connection to a specific instance but automatically re-establishes it to another available one. Execution stops after a config.storage client is explicitly closed, or once the Lua garbage collector removes it.
Subscribe to config.storage events broadcast. You might use one of the following events.
703
+
704
+
* ``info`` is an event corresponding to the update on the client information.
705
+
* ``/path/to/key`` or ``/prefix/to/watch/`` is an event that corresponds to the updates of the specific key or of multiple keys having the specified prefix.
706
+
707
+
:param string key: a key name of an event to subscribe to
708
+
:param function func: a callback to invoke when the key value is updated
709
+
:return: a watcher handle. The handle consists of one method -- ``unregister()``, which unregisters the watcher.
710
+
711
+
To read more about watchers, see the :ref:`Functions for watchers <box-watchers>` section.
712
+
713
+
The method has the same syntax as :ref:`box.watch() <box-watch>` and :ref:`conn:watch() <conn-watch>` functions. In fact, the call ``<config.storage client>:watch('<key>', f)`` internally subscribes to ``config.storage.<key>`` or to ``config.storage:<path>`` event broadcast through :ref:`IPROTO <box_protocol-id>`.
714
+
715
+
All registered watchers are automatically resubscribed when the connection is reestablished.
716
+
717
+
.. note::
718
+
719
+
Keep in mind that garbage collection of a watcher handle doesn't lead to the watcher's destruction.
720
+
In this case, the watcher remains registered.
721
+
It is okay to discard the result of ``watch`` function if the watcher will never be unregistered.
Example on GitHub: `tarantool_config_storage<https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/tarantool_config_storage>`_
731
+
Examples on GitHub: `config_storage<https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/instances.enabled/config_storage>`_
0 commit comments