Skip to content
Snippets Groups Projects
Commit cf89abab authored by Roman Tsisyk's avatar Roman Tsisyk
Browse files

A fix and a test case for Bug#1042798 (box.truncate on non-linear pk)

parent dcb5289a
No related branches found
No related tags found
No related merge requests found
......@@ -244,11 +244,15 @@ function box.on_reload_configuration()
space_mt.replace = function(space, ...) return box.replace(space.n, ...) end
space_mt.delete = function(space, ...) return box.delete(space.n, ...) end
space_mt.truncate = function(space)
local pk = space.index[0].idx
local part_count = pk:part_count()
while #pk > 0 do
for k, v in pk.next, pk, nil do
space:delete(v:slice(0, part_count))
local pk = space.index[0]
while #pk.idx > 0 do
for _k, t in pk.idx.next, pk.idx, nil do
local key = {};
-- ipairs does not work because pk.key_field is zero-indexed
for _k2, key_field in pairs(pk.key_field) do
table.insert(key, t[key_field.fieldno])
end
space:delete(unpack(key))
end
end
end
......
......@@ -557,3 +557,37 @@ error: 'Duplicate key exists in unique index 1'
lua box.space[1]:truncate()
---
...
#
# A test case for Bug #1042798
# Truncate hangs when primary key is not in linear or starts at the first field
# https://bugs.launchpad.net/tarantool/+bug/1042798
#
lua for k, f in pairs(box.space[23].index[0].key_field) do print(k, ' => ', f.fieldno) end
---
0 => 2
1 => 1
...
lua box.insert(23, 1, 2, 3, 4)
---
- 1: {2, 3, 4}
...
lua box.insert(23, 10, 20, 30, 40)
---
- 10: {20, 30, 40}
...
lua box.insert(23, 20, 30, 40, 50)
---
- 20: {30, 40, 50}
...
lua for _k, v in box.space[23]:pairs() do print(v) end
---
1: {2, 3, 4}
10: {20, 30, 40}
20: {30, 40, 50}
...
lua box.space[23]:truncate()
---
...
lua for _k, v in box.space[23]:pairs() do print(v) end
---
...
......@@ -205,3 +205,20 @@ print """# Test that we print index number in error ER_INDEX_VIOLATION"""
exec admin "lua box.space[1]:insert(1, 'hello', 'world')"
exec admin "lua box.space[1]:insert(2, 'hello', 'world')"
exec admin "lua box.space[1]:truncate()"
print """#
# A test case for Bug #1042798
# Truncate hangs when primary key is not in linear or starts at the first field
# https://bugs.launchpad.net/tarantool/+bug/1042798
#"""
# Print key fields in pk
exec admin "lua for k, f in pairs(box.space[23].index[0].key_field) do print(k, ' => ', f.fieldno) end"
exec admin "lua box.insert(23, 1, 2, 3, 4)"
exec admin "lua box.insert(23, 10, 20, 30, 40)"
exec admin "lua box.insert(23, 20, 30, 40, 50)"
exec admin "lua for _k, v in box.space[23]:pairs() do print(v) end"
# Truncate must not hang
exec admin "lua box.space[23]:truncate()"
# Empty result
exec admin "lua for _k, v in box.space[23]:pairs() do print(v) end"
......@@ -243,3 +243,12 @@ space[19].index[0].key_field[0].fieldno = 0
space[19].index[0].key_field[0].type = "NUM"
space[19].index[0].key_field[1].fieldno = 2
space[19].index[0].key_field[1].type = "NUM"
# Space #23, https://bugs.launchpad.net/tarantool/+bug/1042798
space[23].enabled = 1
space[23].index[0].type = "TREE"
space[23].index[0].unique = 1
space[23].index[0].key_field[0].fieldno = 2
space[23].index[0].key_field[0].type = "NUM"
space[23].index[0].key_field[1].fieldno = 1
space[23].index[0].key_field[1].type = "NUM"
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