diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in index 07ac9ad0a01dd3f0e802d339ef5bce9af3c08eaf..b1b26f480453248d3bf912c0718ad192da5372d1 100755 --- a/extra/dist/tarantoolctl.in +++ b/extra/dist/tarantoolctl.in @@ -413,18 +413,16 @@ end -- CAT command helpers -- -- -------------------------------------------------------------------------- -- -local function find_space(sid, spaces) - if type(spaces) == 'number' then - return sid == spaces - end - local shown = false - for _, v in ipairs(spaces) do - if v == sid then - shown = true - break +local function find_in_list(id, list) + if type(list) == 'number' then + return id == list + end + for _, v in ipairs(list) do + if v == id then + return true end end - return shown + return false end local write_lua_table = nil @@ -865,6 +863,7 @@ local function cat() local options = keyword_arguments local from, to, spaces = options.from, options.to, options.space local show_system, cat_format = options['show-system'], options.format + local replicas = options.replica local format_cb = cat_formats[cat_format] local is_printed = false @@ -872,12 +871,22 @@ local function cat() log.error("Processing file '%s'", file) for lsn, record in xlog.pairs(file) do local sid = record.BODY.space_id - local is_filtered = spaces ~= nil - local is_system = sid < 512 and show_system == false - local isnt_specified = not (is_filtered and find_space(sid, spaces)) + local rid = record.HEADER.replica_id + -- space filter rules + local is_space_filtered = spaces ~= nil + local is_space_system = sid < 512 and show_system == false + local isnt_space_specified = not (is_space_filtered and + find_in_list(sid, spaces)) + -- replica id filter rules + local is_replica_id_filtered = replicas ~= nil + local isnt_replica_id_specified = not (is_replica_id_filtered and + find_in_list(rid, replicas)) + if (lsn < from) or - (is_filtered and is_system and isnt_specified) or - (is_system and isnt_specified) then + (is_space_filtered and is_space_system and + isnt_space_specified) or + (is_space_system and isnt_space_specified) or + (is_replica_id_filtered and isnt_replica_id_specified) then -- pass this tuple elseif lsn >= to then -- stop, as we've finished reading tuple with lsn == to @@ -901,6 +910,7 @@ local function play() local from, to, spaces = options.from, options.to, options.space local show_system = options['show-system'] local uri = table.remove(positional_arguments, 1) + local replicas = options.replica if uri == nil then error("Empty URI is provided") @@ -913,12 +923,22 @@ local function play() log.info(("Processing file '%s'"):format(file)) for lsn, record in xlog.pairs(file) do local sid = record.BODY.space_id - local is_filtered = spaces ~= nil - local is_system = sid < 512 and show_system == false - local isnt_specified = not (is_filtered and find_space(sid, spaces)) + local rid = record.HEADER.replica_id + -- space filter rules + local is_space_filtered = spaces ~= nil + local is_space_system = sid < 512 and show_system == false + local isnt_space_specified = not (is_space_filtered and + find_in_list(sid, spaces)) + -- replica id filter rules + local is_replica_id_filtered = replicas ~= nil + local isnt_replica_id_specified = not (is_replica_id_filtered and + find_in_list(rid, replicas)) + if (lsn < from) or - (is_filtered and is_system and isnt_specified) or - (is_system and isnt_specified) then + (is_space_filtered and is_space_system and + isnt_space_specified) or + (is_space_system and isnt_space_specified) or + (is_replica_id_filtered and isnt_replica_id_specified) then -- pass this tuple elseif lsn >= to then -- stop, as we've finished reading tuple with lsn == to @@ -1108,7 +1128,7 @@ local commands = setmetatable({ func = exit_wrapper(cat), process = process_remote, help = { header = "%s cat <filename>.. [--space=space_no ..] [--show-system]" .. - " [--from=from_lsn] [--to=to_lsn]", + " [--from=from_lsn] [--to=to_lsn] [--replica=replica_id ..]", description = [=[ Print into stdout the contents of .snap/.xlog files. @@ -1119,6 +1139,8 @@ local commands = setmetatable({ * --show-system to show the contents of system spaces. * --from=from_lsn to show operations starting from the given lsn. * --to=to_lsn to show operations ending with the given lsn. + * --replica=replica_id to filter the output by replica id. + May be passed more than once. ]=], weight = 90, deprecated = false, @@ -1138,6 +1160,8 @@ local commands = setmetatable({ * --show-system to show the contents of system spaces. * --from=from_lsn to show operations starting from the given lsn. * --to=to_lsn to show operations ending with the given lsn. + * --replica=replica_id to filter the output by replica id. + May be passed more than once. ]=], weight = 100, deprecated = false, @@ -1232,7 +1256,8 @@ do { 'from', 'number' }, { 'to', 'number' }, { 'help', 'boolean' }, - { 'format', 'string' } + { 'format', 'string' }, + { 'replica', 'number+' }, }) local cmd_name diff --git a/test/app-tap/tarantoolctl.result b/test/app-tap/tarantoolctl.result index b5c1feee956618e919b40ea132851df81ef9589f..69efd2aab5b02756e78c8f973e6a7dac83e48224 100644 --- a/test/app-tap/tarantoolctl.result +++ b/test/app-tap/tarantoolctl.result @@ -51,7 +51,7 @@ ok - check answers in case of call # check basic help: end ok - check basic help # fill and test cat output - 1..19 + 1..25 ok - check 'start' command status for 'filler' ok - cat result ok - cat line count @@ -67,6 +67,12 @@ ok - check basic help ok - cat + --from=3 --to=6 --format=json --show-system line count ok - cat + --from=6 --to=3 --format=json --show-system result ok - cat + --from=6 --to=3 --format=json --show-system line count + ok - cat + --from=3 --to=6 --format=json --show-system --replica 1 result + ok - cat + --from=3 --to=6 --format=json --show-system --replica 1 line count + ok - cat + --from=3 --to=6 --format=json --show-system --replica 1 --replica 2 result + ok - cat + --from=3 --to=6 --format=json --show-system --replica 1 --replica 2 line count + ok - cat + --from=3 --to=6 --format=json --show-system --replica 2 result + ok - cat + --from=3 --to=6 --format=json --show-system --replica 2 line count ok - cat + --space=280 result ok - cat + --space=280 line count ok - cat + --space=288 result diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua index 39418643a10b6e2d7d4465c345a7f87e53f582f0..50ee33b540bc47e5884ecbe5a258f3c097c1cb60 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -324,7 +324,7 @@ do local status, err = pcall(function() test:test("fill and test cat output", function(test_i) - test_i:plan(19) + test_i:plan(25) check_ok(test_i, dir, 'start', 'filler', 0) check_ctlcat_xlog(test_i, dir, nil, "---\n", 6) check_ctlcat_xlog(test_i, dir, "--show-system", "---\n", 9) @@ -333,6 +333,9 @@ do 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=6 --to=3 --format=json --show-system", "\n", 0) + check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 1", "\n", 3) + check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 1 --replica 2", "\n", 3) + check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 2", "\n", 0) check_ctlcat_snap(test_i, dir, "--space=280", "---\n", 12) check_ctlcat_snap(test_i, dir, "--space=288", "---\n", 31) end)