diff --git a/cmake/define.inc b/cmake/define.inc index 92044b8c2dd3710c5a1808abcecd7d2358230e7a..21b517e197fbb8ee568d3017cd5e78a8750644e2 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 0812711a5824ce0b328374fcdd04fc5f229ad01c..4273f576b4bfb292e946fa8086527a48389b9908 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 38f36c4ed6678675cecfa9c0da1a3d065b58da86..45eaf6495d0f20c512d175c880af9bc1ed8f0ba6 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/documentation20/cn/02.getting-started/docs.md b/documentation20/cn/02.getting-started/docs.md index adbba4603b94c689cab2e0aaaedf0e232ae3d1f4..64b05740863ddb24e1851dd230ef1093488c128b 100644 --- a/documentation20/cn/02.getting-started/docs.md +++ b/documentation20/cn/02.getting-started/docs.md @@ -190,7 +190,7 @@ taosdemo 详细使用方法请参照 [如何使用taosdemo对TDengine进行性 ### TDengine 服务器支持的平台列表 -| | **CentOS 6/7/8** | **Ubuntu 16/18/20** | **Other Linux** | **统信 UOS** | **银河/中标麒麟** | **凝思 V60/V80** | **华为 EulerOS** | +| | **CentOS 7/8** | **Ubuntu 16/18/20** | **Other Linux** | **统信 UOS** | **银河/中标麒麟** | **凝思 V60/V80** | **华为 EulerOS** | | -------------- | --------------------- | ------------------------ | --------------- | --------------- | ------------------------- | --------------------- | --------------------- | | X64 | ● | ● | | ○ | ● | ● | ● | | 龙芯 MIPS64 | | | ● | | | | | diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index fb4070385cd985fc5c0a2322d86392b013fab46b..fca3b0b57b14a963f1c0e0be11c246f085b45952 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/tscServer.c b/src/client/src/tscServer.c index 52a918bbe22589d85fc89cbff8249065129f1618..126aa3bc046b1e1d133a4d5f28a30a51fe537846 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1536,7 +1536,17 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pMsg += sizeof(SCreateTableMsg); SCreatedTableInfo* p = taosArrayGet(list, i); - strcpy(pCreate->tableName, p->fullname); + //what pCreate->tableName point is a fixed char array which size is 237 + //what p->fullname point is a char* + //before the time we copy p->fullname to pCreate->tableName , we need to check the length of p->fullname + if (strlen(p->fullname) > 237) { + tscError("failed to write this name, which is over 237, just save the first 237 char here"); + strncpy(pCreate->tableName, p->fullname,237); + pCreate->tableName[236]='\0';//I don't know if this line is working properly + }else{ + strcpy(pCreate->tableName, p->fullname); + } + pCreate->igExists = (p->igExist)? 1 : 0; // use dbinfo from table id without modifying current db info diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index edb8169f761e2b5aaba1ddfd7cda8a9008298948..f6614fdb79f18b70cadc2351edc8e402e95bf41e 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 69c6203ab355e93272113b0cdfbab3e066be8148..87128521730c9c58f3c3dd9b35ab3f919f6921ec 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 4b57843708ac8d1c24c69e68fe406b0edbeeabd2..a815942fbedb4f3b99e3595c3960d931ddde192a 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 574bb51368afeaeddef5fbd5c5bd8469fbe0cdef..2dc9b5812bbfa34dcebdde5438516d3be42a51d2 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 6a89a2f823ad3ff57807561d7ead4b919851b000..29dc65d8f8f78c12a9969db48e58ed9e4717fa98 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 c43b0b3435b2073d4711bbb8a0ec0d9e347b0d13..a8a6f6732b7eef33cad040c2aadc4b3e1848bde2 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/src/util/src/tconfig.c b/src/util/src/tconfig.c index 69b0d8d7bb9ad5ab37321a5460c3f083e3a71dba..4c968a8362766b564230befafb27c226c338c51b 100644 --- a/src/util/src/tconfig.c +++ b/src/util/src/tconfig.c @@ -334,8 +334,9 @@ bool taosReadConfigOption(const char *option, char *value, char *value2, char *v if (taosReadDirectoryConfig(cfg, value)) { taosReadDataDirCfg(value, value2, value3); ret = true; + } else { + ret = false; } - ret = false; break; default: uError("config option:%s, input value:%s, can't be recognized", option, value); diff --git a/tests/examples/lua/OpenResty/rest/test.lua b/tests/examples/lua/OpenResty/rest/test.lua index 48aeef3fb4dd8c9a0dc18e8039b4b8c781760666..2dc0cf10f22b90c8bcb925700b1d7ebd00ff153a 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 32d6a4cace9bd0bf66238ff32af1d3ecf0285046..bdc88edbd7b5d6798a8df6530ea82d24eb22915b 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 fe2152945dc1915dca5de31458a8cbb2f007f4f2..b6e0b6d1de200b09750ffba6845ae9bf0606f4d8 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 8c2ea3e9e83237fc8ed9ebce687f5131352e4d14..06568f35d656d5d9af1ae2e88eeaeba92f0ede91 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;