From 1e3b020f2df60e44774d63db0007c0e84e474085 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja@tarantool.org> Date: Thu, 9 Oct 2014 19:55:31 +0400 Subject: [PATCH] Don't store a reference to Lua space in index, store space id instead. --- src/box/lua/schema.lua | 22 +++++++++++----------- src/box/lua/space.cc | 4 ++-- test/box/alter_limits.result | 17 +++-------------- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua index b4ea14a2e4..212946343b 100644 --- a/src/box/lua/schema.lua +++ b/src/box/lua/schema.lua @@ -521,7 +521,7 @@ function box.schema.space.bless(space) local index_mt = {} -- __len and __index index_mt.len = function(index) - local ret = builtin.boxffi_index_len(index.space.id, index.id) + local ret = builtin.boxffi_index_len(index.space_id, index.id) if ret == -1 then box.error() end @@ -556,7 +556,7 @@ function box.schema.space.bless(space) end index_mt.random = function(index, rnd) rnd = rnd or math.random() - local tuple = builtin.boxffi_index_random(index.space.id, index.id, rnd) + local tuple = builtin.boxffi_index_random(index.space_id, index.id, rnd) if tuple == ffi.cast('void *', -1) then box.error() -- error elseif tuple ~= nil then @@ -585,7 +585,7 @@ function box.schema.space.bless(space) end local keybuf = ffi.string(pkey, pkey_end - pkey) - local cdata = builtin.boxffi_index_iterator(index.space.id, index.id, + local cdata = builtin.boxffi_index_iterator(index.space_id, index.id, itype, keybuf); if cdata == nil then box.error() @@ -626,7 +626,7 @@ function box.schema.space.bless(space) index_mt.get = function(index, key) local key, key_end = msgpackffi.encode_tuple(key) port.size = 0; - if builtin.boxffi_select(ffi.cast(port_t, port), index.space.id, + if builtin.boxffi_select(ffi.cast(port_t, port), index.space_id, index.id, box.index.EQ, 0, 2, key, key_end) ~=0 then return box.error() end @@ -669,7 +669,7 @@ function box.schema.space.bless(space) end port.size = 0; - if builtin.boxffi_select(ffi.cast(port_t, port), index.space.id, + if builtin.boxffi_select(ffi.cast(port_t, port), index.space_id, index.id, iterator, offset, limit, key, key_end) ~=0 then return box.error() end @@ -682,22 +682,22 @@ function box.schema.space.bless(space) end index_mt.update = function(index, key, ops) ops = normalize_update_ops(ops) - return internal.update(index.space.id, index.id, keify(key), ops); + return internal.update(index.space_id, index.id, keify(key), ops); end index_mt.delete = function(index, key) - return internal.delete(index.space.id, index.id, keify(key)); + return internal.delete(index.space_id, index.id, keify(key)); end index_mt.drop = function(index) - return box.schema.index.drop(index.space.id, index.id) + return box.schema.index.drop(index.space_id, index.id) end index_mt.rename = function(index, name) - return box.schema.index.rename(index.space.id, index.id, name) + return box.schema.index.rename(index.space_id, index.id, name) end index_mt.alter= function(index, options) - if index.id == nil or index.space == nil then + if index.id == nil or index.space_id == nil then box.error(box.error.PROC_LUA, "Usage: index:alter{opts}") end - return box.schema.index.alter(index.space.id, index.id, options) + return box.schema.index.alter(index.space_id, index.id, options) end -- local space_mt = {} diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc index 3ba4207d3a..baa15f906b 100644 --- a/src/box/lua/space.cc +++ b/src/box/lua/space.cc @@ -168,8 +168,8 @@ lbox_fillspace(struct lua_State *L, struct space *space, int i) lua_pushnumber(L, key_def->iid); lua_setfield(L, -2, "id"); - lua_pushvalue(L, i); - lua_setfield(L, -2, "space"); + lua_pushnumber(L, space->def.id); + lua_setfield(L, -2, "space_id"); lua_pushstring(L, key_def->name); lua_setfield(L, -2, "name"); diff --git a/test/box/alter_limits.result b/test/box/alter_limits.result index 2979bf6c37..be2884b36c 100644 --- a/test/box/alter_limits.result +++ b/test/box/alter_limits.result @@ -634,25 +634,14 @@ s.index.primary:alter({type='tree', unique=false, name='pk'}) --# push filter 'function: .*' to 'function <pointer>' s.index.primary --- -- &0 - unique: true +- unique: true parts: - type: NUM fieldno: 1 id: 0 - type: HASH - space: - index: - 0: *0 - primary: *0 - on_replace: 'function <pointer> - temporary: false - id: 512 - engine: memtx - enabled: true - name: test - field_count: 0 + space_id: 512 name: primary + type: HASH ... --# clear filter s.index.pk.type -- GitLab