Skip to content

Commit

Permalink
Centralized storage: update per review
Browse files Browse the repository at this point in the history
  • Loading branch information
andreyaksenov committed Mar 6, 2024
1 parent 4c38036 commit de3c76c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 47 deletions.
4 changes: 2 additions & 2 deletions doc/concepts/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ There are two approaches to configuring Tarantool:
* *Since version 3.0*: In the YAML format.

YAML configuration allows you to provide the full cluster topology and specify all configuration options.
You can use local configuration in a YAML file for each instance or store configuration data in one reliable place using :ref:`etcd <configuration_etcd_overview>`.
You can use local configuration in a YAML file for each instance or store configuration data in a reliable :ref:`centralized storage <configuration_etcd_overview>`.

* *In version 2.11 and earlier*: :ref:`In code <configuration_code>` using the ``box.cfg`` API.

Expand Down Expand Up @@ -335,7 +335,7 @@ Centralized configuration
:end-before: ee_note_centralized_config_end


Tarantool enables you to store configuration data in one reliable place, for example, a Tarantool or etcd-based configuration storage.
Tarantool enables you to store configuration data in one place using a Tarantool or etcd-based storage.
To achieve this, you need to:

1. Set up a centralized configuration storage.
Expand Down
81 changes: 37 additions & 44 deletions doc/concepts/configuration/configuration_etcd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,33 @@ Centralized configuration storages
**Examples on GitHub**: `centralized_config <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/centralized_config/>`_

Tarantool enables you to store configuration data in one place using a Tarantool or etcd-based storage.
Tarantool enables you to store a cluster's configuration in one reliable place using a Tarantool or etcd-based storage:

- A Tarantool-based configuration storage is a replica set that stores a cluster's configuration in :ref:`synchronous <repl_sync>` spaces.
- `etcd <https://etcd.io/>`__ is a distributed key-value storage for any type of critical data used by distributed systems.

With a :ref:`local YAML configuration <configuration_file>`, you need to make sure that all cluster instances use identical configuration files:

|
.. image:: tarantool_config_local.png
:align: left
:width: 500
:alt: Local configuration file

|
Using a centralized configuration storage, all instances get the actual configuration from one place:

|
.. image:: tarantool_config_centralized.png
:align: left
:width: 500
:alt: Centralized configuration storage

|
This topic describes how to set up a configuration storage, publish a cluster configuration to this storage, and use this configuration for all cluster instances.


Expand All @@ -43,7 +55,6 @@ Setting up a configuration storage
Tarantool-based storage
~~~~~~~~~~~~~~~~~~~~~~~

A Tarantool-based storage is a replica set that stores configuration data in :ref:`synchronous <repl_sync>` spaces.
To make a replica set act as a configuration storage, use the built-in ``config.storage`` :ref:`role <configuration_reference_roles_options>`.


Expand Down Expand Up @@ -117,46 +128,6 @@ Learn more from the :ref:`Starting and stopping instances <admin-start_stop_inst



.. _centralized_configuration_storage_tarantool_interact:

Interacting with the storage
****************************

The :ref:`config module <config-module>` provides the API for interacting with the configuration storage.
For example, you can get the configuration stored by the specified path using the ``config.storage.get()`` function:

.. literalinclude:: /code_snippets/snippets/centralized_config/instances.enabled/tarantool_config_storage/myapp.lua
:language: lua
:start-after: get_config_by_path
:end-at: get('/myapp/config/all')
:dedent:

To get all configurations stored by the specified prefix (ending with ``/``), pass it to ``config.storage.get()``:

.. literalinclude:: /code_snippets/snippets/centralized_config/instances.enabled/tarantool_config_storage/myapp.lua
:language: lua
:start-after: get_config_by_prefix
:end-at: get('/myapp/')
:dedent:

Learn more from the :ref:`config_storage_api_reference` section.


.. _centralized_configuration_storage_tarantool_watch_changes:

Watching configuration updates
******************************

The ``net.box module`` provides the ability to monitor configuration updates by watching path or prefix changes.
In the example below, :ref:`conn:watch() <conn-watch>` is used to monitor updates of a configuration stored by the ``/myapp/config/all`` path:

.. literalinclude:: /code_snippets/snippets/centralized_config/instances.enabled/config_storage/myapp.lua
:language: lua
:dedent:

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>`_.



.. _centralized_configuration_storage_set_up_etcd:

Expand Down Expand Up @@ -213,7 +184,7 @@ To publish a cluster's configuration (``source.yaml``) to a centralized storage,

.. code-block:: console
$ tt cluster publish "http://localhost:2379/myapp" source.yaml
$ tt cluster publish "http://sampleuser:123456@localhost:2379/myapp" source.yaml
Executing this command publishes a cluster configuration by the ``/myapp/config/all`` path.

Expand All @@ -222,12 +193,34 @@ Executing this command publishes a cluster configuration by the ``/myapp/config/
You can see a cluster's configuration using the ``tt cluster show`` command.



.. _centralized_configuration_storage_publish_config_tarantool:

Publishing configuration using 'config.storage'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The :ref:`config module <config-module>` provides the API for interacting with a Tarantool-based configuration storage.
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:

.. literalinclude:: /code_snippets/snippets/centralized_config/instances.enabled/tarantool_config_storage/myapp.lua
:language: lua
:start-after: function put_config
:end-at: cluster_config_handle:close()
:dedent:

Learn more from the :ref:`config_storage_api_reference` section.

.. NOTE::

The ``net.box module`` provides the ability to monitor configuration updates by watching path or prefix changes. Learn more in :ref:`conn:watch() <conn-watch>`.


.. _centralized_configuration_storage_publish_config_etcdctl:

Publishing configuration using etcdctl
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To publish a cluster's configuration using the ``etcdctl`` utility, use the ``put`` command:
To publish a cluster's configuration to etcd using the ``etcdctl`` utility, use the ``put`` command:

.. code-block:: console
Expand Down
14 changes: 13 additions & 1 deletion doc/reference/reference_lua/net_box.rst
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ Below is a list of all ``net.box`` functions.
In this case, the watcher remains registered.
It is okay to discard the result of ``watch`` function if the watcher will never be unregistered.

**Example:**
**Example 1:**

Server:

Expand All @@ -601,6 +601,18 @@ Below is a list of all ``net.box`` functions.
w:unregister()
**Example 2:**

The ``net.box module`` provides the ability to monitor :ref:`updates of a configuration <centralized_configuration_storage_publish_config_tarantool>` stored in a Tarantool-based configuration storage by watching path or prefix changes.
In the example below, :ref:`conn:watch() <conn-watch>` is used to monitor updates of a configuration stored by the ``/myapp/config/all`` path:

.. literalinclude:: /code_snippets/snippets/centralized_config/instances.enabled/config_storage/myapp.lua
:language: lua
:dedent:

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>`_.


.. _net_box-is_async:

.. method:: request(... {is_async=...})
Expand Down

0 comments on commit de3c76c

Please sign in to comment.