Skip to content

Commit 6359787

Browse files
committed
Roles reference
1 parent 0ec2468 commit 6359787

File tree

1 file changed

+151
-2
lines changed

1 file changed

+151
-2
lines changed

doc/reference/configuration/configuration_reference.rst

+151-2
Original file line numberDiff line numberDiff line change
@@ -2861,11 +2861,12 @@ The ``replication`` section defines configuration parameters related to :ref:`re
28612861
roles
28622862
-----
28632863

2864-
This section describes configuration parameters related to roles.
2864+
This section describes configuration parameters related to application roles.
2865+
An application role is a Lua module that implements specific functions or logic.
28652866

28662867
.. NOTE::
28672868

2868-
Configuration parameters related to roles can be defined in any :ref:`scope <configuration_scopes>`.
2869+
Configuration parameters related to application roles can be defined in any :ref:`scope <configuration_scopes>`.
28692870

28702871
- :ref:`roles <configuration_reference_roles>`
28712872
- :ref:`roles_cfg <configuration_reference_roles_cfg>`
@@ -2877,6 +2878,120 @@ This section describes configuration parameters related to roles.
28772878

28782879
**Since:** :doc:`3.0.0 </release/3.0.0>`.
28792880

2881+
Specify the roles of an instance.
2882+
To specify a role's configuration, use the :ref:`roles_cfg <configuration_reference_roles_cfg>` option.
2883+
2884+
There are two types of application roles:
2885+
2886+
- Built-in roles. For example, the `CRUD <https://github.com/tarantool/crud>`__ module provides the ``roles.crud-storage`` and ``roles.crud-router`` roles that enable CRUD operations in a sharded cluster.
2887+
- Custom roles. For example, you create a custom role to define a stored procedure or implement a supplementary service, such as an e-mail notifier or a replicator.
2888+
2889+
To create a custom role, you need to define the following methods and fields:
2890+
2891+
- ``validate()``
2892+
2893+
Validate a role's configuration.
2894+
This method is called when the initial configuration is applied or the configuration is reloaded for the instance with this role.
2895+
``validate()`` should throw an error if the validation fails.
2896+
2897+
- ``apply()``
2898+
2899+
Apply a role's configuration.
2900+
This method is called when the initial configuration is applied or the configuration is reloaded for the instance with this role.
2901+
``apply()`` should throw an error if the specified configuration can't be applied.
2902+
2903+
- ``stop()``
2904+
2905+
Stop a role.
2906+
This method is called on configuration reload if the role is removed from ``roles`` for the given instance.
2907+
``stop()`` should cancel all background fibers and clean up used resources.
2908+
If these actions can't be performed, ``stop()`` should throw an error.
2909+
2910+
- (Optional) ``dependencies``
2911+
2912+
Define a role's dependencies as an array.
2913+
For roles that depend on each other, their ``validate()`` and ``apply()`` methods are executed taking into account the dependencies.
2914+
Suppose, there are three roles that depend on each other as follows:
2915+
2916+
.. code-block:: none
2917+
2918+
role1
2919+
└─── role2
2920+
└─── role3
2921+
2922+
In this case, ``validate()`` and ``apply()`` for these roles are executed in the following order:
2923+
2924+
.. code-block:: none
2925+
2926+
role3 -> role2 -> role1
2927+
2928+
2929+
**Example: Built-in role**
2930+
2931+
The examples below show how to enable the router and storage-specific roles provided by the `CRUD <https://github.com/tarantool/crud>`__ module:
2932+
2933+
- ``roles.crud-router``:
2934+
2935+
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster_crud/config.yaml
2936+
:language: yaml
2937+
:start-at: routers
2938+
:end-at: roles.crud-router
2939+
:dedent:
2940+
2941+
- ``roles.crud-storage``:
2942+
2943+
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster_crud/config.yaml
2944+
:language: yaml
2945+
:start-at: storages
2946+
:end-at: roles.crud-storage
2947+
:dedent:
2948+
2949+
You can find the full example here: `sharded_cluster_crud <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/sharding/instances.enabled/sharded_cluster_crud>`_.
2950+
2951+
**Example: Custom role**
2952+
2953+
The configuration below shows how to enable the custom ``greeter`` role for ``instance001`` and specify the configuration for this role using :ref:`roles_cfg <configuration_reference_roles_cfg>`:
2954+
2955+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role/config.yaml
2956+
:language: yaml
2957+
:start-at: instance001
2958+
:end-at: greeting
2959+
:dedent:
2960+
2961+
You can define the ``validate()``, ``apply()``, and ``stop()`` functions in the role's code as follows:
2962+
2963+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role/greeter.lua
2964+
:language: lua
2965+
:dedent:
2966+
2967+
You can find the full example here: `application_role <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/config/instances.enabled/application_role>`_.
2968+
2969+
**Example: Role dependency**
2970+
2971+
The example below implements the ``greeter`` role:
2972+
2973+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role_dependency/greeter.lua
2974+
:language: lua
2975+
:dedent:
2976+
2977+
The ``byeer`` role has the ``greeter`` role in the ``dependencies`` field:
2978+
2979+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role_dependency/byeer.lua
2980+
:language: lua
2981+
:dedent:
2982+
2983+
In the configuration, an instance cannot have only the ``byeer`` role because it depends on the ``greeter`` role.
2984+
In this example, ``instance001`` has both roles enabled:
2985+
2986+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role_dependency/config.yaml
2987+
:language: yaml
2988+
:start-at: instance001
2989+
:end-at: byeer
2990+
:dedent:
2991+
2992+
You can find the full example here: `application_role_dependency <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/config/instances.enabled/application_role_dependency>`_.
2993+
2994+
28802995
|
28812996
| Type: array
28822997
| Default: nil
@@ -2889,6 +3004,40 @@ This section describes configuration parameters related to roles.
28893004

28903005
**Since:** :doc:`3.0.0 </release/3.0.0>`.
28913006

3007+
Specify a role's configuration.
3008+
This option accepts a role name as the key and a role's configuration as the value.
3009+
To specify the roles of an instance, use the :ref:`roles <configuration_reference_roles>` option.
3010+
3011+
**Example: Built-in role**
3012+
3013+
The example below shows how to enable and configure the ``roles.crud-router`` role provided by the `CRUD <https://github.com/tarantool/crud>`__ module:
3014+
3015+
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster_crud/config.yaml
3016+
:language: yaml
3017+
:start-at: roles.crud-router
3018+
:end-at: stats_quantile_max_age_time
3019+
:dedent:
3020+
3021+
You can find the full example here: `sharded_cluster_crud <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/sharding/instances.enabled/sharded_cluster_crud>`_.
3022+
3023+
**Example: Custom role**
3024+
3025+
The configuration below shows how to enable the custom ``greeter`` role for ``instance001`` and specify the configuration for this role:
3026+
3027+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role/config.yaml
3028+
:language: yaml
3029+
:start-at: instance001
3030+
:end-at: greeting
3031+
:dedent:
3032+
3033+
You can define the ``validate()``, ``apply()``, and ``stop()`` functions in the role's code as follows:
3034+
3035+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role/greeter.lua
3036+
:language: lua
3037+
:dedent:
3038+
3039+
You can find the full example here: `application_role <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/config/instances.enabled/application_role>`_.
3040+
28923041
|
28933042
| Type: map
28943043
| Default: nil

0 commit comments

Comments
 (0)