From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Alexander Turenko Subject: [PATCH 2/2] Fix tarantoolctl cat/play premature stop with --to Date: Wed, 20 Mar 2019 21:41:14 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: Vladimir Davydov Cc: Alexander Turenko , tarantool-patches@freelists.org List-ID: Stop a file processing loop only when it is guaranteed that we will not find a record that match user-provided filters later in this file. If --replica R is provided one time and we're meet a record from R with a LSN equal or above of a --to value, we'll stop the loop. Otherwise (no --replica, several --replica arguments) a file will be read until an end even if --to is provided. Fixes #3827. --- extra/dist/tarantoolctl.in | 14 +++++++------- test/app-tap/tarantoolctl.test.lua | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in index 014acee6c..0796f4605 100755 --- a/extra/dist/tarantoolctl.in +++ b/extra/dist/tarantoolctl.in @@ -839,11 +839,11 @@ end -- 4. If @a opts.replica is set, record.HEADER.replica_id should -- not be nil and should be in @a opts.replica list. -- --- Once a record with LSN >= @a opts.to is found the loop stops --- (even if a file contains next records with smaller LSN from --- another replicas). Note however that this function is called --- once for each xlog / snap file, so even when it stops on LSN --- >= @a opts.to on a current file a next file will be processed. +-- If @a opts.replica is set and is a singleton list and a record +-- **from this replica** with LSN >= @a opts.to is found the loop +-- stops. Note however that this function is called once for each +-- xlog / snap file, so even when it stops on LSN >= @a opts.to on +-- a current file a next file will be processed. local function filter_xlog(gen, param, state, opts, cb) local spaces = opts.spaces local from, to, spaces = opts.from, opts.to, opts.space @@ -852,11 +852,11 @@ local function filter_xlog(gen, param, state, opts, cb) for lsn, record in gen, param, state do local sid = record.BODY and record.BODY.space_id local rid = record.HEADER.replica_id - if lsn >= to then + if replicas and #replicas == 1 and replicas[1] == rid and 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 + elseif (lsn < from) or (lsn >= to) 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 (replicas and not find_in_list(rid, replicas)) then diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua index 4910b94f3..a914db5c5 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -590,7 +590,7 @@ test:test('filter_xlog', function(test) { 'to w/o replica id', opts = merge(default_opts, {to = 120}), - exp_result = {}, + exp_result = {x[9], x[10]}, }, { 'to and replica id', @@ -600,7 +600,7 @@ test:test('filter_xlog', function(test) { 'to and replica ids', opts = merge(default_opts, {to = 137, replica = {1, 2}}), - exp_result = {x[7]}, + exp_result = {x[7], x[9]}, }, } test:plan(#cases) -- 2.20.1