From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 2245A27779 for ; Mon, 2 Sep 2019 07:14:43 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dDbEZyfd7Vll for ; Mon, 2 Sep 2019 07:14:43 -0400 (EDT) Received: from smtp36.i.mail.ru (smtp36.i.mail.ru [94.100.177.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 6B2F6275C6 for ; Mon, 2 Sep 2019 07:14:42 -0400 (EDT) From: sergos@tarantool.org Subject: [tarantool-patches] [PATCH] initial version: remove savepoints from FFI Date: Mon, 2 Sep 2019 11:14:14 +0000 Message-Id: <20190902111414.35583-1-sergos@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: alexander.turenko@tarantool.org, tarantool-patches@freelists.org Cc: Sergey Ostanevich From: Sergey Ostanevich 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 ``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 + * 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 + +#include +#include +#include + +#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 ``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 + * 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 +#include #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