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 2E10C71825; Tue, 23 Feb 2021 03:16:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 2E10C71825 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1614039384; bh=WPB2ncX4xw9vinEW7jhnYUDR1ZgwrRemZmgxZ/AGgko=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=CefgzQOaNXoYDel+n8P7txg++WJIqu4fC7zHwW5RC/ixV5glOCUgFDn/irA3RQl2K UPUgD4zpGerZsLGMFkIZ/pkorjxiJ2xtqAJ2O+V98bre2mvzUDrRdL9CDVGy9l+T77 tOZ2fZmaKSoipvwg1/EI0j00zdFQj7B4XpW47c5Q= Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 018EE71825 for ; Tue, 23 Feb 2021 03:15:50 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 018EE71825 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1lELMj-0003CR-7l; Tue, 23 Feb 2021 03:15:49 +0300 To: tarantool-patches@dev.tarantool.org, olegrok@tarantool.org, yaroslav.dynnikov@tarantool.org Date: Tue, 23 Feb 2021 01:15:37 +0100 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD975C3EC174F5669229511437AA01F46811CFCF616A939B362182A05F5380850409E129F4D345CBF13F8ACE1D84EDBE58143138693C5D43F73A48921D0D7208650 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70043D879A87EF1BCEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006370D3D68FCEFFDD9EA8638F802B75D45FF5571747095F342E8C7A0BC55FA0FE5FC425FEB8730D38403F1B6F5D5A8807900EFE604B14EE7AB50389733CBF5DBD5E913377AFFFEAFD269176DF2183F8FC7C0D9442B0B5983000E8941B15DA834481FCF19DD082D7633A0EF3E4896CB9E6436389733CBF5DBD5E9D5E8D9A59859A8B6D082881546D93491CC7F00164DA146DA6F5DAA56C3B73B23C77107234E2CFBA567F23339F89546C55F5C1EE8F4F765FC08F9A42B2210255C75ECD9A6C639B01BBD4B6F7A4D31EC0BC0CAF46E325F83A522CA9DD8327EE4930A3850AC1BE2E73579C543ECCDAE434EC4224003CC836476C0CAF46E325F83A50BF2EBBBDD9D6B0F347543BADC64E7283B503F486389A921A5CC5B56E945C8DA X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C4C7A0BC55FA0FE5FC425FEB8730D38403F1B6F5D5A8807900D512293F712EC5B4B1881A6453793CE9C32612AADDFBE061C61BE10805914D3804EBA3D8E7E5B87ABF8C51168CD8EBDB587F3D2152687E5CDC48ACC2A39D04F89CDFB48F4795C241BDAD6C7F3747799A X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34AE88D5ADEBE7C98355EADD24D4E2C725ECEA53D39D3E0D34AFAEB11FF84FB515B260C9E4E3AE66F41D7E09C32AA3244CD5C7BDBEFAD55933FF677D406E37CAD7250262A5EE9971B0FACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj2drqE2xHc+GD2UftxlOfzQ== X-Mailru-Sender: 689FA8AB762F73936BC43F508A063822D1113696EFB4710D4BE9013A83A42C7F3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: [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: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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 -- 2.24.3 (Apple Git-128)