diff --git a/src/box/box_lua_space.cc b/src/box/box_lua_space.cc index edc3c5aa28748a7a97058873ea09454ded864188..4a6b39c813fe32e0e9fe8cb77b6e6085c44809bf 100644 --- a/src/box/box_lua_space.cc +++ b/src/box/box_lua_space.cc @@ -63,7 +63,7 @@ lbox_fillspace(struct lua_State *L, struct space *space, int i) lua_settable(L, i); lua_pushstring(L, "enabled"); - lua_pushboolean(L, space->engine.state != READY_NO_KEYS); + lua_pushboolean(L, space_index(space, 0) != 0); lua_settable(L, i); lua_getfield(L, i, "index"); diff --git a/test/box/alter_limits.result b/test/box/alter_limits.result index 1c545a9b9aa51bc3c7da120e59577e65d10e529d..dd0d16af27b730c72b6ad2957ccd9d340c0e4359 100644 --- a/test/box/alter_limits.result +++ b/test/box/alter_limits.result @@ -852,49 +852,359 @@ s:insert(3, 2) s:drop() --- ... --- ----------- --- --- --- space cache --- ----------- --- - all the various kinds of reference to a dropped space --- - iterator to index --- index to space --- space to index --- variable --- key def --- all userdata given away to lua - think how --- --- +-- ---------------------------------------------------------------- +-- SPACE CACHE: what happens to a space cache when an object is gone +-- ---------------------------------------------------------------- +s = box.schema.create_space('test') +--- +... +s1 = s +--- +... +s:create_index('primary', 'tree') +--- +... +s1.index.primary.id +--- +- 0 +... +primary = s1.index.primary +--- +... +s.index.primary:drop() +--- +... +primary.id +--- +- 0 +... +primary:select() +--- +- error: 'No index #0 is defined in space 512' +... +-- @todo: add a test case for dangling iterator (currently no checks +-- for a dangling iterator in the code +-- ---------------------------------------------------------------- +-- ---------------------------------------------------------------- +-- RECOVERY: check that all indexes are correctly built +-- during recovery regardless of when they are created +-- ---------------------------------------------------------------- +-- primary, secondary keys in a snapshot +s_empty = box.schema.create_space('s_empty') +--- +... +s_empty:create_index('primary', 'tree', {unique = true, parts = {0, 'num'}}) +--- +... +s_empty:create_index('secondary', 'hash', {unique = true, parts = {1, 'num'}}) +--- +... +s_full = box.schema.create_space('s_full') +--- +... +s_full:create_index('primary', 'tree', {unique = true, parts = {0, 'num'}}) +--- +... +s_full:create_index('secondary', 'hash', {unique = true, parts = {1, 'num'}}) +--- +... +s_full:insert(1, 1, 'a') +--- +- [1, 1, 'a'] +... +s_full:insert(2, 2, 'b') +--- +- [2, 2, 'b'] +... +s_full:insert(3, 3, 'c') +--- +- [3, 3, 'c'] +... +s_full:insert(4, 4, 'd') +--- +- [4, 4, 'd'] +... +s_full:insert(5, 5, 'e') +--- +- [5, 5, 'e'] +... +s_nil = box.schema.create_space('s_nil') +--- +... +s_drop = box.schema.create_space('s_drop') +--- +... +box.snapshot() +--- +- ok +... +s_drop:drop() +--- +... +s_nil:create_index('primary', 'hash', {unique=true, parts = {0, 'num'}}) +--- +... +s_nil:insert(1,2,3,4,5,6); +--- +- [1, 2, 3, 4, 5, 6] +... +s_nil:insert(7, 8, 9, 10, 11,12) +--- +- [7, 8, 9, 10, 11, 12] +... +s_nil:create_index('secondary', 'tree', {unique=false, parts = {1, 'num', 2, 'num', 3, 'num'}}) +--- +... +s_nil:insert(13, 14, 15, 16, 17) +--- +- [13, 14, 15, 16, 17] +... +r_empty = box.schema.create_space('r_empty') +--- +... +r_empty:create_index('primary', 'tree', {unique = true, parts = {0, 'num'}}) +--- +... +r_empty:create_index('secondary', 'hash', {unique = true, parts = {1, 'num'}}) +--- +... +r_full = box.schema.create_space('r_full') +--- +... +r_full:create_index('primary', 'tree', {unique = true, parts = {0, 'num'}}) +--- +... +r_full:create_index('secondary', 'hash', {unique = true, parts = {1, 'num'}}) +--- +... +r_full:insert(1, 1, 'a') +--- +- [1, 1, 'a'] +... +r_full:insert(2, 2, 'b') +--- +- [2, 2, 'b'] +... +r_full:insert(3, 3, 'c') +--- +- [3, 3, 'c'] +... +r_full:insert(4, 4, 'd') +--- +- [4, 4, 'd'] +... +r_full:insert(5, 5, 'e') +--- +- [5, 5, 'e'] +... +s_full:create_index('multikey', 'tree', {unique = true, parts = { 1, 'num', 2, 'str'}}) +--- +... +s_full:insert(6, 6, 'f') +--- +- [6, 6, 'f'] +... +s_full:insert(7, 7, 'g') +--- +- [7, 7, 'g'] +... +s_full:insert(8, 8, 'h') +--- +- [8, 8, 'h'] +... +r_disabled = box.schema.create_space('r_disabled') +--- +... +--# stop server default +--# start server default +s_empty = box.space['s_empty'] +--- +... +s_full = box.space['s_full'] +--- +... +s_nil = box.space['s_nil'] +--- +... +s_drop = box.space['s_drop'] +--- +... +r_empty = box.space['r_empty'] +--- +... +r_full = box.space['r_full'] +--- +... +r_disabled = box.space['r_disabled'] +--- +... +s_drop +--- +- null +... +s_empty.index.primary.type +--- +- TREE +... +s_full.index.primary.type +--- +- TREE +... +r_empty.index.primary.type +--- +- TREE +... +r_full.index.primary.type +--- +- TREE +... +s_nil.index.primary.type +--- +- HASH +... +s_empty.index.primary.name +--- +- primary +... +s_full.index.primary.name +--- +- primary +... +r_empty.index.primary.name +--- +- primary +... +r_full.index.primary.name +--- +- primary +... +s_nil.index.primary.name +--- +- primary +... +s_empty.enabled +--- +- true +... +s_full.enabled +--- +- true +... +r_empty.enabled +--- +- true +... +r_full.enabled +--- +- true +... +s_nil.enabled +--- +- true +... +r_disabled.enabled +--- +- false +... +s_empty.index.secondary.name +--- +- secondary +... +s_full.index.secondary.name +--- +- secondary +... +r_empty.index.secondary.name +--- +- secondary +... +r_full.index.secondary.name +--- +- secondary +... +s_nil.index.secondary.name +--- +- secondary +... +s_empty.index.primary:count(1) +--- +- 0 +... +s_full.index.primary:count(1) +--- +- 1 +... +r_empty.index.primary:count(1) +--- +- 0 +... +r_full.index.primary:count(1) +--- +- 1 +... +s_nil.index.primary:count(1) +--- +- 1 +... +s_empty.index.secondary:count(1) +--- +- 0 +... +s_full.index.secondary:count(1) +--- +- 1 +... +r_empty.index.secondary:count(1) +--- +- 0 +... +r_full.index.secondary:count(1) +--- +- 1 +... +s_nil.index.secondary:count(1) +--- +- 0 +... +s_empty.index.primary:select() +--- +... +s_full.index.primary:select() +--- +- [1, 1, 'a'] +- [2, 2, 'b'] +- [3, 3, 'c'] +- [4, 4, 'd'] +- [5, 5, 'e'] +- [6, 6, 'f'] +- [7, 7, 'g'] +- [8, 8, 'h'] +... +r_empty.index.primary:select() +--- +... +r_full.index.primary:select() +--- +- [1, 1, 'a'] +- [2, 2, 'b'] +- [3, 3, 'c'] +- [4, 4, 'd'] +- [5, 5, 'e'] +... +s_nil.index.secondary:select() +--- +- [1, 2, 3, 4, 5, 6] +- [7, 8, 9, 10, 11, 12] +- [13, 14, 15, 16, 17] +... -- -- inject error at various stages of commit and see that --- the alter has no effects --- - test that during commit phase --- -> inject error at commit, inject error at rollback +-- the alter has no effects -- --- usability +-- @todo usability -- --------- -- - space name in all error messages! -- error: Duplicate key exists in unique index 1 (ugly) -- --- triggers --- -------- --- - test that after disabling triggers we can --- create an empty snapshot --- - test for run_triggers on/off --- --- recovery --- -------- --- - add primary key in snapshot --- - add secondary key in snapshot --- - add primary key in xlog --- - add secondary key in xlog --- - the same for an empty space and a space with data --- - test start from a space entry added in xlog --- - test start from a space entry dropped in xlog --- - test enabled/disabled property for these --- spaces and space from a snapshot --- --- --- features +-- @todo features -------- -- - ffi function to enable/disable space diff --git a/test/box/alter_limits.test.lua b/test/box/alter_limits.test.lua index 9dae0f4ae83df86da2ad24466386d8ceba90010b..07ac0a66a403fcec2d275119cc0eb1a5d3885582 100644 --- a/test/box/alter_limits.test.lua +++ b/test/box/alter_limits.test.lua @@ -293,49 +293,138 @@ s:insert(2, 2) s.index.secondary:alter({ unique = false}) s:insert(3, 2) s:drop() --- ----------- --- --- --- space cache --- ----------- --- - all the various kinds of reference to a dropped space --- - iterator to index --- index to space --- space to index --- variable --- key def --- all userdata given away to lua - think how --- --- +-- ---------------------------------------------------------------- +-- SPACE CACHE: what happens to a space cache when an object is gone +-- ---------------------------------------------------------------- +s = box.schema.create_space('test') +s1 = s +s:create_index('primary', 'tree') +s1.index.primary.id +primary = s1.index.primary +s.index.primary:drop() +primary.id +primary:select() +-- @todo: add a test case for dangling iterator (currently no checks +-- for a dangling iterator in the code +-- ---------------------------------------------------------------- +-- ---------------------------------------------------------------- +-- RECOVERY: check that all indexes are correctly built +-- during recovery regardless of when they are created +-- ---------------------------------------------------------------- +-- primary, secondary keys in a snapshot +s_empty = box.schema.create_space('s_empty') +s_empty:create_index('primary', 'tree', {unique = true, parts = {0, 'num'}}) +s_empty:create_index('secondary', 'hash', {unique = true, parts = {1, 'num'}}) + +s_full = box.schema.create_space('s_full') +s_full:create_index('primary', 'tree', {unique = true, parts = {0, 'num'}}) +s_full:create_index('secondary', 'hash', {unique = true, parts = {1, 'num'}}) + +s_full:insert(1, 1, 'a') +s_full:insert(2, 2, 'b') +s_full:insert(3, 3, 'c') +s_full:insert(4, 4, 'd') +s_full:insert(5, 5, 'e') + +s_nil = box.schema.create_space('s_nil') + +s_drop = box.schema.create_space('s_drop') + +box.snapshot() + +s_drop:drop() + +s_nil:create_index('primary', 'hash', {unique=true, parts = {0, 'num'}}) +s_nil:insert(1,2,3,4,5,6); +s_nil:insert(7, 8, 9, 10, 11,12) +s_nil:create_index('secondary', 'tree', {unique=false, parts = {1, 'num', 2, 'num', 3, 'num'}}) +s_nil:insert(13, 14, 15, 16, 17) + +r_empty = box.schema.create_space('r_empty') +r_empty:create_index('primary', 'tree', {unique = true, parts = {0, 'num'}}) +r_empty:create_index('secondary', 'hash', {unique = true, parts = {1, 'num'}}) + +r_full = box.schema.create_space('r_full') +r_full:create_index('primary', 'tree', {unique = true, parts = {0, 'num'}}) +r_full:create_index('secondary', 'hash', {unique = true, parts = {1, 'num'}}) + +r_full:insert(1, 1, 'a') +r_full:insert(2, 2, 'b') +r_full:insert(3, 3, 'c') +r_full:insert(4, 4, 'd') +r_full:insert(5, 5, 'e') + +s_full:create_index('multikey', 'tree', {unique = true, parts = { 1, 'num', 2, 'str'}}) +s_full:insert(6, 6, 'f') +s_full:insert(7, 7, 'g') +s_full:insert(8, 8, 'h') + +r_disabled = box.schema.create_space('r_disabled') + +--# stop server default +--# start server default + +s_empty = box.space['s_empty'] +s_full = box.space['s_full'] +s_nil = box.space['s_nil'] +s_drop = box.space['s_drop'] +r_empty = box.space['r_empty'] +r_full = box.space['r_full'] +r_disabled = box.space['r_disabled'] + +s_drop + +s_empty.index.primary.type +s_full.index.primary.type +r_empty.index.primary.type +r_full.index.primary.type +s_nil.index.primary.type + +s_empty.index.primary.name +s_full.index.primary.name +r_empty.index.primary.name +r_full.index.primary.name +s_nil.index.primary.name + +s_empty.enabled +s_full.enabled +r_empty.enabled +r_full.enabled +s_nil.enabled +r_disabled.enabled + +s_empty.index.secondary.name +s_full.index.secondary.name +r_empty.index.secondary.name +r_full.index.secondary.name +s_nil.index.secondary.name + +s_empty.index.primary:count(1) +s_full.index.primary:count(1) +r_empty.index.primary:count(1) +r_full.index.primary:count(1) +s_nil.index.primary:count(1) + +s_empty.index.secondary:count(1) +s_full.index.secondary:count(1) +r_empty.index.secondary:count(1) +r_full.index.secondary:count(1) +s_nil.index.secondary:count(1) + +s_empty.index.primary:select() +s_full.index.primary:select() +r_empty.index.primary:select() +r_full.index.primary:select() +s_nil.index.secondary:select() + -- -- inject error at various stages of commit and see that --- the alter has no effects --- - test that during commit phase --- -> inject error at commit, inject error at rollback +-- the alter has no effects -- --- usability +-- @todo usability -- --------- -- - space name in all error messages! -- error: Duplicate key exists in unique index 1 (ugly) -- --- triggers --- -------- --- - test that after disabling triggers we can --- create an empty snapshot --- - test for run_triggers on/off --- --- recovery --- -------- --- - add primary key in snapshot --- - add secondary key in snapshot --- - add primary key in xlog --- - add secondary key in xlog --- - the same for an empty space and a space with data --- - test start from a space entry added in xlog --- - test start from a space entry dropped in xlog --- - test enabled/disabled property for these --- spaces and space from a snapshot --- --- --- features +-- @todo features -------- -- - ffi function to enable/disable space