Skip to content
Snippets Groups Projects
Commit 4cc9972d authored by bigbes's avatar bigbes
Browse files

Fixes gh-636 - Flush schema in box.net.box

Added method remote:reload_schema()
parent 920986af
No related branches found
No related tags found
No related merge requests found
...@@ -40,20 +40,18 @@ local GREETING_SIZE = 128 ...@@ -40,20 +40,18 @@ local GREETING_SIZE = 128
local TIMEOUT_INFINITY = 500 * 365 * 86400 local TIMEOUT_INFINITY = 500 * 365 * 86400
local sequence_mt = { __serialize = 'sequence'} local sequence_mt = { __serialize = 'sequence' }
local mapping_mt = { __serialize = 'mapping'} local mapping_mt = { __serialize = 'mapping' }
local CONSOLE_FAKESYNC = 15121974 local CONSOLE_FAKESYNC = 15121974
local function request(header, body) local function request(header, body)
-- hint msgpack to always encode header and body as a map -- hint msgpack to always encode header and body as a map
header = msgpack.encode(setmetatable(header, mapping_mt)) header = msgpack.encode(setmetatable(header, mapping_mt))
body = msgpack.encode(setmetatable(body, mapping_mt)) body = msgpack.encode(setmetatable(body, mapping_mt))
local len = msgpack.encode(string.len(header) + string.len(body)) local len = msgpack.encode(string.len(header) + string.len(body))
return len .. header .. body return len .. header .. body
end end
...@@ -158,8 +156,7 @@ local proto = { ...@@ -158,8 +156,7 @@ local proto = {
end, end,
-- select -- select
select = function(sync, spaceno, indexno, key, opts) select = function(sync, spaceno, indexno, key, opts)
if opts == nil then if opts == nil then
opts = {} opts = {}
end end
...@@ -517,6 +514,17 @@ local remote_methods = { ...@@ -517,6 +514,17 @@ local remote_methods = {
} }
end, end,
reload_schema = function(self)
xpcall(function() self:_load_schema() end,
function(e)
log.info("Can't load schema: %s", tostring(e))
end)
if self.state ~= 'error' and self.state ~= 'closed' then
self:_switch_state('active')
end
end,
close = function(self) close = function(self)
if self.state ~= 'closed' then if self.state ~= 'closed' then
self:_switch_state('closed') self:_switch_state('closed')
...@@ -779,11 +787,11 @@ local remote_methods = { ...@@ -779,11 +787,11 @@ local remote_methods = {
_auth = function(self) _auth = function(self)
if self.opts.user == nil or self.opts.password == nil then if self.opts.user == nil or self.opts.password == nil then
self:_switch_state 'authen' self:_switch_state('authen')
return return
end end
self:_switch_state 'auth' self:_switch_state('auth')
local auth_res = self:_request_internal('auth', local auth_res = self:_request_internal('auth',
false, self.opts.user, self.opts.password, self.handshake) false, self.opts.user, self.opts.password, self.handshake)
...@@ -793,7 +801,7 @@ local remote_methods = { ...@@ -793,7 +801,7 @@ local remote_methods = {
return return
end end
self:_switch_state 'authen' self:_switch_state('authen')
end, end,
-- states wakeup _read_worker -- states wakeup _read_worker
...@@ -821,10 +829,9 @@ local remote_methods = { ...@@ -821,10 +829,9 @@ local remote_methods = {
return false return false
end, end,
_load_schema = function(self) _load_schema = function(self)
if self.state ~= 'authen' then if self.state == 'closed' or self.state == 'error' then
self:_fatal 'Can not load schema from the state' self:_fatal('Can not load schema from the state')
return return
end end
...@@ -837,7 +844,6 @@ local remote_methods = { ...@@ -837,7 +844,6 @@ local remote_methods = {
local sl = {} local sl = {}
for _, space in pairs(spaces) do for _, space in pairs(spaces) do
local name = space[3] local name = space[3]
local id = space[1] local id = space[1]
...@@ -851,7 +857,6 @@ local remote_methods = { ...@@ -851,7 +857,6 @@ local remote_methods = {
field_count = field_count, field_count = field_count,
enabled = true, enabled = true,
index = {} index = {}
} }
if #space > 5 and string.match(space[6], 'temporary') then if #space > 5 and string.match(space[6], 'temporary') then
s.temporary = true s.temporary = true
...@@ -863,7 +868,6 @@ local remote_methods = { ...@@ -863,7 +868,6 @@ local remote_methods = {
sl[id] = s sl[id] = s
sl[name] = s sl[name] = s
end end
for _, index in pairs(indexes) do for _, index in pairs(indexes) do
...@@ -1072,11 +1076,9 @@ local remote_methods = { ...@@ -1072,11 +1076,9 @@ local remote_methods = {
end, end,
_request_internal = function(self, name, raise, ...) _request_internal = function(self, name, raise, ...)
local sync = self.proto:sync() local sync = self.proto:sync()
local request = self.proto[name](sync, ...) local request = self.proto[name](sync, ...)
return self:_request_raw(sync, request, raise) return self:_request_raw(sync, request, raise)
end, end,
-- private (low level) methods -- private (low level) methods
......
...@@ -141,7 +141,7 @@ cn.space.net_box_test_space:insert{234, 1,2,3} ...@@ -141,7 +141,7 @@ cn.space.net_box_test_space:insert{234, 1,2,3}
... ...
cn.space.net_box_test_space.insert{234, 1,2,3} cn.space.net_box_test_space.insert{234, 1,2,3}
--- ---
- error: 'builtin/net.box.lua:229: Use space:method(...) instead space.method(...)' - error: 'builtin/net.box.lua:226: Use space:method(...) instead space.method(...)'
... ...
cn.space.net_box_test_space:replace{354, 1,2,3} cn.space.net_box_test_space:replace{354, 1,2,3}
--- ---
...@@ -648,3 +648,83 @@ end; ...@@ -648,3 +648,83 @@ end;
gh594() gh594()
--- ---
... ...
-- #636: Reload schema on demand
sp = box.schema.create_space('test_old')
---
...
sp:create_index('primary')
---
- unique: true
parts:
- type: NUM
fieldno: 1
id: 0
space_id: 512
name: primary
type: TREE
...
sp:insert{1, 2, 3}
---
- [1, 2, 3]
...
LISTEN = require('uri').parse(box.cfg.listen)
---
...
uri = string.format('%s:%s', LISTEN.host, LISTEN.service)
---
...
con = remote.new(uri)
---
...
con:ping()
---
- true
...
con.space.test_old:select{}
---
- - [1, 2, 3]
...
con.space.test:select{}
---
- error: '[string "return con.space.test:select{} "]:1: attempt to index field ''test''
(a nil value)'
...
sp = box.schema.create_space('test')
---
...
sp:create_index('primary')
---
- unique: true
parts:
- type: NUM
fieldno: 1
id: 0
space_id: 513
name: primary
type: TREE
...
sp:insert{2, 3, 4}
---
- [2, 3, 4]
...
con.space.test:select{}
---
- error: '[string "return con.space.test:select{} "]:1: attempt to index field ''test''
(a nil value)'
...
con:reload_schema()
---
...
con.space.test:select{}
---
- - [2, 3, 4]
...
box.space.test:drop()
---
...
box.space.test_old:drop()
---
...
con:close()
---
...
...@@ -262,3 +262,28 @@ function gh594() ...@@ -262,3 +262,28 @@ function gh594()
end; end;
--# setopt delimiter '' --# setopt delimiter ''
gh594() gh594()
-- #636: Reload schema on demand
sp = box.schema.create_space('test_old')
sp:create_index('primary')
sp:insert{1, 2, 3}
LISTEN = require('uri').parse(box.cfg.listen)
uri = string.format('%s:%s', LISTEN.host, LISTEN.service)
con = remote.new(uri)
con:ping()
con.space.test_old:select{}
con.space.test:select{}
sp = box.schema.create_space('test')
sp:create_index('primary')
sp:insert{2, 3, 4}
con.space.test:select{}
con:reload_schema()
con.space.test:select{}
box.space.test:drop()
box.space.test_old:drop()
con:close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment