[Tarantool-patches] [PATCH] Move rollback to savepoint from ffi to C-API
Leonid Vasiliev
lvasiliev at tarantool.org
Fri Dec 13 15:08:10 MSK 2019
https://github.com/tarantool/tarantool/issues/4427
https://github.com/tarantool/tarantool/tree/lvasiliev/gh-4427-move-rallback-from-ffi-to-c-api-v2
After the "FFI vs C-API" discussion
---
src/box/lua/init.c | 28 ++++++++++++++++++++++++++++
src/box/lua/schema.lua | 5 +----
2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/src/box/lua/init.c b/src/box/lua/init.c
index 7ffed409d..3d26dbb93 100644
--- a/src/box/lua/init.c
+++ b/src/box/lua/init.c
@@ -107,6 +107,26 @@ lbox_rollback(lua_State *L)
return 0;
}
+static int
+lbox_txn_rollback_to_savepoint(struct lua_State *L)
+{
+ if (lua_gettop(L) != 1 || lua_type(L, 1) != LUA_TCDATA)
+ luaL_error(L, "Usage: txn:rollback to savepoint(savepoint)");
+
+ uint32_t cdata_type;
+ struct txn_savepoint **sp_ptr = luaL_checkcdata(L, 1, &cdata_type);
+
+ if (sp_ptr == NULL)
+ luaL_error(L, "Usage: txn:rollback to savepoint(savepoint)");
+
+ int rc = box_txn_rollback_to_savepoint(*sp_ptr);
+ if (rc != 0)
+ return luaT_push_nil_and_error(L);
+
+ lua_pushnumber(L, 0);
+ return 1;
+}
+
/**
* Get a next txn statement from the current transaction. This is
* a C closure and 2 upvalues should be available: first is a
@@ -288,6 +308,11 @@ static const struct luaL_Reg boxlib_backup[] = {
{NULL, NULL}
};
+static const struct luaL_Reg boxlib_internal[] = {
+ {"rollback_to_savepoint", lbox_txn_rollback_to_savepoint},
+ {NULL, NULL}
+};
+
#include "say.h"
void
@@ -300,6 +325,9 @@ box_lua_init(struct lua_State *L)
luaL_register(L, "box.backup", boxlib_backup);
lua_pop(L, 1);
+ luaL_register(L, "box.internal", boxlib_internal);
+ lua_pop(L, 1);
+
box_lua_error_init(L);
box_lua_tuple_init(L);
box_lua_call_init(L);
diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua
index e898c3aa6..b08a8c615 100644
--- a/src/box/lua/schema.lua
+++ b/src/box/lua/schema.lua
@@ -77,9 +77,6 @@ ffi.cdef[[
box_txn_savepoint_t *
box_txn_savepoint();
- int
- box_txn_rollback_to_savepoint(box_txn_savepoint_t *savepoint);
-
struct port_tuple_entry {
struct port_tuple_entry *next;
struct tuple *tuple;
@@ -351,7 +348,7 @@ box.rollback_to_savepoint = function(savepoint)
if savepoint.txn_id ~= builtin.box_txn_id() then
box.error(box.error.NO_SUCH_SAVEPOINT)
end
- if builtin.box_txn_rollback_to_savepoint(savepoint.csavepoint) == -1 then
+ if box.internal.rollback_to_savepoint(savepoint.csavepoint) == nil then
box.error()
end
end
--
2.17.1
More information about the Tarantool-patches
mailing list