Функция box.once
-
box.once(key, function[, ...])¶ Выполнение функции при условии, что она раньше не выполнялась. Передаваемое значение проверяется на предмет того, выполнялась ли функция. Если она выполнялась, ничего не происходит. В противном случае вызывается функция.
See an example of using
box.once()in Adding storage code.Warning: If an error occurs inside
box.once()when initializing a database, you can re-execute the failedbox.once()block without stopping the database. The solution is to delete theonceobject from the system space _schema. Saybox.space._schema:select{}, find youronceobject there and delete it.Когда
box.once()используется для инициализации, следует подождать, пока база данных не будет в нужном состоянии (только для чтения или для чтения и записи). Для этого см. функции во Вложенный модуль box.ctl.Параметры: - key (
string) – значение для проверки - function (
function) – функция - ... – arguments that must be passed to the function
Примечание
Параметр
keyсохраняется в системном спейсе _schema после вызоваbox.once(), чтобы предотвратить повторный вызов по ключу. Эти ключи распространяются на набор реплик. Поэтому одновременный вызовbox.onceс одинаковыми ключами на двух экземплярах одного набора реплик может быть успешным, но приведет к конфликту транзакций.Example
The example shows how to re-execute the
box.once()block that contains thehellokey.First, check the
_schemasystem space. The_schemaspace in the example contains twobox.onceobjects –oncebyeandoncehello:app:instance001> box.space._schema:select{} --- - - ['oncebye'] - ['oncehello'] - ['replicaset_name', 'replicaset001'] - ['replicaset_uuid', '72d2d9bf-5d9f-48c4-ba80-9d657e128fee'] - ['version', 3, 1, 0]
Delete the
oncehelloobject:app:instance001> box.space._schema:delete('oncehello') --- - ['oncehello'] ...
After that, check the
_schemaspace again:app:instance001> box.space._schema:select{} --- - - ['oncebye'] - ['replicaset_name', 'replicaset001'] - ['replicaset_uuid', '72d2d9bf-5d9f-48c4-ba80-9d657e128fee'] - ['version', 3, 1, 0] ...
To re-execute the function, call the
box.once()method again:app:instance001> box.once('hello', function() end) --- ... app:instance001> box.space._schema:select{} --- - - ['oncebye'] - ['oncehello'] - ['replicaset_name', 'replicaset001'] - ['replicaset_uuid', '72d2d9bf-5d9f-48c4-ba80-9d657e128fee'] - ['version', 3, 1, 0] ...
- key (