Skip to content
Snippets Groups Projects
Commit 24a87ff2 authored by Serge Petrenko's avatar Serge Petrenko Committed by Vladimir Davydov
Browse files

tarantoolctl: fix cat and play for empty body requests

If space.before_replace returns the old tuple, the operation turns into
no-op, but is still written to WAL as IPROTO_NOP for the sake of
replication. Such a request doesn't have a body, and tarantoolctl failed
to parse such requests in `tarantoolctl cat` and `tarantoolctl play`.
Fix this by checking whether a request has a body. Also skip such
requests in `play`, since they have no effect, and, while we're at it,
make sure `play` and `cat` do not read excess rows with lsn>=to in case
these rows are skipped.

Closes #3675
parent 4e705085
No related branches found
No related tags found
No related merge requests found
...@@ -373,6 +373,12 @@ write_lua_table = function(tuple) ...@@ -373,6 +373,12 @@ write_lua_table = function(tuple)
end end
local function cat_lua_cb(record) local function cat_lua_cb(record)
-- Ignore both versions of IPROTO_NOP: the one without a
-- body (new), and the one with empty body (old).
if record.HEADER.type == 'NOP' or record.BODY == nil or
record.BODY.space_id == nil then
return
end
io.stdout:write(('box.space[%d]'):format(record.BODY.space_id)) io.stdout:write(('box.space[%d]'):format(record.BODY.space_id))
local op = record.HEADER.type:lower() local op = record.HEADER.type:lower()
io.stdout:write((':%s('):format(op)) io.stdout:write((':%s('):format(op))
...@@ -816,17 +822,17 @@ local function cat() ...@@ -816,17 +822,17 @@ local function cat()
for id, file in ipairs(positional_arguments) do for id, file in ipairs(positional_arguments) do
log.error("Processing file '%s'", file) log.error("Processing file '%s'", file)
for lsn, record in xlog.pairs(file) do for lsn, record in xlog.pairs(file) do
local sid = record.BODY.space_id local sid = record.BODY and record.BODY.space_id
local rid = record.HEADER.replica_id local rid = record.HEADER.replica_id
if (lsn < from) or if lsn >= to then
-- stop, as we've finished reading tuple with lsn == to
-- and the next lsn's will be bigger
break
elseif (lsn < from) or
(not spaces and sid and sid < 512 and not show_system) or (not spaces and sid and sid < 512 and not show_system) or
(spaces and (sid == nil or not find_in_list(sid, spaces))) or (spaces and (sid == nil or not find_in_list(sid, spaces))) or
(replicas and not find_in_list(rid, replicas)) then (replicas and not find_in_list(rid, replicas)) then
-- pass this tuple -- pass this tuple
elseif lsn >= to then
-- stop, as we've finished reading tuple with lsn == to
-- and the next lsn's will be bigger
break
else else
is_printed = true is_printed = true
format_cb(record) format_cb(record)
...@@ -857,17 +863,17 @@ local function play() ...@@ -857,17 +863,17 @@ local function play()
for id, file in ipairs(positional_arguments) do for id, file in ipairs(positional_arguments) do
log.info(("Processing file '%s'"):format(file)) log.info(("Processing file '%s'"):format(file))
for lsn, record in xlog.pairs(file) do for lsn, record in xlog.pairs(file) do
local sid = record.BODY.space_id local sid = record.BODY and record.BODY.space_id
local rid = record.HEADER.replica_id local rid = record.HEADER.replica_id
if (lsn < from) or if lsn >= to then
(not spaces and sid and sid < 512 and not show_system) or
(spaces and (sid == nil or not find_in_list(sid, spaces))) or
(replicas and not find_in_list(rid, replicas)) then
-- pass this tuple
elseif lsn >= to then
-- stop, as we've finished reading tuple with lsn == to -- stop, as we've finished reading tuple with lsn == to
-- and the next lsn's will be bigger -- and the next lsn's will be bigger
break break
elseif (lsn < from) or sid == nil or
(not spaces and sid < 512 and not show_system) or
(spaces and not find_in_list(sid, spaces)) or
(replicas and not find_in_list(rid, replicas)) then
-- pass this tuple
else else
local args, so = {}, remote.space[sid] local args, so = {}, remote.space[sid]
if so == nil then if so == nil then
......
...@@ -345,6 +345,10 @@ do ...@@ -345,6 +345,10 @@ do
space:update({[1] = 2}, {[1] = {[1] = '\x3d', [2] = 3, [3] = 4}}) space:update({[1] = 2}, {[1] = {[1] = '\x3d', [2] = 3, [3] = 4}})
space:upsert({[1] = 3, [2] = 4, [3] = 5, [4] = 6}, {[1] = {[1] = '\x3d', [2] = 3, [3] = 4}}) space:upsert({[1] = 3, [2] = 4, [3] = 5, [4] = 6}, {[1] = {[1] = '\x3d', [2] = 3, [3] = 4}})
space:upsert({[1] = 3, [2] = 4, [3] = 5, [4] = 6}, {[1] = {[1] = '\x3d', [2] = 3, [3] = 4}}) space:upsert({[1] = 3, [2] = 4, [3] = 5, [4] = 6}, {[1] = {[1] = '\x3d', [2] = 3, [3] = 4}})
f = function(old, new) return old end
space:before_replace(f)
space:replace{1,5}
space:before_replace(nil, f)
os.exit(0) os.exit(0)
]] ]]
...@@ -372,11 +376,11 @@ do ...@@ -372,11 +376,11 @@ do
test:test("fill and test cat output", function(test_i) test:test("fill and test cat output", function(test_i)
test_i:plan(29) test_i:plan(29)
check_ok(test_i, dir, 'start', 'filler', 0) check_ok(test_i, dir, 'start', 'filler', 0)
check_ctlcat_xlog(test_i, dir, nil, "---\n", 6) check_ctlcat_xlog(test_i, dir, nil, "---\n", 7)
check_ctlcat_xlog(test_i, dir, "--space=512", "---\n", 6) check_ctlcat_xlog(test_i, dir, "--space=512", "---\n", 6)
check_ctlcat_xlog(test_i, dir, "--space=666", "---\n", 0) check_ctlcat_xlog(test_i, dir, "--space=666", "---\n", 0)
check_ctlcat_xlog(test_i, dir, "--show-system", "---\n", 9) check_ctlcat_xlog(test_i, dir, "--show-system", "---\n", 10)
check_ctlcat_xlog(test_i, dir, "--format=json", "\n", 6) check_ctlcat_xlog(test_i, dir, "--format=json", "\n", 7)
check_ctlcat_xlog(test_i, dir, "--format=lua", "\n", 6) check_ctlcat_xlog(test_i, dir, "--format=lua", "\n", 6)
check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json", "\n", 2) check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json", "\n", 2)
check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system", "\n", 3) check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system", "\n", 3)
...@@ -411,6 +415,10 @@ do ...@@ -411,6 +415,10 @@ do
space:update({[1] = 2}, {[1] = {[1] = '\x3d', [2] = 3, [3] = 4}}) space:update({[1] = 2}, {[1] = {[1] = '\x3d', [2] = 3, [3] = 4}})
space:upsert({[1] = 3, [2] = 4, [3] = 5, [4] = 6}, {[1] = {[1] = '\x3d', [2] = 3, [3] = 4}}) space:upsert({[1] = 3, [2] = 4, [3] = 5, [4] = 6}, {[1] = {[1] = '\x3d', [2] = 3, [3] = 4}})
space:upsert({[1] = 3, [2] = 4, [3] = 5, [4] = 6}, {[1] = {[1] = '\x3d', [2] = 3, [3] = 4}}) space:upsert({[1] = 3, [2] = 4, [3] = 5, [4] = 6}, {[1] = {[1] = '\x3d', [2] = 3, [3] = 4}})
f = function(old, new) return old end
space:before_replace(f)
space:replace{1,5}
space:before_replace(nil, f)
os.exit(0) os.exit(0)
]] ]]
create_script(dir, 'filler.lua', filler_code) create_script(dir, 'filler.lua', filler_code)
......
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