|
1 | 1 | .. _box-once: |
2 | 2 |
|
3 | | -------------------------------------------------------------------------------- |
4 | | - Function box.once |
5 | | -------------------------------------------------------------------------------- |
| 3 | +Function box.once |
| 4 | +================= |
6 | 5 |
|
7 | 6 | .. function:: box.once(key, function[, ...]) |
8 | 7 |
|
|
18 | 17 | stopping the database. The solution is to delete the ``once`` object from |
19 | 18 | the system space :ref:`_schema <box_space-schema>`. |
20 | 19 | Say ``box.space._schema:select{}``, find your ``once`` object there and |
21 | | - delete it. For example, re-executing a block with ``key='hello'`` : |
| 20 | + delete it. |
22 | 21 |
|
23 | 22 | When ``box.once()`` is used for initialization, it may be useful to |
24 | 23 | wait until the database is in an appropriate state (read-only or read-write). |
25 | 24 | In that case, see the functions in the :doc:`/reference/reference_lua/box_ctl`. |
26 | 25 |
|
27 | | - .. code-block:: tarantoolsession |
| 26 | + :param string key: a value that will be checked |
| 27 | + :param function function: a function |
| 28 | + :param ...: arguments that must be passed to the function |
| 29 | + |
| 30 | + .. NOTE:: |
| 31 | + |
| 32 | + The parameter ``key`` will be stored in the :ref:`_schema <box_space-schema>` |
| 33 | + system space after ``box.once()`` is called in order to prevent a double |
| 34 | + run. These keys are global per replica set. So a simultaneous call of |
| 35 | + ``box.once()`` with the same key on two instances of the same replica set |
| 36 | + may succeed on both of them, but it'll lead to a transaction conflict. |
28 | 37 |
|
29 | | - tarantool> box.space._schema:select{} |
| 38 | + |
| 39 | + **Example** |
| 40 | + |
| 41 | + The example shows how to re-execute the ``box.once()`` block that contains the ``hello`` key. |
| 42 | + |
| 43 | + First, check the ``_schema`` system space. |
| 44 | + The ``_schema`` space in the example contains two ``box.once`` objects -- ``oncebye`` and ``oncehello``: |
| 45 | + |
| 46 | + .. code-block:: tarantoolsession |
| 47 | +
|
| 48 | + app:instance001> box.space._schema:select{} |
30 | 49 | --- |
31 | | - - - ['cluster', 'b4e15788-d962-4442-892e-d6c1dd5d13f2'] |
32 | | - - ['max_id', 512] |
33 | | - - ['oncebye'] |
| 50 | + - - ['oncebye'] |
34 | 51 | - ['oncehello'] |
35 | | - - ['version', 1, 7, 2] |
36 | | - ... |
| 52 | + - ['replicaset_name', 'replicaset001'] |
| 53 | + - ['replicaset_uuid', '72d2d9bf-5d9f-48c4-ba80-9d657e128fee'] |
| 54 | + - ['version', 3, 1, 0] |
| 55 | +
|
| 56 | + Delete the ``oncehello`` object: |
| 57 | + |
| 58 | + .. code-block:: tarantoolsession |
37 | 59 |
|
38 | | - tarantool> box.space._schema:delete('oncehello') |
| 60 | + app:instance001> box.space._schema:delete('oncehello') |
39 | 61 | --- |
40 | 62 | - ['oncehello'] |
41 | 63 | ... |
42 | 64 |
|
43 | | - tarantool> box.once('hello', function() end) |
| 65 | + After that, check the ``_schema`` space again: |
| 66 | + |
| 67 | + .. code-block:: tarantoolsession |
| 68 | +
|
| 69 | + app:instance001> box.space._schema:select{} |
44 | 70 | --- |
| 71 | + - - ['oncebye'] |
| 72 | + - ['replicaset_name', 'replicaset001'] |
| 73 | + - ['replicaset_uuid', '72d2d9bf-5d9f-48c4-ba80-9d657e128fee'] |
| 74 | + - ['version', 3, 1, 0] |
45 | 75 | ... |
46 | 76 |
|
47 | | - :param string key: a value that will be checked |
48 | | - :param function function: a function |
49 | | - :param ...: arguments that must be passed to function |
| 77 | + To re-execute the function, call the ``box.once()`` method again: |
50 | 78 |
|
51 | | - .. NOTE:: |
| 79 | + .. code-block:: tarantoolsession |
| 80 | +
|
| 81 | + app:instance001> box.once('hello', function() end) |
| 82 | + --- |
| 83 | + ... |
| 84 | +
|
| 85 | + app:instance001> box.space._schema:select{} |
| 86 | + --- |
| 87 | + - - ['oncebye'] |
| 88 | + - ['oncehello'] |
| 89 | + - ['replicaset_name', 'replicaset001'] |
| 90 | + - ['replicaset_uuid', '72d2d9bf-5d9f-48c4-ba80-9d657e128fee'] |
| 91 | + - ['version', 3, 1, 0] |
| 92 | + ... |
52 | 93 |
|
53 | | - The parameter ``key`` will be stored in the :ref:`_schema <box_space-schema>` |
54 | | - system space after ``box.once()`` is called in order to prevent a double |
55 | | - run. These keys are global per replica set. So a simultaneous call of |
56 | | - ``box.once()`` with the same key on two instances of the same replica set |
57 | | - may succeed on both of them, but it'll lead to a transaction conflict. |
|
0 commit comments