Skip to content
Snippets Groups Projects
Commit ce765928 authored by Vladislav Shpilevoy's avatar Vladislav Shpilevoy
Browse files

swim: call swim:new/delete via Lua C, not via FFI

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
parent d958254d
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -118,6 +118,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
......@@ -170,7 +171,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
......
......@@ -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>
......@@ -452,6 +453,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);
......
/*
* 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);
}
/*
* 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);
......@@ -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);
......@@ -474,7 +469,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
......@@ -829,11 +824,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),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment