diff --git a/cmake/define.inc b/cmake/define.inc index 7894e6dab5d4ddd44e69f77702004183f431d3a6..a5fbd8abe959fb8530dd8cc26c79eefd47ec6b9f 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -124,6 +124,10 @@ IF (TD_APLHINE) MESSAGE(STATUS "aplhine is defined") ENDIF () +IF (TD_BUILD_HTTP) + ADD_DEFINITIONS(-DHTTP_EMBEDDED) +ENDIF () + IF (TD_LINUX) ADD_DEFINITIONS(-DLINUX) ADD_DEFINITIONS(-D_LINUX) diff --git a/cmake/input.inc b/cmake/input.inc index d746cf52f6eb016795d6fa6d01f408925159c710..ed8788922c8026cbc4c6b90ef477dcbd21cf8ba0 100755 --- a/cmake/input.inc +++ b/cmake/input.inc @@ -90,6 +90,12 @@ IF (${BUILD_JDBC} MATCHES "false") SET(TD_BUILD_JDBC FALSE) ENDIF () +SET(TD_BUILD_HTTP TRUE) + +IF (${BUILD_HTTP} MATCHES "false") + SET(TD_BUILD_HTTP FALSE) +ENDIF () + SET(TD_MEMORY_SANITIZER FALSE) IF (${MEMORY_SANITIZER} MATCHES "true") SET(TD_MEMORY_SANITIZER TRUE) diff --git a/packaging/tools/make_install.sh b/packaging/tools/make_install.sh index 106545dc9143ffb110112e51bd86da350e234929..ee2a579c1f1ed99dd2797abdd2ba00e595eb9f8d 100755 --- a/packaging/tools/make_install.sh +++ b/packaging/tools/make_install.sh @@ -245,8 +245,10 @@ function install_lib() { else ${csudo} cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* + ${csudo} ln -sf ${install_main_dir}/driver/libtaos.* ${install_main_dir}/driver/libtaos.1.dylib || : + ${csudo} ln -sf ${install_main_dir}/driver/libtaos.1.dylib ${install_main_dir}/driver/libtaos.dylib || : ${csudo} ln -sf ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib || : - ${csudo} ln -sf ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib || : + ${csudo} ln -sf ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib || : fi install_jemalloc diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt index cf53977103c3a9760286e70447d826f7026d7e53..4eb0d2b2bfdd1d42ec93a85083c2f0fc0382af5a 100644 --- a/src/client/CMakeLists.txt +++ b/src/client/CMakeLists.txt @@ -5,7 +5,11 @@ INCLUDE_DIRECTORIES(inc) INCLUDE_DIRECTORIES(jni) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/zlib-1.2.11/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/plugins/http/inc) + +IF (TD_BUILD_HTTP) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/plugins/http/inc) +ENDIF () + AUX_SOURCE_DIRECTORY(src SRC) IF (TD_LINUX) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 8d6c655bc9f605ce3daa03075d60b64f2e5285fe..f4a694ad71cfd62f25f4df9000baecfada1fdbf4 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -29,7 +29,10 @@ #include "tsclient.h" #include "ttimer.h" #include "ttokendef.h" + +#ifdef HTTP_EMBEDDED #include "httpInt.h" +#endif static void freeQueryInfoImpl(SQueryInfo* pQueryInfo); @@ -5197,11 +5200,14 @@ void tscRemoveCachedTableMeta(STableMetaInfo* pTableMetaInfo, uint64_t id) { char* cloneCurrentDBName(SSqlObj* pSql) { char *p = NULL; +#ifdef HTTP_EMBEDDED HttpContext *pCtx = NULL; +#endif pthread_mutex_lock(&pSql->pTscObj->mutex); STscObj *pTscObj = pSql->pTscObj; switch (pTscObj->from) { +#ifdef HTTP_EMBEDDED case TAOS_REQ_FROM_HTTP: pCtx = pSql->param; if (pCtx && pCtx->db[0] != '\0') { @@ -5212,6 +5218,7 @@ char* cloneCurrentDBName(SSqlObj* pSql) { p = strdup(db); } break; +#endif default: break; } diff --git a/src/connector/grafanaplugin b/src/connector/grafanaplugin index 4a4d79099b076b8ff12d5b4fdbcba54049a6866d..016d8e82a24d72779be0ab0090580a372b4fffca 160000 --- a/src/connector/grafanaplugin +++ b/src/connector/grafanaplugin @@ -1 +1 @@ -Subproject commit 4a4d79099b076b8ff12d5b4fdbcba54049a6866d +Subproject commit 016d8e82a24d72779be0ab0090580a372b4fffca diff --git a/src/dnode/CMakeLists.txt b/src/dnode/CMakeLists.txt index 47186130ead0d1ee3f4593b7ef346f8cc47f7cba..a009448c822ca651fd91583277ed92b183f155d2 100644 --- a/src/dnode/CMakeLists.txt +++ b/src/dnode/CMakeLists.txt @@ -18,7 +18,12 @@ ELSE () ENDIF () ADD_EXECUTABLE(taosd ${SRC}) + +IF (TD_BUILD_HTTP) TARGET_LINK_LIBRARIES(taosd mnode monitor http tsdb twal vnode cJson lua lz4 balance sync ${LINK_JEMALLOC}) +ELSE () +TARGET_LINK_LIBRARIES(taosd mnode monitor tsdb twal vnode cJson lua lz4 balance sync ${LINK_JEMALLOC}) +ENDIF () IF (TD_SOMODE_STATIC) TARGET_LINK_LIBRARIES(taosd taos_static) diff --git a/src/dnode/src/dnodeModule.c b/src/dnode/src/dnodeModule.c index a661585b3b39df986ac7866a255472e47e789fe6..39f9e352793ffcab885438309980c0c530e048ad 100644 --- a/src/dnode/src/dnodeModule.c +++ b/src/dnode/src/dnodeModule.c @@ -49,6 +49,7 @@ static void dnodeAllocModules() { tsModule[TSDB_MOD_MNODE].startFp = mnodeStartSystem; tsModule[TSDB_MOD_MNODE].stopFp = mnodeStopSystem; +#ifdef HTTP_EMBEDDED tsModule[TSDB_MOD_HTTP].enable = (tsEnableHttpModule == 1); tsModule[TSDB_MOD_HTTP].name = "http"; tsModule[TSDB_MOD_HTTP].initFp = httpInitSystem; @@ -58,6 +59,7 @@ static void dnodeAllocModules() { if (tsEnableHttpModule) { dnodeSetModuleStatus(TSDB_MOD_HTTP); } +#endif #ifdef _MQTT tsModule[TSDB_MOD_MQTT].enable = (tsEnableMqttModule == 1); diff --git a/src/dnode/src/dnodeShell.c b/src/dnode/src/dnodeShell.c index 5606681f0f931070e9cbf21d6b98b0d2eb51bdfa..98bbbf8f73b26535030c5096f128a7f84c2b9f61 100644 --- a/src/dnode/src/dnodeShell.c +++ b/src/dnode/src/dnodeShell.c @@ -240,7 +240,9 @@ void *dnodeSendCfgTableToRecv(int32_t vgId, int32_t tid) { SStatisInfo dnodeGetStatisInfo() { SStatisInfo info = {0}; if (dnodeGetRunStatus() == TSDB_RUN_STATUS_RUNING) { +#ifdef HTTP_EMBEDDED info.httpReqNum = httpGetReqCount(); +#endif info.queryReqNum = atomic_exchange_32(&tsQueryReqNum, 0); info.submitReqNum = atomic_exchange_32(&tsSubmitReqNum, 0); } diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 996ca9a4a31d937699eaa7e569828bf1a0def79c..f8e6e59863e7748b3752e6afb56cbd4242bb43f2 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -586,6 +586,7 @@ static int64_t getTSRandTail(int64_t timeStampStep, int32_t seq, int disorderRatio, int disorderRange); static bool getInfoFromJsonFile(char* file); static void init_rand_data(); +static int regexMatch(const char *s, const char *reg, int cflags); /* ************ Global variables ************ */ @@ -803,7 +804,7 @@ static void printHelp() { printf("%s%s%s%s\n", indent, "-q, --query-mode=MODE", "\t\t", "Query mode -- 0: SYNC, 1: ASYNC. By default use SYNC."); printf("%s%s%s%s\n", indent, "-b, --data-type=DATATYPE", "\t", - "The data_type of columns, By default use: FLOAT, INT, FLOAT."); + "The data_type of columns, By default use: FLOAT,INT,FLOAT. NCHAR and BINARY can also use custom length. Eg: NCHAR(16),BINARY(8)"); printf("%s%s%s%s%d\n", indent, "-w, --binwidth=WIDTH", "\t\t", "The width of data_type 'BINARY' or 'NCHAR'. By default use ", g_args.binwidth); @@ -1579,9 +1580,8 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { && strcasecmp(dataType, "SMALLINT") && strcasecmp(dataType, "BIGINT") && strcasecmp(dataType, "DOUBLE") - && strcasecmp(dataType, "BINARY") && strcasecmp(dataType, "TIMESTAMP") - && strcasecmp(dataType, "NCHAR") + && !regexMatch(dataType, "^(NCHAR|BINARY)(\\([1-9][0-9]*\\))?$", REG_ICASE | REG_EXTENDED) && strcasecmp(dataType, "UTINYINT") && strcasecmp(dataType, "USMALLINT") && strcasecmp(dataType, "UINT") @@ -1603,9 +1603,11 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { arguments->data_type[0] = TSDB_DATA_TYPE_FLOAT; } else if (0 == strcasecmp(dataType, "DOUBLE")) { arguments->data_type[0] = TSDB_DATA_TYPE_DOUBLE; - } else if (0 == strcasecmp(dataType, "BINARY")) { + } else if (1 == regexMatch(dataType, "^BINARY(\\([1-9][0-9]*\\))?$", REG_ICASE | + REG_EXTENDED)) { arguments->data_type[0] = TSDB_DATA_TYPE_BINARY; - } else if (0 == strcasecmp(dataType, "NCHAR")) { + } else if (1 == regexMatch(dataType, "^NCHAR(\\([1-9][0-9]*\\))?$", REG_ICASE | + REG_EXTENDED)) { arguments->data_type[0] = TSDB_DATA_TYPE_NCHAR; } else if (0 == strcasecmp(dataType, "BOOL")) { arguments->data_type[0] = TSDB_DATA_TYPE_BOOL; @@ -1638,9 +1640,8 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { && strcasecmp(token, "SMALLINT") && strcasecmp(token, "BIGINT") && strcasecmp(token, "DOUBLE") - && strcasecmp(token, "BINARY") && strcasecmp(token, "TIMESTAMP") - && strcasecmp(token, "NCHAR") + && !regexMatch(token, "^(NCHAR|BINARY)(\\([1-9][0-9]*\\))?$", REG_ICASE | REG_EXTENDED) && strcasecmp(token, "UTINYINT") && strcasecmp(token, "USMALLINT") && strcasecmp(token, "UINT") @@ -1663,9 +1664,11 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { arguments->data_type[index] = TSDB_DATA_TYPE_DOUBLE; } else if (0 == strcasecmp(token, "TINYINT")) { arguments->data_type[index] = TSDB_DATA_TYPE_TINYINT; - } else if (0 == strcasecmp(token, "BINARY")) { + } else if (1 == regexMatch(token, "^BINARY(\\([1-9][0-9]*\\))?$", REG_ICASE | + REG_EXTENDED)) { arguments->data_type[index] = TSDB_DATA_TYPE_BINARY; - } else if (0 == strcasecmp(token, "NCHAR")) { + } else if (1 == regexMatch(token, "^NCHAR(\\([1-9][0-9]*\\))?$", REG_ICASE | + REG_EXTENDED)) { arguments->data_type[index] = TSDB_DATA_TYPE_NCHAR; } else if (0 == strcasecmp(token, "BOOL")) { arguments->data_type[index] = TSDB_DATA_TYPE_BOOL; @@ -2660,117 +2663,127 @@ static int printfInsertMeta() { } } - printf(" super table count: \033[33m%"PRIu64"\033[0m\n", - g_Dbs.db[i].superTblCount); - for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { - printf(" super table[\033[33m%"PRIu64"\033[0m]:\n", j); - printf(" stbName: \033[33m%s\033[0m\n", - g_Dbs.db[i].superTbls[j].stbName); - - if (PRE_CREATE_SUBTBL == g_Dbs.db[i].superTbls[j].autoCreateTable) { - printf(" autoCreateTable: \033[33m%s\033[0m\n", "no"); - } else if (AUTO_CREATE_SUBTBL == - g_Dbs.db[i].superTbls[j].autoCreateTable) { - printf(" autoCreateTable: \033[33m%s\033[0m\n", "yes"); - } else { - printf(" autoCreateTable: \033[33m%s\033[0m\n", "error"); - } - - if (TBL_NO_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists) { - printf(" childTblExists: \033[33m%s\033[0m\n", "no"); - } else if (TBL_ALREADY_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists) { - printf(" childTblExists: \033[33m%s\033[0m\n", "yes"); - } else { - printf(" childTblExists: \033[33m%s\033[0m\n", "error"); - } - - printf(" childTblCount: \033[33m%"PRId64"\033[0m\n", - g_Dbs.db[i].superTbls[j].childTblCount); - printf(" childTblPrefix: \033[33m%s\033[0m\n", - g_Dbs.db[i].superTbls[j].childTblPrefix); - printf(" dataSource: \033[33m%s\033[0m\n", - g_Dbs.db[i].superTbls[j].dataSource); - printf(" iface: \033[33m%s\033[0m\n", - (g_Dbs.db[i].superTbls[j].iface==TAOSC_IFACE)?"taosc": - (g_Dbs.db[i].superTbls[j].iface==REST_IFACE)?"rest":"stmt"); - if (g_Dbs.db[i].superTbls[j].childTblLimit > 0) { - printf(" childTblLimit: \033[33m%"PRId64"\033[0m\n", - g_Dbs.db[i].superTbls[j].childTblLimit); - } - if (g_Dbs.db[i].superTbls[j].childTblOffset > 0) { - printf(" childTblOffset: \033[33m%"PRIu64"\033[0m\n", - g_Dbs.db[i].superTbls[j].childTblOffset); - } - printf(" insertRows: \033[33m%"PRId64"\033[0m\n", - g_Dbs.db[i].superTbls[j].insertRows); - /* - if (0 == g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl) { - printf(" multiThreadWriteOneTbl: \033[33m no\033[0m\n"); - }else { - printf(" multiThreadWriteOneTbl: \033[33m yes\033[0m\n"); - } - */ - printf(" interlaceRows: \033[33m%u\033[0m\n", - g_Dbs.db[i].superTbls[j].interlaceRows); + if (g_args.use_metric) { + printf(" super table count: \033[33m%"PRIu64"\033[0m\n", + g_Dbs.db[i].superTblCount); + for (uint64_t j = 0; j < g_Dbs.db[i].superTblCount; j++) { + printf(" super table[\033[33m%"PRIu64"\033[0m]:\n", j); - if (g_Dbs.db[i].superTbls[j].interlaceRows > 0) { - printf(" stable insert interval: \033[33m%"PRIu64"\033[0m\n", - g_Dbs.db[i].superTbls[j].insertInterval); - } + printf(" stbName: \033[33m%s\033[0m\n", + g_Dbs.db[i].superTbls[j].stbName); - printf(" disorderRange: \033[33m%d\033[0m\n", - g_Dbs.db[i].superTbls[j].disorderRange); - printf(" disorderRatio: \033[33m%d\033[0m\n", - g_Dbs.db[i].superTbls[j].disorderRatio); - printf(" maxSqlLen: \033[33m%"PRIu64"\033[0m\n", - g_Dbs.db[i].superTbls[j].maxSqlLen); - printf(" timeStampStep: \033[33m%"PRId64"\033[0m\n", - g_Dbs.db[i].superTbls[j].timeStampStep); - printf(" startTimestamp: \033[33m%s\033[0m\n", - g_Dbs.db[i].superTbls[j].startTimestamp); - printf(" sampleFormat: \033[33m%s\033[0m\n", - g_Dbs.db[i].superTbls[j].sampleFormat); - printf(" sampleFile: \033[33m%s\033[0m\n", - g_Dbs.db[i].superTbls[j].sampleFile); - printf(" tagsFile: \033[33m%s\033[0m\n", - g_Dbs.db[i].superTbls[j].tagsFile); - printf(" columnCount: \033[33m%d\033[0m\n", - g_Dbs.db[i].superTbls[j].columnCount); - for (int k = 0; k < g_Dbs.db[i].superTbls[j].columnCount; k++) { - //printf("dataType:%s, dataLen:%d\t", g_Dbs.db[i].superTbls[j].columns[k].dataType, g_Dbs.db[i].superTbls[j].columns[k].dataLen); - if ((0 == strncasecmp(g_Dbs.db[i].superTbls[j].columns[k].dataType, - "binary", 6)) - || (0 == strncasecmp(g_Dbs.db[i].superTbls[j].columns[k].dataType, - "nchar", 5))) { - printf("column[\033[33m%d\033[0m]:\033[33m%s(%d)\033[0m ", k, - g_Dbs.db[i].superTbls[j].columns[k].dataType, - g_Dbs.db[i].superTbls[j].columns[k].dataLen); + if (PRE_CREATE_SUBTBL == g_Dbs.db[i].superTbls[j].autoCreateTable) { + printf(" autoCreateTable: \033[33m%s\033[0m\n", "no"); + } else if (AUTO_CREATE_SUBTBL == + g_Dbs.db[i].superTbls[j].autoCreateTable) { + printf(" autoCreateTable: \033[33m%s\033[0m\n", "yes"); } else { - printf("column[%d]:\033[33m%s\033[0m ", k, - g_Dbs.db[i].superTbls[j].columns[k].dataType); + printf(" autoCreateTable: \033[33m%s\033[0m\n", "error"); } - } - printf("\n"); - printf(" tagCount: \033[33m%d\033[0m\n ", - g_Dbs.db[i].superTbls[j].tagCount); - for (int k = 0; k < g_Dbs.db[i].superTbls[j].tagCount; k++) { - //printf("dataType:%s, dataLen:%d\t", g_Dbs.db[i].superTbls[j].tags[k].dataType, g_Dbs.db[i].superTbls[j].tags[k].dataLen); - if ((0 == strncasecmp(g_Dbs.db[i].superTbls[j].tags[k].dataType, - "binary", strlen("binary"))) - || (0 == strncasecmp(g_Dbs.db[i].superTbls[j].tags[k].dataType, - "nchar", strlen("nchar")))) { - printf("tag[%d]:\033[33m%s(%d)\033[0m ", k, - g_Dbs.db[i].superTbls[j].tags[k].dataType, - g_Dbs.db[i].superTbls[j].tags[k].dataLen); + if (TBL_NO_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists) { + printf(" childTblExists: \033[33m%s\033[0m\n", "no"); + } else if (TBL_ALREADY_EXISTS == g_Dbs.db[i].superTbls[j].childTblExists) { + printf(" childTblExists: \033[33m%s\033[0m\n", "yes"); } else { - printf("tag[%d]:\033[33m%s\033[0m ", k, - g_Dbs.db[i].superTbls[j].tags[k].dataType); + printf(" childTblExists: \033[33m%s\033[0m\n", "error"); + } + + printf(" childTblCount: \033[33m%"PRId64"\033[0m\n", + g_Dbs.db[i].superTbls[j].childTblCount); + printf(" childTblPrefix: \033[33m%s\033[0m\n", + g_Dbs.db[i].superTbls[j].childTblPrefix); + printf(" dataSource: \033[33m%s\033[0m\n", + g_Dbs.db[i].superTbls[j].dataSource); + printf(" iface: \033[33m%s\033[0m\n", + (g_Dbs.db[i].superTbls[j].iface==TAOSC_IFACE)?"taosc": + (g_Dbs.db[i].superTbls[j].iface==REST_IFACE)?"rest":"stmt"); + if (g_Dbs.db[i].superTbls[j].childTblLimit > 0) { + printf(" childTblLimit: \033[33m%"PRId64"\033[0m\n", + g_Dbs.db[i].superTbls[j].childTblLimit); + } + if (g_Dbs.db[i].superTbls[j].childTblOffset > 0) { + printf(" childTblOffset: \033[33m%"PRIu64"\033[0m\n", + g_Dbs.db[i].superTbls[j].childTblOffset); + } + printf(" insertRows: \033[33m%"PRId64"\033[0m\n", + g_Dbs.db[i].superTbls[j].insertRows); + /* + if (0 == g_Dbs.db[i].superTbls[j].multiThreadWriteOneTbl) { + printf(" multiThreadWriteOneTbl: \033[33m no\033[0m\n"); + }else { + printf(" multiThreadWriteOneTbl: \033[33m yes\033[0m\n"); + } + */ + printf(" interlaceRows: \033[33m%u\033[0m\n", + g_Dbs.db[i].superTbls[j].interlaceRows); + + if (g_Dbs.db[i].superTbls[j].interlaceRows > 0) { + printf(" stable insert interval: \033[33m%"PRIu64"\033[0m\n", + g_Dbs.db[i].superTbls[j].insertInterval); + } + + printf(" disorderRange: \033[33m%d\033[0m\n", + g_Dbs.db[i].superTbls[j].disorderRange); + printf(" disorderRatio: \033[33m%d\033[0m\n", + g_Dbs.db[i].superTbls[j].disorderRatio); + printf(" maxSqlLen: \033[33m%"PRIu64"\033[0m\n", + g_Dbs.db[i].superTbls[j].maxSqlLen); + printf(" timeStampStep: \033[33m%"PRId64"\033[0m\n", + g_Dbs.db[i].superTbls[j].timeStampStep); + printf(" startTimestamp: \033[33m%s\033[0m\n", + g_Dbs.db[i].superTbls[j].startTimestamp); + printf(" sampleFormat: \033[33m%s\033[0m\n", + g_Dbs.db[i].superTbls[j].sampleFormat); + printf(" sampleFile: \033[33m%s\033[0m\n", + g_Dbs.db[i].superTbls[j].sampleFile); + printf(" tagsFile: \033[33m%s\033[0m\n", + g_Dbs.db[i].superTbls[j].tagsFile); + printf(" columnCount: \033[33m%d\033[0m\n ", + g_Dbs.db[i].superTbls[j].columnCount); + for (int k = 0; k < g_Dbs.db[i].superTbls[j].columnCount; k++) { + //printf("dataType:%s, dataLen:%d\t", g_Dbs.db[i].superTbls[j].columns[k].dataType, g_Dbs.db[i].superTbls[j].columns[k].dataLen); + if ((0 == strncasecmp(g_Dbs.db[i].superTbls[j].columns[k].dataType, + "binary", 6)) + || (0 == strncasecmp(g_Dbs.db[i].superTbls[j].columns[k].dataType, + "nchar", 5))) { + printf("column[%d]:\033[33m%s(%d)\033[0m ", k, + g_Dbs.db[i].superTbls[j].columns[k].dataType, + g_Dbs.db[i].superTbls[j].columns[k].dataLen); + } else { + printf("column[%d]:\033[33m%s\033[0m ", k, + g_Dbs.db[i].superTbls[j].columns[k].dataType); + } + } + printf("\n"); + + printf(" tagCount: \033[33m%d\033[0m\n ", + g_Dbs.db[i].superTbls[j].tagCount); + for (int k = 0; k < g_Dbs.db[i].superTbls[j].tagCount; k++) { + //printf("dataType:%s, dataLen:%d\t", g_Dbs.db[i].superTbls[j].tags[k].dataType, g_Dbs.db[i].superTbls[j].tags[k].dataLen); + if ((0 == strncasecmp(g_Dbs.db[i].superTbls[j].tags[k].dataType, + "binary", strlen("binary"))) + || (0 == strncasecmp(g_Dbs.db[i].superTbls[j].tags[k].dataType, + "nchar", strlen("nchar")))) { + printf("tag[%d]:\033[33m%s(%d)\033[0m ", k, + g_Dbs.db[i].superTbls[j].tags[k].dataType, + g_Dbs.db[i].superTbls[j].tags[k].dataLen); + } else { + printf("tag[%d]:\033[33m%s\033[0m ", k, + g_Dbs.db[i].superTbls[j].tags[k].dataType); + } } + printf("\n"); } - printf("\n"); + } else { + printf(" childTblCount: \033[33m%"PRId64"\033[0m\n", + g_args.ntables); + printf(" insertRows: \033[33m%"PRId64"\033[0m\n", + g_args.insertRows); } + + printf("\n"); } @@ -10286,8 +10299,7 @@ static void startMultiThreadInsertData(int threads, char* db_name, b = ntables % threads; } - if ((stbInfo) - && (stbInfo->iface == REST_IFACE)) { + if (g_args.iface == REST_IFACE || ((stbInfo) && (stbInfo->iface == REST_IFACE))) { if (convertHostToServAddr( g_Dbs.host, g_Dbs.port, &(g_Dbs.serv_addr)) != 0) { ERROR_EXIT("convert host to server address"); @@ -11738,6 +11750,8 @@ static void initOfQueryMeta() { } static void setParaFromArg() { + char type[20]; + char length[20]; if (g_args.host) { tstrncpy(g_Dbs.host, g_args.host, MAX_HOSTNAME_SIZE); } else { @@ -11819,7 +11833,17 @@ static void setParaFromArg() { g_Dbs.db[0].superTbls[0].columns[i].data_type = data_type[i]; tstrncpy(g_Dbs.db[0].superTbls[0].columns[i].dataType, dataType[i], min(DATATYPE_BUFF_LEN, strlen(dataType[i]) + 1)); - g_Dbs.db[0].superTbls[0].columns[i].dataLen = g_args.binwidth; + if (1 == regexMatch(dataType[i], "^(NCHAR|BINARY)(\\([1-9][0-9]*\\))$", REG_ICASE | + REG_EXTENDED)) { + sscanf(dataType[i], "%[^(](%[^)]", type, length); + g_Dbs.db[0].superTbls[0].columns[i].dataLen = atoi(length); + tstrncpy(g_Dbs.db[0].superTbls[0].columns[i].dataType, + type, min(DATATYPE_BUFF_LEN, strlen(type) + 1)); + } else { + g_Dbs.db[0].superTbls[0].columns[i].dataLen = g_args.binwidth; + tstrncpy(g_Dbs.db[0].superTbls[0].columns[i].dataType, + dataType[i], min(DATATYPE_BUFF_LEN, strlen(dataType[i]) + 1)); + } g_Dbs.db[0].superTbls[0].columnCount++; } diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index 3bb62af6f63cf4c896b3bb2ffb375a15f74f85b6..e1a213c3565c234323e0f5cfc8e62393f8a47c29 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -38,8 +38,8 @@ static int converStringToReadable(char *str, int size, char *buf, int bufsize); static int convertNCharToReadable(char *str, int size, char *buf, int bufsize); -static void taosDumpCharset(FILE *fp); -static void taosLoadFileCharset(FILE *fp, char *fcharset); +static void dumpCharset(FILE *fp); +static void loadFileCharset(FILE *fp, char *fcharset); typedef struct { short bytes; @@ -159,7 +159,8 @@ typedef struct { } TableRecord; typedef struct { - bool isStable; + bool isStb; + bool belongStb; int64_t dumpNtbCount; TableRecord **dumpNtbInfos; TableRecord tableRecord; @@ -329,18 +330,19 @@ static resultStatistics g_resultStatistics = {0}; static FILE *g_fpOfResult = NULL; static int g_numOfCores = 1; -static int taosDumpOut(); -static int taosDumpIn(); -static void taosDumpCreateDbClause(SDbInfo *dbInfo, bool isDumpProperty, +static int dumpOut(); +static int dumpIn(); +static void dumpCreateDbClause(SDbInfo *dbInfo, bool isDumpProperty, FILE *fp); -//static int taosDumpDb(SDbInfo *dbInfo, FILE *fp, TAOS *taos); -static int dumpStable(char *table, FILE *fp, SDbInfo *dbInfo); +//static int dumpDb(SDbInfo *dbInfo, FILE *fp, TAOS *taos); +static int dumpStableClasuse(SDbInfo *dbInfo, char *table, FILE *fp); static int dumpCreateTableClause(STableDef *tableDes, int numOfCols, FILE *fp, char* dbName); -static void taosDumpCreateMTableClause(STableDef *tableDes, char *stable, +static void dumpCreateMTableClause(STableDef *tableDes, char *stable, int numOfCols, FILE *fp, char* dbName); -static int64_t taosDumpTable(char *tbName, char *stable, - FILE *fp, char* dbName, int precision); +static int getTableDes( + char* dbName, char *table, + STableDef *stableDes, bool isSuperTable); static int64_t dumpTableData(FILE *fp, char *tbName, char* dbName, int precision, @@ -420,16 +422,16 @@ static void printVersion() { } } -UNUSED_FUNC void errorWrongValue(char *program, char *wrong_arg, char *wrong_value) +void errorWrongValue(char *program, char *wrong_arg, char *wrong_value) { fprintf(stderr, "%s %s: %s is an invalid value\n", program, wrong_arg, wrong_value); - fprintf(stderr, "Try `taosdemo --help' or `taosdemo --usage' for more information.\n"); + fprintf(stderr, "Try `taosdump --help' or `taosdump --usage' for more information.\n"); } static void errorUnrecognized(char *program, char *wrong_arg) { fprintf(stderr, "%s: unrecognized options '%s'\n", program, wrong_arg); - fprintf(stderr, "Try `taosdemo --help' or `taosdemo --usage' for more information.\n"); + fprintf(stderr, "Try `taosdump --help' or `taosdump --usage' for more information.\n"); } static void errorPrintReqArg(char *program, char *wrong_arg) @@ -438,7 +440,7 @@ static void errorPrintReqArg(char *program, char *wrong_arg) "%s: option requires an argument -- '%s'\n", program, wrong_arg); fprintf(stderr, - "Try `taosdemo --help' or `taosdemo --usage' for more information.\n"); + "Try `taosdump --help' or `taosdump --usage' for more information.\n"); } static void errorPrintReqArg2(char *program, char *wrong_arg) @@ -447,7 +449,7 @@ static void errorPrintReqArg2(char *program, char *wrong_arg) "%s: option requires a number argument '-%s'\n", program, wrong_arg); fprintf(stderr, - "Try `taosdemo --help' or `taosdemo --usage' for more information.\n"); + "Try `taosdump --help' or `taosdump --usage' for more information.\n"); } static void errorPrintReqArg3(char *program, char *wrong_arg) @@ -456,7 +458,7 @@ static void errorPrintReqArg3(char *program, char *wrong_arg) "%s: option '%s' requires an argument\n", program, wrong_arg); fprintf(stderr, - "Try `taosdemo --help' or `taosdemo --usage' for more information.\n"); + "Try `taosdump --help' or `taosdump --usage' for more information.\n"); } /* Parse a single option. */ @@ -483,7 +485,14 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { errorPrintReqArg2("taosdump", "P"); exit(EXIT_FAILURE); } - g_args.port = atoi(arg); + + uint64_t port = atoi(arg); + if (port > 65535) { + errorWrongValue("taosdump", "-P or --port", arg); + exit(EXIT_FAILURE); + } + g_args.port = (uint16_t)port; + break; case 'q': g_args.mysqlFlag = atoi(arg); @@ -815,15 +824,20 @@ static int getTableRecordInfo( while ((row = taos_fetch_row(result)) != NULL) { isSet = true; - pTableRecordInfo->isStable = false; + pTableRecordInfo->isStb = false; tstrncpy(pTableRecordInfo->tableRecord.name, (char *)row[TSDB_SHOW_TABLES_NAME_INDEX], min(TSDB_TABLE_NAME_LEN, fields[TSDB_SHOW_TABLES_NAME_INDEX].bytes + 1)); - tstrncpy(pTableRecordInfo->tableRecord.stable, - (char *)row[TSDB_SHOW_TABLES_METRIC_INDEX], - min(TSDB_TABLE_NAME_LEN, - fields[TSDB_SHOW_TABLES_METRIC_INDEX].bytes + 1)); + if (strlen((char *)row[TSDB_SHOW_TABLES_METRIC_INDEX]) > 0) { + pTableRecordInfo->belongStb = true; + tstrncpy(pTableRecordInfo->tableRecord.stable, + (char *)row[TSDB_SHOW_TABLES_METRIC_INDEX], + min(TSDB_TABLE_NAME_LEN, + fields[TSDB_SHOW_TABLES_METRIC_INDEX].bytes + 1)); + } else { + pTableRecordInfo->belongStb = false; + } break; } @@ -848,7 +862,7 @@ static int getTableRecordInfo( while ((row = taos_fetch_row(result)) != NULL) { isSet = true; - pTableRecordInfo->isStable = true; + pTableRecordInfo->isStb = true; tstrncpy(pTableRecordInfo->tableRecord.stable, table, TSDB_TABLE_NAME_LEN); break; @@ -951,7 +965,66 @@ static int getDumpDbCount() return count; } -static int64_t dumpNormalTableWithoutStb(SDbInfo *dbInfo, char *ntbName) +static int convertSchemaToAvroSchema(STableDef *stableDes, char **avroSchema) +{ + errorPrint("%s() LN%d TODO: covert table schema to avro schema\n", + __func__, __LINE__); + return 0; +} + +static int64_t dumpNormalTable( + char *dbName, + char *stable, + char *tbName, + int precision, + FILE *fp + ) { + int colCount = 0; + + STableDef *tableDes = (STableDef *)calloc(1, sizeof(STableDef) + + sizeof(SColDes) * TSDB_MAX_COLUMNS); + + if (stable != NULL && stable[0] != '\0') { // dump table schema which is created by using super table + colCount = getTableDes(dbName, tbName, tableDes, false); + + if (colCount < 0) { + errorPrint("%s", "getTableDes() failed\n"); + free(tableDes); + return -1; + } + + // create child-table using super-table + dumpCreateMTableClause(tableDes, stable, colCount, fp, dbName); + } else { // dump table definition + colCount = getTableDes(dbName, tbName, tableDes, false); + + if (colCount < 0) { + free(tableDes); + return -1; + } + + // create normal-table or super-table + dumpCreateTableClause(tableDes, colCount, fp, dbName); + } + + char *jsonAvroSchema = NULL; + if (g_args.avro) { + convertSchemaToAvroSchema(tableDes, &jsonAvroSchema); + } + + free(tableDes); + + int64_t ret = 0; + if (!g_args.schemaonly) { + ret = dumpTableData(fp, tbName, dbName, precision, + jsonAvroSchema); + } + + return ret; +} + +static int64_t dumpNormalTableBelongStb( + SDbInfo *dbInfo, char *stbName, char *ntbName) { int64_t count = 0; @@ -973,21 +1046,47 @@ static int64_t dumpNormalTableWithoutStb(SDbInfo *dbInfo, char *ntbName) return -1; } - count = taosDumpTable(ntbName, NULL, - fp, dbInfo->name, getPrecisionByString(dbInfo->precision)); + count = dumpNormalTable( + dbInfo->name, + stbName, + ntbName, + getPrecisionByString(dbInfo->precision), + fp); fclose(fp); return count; } -static int64_t dumpNormalTable(FILE *fp, TAOS *taos, char *dbName, char *tbName, - char *stbName, - int precision) +static int64_t dumpNormalTableWithoutStb(SDbInfo *dbInfo, char *ntbName) { int64_t count = 0; - count = taosDumpTable(tbName, stbName, - fp, dbName, precision); + char tmpBuf[4096] = {0}; + FILE *fp = NULL; + + if (g_args.outpath[0] != 0) { + sprintf(tmpBuf, "%s/%s.%s.sql", + g_args.outpath, dbInfo->name, ntbName); + } else { + sprintf(tmpBuf, "%s.%s.sql", + dbInfo->name, ntbName); + } + + fp = fopen(tmpBuf, "w"); + if (fp == NULL) { + errorPrint("%s() LN%d, failed to open file %s\n", + __func__, __LINE__, tmpBuf); + return -1; + } + + count = dumpNormalTable( + dbInfo->name, + NULL, + ntbName, + getPrecisionByString(dbInfo->precision), + fp); + + fclose(fp); return count; } @@ -1021,12 +1120,12 @@ static void *dumpNtbOfDb(void *arg) { debugPrint("[%d] No.\t%"PRId64" table name: %s\n", pThreadInfo->threadIndex, i, ((TableInfo *)(g_tablesList + pThreadInfo->tableFrom+i))->name); - dumpNormalTable(fp, - pThreadInfo->taos, + dumpNormalTable( pThreadInfo->dbName, - ((TableInfo *)(g_tablesList + pThreadInfo->tableFrom+i))->name, ((TableInfo *)(g_tablesList + pThreadInfo->tableFrom+i))->stable, - pThreadInfo->precision); + ((TableInfo *)(g_tablesList + pThreadInfo->tableFrom+i))->name, + pThreadInfo->precision, + fp); } fclose(fp); @@ -1080,12 +1179,12 @@ static void *dumpNormalTablesOfStb(void *arg) { debugPrint("[%d] sub table %"PRId64": name: %s\n", pThreadInfo->threadIndex, i++, (char *)row[TSDB_SHOW_TABLES_NAME_INDEX]); - dumpNormalTable(fp, - pThreadInfo->taos, + dumpNormalTable( pThreadInfo->dbName, - (char *)row[TSDB_SHOW_TABLES_NAME_INDEX], pThreadInfo->stbName, - pThreadInfo->precision); + (char *)row[TSDB_SHOW_TABLES_NAME_INDEX], + pThreadInfo->precision, + fp); } fclose(fp); @@ -1300,7 +1399,7 @@ static int64_t dumpCreateSTableClauseOfDb( int64_t superTblCnt = 0; while ((row = taos_fetch_row(res)) != NULL) { - if (0 == dumpStable(row[TSDB_SHOW_TABLES_NAME_INDEX], fp, dbInfo)) { + if (0 == dumpStableClasuse(dbInfo, row[TSDB_SHOW_TABLES_NAME_INDEX], fp)) { superTblCnt ++; } } @@ -1382,7 +1481,7 @@ static int64_t dumpNTablesOfDb(SDbInfo *dbInfo) static int64_t dumpWholeDatabase(SDbInfo *dbInfo, FILE *fp) { - taosDumpCreateDbClause(dbInfo, g_args.with_property, fp); + dumpCreateDbClause(dbInfo, g_args.with_property, fp); fprintf(g_fpOfResult, "\n#### database: %s\n", dbInfo->name); @@ -1393,14 +1492,13 @@ static int64_t dumpWholeDatabase(SDbInfo *dbInfo, FILE *fp) return dumpNTablesOfDb(dbInfo); } -static int taosDumpOut() { +static int dumpOut() { TAOS *taos = NULL; TAOS_RES *result = NULL; TAOS_ROW row; FILE *fp = NULL; int32_t count = 0; - TableRecordInfo tableRecordInfo; char tmpBuf[4096] = {0}; if (g_args.outpath[0] != 0) { @@ -1446,7 +1544,7 @@ static int taosDumpOut() { /* --------------------------------- Main Code -------------------------------- */ /* if (g_args.databases || g_args.all_databases) { // dump part of databases or all databases */ /* */ - taosDumpCharset(fp); + dumpCharset(fp); sprintf(command, "show databases"); result = taos_query(taos, command); @@ -1568,11 +1666,13 @@ static int taosDumpOut() { g_totalDumpOutRows += records; } } else { - taosDumpCreateDbClause(g_dbInfos[0], g_args.with_property, fp); + dumpCreateDbClause(g_dbInfos[0], g_args.with_property, fp); } int superTblCnt = 0 ; for (int i = 1; g_args.arg_list[i]; i++) { + TableRecordInfo tableRecordInfo; + if (getTableRecordInfo(g_dbInfos[0]->name, g_args.arg_list[i], &tableRecordInfo) < 0) { @@ -1582,14 +1682,24 @@ static int taosDumpOut() { } int64_t records = 0; - if (tableRecordInfo.isStable) { // dump all table of this stable - int ret = dumpStable( + if (tableRecordInfo.isStb) { // dump all table of this stable + int ret = dumpStableClasuse( + g_dbInfos[0], tableRecordInfo.tableRecord.stable, - fp, g_dbInfos[0]); + fp); if (ret >= 0) { superTblCnt++; records = dumpNtbOfStbByThreads(g_dbInfos[0], g_args.arg_list[i]); } + } else if (tableRecordInfo.belongStb){ + dumpStableClasuse( + g_dbInfos[0], + tableRecordInfo.tableRecord.stable, + fp); + records = dumpNormalTableBelongStb( + g_dbInfos[0], + tableRecordInfo.tableRecord.stable, + g_args.arg_list[i]); } else { records = dumpNormalTableWithoutStb(g_dbInfos[0], g_args.arg_list[i]); } @@ -1781,74 +1891,7 @@ static int getTableDes( return colCount; } -static int convertSchemaToAvroSchema(STableDef *stableDes, char **avroSchema) -{ - errorPrint("%s() LN%d TODO: covert table schema to avro schema\n", - __func__, __LINE__); - return 0; -} - -static int64_t taosDumpTable( - char *tbName, char *stable, - FILE *fp, char* dbName, int precision) { - int colCount = 0; - - STableDef *tableDes = (STableDef *)calloc(1, sizeof(STableDef) - + sizeof(SColDes) * TSDB_MAX_COLUMNS); - - if (stable != NULL && stable[0] != '\0') { // dump table schema which is created by using super table - /* - colCount = getTableDes(stable, tableDes, taos); - - if (count < 0) { - free(tableDes); - return -1; - } - - dumpCreateTableClause(tableDes, count, fp); - - memset(tableDes, 0, sizeof(STableDef) + sizeof(SColDes) * TSDB_MAX_COLUMNS); - */ - - colCount = getTableDes(dbName, tbName, tableDes, false); - - if (colCount < 0) { - free(tableDes); - return -1; - } - - // create child-table using super-table - taosDumpCreateMTableClause(tableDes, stable, colCount, fp, dbName); - - } else { // dump table definition - colCount = getTableDes(dbName, tbName, tableDes, false); - - if (colCount < 0) { - free(tableDes); - return -1; - } - - // create normal-table or super-table - dumpCreateTableClause(tableDes, colCount, fp, dbName); - } - - char *jsonAvroSchema = NULL; - if (g_args.avro) { - convertSchemaToAvroSchema(tableDes, &jsonAvroSchema); - } - - free(tableDes); - - int64_t ret = 0; - if (!g_args.schemaonly) { - ret = dumpTableData(fp, tbName, dbName, precision, - jsonAvroSchema); - } - - return ret; -} - -static void taosDumpCreateDbClause( +static void dumpCreateDbClause( SDbInfo *dbInfo, bool isDumpProperty, FILE *fp) { char sqlstr[TSDB_MAX_SQL_LEN] = {0}; @@ -1870,7 +1913,7 @@ static void taosDumpCreateDbClause( fprintf(fp, "%s\n\n", sqlstr); } -static int dumpStable(char *stbName, FILE *fp, SDbInfo *dbInfo) +static int dumpStableClasuse(SDbInfo *dbInfo, char *stbName, FILE *fp) { uint64_t sizeOfTableDes = (uint64_t)(sizeof(STableDef) + sizeof(SColDes) * TSDB_MAX_COLUMNS); @@ -1949,7 +1992,7 @@ static int dumpCreateTableClause(STableDef *tableDes, int numOfCols, return fprintf(fp, "%s\n\n", sqlstr); } -static void taosDumpCreateMTableClause(STableDef *tableDes, char *stable, +static void dumpCreateMTableClause(STableDef *tableDes, char *stable, int numOfCols, FILE *fp, char* dbName) { int counter = 0; int count_temp = 0; @@ -2386,7 +2429,7 @@ static int convertNCharToReadable(char *str, int size, char *buf, int bufsize) { return 0; } -static void taosDumpCharset(FILE *fp) { +static void dumpCharset(FILE *fp) { char charsetline[256]; (void)fseek(fp, 0, SEEK_SET); @@ -2394,7 +2437,7 @@ static void taosDumpCharset(FILE *fp) { (void)fwrite(charsetline, strlen(charsetline), 1, fp); } -static void taosLoadFileCharset(FILE *fp, char *fcharset) { +static void loadFileCharset(FILE *fp, char *fcharset) { char * line = NULL; size_t line_size = 0; @@ -2526,7 +2569,7 @@ static void taosMallocDumpFiles() } } -static void taosFreeDumpFiles() +static void freeDumpFiles() { for (int i = 0; i < g_tsSqlFileNum; i++) { tfree(g_tsDumpInSqlFiles[i]); @@ -2594,7 +2637,7 @@ static FILE* taosOpenDumpInFile(char *fptr) { return f; } -static int taosDumpInOneFile(TAOS* taos, FILE* fp, char* fcharset, +static int dumpInOneFile(TAOS* taos, FILE* fp, char* fcharset, char* encode, char* fileName) { int read_len = 0; char * cmd = NULL; @@ -2651,7 +2694,7 @@ static int taosDumpInOneFile(TAOS* taos, FILE* fp, char* fcharset, return 0; } -static void* taosDumpInWorkThreadFp(void *arg) +static void* dumpInWorkThreadFp(void *arg) { threadInfo *pThread = (threadInfo*)arg; setThreadName("dumpInWorkThrd"); @@ -2665,14 +2708,14 @@ static void* taosDumpInWorkThreadFp(void *arg) } fprintf(stderr, ", Success Open input file: %s\n", SQLFileName); - taosDumpInOneFile(pThread->taos, fp, g_tsCharset, g_args.encode, SQLFileName); + dumpInOneFile(pThread->taos, fp, g_tsCharset, g_args.encode, SQLFileName); } } return NULL; } -static void taosStartDumpInWorkThreads() +static void startDumpInWorkThreads() { pthread_attr_t thattr; threadInfo *pThread; @@ -2704,7 +2747,7 @@ static void taosStartDumpInWorkThreads() pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); if (pthread_create(&(pThread->threadID), &thattr, - taosDumpInWorkThreadFp, (void*)pThread) != 0) { + dumpInWorkThreadFp, (void*)pThread) != 0) { errorPrint("%s() LN%d, thread:%d failed to start\n", __func__, __LINE__, pThread->threadIndex); exit(0); @@ -2721,7 +2764,7 @@ static void taosStartDumpInWorkThreads() free(threadObj); } -static int taosDumpIn() { +static int dumpIn() { assert(g_args.isDumpIn); TAOS *taos = NULL; @@ -2750,19 +2793,19 @@ static int taosDumpIn() { } fprintf(stderr, "Success Open input file: %s\n", g_tsDbSqlFile); - taosLoadFileCharset(fp, g_tsCharset); + loadFileCharset(fp, g_tsCharset); - taosDumpInOneFile(taos, fp, g_tsCharset, g_args.encode, + dumpInOneFile(taos, fp, g_tsCharset, g_args.encode, g_tsDbSqlFile); } taos_close(taos); if (0 != tsSqlFileNumOfTbls) { - taosStartDumpInWorkThreads(); + startDumpInWorkThreads(); } - taosFreeDumpFiles(); + freeDumpFiles(); return 0; } @@ -2883,7 +2926,7 @@ int main(int argc, char *argv[]) { fprintf(g_fpOfResult, "# DumpIn start time: %d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); - if (taosDumpIn() < 0) { + if (dumpIn() < 0) { ret = -1; } } else { @@ -2891,7 +2934,7 @@ int main(int argc, char *argv[]) { fprintf(g_fpOfResult, "# DumpOut start time: %d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); - if (taosDumpOut() < 0) { + if (dumpOut() < 0) { ret = -1; } else { fprintf(g_fpOfResult, "\n============================== TOTAL STATISTICS ============================== \n"); diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 320445f7f784884f8aa009e37182fc57a38bb96f..33f8c81a6d82f3573d15f74b7c24fe801d89a6a3 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -2,7 +2,11 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20) PROJECT(TDengine) ADD_SUBDIRECTORY(monitor) -ADD_SUBDIRECTORY(http) + +IF (TD_BUILD_HTTP) + ADD_SUBDIRECTORY(http) +ENDIF () + IF (TD_LINUX AND TD_MQTT) ADD_SUBDIRECTORY(mqtt) -ENDIF () \ No newline at end of file +ENDIF () diff --git a/tests/examples/c/makefile b/tests/examples/c/makefile index eee4e5d9b50d734232ffd4fc56a84451b59e504d..73f4ff43c175bf61ea19a8eacc6d70a06b302cb7 100644 --- a/tests/examples/c/makefile +++ b/tests/examples/c/makefile @@ -7,8 +7,7 @@ LFLAGS = '-Wl,-rpath,/usr/local/taos/driver/' -ltaos -lpthread -lm -lrt CFLAGS = -O3 -g -Wall -Wno-deprecated -fPIC -Wno-unused-result -Wconversion \ -Wno-char-subscripts -D_REENTRANT -Wno-format -D_REENTRANT -DLINUX \ -Wno-unused-function -D_M_X64 -I/usr/local/taos/include -std=gnu99 \ - -I../../../src/os/inc -I../../../src/inc \ - -I../../../src/util/inc -I../../../src/common/inc + -I../../../deps/cJson/inc all: $(TARGET) exe: @@ -18,12 +17,6 @@ exe: gcc $(CFLAGS) ./stream.c -o $(ROOT)stream $(LFLAGS) gcc $(CFLAGS) ./subscribe.c -o $(ROOT)subscribe $(LFLAGS) gcc $(CFLAGS) ./apitest.c -o $(ROOT)apitest $(LFLAGS) - gcc $(CFLAGS) ./clientcfgtest.c -o $(ROOT)clientcfgtest $(LFLAGS) - gcc $(CFLAGS) ./clientcfgtest-wrongtype.c -o $(ROOT)clientcfgtest-wrongtype $(LFLAGS) - gcc $(CFLAGS) ./clientcfgtest-wrongjson.c -o $(ROOT)clientcfgtest-wrongjson $(LFLAGS) - gcc $(CFLAGS) ./clientcfgtest-wrongvalue.c -o $(ROOT)clientcfgtest-wrongvalue $(LFLAGS) - gcc $(CFLAGS) ./clientcfgtest-taosd.c -o $(ROOT)clientcfgtest-taosd $(LFLAGS) - clean: rm $(ROOT)asyncdemo @@ -33,9 +26,7 @@ clean: rm $(ROOT)stream rm $(ROOT)subscribe rm $(ROOT)apitest - rm $(ROOT)clientcfgtest - rm $(ROOT)clientcfgtest-wrongtype - rm $(ROOT)clientcfgtest-wrongjson - rm $(ROOT)clientcfgtest-wrongvalue - rm $(ROOT)clientcfgtest-taosd + + + diff --git a/tests/gotest/batchtest.bat b/tests/gotest/batchtest.bat index 2a96ee31eb6211dbc5f300fbb2f3d62c03df3061..f9e6f83d50b1f1fa04cb18972376b3951447cc81 100755 --- a/tests/gotest/batchtest.bat +++ b/tests/gotest/batchtest.bat @@ -9,7 +9,7 @@ if "%severIp%"=="" (set severIp=127.0.0.1) if "%serverPort%"=="" (set serverPort=6030) go env -w GO111MODULE=on -go env -w GOPROXY=https://goproxy.io,direct +go env -w GOPROXY=https://goproxy.cn,direct cd case001 case001.bat %severIp% %serverPort% @@ -25,4 +25,4 @@ rem cd nanosupport rem nanoCase.bat :: cd nanosupport -:: nanoCase.bat \ No newline at end of file +:: nanoCase.bat diff --git a/tests/gotest/batchtest.sh b/tests/gotest/batchtest.sh index 503d77b226885b10e3874a3e0718789bed34b200..046249bcf7e8abab57d43b6b6e268361ccc1a695 100755 --- a/tests/gotest/batchtest.sh +++ b/tests/gotest/batchtest.sh @@ -14,7 +14,7 @@ if [ ! -n "$serverPort" ]; then fi go env -w GO111MODULE=on -go env -w GOPROXY=https://goproxy.io,direct +go env -w GOPROXY=https://goproxy.cn,direct bash ./case001/case001.sh $severIp $serverPort bash ./case002/case002.sh $severIp $serverPort diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index b8bb94b26d5117cb9e99468dfa94155ca70c4193..a7c375489aec74517f9bb92938b4179b6f9e5dc0 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -398,6 +398,7 @@ python3 ./test.py -f query/queryWildcardLength.py python3 ./test.py -f query/queryTbnameUpperLower.py python3 ./test.py -f query/query.py python3 ./test.py -f query/queryDiffColsOr.py +python3 ./test.py -f query/queryRegex.py #======================p4-end=============== diff --git a/tests/pytest/query/queryGroupbyWithInterval.py b/tests/pytest/query/queryGroupbyWithInterval.py index 14f6999021f23764bef95afdaa33cbcb695f2f55..d5474d069ab1af7a496515e23a46713d45f6262f 100644 --- a/tests/pytest/query/queryGroupbyWithInterval.py +++ b/tests/pytest/query/queryGroupbyWithInterval.py @@ -41,6 +41,14 @@ class TDTestCase: tdSql.execute( "insert into test22 using stest tags('test21','ccc') values ('2020-09-04 16:54:54.003',210,3)") + #2021-09-17 For jira: https://jira.taosdata.com:18080/browse/TD-6085 + tdSql.query("select last(size),appname from stest where tbname in ('test1','test2','test11')") + tdSql.checkRows(1) + + #2021-09-17 For jira: https://jira.taosdata.com:18080/browse/TD-6314 + tdSql.query("select _block_dist() from stest") + tdSql.checkRows(1) + tdSql.query("select sum(size) from stest interval(1d) group by appname") tdSql.checkRows(3) diff --git a/tests/pytest/query/queryRegex.py b/tests/pytest/query/queryRegex.py new file mode 100644 index 0000000000000000000000000000000000000000..25afa6395f62faeeac51bab73ed742626e4fba90 --- /dev/null +++ b/tests/pytest/query/queryRegex.py @@ -0,0 +1,74 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import taos +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql +from util.dnodes import tdDnodes + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def run(self): + tdSql.prepare() + print("==============step1") + ##2021-09-17 For jira: https://jira.taosdata.com:18080/browse/TD-6585 + tdSql.execute( + "create stable if not exists stb_test(ts timestamp,c0 binary(32)) tags(t0 binary(32))" + ) + tdSql.execute( + 'create table if not exists stb_1 using stb_test tags("abcdefgasdfg12346")' + ) + tdLog.info('insert into stb_1 values("2021-09-13 10:00:00.001","abcefdasdqwerxasdazx12345"') + tdSql.execute('insert into stb_1 values("2021-09-13 10:00:00.001","abcefdasdqwerxasdazx12345")') + + + tdSql.query('select * from stb_test where tbname match "asd"') + tdSql.checkRows(0) + + tdSql.query('select * from stb_test where tbname nmatch "asd"') + tdSql.checkRows(1) + + tdSql.query('select * from stb_test where c0 match "abc"') + tdSql.checkRows(1) + tdSql.checkData(0,1,"abcefdasdqwerxasdazx12345") + + tdSql.query('select * from stb_test where c0 nmatch "abc"') + tdSql.checkRows(0) + + tdSql.error('select * from stb_test where c0 match abc') + + tdSql.error('select * from stb_test where c0 nmatch abc') + + + tdSql.execute('insert into stb_1 values("2020-10-13 10:00:00.001","abcd\\\efgh")') + tdSql.query("select * from stb_1 where c0 match '\\\\'") + tdSql.checkRows(1) + + + + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/script/api/clientcfgtest.c b/tests/script/api/clientcfgtest.c new file mode 100644 index 0000000000000000000000000000000000000000..bfed93498ef51700cee3f56ca035868dcaaf90f2 --- /dev/null +++ b/tests/script/api/clientcfgtest.c @@ -0,0 +1,62 @@ +// The test case to verfy TS-293 +#include +#include +#include +#include +#include +#include "os.h" +#include "taosdef.h" +#include "taoserror.h" +#include "tconfig.h" +#include "tglobal.h" +#include "tulog.h" +#include "tsocket.h" +#include "tutil.h" +extern SGlobalCfg *taosGetConfigOption(const char *option) ; +int main( int argc, char *argv[]){ + + printf("start to test\n"); + + //case1: + //Test config firstEp success + const char config1[128] = "{\"firstEp\":\"BCC-2:6030\",\"debugFlag\":\"135\"}";//input the parameter which want to be configured + taos_set_config(config1); //configure the parameter + + SGlobalCfg *cfg ; + + cfg = taosGetConfigOption("firstEp");//check the option result + if(cfg->cfgStatus != 3){ //If cfgStatus is 3,it means configure is success + printf("config firstEp 'BCC-2:6030'failures!\n"); + exit(1); + } + + + cfg = taosGetConfigOption("debugFlag");//check the option result + if(cfg->cfgStatus != 3){ + printf("config debugFlag '135' failures!\n"); + exit(1); + } + + //case2: + //Test config only useful at the first time + //The result is failure + const char config2[128] = "{\"fqdn\":\"BCC-3\"}"; + taos_set_config(config2); //configure the parameter + + + cfg = taosGetConfigOption("fqdn");//check the option result + if(cfg->cfgStatus == 3){ + printf("config firstEp to 'BCC-3' failures!\n"); + exit(1); + } + else{ + printf("test case success!\n"); + exit(0); + } + + + return 0 ; + + + +} diff --git a/tests/script/api/makefile b/tests/script/api/makefile index 43613f6fe9327a2324f4b4a6b8c720c4b44d7139..2e599947f70787189f1bfee587b8d9171b8d6f2b 100644 --- a/tests/script/api/makefile +++ b/tests/script/api/makefile @@ -7,7 +7,10 @@ LFLAGS = '-Wl,-rpath,/usr/local/taos/driver/' -ltaos -lpthread -lm -lrt CFLAGS = -O0 -g -Wall -Wno-deprecated -fPIC -Wno-unused-result -Wconversion \ -Wno-char-subscripts -D_REENTRANT -Wno-format -D_REENTRANT -DLINUX \ -Wno-unused-function -D_M_X64 -I/usr/local/taos/include -std=gnu99 \ - -fsanitize=address -I../../../deps/cJson/inc + -I../../../deps/cJson/inc\ + -I../../../src/os/inc/ -I../../../src/inc -I../../../src/util/inc \ + -I../../../src/common/inc -I../../../deps/cJson/inc + all: $(TARGET) @@ -16,11 +19,19 @@ exe: gcc $(CFLAGS) ./stmtBatchTest.c -o $(ROOT)stmtBatchTest $(LFLAGS) gcc $(CFLAGS) ./stmtTest.c -o $(ROOT)stmtTest $(LFLAGS) gcc $(CFLAGS) ./stmt_function.c -o $(ROOT)stmt_function $(LFLAGS) + + gcc $(CFLAGS) ./clientcfgtest.c -o $(ROOT)clientcfgtest $(LFLAGS) + gcc $(CFLAGS) ./openTSDBTest.c -o $(ROOT)openTSDBTest $(LFLAGS) + clean: rm $(ROOT)batchprepare rm $(ROOT)stmtBatchTest rm $(ROOT)stmtTest rm $(ROOT)stmt_function + + rm $(ROOT)clientcfgtest + rm $(ROOT)openTSDBTest + diff --git a/tests/test-all.sh b/tests/test-all.sh index dfd7f49178ac3d9b4fc5437181a10e9f846aabcf..5eab3a9ed7469603a79c0df8bacaeec624c38a83 100755 --- a/tests/test-all.sh +++ b/tests/test-all.sh @@ -233,6 +233,7 @@ totalPyFailed=0 totalJDBCFailed=0 totalUnitFailed=0 totalExampleFailed=0 +totalApiFailed=0 if [ "${OS}" == "Linux" ]; then corepath=`grep -oP '.*(?=core_)' /proc/sys/kernel/core_pattern||grep -oP '.*(?=core-)' /proc/sys/kernel/core_pattern` @@ -532,7 +533,28 @@ if [ "$2" != "sim" ] && [ "$2" != "python" ] && [ "$2" != "jdbc" ] && [ "$2" != echo "demo pass" totalExamplePass=`expr $totalExamplePass + 1` fi + echo "### run setconfig tests ###" + + stopTaosd + + cd $tests_dir + echo "current dir: " + pwd + + cd script/api + echo "building setcfgtest" + make > /dev/null + ./clientcfgtest + if [ $? != "0" ]; then + echo "clientcfgtest failed" + totalExampleFailed=`expr $totalExampleFailed + 1` + else + echo "clientcfgtest pass" + totalExamplePass=`expr $totalExamplePass + 1` + fi + + if [ "$totalExamplePass" -gt "0" ]; then echo -e "\n${GREEN} ### Total $totalExamplePass examples succeed! ### ${NC}" fi @@ -544,7 +566,13 @@ if [ "$2" != "sim" ] && [ "$2" != "python" ] && [ "$2" != "jdbc" ] && [ "$2" != if [ "${OS}" == "Linux" ]; then dohavecore 1 fi + + + + + fi + exit $(($totalFailed + $totalPyFailed + $totalJDBCFailed + $totalUnitFailed + $totalExampleFailed))