Skip to content

Commit 9d64371

Browse files
committed
bugfix: update stale schema for metadata gen
Corrects using of an stale schema to generate metadata during `crud.update` working. Now `utils.get_space` using `schema_reload` before returning space to `crud.update` logic. Closes #236
1 parent 57bcf8d commit 9d64371

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

crud/common/utils.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ function utils.get_space(space_name, vshard_router, timeout)
139139
return nil, GetSpaceError:new(error_msg)
140140
end
141141

142+
replicaset.master.conn:reload_schema()
142143
local space = replicaset.master.conn.space[space_name]
143144

144145
return space

test/entrypoint/srv_simple_operations.lua

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,33 @@ package.preload['customers-storage'] = function()
5050
if_not_exists = true,
5151
})
5252

53-
rawset(_G, 'add_extra_field', function(name)
54-
local new_format = box.space.developers:format()
55-
table.insert(new_format, {name = name, type = 'any', is_nullable = true})
56-
box.space.developers:format(new_format)
53+
rawset(_G, 'add_extra_field', function(space_name, field_name)
54+
local space = box.space[space_name]
55+
local new_format = space:format()
56+
table.insert(new_format, {name = field_name, type = 'any', is_nullable = true})
57+
space:format(new_format)
5758
end)
5859

60+
local countries_space = box.schema.space.create('countries', {
61+
format = {
62+
{name = 'id', type = 'unsigned'},
63+
{name = 'bucket_id', type = 'unsigned'},
64+
{name = 'name', type = 'string'},
65+
{name = 'population', type = 'unsigned'},
66+
},
67+
if_not_exists = true,
68+
engine = engine,
69+
})
70+
countries_space:create_index('id', {
71+
parts = { {field = 'id'} },
72+
if_not_exists = true,
73+
})
74+
countries_space:create_index('bucket_id', {
75+
parts = { {field = 'bucket_id'} },
76+
unique = false,
77+
if_not_exists = true,
78+
})
79+
5980
-- Space with huge amount of nullable fields
6081
-- an object that inserted in such space should get
6182
-- explicit nulls in absence fields otherwise

test/integration/simple_operations_test.lua

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ pgroup.test_intermediate_nullable_fields_update = function(g)
411411

412412
helpers.call_on_servers(g.cluster, {'s1-master', 's2-master'}, function(server)
413413
for i = 1, 12 do
414-
server.net_box:call('add_extra_field', {'extra_' .. tostring(i)})
414+
server.net_box:call('add_extra_field', {'developers', 'extra_' .. tostring(i)})
415415
end
416416
end)
417417

@@ -490,6 +490,28 @@ pgroup.test_intermediate_nullable_fields_update = function(g)
490490
})
491491
end
492492

493+
pgroup.test_gh_236_update_return_actual_metadata = function(g)
494+
-- This test checks the relevance of metadata when crud.update working.
495+
-- The reproduction of the bug in the issue [1] was detected when working
496+
-- with bucket_id 2804 (id = 3 at countries space), which base on another
497+
-- storage relative to bucket 477 (id = 1 at countries space).
498+
-- [1] https://github.com/tarantool/crud/issues/236
499+
500+
local result, err = g.cluster.main_server.net_box:call(
501+
'crud.insert', {'countries', {3, box.NULL, 'vatican', 825}})
502+
t.assert_equals(err, nil)
503+
t.assert_not_equals(err, result)
504+
505+
helpers.call_on_servers(g.cluster, {'s1-master', 's2-master'}, function(server)
506+
server.net_box:call('add_extra_field', {'countries', 'extra_gh_236_update'})
507+
end)
508+
509+
local result, err = g.cluster.main_server.net_box:call('crud.update',
510+
{'countries', 3, {{'=', 'extra_gh_236_update', 'testing' }}})
511+
t.assert_equals(err, nil)
512+
t.assert_equals(result.metadata[5], {is_nullable = true, name = 'extra_gh_236_update', type = 'any'})
513+
end
514+
493515
pgroup.test_object_with_nullable_fields = function(g)
494516
-- Insert
495517
local result, err = g.cluster.main_server.net_box:call(

0 commit comments

Comments
 (0)