Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
|
@@ -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} |
|
|
|
|
|