Skip to content
Snippets Groups Projects
Commit 145af72b authored by Nikita Zheleztsov's avatar Nikita Zheleztsov Committed by Serge Petrenko
Browse files

lua: introduce xlog.meta() method

This commit introduces the new method for xlog module: xlog.meta().
It opens an xlog file, reads and returns the meta block of the file,
which includes its filetype, instance_uuid and vclocks.

It's needed in order to introduce checking of names inside the config
module in the following commit.

Needed for #8978

@TarantoolBot document
Title: xlog.meta(file-name) method

Description: Open an xlog file, and return its meta block.
Possible errors: Failed to open a file or it does not contain properly
formatted meta block.

Example:

```lua
tarantool> xlog = require('xlog')
---
...

tarantool> xlog.meta('00000000000000000000.snap')
---
- filetype: SNAP
  prev_vclock: {}
  instance_uuid: 87b2e60f-275c-4efa-9b0e-e9562e309692
  vclock: {}
...
```
parent 21e9ef4b
No related branches found
No related tags found
No related merge requests found
## feature/lua/xlog
* Introduced the `xlog.meta()` method for reading a meta block from an xlog
file.
......@@ -365,8 +365,48 @@ lbox_xlog_parser_open_pairs(struct lua_State *L)
return 3;
}
/** Opens an xlog file and returns its meta block. */
static int
lbox_xlog_parser_open_meta(struct lua_State *L)
{
int args_n = lua_gettop(L);
if (args_n != 1 || !lua_isstring(L, 1))
luaL_error(L, "Usage: parser.open(log_filename)");
const char *filename = luaL_checkstring(L, 1);
/* Construct xlog cursor and object */
struct xlog_cursor *cur = xcalloc(1, sizeof(struct xlog_cursor));
if (xlog_cursor_open(cur, filename) < 0) {
return luaT_error(L);
}
lua_newtable(L);
lua_pushstring(L, "filetype");
lua_pushstring(L, cur->meta.filetype);
lua_settable(L, -3);
lua_pushstring(L, "instance_uuid");
luaT_pushuuidstr(L, &cur->meta.instance_uuid);
lua_settable(L, -3);
lua_pushstring(L, "vclock");
luaT_pushvclock(L, &cur->meta.vclock);
lua_settable(L, -3);
lua_pushstring(L, "prev_vclock");
luaT_pushvclock(L, &cur->meta.prev_vclock);
lua_settable(L, -3);
xlog_cursor_close(cur, false);
free(cur);
return 1;
}
static const struct luaL_Reg lbox_xlog_parser_lib [] = {
{ "pairs", lbox_xlog_parser_open_pairs },
{ "meta", lbox_xlog_parser_open_meta },
{ NULL, NULL }
};
......
......@@ -4,6 +4,11 @@ local function xlog_pairs(...)
return fun.wrap(internal.pairs(...))
end
local function xlog_meta(...)
return internal.meta(...)
end
return {
pairs = xlog_pairs,
meta = xlog_meta,
}
......@@ -2,11 +2,13 @@ local fio = require('fio')
local server = require('luatest.server')
local t = require('luatest')
local xlog = require('xlog')
local uuid = require('uuid')
local g = t.group()
g.before_all(function(cg)
cg.server = server:new()
g.box_cfg = { instance_uuid = uuid() }
cg.server = server:new({box_cfg = g.box_cfg})
cg.server:start()
end)
......@@ -150,3 +152,14 @@ g.test_bad_xlog = function(cg)
},
})
end
g.test_xlog_meta = function(cg)
local glob = fio.glob(fio.pathjoin(cg.server.workdir, '*.snap'))
local snap_path = glob[#glob]
local meta = xlog.meta(snap_path)
t.assert_equals(meta.filetype, 'SNAP')
t.assert_equals(meta.instance_uuid, cg.box_cfg.instance_uuid)
t.assert_not_equals(meta.vclock, nil)
t.assert_not_equals(meta.prev_vclock, nil)
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment