diff --git a/debian/tarantool-modules.install b/debian/tarantool-modules.install index 10d9d4ab21ee4e9b9f46d7681bf5b77676c18132..0bf50083b831b205a3174023a1e6cf5e87b86e0b 100644 --- a/debian/tarantool-modules.install +++ b/debian/tarantool-modules.install @@ -1,2 +1 @@ usr/share/tarantool/box/net/sql.lua -usr/lib/tarantool/box/sophia.so diff --git a/extra/rpm.spec.in b/extra/rpm.spec.in index 34eb9e92fe8f6c35dd82b9e87a35808bd6027b07..26ae083c25be858a4a0928b48deca17c7bf0069b 100644 --- a/extra/rpm.spec.in +++ b/extra/rpm.spec.in @@ -63,21 +63,6 @@ It supports replication, online backup, stored procedures in Lua. This package provides a MySQL interface to use with tarantool-sql-module. -# Tarantool sophia module - -%package sophia-module -Summary: Tarantool sophia bindings -Vendor: tarantool.org -Group: Applications/Databases -Provides: tarantool-sophia-module -Obsoletes: tarantool-sophia-module -%description -n tarantool-sophia-module -Tarantool is a high performance in-memory NoSQL database. -It supports replication, online backup, stored procedures in Lua. - -This package provides tarantool lua bindings to the -sophia database. - # Tarantool dev spec %package dev @@ -174,12 +159,6 @@ useradd -r -g tarantool tarantool > /dev/null 2>&1 %dir "%{_libdir}/tarantool/box" "%{_libdir}/tarantool/box/net/mysql.so" -%files sophia-module -%defattr(-,root,root,-) -%dir "%{_libdir}/tarantool" -%dir "%{_libdir}/tarantool/box" -"%{_libdir}/tarantool/box/sophia.so" - %files dev %defattr(-,root,root,-) %dir "%{_includedir}/tarantool" diff --git a/src/module/CMakeLists.txt b/src/module/CMakeLists.txt index 626bf9f6b65eccc41b1e1e0fdbc12f44fd2fc83c..293ce2e04fa816d455812e08148e913534e69aa9 100644 --- a/src/module/CMakeLists.txt +++ b/src/module/CMakeLists.txt @@ -1,4 +1,3 @@ add_subdirectory(sql) add_subdirectory(pg) add_subdirectory(mysql) -add_subdirectory(sophia) diff --git a/src/module/sophia/CMakeLists.txt b/src/module/sophia/CMakeLists.txt deleted file mode 100644 index 7dca1e0879457b30b055643ae036646268f88a5e..0000000000000000000000000000000000000000 --- a/src/module/sophia/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -include_directories(${SOPHIA_INCLUDE_DIR}) -set (sophia_lib "${PROJECT_BINARY_DIR}/third_party/sophia/db/libsophia.a") - -string(REPLACE "-static" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -string(REPLACE "-static-libgcc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - -add_library(sophia SHARED sophia.cc) -add_dependencies(sophia libsophia) -set_target_properties(sophia PROPERTIES PREFIX "") -target_link_libraries(sophia ${sophia_lib} -rdynamic) - -install(TARGETS sophia LIBRARY DESTINATION ${MODULE_LIBDIR}/box) diff --git a/src/module/sophia/sophia.cc b/src/module/sophia/sophia.cc deleted file mode 100644 index f39ce0aa09fe1116901d7bff9fa14a37392f7743..0000000000000000000000000000000000000000 --- a/src/module/sophia/sophia.cc +++ /dev/null @@ -1,325 +0,0 @@ - -/* - * 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 <sophia.h> - -extern "C" { - #include <lua.h> - #include <lauxlib.h> - #include <lualib.h> -} -#include <lua/init.h> -#include <lua/utils.h> -#include <coeio.h> - -static const char lsophia_name[] = "box.sophia"; - -struct lsophia { - void *env; - void *db; -}; - -static inline struct lsophia* -lsophia_check(struct lua_State *L, int narg) -{ - if (lua_gettop(L) < narg) - luaL_error(L, "%s: incorrect method call", lsophia_name); - return (struct lsophia*)luaL_checkudata(L, narg, lsophia_name); -} - -static int -lsophia_create(struct lua_State *L) -{ - struct lsophia *s = (struct lsophia*) - lua_newuserdata(L, sizeof(struct lsophia)); - luaL_getmetatable(L, lsophia_name); - lua_setmetatable(L, -2); - s->db = NULL; - s->env = sp_env(); - if (s->env == NULL) - luaL_error(L, "%s.create: failed to create env", lsophia_name); - return 1; -} - -static int -lsophia_error(struct lua_State *L) -{ - struct lsophia *s = lsophia_check(L, -1); - lua_pushstring(L, sp_error(s->env)); - return 0; -} - -static ssize_t -lsophia_openfunc(va_list ap) -{ - struct lsophia *s = va_arg(ap, struct lsophia*); - s->db = sp_open(s->env); - return (s->db) ? 0 : -1; -} - -static int -lsophia_open(struct lua_State *L) -{ - struct lsophia *s = lsophia_check(L, -1); - int rc = coeio_custom(lsophia_openfunc, TIMEOUT_INFINITY, s); - lua_pushinteger(L, rc); - return 1; -} - -static ssize_t -lsophia_closedbfunc(va_list ap) -{ - struct lsophia *s = va_arg(ap, struct lsophia*); - return sp_destroy(s->db); -} - -static int -lsophia_close(struct lua_State *L) -{ - int rcret = 0; - int rc; - struct lsophia *s = lsophia_check(L, -1); - if (s->db) { - rc = coeio_custom(lsophia_closedbfunc, TIMEOUT_INFINITY, s); - if (rc == -1) - rcret = -1; - s->db = NULL; - } - if (s->env) { - rc = sp_destroy(s->env); - if (rc == -1) - rcret = -1; - s->env = NULL; - } - lua_pushinteger(L, rcret); - return 1; -} - -static int -lsophia_ctl(struct lua_State *L) -{ - struct lsophia *s = lsophia_check(L, 1); - spopt opt = (spopt)luaL_checkint(L, 2); - int rc = 0; - switch (opt) { - case SPDIR: - rc = sp_ctl(s->env, opt, luaL_checkinteger(L, 3), - luaL_checkstring(L, 4)); - break; - case SPPAGE: - case SPGC: - case SPMERGE: - case SPMERGEWM: - rc = sp_ctl(s->env, opt, luaL_checkinteger(L, 3)); - break; - case SPGCF: - rc = sp_ctl(s->env, opt, luaL_checknumber(L, 3)); - case SPMERGEFORCE: - if (s->db == NULL) - luaL_error(L, "%s:ctl: db must be open", lsophia_name); - rc = sp_ctl(s->db, opt); - break; - case SPALLOC: - case SPCMP: - case SPGROW: - case SPVERSION: - break; - default: - luaL_error(L, "%s:ctl: bad ctl argument", lsophia_name); - break; - } - lua_pushinteger(L, rc); - return 1; -} - -static ssize_t -lsophia_setfunc(va_list ap) -{ - struct lsophia *s = va_arg(ap, struct lsophia*); - const char *key = va_arg(ap, const char*); - size_t keysize = va_arg(ap, size_t); - const char *value = va_arg(ap, const char*); - size_t valuesize = va_arg(ap, size_t); - - return sp_set(s->db, key, keysize, value, valuesize); -} - -static int -lsophia_set(struct lua_State *L) -{ - struct lsophia *s = lsophia_check(L, 1); - if (s->db == NULL) - luaL_error(L, "%s:set: db must be open", lsophia_name); - size_t keysize = 0; - size_t valuesize = 0; - const char *key = luaL_checklstring(L, 2, &keysize); - const char *value = - luaL_checklstring(L, 3, &valuesize); - int rc = coeio_custom(lsophia_setfunc, TIMEOUT_INFINITY, s, - key, keysize, - value, valuesize); - lua_pushinteger(L, rc); - return 1; -} - -static ssize_t -lsophia_deletefunc(va_list ap) -{ - struct lsophia *s = va_arg(ap, struct lsophia*); - const char *key = va_arg(ap, const char*); - size_t keysize = va_arg(ap, size_t); - - return sp_delete(s->db, key, keysize); -} - -static int -lsophia_delete(struct lua_State *L) -{ - struct lsophia *s = lsophia_check(L, 1); - if (s->db == NULL) - luaL_error(L, "%s:delete: db must be open", lsophia_name); - size_t keysize = 0; - const char *key = luaL_checklstring(L, 2, &keysize); - int rc = coeio_custom(lsophia_deletefunc, TIMEOUT_INFINITY, s, - key, keysize); - lua_pushinteger(L, rc); - return 1; -} - -static ssize_t -lsophia_getfunc(va_list ap) -{ - struct lsophia *s = va_arg(ap, struct lsophia*); - const char *key = va_arg(ap, const char*); - size_t keysize = va_arg(ap, size_t); - void **value = va_arg(ap, void**); - size_t *valuesize = va_arg(ap, size_t*); - - return sp_get(s->db, key, keysize, value, valuesize); -} - -static int -lsophia_get(struct lua_State *L) -{ - struct lsophia *s = lsophia_check(L, 1); - if (s->db == NULL) - luaL_error(L, "%s:get: db must be open", lsophia_name); - size_t keysize = 0; - const char *key = luaL_checklstring(L, 2, &keysize); - size_t valuesize = 0; - void *value = NULL; - int rc = coeio_custom(lsophia_getfunc, TIMEOUT_INFINITY, s, - key, keysize, - &value, &valuesize); - if (rc <= 0) { - lua_pushnil(L); - return 1; - } - lua_pushlstring(L, (char*)value, valuesize); - free(value); - return 1; -} - -static void -lsophia_initconst(lua_State *L) -{ - lua_pushstring(L, "SPDIR"); - lua_pushnumber(L, SPDIR); - lua_settable(L, -3); - - lua_pushstring(L, "SPPAGE"); - lua_pushnumber(L, SPPAGE); - lua_settable(L, -3); - - lua_pushstring(L, "SPGC"); - lua_pushnumber(L, SPGC); - lua_settable(L, -3); - - lua_pushstring(L, "SPGCF"); - lua_pushnumber(L, SPGCF); - lua_settable(L, -3); - - lua_pushstring(L, "SPMERGE"); - lua_pushnumber(L, SPMERGE); - lua_settable(L, -3); - - lua_pushstring(L, "SPMERGEWM"); - lua_pushnumber(L, SPMERGEWM); - lua_settable(L, -3); - - lua_pushstring(L, "SPMERGEFORCE"); - lua_pushnumber(L, SPMERGEFORCE); - lua_settable(L, -3); - - lua_pushstring(L, "SPMERGEFORCE"); - lua_pushnumber(L, SPMERGEFORCE); - lua_settable(L, -3); - - lua_pushstring(L, "SPO_RDONLY"); - lua_pushnumber(L, SPO_RDONLY); - lua_settable(L, -3); - - lua_pushstring(L, "SPO_RDWR"); - lua_pushnumber(L, SPO_RDWR); - lua_settable(L, -3); - - lua_pushstring(L, "SPO_CREAT"); - lua_pushnumber(L, SPO_CREAT); - lua_settable(L, -3); -} - -extern "C" { - int LUA_API luaopen_box_sophia(lua_State*); -} - -int LUA_API luaopen_box_sophia(lua_State *L) -{ - static const struct luaL_reg lsophia_meta[] = - { - { "__gc", lsophia_close }, - { "error", lsophia_error }, - { "open", lsophia_open }, - { "close", lsophia_close }, - { "ctl", lsophia_ctl }, - { "set", lsophia_set }, - { "delete", lsophia_delete }, - { "get", lsophia_get }, - { NULL, NULL } - }; - luaL_register_type(L, lsophia_name, lsophia_meta); - struct luaL_reg driver[] = { - {"create", lsophia_create}, - {NULL, NULL} - }; - luaL_openlib(L, "box.sophia", driver, 0); - - lsophia_initconst(L); - return 1; -} diff --git a/test/module/sophia.result b/test/module/sophia.result deleted file mode 100644 index 57d016b172c0ff7a9ca0e0a690a28e581461c71d..0000000000000000000000000000000000000000 --- a/test/module/sophia.result +++ /dev/null @@ -1,146 +0,0 @@ -package.cpath = "?.so" ---- -... -os.execute("mkdir -p box") ---- -- 0 -... -os.execute("cp ../../src/module/sophia/sophia.so box/") ---- -- 0 -... -sophia = require("box.sophia") ---- -... -env = sophia.create() ---- -... -flags = bit.bor(sophia.SPO_RDWR, sophia.SPO_CREAT) ---- -... -env:ctl(sophia.SPDIR, flags, "./sophia") ---- -- 0 -... -env:open() ---- -- 0 -... -t = {} ---- -... -for key=1, 10 do table.insert(t, env:set(tostring(key), tostring(key))) end ---- -... -t ---- -- - 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - 0 -... -t = {} ---- -... -for key=1, 10 do table.insert(t, env:get(tostring(key))) end ---- -... -t ---- -- - '1' - - '2' - - '3' - - '4' - - '5' - - '6' - - '7' - - '8' - - '9' - - '10' -... -t = {} ---- -... -env:close() ---- -- 0 -... -env = sophia.create() ---- -... -flags = bit.bor(sophia.SPO_RDWR) ---- -... -env:ctl(sophia.SPDIR, flags, "./sophia") ---- -- 0 -... -env:open() ---- -- 0 -... -t = {} ---- -... -for key=1, 10 do table.insert(t, env:get(tostring(key))) end ---- -... -t ---- -- - '1' - - '2' - - '3' - - '4' - - '5' - - '6' - - '7' - - '8' - - '9' - - '10' -... -t = {} ---- -... -for key=1, 10 do table.insert(t, env:delete(tostring(key))) end ---- -... -t ---- -- - 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - 0 - - 0 -... -t = {} ---- -... -for key=1, 10 do table.insert(t, env:get(tostring(key))) end ---- -... -t ---- -- [] -... -t = {} ---- -... -env:close() ---- -- 0 -... -os.execute("rm -rf box/") ---- -- 0 -... diff --git a/test/module/sophia.test b/test/module/sophia.test deleted file mode 100644 index 2bb26137470d487da3fcb5f8c02578863d6cfe80..0000000000000000000000000000000000000000 --- a/test/module/sophia.test +++ /dev/null @@ -1,34 +0,0 @@ -# encoding: tarantool -import os -import shutil - -module_path = os.path.join(vardir, "box") -module_path_so = module_path + "/sophia.so" -os.makedirs(module_path) -shutil.copy("../src/module/sophia/sophia.so", module_path_so) - -server.stop() -server.deploy(init_lua="module/sophia.lua") - -exec admin "lua env = box.sophia.create()" -exec admin "lua flags = bit.bor(box.sophia.SPO_RDWR, box.sophia.SPO_CREAT)" -exec admin "lua env:ctl(box.sophia.SPDIR, flags, \"./sophia\")" -exec admin "lua env:open()" -exec admin "lua for key=1, 10 do print(env:set(tostring(key), tostring(key))) end" -exec admin "lua for key=1, 10 do print(env:get(tostring(key))) end" -exec admin "lua env:close()" - -exec admin "lua env = box.sophia.create()" -exec admin "lua flags = bit.bor(box.sophia.SPO_RDWR)" -exec admin "lua env:ctl(box.sophia.SPDIR, flags, \"./sophia\")" -exec admin "lua env:open()" -exec admin "lua for key=1, 10 do print(env:get(tostring(key))) end" -exec admin "lua for key=1, 10 do print(env:delete(tostring(key))) end" -exec admin "lua for key=1, 10 do print(env:get(tostring(key))) end" -exec admin "lua env:close()" - -sophia_repository = os.path.join(vardir, "sophia") -shutil.rmtree(sophia_repository) - -os.unlink(module_path_so) -os.removedirs(module_path) diff --git a/test/module/sophia.test.lua b/test/module/sophia.test.lua deleted file mode 100644 index 922167d38608914df73c64e55714c8aee898f2e2..0000000000000000000000000000000000000000 --- a/test/module/sophia.test.lua +++ /dev/null @@ -1,37 +0,0 @@ -package.cpath = "?.so" - -os.execute("mkdir -p box") -os.execute("cp ../../src/module/sophia/sophia.so box/") - -sophia = require("box.sophia") - -env = sophia.create() -flags = bit.bor(sophia.SPO_RDWR, sophia.SPO_CREAT) -env:ctl(sophia.SPDIR, flags, "./sophia") -env:open() -t = {} -for key=1, 10 do table.insert(t, env:set(tostring(key), tostring(key))) end -t -t = {} -for key=1, 10 do table.insert(t, env:get(tostring(key))) end -t -t = {} -env:close() - -env = sophia.create() -flags = bit.bor(sophia.SPO_RDWR) -env:ctl(sophia.SPDIR, flags, "./sophia") -env:open() -t = {} -for key=1, 10 do table.insert(t, env:get(tostring(key))) end -t -t = {} -for key=1, 10 do table.insert(t, env:delete(tostring(key))) end -t -t = {} -for key=1, 10 do table.insert(t, env:get(tostring(key))) end -t -t = {} -env:close() - -os.execute("rm -rf box/") diff --git a/test/module/suite.ini b/test/module/suite.ini index fba1bc22dc6b612d5b9dc675c36c3639258c8edb..afca8175f19d31be093c3346cc078cac507472ba 100644 --- a/test/module/suite.ini +++ b/test/module/suite.ini @@ -1,4 +1,4 @@ [default] script = box.lua -disabled = sophia.test.lua +disabled = description = tarantool/box, optional lua modules