-
Notifications
You must be signed in to change notification settings - Fork 35
storage: preserve original error on function fail #629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ local trigger = require('internal.trigger') | |
| local ffi = require('ffi') | ||
| local json_encode = require('json').encode | ||
| local yaml_encode = require('yaml').encode | ||
| local msgpack = require('msgpack') | ||
| local fiber_clock = lfiber.clock | ||
| local fiber_yield = lfiber.yield | ||
| local netbox_self = netbox.self | ||
|
|
@@ -260,6 +261,23 @@ else | |
| end | ||
| end | ||
|
|
||
| -- | ||
| -- This is copy-paste from the net_box.lua handle_eval_result. | ||
| -- | ||
| local function handle_results(status, ...) | ||
| if not status then | ||
| box.rollback() | ||
| return status, box.error.new(box.error.PROC_LUA, (...)) | ||
| end | ||
| local results = {...} | ||
| for i = 1, select('#', ...) do | ||
| if type(results[i]) == 'cdata' then | ||
| results[i] = msgpack.decode(msgpack.encode(results[i])) | ||
| end | ||
| end | ||
Gerold103 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return status, unpack(results) | ||
| end | ||
|
|
||
| -- | ||
| -- Invoke a function on this instance. Arguments are unpacked into the function | ||
| -- as arguments. | ||
|
|
@@ -284,7 +302,12 @@ local_call = function(func_name, args) | |
| if not func then | ||
| return pcall(netbox_self_call, netbox_self, func_name, args) | ||
| end | ||
|
Comment on lines
302
to
304
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if my function left a transaction unfinished, and it was called via
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. If the function throws an error during an active transaction, the transaction is rolled back in |
||
| return pcall(func.call, func, args) | ||
| -- If the function is called directly, fails, and leaves an uncommitted | ||
| -- transaction, then in Tarantool versions before 3.0.0-beta1-18, | ||
| -- the original error is replaced by the "Transaction is active" error. | ||
| -- We manually check if the function returned an error. If so, we | ||
| -- rollback the transaction to reveal the original error. | ||
| return handle_results(pcall(func.call, func, args)) | ||
| end | ||
|
|
||
| end | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.