Skip to content

Commit cef17a0

Browse files
authored
Update lua_call behavior: config option and supervised failover tutorial (#4648)
Resolves #4462
1 parent d339f88 commit cef17a0

File tree

4 files changed

+71
-45
lines changed

4 files changed

+71
-45
lines changed

doc/code_snippets/snippets/replication/instances.enabled/supervised_failover/source.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ credentials:
55
roles: [ replication ]
66
privileges:
77
- permissions: [ execute ]
8-
functions: [ 'failover.execute' ]
8+
lua_call: [ 'failover.execute' ]
99

1010
iproto:
1111
advertise:
@@ -23,8 +23,6 @@ failover:
2323
keepalive_interval: 5
2424
renew_interval: 1
2525

26-
roles: [ 'supervised_instance' ]
27-
2826
groups:
2927
group001:
3028
replicasets:

doc/code_snippets/snippets/replication/instances.enabled/supervised_failover/supervised_instance.lua

Lines changed: 0 additions & 23 deletions
This file was deleted.

doc/platform/replication/supervised_failover.rst

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -106,49 +106,96 @@ Configuring a cluster
106106

107107
To configure a cluster to work with an external failover coordinator, follow the steps below:
108108

109-
1. (Optional) If you need to run :ref:`several failover coordinators <supervised_failover_overview_fault_tolerance>` to increase fault tolerance, set up an etcd-based configuration storage, as described in :ref:`configuration_etcd`.
109+
#. (Optional) If you need to run :ref:`several failover coordinators <supervised_failover_overview_fault_tolerance>` to increase fault tolerance, set up an etcd-based configuration storage, as described in :ref:`configuration_etcd`.
110110

111-
2. Set the :ref:`replication.failover <configuration_reference_replication_failover>` option to ``supervised``:
111+
#. Set the :ref:`replication.failover <configuration_reference_replication_failover>` option to ``supervised``:
112112

113113
.. literalinclude:: /code_snippets/snippets/replication/instances.enabled/supervised_failover/source.yaml
114114
:language: yaml
115115
:start-at: replication:
116116
:end-at: failover: supervised
117117
:dedent:
118118

119-
3. Grant a user used for replication :ref:`permissions <configuration_credentials_managing_users_roles_granting_privileges>` to execute the ``failover.execute`` function:
119+
#. Grant a user used for replication :ref:`permissions <configuration_credentials_managing_users_roles_granting_privileges>` to execute the ``failover.execute`` function:
120120

121121
.. literalinclude:: /code_snippets/snippets/replication/instances.enabled/supervised_failover/source.yaml
122122
:language: yaml
123123
:start-at: credentials:
124124
:end-at: failover.execute
125125
:dedent:
126126

127-
4. Create the ``failover.execute`` function in the application code.
128-
For example, you can create a :ref:`custom role <application_roles>` for this purpose:
127+
.. note::
129128

130-
.. literalinclude:: /code_snippets/snippets/replication/instances.enabled/supervised_failover/supervised_instance.lua
131-
:language: lua
132-
:dedent:
133-
134-
Then, you need to enable this role for all storage instances:
135-
136-
.. literalinclude:: /code_snippets/snippets/replication/instances.enabled/supervised_failover/source.yaml
137-
:language: yaml
138-
:start-at: supervised_instance
139-
:end-before: groups:
140-
:dedent:
129+
In Tarantool 3.0 and 3.1, the configuration is different and the function
130+
must be created in the application code. See :ref:`supervised_failover_configuration_with_role` for details.
141131

142-
5. (Optional) Configure options that control how a failover coordinator operates in the :ref:`failover <configuration_reference_failover>` section:
132+
#. (Optional) Configure options that control how a failover coordinator operates in the :ref:`failover <configuration_reference_failover>` section:
143133

144134
.. literalinclude:: /code_snippets/snippets/replication/instances.enabled/supervised_failover/source.yaml
145135
:language: yaml
146136
:start-after: failover: supervised
147-
:end-before: supervised_instance
137+
:end-before: groups
148138
:dedent:
149139

150140
You can find the full example on GitHub: `supervised_failover <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/replication/instances.enabled/supervised_failover>`_.
151141

142+
.. _supervised_failover_configuration_with_role:
143+
144+
Tarantool 3.0 and 3.1 configuration
145+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
146+
147+
Before version 3.2, Tarantool used another mechanism to grant execute access to Lua
148+
functions. In Tarantool 3.0 and 3.1, the ``credentials`` configuration section
149+
should look as follows:
150+
151+
.. code-block:: yaml
152+
153+
# Tarantool 3.0 and 3.1
154+
credentials:
155+
users:
156+
replicator:
157+
password: 'topsecret'
158+
roles: [ replication ]
159+
privileges:
160+
- permissions: [ execute ]
161+
functions: [ 'failover.execute' ]
162+
163+
Additionally, you should create the ``failover.execute`` function in the application code.
164+
For example, you can create a :ref:`custom role <application_roles>` for this purpose:
165+
166+
.. code-block:: lua
167+
168+
-- Tarantool 3.0 and 3.1 --
169+
-- supervised_instance.lua --
170+
return {
171+
validate = function()
172+
end,
173+
apply = function()
174+
if box.info.ro then
175+
return
176+
end
177+
local func_name = 'failover.execute'
178+
local opts = { if_not_exists = true }
179+
box.schema.func.create(func_name, opts)
180+
end,
181+
stop = function()
182+
if box.info.ro then
183+
return
184+
end
185+
local func_name = 'failover.execute'
186+
if not box.schema.func.exists(func_name) then
187+
return
188+
end
189+
box.schema.func.drop(func_name)
190+
end,
191+
}
192+
193+
Then, enable this role for all storage instances:
194+
195+
.. code-block:: yaml
196+
197+
# Tarantool 3.0 and 3.1
198+
roles: [ 'supervised_instance' ]
152199
153200
.. _supervised_failover_start_coordinator:
154201

doc/reference/configuration/configuration_reference.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1445,7 +1445,11 @@ credentials.users.*
14451445

14461446
.. confval:: <user_or_role_name>.privileges.lua_call
14471447

1448-
Whether this user or a user with this role can call any global user-defined Lua function.
1448+
A list of global user-defined Lua functions that this user or a user with this role can call.
1449+
To allow calling all such functions, specify the ``all`` value.
1450+
1451+
This option should be configured together with the ``execute``
1452+
:ref:`permission <configuration_reference_credentials_privileges_permissions>`.
14491453

14501454
.. _configuration_reference_credentials_privileges_sql:
14511455

0 commit comments

Comments
 (0)