Skip to content

Commit 24547d9

Browse files
authored
Add conditional config docs (#4364)
Resolves #3939
1 parent 4de4578 commit 24547d9

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
conditional:
2+
- if: tarantool_version < 3.1.0
3+
labels:
4+
upgraded: 'false'
5+
- if: tarantool_version >= 3.1.0
6+
labels:
7+
upgraded: 'true'
8+
compat:
9+
box_error_serialize_verbose: 'new'
10+
box_error_unpack_type_and_code: 'new'
11+
12+
groups:
13+
group001:
14+
replicasets:
15+
replicaset001:
16+
instances:
17+
instance001: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
instance001:

Diff for: doc/concepts/configuration.rst

+56
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,63 @@ In the example below, ``{{ instance_name }}`` is replaced with *instance001*.
355355

356356
As a result, the paths to :ref:`snapshots and write-ahead logs <configuration_persistence>` differ for different instances.
357357

358+
.. _configuration_conditional:
358359

360+
Conditional configuration sections
361+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
362+
363+
A YAML configuration can include parts that apply only to instances that meet certain conditions.
364+
This is useful for cluster upgrade scenarios: during an upgrade, instances can be running
365+
different Tarantool versions and therefore require different configurations.
366+
367+
Conditional parts are defined in the :ref:`conditional <configuration_reference_conditional>` configuration section in the global scope.
368+
It includes one or more ``if`` subsections. Each ``if`` subsection defines conditions
369+
and configuration parts that apply to instances that meet these conditions.
370+
371+
The example below shows a ``conditional`` section for cluster upgrade from Tarantool 3.0.0
372+
to Tarantool 3.1.0:
373+
374+
- The user-defined :ref:`label <configuration_labels>` ``upgraded`` is ``true``
375+
on instances that are running Tarantool 3.1.0 or later. On older versions, it is ``false``.
376+
- Two :ref:`compat <configuration_reference_compat>` options that were introduced in 3.1.0 are defined for Tarantool 3.1.0
377+
instances. On older versions, they would cause an error.
378+
379+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/conditional/config.yaml
380+
:language: yaml
381+
:start-at: conditional:
382+
:end-before: groups:
383+
:dedent:
384+
385+
Example on GitHub: `conditional <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/config/instances.enabled/conditional>`_
386+
387+
388+
``if`` sections can use one variable -- ``tarantool_version``. It contains
389+
a three-number Tarantool version and compares with values of the same format
390+
using the comparison operators ``>``, ``<``, ``>=``, ``<=``, ``==``, and ``!=``.
391+
You can write complex conditions using the logical operators ``||`` (OR) and ``&&`` (AND).
392+
Parentheses ``()`` can be used to define the operators precedence.
393+
394+
.. code-block:: yaml
395+
396+
conditional:
397+
- if: (tarantool_version > 3.2.0 || tarantool_version == 3.1.3) && tarantool_version <= 3.99.0
398+
-- < ... >
399+
400+
401+
If the same option is set in multiple ``if`` sections that are true for an instance,
402+
this option receives the value from the section declared last in the configuration.
403+
404+
Example:
405+
406+
.. code-block:: yaml
407+
408+
conditional:
409+
- if: tarantool_version >= 3.0.0
410+
labels:
411+
version: '3.0' # applies to versions >= 3.0.0 and < 3.1.0
412+
- if: tarantool_version >= 3.1.0
413+
labels:
414+
version: '3.1+' # applies to versions >= 3.1.0
359415
360416
.. _configuration_environment_variable:
361417

Diff for: doc/reference/configuration/configuration_reference.rst

+51
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,57 @@ The ``compat`` section defines values of the :ref:`compat <compat-module>` modul
688688
| Default: 'new'
689689
| Environment variable: TT_COMPAT_YAML_PRETTY_MULTILINE
690690
691+
692+
.. _configuration_reference_conditional:
693+
694+
conditional
695+
-----------
696+
697+
The ``conditional`` section defines the configuration parts that apply to instances
698+
that meet certain conditions.
699+
700+
.. NOTE::
701+
702+
``conditional`` can be defined in the global :ref:`scope <configuration_scopes>` only.
703+
704+
* :ref:`conditional.if <configuration_reference_conditional_if>`
705+
706+
.. _configuration_reference_conditional_if:
707+
708+
.. confval:: conditional.if
709+
710+
Specify a conditional section of the configuration. The configuration options
711+
defined inside a ``conditional.if`` section apply only to instances on which
712+
the specified condition is true.
713+
714+
Conditions can include one variable -- ``tarantool_version``: a three-number
715+
Tarantool version running on the instance, for example, 3.1.0. It compares to
716+
*version literal* values that include three numbers separated by periods (``x.y.z``).
717+
718+
The following operators are available in conditions:
719+
720+
- comparison: ``>``, ``<``, ``>=``, ``<=``, ``==``, ``!=``
721+
- logical operators ``||`` (OR) and ``&&`` (AND)
722+
- parentheses ``()``
723+
724+
**Example**:
725+
726+
In this example, different configuration parts apply to instances running
727+
Tarantool versions above and below 3.1.0:
728+
729+
- On versions less than 3.1.0, the ``upgraded`` label is set to ``false``.
730+
- On versions 3.1.0 or newer, the ``upgraded`` label is set to ``true``.
731+
Additionally, new ``compat`` options are defined. These options were introduced
732+
in version 3.1.0, so on older versions they would cause an error.
733+
734+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/conditional/config.yaml
735+
:language: yaml
736+
:start-at: conditional:
737+
:end-before: groups:
738+
:dedent:
739+
740+
See also: :ref:`configuration_conditional`
741+
691742
.. _configuration_reference_config:
692743

693744
config

0 commit comments

Comments
 (0)