Skip to content

Commit 12b4c1c

Browse files
committed
Roles reference
1 parent 735d4f1 commit 12b4c1c

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

doc/reference/configuration/configuration_reference.rst

+145
Original file line numberDiff line numberDiff line change
@@ -2877,6 +2877,116 @@ This section describes configuration parameters related to roles.
28772877

28782878
**Since:** :doc:`3.0.0 </release/3.0.0>`.
28792879

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

28903000
**Since:** :doc:`3.0.0 </release/3.0.0>`.
28913001

3002+
Specify a role's configuration.
3003+
This option accepts a role name as the key and a role's configuration as the value.
3004+
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 a custom ``greeter`` role to ``instance001`` and specify 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+
Then, you need to 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: `sharded_cluster_crud <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)