Skip to content

Commit 8564127

Browse files
committed
Roles reference
1 parent 735d4f1 commit 8564127

File tree

1 file changed

+147
-2
lines changed

1 file changed

+147
-2
lines changed

doc/reference/configuration/configuration_reference.rst

+147-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,116 @@ 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+
The ``validate()`` and ``apply()`` methods are executed for related roles 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()`` 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 ``roles.crud-router`` and ``roles.crud-storage`` roles provided by the `CRUD <https://github.com/tarantool/crud>`__ module on routers and storages, respectively:
2932+
2933+
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster_crud/config.yaml
2934+
:language: yaml
2935+
:start-at: routers
2936+
:end-at: roles.crud-router
2937+
:dedent:
2938+
2939+
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster_crud/config.yaml
2940+
:language: yaml
2941+
:start-at: storages
2942+
:end-at: roles.crud-storage
2943+
:dedent:
2944+
2945+
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>`_.
2946+
2947+
**Example: Custom role**
2948+
2949+
The configuration below shows how to assign the custom ``greeter`` role to ``instance001`` and specify the configuration for this role:
2950+
2951+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role/config.yaml
2952+
:language: yaml
2953+
:start-at: instance001
2954+
:end-at: greeting
2955+
:dedent:
2956+
2957+
You can define the ``validate()``, ``apply()``, and ``stop()`` functions in the role's code as follows:
2958+
2959+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role/greeter.lua
2960+
:language: lua
2961+
:dedent:
2962+
2963+
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>`_.
2964+
2965+
**Example: Role dependency**
2966+
2967+
The example below shows how to implement the ``greeter`` role:
2968+
2969+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role_dependency/greeter.lua
2970+
:language: lua
2971+
:dedent:
2972+
2973+
The ``byeer`` role also has the ``greeter`` role specified in the ``dependencies`` field:
2974+
2975+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role_dependency/byeer.lua
2976+
:language: lua
2977+
:dedent:
2978+
2979+
In the configuration, an instance can't have only the ``byeer`` role because it depends on the ``greeter`` role.
2980+
In this example, ``instance001`` has both roles:
2981+
2982+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role_dependency/config.yaml
2983+
:language: yaml
2984+
:start-at: instance001
2985+
:end-at: byeer
2986+
:dedent:
2987+
2988+
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>`_.
2989+
2990+
28802991
|
28812992
| Type: array
28822993
| Default: nil
@@ -2889,6 +3000,40 @@ This section describes configuration parameters related to roles.
28893000

28903001
**Since:** :doc:`3.0.0 </release/3.0.0>`.
28913002

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

0 commit comments

Comments
 (0)