Permalink
Browse files

net_box: update space objects instead of replacing them

Update netbox.space objects in-place instead of re-creating them
on every schema change.

Closes #2401
  • Loading branch information...
ilmarkov authored and rtsisyk committed Oct 24, 2017
1 parent 6007e6d commit 300bc7daccfc8ae3ace5a064ba190a7d3b9787be
Showing with 98 additions and 27 deletions.
  1. +15 −14 src/box/lua/net_box.lua
  2. +13 −0 test/box/alter.result
  3. +5 −0 test/box/alter.test.lua
  4. +41 −0 test/box/net.box.result
  5. +15 −0 test/box/net.box.test.lua
  6. +6 −9 test/box/sql.result
  7. +3 −4 test/box/sql.test.lua
@@ -839,18 +839,21 @@ function remote_methods:_install_schema(schema_version, spaces, indices)
local engine = space[4]
local field_count = space[5]
local format = space[7] or {}
local s = {
id = id,
name = name,
engine = engine,
field_count = field_count,
enabled = true,
index = {},
temporary = false,
_format = format,
connection = self
}
local s = {}
if self.space ~= nil and self.space[id] ~= nil then
s = self.space[id]
else
setmetatable(s, space_mt)
end
s.id = id
s.name = name
s.engine = engine
s.field_count = field_count
s.enabled = true
s.index = {}
s.temporary = false
s._format = format
s.connection = self
if #space > 5 then
local opts = space[6]
if type(opts) == 'table' then
@@ -862,8 +865,6 @@ function remote_methods:_install_schema(schema_version, spaces, indices)
end
end
setmetatable(s, space_mt)
sl[id] = s
sl[name] = s
end
@@ -1686,3 +1686,16 @@ s:insert({1, 1, 'a', 'b', 'c', 'd'})
s:drop()
---
...
s = box.schema.create_space('test')
---
...
idx = s:create_index('idx')
---
...
box.space.test == s
---
- true
...
s:drop()
---
...
@@ -641,3 +641,8 @@ s:format()
_ = s:create_index('primary')
s:insert({1, 1, 'a', 'b', 'c', 'd'})
s:drop()
s = box.schema.create_space('test')
idx = s:create_index('idx')
box.space.test == s
s:drop()
@@ -1931,6 +1931,47 @@ test_run:cmd('cleanup server connecter')
---
- true
...
--
-- gh-2401 update pseudo objects not replace them
--
space:drop()
---
...
space = box.schema.space.create('test')
---
...
c = net.connect(box.cfg.listen)
---
...
cspace = c.space.test
---
...
space.index.test_index == nil
---
- true
...
cspace.index.test_index == nil
---
- true
...
_ = space:create_index("test_index", {parts={1, 'string'}})
---
...
c:reload_schema()
---
...
space.index.test_index ~= nil
---
- true
...
cspace.index.test_index ~= nil
---
- true
...
c.space.test.index.test_index ~= nil
---
- true
...
-- cleanup
box.schema.user.revoke('guest','read,write,execute','universe')
---
@@ -779,6 +779,21 @@ disconnected_cnt
test_run:cmd('stop server connecter')
test_run:cmd('cleanup server connecter')
--
-- gh-2401 update pseudo objects not replace them
--
space:drop()
space = box.schema.space.create('test')
c = net.connect(box.cfg.listen)
cspace = c.space.test
space.index.test_index == nil
cspace.index.test_index == nil
_ = space:create_index("test_index", {parts={1, 'string'}})
c:reload_schema()
space.index.test_index ~= nil
cspace.index.test_index ~= nil
c.space.test.index.test_index ~= nil
-- cleanup
box.schema.user.revoke('guest','read,write,execute','universe')
@@ -34,32 +34,29 @@ _ = box.space.test1:create_index('primary', { type = 'hash' })
_ = box.space.test1:create_index('secondary', { type = 'hash', parts = {2, 'string'}})
---
...
conn:ping()
-- send request to remote server to force schema reloading
conn:reload_schema()
---
- true
...
-- xxx: bug currently selects no rows
space:select{}
---
- error: 'No index #0 is defined in space ''test'''
- []
...
space:insert{1, 'I am a tuple'}
---
- [1, 'I am a tuple']
...
space:select{1}
---
- error: 'No index #0 is defined in space ''test'''
- - [1, 'I am a tuple']
...
-- currently there is no way to find out how many records
-- a space contains
space:select{0}
---
- error: 'No index #0 is defined in space ''test'''
- []
...
space:select{2}
---
- error: 'No index #0 is defined in space ''test'''
- []
...
test_run:cmd('restart server default')
net_box = require('net.box')
@@ -13,15 +13,14 @@ space = conn.space.test
index = box.space.test:create_index('primary', { type = 'hash' })
_ = box.space.test1:create_index('primary', { type = 'hash' })
_ = box.space.test1:create_index('secondary', { type = 'hash', parts = {2, 'string'}})
conn:ping()
-- xxx: bug currently selects no rows
-- send request to remote server to force schema reloading
conn:reload_schema()
space:select{}
space:insert{1, 'I am a tuple'}
space:select{1}
-- currently there is no way to find out how many records
-- a space contains
space:select{0}
space:select{2}

0 comments on commit 300bc7d

Please sign in to comment.