From 39e30941b0c4c8b90c8df129b157ef7075f0ae34 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja.osipov@gmail.com> Date: Tue, 7 Feb 2012 22:42:12 +0400 Subject: [PATCH] A fix and a test case for Bug#928413 "Lua malfunctions..." We didn't check whether or not Lua bindings executed correctly, so we didn't pay attention to these problems: luaL_Buffer was misused, and when configuration would exceed 4K allocated on stack, this led to lost pieces of Lua script prepared by tarantool_lua_load_cfg(). box.on_reload_configuration() did not work correctly with disabled spaces. Fix the above mentioned issued and add a test. --- core/tarantool_lua.m | 12 +-- mod/box/box.lua | 8 +- test/box/configuration.result | 12 +++ test/box/configuration.test | 12 +++ test/box/tarantool_bug928413.cfg | 158 +++++++++++++++++++++++++++++++ 5 files changed, 193 insertions(+), 9 deletions(-) create mode 100644 test/box/tarantool_bug928413.cfg diff --git a/core/tarantool_lua.m b/core/tarantool_lua.m index ccfaebdd59..919437c0ab 100644 --- a/core/tarantool_lua.m +++ b/core/tarantool_lua.m @@ -868,13 +868,11 @@ tarantool_lua_load_cfg(struct lua_State *L, struct tarantool_cfg *cfg) if (strchr(key, '.') == NULL) { lua_pushfstring(L, "box.cfg.%s = %s%s%s\n", key, quote, value, quote); - luaL_addstring(&b, lua_tostring(L, -1)); - lua_pop(L, 1); + luaL_addvalue(&b); } else if (strncmp(key, "space", strlen("space")) == 0) { lua_pushfstring(L, "box.%s = %s%s%s\n", key, quote, value, quote); - luaL_addstring(&b, lua_tostring(L, -1)); - lua_pop(L, 1); + luaL_addvalue(&b); } free(value); } @@ -887,8 +885,10 @@ tarantool_lua_load_cfg(struct lua_State *L, struct tarantool_cfg *cfg) " box.on_reload_configuration()\n" "end\n"); luaL_pushresult(&b); - if (luaL_loadstring(L, lua_tostring(L, -1)) == 0) - lua_pcall(L, 0, 0, 0); + if (luaL_loadstring(L, lua_tostring(L, -1)) != 0 || + lua_pcall(L, 0, 0, 0) != 0) { + panic("%s", lua_tostring(L, -1)); + } lua_pop(L, 1); } diff --git a/mod/box/box.lua b/mod/box/box.lua index 1556becb92..8045fb5201 100644 --- a/mod/box/box.lua +++ b/mod/box/box.lua @@ -123,9 +123,11 @@ function box.on_reload_configuration() for i, space in pairs(box.space) do rawset(space, 'n', i) setmetatable(space, space_mt) - for j, index in pairs(space.index) do - rawset(index, 'idx', box.index.new(i, j)) - setmetatable(index, index_mt) + if type(space.index) == 'table' and space.enabled then + for j, index in pairs(space.index) do + rawset(index, 'idx', box.index.new(i, j)) + setmetatable(index, index_mt) + end end end end diff --git a/test/box/configuration.result b/test/box/configuration.result index ded392434a..d9cde07982 100644 --- a/test/box/configuration.result +++ b/test/box/configuration.result @@ -186,6 +186,18 @@ lua box.cfg.wal_fsync_delay - 0.01 ... +# Bug#928413 Lua malfunction on certain configuration +# (https://bugs.launchpad.net/bugs/928413) + +lua box.cfg.wal_fsync_delay +--- + - 0.1 +... +lua box.space[0].enabled +--- + - true +... + # Test field type conflict in keys tarantool_box -c tarantool_bad_type.cfg diff --git a/test/box/configuration.test b/test/box/configuration.test index 7eb7cb3bd6..97356e8737 100644 --- a/test/box/configuration.test +++ b/test/box/configuration.test @@ -41,6 +41,18 @@ server.deploy("box/tarantool_bug876541.cfg") # check values exec admin "lua box.cfg.wal_fsync_delay" +print """ +# Bug#928413 Lua malfunction on certain configuration +# (https://bugs.launchpad.net/bugs/928413) +""" +# stop current server +server.stop() +# start server from config with different boolean represenation +server.deploy("box/tarantool_bug928413.cfg") +# check values +exec admin "lua box.cfg.wal_fsync_delay" +exec admin "lua box.space[0].enabled" + print """ # Test field type conflict in keys """ diff --git a/test/box/tarantool_bug928413.cfg b/test/box/tarantool_bug928413.cfg new file mode 100644 index 0000000000..3038550eda --- /dev/null +++ b/test/box/tarantool_bug928413.cfg @@ -0,0 +1,158 @@ +slab_alloc_arena = 0.1 + +pid_file = "box.pid" + +logger="cat - >> tarantool.log" + +primary_port = 33013 +secondary_port = 33014 +admin_port = 33015 + +log_level = 4 + +local_hot_standby = true + +slab_alloc_minimal = 48 + +# Growth factor, each subsecuent unit size is factor * prev unit size +slab_alloc_factor = 1.04 + + +# SESSIONS!!! ##################################### +#memcached_space = 52 +space[0].enabled = 1 +#namespace[0].expire_field = 2 + +space[0].index[0].type = "HASH" +space[0].index[0].unique = 1 +space[0].index[0].key_field[0].type = "STR" +space[0].index[0].key_field[0].fieldno = 0 + +space[0].index[1].type = "TREE" +space[0].index[1].unique = 0 +space[0].index[1].key_field[0].type = "STR" +space[0].index[1].key_field[0].fieldno = 1 +################################################### + +# video meta. Indexes: 1.ACCID +space[46] = { + enabled = 1 + index = [{ + type = "HASH" + unique = 1 + key_field = [{ + fieldno = 0 + type = "NUM" + }] + }] + } + +# upload meta. Indexes: 1.ITEMID 2.ACCID 3.UPLOADTIME +space[47] = { + enabled = 1 + index = [{ + type="HASH" + unique = 1 + Key_field = [{ + fieldno = 0 + type = "NUM64" + }] + },{ + type="TREE" + unique = 0 + Key_field = [{ + fieldno = 1 + type = "NUM" + }] + },{ + type="TREE" + unique = 0 + Key_field = [{ + fieldno = 2 + type = "NUM" + }] + }] + } + +# user meta. Indexes: 0.ITEMID 1.ACCID 2.EXTERNALID 3.FLAGS 4.STATUS 5.SERVICEID +space[48] = { + enabled = 1 + index = [{ + type="HASH" + unique = 1 + Key_field = [{ + fieldno = 0 + type = "NUM" + }] + },{ + type="TREE" + unique=0 + Key_field = [{ + fieldno = 1 + type = "NUM" + }] + }, + { + type="HASH" + unique = 1 + Key_field = [{ + fieldno = 2 + type = "STR" + }] + },{ + type="TREE" + unique = 0 + key_field = [{ + fieldno = 3 + type = "NUM" + }] + },{ + type="TREE" + unique = 0 + key_field = [{ + fieldno = 4 + type = "NUM" + }] + },{ + type="TREE" + unique = 0 + key_field = [{ + fieldno = 5 + type = "NUM" + }] + } + ] + + } +space[50] = { + enabled = 1 + index = [{ + type="HASH" + unique = 1 + Key_field = [{ + fieldno = 0 + type = "NUM" + }] + }] + } + + +space[53] = { + enabled = 1 + index = [{ + type = "HASH" + unique = 1 + key_field = [{ + fieldno = 0 + type= "NUM" + }] + }] + } + +wal_fsync_delay = 0.1 +io_collect_interval = 0.001 +logger_nonblock = true +coredump = true +snap_io_rate_limit = 50.0 +custom_proc_title = "videobox" + -- GitLab