config: introduce roles
This patch introduces initial support for roles. Dependencies are not currently supported for roles. Part of #9078 @TarantoolBot document Title: Roles Two new options have been added: "roles" and "roles_cfg". The first one is an array and the second one is a map. Each of these can be defined per instance, replica set, group, and globally. As with almost all other options, with the exception of those defined as 'map', the 'roles' option for the lower scope will replace the roles for the higher scope. Value roles_cfg however defined as "map", so it will be merged. The "roles" option defines the roles for each instance. A role is a program that runs when a configuration is loaded or reloaded. If a role is defined more than once on an instance, it will still only be run once. Three functions must be defined in the role: validate(), apply() and stop(). Each of these functions should throw an error if it occurs. The "roles_cfg" option specifies the configuration for each role. In this option, the role name is the key and the role configuration is the value. On each run, all roles will be loaded (if necessary) in the order in which they were specified; the configuration for each role will then be validated using the corresponding validate() function in the same order; and then they will all be run with apply() function in the same order. If some roles have been removed from the instance, they will be stopped in reverse order using the stop() function. Example of a role structure: ``` local M = {} -- Validates configuration of the role. -- -- Called on initial configuration apply at startup and on -- configuration reload if the role is enabled for the given instance. -- -- The cfg argument may have arbitrary user provided value, -- including nil. -- -- Must raise an error if the validation fail. function M.validate(cfg) -- <...> end -- Applies the given configuration of the role. -- -- Called on initial configuration apply at startup and on -- configuration reload if the role is enabled for the given instance. -- -- The cfg argument may have arbitrary user provided value, -- including nil. -- -- Must raise an error if the given configuration can't be applied. function M.apply(cfg) -- <...> end -- Stops the role. -- -- Called on configuration reload if the role was enabled before -- and removed now from the list of roles of the given instance. -- -- Should cancel all background fibers and clean up hold -- resources. -- -- Must raise an error if this action can't be performed. function M.stop() -- <...> end return M ```
Showing
- changelogs/unreleased/gh-9078-roles.md 4 additions, 0 deletionschangelogs/unreleased/gh-9078-roles.md
- src/box/CMakeLists.txt 1 addition, 0 deletionssrc/box/CMakeLists.txt
- src/box/lua/config/applier/roles.lua 87 additions, 0 deletionssrc/box/lua/config/applier/roles.lua
- src/box/lua/config/init.lua 1 addition, 0 deletionssrc/box/lua/config/init.lua
- src/box/lua/config/instance_config.lua 7 additions, 0 deletionssrc/box/lua/config/instance_config.lua
- src/box/lua/init.c 5 additions, 0 deletionssrc/box/lua/init.c
- test/config-luatest/helpers.lua 34 additions, 2 deletionstest/config-luatest/helpers.lua
- test/config-luatest/roles_test.lua 355 additions, 0 deletionstest/config-luatest/roles_test.lua
Loading
Please register or sign in to comment