diff --git a/doc/user/stored-procedures.xml b/doc/user/stored-procedures.xml index 9fbda02512632cf96e54fe3d5f49b62c745b99c6..d4133eff780c792087440eee2f81e8a4b5581901 100644 --- a/doc/user/stored-procedures.xml +++ b/doc/user/stored-procedures.xml @@ -1410,15 +1410,46 @@ logger = cat - >> tarantool.log <title>Package <code>box.info</code></title> <para> This package provides access to information about - server status. - The information and information from <olink - targetptr="show-info"/> are the same. + server variables: pid, uptime, version and such. + Its contents is identical to output of <olink + targetptr="show-info"/>. </para> <varlistentry> - <term><emphasis role="lua">box.info</emphasis></term> + <term> + <emphasis role="lua">box.info()</emphasis> + </term> + <listitem> + <simpara> + Since contents of box.info is dynamic, it's + not possible to iterate over keys with Lua <emphasis>pairs()</emphasis> + function. For this purpose, <emphasis>box.info()</emphasis> builds + and returns a Lua table with all keys and values + provided in the package. + </simpara> + + <bridgehead renderas="sect4">Example</bridgehead><programlisting> +localhost> lua for k,v in pairs(box.info()) do print(k, ": ", v) end +--- +version: 1.4.7-92-g4ba95ca +status: primary +pid: 1747 +lsn: 1712 +recovery_last_update: 1306964594.980 +recovery_lag: 0.000 +uptime: 39 +build: table: 0x419cb880 +logger_pid: 1748 +config: /home/unera/work/tarantool/test/box/tarantool_good.cfg +... +</programlisting> + </listitem> + </varlistentry> + <varlistentry> + <term> + <emphasis role="lua">box.info.status, box.info.pid, box.info.lsn, ...</emphasis> + </term> <listitem> - - <bridgehead renderas="sect4">Example</bridgehead><programlisting> + <bridgehead renderas="sect4">Example</bridgehead><programlisting> localhost> lua box.info.pid --- - 1747 @@ -1462,7 +1493,6 @@ target: Linux-x86_64-Debug compiler: /usr/bin/gcc options: cmake . -DCMAKE_INSTALL_PREFIX=/usr/local -DENABLE_STATIC=OFF -DENABLE_GCOV=OFF -DENABLE_TRACE=ON -DENABLE_BACKTRACE=ON -DENABLE_CLIENT=OFF ... -localhost> </programlisting> </listitem> </varlistentry> diff --git a/include/tarantool.h b/include/tarantool.h index 675ddfb9c31d7a278c28ffbfb9bc0ff15fbfea79..5b828062c894fbbbb934ff780d9685d689b64a1e 100644 --- a/include/tarantool.h +++ b/include/tarantool.h @@ -45,7 +45,7 @@ i32 mod_reload_config(struct tarantool_cfg *old_conf, struct tarantool_cfg *new_ int mod_cat(const char *filename); void mod_snapshot(struct log_io *, struct nbatch *batch); void mod_info(struct tbuf *out); -const char * mod_status(void); +const char *mod_status(void); extern struct tarantool_cfg cfg; extern const char *cfg_filename; diff --git a/mod/box/box.m b/mod/box/box.m index c8c96c77a1dcad04616e48a40671a994cd508087..b1a695f7cadfa6743eb981a186109cd82a9d092a 100644 --- a/mod/box/box.m +++ b/mod/box/box.m @@ -586,6 +586,8 @@ mod_info(struct tbuf *out) } -const char * mod_status(void) { +const char * +mod_status(void) +{ return status; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index be13d9e146ae5c5ebd54f83215cde15ef3dc6f4f..ffcc8b137f2861488f910f56f85417295a5f3b88 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -100,7 +100,7 @@ set (common_sources nio.c crc32.c rope.c - box_lua_info.m + tarantool_lua_info.m ) if (ENABLE_TRACE) diff --git a/src/tarantool_lua.m b/src/tarantool_lua.m index 447452354423f0f3dd81ff52fdf97bcdef236ce2..fad86f7eccaf1b69befffbd2741a7ecabf37bf0e 100644 --- a/src/tarantool_lua.m +++ b/src/tarantool_lua.m @@ -42,7 +42,7 @@ #include "pickle.h" #include "fiber.h" #include <ctype.h> -#include "box_lua_info.h" +#include "tarantool_lua_info.h" #include TARANTOOL_CONFIG /** diff --git a/src/box_lua_info.h b/src/tarantool_lua_info.h similarity index 90% rename from src/box_lua_info.h rename to src/tarantool_lua_info.h index 727df0e68464daccdcc62cd24968c919d6b274eb..7da7de3eadb6b7610cbb801b408b7cb55a434f7e 100644 --- a/src/box_lua_info.h +++ b/src/tarantool_lua_info.h @@ -1,5 +1,5 @@ -#ifndef INCLUDES_TARANTOOL_MOD_BOX_LUA_INFO_H -#define INCLUDES_TARANTOOL_MOD_BOX_LUA_INFO_H +#ifndef INCLUDES_TARANTOOL_LUA_INFO_H +#define INCLUDES_TARANTOOL_LUA_INFO_H /* * Redistribution and use in source and binary forms, with or @@ -33,4 +33,4 @@ struct lua_State; void lbox_info_init(struct lua_State *L); -#endif /* INCLUDES_TARANTOOL_MOD_BOX_LUA_INFO_H */ +#endif /* INCLUDES_TARANTOOL_LUA_INFO_H */ diff --git a/src/box_lua_info.m b/src/tarantool_lua_info.m similarity index 90% rename from src/box_lua_info.m rename to src/tarantool_lua_info.m index dfbfc9a6fdb6d6ec2a35b54722393dedf9304638..883f4bb0bf49d06551c28649be124f17ace871b2 100644 --- a/src/box_lua_info.m +++ b/src/tarantool_lua_info.m @@ -27,7 +27,7 @@ * SUCH DAMAGE. */ -#include "box_lua_info.h" +#include "tarantool_lua_info.h" #include "lua.h" #include "lauxlib.h" #include "lualib.h" @@ -92,14 +92,17 @@ lbox_info_dynamic_meta [] = {NULL, NULL} }; +/** Evaluate box.info.* function value and push it on the stack. */ static int lbox_info_index(struct lua_State *L) { lua_pushvalue(L, -1); /* dup key */ lua_gettable(L, lua_upvalueindex(1)); /* table[key] */ - if (!lua_isfunction(L, -1)) + if (!lua_isfunction(L, -1)) { + /* No such key. Leave nil is on the stack. */ return 1; + } lua_call(L, 0, 1); lua_remove(L, -2); @@ -108,7 +111,8 @@ lbox_info_index(struct lua_State *L) static void -lbox_info_staticvalues(struct lua_State *L) { +lbox_info_init_static_values(struct lua_State *L) +{ /* tarantool version */ lua_pushstring(L, "version"); lua_pushstring(L, tarantool_version()); @@ -157,13 +161,16 @@ lbox_info_staticvalues(struct lua_State *L) { lua_settable(L, -3); /* box.info.build */ } +/** + * When user invokes box.info(), return a table of key/value + * pairs containing the current info. + */ static int lbox_info_call(struct lua_State *L) { - unsigned i; lua_newtable(L); - lbox_info_staticvalues(L); - for (i = 0; lbox_info_dynamic_meta[i].name; i++) { + lbox_info_init_static_values(L); + for (int i = 0; lbox_info_dynamic_meta[i].name; i++) { lua_pushstring(L, lbox_info_dynamic_meta[i].name); lbox_info_dynamic_meta[i].func(L); lua_settable(L, -3); @@ -196,7 +203,7 @@ lbox_info_init(struct lua_State *L) lua_setmetatable(L, -2); - lbox_info_staticvalues(L); /* fill table */ + lbox_info_init_static_values(L); lua_settable(L, -3); /* box.info = created table */ lua_pop(L, 1); /* cleanup stack */