Tarantool development patches archive
 help / color / mirror / Atom feed
From: Leonid Vasiliev <lvasiliev@tarantool.org>
To: alexander.turenko@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH] Move rollback to savepoint from ffi to C-API
Date: Fri, 13 Dec 2019 15:08:10 +0300	[thread overview]
Message-ID: <ebf3c840507e45dbb7495157d506cbab463dff6d.1576238733.git.lvasiliev@tarantool.org> (raw)

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

             reply	other threads:[~2019-12-13 12:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-13 12:08 Leonid Vasiliev [this message]
2020-01-16 21:17 ` Alexander Turenko
2020-01-20 21:17   ` Leonid Vasiliev
2020-01-21  2:33     ` Alexander Turenko
2020-01-24 14:35       ` Igor Munkin
2020-01-27  7:24         ` Leonid Vasiliev
2020-02-05 16:53           ` Alexander Turenko

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=ebf3c840507e45dbb7495157d506cbab463dff6d.1576238733.git.lvasiliev@tarantool.org \
    --to=lvasiliev@tarantool.org \
    --cc=alexander.turenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] Move rollback to savepoint from ffi to C-API' \
    /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