未验证 提交 7d7680f3 编写于 作者: R robotspace 提交者: GitHub

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.
上级 2d0646d2
...@@ -152,6 +152,17 @@ IF (TD_BUILD_HTTP) ...@@ -152,6 +152,17 @@ IF (TD_BUILD_HTTP)
ADD_DEFINITIONS(-DHTTP_EMBEDDED) ADD_DEFINITIONS(-DHTTP_EMBEDDED)
ENDIF () 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") IF ("${AVRO_SUPPORT}" MATCHES "true")
SET(TD_AVRO_SUPPORT TRUE) SET(TD_AVRO_SUPPORT TRUE)
ELSEIF ("${AVRO_SUPPORT}" MATCHES "false") ELSEIF ("${AVRO_SUPPORT}" MATCHES "false")
......
...@@ -92,6 +92,8 @@ ENDIF () ...@@ -92,6 +92,8 @@ ENDIF ()
SET(TD_BUILD_HTTP FALSE) SET(TD_BUILD_HTTP FALSE)
SET(TD_BUILD_LUA TRUE)
SET(TD_AVRO_SUPPORT FALSE) SET(TD_AVRO_SUPPORT FALSE)
SET(TD_MEMORY_SANITIZER FALSE) SET(TD_MEMORY_SANITIZER FALSE)
......
...@@ -15,7 +15,10 @@ ADD_SUBDIRECTORY(cJson) ...@@ -15,7 +15,10 @@ ADD_SUBDIRECTORY(cJson)
ADD_SUBDIRECTORY(wepoll) ADD_SUBDIRECTORY(wepoll)
ADD_SUBDIRECTORY(MsvcLibX) ADD_SUBDIRECTORY(MsvcLibX)
ADD_SUBDIRECTORY(rmonotonic) ADD_SUBDIRECTORY(rmonotonic)
ADD_SUBDIRECTORY(lua)
IF (TD_BUILD_LUA)
ADD_SUBDIRECTORY(lua)
ENDIF ()
IF (TD_LINUX AND TD_MQTT) IF (TD_LINUX AND TD_MQTT)
ADD_SUBDIRECTORY(MQTT-C) ADD_SUBDIRECTORY(MQTT-C)
......
...@@ -439,7 +439,9 @@ int32_t handleUserDefinedFunc(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -439,7 +439,9 @@ int32_t handleUserDefinedFunc(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const char *msg1 = "invalidate function name"; const char *msg1 = "invalidate function name";
const char *msg2 = "path is too long"; const char *msg2 = "path is too long";
const char *msg3 = "invalid outputtype"; const char *msg3 = "invalid outputtype";
#ifdef LUA_EMBEDDED
const char *msg4 = "invalid script"; const char *msg4 = "invalid script";
#endif
const char *msg5 = "invalid dyn lib"; const char *msg5 = "invalid dyn lib";
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
...@@ -478,9 +480,12 @@ int32_t handleUserDefinedFunc(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -478,9 +480,12 @@ int32_t handleUserDefinedFunc(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
//validate *.lua or .so //validate *.lua or .so
int32_t pathLen = (int32_t)strlen(createInfo->path.z); 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)) { if ((pathLen > 4) && (0 == strncmp(createInfo->path.z + pathLen - 4, ".lua", 4)) && !isValidScript(buf, len)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); 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); void *handle = taosLoadDll(createInfo->path.z);
taosCloseDll(handle); taosCloseDll(handle);
if (handle == NULL) { if (handle == NULL) {
......
...@@ -210,9 +210,9 @@ void taos_init_imp(void) { ...@@ -210,9 +210,9 @@ void taos_init_imp(void) {
taosInitNotes(); taosInitNotes();
rpcInit(); rpcInit();
#ifdef LUA_EMBEDDED
scriptEnvPoolInit(); scriptEnvPoolInit();
#endif
tscDebug("starting to initialize TAOS client ..."); tscDebug("starting to initialize TAOS client ...");
tscDebug("Local End Point is:%s", tsLocalEp); tscDebug("Local End Point is:%s", tsLocalEp);
} }
...@@ -276,7 +276,9 @@ void taos_cleanup(void) { ...@@ -276,7 +276,9 @@ void taos_cleanup(void) {
} }
if (tscEmbedded == 0) { if (tscEmbedded == 0) {
#ifdef LUA_EMBEDDED
scriptEnvPoolCleanup(); scriptEnvPoolCleanup();
#endif
} }
int32_t id = tscObjRef; int32_t id = tscObjRef;
......
...@@ -89,7 +89,9 @@ static SStep tsDnodeSteps[] = { ...@@ -89,7 +89,9 @@ static SStep tsDnodeSteps[] = {
{"dnode-shell", dnodeInitShell, dnodeCleanupShell}, {"dnode-shell", dnodeInitShell, dnodeCleanupShell},
{"dnode-statustmr", dnodeInitStatusTimer,dnodeCleanupStatusTimer}, {"dnode-statustmr", dnodeInitStatusTimer,dnodeCleanupStatusTimer},
{"dnode-telemetry", dnodeInitTelemetry, dnodeCleanupTelemetry}, {"dnode-telemetry", dnodeInitTelemetry, dnodeCleanupTelemetry},
#ifdef LUA_EMBEDDED
{"dnode-script", scriptEnvPoolInit, scriptEnvPoolCleanup}, {"dnode-script", scriptEnvPoolInit, scriptEnvPoolCleanup},
#endif
{"dnode-grant", grantInit, grantCleanUp}, {"dnode-grant", grantInit, grantCleanUp},
}; };
......
...@@ -11,11 +11,19 @@ SET_SOURCE_FILES_PROPERTIES(src/sql.c PROPERTIES COMPILE_FLAGS -w) ...@@ -11,11 +11,19 @@ SET_SOURCE_FILES_PROPERTIES(src/sql.c PROPERTIES COMPILE_FLAGS -w)
TARGET_LINK_LIBRARIES(query tsdb tutil lua) TARGET_LINK_LIBRARIES(query tsdb tutil lua)
IF (TD_LINUX) 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) ADD_SUBDIRECTORY(tests)
ENDIF () ENDIF ()
IF (TD_DARWIN) 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) ADD_SUBDIRECTORY(tests)
ENDIF () ENDIF ()
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#ifndef TDENGINE_QSCRIPT_H #ifndef TDENGINE_QSCRIPT_H
#define TDENGINE_QSCRIPT_H #define TDENGINE_QSCRIPT_H
#ifdef LUA_EMBEDDED
#include <lua.h> #include <lua.h>
#include <lauxlib.h> #include <lauxlib.h>
#include <lualib.h> #include <lualib.h>
...@@ -78,5 +78,5 @@ void destroyScriptCtx(void *pScriptCtx); ...@@ -78,5 +78,5 @@ void destroyScriptCtx(void *pScriptCtx);
int32_t scriptEnvPoolInit(); int32_t scriptEnvPoolInit();
void scriptEnvPoolCleanup(); void scriptEnvPoolCleanup();
bool isValidScript(char *script, int32_t len); bool isValidScript(char *script, int32_t len);
#endif //LUA_EMBEDDED
#endif //TDENGINE_QSCRIPT_H #endif //TDENGINE_QSCRIPT_H
...@@ -8240,7 +8240,7 @@ void destroyUdfInfo(SUdfInfo* pUdfInfo) { ...@@ -8240,7 +8240,7 @@ void destroyUdfInfo(SUdfInfo* pUdfInfo) {
taosCloseDll(pUdfInfo->handle); taosCloseDll(pUdfInfo->handle);
tfree(pUdfInfo); tfree(pUdfInfo);
} }
#ifdef LUA_EMBEDDED
static char* getUdfFuncName(char* funcname, char* name, int type) { static char* getUdfFuncName(char* funcname, char* name, int type) {
switch (type) { switch (type) {
case TSDB_UDF_FUNC_NORMAL: case TSDB_UDF_FUNC_NORMAL:
...@@ -8265,8 +8265,9 @@ static char* getUdfFuncName(char* funcname, char* name, int type) { ...@@ -8265,8 +8265,9 @@ static char* getUdfFuncName(char* funcname, char* name, int type) {
return funcname; return funcname;
} }
#endif
int32_t initUdfInfo(SUdfInfo* pUdfInfo) { int32_t initUdfInfo(SUdfInfo* pUdfInfo) {
#ifdef LUA_EMBEDDED
if (pUdfInfo == NULL || pUdfInfo->handle) { if (pUdfInfo == NULL || pUdfInfo->handle) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -8350,7 +8351,7 @@ int32_t initUdfInfo(SUdfInfo* pUdfInfo) { ...@@ -8350,7 +8351,7 @@ int32_t initUdfInfo(SUdfInfo* pUdfInfo) {
return (*(udfInitFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_INIT])(&pUdfInfo->init); return (*(udfInitFunc)pUdfInfo->funcs[TSDB_UDF_FUNC_INIT])(&pUdfInfo->init);
} }
} }
#endif //LUA_EMBEDDED
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifdef LUA_EMBEDDED
#include "os.h" #include "os.h"
#include "qScript.h" #include "qScript.h"
#include "ttype.h" #include "ttype.h"
...@@ -444,3 +444,4 @@ bool isValidScript(char *script, int32_t len) { ...@@ -444,3 +444,4 @@ bool isValidScript(char *script, int32_t len) {
return ret; return ret;
} }
#endif
...@@ -63,6 +63,7 @@ else ...@@ -63,6 +63,7 @@ else
end end
--[[
local flag = false local flag = false
function query_callback(res) function query_callback(res)
if res.code ~=0 then if res.code ~=0 then
...@@ -80,9 +81,10 @@ end ...@@ -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) 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 while not flag do
-- ngx.say("i am here once...") ngx.say("i am here once...")
ngx.sleep(0.001) -- time unit is second ngx.sleep(0.001) -- time unit is second
end end
--]]
ngx.say("pool water_mark:"..pool:get_water_mark()) ngx.say("pool water_mark:"..pool:get_water_mark())
......
# TDengine driver connector for Lua # 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 Dependencies
- Lua: - Lua:
``` ```
......
...@@ -102,7 +102,7 @@ static int l_query(lua_State *L){ ...@@ -102,7 +102,7 @@ static int l_query(lua_State *L){
printf("failed, reason:%s\n", taos_errstr(result)); printf("failed, reason:%s\n", taos_errstr(result));
lua_pushinteger(L, -1); lua_pushinteger(L, -1);
lua_setfield(L, table_index, "code"); lua_setfield(L, table_index, "code");
lua_pushstring(L, taos_errstr(taos)); lua_pushstring(L, taos_errstr(result));
lua_setfield(L, table_index, "error"); lua_setfield(L, table_index, "error");
return 1; return 1;
......
...@@ -102,7 +102,7 @@ static int l_query(lua_State *L){ ...@@ -102,7 +102,7 @@ static int l_query(lua_State *L){
printf("failed, reason:%s\n", taos_errstr(result)); printf("failed, reason:%s\n", taos_errstr(result));
lua_pushinteger(L, -1); lua_pushinteger(L, -1);
lua_setfield(L, table_index, "code"); lua_setfield(L, table_index, "code");
lua_pushstring(L, taos_errstr(taos)); lua_pushstring(L, taos_errstr(result));
lua_setfield(L, table_index, "error"); lua_setfield(L, table_index, "error");
return 1; return 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册