Skip to content

on_event callback for roles #4666

Open
@TarantoolBot

Description

@TarantoolBot

Dev. issue: tarantool/tarantool#10538

Product: Tarantool
Since: 3.3.0
Root document: https://www.tarantool.io/en/doc/latest/platform/app/app_roles/
SME: @ grafin

Details

Roles can now set a on_event callback, which will be called
every time a box.status system event is broadcasted or the
configuration has been updated (after the apply has finished).

on_event callbacks are called one after another in the order
the roles are applied (according to their dependencies). Each
event (box.status or configuration change) triggers a series
of callbacks, next series (for a new event) will be triggered
after the previous finishes.

on_event callbacks are executed inside a pcall and if error is
raised, it is logged with 'error' level and the series execution
continues.

It is guaranteed that all of the on_event triggers are executed as
part of the configuration process (and 'ready' or 'check_warnings'
status is reached only after all of them are done).

When the callback is called, three arguments are provided,
on_event(config, key, value) where:
config is the current configuration,
key is 'config.apply' if the callback was trigger by configuration
update, or 'box.status' if it was triggered by box.status system
event.
value is the same as in box.status system event.

Example usage:

local config = require('config')

return {
    validate = ...,
    apply = ...,
    stop = ...,
    -- TODO: config parameter should contain role's config,
    -- but 3.3.0 passes the whole instance config to it. It
    -- is a bug (gh-10934).
    on_event = function(_config, key, value)
        local log = require('log')

        log.info('on_event is triggered by ' .. key)
        log.info('is_ro: ' .. value.is_ro)
        log.info('roles_cfg.my_role.foo: ' .. config:get('roles_cfg.my_role.foo'))
    end,
}

Requested by @grafin in tarantool/tarantool@88e656c.

Metadata

Metadata

Assignees

Labels

3.3server[area] Task relates to Tarantool's server (core) functionality

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions