From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: tarantool-patches@dev.tarantool.org, olegrok@tarantool.org, yaroslav.dynnikov@tarantool.org Subject: [Tarantool-patches] [PATCH vshard 01/11] error: introduce vshard.error.timeout() Date: Tue, 23 Feb 2021 01:15:37 +0100 [thread overview] Message-ID: <bddf5b4b2de0e4d956c2aecdf5b2ef80b1888c96.1614039039.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1614039039.git.v.shpilevoy@tarantool.org> 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)
next prev parent reply other threads:[~2021-02-23 0:16 UTC|newest] Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-02-23 0:15 [Tarantool-patches] [PATCH vshard 00/11] VShard Map-Reduce, part 2: Ref, Sched, Map Vladislav Shpilevoy via Tarantool-patches 2021-02-23 0:15 ` Vladislav Shpilevoy via Tarantool-patches [this message] 2021-02-24 10:27 ` [Tarantool-patches] [PATCH vshard 01/11] error: introduce vshard.error.timeout() Oleg Babin via Tarantool-patches 2021-02-24 21:46 ` Vladislav Shpilevoy via Tarantool-patches 2021-02-25 12:42 ` Oleg Babin via Tarantool-patches 2021-02-23 0:15 ` [Tarantool-patches] [PATCH vshard 10/11] sched: introduce vshard.storage.sched module Vladislav Shpilevoy via Tarantool-patches 2021-02-24 10:28 ` Oleg Babin via Tarantool-patches 2021-02-24 21:50 ` Vladislav Shpilevoy via Tarantool-patches 2021-03-04 21:02 ` Oleg Babin via Tarantool-patches 2021-03-05 22:06 ` Vladislav Shpilevoy via Tarantool-patches 2021-03-09 8:03 ` Oleg Babin via Tarantool-patches 2021-02-23 0:15 ` [Tarantool-patches] [PATCH vshard 11/11] router: introduce map_callrw() Vladislav Shpilevoy via Tarantool-patches 2021-02-24 10:28 ` Oleg Babin via Tarantool-patches 2021-02-24 22:04 ` Vladislav Shpilevoy via Tarantool-patches 2021-02-25 12:43 ` Oleg Babin via Tarantool-patches 2021-02-26 23:58 ` Vladislav Shpilevoy via Tarantool-patches 2021-03-01 10:58 ` Oleg Babin via Tarantool-patches 2021-02-23 0:15 ` [Tarantool-patches] [PATCH vshard 02/11] storage: add helper for local functions invocation Vladislav Shpilevoy via Tarantool-patches 2021-02-24 10:27 ` Oleg Babin via Tarantool-patches 2021-02-23 0:15 ` [Tarantool-patches] [PATCH vshard 03/11] storage: cache bucket count Vladislav Shpilevoy via Tarantool-patches 2021-02-24 10:27 ` Oleg Babin via Tarantool-patches 2021-02-24 21:47 ` Vladislav Shpilevoy via Tarantool-patches 2021-02-25 12:42 ` Oleg Babin via Tarantool-patches 2021-02-23 0:15 ` [Tarantool-patches] [PATCH vshard 04/11] registry: module for circular deps resolution Vladislav Shpilevoy via Tarantool-patches 2021-02-24 10:27 ` Oleg Babin via Tarantool-patches 2021-02-23 0:15 ` [Tarantool-patches] [PATCH vshard 05/11] util: introduce safe fiber_cond_wait() Vladislav Shpilevoy via Tarantool-patches 2021-02-24 10:27 ` Oleg Babin via Tarantool-patches 2021-02-24 21:48 ` Vladislav Shpilevoy via Tarantool-patches 2021-02-25 12:42 ` Oleg Babin via Tarantool-patches 2021-02-23 0:15 ` [Tarantool-patches] [PATCH vshard 06/11] util: introduce fiber_is_self_canceled() Vladislav Shpilevoy via Tarantool-patches 2021-02-24 10:27 ` Oleg Babin via Tarantool-patches 2021-02-23 0:15 ` [Tarantool-patches] [PATCH vshard 07/11] storage: introduce bucket_generation_wait() Vladislav Shpilevoy via Tarantool-patches 2021-02-24 10:27 ` Oleg Babin via Tarantool-patches 2021-02-23 0:15 ` [Tarantool-patches] [PATCH vshard 08/11] storage: introduce bucket_are_all_rw() Vladislav Shpilevoy via Tarantool-patches 2021-02-24 10:27 ` Oleg Babin via Tarantool-patches 2021-02-24 21:48 ` Vladislav Shpilevoy via Tarantool-patches 2021-02-23 0:15 ` [Tarantool-patches] [PATCH vshard 09/11] ref: introduce vshard.storage.ref module Vladislav Shpilevoy via Tarantool-patches 2021-02-24 10:28 ` Oleg Babin via Tarantool-patches 2021-02-24 21:49 ` Vladislav Shpilevoy via Tarantool-patches 2021-02-25 12:42 ` Oleg Babin via Tarantool-patches 2021-03-04 21:22 ` Oleg Babin via Tarantool-patches 2021-03-05 22:06 ` Vladislav Shpilevoy via Tarantool-patches 2021-03-09 8:03 ` Oleg Babin via Tarantool-patches 2021-03-21 18:49 ` Vladislav Shpilevoy via Tarantool-patches 2021-03-12 23:13 ` [Tarantool-patches] [PATCH vshard 00/11] VShard Map-Reduce, part 2: Ref, Sched, Map Vladislav Shpilevoy via Tarantool-patches 2021-03-15 7:05 ` Oleg Babin via Tarantool-patches 2021-03-28 18:17 ` Vladislav Shpilevoy via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bddf5b4b2de0e4d956c2aecdf5b2ef80b1888c96.1614039039.git.v.shpilevoy@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=olegrok@tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --cc=yaroslav.dynnikov@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH vshard 01/11] error: introduce vshard.error.timeout()' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox