From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 850A170202; Wed, 24 Feb 2021 13:27:21 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 850A170202 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1614162441; bh=M3jqpnQNK9kydIB03mRIVrP5sKBniy5eNWOQVicVp3c=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=n/qgJZWnn6YjlPxL42e1qgSgNYmYEkuhnQMIQmdla8pbCoxk6KyNYFj5ZEr9D/KXy npvl8twS+sqx4ec0RA5brFqfE86OmNNiwZD97eIqqZYv/guFxMianr3Bt6vqnE9gDn wJLcBk0HZtTGRditlsFrRwUrh82D4/2hBYNg6Sm8= Received: from smtp33.i.mail.ru (smtp33.i.mail.ru [94.100.177.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id B1D4570202 for ; Wed, 24 Feb 2021 13:27:19 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org B1D4570202 Received: by smtp33.i.mail.ru with esmtpa (envelope-from ) id 1lErO0-000555-7L; Wed, 24 Feb 2021 13:27:16 +0300 To: Vladislav Shpilevoy , tarantool-patches@dev.tarantool.org, yaroslav.dynnikov@tarantool.org References: Message-ID: <627b3c57-d8a9-5681-fb4d-38d0053c6aa7@tarantool.org> Date: Wed, 24 Feb 2021 13:27:15 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD975C3EC174F56692254B0AABE1FB071B229FBFD4D57485274182A05F538085040420A5FFA9C7694F51795C9C736E5FD919F1005C728276C33CE4FA377614AD958 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE742D9BD90C58D50E0EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006370D3D68FCEFFDD9EA8638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FC37516A8786216141B1C2FD693501972C8E2B763126F3A3F3389733CBF5DBD5E913377AFFFEAFD269A417C69337E82CC2CC7F00164DA146DAFE8445B8C89999729449624AB7ADAF37F6B57BC7E64490611E7FA7ABCAF51C92A417C69337E82CC2CC7F00164DA146DA6F5DAA56C3B73B237318B6A418E8EAB8D32BA5DBAC0009BE9E8FC8737B5C2249A67BD3AE6DBC366976E601842F6C81A12EF20D2F80756B5F7E9C4E3C761E06A776E601842F6C81A127C277FBC8AE2E8B1E34AC14BB7DB23B3AA81AA40904B5D9DBF02ECDB25306B2B25CBF701D1BE8734AD6D5ED66289B5278DA827A17800CE73349F3DFB73D9B1167F23339F89546C5A8DF7F3B2552694A6FED454B719173D6725E5C173C3A84C391A60F04C81D059235872C767BF85DA2F004C906525384306FED454B719173D6462275124DF8B9C9DE2850DD75B2526BE5BFE6E7EFDEDCD789D4C264860C145E X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A24A6D60772A99906F8E1CD14B953EB46D9897ABC7CCFBB5C1355D89D7DBCDD132 X-C1DE0DAB: 0D63561A33F958A5C25EDFE94AE565BB19BD88FAF8DB4F173F38DF5013FB1E42D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA75B7BFB303F1C7DB4D8E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D346B222596F62B8FA958F5B1C4A32F7AD76EB26E1E0663E5D0F904882971B6F3A345C7ADFFF5D2F8491D7E09C32AA3244CB5CCF886517CA0905C5E1B4948A44B7E24AF4FAF06DA24FDFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojyK6JYJ15DtKhQtXAJZDKWQ== X-Mailru-Sender: 583F1D7ACE8F49BD9317CE1922F30C7E860DC308CCCA943AE653BCFC4D7EAC0232CACEAB7AB8D15923E75C7104EB1B885DEE61814008E47C7013064206BFB89F93956FB04BA385BE9437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH vshard 01/11] error: introduce vshard.error.timeout() X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Oleg Babin via Tarantool-patches Reply-To: Oleg Babin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Hi! Thanks for your patch. Personally, I vote for dropping 1.9 support (it's already broken - #256). But if you want to eliminate "long and ugly" ways you could do something like: ``` local make_timeout if box.error.new ~= nil then make_timeout = function() return box.error.new(box.error.TIMEOUT) end else make_timeout = function() return select(2, pcall(...)) end end ``` On 23.02.2021 03:15, Vladislav Shpilevoy wrote: > The function returns a box.error.TIMEOUT error converted to the > format used by vshard. > > Probably it wouldn't be needed if only Tarantool >= 1.10 was > supported - then error.make(box.error.new(box.error.TIMEOUT)) > wouldn't be so bad. But 1.9 is supposed to work as well, and to > create a timeout error on <= 1.9 it is necessary to make a pcall() > which is long and ugly. > > vshard.error.timeout() provides a version-agnostic way of > returning timeout errors. > > The patch is motivated by timeout error being actively used in the > future patches about map-reduce. > > Needed for #147 > --- > test/router/sync.result | 10 +++++++--- > test/router/sync.test.lua | 3 ++- > test/unit/error.result | 22 ++++++++++++++++++++++ > test/unit/error.test.lua | 9 +++++++++ > vshard/error.lua | 10 ++++++++++ > vshard/replicaset.lua | 3 +-- > vshard/router/init.lua | 6 ++---- > vshard/storage/init.lua | 6 ++---- > 8 files changed, 55 insertions(+), 14 deletions(-) > > diff --git a/test/router/sync.result b/test/router/sync.result > index 6f0821d..040d611 100644 > --- a/test/router/sync.result > +++ b/test/router/sync.result > @@ -45,10 +45,14 @@ vshard.router.bootstrap() > --- > - true > ... > -vshard.router.sync(-1) > +res, err = vshard.router.sync(-1) > --- > -- null > -- Timeout exceeded > +... > +util.portable_error(err) > +--- > +- type: ClientError > + code: 78 > + message: Timeout exceeded > ... > res, err = vshard.router.sync(0) > --- > diff --git a/test/router/sync.test.lua b/test/router/sync.test.lua > index 3150343..cb36b0e 100644 > --- a/test/router/sync.test.lua > +++ b/test/router/sync.test.lua > @@ -15,7 +15,8 @@ util = require('util') > > vshard.router.bootstrap() > > -vshard.router.sync(-1) > +res, err = vshard.router.sync(-1) > +util.portable_error(err) > res, err = vshard.router.sync(0) > util.portable_error(err) > > diff --git a/test/unit/error.result b/test/unit/error.result > index 8552d91..738cfeb 100644 > --- a/test/unit/error.result > +++ b/test/unit/error.result > @@ -97,3 +97,25 @@ util.portable_error(err) > code: 32 > message: '[string "function raise_lua_err() assert(false) end "]:1: assertion failed!' > ... > +-- > +-- lerror.timeout() - portable alternative to box.error.new(box.error.TIMEOUT). > +-- > +err = lerror.timeout() > +--- > +... > +type(err) > +--- > +- table > +... > +assert(err.code == box.error.TIMEOUT) > +--- > +- true > +... > +err.type > +--- > +- ClientError > +... > +err.message > +--- > +- Timeout exceeded > +... > diff --git a/test/unit/error.test.lua b/test/unit/error.test.lua > index 859414e..0a51d33 100644 > --- a/test/unit/error.test.lua > +++ b/test/unit/error.test.lua > @@ -36,3 +36,12 @@ function raise_lua_err() assert(false) end > ok, err = pcall(raise_lua_err) > err = lerror.make(err) > util.portable_error(err) > + > +-- > +-- lerror.timeout() - portable alternative to box.error.new(box.error.TIMEOUT). > +-- > +err = lerror.timeout() > +type(err) > +assert(err.code == box.error.TIMEOUT) > +err.type > +err.message > diff --git a/vshard/error.lua b/vshard/error.lua > index 65da763..a6f46a9 100644 > --- a/vshard/error.lua > +++ b/vshard/error.lua > @@ -212,10 +212,20 @@ local function make_alert(code, ...) > return setmetatable(r, { __serialize = 'seq' }) > end > > +-- > +-- Create a timeout error object. Box.error.new() can't be used because is > +-- present only since 1.10. > +-- > +local function make_timeout() > + local _, err = pcall(box.error, box.error.TIMEOUT) > + return make_error(err) > +end > + > return { > code = error_code, > box = box_error, > vshard = vshard_error, > make = make_error, > alert = make_alert, > + timeout = make_timeout, > } > diff --git a/vshard/replicaset.lua b/vshard/replicaset.lua > index 9c792b3..7437e3b 100644 > --- a/vshard/replicaset.lua > +++ b/vshard/replicaset.lua > @@ -401,8 +401,7 @@ local function replicaset_template_multicallro(prefer_replica, balance) > local timeout = opts.timeout or consts.CALL_TIMEOUT_MAX > local net_status, storage_status, retval, err, replica > if timeout <= 0 then > - net_status, err = pcall(box.error, box.error.TIMEOUT) > - return nil, lerror.make(err) > + return nil, lerror.timeout() > end > local end_time = fiber_clock() + timeout > while not net_status and timeout > 0 do > diff --git a/vshard/router/init.lua b/vshard/router/init.lua > index eeb7515..97bcb0a 100644 > --- a/vshard/router/init.lua > +++ b/vshard/router/init.lua > @@ -628,8 +628,7 @@ local function router_call_impl(router, bucket_id, mode, prefer_replica, > if err then > return nil, err > else > - local _, boxerror = pcall(box.error, box.error.TIMEOUT) > - return nil, lerror.box(boxerror) > + return nil, lerror.timeout() > end > end > > @@ -1235,8 +1234,7 @@ local function router_sync(router, timeout) > local opts = {timeout = timeout} > for rs_uuid, replicaset in pairs(router.replicasets) do > if timeout < 0 then > - local ok, err = pcall(box.error, box.error.TIMEOUT) > - return nil, err > + return nil, lerror.timeout() > end > local status, err = replicaset:callrw('vshard.storage.sync', arg, opts) > if not status then > diff --git a/vshard/storage/init.lua b/vshard/storage/init.lua > index a3e7008..e0ce31d 100644 > --- a/vshard/storage/init.lua > +++ b/vshard/storage/init.lua > @@ -756,8 +756,7 @@ local function sync(timeout) > lfiber.sleep(0.001) > until fiber_clock() > tstart + timeout > log.warn("Timed out during synchronizing replicaset") > - local ok, err = pcall(box.error, box.error.TIMEOUT) > - return nil, lerror.make(err) > + return nil, lerror.timeout() > end > > -------------------------------------------------------------------------------- > @@ -1344,8 +1343,7 @@ local function bucket_send_xc(bucket_id, destination, opts, exception_guard) > while ref.rw ~= 0 do > timeout = deadline - fiber_clock() > if not M.bucket_rw_lock_is_ready_cond:wait(timeout) then > - status, err = pcall(box.error, box.error.TIMEOUT) > - return nil, lerror.make(err) > + return nil, lerror.timeout() > end > lfiber.testcancel() > end