Skip to content

Commit b0f6e99

Browse files
committed
Fixes gh-101 Document module
1 parent 38c828c commit b0f6e99

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

sphinx/dev_guide/internals.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.. _internals:
22

3+
.. _internals-data_persistence:
4+
35
--------------------------------------------------------------------------------
46
Data persistence and the WAL file format
57
--------------------------------------------------------------------------------

sphinx/reference/reference_lua/errcodes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ robust when there are errors, particularly database errors.
7474
say |br|
7575
:samp:`if pcall(box.space.{space-name}:{function-name}() ...`
7676

77+
For some Tarantool box functions, pcall also returns error details
78+
including a file-name and line-number within Tarantool's source code.
79+
This can be seen by unpacking. For example: |br|
80+
``x, y = pcall(function() box.schema.space.create('') end)`` |br|
81+
``y:unpack()``
82+
7783
See the tutorial :ref:`Sum a JSON field for all tuples <c_lua_tutorial-sum_a_json_field>`
7884
to see how pcall can fit in an application.
7985

sphinx/reference/reference_lua/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ This reference covers Tarantool's built-in Lua modules.
4040
tap
4141
tarantool
4242
uuid
43+
xlog
4344
yaml
4445
other
4546
errcodes

sphinx/reference/reference_lua/msgpack.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ takes a series of non-MsgPack values and encodes them.
6262
- [20, null, 20]
6363
...
6464
65+
.. _msgpack-serialize:
66+
6567
The MsgPack output structure can be specified with ``__serialize``:
6668

6769
* ``__serialize = "seq" or "sequence"`` for an array
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
.. _xlog:
2+
3+
-------------------------------------------------------------------------------
4+
Module `xlog`
5+
-------------------------------------------------------------------------------
6+
7+
The xlog module contains one function: pairs().
8+
It can be used to read Tarantool's snapshot files
9+
or write-ahead-log (WAL) files.
10+
A description of the file format is in section
11+
:ref:`Data persistence and the WAL file format <internals-data_persistence>`.
12+
13+
.. _box_index-index_pairs:
14+
15+
.. method:: pairs([file-name])
16+
17+
Open a file,
18+
and allow iterating over one file entry at a time.
19+
20+
Return: `iterator <https://www.lua.org/pil/7.1.html>`_ which can be used in a for/end loop.
21+
22+
Possible errors: File does not contain properly formatted snapshot or write-ahead-log information.
23+
24+
Example:
25+
26+
This will read the first write-ahead-log (WAL) file that was
27+
created in the :ref:`wal_dir <cfg_basic-wal_dir>` directory by the
28+
introductory sandbox exercise
29+
":ref:`Starting Tarantool and making your first database <user_guide_getting_started-first_database>`“.
30+
31+
Each result from ``pairs()`` is formatted with MsgPack
32+
so its structure can be specified with :ref:`__serialize <msgpack-serialize>`.
33+
34+
.. code-block:: none
35+
36+
xlog = require('xlog')
37+
t = {}
38+
for k, v in xlog.pairs('00000000000000000000.xlog') do
39+
table.insert(t, setmetatable(v, { __serialize = "map"}))
40+
end
41+
return t
42+
43+
The first lines of the result will look like:
44+
45+
.. code-block:: none
46+
47+
...
48+
---
49+
- - {'BODY': {'space_id': 272, 'index_base': 1, 'key': ['max_id'],
50+
'tuple': [['+', 2, 1]]},
51+
'HEADER': {'type': 'UPDATE', 'timestamp': 1477846870.8541,
52+
'lsn': 1, 'server_id': 1}}
53+
- {'BODY': {'space_id': 280,
54+
'tuple': [512, 1, 'tester', 'memtx', 0, {}, []]},
55+
'HEADER': {'type': 'INSERT', 'timestamp': 1477846870.8597,
56+
'lsn': 2, 'server_id': 1}}
57+

0 commit comments

Comments
 (0)