Skip to content

Commit b9c3af8

Browse files
committed
Roles reference
1 parent 735d4f1 commit b9c3af8

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

doc/reference/configuration/configuration_reference.rst

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,6 +2877,104 @@ 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 functions and fields:
2891+
2892+
- ``validate()``
2893+
2894+
Validate a role's configuration.
2895+
This function is called when the initial configuration is applied or the configuration is reloaded for the instance with this role.
2896+
2897+
``validate()`` should throw an error if the validation fails.
2898+
2899+
- ``apply()``
2900+
2901+
Apply a role's configuration.
2902+
This function is called when the initial configuration is applied or the configuration is reloaded for the instance with this role.
2903+
2904+
``apply()`` should throw an error if the specified configuration can't be applied.
2905+
2906+
- ``stop()``:
2907+
2908+
Stop a role.
2909+
This function is called on configuration reload if the role is removed from ``roles`` for the given instance.
2910+
2911+
``stop()`` should cancel all background fibers and clean up used resources.
2912+
If these actions can't be performed, ``stop()`` should throw an error.
2913+
2914+
- (Optional) ``dependencies``
2915+
2916+
Define a role's dependencies.
2917+
2918+
**Example: Built-in role**
2919+
2920+
The examples below shows 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:
2921+
2922+
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster_crud/config.yaml
2923+
:language: yaml
2924+
:start-at: routers
2925+
:end-at: roles.crud-router
2926+
:dedent:
2927+
2928+
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster_crud/config.yaml
2929+
:language: yaml
2930+
:start-at: storages
2931+
:end-at: roles.crud-storage
2932+
:dedent:
2933+
2934+
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>`_.
2935+
2936+
**Example: Custom role**
2937+
2938+
The configuration below shows how to assign a custom ``greeter`` role to ``instance001`` and specify configuration for this role:
2939+
2940+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role/config.yaml
2941+
:language: yaml
2942+
:start-at: instance001
2943+
:end-at: greeting
2944+
:dedent:
2945+
2946+
Then, you need to define the ``validate()``, ``apply()``, and ``stop()`` functions in the role's code as follows:
2947+
2948+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role/greeter.lua
2949+
:language: lua
2950+
:dedent:
2951+
2952+
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>`_.
2953+
2954+
**Example: Role dependency**
2955+
2956+
The example below shows how to implement the ``greeter`` role:
2957+
2958+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role_dependency/greeter.lua
2959+
:language: lua
2960+
:dedent:
2961+
2962+
The ``byeer`` role has a similar implementation but also has the ``dependencies`` field specified:
2963+
2964+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role_dependency/byeer.lua
2965+
:language: lua
2966+
:dedent:
2967+
2968+
In the configuration, an instance can't have only the ``byeer`` role because it depends on the ``greeter`` role.
2969+
In this example, ``instance001`` has both roles:
2970+
2971+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role_dependency/config.yaml
2972+
:language: yaml
2973+
:dedent:
2974+
2975+
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>`_.
2976+
2977+
28802978
|
28812979
| Type: array
28822980
| Default: nil
@@ -2889,6 +2987,41 @@ This section describes configuration parameters related to roles.
28892987

28902988
**Since:** :doc:`3.0.0 </release/3.0.0>`.
28912989

2990+
Specify a role's configuration.
2991+
This option accepts a role name as the key and a role's configuration as the value.
2992+
2993+
To specify the roles of an instance, use the :ref:`roles <configuration_reference_roles>` option.
2994+
2995+
**Example: Built-in role**
2996+
2997+
The example below shows how to enable and configure the ``roles.crud-router`` role provided by the `CRUD <https://github.com/tarantool/crud>`__ module:
2998+
2999+
.. literalinclude:: /code_snippets/snippets/sharding/instances.enabled/sharded_cluster_crud/config.yaml
3000+
:language: yaml
3001+
:start-at: roles.crud-router
3002+
:end-at: stats_quantile_max_age_time
3003+
:dedent:
3004+
3005+
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>`_.
3006+
3007+
**Example: Custom role**
3008+
3009+
The configuration below shows how to assign a custom ``greeter`` role to ``instance001`` and specify configuration for this role:
3010+
3011+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role/config.yaml
3012+
:language: yaml
3013+
:start-at: instance001
3014+
:end-at: greeting
3015+
:dedent:
3016+
3017+
Then, you need to define the ``validate()``, ``apply()``, and ``stop()`` functions in the role's code as follows:
3018+
3019+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/application_role/greeter.lua
3020+
:language: lua
3021+
:dedent:
3022+
3023+
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>`_.
3024+
28923025
|
28933026
| Type: map
28943027
| Default: nil

0 commit comments

Comments
 (0)