From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: kostja@tarantool.org
Subject: [tarantool-patches] [PATCH v2 4/5] swim: call swim:new/delete via Lua C, not via FFI
Date: Sat, 8 Jun 2019 12:31:20 +0200 [thread overview]
Message-ID: <212eeba14786bf004ab28a5228501b0896e55c20.1559989748.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1559989748.git.v.shpilevoy@tarantool.org>
These function are going to yield in scope of #4250, because
swim:new() will start a fiber, while swim:delete() cancels and
gives it a control.
Needed for #4250
---
| 2 --
src/CMakeLists.txt | 3 +-
src/lua/init.c | 2 ++
src/lua/swim.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++
src/lua/swim.h | 34 +++++++++++++++++++
src/lua/swim.lua | 13 +++-----
6 files changed, 123 insertions(+), 12 deletions(-)
create mode 100644 src/lua/swim.c
create mode 100644 src/lua/swim.h
--git a/extra/exports b/extra/exports
index 0b1102d03..b8c42c0df 100644
--- a/extra/exports
+++ b/extra/exports
@@ -89,12 +89,10 @@ crypto_stream_delete
lua_static_aligned_alloc
-swim_new
swim_is_configured
swim_cfg
swim_set_payload
swim_set_codec
-swim_delete
swim_add_member
swim_remove_member
swim_probe_member
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 68674d06a..64ea95c17 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -117,6 +117,7 @@ set (server_sources
lua/info.c
lua/string.c
lua/buffer.c
+ lua/swim.c
${lua_sources}
${PROJECT_SOURCE_DIR}/third_party/lua-yaml/lyaml.cc
${PROJECT_SOURCE_DIR}/third_party/lua-yaml/b64.c
@@ -169,7 +170,7 @@ target_link_libraries(server core coll http_parser bit uri uuid swim swim_udp
# Rule of thumb: if exporting a symbol from a static library, list the
# library here.
-set (reexport_libraries server core misc bitset csv swim
+set (reexport_libraries server core misc bitset csv swim swim_udp swim_ev
${LUAJIT_LIBRARIES} ${MSGPUCK_LIBRARIES} ${ICU_LIBRARIES})
set (common_libraries
diff --git a/src/lua/init.c b/src/lua/init.c
index 5ddc5a4d8..d8b3501be 100644
--- a/src/lua/init.c
+++ b/src/lua/init.c
@@ -58,6 +58,7 @@
#include "lua/fio.h"
#include "lua/httpc.h"
#include "lua/utf8.h"
+#include "lua/swim.h"
#include "digest.h"
#include <small/ibuf.h>
@@ -450,6 +451,7 @@ tarantool_lua_init(const char *tarantool_bin, int argc, char **argv)
tarantool_lua_socket_init(L);
tarantool_lua_pickle_init(L);
tarantool_lua_digest_init(L);
+ tarantool_lua_swim_init(L);
luaopen_http_client_driver(L);
lua_pop(L, 1);
luaopen_msgpack(L);
diff --git a/src/lua/swim.c b/src/lua/swim.c
new file mode 100644
index 000000000..3b9e229be
--- /dev/null
+++ b/src/lua/swim.c
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2010-2019, 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 "swim/swim.h"
+#include "trigger.h"
+#include "diag.h"
+#include "lua/utils.h"
+
+static uint32_t ctid_swim_ptr;
+
+/**
+ * Create a new SWIM instance. SWIM is not created via FFI,
+ * because this operation yields.
+ * @retval 1 Success. A SWIM instance pointer is on the stack.
+ * @retval 2 Error. Nil and an error object are pushed.
+ */
+static int
+lua_swim_new(struct lua_State *L)
+{
+ struct swim *s = swim_new();
+ *(struct swim **) luaL_pushcdata(L, ctid_swim_ptr) = s;
+ if (s != NULL)
+ return 1;
+ luaT_pusherror(L, diag_last_error(diag_get()));
+ return 2;
+}
+
+/**
+ * Delete a SWIM instance. SWIM is not deleted via FFI, because
+ * this operation yields.
+ */
+static int
+lua_swim_delete(struct lua_State *L)
+{
+ uint32_t ctypeid;
+ struct swim *s = *(struct swim **) luaL_checkcdata(L, 1, &ctypeid);
+ swim_delete(s);
+ return 0;
+}
+
+void
+tarantool_lua_swim_init(struct lua_State *L)
+{
+ luaL_cdef(L, "struct swim;");
+ ctid_swim_ptr = luaL_ctypeid(L, "struct swim *");
+
+ static const struct luaL_Reg lua_swim_internal_methods [] = {
+ {"swim_new", lua_swim_new},
+ {"swim_delete", lua_swim_delete},
+ {NULL, NULL}
+ };
+ luaL_register_module(L, "swim", lua_swim_internal_methods);
+ lua_pop(L, 1);
+}
diff --git a/src/lua/swim.h b/src/lua/swim.h
new file mode 100644
index 000000000..b60bb76b7
--- /dev/null
+++ b/src/lua/swim.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2010-2019, 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.
+ */
+struct lua_State;
+
+void
+tarantool_lua_swim_init(struct lua_State *L);
diff --git a/src/lua/swim.lua b/src/lua/swim.lua
index 4893d5767..527299284 100644
--- a/src/lua/swim.lua
+++ b/src/lua/swim.lua
@@ -3,6 +3,7 @@ local uuid = require('uuid')
local buffer = require('buffer')
local msgpack = require('msgpack')
local crypto = require('crypto')
+local internal = require('swim')
ffi.cdef[[
struct swim;
@@ -23,9 +24,6 @@ ffi.cdef[[
MEMBER_LEFT,
};
- struct swim *
- swim_new(void);
-
bool
swim_is_configured(const struct swim *swim);
@@ -41,9 +39,6 @@ ffi.cdef[[
swim_set_codec(struct swim *swim, enum crypto_algo algo,
enum crypto_mode mode, const char *key, int key_size);
- void
- swim_delete(struct swim *swim);
-
int
swim_add_member(struct swim *swim, const char *uri,
const struct tt_uuid *uuid);
@@ -466,7 +461,7 @@ local swim_mt_deleted = {
--
local function swim_delete(s)
local ptr = swim_check_instance(s, 'swim:delete')
- capi.swim_delete(ffi.gc(ptr, nil))
+ internal.swim_delete(ffi.gc(ptr, nil))
s.ptr = nil
setmetatable(s, swim_mt_deleted)
end
@@ -821,11 +816,11 @@ local cache_table_mt = { __mode = 'v' }
-- provided.
--
local function swim_new(cfg)
- local ptr = capi.swim_new()
+ local ptr = internal.swim_new()
if ptr == nil then
return nil, box.error.last()
end
- ffi.gc(ptr, capi.swim_delete)
+ ffi.gc(ptr, internal.swim_delete)
local s = setmetatable({
ptr = ptr,
cfg = setmetatable({index = {}}, swim_cfg_not_configured_mt),
--
2.20.1 (Apple Git-117)
next prev parent reply other threads:[~2019-06-08 10:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-08 10:31 [tarantool-patches] [PATCH v2 0/5] SWIM on_member_update Vladislav Shpilevoy
2019-06-08 10:31 ` [tarantool-patches] [PATCH v2 1/5] test: create isolated ev_loop for swim unit tests Vladislav Shpilevoy
2019-06-08 14:32 ` [tarantool-patches] " Konstantin Osipov
2019-06-08 10:31 ` [tarantool-patches] [PATCH v2 2/5] swim: fix a 'use after free' in SWIM tests Vladislav Shpilevoy
2019-06-08 14:32 ` [tarantool-patches] " Konstantin Osipov
2019-06-08 10:31 ` [tarantool-patches] [PATCH v2 3/5] swim: allow to set triggers on member updates Vladislav Shpilevoy
2019-06-08 14:35 ` [tarantool-patches] " Konstantin Osipov
2019-06-08 10:31 ` Vladislav Shpilevoy [this message]
2019-06-08 14:35 ` [tarantool-patches] Re: [PATCH v2 4/5] swim: call swim:new/delete via Lua C, not via FFI Konstantin Osipov
2019-06-08 11:04 ` [tarantool-patches] Re: [PATCH v2 0/5] SWIM on_member_update Vladislav Shpilevoy
2019-06-08 11:06 ` Vladislav Shpilevoy
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=212eeba14786bf004ab28a5228501b0896e55c20.1559989748.git.v.shpilevoy@tarantool.org \
--to=v.shpilevoy@tarantool.org \
--cc=kostja@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [tarantool-patches] [PATCH v2 4/5] swim: call swim:new/delete via Lua C, not via FFI' \
/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