diff --git a/extra/exports b/extra/exports index 0b1102d03073f8e96b05c4599a1aea23f713064a..b8c42c0dff271f3171c092849629e72092ccff4c 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 183cc04efc68c771b134249a1c93a8b95a068e8e..54ac121068300e6c09bf42e213190a41e58773d7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/lua/init.c b/src/lua/init.c index 64a2d43129d72437d043a97e42aba7870fe27cdf..9982828d93f8222d5eb936f7bdfdc45f9eb9c2e5 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> @@ -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); diff --git a/src/lua/swim.c b/src/lua/swim.c new file mode 100644 index 0000000000000000000000000000000000000000..3b9e229bed65328a6ad87f3957f0004c22ff4ddb --- /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 0000000000000000000000000000000000000000..b60bb76b758199e6df5f5b85cbc859ba2ac1a80d --- /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 adb102d06c7a084b175dfdd0321a66718631dea7..086d469df436addc7ff7aebfeba50941cef6411c 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); @@ -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),