box.read_view.open()
Create a new read view.
Parameters:
-
opts(table) — (optional) configurations options for a read view.For example, the
nameoption specifies a read view name. Ifnameis not specified, a read view name is set tounknown.The
idoption specifies the identifier of an existing read view to attach to, as obtained via theidfield of a read view object. Specifyingidlets an application thread attach to a read view that was already opened in the main thread. A new read view (that is, called withoutid) can still be created only in the main thread — callingbox.read_view.open()withoutidin 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})
An object that represents a read view.
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) — iftrue, the returned table includes arefsfield (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.72158296id: 2signature: 0is_system: falsestatus: openvclock: {1: 12}name: my_read_viewrefs:- type: fiberfid: 101- type: threadthread_id: 1group_name: app- type: threadthread_id: 2group_name: app...
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 tofuncafter the read view object
Returns
the value(s) returned by func
Example:
local function read_view_avg(rv, space_name, field_name)local count = 0local sum = 0for _, tuple in rv.space[space_name]:pairs() dosum = sum + tuple[field_name]count = count + 1if count % 1000 == 0 then-- yield once in a while so as not to block other fibersfiber.yield()endendreturn sum / countendlocal rv = box.read_view.open()local avg = rv:with(read_view_avg, 'my_space', 'some_field')
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.
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
A unique numeric identifier of a read view.
Return type
number
A read view name. You can specify a read view name in the box.read_view.open() arguments.
Return type
string
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
The fiber.clock() value at the moment of opening a read view.
Return type
number
The box.info.vclock value at the moment of opening a read view.
Return type
table
The box.info.signature value at the moment of opening a read view.
Return type
number
Get access to database spaces included in a read view. You can use this field to query space data.
Return type
space object