Tarantool CE/EE Documentation portal logo
Support
Updated at November 26, 2026   04:13 PM

box.read_view.open()

box.read_view:open({opts})

Create a new read view.

Parameters:

  • opts (table) — (optional) configurations options for a read view.

    For example, the name option specifies a read view name. If name is not specified, a read view name is set to unknown.

    The id option specifies the identifier of an existing read view to attach to, as obtained via the id field of a read view object. Specifying id lets an application thread attach to a read view that was already opened in the main thread. A new read view (that is, called without id) can still be created only in the main thread — calling box.read_view.open() without id in an application thread raises an error.

Returns

a created read view object

Return type

read_view_object

Example:

tarantool> read_view1 = box.read_view.open({name = 'read_view1'})

Example: opening a read view from an application thread

local rv = box.read_view.open({name = 'shared_read_view'})local threads = require('threads')threads.eval('app', [[  local rv = box.read_view.open({id = ...})  return rv.space.test:select()]], {rv.id})

read_view_object

An object that represents a read view.

read_view_object:info({opts})

Get information about a read view such as a name, status, or ID. All the available fields are listed below in the object options.

Parameters:

  • opts (table) — (optional) configuration options.

    • refs (boolean) — if true, the returned table includes a refs field (default: false).

Returns

information about a read view

If opts.refs is true, the returned table additionally includes a refs field — an array of references taken for this read view.

Each item in the refs array is a table with a type field set to thread for a reference held by an application thread, or fiber for a reference taken by a fiber using read_view_object:with(). The rest of the fields depend on the reference type: a thread reference also has group_name and thread_id fields, while a fiber reference has a fid field. Note that fiber references include only fibers running in the calling thread, and thread references are shown in the main thread only.

The refs option can be useful for figuring out why a particular read view isn't closed.

Return type

table

Example:

tarantool> rv:info({refs = true})---- timestamp: 215658.72158296  id: 2  signature: 0  is_system: false  status: open  vclock: {1: 12}  name: my_read_view  refs:  - type: fiber    fid: 101  - type: thread    thread_id: 1    group_name: app  - type: thread    thread_id: 2    group_name: app...

read_view_object:with(func, ...)

Call a function, ensuring that the read view object remains operational until the function returns, even if the read view is closed from another fiber while the function is running.

The function is passed the read view object as the first argument, followed by the other arguments passed to with(). read_view_object:with() returns the same value(s) as the called function returns. If the called function raises an error, the error is re-raised.

If the read view is closed (that is, read_view_object:close() is called) while the function passed to with() is still running, the read view status changes to close_pending and remains so until the function returns, after which it changes to closed and the read view's resources are freed. A read view in the close_pending status can be accessed the same way as an open read view, but calling with() on it raises an error.

Parameters:

  • func (function) — a function to call
  • ... — arguments passed to func after the read view object

Returns

the value(s) returned by func

Example:

local function read_view_avg(rv, space_name, field_name)    local count = 0    local sum = 0    for _, tuple in rv.space[space_name]:pairs() do        sum = sum + tuple[field_name]        count = count + 1        if count % 1000 == 0 then            -- yield once in a while so as not to block other fibers            fiber.yield()        end    end    return sum / countendlocal rv = box.read_view.open()local avg = rv:with(read_view_avg, 'my_space', 'some_field')

read_view_object:close()

Close a read view. After the read view is closed, its status is set to closed. On an attempt to use it, an error is raised.

If the read view is still in use by an application thread at the moment of closing, it isn't deleted right away: its status is set to close_pending instead. A read view in this status can't be used in the main thread or reopened in another thread; threads that already opened it can keep using it until they stop. Once the last user stops using it, the read view is deleted globally — either explicitly or via Lua garbage collection.

status

A read view status. The possible values are open, close_pending, and closed. A read view switches to close_pending when it's closed in the main thread while still in use by an application thread; see read_view_object:close() above.

Return type

string

id

A unique numeric identifier of a read view.

Return type

number

name

A read view name. You can specify a read view name in the box.read_view.open() arguments.

Return type

string

is_system

Determine whether a read view is system. For example, system read views can be created to make a checkpoint or join a new replica.

Return type

boolean

timestamp

The fiber.clock() value at the moment of opening a read view.

Return type

number

vclock

The box.info.vclock value at the moment of opening a read view.

Return type

table

signature

The box.info.signature value at the moment of opening a read view.

Return type

number

space

Get access to database spaces included in a read view. You can use this field to query space data.

Return type

space object