Tarantool CE/EE Documentation portal logo
Support
Updated at July 17, 2026   02:08 PM

box.atomic()

box.atomic([opts,] tx-function [, function-arguments])

Execute a function, acting as if the function starts with an implicit /reference/reference_lua/box_txn_management/begin and ends with an implicit /reference/reference_lua/box_txn_management/commit if successful, or ends with an implicit /reference/reference_lua/box_txn_management/rollback if there is an error.

Parameters:

  • opts (table) — (optional) transaction options:

  • txn_isolation – the transaction isolation level

  • timeout – a timeout (in seconds), after which the transaction is rolled back

  • tx-function (string) — the function name

  • function-arguments — (optional) arguments passed to the function

Returns

the result of the function passed to atomic() as an argument

Possible errors:

  • error and abort the transaction in case of a conflict.
  • error and abort the transaction if the timeout is exceeded.
  • error if the operation fails to write to disk.
  • error if for some reason memory cannot be allocated.

Example

-- Create an index with the specified sequence --box.schema.sequence.create('id_sequence', { min = 1 })box.space.bands:create_index('primary', { parts = { 'id' }, sequence = 'id_sequence' })-- Insert test data --box.space.bands:insert { 1, 'Roxette', 1986 }box.space.bands:insert { 2, 'Scorpions', 1965 }box.space.bands:insert { 3, 'Ace of Base', 1987 }-- Define a function --local function insert_band(band_name, year)    box.space.bands:insert { nil, band_name, year }end-- Begin and commit the transaction implicitly --box.atomic(insert_band, 'The Beatles', 1960)-- Begin the transaction with the specified isolation level --box.atomic({ txn_isolation = 'read-committed' },        insert_band, 'The Rolling Stones', 1962)