Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH] initial version: remove savepoints from FFI
@ 2019-09-02 11:14 sergos
  2019-09-09 12:06 ` [tarantool-patches] " Alexander Turenko
  0 siblings, 1 reply; 2+ messages in thread
From: sergos @ 2019-09-02 11:14 UTC (permalink / raw)
  To: alexander.turenko, tarantool-patches; +Cc: Sergey Ostanevich

From: Sergey Ostanevich <sergos@tarantool.org>

fixes: #4427

follow-up: need to remove savepoints from FFI completely
---
 src/box/CMakeLists.txt |  1 +
 src/box/lua/init.c     |  2 +
 src/box/lua/schema.lua |  6 +--
 src/box/lua/txn.c      | 90 ++++++++++++++++++++++++++++++++++++++++++
 src/box/lua/txn.h      | 49 +++++++++++++++++++++++
 src/box/txn.c          |  2 +
 6 files changed, 146 insertions(+), 4 deletions(-)
 create mode 100644 src/box/lua/txn.c
 create mode 100644 src/box/lua/txn.h

diff --git a/src/box/CMakeLists.txt b/src/box/CMakeLists.txt
index 9bba37bcb..27a0902f1 100644
--- a/src/box/CMakeLists.txt
+++ b/src/box/CMakeLists.txt
@@ -142,6 +142,7 @@ add_library(box STATIC
     lua/info.c
     lua/stat.c
     lua/ctl.c
+    lua/txn.c
     lua/error.cc
     lua/session.c
     lua/net_box.c
diff --git a/src/box/lua/init.c b/src/box/lua/init.c
index 7ffed409d..a61821fb4 100644
--- a/src/box/lua/init.c
+++ b/src/box/lua/init.c
@@ -53,6 +53,7 @@
 #include "box/lua/stat.h"
 #include "box/lua/info.h"
 #include "box/lua/ctl.h"
+#include "box/lua/txn.h"
 #include "box/lua/session.h"
 #include "box/lua/net_box.h"
 #include "box/lua/cfg.h"
@@ -312,6 +313,7 @@ box_lua_init(struct lua_State *L)
 	box_lua_info_init(L);
 	box_lua_stat_init(L);
 	box_lua_ctl_init(L);
+	box_lua_txn_init(L);
 	box_lua_session_init(L);
 	box_lua_xlog_init(L);
 	box_lua_execute_init(L);
diff --git a/src/box/lua/schema.lua b/src/box/lua/schema.lua
index 65017d391..0fcb2b146 100644
--- a/src/box/lua/schema.lua
+++ b/src/box/lua/schema.lua
@@ -77,8 +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;
@@ -351,8 +349,8 @@ 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
-        box.error()
+    if box.txn.rollback_to_savepoint(savepoint) == -1 then
+        box.error(box.error.NO_SUCH_FUNCTION, "box.txn.rollback_to_savepoint")
     end
 end
 
diff --git a/src/box/lua/txn.c b/src/box/lua/txn.c
new file mode 100644
index 000000000..4362ef403
--- /dev/null
+++ b/src/box/lua/txn.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2010-2018, Tarantool AUTHORS, please see AUTHORS file.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *    copyright notice, this list of conditions and the
+ *    following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#include "box/lua/txn.h"
+#include "box/txn.h"
+
+#include <tarantool_ev.h>
+
+#include <lua.h>
+#include <lauxlib.h>
+#include <lualib.h>
+
+#include "lua/utils.h"
+#include "lua/trigger.h"
+
+#include "box/box.h"
+#include "box/schema.h"
+
+struct txn_savepoint*
+luaT_check_txn_savepoint(struct lua_State *L, int idx)
+{
+	if (lua_type(L, idx) != LUA_TTABLE) 
+		return NULL;
+
+        lua_getfield(L, idx, "csavepoint");
+        
+	uint32_t cdata_type;
+	struct txn_savepoint **sp_ptr = luaL_checkcdata(L, idx + 1, &cdata_type);
+
+        lua_pop(L, 1);
+
+	if (sp_ptr == NULL)
+		return NULL;
+
+	return *sp_ptr;
+}
+
+static int 
+lbox_txn_rollback_to_savepoint(struct lua_State *L)
+{
+        struct txn_savepoint *point;
+        if (lua_gettop(L) != 1 ||
+            (point = luaT_check_txn_savepoint(L, 1)) == NULL)
+                return luaL_error(L, "Usage: txn:rollback_to_savepoint(savepoint)");
+
+        int rc = box_txn_rollback_to_savepoint(point);
+        if (rc != 0)
+            return luaT_push_nil_and_error(L);
+
+        return 0;
+}
+
+static const struct luaL_Reg lbox_txn_lib[] = {
+	{"rollback_to_savepoint", lbox_txn_rollback_to_savepoint},
+	{NULL, NULL}
+};
+
+void
+box_lua_txn_init(struct lua_State *L)
+{
+	luaL_register_module(L, "box.txn", lbox_txn_lib);
+	lua_pop(L, 1);
+}
diff --git a/src/box/lua/txn.h b/src/box/lua/txn.h
new file mode 100644
index 000000000..299a54886
--- /dev/null
+++ b/src/box/lua/txn.h
@@ -0,0 +1,49 @@
+#ifndef INCLUDES_TARANTOOL_LUA_TXN_H
+#define INCLUDES_TARANTOOL_LUA_TXN_H
+
+/*
+ * Copyright 2010-2018, Tarantool AUTHORS, please see AUTHORS file.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *    copyright notice, this list of conditions and the
+ *    following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(__cplusplus)
+extern "C" {
+#endif /* defined(__cplusplus) */
+
+struct lua_State;
+
+void
+box_lua_txn_init(struct lua_State *L);
+
+#if defined(__cplusplus)
+} /* extern "C" */
+#endif /* defined(__cplusplus) */
+
+#endif /* INCLUDES_TARANTOOL_LUA_TXN_H */
+
diff --git a/src/box/txn.c b/src/box/txn.c
index 38b1b595f..38921a2ff 100644
--- a/src/box/txn.c
+++ b/src/box/txn.c
@@ -33,6 +33,7 @@
 #include "tuple.h"
 #include "journal.h"
 #include <fiber.h>
+#include <lauxlib.h>
 #include "xrow.h"
 
 double too_long_threshold;
@@ -875,3 +876,4 @@ txn_on_yield(struct trigger *trigger, void *event)
 	txn_rollback_to_svp(txn, NULL);
 	txn_set_flag(txn, TXN_IS_ABORTED_BY_YIELD);
 }
+
-- 
2.17.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-09-09 12:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-02 11:14 [tarantool-patches] [PATCH] initial version: remove savepoints from FFI sergos
2019-09-09 12:06 ` [tarantool-patches] " Alexander Turenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox