From 7d7680f328f8a13b0df46b20e54471503ed2feb8 Mon Sep 17 00:00:00 2001 From: robotspace Date: Tue, 23 Nov 2021 20:01:55 +0800 Subject: [PATCH] Add a build option to disable embedded lua lib. By default enable (#8715) * Get accurate reason when a query is not executed sucessfully. Disable test case for async query in lua51 connector. * Add a build option to disable embedded lua lib. By default enable. * Restore default dependency for module query to avoid compile error on windows. --- cmake/define.inc | 11 +++++++++++ cmake/input.inc | 2 ++ deps/CMakeLists.txt | 5 ++++- src/client/src/tscSQLParser.c | 7 ++++++- src/client/src/tscSystem.c | 6 ++++-- src/dnode/src/dnodeMain.c | 2 ++ src/query/CMakeLists.txt | 12 ++++++++++-- src/query/inc/qScript.h | 4 ++-- src/query/src/qExecutor.c | 7 ++++--- src/query/src/qScript.c | 3 ++- tests/examples/lua/OpenResty/rest/test.lua | 4 +++- tests/examples/lua/README.md | 7 +++++-- tests/examples/lua/lua51/lua_connector51.c | 2 +- tests/examples/lua/lua_connector.c | 2 +- 14 files changed, 57 insertions(+), 17 deletions(-) diff --git a/cmake/define.inc b/cmake/define.inc index 92044b8c2d..21b517e197 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -152,6 +152,17 @@ IF (TD_BUILD_HTTP) ADD_DEFINITIONS(-DHTTP_EMBEDDED) ENDIF () +IF (${BUILD_LUA} MATCHES "false") + SET(TD_BUILD_LUA FALSE) +ENDIF () + +IF (TD_BUILD_LUA) + MESSAGE("Enable lua") + ADD_DEFINITIONS(-DLUA_EMBEDDED) +ELSE () + MESSAGE("Disable lua") +ENDIF () + IF ("${AVRO_SUPPORT}" MATCHES "true") SET(TD_AVRO_SUPPORT TRUE) ELSEIF ("${AVRO_SUPPORT}" MATCHES "false") diff --git a/cmake/input.inc b/cmake/input.inc index 0812711a58..4273f576b4 100755 --- a/cmake/input.inc +++ b/cmake/input.inc @@ -92,6 +92,8 @@ ENDIF () SET(TD_BUILD_HTTP FALSE) +SET(TD_BUILD_LUA TRUE) + SET(TD_AVRO_SUPPORT FALSE) SET(TD_MEMORY_SANITIZER FALSE) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 38f36c4ed6..45eaf6495d 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -15,7 +15,10 @@ ADD_SUBDIRECTORY(cJson) ADD_SUBDIRECTORY(wepoll) ADD_SUBDIRECTORY(MsvcLibX) ADD_SUBDIRECTORY(rmonotonic) -ADD_SUBDIRECTORY(lua) + +IF (TD_BUILD_LUA) + ADD_SUBDIRECTORY(lua) +ENDIF () IF (TD_LINUX AND TD_MQTT) ADD_SUBDIRECTORY(MQTT-C) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index fb4070385c..fca3b0b57b 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -439,7 +439,9 @@ int32_t handleUserDefinedFunc(SSqlObj* pSql, struct SSqlInfo* pInfo) { const char *msg1 = "invalidate function name"; const char *msg2 = "path is too long"; const char *msg3 = "invalid outputtype"; + #ifdef LUA_EMBEDDED const char *msg4 = "invalid script"; + #endif const char *msg5 = "invalid dyn lib"; SSqlCmd *pCmd = &pSql->cmd; @@ -478,9 +480,12 @@ int32_t handleUserDefinedFunc(SSqlObj* pSql, struct SSqlInfo* pInfo) { } //validate *.lua or .so int32_t pathLen = (int32_t)strlen(createInfo->path.z); +#ifdef LUA_EMBEDDED if ((pathLen > 4) && (0 == strncmp(createInfo->path.z + pathLen - 4, ".lua", 4)) && !isValidScript(buf, len)) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); - } else if (pathLen > 3 && (0 == strncmp(createInfo->path.z + pathLen - 3, ".so", 3))) { + } else +#endif + if (pathLen > 3 && (0 == strncmp(createInfo->path.z + pathLen - 3, ".so", 3))) { void *handle = taosLoadDll(createInfo->path.z); taosCloseDll(handle); if (handle == NULL) { diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index edb8169f76..f6614fdb79 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -210,9 +210,9 @@ void taos_init_imp(void) { taosInitNotes(); rpcInit(); - +#ifdef LUA_EMBEDDED scriptEnvPoolInit(); - +#endif tscDebug("starting to initialize TAOS client ..."); tscDebug("Local End Point is:%s", tsLocalEp); } @@ -276,7 +276,9 @@ void taos_cleanup(void) { } if (tscEmbedded == 0) { + #ifdef LUA_EMBEDDED scriptEnvPoolCleanup(); + #endif } int32_t id = tscObjRef; diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index 69c6203ab3..8712852173 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -89,7 +89,9 @@ static SStep tsDnodeSteps[] = { {"dnode-shell", dnodeInitShell, dnodeCleanupShell}, {"dnode-statustmr", dnodeInitStatusTimer,dnodeCleanupStatusTimer}, {"dnode-telemetry", dnodeInitTelemetry, dnodeCleanupTelemetry}, +#ifdef LUA_EMBEDDED {"dnode-script", scriptEnvPoolInit, scriptEnvPoolCleanup}, +#endif {"dnode-grant", grantInit, grantCleanUp}, }; diff --git a/src/query/CMakeLists.txt b/src/query/CMakeLists.txt index 4b57843708..a815942fbe 100644 --- a/src/query/CMakeLists.txt +++ b/src/query/CMakeLists.txt @@ -11,11 +11,19 @@ SET_SOURCE_FILES_PROPERTIES(src/sql.c PROPERTIES COMPILE_FLAGS -w) TARGET_LINK_LIBRARIES(query tsdb tutil lua) IF (TD_LINUX) - TARGET_LINK_LIBRARIES(query m rt lua) + IF (TD_BUILD_LUA) + TARGET_LINK_LIBRARIES(query m rt lua) + ELSE () + TARGET_LINK_LIBRARIES(query m rt) + ENDIF () ADD_SUBDIRECTORY(tests) ENDIF () IF (TD_DARWIN) - TARGET_LINK_LIBRARIES(query m lua) + IF (TD_BUILD_LUA) + TARGET_LINK_LIBRARIES(query m lua) + ELSE () + TARGET_LINK_LIBRARIES(query m) + ENDIF () ADD_SUBDIRECTORY(tests) ENDIF () diff --git a/src/query/inc/qScript.h b/src/query/inc/qScript.h index 574bb51368..2dc9b5812b 100644 --- a/src/query/inc/qScript.h +++ b/src/query/inc/qScript.h @@ -15,7 +15,7 @@ #ifndef TDENGINE_QSCRIPT_H #define TDENGINE_QSCRIPT_H - +#ifdef LUA_EMBEDDED #include #include #include @@ -78,5 +78,5 @@ void destroyScriptCtx(void *pScriptCtx); int32_t scriptEnvPoolInit(); void scriptEnvPoolCleanup(); bool isValidScript(char *script, int32_t len); - +#endif //LUA_EMBEDDED #endif //TDENGINE_QSCRIPT_H diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 6a89a2f823..29dc65d8f8 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -8240,7 +8240,7 @@ void destroyUdfInfo(SUdfInfo* pUdfInfo) { taosCloseDll(pUdfInfo->handle); tfree(pUdfInfo); } - +#ifdef LUA_EMBEDDED static char* getUdfFuncName(char* funcname, char* name, int type) { switch (type) { case TSDB_UDF_FUNC_NORMAL: @@ -8265,8 +8265,9 @@ static char* getUdfFuncName(char* funcname, char* name, int type) { return funcname; } - +#endif int32_t initUdfInfo(SUdfInfo* pUdfInfo) { +#ifdef LUA_EMBEDDED if (pUdfInfo == NULL || pUdfInfo->handle) { return TSDB_CODE_SUCCESS; } @@ -8350,7 +8351,7 @@ int32_t initUdfInfo(SUdfInfo* pUdfInfo) { return (*(udfInitFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_INIT])(&pUdfInfo->init); } } - +#endif //LUA_EMBEDDED return TSDB_CODE_SUCCESS; } diff --git a/src/query/src/qScript.c b/src/query/src/qScript.c index c43b0b3435..a8a6f6732b 100644 --- a/src/query/src/qScript.c +++ b/src/query/src/qScript.c @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ - +#ifdef LUA_EMBEDDED #include "os.h" #include "qScript.h" #include "ttype.h" @@ -444,3 +444,4 @@ bool isValidScript(char *script, int32_t len) { return ret; } +#endif diff --git a/tests/examples/lua/OpenResty/rest/test.lua b/tests/examples/lua/OpenResty/rest/test.lua index 48aeef3fb4..2dc0cf10f2 100644 --- a/tests/examples/lua/OpenResty/rest/test.lua +++ b/tests/examples/lua/OpenResty/rest/test.lua @@ -63,6 +63,7 @@ else end +--[[ local flag = false function query_callback(res) if res.code ~=0 then @@ -80,9 +81,10 @@ end driver.query_a(conn,"insert into m1 values ('2019-09-01 00:00:00.001', 3, 'robotspace'),('2019-09-01 00:00:00.006', 4, 'Hilink'),('2019-09-01 00:00:00.007', 6, 'Harmony')", query_callback) while not flag do --- ngx.say("i am here once...") + ngx.say("i am here once...") ngx.sleep(0.001) -- time unit is second end +--]] ngx.say("pool water_mark:"..pool:get_water_mark()) diff --git a/tests/examples/lua/README.md b/tests/examples/lua/README.md index 32d6a4cace..bdc88edbd7 100644 --- a/tests/examples/lua/README.md +++ b/tests/examples/lua/README.md @@ -1,7 +1,10 @@ # TDengine driver connector for Lua -It's a Lua implementation for [TDengine](https://github.com/taosdata/TDengine), an open-sourced big data platform designed and optimized for the Internet of Things (IoT), Connected Cars, Industrial IoT, and IT Infrastructure and Application Monitoring. You may need to install Lua5.3 . - +It's a Lua implementation for [TDengine](https://github.com/taosdata/TDengine), an open-sourced big data platform designed and optimized for the Internet of Things (IoT), Connected Cars, Industrial IoT, and IT Infrastructure and Application Monitoring. You may need to install Lua5.3 . +As TDengine is built with lua-enable, the built-in lua module conflicts with external lua. The following commands require TDengine built with lua-disable. +To disable built-in lua: +mkdir debug && cd debug +cmake .. -DBUILD_LUA=false && cmake --build . ## Lua Dependencies - Lua: ``` diff --git a/tests/examples/lua/lua51/lua_connector51.c b/tests/examples/lua/lua51/lua_connector51.c index fe2152945d..b6e0b6d1de 100644 --- a/tests/examples/lua/lua51/lua_connector51.c +++ b/tests/examples/lua/lua51/lua_connector51.c @@ -102,7 +102,7 @@ static int l_query(lua_State *L){ printf("failed, reason:%s\n", taos_errstr(result)); lua_pushinteger(L, -1); lua_setfield(L, table_index, "code"); - lua_pushstring(L, taos_errstr(taos)); + lua_pushstring(L, taos_errstr(result)); lua_setfield(L, table_index, "error"); return 1; diff --git a/tests/examples/lua/lua_connector.c b/tests/examples/lua/lua_connector.c index 8c2ea3e9e8..06568f35d6 100644 --- a/tests/examples/lua/lua_connector.c +++ b/tests/examples/lua/lua_connector.c @@ -102,7 +102,7 @@ static int l_query(lua_State *L){ printf("failed, reason:%s\n", taos_errstr(result)); lua_pushinteger(L, -1); lua_setfield(L, table_index, "code"); - lua_pushstring(L, taos_errstr(taos)); + lua_pushstring(L, taos_errstr(result)); lua_setfield(L, table_index, "error"); return 1; -- GitLab