diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 01172ae9c915090f50c830a131ea7c910deb0d30..a23ebdecfd527b55c72bc1e042b84de51b25885b 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -7,4 +7,4 @@ FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT} # [Optional] Uncomment this section to install additional packages. # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # && apt-get -y install --no-install-recommends -RUN apt-get update && apt-get -y install tree vim +RUN apt-get update && apt-get -y install tree vim tmux diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index cb05c84d722c69b3e42290aff1d2699081fb33d4..f9ad25e27512623d772f183a28c7abc59b127d11 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -32,7 +32,7 @@ // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "gcc -v", + "postCreateCommand": "wget https://raw.githubusercontent.com/hzcheng/config/master/.tmux.conf -P /root", // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "root" } \ No newline at end of file diff --git a/cmake/cmake.define b/cmake/cmake.define index 639ae9ca3fd780a98d18969400f7c214dca01485..53d25e10977f73716957ffded17c0409c6ac9865 100644 --- a/cmake/cmake.define +++ b/cmake/cmake.define @@ -1,5 +1,15 @@ cmake_minimum_required(VERSION 3.16) +if (NOT DEFINED TD_GRANT) + SET(TD_GRANT FALSE) +endif() +if (NOT DEFINED TD_USB_DONGLE) + SET(TD_USB_DONGLE FALSE) +endif() +IF (TD_GRANT) + ADD_DEFINITIONS(-D_GRANT) +ENDIF () + IF ("${BUILD_TOOLS}" STREQUAL "") IF (TD_LINUX) IF (TD_ARM_32) @@ -36,16 +46,20 @@ IF (TD_WINDOWS) ENDIF () ELSE () - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") - #SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3") - #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3") - -MESSAGE("System processor ID: ${CMAKE_SYSTEM_PROCESSOR}") -IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") - ADD_DEFINITIONS("-D_TD_ARM_") -ELSE () - ADD_DEFINITIONS("-msse4.2 -mfma") -ENDIF () + IF (${SANITIZER} MATCHES "true") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3") + MESSAGE(STATUS "Will compile with Address Sanitizer!") + ELSE () + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") + ENDIF () + + MESSAGE("System processor ID: ${CMAKE_SYSTEM_PROCESSOR}") + IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") + ADD_DEFINITIONS("-D_TD_ARM_") + ELSE () + ADD_DEFINITIONS("-msse4.2 -mfma") + ENDIF () ENDIF () diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index acb99caffc5b6ab48fb9fdffc237bf1749d5a869..54bb83d244a3a2398db36985176dcc17ce9729ba 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -1,5 +1,6 @@ add_executable(tmq "") add_executable(tstream "") +add_executable(demoapi "") target_sources(tmq PRIVATE @@ -10,6 +11,12 @@ target_sources(tstream PRIVATE "src/tstream.c" ) + +target_sources(demoapi + PRIVATE + "src/demoapi.c" +) + target_link_libraries(tmq taos ) @@ -18,6 +25,10 @@ target_link_libraries(tstream taos ) +target_link_libraries(demoapi + taos +) + target_include_directories(tmq PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) @@ -26,5 +37,11 @@ target_include_directories(tstream PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) +target_include_directories(demoapi + PUBLIC "${TD_SOURCE_DIR}/include/client" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) + SET_TARGET_PROPERTIES(tmq PROPERTIES OUTPUT_NAME tmq) SET_TARGET_PROPERTIES(tstream PROPERTIES OUTPUT_NAME tstream) +SET_TARGET_PROPERTIES(demoapi PROPERTIES OUTPUT_NAME demoapi) diff --git a/example/src/demoapi.c b/example/src/demoapi.c new file mode 100644 index 0000000000000000000000000000000000000000..b1efdb21b961da2046906f269fc63527ce45f710 --- /dev/null +++ b/example/src/demoapi.c @@ -0,0 +1,214 @@ +// C api call sequence demo +// to compile: gcc -o apidemo apidemo.c -ltaos + +#include +#include +#include +#include +#include +#include + +#include "taos.h" + +#define debugPrint(fmt, ...) \ + do { if (g_args.debug_print || g_args.verbose_print) \ + fprintf(stdout, "DEBG: "fmt, __VA_ARGS__); } while(0) + +#define warnPrint(fmt, ...) \ + do { fprintf(stderr, "\033[33m"); \ + fprintf(stderr, "WARN: "fmt, __VA_ARGS__); \ + fprintf(stderr, "\033[0m"); } while(0) + +#define errorPrint(fmt, ...) \ + do { fprintf(stderr, "\033[31m"); \ + fprintf(stderr, "ERROR: "fmt, __VA_ARGS__); \ + fprintf(stderr, "\033[0m"); } while(0) + +#define okPrint(fmt, ...) \ + do { fprintf(stderr, "\033[32m"); \ + fprintf(stderr, "OK: "fmt, __VA_ARGS__); \ + fprintf(stderr, "\033[0m"); } while(0) + +int64_t g_num_of_tb = 2; +int64_t g_num_of_rec = 2; + +static struct argp_option options[] = { + {"tables", 't', "NUMBER", 0, "Number of child tables, default is 10000."}, + {"records", 'n', "NUMBER", 0, + "Number of records for each table, default is 10000."}, + {0}}; + +static error_t parse_opt(int key, char *arg, struct argp_state *state) { + switch (key) { + case 't': + g_num_of_tb = atoll(arg); + break; + + case 'n': + g_num_of_rec = atoll(arg); + break; + } + + return 0; +} + +static struct argp argp = {options, parse_opt, "", ""}; + +static void prepare_data(TAOS* taos) { + TAOS_RES *res; + res = taos_query(taos, "drop database if exists test;"); + taos_free_result(res); + usleep(100000); + + res = taos_query(taos, "create database test;"); + taos_free_result(res); + usleep(100000); + taos_select_db(taos, "test"); + + res = taos_query(taos, "create table meters(ts timestamp, f float, n int, b binary(20), c nchar(20)) tags(area int, city binary(20), dist nchar(20));"); + taos_free_result(res); + + char command[1024] = {0}; + for (int64_t i = 0; i < g_num_of_tb; i ++) { +// sprintf(command, "create table t%"PRId64" using meters tags(%"PRId64", '%s', '%s');", +// i, i, (i%2)?"beijing":"shanghai", (i%2)?"朝阳区":"黄浦区"); + sprintf(command, "create table t%"PRId64" using meters tags(%"PRId64", '%s', '%s');", + i, i, (i%2)?"beijing":"shanghai", (i%2)?"chaoyang":"huangpu"); + res = taos_query(taos, command); + if ((res) && (0 == taos_errno(res))) { + okPrint("t%" PRId64 " created\n", i); + } else { + errorPrint("%s() LN%d: %s\n", + __func__, __LINE__, taos_errstr(res)); + } + taos_free_result(res); + + int64_t j = 0; + int64_t total = 0; + int64_t affected; + for (; j < g_num_of_rec -1; j ++) { + sprintf(command, "insert into t%"PRId64" " + "values(%" PRId64 ", %f, %"PRId64", '%c%d', '%c%d')", + i, 1650000000000+j, (float)j, j, 'a'+(int)j%25, rand(), + 'z' - (int)j%25, rand()); + res = taos_query(taos, command); + if ((res) && (0 == taos_errno(res))) { + affected = taos_affected_rows(res); + total += affected; + } else { + errorPrint("%s() LN%d: %s\n", + __func__, __LINE__, taos_errstr(res)); + } + taos_free_result(res); + } + sprintf(command, "insert into t%"PRId64" values(%" PRId64 ", NULL, NULL, NULL, NULL)", + i, 1650000000000+j+1); + res = taos_query(taos, command); + if ((res) && (0 == taos_errno(res))) { + affected = taos_affected_rows(res); + total += affected; + } else { + errorPrint("%s() LN%d: %s\n", + __func__, __LINE__, taos_errstr(res)); + } + taos_free_result(res); + + printf("insert %"PRId64" records into t%"PRId64", total affected rows: %"PRId64"\n", j, i, total); + } +} + +static int print_result(char *tbname, TAOS_RES* res, int block) { + int64_t num_rows = 0; + TAOS_ROW row = NULL; + int num_fields = taos_num_fields(res); + TAOS_FIELD* fields = taos_fetch_fields(res); + + for (int f = 0; f < num_fields; f++) { + printf("fields[%d].name=%s, fields[%d].type=%d, fields[%d].bytes=%d\n", + f, fields[f].name, f, fields[f].type, f, fields[f].bytes); + } + if (block) { + warnPrint("%s() LN%d, call taos_fetch_block()\n", __func__, __LINE__); + int rows = 0; + while ((rows = taos_fetch_block(res, &row))) { + num_rows += rows; + } + } else { + warnPrint("%s() LN%d, call taos_fetch_rows()\n", __func__, __LINE__); + while ((row = taos_fetch_row(res))) { + char temp[256] = {0}; + taos_print_row(temp, row, fields, num_fields); + puts(temp); + num_rows ++; + + int* lengths = taos_fetch_lengths(res); + if (lengths) { + for (int c = 0; c < num_fields; c++) { + printf("length of column %d is %d\n", c, lengths[c]); + } + } else { + errorPrint("%s() LN%d: %s's lengths is NULL\n", + __func__, __LINE__, tbname); + } + } + } + + return num_rows; +} + +static void verify_query(TAOS* taos) { + // TODO: select count(tbname) from stable once stable query work + // + char tbname[193] = {0}; + char command[1024] = {0}; + + for (int64_t i = 0; i < g_num_of_tb; i++) { + sprintf(tbname, "t%"PRId64"", i); + sprintf(command, "select * from %s", tbname); + TAOS_RES* res = taos_query(taos, command); + + if (res) { + if (0 == taos_errno(res)) { + int field_count = taos_field_count(res); + printf("field_count: %d\n", field_count); + int64_t rows = print_result(tbname, res, i % 2); + printf("rows is: %"PRId64"\n", rows); + + } else { + errorPrint("%s() LN%d: %s\n", + __func__, __LINE__, taos_errstr(res)); + } + } else { + errorPrint("%s() LN%d: %s\n", + __func__, __LINE__, taos_errstr(res)); + } + } +} + +int main(int argc, char *argv[]) { + const char* host = "127.0.0.1"; + const char* user = "root"; + const char* passwd = "taosdata"; + + argp_parse(&argp, argc, argv, 0, 0, NULL); + TAOS* taos = taos_connect(host, user, passwd, "", 0); + if (taos == NULL) { + printf("\033[31mfailed to connect to db, reason:%s\033[0m\n", taos_errstr(taos)); + exit(1); + } + + const char* info = taos_get_server_info(taos); + printf("server info: %s\n", info); + info = taos_get_client_info(taos); + printf("client info: %s\n", info); + + prepare_data(taos); + + verify_query(taos); + + taos_close(taos); + printf("done\n"); + + return 0; +} + diff --git a/example/src/tmq.c b/example/src/tmq.c index efb4d1830eb81e36f5066dacdff5d954ea2793b7..fdd26bc95db32f04823887e006acca138f36bfaa 100644 --- a/example/src/tmq.c +++ b/example/src/tmq.c @@ -20,7 +20,19 @@ #include "taos.h" static int running = 1; -static void msg_process(tmq_message_t* message) { tmqShowMsg(message); } +static void msg_process(TAOS_RES* msg) { + char buf[1024]; + printf("topic: %s\n", tmq_get_topic_name(msg)); + printf("vg:%d\n", tmq_get_vgroup_id(msg)); + while (1) { + TAOS_ROW row = taos_fetch_row(msg); + if (row == NULL) break; + TAOS_FIELD* fields = taos_fetch_fields(msg); + int32_t numOfFields = taos_field_count(msg); + taos_print_row(buf, row, fields, numOfFields); + printf("%s\n", buf); + } +} int32_t init_env() { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -90,7 +102,7 @@ int32_t create_topic() { /*const char* sql = "select * from tu1";*/ /*pRes = tmq_create_topic(pConn, "test_stb_topic_1", sql, strlen(sql));*/ - pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1 from ct1"); + pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1, c2, c3 from ct1"); if (taos_errno(pRes) != 0) { printf("failed to create topic topic_ctb_column, reason:%s\n", taos_errstr(pRes)); return -1; @@ -133,6 +145,7 @@ void tmq_commit_cb_print(tmq_t* tmq, tmq_resp_err_t resp, tmq_topic_vgroup_list_ } tmq_t* build_consumer() { +#if 0 TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); assert(pConn != NULL); @@ -141,11 +154,15 @@ tmq_t* build_consumer() { printf("error in use db, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); +#endif tmq_conf_t* conf = tmq_conf_new(); tmq_conf_set(conf, "group.id", "tg2"); + tmq_conf_set(conf, "td.connect.user", "root"); + tmq_conf_set(conf, "td.connect.pass", "taosdata"); + tmq_conf_set(conf, "td.connect.db", "abc1"); tmq_conf_set_offset_commit_cb(conf, tmq_commit_cb_print); - tmq_t* tmq = tmq_consumer_new(pConn, conf, NULL, 0); + tmq_t* tmq = tmq_consumer_new1(conf, NULL, 0); return tmq; } @@ -163,13 +180,14 @@ void basic_consume_loop(tmq_t* tmq, tmq_list_t* topics) { printf("subscribe err\n"); return; } - /*int32_t cnt = 0;*/ + int32_t cnt = 0; /*clock_t startTime = clock();*/ while (running) { - tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 500); + TAOS_RES* tmqmessage = tmq_consumer_poll(tmq, 500); if (tmqmessage) { - /*cnt++;*/ - msg_process(tmqmessage); + cnt++; + /*printf("get data\n");*/ + /*msg_process(tmqmessage);*/ tmq_message_destroy(tmqmessage); /*} else {*/ /*break;*/ @@ -197,7 +215,7 @@ void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) { } while (running) { - tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 1000); + TAOS_RES* tmqmessage = tmq_consumer_poll(tmq, 1000); if (tmqmessage) { msg_process(tmqmessage); tmq_message_destroy(tmqmessage); @@ -225,10 +243,10 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics) { int32_t skipLogNum = 0; clock_t startTime = clock(); while (running) { - tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 500); + TAOS_RES* tmqmessage = tmq_consumer_poll(tmq, 500); if (tmqmessage) { batchCnt++; - skipLogNum += tmqGetSkipLogNum(tmqmessage); + /*skipLogNum += tmqGetSkipLogNum(tmqmessage);*/ /*msg_process(tmqmessage);*/ tmq_message_destroy(tmqmessage); } else { diff --git a/include/client/taos.h b/include/client/taos.h index d3856d432e76a5a9667b0b22f5710509b0c01ba8..218090363305fb7bbcb1cc2fa1627e4afb89bf12 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -30,7 +30,7 @@ typedef void **TAOS_ROW; #if 0 typedef void TAOS_STREAM; #endif -typedef void TAOS_SUB; +typedef void TAOS_SUB; // Data type definition #define TSDB_DATA_TYPE_NULL 0 // 1 bytes @@ -138,13 +138,13 @@ typedef enum { #define RET_MSG_LENGTH 1024 typedef struct setConfRet { SET_CONF_RET_CODE retCode; - char retMsg[RET_MSG_LENGTH]; + char retMsg[RET_MSG_LENGTH]; } setConfRet; -DLL_EXPORT void taos_cleanup(void); -DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); -DLL_EXPORT setConfRet taos_set_config(const char *config); -DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); +DLL_EXPORT void taos_cleanup(void); +DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); +DLL_EXPORT setConfRet taos_set_config(const char *config); +DLL_EXPORT TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port); DLL_EXPORT TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, const char *pass, int passLen, const char *db, int dbLen, uint16_t port); DLL_EXPORT TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port); @@ -152,34 +152,34 @@ DLL_EXPORT void taos_close(TAOS *taos); const char *taos_data_type(int type); -DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos); -DLL_EXPORT int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length); -DLL_EXPORT int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_BIND *tags); -DLL_EXPORT int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name); -DLL_EXPORT int taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name); - -DLL_EXPORT int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert); -DLL_EXPORT int taos_stmt_num_params(TAOS_STMT *stmt, int *nums); -DLL_EXPORT int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes); -DLL_EXPORT int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND *bind); -DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind); -DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int colIdx); -DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt); -DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt); -DLL_EXPORT TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt); -DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt); -DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt); -DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt); - -DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql); -DLL_EXPORT TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen); - -DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res); -DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result -DLL_EXPORT void taos_free_result(TAOS_RES *res); -DLL_EXPORT int taos_field_count(TAOS_RES *res); -DLL_EXPORT int taos_num_fields(TAOS_RES *res); -DLL_EXPORT int taos_affected_rows(TAOS_RES *res); +DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos); +DLL_EXPORT int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length); +DLL_EXPORT int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_BIND *tags); +DLL_EXPORT int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name); +DLL_EXPORT int taos_stmt_set_sub_tbname(TAOS_STMT *stmt, const char *name); + +DLL_EXPORT int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert); +DLL_EXPORT int taos_stmt_num_params(TAOS_STMT *stmt, int *nums); +DLL_EXPORT int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes); +DLL_EXPORT int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND *bind); +DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind); +DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int colIdx); +DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt); +DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt); +DLL_EXPORT TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt); +DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt); +DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt); +DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt); + +DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql); +DLL_EXPORT TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen); + +DLL_EXPORT TAOS_ROW taos_fetch_row(TAOS_RES *res); +DLL_EXPORT int taos_result_precision(TAOS_RES *res); // get the time precision of result +DLL_EXPORT void taos_free_result(TAOS_RES *res); +DLL_EXPORT int taos_field_count(TAOS_RES *res); +DLL_EXPORT int taos_num_fields(TAOS_RES *res); +DLL_EXPORT int taos_affected_rows(TAOS_RES *res); DLL_EXPORT TAOS_FIELD *taos_fetch_fields(TAOS_RES *res); DLL_EXPORT int taos_select_db(TAOS *taos, const char *db); @@ -188,14 +188,14 @@ DLL_EXPORT void taos_stop_query(TAOS_RES *res); DLL_EXPORT bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col); DLL_EXPORT bool taos_is_update_query(TAOS_RES *res); DLL_EXPORT int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows); -DLL_EXPORT int taos_fetch_block_s(TAOS_RES *res, int* numOfRows, TAOS_ROW *rows); -DLL_EXPORT int taos_fetch_raw_block(TAOS_RES *res, int* numOfRows, void** pData); +DLL_EXPORT int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows); +DLL_EXPORT int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData); DLL_EXPORT int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex); DLL_EXPORT int taos_validate_sql(TAOS *taos, const char *sql); DLL_EXPORT void taos_reset_current_db(TAOS *taos); -DLL_EXPORT int *taos_fetch_lengths(TAOS_RES *res); -DLL_EXPORT TAOS_ROW *taos_result_block(TAOS_RES *res); +DLL_EXPORT int *taos_fetch_lengths(TAOS_RES *res); +DLL_EXPORT TAOS_ROW *taos_result_block(TAOS_RES *res); DLL_EXPORT const char *taos_get_server_info(TAOS *taos); DLL_EXPORT const char *taos_get_client_info(); @@ -237,9 +237,9 @@ typedef struct tmq_t tmq_t; typedef struct tmq_topic_vgroup_t tmq_topic_vgroup_t; typedef struct tmq_topic_vgroup_list_t tmq_topic_vgroup_list_t; -typedef struct tmq_conf_t tmq_conf_t; -typedef struct tmq_list_t tmq_list_t; -typedef struct tmq_message_t tmq_message_t; +typedef struct tmq_conf_t tmq_conf_t; +typedef struct tmq_list_t tmq_list_t; +// typedef struct tmq_message_t tmq_message_t; typedef void(tmq_commit_cb(tmq_t *, tmq_resp_err_t, tmq_topic_vgroup_list_t *, void *param)); @@ -247,10 +247,10 @@ DLL_EXPORT tmq_list_t *tmq_list_new(); DLL_EXPORT int32_t tmq_list_append(tmq_list_t *, const char *); DLL_EXPORT void tmq_list_destroy(tmq_list_t *); -// will be removed in 3.0 +#if 1 DLL_EXPORT tmq_t *tmq_consumer_new(void *conn, tmq_conf_t *conf, char *errstr, int32_t errstrLen); +#endif -// will replace last one DLL_EXPORT tmq_t *tmq_consumer_new1(tmq_conf_t *conf, char *errstr, int32_t errstrLen); DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t); @@ -259,7 +259,7 @@ DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t); DLL_EXPORT tmq_resp_err_t tmq_subscribe(tmq_t *tmq, tmq_list_t *topic_list); DLL_EXPORT tmq_resp_err_t tmq_unsubscribe(tmq_t *tmq); DLL_EXPORT tmq_resp_err_t tmq_subscription(tmq_t *tmq, tmq_list_t **topics); -DLL_EXPORT tmq_message_t *tmq_consumer_poll(tmq_t *tmq, int64_t blocking_time); +DLL_EXPORT TAOS_RES *tmq_consumer_poll(tmq_t *tmq, int64_t blocking_time); DLL_EXPORT tmq_resp_err_t tmq_consumer_close(tmq_t *tmq); #if 0 DLL_EXPORT tmq_resp_err_t tmq_assign(tmq_t* tmq, const tmq_topic_vgroup_list_t* vgroups); @@ -268,8 +268,8 @@ DLL_EXPORT tmq_resp_err_t tmq_assignment(tmq_t* tmq, tmq_topic_vgroup_list_t** v DLL_EXPORT tmq_resp_err_t tmq_commit(tmq_t *tmq, const tmq_topic_vgroup_list_t *offsets, int32_t async); #if 0 DLL_EXPORT tmq_resp_err_t tmq_commit_message(tmq_t* tmq, const tmq_message_t* tmqmessage, int32_t async); -#endif DLL_EXPORT tmq_resp_err_t tmq_seek(tmq_t *tmq, const tmq_topic_vgroup_t *offset); +#endif /* ----------------------TMQ CONFIGURATION INTERFACE---------------------- */ enum tmq_conf_res_t { @@ -285,21 +285,24 @@ DLL_EXPORT tmq_conf_res_t tmq_conf_set(tmq_conf_t *conf, const char *key, const DLL_EXPORT void tmq_conf_destroy(tmq_conf_t *conf); DLL_EXPORT void tmq_conf_set_offset_commit_cb(tmq_conf_t *conf, tmq_commit_cb *cb); +#if 0 // temporary used function for demo only void tmqShowMsg(tmq_message_t *tmq_message); int32_t tmqGetSkipLogNum(tmq_message_t *tmq_message); +#endif /* -------------------------TMQ MSG HANDLE INTERFACE---------------------- */ +DLL_EXPORT char *tmq_get_topic_name(TAOS_RES *res); +DLL_EXPORT int32_t tmq_get_vgroup_id(TAOS_RES *res); +#if 0 DLL_EXPORT TAOS_ROW tmq_get_row(tmq_message_t *message); -DLL_EXPORT char *tmq_get_topic_name(tmq_message_t *message); -DLL_EXPORT int32_t tmq_get_vgroup_id(tmq_message_t *message); DLL_EXPORT int64_t tmq_get_request_offset(tmq_message_t *message); DLL_EXPORT int64_t tmq_get_response_offset(tmq_message_t *message); DLL_EXPORT TAOS_FIELD *tmq_get_fields(tmq_t *tmq, const char *topic); DLL_EXPORT int32_t tmq_field_count(tmq_t *tmq, const char *topic); -DLL_EXPORT void tmq_message_destroy(tmq_message_t *tmq_message); - +#endif +DLL_EXPORT void tmq_message_destroy(TAOS_RES *res); /* --------------------TMPORARY INTERFACE FOR TESTING--------------------- */ #if 0 DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS *taos, const char *name, const char *sql, int sqlLen); @@ -308,7 +311,7 @@ DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS *taos, const char *name, const char * DLL_EXPORT TAOS_RES *tmq_create_stream(TAOS *taos, const char *streamName, const char *tbName, const char *sql); /* ------------------------------ TMQ END -------------------------------- */ -#if 1 // Shuduo: temporary enable for app build +#if 1 // Shuduo: temporary enable for app build typedef void (*TAOS_SUBSCRIBE_CALLBACK)(TAOS_SUB *tsub, TAOS_RES *res, void *param, int code); #endif diff --git a/include/common/taosdef.h b/include/common/taosdef.h index 5001a99c2a2cca535ccea1231599044e12733efb..6e344dfdb4422456b745c66e85a4f5f27800b4e0 100644 --- a/include/common/taosdef.h +++ b/include/common/taosdef.h @@ -57,6 +57,8 @@ typedef enum { TD_ROW_PARTIAL_UPDATE = 2, } TDUpdateConfig; +#define TD_SUPPORT_UPDATE(u) ((u) > 0) + typedef enum { TSDB_STATIS_OK = 0, // statis part exist and load successfully TSDB_STATIS_NONE = 1, // statis part not exist diff --git a/include/common/tcommon.h b/include/common/tcommon.h index 1040130f769bd0d852663f0e19f85b32b4c26a06..7c308f9354ff38f7e4bd699de3aa61e0bbc786a8 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -222,7 +222,7 @@ typedef struct SFunctParam { // the structure for sql function in select clause typedef struct SResSchame { int8_t type; - int32_t colId; + int32_t slotId; int32_t bytes; int32_t precision; int32_t scale; diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index b2b8cff19a8b6ddb45c5ab3785bd97c2a506d2d6..15f3246013c5d289aa6689d55de162c435153344 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -136,7 +136,8 @@ static FORCE_INLINE void colDataAppendInt8(SColumnInfoData* pColumnInfoData, uin } static FORCE_INLINE void colDataAppendInt16(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int16_t* v) { - ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_SMALLINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_USMALLINT); + ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_SMALLINT || + pColumnInfoData->info.type == TSDB_DATA_TYPE_USMALLINT); char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow; *(int16_t*)p = *(int16_t*)v; } @@ -198,27 +199,30 @@ int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullF int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, uint32_t numOfRows); int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows); -void colInfoDataCleanup(SColumnInfoData* pColumn, uint32_t numOfRows); -void blockDataCleanup(SSDataBlock* pDataBlock); +void colInfoDataCleanup(SColumnInfoData* pColumn, uint32_t numOfRows); +void blockDataCleanup(SSDataBlock* pDataBlock); -size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize); -void* blockDataDestroy(SSDataBlock* pBlock); +size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize); int32_t blockDataTrimFirstNRows(SSDataBlock* pBlock, size_t n); -SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock); +SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData); void blockDebugShowData(const SArray* dataBlocks); +static FORCE_INLINE int32_t blockGetEncodeSize(const SSDataBlock* pBlock) { + return blockDataGetSerialMetaSize(pBlock) + blockDataGetSize(pBlock); +} + static FORCE_INLINE int32_t blockCompressColData(SColumnInfoData* pColRes, int32_t numOfRows, char* data, - int8_t compressed) { + int8_t compressed) { int32_t colSize = colDataGetLength(pColRes, numOfRows); return (*(tDataTypes[pColRes->info.type].compFunc))(pColRes->pData, colSize, numOfRows, data, colSize + COMP_OVERFLOW_BYTES, compressed, NULL, 0); } static FORCE_INLINE void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols, - int8_t needCompress) { + int8_t needCompress) { int32_t* colSizes = (int32_t*)data; data += numOfCols * sizeof(int32_t); diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 8e07d4e6699a87142568d8073ec3801caf7e3fde..8a87a1bd2eb3670e34ecdb24c711c2b0c904e9b1 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -482,7 +482,7 @@ void tdResetDataCols(SDataCols *pCols); int32_t tdInitDataCols(SDataCols *pCols, STSchema *pSchema); SDataCols *tdDupDataCols(SDataCols *pCols, bool keepData); SDataCols *tdFreeDataCols(SDataCols *pCols); -int32_t tdMergeDataCols(SDataCols *target, SDataCols *source, int32_t rowsToMerge, int32_t *pOffset, bool forceSetNull); +int32_t tdMergeDataCols(SDataCols *target, SDataCols *source, int32_t rowsToMerge, int32_t *pOffset, bool forceSetNull, TDRowVerT maxVer); // ----------------- K-V data row structure /* |<-------------------------------------- len -------------------------------------------->| diff --git a/include/common/tglobal.h b/include/common/tglobal.h index f03943e1053dd1cc8834afa6fa0823ce62443c7e..5022cb7be80773460f42844af10cc17290de658b 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -18,6 +18,7 @@ #include "tarray.h" #include "tdef.h" +#include "tconfig.h" #ifdef __cplusplus extern "C" { @@ -129,6 +130,7 @@ void taosCfgDynamicOptions(const char *option, const char *value); void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary); struct SConfig *taosGetCfg(); +int32_t taosAddClientLogCfg(SConfig *pCfg); #ifdef __cplusplus } diff --git a/include/common/tmsg.h b/include/common/tmsg.h index ba9147dcdd95426fcbcb2883cbcdbbd6d6cce3de..8686d91a101880f86da1e1a20a6b9bbca9ce03b2 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -86,30 +86,31 @@ enum { typedef enum _mgmt_table { TSDB_MGMT_TABLE_START, - TSDB_MGMT_TABLE_ACCT, - TSDB_MGMT_TABLE_USER, - TSDB_MGMT_TABLE_DB, - TSDB_MGMT_TABLE_TABLE, TSDB_MGMT_TABLE_DNODE, TSDB_MGMT_TABLE_MNODE, + TSDB_MGMT_TABLE_MODULE, TSDB_MGMT_TABLE_QNODE, TSDB_MGMT_TABLE_SNODE, TSDB_MGMT_TABLE_BNODE, - TSDB_MGMT_TABLE_VGROUP, + TSDB_MGMT_TABLE_CLUSTER, + TSDB_MGMT_TABLE_DB, + TSDB_MGMT_TABLE_FUNC, + TSDB_MGMT_TABLE_INDEX, TSDB_MGMT_TABLE_STB, - TSDB_MGMT_TABLE_MODULE, - TSDB_MGMT_TABLE_QUERIES, TSDB_MGMT_TABLE_STREAMS, - TSDB_MGMT_TABLE_VARIABLES, - TSDB_MGMT_TABLE_CONNS, - TSDB_MGMT_TABLE_TRANS, + TSDB_MGMT_TABLE_TABLE, + TSDB_MGMT_TABLE_USER, TSDB_MGMT_TABLE_GRANTS, + TSDB_MGMT_TABLE_VGROUP, + TSDB_MGMT_TABLE_TOPICS, + TSDB_MGMT_TABLE_CONSUMERS, + TSDB_MGMT_TABLE_SUBSCRIBES, + TSDB_MGMT_TABLE_TRANS, + TSDB_MGMT_TABLE_SMAS, + TSDB_MGMT_TABLE_CONFIGS, + TSDB_MGMT_TABLE_CONNS, + TSDB_MGMT_TABLE_QUERIES, TSDB_MGMT_TABLE_VNODES, - TSDB_MGMT_TABLE_CLUSTER, - TSDB_MGMT_TABLE_STREAMTABLES, - TSDB_MGMT_TABLE_TP, - TSDB_MGMT_TABLE_FUNC, - TSDB_MGMT_TABLE_INDEX, TSDB_MGMT_TABLE_MAX, } EShowType; @@ -260,6 +261,7 @@ typedef struct { typedef struct SSchema { int8_t type; + int8_t index; // default is 0, not index created col_id_t colId; int32_t bytes; char name[TSDB_COL_NAME_LEN]; @@ -331,6 +333,7 @@ int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp); void* taosDecodeSEpSet(void* buf, SEpSet* pEp); typedef struct { + int8_t connType; int32_t pid; char app[TSDB_APP_NAME_LEN]; char db[TSDB_DB_NAME_LEN]; @@ -345,6 +348,7 @@ typedef struct { int64_t clusterId; int32_t connId; int8_t superUser; + int8_t connType; SEpSet epSet; char sVersion[128]; } SConnectRsp; @@ -360,7 +364,7 @@ typedef struct { int32_t maxTimeSeries; int32_t maxStreams; int32_t accessState; // Configured only by command - int64_t maxStorage; // In unit of GB + int64_t maxStorage; } SCreateAcctReq, SAlterAcctReq; int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq); @@ -484,7 +488,7 @@ typedef struct { char intervalUnit; char slidingUnit; char - offsetUnit; // TODO Remove it, the offset is the number of precision tickle, and it must be a immutable duration. + offsetUnit; // TODO Remove it, the offset is the number of precision tickle, and it must be a immutable duration. int8_t precision; int64_t interval; int64_t sliding; @@ -744,8 +748,8 @@ typedef struct { } SVnodeLoad; typedef struct { - int32_t sver; // software version - int64_t dver; // dnode table version in sdb + int32_t sver; // software version + int64_t dnodeVer; // dnode table version in sdb int32_t dnodeId; int64_t clusterId; int64_t rebootTime; @@ -759,6 +763,7 @@ typedef struct { int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq); int32_t tDeserializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq); +void tFreeSStatusReq(SStatusReq* pReq); typedef struct { int32_t dnodeId; @@ -772,7 +777,7 @@ typedef struct { } SDnodeEp; typedef struct { - int64_t dver; + int64_t dnodeVer; SDnodeCfg dnodeCfg; SArray* pDnodeEps; // Array of SDnodeEp } SStatusRsp; @@ -952,9 +957,14 @@ typedef struct { char db[TSDB_DB_FNAME_LEN]; char tb[TSDB_TABLE_NAME_LEN]; int64_t showId; - int8_t free; } SRetrieveTableReq; +typedef struct SSysTableSchema { + int8_t type; + col_id_t colId; + int32_t bytes; +} SSysTableSchema; + int32_t tSerializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq); int32_t tDeserializeSRetrieveTableReq(void* buf, int32_t bufLen, SRetrieveTableReq* pReq); @@ -1875,7 +1885,6 @@ typedef struct { char topicName[TSDB_TOPIC_FNAME_LEN]; char cgroup[TSDB_CGROUP_LEN]; char* sql; - char* logicalPlan; char* physicalPlan; char* qmsg; } SMqSetCVgReq; @@ -1889,7 +1898,6 @@ static FORCE_INLINE int32_t tEncodeSMqSetCVgReq(void** buf, const SMqSetCVgReq* tlen += taosEncodeString(buf, pReq->topicName); tlen += taosEncodeString(buf, pReq->cgroup); tlen += taosEncodeString(buf, pReq->sql); - tlen += taosEncodeString(buf, pReq->logicalPlan); tlen += taosEncodeString(buf, pReq->physicalPlan); tlen += taosEncodeString(buf, pReq->qmsg); return tlen; @@ -1903,7 +1911,6 @@ static FORCE_INLINE void* tDecodeSMqSetCVgReq(void* buf, SMqSetCVgReq* pReq) { buf = taosDecodeStringTo(buf, pReq->topicName); buf = taosDecodeStringTo(buf, pReq->cgroup); buf = taosDecodeString(buf, &pReq->sql); - buf = taosDecodeString(buf, &pReq->logicalPlan); buf = taosDecodeString(buf, &pReq->physicalPlan); buf = taosDecodeString(buf, &pReq->qmsg); return buf; @@ -2015,6 +2022,7 @@ typedef struct { static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema) { int32_t tlen = 0; tlen += taosEncodeFixedI8(buf, pSchema->type); + tlen += taosEncodeFixedI8(buf, pSchema->index); tlen += taosEncodeFixedI32(buf, pSchema->bytes); tlen += taosEncodeFixedI16(buf, pSchema->colId); tlen += taosEncodeString(buf, pSchema->name); @@ -2023,6 +2031,7 @@ static FORCE_INLINE int32_t taosEncodeSSchema(void** buf, const SSchema* pSchema static FORCE_INLINE void* taosDecodeSSchema(void* buf, SSchema* pSchema) { buf = taosDecodeFixedI8(buf, &pSchema->type); + buf = taosDecodeFixedI8(buf, &pSchema->index); buf = taosDecodeFixedI32(buf, &pSchema->bytes); buf = taosDecodeFixedI16(buf, &pSchema->colId); buf = taosDecodeStringTo(buf, pSchema->name); @@ -2031,6 +2040,7 @@ static FORCE_INLINE void* taosDecodeSSchema(void* buf, SSchema* pSchema) { static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSchema) { if (tEncodeI8(pEncoder, pSchema->type) < 0) return -1; + if (tEncodeI8(pEncoder, pSchema->index) < 0) return -1; if (tEncodeI32(pEncoder, pSchema->bytes) < 0) return -1; if (tEncodeI16(pEncoder, pSchema->colId) < 0) return -1; if (tEncodeCStr(pEncoder, pSchema->name) < 0) return -1; @@ -2039,6 +2049,7 @@ static FORCE_INLINE int32_t tEncodeSSchema(SCoder* pEncoder, const SSchema* pSch static FORCE_INLINE int32_t tDecodeSSchema(SCoder* pDecoder, SSchema* pSchema) { if (tDecodeI8(pDecoder, &pSchema->type) < 0) return -1; + if (tDecodeI8(pDecoder, &pSchema->index) < 0) return -1; if (tDecodeI32(pDecoder, &pSchema->bytes) < 0) return -1; if (tDecodeI16(pDecoder, &pSchema->colId) < 0) return -1; if (tDecodeCStrTo(pDecoder, pSchema->name) < 0) return -1; @@ -2360,11 +2371,10 @@ typedef struct { } SMqSubVgEp; typedef struct { - char topic[TSDB_TOPIC_FNAME_LEN]; - int8_t isSchemaAdaptive; - SArray* vgs; // SArray - int32_t numOfFields; - TAOS_FIELD* fields; + char topic[TSDB_TOPIC_FNAME_LEN]; + int8_t isSchemaAdaptive; + SArray* vgs; // SArray + SSchemaWrapper schema; } SMqSubTopicEp; typedef struct { @@ -2379,6 +2389,53 @@ typedef struct { SArray* pBlockData; // SArray } SMqPollRsp; +typedef struct { + SMqRspHead head; + int64_t reqOffset; + int64_t rspOffset; + int32_t skipLogNum; + int32_t dataLen; + SArray* blockPos; // beginning pos for each SRetrieveTableRsp + void* blockData; // serialized batched SRetrieveTableRsp +} SMqPollRspV2; + +static FORCE_INLINE int32_t tEncodeSMqPollRspV2(void** buf, const SMqPollRspV2* pRsp) { + int32_t tlen = 0; + tlen += taosEncodeFixedI64(buf, pRsp->reqOffset); + tlen += taosEncodeFixedI64(buf, pRsp->rspOffset); + tlen += taosEncodeFixedI32(buf, pRsp->skipLogNum); + tlen += taosEncodeFixedI32(buf, pRsp->dataLen); + if (pRsp->dataLen != 0) { + int32_t sz = taosArrayGetSize(pRsp->blockPos); + tlen += taosEncodeFixedI32(buf, sz); + for (int32_t i = 0; i < sz; i++) { + int32_t blockPos = *(int32_t*)taosArrayGet(pRsp->blockPos, i); + tlen += taosEncodeFixedI32(buf, blockPos); + } + tlen += taosEncodeBinary(buf, pRsp->blockData, pRsp->dataLen); + } + return tlen; +} + +static FORCE_INLINE void* tDecodeSMqPollRspV2(const void* buf, SMqPollRspV2* pRsp) { + buf = taosDecodeFixedI64(buf, &pRsp->reqOffset); + buf = taosDecodeFixedI64(buf, &pRsp->rspOffset); + buf = taosDecodeFixedI32(buf, &pRsp->skipLogNum); + buf = taosDecodeFixedI32(buf, &pRsp->dataLen); + if (pRsp->dataLen != 0) { + int32_t sz; + buf = taosDecodeFixedI32(buf, &sz); + pRsp->blockPos = taosArrayInit(sz, sizeof(int32_t)); + for (int32_t i = 0; i < sz; i++) { + int32_t blockPos; + buf = taosDecodeFixedI32(buf, &blockPos); + taosArrayPush(pRsp->blockPos, &blockPos); + } + buf = taosDecodeBinary(buf, &pRsp->blockData, pRsp->dataLen); + } + return (void*)buf; +} + typedef struct { SMqRspHead head; char cgroup[TSDB_CGROUP_LEN]; @@ -2416,8 +2473,7 @@ static FORCE_INLINE int32_t tEncodeSMqSubTopicEp(void** buf, const SMqSubTopicEp SMqSubVgEp* pVgEp = (SMqSubVgEp*)taosArrayGet(pTopicEp->vgs, i); tlen += tEncodeSMqSubVgEp(buf, pVgEp); } - tlen += taosEncodeFixedI32(buf, pTopicEp->numOfFields); - // tlen += taosEncodeBinary(buf, pTopicEp->fields, pTopicEp->numOfFields * sizeof(TAOS_FIELD)); + tlen += taosEncodeSSchemaWrapper(buf, &pTopicEp->schema); return tlen; } @@ -2435,8 +2491,7 @@ static FORCE_INLINE void* tDecodeSMqSubTopicEp(void* buf, SMqSubTopicEp* pTopicE buf = tDecodeSMqSubVgEp(buf, &vgEp); taosArrayPush(pTopicEp->vgs, &vgEp); } - buf = taosDecodeFixedI32(buf, &pTopicEp->numOfFields); - // buf = taosDecodeBinary(buf, (void**)&pTopicEp->fields, pTopicEp->numOfFields * sizeof(TAOS_FIELD)); + buf = taosDecodeSSchemaWrapper(buf, &pTopicEp->schema); return buf; } diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 5f919a28d70cd76a5975b5ed702e7548754055ea..e553dff270ff06b5f778ee4f050d522dd2f7e492 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -136,7 +136,6 @@ enum { TD_DEF_MSG_TYPE(TDMT_MND_KILL_CONN, "mnode-kill-conn", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_HEARTBEAT, "mnode-heartbeat", SClientHbBatchReq, SClientHbBatchRsp) TD_DEF_MSG_TYPE(TDMT_MND_SHOW, "mnode-show", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_MND_SHOW_RETRIEVE, "mnode-retrieve", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_SYSTABLE_RETRIEVE, "mnode-systable-retrieve", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_STATUS, "mnode-status", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_TRANS_TIMER, "mnode-trans-tmr", NULL, NULL) @@ -189,8 +188,8 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_CREATE_TOPIC, "vnode-create-topic", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_ALTER_TOPIC, "vnode-alter-topic", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_DROP_TOPIC, "vnode-drop-topic", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_SHOW_TABLES, "vnode-show-tables", SVShowTablesReq, SVShowTablesRsp) - TD_DEF_MSG_TYPE(TDMT_VND_SHOW_TABLES_FETCH, "vnode-show-tables-fetch", SVShowTablesFetchReq, SVShowTablesFetchRsp) +// TD_DEF_MSG_TYPE(TDMT_VND_SHOW_TABLES, "vnode-show-tables", SVShowTablesReq, SVShowTablesRsp) +// TD_DEF_MSG_TYPE(TDMT_VND_SHOW_TABLES_FETCH, "vnode-show-tables-fetch", SVShowTablesFetchReq, SVShowTablesFetchRsp) TD_DEF_MSG_TYPE(TDMT_VND_QUERY_CONTINUE, "vnode-query-continue", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_QUERY_HEARTBEAT, "vnode-query-heartbeat", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_EXPLAIN, "vnode-explain", NULL, NULL) diff --git a/include/common/trow.h b/include/common/trow.h index b7ffcd14c642d07d88e8bed20f2a7ecd394c9895..539bda078d748aee4509292055cc7d24d0e33961 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -230,7 +230,7 @@ static FORCE_INLINE int32_t tdAppendColValToTpRow(SRowBuilder *pBuilder, TDRowVa static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val, bool isCopyVarData, int8_t colType, int16_t colIdx, int32_t offset, col_id_t colId); -int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool forceSetNull); +int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols); /** * @brief diff --git a/include/common/ttime.h b/include/common/ttime.h index 306f54bedb2f5609dc2f1e48d47f483e2d9f0d0f..3de0b98d85217f142a903c6e42c257bba5f299b9 100644 --- a/include/common/ttime.h +++ b/include/common/ttime.h @@ -40,6 +40,7 @@ extern "C" { * @return timestamp decided by global conf variable, tsTimePrecision * if precision == TSDB_TIME_PRECISION_MICRO, it returns timestamp in microsecond. * precision == TSDB_TIME_PRECISION_MILLI, it returns timestamp in millisecond. + * precision == TSDB_TIME_PRECISION_NANO, it returns timestamp in nanosecond. */ static FORCE_INLINE int64_t taosGetTimestamp(int32_t precision) { if (precision == TSDB_TIME_PRECISION_MICRO) { @@ -51,6 +52,24 @@ static FORCE_INLINE int64_t taosGetTimestamp(int32_t precision) { } } +/* + * @return timestamp of today at 00:00:00 in given precision + * if precision == TSDB_TIME_PRECISION_MICRO, it returns timestamp in microsecond. + * precision == TSDB_TIME_PRECISION_MILLI, it returns timestamp in millisecond. + * precision == TSDB_TIME_PRECISION_NANO, it returns timestamp in nanosecond. + */ +static FORCE_INLINE int64_t taosGetTimestampToday(int32_t precision) { + int64_t factor = (precision == TSDB_TIME_PRECISION_MILLI) ? 1000 : + (precision == TSDB_TIME_PRECISION_MICRO) ? 1000000 : 1000000000; + time_t t = taosTime(NULL); + struct tm * tm= taosLocalTime(&t, NULL); + tm->tm_hour = 0; + tm->tm_min = 0; + tm->tm_sec = 0; + + return (int64_t)taosMktime(tm) * factor; +} + int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision); int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precision); int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision); @@ -64,6 +83,7 @@ char getPrecisionUnit(int32_t precision); int64_t convertTimePrecision(int64_t time, int32_t fromPrecision, int32_t toPrecision); int64_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char toUnit); +int32_t convertStringToTimestamp(int16_t type, char *inputData, int64_t timePrec, int64_t *timeVal); void taosFormatUtcTime(char *buf, int32_t bufLen, int64_t time, int32_t precision); diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index 3eb43c35e15a739ea4a33a634b52ee9490ea4cb9..23dd4b38ffb576af35354d56729b7964c0845a20 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -140,88 +140,91 @@ #define TK_APPS 122 #define TK_CONNECTIONS 123 #define TK_LICENCE 124 -#define TK_QUERIES 125 -#define TK_SCORES 126 -#define TK_TOPICS 127 -#define TK_VARIABLES 128 -#define TK_BNODES 129 -#define TK_SNODES 130 -#define TK_LIKE 131 -#define TK_INDEX 132 -#define TK_FULLTEXT 133 -#define TK_FUNCTION 134 -#define TK_INTERVAL 135 -#define TK_TOPIC 136 -#define TK_AS 137 -#define TK_DESC 138 -#define TK_DESCRIBE 139 -#define TK_RESET 140 -#define TK_QUERY 141 -#define TK_EXPLAIN 142 -#define TK_ANALYZE 143 -#define TK_VERBOSE 144 -#define TK_NK_BOOL 145 -#define TK_RATIO 146 -#define TK_COMPACT 147 -#define TK_VNODES 148 -#define TK_IN 149 -#define TK_OUTPUTTYPE 150 -#define TK_AGGREGATE 151 -#define TK_BUFSIZE 152 -#define TK_STREAM 153 -#define TK_INTO 154 -#define TK_KILL 155 -#define TK_CONNECTION 156 -#define TK_MERGE 157 -#define TK_VGROUP 158 -#define TK_REDISTRIBUTE 159 -#define TK_SPLIT 160 -#define TK_SYNCDB 161 -#define TK_NULL 162 -#define TK_FIRST 163 -#define TK_LAST 164 -#define TK_NOW 165 -#define TK_ROWTS 166 -#define TK_TBNAME 167 -#define TK_QSTARTTS 168 -#define TK_QENDTS 169 -#define TK_WSTARTTS 170 -#define TK_WENDTS 171 -#define TK_WDURATION 172 -#define TK_BETWEEN 173 -#define TK_IS 174 -#define TK_NK_LT 175 -#define TK_NK_GT 176 -#define TK_NK_LE 177 -#define TK_NK_GE 178 -#define TK_NK_NE 179 -#define TK_MATCH 180 -#define TK_NMATCH 181 -#define TK_JOIN 182 -#define TK_INNER 183 -#define TK_SELECT 184 -#define TK_DISTINCT 185 -#define TK_WHERE 186 -#define TK_PARTITION 187 -#define TK_BY 188 -#define TK_SESSION 189 -#define TK_STATE_WINDOW 190 -#define TK_SLIDING 191 -#define TK_FILL 192 -#define TK_VALUE 193 -#define TK_NONE 194 -#define TK_PREV 195 -#define TK_LINEAR 196 -#define TK_NEXT 197 -#define TK_GROUP 198 -#define TK_HAVING 199 -#define TK_ORDER 200 -#define TK_SLIMIT 201 -#define TK_SOFFSET 202 -#define TK_LIMIT 203 -#define TK_OFFSET 204 -#define TK_ASC 205 -#define TK_NULLS 206 +#define TK_GRANTS 125 +#define TK_QUERIES 126 +#define TK_SCORES 127 +#define TK_TOPICS 128 +#define TK_VARIABLES 129 +#define TK_BNODES 130 +#define TK_SNODES 131 +#define TK_LIKE 132 +#define TK_INDEX 133 +#define TK_FULLTEXT 134 +#define TK_FUNCTION 135 +#define TK_INTERVAL 136 +#define TK_TOPIC 137 +#define TK_AS 138 +#define TK_DESC 139 +#define TK_DESCRIBE 140 +#define TK_RESET 141 +#define TK_QUERY 142 +#define TK_EXPLAIN 143 +#define TK_ANALYZE 144 +#define TK_VERBOSE 145 +#define TK_NK_BOOL 146 +#define TK_RATIO 147 +#define TK_COMPACT 148 +#define TK_VNODES 149 +#define TK_IN 150 +#define TK_OUTPUTTYPE 151 +#define TK_AGGREGATE 152 +#define TK_BUFSIZE 153 +#define TK_STREAM 154 +#define TK_INTO 155 +#define TK_KILL 156 +#define TK_CONNECTION 157 +#define TK_MERGE 158 +#define TK_VGROUP 159 +#define TK_REDISTRIBUTE 160 +#define TK_SPLIT 161 +#define TK_SYNCDB 162 +#define TK_NULL 163 +#define TK_FIRST 164 +#define TK_LAST 165 +#define TK_CAST 166 +#define TK_NOW 167 +#define TK_TODAY 168 +#define TK_ROWTS 169 +#define TK_TBNAME 170 +#define TK_QSTARTTS 171 +#define TK_QENDTS 172 +#define TK_WSTARTTS 173 +#define TK_WENDTS 174 +#define TK_WDURATION 175 +#define TK_BETWEEN 176 +#define TK_IS 177 +#define TK_NK_LT 178 +#define TK_NK_GT 179 +#define TK_NK_LE 180 +#define TK_NK_GE 181 +#define TK_NK_NE 182 +#define TK_MATCH 183 +#define TK_NMATCH 184 +#define TK_JOIN 185 +#define TK_INNER 186 +#define TK_SELECT 187 +#define TK_DISTINCT 188 +#define TK_WHERE 189 +#define TK_PARTITION 190 +#define TK_BY 191 +#define TK_SESSION 192 +#define TK_STATE_WINDOW 193 +#define TK_SLIDING 194 +#define TK_FILL 195 +#define TK_VALUE 196 +#define TK_NONE 197 +#define TK_PREV 198 +#define TK_LINEAR 199 +#define TK_NEXT 200 +#define TK_GROUP 201 +#define TK_HAVING 202 +#define TK_ORDER 203 +#define TK_SLIMIT 204 +#define TK_SOFFSET 205 +#define TK_LIMIT 206 +#define TK_OFFSET 207 +#define TK_ASC 208 +#define TK_NULLS 209 #define TK_NK_SPACE 300 #define TK_NK_COMMENT 301 diff --git a/include/common/ttypes.h b/include/common/ttypes.h index 37d688a0efcf9da39f99937e5a7150e78a35d4d9..23b260849dc382ffaca7466b782d21698dd8b93d 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -24,9 +24,9 @@ extern "C" { #include "types.h" // ----------------- For variable data types such as TSDB_DATA_TYPE_BINARY and TSDB_DATA_TYPE_NCHAR -typedef int32_t VarDataOffsetT; typedef uint32_t TDRowLenT; typedef uint8_t TDRowValT; +typedef uint64_t TDRowVerT; typedef int16_t col_id_t; typedef int8_t col_type_t; typedef int32_t col_bytes_t; @@ -141,9 +141,47 @@ typedef struct { } \ } while (0) +#define NUM_TO_STRING(_inputType, _input, _outputBytes, _output) \ + do { \ + switch (_inputType) { \ + case TSDB_DATA_TYPE_TINYINT: \ + snprintf(_output, (int32_t)(_outputBytes), "%d", *(int8_t *)(_input)); \ + break; \ + case TSDB_DATA_TYPE_UTINYINT: \ + snprintf(_output, (int32_t)(_outputBytes), "%d", *(uint8_t *)(_input)); \ + break; \ + case TSDB_DATA_TYPE_SMALLINT: \ + snprintf(_output, (int32_t)(_outputBytes), "%d", *(int16_t *)(_input)); \ + break; \ + case TSDB_DATA_TYPE_USMALLINT: \ + snprintf(_output, (int32_t)(_outputBytes), "%d", *(uint16_t *)(_input)); \ + break; \ + case TSDB_DATA_TYPE_TIMESTAMP: \ + case TSDB_DATA_TYPE_BIGINT: \ + snprintf(_output, (int32_t)(_outputBytes), "%" PRId64, *(int64_t *)(_input)); \ + break; \ + case TSDB_DATA_TYPE_UBIGINT: \ + snprintf(_output, (int32_t)(_outputBytes), "%" PRIu64, *(uint64_t *)(_input)); \ + break; \ + case TSDB_DATA_TYPE_FLOAT: \ + snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \ + break; \ + case TSDB_DATA_TYPE_DOUBLE: \ + snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \ + break; \ + case TSDB_DATA_TYPE_UINT: \ + snprintf(_output, (int32_t)(_outputBytes), "%u", *(uint32_t *)(_input)); \ + break; \ + default: \ + snprintf(_output, (int32_t)(_outputBytes), "%d", *(int32_t *)(_input)); \ + break; \ + } \ + } while (0) + #define IS_SIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_TINYINT && (_t) <= TSDB_DATA_TYPE_BIGINT) #define IS_UNSIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_UTINYINT && (_t) <= TSDB_DATA_TYPE_UBIGINT) #define IS_FLOAT_TYPE(_t) ((_t) == TSDB_DATA_TYPE_FLOAT || (_t) == TSDB_DATA_TYPE_DOUBLE) +#define IS_INTEGER_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t))) #define IS_NUMERIC_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t)) || (IS_FLOAT_TYPE(_t))) #define IS_MATHABLE_TYPE(_t) (IS_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL) || (_t) == (TSDB_DATA_TYPE_TIMESTAMP)) diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index e4f4bdf8f994c31df6f31ce6df1347e384df5de6..b48fd232045a03608b593511982476d329f5d05f 100644 --- a/include/dnode/mgmt/dnode.h +++ b/include/dnode/mgmt/dnode.h @@ -30,12 +30,12 @@ typedef struct SDnode SDnode; * * @return int32_t 0 for success and -1 for failure */ -int32_t dndInit(); +int32_t dmInit(); /** * @brief Clear the environment */ -void dndCleanup(); +void dmCleanup(); /* ------------------------ SDnode ----------------------- */ typedef struct { @@ -51,7 +51,7 @@ typedef struct { int8_t ntype; } SDnodeOpt; -typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_CHILD } EDndEvent; +typedef enum { DND_EVENT_START = 0, DND_EVENT_STOP = 1, DND_EVENT_CHILD = 2 } EDndEvent; /** * @brief Initialize and start the dnode. @@ -59,21 +59,21 @@ typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_CHILD } EDndEvent; * @param pOption Option of the dnode. * @return SDnode* The dnode object. */ -SDnode *dndCreate(const SDnodeOpt *pOption); +SDnode *dmCreate(const SDnodeOpt *pOption); /** * @brief Stop and cleanup the dnode. * * @param pDnode The dnode object to close. */ -void dndClose(SDnode *pDnode); +void dmClose(SDnode *pDnode); /** * @brief Run dnode until specific event is receive. * * @param pDnode The dnode object to run. */ -int32_t dndRun(SDnode *pDnode); +int32_t dmRun(SDnode *pDnode); /** * @brief Handle event in the dnode. @@ -81,7 +81,7 @@ int32_t dndRun(SDnode *pDnode); * @param pDnode The dnode object to close. * @param event The event to handle. */ -void dndHandleEvent(SDnode *pDnode, EDndEvent event); +void dmSetEvent(SDnode *pDnode, EDndEvent event); #ifdef __cplusplus } diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 08ab63e55abb4498e058c8e014387c1046a76621..98481259194ba6f87e99e7c465d21c84244747ef 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -68,31 +68,18 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption); * @param pMnode The mnode object. */ int32_t mndStart(SMnode *pMnode); +void mndStop(SMnode *pMnode); /** * @brief Get mnode monitor info. * * @param pMnode The mnode object. - * @param pClusterInfo - * @param pVgroupInfo - * @param pGrantInfo + * @param pCluster + * @param pVgroup + * @param pGrant * @return int32_t 0 for success, -1 for failure. */ -int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo, - SMonGrantInfo *pGrantInfo); - -/** - * @brief Get user authentication info. - * - * @param pMnode The mnode object. - * @param user - * @param spi - * @param encrypt - * @param secret - * @param ckey - * @return int32_t 0 for success, -1 for failure. - */ -int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey); +int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pCluster, SMonVgroupInfo *pVgroup, SMonGrantInfo *pGrant); /** * @brief Process the read, write, sync request. @@ -102,6 +89,11 @@ int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, cha */ int32_t mndProcessMsg(SNodeMsg *pMsg); +/** + * @brief Generate machine code + */ +void mndGenerateMachineCode(); + #ifdef __cplusplus } #endif diff --git a/include/libs/command/command.h b/include/libs/command/command.h index fa229d72654950546d4e8d5e65f0aa089daf93f7..0cd566ee464dc23d0af5288281448c98204e6a2e 100644 --- a/include/libs/command/command.h +++ b/include/libs/command/command.h @@ -22,7 +22,7 @@ typedef struct SExplainCtx SExplainCtx; int32_t qExecCommand(SNode* pStmt, SRetrieveTableRsp** pRsp); int32_t qExecStaticExplain(SQueryPlan *pDag, SRetrieveTableRsp **pRsp); -int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int32_t startTs); +int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs); int32_t qExecExplainEnd(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp); int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t groupId, SRetrieveTableRsp **pRsp); void qExplainFreeCtx(SExplainCtx *pCtx); diff --git a/include/libs/function/functionMgt.h b/include/libs/function/functionMgt.h index 57a3862a9a811b09c1bdf89583850306e025df94..a471de3147a999afbec8346afb08ebc833699b12 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -85,8 +85,8 @@ typedef enum EFunctionType { // conversion function FUNCTION_TYPE_CAST = 2000, FUNCTION_TYPE_TO_ISO8601, + FUNCTION_TYPE_TO_UNIXTIMESTAMP, FUNCTION_TYPE_TO_JSON, - FUNCTION_TYPE_UNIXTIMESTAMP, // date and time function FUNCTION_TYPE_NOW = 2500, @@ -123,7 +123,7 @@ void fmFuncMgtDestroy(); int32_t fmGetFuncInfo(const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType); -int32_t fmGetFuncResultType(SFunctionNode* pFunc); +int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len); bool fmIsAggFunc(int32_t funcId); bool fmIsScalarFunc(int32_t funcId); @@ -135,8 +135,17 @@ bool fmIsTimeorderFunc(int32_t funcId); bool fmIsPseudoColumnFunc(int32_t funcId); bool fmIsWindowPseudoColumnFunc(int32_t funcId); bool fmIsWindowClauseFunc(int32_t funcId); +bool fmIsSpecialDataRequiredFunc(int32_t funcId); +bool fmIsDynamicScanOptimizedFunc(int32_t funcId); -int32_t fmFuncScanType(int32_t funcId); +typedef enum EFuncDataRequired { + FUNC_DATA_REQUIRED_ALL_NEEDED = 1, + FUNC_DATA_REQUIRED_STATIS_NEEDED, + FUNC_DATA_REQUIRED_NO_NEEDED, + FUNC_DATA_REQUIRED_DISCARD +} EFuncDataRequired; + +EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow); int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet); int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet); diff --git a/include/libs/monitor/monitor.h b/include/libs/monitor/monitor.h index f5080fbe7b518733a55c38d2b93b489691e76906..af0580674d950077f60c37f98e66c3451e91a479 100644 --- a/include/libs/monitor/monitor.h +++ b/include/libs/monitor/monitor.h @@ -78,6 +78,9 @@ typedef struct { typedef struct { float uptime; // day int8_t has_mnode; + int8_t has_qnode; + int8_t has_snode; + int8_t has_bnode; SMonDiskDesc logdir; SMonDiskDesc tempdir; } SMonDnodeInfo; @@ -134,8 +137,8 @@ typedef struct { typedef struct { int32_t expire_time; - int32_t timeseries_used; - int32_t timeseries_total; + int64_t timeseries_used; + int64_t timeseries_total; } SMonGrantInfo; typedef struct { diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 7d0d0137ec12e9ae311dcfd6a23c4521486db7d7..e1a63bd66bdea3567a5671abf3869b09db71cb21 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -267,6 +267,11 @@ typedef struct SDescribeStmt { STableMeta* pMeta; } SDescribeStmt; +typedef struct SKillStmt { + ENodeType type; + int32_t targetId; +} SKillStmt; + #ifdef __cplusplus } #endif diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index c91779ba8b4c74187fbb4cba6bd5a9a4d4b16b48..02636a178e403e82d4d6c0ac9be8279b70f510d5 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -52,7 +52,8 @@ extern "C" { for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); (NULL != cell ? (node = &(cell->pNode), true) : (node = NULL, false)); cell = cell->pNext) typedef enum ENodeType { - // Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN, VALUE, OPERATOR, FUNCTION and so on. + // Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN, + // VALUE, OPERATOR, FUNCTION and so on. QUERY_NODE_COLUMN = 1, QUERY_NODE_VALUE, QUERY_NODE_OPERATOR, @@ -69,7 +70,7 @@ typedef enum ENodeType { QUERY_NODE_INTERVAL_WINDOW, QUERY_NODE_NODE_LIST, QUERY_NODE_FILL, - QUERY_NODE_RAW_EXPR, // Only be used in parser module. + QUERY_NODE_RAW_EXPR, // Only be used in parser module. QUERY_NODE_TARGET, QUERY_NODE_DATABLOCK_DESC, QUERY_NODE_SLOT_DESC, @@ -126,30 +127,30 @@ typedef enum ENodeType { QUERY_NODE_REDISTRIBUTE_VGROUP_STMT, QUERY_NODE_SPLIT_VGROUP_STMT, QUERY_NODE_SYNCDB_STMT, - QUERY_NODE_SHOW_DATABASES_STMT, - QUERY_NODE_SHOW_TABLES_STMT, - QUERY_NODE_SHOW_STABLES_STMT, - QUERY_NODE_SHOW_USERS_STMT, QUERY_NODE_SHOW_DNODES_STMT, - QUERY_NODE_SHOW_VGROUPS_STMT, QUERY_NODE_SHOW_MNODES_STMT, QUERY_NODE_SHOW_MODULES_STMT, QUERY_NODE_SHOW_QNODES_STMT, + QUERY_NODE_SHOW_SNODES_STMT, + QUERY_NODE_SHOW_BNODES_STMT, + QUERY_NODE_SHOW_DATABASES_STMT, QUERY_NODE_SHOW_FUNCTIONS_STMT, QUERY_NODE_SHOW_INDEXES_STMT, + QUERY_NODE_SHOW_STABLES_STMT, QUERY_NODE_SHOW_STREAMS_STMT, - QUERY_NODE_SHOW_APPS_STMT, - QUERY_NODE_SHOW_CONNECTIONS_STMT, + QUERY_NODE_SHOW_TABLES_STMT, + QUERY_NODE_SHOW_USERS_STMT, QUERY_NODE_SHOW_LICENCE_STMT, - QUERY_NODE_SHOW_CREATE_DATABASE_STMT, - QUERY_NODE_SHOW_CREATE_TABLE_STMT, - QUERY_NODE_SHOW_CREATE_STABLE_STMT, - QUERY_NODE_SHOW_QUERIES_STMT, - QUERY_NODE_SHOW_SCORES_STMT, + QUERY_NODE_SHOW_VGROUPS_STMT, QUERY_NODE_SHOW_TOPICS_STMT, - QUERY_NODE_SHOW_VARIABLE_STMT, - QUERY_NODE_SHOW_BNODES_STMT, - QUERY_NODE_SHOW_SNODES_STMT, + QUERY_NODE_SHOW_CONSUMERS_STMT, + QUERY_NODE_SHOW_SUBSCRIBES_STMT, + QUERY_NODE_SHOW_TRANS_STMT, + QUERY_NODE_SHOW_SMAS_STMT, + QUERY_NODE_SHOW_CONFIGS_STMT, + QUERY_NODE_SHOW_CONNECTIONS_STMT, + QUERY_NODE_SHOW_QUERIES_STMT, + QUERY_NODE_SHOW_VNODES_STMT, QUERY_NODE_KILL_CONNECTION_STMT, QUERY_NODE_KILL_QUERY_STMT, @@ -216,6 +217,7 @@ SNodeList* nodesMakeList(); int32_t nodesListAppend(SNodeList* pList, SNodeptr pNode); int32_t nodesListStrictAppend(SNodeList* pList, SNodeptr pNode); int32_t nodesListMakeAppend(SNodeList** pList, SNodeptr pNode); +int32_t nodesListMakeStrictAppend(SNodeList** pList, SNodeptr pNode); int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc); int32_t nodesListStrictAppendList(SNodeList* pTarget, SNodeList* pSrc); int32_t nodesListPushFront(SNodeList* pList, SNodeptr pNode); @@ -230,6 +232,7 @@ typedef enum EDealRes { DEAL_RES_CONTINUE = 1, DEAL_RES_IGNORE_CHILD, DEAL_RES_ERROR, + DEAL_RES_END } EDealRes; typedef EDealRes (*FNodeWalker)(SNode* pNode, void* pContext); diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index 7cb96104bdec83857fd669e2cb644c0f12fa26c9..3b5f9abe817c7432ef87ce589ac4d73c7ff7d8d3 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -30,6 +30,7 @@ typedef struct SLogicNode { SNode* pConditions; SNodeList* pChildren; struct SLogicNode* pParent; + int32_t optimizedFlag; } SLogicNode; typedef enum EScanType { @@ -50,6 +51,8 @@ typedef struct SScanLogicNode { SName tableName; bool showRewrite; double ratio; + SNodeList* pDynamicScanFuncs; + int32_t dataRequired; } SScanLogicNode; typedef struct SJoinLogicNode { @@ -84,6 +87,7 @@ typedef struct SVnodeModifLogicNode { typedef struct SExchangeLogicNode { SLogicNode node; int32_t srcGroupId; + uint8_t precision; } SExchangeLogicNode; typedef enum EWindowType { @@ -163,7 +167,7 @@ typedef struct SDataBlockDescNode { SNodeList* pSlots; int32_t totalRowSize; int32_t outputRowSize; - int16_t precision; + uint8_t precision; } SDataBlockDescNode; typedef struct SPhysiNode { @@ -195,20 +199,13 @@ typedef struct SSystemTableScanPhysiNode { int32_t accountId; } SSystemTableScanPhysiNode; -typedef enum EScanRequired { - SCAN_REQUIRED_DATA_NO_NEEDED = 1, - SCAN_REQUIRED_DATA_STATIS_NEEDED, - SCAN_REQUIRED_DATA_ALL_NEEDED, - SCAN_REQUIRED_DATA_DISCARD, -} EScanRequired; - typedef struct STableScanPhysiNode { SScanPhysiNode scan; uint8_t scanFlag; // denotes reversed scan of data or not STimeWindow scanRange; double ratio; - EScanRequired scanRequired; - SNodeList* pScanReferFuncs; + int32_t dataRequired; + SNodeList* pDynamicScanFuncs; } STableScanPhysiNode; typedef STableScanPhysiNode STableSeqScanPhysiNode; @@ -253,11 +250,11 @@ typedef struct SWinodwPhysiNode { SPhysiNode node; SNodeList* pExprs; // these are expression list of parameter expression of function SNodeList* pFuncs; + SNode* pTspk; // timestamp primary key } SWinodwPhysiNode; typedef struct SIntervalPhysiNode { SWinodwPhysiNode window; - SNode* pTspk; // timestamp primary key int64_t interval; int64_t offset; int64_t sliding; @@ -274,7 +271,7 @@ typedef struct SMultiTableIntervalPhysiNode { typedef struct SSessionWinodwPhysiNode { SWinodwPhysiNode window; - int64_t gap; + int64_t gap; } SSessionWinodwPhysiNode; typedef struct SStateWinodwPhysiNode { diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index f052c9daa721379d3e8e77ef8ba3b65c9d1dc753..3e78da63de2f3a9726aad07ef7c7cc615ebda56e 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -190,6 +190,7 @@ typedef struct SLimitNode { typedef struct SStateWindowNode { ENodeType type; // QUERY_NODE_STATE_WINDOW + SNode* pCol; // timestamp primary key SNode* pExpr; } SStateWindowNode; diff --git a/include/libs/scalar/filter.h b/include/libs/scalar/filter.h index c81cb49b642cd116cba24ca319f3b60414e0dc29..f1cd99f04a17a8b316319d96c4e49309406866e1 100644 --- a/include/libs/scalar/filter.h +++ b/include/libs/scalar/filter.h @@ -19,8 +19,8 @@ extern "C" { #endif -#include "tcommon.h" #include "nodes.h" +#include "tcommon.h" typedef struct SFilterInfo SFilterInfo; typedef int32_t (*filer_get_col_from_id)(void *, int32_t, void **); @@ -31,20 +31,20 @@ enum { FLT_OPTION_NEED_UNIQE = 4, }; -typedef struct SFilterColumnParam{ +typedef struct SFilterColumnParam { int32_t numOfCols; - SArray* pDataBlock; + SArray *pDataBlock; } SFilterColumnParam; extern int32_t filterInitFromNode(SNode *pNode, SFilterInfo **pinfo, uint32_t options); -extern bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnDataAgg *statis, int16_t numOfCols); +extern bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t **p, SColumnDataAgg *statis, int16_t numOfCols); extern int32_t filterSetDataFromSlotId(SFilterInfo *info, void *param); extern int32_t filterSetDataFromColId(SFilterInfo *info, void *param); extern int32_t filterGetTimeRange(SNode *pNode, STimeWindow *win, bool *isStrict); -extern int32_t filterConverNcharColumns(SFilterInfo* pFilterInfo, int32_t rows, bool *gotNchar); -extern int32_t filterFreeNcharColumns(SFilterInfo* pFilterInfo); -extern void filterFreeInfo(SFilterInfo *info); -extern bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t numOfCols, int32_t numOfRows); +extern int32_t filterConverNcharColumns(SFilterInfo *pFilterInfo, int32_t rows, bool *gotNchar); +extern int32_t filterFreeNcharColumns(SFilterInfo *pFilterInfo); +extern void filterFreeInfo(SFilterInfo *info); +extern bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t numOfCols, int32_t numOfRows); #ifdef __cplusplus } diff --git a/include/libs/scalar/scalar.h b/include/libs/scalar/scalar.h index b5acc64f0b7040070cc6e85481c7f41adea5e298..10b4866a965a47aafc03232c9f73168c30d6f597 100644 --- a/include/libs/scalar/scalar.h +++ b/include/libs/scalar/scalar.h @@ -31,8 +31,8 @@ pNode will be freed in API; */ int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes); -/* -pDst need to freed in caller +/* +pDst need to freed in caller */ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst); @@ -70,6 +70,15 @@ int32_t ltrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOut int32_t rtrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +/* Conversion functions */ +int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); + +/* Time related functions */ +int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t toUnixtimestampFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); + bool getTimePseudoFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); int32_t winStartTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); diff --git a/include/os/osDir.h b/include/os/osDir.h index d3597cab36aa27e19360f290ec841c54a3e96ccd..e7da54bf548ff4da95e800e0beccdda9e13c4df7 100644 --- a/include/os/osDir.h +++ b/include/os/osDir.h @@ -38,6 +38,7 @@ typedef struct TdDirEntry *TdDirEntryPtr; void taosRemoveDir(const char *dirname); bool taosDirExist(char *dirname); int32_t taosMkDir(const char *dirname); +int32_t taosMulMkDir(const char *dirname); void taosRemoveOldFiles(const char *dirname, int32_t keepDays); int32_t taosExpandDir(const char *dirname, char *outname, int32_t maxlen); int32_t taosRealPath(char *dirname, int32_t maxlen); diff --git a/include/os/osFile.h b/include/os/osFile.h index 143b4bf2f8509fce4731c89e9e75b3212bac678e..36ca6fb8bb507cb604aca8399011960f9a14ca1d 100644 --- a/include/os/osFile.h +++ b/include/os/osFile.h @@ -44,7 +44,7 @@ extern "C" { typedef struct TdFile *TdFilePtr; -#define TD_FILE_CTEATE 0x0001 +#define TD_FILE_CREATE 0x0001 #define TD_FILE_WRITE 0x0002 #define TD_FILE_READ 0x0004 #define TD_FILE_TRUNC 0x0008 @@ -79,7 +79,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count); void taosFprintfFile(TdFilePtr pFile, const char *format, ...); -int64_t taosGetLineFile(TdFilePtr pFile, char ** __restrict__ ptrBuf); +int64_t taosGetLineFile(TdFilePtr pFile, char ** __restrict ptrBuf); int32_t taosEOFFile(TdFilePtr pFile); diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h index 022f11bb0e646125a73d9a962fabb252a003b11a..c009bcf350858b934d14e48e3424a8611046ddb0 100644 --- a/include/os/osSysinfo.h +++ b/include/os/osSysinfo.h @@ -39,7 +39,7 @@ int32_t taosGetEmail(char *email, int32_t maxLen); int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen); int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores); int32_t taosGetCpuCores(float *numOfCores); -int32_t taosGetCpuUsage(double *cpu_system, double *cpu_engine); +void taosGetCpuUsage(double *cpu_system, double *cpu_engine); int32_t taosGetTotalMemory(int64_t *totalKB); int32_t taosGetProcMemory(int64_t *usedKB); int32_t taosGetSysMemory(int64_t *usedKB); diff --git a/include/os/osSystem.h b/include/os/osSystem.h index 15959a2d8c690813d777577075a373dfc501637f..33b0a46ee91f706242a1279a3a42567e51621d92 100644 --- a/include/os/osSystem.h +++ b/include/os/osSystem.h @@ -29,6 +29,13 @@ extern "C" { #define tcgetattr TCGETATTR_FUNC_TAOS_FORBID #endif +typedef struct TdCmd *TdCmdPtr; + +TdCmdPtr taosOpenCmd(const char *cmd); +int64_t taosGetLineCmd(TdCmdPtr pCmd, char ** __restrict ptrBuf); +int32_t taosEOFCmd(TdCmdPtr pCmd); +int64_t taosCloseCmd(TdCmdPtr *ppCmd); + void* taosLoadDll(const char* filename); void* taosLoadSym(void* handle, char* name); void taosCloseDll(void* handle); diff --git a/include/os/osTime.h b/include/os/osTime.h index 766fec0fbd9c1a74be89e87fb74bf4d17a0e3453..fd431f6df8e65e952ce63d54a31a54c32432dd27 100644 --- a/include/os/osTime.h +++ b/include/os/osTime.h @@ -27,9 +27,11 @@ extern "C" { #ifndef ALLOW_FORBID_FUNC #define strptime STRPTIME_FUNC_TAOS_FORBID #define gettimeofday GETTIMEOFDAY_FUNC_TAOS_FORBID + #define localtime LOCALTIME_FUNC_TAOS_FORBID #define localtime_s LOCALTIMES_FUNC_TAOS_FORBID #define localtime_r LOCALTIMER_FUNC_TAOS_FORBID #define time TIME_FUNC_TAOS_FORBID + #define mktime MKTIME_FUNC_TAOS_FORBID #endif #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) @@ -82,6 +84,8 @@ static FORCE_INLINE int64_t taosGetTimestampNs() { char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm); struct tm *taosLocalTime(const time_t *timep, struct tm *result); +time_t taosTime(time_t *t); +time_t taosMktime(struct tm *timep); #ifdef __cplusplus } diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 04baa3c09d2048d033b877bdda71557367229d20..e31eea1b157cf73ac54c7dd42e2c7c803c26d83f 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -566,8 +566,6 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_AMBIGUOUS_COLUMN TAOS_DEF_ERROR_CODE(0, 0x2603) #define TSDB_CODE_PAR_WRONG_VALUE_TYPE TAOS_DEF_ERROR_CODE(0, 0x2604) #define TSDB_CODE_PAR_INVALID_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2605) -#define TSDB_CODE_PAR_FUNTION_PARA_NUM TAOS_DEF_ERROR_CODE(0, 0x2606) -#define TSDB_CODE_PAR_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2607) #define TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION TAOS_DEF_ERROR_CODE(0, 0x2608) #define TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT TAOS_DEF_ERROR_CODE(0, 0x2609) #define TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260A) @@ -597,9 +595,16 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_INVALID_ROLLUP_OPTION TAOS_DEF_ERROR_CODE(0, 0x2622) #define TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION TAOS_DEF_ERROR_CODE(0, 0x2623) #define TSDB_CODE_PAR_GROUPBY_WINDOW_COEXIST TAOS_DEF_ERROR_CODE(0, 0x2624) +#define TSDB_CODE_PAR_INVALID_OPTION_UNIT TAOS_DEF_ERROR_CODE(0, 0x2625) +#define TSDB_CODE_PAR_INVALID_KEEP_UNIT TAOS_DEF_ERROR_CODE(0, 0x2626) //planner -#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700) +#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700) + +//function +#define TSDB_CODE_FUNC_FUNTION_ERROR TAOS_DEF_ERROR_CODE(0, 0x2800) +#define TSDB_CODE_FUNC_FUNTION_PARA_NUM TAOS_DEF_ERROR_CODE(0, 0x2801) +#define TSDB_CODE_FUNC_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2802) #ifdef __cplusplus } diff --git a/include/util/tdef.h b/include/util/tdef.h index 263c90c0f8cea5772d2bb18843dec899f02d72de..6baf784fe38e8555e89210a172592c3c44392e77 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -94,12 +94,19 @@ extern const int32_t TYPE_BYTES[15]; #define TSDB_TIME_PRECISION_MICRO_STR "us" #define TSDB_TIME_PRECISION_NANO_STR "ns" +#define TSDB_TIME_PRECISION_SEC_DIGITS 10 +#define TSDB_TIME_PRECISION_MILLI_DIGITS 13 +#define TSDB_TIME_PRECISION_MICRO_DIGITS 16 +#define TSDB_TIME_PRECISION_NANO_DIGITS 19 + #define TSDB_INFORMATION_SCHEMA_DB "information_schema" +#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema" #define TSDB_INS_TABLE_DNODES "dnodes" #define TSDB_INS_TABLE_MNODES "mnodes" #define TSDB_INS_TABLE_MODULES "modules" #define TSDB_INS_TABLE_QNODES "qnodes" #define TSDB_INS_TABLE_BNODES "bnodes" +#define TSDB_INS_TABLE_SNODES "snodes" #define TSDB_INS_TABLE_CLUSTER "cluster" #define TSDB_INS_TABLE_USER_DATABASES "user_databases" #define TSDB_INS_TABLE_USER_FUNCTIONS "user_functions" @@ -109,9 +116,17 @@ extern const int32_t TYPE_BYTES[15]; #define TSDB_INS_TABLE_USER_TABLES "user_tables" #define TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED "user_table_distributed" #define TSDB_INS_TABLE_USER_USERS "user_users" +#define TSDB_INS_TABLE_LICENCES "grants" #define TSDB_INS_TABLE_VGROUPS "vgroups" -#define TSDB_INS_TABLE_BNODES "bnodes" -#define TSDB_INS_TABLE_SNODES "snodes" +#define TSDB_INS_TABLE_TOPICS "topics" +#define TSDB_INS_TABLE_CONSUMERS "consumers" +#define TSDB_INS_TABLE_SUBSCRIBES "subscribes" +#define TSDB_INS_TABLE_TRANS "trans" +#define TSDB_INS_TABLE_SMAS "smas" +#define TSDB_INS_TABLE_CONFIGS "configs" +#define TSDB_INS_TABLE_CONNS "connections" +#define TSDB_INS_TABLE_QUERIES "queries" +#define TSDB_INS_TABLE_VNODES "vnodes" #define TSDB_INDEX_TYPE_SMA "SMA" #define TSDB_INDEX_TYPE_FULLTEXT "FULLTEXT" @@ -491,6 +506,15 @@ enum { #define QNODE_HANDLE 1 #define DEFAULT_HANDLE 0 +#define TSDB_CONFIG_OPTION_LEN 16 +#define TSDB_CONIIG_VALUE_LEN 48 +#define TSDB_CONFIG_NUMBER 8 + +#define QUERY_ID_SIZE 20 +#define QUERY_OBJ_ID_SIZE 18 +#define SUBQUERY_INFO_SIZE 6 +#define QUERY_SAVE_SIZE 20 + #define MAX_NUM_STR_SIZE 40 diff --git a/include/util/tencode.h b/include/util/tencode.h index cdde378b69f7954c168fb633b83139967b37545c..7c877ae4283fc662cf5cd43d59b571e931b08a02 100644 --- a/include/util/tencode.h +++ b/include/util/tencode.h @@ -18,7 +18,6 @@ #include "tcoding.h" #include "tfreelist.h" -#include "tmacro.h" #ifdef __cplusplus extern "C" { diff --git a/include/util/tmacro.h b/include/util/tmacro.h deleted file mode 100644 index 07c6e6509e4d5eedd7c14a830922b8347111f6e8..0000000000000000000000000000000000000000 --- a/include/util/tmacro.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_UTIL_MACRO_H_ -#define _TD_UTIL_MACRO_H_ - -#include "os.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// Module init/clear MACRO definitions -#define TD_MOD_UNINITIALIZED 0 -#define TD_MOD_INITIALIZED 1 - -typedef int8_t td_mode_flag_t; - -#define TD_CHECK_AND_SET_MODE_INIT(FLAG) atomic_val_compare_exchange_8((FLAG), TD_MOD_UNINITIALIZED, TD_MOD_INITIALIZED) -#define TD_CHECK_AND_SET_MOD_CLEAR(FLAG) atomic_val_compare_exchange_8((FLAG), TD_MOD_INITIALIZED, TD_MOD_UNINITIALIZED) - -#define TD_IS_NULL(PTR) ((PTR) == NULL) - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_UTIL_MACRO_H_*/ \ No newline at end of file diff --git a/include/util/tprocess.h b/include/util/tprocess.h index c5f33140dd701fe5f4c301d733ec96c7c2bf780c..2b0fd89aa5a02c4c9a388a1a3a2973f433a4614d 100644 --- a/include/util/tprocess.h +++ b/include/util/tprocess.h @@ -22,13 +22,13 @@ extern "C" { #endif -typedef enum { PROC_REQ = 1, PROC_RSP, PROC_REGIST, PROC_RELEASE } ProcFuncType; +typedef enum { PROC_FUNC_REQ = 1, PROC_FUNC_RSP, PROC_FUNC_REGIST, PROC_FUNC_RELEASE } EProcFuncType; typedef struct SProcObj SProcObj; typedef void *(*ProcMallocFp)(int32_t contLen); typedef void *(*ProcFreeFp)(void *pCont); typedef void (*ProcConsumeFp)(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, - ProcFuncType ftype); + EProcFuncType ftype); typedef struct { ProcConsumeFp childConsumeFp; @@ -53,11 +53,11 @@ int32_t taosProcRun(SProcObj *pProc); void taosProcStop(SProcObj *pProc); int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, - void *handle, ProcFuncType ftype); + void *handle, EProcFuncType ftype); void taosProcRemoveHandle(SProcObj *pProc, void *handle); void taosProcCloseHandles(SProcObj *pProc, void (*HandleFp)(void *handle)); void taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, - ProcFuncType ftype); + EProcFuncType ftype); #ifdef __cplusplus } diff --git a/packaging/install.sh b/packaging/install.sh index 3aae074af55ada32ecee1a8033b71217c706d301..9ce7fc326a9685aa40ad3a08b70f78656770c792 100755 --- a/packaging/install.sh +++ b/packaging/install.sh @@ -157,7 +157,7 @@ function install_main_path() { ${csudo} mkdir -p ${install_main_dir}/cfg ${csudo} mkdir -p ${install_main_dir}/bin ${csudo} mkdir -p ${install_main_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver + ${csudo} mkdir -p ${install_main_dir}/lib ${csudo} mkdir -p ${install_main_dir}/examples ${csudo} mkdir -p ${install_main_dir}/include ${csudo} mkdir -p ${install_main_dir}/init.d @@ -198,6 +198,10 @@ function install_lib() { # Remove links ${csudo} rm -f ${lib_link_dir}/libtaos.* || : ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : + ${csudo} rm -f ${lib_link_dir}/libtdb.* || : + ${csudo} rm -f ${lib64_link_dir}/libtdb.* || : + + ${csudo} cp -rf ${script_dir}/lib/* ${install_main_dir}/lib && ${csudo} chmod 777 ${install_main_dir}/lib/* ${csudo} ln -s ${install_main_dir}/lib/libtaos.* ${lib_link_dir}/libtaos.so.1 ${csudo} ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so @@ -224,6 +228,12 @@ function install_header() { ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h } +# temp install taosBenchmark +function install_taosTools() { + cd ${script_dir}/taos-tools/ + tar xvf taosTools-1.4.1-Linux-x64.tar.gz && cd taosTools-1.4.1/ && ./install-taostools.sh +} + function add_newHostname_to_hosts() { localIp="127.0.0.1" OLD_IFS="$IFS" @@ -450,14 +460,14 @@ function install_service_on_systemd() { } function install_service() { - if ((${service_mod}==0)); then - install_service_on_systemd - elif ((${service_mod}==1)); then - install_service_on_sysvinit - else - # must manual stop taosd + # if ((${service_mod}==0)); then + # install_service_on_systemd + # elif ((${service_mod}==1)); then + # install_service_on_sysvinit + # else + # # must manual stop taosd kill_process taosd - fi + # fi } function install_TDengine() { @@ -469,6 +479,7 @@ function install_TDengine() { install_log install_header install_lib + install_taosTools if [ -z $1 ]; then # install service and client # For installing new diff --git a/packaging/release.sh b/packaging/release.sh index 5219b1b7b18d1901ead5fb56b6c7a685e7432047..885d73c33b7f47087bf74ce2b22b0ccc03d80541 100755 --- a/packaging/release.sh +++ b/packaging/release.sh @@ -55,6 +55,7 @@ mkdir -p ${install_dir} mkdir -p ${install_dir}/bin mkdir -p ${install_dir}/lib mkdir -p ${install_dir}/inc +mkdir -p ${install_dir}/taos-tools install_files="${script_dir}/install.sh" chmod a+x ${script_dir}/install.sh || : @@ -68,6 +69,8 @@ cp ${bin_files} ${install_dir}/bin && chmod a+x ${install_dir}/bin/* || : cp ${compile_dir}/source/client/libtaos.so ${install_dir}/lib/ cp ${compile_dir}/source/libs/tdb/libtdb.so ${install_dir}/lib/ +taostoolfile="${top_dir}/tools/taosTools-1.4.1-Linux-x64.tar.gz" +cp ${taostoolfile} ${install_dir}/taos-tools #cp ${compile_dir}/source/dnode/mnode/impl/libmnode.so ${install_dir}/lib/ #cp ${compile_dir}/source/dnode/qnode/libqnode.so ${install_dir}/lib/ diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index ae1b34a3bd7dcbe3656b015456eb6282eee2f890..0f12880272d0d10aebdc00482bafe4972691b60a 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -45,6 +45,11 @@ extern "C" { #define HEARTBEAT_INTERVAL 1500 // ms +enum { + CONN_TYPE__QUERY = 1, + CONN_TYPE__TMQ, +}; + typedef struct SAppInstInfo SAppInstInfo; typedef struct { @@ -75,19 +80,19 @@ typedef int32_t (*FHbReqHandle)(SClientHbKey* connKey, void* param, SClientHbReq typedef struct { int8_t inited; // ctl - int8_t threadStop; - TdThread thread; + int8_t threadStop; + TdThread thread; TdThreadMutex lock; // used when app init and cleanup - SArray* appHbMgrs; // SArray one for each cluster - FHbReqHandle reqHandle[HEARTBEAT_TYPE_MAX]; - FHbRspHandle rspHandle[HEARTBEAT_TYPE_MAX]; + SArray* appHbMgrs; // SArray one for each cluster + FHbReqHandle reqHandle[HEARTBEAT_TYPE_MAX]; + FHbRspHandle rspHandle[HEARTBEAT_TYPE_MAX]; } SClientHbMgr; typedef struct SQueryExecMetric { - int64_t start; // start timestamp - int64_t parsed; // start to parse - int64_t send; // start to send to server - int64_t rsp; // receive response from server + int64_t start; // start timestamp, us + int64_t parsed; // start to parse, us + int64_t send; // start to send to server, us + int64_t rsp; // receive response from server, us } SQueryExecMetric; typedef struct SInstanceSummary { @@ -118,42 +123,42 @@ struct SAppInstInfo { }; typedef struct SAppInfo { - int64_t startTime; - char appName[TSDB_APP_NAME_LEN]; - char* ep; - int32_t pid; - int32_t numOfThreads; - SHashObj* pInstMap; + int64_t startTime; + char appName[TSDB_APP_NAME_LEN]; + char* ep; + int32_t pid; + int32_t numOfThreads; + SHashObj* pInstMap; TdThreadMutex mutex; } SAppInfo; typedef struct STscObj { - char user[TSDB_USER_LEN]; - char pass[TSDB_PASSWORD_LEN]; - char db[TSDB_DB_FNAME_LEN]; - char ver[128]; - int32_t acctId; - uint32_t connId; - int32_t connType; - uint64_t id; // ref ID returned by taosAddRef - TdThreadMutex mutex; // used to protect the operation on db - int32_t numOfReqs; // number of sqlObj bound to this connection - SAppInstInfo* pAppInfo; + char user[TSDB_USER_LEN]; + char pass[TSDB_PASSWORD_LEN]; + char db[TSDB_DB_FNAME_LEN]; + char ver[128]; + int8_t connType; + int32_t acctId; + uint32_t connId; + uint64_t id; // ref ID returned by taosAddRef + TdThreadMutex mutex; // used to protect the operation on db + int32_t numOfReqs; // number of sqlObj bound to this connection + SAppInstInfo* pAppInfo; } STscObj; typedef struct SResultColumn { union { - char* nullbitmap; // bitmap, one bit for each item in the list - int32_t* offset; + char* nullbitmap; // bitmap, one bit for each item in the list + int32_t* offset; }; - char* pData; + char* pData; } SResultColumn; typedef struct SReqResultInfo { const char* pRspMsg; const char* pData; - TAOS_FIELD* fields; // todo, column names are not needed. - TAOS_FIELD* userFields; // the fields info that return to user + TAOS_FIELD* fields; // todo, column names are not needed. + TAOS_FIELD* userFields; // the fields info that return to user uint32_t numOfCols; int32_t* length; char** convertBuf; @@ -180,13 +185,30 @@ typedef struct SRequestSendRecvBody { SShowReqInfo showInfo; // todo this attribute will be removed after the query framework being completed. SDataBuf requestMsg; int64_t queryJob; // query job, created according to sql query DAG. - struct SQueryPlan* pDag; // the query dag, generated according to the sql statement. + struct SQueryPlan* pDag; // the query dag, generated according to the sql statement. SReqResultInfo resInfo; } SRequestSendRecvBody; #define ERROR_MSG_BUF_DEFAULT_SIZE 512 +enum { + RES_TYPE__QUERY = 1, + RES_TYPE__TMQ, +}; + +#define TD_RES_QUERY(res) (*(int8_t*)res == RES_TYPE__QUERY) +#define TD_RES_TMQ(res) (*(int8_t*)res == RES_TYPE__TMQ) + +typedef struct { + int8_t resType; + char* topic; + SArray* res; // SArray + int32_t resIter; + int32_t vgId; +} SMqRspObj; + typedef struct SRequestObj { + int8_t resType; // query or tmq uint64_t requestId; int32_t type; // request type STscObj* pTscObj; @@ -203,6 +225,25 @@ typedef struct SRequestObj { SRequestSendRecvBody body; } SRequestObj; +static FORCE_INLINE SReqResultInfo* tmqGetCurResInfo(TAOS_RES* res) { + SMqRspObj* msg = (SMqRspObj*)res; + int32_t resIter = msg->resIter == -1 ? 0 : msg->resIter; + return (SReqResultInfo*)taosArrayGet(msg->res, resIter); +} + +static FORCE_INLINE SReqResultInfo* tmqGetNextResInfo(TAOS_RES* res) { + SMqRspObj* msg = (SMqRspObj*)res; + if (++msg->resIter < taosArrayGetSize(msg->res)) { + return (SReqResultInfo*)taosArrayGet(msg->res, msg->resIter); + } + return NULL; +} + +static FORCE_INLINE SReqResultInfo* tscGetCurResInfo(TAOS_RES* res) { + if (TD_RES_QUERY(res)) return &(((SRequestObj*)res)->body.resInfo); + return tmqGetCurResInfo(res); +} + extern SAppInfo appInfo; extern int32_t clientReqRefPool; extern int32_t clientConnRefPool; @@ -236,16 +277,19 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet); void initMsgHandleFp(); TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db, - uint16_t port); - -void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr); + uint16_t port, int connType); -int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows); +int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery); +int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList); int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest); -int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery); -int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList); +void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4); +void doSetOneRowPtr(SReqResultInfo* pResultInfo); +int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows, + bool convertUcs4); +void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols); +int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4); // --- heartbeat // global, called by mgmt diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 769870ada8b4338ec6391d2483ce3da753c83dc6..fec6c8e5db5d53e15f46b506aff9bcf1c1807246 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -65,10 +65,10 @@ static void deregisterRequest(SRequestObj *pRequest) { int32_t currentInst = atomic_sub_fetch_64(&pActivity->currentRequests, 1); int32_t num = atomic_sub_fetch_32(&pTscObj->numOfReqs, 1); - int64_t duration = taosGetTimestampMs() - pRequest->metric.start; + int64_t duration = taosGetTimestampUs() - pRequest->metric.start; tscDebug("0x%" PRIx64 " free Request from connObj: 0x%" PRIx64 ", reqId:0x%" PRIx64 " elapsed:%" PRIu64 " ms, current:%d, app current:%d", - pRequest->self, pTscObj->id, pRequest->requestId, duration, num, currentInst); + pRequest->self, pTscObj->id, pRequest->requestId, duration/1000, num, currentInst); taosReleaseRef(clientConnRefPool, pTscObj->id); } @@ -149,9 +149,10 @@ void *createRequest(STscObj *pObj, __taos_async_fn_t fp, void *param, int32_t ty return NULL; } + pRequest->resType = RES_TYPE__QUERY; pRequest->pDb = getDbOfConnection(pObj); pRequest->requestId = generateRequestId(); - pRequest->metric.start = taosGetTimestampMs(); + pRequest->metric.start = taosGetTimestampUs(); pRequest->type = type; pRequest->pTscObj = pObj; diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index abb6e7fbd1921fc8f1a04105f043392da249f1f0..82788b2e112efb5c8baa9cb01f93052045dba451 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -23,6 +23,8 @@ static SClientHbMgr clientHbMgr = {0}; static int32_t hbCreateThread(); static void hbStopThread(); +static int32_t hbMqHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req) { return 0; } + static int32_t hbMqHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) { return 0; } static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog *pCatalog) { @@ -297,11 +299,10 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req return TSDB_CODE_SUCCESS; } -int32_t hbMqHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req) { return 0; } - void hbMgrInitMqHbHandle() { clientHbMgr.reqHandle[HEARTBEAT_TYPE_QUERY] = hbQueryHbReqHandle; clientHbMgr.reqHandle[HEARTBEAT_TYPE_MQ] = hbMqHbReqHandle; + clientHbMgr.rspHandle[HEARTBEAT_TYPE_QUERY] = hbQueryHbRspHandle; clientHbMgr.rspHandle[HEARTBEAT_TYPE_MQ] = hbMqHbRspHandle; } @@ -435,11 +436,11 @@ static int32_t hbCreateThread() { taosThreadAttrInit(&thAttr); taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); -// if (taosThreadCreate(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) { -// terrno = TAOS_SYSTEM_ERROR(errno); -// return -1; -// } -// taosThreadAttrDestroy(&thAttr); + if (taosThreadCreate(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + taosThreadAttrDestroy(&thAttr); return 0; } @@ -500,8 +501,6 @@ SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) { } void appHbMgrCleanup(void) { - taosThreadMutexLock(&clientHbMgr.lock); - int sz = taosArrayGetSize(clientHbMgr.appHbMgrs); for (int i = 0; i < sz; i++) { SAppHbMgr *pTarget = taosArrayGetP(clientHbMgr.appHbMgrs, i); @@ -510,8 +509,6 @@ void appHbMgrCleanup(void) { taosHashCleanup(pTarget->connInfo); pTarget->connInfo = NULL; } - - taosThreadMutexUnlock(&clientHbMgr.lock); } int hbMgrInit() { @@ -532,7 +529,6 @@ int hbMgrInit() { } void hbMgrCleanUp() { -#if 0 hbStopThread(); // destroy all appHbMgr @@ -545,7 +541,6 @@ void hbMgrCleanUp() { taosThreadMutexUnlock(&clientHbMgr.lock); clientHbMgr.appHbMgrs = NULL; -#endif } int hbRegisterConnImpl(SAppHbMgr *pAppHbMgr, SClientHbKey connKey, SHbConnInfo *info) { @@ -574,7 +569,7 @@ int hbRegisterConnImpl(SAppHbMgr *pAppHbMgr, SClientHbKey connKey, SHbConnInfo * int hbRegisterConn(SAppHbMgr *pAppHbMgr, int32_t connId, int64_t clusterId, int32_t hbType) { SClientHbKey connKey = { .connId = connId, - .hbType = HEARTBEAT_TYPE_QUERY, + .hbType = hbType, }; SHbConnInfo info = {0}; @@ -584,16 +579,14 @@ int hbRegisterConn(SAppHbMgr *pAppHbMgr, int32_t connId, int64_t clusterId, int3 *pClusterId = clusterId; info.param = pClusterId; - break; + return hbRegisterConnImpl(pAppHbMgr, connKey, &info); } case HEARTBEAT_TYPE_MQ: { - break; + return 0; } default: - break; + return 0; } - - return hbRegisterConnImpl(pAppHbMgr, connKey, &info); } void hbDeregisterConn(SAppHbMgr *pAppHbMgr, SClientHbKey connKey) { diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 9938a2e1b937bec598c09ea120239df051330f3f..96a7230ff3df8ef336d457b8a23231522f2ad216 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -11,9 +11,8 @@ #include "tref.h" static int32_t initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet); -static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest); +static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest, int8_t connType); static void destroySendMsgInfo(SMsgSendInfo* pMsgBody); -static int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp); static bool stringLengthCheck(const char* str, size_t maxsize) { if (str == NULL) { @@ -41,11 +40,10 @@ static char* getClusterKey(const char* user, const char* auth, const char* ip, i } static STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __taos_async_fn_t fp, void* param, - SAppInstInfo* pAppInfo); -static void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols); + SAppInstInfo* pAppInfo, int connType); TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db, - uint16_t port) { + uint16_t port, int connType) { if (taos_init() != TSDB_CODE_SUCCESS) { return NULL; } @@ -113,7 +111,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, taosThreadMutexUnlock(&appInfo.mutex); taosMemoryFreeClear(key); - return taosConnectImpl(user, &secretEncrypt[0], localDb, NULL, NULL, *pInst); + return taosConnectImpl(user, &secretEncrypt[0], localDb, NULL, NULL, *pInst, connType); } int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest) { @@ -174,9 +172,9 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery) { int32_t execLocalCmd(SRequestObj* pRequest, SQuery* pQuery) { SRetrieveTableRsp* pRsp = NULL; - int32_t code = qExecCommand(pQuery->pRoot, &pRsp); + int32_t code = qExecCommand(pQuery->pRoot, &pRsp); if (TSDB_CODE_SUCCESS == code && NULL != pRsp) { - code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp); + code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp, false); } return code; } @@ -190,18 +188,11 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { SCmdMsgInfo* pMsgInfo = pQuery->pCmdMsg; pRequest->type = pMsgInfo->msgType; pRequest->body.requestMsg = (SDataBuf){.pData = pMsgInfo->pMsg, .len = pMsgInfo->msgLen, .handle = NULL}; - pMsgInfo->pMsg = NULL; // pMsg transferred to SMsgSendInfo management + pMsgInfo->pMsg = NULL; // pMsg transferred to SMsgSendInfo management STscObj* pTscObj = pRequest->pTscObj; SMsgSendInfo* pSendMsg = buildMsgInfoImpl(pRequest); - if (pMsgInfo->msgType == TDMT_VND_SHOW_TABLES) { - SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo; - if (pShowReqInfo->pArray == NULL) { - pShowReqInfo->currentIndex = 0; // set the first vnode/ then iterate the next vnode - pShowReqInfo->pArray = pMsgInfo->pExtension; - } - } int64_t transporterId = 0; asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pMsgInfo->epSet, &transporterId, pSendMsg); @@ -211,14 +202,12 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList) { pRequest->type = pQuery->msgType; - SPlanContext cxt = { - .queryId = pRequest->requestId, - .acctId = pRequest->pTscObj->acctId, - .mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp), - .pAstRoot = pQuery->pRoot, - .showRewrite = pQuery->showRewrite - }; - int32_t code = qCreateQueryPlan(&cxt, pPlan, pNodeList); + SPlanContext cxt = {.queryId = pRequest->requestId, + .acctId = pRequest->pTscObj->acctId, + .mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp), + .pAstRoot = pQuery->pRoot, + .showRewrite = pQuery->showRewrite}; + int32_t code = qCreateQueryPlan(&cxt, pPlan, pNodeList); if (code != 0) { return code; } @@ -234,10 +223,10 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t for (int32_t i = 0; i < pResInfo->numOfCols; ++i) { pResInfo->fields[i].bytes = pSchema[i].bytes; - pResInfo->fields[i].type = pSchema[i].type; + pResInfo->fields[i].type = pSchema[i].type; pResInfo->userFields[i].bytes = pSchema[i].bytes; - pResInfo->userFields[i].type = pSchema[i].type; + pResInfo->userFields[i].type = pSchema[i].type; if (pSchema[i].type == TSDB_DATA_TYPE_VARCHAR) { pResInfo->userFields[i].bytes -= VARSTR_HEADER_SIZE; @@ -254,7 +243,8 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter; SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf}; - int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr, pRequest->metric.start, &res); + int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr, + pRequest->metric.start, &res); if (code != TSDB_CODE_SUCCESS) { if (pRequest->body.queryJob != 0) { schedulerFreeJob(pRequest->body.queryJob); @@ -274,14 +264,14 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList } pRequest->code = res.code; - terrno = res.code; + terrno = res.code; return pRequest->code; } SRequestObj* execQueryImpl(STscObj* pTscObj, const char* sql, int sqlLen) { SRequestObj* pRequest = NULL; - SQuery* pQuery = NULL; - SArray* pNodeList = taosArrayInit(4, sizeof(struct SQueryNodeAddr)); + SQuery* pQuery = NULL; + SArray* pNodeList = taosArrayInit(4, sizeof(struct SQueryNodeAddr)); int32_t code = buildRequest(pTscObj, sql, sqlLen, &pRequest); if (TSDB_CODE_SUCCESS == code) { @@ -320,15 +310,15 @@ SRequestObj* execQueryImpl(STscObj* pTscObj, const char* sql, int sqlLen) { } int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) { - SCatalog *pCatalog = NULL; - int32_t code = 0; - int32_t dbNum = taosArrayGetSize(pRequest->dbList); - int32_t tblNum = taosArrayGetSize(pRequest->tableList); + SCatalog* pCatalog = NULL; + int32_t code = 0; + int32_t dbNum = taosArrayGetSize(pRequest->dbList); + int32_t tblNum = taosArrayGetSize(pRequest->tableList); if (dbNum <= 0 && tblNum <= 0) { return TSDB_CODE_QRY_APP_ERROR; } - + code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCatalog); if (code != TSDB_CODE_SUCCESS) { return code; @@ -337,8 +327,8 @@ int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) { SEpSet epset = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); for (int32_t i = 0; i < dbNum; ++i) { - char *dbFName = taosArrayGet(pRequest->dbList, i); - + char* dbFName = taosArrayGet(pRequest->dbList, i); + code = catalogRefreshDBVgInfo(pCatalog, pTscObj->pAppInfo->pTransporter, &epset, dbFName); if (code != TSDB_CODE_SUCCESS) { return code; @@ -346,7 +336,7 @@ int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) { } for (int32_t i = 0; i < tblNum; ++i) { - SName *tableName = taosArrayGet(pRequest->tableList, i); + SName* tableName = taosArrayGet(pRequest->tableList, i); code = catalogRefreshTableMeta(pCatalog, pTscObj->pAppInfo->pTransporter, &epset, tableName, -1); if (code != TSDB_CODE_SUCCESS) { @@ -357,11 +347,10 @@ int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) { return code; } - SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen) { SRequestObj* pRequest = NULL; - int32_t retryNum = 0; - int32_t code = 0; + int32_t retryNum = 0; + int32_t code = 0; while (retryNum++ < REQUEST_MAX_TRY_TIMES) { pRequest = execQueryImpl(pTscObj, sql, sqlLen); @@ -377,7 +366,7 @@ SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen) { destroyRequest(pRequest); } - + return pRequest; } @@ -429,7 +418,7 @@ int initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSe } STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __taos_async_fn_t fp, void* param, - SAppInstInfo* pAppInfo) { + SAppInstInfo* pAppInfo, int connType) { STscObj* pTscObj = createTscObj(user, auth, db, pAppInfo); if (NULL == pTscObj) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -443,7 +432,7 @@ STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __t return NULL; } - SMsgSendInfo* body = buildConnectMsg(pRequest); + SMsgSendInfo* body = buildConnectMsg(pRequest, connType); int64_t transporterId = 0; asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body); @@ -466,7 +455,7 @@ STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __t return pTscObj; } -static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest) { +static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest, int8_t connType) { SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); if (pMsgSendInfo == NULL) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -489,6 +478,7 @@ static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest) { } taosMemoryFreeClear(db); + connectReq.connType = connType; connectReq.pid = htonl(appInfo.pid); connectReq.startTime = htobe64(appInfo.startTime); tstrncpy(connectReq.app, appInfo.appName, sizeof(connectReq.app)); @@ -509,7 +499,8 @@ static void destroySendMsgInfo(SMsgSendInfo* pMsgBody) { } bool persistConnForSpecificMsg(void* parenct, tmsg_t msgType) { - return msgType == TDMT_VND_QUERY_RSP || msgType == TDMT_VND_FETCH_RSP || msgType == TDMT_VND_RES_READY_RSP || msgType == TDMT_VND_QUERY_HEARTBEAT_RSP; + return msgType == TDMT_VND_QUERY_RSP || msgType == TDMT_VND_FETCH_RSP || msgType == TDMT_VND_RES_READY_RSP || + msgType == TDMT_VND_QUERY_HEARTBEAT_RSP; } void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { @@ -520,7 +511,7 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { SRequestObj* pRequest = (SRequestObj*)taosAcquireRef(clientReqRefPool, pSendInfo->requestObjRefId); assert(pRequest->self == pSendInfo->requestObjRefId); - pRequest->metric.rsp = taosGetTimestampMs(); + pRequest->metric.rsp = taosGetTimestampUs(); STscObj* pTscObj = pRequest->pTscObj; if (pEpSet) { @@ -536,10 +527,10 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { int32_t elapsed = pRequest->metric.rsp - pRequest->metric.start; if (pMsg->code == TSDB_CODE_SUCCESS) { tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%d ms, reqId:0x%" PRIx64, pRequest->self, - TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId); + TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed / 1000, pRequest->requestId); } else { tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%d ms, reqId:0x%" PRIx64, pRequest->self, - TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId); + TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed / 1000, pRequest->requestId); } taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId); @@ -573,7 +564,7 @@ TAOS* taos_connect_auth(const char* ip, const char* user, const char* auth, cons return NULL; } - return taos_connect_internal(ip, user, NULL, auth, db, port); + return taos_connect_internal(ip, user, NULL, auth, db, port, CONN_TYPE__QUERY); } TAOS* taos_connect_l(const char* ip, int ipLen, const char* user, int userLen, const char* pass, int passLen, @@ -590,7 +581,7 @@ TAOS* taos_connect_l(const char* ip, int ipLen, const char* user, int userLen, c return taos_connect(ipStr, userStr, passStr, dbStr, port); } -static void doSetOneRowPtr(SReqResultInfo* pResultInfo) { +void doSetOneRowPtr(SReqResultInfo* pResultInfo) { for (int32_t i = 0; i < pResultInfo->numOfCols; ++i) { SResultColumn* pCol = &pResultInfo->pCol[i]; @@ -605,113 +596,52 @@ static void doSetOneRowPtr(SReqResultInfo* pResultInfo) { pResultInfo->row[i] = varDataVal(pStart); } else { pResultInfo->row[i] = NULL; + pResultInfo->length[i] = 0; } } else { if (!colDataIsNull_f(pCol->nullbitmap, pResultInfo->current)) { pResultInfo->row[i] = pResultInfo->pCol[i].pData + bytes * pResultInfo->current; + pResultInfo->length[i] = bytes; } else { pResultInfo->row[i] = NULL; + pResultInfo->length[i] = 0; } } } } -void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr) { +void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) { assert(pRequest != NULL); - SReqResultInfo* pResultInfo = &pRequest->body.resInfo; - - SEpSet epSet = {0}; + SReqResultInfo* pResultInfo = &pRequest->body.resInfo; if (pResultInfo->pData == NULL || pResultInfo->current >= pResultInfo->numOfRows) { - if (pRequest->type == TDMT_VND_QUERY) { - // All data has returned to App already, no need to try again - if (pResultInfo->completed) { - pResultInfo->numOfRows = 0; - return NULL; - } - - SReqResultInfo* pResInfo = &pRequest->body.resInfo; - pRequest->code = schedulerFetchRows(pRequest->body.queryJob, (void**)&pResInfo->pData); - if (pRequest->code != TSDB_CODE_SUCCESS) { - pResultInfo->numOfRows = 0; - return NULL; - } - - pRequest->code = setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResInfo->pData); - if (pRequest->code != TSDB_CODE_SUCCESS) { - pResultInfo->numOfRows = 0; - return NULL; - } - - tscDebug("0x%" PRIx64 " fetch results, numOfRows:%d total Rows:%" PRId64 ", complete:%d, reqId:0x%" PRIx64, - pRequest->self, pResInfo->numOfRows, pResInfo->totalRows, pResInfo->completed, pRequest->requestId); - - if (pResultInfo->numOfRows == 0) { - return NULL; - } - - goto _return; - } else if (pRequest->type == TDMT_MND_SHOW) { - pRequest->type = TDMT_MND_SHOW_RETRIEVE; - epSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp); - } else if (pRequest->type == TDMT_VND_SHOW_TABLES) { - pRequest->type = TDMT_VND_SHOW_TABLES_FETCH; - SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo; - SVgroupInfo* pVgroupInfo = taosArrayGet(pShowReqInfo->pArray, pShowReqInfo->currentIndex); - - epSet = pVgroupInfo->epSet; - } else if (pRequest->type == TDMT_VND_SHOW_TABLES_FETCH) { - pRequest->type = TDMT_VND_SHOW_TABLES; - SShowReqInfo* pShowReqInfo = &pRequest->body.showInfo; - pShowReqInfo->currentIndex += 1; - if (pShowReqInfo->currentIndex >= taosArrayGetSize(pShowReqInfo->pArray)) { - return NULL; - } - - SVgroupInfo* pVgroupInfo = taosArrayGet(pShowReqInfo->pArray, pShowReqInfo->currentIndex); - SVShowTablesReq* pShowReq = taosMemoryCalloc(1, sizeof(SVShowTablesReq)); - pShowReq->head.vgId = htonl(pVgroupInfo->vgId); - - pRequest->body.requestMsg.len = sizeof(SVShowTablesReq); - pRequest->body.requestMsg.pData = pShowReq; - - SMsgSendInfo* body = buildMsgInfoImpl(pRequest); - epSet = pVgroupInfo->epSet; - - int64_t transporterId = 0; - STscObj* pTscObj = pRequest->pTscObj; - asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, body); - tsem_wait(&pRequest->body.rspSem); - - pRequest->type = TDMT_VND_SHOW_TABLES_FETCH; - } else if (pRequest->type == TDMT_MND_SHOW_RETRIEVE) { - epSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp); - - if (pResultInfo->completed) { - return NULL; - } - } - + // All data has returned to App already, no need to try again if (pResultInfo->completed) { pResultInfo->numOfRows = 0; return NULL; } - SMsgSendInfo* body = buildMsgInfoImpl(pRequest); + SReqResultInfo* pResInfo = &pRequest->body.resInfo; + pRequest->code = schedulerFetchRows(pRequest->body.queryJob, (void**)&pResInfo->pData); + if (pRequest->code != TSDB_CODE_SUCCESS) { + pResultInfo->numOfRows = 0; + return NULL; + } - int64_t transporterId = 0; - STscObj* pTscObj = pRequest->pTscObj; - asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, body); + pRequest->code = setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResInfo->pData, convertUcs4); + if (pRequest->code != TSDB_CODE_SUCCESS) { + pResultInfo->numOfRows = 0; + return NULL; + } - tsem_wait(&pRequest->body.rspSem); + tscDebug("0x%" PRIx64 " fetch results, numOfRows:%d total Rows:%" PRId64 ", complete:%d, reqId:0x%" PRIx64, + pRequest->self, pResInfo->numOfRows, pResInfo->totalRows, pResInfo->completed, pRequest->requestId); - pResultInfo->current = 0; - if (pResultInfo->numOfRows <= pResultInfo->current) { + if (pResultInfo->numOfRows == 0) { return NULL; } } -_return: if (setupOneRowPtr) { doSetOneRowPtr(pResultInfo); pResultInfo->current += 1; @@ -722,8 +652,8 @@ _return: static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) { if (pResInfo->row == NULL) { - pResInfo->row = taosMemoryCalloc(pResInfo->numOfCols, POINTER_BYTES); - pResInfo->pCol = taosMemoryCalloc(pResInfo->numOfCols, sizeof(SResultColumn)); + pResInfo->row = taosMemoryCalloc(pResInfo->numOfCols, POINTER_BYTES); + pResInfo->pCol = taosMemoryCalloc(pResInfo->numOfCols, sizeof(SResultColumn)); pResInfo->length = taosMemoryCalloc(pResInfo->numOfCols, sizeof(int32_t)); pResInfo->convertBuf = taosMemoryCalloc(pResInfo->numOfCols, POINTER_BYTES); @@ -735,7 +665,43 @@ static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) { return TSDB_CODE_SUCCESS; } -int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows) { +static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int32_t numOfCols, int32_t* colLength) { + for (int32_t i = 0; i < numOfCols; ++i) { + int32_t type = pResultInfo->fields[i].type; + int32_t bytes = pResultInfo->fields[i].bytes; + + if (type == TSDB_DATA_TYPE_NCHAR && colLength[i] > 0) { + char* p = taosMemoryRealloc(pResultInfo->convertBuf[i], colLength[i]); + if (p == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + pResultInfo->convertBuf[i] = p; + + SResultColumn* pCol = &pResultInfo->pCol[i]; + for (int32_t j = 0; j < numOfRows; ++j) { + if (pCol->offset[j] != -1) { + char* pStart = pCol->offset[j] + pCol->pData; + + int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(pStart), varDataLen(pStart), varDataVal(p)); + ASSERT(len <= bytes); + + varDataSetLen(p, len); + pCol->offset[j] = (p - pResultInfo->convertBuf[i]); + p += (len + VARSTR_HEADER_SIZE); + } + } + + pResultInfo->pCol[i].pData = pResultInfo->convertBuf[i]; + pResultInfo->row[i] = pResultInfo->pCol[i].pData; + } + } + + return TSDB_CODE_SUCCESS; +} + +int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows, + bool convertUcs4) { assert(numOfCols > 0 && pFields != NULL && pResultInfo != NULL); if (numOfRows == 0) { return TSDB_CODE_SUCCESS; @@ -767,37 +733,11 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32 } // convert UCS4-LE encoded character to native multi-bytes character in current data block. - for (int32_t i = 0; i < numOfCols; ++i) { - int32_t type = pResultInfo->fields[i].type; - int32_t bytes = pResultInfo->fields[i].bytes; - - if (type == TSDB_DATA_TYPE_NCHAR) { - char* p = taosMemoryRealloc(pResultInfo->convertBuf[i], colLength[i]); - if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pResultInfo->convertBuf[i] = p; - - SResultColumn* pCol = &pResultInfo->pCol[i]; - for (int32_t j = 0; j < numOfRows; ++j) { - if (pCol->offset[j] != -1) { - pStart = pCol->offset[j] + pCol->pData; - - int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(pStart), varDataLen(pStart), varDataVal(p)); - ASSERT(len <= bytes); - - varDataSetLen(p, len); - pCol->offset[j] = (p - pResultInfo->convertBuf[i]); - p += (len + VARSTR_HEADER_SIZE); - } - } - - pResultInfo->pCol[i].pData = pResultInfo->convertBuf[i]; - pResultInfo->row[i] = pResultInfo->pCol[i].pData; - } + if (convertUcs4) { + code = doConvertUCS4(pResultInfo, numOfRows, numOfCols, colLength); } - return TSDB_CODE_SUCCESS; + return code; } char* getDbOfConnection(STscObj* pObj) { @@ -829,18 +769,19 @@ void resetConnectDB(STscObj* pTscObj) { taosThreadMutexUnlock(&pTscObj->mutex); } -int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp) { +int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4) { assert(pResultInfo != NULL && pRsp != NULL); - pResultInfo->pRspMsg = (const char*)pRsp; - pResultInfo->pData = (void*)pRsp->data; - pResultInfo->numOfRows = htonl(pRsp->numOfRows); - pResultInfo->current = 0; - pResultInfo->completed = (pRsp->completed == 1); + pResultInfo->pRspMsg = (const char*)pRsp; + pResultInfo->pData = (void*)pRsp->data; + pResultInfo->numOfRows = htonl(pRsp->numOfRows); + pResultInfo->current = 0; + pResultInfo->completed = (pRsp->completed == 1); pResultInfo->payloadLen = htonl(pRsp->compLen); - pResultInfo->precision = pRsp->precision; + pResultInfo->precision = pRsp->precision; // TODO handle the compressed case pResultInfo->totalRows += pResultInfo->numOfRows; - return setResultDataPtr(pResultInfo, pResultInfo->fields, pResultInfo->numOfCols, pResultInfo->numOfRows); + return setResultDataPtr(pResultInfo, pResultInfo->fields, pResultInfo->numOfCols, pResultInfo->numOfRows, + convertUcs4); } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index e10cf5179e4da9af768141ee8b37ca48545f4895..42d204284e8693538ab64a4135d3d08066d8d37d 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -71,7 +71,7 @@ void taos_cleanup(void) { tscInfo("all local resources released"); } -setConfRet taos_set_config(const char *config) { +setConfRet taos_set_config(const char *config) { // TODO setConfRet ret = {SET_CONF_RET_SUCC, {0}}; return ret; @@ -87,7 +87,7 @@ TAOS *taos_connect(const char *ip, const char *user, const char *pass, const cha pass = TSDB_DEFAULT_PASS; } - return taos_connect_internal(ip, user, pass, NULL, db, port); + return taos_connect_internal(ip, user, pass, NULL, db, port, CONN_TYPE__QUERY); } void taos_close(TAOS *taos) { @@ -124,8 +124,10 @@ const char *taos_errstr(TAOS_RES *res) { } void taos_free_result(TAOS_RES *res) { - SRequestObj *pRequest = (SRequestObj *)res; - destroyRequest(pRequest); + if (TD_RES_QUERY(res)) { + SRequestObj *pRequest = (SRequestObj *)res; + destroyRequest(pRequest); + } } int taos_field_count(TAOS_RES *res) { @@ -133,8 +135,7 @@ int taos_field_count(TAOS_RES *res) { return 0; } - SRequestObj *pRequest = (SRequestObj *)res; - SReqResultInfo *pResInfo = &pRequest->body.resInfo; + SReqResultInfo *pResInfo = tscGetCurResInfo(res); return pResInfo->numOfCols; } @@ -145,7 +146,7 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) { return NULL; } - SReqResultInfo *pResInfo = &(((SRequestObj *)res)->body.resInfo); + SReqResultInfo *pResInfo = tscGetCurResInfo(res); return pResInfo->userFields; } @@ -162,13 +163,40 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { return NULL; } - SRequestObj *pRequest = (SRequestObj *)res; - if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT || - pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) { - return NULL; - } + if (TD_RES_QUERY(res)) { + SRequestObj *pRequest = (SRequestObj *)res; + if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT || + pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) { + return NULL; + } - return doFetchRow(pRequest, true); + return doFetchRows(pRequest, true, true); + + } else if (TD_RES_TMQ(res)) { + SMqRspObj *msg = ((SMqRspObj *)res); + if (msg->resIter == -1) msg->resIter++; + SReqResultInfo *pResultInfo = taosArrayGet(msg->res, msg->resIter); + if (pResultInfo->current < pResultInfo->numOfRows) { + doSetOneRowPtr(pResultInfo); + pResultInfo->current += 1; + return pResultInfo->row; + } else { + msg->resIter++; + if (msg->resIter < taosArrayGetSize(msg->res)) { + pResultInfo = taosArrayGet(msg->res, msg->resIter); + doSetOneRowPtr(pResultInfo); + pResultInfo->current += 1; + return pResultInfo->row; + } else { + return NULL; + } + } + + } else { + // assert to avoid uninitialization error + ASSERT(0); + } + return NULL; } int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) { @@ -260,12 +288,12 @@ int *taos_fetch_lengths(TAOS_RES *res) { return NULL; } - return ((SRequestObj *)res)->body.resInfo.length; + SReqResultInfo *pResInfo = tscGetCurResInfo(res); + return pResInfo->length; } TAOS_ROW *taos_result_block(TAOS_RES *res) { - SRequestObj* pRequest = (SRequestObj*) res; - if (pRequest == NULL) { + if (res == NULL) { terrno = TSDB_CODE_INVALID_PARA; return NULL; } @@ -274,7 +302,8 @@ TAOS_ROW *taos_result_block(TAOS_RES *res) { return NULL; } - return &pRequest->body.resInfo.row; + SReqResultInfo *pResInfo = tscGetCurResInfo(res); + return &pResInfo->row; } // todo intergrate with tDataTypes @@ -313,7 +342,7 @@ const char *taos_data_type(int type) { const char *taos_get_client_info() { return version; } int taos_affected_rows(TAOS_RES *res) { - if (res == NULL) { + if (res == NULL || TD_RES_TMQ(res)) { return 0; } @@ -323,12 +352,17 @@ int taos_affected_rows(TAOS_RES *res) { } int taos_result_precision(TAOS_RES *res) { - SRequestObj* pRequest = (SRequestObj*) res; - if (pRequest == NULL) { + if (res == NULL) { return TSDB_TIME_PRECISION_MILLI; } - - return pRequest->body.resInfo.precision; + if (TD_RES_QUERY(res)) { + SRequestObj *pRequest = (SRequestObj *)res; + return pRequest->body.resInfo.precision; + } else if (TD_RES_TMQ(res)) { + SReqResultInfo *info = tmqGetCurResInfo(res); + return info->precision; + } + return TSDB_TIME_PRECISION_MILLI; } int taos_select_db(TAOS *taos, const char *db) { @@ -370,90 +404,117 @@ void taos_stop_query(TAOS_RES *res) { } bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) { - SRequestObj *pRequestObj = res; - SReqResultInfo *pResultInfo = &pRequestObj->body.resInfo; + SReqResultInfo *pResultInfo = tscGetCurResInfo(res); if (col >= pResultInfo->numOfCols || col < 0 || row >= pResultInfo->numOfRows || row < 0) { return true; } - SResultColumn *pCol = &pRequestObj->body.resInfo.pCol[col]; - return colDataIsNull_f(pCol->nullbitmap, row); + SResultColumn *pCol = &pResultInfo->pCol[col]; + if (IS_VAR_DATA_TYPE(pResultInfo->fields[col].type)) { + return (pCol->offset[row] == -1); + } else { + return colDataIsNull_f(pCol->nullbitmap, row); + } } -bool taos_is_update_query(TAOS_RES *res) { - return taos_num_fields(res) == 0; -} +bool taos_is_update_query(TAOS_RES *res) { return taos_num_fields(res) == 0; } int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { int32_t numOfRows = 0; - /*int32_t code = */taos_fetch_block_s(res, &numOfRows, rows); + /*int32_t code = */ taos_fetch_block_s(res, &numOfRows, rows); return numOfRows; } -int taos_fetch_block_s(TAOS_RES *res, int* numOfRows, TAOS_ROW *rows) { - SRequestObj *pRequest = (SRequestObj *)res; - if (pRequest == NULL) { +int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) { + if (res == NULL) { return 0; } + if (TD_RES_QUERY(res)) { + SRequestObj *pRequest = (SRequestObj *)res; - (*rows) = NULL; - (*numOfRows) = 0; + (*rows) = NULL; + (*numOfRows) = 0; - if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT || - pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) { - return 0; - } + if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT || + pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) { + return 0; + } - doFetchRow(pRequest, false); + doFetchRows(pRequest, false, true); - // TODO refactor - SReqResultInfo *pResultInfo = &pRequest->body.resInfo; - pResultInfo->current = pResultInfo->numOfRows; + // TODO refactor + SReqResultInfo *pResultInfo = &pRequest->body.resInfo; + pResultInfo->current = pResultInfo->numOfRows; - (*rows) = pResultInfo->row; - (*numOfRows) = pResultInfo->numOfRows; - return pRequest->code; + (*rows) = pResultInfo->row; + (*numOfRows) = pResultInfo->numOfRows; + return pRequest->code; + } else if (TD_RES_TMQ(res)) { + SReqResultInfo *pResultInfo = tmqGetNextResInfo(res); + if (pResultInfo == NULL) return -1; + + pResultInfo->current = pResultInfo->numOfRows; + (*rows) = pResultInfo->row; + (*numOfRows) = pResultInfo->numOfRows; + return 0; + } else { + ASSERT(0); + return -1; + } } -int taos_fetch_raw_block(TAOS_RES *res, int* numOfRows, void** pData) { - SRequestObj *pRequest = (SRequestObj *)res; - if (pRequest == NULL) { +int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) { + if (res == NULL) { + return 0; + } + if (TD_RES_TMQ(res)) { + SReqResultInfo *pResultInfo = tmqGetNextResInfo(res); + if (pResultInfo == NULL) { + (*numOfRows) = 0; + return 0; + } + + pResultInfo->current = pResultInfo->numOfRows; + (*numOfRows) = pResultInfo->numOfRows; + (*pData) = (void *)pResultInfo->pData; return 0; } + SRequestObj *pRequest = (SRequestObj *)res; + if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || pRequest->type == TSDB_SQL_INSERT || pRequest->code != TSDB_CODE_SUCCESS || taos_num_fields(res) == 0) { return 0; } - doFetchRow(pRequest, false); + doFetchRows(pRequest, false, false); SReqResultInfo *pResultInfo = &pRequest->body.resInfo; pResultInfo->current = pResultInfo->numOfRows; (*numOfRows) = pResultInfo->numOfRows; - (*pData) = (void*) pResultInfo->pData; + (*pData) = (void *)pResultInfo->pData; return 0; } int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) { - SRequestObj *pRequest = (SRequestObj *)res; - if (pRequest == NULL) { + if (res == NULL) { return 0; } - int32_t numOfFields = taos_num_fields(pRequest); + int32_t numOfFields = taos_num_fields(res); if (columnIndex < 0 || columnIndex >= numOfFields || numOfFields == 0) { return 0; } - TAOS_FIELD* pField = &pRequest->body.resInfo.userFields[columnIndex]; + SReqResultInfo *pResInfo = tscGetCurResInfo(res); + TAOS_FIELD *pField = &pResInfo->userFields[columnIndex]; if (!IS_VAR_DATA_TYPE(pField->type)) { return 0; } - return pRequest->body.resInfo.pCol[columnIndex].offset; + return pResInfo->pCol[columnIndex].offset; } int taos_validate_sql(TAOS *taos, const char *sql) { return true; } @@ -483,18 +544,19 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { // TODO } -TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char* topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval) { - // TODO - return NULL; +TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char *topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, + void *param, int interval) { + // TODO + return NULL; } TAOS_RES *taos_consume(TAOS_SUB *tsub) { - // TODO - return NULL; + // TODO + return NULL; } void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) { - // TODO + // TODO } int taos_load_table_info(TAOS *taos, const char *tableNameList) { @@ -553,26 +615,26 @@ int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name) { } int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert) { - // TODO - return -1; + // TODO + return -1; } int taos_stmt_num_params(TAOS_STMT *stmt, int *nums) { - // TODO - return -1; + // TODO + return -1; } -int taos_stmt_add_batch(TAOS_STMT* stmt) { - // TODO - return -1; +int taos_stmt_add_batch(TAOS_STMT *stmt) { + // TODO + return -1; } TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt) { - // TODO - return NULL; + // TODO + return NULL; } -int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind) { - // TODO - return -1; +int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) { + // TODO + return -1; } diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 43143917436435d735a9cdc733902e60f20457a0..67c5679cac5156b21ce0b892e6d0d824854c0f6a 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -69,9 +69,9 @@ int32_t processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) { pTscObj->pAppInfo->clusterId = connectRsp.clusterId; atomic_add_fetch_64(&pTscObj->pAppInfo->numOfConns, 1); - pTscObj->connType = HEARTBEAT_TYPE_QUERY; + pTscObj->connType = connectRsp.connType; - hbRegisterConn(pTscObj->pAppInfo->pAppHbMgr, connectRsp.connId, connectRsp.clusterId, HEARTBEAT_TYPE_QUERY); + hbRegisterConn(pTscObj->pAppInfo->pAppHbMgr, connectRsp.connId, connectRsp.clusterId, connectRsp.connType); // pRequest->body.resInfo.pRspMsg = pMsg->pData; tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, connectRsp.clusterId, @@ -90,150 +90,13 @@ SMsgSendInfo* buildMsgInfoImpl(SRequestObj *pRequest) { pMsgSendInfo->param = pRequest; pMsgSendInfo->msgType = pRequest->type; - if (pRequest->type == TDMT_MND_SHOW_RETRIEVE || pRequest->type == TDMT_VND_SHOW_TABLES_FETCH) { - if (pRequest->type == TDMT_MND_SHOW_RETRIEVE) { - SRetrieveTableReq retrieveReq = {0}; - retrieveReq.showId = pRequest->body.showInfo.execId; - - int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &retrieveReq); - void* pReq = taosMemoryMalloc(contLen); - tSerializeSRetrieveTableReq(pReq, contLen, &retrieveReq); - pMsgSendInfo->msgInfo.pData = pReq; - pMsgSendInfo->msgInfo.len = contLen; - pMsgSendInfo->msgInfo.handle = NULL; - } else { - SVShowTablesFetchReq* pFetchMsg = taosMemoryCalloc(1, sizeof(SVShowTablesFetchReq)); - if (pFetchMsg == NULL) { - return NULL; - } - - pFetchMsg->id = htobe64(pRequest->body.showInfo.execId); - pFetchMsg->head.vgId = htonl(pRequest->body.showInfo.vgId); - - pMsgSendInfo->msgInfo.pData = pFetchMsg; - pMsgSendInfo->msgInfo.len = sizeof(SVShowTablesFetchReq); - pMsgSendInfo->msgInfo.handle = NULL; - } - } else { - assert(pRequest != NULL); - pMsgSendInfo->msgInfo = pRequest->body.requestMsg; - } + assert(pRequest != NULL); + pMsgSendInfo->msgInfo = pRequest->body.requestMsg; pMsgSendInfo->fp = (handleRequestRspFp[TMSG_INDEX(pRequest->type)] == NULL)? genericRspCallback:handleRequestRspFp[TMSG_INDEX(pRequest->type)]; return pMsgSendInfo; } -int32_t processShowRsp(void* param, const SDataBuf* pMsg, int32_t code) { - SRequestObj* pRequest = param; - if (code != TSDB_CODE_SUCCESS) { - setErrno(pRequest, code); - tsem_post(&pRequest->body.rspSem); - return code; - } - - SShowRsp showRsp = {0}; - tDeserializeSShowRsp(pMsg->pData, pMsg->len, &showRsp); - STableMetaRsp *pMetaMsg = &showRsp.tableMeta; - - taosMemoryFreeClear(pRequest->body.resInfo.pRspMsg); - pRequest->body.resInfo.pRspMsg = pMsg->pData; - SReqResultInfo* pResInfo = &pRequest->body.resInfo; - - if (pResInfo->fields == NULL) { - TAOS_FIELD* pFields = taosMemoryCalloc(pMetaMsg->numOfColumns, sizeof(TAOS_FIELD)); - for (int32_t i = 0; i < pMetaMsg->numOfColumns; ++i) { - SSchema* pSchema = &pMetaMsg->pSchemas[i]; - tstrncpy(pFields[i].name, pSchema->name, tListLen(pFields[i].name)); - pFields[i].type = pSchema->type; - pFields[i].bytes = pSchema->bytes; - } - - pResInfo->fields = pFields; - } - - pResInfo->numOfCols = pMetaMsg->numOfColumns; - pRequest->body.showInfo.execId = showRsp.showId; - tFreeSShowRsp(&showRsp); - - // todo - if (pRequest->type == TDMT_VND_SHOW_TABLES) { - SShowReqInfo* pShowInfo = &pRequest->body.showInfo; - - int32_t index = pShowInfo->currentIndex; - SVgroupInfo* pInfo = taosArrayGet(pShowInfo->pArray, index); - pShowInfo->vgId = pInfo->vgId; - } - - tsem_post(&pRequest->body.rspSem); - return 0; -} - -int32_t processRetrieveMnodeRsp(void* param, const SDataBuf* pMsg, int32_t code) { - SRequestObj *pRequest = param; - SReqResultInfo *pResInfo = &pRequest->body.resInfo; - taosMemoryFreeClear(pResInfo->pRspMsg); - - if (code != TSDB_CODE_SUCCESS) { - setErrno(pRequest, code); - tsem_post(&pRequest->body.rspSem); - return code; - } - - assert(pMsg->len >= sizeof(SRetrieveTableRsp)); - - SRetrieveTableRsp *pRetrieve = (SRetrieveTableRsp *) pMsg->pData; - pRetrieve->numOfRows = htonl(pRetrieve->numOfRows); - pRetrieve->precision = htons(pRetrieve->precision); - - pResInfo->pRspMsg = pMsg->pData; - pResInfo->numOfRows = pRetrieve->numOfRows; - pResInfo->pData = pRetrieve->data; - pResInfo->completed = pRetrieve->completed; - - pResInfo->current = 0; - setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows); - - tscDebug("0x%"PRIx64" numOfRows:%d, complete:%d, qId:0x%"PRIx64, pRequest->self, pRetrieve->numOfRows, - pRetrieve->completed, pRequest->body.showInfo.execId); - - tsem_post(&pRequest->body.rspSem); - return 0; -} - -int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) { - SRequestObj* pRequest = param; - - SReqResultInfo* pResInfo = &pRequest->body.resInfo; - taosMemoryFreeClear(pResInfo->pRspMsg); - - if (code != TSDB_CODE_SUCCESS) { - setErrno(pRequest, code); - tsem_post(&pRequest->body.rspSem); - return code; - } - - assert(pMsg->len >= sizeof(SRetrieveTableRsp)); - - pResInfo->pRspMsg = pMsg->pData; - - SVShowTablesFetchRsp *pFetchRsp = (SVShowTablesFetchRsp *) pMsg->pData; - pFetchRsp->numOfRows = htonl(pFetchRsp->numOfRows); - pFetchRsp->precision = htons(pFetchRsp->precision); - - pResInfo->pRspMsg = pMsg->pData; - pResInfo->numOfRows = pFetchRsp->numOfRows; - pResInfo->pData = pFetchRsp->data; - - pResInfo->current = 0; - setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows); - - tscDebug("0x%"PRIx64" numOfRows:%d, complete:%d, qId:0x%"PRIx64, pRequest->self, pFetchRsp->numOfRows, - pFetchRsp->completed, pRequest->body.showInfo.execId); - - tsem_post(&pRequest->body.rspSem); - return 0; -} - int32_t processCreateDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { // todo rsp with the vnode id list SRequestObj* pRequest = param; @@ -256,13 +119,14 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { if (usedbRsp.vgVersion >= 0) { int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog); if (code != TSDB_CODE_SUCCESS) { - tscWarn("catalogGetHandle failed, clusterId:%"PRIx64", error:%s", pRequest->pTscObj->pAppInfo->clusterId, tstrerror(code)); + tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->pTscObj->pAppInfo->clusterId, + tstrerror(code)); } else { catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid); } } - tFreeSUsedbRsp(&usedbRsp); + tFreeSUsedbRsp(&usedbRsp); } if (code != TSDB_CODE_SUCCESS) { @@ -276,7 +140,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); SName name = {0}; - tNameFromString(&name, usedbRsp.db, T_NAME_ACCT|T_NAME_DB); + tNameFromString(&name, usedbRsp.db, T_NAME_ACCT | T_NAME_DB); SUseDbOutput output = {0}; code = queryBuildUseDbOutput(&output, &usedbRsp); @@ -288,11 +152,12 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { tscError("failed to build use db output since %s", terrstr()); } else { - struct SCatalog *pCatalog = NULL; - + struct SCatalog* pCatalog = NULL; + int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog); if (code != TSDB_CODE_SUCCESS) { - tscWarn("catalogGetHandle failed, clusterId:%"PRIx64", error:%s", pRequest->pTscObj->pAppInfo->clusterId, tstrerror(code)); + tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->pTscObj->pAppInfo->clusterId, + tstrerror(code)); } else { catalogUpdateDBVgInfo(pCatalog, output.db, output.dbId, output.dbVgroup); } @@ -420,13 +285,8 @@ void initMsgHandleFp() { #endif handleRequestRspFp[TMSG_INDEX(TDMT_MND_CONNECT)] = processConnectRsp; - handleRequestRspFp[TMSG_INDEX(TDMT_MND_SHOW)] = processShowRsp; - handleRequestRspFp[TMSG_INDEX(TDMT_MND_SHOW_RETRIEVE)] = processRetrieveMnodeRsp; handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_DB)] = processCreateDbRsp; handleRequestRspFp[TMSG_INDEX(TDMT_MND_USE_DB)] = processUseDbRsp; handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_STB)] = processCreateTableRsp; handleRequestRspFp[TMSG_INDEX(TDMT_MND_DROP_DB)] = processDropDbRsp; - - handleRequestRspFp[TMSG_INDEX(TDMT_VND_SHOW_TABLES)] = processShowRsp; - handleRequestRspFp[TMSG_INDEX(TDMT_VND_SHOW_TABLES_FETCH)] = processRetrieveVndRsp; } diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 955e25fd71c9f4ff353b7f12ffbf3ea117ddba6d..478e328a165e04903544590bdb48b4303b5cef74 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -17,27 +17,32 @@ #include "clientLog.h" #include "parser.h" #include "planner.h" -#include "scheduler.h" #include "tdatablock.h" #include "tdef.h" #include "tglobal.h" #include "tmsgtype.h" -#include "tpagedbuf.h" #include "tqueue.h" #include "tref.h" -typedef struct { - int32_t curBlock; - int32_t curRow; - void** uData; -} SMqRowIter; - struct tmq_message_t { SMqPollRsp msg; - void* vg; - SMqRowIter iter; + char* topic; + SArray* res; // SArray + int32_t vgId; + int32_t resIter; }; +typedef struct { + int8_t tmqRspType; + int32_t epoch; +} SMqRspWrapper; + +typedef struct { + int8_t tmqRspType; + int32_t epoch; + SMqCMGetSubEpRsp msg; +} SMqAskEpRspWrapper; + struct tmq_list_t { SArray container; }; @@ -114,16 +119,24 @@ typedef struct { typedef struct { // subscribe info - int32_t sqlLen; - char* sql; - char* topicName; - int64_t topicId; - SArray* vgs; // SArray - int8_t isSchemaAdaptive; - int32_t numOfFields; - TAOS_FIELD* fields; + int32_t sqlLen; + char* sql; + char* topicName; + int64_t topicId; + SArray* vgs; // SArray + int8_t isSchemaAdaptive; + int32_t numOfFields; + SSchemaWrapper schema; } SMqClientTopic; +typedef struct { + int8_t tmqRspType; + int32_t epoch; + SMqClientVg* vgHandle; + SMqClientTopic* topicHandle; + SMqPollRspV2 msg; +} SMqPollRspWrapper; + typedef struct { tmq_t* tmq; tsem_t rspSem; @@ -139,10 +152,10 @@ typedef struct { typedef struct { tmq_t* tmq; SMqClientVg* pVg; + SMqClientTopic* pTopic; int32_t epoch; int32_t vgId; tsem_t rspSem; - tmq_message_t** msg; int32_t sync; } SMqPollCbParam; @@ -250,7 +263,7 @@ static int32_t tmqMakeTopicVgKey(char* dst, const char* topicName, int32_t vg) { } void tmqClearUnhandleMsg(tmq_t* tmq) { - tmq_message_t* msg = NULL; + SMqRspWrapper* msg = NULL; while (1) { taosGetQitem(tmq->qall, (void**)&msg); if (msg) @@ -344,7 +357,15 @@ tmq_t* tmq_consumer_new1(tmq_conf_t* conf, char* errstr, int32_t errstrLen) { if (pTmq == NULL) { return NULL; } - pTmq->pTscObj = taos_connect(conf->ip, conf->user, conf->pass, conf->db, conf->port); + const char* user = conf->user == NULL ? TSDB_DEFAULT_USER : conf->user; + const char* pass = conf->pass == NULL ? TSDB_DEFAULT_PASS : conf->pass; + + ASSERT(user); + ASSERT(pass); + ASSERT(conf->db); + + pTmq->pTscObj = taos_connect_internal(conf->ip, user, pass, NULL, conf->db, conf->port, CONN_TYPE__TMQ); + if (pTmq->pTscObj == NULL) return NULL; pTmq->inWaiting = 0; pTmq->status = 0; @@ -770,7 +791,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { } } - struct tm* ptm = localtime(&tt); + struct tm* ptm = taosLocalTime(&tt, NULL); size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", ptm); if (precision == TSDB_TIME_PRECISION_NANO) { @@ -783,7 +804,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { return buf; } - +#if 0 int32_t tmqGetSkipLogNum(tmq_message_t* tmq_message) { if (tmq_message == NULL) return 0; SMqPollRsp* pRsp = &tmq_message->msg; @@ -833,11 +854,13 @@ void tmqShowMsg(tmq_message_t* tmq_message) { } } } +#endif int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { /*printf("recv poll\n");*/ SMqPollCbParam* pParam = (SMqPollCbParam*)param; SMqClientVg* pVg = pParam->pVg; + SMqClientTopic* pTopic = pParam->pTopic; tmq_t* tmq = pParam->tmq; if (code != 0) { tscWarn("msg discard from vg %d, epoch %d, code:%x", pParam->vgId, pParam->epoch, code); @@ -849,7 +872,8 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { if (msgEpoch < tmqEpoch) { /*printf("discard rsp epoch %d, current epoch %d\n", msgEpoch, tmqEpoch);*/ /*tsem_post(&tmq->rspSem);*/ - tscWarn("msg discard from vg %d since from earlier epoch, rsp epoch %d, current epoch %d", pParam->vgId, msgEpoch, tmqEpoch); + tscWarn("msg discard from vg %d since from earlier epoch, rsp epoch %d, current epoch %d", pParam->vgId, msgEpoch, + tmqEpoch); return 0; } @@ -879,18 +903,22 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { #endif /*SMqConsumeRsp* pRsp = taosMemoryCalloc(1, sizeof(SMqConsumeRsp));*/ - tmq_message_t* pRsp = taosAllocateQitem(sizeof(tmq_message_t)); - if (pRsp == NULL) { + /*tmq_message_t* pRsp = taosAllocateQitem(sizeof(tmq_message_t));*/ + SMqPollRspWrapper* pRspWrapper = taosAllocateQitem(sizeof(SMqPollRspWrapper)); + if (pRspWrapper == NULL) { tscWarn("msg discard from vg %d, epoch %d since out of memory", pParam->vgId, pParam->epoch); goto CREATE_MSG_FAIL; } - memcpy(pRsp, pMsg->pData, sizeof(SMqRspHead)); - tDecodeSMqPollRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRsp->msg); - pRsp->iter.curBlock = 0; - pRsp->iter.curRow = 0; + pRspWrapper->tmqRspType = TMQ_MSG_TYPE__POLL_RSP; + pRspWrapper->vgHandle = pVg; + pRspWrapper->topicHandle = pTopic; + /*memcpy(pRsp, pMsg->pData, sizeof(SMqRspHead));*/ + memcpy(&pRspWrapper->msg, pMsg->pData, sizeof(SMqRspHead)); + tDecodeSMqPollRspV2(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRspWrapper->msg); // TODO: alloc mem /*pRsp->*/ /*printf("rsp commit off:%ld rsp off:%ld has data:%d\n", pRsp->committedOffset, pRsp->rspOffset, pRsp->numOfTopics);*/ + #if 0 if (pRsp->msg.numOfTopics == 0) { /*printf("no data\n");*/ @@ -899,11 +927,10 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { } #endif - tscDebug("consumer %ld recv poll: vg %d, req offset %ld, rsp offset %ld", tmq->consumerId, pParam->pVg->vgId, pRsp->msg.reqOffset, - pRsp->msg.rspOffset); + tscDebug("consumer %ld recv poll: vg %d, req offset %ld, rsp offset %ld", tmq->consumerId, pVg->vgId, + pRspWrapper->msg.reqOffset, pRspWrapper->msg.rspOffset); - pRsp->vg = pParam->pVg; - taosWriteQitem(tmq->mqueue, pRsp); + taosWriteQitem(tmq->mqueue, pRspWrapper); atomic_add_fetch_32(&tmq->readyRequest, 1); /*tsem_post(&tmq->rspSem);*/ return 0; @@ -921,7 +948,8 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { bool set = false; int32_t topicNumGet = taosArrayGetSize(pRsp->topics); char vgKey[TSDB_TOPIC_FNAME_LEN + 22]; - tscDebug("consumer %ld update ep epoch %d to epoch %d, topic num: %d", tmq->consumerId, tmq->epoch, epoch, topicNumGet); + tscDebug("consumer %ld update ep epoch %d to epoch %d, topic num: %d", tmq->consumerId, tmq->epoch, epoch, + topicNumGet); SArray* newTopics = taosArrayInit(topicNumGet, sizeof(SMqClientTopic)); if (newTopics == NULL) { return false; @@ -936,6 +964,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { for (int32_t i = 0; i < topicNumGet; i++) { SMqClientTopic topic = {0}; SMqSubTopicEp* pTopicEp = taosArrayGet(pRsp->topics, i); + topic.schema = pTopicEp->schema; taosHashClear(pHash); topic.topicName = strdup(pTopicEp->topic); @@ -1019,16 +1048,19 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) { } tDeleteSMqCMGetSubEpRsp(&rsp); } else { - SMqCMGetSubEpRsp* pRsp = taosAllocateQitem(sizeof(SMqCMGetSubEpRsp)); - if (pRsp == NULL) { + /*SMqCMGetSubEpRsp* pRsp = taosAllocateQitem(sizeof(SMqCMGetSubEpRsp));*/ + SMqAskEpRspWrapper* pWrapper = taosAllocateQitem(sizeof(SMqAskEpRspWrapper)); + if (pWrapper == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; code = -1; goto END; } - memcpy(pRsp, pMsg->pData, sizeof(SMqRspHead)); - tDecodeSMqCMGetSubEpRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), pRsp); + pWrapper->tmqRspType = TMQ_MSG_TYPE__EP_RSP; + pWrapper->epoch = head->epoch; + memcpy(&pWrapper->msg, pMsg->pData, sizeof(SMqRspHead)); + tDecodeSMqCMGetSubEpRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pWrapper->msg); - taosWriteQitem(tmq->mqueue, pRsp); + taosWriteQitem(tmq->mqueue, pWrapper); /*tsem_post(&tmq->rspSem);*/ } @@ -1156,6 +1188,28 @@ SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClientTo return pReq; } +SMqRspObj* tmqBuildRspFromWrapper(SMqPollRspWrapper* pWrapper) { + SMqRspObj* pRspObj = taosMemoryCalloc(1, sizeof(SMqRspObj)); + pRspObj->resType = RES_TYPE__TMQ; + pRspObj->topic = strdup(pWrapper->topicHandle->topicName); + pRspObj->resIter = -1; + pRspObj->vgId = pWrapper->vgHandle->vgId; + SMqPollRspV2* pRsp = &pWrapper->msg; + int32_t blockNum = taosArrayGetSize(pRsp->blockPos); + pRspObj->res = taosArrayInit(blockNum, sizeof(SReqResultInfo)); + for (int32_t i = 0; i < blockNum; i++) { + int32_t pos = *(int32_t*)taosArrayGet(pRsp->blockPos, i); + SRetrieveTableRsp* pRetrieve = POINTER_SHIFT(pRsp->blockData, pos); + SReqResultInfo resInfo = {0}; + resInfo.totalRows = 0; + resInfo.precision = TSDB_TIME_PRECISION_MILLI; + setResSchemaInfo(&resInfo, pWrapper->topicHandle->schema.pSchema, pWrapper->topicHandle->schema.nCols); + setQueryResultFromRsp(&resInfo, pRetrieve, true); + taosArrayPush(pRspObj->res, &resInfo); + } + return pRspObj; +} + #if 0 tmq_message_t* tmqSyncPollImpl(tmq_t* tmq, int64_t blockingTime) { tmq_message_t* msg = NULL; @@ -1262,6 +1316,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { } pParam->tmq = tmq; pParam->pVg = pVg; + pParam->pTopic = pTopic; pParam->vgId = pVg->vgId; pParam->epoch = tmq->epoch; pParam->sync = 0; @@ -1289,7 +1344,8 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { int64_t transporterId = 0; /*printf("send poll\n");*/ atomic_add_fetch_32(&tmq->waitingRequest, 1); - tscDebug("consumer %ld send poll to %s : vg %d, epoch %d, req offset %ld, reqId %lu", tmq->consumerId, pTopic->topicName, pVg->vgId, tmq->epoch, pVg->currentOffset, pReq->reqId); + tscDebug("consumer %ld send poll to %s : vg %d, epoch %d, req offset %ld, reqId %lu", tmq->consumerId, + pTopic->topicName, pVg->vgId, tmq->epoch, pVg->currentOffset, pReq->reqId); /*printf("send vg %d %ld\n", pVg->vgId, pVg->currentOffset);*/ asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &pVg->epSet, &transporterId, sendInfo); pVg->pollCnt++; @@ -1299,13 +1355,13 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { return 0; } -// return -int32_t tmqHandleNoPollRsp(tmq_t* tmq, SMqRspHead* rspHead, bool* pReset) { - if (rspHead->mqMsgType == TMQ_MSG_TYPE__EP_RSP) { +int32_t tmqHandleNoPollRsp(tmq_t* tmq, SMqRspWrapper* rspWrapper, bool* pReset) { + if (rspWrapper->tmqRspType == TMQ_MSG_TYPE__EP_RSP) { /*printf("ep %d %d\n", rspMsg->head.epoch, tmq->epoch);*/ - if (rspHead->epoch > atomic_load_32(&tmq->epoch)) { - SMqCMGetSubEpRsp* rspMsg = (SMqCMGetSubEpRsp*)rspHead; - tmqUpdateEp(tmq, rspHead->epoch, rspMsg); + if (rspWrapper->epoch > atomic_load_32(&tmq->epoch)) { + SMqAskEpRspWrapper* pEpRspWrapper = (SMqAskEpRspWrapper*)rspWrapper; + SMqCMGetSubEpRsp* rspMsg = &pEpRspWrapper->msg; + tmqUpdateEp(tmq, rspWrapper->epoch, rspMsg); /*tmqClearUnhandleMsg(tmq);*/ *pReset = true; } else { @@ -1317,41 +1373,43 @@ int32_t tmqHandleNoPollRsp(tmq_t* tmq, SMqRspHead* rspHead, bool* pReset) { return 0; } -tmq_message_t* tmqHandleAllRsp(tmq_t* tmq, int64_t blockingTime, bool pollIfReset) { +SMqRspObj* tmqHandleAllRsp(tmq_t* tmq, int64_t blockingTime, bool pollIfReset) { while (1) { - SMqRspHead* rspHead = NULL; - taosGetQitem(tmq->qall, (void**)&rspHead); - if (rspHead == NULL) { + SMqRspWrapper* rspWrapper = NULL; + taosGetQitem(tmq->qall, (void**)&rspWrapper); + if (rspWrapper == NULL) { taosReadAllQitems(tmq->mqueue, tmq->qall); - taosGetQitem(tmq->qall, (void**)&rspHead); - if (rspHead == NULL) return NULL; + taosGetQitem(tmq->qall, (void**)&rspWrapper); + if (rspWrapper == NULL) return NULL; } - if (rspHead->mqMsgType == TMQ_MSG_TYPE__POLL_RSP) { - tmq_message_t* rspMsg = (tmq_message_t*)rspHead; + if (rspWrapper->tmqRspType == TMQ_MSG_TYPE__POLL_RSP) { + SMqPollRspWrapper* pollRspWrapper = (SMqPollRspWrapper*)rspWrapper; atomic_sub_fetch_32(&tmq->readyRequest, 1); /*printf("handle poll rsp %d\n", rspMsg->head.mqMsgType);*/ - if (rspMsg->msg.head.epoch == atomic_load_32(&tmq->epoch)) { + if (pollRspWrapper->msg.head.epoch == atomic_load_32(&tmq->epoch)) { /*printf("epoch match\n");*/ - SMqClientVg* pVg = rspMsg->vg; + SMqClientVg* pVg = pollRspWrapper->vgHandle; /*printf("vg %d offset %ld up to %ld\n", pVg->vgId, pVg->currentOffset, rspMsg->msg.rspOffset);*/ - pVg->currentOffset = rspMsg->msg.rspOffset; + pVg->currentOffset = pollRspWrapper->msg.rspOffset; atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); - if (rspMsg->msg.numOfTopics == 0) { - taosFreeQitem(rspMsg); - rspHead = NULL; + if (pollRspWrapper->msg.dataLen == 0) { + taosFreeQitem(pollRspWrapper); + rspWrapper = NULL; continue; } - return rspMsg; + // build rsp + SMqRspObj* pRsp = tmqBuildRspFromWrapper(pollRspWrapper); + return pRsp; } else { /*printf("epoch mismatch\n");*/ - taosFreeQitem(rspMsg); + taosFreeQitem(pollRspWrapper); } } else { /*printf("handle ep rsp %d\n", rspMsg->head.mqMsgType);*/ bool reset = false; - tmqHandleNoPollRsp(tmq, rspHead, &reset); - taosFreeQitem(rspHead); + tmqHandleNoPollRsp(tmq, rspWrapper, &reset); + taosFreeQitem(rspWrapper); if (pollIfReset && reset) { tscDebug("consumer %ld reset and repoll", tmq->consumerId); tmqPollImpl(tmq, blockingTime); @@ -1385,17 +1443,17 @@ tmq_message_t* tmq_consumer_poll_v1(tmq_t* tmq, int64_t blocking_time) { } #endif -tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) { - tmq_message_t* rspMsg; - int64_t startTime = taosGetTimestampMs(); +TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) { + SMqRspObj* rspObj; + int64_t startTime = taosGetTimestampMs(); // TODO: put into another thread or delayed queue int64_t status = atomic_load_64(&tmq->status); tmqAskEp(tmq, status == TMQ_CONSUMER_STATUS__INIT); - rspMsg = tmqHandleAllRsp(tmq, blocking_time, false); - if (rspMsg) { - return rspMsg; + rspObj = tmqHandleAllRsp(tmq, blocking_time, false); + if (rspObj) { + return (TAOS_RES*)rspObj; } while (1) { @@ -1405,9 +1463,9 @@ tmq_message_t* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) { /*tsem_wait(&tmq->rspSem);*/ - rspMsg = tmqHandleAllRsp(tmq, blocking_time, false); - if (rspMsg) { - return rspMsg; + rspObj = tmqHandleAllRsp(tmq, blocking_time, false); + if (rspObj) { + return (TAOS_RES*)rspObj; } if (blocking_time != 0) { int64_t endTime = taosGetTimestampMs(); @@ -1549,6 +1607,7 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* tmq_topic_v } #endif +#if 0 void tmq_message_destroy(tmq_message_t* tmq_message) { if (tmq_message == NULL) return; SMqPollRsp* pRsp = &tmq_message->msg; @@ -1556,6 +1615,7 @@ void tmq_message_destroy(tmq_message_t* tmq_message) { /*taosMemoryFree(tmq_message);*/ taosFreeQitem(tmq_message); } +#endif tmq_resp_err_t tmq_consumer_close(tmq_t* tmq) { return TMQ_RESP_ERR__SUCCESS; } @@ -1566,30 +1626,27 @@ const char* tmq_err2str(tmq_resp_err_t err) { return "fail"; } -TAOS_ROW tmq_get_row(tmq_message_t* message) { - SMqPollRsp* rsp = &message->msg; - while (1) { - if (message->iter.curBlock < taosArrayGetSize(rsp->pBlockData)) { - SSDataBlock* pBlock = taosArrayGet(rsp->pBlockData, message->iter.curBlock); - if (message->iter.curRow < pBlock->info.rows) { - for (int i = 0; i < pBlock->info.numOfCols; i++) { - SColumnInfoData* pData = taosArrayGet(pBlock->pDataBlock, i); - if (colDataIsNull_s(pData, message->iter.curRow)) - message->iter.uData[i] = NULL; - else { - message->iter.uData[i] = colDataGetData(pData, message->iter.curRow); - } - } - message->iter.curRow++; - return message->iter.uData; - } else { - message->iter.curBlock++; - message->iter.curRow = 0; - continue; - } - } +char* tmq_get_topic_name(TAOS_RES* res) { + if (TD_RES_TMQ(res)) { + SMqRspObj* pRspObj = (SMqRspObj*)res; + return pRspObj->topic; + } else { return NULL; } } -char* tmq_get_topic_name(tmq_message_t* message) { return "not implemented yet"; } +int32_t tmq_get_vgroup_id(TAOS_RES* res) { + if (TD_RES_TMQ(res)) { + SMqRspObj* pRspObj = (SMqRspObj*)res; + return pRspObj->vgId; + } else { + return -1; + } +} + +void tmq_message_destroy(TAOS_RES* res) { + if (res == NULL) return; + if (TD_RES_TMQ(res)) { + SMqRspObj* pRspObj = (SMqRspObj*)res; + } +} diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 772f9049e582577b23faffe399e9ac0961e4b9fd..2730723a1734bd37c0da324538fbba48bb4f34ec 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -400,7 +400,7 @@ TEST(testCase, show_vgroup_Test) { taos_free_result(pRes); taos_close(pConn); } -#endif + TEST(testCase, create_multiple_tables) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -459,11 +459,10 @@ TEST(testCase, create_multiple_tables) { taos_free_result(pRes); - for (int32_t i = 0; i < 25000; ++i) { + for (int32_t i = 0; i < 500; i += 2) { char sql[512] = {0}; snprintf(sql, tListLen(sql), - "create table t_x_%d using st1 tags(2) t_x_%d using st1 tags(5) t_x_%d using st1 tags(911)", i, - (i + 1) * 30, (i + 2) * 40); + "create table t_x_%d using st1 tags(2) t_x_%d using st1 tags(5)", i, i + 1); TAOS_RES* pres = taos_query(pConn, sql); if (taos_errno(pres) != 0) { printf("failed to create table %d\n, reason:%s", i, taos_errstr(pres)); @@ -654,6 +653,8 @@ TEST(testCase, projection_query_stables) { taos_close(pConn); } +#endif + TEST(testCase, agg_query_tables) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(pConn, nullptr); @@ -661,7 +662,7 @@ TEST(testCase, agg_query_tables) { TAOS_RES* pRes = taos_query(pConn, "use abc1"); taos_free_result(pRes); - pRes = taos_query(pConn, "select count(*) from tu"); + pRes = taos_query(pConn, "select * from test_block_raw.all_type"); if (taos_errno(pRes) != 0) { printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); @@ -672,10 +673,21 @@ TEST(testCase, agg_query_tables) { TAOS_FIELD* pFields = taos_fetch_fields(pRes); int32_t numOfFields = taos_num_fields(pRes); + int32_t n = 0; + void* data = NULL; + int32_t code = taos_fetch_raw_block(pRes, &n, &data); + char str[512] = {0}; while ((pRow = taos_fetch_row(pRes)) != NULL) { + int32_t* length = taos_fetch_lengths(pRes); + for(int32_t i = 0; i < numOfFields; ++i) { + printf("(%d):%d " , i, length[i]); + } + printf("\n"); + int32_t code = taos_print_row(str, pRow, pFields, numOfFields); printf("%s\n", str); + memset(str, 0, sizeof(str)); } taos_free_result(pRes); diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 053a1a1ee6a802da00350cc08b429191d6ffd894..beabc1b6eb276b06c4b3e87c917b09b11df41e29 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -1149,10 +1149,11 @@ void* blockDataDestroy(SSDataBlock* pBlock) { return NULL; } -SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock) { +SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData) { if(pDataBlock == NULL){ return NULL; } + int32_t numOfCols = pDataBlock->info.numOfCols; SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); @@ -1160,6 +1161,7 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock) { pBlock->info.numOfCols = numOfCols; pBlock->info.hasVarCol = pDataBlock->info.hasVarCol; + pBlock->info.rowSize = pDataBlock->info.rows; for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData colInfo = {0}; @@ -1168,6 +1170,23 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock) { taosArrayPush(pBlock->pDataBlock, &colInfo); } + if (copyData) { + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, i); + SColumnInfoData* pSrc = taosArrayGet(pDataBlock->pDataBlock, i); + + int32_t code = colInfoDataEnsureCapacity(pDst, pDataBlock->info.rows); + if (code != TSDB_CODE_SUCCESS) { + return NULL; + } + + colDataAssign(pDst, pSrc, pDataBlock->info.rows); + } + + pBlock->info.rows = pDataBlock->info.rows; + pBlock->info.capacity = pDataBlock->info.rows; + } + return pBlock; } @@ -1368,7 +1387,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { } } - struct tm* ptm = localtime(&tt); + struct tm* ptm = taosLocalTime(&tt, NULL); size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", ptm); if (precision == TSDB_TIME_PRECISION_NANO) { diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index f6614633fb50a4ba60534e2a785755f809563beb..f2a5a98d96c0fb524e510c3a49dd9c82f1a1dfd3 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -411,6 +411,7 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) { #endif pCols->numOfRows = 0; + pCols->bitmapMode = 0; pCols->numOfCols = schemaNCols(pSchema); for (i = 0; i < schemaNCols(pSchema); ++i) { diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 0bc1fa09f519ea49af319a8ab4a80afe5966766c..9226e9aa37e25e8ce7c8faed5345588c84229d74 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -189,7 +189,7 @@ static int32_t taosSetTfsCfg(SConfig *pCfg) { tsDiskCfgNum = 1; taosAddDataDir(0, pItem->str, 0, 1); tstrncpy(tsDataDir, pItem->str, PATH_MAX); - if (taosMkDir(tsDataDir) != 0) { + if (taosMulMkDir(tsDataDir) != 0) { uError("failed to create dataDir:%s since %s", tsDataDir, terrstr()); return -1; } @@ -200,12 +200,12 @@ static int32_t taosSetTfsCfg(SConfig *pCfg) { memcpy(&tsDiskCfg[index], pCfg, sizeof(SDiskCfg)); if (pCfg->level == 0 && pCfg->primary == 1) { tstrncpy(tsDataDir, pCfg->dir, PATH_MAX); - if (taosMkDir(tsDataDir) != 0) { + if (taosMulMkDir(tsDataDir) != 0) { uError("failed to create dataDir:%s since %s", tsDataDir, terrstr()); return -1; } } - if (taosMkDir(pCfg->dir) != 0) { + if (taosMulMkDir(pCfg->dir) != 0) { uError("failed to create tfsDir:%s since %s", tsDataDir, terrstr()); return -1; } @@ -256,7 +256,7 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e return 0; } -static int32_t taosAddClientLogCfg(SConfig *pCfg) { +int32_t taosAddClientLogCfg(SConfig *pCfg) { if (cfgAddDir(pCfg, "configDir", configDir, 1) != 0) return -1; if (cfgAddDir(pCfg, "scriptDir", configDir, 1) != 0) return -1; if (cfgAddDir(pCfg, "logDir", tsLogDir, 1) != 0) return -1; @@ -486,7 +486,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) { tstrncpy(tsTempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX); taosExpandDir(tsTempDir, tsTempDir, PATH_MAX); tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval; - if (taosMkDir(tsTempDir) != 0) { + if (taosMulMkDir(tsTempDir) != 0) { uError("failed to create tempDir:%s since %s", tsTempDir, terrstr()); return -1; } @@ -495,7 +495,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) { tsRpcTimer = cfgGetItem(pCfg, "rpcTimer")->i32; tsRpcMaxTime = cfgGetItem(pCfg, "rpcMaxTime")->i32; tsRpcForceTcp = cfgGetItem(pCfg, "rpcForceTcp")->i32; - tsShellActivityTimer = cfgGetItem(pCfg, "shellActivityTimer")->bval; + tsShellActivityTimer = cfgGetItem(pCfg, "shellActivityTimer")->i32; tsCompressMsgSize = cfgGetItem(pCfg, "compressMsgSize")->i32; tsCompressColData = cfgGetItem(pCfg, "compressColData")->i32; tsMaxWildCardsLen = cfgGetItem(pCfg, "maxWildCardsLength")->i32; @@ -616,7 +616,7 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi taosSetAllDebugFlag(cfgGetItem(pCfg, "debugFlag")->i32); - if (taosMkDir(tsLogDir) != 0) { + if (taosMulMkDir(tsLogDir) != 0) { uError("failed to create dir:%s since %s", tsLogDir, terrstr()); cfgCleanup(pCfg); return -1; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 5973a70b59c8601d1c9c3e20c897d659dc2198b3..031ebdaf49854a07e64a2d0f0feeedaea23a115f 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -308,6 +308,7 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) { tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nTagCols); for (col_id_t i = 0; i < pReq->stbCfg.nTagCols; ++i) { tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pTagSchema[i].type); + tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pTagSchema[i].index); tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pTagSchema[i].colId); tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].bytes); tlen += taosEncodeString(buf, pReq->stbCfg.pTagSchema[i].name); @@ -378,6 +379,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) { pReq->stbCfg.pTagSchema = (SSchema *)taosMemoryMalloc(pReq->stbCfg.nTagCols * sizeof(SSchema)); for (col_id_t i = 0; i < pReq->stbCfg.nTagCols; ++i) { buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pTagSchema[i].type)); + buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pTagSchema[i].index)); buf = taosDecodeFixedI16(buf, &pReq->stbCfg.pTagSchema[i].colId); buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].bytes); buf = taosDecodeStringTo(buf, pReq->stbCfg.pTagSchema[i].name); @@ -868,7 +870,7 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { // status if (tEncodeI32(&encoder, pReq->sver) < 0) return -1; - if (tEncodeI64(&encoder, pReq->dver) < 0) return -1; + if (tEncodeI64(&encoder, pReq->dnodeVer) < 0) return -1; if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1; if (tEncodeI64(&encoder, pReq->clusterId) < 0) return -1; if (tEncodeI64(&encoder, pReq->rebootTime) < 0) return -1; @@ -913,7 +915,7 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { // status if (tDecodeI32(&decoder, &pReq->sver) < 0) return -1; - if (tDecodeI64(&decoder, &pReq->dver) < 0) return -1; + if (tDecodeI64(&decoder, &pReq->dnodeVer) < 0) return -1; if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1; if (tDecodeI64(&decoder, &pReq->clusterId) < 0) return -1; if (tDecodeI64(&decoder, &pReq->rebootTime) < 0) return -1; @@ -958,6 +960,8 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { return 0; } +void tFreeSStatusReq(SStatusReq *pReq) { taosArrayDestroy(pReq->pVloads); } + int32_t tSerializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -965,7 +969,7 @@ int32_t tSerializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) { if (tStartEncode(&encoder) < 0) return -1; // status - if (tEncodeI64(&encoder, pRsp->dver) < 0) return -1; + if (tEncodeI64(&encoder, pRsp->dnodeVer) < 0) return -1; // dnode cfg if (tEncodeI32(&encoder, pRsp->dnodeCfg.dnodeId) < 0) return -1; @@ -996,7 +1000,7 @@ int32_t tDeserializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) { if (tStartDecode(&decoder) < 0) return -1; // status - if (tDecodeI64(&decoder, &pRsp->dver) < 0) return -1; + if (tDecodeI64(&decoder, &pRsp->dnodeVer) < 0) return -1; // cluster cfg if (tDecodeI32(&decoder, &pRsp->dnodeCfg.dnodeId) < 0) return -1; @@ -1960,7 +1964,7 @@ int32_t tDeserializeSUseDbBatchRsp(void *buf, int32_t bufLen, SUseDbBatchRsp *pR int32_t numOfBatch = taosArrayGetSize(pRsp->pArray); if (tDecodeI32(&decoder, &numOfBatch) < 0) return -1; - pRsp->pArray = taosArrayInit(numOfBatch, sizeof(SUseDbBatchRsp)); + pRsp->pArray = taosArrayInit(numOfBatch, sizeof(SUseDbRsp)); if (pRsp->pArray == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -1989,7 +1993,7 @@ void tFreeSUseDbBatchRsp(SUseDbBatchRsp *pRsp) { taosArrayDestroy(pRsp->pArray); } -int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq) { +int32_t tSerializeSDbCfgReq(void *buf, int32_t bufLen, SDbCfgReq *pReq) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -2002,7 +2006,7 @@ int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq) { return tlen; } -int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq) { +int32_t tDeserializeSDbCfgReq(void *buf, int32_t bufLen, SDbCfgReq *pReq) { SCoder decoder = {0}; tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); @@ -2014,7 +2018,7 @@ int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq) { return 0; } -int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp) { +int32_t tSerializeSDbCfgRsp(void *buf, int32_t bufLen, const SDbCfgRsp *pRsp) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -2045,7 +2049,7 @@ int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp) { return tlen; } -int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp) { +int32_t tDeserializeSDbCfgRsp(void *buf, int32_t bufLen, SDbCfgRsp *pRsp) { SCoder decoder = {0}; tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); @@ -2076,7 +2080,7 @@ int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp) { return 0; } -int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq) { +int32_t tSerializeSUserIndexReq(void *buf, int32_t bufLen, SUserIndexReq *pReq) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -2089,7 +2093,7 @@ int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq) return tlen; } -int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq) { +int32_t tDeserializeSUserIndexReq(void *buf, int32_t bufLen, SUserIndexReq *pReq) { SCoder decoder = {0}; tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); @@ -2101,7 +2105,7 @@ int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq return 0; } -int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp) { +int32_t tSerializeSUserIndexRsp(void *buf, int32_t bufLen, const SUserIndexRsp *pRsp) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -2118,7 +2122,7 @@ int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* return tlen; } -int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp) { +int32_t tDeserializeSUserIndexRsp(void *buf, int32_t bufLen, SUserIndexRsp *pRsp) { SCoder decoder = {0}; tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); @@ -2134,7 +2138,6 @@ int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp return 0; } - int32_t tSerializeSShowReq(void *buf, int32_t bufLen, SShowReq *pReq) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -2181,7 +2184,6 @@ int32_t tSerializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableReq if (tStartEncode(&encoder) < 0) return -1; if (tEncodeI64(&encoder, pReq->showId) < 0) return -1; if (tEncodeI32(&encoder, pReq->type) < 0) return -1; - if (tEncodeI8(&encoder, pReq->free) < 0) return -1; if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; if (tEncodeCStr(&encoder, pReq->tb) < 0) return -1; tEndEncode(&encoder); @@ -2198,7 +2200,6 @@ int32_t tDeserializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableR if (tStartDecode(&decoder) < 0) return -1; if (tDecodeI64(&decoder, &pReq->showId) < 0) return -1; if (tDecodeI32(&decoder, &pReq->type) < 0) return -1; - if (tDecodeI8(&decoder, &pReq->free) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->tb) < 0) return -1; tEndDecode(&decoder); @@ -2531,6 +2532,7 @@ int32_t tSerializeSConnectReq(void *buf, int32_t bufLen, SConnectReq *pReq) { tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); if (tStartEncode(&encoder) < 0) return -1; + if (tEncodeI8(&encoder, pReq->connType) < 0) return -1; if (tEncodeI32(&encoder, pReq->pid) < 0) return -1; if (tEncodeCStr(&encoder, pReq->app) < 0) return -1; if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; @@ -2547,6 +2549,7 @@ int32_t tDeserializeSConnectReq(void *buf, int32_t bufLen, SConnectReq *pReq) { tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER); if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->connType) < 0) return -1; if (tDecodeI32(&decoder, &pReq->pid) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->app) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; @@ -2566,6 +2569,7 @@ int32_t tSerializeSConnectRsp(void *buf, int32_t bufLen, SConnectRsp *pRsp) { if (tEncodeI64(&encoder, pRsp->clusterId) < 0) return -1; if (tEncodeI32(&encoder, pRsp->connId) < 0) return -1; if (tEncodeI8(&encoder, pRsp->superUser) < 0) return -1; + if (tEncodeI8(&encoder, pRsp->connType) < 0) return -1; if (tEncodeSEpSet(&encoder, &pRsp->epSet) < 0) return -1; if (tEncodeCStr(&encoder, pRsp->sVersion) < 0) return -1; tEndEncode(&encoder); @@ -2584,6 +2588,7 @@ int32_t tDeserializeSConnectRsp(void *buf, int32_t bufLen, SConnectRsp *pRsp) { if (tDecodeI64(&decoder, &pRsp->clusterId) < 0) return -1; if (tDecodeI32(&decoder, &pRsp->connId) < 0) return -1; if (tDecodeI8(&decoder, &pRsp->superUser) < 0) return -1; + if (tDecodeI8(&decoder, &pRsp->connType) < 0) return -1; if (tDecodeSEpSet(&decoder, &pRsp->epSet) < 0) return -1; if (tDecodeCStrTo(&decoder, pRsp->sVersion) < 0) return -1; tEndDecode(&decoder); diff --git a/source/common/src/trow.c b/source/common/src/trow.c index d9c48bfe7684ea54f0e1ceb9400f03beb2f36973..7392b0bf8b2c66397f8574d30621c01468c61d11 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -385,7 +385,6 @@ int tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int pCol->len += pCol->bytes; } #ifdef TD_SUPPORT_BITMAP - tdSetBitmapValType(pCol->pBitmap, numOfRows, valType, bitmapMode); #endif return 0; @@ -486,7 +485,7 @@ static int32_t tdAppendKvRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols * @param pCols * @param forceSetNull */ -int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool forceSetNull) { +int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols) { if (TD_IS_TP_ROW(pRow)) { return tdAppendTpRowToDataCol(pRow, pSchema, pCols); } else if (TD_IS_KV_ROW(pRow)) { @@ -497,7 +496,7 @@ int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCol return TSDB_CODE_SUCCESS; } -int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset, bool forceSetNull) { +int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset, bool forceSetNull, TDRowVerT maxVer) { ASSERT(rowsToMerge > 0 && rowsToMerge <= source->numOfRows); ASSERT(target->numOfCols == source->numOfCols); int offset = 0; @@ -510,6 +509,7 @@ int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int * if ((target->numOfRows == 0) || (dataColsKeyLast(target) < dataColsKeyAtRow(source, *pOffset))) { // No overlap ASSERT(target->numOfRows + rowsToMerge <= target->maxPoints); + // TODO: filter the maxVer for (int i = 0; i < rowsToMerge; i++) { for (int j = 0; j < source->numOfCols; j++) { if (source->cols[j].len > 0 || target->cols[j].len > 0) { @@ -555,9 +555,9 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i // TKEY tkey2 = (*iter2 >= limit2) ? TKEY_NULL : dataColsTKeyAt(src2, *iter2); ASSERT(tkey1 == TKEY_NULL || (!TKEY_IS_DELETED(tkey1))); - + // TODO: filter the maxVer if (key1 < key2) { - for (int i = 0; i < src1->numOfCols; i++) { + for (int i = 0; i < src1->numOfCols; ++i) { ASSERT(target->cols[i].type == src1->cols[i].type); if (src1->cols[i].len > 0 || target->cols[i].len > 0) { SCellVal sVal = {0}; @@ -568,12 +568,12 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i } } - target->numOfRows++; - (*iter1)++; + ++target->numOfRows; + ++(*iter1); } else if (key1 >= key2) { - // if ((key1 > key2) || (key1 == key2 && !TKEY_IS_DELETED(tkey2))) { - if ((key1 > key2) || (key1 == key2)) { - for (int i = 0; i < src2->numOfCols; i++) { + // TODO: filter the maxVer + if ((key1 > key2) || ((key1 == key2) && !TKEY_IS_DELETED(key2))) { + for (int i = 0; i < src2->numOfCols; ++i) { SCellVal sVal = {0}; ASSERT(target->cols[i].type == src2->cols[i].type); if (tdGetColDataOfRow(&sVal, src2->cols + i, *iter2, src2->bitmapMode) < 0) { @@ -590,11 +590,11 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i dataColSetNullAt(&target->cols[i], target->numOfRows, true, target->bitmapMode); } } - target->numOfRows++; + ++target->numOfRows; } - (*iter2)++; - if (key1 == key2) (*iter1)++; + ++(*iter2); + if (key1 == key2) ++(*iter1); } ASSERT(target->numOfRows <= target->maxPoints); diff --git a/source/common/src/ttime.c b/source/common/src/ttime.c index a65352f2b919f85894996193796f4d2efde15b16..4686d856cc36ebb1ecf71b7eda17b16c388fea87 100644 --- a/source/common/src/ttime.c +++ b/source/common/src/ttime.c @@ -70,7 +70,7 @@ void deltaToUtcInitOnce() { struct tm tm = {0}; (void)taosStrpTime("1970-01-01 00:00:00", (const char*)("%Y-%m-%d %H:%M:%S"), &tm); - m_deltaUtc = (int64_t)mktime(&tm); + m_deltaUtc = (int64_t)taosMktime(&tm); // printf("====delta:%lld\n\n", seconds); } @@ -344,7 +344,7 @@ int32_t parseLocaltimeDst(char* timestr, int64_t* time, int32_t timePrec) { } /* mktime will be affected by TZ, set by using taos_options */ - int64_t seconds = mktime(&tm); + int64_t seconds = taosMktime(&tm); int64_t fraction = 0; @@ -406,7 +406,31 @@ int64_t convertTimeFromPrecisionToUnit(int64_t time, int32_t fromPrecision, char default: { return -1; } - } + } +} + +int32_t convertStringToTimestamp(int16_t type, char *inputData, int64_t timePrec, int64_t *timeVal) { + int32_t charLen = varDataLen(inputData); + char *newColData; + if (type == TSDB_DATA_TYPE_BINARY) { + newColData = taosMemoryCalloc(1, charLen + 1); + memcpy(newColData, varDataVal(inputData), charLen); + taosParseTime(newColData, timeVal, charLen, (int32_t)timePrec, 0); + taosMemoryFree(newColData); + } else if (type == TSDB_DATA_TYPE_NCHAR) { + newColData = taosMemoryCalloc(1, charLen / TSDB_NCHAR_SIZE + 1); + int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(inputData), charLen, newColData); + if (len < 0){ + taosMemoryFree(newColData); + return TSDB_CODE_FAILED; + } + newColData[len] = 0; + taosParseTime(newColData, timeVal, len + 1, (int32_t)timePrec, 0); + taosMemoryFree(newColData); + } else { + return TSDB_CODE_FAILED; + } + return TSDB_CODE_SUCCESS; } static int32_t getDuration(int64_t val, char unit, int64_t* result, int32_t timePrecision) { @@ -515,7 +539,7 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) { tm.tm_year = mon / 12; tm.tm_mon = mon % 12; - return (int64_t)(mktime(&tm) * TSDB_TICK_PER_SECOND(precision)); + return (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision)); } int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char unit, int32_t precision) { @@ -574,7 +598,7 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio tm.tm_mon = mon % 12; } - start = (int64_t)(mktime(&tm) * TSDB_TICK_PER_SECOND(precision)); + start = (int64_t)(taosMktime(&tm) * TSDB_TICK_PER_SECOND(precision)); } else { int64_t delta = t - pInterval->interval; int32_t factor = (delta >= 0) ? 1 : -1; @@ -721,7 +745,7 @@ void taosFormatUtcTime(char* buf, int32_t bufLen, int64_t t, int32_t precision) assert(false); } - ptm = localtime("); + ptm = taosLocalTime(", NULL); int32_t length = (int32_t)strftime(ts, 40, "%Y-%m-%dT%H:%M:%S", ptm); length += snprintf(ts + length, fractionLen, format, mod); length += (int32_t)strftime(ts + length, 40 - length, "%z", ptm); diff --git a/source/common/src/ttszip.c b/source/common/src/ttszip.c index 15e741d3076161f33738124dadfaad551bb56bca..3160d64c12b7e18a5af98f497e8d66d4c5a985d1 100644 --- a/source/common/src/ttszip.c +++ b/source/common/src/ttszip.c @@ -39,7 +39,7 @@ STSBuf* tsBufCreate(bool autoDelete, int32_t order) { taosGetTmpfilePath(tsTempDir, "join", pTSBuf->path); // pTSBuf->pFile = fopen(pTSBuf->path, "wb+"); - pTSBuf->pFile = taosOpenFile(pTSBuf->path, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC); + pTSBuf->pFile = taosOpenFile(pTSBuf->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC); if (pTSBuf->pFile == NULL) { taosMemoryFree(pTSBuf); return NULL; diff --git a/source/common/src/tvariant.c b/source/common/src/tvariant.c index 8c5010e577a0de784f70733830432df90446dc6d..a0503e43a187d8b136b7e8ab7673be6a15ebe230 100644 --- a/source/common/src/tvariant.c +++ b/source/common/src/tvariant.c @@ -1028,13 +1028,18 @@ int32_t taosVariantTypeSetType(SVariant *pVariant, char type) { char * taosVariantGet(SVariant *pVar, int32_t type) { switch (type) { - case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_BIGINT: - case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_TIMESTAMP: return (char *)&pVar->i; + case TSDB_DATA_TYPE_UTINYINT: + case TSDB_DATA_TYPE_USMALLINT: + case TSDB_DATA_TYPE_UINT: + case TSDB_DATA_TYPE_UBIGINT: + return (char *)&pVar->u; case TSDB_DATA_TYPE_DOUBLE: case TSDB_DATA_TYPE_FLOAT: return (char *)&pVar->d; @@ -1042,7 +1047,7 @@ char * taosVariantGet(SVariant *pVar, int32_t type) { return (char *)pVar->pz; case TSDB_DATA_TYPE_NCHAR: return (char *)pVar->ucs4; - default: + default: return NULL; } diff --git a/source/dnode/mgmt/CMakeLists.txt b/source/dnode/mgmt/CMakeLists.txt index f4987734628d7947724d67bdd0746927dc80c8bf..49ea54e92835f1173e80fef46f6184f258ebdb5e 100644 --- a/source/dnode/mgmt/CMakeLists.txt +++ b/source/dnode/mgmt/CMakeLists.txt @@ -1,28 +1,16 @@ -aux_source_directory(dm DNODE_SRC) -aux_source_directory(qm DNODE_SRC) -aux_source_directory(bm DNODE_SRC) -aux_source_directory(sm DNODE_SRC) -aux_source_directory(vm DNODE_SRC) -aux_source_directory(mm DNODE_SRC) -aux_source_directory(main DNODE_SRC) -add_library(dnode STATIC ${DNODE_SRC}) -target_link_libraries( - dnode cjson mnode vnode qnode snode bnode wal sync taos tfs monitor -) -target_include_directories( - dnode - PUBLIC "${TD_SOURCE_DIR}/include/dnode/mgmt" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" -) +add_subdirectory(interface) +add_subdirectory(implement) +add_subdirectory(mgmt_bnode) +add_subdirectory(mgmt_mnode) +add_subdirectory(mgmt_qnode) +add_subdirectory(mgmt_snode) +add_subdirectory(mgmt_vnode) +add_subdirectory(test) aux_source_directory(exe EXEC_SRC) add_executable(taosd ${EXEC_SRC}) target_include_directories( taosd - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/implement/inc" ) target_link_libraries(taosd dnode) - -if(${BUILD_TEST}) - add_subdirectory(test) -endif(${BUILD_TEST}) diff --git a/source/dnode/mgmt/dm/dmHandle.c b/source/dnode/mgmt/dm/dmHandle.c deleted file mode 100644 index 46d94fb8449bfd9ef8d6a8c77f92779832c4c91e..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/dm/dmHandle.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "dmInt.h" - -void dmSendStatusReq(SDnodeMgmt *pMgmt) { - SDnode *pDnode = pMgmt->pDnode; - SStatusReq req = {0}; - - taosRLockLatch(&pMgmt->latch); - req.sver = tsVersion; - req.dver = pMgmt->dver; - req.dnodeId = pDnode->dnodeId; - req.clusterId = pDnode->clusterId; - req.rebootTime = pDnode->rebootTime; - req.updateTime = pMgmt->updateTime; - req.numOfCores = tsNumOfCores; - req.numOfSupportVnodes = pDnode->numOfSupportVnodes; - tstrncpy(req.dnodeEp, pDnode->localEp, TSDB_EP_LEN); - - req.clusterCfg.statusInterval = tsStatusInterval; - req.clusterCfg.checkTime = 0; - char timestr[32] = "1970-01-01 00:00:00.00"; - (void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0); - memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); - memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN); - memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN); - taosRUnLockLatch(&pMgmt->latch); - - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, VNODES); - if (pWrapper != NULL) { - SMonVloadInfo info = {0}; - dmGetVnodeLoads(pWrapper, &info); - req.pVloads = info.pVloads; - dndReleaseWrapper(pWrapper); - } - - int32_t contLen = tSerializeSStatusReq(NULL, 0, &req); - void *pHead = rpcMallocCont(contLen); - tSerializeSStatusReq(pHead, contLen, &req); - taosArrayDestroy(req.pVloads); - - SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)0x9527}; - pMgmt->statusSent = 1; - - dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle); - SEpSet epSet = {0}; - dmGetMnodeEpSet(pMgmt, &epSet); - tmsgSendReq(&pMgmt->msgCb, &epSet, &rpcMsg); -} - -static void dmUpdateDnodeCfg(SDnodeMgmt *pMgmt, SDnodeCfg *pCfg) { - SDnode *pDnode = pMgmt->pDnode; - - if (pDnode->dnodeId == 0) { - dInfo("set dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId); - taosWLockLatch(&pMgmt->latch); - pDnode->dnodeId = pCfg->dnodeId; - pDnode->clusterId = pCfg->clusterId; - dmWriteFile(pMgmt); - taosWUnLockLatch(&pMgmt->latch); - } -} - -int32_t dmProcessStatusRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { - SDnode *pDnode = pMgmt->pDnode; - SRpcMsg *pRsp = &pMsg->rpcMsg; - - if (pRsp->code != TSDB_CODE_SUCCESS) { - if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pDnode->dropped && pDnode->dnodeId > 0) { - dInfo("dnode:%d, set to dropped since not exist in mnode", pDnode->dnodeId); - pDnode->dropped = 1; - dmWriteFile(pMgmt); - } - } else { - SStatusRsp statusRsp = {0}; - if (pRsp->pCont != NULL && pRsp->contLen != 0 && - tDeserializeSStatusRsp(pRsp->pCont, pRsp->contLen, &statusRsp) == 0) { - pMgmt->dver = statusRsp.dver; - dmUpdateDnodeCfg(pMgmt, &statusRsp.dnodeCfg); - dmUpdateDnodeEps(pMgmt, statusRsp.pDnodeEps); - } - tFreeSStatusRsp(&statusRsp); - } - - pMgmt->statusSent = 0; - return TSDB_CODE_SUCCESS; -} - -int32_t dmProcessAuthRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { - SRpcMsg *pRsp = &pMsg->rpcMsg; - dError("auth rsp is received, but not supported yet"); - return 0; -} - -int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { - SRpcMsg *pRsp = &pMsg->rpcMsg; - dError("grant rsp is received, but not supported yet"); - return 0; -} - -int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { - SRpcMsg *pReq = &pMsg->rpcMsg; - SDCfgDnodeReq *pCfg = pReq->pCont; - dError("config req is received, but not supported yet"); - return TSDB_CODE_OPS_NOT_SUPPORT; -} - -static int32_t dmProcessCreateNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg *pMsg) { - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, ntype); - if (pWrapper != NULL) { - dndReleaseWrapper(pWrapper); - terrno = TSDB_CODE_NODE_ALREADY_DEPLOYED; - dError("failed to create node since %s", terrstr()); - return -1; - } - - pWrapper = &pDnode->wrappers[ntype]; - - if (taosMkDir(pWrapper->path) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to create dir:%s since %s", pWrapper->path, terrstr()); - return -1; - } - - int32_t code = (*pWrapper->fp.createMsgFp)(pWrapper, pMsg); - if (code != 0) { - dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); - } else { - dDebug("node:%s, has been opened", pWrapper->name); - pWrapper->deployed = true; - } - - return code; -} - -static int32_t dmProcessDropNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg *pMsg) { - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, ntype); - if (pWrapper == NULL) { - terrno = TSDB_CODE_NODE_NOT_DEPLOYED; - dError("failed to drop node since %s", terrstr()); - return -1; - } - - taosWLockLatch(&pWrapper->latch); - pWrapper->deployed = false; - - int32_t code = (*pWrapper->fp.dropMsgFp)(pWrapper, pMsg); - if (code != 0) { - pWrapper->deployed = true; - dError("node:%s, failed to drop since %s", pWrapper->name, terrstr()); - } else { - pWrapper->deployed = false; - dDebug("node:%s, has been dropped", pWrapper->name); - } - - taosWUnLockLatch(&pWrapper->latch); - dndReleaseWrapper(pWrapper); - return code; -} - -int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg) { - switch (pMsg->rpcMsg.msgType) { - case TDMT_DND_CREATE_MNODE: - return dmProcessCreateNodeMsg(pDnode, MNODE, pMsg); - case TDMT_DND_DROP_MNODE: - return dmProcessDropNodeMsg(pDnode, MNODE, pMsg); - case TDMT_DND_CREATE_QNODE: - return dmProcessCreateNodeMsg(pDnode, QNODE, pMsg); - case TDMT_DND_DROP_QNODE: - return dmProcessDropNodeMsg(pDnode, QNODE, pMsg); - case TDMT_DND_CREATE_SNODE: - return dmProcessCreateNodeMsg(pDnode, SNODE, pMsg); - case TDMT_DND_DROP_SNODE: - return dmProcessDropNodeMsg(pDnode, SNODE, pMsg); - case TDMT_DND_CREATE_BNODE: - return dmProcessCreateNodeMsg(pDnode, BNODE, pMsg); - case TDMT_DND_DROP_BNODE: - return dmProcessDropNodeMsg(pDnode, BNODE, pMsg); - default: - terrno = TSDB_CODE_MSG_NOT_PROCESSED; - return -1; - } -} - -void dmInitMsgHandle(SMgmtWrapper *pWrapper) { - // Requests handled by DNODE - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_NETWORK_TEST, dmProcessMgmtMsg, DEFAULT_HANDLE); - - // Requests handled by MNODE - dndSetMsgHandle(pWrapper, TDMT_MND_STATUS_RSP, dmProcessMonitorMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); -} diff --git a/source/dnode/mgmt/dm/dmInt.c b/source/dnode/mgmt/dm/dmInt.c deleted file mode 100644 index c710af9006feefd5284f8106ac79af8261ddf818..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/dm/dmInt.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "dmInt.h" - -void dmGetMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet) { - taosRLockLatch(&pMgmt->latch); - *pEpSet = pMgmt->mnodeEpSet; - taosRUnLockLatch(&pMgmt->latch); -} - -void dmUpdateMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet) { - dInfo("mnode is changed, num:%d use:%d", pEpSet->numOfEps, pEpSet->inUse); - - taosWLockLatch(&pMgmt->latch); - pMgmt->mnodeEpSet = *pEpSet; - for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { - dInfo("mnode index:%d %s:%u", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port); - } - - taosWUnLockLatch(&pMgmt->latch); -} - -void dmGetDnodeEp(SMgmtWrapper *pWrapper, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) { - SDnodeMgmt *pMgmt = pWrapper->pMgmt; - taosRLockLatch(&pMgmt->latch); - - SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t)); - if (pDnodeEp != NULL) { - if (pPort != NULL) { - *pPort = pDnodeEp->ep.port; - } - if (pFqdn != NULL) { - tstrncpy(pFqdn, pDnodeEp->ep.fqdn, TSDB_FQDN_LEN); - } - if (pEp != NULL) { - snprintf(pEp, TSDB_EP_LEN, "%s:%u", pDnodeEp->ep.fqdn, pDnodeEp->ep.port); - } - } - - taosRUnLockLatch(&pMgmt->latch); -} - -void dmSendRedirectRsp(SDnodeMgmt *pMgmt, const SRpcMsg *pReq) { - SDnode *pDnode = pMgmt->pDnode; - - SEpSet epSet = {0}; - dmGetMnodeEpSet(pMgmt, &epSet); - - dDebug("RPC %p, req is redirected, num:%d use:%d", pReq->handle, epSet.numOfEps, epSet.inUse); - for (int32_t i = 0; i < epSet.numOfEps; ++i) { - dDebug("mnode index:%d %s:%u", i, epSet.eps[i].fqdn, epSet.eps[i].port); - if (strcmp(epSet.eps[i].fqdn, pDnode->localFqdn) == 0 && epSet.eps[i].port == pDnode->serverPort) { - epSet.inUse = (i + 1) % epSet.numOfEps; - } - - epSet.eps[i].port = htons(epSet.eps[i].port); - } - - rpcSendRedirectRsp(pReq->handle, &epSet); -} - -static int32_t dmStart(SMgmtWrapper *pWrapper) { - dDebug("dnode-mgmt start to run"); - return dmStartThread(pWrapper->pMgmt); -} - -static int32_t dmInit(SMgmtWrapper *pWrapper) { - SDnode *pDnode = pWrapper->pDnode; - SDnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeMgmt)); - dInfo("dnode-mgmt start to init"); - - pDnode->dnodeId = 0; - pDnode->dropped = 0; - pDnode->clusterId = 0; - pMgmt->path = pWrapper->path; - pMgmt->pDnode = pDnode; - pMgmt->pWrapper = pWrapper; - taosInitRWLatch(&pMgmt->latch); - - pMgmt->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); - if (pMgmt->dnodeHash == NULL) { - dError("failed to init dnode hash"); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - if (dmReadFile(pMgmt) != 0) { - dError("failed to read file since %s", terrstr()); - return -1; - } - - if (pDnode->dropped) { - dError("dnode will not start since its already dropped"); - return -1; - } - - if (dmStartWorker(pMgmt) != 0) { - return -1; - } - - if (dndInitTrans(pDnode) != 0) { - dError("failed to init transport since %s", terrstr()); - return -1; - } - - pWrapper->pMgmt = pMgmt; - pMgmt->msgCb = dndCreateMsgcb(pWrapper); - - dInfo("dnode-mgmt is initialized"); - return 0; -} - -static void dmCleanup(SMgmtWrapper *pWrapper) { - SDnodeMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return; - - dInfo("dnode-mgmt start to clean up"); - SDnode *pDnode = pMgmt->pDnode; - dmStopWorker(pMgmt); - - taosWLockLatch(&pMgmt->latch); - - if (pMgmt->dnodeEps != NULL) { - taosArrayDestroy(pMgmt->dnodeEps); - pMgmt->dnodeEps = NULL; - } - - if (pMgmt->dnodeHash != NULL) { - taosHashCleanup(pMgmt->dnodeHash); - pMgmt->dnodeHash = NULL; - } - - taosWUnLockLatch(&pMgmt->latch); - - taosMemoryFree(pMgmt); - pWrapper->pMgmt = NULL; - dndCleanupTrans(pDnode); - - dInfo("dnode-mgmt is cleaned up"); -} - -static int32_t dmRequire(SMgmtWrapper *pWrapper, bool *required) { - *required = true; - return 0; -} - -void dmSetMgmtFp(SMgmtWrapper *pWrapper) { - SMgmtFp mgmtFp = {0}; - mgmtFp.openFp = dmInit; - mgmtFp.closeFp = dmCleanup; - mgmtFp.startFp = dmStart; - mgmtFp.requiredFp = dmRequire; - - dmInitMsgHandle(pWrapper); - pWrapper->name = "dnode"; - pWrapper->fp = mgmtFp; -} diff --git a/source/dnode/mgmt/dm/dmWorker.c b/source/dnode/mgmt/dm/dmWorker.c deleted file mode 100644 index 7009469c00dae45ec100f08718bdd22239edbeba..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/dm/dmWorker.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "dmInt.h" - -static void *dmThreadRoutine(void *param) { - SDnodeMgmt *pMgmt = param; - SDnode *pDnode = pMgmt->pDnode; - int64_t lastStatusTime = taosGetTimestampMs(); - int64_t lastMonitorTime = lastStatusTime; - - setThreadName("dnode-hb"); - - while (true) { - taosThreadTestCancel(); - taosMsleep(200); - if (dndGetStatus(pDnode) != DND_STAT_RUNNING || pDnode->dropped) { - continue; - } - - int64_t curTime = taosGetTimestampMs(); - float statusInterval = (curTime - lastStatusTime) / 1000.0f; - if (statusInterval >= tsStatusInterval && !pMgmt->statusSent) { - dmSendStatusReq(pMgmt); - lastStatusTime = curTime; - } - - float monitorInterval = (curTime - lastMonitorTime) / 1000.0f; - if (monitorInterval >= tsMonitorInterval) { - dmSendMonitorReport(pDnode); - lastMonitorTime = curTime; - } - } - return TSDB_CODE_SUCCESS; -} - -int32_t dmStartThread(SDnodeMgmt *pMgmt) { - pMgmt->threadId = taosCreateThread(dmThreadRoutine, pMgmt); - if (pMgmt->threadId == NULL) { - dError("failed to init dnode thread"); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - return 0; -} - -static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { - SDnodeMgmt *pMgmt = pInfo->ahandle; - - SDnode *pDnode = pMgmt->pDnode; - SRpcMsg *pRpc = &pMsg->rpcMsg; - int32_t code = -1; - dTrace("msg:%p, will be processed in dnode queue", pMsg); - - switch (pRpc->msgType) { - case TDMT_DND_CONFIG_DNODE: - code = dmProcessConfigReq(pMgmt, pMsg); - break; - case TDMT_MND_STATUS_RSP: - code = dmProcessStatusRsp(pMgmt, pMsg); - break; - case TDMT_MND_AUTH_RSP: - code = dmProcessAuthRsp(pMgmt, pMsg); - break; - case TDMT_MND_GRANT_RSP: - code = dmProcessGrantRsp(pMgmt, pMsg); - break; - default: - code = dmProcessCDnodeReq(pMgmt->pDnode, pMsg); - break; - } - - if (pRpc->msgType & 1u) { - if (code != 0) code = terrno; - SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = code}; - rpcSendResponse(&rsp); - } - - dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); - rpcFreeCont(pMsg->rpcMsg.pCont); - taosFreeQitem(pMsg); -} - -int32_t dmStartWorker(SDnodeMgmt *pMgmt) { - SSingleWorkerCfg mcfg = {.min = 1, .max = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessQueue, .param = pMgmt}; - if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mcfg) != 0) { - dError("failed to start dnode mgmt worker since %s", terrstr()); - return -1; - } - - SSingleWorkerCfg scfg = {.min = 1, .max = 1, .name = "dnode-monitor", .fp = (FItem)dmProcessQueue, .param = pMgmt}; - if (tSingleWorkerInit(&pMgmt->monitorWorker, &scfg) != 0) { - dError("failed to start dnode monitor worker since %s", terrstr()); - return -1; - } - - dDebug("dnode workers are initialized"); - return 0; -} - -void dmStopWorker(SDnodeMgmt *pMgmt) { - tSingleWorkerCleanup(&pMgmt->mgmtWorker); - tSingleWorkerCleanup(&pMgmt->monitorWorker); - - if (pMgmt->threadId != NULL) { - taosDestoryThread(pMgmt->threadId); - pMgmt->threadId = NULL; - } - dDebug("dnode workers are closed"); -} - -int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SDnodeMgmt *pMgmt = pWrapper->pMgmt; - SSingleWorker *pWorker = &pMgmt->mgmtWorker; - - dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); - taosWriteQitem(pWorker->queue, pMsg); - return 0; -} - -int32_t dmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SDnodeMgmt *pMgmt = pWrapper->pMgmt; - SSingleWorker *pWorker = &pMgmt->monitorWorker; - - dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); - taosWriteQitem(pWorker->queue, pMsg); - return 0; -} diff --git a/source/dnode/mgmt/exe/dndMain.c b/source/dnode/mgmt/exe/dmMain.c similarity index 69% rename from source/dnode/mgmt/exe/dndMain.c rename to source/dnode/mgmt/exe/dmMain.c index 997c56f9fb10f63b67bf858de4b76a1efedaaa4c..3f5c22dd8488870cca64b1c831d1a4d3a7cf6b1a 100644 --- a/source/dnode/mgmt/exe/dndMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -14,46 +14,46 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dmImp.h" #include "tconfig.h" static struct { - bool dumpConfig; - bool generateGrant; - bool printAuth; - bool printVersion; - char envFile[PATH_MAX]; - char apolloUrl[PATH_MAX]; - SArray *pArgs; // SConfigPair - SDnode *pDnode; - EDndType ntype; + bool dumpConfig; + bool generateGrant; + bool printAuth; + bool printVersion; + char envFile[PATH_MAX]; + char apolloUrl[PATH_MAX]; + SArray *pArgs; // SConfigPair + SDnode *pDnode; + EDndNodeType ntype; } global = {0}; -static void dndStopDnode(int signum, void *info, void *ctx) { +static void dmStopDnode(int signum, void *info, void *ctx) { SDnode *pDnode = atomic_val_compare_exchange_ptr(&global.pDnode, 0, global.pDnode); if (pDnode != NULL) { - dndHandleEvent(pDnode, DND_EVENT_STOP); + dmSetEvent(pDnode, DND_EVENT_STOP); } } -static void dndSetSignalHandle() { - taosSetSignal(SIGTERM, dndStopDnode); - taosSetSignal(SIGHUP, dndStopDnode); - taosSetSignal(SIGINT, dndStopDnode); - taosSetSignal(SIGTSTP, dndStopDnode); - taosSetSignal(SIGABRT, dndStopDnode); - taosSetSignal(SIGBREAK, dndStopDnode); - taosSetSignal(SIGQUIT, dndStopDnode); +static void dmSetSignalHandle() { + taosSetSignal(SIGTERM, dmStopDnode); + taosSetSignal(SIGHUP, dmStopDnode); + taosSetSignal(SIGINT, dmStopDnode); + taosSetSignal(SIGTSTP, dmStopDnode); + taosSetSignal(SIGABRT, dmStopDnode); + taosSetSignal(SIGBREAK, dmStopDnode); + taosSetSignal(SIGQUIT, dmStopDnode); if (!tsMultiProcess) { - } else if (global.ntype == DNODE || global.ntype == NODE_MAX) { + } else if (global.ntype == DNODE || global.ntype == NODE_END) { taosIgnSignal(SIGCHLD); } else { taosKillChildOnParentStopped(); } } -static int32_t dndParseArgs(int32_t argc, char const *argv[]) { +static int32_t dmParseArgs(int32_t argc, char const *argv[]) { for (int32_t i = 1; i < argc; ++i) { if (strcmp(argv[i], "-c") == 0) { if (i < argc - 1) { @@ -72,8 +72,8 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) { tstrncpy(global.envFile, argv[++i], PATH_MAX); } else if (strcmp(argv[i], "-n") == 0) { global.ntype = atoi(argv[++i]); - if (global.ntype <= DNODE || global.ntype > NODE_MAX) { - printf("'-n' range is [1 - %d], default is 0\n", NODE_MAX - 1); + if (global.ntype <= DNODE || global.ntype > NODE_END) { + printf("'-n' range is [1 - %d], default is 0\n", NODE_END - 1); return -1; } } else if (strcmp(argv[i], "-k") == 0) { @@ -89,12 +89,9 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) { return 0; } -static void dndGenerateGrant() { - // grantParseParameter(); - printf("this feature is not implemented yet\n"); -} +static void dmGenerateGrant() { mndGenerateMachineCode(); } -static void dndPrintVersion() { +static void dmPrintVersion() { #ifdef TD_ENTERPRISE char *releaseName = "enterprise"; #else @@ -105,12 +102,12 @@ static void dndPrintVersion() { printf("buildInfo: %s\n", buildinfo); } -static void dndDumpCfg() { +static void dmDumpCfg() { SConfig *pCfg = taosGetCfg(); cfgDumpCfg(pCfg, 0, 1); } -static SDnodeOpt dndGetOpt() { +static SDnodeOpt dmGetOpt() { SConfig *pCfg = taosGetCfg(); SDnodeOpt option = {0}; @@ -127,43 +124,43 @@ static SDnodeOpt dndGetOpt() { return option; } -static int32_t dndInitLog() { +static int32_t dmInitLog() { char logName[12] = {0}; - snprintf(logName, sizeof(logName), "%slog", dndNodeLogStr(global.ntype)); + snprintf(logName, sizeof(logName), "%slog", dmLogName(global.ntype)); return taosCreateLog(logName, 1, configDir, global.envFile, global.apolloUrl, global.pArgs, 0); } -static void dndSetProcInfo(int32_t argc, char **argv) { +static void dmSetProcInfo(int32_t argc, char **argv) { taosSetProcPath(argc, argv); - if (global.ntype != DNODE && global.ntype != NODE_MAX) { - const char *name = dndNodeProcStr(global.ntype); + if (global.ntype != DNODE && global.ntype != NODE_END) { + const char *name = dmProcName(global.ntype); taosSetProcName(argc, argv, name); } } -static int32_t dndRunDnode() { - if (dndInit() != 0) { +static int32_t dmRunDnode() { + if (dmInit() != 0) { dError("failed to init environment since %s", terrstr()); return -1; } - SDnodeOpt option = dndGetOpt(); - SDnode *pDnode = dndCreate(&option); + SDnodeOpt option = dmGetOpt(); + SDnode *pDnode = dmCreate(&option); if (pDnode == NULL) { dError("failed to to create dnode since %s", terrstr()); return -1; } else { global.pDnode = pDnode; - dndSetSignalHandle(); + dmSetSignalHandle(); } dInfo("start the service"); - int32_t code = dndRun(pDnode); + int32_t code = dmRun(pDnode); dInfo("start shutting down the service"); global.pDnode = NULL; - dndClose(pDnode); - dndCleanup(); + dmClose(pDnode); + dmCleanup(); taosCloseLog(); taosCleanupCfg(); return code; @@ -175,22 +172,22 @@ int main(int argc, char const *argv[]) { return -1; } - if (dndParseArgs(argc, argv) != 0) { + if (dmParseArgs(argc, argv) != 0) { printf("failed to start since parse args error\n"); return -1; } if (global.generateGrant) { - dndGenerateGrant(); + dmGenerateGrant(); return 0; } if (global.printVersion) { - dndPrintVersion(); + dmPrintVersion(); return 0; } - if (dndInitLog() != 0) { + if (dmInitLog() != 0) { printf("failed to start since init log error\n"); return -1; } @@ -201,12 +198,12 @@ int main(int argc, char const *argv[]) { } if (global.dumpConfig) { - dndDumpCfg(); + dmDumpCfg(); taosCleanupCfg(); taosCloseLog(); return 0; } - dndSetProcInfo(argc, (char **)argv); - return dndRunDnode(); + dmSetProcInfo(argc, (char **)argv); + return dmRunDnode(); } diff --git a/source/dnode/mgmt/implement/CMakeLists.txt b/source/dnode/mgmt/implement/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..26c14edc77fca9184dd72dfa511049cc323a8c18 --- /dev/null +++ b/source/dnode/mgmt/implement/CMakeLists.txt @@ -0,0 +1,17 @@ +aux_source_directory(src IMPLEMENT_SRC) +add_library(dnode STATIC ${IMPLEMENT_SRC}) +target_link_libraries( + dnode mgmt_bnode mgmt_mnode mgmt_qnode mgmt_snode mgmt_vnode +) +target_include_directories( + dnode + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) + +IF (TD_GRANT) + TARGET_LINK_LIBRARIES(dnode grant) +ENDIF () +IF (TD_USB_DONGLE) + TARGET_LINK_LIBRARIES(dnode usb_dongle) +else() +ENDIF () \ No newline at end of file diff --git a/source/dnode/mgmt/implement/inc/dmImp.h b/source/dnode/mgmt/implement/inc/dmImp.h new file mode 100644 index 0000000000000000000000000000000000000000..52a56305fdaf97fb17c2aa616308bc1f2831b672 --- /dev/null +++ b/source/dnode/mgmt/implement/inc/dmImp.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_DND_IMP_H_ +#define _TD_DND_IMP_H_ + +#include "dmInt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int32_t dmOpenNode(SMgmtWrapper *pWrapper); +void dmCloseNode(SMgmtWrapper *pWrapper); + +// dmTransport.c +int32_t dmInitTrans(SDnode *pDnode); +void dmCleanupTrans(SDnode *pDnode); +SProcCfg dmGenProcCfg(SMgmtWrapper *pWrapper); +SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper); +int32_t dmInitMsgHandle(SDnode *pDnode); +void dmSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); +void dmSendToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp); + +// dmEps.c +int32_t dmReadEps(SDnode *pDnode); +int32_t dmWriteEps(SDnode *pDnode); +void dmUpdateEps(SDnode *pDnode, SArray *pDnodeEps); + +// dmHandle.c +void dmSendStatusReq(SDnode *pDnode); +int32_t dmProcessConfigReq(SDnode *pDnode, SNodeMsg *pMsg); +int32_t dmProcessAuthRsp(SDnode *pDnode, SNodeMsg *pMsg); +int32_t dmProcessGrantRsp(SDnode *pDnode, SNodeMsg *pMsg); +int32_t dmProcessCreateNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg); +int32_t dmProcessDropNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg); + +// dmMonitor.c +void dmGetVnodeLoads(SDnode *pDnode, SMonVloadInfo *pInfo); +void dmSendMonitorReport(SDnode *pDnode); + +// dmWorker.c +int32_t dmStartStatusThread(SDnode *pDnode); +void dmStopStatusThread(SDnode *pDnode); +int32_t dmStartMonitorThread(SDnode *pDnode); +void dmStopMonitorThread(SDnode *pDnode); +int32_t dmStartWorker(SDnode *pDnode); +void dmStopWorker(SDnode *pDnode); +int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +int32_t dmProcessStatusMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); + +// mgmt nodes +void dmSetMgmtFp(SMgmtWrapper *pWrapper); +void bmSetMgmtFp(SMgmtWrapper *pWrapper); +void qmSetMgmtFp(SMgmtWrapper *pWrapper); +void smSetMgmtFp(SMgmtWrapper *pWrapper); +void vmSetMgmtFp(SMgmtWrapper *pWrapper); +void mmSetMgmtFp(SMgmtWrapper *pWrapper); + +void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); +void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo); +void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo); +void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo); +void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo); +void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_DND_IMP_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/dm/dmFile.c b/source/dnode/mgmt/implement/src/dmEps.c similarity index 65% rename from source/dnode/mgmt/dm/dmFile.c rename to source/dnode/mgmt/implement/src/dmEps.c index 1ac86870e334ccb831c8d91d73951c6fe2ca8042..ae1cd513b51b488e8af074d1730acfaa7e6863dd 100644 --- a/source/dnode/mgmt/dm/dmFile.c +++ b/source/dnode/mgmt/implement/src/dmEps.c @@ -14,32 +14,50 @@ */ #define _DEFAULT_SOURCE -#include "dmInt.h" +#include "dmImp.h" -static void dmPrintDnodes(SDnodeMgmt *pMgmt); -static bool dmIsEpChanged(SDnodeMgmt *pMgmt, int32_t dnodeId, const char *ep); -static void dmResetDnodes(SDnodeMgmt *pMgmt, SArray *dnodeEps); +static void dmPrintEps(SDnode *pDnode); +static bool dmIsEpChanged(SDnode *pDnode, int32_t dnodeId, const char *ep); +static void dmResetEps(SDnode *pDnode, SArray *dnodeEps); -int32_t dmReadFile(SDnodeMgmt *pMgmt) { +static void dmGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) { + taosRLockLatch(&pDnode->data.latch); + + SDnodeEp *pDnodeEp = taosHashGet(pDnode->data.dnodeHash, &dnodeId, sizeof(int32_t)); + if (pDnodeEp != NULL) { + if (pPort != NULL) { + *pPort = pDnodeEp->ep.port; + } + if (pFqdn != NULL) { + tstrncpy(pFqdn, pDnodeEp->ep.fqdn, TSDB_FQDN_LEN); + } + if (pEp != NULL) { + snprintf(pEp, TSDB_EP_LEN, "%s:%u", pDnodeEp->ep.fqdn, pDnodeEp->ep.port); + } + } + + taosRUnLockLatch(&pDnode->data.latch); +} + +int32_t dmReadEps(SDnode *pDnode) { int32_t code = TSDB_CODE_INVALID_JSON_FORMAT; int32_t len = 0; int32_t maxLen = 256 * 1024; char *content = taosMemoryCalloc(1, maxLen + 1); cJSON *root = NULL; - char file[PATH_MAX]; + char file[PATH_MAX] = {0}; TdFilePtr pFile = NULL; - SDnode *pDnode = pMgmt->pDnode; - pMgmt->dnodeEps = taosArrayInit(1, sizeof(SDnodeEp)); - if (pMgmt->dnodeEps == NULL) { + pDnode->data.dnodeEps = taosArrayInit(1, sizeof(SDnodeEp)); + if (pDnode->data.dnodeEps == NULL) { dError("failed to calloc dnodeEp array since %s", strerror(errno)); goto PRASE_DNODE_OVER; } - snprintf(file, sizeof(file), "%s%sdnode.json", pMgmt->path, TD_DIRSEP); + snprintf(file, sizeof(file), "%s%sdnode.json", pDnode->wrappers[DNODE].path, TD_DIRSEP); pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - dDebug("file %s not exist", file); + // dDebug("file %s not exist", file); code = 0; goto PRASE_DNODE_OVER; } @@ -62,21 +80,21 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) { dError("failed to read %s since dnodeId not found", file); goto PRASE_DNODE_OVER; } - pDnode->dnodeId = dnodeId->valueint; + pDnode->data.dnodeId = dnodeId->valueint; cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId"); if (!clusterId || clusterId->type != cJSON_String) { dError("failed to read %s since clusterId not found", file); goto PRASE_DNODE_OVER; } - pDnode->clusterId = atoll(clusterId->valuestring); + pDnode->data.clusterId = atoll(clusterId->valuestring); cJSON *dropped = cJSON_GetObjectItem(root, "dropped"); if (!dropped || dropped->type != cJSON_Number) { dError("failed to read %s since dropped not found", file); goto PRASE_DNODE_OVER; } - pDnode->dropped = dropped->valueint; + pDnode->data.dropped = dropped->valueint; cJSON *dnodes = cJSON_GetObjectItem(root, "dnodes"); if (!dnodes || dnodes->type != cJSON_Array) { @@ -126,43 +144,43 @@ int32_t dmReadFile(SDnodeMgmt *pMgmt) { } dnodeEp.isMnode = isMnode->valueint; - taosArrayPush(pMgmt->dnodeEps, &dnodeEp); + taosArrayPush(pDnode->data.dnodeEps, &dnodeEp); } code = 0; dDebug("succcessed to read file %s", file); - dmPrintDnodes(pMgmt); + dmPrintEps(pDnode); PRASE_DNODE_OVER: if (content != NULL) taosMemoryFree(content); if (root != NULL) cJSON_Delete(root); if (pFile != NULL) taosCloseFile(&pFile); - if (dmIsEpChanged(pMgmt, pDnode->dnodeId, pDnode->localEp)) { - dError("localEp %s different with %s and need reconfigured", pDnode->localEp, file); + if (dmIsEpChanged(pDnode, pDnode->data.dnodeId, pDnode->data.localEp)) { + dError("localEp %s different with %s and need reconfigured", pDnode->data.localEp, file); return -1; } - if (taosArrayGetSize(pMgmt->dnodeEps) == 0) { + if (taosArrayGetSize(pDnode->data.dnodeEps) == 0) { SDnodeEp dnodeEp = {0}; dnodeEp.isMnode = 1; - taosGetFqdnPortFromEp(pDnode->firstEp, &dnodeEp.ep); - taosArrayPush(pMgmt->dnodeEps, &dnodeEp); + taosGetFqdnPortFromEp(pDnode->data.firstEp, &dnodeEp.ep); + taosArrayPush(pDnode->data.dnodeEps, &dnodeEp); } - dmResetDnodes(pMgmt, pMgmt->dnodeEps); + dmResetEps(pDnode, pDnode->data.dnodeEps); terrno = code; return code; } -int32_t dmWriteFile(SDnodeMgmt *pMgmt) { - SDnode *pDnode = pMgmt->pDnode; - - char file[PATH_MAX]; - snprintf(file, sizeof(file), "%s%sdnode.json.bak", pMgmt->path, TD_DIRSEP); +int32_t dmWriteEps(SDnode *pDnode) { + char file[PATH_MAX] = {0}; + char realfile[PATH_MAX]; + snprintf(file, sizeof(file), "%s%sdnode.json.bak", pDnode->wrappers[DNODE].path, TD_DIRSEP); + snprintf(realfile, sizeof(realfile), "%s%sdnode.json", pDnode->wrappers[DNODE].path, TD_DIRSEP); - TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { dError("failed to write %s since %s", file, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); @@ -174,14 +192,14 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) { char *content = taosMemoryCalloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); - len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pDnode->dnodeId); - len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pDnode->clusterId); - len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pDnode->dropped); + len += snprintf(content + len, maxLen - len, " \"dnodeId\": %d,\n", pDnode->data.dnodeId); + len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pDnode->data.clusterId); + len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pDnode->data.dropped); len += snprintf(content + len, maxLen - len, " \"dnodes\": [{\n"); - int32_t numOfEps = (int32_t)taosArrayGetSize(pMgmt->dnodeEps); + int32_t numOfEps = (int32_t)taosArrayGetSize(pDnode->data.dnodeEps); for (int32_t i = 0; i < numOfEps; ++i) { - SDnodeEp *pDnodeEp = taosArrayGet(pMgmt->dnodeEps, i); + SDnodeEp *pDnodeEp = taosArrayGet(pDnode->data.dnodeEps, i); len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pDnodeEp->id); len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pDnodeEp->ep.fqdn); len += snprintf(content + len, maxLen - len, " \"port\": %u,\n", pDnodeEp->ep.port); @@ -199,50 +217,47 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) { taosCloseFile(&pFile); taosMemoryFree(content); - char realfile[PATH_MAX]; - snprintf(realfile, sizeof(realfile), "%s%sdnode.json", pMgmt->path, TD_DIRSEP); - if (taosRenameFile(file, realfile) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to rename %s since %s", file, terrstr()); return -1; } - pMgmt->updateTime = taosGetTimestampMs(); + pDnode->data.updateTime = taosGetTimestampMs(); dDebug("successed to write %s", realfile); return 0; } -void dmUpdateDnodeEps(SDnodeMgmt *pMgmt, SArray *dnodeEps) { - int32_t numOfEps = taosArrayGetSize(dnodeEps); +void dmUpdateEps(SDnode *pDnode, SArray *eps) { + int32_t numOfEps = taosArrayGetSize(eps); if (numOfEps <= 0) return; - taosWLockLatch(&pMgmt->latch); + taosWLockLatch(&pDnode->data.latch); - int32_t numOfEpsOld = (int32_t)taosArrayGetSize(pMgmt->dnodeEps); + int32_t numOfEpsOld = (int32_t)taosArrayGetSize(pDnode->data.dnodeEps); if (numOfEps != numOfEpsOld) { - dmResetDnodes(pMgmt, dnodeEps); - dmWriteFile(pMgmt); + dmResetEps(pDnode, eps); + dmWriteEps(pDnode); } else { int32_t size = numOfEps * sizeof(SDnodeEp); - if (memcmp(pMgmt->dnodeEps->pData, dnodeEps->pData, size) != 0) { - dmResetDnodes(pMgmt, dnodeEps); - dmWriteFile(pMgmt); + if (memcmp(pDnode->data.dnodeEps->pData, eps->pData, size) != 0) { + dmResetEps(pDnode, eps); + dmWriteEps(pDnode); } } - taosWUnLockLatch(&pMgmt->latch); + taosWUnLockLatch(&pDnode->data.latch); } -static void dmResetDnodes(SDnodeMgmt *pMgmt, SArray *dnodeEps) { - if (pMgmt->dnodeEps != dnodeEps) { - SArray *tmp = pMgmt->dnodeEps; - pMgmt->dnodeEps = taosArrayDup(dnodeEps); +static void dmResetEps(SDnode *pDnode, SArray *dnodeEps) { + if (pDnode->data.dnodeEps != dnodeEps) { + SArray *tmp = pDnode->data.dnodeEps; + pDnode->data.dnodeEps = taosArrayDup(dnodeEps); taosArrayDestroy(tmp); } - pMgmt->mnodeEpSet.inUse = 0; - pMgmt->mnodeEpSet.numOfEps = 0; + pDnode->data.mnodeEps.inUse = 0; + pDnode->data.mnodeEps.numOfEps = 0; int32_t mIndex = 0; int32_t numOfEps = (int32_t)taosArrayGetSize(dnodeEps); @@ -251,40 +266,40 @@ static void dmResetDnodes(SDnodeMgmt *pMgmt, SArray *dnodeEps) { SDnodeEp *pDnodeEp = taosArrayGet(dnodeEps, i); if (!pDnodeEp->isMnode) continue; if (mIndex >= TSDB_MAX_REPLICA) continue; - pMgmt->mnodeEpSet.numOfEps++; + pDnode->data.mnodeEps.numOfEps++; - pMgmt->mnodeEpSet.eps[mIndex] = pDnodeEp->ep; + pDnode->data.mnodeEps.eps[mIndex] = pDnodeEp->ep; mIndex++; } for (int32_t i = 0; i < numOfEps; i++) { SDnodeEp *pDnodeEp = taosArrayGet(dnodeEps, i); - taosHashPut(pMgmt->dnodeHash, &pDnodeEp->id, sizeof(int32_t), pDnodeEp, sizeof(SDnodeEp)); + taosHashPut(pDnode->data.dnodeHash, &pDnodeEp->id, sizeof(int32_t), pDnodeEp, sizeof(SDnodeEp)); } - dmPrintDnodes(pMgmt); + dmPrintEps(pDnode); } -static void dmPrintDnodes(SDnodeMgmt *pMgmt) { - int32_t numOfEps = (int32_t)taosArrayGetSize(pMgmt->dnodeEps); +static void dmPrintEps(SDnode *pDnode) { + int32_t numOfEps = (int32_t)taosArrayGetSize(pDnode->data.dnodeEps); dDebug("print dnode ep list, num:%d", numOfEps); for (int32_t i = 0; i < numOfEps; i++) { - SDnodeEp *pEp = taosArrayGet(pMgmt->dnodeEps, i); + SDnodeEp *pEp = taosArrayGet(pDnode->data.dnodeEps, i); dDebug("dnode:%d, fqdn:%s port:%u isMnode:%d", pEp->id, pEp->ep.fqdn, pEp->ep.port, pEp->isMnode); } } -static bool dmIsEpChanged(SDnodeMgmt *pMgmt, int32_t dnodeId, const char *ep) { +static bool dmIsEpChanged(SDnode *pDnode, int32_t dnodeId, const char *ep) { bool changed = false; - taosRLockLatch(&pMgmt->latch); + taosRLockLatch(&pDnode->data.latch); - SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t)); + SDnodeEp *pDnodeEp = taosHashGet(pDnode->data.dnodeHash, &dnodeId, sizeof(int32_t)); if (pDnodeEp != NULL) { char epstr[TSDB_EP_LEN + 1]; snprintf(epstr, TSDB_EP_LEN, "%s:%u", pDnodeEp->ep.fqdn, pDnodeEp->ep.port); changed = strcmp(ep, epstr) != 0; } - taosRUnLockLatch(&pMgmt->latch); + taosRUnLockLatch(&pDnode->data.latch); return changed; } diff --git a/source/dnode/mgmt/implement/src/dmExec.c b/source/dnode/mgmt/implement/src/dmExec.c new file mode 100644 index 0000000000000000000000000000000000000000..f66e7cd9d329e8fbb7590e0bab7d17e0a54ad444 --- /dev/null +++ b/source/dnode/mgmt/implement/src/dmExec.c @@ -0,0 +1,339 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "dmImp.h" + +static bool dmRequireNode(SMgmtWrapper *pWrapper) { + bool required = false; + int32_t code = (*pWrapper->fp.requiredFp)(pWrapper, &required); + if (!required) { + dDebug("node:%s, does not require startup", pWrapper->name); + } + return required; +} + +static int32_t dmInitParentProc(SMgmtWrapper *pWrapper) { + int32_t shmsize = tsMnodeShmSize; + if (pWrapper->ntype == VNODE) { + shmsize = tsVnodeShmSize; + } else if (pWrapper->ntype == QNODE) { + shmsize = tsQnodeShmSize; + } else if (pWrapper->ntype == SNODE) { + shmsize = tsSnodeShmSize; + } else if (pWrapper->ntype == MNODE) { + shmsize = tsMnodeShmSize; + } else if (pWrapper->ntype == BNODE) { + shmsize = tsBnodeShmSize; + } else { + return -1; + } + + if (taosCreateShm(&pWrapper->procShm, pWrapper->ntype, shmsize) != 0) { + terrno = TAOS_SYSTEM_ERROR(terrno); + dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr()); + return -1; + } + dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->procShm.id, shmsize); + + SProcCfg cfg = dmGenProcCfg(pWrapper); + cfg.isChild = false; + pWrapper->procType = DND_PROC_PARENT; + pWrapper->procObj = taosProcInit(&cfg); + if (pWrapper->procObj == NULL) { + dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr()); + return -1; + } + + return 0; +} + +static int32_t dmNewNodeProc(SMgmtWrapper *pWrapper, EDndNodeType n) { + char tstr[8] = {0}; + char *args[6] = {0}; + snprintf(tstr, sizeof(tstr), "%d", n); + args[1] = "-c"; + args[2] = configDir; + args[3] = "-n"; + args[4] = tstr; + args[5] = NULL; + + int32_t pid = taosNewProc(args); + if (pid <= 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("node:%s, failed to exec in new process since %s", pWrapper->name, terrstr()); + return -1; + } + + pWrapper->procId = pid; + dInfo("node:%s, continue running in new process:%d", pWrapper->name, pid); + return 0; +} + +static int32_t dmRunParentProc(SMgmtWrapper *pWrapper) { + if (pWrapper->pDnode->ntype == NODE_END) { + dInfo("node:%s, should be started manually in child process", pWrapper->name); + } else { + if (dmNewNodeProc(pWrapper, pWrapper->ntype) != 0) { + return -1; + } + } + if (taosProcRun(pWrapper->procObj) != 0) { + dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); + return -1; + } + return 0; +} + +static int32_t dmInitChildProc(SMgmtWrapper *pWrapper) { + SProcCfg cfg = dmGenProcCfg(pWrapper); + cfg.isChild = true; + pWrapper->procObj = taosProcInit(&cfg); + if (pWrapper->procObj == NULL) { + dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr()); + return -1; + } + return 0; +} + +static int32_t dmRunChildProc(SMgmtWrapper *pWrapper) { + if (taosProcRun(pWrapper->procObj) != 0) { + dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); + return -1; + } + return 0; +} + +int32_t dmOpenNode(SMgmtWrapper *pWrapper) { + if (taosMkDir(pWrapper->path) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr()); + return -1; + } + + if (pWrapper->procType == DND_PROC_SINGLE || pWrapper->procType == DND_PROC_CHILD) { + if ((*pWrapper->fp.openFp)(pWrapper) != 0) { + dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); + return -1; + } + if (pWrapper->procType == DND_PROC_CHILD) { + if (dmInitChildProc(pWrapper) != 0) return -1; + if (dmRunChildProc(pWrapper) != 0) return -1; + } + dDebug("node:%s, has been opened", pWrapper->name); + pWrapper->deployed = true; + } else { + if (dmInitParentProc(pWrapper) != 0) return -1; + if (dmWriteShmFile(pWrapper) != 0) return -1; + if (dmRunParentProc(pWrapper) != 0) return -1; + } + + return 0; +} + +int32_t dmStartNode(SMgmtWrapper *pWrapper) { + if (pWrapper->procType == DND_PROC_PARENT) { + dInfo("node:%s, not start in parent process", pWrapper->name); + } else if (pWrapper->procType == DND_PROC_CHILD) { + dInfo("node:%s, start in child process", pWrapper->name); + if (pWrapper->ntype != DNODE) { + if (pWrapper->fp.startFp != NULL && (*pWrapper->fp.startFp)(pWrapper) != 0) { + dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); + return -1; + } + } + } else { + if (pWrapper->fp.startFp != NULL && (*pWrapper->fp.startFp)(pWrapper) != 0) { + dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); + return -1; + } + } + + return 0; +} + +void dmStopNode(SMgmtWrapper *pWrapper) { + if (pWrapper->fp.stopFp != NULL) { + (*pWrapper->fp.stopFp)(pWrapper); + } +} + +void dmCloseNode(SMgmtWrapper *pWrapper) { + dInfo("node:%s, start to close", pWrapper->name); + if (pWrapper->procType == DND_PROC_PARENT) { + if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) { + dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId); + taosKillProc(pWrapper->procId); + dInfo("node:%s, wait for child process:%d to stop", pWrapper->name, pWrapper->procId); + taosWaitProc(pWrapper->procId); + dInfo("node:%s, child process:%d is stopped", pWrapper->name, pWrapper->procId); + } + } + + dmStopNode(pWrapper); + + pWrapper->required = false; + taosWLockLatch(&pWrapper->latch); + if (pWrapper->deployed) { + (*pWrapper->fp.closeFp)(pWrapper); + pWrapper->deployed = false; + } + taosWUnLockLatch(&pWrapper->latch); + + while (pWrapper->refCount > 0) { + taosMsleep(10); + } + + if (pWrapper->procObj) { + taosProcCleanup(pWrapper->procObj); + pWrapper->procObj = NULL; + } + + dInfo("node:%s, has been closed", pWrapper->name); +} + +static int32_t dmOpenNodes(SDnode *pDnode) { + if (pDnode->ptype == DND_PROC_CHILD) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; + pWrapper->required = dmRequireNode(pWrapper); + if (!pWrapper->required) { + dError("dnode:%s, failed to open since not required", pWrapper->name); + } + + pWrapper->procType = DND_PROC_CHILD; + + SMsgCb msgCb = pDnode->data.msgCb; + msgCb.pWrapper = pWrapper; + tmsgSetDefaultMsgCb(&msgCb); + + if (dmOpenNode(pWrapper) != 0) { + dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); + return -1; + } + } else { + for (EDndNodeType n = DNODE; n < NODE_END; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + pWrapper->required = dmRequireNode(pWrapper); + if (!pWrapper->required) continue; + + if (pDnode->ptype == DND_PROC_PARENT && n != DNODE) { + pWrapper->procType = DND_PROC_PARENT; + } else { + pWrapper->procType = DND_PROC_SINGLE; + } + + if (dmOpenNode(pWrapper) != 0) { + dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); + return -1; + } + } + } + + dmSetStatus(pDnode, DND_STAT_RUNNING); + return 0; +} + +static int32_t dmStartNodes(SDnode *pDnode) { + for (EDndNodeType n = DNODE; n < NODE_END; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + if (!pWrapper->required) continue; + if (dmStartNode(pWrapper) != 0) { + dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); + return -1; + } + } + + dInfo("TDengine initialized successfully"); + dmReportStartup(pDnode, "TDengine", "initialized successfully"); + return 0; +} + +static void dmStopNodes(SDnode *pDnode) { + for (EDndNodeType n = DNODE; n < NODE_END; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + dmStopNode(pWrapper); + } +} + +static void dmCloseNodes(SDnode *pDnode) { + for (EDndNodeType n = DNODE; n < NODE_END; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + dmCloseNode(pWrapper); + } +} + +static void dmProcessProcHandle(void *handle) { + dWarn("handle:%p, the child process dies and send an offline rsp", handle); + SRpcMsg rpcMsg = {.handle = handle, .code = TSDB_CODE_NODE_OFFLINE}; + rpcSendResponse(&rpcMsg); +} + +static void dmWatchNodes(SDnode *pDnode) { + taosThreadMutexLock(&pDnode->mutex); + if (pDnode->ptype == DND_PROC_PARENT) { + for (EDndNodeType n = DNODE + 1; n < NODE_END; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + if (!pWrapper->required) continue; + if (pWrapper->procType != DND_PROC_PARENT) continue; + if (pDnode->ntype == NODE_END) continue; + + if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) { + dWarn("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId); + if (pWrapper->procObj) { + taosProcCloseHandles(pWrapper->procObj, dmProcessProcHandle); + } + dmNewNodeProc(pWrapper, n); + } + } + } + taosThreadMutexUnlock(&pDnode->mutex); +} + +int32_t dmRun(SDnode *pDnode) { + if (!tsMultiProcess) { + pDnode->ptype = DND_PROC_SINGLE; + dInfo("dnode run in single process"); + } else if (pDnode->ntype == DNODE || pDnode->ntype == NODE_END) { + pDnode->ptype = DND_PROC_PARENT; + dInfo("dnode run in parent process"); + } else { + pDnode->ptype = DND_PROC_CHILD; + SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; + dInfo("%s run in child process", pWrapper->name); + } + + if (dmOpenNodes(pDnode) != 0) { + dError("failed to open nodes since %s", terrstr()); + return -1; + } + + if (dmStartNodes(pDnode) != 0) { + dError("failed to start nodes since %s", terrstr()); + return -1; + } + + while (1) { + taosMsleep(100); + if (pDnode->event & DND_EVENT_STOP) { + dInfo("dnode is about to stop"); + dmSetStatus(pDnode, DND_STAT_STOPPED); + dmStopNodes(pDnode); + dmCloseNodes(pDnode); + return 0; + } else { + dmWatchNodes(pDnode); + } + } +} diff --git a/source/dnode/mgmt/implement/src/dmHandle.c b/source/dnode/mgmt/implement/src/dmHandle.c new file mode 100644 index 0000000000000000000000000000000000000000..93b24535a984529a55fc5957dfed4d477802cbd6 --- /dev/null +++ b/source/dnode/mgmt/implement/src/dmHandle.c @@ -0,0 +1,274 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "dmImp.h" + +static void dmUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) { + if (pDnode->data.dnodeId == 0) { + dInfo("set dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId); + taosWLockLatch(&pDnode->data.latch); + pDnode->data.dnodeId = pCfg->dnodeId; + pDnode->data.clusterId = pCfg->clusterId; + dmWriteEps(pDnode); + taosWUnLockLatch(&pDnode->data.latch); + } +} + +static int32_t dmProcessStatusRsp(SDnode *pDnode, SRpcMsg *pRsp) { + if (pRsp->code != TSDB_CODE_SUCCESS) { + if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pDnode->data.dropped && pDnode->data.dnodeId > 0) { + dInfo("dnode:%d, set to dropped since not exist in mnode", pDnode->data.dnodeId); + pDnode->data.dropped = 1; + dmWriteEps(pDnode); + } + } else { + SStatusRsp statusRsp = {0}; + if (pRsp->pCont != NULL && pRsp->contLen > 0 && + tDeserializeSStatusRsp(pRsp->pCont, pRsp->contLen, &statusRsp) == 0) { + pDnode->data.dnodeVer = statusRsp.dnodeVer; + dmUpdateDnodeCfg(pDnode, &statusRsp.dnodeCfg); + dmUpdateEps(pDnode, statusRsp.pDnodeEps); + } + tFreeSStatusRsp(&statusRsp); + } + + return TSDB_CODE_SUCCESS; +} + +void dmSendStatusReq(SDnode *pDnode) { + SStatusReq req = {0}; + + taosRLockLatch(&pDnode->data.latch); + req.sver = tsVersion; + req.dnodeVer = pDnode->data.dnodeVer; + req.dnodeId = pDnode->data.dnodeId; + req.clusterId = pDnode->data.clusterId; + req.rebootTime = pDnode->data.rebootTime; + req.updateTime = pDnode->data.updateTime; + req.numOfCores = tsNumOfCores; + req.numOfSupportVnodes = pDnode->data.supportVnodes; + tstrncpy(req.dnodeEp, pDnode->data.localEp, TSDB_EP_LEN); + + req.clusterCfg.statusInterval = tsStatusInterval; + req.clusterCfg.checkTime = 0; + char timestr[32] = "1970-01-01 00:00:00.00"; + (void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0); + memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); + memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN); + memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN); + taosRUnLockLatch(&pDnode->data.latch); + + SMonVloadInfo info = {0}; + dmGetVnodeLoads(pDnode, &info); + req.pVloads = info.pVloads; + + int32_t contLen = tSerializeSStatusReq(NULL, 0, &req); + void *pHead = rpcMallocCont(contLen); + tSerializeSStatusReq(pHead, contLen, &req); + tFreeSStatusReq(&req); + + SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)0x9527}; + SRpcMsg rpcRsp = {0}; + + dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle); + dmSendToMnodeRecv(pDnode, &rpcMsg, &rpcRsp); + dmProcessStatusRsp(pDnode, &rpcRsp); +} + +int32_t dmProcessAuthRsp(SDnode *pDnode, SNodeMsg *pMsg) { + SRpcMsg *pRsp = &pMsg->rpcMsg; + dError("auth rsp is received, but not supported yet"); + return 0; +} + +int32_t dmProcessGrantRsp(SDnode *pDnode, SNodeMsg *pMsg) { + SRpcMsg *pRsp = &pMsg->rpcMsg; + dError("grant rsp is received, but not supported yet"); + return 0; +} + +int32_t dmProcessConfigReq(SDnode *pDnode, SNodeMsg *pMsg) { + SRpcMsg *pReq = &pMsg->rpcMsg; + SDCfgDnodeReq *pCfg = pReq->pCont; + dError("config req is received, but not supported yet"); + return TSDB_CODE_OPS_NOT_SUPPORT; +} + +int32_t dmProcessCreateNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg) { + SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype); + if (pWrapper != NULL) { + dmReleaseWrapper(pWrapper); + terrno = TSDB_CODE_NODE_ALREADY_DEPLOYED; + dError("failed to create node since %s", terrstr()); + return -1; + } + + taosThreadMutexLock(&pDnode->mutex); + pWrapper = &pDnode->wrappers[ntype]; + + if (taosMkDir(pWrapper->path) != 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + dError("failed to create dir:%s since %s", pWrapper->path, terrstr()); + return -1; + } + + int32_t code = (*pWrapper->fp.createFp)(pWrapper, pMsg); + if (code != 0) { + dError("node:%s, failed to create since %s", pWrapper->name, terrstr()); + } else { + dDebug("node:%s, has been created", pWrapper->name); + pWrapper->required = true; + pWrapper->deployed = true; + pWrapper->procType = pDnode->ptype; + (void)dmOpenNode(pWrapper); + } + + taosThreadMutexUnlock(&pDnode->mutex); + return code; +} + +int32_t dmProcessDropNodeReq(SDnode *pDnode, EDndNodeType ntype, SNodeMsg *pMsg) { + SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype); + if (pWrapper == NULL) { + terrno = TSDB_CODE_NODE_NOT_DEPLOYED; + dError("failed to drop node since %s", terrstr()); + return -1; + } + + taosThreadMutexLock(&pDnode->mutex); + + int32_t code = (*pWrapper->fp.dropFp)(pWrapper, pMsg); + if (code != 0) { + dError("node:%s, failed to drop since %s", pWrapper->name, terrstr()); + } else { + dDebug("node:%s, has been dropped", pWrapper->name); + } + + dmReleaseWrapper(pWrapper); + + if (code == 0) { + dmCloseNode(pWrapper); + pWrapper->required = false; + pWrapper->deployed = false; + taosRemoveDir(pWrapper->path); + } + taosThreadMutexUnlock(&pDnode->mutex); + return code; +} + +static void dmSetMgmtMsgHandle(SMgmtWrapper *pWrapper) { + // Requests handled by DNODE + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); + + // Requests handled by MNODE + dmSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); +} + +static int32_t dmStartMgmt(SMgmtWrapper *pWrapper) { + if (dmStartStatusThread(pWrapper->pDnode) != 0) { + return -1; + } + if (dmStartMonitorThread(pWrapper->pDnode) != 0) { + return -1; + } + return 0; +} + +static void dmStopMgmt(SMgmtWrapper *pWrapper) { + dmStopMonitorThread(pWrapper->pDnode); + dmStopStatusThread(pWrapper->pDnode); +} + +static int32_t dmInitMgmt(SMgmtWrapper *pWrapper) { + dInfo("dnode-mgmt start to init"); + SDnode *pDnode = pWrapper->pDnode; + + pDnode->data.dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); + if (pDnode->data.dnodeHash == NULL) { + dError("failed to init dnode hash"); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + if (dmReadEps(pDnode) != 0) { + dError("failed to read file since %s", terrstr()); + return -1; + } + + if (pDnode->data.dropped) { + dError("dnode will not start since its already dropped"); + return -1; + } + + if (dmStartWorker(pDnode) != 0) { + return -1; + } + + if (dmInitTrans(pDnode) != 0) { + dError("failed to init transport since %s", terrstr()); + return -1; + } + + dInfo("dnode-mgmt is initialized"); + return 0; +} + +static void dmCleanupMgmt(SMgmtWrapper *pWrapper) { + dInfo("dnode-mgmt start to clean up"); + SDnode *pDnode = pWrapper->pDnode; + dmStopWorker(pDnode); + + taosWLockLatch(&pDnode->data.latch); + if (pDnode->data.dnodeEps != NULL) { + taosArrayDestroy(pDnode->data.dnodeEps); + pDnode->data.dnodeEps = NULL; + } + if (pDnode->data.dnodeHash != NULL) { + taosHashCleanup(pDnode->data.dnodeHash); + pDnode->data.dnodeHash = NULL; + } + taosWUnLockLatch(&pDnode->data.latch); + + dmCleanupTrans(pDnode); + dInfo("dnode-mgmt is cleaned up"); +} + +static int32_t dmRequireMgmt(SMgmtWrapper *pWrapper, bool *required) { + *required = true; + return 0; +} + +void dmSetMgmtFp(SMgmtWrapper *pWrapper) { + SMgmtFp mgmtFp = {0}; + mgmtFp.openFp = dmInitMgmt; + mgmtFp.closeFp = dmCleanupMgmt; + mgmtFp.startFp = dmStartMgmt; + mgmtFp.stopFp = dmStopMgmt; + mgmtFp.requiredFp = dmRequireMgmt; + + dmSetMgmtMsgHandle(pWrapper); + pWrapper->name = "dnode"; + pWrapper->fp = mgmtFp; +} diff --git a/source/dnode/mgmt/dm/dmMonitor.c b/source/dnode/mgmt/implement/src/dmMonitor.c similarity index 70% rename from source/dnode/mgmt/dm/dmMonitor.c rename to source/dnode/mgmt/implement/src/dmMonitor.c index fb5855070ca420685cd1a74f9e41089de8d2bd7f..b0774cd66f1620dedfaabe38c1a08a66808ca857 100644 --- a/source/dnode/mgmt/dm/dmMonitor.c +++ b/source/dnode/mgmt/implement/src/dmMonitor.c @@ -14,22 +14,21 @@ */ #define _DEFAULT_SOURCE -#include "dmInt.h" +#include "dmImp.h" static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) { pInfo->protocol = 1; - pInfo->dnode_id = pDnode->dnodeId; - pInfo->cluster_id = pDnode->clusterId; + pInfo->dnode_id = pDnode->data.dnodeId; + pInfo->cluster_id = pDnode->data.clusterId; tstrncpy(pInfo->dnode_ep, tsLocalEp, TSDB_EP_LEN); } static void dmGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) { - pInfo->uptime = (taosGetTimestampMs() - pDnode->rebootTime) / (86400000.0f); - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, MNODE); - if (pWrapper != NULL) { - pInfo->has_mnode = pWrapper->required; - dndReleaseWrapper(pWrapper); - } + pInfo->uptime = (taosGetTimestampMs() - pDnode->data.rebootTime) / (86400000.0f); + pInfo->has_mnode = pDnode->wrappers[MNODE].required; + pInfo->has_qnode = pDnode->wrappers[QNODE].required; + pInfo->has_snode = pDnode->wrappers[SNODE].required; + pInfo->has_bnode = pDnode->wrappers[BNODE].required; tstrncpy(pInfo->logdir.name, tsLogDir, sizeof(pInfo->logdir.name)); pInfo->logdir.size = tsLogSpace.size; tstrncpy(pInfo->tempdir.name, tsTempDir, sizeof(pInfo->tempdir.name)); @@ -56,7 +55,7 @@ void dmSendMonitorReport(SDnode *pDnode) { SRpcMsg req = {0}; SRpcMsg rsp; SEpSet epset = {.inUse = 0, .numOfEps = 1}; - tstrncpy(epset.eps[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN); + tstrncpy(epset.eps[0].fqdn, pDnode->data.localFqdn, TSDB_FQDN_LEN); epset.eps[0].port = tsServerPort; SMgmtWrapper *pWrapper = NULL; @@ -65,14 +64,14 @@ void dmSendMonitorReport(SDnode *pDnode) { bool getFromAPI = !tsMultiProcess; pWrapper = &pDnode->wrappers[MNODE]; if (getFromAPI) { - if (dndMarkWrapper(pWrapper) != 0) { + if (dmMarkWrapper(pWrapper) == 0) { mmGetMonitorInfo(pWrapper, &mmInfo); - dndReleaseWrapper(pWrapper); + dmReleaseWrapper(pWrapper); } } else { if (pWrapper->required) { req.msgType = TDMT_MON_MM_INFO; - dndSendRecv(pDnode, &epset, &req, &rsp); + dmSendRecv(pDnode, &epset, &req, &rsp); if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonMmInfo(rsp.pCont, rsp.contLen, &mmInfo); } @@ -80,16 +79,16 @@ void dmSendMonitorReport(SDnode *pDnode) { } } - pWrapper = &pDnode->wrappers[VNODES]; + pWrapper = &pDnode->wrappers[VNODE]; if (getFromAPI) { - if (dndMarkWrapper(pWrapper) != 0) { + if (dmMarkWrapper(pWrapper) == 0) { vmGetMonitorInfo(pWrapper, &vmInfo); - dndReleaseWrapper(pWrapper); + dmReleaseWrapper(pWrapper); } } else { if (pWrapper->required) { req.msgType = TDMT_MON_VM_INFO; - dndSendRecv(pDnode, &epset, &req, &rsp); + dmSendRecv(pDnode, &epset, &req, &rsp); if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonVmInfo(rsp.pCont, rsp.contLen, &vmInfo); } @@ -99,14 +98,14 @@ void dmSendMonitorReport(SDnode *pDnode) { pWrapper = &pDnode->wrappers[QNODE]; if (getFromAPI) { - if (dndMarkWrapper(pWrapper) != 0) { + if (dmMarkWrapper(pWrapper) == 0) { qmGetMonitorInfo(pWrapper, &qmInfo); - dndReleaseWrapper(pWrapper); + dmReleaseWrapper(pWrapper); } } else { if (pWrapper->required) { req.msgType = TDMT_MON_QM_INFO; - dndSendRecv(pDnode, &epset, &req, &rsp); + dmSendRecv(pDnode, &epset, &req, &rsp); if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonQmInfo(rsp.pCont, rsp.contLen, &qmInfo); } @@ -116,14 +115,14 @@ void dmSendMonitorReport(SDnode *pDnode) { pWrapper = &pDnode->wrappers[SNODE]; if (getFromAPI) { - if (dndMarkWrapper(pWrapper) != 0) { + if (dmMarkWrapper(pWrapper) == 0) { smGetMonitorInfo(pWrapper, &smInfo); - dndReleaseWrapper(pWrapper); + dmReleaseWrapper(pWrapper); } } else { if (pWrapper->required) { req.msgType = TDMT_MON_SM_INFO; - dndSendRecv(pDnode, &epset, &req, &rsp); + dmSendRecv(pDnode, &epset, &req, &rsp); if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonSmInfo(rsp.pCont, rsp.contLen, &smInfo); } @@ -133,14 +132,14 @@ void dmSendMonitorReport(SDnode *pDnode) { pWrapper = &pDnode->wrappers[BNODE]; if (getFromAPI) { - if (dndMarkWrapper(pWrapper) != 0) { + if (dmMarkWrapper(pWrapper) == 0) { bmGetMonitorInfo(pWrapper, &bmInfo); - dndReleaseWrapper(pWrapper); + dmReleaseWrapper(pWrapper); } } else { if (pWrapper->required) { req.msgType = TDMT_MON_BM_INFO; - dndSendRecv(pDnode, &epset, &req, &rsp); + dmSendRecv(pDnode, &epset, &req, &rsp); if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonBmInfo(rsp.pCont, rsp.contLen, &bmInfo); } @@ -162,7 +161,10 @@ void dmSendMonitorReport(SDnode *pDnode) { monSendReport(); } -void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) { +void dmGetVnodeLoads(SDnode *pDnode, SMonVloadInfo *pInfo) { + SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, VNODE); + if (pWrapper == NULL) return; + bool getFromAPI = !tsMultiProcess; if (getFromAPI) { vmGetVnodeLoads(pWrapper, pInfo); @@ -170,26 +172,14 @@ void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo) { SRpcMsg req = {.msgType = TDMT_MON_VM_LOAD}; SRpcMsg rsp = {0}; SEpSet epset = {.inUse = 0, .numOfEps = 1}; - tstrncpy(epset.eps[0].fqdn, tsLocalFqdn, TSDB_FQDN_LEN); + tstrncpy(epset.eps[0].fqdn, pDnode->data.localFqdn, TSDB_FQDN_LEN); epset.eps[0].port = tsServerPort; - dndSendRecv(pWrapper->pDnode, &epset, &req, &rsp); + dmSendRecv(pDnode, &epset, &req, &rsp); if (rsp.code == 0 && rsp.contLen > 0) { tDeserializeSMonVloadInfo(rsp.pCont, rsp.contLen, pInfo); } rpcFreeCont(rsp.pCont); } -} - -void dmGetMonitorSysInfo(SMonSysInfo *pInfo) { - taosGetCpuUsage(&pInfo->cpu_engine, &pInfo->cpu_system); - taosGetCpuCores(&pInfo->cpu_cores); - taosGetProcMemory(&pInfo->mem_engine); - taosGetSysMemory(&pInfo->mem_system); - pInfo->mem_total = tsTotalMemoryKB; - pInfo->disk_engine = 0; - pInfo->disk_used = tsDataSpace.size.used; - pInfo->disk_total = tsDataSpace.size.total; - taosGetCardInfoDelta(&pInfo->net_in, &pInfo->net_out); - taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk); + dmReleaseWrapper(pWrapper); } diff --git a/source/dnode/mgmt/implement/src/dmObj.c b/source/dnode/mgmt/implement/src/dmObj.c new file mode 100644 index 0000000000000000000000000000000000000000..66bfb2701624afe8ad5decfe849ac8a9bd9b39ca --- /dev/null +++ b/source/dnode/mgmt/implement/src/dmObj.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "dmImp.h" + +static int32_t dmInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { + pDnode->data.dnodeId = 0; + pDnode->data.clusterId = 0; + pDnode->data.dnodeVer = 0; + pDnode->data.updateTime = 0; + pDnode->data.rebootTime = taosGetTimestampMs(); + pDnode->data.dropped = 0; + pDnode->data.localEp = strdup(pOption->localEp); + pDnode->data.localFqdn = strdup(pOption->localFqdn); + pDnode->data.firstEp = strdup(pOption->firstEp); + pDnode->data.secondEp = strdup(pOption->secondEp); + pDnode->data.dataDir = strdup(pOption->dataDir); + pDnode->data.disks = pOption->disks; + pDnode->data.numOfDisks = pOption->numOfDisks; + pDnode->data.supportVnodes = pOption->numOfSupportVnodes; + pDnode->data.serverPort = pOption->serverPort; + pDnode->ntype = pOption->ntype; + + if (pDnode->data.dataDir == NULL || pDnode->data.localEp == NULL || pDnode->data.localFqdn == NULL || + pDnode->data.firstEp == NULL || pDnode->data.secondEp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_END) { + pDnode->data.lockfile = dmCheckRunning(pDnode->data.dataDir); + if (pDnode->data.lockfile == NULL) { + return -1; + } + } + + taosInitRWLatch(&pDnode->data.latch); + taosThreadMutexInit(&pDnode->mutex, NULL); + return 0; +} + +static void dmClearVars(SDnode *pDnode) { + for (EDndNodeType n = DNODE; n < NODE_END; ++n) { + SMgmtWrapper *pMgmt = &pDnode->wrappers[n]; + taosMemoryFreeClear(pMgmt->path); + } + if (pDnode->data.lockfile != NULL) { + taosUnLockFile(pDnode->data.lockfile); + taosCloseFile(&pDnode->data.lockfile); + pDnode->data.lockfile = NULL; + } + taosMemoryFreeClear(pDnode->data.localEp); + taosMemoryFreeClear(pDnode->data.localFqdn); + taosMemoryFreeClear(pDnode->data.firstEp); + taosMemoryFreeClear(pDnode->data.secondEp); + taosMemoryFreeClear(pDnode->data.dataDir); + taosThreadMutexDestroy(&pDnode->mutex); + memset(&pDnode->mutex, 0, sizeof(pDnode->mutex)); + taosMemoryFree(pDnode); + dDebug("dnode memory is cleared, data:%p", pDnode); +} + +SDnode *dmCreate(const SDnodeOpt *pOption) { + dDebug("start to create dnode"); + int32_t code = -1; + char path[PATH_MAX] = {0}; + SDnode *pDnode = NULL; + + pDnode = taosMemoryCalloc(1, sizeof(SDnode)); + if (pDnode == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _OVER; + } + + if (dmInitVars(pDnode, pOption) != 0) { + dError("failed to init variables since %s", terrstr()); + goto _OVER; + } + + dmSetStatus(pDnode, DND_STAT_INIT); + dmSetMgmtFp(&pDnode->wrappers[DNODE]); + mmSetMgmtFp(&pDnode->wrappers[MNODE]); + vmSetMgmtFp(&pDnode->wrappers[VNODE]); + qmSetMgmtFp(&pDnode->wrappers[QNODE]); + smSetMgmtFp(&pDnode->wrappers[SNODE]); + bmSetMgmtFp(&pDnode->wrappers[BNODE]); + + for (EDndNodeType n = DNODE; n < NODE_END; ++n) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; + snprintf(path, sizeof(path), "%s%s%s", pDnode->data.dataDir, TD_DIRSEP, pWrapper->name); + pWrapper->path = strdup(path); + pWrapper->procShm.id = -1; + pWrapper->pDnode = pDnode; + pWrapper->ntype = n; + pWrapper->procType = DND_PROC_SINGLE; + taosInitRWLatch(&pWrapper->latch); + + if (pWrapper->path == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _OVER; + } + + if (n != DNODE && dmReadShmFile(pWrapper) != 0) { + dError("node:%s, failed to read shm file since %s", pWrapper->name, terrstr()); + goto _OVER; + } + } + + if (dmInitMsgHandle(pDnode) != 0) { + dError("failed to init msg handles since %s", terrstr()); + goto _OVER; + } + + pDnode->data.msgCb = dmGetMsgcb(&pDnode->wrappers[DNODE]); + tmsgSetDefaultMsgCb(&pDnode->data.msgCb); + + dInfo("dnode is created, data:%p", pDnode); + code = 0; + +_OVER: + if (code != 0 && pDnode) { + dmClearVars(pDnode); + pDnode = NULL; + dError("failed to create dnode since %s", terrstr()); + } + + return pDnode; +} + +void dmClose(SDnode *pDnode) { + if (pDnode == NULL) return; + dmClearVars(pDnode); + dInfo("dnode is closed, data:%p", pDnode); +} diff --git a/source/dnode/mgmt/main/dndTransport.c b/source/dnode/mgmt/implement/src/dmTransport.c similarity index 54% rename from source/dnode/mgmt/main/dndTransport.c rename to source/dnode/mgmt/implement/src/dmTransport.c index 75722c8f9c1424df5b41f294414096f5c6910b7d..aa38c2492d0d9d62e317476179c2a19eab99e3c8 100644 --- a/source/dnode/mgmt/main/dndTransport.c +++ b/source/dnode/mgmt/implement/src/dmTransport.c @@ -14,18 +14,31 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dmImp.h" #define INTERNAL_USER "_dnd" #define INTERNAL_CKEY "_key" #define INTERNAL_SECRET "_pwd" -static void dndUpdateMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[DNODE]; - dmUpdateMnodeEpSet(pWrapper->pMgmt, pEpSet); +static void dmGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { + taosRLockLatch(&pDnode->data.latch); + *pEpSet = pDnode->data.mnodeEps; + taosRUnLockLatch(&pDnode->data.latch); } -static inline NodeMsgFp dndGetMsgFp(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { +static void dmSetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { + dInfo("mnode is changed, num:%d use:%d", pEpSet->numOfEps, pEpSet->inUse); + + taosWLockLatch(&pDnode->data.latch); + pDnode->data.mnodeEps = *pEpSet; + for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { + dInfo("mnode index:%d %s:%u", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port); + } + + taosWUnLockLatch(&pDnode->data.latch); +} + +static inline NodeMsgFp dmGetMsgFp(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pRpc->msgType)]; if (msgFp == NULL) { terrno = TSDB_CODE_MSG_NOT_PROCESSED; @@ -34,7 +47,7 @@ static inline NodeMsgFp dndGetMsgFp(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { return msgFp; } -static inline int32_t dndBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) { +static inline int32_t dmBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) { SRpcConnInfo connInfo = {0}; if ((pRpc->msgType & 1U) && rpcGetConnInfo(pRpc->handle, &connInfo) != 0) { terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; @@ -49,27 +62,29 @@ static inline int32_t dndBuildMsg(SNodeMsg *pMsg, SRpcMsg *pRpc) { return 0; } -static void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) { +static void dmProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSet) { int32_t code = -1; SNodeMsg *pMsg = NULL; NodeMsgFp msgFp = NULL; + uint16_t msgType = pRpc->msgType; - if (pEpSet && pEpSet->numOfEps > 0 && pRpc->msgType == TDMT_MND_STATUS_RSP) { - dndUpdateMnodeEpSet(pWrapper->pDnode, pEpSet); + if (pEpSet && pEpSet->numOfEps > 0 && msgType == TDMT_MND_STATUS_RSP) { + dmSetMnodeEpSet(pWrapper->pDnode, pEpSet); } - if (dndMarkWrapper(pWrapper) != 0) goto _OVER; - if ((msgFp = dndGetMsgFp(pWrapper, pRpc)) == NULL) goto _OVER; + if (dmMarkWrapper(pWrapper) != 0) goto _OVER; + if ((msgFp = dmGetMsgFp(pWrapper, pRpc)) == NULL) goto _OVER; if ((pMsg = taosAllocateQitem(sizeof(SNodeMsg))) == NULL) goto _OVER; - if (dndBuildMsg(pMsg, pRpc) != 0) goto _OVER; + if (dmBuildMsg(pMsg, pRpc) != 0) goto _OVER; - if (pWrapper->procType == PROC_SINGLE) { - dTrace("msg:%p, is created, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user); + if (pWrapper->procType == DND_PROC_SINGLE) { + dTrace("msg:%p, is created, type:%s handle:%p user:%s", pMsg, TMSG_INFO(msgType), pRpc->handle, pMsg->user); code = (*msgFp)(pWrapper, pMsg); - } else if (pWrapper->procType == PROC_PARENT) { - dTrace("msg:%p, is created and put into child queue, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user); - code = taosProcPutToChildQ(pWrapper->pProc, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, pRpc->handle, - PROC_REQ); + } else if (pWrapper->procType == DND_PROC_PARENT) { + dTrace("msg:%p, is created and put into child queue, type:%s handle:%p user:%s", pMsg, TMSG_INFO(msgType), + pRpc->handle, pMsg->user); + code = taosProcPutToChildQ(pWrapper->procObj, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen, pRpc->handle, + PROC_FUNC_REQ); } else { dTrace("msg:%p, should not processed in child process, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user); ASSERT(1); @@ -77,16 +92,22 @@ static void dndProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpS _OVER: if (code == 0) { - if (pWrapper->procType == PROC_PARENT) { + if (pWrapper->procType == DND_PROC_PARENT) { dTrace("msg:%p, is freed in parent process", pMsg); taosFreeQitem(pMsg); rpcFreeCont(pRpc->pCont); } } else { - dError("msg:%p, failed to process since 0x%04x:%s", pMsg, code & 0XFFFF, terrstr()); - if (pRpc->msgType & 1U) { + dError("msg:%p, type:%s failed to process since 0x%04x:%s", pMsg, TMSG_INFO(msgType), code & 0XFFFF, terrstr()); + if (msgType & 1U) { if (terrno != 0) code = terrno; - SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno}; + if (code == TSDB_CODE_NODE_NOT_DEPLOYED || code == TSDB_CODE_NODE_OFFLINE) { + if (msgType > TDMT_MND_MSG && msgType < TDMT_VND_MSG) { + code = TSDB_CODE_NODE_REDIRECT; + } + } + + SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = code}; tmsgSendRsp(&rsp); } dTrace("msg:%p, is freed", pMsg); @@ -94,23 +115,23 @@ _OVER: rpcFreeCont(pRpc->pCont); } - dndReleaseWrapper(pWrapper); + dmReleaseWrapper(pWrapper); } -static void dndProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { - STransMgmt *pMgmt = &pDnode->trans; +static void dmProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { + SDnodeTrans *pTrans = &pDnode->trans; tmsg_t msgType = pMsg->msgType; bool isReq = msgType & 1u; - SMsgHandle *pHandle = &pMgmt->msgHandles[TMSG_INDEX(msgType)]; - SMgmtWrapper *pWrapper = pHandle->pWrapper; + SMsgHandle *pHandle = &pTrans->msgHandles[TMSG_INDEX(msgType)]; + SMgmtWrapper *pWrapper = pHandle->pNdWrapper; if (msgType == TDMT_DND_NETWORK_TEST) { dTrace("network test req will be processed, handle:%p, app:%p", pMsg->handle, pMsg->ahandle); - dndProcessStartupReq(pDnode, pMsg); + dmProcessStartupReq(pDnode, pMsg); return; } - if (dndGetStatus(pDnode) != DND_STAT_RUNNING) { + if (pDnode->status != DND_STAT_RUNNING) { dError("msg:%s ignored since dnode not running, handle:%p app:%p", TMSG_INFO(msgType), pMsg->handle, pMsg->ahandle); if (isReq) { SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_APP_NOT_READY, .ahandle = pMsg->ahandle}; @@ -134,6 +155,7 @@ static void dndProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { rpcSendResponse(&rspMsg); } rpcFreeCont(pMsg->pCont); + return; } if (pHandle->pMndWrapper != NULL || pHandle->pQndWrapper != NULL) { @@ -148,162 +170,13 @@ static void dndProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { } dTrace("msg:%s will be processed by %s, app:%p", TMSG_INFO(msgType), pWrapper->name, pMsg->ahandle); - dndProcessRpcMsg(pWrapper, pMsg, pEpSet); -} - -static int32_t dndInitClient(SDnode *pDnode) { - STransMgmt *pMgmt = &pDnode->trans; - - SRpcInit rpcInit; - memset(&rpcInit, 0, sizeof(rpcInit)); - rpcInit.label = "DND"; - rpcInit.numOfThreads = 1; - rpcInit.cfp = (RpcCfp)dndProcessMsg; - rpcInit.sessions = 1024; - rpcInit.connType = TAOS_CONN_CLIENT; - rpcInit.idleTime = tsShellActivityTimer * 1000; - rpcInit.user = INTERNAL_USER; - rpcInit.ckey = INTERNAL_CKEY; - rpcInit.spi = 1; - rpcInit.parent = pDnode; - - char pass[TSDB_PASSWORD_LEN + 1] = {0}; - taosEncryptPass_c((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass); - rpcInit.secret = pass; - - pMgmt->clientRpc = rpcOpen(&rpcInit); - if (pMgmt->clientRpc == NULL) { - dError("failed to init dnode rpc client"); - return -1; - } - - dDebug("dnode rpc client is initialized"); - return 0; -} - -static void dndCleanupClient(SDnode *pDnode) { - STransMgmt *pMgmt = &pDnode->trans; - if (pMgmt->clientRpc) { - rpcClose(pMgmt->clientRpc); - pMgmt->clientRpc = NULL; - dDebug("dnode rpc client is closed"); - } -} - -static inline void dndSendMsgToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp) { - SEpSet epSet = {0}; - SMgmtWrapper *pWrapper = &pDnode->wrappers[DNODE]; - dmGetMnodeEpSet(pWrapper->pMgmt, &epSet); - rpcSendRecv(pDnode->trans.clientRpc, &epSet, pReq, pRsp); -} - -static inline int32_t dndGetHideUserAuth(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, - char *ckey) { - int32_t code = 0; - char pass[TSDB_PASSWORD_LEN + 1] = {0}; - - if (strcmp(user, INTERNAL_USER) == 0) { - taosEncryptPass_c((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass); - } else if (strcmp(user, TSDB_NETTEST_USER) == 0) { - taosEncryptPass_c((uint8_t *)(TSDB_NETTEST_USER), strlen(TSDB_NETTEST_USER), pass); - } else { - code = -1; - } - - if (code == 0) { - memcpy(secret, pass, TSDB_PASSWORD_LEN); - *spi = 1; - *encrypt = 0; - *ckey = 0; - } - - return code; + dmProcessRpcMsg(pWrapper, pMsg, pEpSet); } -static int32_t dndRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) { - if (dndGetHideUserAuth(pDnode, user, spi, encrypt, secret, ckey) == 0) { - dTrace("user:%s, get auth from mnode, spi:%d encrypt:%d", user, *spi, *encrypt); - return 0; - } - - SAuthReq authReq = {0}; - tstrncpy(authReq.user, user, TSDB_USER_LEN); - int32_t contLen = tSerializeSAuthReq(NULL, 0, &authReq); - void *pReq = rpcMallocCont(contLen); - tSerializeSAuthReq(pReq, contLen, &authReq); - - SRpcMsg rpcMsg = {.pCont = pReq, .contLen = contLen, .msgType = TDMT_MND_AUTH, .ahandle = (void *)9528}; - SRpcMsg rpcRsp = {0}; - dTrace("user:%s, send user auth req to other mnodes, spi:%d encrypt:%d", user, authReq.spi, authReq.encrypt); - dndSendMsgToMnodeRecv(pDnode, &rpcMsg, &rpcRsp); - - if (rpcRsp.code != 0) { - terrno = rpcRsp.code; - dError("user:%s, failed to get user auth from other mnodes since %s", user, terrstr()); - } else { - SAuthRsp authRsp = {0}; - tDeserializeSAuthReq(rpcRsp.pCont, rpcRsp.contLen, &authRsp); - memcpy(secret, authRsp.secret, TSDB_PASSWORD_LEN); - memcpy(ckey, authRsp.ckey, TSDB_PASSWORD_LEN); - *spi = authRsp.spi; - *encrypt = authRsp.encrypt; - dTrace("user:%s, success to get user auth from other mnodes, spi:%d encrypt:%d", user, authRsp.spi, - authRsp.encrypt); - } - - rpcFreeCont(rpcRsp.pCont); - return rpcRsp.code; -} +int32_t dmInitMsgHandle(SDnode *pDnode) { + SDnodeTrans *pTrans = &pDnode->trans; -static int32_t dndInitServer(SDnode *pDnode) { - STransMgmt *pMgmt = &pDnode->trans; - - SRpcInit rpcInit; - memset(&rpcInit, 0, sizeof(rpcInit)); - rpcInit.localPort = pDnode->serverPort; - rpcInit.label = "DND"; - rpcInit.numOfThreads = tsNumOfRpcThreads; - rpcInit.cfp = (RpcCfp)dndProcessMsg; - rpcInit.sessions = tsMaxShellConns; - rpcInit.connType = TAOS_CONN_SERVER; - rpcInit.idleTime = tsShellActivityTimer * 1000; - rpcInit.afp = (RpcAfp)dndRetrieveUserAuthInfo; - rpcInit.parent = pDnode; - - pMgmt->serverRpc = rpcOpen(&rpcInit); - if (pMgmt->serverRpc == NULL) { - dError("failed to init dnode rpc server"); - return -1; - } - - dDebug("dnode rpc server is initialized"); - return 0; -} - -static void dndCleanupServer(SDnode *pDnode) { - STransMgmt *pMgmt = &pDnode->trans; - if (pMgmt->serverRpc) { - rpcClose(pMgmt->serverRpc); - pMgmt->serverRpc = NULL; - dDebug("dnode rpc server is closed"); - } -} - -int32_t dndInitTrans(SDnode *pDnode) { - if (dndInitServer(pDnode) != 0) return -1; - if (dndInitClient(pDnode) != 0) return -1; - return 0; -} - -void dndCleanupTrans(SDnode *pDnode) { - dndCleanupServer(pDnode); - dndCleanupClient(pDnode); -} - -int32_t dndInitMsgHandle(SDnode *pDnode) { - STransMgmt *pMgmt = &pDnode->trans; - - for (EDndType n = 0; n < NODE_MAX; ++n) { + for (EDndNodeType n = DNODE; n < NODE_END; ++n) { SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; for (int32_t msgIndex = 0; msgIndex < TDMT_MAX; ++msgIndex) { @@ -311,7 +184,7 @@ int32_t dndInitMsgHandle(SDnode *pDnode) { int8_t vgId = pWrapper->msgVgIds[msgIndex]; if (msgFp == NULL) continue; - SMsgHandle *pHandle = &pMgmt->msgHandles[msgIndex]; + SMsgHandle *pHandle = &pTrans->msgHandles[msgIndex]; if (vgId == QNODE_HANDLE) { if (pHandle->pQndWrapper != NULL) { dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]); @@ -325,11 +198,11 @@ int32_t dndInitMsgHandle(SDnode *pDnode) { } pHandle->pMndWrapper = pWrapper; } else { - if (pHandle->pWrapper != NULL) { + if (pHandle->pNdWrapper != NULL) { dError("msg:%s has multiple process nodes", tMsgInfo[msgIndex]); return -1; } - pHandle->pWrapper = pWrapper; + pHandle->pNdWrapper = pWrapper; } } } @@ -337,34 +210,60 @@ int32_t dndInitMsgHandle(SDnode *pDnode) { return 0; } -static int32_t dndSendRpcReq(STransMgmt *pMgmt, const SEpSet *pEpSet, SRpcMsg *pReq) { - if (pMgmt->clientRpc == NULL) { +static inline int32_t dmSendRpcReq(SDnode *pDnode, const SEpSet *pEpSet, SRpcMsg *pReq) { + if (pDnode->trans.clientRpc == NULL) { terrno = TSDB_CODE_NODE_OFFLINE; return -1; } - rpcSendRequest(pMgmt->clientRpc, pEpSet, pReq, NULL); + rpcSendRequest(pDnode->trans.clientRpc, pEpSet, pReq, NULL); return 0; } -static void dndSendRpcRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) { - if (pRsp->code == TSDB_CODE_APP_NOT_READY || pRsp->code == TSDB_CODE_NODE_REDIRECT || - pRsp->code == TSDB_CODE_NODE_OFFLINE) { - dmSendRedirectRsp(pWrapper->pMgmt, pRsp); +static void dmSendRpcRedirectRsp(SDnode *pDnode, const SRpcMsg *pReq) { + SEpSet epSet = {0}; + dmGetMnodeEpSet(pDnode, &epSet); + + dDebug("RPC %p, req is redirected, num:%d use:%d", pReq->handle, epSet.numOfEps, epSet.inUse); + for (int32_t i = 0; i < epSet.numOfEps; ++i) { + dDebug("mnode index:%d %s:%u", i, epSet.eps[i].fqdn, epSet.eps[i].port); + if (strcmp(epSet.eps[i].fqdn, pDnode->data.localFqdn) == 0 && epSet.eps[i].port == pDnode->data.serverPort) { + epSet.inUse = (i + 1) % epSet.numOfEps; + } + + epSet.eps[i].port = htons(epSet.eps[i].port); + } + + rpcSendRedirectRsp(pReq->handle, &epSet); +} + +static inline void dmSendRpcRsp(SDnode *pDnode, const SRpcMsg *pRsp) { + if (pRsp->code == TSDB_CODE_NODE_REDIRECT) { + dmSendRpcRedirectRsp(pDnode, pRsp); } else { rpcSendResponse(pRsp); } } -static int32_t dndSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) { - if (dndGetStatus(pWrapper->pDnode) != DND_STAT_RUNNING) { +void dmSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp) { + rpcSendRecv(pDnode->trans.clientRpc, pEpSet, pReq, pRsp); +} + +void dmSendToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp) { + SEpSet epSet = {0}; + dmGetMnodeEpSet(pDnode, &epSet); + rpcSendRecv(pDnode->trans.clientRpc, &epSet, pReq, pRsp); +} + +static inline int32_t dmSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) { + if (pWrapper->pDnode->status != DND_STAT_RUNNING) { terrno = TSDB_CODE_NODE_OFFLINE; dError("failed to send rpc msg since %s, handle:%p", terrstr(), pReq->handle); return -1; } - if (pWrapper->procType != PROC_CHILD) { - return dndSendRpcReq(&pWrapper->pDnode->trans, pEpSet, pReq); + if (pWrapper->procType != DND_PROC_CHILD) { + return dmSendRpcReq(pWrapper->pDnode, pEpSet, pReq); } else { char *pHead = taosMemoryMalloc(sizeof(SRpcMsg) + sizeof(SEpSet)); if (pHead == NULL) { @@ -374,51 +273,40 @@ static int32_t dndSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg memcpy(pHead, pReq, sizeof(SRpcMsg)); memcpy(pHead + sizeof(SRpcMsg), pEpSet, sizeof(SEpSet)); - taosProcPutToParentQ(pWrapper->pProc, pHead, sizeof(SRpcMsg) + sizeof(SEpSet), pReq->pCont, pReq->contLen, - PROC_REQ); + taosProcPutToParentQ(pWrapper->procObj, pHead, sizeof(SRpcMsg) + sizeof(SEpSet), pReq->pCont, pReq->contLen, + PROC_FUNC_REQ); taosMemoryFree(pHead); return 0; } } -static void dndSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) { - if (pWrapper->procType != PROC_CHILD) { - dndSendRpcRsp(pWrapper, pRsp); +static inline void dmSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) { + if (pWrapper->procType != DND_PROC_CHILD) { + dmSendRpcRsp(pWrapper->pDnode, pRsp); } else { - taosProcPutToParentQ(pWrapper->pProc, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen, PROC_RSP); + taosProcPutToParentQ(pWrapper->procObj, pRsp, sizeof(SRpcMsg), pRsp->pCont, pRsp->contLen, PROC_FUNC_RSP); } } -static void dndRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) { - if (pWrapper->procType != PROC_CHILD) { +static inline void dmRegisterBrokenLinkArg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) { + if (pWrapper->procType != DND_PROC_CHILD) { rpcRegisterBrokenLinkArg(pMsg); } else { - taosProcPutToParentQ(pWrapper->pProc, pMsg, sizeof(SRpcMsg), pMsg->pCont, pMsg->contLen, PROC_REGIST); + taosProcPutToParentQ(pWrapper->procObj, pMsg, sizeof(SRpcMsg), pMsg->pCont, pMsg->contLen, PROC_FUNC_REGIST); } } -static void dndReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type) { - if (pWrapper->procType != PROC_CHILD) { +static inline void dmReleaseHandle(SMgmtWrapper *pWrapper, void *handle, int8_t type) { + if (pWrapper->procType != DND_PROC_CHILD) { rpcReleaseHandle(handle, type); } else { SRpcMsg msg = {.handle = handle, .code = type}; - taosProcPutToParentQ(pWrapper->pProc, &msg, sizeof(SRpcMsg), NULL, 0, PROC_RELEASE); + taosProcPutToParentQ(pWrapper->procObj, &msg, sizeof(SRpcMsg), NULL, 0, PROC_FUNC_RELEASE); } } -SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper) { - SMsgCb msgCb = { - .pWrapper = pWrapper, - .sendReqFp = dndSendReq, - .sendRspFp = dndSendRsp, - .registerBrokenLinkArgFp = dndRegisterBrokenLinkArg, - .releaseHandleFp = dndReleaseHandle, - }; - return msgCb; -} - -static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, - ProcFuncType ftype) { +static void dmConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, + EProcFuncType ftype) { SRpcMsg *pRpc = &pMsg->rpcMsg; pRpc->pCont = pCont; dTrace("msg:%p, get from child queue, handle:%p app:%p", pMsg, pRpc->handle, pRpc->ahandle); @@ -430,7 +318,7 @@ static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t dError("msg:%p, failed to process since code:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); if (pRpc->msgType & 1U) { SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = terrno}; - dndSendRsp(pWrapper, &rsp); + dmSendRsp(pWrapper, &rsp); } dTrace("msg:%p, is freed", pMsg); @@ -439,26 +327,27 @@ static void dndConsumeChildQueue(SMgmtWrapper *pWrapper, SNodeMsg *pMsg, int16_t } } -static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, - ProcFuncType ftype) { +static void dmConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t msgLen, void *pCont, int32_t contLen, + EProcFuncType ftype) { pMsg->pCont = pCont; - dTrace("msg:%p, get from parent queue, ftype:%d handle:%p, app:%p", pMsg, ftype, pMsg->handle, pMsg->ahandle); + dTrace("msg:%p, get from parent queue, ftype:%d handle:%p code:0x%04x mtype:%d, app:%p", pMsg, ftype, pMsg->handle, + pMsg->code & 0xFFFF, pMsg->msgType, pMsg->ahandle); switch (ftype) { - case PROC_REGIST: + case PROC_FUNC_REGIST: rpcRegisterBrokenLinkArg(pMsg); break; - case PROC_RELEASE: - taosProcRemoveHandle(pWrapper->pProc, pMsg->handle); + case PROC_FUNC_RELEASE: + taosProcRemoveHandle(pWrapper->procObj, pMsg->handle); rpcReleaseHandle(pMsg->handle, (int8_t)pMsg->code); rpcFreeCont(pCont); break; - case PROC_REQ: - dndSendRpcReq(&pWrapper->pDnode->trans, (SEpSet *)((char *)pMsg + sizeof(SRpcMsg)), pMsg); + case PROC_FUNC_REQ: + dmSendRpcReq(pWrapper->pDnode, (SEpSet *)((char *)pMsg + sizeof(SRpcMsg)), pMsg); break; - case PROC_RSP: - taosProcRemoveHandle(pWrapper->pProc, pMsg->handle); - dndSendRpcRsp(pWrapper, pMsg); + case PROC_FUNC_RSP: + taosProcRemoveHandle(pWrapper->procObj, pMsg->handle); + dmSendRpcRsp(pWrapper->pDnode, pMsg); break; default: break; @@ -466,23 +355,171 @@ static void dndConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t taosMemoryFree(pMsg); } -SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper) { - SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dndConsumeChildQueue, +SProcCfg dmGenProcCfg(SMgmtWrapper *pWrapper) { + SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dmConsumeChildQueue, .childMallocHeadFp = (ProcMallocFp)taosAllocateQitem, .childFreeHeadFp = (ProcFreeFp)taosFreeQitem, .childMallocBodyFp = (ProcMallocFp)rpcMallocCont, .childFreeBodyFp = (ProcFreeFp)rpcFreeCont, - .parentConsumeFp = (ProcConsumeFp)dndConsumeParentQueue, + .parentConsumeFp = (ProcConsumeFp)dmConsumeParentQueue, .parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc, .parentFreeHeadFp = (ProcFreeFp)taosMemoryFree, .parentMallocBodyFp = (ProcMallocFp)rpcMallocCont, .parentFreeBodyFp = (ProcFreeFp)rpcFreeCont, - .shm = pWrapper->shm, + .shm = pWrapper->procShm, .parent = pWrapper, .name = pWrapper->name}; return cfg; } -void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp) { - rpcSendRecv(pDnode->trans.clientRpc, pEpSet, pReq, pRsp); +static int32_t dmInitClient(SDnode *pDnode) { + SDnodeTrans *pTrans = &pDnode->trans; + + SRpcInit rpcInit = {0}; + rpcInit.label = "DND"; + rpcInit.numOfThreads = 1; + rpcInit.cfp = (RpcCfp)dmProcessMsg; + rpcInit.sessions = 1024; + rpcInit.connType = TAOS_CONN_CLIENT; + rpcInit.idleTime = tsShellActivityTimer * 1000; + rpcInit.user = INTERNAL_USER; + rpcInit.ckey = INTERNAL_CKEY; + rpcInit.spi = 1; + rpcInit.parent = pDnode; + + char pass[TSDB_PASSWORD_LEN + 1] = {0}; + taosEncryptPass_c((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass); + rpcInit.secret = pass; + + pTrans->clientRpc = rpcOpen(&rpcInit); + if (pTrans->clientRpc == NULL) { + dError("failed to init dnode rpc client"); + return -1; + } + + dDebug("dnode rpc client is initialized"); + return 0; +} + +static void dmCleanupClient(SDnode *pDnode) { + SDnodeTrans *pTrans = &pDnode->trans; + if (pTrans->clientRpc) { + rpcClose(pTrans->clientRpc); + pTrans->clientRpc = NULL; + dDebug("dnode rpc client is closed"); + } +} + +static inline int32_t dmGetHideUserAuth(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, + char *ckey) { + int32_t code = 0; + char pass[TSDB_PASSWORD_LEN + 1] = {0}; + + if (strcmp(user, INTERNAL_USER) == 0) { + taosEncryptPass_c((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass); + } else if (strcmp(user, TSDB_NETTEST_USER) == 0) { + taosEncryptPass_c((uint8_t *)(TSDB_NETTEST_USER), strlen(TSDB_NETTEST_USER), pass); + } else { + code = -1; + } + + if (code == 0) { + memcpy(secret, pass, TSDB_PASSWORD_LEN); + *spi = 1; + *encrypt = 0; + *ckey = 0; + } + + return code; +} + +static inline int32_t dmRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, + char *ckey) { + if (dmGetHideUserAuth(pDnode, user, spi, encrypt, secret, ckey) == 0) { + dTrace("user:%s, get auth from mnode, spi:%d encrypt:%d", user, *spi, *encrypt); + return 0; + } + + SAuthReq authReq = {0}; + tstrncpy(authReq.user, user, TSDB_USER_LEN); + int32_t contLen = tSerializeSAuthReq(NULL, 0, &authReq); + void *pReq = rpcMallocCont(contLen); + tSerializeSAuthReq(pReq, contLen, &authReq); + + SRpcMsg rpcMsg = {.pCont = pReq, .contLen = contLen, .msgType = TDMT_MND_AUTH, .ahandle = (void *)9528}; + SRpcMsg rpcRsp = {0}; + dTrace("user:%s, send user auth req to other mnodes, spi:%d encrypt:%d", user, authReq.spi, authReq.encrypt); + dmSendToMnodeRecv(pDnode, &rpcMsg, &rpcRsp); + + if (rpcRsp.code != 0) { + terrno = rpcRsp.code; + dError("user:%s, failed to get user auth from other mnodes since %s", user, terrstr()); + } else { + SAuthRsp authRsp = {0}; + tDeserializeSAuthReq(rpcRsp.pCont, rpcRsp.contLen, &authRsp); + memcpy(secret, authRsp.secret, TSDB_PASSWORD_LEN); + memcpy(ckey, authRsp.ckey, TSDB_PASSWORD_LEN); + *spi = authRsp.spi; + *encrypt = authRsp.encrypt; + dTrace("user:%s, success to get user auth from other mnodes, spi:%d encrypt:%d", user, authRsp.spi, + authRsp.encrypt); + } + + rpcFreeCont(rpcRsp.pCont); + return rpcRsp.code; +} + +static int32_t dmInitServer(SDnode *pDnode) { + SDnodeTrans *pTrans = &pDnode->trans; + + SRpcInit rpcInit = {0}; + rpcInit.localPort = pDnode->data.serverPort; + rpcInit.label = "DND"; + rpcInit.numOfThreads = tsNumOfRpcThreads; + rpcInit.cfp = (RpcCfp)dmProcessMsg; + rpcInit.sessions = tsMaxShellConns; + rpcInit.connType = TAOS_CONN_SERVER; + rpcInit.idleTime = tsShellActivityTimer * 1000; + rpcInit.afp = (RpcAfp)dmRetrieveUserAuthInfo; + rpcInit.parent = pDnode; + + pTrans->serverRpc = rpcOpen(&rpcInit); + if (pTrans->serverRpc == NULL) { + dError("failed to init dnode rpc server"); + return -1; + } + + dDebug("dnode rpc server is initialized"); + return 0; +} + +static void dmCleanupServer(SDnode *pDnode) { + SDnodeTrans *pTrans = &pDnode->trans; + if (pTrans->serverRpc) { + rpcClose(pTrans->serverRpc); + pTrans->serverRpc = NULL; + dDebug("dnode rpc server is closed"); + } +} + +int32_t dmInitTrans(SDnode *pDnode) { + if (dmInitServer(pDnode) != 0) return -1; + if (dmInitClient(pDnode) != 0) return -1; + return 0; +} + +void dmCleanupTrans(SDnode *pDnode) { + dmCleanupServer(pDnode); + dmCleanupClient(pDnode); +} + +SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper) { + SMsgCb msgCb = { + .sendReqFp = dmSendReq, + .sendRspFp = dmSendRsp, + .registerBrokenLinkArgFp = dmRegisterBrokenLinkArg, + .releaseHandleFp = dmReleaseHandle, + .pWrapper = pWrapper, + }; + return msgCb; } \ No newline at end of file diff --git a/source/dnode/mgmt/implement/src/dmWorker.c b/source/dnode/mgmt/implement/src/dmWorker.c new file mode 100644 index 0000000000000000000000000000000000000000..6ffb8e1a23f531b0f1a3f523450600cafc14ccac --- /dev/null +++ b/source/dnode/mgmt/implement/src/dmWorker.c @@ -0,0 +1,181 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "dmImp.h" + +static void *dmStatusThreadFp(void *param) { + SDnode *pDnode = param; + int64_t lastTime = taosGetTimestampMs(); + + setThreadName("dnode-status"); + + while (1) { + taosThreadTestCancel(); + taosMsleep(200); + + if (pDnode->status != DND_STAT_RUNNING || pDnode->data.dropped) { + continue; + } + + int64_t curTime = taosGetTimestampMs(); + float interval = (curTime - lastTime) / 1000.0f; + if (interval >= tsStatusInterval) { + dmSendStatusReq(pDnode); + lastTime = curTime; + } + } + + return NULL; +} + +static void *dmMonitorThreadFp(void *param) { + SDnode *pDnode = param; + int64_t lastTime = taosGetTimestampMs(); + + setThreadName("dnode-monitor"); + + while (1) { + taosThreadTestCancel(); + taosMsleep(200); + + if (pDnode->status != DND_STAT_RUNNING || pDnode->data.dropped) { + continue; + } + + int64_t curTime = taosGetTimestampMs(); + float interval = (curTime - lastTime) / 1000.0f; + if (interval >= tsMonitorInterval) { + dmSendMonitorReport(pDnode); + lastTime = curTime; + } + } + + return NULL; +} + +int32_t dmStartStatusThread(SDnode *pDnode) { + pDnode->data.statusThreadId = taosCreateThread(dmStatusThreadFp, pDnode); + if (pDnode->data.statusThreadId == NULL) { + dError("failed to init dnode status thread"); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + return 0; +} + +void dmStopStatusThread(SDnode *pDnode) { + if (pDnode->data.statusThreadId != NULL) { + taosDestoryThread(pDnode->data.statusThreadId); + pDnode->data.statusThreadId = NULL; + } +} + +int32_t dmStartMonitorThread(SDnode *pDnode) { + pDnode->data.monitorThreadId = taosCreateThread(dmMonitorThreadFp, pDnode); + if (pDnode->data.monitorThreadId == NULL) { + dError("failed to init dnode monitor thread"); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + return 0; +} + +void dmStopMonitorThread(SDnode *pDnode) { + if (pDnode->data.monitorThreadId != NULL) { + taosDestoryThread(pDnode->data.monitorThreadId); + pDnode->data.monitorThreadId = NULL; + } +} + +static void dmProcessMgmtQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { + SDnode *pDnode = pInfo->ahandle; + SRpcMsg *pRpc = &pMsg->rpcMsg; + int32_t code = -1; + dTrace("msg:%p, will be processed in dnode-mgmt queue", pMsg); + + switch (pRpc->msgType) { + case TDMT_DND_CONFIG_DNODE: + code = dmProcessConfigReq(pDnode, pMsg); + break; + case TDMT_MND_AUTH_RSP: + code = dmProcessAuthRsp(pDnode, pMsg); + break; + case TDMT_MND_GRANT_RSP: + code = dmProcessGrantRsp(pDnode, pMsg); + break; + case TDMT_DND_CREATE_MNODE: + code = dmProcessCreateNodeReq(pDnode, MNODE, pMsg); + break; + case TDMT_DND_DROP_MNODE: + code = dmProcessDropNodeReq(pDnode, MNODE, pMsg); + break; + case TDMT_DND_CREATE_QNODE: + code = dmProcessCreateNodeReq(pDnode, QNODE, pMsg); + break; + case TDMT_DND_DROP_QNODE: + code = dmProcessDropNodeReq(pDnode, QNODE, pMsg); + break; + case TDMT_DND_CREATE_SNODE: + code = dmProcessCreateNodeReq(pDnode, SNODE, pMsg); + break; + case TDMT_DND_DROP_SNODE: + code = dmProcessDropNodeReq(pDnode, SNODE, pMsg); + break; + case TDMT_DND_CREATE_BNODE: + code = dmProcessCreateNodeReq(pDnode, BNODE, pMsg); + break; + case TDMT_DND_DROP_BNODE: + code = dmProcessDropNodeReq(pDnode, BNODE, pMsg); + break; + default: + break; + } + + if (pRpc->msgType & 1u) { + if (code != 0) code = terrno; + SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = code}; + rpcSendResponse(&rsp); + } + + dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); + rpcFreeCont(pMsg->rpcMsg.pCont); + taosFreeQitem(pMsg); +} + +int32_t dmStartWorker(SDnode *pDnode) { + SSingleWorkerCfg cfg = {.min = 1, .max = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessMgmtQueue, .param = pDnode}; + if (tSingleWorkerInit(&pDnode->data.mgmtWorker, &cfg) != 0) { + dError("failed to start dnode-mgmt worker since %s", terrstr()); + return -1; + } + + dDebug("dnode workers are initialized"); + return 0; +} + +void dmStopWorker(SDnode *pDnode) { + tSingleWorkerCleanup(&pDnode->data.mgmtWorker); + dDebug("dnode workers are closed"); +} + +int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SSingleWorker *pWorker = &pWrapper->pDnode->data.mgmtWorker; + dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); + taosWriteQitem(pWorker->queue, pMsg); + return 0; +} diff --git a/source/dnode/mgmt/inc/dmInt.h b/source/dnode/mgmt/inc/dmInt.h deleted file mode 100644 index a671368f06beff478086755db1b4ea8888fa3e2d..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/inc/dmInt.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_DND_DNODE_INT_H_ -#define _TD_DND_DNODE_INT_H_ - -#include "dndInt.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct SDnodeMgmt { - int64_t dver; - int64_t updateTime; - int8_t statusSent; - SEpSet mnodeEpSet; - SHashObj *dnodeHash; - SArray *dnodeEps; - TdThread *threadId; - SRWLatch latch; - SSingleWorker mgmtWorker; - SSingleWorker monitorWorker; - SMsgCb msgCb; - const char *path; - SDnode *pDnode; - SMgmtWrapper *pWrapper; -} SDnodeMgmt; - -// dmFile.c -int32_t dmReadFile(SDnodeMgmt *pMgmt); -int32_t dmWriteFile(SDnodeMgmt *pMgmt); -void dmUpdateDnodeEps(SDnodeMgmt *pMgmt, SArray *pDnodeEps); - -// dmHandle.c -void dmInitMsgHandle(SMgmtWrapper *pWrapper); -void dmSendStatusReq(SDnodeMgmt *pMgmt); -int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t dmProcessStatusRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t dmProcessAuthRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg); -int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg); - -// dmMonitor.c -void dmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); -void dmSendMonitorReport(SDnode *pDnode); - -// dmWorker.c -int32_t dmStartThread(SDnodeMgmt *pMgmt); -int32_t dmStartWorker(SDnodeMgmt *pMgmt); -void dmStopWorker(SDnodeMgmt *pMgmt); -int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); -int32_t dmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_DND_DNODE_INT_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/inc/dndInt.h b/source/dnode/mgmt/inc/dndInt.h deleted file mode 100644 index 7faf1e4276ea879da4b20003d088fccb5f5c688c..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/inc/dndInt.h +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_DND_INT_H_ -#define _TD_DND_INT_H_ - -#include "os.h" - -#include "cJSON.h" -#include "tcache.h" -#include "tcrc32c.h" -#include "tdatablock.h" -#include "tglobal.h" -#include "thash.h" -#include "tlockfree.h" -#include "tlog.h" -#include "tmsg.h" -#include "tmsgcb.h" -#include "tprocess.h" -#include "tqueue.h" -#include "trpc.h" -#include "tthread.h" -#include "ttime.h" -#include "tworker.h" - -#include "dnode.h" -#include "monitor.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} -#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} -#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} -#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", DEBUG_INFO, 255, __VA_ARGS__); }} -#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }} -#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }} - -typedef enum { DNODE, VNODES, QNODE, SNODE, MNODE, BNODE, NODE_MAX } EDndType; -typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EDndStatus; -typedef enum { DND_ENV_INIT, DND_ENV_READY, DND_ENV_CLEANUP } EEnvStatus; -typedef enum { PROC_SINGLE, PROC_CHILD, PROC_PARENT } EProcType; - -typedef struct SMgmtFp SMgmtFp; -typedef struct SMgmtWrapper SMgmtWrapper; -typedef struct SMsgHandle SMsgHandle; -typedef struct SDnodeMgmt SDnodeMgmt; -typedef struct SVnodesMgmt SVnodesMgmt; -typedef struct SMnodeMgmt SMnodeMgmt; -typedef struct SQnodeMgmt SQnodeMgmt; -typedef struct SSnodeMgmt SSnodeMgmt; -typedef struct SBnodeMgmt SBnodeMgmt; - -typedef int32_t (*NodeMsgFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); -typedef int32_t (*OpenNodeFp)(SMgmtWrapper *pWrapper); -typedef void (*CloseNodeFp)(SMgmtWrapper *pWrapper); -typedef int32_t (*StartNodeFp)(SMgmtWrapper *pWrapper); -typedef int32_t (*CreateNodeFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); -typedef int32_t (*DropNodeFp)(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); -typedef int32_t (*RequireNodeFp)(SMgmtWrapper *pWrapper, bool *required); - -typedef struct SMsgHandle { - SMgmtWrapper *pQndWrapper; - SMgmtWrapper *pMndWrapper; - SMgmtWrapper *pWrapper; -} SMsgHandle; - -typedef struct SMgmtFp { - OpenNodeFp openFp; - CloseNodeFp closeFp; - StartNodeFp startFp; - CreateNodeFp createMsgFp; - DropNodeFp dropMsgFp; - RequireNodeFp requiredFp; -} SMgmtFp; - -typedef struct SMgmtWrapper { - const char *name; - char *path; - int32_t refCount; - SRWLatch latch; - EDndType ntype; - bool deployed; - bool required; - EProcType procType; - int32_t procId; - SProcObj *pProc; - SShm shm; - void *pMgmt; - SDnode *pDnode; - SMgmtFp fp; - int8_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode - NodeMsgFp msgFps[TDMT_MAX]; -} SMgmtWrapper; - -typedef struct { - void *serverRpc; - void *clientRpc; - SMsgHandle msgHandles[TDMT_MAX]; -} STransMgmt; - -typedef struct SDnode { - int64_t clusterId; - int32_t dnodeId; - int32_t numOfSupportVnodes; - int64_t rebootTime; - char *localEp; - char *localFqdn; - char *firstEp; - char *secondEp; - char *dataDir; - SDiskCfg *disks; - int32_t numOfDisks; - uint16_t serverPort; - bool dropped; - EDndType ntype; - EDndStatus status; - EDndEvent event; - SStartupReq startup; - TdFilePtr lockfile; - STransMgmt trans; - SMgmtWrapper wrappers[NODE_MAX]; -} SDnode; - -// dndEnv.c -const char *dndStatStr(EDndStatus stat); -const char *dndNodeLogStr(EDndType ntype); -const char *dndNodeProcStr(EDndType ntype); -const char *dndEventStr(EDndEvent ev); - -// dndExec.c -int32_t dndOpenNode(SMgmtWrapper *pWrapper); -void dndCloseNode(SMgmtWrapper *pWrapper); - -// dndFile.c -int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed); -int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed); -TdFilePtr dndCheckRunning(const char *dataDir); -int32_t dndReadShmFile(SDnode *pDnode); -int32_t dndWriteShmFile(SDnode *pDnode); - -// dndInt.c -EDndStatus dndGetStatus(SDnode *pDnode); -void dndSetStatus(SDnode *pDnode, EDndStatus stat); -void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId); -SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndType nType); -int32_t dndMarkWrapper(SMgmtWrapper *pWrapper); -void dndReleaseWrapper(SMgmtWrapper *pWrapper); -void dndHandleEvent(SDnode *pDnode, EDndEvent event); -void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); -void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); - -// dndTransport.c -int32_t dndInitTrans(SDnode *pDnode); -void dndCleanupTrans(SDnode *pDnode); -SMsgCb dndCreateMsgcb(SMgmtWrapper *pWrapper); -SProcCfg dndGenProcCfg(SMgmtWrapper *pWrapper); -int32_t dndInitMsgHandle(SDnode *pDnode); -void dndSendRecv(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pReq, SRpcMsg *pRsp); - -// mgmt -void dmSetMgmtFp(SMgmtWrapper *pWrapper); -void bmSetMgmtFp(SMgmtWrapper *pWrapper); -void qmSetMgmtFp(SMgmtWrapper *pMgmt); -void smSetMgmtFp(SMgmtWrapper *pWrapper); -void vmSetMgmtFp(SMgmtWrapper *pWrapper); -void mmSetMgmtFp(SMgmtWrapper *pMgmt); - -void dmGetMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet); -void dmUpdateMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet); -void dmSendRedirectRsp(SDnodeMgmt *pMgmt, const SRpcMsg *pMsg); - -void dmGetMonitorSysInfo(SMonSysInfo *pInfo); -void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); -void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo); -void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *vmInfo); -void qmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonQmInfo *qmInfo); -void smGetMonitorInfo(SMgmtWrapper *pWrapper, SMonSmInfo *smInfo); -void bmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonBmInfo *bmInfo); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_DND_INT_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/interface/CMakeLists.txt b/source/dnode/mgmt/interface/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..69cb6e040fd917b4756902a1a5c366bdf20d4e5d --- /dev/null +++ b/source/dnode/mgmt/interface/CMakeLists.txt @@ -0,0 +1,10 @@ +aux_source_directory(src DNODE_INTERFACE) +add_library(dnode_interface STATIC ${DNODE_INTERFACE}) +target_include_directories( + dnode_interface + PUBLIC "${TD_SOURCE_DIR}/include/dnode/mgmt" + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + dnode_interface cjson mnode vnode qnode snode bnode wal sync taos tfs monitor +) \ No newline at end of file diff --git a/source/dnode/mgmt/interface/inc/dmDef.h b/source/dnode/mgmt/interface/inc/dmDef.h new file mode 100644 index 0000000000000000000000000000000000000000..a38349f852cc5df3485581c1534295c29dedfec7 --- /dev/null +++ b/source/dnode/mgmt/interface/inc/dmDef.h @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_DM_DEF_H_ +#define _TD_DM_DEF_H_ + +#include "dmLog.h" + +#include "cJSON.h" +#include "tcache.h" +#include "tcrc32c.h" +#include "tdatablock.h" +#include "tglobal.h" +#include "thash.h" +#include "tlockfree.h" +#include "tlog.h" +#include "tmsg.h" +#include "tmsgcb.h" +#include "tprocess.h" +#include "tqueue.h" +#include "trpc.h" +#include "tthread.h" +#include "ttime.h" +#include "tworker.h" + +#include "dnode.h" +#include "mnode.h" +#include "monitor.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { DNODE, VNODE, QNODE, SNODE, MNODE, BNODE, NODE_END } EDndNodeType; +typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EDndRunStatus; +typedef enum { DND_ENV_INIT, DND_ENV_READY, DND_ENV_CLEANUP } EDndEnvStatus; +typedef enum { DND_PROC_SINGLE, DND_PROC_CHILD, DND_PROC_PARENT } EDndProcType; + +typedef int32_t (*NodeMsgFp)(struct SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +typedef int32_t (*OpenNodeFp)(struct SMgmtWrapper *pWrapper); +typedef void (*CloseNodeFp)(struct SMgmtWrapper *pWrapper); +typedef int32_t (*StartNodeFp)(struct SMgmtWrapper *pWrapper); +typedef void (*StopNodeFp)(struct SMgmtWrapper *pWrapper); +typedef int32_t (*CreateNodeFp)(struct SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +typedef int32_t (*DropNodeFp)(struct SMgmtWrapper *pWrapper, SNodeMsg *pMsg); +typedef int32_t (*RequireNodeFp)(struct SMgmtWrapper *pWrapper, bool *required); + +typedef struct { + SMgmtWrapper *pQndWrapper; + SMgmtWrapper *pMndWrapper; + SMgmtWrapper *pNdWrapper; +} SMsgHandle; + +typedef struct { + OpenNodeFp openFp; + CloseNodeFp closeFp; + StartNodeFp startFp; + StopNodeFp stopFp; + CreateNodeFp createFp; + DropNodeFp dropFp; + RequireNodeFp requiredFp; +} SMgmtFp; + +typedef struct SMgmtWrapper { + SDnode *pDnode; + struct { + const char *name; + char *path; + int32_t refCount; + SRWLatch latch; + EDndNodeType ntype; + bool deployed; + bool required; + SMgmtFp fp; + void *pMgmt; + }; + struct { + EDndProcType procType; + int32_t procId; + SProcObj *procObj; + SShm procShm; + }; + struct { + int8_t msgVgIds[TDMT_MAX]; // Handle the case where the same message type is distributed to qnode or vnode + NodeMsgFp msgFps[TDMT_MAX]; + }; +} SMgmtWrapper; + +typedef struct { + void *serverRpc; + void *clientRpc; + SMsgHandle msgHandles[TDMT_MAX]; +} SDnodeTrans; + +typedef struct { + int32_t dnodeId; + int64_t clusterId; + int64_t dnodeVer; + int64_t updateTime; + int64_t rebootTime; + bool dropped; + SEpSet mnodeEps; + SArray *dnodeEps; + SHashObj *dnodeHash; + TdThread *statusThreadId; + TdThread *monitorThreadId; + SRWLatch latch; + SSingleWorker mgmtWorker; + SMsgCb msgCb; + SDnode *pDnode; + TdFilePtr lockfile; + char *localEp; + char *localFqdn; + char *firstEp; + char *secondEp; + char *dataDir; + SDiskCfg *disks; + int32_t numOfDisks; + int32_t supportVnodes; + uint16_t serverPort; +} SDnodeData; + +typedef struct SDnode { + EDndProcType ptype; + EDndNodeType ntype; + EDndRunStatus status; + EDndEvent event; + SStartupReq startup; + SDnodeTrans trans; + SDnodeData data; + TdThreadMutex mutex; + SMgmtWrapper wrappers[NODE_END]; +} SDnode; + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_DM_DEF_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/interface/inc/dmInt.h b/source/dnode/mgmt/interface/inc/dmInt.h new file mode 100644 index 0000000000000000000000000000000000000000..3c8ecdc71bf052e76a29943087dbfd678496f4cc --- /dev/null +++ b/source/dnode/mgmt/interface/inc/dmInt.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_DM_INT_H_ +#define _TD_DM_INT_H_ + +#include "dmDef.h" + +#ifdef __cplusplus +extern "C" { +#endif + +// dmInt.c +SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType nType); +int32_t dmMarkWrapper(SMgmtWrapper *pWrapper); +void dmReleaseWrapper(SMgmtWrapper *pWrapper); +const char *dmStatName(EDndRunStatus stat); +const char *dmLogName(EDndNodeType ntype); +const char *dmProcName(EDndNodeType ntype); +const char *dmEventName(EDndEvent ev); + +void dmSetStatus(SDnode *pDnode, EDndRunStatus stat); +void dmSetEvent(SDnode *pDnode, EDndEvent event); +void dmSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId); +void dmReportStartup(SDnode *pDnode, const char *pName, const char *pDesc); +void dmProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); +void dmGetMonitorSysInfo(SMonSysInfo *pInfo); + +// dmFile.c +int32_t dmReadFile(SMgmtWrapper *pWrapper, bool *pDeployed); +int32_t dmWriteFile(SMgmtWrapper *pWrapper, bool deployed); +TdFilePtr dmCheckRunning(const char *dataDir); +int32_t dmReadShmFile(SMgmtWrapper *pWrapper); +int32_t dmWriteShmFile(SMgmtWrapper *pWrapper); + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_DM_INT_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/interface/inc/dmLog.h b/source/dnode/mgmt/interface/inc/dmLog.h new file mode 100644 index 0000000000000000000000000000000000000000..c21933fc01fd19624f1b763e4191ce4456411494 --- /dev/null +++ b/source/dnode/mgmt/interface/inc/dmLog.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_DM_LOG_H_ +#define _TD_DM_LOG_H_ + +#include "tlog.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} +#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} +#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} +#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", DEBUG_INFO, 255, __VA_ARGS__); }} +#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }} +#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }} + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_DM_LOG_H_*/ \ No newline at end of file diff --git a/source/dnode/mgmt/main/dndEnv.c b/source/dnode/mgmt/interface/src/dmEnv.c similarity index 58% rename from source/dnode/mgmt/main/dndEnv.c rename to source/dnode/mgmt/interface/src/dmEnv.c index 3c3f2144ab26c6c395aa38219bbfe700700ebced..b6f309ec6ff29582bf8189a01f2c64316541be2e 100644 --- a/source/dnode/mgmt/main/dndEnv.c +++ b/source/dnode/mgmt/interface/src/dmEnv.c @@ -14,12 +14,12 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dmInt.h" #include "wal.h" static int8_t once = DND_ENV_INIT; -int32_t dndInit() { +int32_t dmInit() { dDebug("start to init dnode env"); if (atomic_val_compare_exchange_8(&once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) { terrno = TSDB_CODE_REPEAT_INIT; @@ -45,7 +45,7 @@ int32_t dndInit() { return 0; } -void dndCleanup() { +void dmCleanup() { dDebug("start to cleanup dnode env"); if (atomic_val_compare_exchange_8(&once, DND_ENV_READY, DND_ENV_CLEANUP) != DND_ENV_READY) { dError("dnode env is already cleaned up"); @@ -57,63 +57,3 @@ void dndCleanup() { taosStopCacheRefreshWorker(); dInfo("dnode env is cleaned up"); } - -const char *dndStatStr(EDndStatus status) { - switch (status) { - case DND_STAT_INIT: - return "init"; - case DND_STAT_RUNNING: - return "running"; - case DND_STAT_STOPPED: - return "stopped"; - default: - return "UNKNOWN"; - } -} - -const char *dndNodeLogStr(EDndType ntype) { - switch (ntype) { - case VNODES: - return "vnode"; - case QNODE: - return "qnode"; - case SNODE: - return "snode"; - case MNODE: - return "mnode"; - case BNODE: - return "bnode"; - default: - return "taosd"; - } -} - -const char *dndNodeProcStr(EDndType ntype) { - switch (ntype) { - case VNODES: - return "taosv"; - case QNODE: - return "taosq"; - case SNODE: - return "taoss"; - case MNODE: - return "taosm"; - case BNODE: - return "taosb"; - default: - return "taosd"; - } -} - -const char *dndEventStr(EDndEvent ev) { - switch (ev) { - case DND_EVENT_START: - return "start"; - case DND_EVENT_STOP: - return "stop"; - case DND_EVENT_CHILD: - return "child"; - default: - return "UNKNOWN"; - } -} \ No newline at end of file diff --git a/source/dnode/mgmt/main/dndFile.c b/source/dnode/mgmt/interface/src/dmFile.c similarity index 64% rename from source/dnode/mgmt/main/dndFile.c rename to source/dnode/mgmt/interface/src/dmFile.c index d4d2a3e6ea42e466e4986de98aafdd42c82c23ef..e9117939d72ca5c094d7fe6066cb1843d4efaeed 100644 --- a/source/dnode/mgmt/main/dndFile.c +++ b/source/dnode/mgmt/interface/src/dmFile.c @@ -14,22 +14,22 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dmInt.h" #define MAXLEN 1024 -int32_t dndReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) { +int32_t dmReadFile(SMgmtWrapper *pWrapper, bool *pDeployed) { int32_t code = TSDB_CODE_INVALID_JSON_FORMAT; int64_t len = 0; char content[MAXLEN + 1] = {0}; cJSON *root = NULL; - char file[PATH_MAX]; + char file[PATH_MAX] = {0}; TdFilePtr pFile = NULL; snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - dDebug("file %s not exist", file); + // dDebug("file %s not exist", file); code = 0; goto _OVER; } @@ -64,7 +64,7 @@ _OVER: return code; } -int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) { +int32_t dmWriteFile(SMgmtWrapper *pWrapper, bool deployed) { int32_t code = -1; int32_t len = 0; char content[MAXLEN + 1] = {0}; @@ -75,7 +75,7 @@ int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) { snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); snprintf(realfile, sizeof(realfile), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name); - pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to write %s since %s", file, terrstr()); @@ -117,11 +117,11 @@ _OVER: return code; } -TdFilePtr dndCheckRunning(const char *dataDir) { +TdFilePtr dmCheckRunning(const char *dataDir) { char filepath[PATH_MAX] = {0}; snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP); - TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to lock file:%s since %s", filepath, terrstr()); @@ -140,18 +140,17 @@ TdFilePtr dndCheckRunning(const char *dataDir) { return pFile; } -int32_t dndReadShmFile(SDnode *pDnode) { +int32_t dmReadShmFile(SMgmtWrapper *pWrapper) { int32_t code = -1; - char itemName[24] = {0}; char content[MAXLEN + 1] = {0}; char file[PATH_MAX] = {0}; cJSON *root = NULL; TdFilePtr pFile = NULL; - snprintf(file, sizeof(file), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP); + snprintf(file, sizeof(file), "%s%sshmfile", pWrapper->path, TD_DIRSEP); pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - dDebug("file %s not exist", file); + // dDebug("node:%s, file %s not exist", pWrapper->name, file); code = 0; goto _OVER; } @@ -160,44 +159,36 @@ int32_t dndReadShmFile(SDnode *pDnode) { root = cJSON_Parse(content); if (root == NULL) { terrno = TSDB_CODE_INVALID_JSON_FORMAT; - dError("failed to read %s since invalid json format", file); + dError("node:%s, failed to read %s since invalid json format", pWrapper->name, file); goto _OVER; } - for (EDndType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) { - snprintf(itemName, sizeof(itemName), "%s_shmid", dndNodeProcStr(ntype)); - cJSON *shmid = cJSON_GetObjectItem(root, itemName); - if (shmid && shmid->type == cJSON_Number) { - pDnode->wrappers[ntype].shm.id = shmid->valueint; - } - - snprintf(itemName, sizeof(itemName), "%s_shmsize", dndNodeProcStr(ntype)); - cJSON *shmsize = cJSON_GetObjectItem(root, itemName); - if (shmsize && shmsize->type == cJSON_Number) { - pDnode->wrappers[ntype].shm.size = shmsize->valueint; - } + cJSON *shmid = cJSON_GetObjectItem(root, "shmid"); + if (shmid && shmid->type == cJSON_Number) { + pWrapper->procShm.id = shmid->valueint; + } + + cJSON *shmsize = cJSON_GetObjectItem(root, "shmsize"); + if (shmsize && shmsize->type == cJSON_Number) { + pWrapper->procShm.size = shmsize->valueint; } } - if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) { - for (EDndType ntype = DNODE; ntype < NODE_MAX; ++ntype) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; - if (pWrapper->shm.id >= 0) { - dDebug("shmid:%d, is closed, size:%d", pWrapper->shm.id, pWrapper->shm.size); - taosDropShm(&pWrapper->shm); - } + if (!tsMultiProcess || pWrapper->pDnode->ntype == DNODE || pWrapper->pDnode->ntype == NODE_END) { + if (pWrapper->procShm.id >= 0) { + dDebug("node:%s, shmid:%d, is closed, size:%d", pWrapper->name, pWrapper->procShm.id, pWrapper->procShm.size); + taosDropShm(&pWrapper->procShm); } } else { - SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; - if (taosAttachShm(&pWrapper->shm) != 0) { + if (taosAttachShm(&pWrapper->procShm) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("shmid:%d, failed to attach shm since %s", pWrapper->shm.id, terrstr()); + dError("shmid:%d, failed to attach shm since %s", pWrapper->procShm.id, terrstr()); goto _OVER; } - dInfo("node:%s, shmid:%d is attached, size:%d", pWrapper->name, pWrapper->shm.id, pWrapper->shm.size); + dInfo("node:%s, shmid:%d is attached, size:%d", pWrapper->name, pWrapper->procShm.id, pWrapper->procShm.size); } - dDebug("successed to load %s", file); + dDebug("node:%s, successed to load %s", pWrapper->name, file); code = 0; _OVER: @@ -207,7 +198,7 @@ _OVER: return code; } -int32_t dndWriteShmFile(SDnode *pDnode) { +int32_t dmWriteShmFile(SMgmtWrapper *pWrapper) { int32_t code = -1; int32_t len = 0; char content[MAXLEN + 1] = {0}; @@ -215,37 +206,30 @@ int32_t dndWriteShmFile(SDnode *pDnode) { char realfile[PATH_MAX] = {0}; TdFilePtr pFile = NULL; - snprintf(file, sizeof(file), "%s%s.shmfile.bak", pDnode->dataDir, TD_DIRSEP); - snprintf(realfile, sizeof(realfile), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP); + snprintf(file, sizeof(file), "%s%sshmfile.bak", pWrapper->path, TD_DIRSEP); + snprintf(realfile, sizeof(realfile), "%s%sshmfile", pWrapper->path, TD_DIRSEP); - pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to open file:%s since %s", file, terrstr()); + dError("node:%s, failed to open file:%s since %s", pWrapper->name, file, terrstr()); goto _OVER; } len += snprintf(content + len, MAXLEN - len, "{\n"); - for (EDndType ntype = DNODE + 1; ntype < NODE_MAX; ++ntype) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; - len += snprintf(content + len, MAXLEN - len, " \"%s_shmid\":%d,\n", dndNodeProcStr(ntype), pWrapper->shm.id); - if (ntype == NODE_MAX - 1) { - len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d\n", dndNodeProcStr(ntype), pWrapper->shm.size); - } else { - len += snprintf(content + len, MAXLEN - len, " \"%s_shmsize\":%d,\n", dndNodeProcStr(ntype), pWrapper->shm.size); - } - } + len += snprintf(content + len, MAXLEN - len, " \"shmid\":%d,\n", pWrapper->procShm.id); + len += snprintf(content + len, MAXLEN - len, " \"shmsize\":%d\n", pWrapper->procShm.size); len += snprintf(content + len, MAXLEN - len, "}\n"); if (taosWriteFile(pFile, content, len) != len) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to write file:%s since %s", file, terrstr()); + dError("node:%s, failed to write file:%s since %s", pWrapper->name, file, terrstr()); goto _OVER; } if (taosFsyncFile(pFile) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to fsync file:%s since %s", file, terrstr()); + dError("node:%s, failed to fsync file:%s since %s", pWrapper->name, file, terrstr()); goto _OVER; } @@ -253,11 +237,11 @@ int32_t dndWriteShmFile(SDnode *pDnode) { if (taosRenameFile(file, realfile) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to rename %s to %s since %s", file, realfile, terrstr()); + dError("node:%s, failed to rename %s to %s since %s", pWrapper->name, file, realfile, terrstr()); return -1; } - dInfo("successed to write %s", realfile); + dInfo("node:%s, successed to write %s", pWrapper->name, realfile); code = 0; _OVER: diff --git a/source/dnode/mgmt/interface/src/dmInt.c b/source/dnode/mgmt/interface/src/dmInt.c new file mode 100644 index 0000000000000000000000000000000000000000..10599c004385a8faa3a1e592fbdaa4e6ea4778b3 --- /dev/null +++ b/source/dnode/mgmt/interface/src/dmInt.c @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "dmInt.h" + +const char *dmStatName(EDndRunStatus status) { + switch (status) { + case DND_STAT_INIT: + return "init"; + case DND_STAT_RUNNING: + return "running"; + case DND_STAT_STOPPED: + return "stopped"; + default: + return "UNKNOWN"; + } +} + +const char *dmLogName(EDndNodeType ntype) { + switch (ntype) { + case VNODE: + return "vnode"; + case QNODE: + return "qnode"; + case SNODE: + return "snode"; + case MNODE: + return "mnode"; + case BNODE: + return "bnode"; + default: + return "taosd"; + } +} + +const char *dmProcName(EDndNodeType ntype) { + switch (ntype) { + case VNODE: + return "taosv"; + case QNODE: + return "taosq"; + case SNODE: + return "taoss"; + case MNODE: + return "taosm"; + case BNODE: + return "taosb"; + default: + return "taosd"; + } +} + +const char *dmEventName(EDndEvent ev) { + switch (ev) { + case DND_EVENT_START: + return "start"; + case DND_EVENT_STOP: + return "stop"; + case DND_EVENT_CHILD: + return "child"; + default: + return "UNKNOWN"; + } +} + +void dmSetStatus(SDnode *pDnode, EDndRunStatus status) { + if (pDnode->status != status) { + dDebug("dnode status set from %s to %s", dmStatName(pDnode->status), dmStatName(status)); + pDnode->status = status; + } +} + +void dmSetEvent(SDnode *pDnode, EDndEvent event) { + if (event == DND_EVENT_STOP) { + pDnode->event = event; + } +} + +void dmSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) { + pWrapper->msgFps[TMSG_INDEX(msgType)] = nodeMsgFp; + pWrapper->msgVgIds[TMSG_INDEX(msgType)] = vgId; +} + +SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType ntype) { + SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; + SMgmtWrapper *pRetWrapper = pWrapper; + + taosRLockLatch(&pWrapper->latch); + if (pWrapper->deployed) { + int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); + dTrace("node:%s, is acquired, refCount:%d", pWrapper->name, refCount); + } else { + terrno = TSDB_CODE_NODE_NOT_DEPLOYED; + pRetWrapper = NULL; + } + taosRUnLockLatch(&pWrapper->latch); + + return pRetWrapper; +} + +int32_t dmMarkWrapper(SMgmtWrapper *pWrapper) { + int32_t code = 0; + + taosRLockLatch(&pWrapper->latch); + if (pWrapper->deployed || (pWrapper->procType == DND_PROC_PARENT && pWrapper->required)) { + int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); + dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount); + } else { + terrno = TSDB_CODE_NODE_NOT_DEPLOYED; + code = -1; + } + taosRUnLockLatch(&pWrapper->latch); + + return code; +} + +void dmReleaseWrapper(SMgmtWrapper *pWrapper) { + if (pWrapper == NULL) return; + + taosRLockLatch(&pWrapper->latch); + int32_t refCount = atomic_sub_fetch_32(&pWrapper->refCount, 1); + taosRUnLockLatch(&pWrapper->latch); + dTrace("node:%s, is released, refCount:%d", pWrapper->name, refCount); +} + +void dmReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) { + SStartupReq *pStartup = &pDnode->startup; + tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN); + tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN); + pStartup->finished = 0; +} + +static void dmGetStartup(SDnode *pDnode, SStartupReq *pStartup) { + memcpy(pStartup, &pDnode->startup, sizeof(SStartupReq)); + pStartup->finished = (pDnode->status == DND_STAT_RUNNING); +} + +void dmProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) { + dDebug("startup req is received"); + SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq)); + dmGetStartup(pDnode, pStartup); + + dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished); + SRpcMsg rpcRsp = { + .handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq), .ahandle = pReq->ahandle}; + rpcSendResponse(&rpcRsp); +} + +void dmGetMonitorSysInfo(SMonSysInfo *pInfo) { + taosGetCpuUsage(&pInfo->cpu_engine, &pInfo->cpu_system); + taosGetCpuCores(&pInfo->cpu_cores); + taosGetProcMemory(&pInfo->mem_engine); + taosGetSysMemory(&pInfo->mem_system); + pInfo->mem_total = tsTotalMemoryKB; + pInfo->disk_engine = 0; + pInfo->disk_used = tsDataSpace.size.used; + pInfo->disk_total = tsDataSpace.size.total; + taosGetCardInfoDelta(&pInfo->net_in, &pInfo->net_out); + taosGetProcIODelta(&pInfo->io_read, &pInfo->io_write, &pInfo->io_read_disk, &pInfo->io_write_disk); +} diff --git a/source/dnode/mgmt/main/dndExec.c b/source/dnode/mgmt/main/dndExec.c deleted file mode 100644 index 6c0d0456c9225547a0d4dfcd59d1a6ddc6fa67ff..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/main/dndExec.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "dndInt.h" - -static bool dndRequireNode(SMgmtWrapper *pWrapper) { - bool required = false; - int32_t code = (*pWrapper->fp.requiredFp)(pWrapper, &required); - if (!required) { - dDebug("node:%s, does not require startup", pWrapper->name); - } else { - dDebug("node:%s, needs to be started", pWrapper->name); - } - return required; -} - -int32_t dndOpenNode(SMgmtWrapper *pWrapper) { - if (taosMkDir(pWrapper->path) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr()); - return -1; - } - - if ((*pWrapper->fp.openFp)(pWrapper) != 0) { - dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); - return -1; - } - - dDebug("node:%s, has been opened", pWrapper->name); - pWrapper->deployed = true; - return 0; -} - -void dndCloseNode(SMgmtWrapper *pWrapper) { - dDebug("node:%s, mgmt start to close", pWrapper->name); - pWrapper->required = false; - taosWLockLatch(&pWrapper->latch); - if (pWrapper->deployed) { - (*pWrapper->fp.closeFp)(pWrapper); - pWrapper->deployed = false; - } - taosWUnLockLatch(&pWrapper->latch); - - while (pWrapper->refCount > 0) { - taosMsleep(10); - } - - if (pWrapper->pProc) { - taosProcCleanup(pWrapper->pProc); - pWrapper->pProc = NULL; - } - dDebug("node:%s, mgmt has been closed", pWrapper->name); -} - - -static int32_t dndNewProc(SMgmtWrapper *pWrapper, EDndType n) { - char tstr[8] = {0}; - char *args[6] = {0}; - snprintf(tstr, sizeof(tstr), "%d", n); - args[1] = "-c"; - args[2] = configDir; - args[3] = "-n"; - args[4] = tstr; - args[5] = NULL; - - int32_t pid = taosNewProc(args); - if (pid <= 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("node:%s, failed to exec in new process since %s", pWrapper->name, terrstr()); - return -1; - } - - pWrapper->procId = pid; - dInfo("node:%s, continue running in new process:%d", pWrapper->name, pid); - return 0; -} - -static void dndProcessProcHandle(void *handle) { - dWarn("handle:%p, the child process dies and send an offline rsp", handle); - SRpcMsg rpcMsg = {.handle = handle, .code = TSDB_CODE_NODE_OFFLINE}; - rpcSendResponse(&rpcMsg); -} - -static int32_t dndRunInSingleProcess(SDnode *pDnode) { - dInfo("dnode run in single process"); - - for (EDndType n = DNODE; n < NODE_MAX; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - pWrapper->required = dndRequireNode(pWrapper); - if (!pWrapper->required) continue; - - if (dndOpenNode(pWrapper) != 0) { - dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); - return -1; - } - } - - dndSetStatus(pDnode, DND_STAT_RUNNING); - - for (EDndType n = 0; n < NODE_MAX; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - if (!pWrapper->required) continue; - if (pWrapper->fp.startFp == NULL) continue; - if ((*pWrapper->fp.startFp)(pWrapper) != 0) { - dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); - return -1; - } - } - - dInfo("TDengine initialized successfully"); - dndReportStartup(pDnode, "TDengine", "initialized successfully"); - while (1) { - if (pDnode->event == DND_EVENT_STOP) { - dInfo("dnode is about to stop"); - dndSetStatus(pDnode, DND_STAT_STOPPED); - break; - } - taosMsleep(100); - } - - return 0; -} - -static int32_t dndRunInParentProcess(SDnode *pDnode) { - dInfo("dnode run in parent process"); - SMgmtWrapper *pDWrapper = &pDnode->wrappers[DNODE]; - if (dndOpenNode(pDWrapper) != 0) { - dError("node:%s, failed to start since %s", pDWrapper->name, terrstr()); - return -1; - } - - for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - pWrapper->required = dndRequireNode(pWrapper); - if (!pWrapper->required) continue; - - int32_t shmsize = tsMnodeShmSize; - if (n == VNODES) { - shmsize = tsVnodeShmSize; - } else if (n == QNODE) { - shmsize = tsQnodeShmSize; - } else if (n == SNODE) { - shmsize = tsSnodeShmSize; - } else if (n == MNODE) { - shmsize = tsMnodeShmSize; - } else if (n == BNODE) { - shmsize = tsBnodeShmSize; - } else { - } - - if (taosCreateShm(&pWrapper->shm, n, shmsize) != 0) { - terrno = TAOS_SYSTEM_ERROR(terrno); - dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr()); - return -1; - } - dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->shm.id, shmsize); - - SProcCfg cfg = dndGenProcCfg(pWrapper); - cfg.isChild = false; - pWrapper->procType = PROC_PARENT; - pWrapper->pProc = taosProcInit(&cfg); - if (pWrapper->pProc == NULL) { - dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr()); - return -1; - } - } - - if (dndWriteShmFile(pDnode) != 0) { - dError("failed to write runtime file since %s", terrstr()); - return -1; - } - - for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - if (!pWrapper->required) continue; - - if (pDnode->ntype == NODE_MAX) { - dInfo("node:%s, should be started manually", pWrapper->name); - } else { - if (dndNewProc(pWrapper, n) != 0) { - return -1; - } - } - - if (taosProcRun(pWrapper->pProc) != 0) { - dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); - return -1; - } - } - - dndSetStatus(pDnode, DND_STAT_RUNNING); - - if ((*pDWrapper->fp.startFp)(pDWrapper) != 0) { - dError("node:%s, failed to start since %s", pDWrapper->name, terrstr()); - return -1; - } - - dInfo("TDengine initialized successfully"); - dndReportStartup(pDnode, "TDengine", "initialized successfully"); - - while (1) { - if (pDnode->event == DND_EVENT_STOP) { - dInfo("dnode is about to stop"); - dndSetStatus(pDnode, DND_STAT_STOPPED); - - for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - if (!pWrapper->required) continue; - if (pDnode->ntype == NODE_MAX) continue; - - if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) { - dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId); - taosKillProc(pWrapper->procId); - dInfo("node:%s, wait for child process:%d to stop", pWrapper->name, pWrapper->procId); - taosWaitProc(pWrapper->procId); - dInfo("node:%s, child process:%d is stopped", pWrapper->name, pWrapper->procId); - } - } - break; - } else { - for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - if (!pWrapper->required) continue; - if (pDnode->ntype == NODE_MAX) continue; - - if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) { - dWarn("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId); - taosProcCloseHandles(pWrapper->pProc, dndProcessProcHandle); - dndNewProc(pWrapper, n); - } - } - } - - taosMsleep(100); - } - - return 0; -} - -static int32_t dndRunInChildProcess(SDnode *pDnode) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype]; - dInfo("%s run in child process", pWrapper->name); - - pWrapper->required = dndRequireNode(pWrapper); - if (!pWrapper->required) { - dError("%s does not require startup", pWrapper->name); - return -1; - } - - SMsgCb msgCb = dndCreateMsgcb(pWrapper); - tmsgSetDefaultMsgCb(&msgCb); - pWrapper->procType = PROC_CHILD; - - if (dndOpenNode(pWrapper) != 0) { - dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); - return -1; - } - - SProcCfg cfg = dndGenProcCfg(pWrapper); - cfg.isChild = true; - pWrapper->pProc = taosProcInit(&cfg); - if (pWrapper->pProc == NULL) { - dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr()); - return -1; - } - - if (pWrapper->fp.startFp != NULL) { - if ((*pWrapper->fp.startFp)(pWrapper) != 0) { - dError("node:%s, failed to start since %s", pWrapper->name, terrstr()); - return -1; - } - } - - dndSetStatus(pDnode, DND_STAT_RUNNING); - - if (taosProcRun(pWrapper->pProc) != 0) { - dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); - return -1; - } - - dInfo("TDengine initialized successfully"); - dndReportStartup(pDnode, "TDengine", "initialized successfully"); - while (1) { - if (pDnode->event == DND_EVENT_STOP) { - dInfo("%s is about to stop", pWrapper->name); - dndSetStatus(pDnode, DND_STAT_STOPPED); - break; - } - taosMsleep(100); - } - - return 0; -} - -int32_t dndRun(SDnode *pDnode) { - if (!tsMultiProcess) { - return dndRunInSingleProcess(pDnode); - } else if (pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) { - return dndRunInParentProcess(pDnode); - } else { - return dndRunInChildProcess(pDnode); - } - - return 0; -} diff --git a/source/dnode/mgmt/main/dndInt.c b/source/dnode/mgmt/main/dndInt.c deleted file mode 100644 index 7b207fd49622a7fda45d74788a2e7f2eb4000569..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/main/dndInt.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "dndInt.h" - -static int32_t dndInitVars(SDnode *pDnode, const SDnodeOpt *pOption) { - pDnode->numOfSupportVnodes = pOption->numOfSupportVnodes; - pDnode->serverPort = pOption->serverPort; - pDnode->dataDir = strdup(pOption->dataDir); - pDnode->localEp = strdup(pOption->localEp); - pDnode->localFqdn = strdup(pOption->localFqdn); - pDnode->firstEp = strdup(pOption->firstEp); - pDnode->secondEp = strdup(pOption->secondEp); - pDnode->disks = pOption->disks; - pDnode->numOfDisks = pOption->numOfDisks; - pDnode->ntype = pOption->ntype; - pDnode->rebootTime = taosGetTimestampMs(); - - if (pDnode->dataDir == NULL || pDnode->localEp == NULL || pDnode->localFqdn == NULL || pDnode->firstEp == NULL || - pDnode->secondEp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - if (!tsMultiProcess || pDnode->ntype == DNODE || pDnode->ntype == NODE_MAX) { - pDnode->lockfile = dndCheckRunning(pDnode->dataDir); - if (pDnode->lockfile == NULL) { - return -1; - } - } - - return 0; -} - -static void dndClearVars(SDnode *pDnode) { - for (EDndType n = 0; n < NODE_MAX; ++n) { - SMgmtWrapper *pMgmt = &pDnode->wrappers[n]; - taosMemoryFreeClear(pMgmt->path); - } - if (pDnode->lockfile != NULL) { - taosUnLockFile(pDnode->lockfile); - taosCloseFile(&pDnode->lockfile); - pDnode->lockfile = NULL; - } - taosMemoryFreeClear(pDnode->localEp); - taosMemoryFreeClear(pDnode->localFqdn); - taosMemoryFreeClear(pDnode->firstEp); - taosMemoryFreeClear(pDnode->secondEp); - taosMemoryFreeClear(pDnode->dataDir); - taosMemoryFree(pDnode); - dDebug("dnode memory is cleared, data:%p", pDnode); -} - -SDnode *dndCreate(const SDnodeOpt *pOption) { - dDebug("start to create dnode object"); - int32_t code = -1; - char path[PATH_MAX] = {0}; - SDnode *pDnode = NULL; - - pDnode = taosMemoryCalloc(1, sizeof(SDnode)); - if (pDnode == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - goto _OVER; - } - - if (dndInitVars(pDnode, pOption) != 0) { - dError("failed to init variables since %s", terrstr()); - goto _OVER; - } - - dndSetStatus(pDnode, DND_STAT_INIT); - dmSetMgmtFp(&pDnode->wrappers[DNODE]); - mmSetMgmtFp(&pDnode->wrappers[MNODE]); - vmSetMgmtFp(&pDnode->wrappers[VNODES]); - qmSetMgmtFp(&pDnode->wrappers[QNODE]); - smSetMgmtFp(&pDnode->wrappers[SNODE]); - bmSetMgmtFp(&pDnode->wrappers[BNODE]); - - for (EDndType n = 0; n < NODE_MAX; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - snprintf(path, sizeof(path), "%s%s%s", pDnode->dataDir, TD_DIRSEP, pWrapper->name); - pWrapper->path = strdup(path); - pWrapper->shm.id = -1; - pWrapper->pDnode = pDnode; - pWrapper->ntype = n; - if (pWrapper->path == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - goto _OVER; - } - - pWrapper->procType = PROC_SINGLE; - taosInitRWLatch(&pWrapper->latch); - } - - if (dndInitMsgHandle(pDnode) != 0) { - dError("failed to init msg handles since %s", terrstr()); - goto _OVER; - } - - if (dndReadShmFile(pDnode) != 0) { - dError("failed to read shm file since %s", terrstr()); - goto _OVER; - } - - SMsgCb msgCb = dndCreateMsgcb(&pDnode->wrappers[0]); - tmsgSetDefaultMsgCb(&msgCb); - - dInfo("dnode is created, data:%p", pDnode); - code = 0; - -_OVER: - if (code != 0 && pDnode) { - dndClearVars(pDnode); - pDnode = NULL; - dError("failed to create dnode since %s", terrstr()); - } - - return pDnode; -} - -void dndClose(SDnode *pDnode) { - if (pDnode == NULL) return; - - for (EDndType n = 0; n < NODE_MAX; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - dndCloseNode(pWrapper); - } - - dndClearVars(pDnode); - dInfo("dnode is closed, data:%p", pDnode); -} - -void dndHandleEvent(SDnode *pDnode, EDndEvent event) { - if (event == DND_EVENT_STOP) { - pDnode->event = event; - } -} - -SMgmtWrapper *dndAcquireWrapper(SDnode *pDnode, EDndType ntype) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype]; - SMgmtWrapper *pRetWrapper = pWrapper; - - taosRLockLatch(&pWrapper->latch); - if (pWrapper->deployed) { - int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); - dTrace("node:%s, is acquired, refCount:%d", pWrapper->name, refCount); - } else { - terrno = TSDB_CODE_NODE_REDIRECT; - pRetWrapper = NULL; - } - taosRUnLockLatch(&pWrapper->latch); - - return pRetWrapper; -} - -int32_t dndMarkWrapper(SMgmtWrapper *pWrapper) { - int32_t code = 0; - - taosRLockLatch(&pWrapper->latch); - if (pWrapper->deployed || (pWrapper->procType == PROC_PARENT && pWrapper->required)) { - int32_t refCount = atomic_add_fetch_32(&pWrapper->refCount, 1); - dTrace("node:%s, is marked, refCount:%d", pWrapper->name, refCount); - } else { - terrno = TSDB_CODE_NODE_REDIRECT; - code = -1; - } - taosRUnLockLatch(&pWrapper->latch); - - return code; -} - -void dndReleaseWrapper(SMgmtWrapper *pWrapper) { - if (pWrapper == NULL) return; - - taosRLockLatch(&pWrapper->latch); - int32_t refCount = atomic_sub_fetch_32(&pWrapper->refCount, 1); - taosRUnLockLatch(&pWrapper->latch); - dTrace("node:%s, is released, refCount:%d", pWrapper->name, refCount); -} - -void dndSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgFp, int8_t vgId) { - pWrapper->msgFps[TMSG_INDEX(msgType)] = nodeMsgFp; - pWrapper->msgVgIds[TMSG_INDEX(msgType)] = vgId; -} - -EDndStatus dndGetStatus(SDnode *pDnode) { return pDnode->status; } - -void dndSetStatus(SDnode *pDnode, EDndStatus status) { - if (pDnode->status != status) { - dDebug("dnode status set from %s to %s", dndStatStr(pDnode->status), dndStatStr(status)); - pDnode->status = status; - } -} - -void dndReportStartup(SDnode *pDnode, const char *pName, const char *pDesc) { - SStartupReq *pStartup = &pDnode->startup; - tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN); - tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN); - pStartup->finished = 0; -} - -static void dndGetStartup(SDnode *pDnode, SStartupReq *pStartup) { - memcpy(pStartup, &pDnode->startup, sizeof(SStartupReq)); - pStartup->finished = (dndGetStatus(pDnode) == DND_STAT_RUNNING); -} - -void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) { - dDebug("startup req is received"); - SStartupReq *pStartup = rpcMallocCont(sizeof(SStartupReq)); - dndGetStartup(pDnode, pStartup); - - dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished); - SRpcMsg rpcRsp = { - .handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq), .ahandle = pReq->ahandle}; - rpcSendResponse(&rpcRsp); -} \ No newline at end of file diff --git a/source/dnode/mgmt/mgmt_bnode/CMakeLists.txt b/source/dnode/mgmt/mgmt_bnode/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6a447dccf89b9cca83b2cd3df8309c9a3cec9fe0 --- /dev/null +++ b/source/dnode/mgmt/mgmt_bnode/CMakeLists.txt @@ -0,0 +1,9 @@ +aux_source_directory(src MGMT_BNODE) +add_library(mgmt_bnode STATIC ${MGMT_BNODE}) +target_include_directories( + mgmt_bnode + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + mgmt_bnode dnode_interface +) \ No newline at end of file diff --git a/source/dnode/mgmt/inc/bmInt.h b/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h similarity index 89% rename from source/dnode/mgmt/inc/bmInt.h rename to source/dnode/mgmt/mgmt_bnode/inc/bmInt.h index 84a6a53e99c3c8785f982c0ffbcf83180fa69430..3adcc1206bf7f8f9e5360102e49b90771344178e 100644 --- a/source/dnode/mgmt/inc/bmInt.h +++ b/source/dnode/mgmt/mgmt_bnode/inc/bmInt.h @@ -16,7 +16,7 @@ #ifndef _TD_DND_BNODE_INT_H_ #define _TD_DND_BNODE_INT_H_ -#include "dndInt.h" +#include "dmInt.h" #include "bnode.h" @@ -27,16 +27,12 @@ extern "C" { typedef struct SBnodeMgmt { SBnode *pBnode; SDnode *pDnode; - SMgmtWrapper *pWrapper; + SMgmtWrapper *pWrapper; const char *path; SMultiWorker writeWorker; SSingleWorker monitorWorker; } SBnodeMgmt; -// bmInt.c -int32_t bmOpen(SMgmtWrapper *pWrapper); -int32_t bmDrop(SMgmtWrapper *pWrapper); - // bmHandle.c void bmInitMsgHandle(SMgmtWrapper *pWrapper); int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); diff --git a/source/dnode/mgmt/bm/bmHandle.c b/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c similarity index 79% rename from source/dnode/mgmt/bm/bmHandle.c rename to source/dnode/mgmt/mgmt_bnode/src/bmHandle.c index 645a1d09c2a918f6e2705bba2696ee242b55cf55..49bf9201e182f22df25f5c402d275780f65db35a 100644 --- a/source/dnode/mgmt/bm/bmHandle.c +++ b/source/dnode/mgmt/mgmt_bnode/src/bmHandle.c @@ -53,13 +53,19 @@ int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (createReq.dnodeId != pDnode->dnodeId) { + if (createReq.dnodeId != pDnode->data.dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; - dError("failed to create bnode since %s, input:%d cur:%d", terrstr(), createReq.dnodeId, pDnode->dnodeId); + dError("failed to create bnode since %s, input:%d cur:%d", terrstr(), createReq.dnodeId, pDnode->data.dnodeId); return -1; - } else { - return bmOpen(pWrapper); } + + bool deployed = true; + if (dmWriteFile(pWrapper, deployed) != 0) { + dError("failed to write bnode file since %s", terrstr()); + return -1; + } + + return 0; } int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { @@ -72,15 +78,21 @@ int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (dropReq.dnodeId != pDnode->dnodeId) { + if (dropReq.dnodeId != pDnode->data.dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to drop bnode since %s", terrstr()); return -1; - } else { - return bmDrop(pWrapper); } + + bool deployed = false; + if (dmWriteFile(pWrapper, deployed) != 0) { + dError("failed to write bnode file since %s", terrstr()); + return -1; + } + + return 0; } void bmInitMsgHandle(SMgmtWrapper *pWrapper) { - dndSetMsgHandle(pWrapper, TDMT_MON_BM_INFO, bmProcessMonitorMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MON_BM_INFO, bmProcessMonitorMsg, DEFAULT_HANDLE); } diff --git a/source/dnode/mgmt/bm/bmInt.c b/source/dnode/mgmt/mgmt_bnode/src/bmInt.c similarity index 66% rename from source/dnode/mgmt/bm/bmInt.c rename to source/dnode/mgmt/mgmt_bnode/src/bmInt.c index 990c7873a98d4e5cf608f6546a1c43929d7c30ed..f635df8ec78382ed2b34d8b45f2f3c614fa7b4cb 100644 --- a/source/dnode/mgmt/bm/bmInt.c +++ b/source/dnode/mgmt/mgmt_bnode/src/bmInt.c @@ -16,70 +16,25 @@ #define _DEFAULT_SOURCE #include "bmInt.h" -static int32_t bmRequire(SMgmtWrapper *pWrapper, bool *required) { return dndReadFile(pWrapper, required); } +static int32_t bmRequire(SMgmtWrapper *pWrapper, bool *required) { return dmReadFile(pWrapper, required); } static void bmInitOption(SBnodeMgmt *pMgmt, SBnodeOpt *pOption) { - SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = pMgmt->pDnode->data.msgCb; + msgCb.pWrapper = pMgmt->pWrapper; pOption->msgCb = msgCb; } -static int32_t bmOpenImp(SBnodeMgmt *pMgmt) { - SBnodeOpt option = {0}; - bmInitOption(pMgmt, &option); - - pMgmt->pBnode = bndOpen(pMgmt->path, &option); - if (pMgmt->pBnode == NULL) { - dError("failed to open bnode since %s", terrstr()); - return -1; - } - - if (bmStartWorker(pMgmt) != 0) { - dError("failed to start bnode worker since %s", terrstr()); - return -1; - } - - bool deployed = true; - if (dndWriteFile(pMgmt->pWrapper, deployed) != 0) { - dError("failed to write bnode file since %s", terrstr()); - return -1; - } - - return 0; -} +static void bmClose(SMgmtWrapper *pWrapper) { + SBnodeMgmt *pMgmt = pWrapper->pMgmt; + if (pMgmt == NULL) return; -static void bmCloseImp(SBnodeMgmt *pMgmt) { + dInfo("bnode-mgmt start to cleanup"); if (pMgmt->pBnode != NULL) { bmStopWorker(pMgmt); bndClose(pMgmt->pBnode); pMgmt->pBnode = NULL; } -} - -int32_t bmDrop(SMgmtWrapper *pWrapper) { - SBnodeMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return 0; - - dInfo("bnode-mgmt start to drop"); - bool deployed = false; - if (dndWriteFile(pWrapper, deployed) != 0) { - dError("failed to drop bnode since %s", terrstr()); - return -1; - } - bmCloseImp(pMgmt); - taosRemoveDir(pMgmt->path); - pWrapper->pMgmt = NULL; - taosMemoryFree(pMgmt); - dInfo("bnode-mgmt is dropped"); - return 0; -} - -static void bmClose(SMgmtWrapper *pWrapper) { - SBnodeMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return; - - dInfo("bnode-mgmt start to cleanup"); - bmCloseImp(pMgmt); pWrapper->pMgmt = NULL; taosMemoryFree(pMgmt); dInfo("bnode-mgmt is cleaned up"); @@ -98,23 +53,30 @@ int32_t bmOpen(SMgmtWrapper *pWrapper) { pMgmt->pWrapper = pWrapper; pWrapper->pMgmt = pMgmt; - int32_t code = bmOpenImp(pMgmt); - if (code != 0) { - dError("failed to init bnode-mgmt since %s", terrstr()); + SBnodeOpt option = {0}; + bmInitOption(pMgmt, &option); + pMgmt->pBnode = bndOpen(pMgmt->path, &option); + if (pMgmt->pBnode == NULL) { + dError("failed to open bnode since %s", terrstr()); bmClose(pWrapper); - } else { - dInfo("bnode-mgmt is initialized"); + return -1; } - return code; + if (bmStartWorker(pMgmt) != 0) { + dError("failed to start bnode worker since %s", terrstr()); + bmClose(pWrapper); + return -1; + } + + return 0; } void bmSetMgmtFp(SMgmtWrapper *pWrapper) { SMgmtFp mgmtFp = {0}; mgmtFp.openFp = bmOpen; mgmtFp.closeFp = bmClose; - mgmtFp.createMsgFp = bmProcessCreateReq; - mgmtFp.dropMsgFp = bmProcessDropReq; + mgmtFp.createFp = bmProcessCreateReq; + mgmtFp.dropFp = bmProcessDropReq; mgmtFp.requiredFp = bmRequire; bmInitMsgHandle(pWrapper); diff --git a/source/dnode/mgmt/bm/bmWorker.c b/source/dnode/mgmt/mgmt_bnode/src/bmWorker.c similarity index 100% rename from source/dnode/mgmt/bm/bmWorker.c rename to source/dnode/mgmt/mgmt_bnode/src/bmWorker.c diff --git a/source/dnode/mgmt/mgmt_mnode/CMakeLists.txt b/source/dnode/mgmt/mgmt_mnode/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5ca9af5628cb9bc54b8af860b9efdc753cd93121 --- /dev/null +++ b/source/dnode/mgmt/mgmt_mnode/CMakeLists.txt @@ -0,0 +1,9 @@ +aux_source_directory(src MGMT_MNODE) +add_library(mgmt_mnode STATIC ${MGMT_MNODE}) +target_include_directories( + mgmt_mnode + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + mgmt_mnode dnode_interface +) \ No newline at end of file diff --git a/source/dnode/mgmt/inc/mmInt.h b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h similarity index 92% rename from source/dnode/mgmt/inc/mmInt.h rename to source/dnode/mgmt/mgmt_mnode/inc/mmInt.h index 74b1cc44bf58767b9c2345c574b3243280aac18e..5f66ae230a5e50e36d52f861652dc334077386d4 100644 --- a/source/dnode/mgmt/inc/mmInt.h +++ b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h @@ -16,7 +16,8 @@ #ifndef _TD_DND_MNODE_INT_H_ #define _TD_DND_MNODE_INT_H_ -#include "dndInt.h" +#include "dmInt.h" + #include "mnode.h" #ifdef __cplusplus @@ -40,11 +41,9 @@ typedef struct SMnodeMgmt { // mmFile.c int32_t mmReadFile(SMnodeMgmt *pMgmt, bool *pDeployed); -int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed); +int32_t mmWriteFile(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq, bool deployed); // mmInt.c -int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq); -int32_t mmDrop(SMgmtWrapper *pWrapper); int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pReq); // mmHandle.c diff --git a/source/dnode/mgmt/mm/mmFile.c b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c similarity index 77% rename from source/dnode/mgmt/mm/mmFile.c rename to source/dnode/mgmt/mgmt_mnode/src/mmFile.c index 57e1c0cb929f2377dac7eb9da7b1c29a401c6d28..baf16f591d8f0066ad49abc8f0b74f143028bcfc 100644 --- a/source/dnode/mgmt/mm/mmFile.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c @@ -28,7 +28,7 @@ int32_t mmReadFile(SMnodeMgmt *pMgmt, bool *pDeployed) { snprintf(file, sizeof(file), "%s%smnode.json", pMgmt->path, TD_DIRSEP); pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - dDebug("file %s not exist", file); + // dDebug("file %s not exist", file); code = 0; goto PRASE_MNODE_OVER; } @@ -105,11 +105,13 @@ PRASE_MNODE_OVER: return code; } -int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) { - char file[PATH_MAX]; - snprintf(file, sizeof(file), "%s%smnode.json.bak", pMgmt->path, TD_DIRSEP); +int32_t mmWriteFile(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq, bool deployed) { + char file[PATH_MAX] = {0}; + char realfile[PATH_MAX] = {0}; + snprintf(file, sizeof(file), "%s%smnode.json.bak", pWrapper->path, TD_DIRSEP); + snprintf(realfile, sizeof(realfile), "%s%smnode.json", pWrapper->path, TD_DIRSEP); - TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to write %s since %s", file, terrstr()); @@ -119,21 +121,30 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) { int32_t len = 0; int32_t maxLen = 4096; char *content = taosMemoryCalloc(1, maxLen + 1); - + len += snprintf(content + len, maxLen - len, "{\n"); - len += snprintf(content + len, maxLen - len, " \"deployed\": %d,\n", deployed); len += snprintf(content + len, maxLen - len, " \"mnodes\": [{\n"); - for (int32_t i = 0; i < pMgmt->replica; ++i) { - SReplica *pReplica = &pMgmt->replicas[i]; - len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pReplica->id); - len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn); - len += snprintf(content + len, maxLen - len, " \"port\": %u\n", pReplica->port); - if (i < pMgmt->replica - 1) { - len += snprintf(content + len, maxLen - len, " },{\n"); - } else { - len += snprintf(content + len, maxLen - len, " }]\n"); + + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + if (pReq != NULL || pMgmt != NULL) { + int8_t replica = (pReq != NULL ? pReq->replica : pMgmt->replica); + for (int32_t i = 0; i < replica; ++i) { + SReplica *pReplica = &pMgmt->replicas[i]; + if (pReq != NULL) { + pReplica = &pReq->replicas[i]; + } + len += snprintf(content + len, maxLen - len, " \"id\": %d,\n", pReplica->id); + len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn); + len += snprintf(content + len, maxLen - len, " \"port\": %u\n", pReplica->port); + if (i < replica - 1) { + len += snprintf(content + len, maxLen - len, " },{\n"); + } else { + len += snprintf(content + len, maxLen - len, " }],\n"); + } } } + + len += snprintf(content + len, maxLen - len, " \"deployed\": %d\n", deployed); len += snprintf(content + len, maxLen - len, "}\n"); taosWriteFile(pFile, content, len); @@ -141,9 +152,6 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) { taosCloseFile(&pFile); taosMemoryFree(content); - char realfile[PATH_MAX]; - snprintf(realfile, sizeof(realfile), "%s%smnode.json", pMgmt->path, TD_DIRSEP); - if (taosRenameFile(file, realfile) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to rename %s since %s", file, terrstr()); diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c new file mode 100644 index 0000000000000000000000000000000000000000..38885333c9253badd1d9af26cb6ee74510269c80 --- /dev/null +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "mmInt.h" + +void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + mndGetMonitorInfo(pMgmt->pMnode, &mmInfo->cluster, &mmInfo->vgroup, &mmInfo->grant); +} + +int32_t mmProcessGetMonMmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { + SMonMmInfo mmInfo = {0}; + mmGetMonitorInfo(pWrapper, &mmInfo); + dmGetMonitorSysInfo(&mmInfo.sys); + monGetLogs(&mmInfo.log); + + int32_t rspLen = tSerializeSMonMmInfo(NULL, 0, &mmInfo); + if (rspLen < 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + void *pRsp = rpcMallocCont(rspLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + tSerializeSMonMmInfo(pRsp, rspLen, &mmInfo); + pReq->pRsp = pRsp; + pReq->rspLen = rspLen; + tFreeSMonMmInfo(&mmInfo); + return 0; +} + +int32_t mmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SDnode *pDnode = pWrapper->pDnode; + SRpcMsg *pReq = &pMsg->rpcMsg; + + SDCreateMnodeReq createReq = {0}; + if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + if (createReq.replica <= 1 || createReq.dnodeId != pDnode->data.dnodeId) { + terrno = TSDB_CODE_INVALID_OPTION; + dError("failed to create mnode since %s", terrstr()); + return -1; + } + + bool deployed = true; + if (mmWriteFile(pWrapper, &createReq, deployed) != 0) { + dError("failed to write mnode file since %s", terrstr()); + return -1; + } + + return 0; +} + +int32_t mmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SDnode *pDnode = pWrapper->pDnode; + SRpcMsg *pReq = &pMsg->rpcMsg; + + SDDropMnodeReq dropReq = {0}; + if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + if (dropReq.dnodeId != pDnode->data.dnodeId) { + terrno = TSDB_CODE_INVALID_OPTION; + dError("failed to drop mnode since %s", terrstr()); + return -1; + } + + bool deployed = false; + if (mmWriteFile(pWrapper, NULL, deployed) != 0) { + dError("failed to write mnode file since %s", terrstr()); + return -1; + } + + return 0; +} + +int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { + SDnode *pDnode = pMgmt->pDnode; + SRpcMsg *pReq = &pMsg->rpcMsg; + + SDAlterMnodeReq alterReq = {0}; + if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &alterReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + if (alterReq.dnodeId != pDnode->data.dnodeId) { + terrno = TSDB_CODE_INVALID_OPTION; + dError("failed to alter mnode since %s, dnodeId:%d input:%d", terrstr(), pDnode->data.dnodeId, alterReq.dnodeId); + return -1; + } else { + return mmAlter(pMgmt, &alterReq); + } +} + +void mmInitMsgHandle(SMgmtWrapper *pWrapper) { + dmSetMsgHandle(pWrapper, TDMT_MON_MM_INFO, mmProcessMonitorMsg, DEFAULT_HANDLE); + + // Requests handled by DNODE + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + + // Requests handled by MNODE + dmSetMsgHandle(pWrapper, TDMT_MND_CONNECT, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_USER, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_USER, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_USER, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_GET_USER_AUTH, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CONFIG_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_USE_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_SYNC_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_COMPACT_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_RETRIEVE_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_STB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_STB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_STB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_SMA, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_SMA, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_TABLE_META, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_VGROUP_LIST, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_KILL_QUERY, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_KILL_CONN, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_HEARTBEAT, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_SYSTABLE_RETRIEVE, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_STATUS, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_KILL_TRANS, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_GRANT, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_AUTH, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_SUBSCRIBE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_MQ_COMMIT_OFFSET, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_GET_SUB_EP, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_STREAM, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_GET_DB_CFG, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_GET_INDEX, mmProcessReadMsg, DEFAULT_HANDLE); + + // Requests handled by VNODE + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_REB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY, mmProcessQueryMsg, MNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, mmProcessQueryMsg, MNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_FETCH, mmProcessQueryMsg, MNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, mmProcessQueryMsg, MNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, mmProcessQueryMsg, MNODE_HANDLE); +} diff --git a/source/dnode/mgmt/mm/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c similarity index 72% rename from source/dnode/mgmt/mm/mmInt.c rename to source/dnode/mgmt/mgmt_mnode/src/mmInt.c index 64daf09bf928388cff41881694ecf54dbbbd2e2c..69b4d509399cbf0a6e8cd831b4217913a883d530 100644 --- a/source/dnode/mgmt/mm/mmInt.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c @@ -18,9 +18,9 @@ #include "wal.h" static bool mmDeployRequired(SDnode *pDnode) { - if (pDnode->dnodeId > 0) return false; - if (pDnode->clusterId > 0) return false; - if (strcmp(pDnode->localEp, pDnode->firstEp) != 0) return false; + if (pDnode->data.dnodeId > 0) return false; + if (pDnode->data.clusterId > 0) return false; + if (strcmp(pDnode->data.localEp, pDnode->data.firstEp) != 0) return false; return true; } @@ -39,7 +39,8 @@ static int32_t mmRequire(SMgmtWrapper *pWrapper, bool *required) { } static void mmInitOption(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { - SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = pMgmt->pDnode->data.msgCb; + msgCb.pWrapper = pMgmt->pWrapper; msgCb.queueFps[QUERY_QUEUE] = mmPutMsgToQueryQueue; msgCb.queueFps[READ_QUEUE] = mmPutMsgToReadQueue; msgCb.queueFps[WRITE_QUEUE] = mmPutMsgToWriteQueue; @@ -53,8 +54,8 @@ static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { pOption->selfIndex = 0; SReplica *pReplica = &pOption->replicas[0]; pReplica->id = 1; - pReplica->port = pMgmt->pDnode->serverPort; - tstrncpy(pReplica->fqdn, pMgmt->pDnode->localFqdn, TSDB_FQDN_LEN); + pReplica->port = pMgmt->pDnode->data.serverPort; + tstrncpy(pReplica->fqdn, pMgmt->pDnode->data.localFqdn, TSDB_FQDN_LEN); pOption->deploy = true; pMgmt->selfIndex = pOption->selfIndex; @@ -80,7 +81,7 @@ static int32_t mmBuildOptionFromReq(SMnodeMgmt *pMgmt, SMnodeOpt *pOption, SDCre pReplica->id = pCreate->replicas[i].id; pReplica->port = pCreate->replicas[i].port; memcpy(pReplica->fqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN); - if (pReplica->id == pMgmt->pDnode->dnodeId) { + if (pReplica->id == pMgmt->pDnode->data.dnodeId) { pOption->selfIndex = i; } } @@ -97,41 +98,18 @@ static int32_t mmBuildOptionFromReq(SMnodeMgmt *pMgmt, SMnodeOpt *pOption, SDCre return 0; } -static int32_t mmOpenImp(SMnodeMgmt *pMgmt, SDCreateMnodeReq *pReq) { +int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pReq) { SMnodeOpt option = {0}; - if (pReq != NULL) { - if (mmBuildOptionFromReq(pMgmt, &option, pReq) != 0) { - return -1; - } - } else { - bool deployed = false; - if (mmReadFile(pMgmt, &deployed) != 0) { - dError("failed to read file since %s", terrstr()); - return -1; - } - - if (!deployed) { - dInfo("mnode start to deploy"); - mmBuildOptionForDeploy(pMgmt, &option); - } else { - dInfo("mnode start to open"); - mmBuildOptionForOpen(pMgmt, &option); - } - } - - pMgmt->pMnode = mndOpen(pMgmt->path, &option); - if (pMgmt->pMnode == NULL) { - dError("failed to open mnode since %s", terrstr()); + if (mmBuildOptionFromReq(pMgmt, &option, pReq) != 0) { return -1; } - if (mmStartWorker(pMgmt) != 0) { - dError("failed to start mnode worker since %s", terrstr()); + if (mndAlter(pMgmt->pMnode, &option) != 0) { return -1; } bool deployed = true; - if (mmWriteFile(pMgmt, deployed) != 0) { + if (mmWriteFile(pMgmt->pWrapper, pReq, deployed) != 0) { dError("failed to write mnode file since %s", terrstr()); return -1; } @@ -139,53 +117,23 @@ static int32_t mmOpenImp(SMnodeMgmt *pMgmt, SDCreateMnodeReq *pReq) { return 0; } -static void mmCloseImp(SMnodeMgmt *pMgmt) { +static void mmClose(SMgmtWrapper *pWrapper) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + if (pMgmt == NULL) return; + + dInfo("mnode-mgmt start to cleanup"); if (pMgmt->pMnode != NULL) { mmStopWorker(pMgmt); mndClose(pMgmt->pMnode); pMgmt->pMnode = NULL; } -} - -int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pReq) { - SMnodeOpt option = {0}; - if (mmBuildOptionFromReq(pMgmt, &option, pReq) != 0) { - return -1; - } - return mndAlter(pMgmt->pMnode, &option); -} - -int32_t mmDrop(SMgmtWrapper *pWrapper) { - SMnodeMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return 0; - - dInfo("mnode-mgmt start to drop"); - bool deployed = false; - if (mmWriteFile(pMgmt, deployed) != 0) { - dError("failed to drop mnode since %s", terrstr()); - return -1; - } - - mmCloseImp(pMgmt); - taosRemoveDir(pMgmt->path); - pWrapper->pMgmt = NULL; - taosMemoryFree(pMgmt); - dInfo("mnode-mgmt is dropped"); - return 0; -} - -static void mmClose(SMgmtWrapper *pWrapper) { - SMnodeMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return; - dInfo("mnode-mgmt start to cleanup"); - mmCloseImp(pMgmt); pWrapper->pMgmt = NULL; taosMemoryFree(pMgmt); dInfo("mnode-mgmt is cleaned up"); } -int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq) { +static int32_t mmOpen(SMgmtWrapper *pWrapper) { dInfo("mnode-mgmt start to init"); if (walInit() != 0) { dError("failed to init wal since %s", terrstr()); @@ -203,18 +151,49 @@ int32_t mmOpenFromMsg(SMgmtWrapper *pWrapper, SDCreateMnodeReq *pReq) { pMgmt->pWrapper = pWrapper; pWrapper->pMgmt = pMgmt; - int32_t code = mmOpenImp(pMgmt, pReq); - if (code != 0) { - dError("failed to init mnode-mgmt since %s", terrstr()); + bool deployed = false; + if (mmReadFile(pMgmt, &deployed) != 0) { + dError("failed to read file since %s", terrstr()); mmClose(pWrapper); + return -1; + } + + SMnodeOpt option = {0}; + if (!deployed) { + dInfo("mnode start to deploy"); + if (pWrapper->procType == DND_PROC_CHILD) { + pWrapper->pDnode->data.dnodeId = 1; + } + mmBuildOptionForDeploy(pMgmt, &option); } else { - dInfo("mnode-mgmt is initialized"); + dInfo("mnode start to open"); + mmBuildOptionForOpen(pMgmt, &option); } - return code; -} + pMgmt->pMnode = mndOpen(pMgmt->path, &option); + if (pMgmt->pMnode == NULL) { + dError("failed to open mnode since %s", terrstr()); + mmClose(pWrapper); + return -1; + } + + if (mmStartWorker(pMgmt) != 0) { + dError("failed to start mnode worker since %s", terrstr()); + mmClose(pWrapper); + return -1; + } + + if (!deployed) { + deployed = true; + if (mmWriteFile(pWrapper, NULL, deployed) != 0) { + dError("failed to write mnode file since %s", terrstr()); + return -1; + } + } -static int32_t mmOpen(SMgmtWrapper *pWrapper) { return mmOpenFromMsg(pWrapper, NULL); } + dInfo("mnode-mgmt is initialized"); + return 0; +} static int32_t mmStart(SMgmtWrapper *pWrapper) { dDebug("mnode-mgmt start to run"); @@ -222,13 +201,22 @@ static int32_t mmStart(SMgmtWrapper *pWrapper) { return mndStart(pMgmt->pMnode); } +static void mmStop(SMgmtWrapper *pWrapper) { + dDebug("mnode-mgmt start to stop"); + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + if (pMgmt != NULL) { + mndStop(pMgmt->pMnode); + } +} + void mmSetMgmtFp(SMgmtWrapper *pWrapper) { SMgmtFp mgmtFp = {0}; mgmtFp.openFp = mmOpen; mgmtFp.closeFp = mmClose; mgmtFp.startFp = mmStart; - mgmtFp.createMsgFp = mmProcessCreateReq; - mgmtFp.dropMsgFp = mmProcessDropReq; + mgmtFp.stopFp = mmStop; + mgmtFp.createFp = mmProcessCreateReq; + mgmtFp.dropFp = mmProcessDropReq; mgmtFp.requiredFp = mmRequire; mmInitMsgHandle(pWrapper); diff --git a/source/dnode/mgmt/mm/mmWorker.c b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c similarity index 100% rename from source/dnode/mgmt/mm/mmWorker.c rename to source/dnode/mgmt/mgmt_mnode/src/mmWorker.c diff --git a/source/dnode/mgmt/mgmt_qnode/CMakeLists.txt b/source/dnode/mgmt/mgmt_qnode/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..bf31b2afc3349593d3e54ef63c76c74762e87cc5 --- /dev/null +++ b/source/dnode/mgmt/mgmt_qnode/CMakeLists.txt @@ -0,0 +1,9 @@ +aux_source_directory(src MGMT_QNODE) +add_library(mgmt_qnode STATIC ${MGMT_QNODE}) +target_include_directories( + mgmt_qnode + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + mgmt_qnode dnode_interface +) \ No newline at end of file diff --git a/source/dnode/mgmt/inc/qmInt.h b/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h similarity index 92% rename from source/dnode/mgmt/inc/qmInt.h rename to source/dnode/mgmt/mgmt_qnode/inc/qmInt.h index 012869d6375e5a8102273e67f920b1fda8da9f32..d52fbff683a5c5d43de21151d3e28b3e132e9620 100644 --- a/source/dnode/mgmt/inc/qmInt.h +++ b/source/dnode/mgmt/mgmt_qnode/inc/qmInt.h @@ -16,7 +16,8 @@ #ifndef _TD_DND_QNODE_INT_H_ #define _TD_DND_QNODE_INT_H_ -#include "dndInt.h" +#include "dmInt.h" + #include "qnode.h" #ifdef __cplusplus @@ -33,10 +34,6 @@ typedef struct SQnodeMgmt { SSingleWorker monitorWorker; } SQnodeMgmt; -// qmInt.c -int32_t qmOpen(SMgmtWrapper *pWrapper); -int32_t qmDrop(SMgmtWrapper *pWrapper); - // qmHandle.c void qmInitMsgHandle(SMgmtWrapper *pWrapper); int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); diff --git a/source/dnode/mgmt/qm/qmHandle.c b/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c similarity index 66% rename from source/dnode/mgmt/qm/qmHandle.c rename to source/dnode/mgmt/mgmt_qnode/src/qmHandle.c index 96fc33852962cce1b4c74bffdd0ad0ee1ee2b371..805b4c7264e57794cfd31d7207784d47edde8cbc 100644 --- a/source/dnode/mgmt/qm/qmHandle.c +++ b/source/dnode/mgmt/mgmt_qnode/src/qmHandle.c @@ -53,13 +53,19 @@ int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (createReq.dnodeId != pDnode->dnodeId) { + if (createReq.dnodeId != pDnode->data.dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to create qnode since %s", terrstr()); return -1; - } else { - return qmOpen(pWrapper); } + + bool deployed = true; + if (dmWriteFile(pWrapper, deployed) != 0) { + dError("failed to write qnode file since %s", terrstr()); + return -1; + } + + return 0; } int32_t qmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { @@ -72,27 +78,32 @@ int32_t qmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (dropReq.dnodeId != pDnode->dnodeId) { + if (dropReq.dnodeId != pDnode->data.dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to drop qnode since %s", terrstr()); return -1; - } else { - return qmDrop(pWrapper); } + + bool deployed = false; + if (dmWriteFile(pWrapper, deployed) != 0) { + dError("failed to write qnode file since %s", terrstr()); + return -1; + } + + return 0; } void qmInitMsgHandle(SMgmtWrapper *pWrapper) { - dndSetMsgHandle(pWrapper, TDMT_MON_QM_INFO, qmProcessMonitorMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MON_QM_INFO, qmProcessMonitorMsg, DEFAULT_HANDLE); // Requests handled by VNODE - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, qmProcessQueryMsg, QNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, qmProcessQueryMsg, QNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, qmProcessFetchMsg, QNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, qmProcessFetchMsg, QNODE_HANDLE); - - dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, qmProcessFetchMsg, QNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, qmProcessFetchMsg, QNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, qmProcessFetchMsg, QNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, qmProcessFetchMsg, QNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, qmProcessFetchMsg, QNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY, qmProcessQueryMsg, QNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, qmProcessQueryMsg, QNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_FETCH, qmProcessFetchMsg, QNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, qmProcessFetchMsg, QNODE_HANDLE); + + dmSetMsgHandle(pWrapper, TDMT_VND_RES_READY, qmProcessFetchMsg, QNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, qmProcessFetchMsg, QNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, qmProcessFetchMsg, QNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, qmProcessFetchMsg, QNODE_HANDLE); } diff --git a/source/dnode/mgmt/qm/qmInt.c b/source/dnode/mgmt/mgmt_qnode/src/qmInt.c similarity index 66% rename from source/dnode/mgmt/qm/qmInt.c rename to source/dnode/mgmt/mgmt_qnode/src/qmInt.c index 585a7fb18369ba2a4728b9dcb87706da5131292c..d8d02b2619995396888a04aae7966d52d0a18d02 100644 --- a/source/dnode/mgmt/qm/qmInt.c +++ b/source/dnode/mgmt/mgmt_qnode/src/qmInt.c @@ -16,79 +16,34 @@ #define _DEFAULT_SOURCE #include "qmInt.h" -static int32_t qmRequire(SMgmtWrapper *pWrapper, bool *required) { return dndReadFile(pWrapper, required); } +static int32_t qmRequire(SMgmtWrapper *pWrapper, bool *required) { return dmReadFile(pWrapper, required); } static void qmInitOption(SQnodeMgmt *pMgmt, SQnodeOpt *pOption) { - SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = pMgmt->pDnode->data.msgCb; + msgCb.pWrapper = pMgmt->pWrapper; msgCb.queueFps[QUERY_QUEUE] = qmPutMsgToQueryQueue; msgCb.queueFps[FETCH_QUEUE] = qmPutMsgToFetchQueue; msgCb.qsizeFp = qmGetQueueSize; pOption->msgCb = msgCb; } -static int32_t qmOpenImp(SQnodeMgmt *pMgmt) { - SQnodeOpt option = {0}; - qmInitOption(pMgmt, &option); - - pMgmt->pQnode = qndOpen(&option); - if (pMgmt->pQnode == NULL) { - dError("failed to open qnode since %s", terrstr()); - return -1; - } - - if (qmStartWorker(pMgmt) != 0) { - dError("failed to start qnode worker since %s", terrstr()); - return -1; - } - - bool deployed = true; - if (dndWriteFile(pMgmt->pWrapper, deployed) != 0) { - dError("failed to write qnode file since %s", terrstr()); - return -1; - } - - return 0; -} +static void qmClose(SMgmtWrapper *pWrapper) { + SQnodeMgmt *pMgmt = pWrapper->pMgmt; + if (pMgmt == NULL) return; -static void qmCloseImp(SQnodeMgmt *pMgmt) { + dInfo("qnode-mgmt start to cleanup"); if (pMgmt->pQnode != NULL) { qmStopWorker(pMgmt); qndClose(pMgmt->pQnode); pMgmt->pQnode = NULL; } -} - -int32_t qmDrop(SMgmtWrapper *pWrapper) { - SQnodeMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return 0; - - dInfo("qnode-mgmt start to drop"); - bool deployed = false; - if (dndWriteFile(pWrapper, deployed) != 0) { - dError("failed to drop qnode since %s", terrstr()); - return -1; - } - qmCloseImp(pMgmt); - taosRemoveDir(pMgmt->path); - pWrapper->pMgmt = NULL; - taosMemoryFree(pMgmt); - dInfo("qnode-mgmt is dropped"); - return 0; -} - -static void qmClose(SMgmtWrapper *pWrapper) { - SQnodeMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return; - - dInfo("qnode-mgmt start to cleanup"); - qmCloseImp(pMgmt); pWrapper->pMgmt = NULL; taosMemoryFree(pMgmt); dInfo("qnode-mgmt is cleaned up"); } -int32_t qmOpen(SMgmtWrapper *pWrapper) { +static int32_t qmOpen(SMgmtWrapper *pWrapper) { dInfo("qnode-mgmt start to init"); SQnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SQnodeMgmt)); if (pMgmt == NULL) { @@ -101,23 +56,31 @@ int32_t qmOpen(SMgmtWrapper *pWrapper) { pMgmt->pWrapper = pWrapper; pWrapper->pMgmt = pMgmt; - int32_t code = qmOpenImp(pMgmt); - if (code != 0) { - dError("failed to init qnode-mgmt since %s", terrstr()); + SQnodeOpt option = {0}; + qmInitOption(pMgmt, &option); + pMgmt->pQnode = qndOpen(&option); + if (pMgmt->pQnode == NULL) { + dError("failed to open qnode since %s", terrstr()); qmClose(pWrapper); - } else { - dInfo("qnode-mgmt is initialized"); + return -1; } - return code; + if (qmStartWorker(pMgmt) != 0) { + dError("failed to start qnode worker since %s", terrstr()); + qmClose(pWrapper); + return -1; + } + + dInfo("qnode-mgmt is initialized"); + return 0; } void qmSetMgmtFp(SMgmtWrapper *pWrapper) { SMgmtFp mgmtFp = {0}; mgmtFp.openFp = qmOpen; mgmtFp.closeFp = qmClose; - mgmtFp.createMsgFp = qmProcessCreateReq; - mgmtFp.dropMsgFp = qmProcessDropReq; + mgmtFp.createFp = qmProcessCreateReq; + mgmtFp.dropFp = qmProcessDropReq; mgmtFp.requiredFp = qmRequire; qmInitMsgHandle(pWrapper); diff --git a/source/dnode/mgmt/qm/qmWorker.c b/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c similarity index 99% rename from source/dnode/mgmt/qm/qmWorker.c rename to source/dnode/mgmt/mgmt_qnode/src/qmWorker.c index 974052cdf64683f990269bf6aad34725a56229f8..6b27af4fbd343d6b8bc616ddcb09b671c29bbfe0 100644 --- a/source/dnode/mgmt/qm/qmWorker.c +++ b/source/dnode/mgmt/mgmt_qnode/src/qmWorker.c @@ -32,7 +32,7 @@ static void qmProcessMonitorQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { SRpcMsg *pRpc = &pMsg->rpcMsg; int32_t code = -1; - if (pMsg->rpcMsg.msgType == TDMT_MON_SM_INFO) { + if (pMsg->rpcMsg.msgType == TDMT_MON_QM_INFO) { code = qmProcessGetMonQmInfoReq(pMgmt->pWrapper, pMsg); } else { terrno = TSDB_CODE_MSG_NOT_PROCESSED; diff --git a/source/dnode/mgmt/mgmt_snode/CMakeLists.txt b/source/dnode/mgmt/mgmt_snode/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..b8a99c9d4df894c58854bef6a56b9b3daebcff6a --- /dev/null +++ b/source/dnode/mgmt/mgmt_snode/CMakeLists.txt @@ -0,0 +1,9 @@ +aux_source_directory(src MGMT_SNODE) +add_library(mgmt_snode STATIC ${MGMT_SNODE}) +target_include_directories( + mgmt_snode + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + mgmt_snode dnode_interface +) \ No newline at end of file diff --git a/source/dnode/mgmt/inc/smInt.h b/source/dnode/mgmt/mgmt_snode/inc/smInt.h similarity index 92% rename from source/dnode/mgmt/inc/smInt.h rename to source/dnode/mgmt/mgmt_snode/inc/smInt.h index 039dea24919eefa551c6c332c11f790747156f4a..9eb48af733f5947b9318972719d7fae8c97a1119 100644 --- a/source/dnode/mgmt/inc/smInt.h +++ b/source/dnode/mgmt/mgmt_snode/inc/smInt.h @@ -16,7 +16,8 @@ #ifndef _TD_DND_SNODE_INT_H_ #define _TD_DND_SNODE_INT_H_ -#include "dndInt.h" +#include "dmInt.h" + #include "snode.h" #ifdef __cplusplus @@ -35,10 +36,6 @@ typedef struct SSnodeMgmt { SSingleWorker monitorWorker; } SSnodeMgmt; -// smInt.c -int32_t smOpen(SMgmtWrapper *pWrapper); -int32_t smDrop(SMgmtWrapper *pWrapper); - // smHandle.c void smInitMsgHandle(SMgmtWrapper *pWrapper); int32_t smProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg); diff --git a/source/dnode/mgmt/sm/smHandle.c b/source/dnode/mgmt/mgmt_snode/src/smHandle.c similarity index 78% rename from source/dnode/mgmt/sm/smHandle.c rename to source/dnode/mgmt/mgmt_snode/src/smHandle.c index 36345cf49032f6be6b951704aafbe39dae1886c2..defc5ab136b4703273f649e65385c6c3b291a92d 100644 --- a/source/dnode/mgmt/sm/smHandle.c +++ b/source/dnode/mgmt/mgmt_snode/src/smHandle.c @@ -53,13 +53,19 @@ int32_t smProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (createReq.dnodeId != pDnode->dnodeId) { + if (createReq.dnodeId != pDnode->data.dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to create snode since %s", terrstr()); return -1; - } else { - return smOpen(pWrapper); } + + bool deployed = true; + if (dmWriteFile(pWrapper, deployed) != 0) { + dError("failed to write snode file since %s", terrstr()); + return -1; + } + + return 0; } int32_t smProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { @@ -72,19 +78,25 @@ int32_t smProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (dropReq.dnodeId != pDnode->dnodeId) { + if (dropReq.dnodeId != pDnode->data.dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to drop snode since %s", terrstr()); return -1; - } else { - return smDrop(pWrapper); } + + bool deployed = false; + if (dmWriteFile(pWrapper, deployed) != 0) { + dError("failed to write snode file since %s", terrstr()); + return -1; + } + + return 0; } void smInitMsgHandle(SMgmtWrapper *pWrapper) { - dndSetMsgHandle(pWrapper, TDMT_MON_SM_INFO, smProcessMonitorMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MON_SM_INFO, smProcessMonitorMsg, DEFAULT_HANDLE); // Requests handled by SNODE - dndSetMsgHandle(pWrapper, TDMT_SND_TASK_DEPLOY, smProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_SND_TASK_EXEC, smProcessExecMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_SND_TASK_DEPLOY, smProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_SND_TASK_EXEC, smProcessExecMsg, DEFAULT_HANDLE); } diff --git a/source/dnode/mgmt/sm/smInt.c b/source/dnode/mgmt/mgmt_snode/src/smInt.c similarity index 65% rename from source/dnode/mgmt/sm/smInt.c rename to source/dnode/mgmt/mgmt_snode/src/smInt.c index ef4e95d915de8afa3d9f660884a3b0637240d7e7..8adf643a2b4038f3199953f5ed5b6a92b4e5e2ea 100644 --- a/source/dnode/mgmt/sm/smInt.c +++ b/source/dnode/mgmt/mgmt_snode/src/smInt.c @@ -16,70 +16,25 @@ #define _DEFAULT_SOURCE #include "smInt.h" -static int32_t smRequire(SMgmtWrapper *pWrapper, bool *required) { return dndReadFile(pWrapper, required); } +static int32_t smRequire(SMgmtWrapper *pWrapper, bool *required) { return dmReadFile(pWrapper, required); } static void smInitOption(SSnodeMgmt *pMgmt, SSnodeOpt *pOption) { - SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = pMgmt->pDnode->data.msgCb; + msgCb.pWrapper = pMgmt->pWrapper; pOption->msgCb = msgCb; } -static int32_t smOpenImp(SSnodeMgmt *pMgmt) { - SSnodeOpt option = {0}; - smInitOption(pMgmt, &option); - - pMgmt->pSnode = sndOpen(pMgmt->path, &option); - if (pMgmt->pSnode == NULL) { - dError("failed to open snode since %s", terrstr()); - return -1; - } - - if (smStartWorker(pMgmt) != 0) { - dError("failed to start snode worker since %s", terrstr()); - return -1; - } - - bool deployed = true; - if (dndWriteFile(pMgmt->pWrapper, deployed) != 0) { - dError("failed to write snode file since %s", terrstr()); - return -1; - } - - return 0; -} +static void smClose(SMgmtWrapper *pWrapper) { + SSnodeMgmt *pMgmt = pWrapper->pMgmt; + if (pMgmt == NULL) return; -static void smCloseImp(SSnodeMgmt *pMgmt) { + dInfo("snode-mgmt start to cleanup"); if (pMgmt->pSnode != NULL) { smStopWorker(pMgmt); sndClose(pMgmt->pSnode); pMgmt->pSnode = NULL; } -} - -int32_t smDrop(SMgmtWrapper *pWrapper) { - SSnodeMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return 0; - dInfo("snode-mgmt start to drop"); - bool deployed = false; - if (dndWriteFile(pWrapper, deployed) != 0) { - dError("failed to drop snode since %s", terrstr()); - return -1; - } - - smCloseImp(pMgmt); - taosRemoveDir(pMgmt->path); - pWrapper->pMgmt = NULL; - taosMemoryFree(pMgmt); - dInfo("snode-mgmt is dropped"); - return 0; -} - -static void smClose(SMgmtWrapper *pWrapper) { - SSnodeMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return; - - dInfo("snode-mgmt start to cleanup"); - smCloseImp(pMgmt); pWrapper->pMgmt = NULL; taosMemoryFree(pMgmt); dInfo("snode-mgmt is cleaned up"); @@ -98,23 +53,28 @@ int32_t smOpen(SMgmtWrapper *pWrapper) { pMgmt->pWrapper = pWrapper; pWrapper->pMgmt = pMgmt; - int32_t code = smOpenImp(pMgmt); - if (code != 0) { - dError("failed to init snode-mgmt since %s", terrstr()); - smClose(pWrapper); - } else { - dInfo("snode-mgmt is initialized"); + SSnodeOpt option = {0}; + smInitOption(pMgmt, &option); + pMgmt->pSnode = sndOpen(pMgmt->path, &option); + if (pMgmt->pSnode == NULL) { + dError("failed to open snode since %s", terrstr()); + return -1; } - return code; + if (smStartWorker(pMgmt) != 0) { + dError("failed to start snode worker since %s", terrstr()); + return -1; + } + + return 0; } void smSetMgmtFp(SMgmtWrapper *pWrapper) { SMgmtFp mgmtFp = {0}; mgmtFp.openFp = smOpen; mgmtFp.closeFp = smClose; - mgmtFp.createMsgFp = smProcessCreateReq; - mgmtFp.dropMsgFp = smProcessDropReq; + mgmtFp.createFp = smProcessCreateReq; + mgmtFp.dropFp = smProcessDropReq; mgmtFp.requiredFp = smRequire; smInitMsgHandle(pWrapper); diff --git a/source/dnode/mgmt/sm/smWorker.c b/source/dnode/mgmt/mgmt_snode/src/smWorker.c similarity index 100% rename from source/dnode/mgmt/sm/smWorker.c rename to source/dnode/mgmt/mgmt_snode/src/smWorker.c diff --git a/source/dnode/mgmt/mgmt_vnode/CMakeLists.txt b/source/dnode/mgmt/mgmt_vnode/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..55a76cf772ea66bdceded16f50e49001485dfbbd --- /dev/null +++ b/source/dnode/mgmt/mgmt_vnode/CMakeLists.txt @@ -0,0 +1,9 @@ +aux_source_directory(src MGMT_VNODE) +add_library(mgmt_vnode STATIC ${MGMT_VNODE}) +target_include_directories( + mgmt_vnode + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + mgmt_vnode dnode_interface +) \ No newline at end of file diff --git a/source/dnode/mgmt/inc/vmInt.h b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h similarity index 97% rename from source/dnode/mgmt/inc/vmInt.h rename to source/dnode/mgmt/mgmt_vnode/inc/vmInt.h index f8466fe4f232979baa12867e13cfbe01d68a46ff..ab8328d038c22ae122e868104f94d2d9fad81bf2 100644 --- a/source/dnode/mgmt/inc/vmInt.h +++ b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h @@ -16,8 +16,9 @@ #ifndef _TD_DND_VNODES_INT_H_ #define _TD_DND_VNODES_INT_H_ +#include "dmInt.h" + #include "sync.h" -#include "dndInt.h" #include "vnode.h" #ifdef __cplusplus @@ -95,6 +96,7 @@ int32_t vmProcessSyncVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pReq); int32_t vmProcessCompactVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pReq); int32_t vmProcessGetMonVmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq); int32_t vmProcessGetVnodeLoadsReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq); +void vmGetVnodeLoads(SMgmtWrapper *pWrapper, SMonVloadInfo *pInfo); // vmFile.c int32_t vmGetVnodesFromFile(SVnodesMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes); diff --git a/source/dnode/mgmt/vm/vmFile.c b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c similarity index 99% rename from source/dnode/mgmt/vm/vmFile.c rename to source/dnode/mgmt/mgmt_vnode/src/vmFile.c index ba59482c1a6d40331fcab06ab1bc530b14f050bd..7e00a022b2dbf755bd95d089f31cd7d7211f137c 100644 --- a/source/dnode/mgmt/vm/vmFile.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c @@ -154,7 +154,7 @@ int32_t vmWriteVnodesToFile(SVnodesMgmt *pMgmt) { snprintf(file, sizeof(file), "%s%svnodes.json.bak", pMgmt->path, TD_DIRSEP); snprintf(realfile, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP); - TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); dError("failed to write %s since %s", file, terrstr()); diff --git a/source/dnode/mgmt/vm/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c similarity index 71% rename from source/dnode/mgmt/vm/vmHandle.c rename to source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 0e74ca656c824c187132f12d54227ea0a80fba6a..484b6646b5498f29b726d37480ff97cdabcd41a8 100644 --- a/source/dnode/mgmt/vm/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -143,7 +143,7 @@ int32_t vmProcessCreateVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { return -1; } - SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = pMgmt->pDnode->data.msgCb; msgCb.pWrapper = pMgmt->pWrapper; msgCb.queueFps[QUERY_QUEUE] = vmPutMsgToQueryQueue; msgCb.queueFps[FETCH_QUEUE] = vmPutMsgToFetchQueue; @@ -304,54 +304,51 @@ int32_t vmProcessCompactVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { } void vmInitMsgHandle(SMgmtWrapper *pWrapper) { - dndSetMsgHandle(pWrapper, TDMT_MON_VM_INFO, vmProcessMonitorMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MON_VM_LOAD, vmProcessMonitorMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MON_VM_INFO, vmProcessMonitorMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MON_VM_LOAD, vmProcessMonitorMsg, DEFAULT_HANDLE); // Requests handled by VNODE - dndSetMsgHandle(pWrapper, TDMT_VND_SUBMIT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_UPDATE_TAG_VAL, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TABLE_META, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TABLES_META, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONSUME, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_QUERY, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CONNECT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_DISCONNECT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_RES_READY, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CANCEL_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_SHOW_TABLES_FETCH, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CONSUME, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, (NodeMsgFp)vmProcessMergeMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_WRITE_EXEC, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_SUBMIT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_FETCH, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_UPDATE_TAG_VAL, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TABLE_META, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TABLES_META, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CONSUME, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_QUERY, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CONNECT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_DISCONNECT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_RES_READY, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CANCEL_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CONSUME, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, (NodeMsgFp)vmProcessMergeMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASK_WRITE_EXEC, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); } diff --git a/source/dnode/mgmt/vm/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c similarity index 97% rename from source/dnode/mgmt/vm/vmInt.c rename to source/dnode/mgmt/mgmt_vnode/src/vmInt.c index 6a1a5c3987ccb50c1a0008e29298e2d67148061b..1b8e0eb961e4d43800557a16ee8c9c212f422eb2 100644 --- a/source/dnode/mgmt/vm/vmInt.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c @@ -126,9 +126,9 @@ static void *vmOpenVnodeFunc(void *param) { char stepDesc[TSDB_STEP_DESC_LEN] = {0}; snprintf(stepDesc, TSDB_STEP_DESC_LEN, "vgId:%d, start to restore, %d of %d have been opened", pCfg->vgId, pMgmt->state.openVnodes, pMgmt->state.totalVnodes); - dndReportStartup(pDnode, "open-vnodes", stepDesc); + dmReportStartup(pDnode, "open-vnodes", stepDesc); - SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = pMgmt->pDnode->data.msgCb; msgCb.pWrapper = pMgmt->pWrapper; msgCb.queueFps[QUERY_QUEUE] = vmPutMsgToQueryQueue; msgCb.queueFps[FETCH_QUEUE] = vmPutMsgToFetchQueue; @@ -278,11 +278,11 @@ static int32_t vmInit(SMgmtWrapper *pWrapper) { taosInitRWLatch(&pMgmt->latch); SDiskCfg dCfg = {0}; - tstrncpy(dCfg.dir, pDnode->dataDir, TSDB_FILENAME_LEN); + tstrncpy(dCfg.dir, pDnode->data.dataDir, TSDB_FILENAME_LEN); dCfg.level = 0; dCfg.primary = 1; - SDiskCfg *pDisks = pDnode->disks; - int32_t numOfDisks = pDnode->numOfDisks; + SDiskCfg *pDisks = pDnode->data.disks; + int32_t numOfDisks = pDnode->data.numOfDisks; if (numOfDisks <= 0 || pDisks == NULL) { pDisks = &dCfg; numOfDisks = 1; @@ -299,7 +299,7 @@ static int32_t vmInit(SMgmtWrapper *pWrapper) { goto _OVER; } - if (vnodeInit() != 0) { + if (vnodeInit(tsNumOfCommitThreads) != 0) { dError("failed to init vnode since %s", terrstr()); goto _OVER; } @@ -329,7 +329,7 @@ _OVER: static int32_t vmRequire(SMgmtWrapper *pWrapper, bool *required) { SDnode *pDnode = pWrapper->pDnode; - *required = pDnode->numOfSupportVnodes > 0; + *required = pDnode->data.supportVnodes > 0; return 0; } diff --git a/source/dnode/mgmt/vm/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c similarity index 98% rename from source/dnode/mgmt/vm/vmWorker.c rename to source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index ff92cf880b0107f2544d0ef58664fc41c65464f7..2fb29ce944ac4e5f0ee7e6386a76111af6dc4942 100644 --- a/source/dnode/mgmt/vm/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -115,7 +115,7 @@ static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO } } - vnodeProcessWMsgs(pVnode->pImpl, pArray); + vnodePreprocessWriteReqs(pVnode->pImpl, pArray); numOfMsgs = taosArrayGetSize(pArray); for (int32_t i = 0; i < numOfMsgs; i++) { @@ -123,7 +123,7 @@ static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO SRpcMsg *pRpc = &pMsg->rpcMsg; SRpcMsg *pRsp = NULL; - int32_t code = vnodeApplyWMsg(pVnode->pImpl, pRpc, &pRsp); + int32_t code = vnodeProcessWriteReq(pVnode->pImpl, pRpc, &pRsp); if (pRsp != NULL) { pRsp->ahandle = pRpc->ahandle; tmsgSendRsp(pRsp); @@ -153,7 +153,7 @@ static void vmProcessApplyQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO // todo SRpcMsg *pRsp = NULL; - (void)vnodeApplyWMsg(pVnode->pImpl, &pMsg->rpcMsg, &pRsp); + (void)vnodeProcessWriteReq(pVnode->pImpl, &pMsg->rpcMsg, &pRsp); } } diff --git a/source/dnode/mgmt/mm/mmHandle.c b/source/dnode/mgmt/mm/mmHandle.c deleted file mode 100644 index eeae9da8b7ef90d874cb33b66b9b37c0346d4d49..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/mm/mmHandle.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "mmInt.h" - -void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo) { - SMnodeMgmt *pMgmt = pWrapper->pMgmt; - mndGetMonitorInfo(pMgmt->pMnode, &mmInfo->cluster, &mmInfo->vgroup, &mmInfo->grant); -} - -int32_t mmProcessGetMonMmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { - SMonMmInfo mmInfo = {0}; - mmGetMonitorInfo(pWrapper, &mmInfo); - dmGetMonitorSysInfo(&mmInfo.sys); - monGetLogs(&mmInfo.log); - - int32_t rspLen = tSerializeSMonMmInfo(NULL, 0, &mmInfo); - if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - void *pRsp = rpcMallocCont(rspLen); - if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - tSerializeSMonMmInfo(pRsp, rspLen, &mmInfo); - pReq->pRsp = pRsp; - pReq->rspLen = rspLen; - tFreeSMonMmInfo(&mmInfo); - return 0; -} - -int32_t mmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SDnode *pDnode = pWrapper->pDnode; - SRpcMsg *pReq = &pMsg->rpcMsg; - - SDCreateMnodeReq createReq = {0}; - if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - if (createReq.replica <= 1 || createReq.dnodeId != pDnode->dnodeId) { - terrno = TSDB_CODE_INVALID_OPTION; - dError("failed to create mnode since %s", terrstr()); - return -1; - } else { - return mmOpenFromMsg(pWrapper, &createReq); - } -} - -int32_t mmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SDnode *pDnode = pWrapper->pDnode; - SRpcMsg *pReq = &pMsg->rpcMsg; - - SDDropMnodeReq dropReq = {0}; - if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - if (dropReq.dnodeId != pDnode->dnodeId) { - terrno = TSDB_CODE_INVALID_OPTION; - dError("failed to drop mnode since %s", terrstr()); - return -1; - } else { - return mmDrop(pWrapper); - } -} - -int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { - SDnode *pDnode = pMgmt->pDnode; - SRpcMsg *pReq = &pMsg->rpcMsg; - - SDAlterMnodeReq alterReq = {0}; - if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &alterReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - if (alterReq.dnodeId != pDnode->dnodeId) { - terrno = TSDB_CODE_INVALID_OPTION; - dError("failed to alter mnode since %s", terrstr()); - return -1; - } else { - return mmAlter(pMgmt, &alterReq); - } -} - -void mmInitMsgHandle(SMgmtWrapper *pWrapper) { - dndSetMsgHandle(pWrapper, TDMT_MON_MM_INFO, mmProcessMonitorMsg, DEFAULT_HANDLE); - - // Requests handled by DNODE - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - - // Requests handled by MNODE - dndSetMsgHandle(pWrapper, TDMT_MND_CONNECT, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_USER, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_USER, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_USER, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_GET_USER_AUTH, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CONFIG_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_DB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_DB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_USE_DB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_DB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_SYNC_DB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_COMPACT_DB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_RETRIEVE_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_STB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_STB, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_SMA, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_SMA, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_TABLE_META, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_VGROUP_LIST, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_KILL_QUERY, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_KILL_CONN, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_HEARTBEAT, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_SHOW, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_SHOW_RETRIEVE, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_SYSTABLE_RETRIEVE, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_STATUS, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_KILL_TRANS, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_GRANT, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_AUTH, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_ALTER_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_DROP_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_SUBSCRIBE, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_MQ_COMMIT_OFFSET, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_GET_SUB_EP, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_CREATE_STREAM, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_GET_DB_CFG, mmProcessReadMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_GET_INDEX, mmProcessReadMsg, DEFAULT_HANDLE); - - // Requests handled by VNODE - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); - - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, mmProcessQueryMsg, MNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, mmProcessQueryMsg, MNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, mmProcessQueryMsg, MNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, mmProcessQueryMsg, MNODE_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, mmProcessQueryMsg, MNODE_HANDLE); -} diff --git a/source/dnode/mgmt/test/CMakeLists.txt b/source/dnode/mgmt/test/CMakeLists.txt index ce93a14d3fc30e6d22877e28a4d04f4e3618a349..e1656ceb34d222fb13ef524b087349756d46d6ff 100644 --- a/source/dnode/mgmt/test/CMakeLists.txt +++ b/source/dnode/mgmt/test/CMakeLists.txt @@ -1,8 +1,9 @@ -enable_testing() - -add_subdirectory(qnode) -add_subdirectory(bnode) -add_subdirectory(snode) -add_subdirectory(mnode) -add_subdirectory(vnode) -add_subdirectory(sut) +if(${BUILD_TEST}) + enable_testing() + add_subdirectory(qnode) + add_subdirectory(bnode) + add_subdirectory(snode) + add_subdirectory(mnode) + add_subdirectory(vnode) + add_subdirectory(sut) +endif(${BUILD_TEST}) diff --git a/source/dnode/mgmt/test/bnode/CMakeLists.txt b/source/dnode/mgmt/test/bnode/CMakeLists.txt index 0c0006488d22a5d3ce88adbdfd840e824d99bde7..7108d3adb913abca3abe3aa614b1a6d4784b9120 100644 --- a/source/dnode/mgmt/test/bnode/CMakeLists.txt +++ b/source/dnode/mgmt/test/bnode/CMakeLists.txt @@ -1,8 +1,7 @@ -aux_source_directory(. BQTEST_SRC) -add_executable(dbnodeTest ${BQTEST_SRC}) +aux_source_directory(. DND_BNODE_TEST_SRC) +add_executable(dbnodeTest ${DND_BNODE_TEST_SRC}) target_link_libraries( - dbnodeTest - PUBLIC sut + dbnodeTest sut ) add_test( diff --git a/source/dnode/mgmt/test/mnode/CMakeLists.txt b/source/dnode/mgmt/test/mnode/CMakeLists.txt index 323748724285ae0e57b9783789aa2cb08837e0c7..e83f5dbbec9e84feac3738838e8c96e6dd3f3a3b 100644 --- a/source/dnode/mgmt/test/mnode/CMakeLists.txt +++ b/source/dnode/mgmt/test/mnode/CMakeLists.txt @@ -1,8 +1,7 @@ -aux_source_directory(. DMTEST_SRC) -add_executable(dmnodeTest ${DMTEST_SRC}) +aux_source_directory(. DND_MNODE_TEST_SRC) +add_executable(dmnodeTest ${DND_MNODE_TEST_SRC}) target_link_libraries( - dmnodeTest - PUBLIC sut + dmnodeTest sut ) add_test( diff --git a/source/dnode/mgmt/test/mnode/dmnode.cpp b/source/dnode/mgmt/test/mnode/dmnode.cpp index 348eb50c8fb4f4718029e267c20487628064306c..e92e51fa39c33bd8808e0f70c2dd5a32bc01ed83 100644 --- a/source/dnode/mgmt/test/mnode/dmnode.cpp +++ b/source/dnode/mgmt/test/mnode/dmnode.cpp @@ -188,7 +188,7 @@ TEST_F(DndTestMnode, 03_Drop_Mnode) { SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_MNODE, pReq, contLen); ASSERT_NE(pRsp, nullptr); - ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_REDIRECT); + ASSERT_EQ(pRsp->code, TSDB_CODE_NODE_NOT_DEPLOYED); } { diff --git a/source/dnode/mgmt/test/qnode/CMakeLists.txt b/source/dnode/mgmt/test/qnode/CMakeLists.txt index d118a8723a7926dd0d9088e45c5fed17494d988e..20cb53fc45c28b5feb26f35c8d698fb50bdd2e01 100644 --- a/source/dnode/mgmt/test/qnode/CMakeLists.txt +++ b/source/dnode/mgmt/test/qnode/CMakeLists.txt @@ -1,5 +1,5 @@ -aux_source_directory(. DQTEST_SRC) -add_executable(dqnodeTest ${DQTEST_SRC}) +aux_source_directory(. DND_QNODE_TEST_SRC) +add_executable(dqnodeTest ${DND_QNODE_TEST_SRC}) target_link_libraries( dqnodeTest PUBLIC sut diff --git a/source/dnode/mgmt/test/snode/CMakeLists.txt b/source/dnode/mgmt/test/snode/CMakeLists.txt index eaabc5647bb048e5a716f9dc91faf772e6351ca0..70f305438128a80e7e07073036a5abc0e37d7ae2 100644 --- a/source/dnode/mgmt/test/snode/CMakeLists.txt +++ b/source/dnode/mgmt/test/snode/CMakeLists.txt @@ -1,5 +1,5 @@ -aux_source_directory(. SQTEST_SRC) -add_executable(dsnodeTest ${SQTEST_SRC}) +aux_source_directory(. DND_SNODE_TEST_SRC) +add_executable(dsnodeTest ${DND_SNODE_TEST_SRC}) target_link_libraries( dsnodeTest PUBLIC sut diff --git a/source/dnode/mgmt/test/sut/CMakeLists.txt b/source/dnode/mgmt/test/sut/CMakeLists.txt index 3a993986fe6e7ae08b4c9c9bf308a1828a500df7..c2e1d7e7cd478deb6c793b2b18c6abb1b931db85 100644 --- a/source/dnode/mgmt/test/sut/CMakeLists.txt +++ b/source/dnode/mgmt/test/sut/CMakeLists.txt @@ -1,14 +1,10 @@ -aux_source_directory(src SUT_SRC) -add_library(sut STATIC STATIC ${SUT_SRC}) -target_link_libraries( - sut - PUBLIC dnode - PUBLIC util - PUBLIC os - PUBLIC gtest_main -) - +aux_source_directory(src DND_SUT_SRC) +add_library(sut STATIC STATIC ${DND_SUT_SRC}) target_include_directories( sut PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) + +target_link_libraries( + sut dnode gtest_main +) diff --git a/source/dnode/mgmt/test/sut/inc/sut.h b/source/dnode/mgmt/test/sut/inc/sut.h index 1dd68574fec694231fb2d903e41ca35873a67518..268f779fcf81900d990b4327efbdc9be1f482442 100644 --- a/source/dnode/mgmt/test/sut/inc/sut.h +++ b/source/dnode/mgmt/test/sut/inc/sut.h @@ -20,7 +20,6 @@ #include "os.h" #include "dnode.h" -#include "tmsg.h" #include "tdataformat.h" #include "tglobal.h" #include "tmsg.h" @@ -48,92 +47,61 @@ class Testbase { int32_t connId; public: - void SendShowMetaReq(int8_t showType, const char* db); - void SendShowRetrieveReq(); - - STableMetaRsp* GetShowMeta(); - SRetrieveTableRsp* GetRetrieveRsp(); + int32_t SendShowReq(int8_t showType, const char *tb, const char* db); + int32_t GetShowRows(); +#if 0 int32_t GetMetaNum(); const char* GetMetaTbName(); - int32_t GetMetaColId(int32_t index); - int8_t GetMetaType(int32_t index); - int32_t GetMetaBytes(int32_t index); - const char* GetMetaName(int32_t index); - - const char* GetShowName(); - int32_t GetShowRows(); - int8_t GetShowInt8(); - int16_t GetShowInt16(); - int32_t GetShowInt32(); - int64_t GetShowInt64(); - int64_t GetShowTimestamp(); - const char* GetShowBinary(int32_t len); + int8_t GetMetaType(int32_t col); + int32_t GetMetaBytes(int32_t col); + const char* GetMetaName(int32_t col); + + int8_t GetShowInt8(int32_t row, int32_t col); + int16_t GetShowInt16(int32_t row, int32_t col); + int32_t GetShowInt32(int32_t row, int32_t col); + int64_t GetShowInt64(int32_t row, int32_t col); + int64_t GetShowTimestamp(int32_t row, int32_t col); + const char* GetShowBinary(int32_t row, int32_t col); +#endif private: - int64_t showId; - STableMetaRsp metaRsp; - SRetrieveTableRsp* pRetrieveRsp; - char* pData; - int32_t pos; + SRetrieveMetaTableRsp* showRsp; }; +#if 0 + #define CHECK_META(tbName, numOfColumns) \ { \ EXPECT_EQ(test.GetMetaNum(), numOfColumns); \ EXPECT_STREQ(test.GetMetaTbName(), tbName); \ } -#define CHECK_SCHEMA(colId, type, bytes, colName) \ - { \ - EXPECT_EQ(test.GetMetaType(colId), type); \ - EXPECT_EQ(test.GetMetaBytes(colId), bytes); \ - EXPECT_STREQ(test.GetMetaName(colId), colName); \ - } - -#define CheckBinary(val, len) \ - { EXPECT_STREQ(test.GetShowBinary(len), val); } - -#define CheckBinaryByte(b, len) \ +#define CHECK_SCHEMA(col, type, bytes, colName) \ { \ - char* bytes = (char*)taosMemoryCalloc(1, len); \ - for (int32_t i = 0; i < len - 1; ++i) { \ - bytes[i] = b; \ - } \ - EXPECT_STREQ(test.GetShowBinary(len), bytes); \ + EXPECT_EQ(test.GetMetaType(col), type); \ + EXPECT_EQ(test.GetMetaBytes(col), bytes); \ + EXPECT_STREQ(test.GetMetaName(col), colName); \ } +#define CheckBinary(row, col, val) \ + { EXPECT_STREQ(test.GetShowBinary(row, col), val); } + #define CheckInt8(val) \ - { EXPECT_EQ(test.GetShowInt8(), val); } + { EXPECT_EQ(test.GetShowInt8(row, col), val); } #define CheckInt16(val) \ - { EXPECT_EQ(test.GetShowInt16(), val); } + { EXPECT_EQ(test.GetShowInt16(row, col), val); } #define CheckInt32(val) \ - { EXPECT_EQ(test.GetShowInt32(), val); } + { EXPECT_EQ(test.GetShowInt32row, col(), val); } #define CheckInt64(val) \ - { EXPECT_EQ(test.GetShowInt64(), val); } + { EXPECT_EQ(test.GetShowInt64(row, col), val); } #define CheckTimestamp() \ - { EXPECT_GT(test.GetShowTimestamp(), 0); } - -#define IgnoreBinary(len) \ - { test.GetShowBinary(len); } - -#define IgnoreInt8() \ - { test.GetShowInt8(); } - -#define IgnoreInt16() \ - { test.GetShowInt16(); } - -#define IgnoreInt32() \ - { test.GetShowInt32(); } - -#define IgnoreInt64() \ - { test.GetShowInt64(); } + { EXPECT_GT(test.GetShowTimestamp(row, col), 0); } -#define IgnoreTimestamp() \ - { test.GetShowTimestamp(); } +#endif #endif /* _TD_TEST_BASE_H_ */ diff --git a/source/dnode/mgmt/test/sut/src/server.cpp b/source/dnode/mgmt/test/sut/src/server.cpp index c5379c6d174dce3f4dce5f1cba834e93a5549207..91db59757bf4508d633fd76fb86471707682ec00 100644 --- a/source/dnode/mgmt/test/sut/src/server.cpp +++ b/source/dnode/mgmt/test/sut/src/server.cpp @@ -17,7 +17,7 @@ void* serverLoop(void* param) { SDnode* pDnode = (SDnode*)param; - dndRun(pDnode); + dmRun(pDnode); return NULL; } @@ -36,7 +36,7 @@ bool TestServer::DoStart() { SDnodeOpt option = BuildOption(path, fqdn, port, firstEp); taosMkDir(path); - pDnode = dndCreate(&option); + pDnode = dmCreate(&option); if (pDnode == NULL) { return false; } @@ -68,11 +68,11 @@ bool TestServer::Start(const char* path, const char* fqdn, uint16_t port, const } void TestServer::Stop() { - dndHandleEvent(pDnode, DND_EVENT_STOP); + dmSetEvent(pDnode, DND_EVENT_STOP); taosThreadJoin(threadId, NULL); if (pDnode != NULL) { - dndClose(pDnode); + dmClose(pDnode); pDnode = NULL; } } diff --git a/source/dnode/mgmt/test/sut/src/sut.cpp b/source/dnode/mgmt/test/sut/src/sut.cpp index 14197153b49bb2552d29409801d35ce40d8090c6..9b4c4798653858ad22beb7ed637da3b6352674f4 100644 --- a/source/dnode/mgmt/test/sut/src/sut.cpp +++ b/source/dnode/mgmt/test/sut/src/sut.cpp @@ -40,7 +40,7 @@ void Testbase::InitLog(const char* path) { } void Testbase::Init(const char* path, int16_t port) { - dndInit(); + dmInit(); char fqdn[] = "localhost"; char firstEp[TSDB_EP_LEN] = {0}; @@ -49,20 +49,18 @@ void Testbase::Init(const char* path, int16_t port) { InitLog("/tmp/td"); server.Start(path, fqdn, port, firstEp); client.Init("root", "taosdata", fqdn, port); - - tFreeSTableMetaRsp(&metaRsp); - showId = 0; - pData = 0; - pos = 0; - pRetrieveRsp = NULL; + showRsp = NULL; } void Testbase::Cleanup() { - tFreeSTableMetaRsp(&metaRsp); + if (showRsp != NULL) { + rpcFreeCont(showRsp); + showRsp = NULL; + } client.Cleanup(); taosMsleep(10); server.Stop(); - dndCleanup(); + dmCleanup(); } void Testbase::Restart() { @@ -84,112 +82,40 @@ SRpcMsg* Testbase::SendReq(tmsg_t msgType, void* pCont, int32_t contLen) { return client.SendReq(&rpcMsg); } -void Testbase::SendShowMetaReq(int8_t showType, const char* db) { - SShowReq showReq = {0}; - showReq.type = showType; - strcpy(showReq.db, db); - - int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq); - void* pReq = rpcMallocCont(contLen); - tSerializeSShowReq(pReq, contLen, &showReq); - tFreeSShowReq(&showReq); - - SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW, pReq, contLen); - ASSERT(pRsp->pCont != nullptr); - - if (pRsp->contLen == 0) return; - - SShowRsp showRsp = {0}; - tDeserializeSShowRsp(pRsp->pCont, pRsp->contLen, &showRsp); - tFreeSTableMetaRsp(&metaRsp); - metaRsp = showRsp.tableMeta; - showId = showRsp.showId; -} - -int32_t Testbase::GetMetaColId(int32_t index) { - SSchema* pSchema = &metaRsp.pSchemas[index]; - return pSchema->colId; -} - -int8_t Testbase::GetMetaType(int32_t index) { - SSchema* pSchema = &metaRsp.pSchemas[index]; - return pSchema->type; -} - -int32_t Testbase::GetMetaBytes(int32_t index) { - SSchema* pSchema = &metaRsp.pSchemas[index]; - return pSchema->bytes; -} - -const char* Testbase::GetMetaName(int32_t index) { - SSchema* pSchema = &metaRsp.pSchemas[index]; - return pSchema->name; -} - -int32_t Testbase::GetMetaNum() { return metaRsp.numOfColumns; } - -const char* Testbase::GetMetaTbName() { return metaRsp.tbName; } +int32_t Testbase::SendShowReq(int8_t showType, const char *tb, const char* db) { + if (showRsp != NULL) { + rpcFreeCont(showRsp); + showRsp = NULL; + } -void Testbase::SendShowRetrieveReq() { SRetrieveTableReq retrieveReq = {0}; - retrieveReq.showId = showId; - retrieveReq.free = 0; + retrieveReq.type = showType; + strcpy(retrieveReq.db, db); + strcpy(retrieveReq.tb, tb); int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &retrieveReq); void* pReq = rpcMallocCont(contLen); tSerializeSRetrieveTableReq(pReq, contLen, &retrieveReq); - SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW_RETRIEVE, pReq, contLen); - pRetrieveRsp = (SRetrieveTableRsp*)pRsp->pCont; - pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); - pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); - pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen); - - pData = pRetrieveRsp->data; - pos = 0; -} - -const char* Testbase::GetShowName() { return metaRsp.tbName; } - -int8_t Testbase::GetShowInt8() { - int8_t data = *((int8_t*)(pData + pos)); - pos += sizeof(int8_t); - return data; -} - -int16_t Testbase::GetShowInt16() { - int16_t data = *((int16_t*)(pData + pos)); - pos += sizeof(int16_t); - return data; -} + SRpcMsg* pRsp = SendReq(TDMT_MND_SYSTABLE_RETRIEVE, pReq, contLen); + ASSERT(pRsp->pCont != nullptr); -int32_t Testbase::GetShowInt32() { - int32_t data = *((int32_t*)(pData + pos)); - pos += sizeof(int32_t); - return data; -} + if (pRsp->contLen == 0) return -1; -int64_t Testbase::GetShowInt64() { - int64_t data = *((int64_t*)(pData + pos)); - pos += sizeof(int64_t); - return data; -} + showRsp = (SRetrieveMetaTableRsp*)pRsp->pCont; + showRsp->handle = htobe64(showRsp->handle); // show Id + showRsp->useconds = htobe64(showRsp->useconds); + showRsp->numOfRows = htonl(showRsp->numOfRows); + showRsp->compLen = htonl(showRsp->compLen); + if (showRsp->numOfRows <= 0) return -1; -int64_t Testbase::GetShowTimestamp() { - int64_t data = *((int64_t*)(pData + pos)); - pos += sizeof(int64_t); - return data; + return 0; } -const char* Testbase::GetShowBinary(int32_t len) { - pos += sizeof(VarDataLenT); - char* data = (char*)(pData + pos); - pos += len; - return data; +int32_t Testbase::GetShowRows() { + if (showRsp != NULL) { + return showRsp->numOfRows; + } else { + return 0; + } } - -int32_t Testbase::GetShowRows() { return pRetrieveRsp->numOfRows; } - -STableMetaRsp* Testbase::GetShowMeta() { return &metaRsp; } - -SRetrieveTableRsp* Testbase::GetRetrieveRsp() { return pRetrieveRsp; } diff --git a/source/dnode/mgmt/test/vnode/CMakeLists.txt b/source/dnode/mgmt/test/vnode/CMakeLists.txt index e2cd868513c9e0dd0fe265e61f62ba9da45ab2c6..34402286aa6f0426dce70e17fd30625c357a17cc 100644 --- a/source/dnode/mgmt/test/vnode/CMakeLists.txt +++ b/source/dnode/mgmt/test/vnode/CMakeLists.txt @@ -1,5 +1,5 @@ -aux_source_directory(. VNODE_SRC) -add_executable(dvnodeTest ${VNODE_SRC}) +aux_source_directory(. DND_VNODE_TEST_SRC) +add_executable(dvnodeTest ${DND_VNODE_TEST_SRC}) target_link_libraries( dvnodeTest PUBLIC sut diff --git a/source/dnode/mnode/impl/CMakeLists.txt b/source/dnode/mnode/impl/CMakeLists.txt index 341dbf6135ed82caec7230268d124b0dc12020c7..8cb5e2a528fa52430d07d47f691a1c5a493a55ac 100644 --- a/source/dnode/mnode/impl/CMakeLists.txt +++ b/source/dnode/mnode/impl/CMakeLists.txt @@ -9,6 +9,13 @@ target_link_libraries( mnode scheduler sdb wal transport cjson sync monitor executor qworker stream parser ) +IF (TD_GRANT) + TARGET_LINK_LIBRARIES(mnode grant) +ENDIF () +IF (TD_USB_DONGLE) + TARGET_LINK_LIBRARIES(mnode usb_dongle) +ENDIF () + if(${BUILD_TEST}) add_subdirectory(test) endif(${BUILD_TEST}) diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 38dbdc4799ebd9268ef37268db56c52b3ad763ff..5b96416fd719ea5b50ddc275f5165a50c4d4f535 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -213,7 +213,7 @@ typedef struct { int32_t maxConsumers; int32_t maxConns; int32_t maxTopics; - int64_t maxStorage; // In unit of GB + int64_t maxStorage; int32_t accessState; // Configured only by command } SAcctCfg; @@ -379,20 +379,20 @@ typedef struct { } SFuncObj; typedef struct { - int64_t id; - int8_t type; - int8_t replica; - int16_t numOfColumns; - int32_t rowSize; - int32_t numOfRows; - int32_t numOfReads; - int32_t payloadLen; - void* pIter; - SMnode* pMnode; - char db[TSDB_DB_FNAME_LEN]; - int16_t offset[TSDB_MAX_COLUMNS]; - int32_t bytes[TSDB_MAX_COLUMNS]; - char payload[]; + int64_t id; + int8_t type; + int8_t replica; + int16_t numOfColumns; + int32_t rowSize; + int32_t numOfRows; + int32_t payloadLen; + void* pIter; + SMnode* pMnode; + STableMetaRsp* pMeta; + bool sysDbRsp; + char db[TSDB_DB_FNAME_LEN]; + int16_t offset[TSDB_MAX_COLUMNS]; + int32_t bytes[TSDB_MAX_COLUMNS]; } SShowObj; typedef struct { @@ -625,14 +625,14 @@ static FORCE_INLINE void* tDecodeSubscribeObj(void* buf, SMqSubscribeObj* pSub) static FORCE_INLINE void tDeleteSMqSubscribeObj(SMqSubscribeObj* pSub) { if (pSub->consumers) { - //taosArrayDestroyEx(pSub->consumers, (void (*)(void*))tDeleteSMqSubConsumer); - // taosArrayDestroy(pSub->consumers); + // taosArrayDestroyEx(pSub->consumers, (void (*)(void*))tDeleteSMqSubConsumer); + // taosArrayDestroy(pSub->consumers); pSub->consumers = NULL; } if (pSub->unassignedVg) { - //taosArrayDestroyEx(pSub->unassignedVg, (void (*)(void*))tDeleteSMqConsumerEp); - // taosArrayDestroy(pSub->unassignedVg); + // taosArrayDestroyEx(pSub->unassignedVg, (void (*)(void*))tDeleteSMqConsumerEp); + // taosArrayDestroy(pSub->unassignedVg); pSub->unassignedVg = NULL; } } @@ -647,8 +647,9 @@ typedef struct { int32_t version; SRWLatch lock; int32_t sqlLen; + int32_t astLen; char* sql; - char* logicalPlan; + char* ast; char* physicalPlan; SSchemaWrapper schema; } SMqTopicObj; diff --git a/include/common/tgrant.h b/source/dnode/mnode/impl/inc/mndGrant.h similarity index 92% rename from include/common/tgrant.h rename to source/dnode/mnode/impl/inc/mndGrant.h index 962af0ddc4b431313871e8d46f3c58c609da2479..ad3dc7f79d2d9925e223880bde05560f1587fb11 100644 --- a/include/common/tgrant.h +++ b/source/dnode/mnode/impl/inc/mndGrant.h @@ -36,8 +36,8 @@ typedef enum { TSDB_GRANT_CPU_CORES, } EGrantType; -int32_t grantInit(); -void grantCleanUp(); +int32_t mndInitGrant(); +void mndCleanupGrant(); void grantParseParameter(); int32_t grantCheck(EGrantType grant); void grantReset(EGrantType grant, uint64_t value); diff --git a/source/dnode/mnode/impl/inc/mndInfoSchema.h b/source/dnode/mnode/impl/inc/mndInfoSchema.h index 7db41254027c3c2924e094ae806bbcc8907f0981..3aea99a909e02796dfbd9862c56339f9f1ba27c4 100644 --- a/source/dnode/mnode/impl/inc/mndInfoSchema.h +++ b/source/dnode/mnode/impl/inc/mndInfoSchema.h @@ -23,20 +23,20 @@ extern "C" { #endif typedef struct SInfosTableSchema { - char *name; - int32_t type; - int32_t bytes; + const char *name; + const int32_t type; + const int32_t bytes; } SInfosTableSchema; typedef struct SInfosTableMeta { - char *name; + const char *name; const SInfosTableSchema *schema; - int32_t colNum; + const int32_t colNum; } SInfosTableMeta; -int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp); int32_t mndInitInfos(SMnode *pMnode); -void mndCleanupInfos(SMnode *pMnode); +void mndCleanupInfos(SMnode *pMnode); +int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index fa1502fe104da2993a08eaadda6d8ca2cc33b229..11c1b09cc9c10c23d0279fcf35dfac92790f01ad 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -41,8 +41,7 @@ extern "C" { typedef int32_t (*MndMsgFp)(SNodeMsg *pMsg); typedef int32_t (*MndInitFp)(SMnode *pMnode); typedef void (*MndCleanupFp)(SMnode *pMnode); -typedef int32_t (*ShowMetaFp)(SNodeMsg *pMsg, SShowObj *pShow, STableMetaRsp *pMeta); -typedef int32_t (*ShowRetrieveFp)(SNodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +typedef int32_t (*ShowRetrieveFp)(SNodeMsg *pMsg, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); typedef void (*ShowFreeIterFp)(SMnode *pMnode, void *pIter); typedef struct SMnodeLoad { @@ -98,7 +97,7 @@ typedef struct { int64_t timeseriesAllowed; } SGrantInfo; -typedef struct SMnode { +struct SMnode { int32_t selfId; int64_t clusterId; int8_t replica; @@ -122,7 +121,7 @@ typedef struct SMnode { SGrantInfo grant; MndMsgFp msgFp[TDMT_MAX]; SMsgCb msgCb; -} SMnode; +}; void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp); int64_t mndGenerateUid(char *name, int32_t len); diff --git a/source/dnode/mnode/impl/inc/mndShow.h b/source/dnode/mnode/impl/inc/mndShow.h index a269fa35c1ded912ce3be8d463df23132184fb5c..03f901e9c412e1ddf466cf336190d4fe7a590b0c 100644 --- a/source/dnode/mnode/impl/inc/mndShow.h +++ b/source/dnode/mnode/impl/inc/mndShow.h @@ -26,8 +26,6 @@ int32_t mndInitShow(SMnode *pMnode); void mndCleanupShow(SMnode *pMnode); void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp); void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType msgType, ShowFreeIterFp fp); -void mndVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_t capacity, SShowObj *pShow); -char *mndShowStr(int32_t showType); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index 68c8c6d12744b79433b5f00a3bfe3f97dab0495b..25bf20fa0d5d53e1352fb838d620d916392f814f 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -17,7 +17,7 @@ #include "mndAcct.h" #include "mndShow.h" -#define TSDB_ACCT_VER_NUMBER 1 +#define TSDB_ACCT_VER_NUMBER 1 #define TSDB_ACCT_RESERVE_SIZE 128 static int32_t mndCreateDefaultAcct(SMnode *pMnode); @@ -80,32 +80,32 @@ static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) { terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, TSDB_ACCT_VER_NUMBER, sizeof(SAcctObj) + TSDB_ACCT_RESERVE_SIZE); - if (pRaw == NULL) goto ACCT_ENCODE_OVER; + if (pRaw == NULL) goto _OVER; int32_t dataPos = 0; - SDB_SET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN, ACCT_ENCODE_OVER) - SDB_SET_INT64(pRaw, dataPos, pAcct->createdTime, ACCT_ENCODE_OVER) - SDB_SET_INT64(pRaw, dataPos, pAcct->updateTime, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->acctId, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->status, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxUsers, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxDbs, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStbs, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTbs, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTimeSeries, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStreams, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxFuncs, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxConsumers, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxConns, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTopics, ACCT_ENCODE_OVER) - SDB_SET_INT64(pRaw, dataPos, pAcct->cfg.maxStorage, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.accessState, ACCT_ENCODE_OVER) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, ACCT_ENCODE_OVER) - SDB_SET_DATALEN(pRaw, dataPos, ACCT_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN, _OVER) + SDB_SET_INT64(pRaw, dataPos, pAcct->createdTime, _OVER) + SDB_SET_INT64(pRaw, dataPos, pAcct->updateTime, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->acctId, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->status, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxUsers, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxDbs, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStbs, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTbs, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTimeSeries, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStreams, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxFuncs, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxConsumers, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxConns, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTopics, _OVER) + SDB_SET_INT64(pRaw, dataPos, pAcct->cfg.maxStorage, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.accessState, _OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, _OVER) + SDB_SET_DATALEN(pRaw, dataPos, _OVER) terrno = 0; -ACCT_ENCODE_OVER: +_OVER: if (terrno != 0) { mError("acct:%s, failed to encode to raw:%p since %s", pAcct->acct, pRaw, terrstr()); sdbFreeRaw(pRaw); @@ -120,42 +120,42 @@ static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) { terrno = TSDB_CODE_OUT_OF_MEMORY; int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto ACCT_DECODE_OVER; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER; if (sver != TSDB_ACCT_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - goto ACCT_DECODE_OVER; + goto _OVER; } SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj)); - if (pRow == NULL) goto ACCT_DECODE_OVER; + if (pRow == NULL) goto _OVER; SAcctObj *pAcct = sdbGetRowObj(pRow); - if (pAcct == NULL) goto ACCT_DECODE_OVER; + if (pAcct == NULL) goto _OVER; int32_t dataPos = 0; - SDB_GET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN, ACCT_DECODE_OVER) - SDB_GET_INT64(pRaw, dataPos, &pAcct->createdTime, ACCT_DECODE_OVER) - SDB_GET_INT64(pRaw, dataPos, &pAcct->updateTime, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->acctId, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->status, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxUsers, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxDbs, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStbs, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTbs, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTimeSeries, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStreams, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxFuncs, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxConsumers, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxConns, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTopics, ACCT_DECODE_OVER) - SDB_GET_INT64(pRaw, dataPos, &pAcct->cfg.maxStorage, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.accessState, ACCT_DECODE_OVER) - SDB_GET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, ACCT_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN, _OVER) + SDB_GET_INT64(pRaw, dataPos, &pAcct->createdTime, _OVER) + SDB_GET_INT64(pRaw, dataPos, &pAcct->updateTime, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->acctId, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->status, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxUsers, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxDbs, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStbs, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTbs, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTimeSeries, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStreams, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxFuncs, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxConsumers, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxConns, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTopics, _OVER) + SDB_GET_INT64(pRaw, dataPos, &pAcct->cfg.maxStorage, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.accessState, _OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, _OVER) terrno = 0; -ACCT_DECODE_OVER: +_OVER: if (terrno != 0) { mError("acct:%s, failed to decode from raw:%p since %s", pAcct->acct, pRaw, terrstr()); taosMemoryFreeClear(pRow); diff --git a/source/dnode/mnode/impl/src/mndAuth.c b/source/dnode/mnode/impl/src/mndAuth.c index 20dd7f1378ff857dd21c63cb6472668ce4ff2556..fc94ec364590872d87577211e8e8f8780673f643 100644 --- a/source/dnode/mnode/impl/src/mndAuth.c +++ b/source/dnode/mnode/impl/src/mndAuth.c @@ -26,22 +26,22 @@ int32_t mndInitAuth(SMnode *pMnode) { void mndCleanupAuth(SMnode *pMnode) {} -int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) { - SUserObj *pUser = mndAcquireUser(pMnode, user); +static int32_t mndRetriveAuth(SMnode *pMnode, SAuthRsp *pRsp) { + SUserObj *pUser = mndAcquireUser(pMnode, pRsp->user); if (pUser == NULL) { - *secret = 0; - mError("user:%s, failed to auth user since %s", user, terrstr()); + *pRsp->secret = 0; + mError("user:%s, failed to auth user since %s", pRsp->user, terrstr()); return -1; } - *spi = 1; - *encrypt = 0; - *ckey = 0; + pRsp->spi = 1; + pRsp->encrypt = 0; + *pRsp->ckey = 0; - memcpy(secret, pUser->pass, TSDB_PASSWORD_LEN); + memcpy(pRsp->secret, pUser->pass, TSDB_PASSWORD_LEN); mndReleaseUser(pMnode, pUser); - mDebug("user:%s, auth info is returned", user); + mDebug("user:%s, auth info is returned", pRsp->user); return 0; } @@ -55,14 +55,19 @@ static int32_t mndProcessAuthReq(SNodeMsg *pReq) { SAuthReq authRsp = {0}; memcpy(authRsp.user, authReq.user, TSDB_USER_LEN); - int32_t code = - mndRetriveAuth(pReq->pNode, authRsp.user, &authRsp.spi, &authRsp.encrypt, authRsp.secret, authRsp.ckey); + int32_t code = mndRetriveAuth(pReq->pNode, &authRsp); mTrace("user:%s, auth req received, spi:%d encrypt:%d ruser:%s", pReq->user, authRsp.spi, authRsp.encrypt, authRsp.user); int32_t contLen = tSerializeSAuthReq(NULL, 0, &authRsp); void *pRsp = rpcMallocCont(contLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + tSerializeSAuthReq(pRsp, contLen, &authRsp); + pReq->pRsp = pRsp; pReq->rspLen = contLen; return code; @@ -95,11 +100,11 @@ int32_t mndCheckAlterUserAuth(SUserObj *pOperUser, SUserObj *pUser, SDbObj *pDb, } } - if (pAlter->alterType == TSDB_ALTER_USER_CLEAR_WRITE_DB || pAlter->alterType == TSDB_ALTER_USER_CLEAR_READ_DB) { - if (pOperUser->superUser) { - return 0; - } + if (pAlter->alterType == TSDB_ALTER_USER_CLEAR_WRITE_DB || pAlter->alterType == TSDB_ALTER_USER_CLEAR_READ_DB) { + if (pOperUser->superUser) { + return 0; } + } if (pAlter->alterType == TSDB_ALTER_USER_ADD_READ_DB || pAlter->alterType == TSDB_ALTER_USER_REMOVE_READ_DB || pAlter->alterType == TSDB_ALTER_USER_ADD_WRITE_DB || pAlter->alterType == TSDB_ALTER_USER_REMOVE_WRITE_DB) { @@ -176,4 +181,4 @@ int32_t mndCheckReadAuth(SUserObj *pOperUser, SDbObj *pDb) { terrno = TSDB_CODE_MND_NO_RIGHTS; return -1; -} \ No newline at end of file +} diff --git a/source/dnode/mnode/impl/src/mndBnode.c b/source/dnode/mnode/impl/src/mndBnode.c index 86e29765164a03a9b2c58b453060bdcc8c2e4a7e..f7c4a6c2258425388ae4194a5846998476a7b39a 100644 --- a/source/dnode/mnode/impl/src/mndBnode.c +++ b/source/dnode/mnode/impl/src/mndBnode.c @@ -33,8 +33,7 @@ static int32_t mndProcessCreateBnodeReq(SNodeMsg *pReq); static int32_t mndProcessCreateBnodeRsp(SNodeMsg *pRsp); static int32_t mndProcessDropBnodeReq(SNodeMsg *pReq); static int32_t mndProcessDropBnodeRsp(SNodeMsg *pRsp); -static int32_t mndGetBnodeMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); -static int32_t mndRetrieveBnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndRetrieveBnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); static void mndCancelGetNextBnode(SMnode *pMnode, void *pIter); int32_t mndInitBnode(SMnode *pMnode) { @@ -438,39 +437,35 @@ static int32_t mndProcessDropBnodeRsp(SNodeMsg *pRsp) { return 0; } -static int32_t mndRetrieveBnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { +static int32_t mndRetrieveBnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; int32_t cols = 0; SBnodeObj *pObj = NULL; - char *pWrite; while (numOfRows < rows) { pShow->pIter = sdbFetch(pSdb, SDB_BNODE, pShow->pIter, (void **)&pObj); if (pShow->pIter == NULL) break; cols = 0; + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) &pObj->id, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int16_t *)pWrite = pObj->id; - cols++; + char buf[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(buf, pObj->pDnode->ep, pShow->bytes[cols]); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pObj->pDnode->ep, pShow->bytes[cols]); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, buf, false); - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pObj->createdTime; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) &pObj->createdTime, false); numOfRows++; sdbRelease(pSdb, pObj); } - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); - pShow->numOfReads += numOfRows; + pShow->numOfRows += numOfRows; return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index 5a811ea490c8c8820f50ece5a198f7d1f8802e13..57326b26ceb818fec893eabcadd10573c8182182 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -26,7 +26,7 @@ static int32_t mndClusterActionInsert(SSdb *pSdb, SClusterObj *pCluster); static int32_t mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster); static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOldCluster, SClusterObj *pNewCluster); static int32_t mndCreateDefaultCluster(SMnode *pMnode); -static int32_t mndRetrieveClusters(SNodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndRetrieveClusters(SNodeMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); static void mndCancelGetNextCluster(SMnode *pMnode, void *pIter); int32_t mndInitCluster(SMnode *pMnode) { @@ -178,12 +178,11 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) { return sdbWrite(pMnode->pSdb, pRaw); } -static int32_t mndRetrieveClusters(SNodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { +static int32_t mndRetrieveClusters(SNodeMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { SMnode *pMnode = pMsg->pNode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; int32_t cols = 0; - char *pWrite; SClusterObj *pCluster = NULL; while (numOfRows < rows) { @@ -191,25 +190,23 @@ static int32_t mndRetrieveClusters(SNodeMsg *pMsg, SShowObj *pShow, char *data, if (pShow->pIter == NULL) break; cols = 0; + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) &pCluster->id, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pCluster->id; - cols++; + char buf[tListLen(pCluster->name) + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(buf, pCluster->name, pShow->bytes[cols]); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pCluster->name, TSDB_CLUSTER_ID_LEN); - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, buf, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pCluster->createdTime; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) &pCluster->createdTime, false); sdbRelease(pSdb, pCluster); numOfRows++; } - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); - pShow->numOfReads += numOfRows; + pShow->numOfRows += numOfRows; return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index 1a865247b9ad3b1eb4c489d3619a12b3abe6aa4c..d2a3c381351f7e2718d2c83466240fb0e4301fbe 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -35,7 +35,7 @@ static int32_t mndConsumerActionInsert(SSdb *pSdb, SMqConsumerObj *pConsumer); static int32_t mndConsumerActionDelete(SSdb *pSdb, SMqConsumerObj *pConsumer); static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pConsumer, SMqConsumerObj *pNewConsumer); static int32_t mndProcessConsumerMetaMsg(SNodeMsg *pMsg); -static int32_t mndRetrieveConsumer(SNodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndRetrieveConsumer(SNodeMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); static void mndCancelGetNextConsumer(SMnode *pMnode, void *pIter); int32_t mndInitConsumer(SMnode *pMnode) { diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 49e9ccaba66c44140c7cd615d5641928a3f72069..3db4e9870e9288b925c3b8feb3591c11db8bb7c5 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -38,7 +38,7 @@ static int32_t mndProcessDropDbReq(SNodeMsg *pReq); static int32_t mndProcessUseDbReq(SNodeMsg *pReq); static int32_t mndProcessSyncDbReq(SNodeMsg *pReq); static int32_t mndProcessCompactDbReq(SNodeMsg *pReq); -static int32_t mndRetrieveDbs(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndRetrieveDbs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rowsCapacity); static void mndCancelGetNextDb(SMnode *pMnode, void *pIter); static int32_t mndProcessGetDbCfgReq(SNodeMsg *pReq); static int32_t mndProcessGetIndexReq(SNodeMsg *pReq); @@ -1351,90 +1351,76 @@ char *mnGetDbStr(char *src) { return pos; } -static char *getDataPosition(char *pData, SShowObj *pShow, int32_t cols, int32_t rows, int32_t capacityOfRow) { - return pData + pShow->offset[cols] * capacityOfRow + pShow->bytes[cols] * rows; -} - -static void dumpDbInfoToPayload(char *data, SDbObj *pDb, SShowObj *pShow, int32_t rows, int32_t rowCapacity, - int64_t numOfTables) { +static void dumpDbInfoData(SSDataBlock* pBlock, SDbObj *pDb, SShowObj *pShow, int32_t rows, int64_t numOfTables) { int32_t cols = 0; - char *pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); + char* buf = taosMemoryMalloc(pShow->bytes[cols]); char *name = mnGetDbStr(pDb->name); if (name != NULL) { - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(buf, name, pShow->bytes[cols]); } else { - STR_TO_VARSTR(pWrite, "NULL"); +// STR_TO_VARSTR(pWrite, "NULL"); + ASSERT(0); } - cols++; - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int64_t *)pWrite = pDb->createdTime; - cols++; + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, buf, false); + taosMemoryFree(buf); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int16_t *)pWrite = pDb->cfg.numOfVgroups; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->createdTime, false); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int64_t *)pWrite = numOfTables; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.numOfVgroups, false); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int16_t *)pWrite = pDb->cfg.replications; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&numOfTables, false); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int16_t *)pWrite = pDb->cfg.quorum; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.replications, false); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int32_t *)pWrite = pDb->cfg.daysPerFile; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.quorum, false); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.daysPerFile, false); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); char tmp[128] = {0}; + int32_t len = 0; if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) { - sprintf(tmp, "%d,%d,%d", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2, pDb->cfg.daysToKeep0); + len = sprintf(&tmp[VARSTR_HEADER_SIZE], "%d,%d,%d", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2, pDb->cfg.daysToKeep0); } else { - sprintf(tmp, "%d,%d,%d", pDb->cfg.daysToKeep0, pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2); + len = sprintf(&tmp[VARSTR_HEADER_SIZE], "%d,%d,%d", pDb->cfg.daysToKeep0, pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2); } - STR_WITH_SIZE_TO_VARSTR(pWrite, tmp, strlen(tmp)); - cols++; - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int32_t *)pWrite = pDb->cfg.cacheBlockSize; - cols++; + varDataSetLen(tmp, len); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)tmp, false); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.cacheBlockSize, false); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int32_t *)pWrite = pDb->cfg.totalBlocks; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.totalBlocks, false); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int32_t *)pWrite = pDb->cfg.minRows; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.minRows, false); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int32_t *)pWrite = pDb->cfg.maxRows; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.maxRows, false); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int8_t *)pWrite = pDb->cfg.walLevel; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.walLevel, false); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int32_t *)pWrite = pDb->cfg.fsyncPeriod; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.fsyncPeriod, false); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int8_t *)pWrite = pDb->cfg.compression; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.compression, false); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int8_t *)pWrite = pDb->cfg.cacheLastRow; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.cacheLastRow, false); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); char *prec = NULL; switch (pDb->cfg.precision) { case TSDB_TIME_PRECISION_MILLI: @@ -1450,28 +1436,31 @@ static void dumpDbInfoToPayload(char *data, SDbObj *pDb, SShowObj *pShow, int32_ prec = "none"; break; } - STR_WITH_SIZE_TO_VARSTR(pWrite, prec, 2); - cols++; - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int32_t *)pWrite = pDb->cfg.ttl; - cols++; + char t[10] = {0}; + STR_WITH_SIZE_TO_VARSTR(t, prec, 2); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)t, false); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int8_t *)pWrite = pDb->cfg.singleSTable; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.ttl, false); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); - *(int8_t *)pWrite = pDb->cfg.streamMode; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.singleSTable, false); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.streamMode, false); - pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); char *status = "ready"; - STR_WITH_SIZE_TO_VARSTR(pWrite, status, strlen(status)); - cols++; + char b[24] = {0}; + STR_WITH_SIZE_TO_VARSTR(b, status, strlen(status)); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, rows, (const char *)b, false); // pWrite = getDataPosition(data, pShow, cols, rows, rowCapacity); // *(int8_t *)pWrite = pDb->cfg.update; + } static void setInformationSchemaDbCfg(SDbObj *pDbObj) { @@ -1486,6 +1475,18 @@ static void setInformationSchemaDbCfg(SDbObj *pDbObj) { pDbObj->cfg.precision = TSDB_TIME_PRECISION_MILLI; } +static void setPerfSchemaDbCfg(SDbObj* pDbObj) { + ASSERT(pDbObj != NULL); + strncpy(pDbObj->name, TSDB_PERFORMANCE_SCHEMA_DB, tListLen(pDbObj->name)); + + pDbObj->createdTime = 0; + pDbObj->cfg.numOfVgroups = 0; + pDbObj->cfg.quorum = 1; + pDbObj->cfg.replications = 1; + pDbObj->cfg.update = 1; + pDbObj->cfg.precision = TSDB_TIME_PRECISION_MILLI; +} + static bool mndGetTablesOfDbFp(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3) { SVgObj *pVgroup = pObj; int32_t *numOfTables = p1; @@ -1494,12 +1495,28 @@ static bool mndGetTablesOfDbFp(SMnode *pMnode, void *pObj, void *p1, void *p2, v return true; } -static int32_t mndRetrieveDbs(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rowsCapacity) { +static int32_t mndRetrieveDbs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rowsCapacity) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; SDbObj *pDb = NULL; + // Append the information_schema database into the result. + if (!pShow->sysDbRsp) { + SDbObj infoschemaDb = {0}; + setInformationSchemaDbCfg(&infoschemaDb); + dumpDbInfoData(pBlock, &infoschemaDb, pShow, numOfRows, 14); + + numOfRows += 1; + + SDbObj perfschemaDb = {0}; + setPerfSchemaDbCfg(&perfschemaDb); + dumpDbInfoData(pBlock, &perfschemaDb, pShow, numOfRows, 3); + + numOfRows += 1; + pShow->sysDbRsp = true; + } + while (numOfRows < rowsCapacity) { pShow->pIter = sdbFetch(pSdb, SDB_DB, pShow->pIter, (void **)&pDb); if (pShow->pIter == NULL) { @@ -1509,21 +1526,12 @@ static int32_t mndRetrieveDbs(SNodeMsg *pReq, SShowObj *pShow, char *data, int32 int32_t numOfTables = 0; sdbTraverse(pSdb, SDB_VGROUP, mndGetTablesOfDbFp, &numOfTables, NULL, NULL); - dumpDbInfoToPayload(data, pDb, pShow, numOfRows, rowsCapacity, numOfTables); + dumpDbInfoData(pBlock, pDb, pShow, numOfRows, numOfTables); numOfRows++; sdbRelease(pSdb, pDb); } - // Append the information_schema database into the result. - if (numOfRows < rowsCapacity) { - SDbObj dummyISDb = {0}; - setInformationSchemaDbCfg(&dummyISDb); - dumpDbInfoToPayload(data, &dummyISDb, pShow, numOfRows, rowsCapacity, 14); - numOfRows += 1; - } - - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rowsCapacity, pShow); - pShow->numOfReads += numOfRows; + pShow->numOfRows += numOfRows; return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 86ec49127a5919ca45c291e97d5c91507e3568cd..5ce87a413c7ac3c2637c1fd3f60e9451d3212b45 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -24,9 +24,6 @@ #define TSDB_DNODE_VER_NUMBER 1 #define TSDB_DNODE_RESERVE_SIZE 64 -#define TSDB_CONFIG_OPTION_LEN 16 -#define TSDB_CONIIG_VALUE_LEN 48 -#define TSDB_CONFIG_NUMBER 8 static const char *offlineReason[] = { "", @@ -55,10 +52,9 @@ static int32_t mndProcessConfigDnodeReq(SNodeMsg *pReq); static int32_t mndProcessConfigDnodeRsp(SNodeMsg *pRsp); static int32_t mndProcessStatusReq(SNodeMsg *pReq); -static int32_t mndGetConfigMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); -static int32_t mndRetrieveConfigs(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndRetrieveConfigs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); static void mndCancelGetNextConfig(SMnode *pMnode, void *pIter); -static int32_t mndRetrieveDnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndRetrieveDnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); static void mndCancelGetNextDnode(SMnode *pMnode, void *pIter); int32_t mndInitDnode(SMnode *pMnode) { @@ -77,8 +73,8 @@ int32_t mndInitDnode(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_DND_CONFIG_DNODE_RSP, mndProcessConfigDnodeRsp); mndSetMsgHandle(pMnode, TDMT_MND_STATUS, mndProcessStatusReq); - mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_VARIABLES, mndRetrieveConfigs); - mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_VARIABLES, mndCancelGetNextConfig); + mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONFIGS, mndRetrieveConfigs); + mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CONFIGS, mndCancelGetNextConfig); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_DNODE, mndRetrieveDnodes); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_DNODE, mndCancelGetNextDnode); @@ -354,7 +350,7 @@ static int32_t mndProcessStatusReq(SNodeMsg *pReq) { int64_t curMs = taosGetTimestampMs(); bool online = mndIsDnodeOnline(pMnode, pDnode, curMs); - bool dnodeChanged = (statusReq.dver != sdbGetTableVer(pMnode->pSdb, SDB_DNODE)); + bool dnodeChanged = (statusReq.dnodeVer != sdbGetTableVer(pMnode->pSdb, SDB_DNODE)); bool reboot = (pDnode->rebootTime != statusReq.rebootTime); bool needCheck = !online || dnodeChanged || reboot; @@ -405,7 +401,7 @@ static int32_t mndProcessStatusReq(SNodeMsg *pReq) { pDnode->numOfSupportVnodes = statusReq.numOfSupportVnodes; SStatusRsp statusRsp = {0}; - statusRsp.dver = sdbGetTableVer(pMnode->pSdb, SDB_DNODE); + statusRsp.dnodeVer = sdbGetTableVer(pMnode->pSdb, SDB_DNODE); statusRsp.dnodeCfg.dnodeId = pDnode->id; statusRsp.dnodeCfg.clusterId = pMnode->clusterId; statusRsp.pDnodeEps = taosArrayInit(mndGetDnodeSize(pMnode), sizeof(SDnodeEp)); @@ -638,38 +634,7 @@ static int32_t mndProcessConfigDnodeRsp(SNodeMsg *pRsp) { return TSDB_CODE_SUCCESS; } -static int32_t mndGetConfigMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "name"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_CONIIG_VALUE_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "value"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = TSDB_CONFIG_NUMBER; - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - - return 0; -} - -static int32_t mndRetrieveConfigs(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { +static int32_t mndRetrieveConfigs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; int32_t totalRows = 0; int32_t numOfRows = 0; @@ -694,34 +659,36 @@ static int32_t mndRetrieveConfigs(SNodeMsg *pReq, SShowObj *pShow, char *data, i snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsCharset); totalRows++; + char buf[TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE] = {0}; + char bufVal[TSDB_CONIIG_VALUE_LEN + VARSTR_HEADER_SIZE] = {0}; + for (int32_t i = 0; i < totalRows; i++) { cols = 0; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, cfgOpts[i], TSDB_CONFIG_OPTION_LEN); - cols++; + STR_WITH_MAXSIZE_TO_VARSTR(buf, cfgOpts[i], TSDB_CONFIG_OPTION_LEN); + + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) buf, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, cfgVals[i], TSDB_CONIIG_VALUE_LEN); - cols++; + STR_WITH_MAXSIZE_TO_VARSTR(bufVal, cfgVals[i], TSDB_CONIIG_VALUE_LEN); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) bufVal, false); numOfRows++; } - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); - pShow->numOfReads += numOfRows; + pShow->numOfRows += numOfRows; return numOfRows; } static void mndCancelGetNextConfig(SMnode *pMnode, void *pIter) {} -static int32_t mndRetrieveDnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { +static int32_t mndRetrieveDnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; int32_t cols = 0; SDnodeObj *pDnode = NULL; - char *pWrite; int64_t curMs = taosGetTimestampMs(); while (numOfRows < rows) { @@ -731,40 +698,42 @@ static int32_t mndRetrieveDnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, in cols = 0; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int16_t *)pWrite = pDnode->id; - cols++; + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) &pDnode->id, false); + + char buf[tListLen(pDnode->ep) + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(buf, pDnode->ep, pShow->bytes[cols]); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, buf, false); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + int16_t id = mndGetVnodesNum(pMnode, pDnode->id); + colDataAppend(pColInfo, numOfRows, (const char*) &id, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDnode->ep, pShow->bytes[cols]); - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pDnode->numOfSupportVnodes, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int16_t *)pWrite = mndGetVnodesNum(pMnode, pDnode->id); - cols++; + char b1[9] = {0}; + STR_TO_VARSTR(b1, online? "ready":"offline"); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int16_t *)pWrite = pDnode->numOfSupportVnodes; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, b1, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_TO_VARSTR(pWrite, online ? "ready" : "offline"); - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) &pDnode->createdTime, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pDnode->createdTime; - cols++; + char b[tListLen(offlineReason) + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(b, online ? "" : offlineReason[pDnode->offlineReason]); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_TO_VARSTR(pWrite, online ? "" : offlineReason[pDnode->offlineReason]); - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, b, false); numOfRows++; sdbRelease(pSdb, pDnode); } - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); - pShow->numOfReads += numOfRows; + pShow->numOfRows += numOfRows; return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index 842e74197be8ade5ba2f52cd83bc48e3f3cf6e9a..a18afbea738420c204df67932785fd5eec72a139 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -34,8 +34,7 @@ static int32_t mndDropFunc(SMnode *pMnode, SNodeMsg *pReq, SFuncObj *pFunc); static int32_t mndProcessCreateFuncReq(SNodeMsg *pReq); static int32_t mndProcessDropFuncReq(SNodeMsg *pReq); static int32_t mndProcessRetrieveFuncReq(SNodeMsg *pReq); -static int32_t mndGetFuncMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); -static int32_t mndRetrieveFuncs(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndRetrieveFuncs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); static void mndCancelGetNextFunc(SMnode *pMnode, void *pIter); int32_t mndInitFunc(SMnode *pMnode) { @@ -462,70 +461,6 @@ RETRIEVE_FUNC_OVER: return code; } -static int32_t mndGetFuncMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - SMnode *pMnode = pReq->pNode; - SSdb *pSdb = pMnode->pSdb; - - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = TSDB_FUNC_NAME_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "name"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = PATH_MAX + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "comment"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "aggregate"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_TYPE_STR_MAX_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "outputtype"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "create_time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "code_len"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "bufsize"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = sdbGetSize(pSdb, SDB_FUNC); - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - - return 0; -} - static void *mnodeGenTypeStr(char *buf, int32_t buflen, uint8_t type, int16_t len) { char *msg = "unknown"; if (type >= sizeof(tDataTypes) / sizeof(tDataTypes[0])) { @@ -544,13 +479,12 @@ static void *mnodeGenTypeStr(char *buf, int32_t buflen, uint8_t type, int16_t le return tDataTypes[type].name; } -static int32_t mndRetrieveFuncs(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { +static int32_t mndRetrieveFuncs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; SFuncObj *pFunc = NULL; int32_t cols = 0; - char *pWrite; char buf[TSDB_TYPE_STR_MAX_LEN]; while (numOfRows < rows) { @@ -559,41 +493,43 @@ static int32_t mndRetrieveFuncs(SNodeMsg *pReq, SShowObj *pShow, char *data, int cols = 0; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pFunc->name, pShow->bytes[cols]); - cols++; + char b1[tListLen(pFunc->name) + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(b1, pFunc->name, pShow->bytes[cols]); + + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) b1, false); + + char* b2 = taosMemoryCalloc(1, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(b2, pFunc->pComment, pShow->bytes[cols]); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) b2, false); + + int32_t isAgg = (pFunc->funcType == TSDB_FUNC_TYPE_AGGREGATE) ? 1 : 0; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pFunc->pComment, pShow->bytes[cols]); - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) &isAgg, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int32_t *)pWrite = pFunc->funcType == TSDB_FUNC_TYPE_AGGREGATE ? 1 : 0; - cols++; + char b3[TSDB_TYPE_STR_MAX_LEN] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(b3, mnodeGenTypeStr(buf, TSDB_TYPE_STR_MAX_LEN, pFunc->outputType, pFunc->outputLen), pShow->bytes[cols]); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, mnodeGenTypeStr(buf, TSDB_TYPE_STR_MAX_LEN, pFunc->outputType, pFunc->outputLen), - pShow->bytes[cols]); - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) b3, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pFunc->createdTime; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) &pFunc->createdTime, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int32_t *)pWrite = pFunc->codeSize; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) &pFunc->codeSize, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int32_t *)pWrite = pFunc->bufSize; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) &pFunc->bufSize, false); numOfRows++; sdbRelease(pSdb, pFunc); } - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); - pShow->numOfReads += numOfRows; + pShow->numOfRows += numOfRows; return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndGrant.c b/source/dnode/mnode/impl/src/mndGrant.c new file mode 100644 index 0000000000000000000000000000000000000000..cab1e241e22da7e29c200bb27f1b9e5adc16fb52 --- /dev/null +++ b/source/dnode/mnode/impl/src/mndGrant.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "os.h" +#include "taoserror.h" +#include "mndGrant.h" +#include "mndInt.h" +#include "mndShow.h" + +#ifndef _GRANT +static int32_t mndRetrieveGrant(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { return TSDB_CODE_OPS_NOT_SUPPORT; } + +int32_t mndInitGrant(SMnode *pMnode) { + mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_GRANTS, mndRetrieveGrant); + return TSDB_CODE_SUCCESS; +} +void mndCleanupGrant() {} +void grantParseParameter() { mError("can't parsed parameter k"); } +int32_t grantCheck(EGrantType grant) { return TSDB_CODE_SUCCESS; } +void grantReset(EGrantType grant, uint64_t value) {} +void grantAdd(EGrantType grant, uint64_t value) {} +void grantRestore(EGrantType grant, uint64_t value) {} + +#endif + +void mndGenerateMachineCode() { grantParseParameter(); } diff --git a/source/dnode/mnode/impl/src/mndInfoSchema.c b/source/dnode/mnode/impl/src/mndInfoSchema.c index d60e7f5cf9022be4708e2ff93fa7bf78ac7aaef7..c21a6e61df03ac9aa6f8be87402c7f33c5b76561 100644 --- a/source/dnode/mnode/impl/src/mndInfoSchema.c +++ b/source/dnode/mnode/impl/src/mndInfoSchema.c @@ -18,59 +18,65 @@ #define SYSTABLE_SCH_TABLE_NAME_LEN ((TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE) #define SYSTABLE_SCH_DB_NAME_LEN ((TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE) -#define SYSTABLE_SCH_COL_NAME_LEN ((TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE) +#define SYSTABLE_SCH_COL_NAME_LEN ((TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE) -//!!!! Note: only APPEND columns in below tables, NO insert !!!! static const SInfosTableSchema dnodesSchema[] = { {.name = "id", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, - {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "vnodes", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, {.name = "max_vnodes", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, - {.name = "status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "note", .bytes = 256 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "note", .bytes = 256 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, }; + static const SInfosTableSchema mnodesSchema[] = { {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "role", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "role", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "role_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, }; + static const SInfosTableSchema modulesSchema[] = { {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "endpoint", .bytes = 134, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "module", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "endpoint", .bytes = 134, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "module", .bytes = 10, .type = TSDB_DATA_TYPE_VARCHAR}, }; + static const SInfosTableSchema qnodesSchema[] = { {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, }; + static const SInfosTableSchema snodesSchema[] = { {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, }; + static const SInfosTableSchema bnodesSchema[] = { {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, }; + static const SInfosTableSchema clusterSchema[] = { {.name = "id", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, - {.name = "name", .bytes = TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "name", .bytes = TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, }; + static const SInfosTableSchema userDBSchema[] = { - {.name = "name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, {.name = "vgroups", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, {.name = "ntables", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, - {.name = "replica", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, - {.name = "quorum", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT}, + {.name = "replica", .bytes = 2, .type = TSDB_DATA_TYPE_TINYINT}, + {.name = "quorum", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, {.name = "days", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "keep", .bytes = 24 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "keep", .bytes = 24 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "cache", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "blocks", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "minrows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, @@ -79,61 +85,66 @@ static const SInfosTableSchema userDBSchema[] = { {.name = "fsync", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "comp", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, {.name = "cachelast", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, - {.name = "precision", .bytes = 2 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "precision", .bytes = 2 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "ttl", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "single_stable", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, {.name = "stream_mode", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, - {.name = "status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - // {.name = "update", .bytes = 1, .type = - // TSDB_DATA_TYPE_TINYINT}, // disable update + {.name = "status", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + // {.name = "update", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, // disable update }; + static const SInfosTableSchema userFuncSchema[] = { - {.name = "name", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "name", .bytes = 32, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, {.name = "ntables", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "precision", .bytes = 2, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "status", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "precision", .bytes = 2, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "status", .bytes = 10, .type = TSDB_DATA_TYPE_VARCHAR}, }; + static const SInfosTableSchema userIdxSchema[] = { - {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "table_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "index_database", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "index_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "column_name", .bytes = SYSTABLE_SCH_COL_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "index_type", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "index_extensions", .bytes = 256, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "table_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "index_database", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "index_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "column_name", .bytes = SYSTABLE_SCH_COL_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "index_type", .bytes = 10, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "index_extensions", .bytes = 256, .type = TSDB_DATA_TYPE_VARCHAR}, }; + static const SInfosTableSchema userStbsSchema[] = { - {.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, {.name = "columns", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "tags", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "last_update", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "table_comment", .bytes = 1024 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_INT}, + {.name = "table_comment", .bytes = 1024 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, }; + static const SInfosTableSchema userStreamsSchema[] = { - {.name = "stream_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "user_name", .bytes = 23, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "dest_table", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "stream_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "user_name", .bytes = 23, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "dest_table", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "sql", .bytes = 1024, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "sql", .bytes = 1024, .type = TSDB_DATA_TYPE_VARCHAR}, }; + static const SInfosTableSchema userTblsSchema[] = { - {.name = "table_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "table_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, {.name = "columns", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "uid", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "ttl", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "table_comment", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, }; + static const SInfosTableSchema userTblDistSchema[] = { - {.name = "db_name", .bytes = 32, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "table_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "distributed_histogram", .bytes = 500, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "db_name", .bytes = 32, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "table_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "distributed_histogram", .bytes = 500, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "min_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "max_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "avg_of_rows", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, @@ -145,24 +156,43 @@ static const SInfosTableSchema userTblDistSchema[] = { {.name = "rows_in_mem", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "seek_header_time", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, }; + static const SInfosTableSchema userUsersSchema[] = { - {.name = "name", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "privilege", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "name", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "privilege", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "account", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "account", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SInfosTableSchema grantsSchema[] = { + {.name = "version", .bytes = 8 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "expire time", .bytes = 19 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "expired", .bytes = 5 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "storage(GB)", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "timeseries", .bytes = 21 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "databases", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "users", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "accounts", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "dnodes", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "connections", .bytes = 11 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "streams", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "cpu cores", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "speed(PPS)", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "querytime", .bytes = 9 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, }; + static const SInfosTableSchema vgroupsSchema[] = { {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "tables", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "status", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "status", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "onlines", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "v1_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "v1_status", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "v1_status", .bytes = 10, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "v2_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "v2_status", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "v2_status", .bytes = 10, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "v3_dnode", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "v3_status", .bytes = 10, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "v3_status", .bytes = 10, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "compacting", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "nfiles", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "file_size", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, @@ -170,16 +200,16 @@ static const SInfosTableSchema vgroupsSchema[] = { // TODO put into perf schema static const SInfosTableSchema topicSchema[] = { - {.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "sql", .bytes = 1024, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "sql", .bytes = 1024, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "row_len", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, }; static const SInfosTableSchema consumerSchema[] = { - {.name = "client_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "client_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "status", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, // ep @@ -188,10 +218,58 @@ static const SInfosTableSchema consumerSchema[] = { }; static const SInfosTableSchema subscribeSchema[] = { - {.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, - {.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "client_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY}, + {.name = "client_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SInfosTableSchema smaSchema[] = { + {.name = "sma_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SInfosTableSchema transSchema[] = { + {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "created_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "stage", .bytes = TSDB_TRANS_STAGE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "db", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "type", .bytes = TSDB_TRANS_TYPE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "last_exec_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "last_error", .bytes = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SInfosTableSchema configSchema[] = { + {.name = "name", .bytes = TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "value", .bytes = TSDB_CONIIG_VALUE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SInfosTableSchema connSchema[] = { + {.name = "connId", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "user", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "program", .bytes = TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "ip:port", .bytes = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "login_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "last_access", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, +}; + +static const SInfosTableSchema querySchema[] = { + {.name = "queryId", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "connId", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "user", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "ip:port", .bytes = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "qid", .bytes = 22 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "created_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "time", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, + {.name = "sql_obj_id", .bytes = QUERY_OBJ_ID_SIZE + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "ep", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "stable_query", .bytes = 1, .type = TSDB_DATA_TYPE_BOOL}, + {.name = "sub_queries", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "sub_query_info", .bytes = TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "sql", .bytes = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, }; static const SInfosTableMeta infosMeta[] = { @@ -199,9 +277,9 @@ static const SInfosTableMeta infosMeta[] = { {TSDB_INS_TABLE_MNODES, mnodesSchema, tListLen(mnodesSchema)}, {TSDB_INS_TABLE_MODULES, modulesSchema, tListLen(modulesSchema)}, {TSDB_INS_TABLE_QNODES, qnodesSchema, tListLen(qnodesSchema)}, + {TSDB_INS_TABLE_SNODES, snodesSchema, tListLen(snodesSchema)}, {TSDB_INS_TABLE_BNODES, bnodesSchema, tListLen(bnodesSchema)}, {TSDB_INS_TABLE_CLUSTER, clusterSchema, tListLen(clusterSchema)}, - {TSDB_INS_TABLE_SNODES, snodesSchema, tListLen(snodesSchema)}, {TSDB_INS_TABLE_USER_DATABASES, userDBSchema, tListLen(userDBSchema)}, {TSDB_INS_TABLE_USER_FUNCTIONS, userFuncSchema, tListLen(userFuncSchema)}, {TSDB_INS_TABLE_USER_INDEXES, userIdxSchema, tListLen(userIdxSchema)}, @@ -210,11 +288,19 @@ static const SInfosTableMeta infosMeta[] = { {TSDB_INS_TABLE_USER_TABLES, userTblsSchema, tListLen(userTblsSchema)}, {TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED, userTblDistSchema, tListLen(userTblDistSchema)}, {TSDB_INS_TABLE_USER_USERS, userUsersSchema, tListLen(userUsersSchema)}, + {TSDB_INS_TABLE_LICENCES, grantsSchema, tListLen(grantsSchema)}, {TSDB_INS_TABLE_VGROUPS, vgroupsSchema, tListLen(vgroupsSchema)}, + {TSDB_INS_TABLE_TOPICS, topicSchema, tListLen(topicSchema)}, + {TSDB_INS_TABLE_CONSUMERS, consumerSchema, tListLen(consumerSchema)}, + {TSDB_INS_TABLE_SUBSCRIBES, subscribeSchema, tListLen(subscribeSchema)}, + {TSDB_INS_TABLE_TRANS, transSchema, tListLen(transSchema)}, + {TSDB_INS_TABLE_SMAS, smaSchema, tListLen(smaSchema)}, + {TSDB_INS_TABLE_CONFIGS, configSchema, tListLen(configSchema)}, + {TSDB_INS_TABLE_CONNS, connSchema, tListLen(connSchema)}, + {TSDB_INS_TABLE_QUERIES, querySchema, tListLen(querySchema)}, }; -// connection/application/ -int32_t mndInitInfosTableSchema(const SInfosTableSchema *pSrc, int32_t colNum, SSchema **pDst) { +static int32_t mndInitInfosTableSchema(const SInfosTableSchema *pSrc, int32_t colNum, SSchema **pDst) { SSchema *schema = taosMemoryCalloc(colNum, sizeof(SSchema)); if (NULL == schema) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -222,40 +308,39 @@ int32_t mndInitInfosTableSchema(const SInfosTableSchema *pSrc, int32_t colNum, S } for (int32_t i = 0; i < colNum; ++i) { - strcpy(schema[i].name, pSrc[i].name); - + tstrncpy(schema[i].name, pSrc[i].name, sizeof(schema[i].name)); schema[i].type = pSrc[i].type; schema[i].colId = i + 1; schema[i].bytes = pSrc[i].bytes; } *pDst = schema; - return TSDB_CODE_SUCCESS; + return 0; } -int32_t mndInsInitMeta(SHashObj *hash) { +static int32_t mndInsInitMeta(SHashObj *hash) { STableMetaRsp meta = {0}; - strcpy(meta.dbFName, TSDB_INFORMATION_SCHEMA_DB); + tstrncpy(meta.dbFName, TSDB_INFORMATION_SCHEMA_DB, sizeof(meta.dbFName)); meta.tableType = TSDB_SYSTEM_TABLE; meta.sversion = 1; meta.tversion = 1; for (int32_t i = 0; i < tListLen(infosMeta); ++i) { - strcpy(meta.tbName, infosMeta[i].name); + tstrncpy(meta.tbName, infosMeta[i].name, sizeof(meta.tbName)); meta.numOfColumns = infosMeta[i].colNum; if (mndInitInfosTableSchema(infosMeta[i].schema, infosMeta[i].colNum, &meta.pSchemas)) { return -1; } - if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) { + if (taosHashPut(hash, meta.tbName, strlen(meta.tbName) + 1, &meta, sizeof(meta))) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } } - return TSDB_CODE_SUCCESS; + return 0; } int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp) { @@ -264,29 +349,28 @@ int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char * return -1; } - STableMetaRsp *meta = (STableMetaRsp *)taosHashGet(pMnode->infosMeta, tbName, strlen(tbName)); - if (NULL == meta) { + STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName) + 1); + if (NULL == pMeta) { mError("invalid information schema table name:%s", tbName); terrno = TSDB_CODE_MND_INVALID_INFOS_TBL; return -1; } - *pRsp = *meta; + *pRsp = *pMeta; - pRsp->pSchemas = taosMemoryCalloc(meta->numOfColumns, sizeof(SSchema)); + pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema)); if (pRsp->pSchemas == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; pRsp->pSchemas = NULL; return -1; } - memcpy(pRsp->pSchemas, meta->pSchemas, meta->numOfColumns * sizeof(SSchema)); - + memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema)); return 0; } int32_t mndInitInfos(SMnode *pMnode) { - pMnode->infosMeta = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); + pMnode->infosMeta = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), false, HASH_NO_LOCK); if (pMnode->infosMeta == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -300,16 +384,12 @@ void mndCleanupInfos(SMnode *pMnode) { return; } - void *pIter = taosHashIterate(pMnode->infosMeta, NULL); - while (pIter) { - STableMetaRsp *meta = (STableMetaRsp *)pIter; - - taosMemoryFreeClear(meta->pSchemas); - - pIter = taosHashIterate(pMnode->infosMeta, pIter); + STableMetaRsp *pMeta = taosHashIterate(pMnode->infosMeta, NULL); + while (pMeta) { + taosMemoryFreeClear(pMeta->pSchemas); + pMeta = taosHashIterate(pMnode->infosMeta, pMeta); } taosHashCleanup(pMnode->infosMeta); pMnode->infosMeta = NULL; } - diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 8c75a737a28e9d0e4b7892d7f6c4a03caa83fa86..6be7097e6af9304cfc2d4f2a81d497f287fb7b13 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -35,7 +35,7 @@ static int32_t mndProcessDropMnodeReq(SNodeMsg *pReq); static int32_t mndProcessCreateMnodeRsp(SNodeMsg *pRsp); static int32_t mndProcessAlterMnodeRsp(SNodeMsg *pRsp); static int32_t mndProcessDropMnodeRsp(SNodeMsg *pRsp); -static int32_t mndRetrieveMnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndRetrieveMnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); static void mndCancelGetNextMnode(SMnode *pMnode, void *pIter); int32_t mndInitMnode(SMnode *pMnode) { @@ -615,7 +615,7 @@ static int32_t mndProcessDropMnodeRsp(SNodeMsg *pRsp) { return 0; } -static int32_t mndRetrieveMnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { +static int32_t mndRetrieveMnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; @@ -628,35 +628,33 @@ static int32_t mndRetrieveMnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, in if (pShow->pIter == NULL) break; cols = 0; + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) &pObj->id, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int16_t *)pWrite = pObj->id; - cols++; + char b1[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(b1, pObj->pDnode->ep, pShow->bytes[cols]); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pObj->pDnode->ep, pShow->bytes[cols]); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, b1, false); - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; const char *roles = mndGetRoleStr(pObj->role); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, roles, pShow->bytes[cols]); - cols++; + char* b2 = taosMemoryCalloc(1, strlen(roles) + VARSTR_HEADER_SIZE); + STR_WITH_MAXSIZE_TO_VARSTR(b2, roles, pShow->bytes[cols]); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) b2, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pObj->roleTime; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pObj->roleTime, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pObj->createdTime; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pObj->createdTime, false); numOfRows++; sdbRelease(pSdb, pObj); } - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); - pShow->numOfReads += numOfRows; + pShow->numOfRows += numOfRows; return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndOffset.c b/source/dnode/mnode/impl/src/mndOffset.c index 22dad48772b2024cb2bb96243de070300aec4e0a..31c16e1e1d1349a11ce89c2ee325f99af9735156 100644 --- a/source/dnode/mnode/impl/src/mndOffset.c +++ b/source/dnode/mnode/impl/src/mndOffset.c @@ -201,6 +201,7 @@ static int32_t mndOffsetActionDelete(SSdb *pSdb, SMqOffsetObj *pOffset) { static int32_t mndOffsetActionUpdate(SSdb *pSdb, SMqOffsetObj *pOldOffset, SMqOffsetObj *pNewOffset) { mTrace("offset:%s, perform update action", pOldOffset->key); + pOldOffset->offset = pNewOffset->offset; return 0; } diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 320671c332b72545303c978e736d446eca970905..353a147a92c6879fe364feb626f79b0006dfd547 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -23,13 +23,9 @@ #include "tglobal.h" #include "version.h" -#define QUERY_ID_SIZE 20 -#define QUERY_OBJ_ID_SIZE 18 -#define SUBQUERY_INFO_SIZE 6 -#define QUERY_SAVE_SIZE 20 - typedef struct { int32_t id; + int8_t connType; char user[TSDB_USER_LEN]; char app[TSDB_APP_NAME_LEN]; // app name that invokes taosc int64_t appStartTimeMs; // app start time @@ -44,8 +40,8 @@ typedef struct { SQueryDesc *pQueries; } SConnObj; -static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, uint32_t ip, uint16_t port, int32_t pid, - const char *app, int64_t startTime); +static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, int8_t connType, uint32_t ip, uint16_t port, + int32_t pid, const char *app, int64_t startTime); static void mndFreeConn(SConnObj *pConn); static SConnObj *mndAcquireConn(SMnode *pMnode, int32_t connId); static void mndReleaseConn(SMnode *pMnode, SConnObj *pConn); @@ -55,9 +51,7 @@ static int32_t mndProcessHeartBeatReq(SNodeMsg *pReq); static int32_t mndProcessConnectReq(SNodeMsg *pReq); static int32_t mndProcessKillQueryReq(SNodeMsg *pReq); static int32_t mndProcessKillConnReq(SNodeMsg *pReq); -static int32_t mndGetConnsMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); static int32_t mndRetrieveConns(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); -static int32_t mndGetQueryMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); static int32_t mndRetrieveQueries(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextQuery(SMnode *pMnode, void *pIter); @@ -77,9 +71,9 @@ int32_t mndInitProfile(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_MND_KILL_QUERY, mndProcessKillQueryReq); mndSetMsgHandle(pMnode, TDMT_MND_KILL_CONN, mndProcessKillConnReq); - mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONNS, mndRetrieveConns); +// mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONNS, mndRetrieveConns); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CONNS, mndCancelGetNextConn); - mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_QUERIES, mndRetrieveQueries); +// mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_QUERIES, mndRetrieveQueries); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_QUERIES, mndCancelGetNextQuery); return 0; @@ -93,8 +87,8 @@ void mndCleanupProfile(SMnode *pMnode) { } } -static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, uint32_t ip, uint16_t port, int32_t pid, - const char *app, int64_t startTime) { +static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, int8_t connType, uint32_t ip, uint16_t port, + int32_t pid, const char *app, int64_t startTime) { SProfileMgmt *pMgmt = &pMnode->profileMgmt; int32_t connId = atomic_add_fetch_32(&pMgmt->connId, 1); @@ -102,6 +96,7 @@ static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, uint32_t ip, ui if (startTime == 0) startTime = taosGetTimestampMs(); SConnObj connObj = {.id = connId, + .connType = connType, .appStartTimeMs = startTime, .pid = pid, .ip = ip, @@ -159,8 +154,8 @@ static void mndReleaseConn(SMnode *pMnode, SConnObj *pConn) { } void *mndGetNextConn(SMnode *pMnode, SCacheIter *pIter) { - SConnObj* pConn = NULL; - bool hasNext = taosCacheIterNext(pIter); + SConnObj *pConn = NULL; + bool hasNext = taosCacheIterNext(pIter); if (hasNext) { size_t dataLen = 0; pConn = taosCacheIterGetData(pIter, &dataLen); @@ -210,8 +205,8 @@ static int32_t mndProcessConnectReq(SNodeMsg *pReq) { } } - pConn = - mndCreateConn(pMnode, pReq->user, pReq->clientIp, pReq->clientPort, connReq.pid, connReq.app, connReq.startTime); + pConn = mndCreateConn(pMnode, pReq->user, connReq.connType, pReq->clientIp, pReq->clientPort, connReq.pid, + connReq.app, connReq.startTime); if (pConn == NULL) { mError("user:%s, failed to login from %s while create connection since %s", pReq->user, ip, terrstr()); goto CONN_OVER; @@ -222,6 +217,7 @@ static int32_t mndProcessConnectReq(SNodeMsg *pReq) { connectRsp.superUser = pUser->superUser; connectRsp.clusterId = pMnode->clusterId; connectRsp.connId = pConn->id; + connectRsp.connType = connReq.connType; snprintf(connectRsp.sVersion, sizeof(connectRsp.sVersion), "ver:%s\nbuild:%s\ngitinfo:%s", version, buildinfo, gitinfo); @@ -343,7 +339,6 @@ static int32_t mndProcessHeartBeatReq(SNodeMsg *pReq) { return -1; } - SClientHbBatchRsp batchRsp = {0}; batchRsp.rsps = taosArrayInit(0, sizeof(SClientHbRsp)); @@ -556,81 +551,6 @@ static int32_t mndProcessKillConnReq(SNodeMsg *pReq) { } } -static int32_t mndGetConnsMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - SMnode *pMnode = pReq->pNode; - SProfileMgmt *pMgmt = &pMnode->profileMgmt; - - SUserObj *pUser = mndAcquireUser(pMnode, pReq->user); - if (pUser == NULL) return 0; - if (!pUser->superUser) { - mndReleaseUser(pMnode, pUser); - terrno = TSDB_CODE_MND_NO_RIGHTS; - return -1; - } - mndReleaseUser(pMnode, pUser); - - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "connId"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "user"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - // app name - pShow->bytes[cols] = TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "program"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - // app pid - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "pid"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "ip:port"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "login_time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "last_access"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = taosCacheGetNumOfObj(pMgmt->cache); - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - - return 0; -} - static int32_t mndRetrieveConns(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { SMnode *pMnode = pReq->pNode; int32_t numOfRows = 0; @@ -685,126 +605,11 @@ static int32_t mndRetrieveConns(SNodeMsg *pReq, SShowObj *pShow, char *data, int numOfRows++; } - pShow->numOfReads += numOfRows; + pShow->numOfRows += numOfRows; return numOfRows; } -static int32_t mndGetQueryMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - SMnode *pMnode = pReq->pNode; - SProfileMgmt *pMgmt = &pMnode->profileMgmt; - - SUserObj *pUser = mndAcquireUser(pMnode, pReq->user); - if (pUser == NULL) return 0; - if (!pUser->superUser) { - mndReleaseUser(pMnode, pUser); - terrno = TSDB_CODE_MND_NO_RIGHTS; - return -1; - } - mndReleaseUser(pMnode, pUser); - - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "queryId"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "connId"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "user"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "ip:port"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 22 + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "qid"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "created_time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_BIGINT; - strcpy(pSchema[cols].name, "time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = QUERY_OBJ_ID_SIZE + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "sql_obj_id"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "pid"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "ep"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 1; - pSchema[cols].type = TSDB_DATA_TYPE_BOOL; - strcpy(pSchema[cols].name, "stable_query"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "sub_queries"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "sub_query_info"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "sql"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = 1000000; - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - - return 0; -} - static int32_t mndRetrieveQueries(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { SMnode *pMnode = pReq->pNode; int32_t numOfRows = 0; @@ -903,8 +708,7 @@ static int32_t mndRetrieveQueries(SNodeMsg *pReq, SShowObj *pShow, char *data, i } } - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); - pShow->numOfReads += numOfRows; + pShow->numOfRows += numOfRows; return numOfRows; } @@ -917,4 +721,4 @@ static void mndCancelGetNextQuery(SMnode *pMnode, void *pIter) { int32_t mndGetNumOfConnections(SMnode *pMnode) { SProfileMgmt *pMgmt = &pMnode->profileMgmt; return taosCacheGetNumOfObj(pMgmt->cache); -} \ No newline at end of file +} diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index 3f8c7e88f93cba86dd0828b1a87e41e9c69ffaf0..3b622795cb0f56095484481ba848f06295384e80 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -34,7 +34,7 @@ static int32_t mndProcessCreateQnodeRsp(SNodeMsg *pRsp); static int32_t mndProcessDropQnodeReq(SNodeMsg *pReq); static int32_t mndProcessDropQnodeRsp(SNodeMsg *pRsp); static int32_t mndProcessQnodeListReq(SNodeMsg *pReq); -static int32_t mndRetrieveQnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndRetrieveQnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); static void mndCancelGetNextQnode(SMnode *pMnode, void *pIter); int32_t mndInitQnode(SMnode *pMnode) { @@ -497,7 +497,7 @@ static int32_t mndProcessDropQnodeRsp(SNodeMsg *pRsp) { return 0; } -static int32_t mndRetrieveQnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { +static int32_t mndRetrieveQnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; @@ -510,26 +510,22 @@ static int32_t mndRetrieveQnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, in if (pShow->pIter == NULL) break; cols = 0; + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*)&pObj->id, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int16_t *)pWrite = pObj->id; - cols++; + char ep[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->bytes[cols]); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)ep, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pObj->pDnode->ep, pShow->bytes[cols]); - - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pObj->createdTime; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pObj->createdTime, false); numOfRows++; sdbRelease(pSdb, pObj); } - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); - pShow->numOfReads += numOfRows; + pShow->numOfRows += numOfRows; return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 03e6049d82127a3804383d1e63fe72c755a0e995..617cebf61d4b69c1e0a321b3d1f1eda16b4befec 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -60,7 +60,6 @@ static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowReq *pReq) { showObj.type = pReq->type; showObj.payloadLen = pReq->payloadLen; memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN); - memcpy(showObj.payload, pReq->payload, pReq->payloadLen); int32_t keepTime = tsShellActivityTimer * 6 * 1000; SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime); @@ -113,95 +112,11 @@ static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) { taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove); } -static int32_t mndProcessRetrieveReq(SNodeMsg *pReq) { - SMnode *pMnode = pReq->pNode; - SShowMgmt *pMgmt = &pMnode->showMgmt; - int32_t rowsToRead = 0; - int32_t size = 0; - int32_t rowsRead = 0; - - SRetrieveTableReq retrieveReq = {0}; - if (tDeserializeSRetrieveTableReq(pReq->rpcMsg.pCont, pReq->rpcMsg.contLen, &retrieveReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - SShowObj *pShow = mndAcquireShowObj(pMnode, retrieveReq.showId); - if (pShow == NULL) { - terrno = TSDB_CODE_MND_INVALID_SHOWOBJ; - mError("failed to process show-retrieve req:%p since %s", pShow, terrstr()); - return -1; - } - - ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type]; - if (retrieveFp == NULL) { - mndReleaseShowObj(pShow, false); - terrno = TSDB_CODE_MSG_NOT_PROCESSED; - mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr()); - return -1; - } - - mDebug("show:0x%" PRIx64 ", start retrieve data, numOfReads:%d numOfRows:%d type:%s", pShow->id, pShow->numOfReads, - pShow->numOfRows, mndShowStr(pShow->type)); - - if (mndCheckRetrieveFinished(pShow)) { - mDebug("show:0x%" PRIx64 ", read finished, numOfReads:%d numOfRows:%d", pShow->id, pShow->numOfReads, - pShow->numOfRows); - pShow->numOfReads = pShow->numOfRows; - } - - if ((retrieveReq.free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) { - rowsToRead = pShow->numOfRows - pShow->numOfReads; - } - - /* return no more than 100 tables in one round trip */ - if (rowsToRead > SHOW_STEP_SIZE) rowsToRead = SHOW_STEP_SIZE; - - /* - * the actual number of table may be larger than the value of pShow->numOfRows, if a query is - * issued during a continuous create table operation. Therefore, rowToRead may be less than 0. - */ - if (rowsToRead < 0) rowsToRead = 0; - size = pShow->rowSize * rowsToRead; - - size += SHOW_STEP_SIZE; - SRetrieveTableRsp *pRsp = rpcMallocCont(size); - if (pRsp == NULL) { - mndReleaseShowObj(pShow, false); - terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr()); - return -1; - } - - // if free flag is set, client wants to clean the resources - if ((retrieveReq.free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) { - rowsRead = (*retrieveFp)(pReq, pShow, pRsp->data, rowsToRead); - } - - mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead); - - pRsp->numOfRows = htonl(rowsRead); - pRsp->precision = TSDB_TIME_PRECISION_MILLI; // millisecond time precision - - pReq->pRsp = pRsp; - pReq->rspLen = size; - - if (rowsRead == 0 || rowsToRead == 0 || (rowsRead == rowsToRead && pShow->numOfRows == pShow->numOfReads)) { - pRsp->completed = 1; - mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); - mndReleaseShowObj(pShow, true); - } else { - mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id); - mndReleaseShowObj(pShow, false); - } - - return TSDB_CODE_SUCCESS; -} - static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { SMnode *pMnode = pReq->pNode; SShowMgmt *pMgmt = &pMnode->showMgmt; - int32_t rowsToRead = 0; + SShowObj *pShow = NULL; + int32_t rowsToRead = SHOW_STEP_SIZE; int32_t size = 0; int32_t rowsRead = 0; @@ -211,8 +126,6 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { return -1; } - SShowObj* pShow = NULL; - if (retrieveReq.showId == 0) { SShowReq req = {0}; req.type = retrieveReq.type; @@ -225,15 +138,14 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { return -1; } - STableMetaRsp *meta = (STableMetaRsp *)taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb)); - pShow->numOfRows = 100; - + pShow->pMeta = (STableMetaRsp *)taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb) + 1); + pShow->numOfColumns = pShow->pMeta->numOfColumns; int32_t offset = 0; - for(int32_t i = 0; i < meta->numOfColumns; ++i) { - pShow->numOfColumns = meta->numOfColumns; + + for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) { pShow->offset[i] = offset; - int32_t bytes = meta->pSchemas[i].bytes; + int32_t bytes = pShow->pMeta->pSchemas[i].bytes; pShow->rowSize += bytes; pShow->bytes[i] = bytes; offset += bytes; @@ -245,154 +157,113 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { mError("failed to process show-retrieve req:%p since %s", pShow, terrstr()); return -1; } - - pShow->numOfReads = 0; } ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type]; if (retrieveFp == NULL) { - mndReleaseShowObj((SShowObj*) pShow, false); + mndReleaseShowObj(pShow, false); terrno = TSDB_CODE_MSG_NOT_PROCESSED; mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr()); return -1; } - mDebug("show:0x%" PRIx64 ", start retrieve data, numOfReads:%d numOfRows:%d type:%s", pShow->id, pShow->numOfReads, - pShow->numOfRows, mndShowStr(pShow->type)); + mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type); - if (mndCheckRetrieveFinished((SShowObj*) pShow)) { - mDebug("show:0x%" PRIx64 ", read finished, numOfReads:%d numOfRows:%d", pShow->id, pShow->numOfReads, - pShow->numOfRows); - pShow->numOfReads = pShow->numOfRows; - } + int32_t numOfCols = pShow->pMeta->numOfColumns; + SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); + pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); + pBlock->info.numOfCols = numOfCols; + + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData idata = {0}; + SSchema *p = &pShow->pMeta->pSchemas[i]; + + idata.info.bytes = p->bytes; + idata.info.type = p->type; + idata.info.colId = p->colId; - if ((retrieveReq.free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) { - rowsToRead = pShow->numOfRows - pShow->numOfReads; + taosArrayPush(pBlock->pDataBlock, &idata); + if (IS_VAR_DATA_TYPE(p->type)) { + pBlock->info.hasVarCol = true; + } } - /* return no more than 100 tables in one round trip */ - if (rowsToRead > SHOW_STEP_SIZE) rowsToRead = SHOW_STEP_SIZE; + blockDataEnsureCapacity(pBlock, rowsToRead); + if (mndCheckRetrieveFinished(pShow)) { + mDebug("show:0x%" PRIx64 ", read finished, numOfRows:%d", pShow->id, pShow->numOfRows); + rowsRead = 0; + } else { + rowsRead = (*retrieveFp)(pReq, pShow, pBlock, rowsToRead); + if (rowsRead < 0) { + terrno = rowsRead; + mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); + mndReleaseShowObj(pShow, true); + return -1; + } + + pBlock->info.rows = rowsRead; + mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows); + } - /* - * the actual number of table may be larger than the value of pShow->numOfRows, if a query is - * issued during a continuous create table operation. Therefore, rowToRead may be less than 0. - */ - if (rowsToRead < 0) rowsToRead = 0; - size = pShow->rowSize * rowsToRead; + size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns + + blockDataGetSize(pBlock) + blockDataGetSerialMetaSize(pBlock); - size += SHOW_STEP_SIZE; SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size); if (pRsp == NULL) { - mndReleaseShowObj((SShowObj*) pShow, false); + mndReleaseShowObj(pShow, false); terrno = TSDB_CODE_OUT_OF_MEMORY; mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr()); + blockDataDestroy(pBlock); return -1; } pRsp->handle = htobe64(pShow->id); - // if free flag is set, client wants to clean the resources - if ((retrieveReq.free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) { - rowsRead = (*retrieveFp)(pReq, (SShowObj*) pShow, pRsp->data, rowsToRead); - if (rowsRead < 0) { - terrno = rowsRead; - rpcFreeCont(pRsp); - mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); - mndReleaseShowObj((SShowObj*) pShow, true); - return -1; + if (rowsRead > 0) { + char *pStart = pRsp->data; + SSchema *ps = pShow->pMeta->pSchemas; + + *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns); + pStart += sizeof(int32_t); // number of columns + + for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) { + SSysTableSchema *pSchema = (SSysTableSchema *)pStart; + pSchema->bytes = htonl(ps[i].bytes); + pSchema->colId = htons(ps[i].colId); + pSchema->type = ps[i].type; + + pStart += sizeof(SSysTableSchema); } - } - mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead); + int32_t len = 0; + blockCompressEncode(pBlock, pStart, &len, pShow->pMeta->numOfColumns, false); + } pRsp->numOfRows = htonl(rowsRead); pRsp->precision = TSDB_TIME_PRECISION_MILLI; // millisecond time precision - pReq->pRsp = pRsp; pReq->rspLen = size; - if (rowsRead == 0 || rowsToRead == 0 || (rowsRead < rowsToRead)) { + if (rowsRead == 0 || rowsRead < rowsToRead) { pRsp->completed = 1; mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); - mndReleaseShowObj((SShowObj*) pShow, true); + mndReleaseShowObj(pShow, true); } else { mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id); - mndReleaseShowObj((SShowObj*) pShow, false); + mndReleaseShowObj(pShow, false); } + blockDataDestroy(pBlock); return TSDB_CODE_SUCCESS; } -char *mndShowStr(int32_t showType) { - switch (showType) { - case TSDB_MGMT_TABLE_ACCT: - return "show accounts"; - case TSDB_MGMT_TABLE_USER: - return "show users"; - case TSDB_MGMT_TABLE_DB: - return "show databases"; - case TSDB_MGMT_TABLE_TABLE: - return "show tables"; - case TSDB_MGMT_TABLE_DNODE: - return "show dnodes"; - case TSDB_MGMT_TABLE_MNODE: - return "show mnodes"; - case TSDB_MGMT_TABLE_QNODE: - return "show qnodes"; - case TSDB_MGMT_TABLE_SNODE: - return "show snodes"; - case TSDB_MGMT_TABLE_BNODE: - return "show bnodes"; - case TSDB_MGMT_TABLE_VGROUP: - return "show vgroups"; - case TSDB_MGMT_TABLE_STB: - return "show stables"; - case TSDB_MGMT_TABLE_MODULE: - return "show modules"; - case TSDB_MGMT_TABLE_QUERIES: - return "show queries"; - case TSDB_MGMT_TABLE_STREAMS: - return "show streams"; - case TSDB_MGMT_TABLE_VARIABLES: - return "show configs"; - case TSDB_MGMT_TABLE_CONNS: - return "show connections"; - case TSDB_MGMT_TABLE_TRANS: - return "show trans"; - case TSDB_MGMT_TABLE_GRANTS: - return "show grants"; - case TSDB_MGMT_TABLE_VNODES: - return "show vnodes"; - case TSDB_MGMT_TABLE_CLUSTER: - return "show cluster"; - case TSDB_MGMT_TABLE_STREAMTABLES: - return "show streamtables"; - case TSDB_MGMT_TABLE_TP: - return "show topics"; - case TSDB_MGMT_TABLE_FUNC: - return "show functions"; - case TSDB_MGMT_TABLE_INDEX: - return "show indexes"; - default: - return "undefined"; - } -} - static bool mndCheckRetrieveFinished(SShowObj *pShow) { - if (pShow->pIter == NULL && pShow->numOfReads != 0) { + if (pShow->pIter == NULL && pShow->numOfRows != 0) { return true; } return false; } -void mndVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_t capacity, SShowObj *pShow) { - if (rows < capacity) { - for (int32_t i = 0; i < numOfCols; ++i) { - memmove(data + pShow->offset[i] * rows, data + pShow->offset[i] * capacity, pShow->bytes[i] * rows); - } - } -} - void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) { SShowMgmt *pMgmt = &pMnode->showMgmt; pMgmt->retrieveFps[showType] = fp; diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index f56c72d93e3aa4f0b7eb98b4de214e01daabedd2..1e68e8e9c5a27d8294f8e1f86fdd8f62687690f9 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -40,8 +40,7 @@ static int32_t mndProcessMCreateSmaReq(SNodeMsg *pReq); static int32_t mndProcessMDropSmaReq(SNodeMsg *pReq); static int32_t mndProcessVCreateSmaRsp(SNodeMsg *pRsp); static int32_t mndProcessVDropSmaRsp(SNodeMsg *pRsp); -static int32_t mndGetSmaMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); -static int32_t mndRetrieveSma(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndRetrieveSma(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); static void mndCancelGetNextSma(SMnode *pMnode, void *pIter); int32_t mndInitSma(SMnode *pMnode) { @@ -725,54 +724,12 @@ static int32_t mndProcessVDropSmaRsp(SNodeMsg *pRsp) { return 0; } -static int32_t mndGetSmaMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - SMnode *pMnode = pReq->pNode; - SSdb *pSdb = pMnode->pSdb; - - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = TSDB_INDEX_NAME_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "name"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "create_time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "stb"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = sdbGetSize(pSdb, SDB_SMA); - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - - return 0; -} - -static int32_t mndRetrieveSma(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { +static int32_t mndRetrieveSma(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; SSmaObj *pSma = NULL; int32_t cols = 0; - char *pWrite; - char prefix[TSDB_DB_FNAME_LEN] = {0}; SDbObj *pDb = mndAcquireDb(pMnode, pShow->db); if (pDb == NULL) return 0; @@ -790,27 +747,32 @@ static int32_t mndRetrieveSma(SNodeMsg *pReq, SShowObj *pShow, char *data, int32 SName smaName = {0}; tNameFromString(&smaName, pSma->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_TO_VARSTR(pWrite, (char *)tNameGetTableName(&smaName)); - cols++; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pSma->createdTime; + char n[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(n, (char *)tNameGetTableName(&smaName)); cols++; SName stbName = {0}; tNameFromString(&stbName, pSma->stb, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_TO_VARSTR(pWrite, (char *)tNameGetTableName(&stbName)); - cols++; + + char n1[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(n1, (char *)tNameGetTableName(&stbName)); + + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) n, false); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pSma->createdTime, false); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)n1, false); numOfRows++; sdbRelease(pSdb, pSma); } mndReleaseDb(pMnode, pDb); - pShow->numOfReads += numOfRows; - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); + pShow->numOfRows += numOfRows; return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index cc25e523c131c4ef7d16098a9b112231223a1067..686cf1400dc75e75b276ac89c5798198bd04d471 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -33,7 +33,7 @@ static int32_t mndProcessCreateSnodeReq(SNodeMsg *pReq); static int32_t mndProcessCreateSnodeRsp(SNodeMsg *pRsp); static int32_t mndProcessDropSnodeReq(SNodeMsg *pReq); static int32_t mndProcessDropSnodeRsp(SNodeMsg *pRsp); -static int32_t mndRetrieveSnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndRetrieveSnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); static void mndCancelGetNextSnode(SMnode *pMnode, void *pIter); int32_t mndInitSnode(SMnode *pMnode) { @@ -447,39 +447,35 @@ static int32_t mndProcessDropSnodeRsp(SNodeMsg *pRsp) { return 0; } -static int32_t mndRetrieveSnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { +static int32_t mndRetrieveSnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; int32_t cols = 0; SSnodeObj *pObj = NULL; - char *pWrite; while (numOfRows < rows) { pShow->pIter = sdbFetch(pSdb, SDB_SNODE, pShow->pIter, (void **)&pObj); if (pShow->pIter == NULL) break; cols = 0; + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*)&pObj->id, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int16_t *)pWrite = pObj->id; - cols++; + char ep[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->bytes[cols]); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pObj->pDnode->ep, pShow->bytes[cols]); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)ep, false); - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pObj->createdTime; - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pObj->createdTime, false); numOfRows++; sdbRelease(pSdb, pObj); } - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); - pShow->numOfReads += numOfRows; + pShow->numOfRows += numOfRows; return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index afcea6e7322591096966be8d747c818bd4724036..92a67fd7e9401afc44e39fa5283e37bbddd3c8a1 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -39,7 +39,7 @@ static int32_t mndProcessVCreateStbRsp(SNodeMsg *pRsp); static int32_t mndProcessVAlterStbRsp(SNodeMsg *pRsp); static int32_t mndProcessVDropStbRsp(SNodeMsg *pRsp); static int32_t mndProcessTableMetaReq(SNodeMsg *pReq); -static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); static void mndCancelGetNextStb(SMnode *pMnode, void *pIter); int32_t mndInitStb(SMnode *pMnode) { @@ -1638,13 +1638,12 @@ static void mndExtractTableName(char *tableId, char *name) { } } -static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { +static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; SStbObj *pStb = NULL; int32_t cols = 0; - char *pWrite; SDbObj* pDb = NULL; if (strlen(pShow->db) > 0) { @@ -1664,42 +1663,45 @@ static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, char *data, int32 cols = 0; SName name = {0}; - char stbName[TSDB_TABLE_NAME_LEN] = {0}; - mndExtractTableName(pStb->name, stbName); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_TO_VARSTR(pWrite, stbName); - cols++; + char stbName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + mndExtractTableName(pStb->name, &stbName[VARSTR_HEADER_SIZE]); + varDataSetLen(stbName, strlen(&stbName[VARSTR_HEADER_SIZE])); - char db[TSDB_DB_NAME_LEN] = {0}; + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) stbName, false); + + char db[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; tNameFromString(&name, pStb->db, T_NAME_ACCT|T_NAME_DB); - tNameGetDbName(&name, db); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_TO_VARSTR(pWrite, db); - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pStb->createdTime; - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int32_t *)pWrite = pStb->numOfColumns; - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int32_t *)pWrite = pStb->numOfTags; - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pStb->updateTime; // number of tables - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - if (pStb->commentLen != 0) { - STR_TO_VARSTR(pWrite, pStb->comment); - } else { - STR_TO_VARSTR(pWrite, ""); + tNameGetDbName(&name, varDataVal(db)); + varDataSetLen(db, strlen(varDataVal(db))); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char*) db, false); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pStb->createdTime, false); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pStb->numOfColumns, false); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pStb->numOfTags, false); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pStb->updateTime, false); // number of tables + + char* p = taosMemoryMalloc(pStb->commentLen + VARSTR_HEADER_SIZE); // check malloc failures + if (p != NULL) { + if (pStb->commentLen != 0) { + STR_TO_VARSTR(p, pStb->comment); + } else { + STR_TO_VARSTR(p, ""); + } + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols); + colDataAppend(pColInfo, numOfRows, (const char *)p, false); + taosMemoryFree(p); } - cols++; numOfRows++; sdbRelease(pSdb, pStb); @@ -1709,8 +1711,7 @@ static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, char *data, int32 mndReleaseDb(pMnode, pDb); } - pShow->numOfReads += numOfRows; - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); + pShow->numOfRows += numOfRows; return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index 4411db97a5cd752e291e2bc5f14ab8d112cddbf1..a0ee8ff44cad00ff56d5927e98fe0d75bd391d9f 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -58,8 +58,8 @@ int32_t mndInitStream(SMnode *pMnode) { /*mndSetMsgHandle(pMnode, TDMT_MND_DROP_STREAM, mndProcessDropStreamReq);*/ /*mndSetMsgHandle(pMnode, TDMT_MND_DROP_STREAM_RSP, mndProcessDropStreamInRsp);*/ - mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TP, mndRetrieveStream); - mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TP, mndCancelGetNextStream); + // mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndRetrieveStream); + mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndCancelGetNextStream); return sdbSetTable(pMnode->pSdb, table); } @@ -421,50 +421,6 @@ static int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfS return 0; } -static int32_t mndGetStreamMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - SMnode *pMnode = pReq->pNode; - SSdb *pSdb = pMnode->pSdb; - - if (mndGetNumOfStreams(pMnode, pShow->db, &pShow->numOfRows) != 0) { - return -1; - } - - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "name"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "create_time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "sql"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = sdbGetSize(pSdb, SDB_STREAM); - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - - return 0; -} - static int32_t mndRetrieveStream(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; @@ -515,8 +471,7 @@ static int32_t mndRetrieveStream(SNodeMsg *pReq, SShowObj *pShow, char *data, in } mndReleaseDb(pMnode, pDb); - pShow->numOfReads += numOfRows; - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); + pShow->numOfRows += numOfRows; return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index dbd5e43b6df3e8aa85a0b6153c7f6c6898deaba1..3a31b0abb9ef47e78772d9a8612155b7ed344382 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -60,8 +60,10 @@ static int32_t mndProcessResetOffsetReq(SNodeMsg *pMsg); static int32_t mndPersistMqSetConnReq(SMnode *pMnode, STrans *pTrans, const SMqTopicObj *pTopic, const char *cgroup, const SMqConsumerEp *pConsumerEp); -static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp, const char* topicName); -static int32_t mndPersistCancelConnReq(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp, const char* oldTopicName); +static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp, + const char *topicName); +static int32_t mndPersistCancelConnReq(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp, + const char *oldTopicName); int32_t mndInitSubscribe(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_SUBSCRIBE, @@ -102,7 +104,8 @@ static SMqSubscribeObj *mndCreateSubscription(SMnode *pMnode, const SMqTopicObj return pSub; } -static int32_t mndBuildRebalanceMsg(void **pBuf, int32_t *pLen, const SMqConsumerEp *pConsumerEp, const char* topicName) { +static int32_t mndBuildRebalanceMsg(void **pBuf, int32_t *pLen, const SMqConsumerEp *pConsumerEp, + const char *topicName) { SMqMVRebReq req = { .vgId = pConsumerEp->vgId, .oldConsumerId = pConsumerEp->oldConsumerId, @@ -131,7 +134,8 @@ static int32_t mndBuildRebalanceMsg(void **pBuf, int32_t *pLen, const SMqConsume return 0; } -static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp, const char* topicName) { +static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp, + const char *topicName) { ASSERT(pConsumerEp->oldConsumerId != -1); void *buf; @@ -158,7 +162,8 @@ static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqC return 0; } -static int32_t mndBuildCancelConnReq(void **pBuf, int32_t *pLen, const SMqConsumerEp *pConsumerEp, const char* oldTopicName) { +static int32_t mndBuildCancelConnReq(void **pBuf, int32_t *pLen, const SMqConsumerEp *pConsumerEp, + const char *oldTopicName) { SMqCancelConnReq req = {0}; req.consumerId = pConsumerEp->consumerId; req.vgId = pConsumerEp->vgId; @@ -182,7 +187,8 @@ static int32_t mndBuildCancelConnReq(void **pBuf, int32_t *pLen, const SMqConsum return 0; } -static int32_t mndPersistCancelConnReq(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp, const char* oldTopicName) { +static int32_t mndPersistCancelConnReq(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp, + const char *oldTopicName) { void *buf; int32_t tlen; if (mndBuildCancelConnReq(&buf, &tlen, pConsumerEp, oldTopicName) < 0) { @@ -219,13 +225,14 @@ static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg) { terrno = TSDB_CODE_MND_CONSUMER_NOT_EXIST; return -1; } - //TODO add lock + // TODO add lock ASSERT(strcmp(pReq->cgroup, pConsumer->cgroup) == 0); - int32_t serverEpoch = pConsumer->epoch; + int32_t serverEpoch = pConsumer->epoch; // TODO int32_t hbStatus = atomic_load_32(&pConsumer->hbStatus); - mDebug("consumer %ld epoch(%d) try to get sub ep, server epoch %d, old val: %d", consumerId, epoch, serverEpoch, hbStatus); + mDebug("consumer %ld epoch(%d) try to get sub ep, server epoch %d, old val: %d", consumerId, epoch, serverEpoch, + hbStatus); atomic_store_32(&pConsumer->hbStatus, 0); /*SSdbRaw *pConsumerRaw = mndConsumerActionEncode(pConsumer);*/ /*sdbSetRawStatus(pConsumerRaw, SDB_STATUS_READY);*/ @@ -233,7 +240,8 @@ static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg) { strcpy(rsp.cgroup, pReq->cgroup); if (epoch != serverEpoch) { - mInfo("send new assignment to consumer %ld, consumer epoch %d, server epoch %d", pConsumer->consumerId, epoch, serverEpoch); + mInfo("send new assignment to consumer %ld, consumer epoch %d, server epoch %d", pConsumer->consumerId, epoch, + serverEpoch); mDebug("consumer %ld try r lock", consumerId); taosRLockLatch(&pConsumer->lock); mDebug("consumer %ld r locked", consumerId); @@ -251,8 +259,15 @@ static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg) { if (consumerId == pSubConsumer->consumerId) { int32_t vgsz = taosArrayGetSize(pSubConsumer->vgInfo); mInfo("topic %s has %d vg", topicName, serverEpoch); + SMqSubTopicEp topicEp; strcpy(topicEp.topic, topicName); + + SMqTopicObj *pTopic = mndAcquireTopic(pMnode, topicName); + ASSERT(pTopic != NULL); + topicEp.schema = pTopic->schema; + mndReleaseTopic(pMnode, pTopic); + topicEp.vgs = taosArrayInit(vgsz, sizeof(SMqSubVgEp)); for (int32_t k = 0; k < vgsz; k++) { char offsetKey[TSDB_PARTITION_KEY_LEN]; @@ -409,7 +424,8 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { SMqSubscribeObj *pSub = mndAcquireSubscribeByKey(pMnode, pRebSub->key); taosMemoryFreeClear(pRebSub->key); - mInfo("mq rebalance subscription: %s, vgNum: %d, unassignedVg: %d", pSub->key, pSub->vgNum, (int32_t)taosArrayGetSize(pSub->unassignedVg)); + mInfo("mq rebalance subscription: %s, vgNum: %d, unassignedVg: %d", pSub->key, pSub->vgNum, + (int32_t)taosArrayGetSize(pSub->unassignedVg)); // remove lost consumer for (int32_t i = 0; i < taosArrayGetSize(pRebSub->lostConsumers); i++) { @@ -453,18 +469,19 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { ASSERT(pConsumerEp != NULL); ASSERT(pConsumerEp->consumerId == pSubConsumer->consumerId); taosArrayPush(pSub->unassignedVg, pConsumerEp); + mDebug("mq rebalance: vg %d push to unassignedVg", pConsumerEp->vgId); } SMqConsumerObj *pRebConsumer = mndAcquireConsumer(pMnode, pSubConsumer->consumerId); mDebug("consumer %ld try w lock", pRebConsumer->consumerId); taosWLockLatch(&pRebConsumer->lock); mDebug("consumer %ld w locked", pRebConsumer->consumerId); - int32_t status = atomic_load_32(&pRebConsumer->status); + int32_t status = atomic_load_32(&pRebConsumer->status); if (vgThisConsumerAfterRb != vgThisConsumerBeforeRb || (vgThisConsumerAfterRb != 0 && status != MQ_CONSUMER_STATUS__ACTIVE) || (vgThisConsumerAfterRb == 0 && status != MQ_CONSUMER_STATUS__LOST)) { /*if (vgThisConsumerAfterRb != vgThisConsumerBeforeRb) {*/ - /*pRebConsumer->epoch++;*/ + /*pRebConsumer->epoch++;*/ /*}*/ if (vgThisConsumerAfterRb != 0) { atomic_store_32(&pRebConsumer->status, MQ_CONSUMER_STATUS__ACTIVE); @@ -496,11 +513,12 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { while (taosArrayGetSize(pSubConsumer->vgInfo) < vgThisConsumerAfterRb) { SMqConsumerEp *pConsumerEp = taosArrayPop(pSub->unassignedVg); + mDebug("mq rebalance: vg %d pop from unassignedVg", pConsumerEp->vgId); ASSERT(pConsumerEp != NULL); pConsumerEp->oldConsumerId = pConsumerEp->consumerId; pConsumerEp->consumerId = pSubConsumer->consumerId; - //TODO + // TODO pConsumerEp->epoch = 0; taosArrayPush(pSubConsumer->vgInfo, pConsumerEp); @@ -554,7 +572,6 @@ static int32_t mndPersistMqSetConnReq(SMnode *pMnode, STrans *pTrans, const SMqT .vgId = vgId, .consumerId = pConsumerEp->consumerId, .sql = pTopic->sql, - .logicalPlan = pTopic->logicalPlan, .physicalPlan = pTopic->physicalPlan, .qmsg = pConsumerEp->qmsg, }; diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 4d7f00c24c04fb357d0766f570b5c245a7099490..b9c42fe899a2bd798ba039b514483b3e38a8c907 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -26,7 +26,7 @@ #include "parser.h" #include "tname.h" -#define MND_TOPIC_VER_NUMBER 1 +#define MND_TOPIC_VER_NUMBER 1 #define MND_TOPIC_RESERVE_SIZE 64 static int32_t mndTopicActionInsert(SSdb *pSdb, SMqTopicObj *pTopic); @@ -35,8 +35,6 @@ static int32_t mndTopicActionUpdate(SSdb *pSdb, SMqTopicObj *pTopic, SMqTopicObj static int32_t mndProcessCreateTopicReq(SNodeMsg *pReq); static int32_t mndProcessDropTopicReq(SNodeMsg *pReq); static int32_t mndProcessDropTopicInRsp(SNodeMsg *pRsp); -static int32_t mndProcessTopicMetaReq(SNodeMsg *pReq); -static int32_t mndGetTopicMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); static int32_t mndRetrieveTopic(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextTopic(SMnode *pMnode, void *pIter); @@ -53,8 +51,8 @@ int32_t mndInitTopic(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_MND_DROP_TOPIC, mndProcessDropTopicReq); mndSetMsgHandle(pMnode, TDMT_VND_DROP_TOPIC_RSP, mndProcessDropTopicInRsp); - mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TP, mndRetrieveTopic); - mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TP, mndCancelGetNextTopic); + // mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndRetrieveTopic); + mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndCancelGetNextTopic); return sdbSetTable(pMnode->pSdb, table); } @@ -64,11 +62,10 @@ void mndCleanupTopic(SMnode *pMnode) {} SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) { terrno = TSDB_CODE_OUT_OF_MEMORY; - int32_t logicalPlanLen = strlen(pTopic->logicalPlan) + 1; int32_t physicalPlanLen = strlen(pTopic->physicalPlan) + 1; - int32_t swLen = taosEncodeSSchemaWrapper(NULL, &pTopic->schema); + int32_t schemaLen = taosEncodeSSchemaWrapper(NULL, &pTopic->schema); int32_t size = - sizeof(SMqTopicObj) + logicalPlanLen + physicalPlanLen + pTopic->sqlLen + swLen + MND_TOPIC_RESERVE_SIZE; + sizeof(SMqTopicObj) + physicalPlanLen + pTopic->sqlLen + pTopic->astLen + schemaLen + MND_TOPIC_RESERVE_SIZE; SSdbRaw *pRaw = sdbAllocRaw(SDB_TOPIC, MND_TOPIC_VER_NUMBER, size); if (pRaw == NULL) goto TOPIC_ENCODE_OVER; @@ -82,19 +79,19 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) { SDB_SET_INT32(pRaw, dataPos, pTopic->version, TOPIC_ENCODE_OVER); SDB_SET_INT32(pRaw, dataPos, pTopic->sqlLen, TOPIC_ENCODE_OVER); SDB_SET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen, TOPIC_ENCODE_OVER); - SDB_SET_INT32(pRaw, dataPos, logicalPlanLen, TOPIC_ENCODE_OVER); - SDB_SET_BINARY(pRaw, dataPos, pTopic->logicalPlan, logicalPlanLen, TOPIC_ENCODE_OVER); + SDB_SET_INT32(pRaw, dataPos, pTopic->astLen, TOPIC_ENCODE_OVER); + SDB_SET_BINARY(pRaw, dataPos, pTopic->ast, pTopic->astLen, TOPIC_ENCODE_OVER); SDB_SET_INT32(pRaw, dataPos, physicalPlanLen, TOPIC_ENCODE_OVER); SDB_SET_BINARY(pRaw, dataPos, pTopic->physicalPlan, physicalPlanLen, TOPIC_ENCODE_OVER); - void *swBuf = taosMemoryMalloc(swLen); + void *swBuf = taosMemoryMalloc(schemaLen); if (swBuf == NULL) { goto TOPIC_ENCODE_OVER; } void *aswBuf = swBuf; taosEncodeSSchemaWrapper(&aswBuf, &pTopic->schema); - SDB_SET_INT32(pRaw, dataPos, swLen, TOPIC_ENCODE_OVER); - SDB_SET_BINARY(pRaw, dataPos, swBuf, swLen, TOPIC_ENCODE_OVER); + SDB_SET_INT32(pRaw, dataPos, schemaLen, TOPIC_ENCODE_OVER); + SDB_SET_BINARY(pRaw, dataPos, swBuf, schemaLen, TOPIC_ENCODE_OVER); SDB_SET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE, TOPIC_ENCODE_OVER); SDB_SET_DATALEN(pRaw, dataPos, TOPIC_ENCODE_OVER); @@ -138,23 +135,25 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { SDB_GET_INT64(pRaw, dataPos, &pTopic->uid, TOPIC_DECODE_OVER); SDB_GET_INT64(pRaw, dataPos, &pTopic->dbUid, TOPIC_DECODE_OVER); SDB_GET_INT32(pRaw, dataPos, &pTopic->version, TOPIC_DECODE_OVER); - SDB_GET_INT32(pRaw, dataPos, &pTopic->sqlLen, TOPIC_DECODE_OVER); - pTopic->sql = taosMemoryCalloc(pTopic->sqlLen + 1, sizeof(char)); + SDB_GET_INT32(pRaw, dataPos, &pTopic->sqlLen, TOPIC_DECODE_OVER); + pTopic->sql = taosMemoryCalloc(pTopic->sqlLen, sizeof(char)); + if (pTopic->sql == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto TOPIC_DECODE_OVER; + } SDB_GET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen, TOPIC_DECODE_OVER); - SDB_GET_INT32(pRaw, dataPos, &len, TOPIC_DECODE_OVER); - pTopic->logicalPlan = taosMemoryCalloc(len + 1, sizeof(char)); - if (pTopic->logicalPlan == NULL) { + SDB_GET_INT32(pRaw, dataPos, &pTopic->astLen, TOPIC_DECODE_OVER); + pTopic->ast = taosMemoryCalloc(pTopic->astLen, sizeof(char)); + if (pTopic->ast == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto TOPIC_DECODE_OVER; } - SDB_GET_BINARY(pRaw, dataPos, pTopic->logicalPlan, len, TOPIC_DECODE_OVER); - + SDB_GET_BINARY(pRaw, dataPos, pTopic->ast, pTopic->astLen, TOPIC_DECODE_OVER); SDB_GET_INT32(pRaw, dataPos, &len, TOPIC_DECODE_OVER); - pTopic->physicalPlan = taosMemoryCalloc(len + 1, sizeof(char)); + pTopic->physicalPlan = taosMemoryCalloc(len, sizeof(char)); if (pTopic->physicalPlan == NULL) { - taosMemoryFree(pTopic->logicalPlan); terrno = TSDB_CODE_OUT_OF_MEMORY; goto TOPIC_DECODE_OVER; } @@ -258,6 +257,7 @@ static int32_t mndCheckCreateTopicReq(SCMCreateTopicReq *pCreate) { return 0; } +#if 0 static int32_t mndGetPlanString(const SCMCreateTopicReq *pCreate, char **pStr) { if (NULL == pCreate->ast) { return TSDB_CODE_SUCCESS; @@ -280,6 +280,7 @@ static int32_t mndGetPlanString(const SCMCreateTopicReq *pCreate, char **pStr) { terrno = code; return code; } +#endif static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq *pCreate, SDbObj *pDb) { mDebug("topic:%s to create", pCreate->name); @@ -291,32 +292,39 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq topicObj.uid = mndGenerateUid(pCreate->name, strlen(pCreate->name)); topicObj.dbUid = pDb->uid; topicObj.version = 1; - topicObj.sql = pCreate->sql; - topicObj.physicalPlan = ""; - topicObj.logicalPlan = ""; - topicObj.sqlLen = strlen(pCreate->sql); - - char *pPlanStr = NULL; - if (TSDB_CODE_SUCCESS != mndGetPlanString(pCreate, &pPlanStr)) { - mError("topic:%s, failed to get plan since %s", pCreate->name, terrstr()); + topicObj.sql = strdup(pCreate->sql); + topicObj.sqlLen = strlen(pCreate->sql) + 1; + topicObj.ast = strdup(pCreate->ast); + topicObj.astLen = strlen(pCreate->ast) + 1; + + SNode *pAst = NULL; + if (nodesStringToNode(pCreate->ast, &pAst) != 0) { + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); return -1; } - if (NULL != pPlanStr) { - topicObj.physicalPlan = pPlanStr; - } - SNode *pAst = NULL; - if (nodesStringToNode(pCreate->ast, &pAst) < 0) { + SQueryPlan *pPlan = NULL; + + SPlanContext cxt = {.pAstRoot = pAst, .topicQuery = true}; + if (qCreateQueryPlan(&cxt, &pPlan, NULL) != 0) { + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); return -1; } + if (qExtractResultSchema(pAst, &topicObj.schema.nCols, &topicObj.schema.pSchema) != 0) { + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + + if (nodesNodeToString(pPlan, false, &topicObj.physicalPlan, NULL) != 0) { + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); return -1; } STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_TOPIC, &pReq->rpcMsg); if (pTrans == NULL) { mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); - taosMemoryFreeClear(pPlanStr); + taosMemoryFreeClear(topicObj.physicalPlan); return -1; } mDebug("trans:%d, used to create topic:%s", pTrans->id, pCreate->name); @@ -324,7 +332,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq SSdbRaw *pRedoRaw = mndTopicActionEncode(&topicObj); if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr()); - taosMemoryFreeClear(pPlanStr); + taosMemoryFreeClear(topicObj.physicalPlan); mndTransDrop(pTrans); return -1; } @@ -332,12 +340,12 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq if (mndTransPrepare(pMnode, pTrans) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - taosMemoryFreeClear(pPlanStr); + taosMemoryFreeClear(topicObj.physicalPlan); mndTransDrop(pTrans); return -1; } - taosMemoryFreeClear(pPlanStr); + taosMemoryFreeClear(topicObj.physicalPlan); mndTransDrop(pTrans); return 0; } @@ -501,50 +509,6 @@ static int32_t mndGetNumOfTopics(SMnode *pMnode, char *dbName, int32_t *pNumOfTo return 0; } -static int32_t mndGetTopicMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - SMnode *pMnode = pReq->pNode; - SSdb *pSdb = pMnode->pSdb; - - if (mndGetNumOfTopics(pMnode, pShow->db, &pShow->numOfRows) != 0) { - return -1; - } - - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "name"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "create_time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "sql"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = sdbGetSize(pSdb, SDB_TOPIC); - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - - return 0; -} - static int32_t mndRetrieveTopic(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; @@ -595,8 +559,7 @@ static int32_t mndRetrieveTopic(SNodeMsg *pReq, SShowObj *pShow, char *data, int } mndReleaseDb(pMnode, pDb); - pShow->numOfReads += numOfRows; - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); + pShow->numOfRows += numOfRows; return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index cfaaa304a9bf864b902883c0b3eaf2e67eed3db0..537ddc03c3df0bc999ae07c86d059ef2582ec409 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -58,7 +58,6 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans); static int32_t mndProcessTransReq(SNodeMsg *pReq); static int32_t mndProcessKillTransReq(SNodeMsg *pReq); -static int32_t mndGetTransMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); static int32_t mndRetrieveTrans(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter); @@ -74,7 +73,7 @@ int32_t mndInitTrans(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_MND_TRANS_TIMER, mndProcessTransReq); mndSetMsgHandle(pMnode, TDMT_MND_KILL_TRANS, mndProcessKillTransReq); - mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndRetrieveTrans); +// mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndRetrieveTrans); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TRANS, mndCancelGetNextTrans); return sdbSetTable(pMnode->pSdb, table); } @@ -1260,69 +1259,6 @@ void mndTransPullup(SMnode *pMnode) { sdbWriteFile(pMnode->pSdb); } -static int32_t mndGetTransMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - SMnode *pMnode = pReq->pNode; - SSdb *pSdb = pMnode->pSdb; - - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "id"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "create_time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_TRANS_STAGE_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "stage"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = (TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "db"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_TRANS_TYPE_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "type"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "last_exec_time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "last_error"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = sdbGetSize(pSdb, SDB_TRANS); - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - return 0; -} - static int32_t mndRetrieveTrans(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; @@ -1370,8 +1306,7 @@ static int32_t mndRetrieveTrans(SNodeMsg *pReq, SShowObj *pShow, char *data, int sdbRelease(pSdb, pTrans); } - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); - pShow->numOfReads += numOfRows; + pShow->numOfRows += numOfRows; return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 6e1aae64ab0c86fb5e7cbab31d85e800f552cebb..054bff466cf9d7365b0f1907a98340b319aa1355 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -35,8 +35,7 @@ static int32_t mndProcessCreateUserReq(SNodeMsg *pReq); static int32_t mndProcessAlterUserReq(SNodeMsg *pReq); static int32_t mndProcessDropUserReq(SNodeMsg *pReq); static int32_t mndProcessGetUserAuthReq(SNodeMsg *pReq); -static int32_t mndGetUserMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); -static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); static void mndCancelGetNextUser(SMnode *pMnode, void *pIter); int32_t mndInitUser(SMnode *pMnode) { @@ -640,53 +639,7 @@ GET_AUTH_OVER: return code; } -static int32_t mndGetUserMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - SMnode *pMnode = pReq->pNode; - SSdb *pSdb = pMnode->pSdb; - - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "name"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 10 + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "privilege"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "create_time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "account"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = sdbGetSize(pSdb, SDB_USER); - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - - return 0; -} - -static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { +static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; @@ -699,35 +652,35 @@ static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, char *data, int if (pShow->pIter == NULL) break; cols = 0; + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, cols); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pUser->user, pShow->bytes[cols]); - cols++; + char name[TSDB_USER_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_WITH_MAXSIZE_TO_VARSTR(name, pUser->user, pShow->bytes[cols]); + + colDataAppend(pColInfo, numOfRows, (const char*) name, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - if (pUser->superUser) { - const char *src = "super"; - STR_WITH_SIZE_TO_VARSTR(pWrite, src, strlen(src)); - } else { - const char *src = "normal"; - STR_WITH_SIZE_TO_VARSTR(pWrite, src, strlen(src)); - } cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols); + + const char* src = pUser->superUser? "super":"normal"; + char b[10+VARSTR_HEADER_SIZE] = {0}; + STR_WITH_SIZE_TO_VARSTR(b, src, strlen(src)); + colDataAppend(pColInfo, numOfRows, (const char*) b, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int64_t *)pWrite = pUser->createdTime; cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols); + colDataAppend(pColInfo, numOfRows, (const char*) &pUser->createdTime, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pUser->acct, pShow->bytes[cols]); cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols); + STR_WITH_MAXSIZE_TO_VARSTR(name, pUser->acct, pShow->bytes[cols]); + colDataAppend(pColInfo, numOfRows, (const char*) name, false); numOfRows++; sdbRelease(pSdb, pUser); } - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); - pShow->numOfReads += numOfRows; + pShow->numOfRows += numOfRows; return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index bbe1760febfffab36c6a12fb8d0995061f1ebe7c..dcb48c95a7214199c15f9cbb55f9e2a6d1b4ccf9 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -35,10 +35,9 @@ static int32_t mndProcessDropVnodeRsp(SNodeMsg *pRsp); static int32_t mndProcessSyncVnodeRsp(SNodeMsg *pRsp); static int32_t mndProcessCompactVnodeRsp(SNodeMsg *pRsp); -static int32_t mndGetVgroupMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); -static int32_t mndRetrieveVgroups(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndRetrieveVgroups(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); static void mndCancelGetNextVgroup(SMnode *pMnode, void *pIter); -static int32_t mndRetrieveVnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndRetrieveVnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); static void mndCancelGetNextVnode(SMnode *pMnode, void *pIter); int32_t mndInitVgroup(SMnode *pMnode) { @@ -499,64 +498,12 @@ static int32_t mndGetVgroupMaxReplica(SMnode *pMnode, char *dbName, int8_t *pRep return 0; } -static int32_t mndGetVgroupMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - SMnode *pMnode = pReq->pNode; - SSdb *pSdb = pMnode->pSdb; - - if (mndGetVgroupMaxReplica(pMnode, pShow->db, &pShow->replica, &pShow->numOfRows) != 0) { - return -1; - } - - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "vgId"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "tables"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - for (int32_t i = 0; i < pShow->replica; ++i) { - pShow->bytes[cols] = 2; - pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; - snprintf(pSchema[cols].name, TSDB_COL_NAME_LEN, "v%d_dnode", i + 1); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 9 + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - snprintf(pSchema[cols].name, TSDB_COL_NAME_LEN, "v%d_status", i + 1); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - } - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - - return 0; -} - -static int32_t mndRetrieveVgroups(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { +static int32_t mndRetrieveVgroups(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; SVgObj *pVgroup = NULL; int32_t cols = 0; - char *pWrite; SDbObj *pDb = NULL; if (strlen(pShow->db) > 0) { @@ -575,46 +522,61 @@ static int32_t mndRetrieveVgroups(SNodeMsg *pReq, SShowObj *pShow, char *data, i } cols = 0; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int32_t *)pWrite = pVgroup->vgId; - cols++; + SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pVgroup->vgId, false); SName name = {0}; - char db[TSDB_DB_NAME_LEN] = {0}; - tNameFromString(&name, pVgroup->dbName, T_NAME_ACCT|T_NAME_DB); - tNameGetDbName(&name, db); - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_TO_VARSTR(pWrite, db); - cols++; - - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int32_t *)pWrite = pVgroup->numOfTables; - cols++; - - //status - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_TO_VARSTR(pWrite, "ready"); // TODO - cols++; - - //onlines - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int32_t *)pWrite = pVgroup->replica; - cols++; - - - for (int32_t i = 0; i < pVgroup->replica; ++i) { - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(int16_t *)pWrite = pVgroup->vnodeGid[i].dnodeId; - cols++; - - const char *role = mndGetRoleStr(pVgroup->vnodeGid[i].role); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, role, pShow->bytes[cols]); - cols++; + char db[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + tNameFromString(&name, pVgroup->dbName, T_NAME_ACCT | T_NAME_DB); + tNameGetDbName(&name, varDataVal(db)); + varDataSetLen(db, strlen(varDataVal(db))); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)db, false); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pVgroup->numOfTables, false); + + // status + char buf[10] = {0}; + STR_TO_VARSTR(buf, "ready"); // TODO + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, buf, false); + + // onlines + int32_t onlines = pVgroup->replica; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&onlines, false); + + // default 3 replica + for (int32_t i = 0; i < 3; ++i) { + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + if (i < pVgroup->replica) { + colDataAppend(pColInfo, numOfRows, (const char *)&pVgroup->vnodeGid[i].dnodeId, false); + + char buf1[20] = {0}; + const char *role = mndGetRoleStr(pVgroup->vnodeGid[i].role); + STR_WITH_MAXSIZE_TO_VARSTR(buf1, role, pShow->bytes[cols]); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)buf1, false); + } else { + colDataAppendNULL(pColInfo, numOfRows); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppendNULL(pColInfo, numOfRows); + } } + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppendNULL(pColInfo, numOfRows); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppendNULL(pColInfo, numOfRows); + + pColInfo = taosArrayGet(pBlock->pDataBlock, cols); + colDataAppendNULL(pColInfo, numOfRows); + numOfRows++; sdbRelease(pSdb, pVgroup); } @@ -623,8 +585,7 @@ static int32_t mndRetrieveVgroups(SNodeMsg *pReq, SShowObj *pShow, char *data, i mndReleaseDb(pMnode, pDb); } - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); - pShow->numOfReads += numOfRows; + pShow->numOfRows += numOfRows; return numOfRows; } @@ -653,12 +614,11 @@ int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId) { return numOfVnodes; } -static int32_t mndRetrieveVnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { +static int32_t mndRetrieveVnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; SVgObj *pVgroup = NULL; - char *pWrite; int32_t cols = 0; // int32_t dnodeId = pShow->replica; @@ -670,30 +630,29 @@ static int32_t mndRetrieveVnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, in SVnodeGid *pVgid = &pVgroup->vnodeGid[i]; cols = 0; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(uint32_t *)pWrite = pVgroup->vgId; - cols++; + SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pVgroup->vgId, false); SName name = {0}; - char db[TSDB_DB_NAME_LEN] = {0}; - tNameFromString(&name, pVgroup->dbName, T_NAME_ACCT|T_NAME_DB); - tNameGetDbName(&name, db); + char db[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + tNameFromString(&name, pVgroup->dbName, T_NAME_ACCT | T_NAME_DB); + tNameGetDbName(&name, varDataVal(db)); + varDataSetLen(db, strlen(varDataVal(db))); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_TO_VARSTR(pWrite, db); - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)db, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(uint32_t *)pWrite = 0; //todo: Tables - cols++; + uint32_t val = 0; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&val, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_TO_VARSTR(pWrite, mndGetRoleStr(pVgid->role)); - cols++; + char buf[20] = {0}; + STR_TO_VARSTR(buf, mndGetRoleStr(pVgid->role)); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)buf, false); - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - *(uint32_t *)pWrite = pVgroup->replica; //onlines - cols++; + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + colDataAppend(pColInfo, numOfRows, (const char *)&pVgroup->replica, false); // onlines numOfRows++; } @@ -701,8 +660,7 @@ static int32_t mndRetrieveVnodes(SNodeMsg *pReq, SShowObj *pShow, char *data, in sdbRelease(pSdb, pVgroup); } - mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow); - pShow->numOfReads += numOfRows; + pShow->numOfRows += numOfRows; return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 5a1780530c257cc7c37ac11cbcd1f40db383481d..f765b0ce113615d31195b3f3682f5858678eb00d 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -40,6 +40,7 @@ #include "mndUser.h" #include "mndVgroup.h" #include "mndQuery.h" +#include "mndGrant.h" #define MQ_TIMER_MS 3000 #define TRNAS_TIMER_MS 6000 @@ -197,6 +198,7 @@ static int32_t mndInitSteps(SMnode *pMnode, bool deploy) { if (mndAllocStep(pMnode, "mnode-qnode", mndInitBnode, mndCleanupBnode) != 0) return -1; if (mndAllocStep(pMnode, "mnode-dnode", mndInitDnode, mndCleanupDnode) != 0) return -1; if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return -1; + if (mndAllocStep(pMnode, "mnode-grant", mndInitGrant, mndCleanupGrant) != 0) return -1; if (mndAllocStep(pMnode, "mnode-auth", mndInitAuth, mndCleanupAuth) != 0) return -1; if (mndAllocStep(pMnode, "mnode-acct", mndInitAcct, mndCleanupAcct) != 0) return -1; if (mndAllocStep(pMnode, "mnode-stream", mndInitStream, mndCleanupStream) != 0) return -1; @@ -220,7 +222,6 @@ static int32_t mndInitSteps(SMnode *pMnode, bool deploy) { if (mndAllocStep(pMnode, "mnode-query", mndInitQuery, mndCleanupQuery) != 0) return -1; if (mndAllocStep(pMnode, "mnode-sync", mndInitSync, mndCleanupSync) != 0) return -1; if (mndAllocStep(pMnode, "mnode-telem", mndInitTelem, mndCleanupTelem) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-timer", NULL, mndCleanupTimer) != 0) return -1; return 0; } @@ -346,6 +347,8 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption) { int32_t mndStart(SMnode *pMnode) { return mndInitTimer(pMnode); } +void mndStop(SMnode *pMnode) { return mndCleanupTimer(pMnode); } + int32_t mndProcessMsg(SNodeMsg *pMsg) { SMnode *pMnode = pMsg->pNode; SRpcMsg *pRpc = &pMsg->rpcMsg; diff --git a/source/dnode/mnode/impl/test/CMakeLists.txt b/source/dnode/mnode/impl/test/CMakeLists.txt index d2aa44f37246362ed4a7e6ed48273edf4f921b8f..9b669b303ad0b3c2f30b6f5162bf1d44f35f6d3e 100644 --- a/source/dnode/mnode/impl/test/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/CMakeLists.txt @@ -1,17 +1,17 @@ enable_testing() #add_subdirectory(user) -#add_subdirectory(acct) +add_subdirectory(acct) #add_subdirectory(trans) #add_subdirectory(qnode) #add_subdirectory(snode) -#add_subdirectory(bnode) +add_subdirectory(bnode) #add_subdirectory(show) #add_subdirectory(profile) -add_subdirectory(dnode) +#add_subdirectory(dnode) #add_subdirectory(mnode) -add_subdirectory(db) -add_subdirectory(stb) +#add_subdirectory(db) +#add_subdirectory(stb) #add_subdirectory(sma) #add_subdirectory(func) #add_subdirectory(topic) diff --git a/source/dnode/mnode/impl/test/acct/CMakeLists.txt b/source/dnode/mnode/impl/test/acct/CMakeLists.txt index 8c8bf54bc4f59b7146f479abded66ab8fa1c271f..40f8b0726e28446170a71bbbccde979376448fbb 100644 --- a/source/dnode/mnode/impl/test/acct/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/acct/CMakeLists.txt @@ -1,11 +1,11 @@ -aux_source_directory(. ACCT_SRC) -add_executable(mnode_test_acct ${ACCT_SRC}) +aux_source_directory(. MNODE_ACCT_TEST_SRC) +add_executable(acctTest ${MNODE_ACCT_TEST_SRC}) target_link_libraries( - mnode_test_acct + acctTest PUBLIC sut ) add_test( - NAME mnode_test_acct - COMMAND mnode_test_acct + NAME acctTest + COMMAND acctTest ) diff --git a/source/dnode/mnode/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp index 2bc4f40614409c2dfbe99b6bd524dfcda361ee26..0260b5f59ebf1468be576a9192566b0bbb7d1698 100644 --- a/source/dnode/mnode/impl/test/acct/acct.cpp +++ b/source/dnode/mnode/impl/test/acct/acct.cpp @@ -54,17 +54,3 @@ TEST_F(MndTestAcct, 03_Drop_Acct) { ASSERT_NE(pRsp, nullptr); ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } - -TEST_F(MndTestAcct, 04_Show_Acct) { - SShowReq showReq = {0}; - showReq.type = TSDB_MGMT_TABLE_ACCT; - - int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq); - void* pReq = rpcMallocCont(contLen); - tSerializeSShowReq(pReq, contLen, &showReq); - tFreeSShowReq(&showReq); - - SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen); - ASSERT_NE(pRsp, nullptr); - ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_MSG_TYPE); -} \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/bnode/CMakeLists.txt b/source/dnode/mnode/impl/test/bnode/CMakeLists.txt index b58b1a856bd4201de19a9c5898786cb2c2814886..310e022a911d4c7cde35e1c804f6c13be696b4f1 100644 --- a/source/dnode/mnode/impl/test/bnode/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/bnode/CMakeLists.txt @@ -1,11 +1,11 @@ -aux_source_directory(. STEST_SRC) -add_executable(mnode_test_bnode ${STEST_SRC}) +aux_source_directory(. MNODE_BNODE_TEST_SRC) +add_executable(mbnodeTest ${MNODE_BNODE_TEST_SRC}) target_link_libraries( - mnode_test_bnode + mbnodeTest PUBLIC sut ) add_test( - NAME mnode_test_bnode - COMMAND mnode_test_bnode + NAME mbnodeTest + COMMAND mbnodeTest ) diff --git a/source/dnode/mnode/impl/test/bnode/bnode.cpp b/source/dnode/mnode/impl/test/bnode/mbnode.cpp similarity index 88% rename from source/dnode/mnode/impl/test/bnode/bnode.cpp rename to source/dnode/mnode/impl/test/bnode/mbnode.cpp index 33816520f2c4d19eb70d296c7a307316cfc06ebf..5e08a9995dde914e0488078e8403b0c39924963f 100644 --- a/source/dnode/mnode/impl/test/bnode/bnode.cpp +++ b/source/dnode/mnode/impl/test/bnode/mbnode.cpp @@ -39,14 +39,7 @@ Testbase MndTestBnode::test; TestServer MndTestBnode::server2; TEST_F(MndTestBnode, 01_Show_Bnode) { - test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, ""); - CHECK_META("show bnodes", 3); - - CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); - CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); - CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - - test.SendShowRetrieveReq(); + test.SendShowReq(TSDB_MGMT_TABLE_BNODE, "bnodes", ""); EXPECT_EQ(test.GetShowRows(), 0); } @@ -76,14 +69,8 @@ TEST_F(MndTestBnode, 02_Create_Bnode) { ASSERT_NE(pRsp, nullptr); ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, ""); - CHECK_META("show bnodes", 3); - test.SendShowRetrieveReq(); + test.SendShowReq(TSDB_MGMT_TABLE_BNODE, "bnodes", ""); EXPECT_EQ(test.GetShowRows(), 1); - - CheckInt16(1); - CheckBinary("localhost:9018", TSDB_EP_LEN); - CheckTimestamp(); } { @@ -115,8 +102,7 @@ TEST_F(MndTestBnode, 03_Drop_Bnode) { ASSERT_EQ(pRsp->code, 0); taosMsleep(1300); - test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); - test.SendShowRetrieveReq(); + test.SendShowReq(TSDB_MGMT_TABLE_DNODE, "dnodes", ""); EXPECT_EQ(test.GetShowRows(), 2); } @@ -132,16 +118,8 @@ TEST_F(MndTestBnode, 03_Drop_Bnode) { ASSERT_NE(pRsp, nullptr); ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, ""); - test.SendShowRetrieveReq(); + test.SendShowReq(TSDB_MGMT_TABLE_BNODE, "bnodes", ""); EXPECT_EQ(test.GetShowRows(), 2); - - CheckInt16(1); - CheckInt16(2); - CheckBinary("localhost:9018", TSDB_EP_LEN); - CheckBinary("localhost:9019", TSDB_EP_LEN); - CheckTimestamp(); - CheckTimestamp(); } { @@ -156,13 +134,8 @@ TEST_F(MndTestBnode, 03_Drop_Bnode) { ASSERT_NE(pRsp, nullptr); ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, ""); - test.SendShowRetrieveReq(); + test.SendShowReq(TSDB_MGMT_TABLE_BNODE, "bnodes", ""); EXPECT_EQ(test.GetShowRows(), 1); - - CheckInt16(1); - CheckBinary("localhost:9018", TSDB_EP_LEN); - CheckTimestamp(); } { diff --git a/source/dnode/mnode/impl/test/db/CMakeLists.txt b/source/dnode/mnode/impl/test/db/CMakeLists.txt index d1e38854e6f0e7a181c0801bfd76b7249b03a226..1a5b4d39363ebd258b7a6c3976d4f2d4901766b1 100644 --- a/source/dnode/mnode/impl/test/db/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/db/CMakeLists.txt @@ -1,7 +1,7 @@ -aux_source_directory(. DB_SRC) -add_executable(mnode_test_db ${DB_SRC}) +aux_source_directory(. MNODE_DB_TEST_SRC) +add_executable(dbTest ${MNODE_DB_TEST_SRC}) target_link_libraries( - mnode_test_db + dbTest PUBLIC sut ) diff --git a/source/dnode/mnode/impl/test/dnode/CMakeLists.txt b/source/dnode/mnode/impl/test/dnode/CMakeLists.txt index 77cc6f0b5dbefe7dcf4c7de2e836188e19c51c13..16e08d6c35d3fe85a4cbb8e5e981150c61acb79b 100644 --- a/source/dnode/mnode/impl/test/dnode/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/dnode/CMakeLists.txt @@ -1,7 +1,7 @@ -aux_source_directory(. DTEST_SRC) -add_executable(mnode_test_dnode ${DTEST_SRC}) +aux_source_directory(. MNODE_DNODE_TEST_SRC) +add_executable(mdnodeTest ${MNODE_DNODE_TEST_SRC}) target_link_libraries( - mnode_test_dnode + mdnodeTest PUBLIC sut ) diff --git a/source/dnode/mnode/impl/test/dnode/dnode.cpp b/source/dnode/mnode/impl/test/dnode/mdnode.cpp similarity index 100% rename from source/dnode/mnode/impl/test/dnode/dnode.cpp rename to source/dnode/mnode/impl/test/dnode/mdnode.cpp diff --git a/source/dnode/mnode/impl/test/stb/CMakeLists.txt b/source/dnode/mnode/impl/test/stb/CMakeLists.txt index eca922acc43da5f3fd737c8add16854c6a781e99..70e20d3411667cd293c98a137cf52b81ba908ff0 100644 --- a/source/dnode/mnode/impl/test/stb/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/stb/CMakeLists.txt @@ -1,7 +1,7 @@ -aux_source_directory(. STB_SRC) -add_executable(mnode_test_stb ${STB_SRC}) +aux_source_directory(. MNODE_STB_TEST_SRC) +add_executable(stbTest ${MNODE_STB_TEST_SRC}) target_link_libraries( - mnode_test_stb + stbTest PUBLIC sut ) diff --git a/source/dnode/mnode/impl/test/topic/topic.cpp b/source/dnode/mnode/impl/test/topic/topic.cpp index 5d603ab5b2059f384975234ad46a0c5af877d968..2111d61e3f1838bc25ebc00ccb3d968496b81c66 100644 --- a/source/dnode/mnode/impl/test/topic/topic.cpp +++ b/source/dnode/mnode/impl/test/topic/topic.cpp @@ -88,6 +88,8 @@ void* MndTestTopic::BuildDropTopicReq(const char* topicName, int32_t* pContLen) } TEST_F(MndTestTopic, 01_Create_Topic) { + // TODO add valid ast for unit test +#if 0 const char* dbname = "1.d1"; const char* topicName = "1.d1.t1"; @@ -99,7 +101,7 @@ TEST_F(MndTestTopic, 01_Create_Topic) { ASSERT_EQ(pRsp->code, 0); } - { test.SendShowMetaReq(TSDB_MGMT_TABLE_TP, ""); } + { test.SendShowMetaReq(TSDB_MGMT_TABLE_TOPICS, ""); } { int32_t contLen = 0; @@ -126,7 +128,7 @@ TEST_F(MndTestTopic, 01_Create_Topic) { } { - test.SendShowMetaReq(TSDB_MGMT_TABLE_TP, dbname); + test.SendShowMetaReq(TSDB_MGMT_TABLE_TOPICS, dbname); CHECK_META("show topics", 3); CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, "name"); @@ -143,7 +145,7 @@ TEST_F(MndTestTopic, 01_Create_Topic) { // restart test.Restart(); - test.SendShowMetaReq(TSDB_MGMT_TABLE_TP, dbname); + test.SendShowMetaReq(TSDB_MGMT_TABLE_TOPICS, dbname); test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); @@ -167,8 +169,9 @@ TEST_F(MndTestTopic, 01_Create_Topic) { ASSERT_NE(pRsp, nullptr); ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TOPIC_NOT_EXIST); - test.SendShowMetaReq(TSDB_MGMT_TABLE_TP, dbname); + test.SendShowMetaReq(TSDB_MGMT_TABLE_TOPICS, dbname); test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 0); } +#endif } diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp index 40b052400ba558e8fd29ae9a889049ba3405ed6d..560b30d13c5d16a2ccc5a63c50c27166de7b65b4 100644 --- a/source/dnode/mnode/impl/test/trans/trans.cpp +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -38,7 +38,7 @@ class MndTestTrans : public ::testing::Test { test.ServerStop(); - pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); int32_t writeLen = taosWriteFile(pFile, buffer, readLen); if (writeLen < 0 || writeLen == readLen) { ASSERT(1); diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index c11025beedfa8cbb5d8e032a28cef26319ae6d9a..f61899766e1bdefcd6272812d6c8d8fc29ae9465 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -232,7 +232,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) { mDebug("start to write file:%s, current ver:%" PRId64 ", commit ver:%" PRId64, curfile, pSdb->curVer, pSdb->lastCommitVer); - TdFilePtr pFile = taosOpenFile(tmpfile, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(tmpfile, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); mError("failed to open file:%s for write since %s", tmpfile, terrstr()); diff --git a/source/dnode/qnode/src/qnode.c b/source/dnode/qnode/src/qnode.c index 0d1e890097e93eef19a1500eba0794ca0452d57c..7b299f1f3ce3fca46e2205f3a8c0226096ada826 100644 --- a/source/dnode/qnode/src/qnode.c +++ b/source/dnode/qnode/src/qnode.c @@ -73,10 +73,6 @@ int32_t qndProcessFetchMsg(SQnode *pQnode, SRpcMsg *pMsg) { return qWorkerProcessCancelMsg(pQnode, pQnode->pQuery, pMsg); case TDMT_VND_DROP_TASK: return qWorkerProcessDropMsg(pQnode, pQnode->pQuery, pMsg); - case TDMT_VND_SHOW_TABLES: - return qWorkerProcessShowMsg(pQnode, pQnode->pQuery, pMsg); - case TDMT_VND_SHOW_TABLES_FETCH: - // return vnodeGetTableList(pQnode, pMsg); case TDMT_VND_TABLE_META: // return vnodeGetTableMeta(pQnode, pMsg); case TDMT_VND_CONSUME: diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index b5fe7d460f6dc2ea8406dc4de2e2cc69badaaffb..3ab007e3a2335685c2bcf4f262e324ee875a2a6b 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -6,30 +6,27 @@ target_sources( # vnode "src/vnd/vnodeArenaMAImpl.c" "src/vnd/vnodeBufferPool.c" + # "src/vnd/vnodeBufferPool2.c" "src/vnd/vnodeCfg.c" "src/vnd/vnodeCommit.c" "src/vnd/vnodeInt.c" "src/vnd/vnodeMain.c" - "src/vnd/vnodeMgr.c" "src/vnd/vnodeQuery.c" "src/vnd/vnodeStateMgr.c" "src/vnd/vnodeWrite.c" + "src/vnd/vnodeModule.c" + "src/vnd/vnodeSvr.c" # meta # "src/meta/metaBDBImpl.c" - "src/meta/metaCache.c" - "src/meta/metaCfg.c" "src/meta/metaIdx.c" "src/meta/metaMain.c" - "src/meta/metaQuery.c" "src/meta/metaTable.c" - "src/meta/metaTbCfg.c" - "src/meta/metaTbTag.c" "src/meta/metaTbUid.c" "src/meta/metaTDBImpl.c" # tsdb - # "src/tsdb/tsdbBDBImpl.c" + "src/tsdb/tsdbTDBImpl.c" "src/tsdb/tsdbCommit.c" "src/tsdb/tsdbCompact.c" "src/tsdb/tsdbFile.c" @@ -40,7 +37,7 @@ target_sources( "src/tsdb/tsdbRead.c" "src/tsdb/tsdbReadImpl.c" "src/tsdb/tsdbScan.c" - # "src/tsdb/tsdbSma.c" + "src/tsdb/tsdbSma.c" "src/tsdb/tsdbWrite.c" # tq @@ -55,6 +52,8 @@ target_include_directories( vnode PUBLIC "inc" PRIVATE "src/inc" + PUBLIC "${TD_SOURCE_DIR}/include/libs/scalar" + ) target_link_libraries( vnode @@ -69,6 +68,7 @@ target_link_libraries( PUBLIC scheduler PUBLIC tdb #PUBLIC bdb + #PUBLIC scalar PUBLIC transport PUBLIC stream ) diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 113501a26b41fba6846a3299e13a946189e36188..76fc09ca1df69902f3df9249a920abbbdd779d02 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -25,82 +25,101 @@ #include "tfs.h" #include "wal.h" +#include "tcommon.h" +#include "tfs.h" #include "tmallocator.h" #include "tmsg.h" #include "trow.h" -#include "tmallocator.h" -#include "tcommon.h" -#include "tfs.h" #ifdef __cplusplus extern "C" { #endif -/* ------------------------ TYPES EXPOSED ------------------------ */ -typedef struct SMgmtWrapper SMgmtWrapper; -typedef struct SVnode SVnode; - -#define META_SUPER_TABLE TD_SUPER_TABLE -#define META_CHILD_TABLE TD_CHILD_TABLE -#define META_NORMAL_TABLE TD_NORMAL_TABLE +// vnode +typedef struct SVnode SVnode; +typedef struct SMetaCfg SMetaCfg; // todo: remove +typedef struct STsdbCfg STsdbCfg; // todo: remove +typedef struct STqCfg STqCfg; // todo: remove +typedef struct SVnodeCfg SVnodeCfg; -// Types exported -typedef struct SMeta SMeta; - -typedef struct SMetaCfg { - /// LRU cache size - uint64_t lruSize; -} SMetaCfg; +int vnodeInit(); +void vnodeCleanup(); +SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg); +void vnodeClose(SVnode *pVnode); +void vnodeDestroy(const char *path); +void vnodePreprocessWriteReqs(SVnode *pVnode, SArray *pMsgs); +int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); +int vnodeProcessCMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); +int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); +int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg); +int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo); +int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg); +int32_t vnodeCompact(SVnode *pVnode); +int32_t vnodeSync(SVnode *pVnode); +int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad); +int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName); -typedef struct SMTbCursor SMTbCursor; -typedef struct SMCtbCursor SMCtbCursor; -typedef struct SMSmaCursor SMSmaCursor; +// meta +typedef struct SMeta SMeta; // todo: remove +typedef struct SMTbCursor SMTbCursor; typedef SVCreateTbReq STbCfg; typedef SVCreateTSmaReq SSmaCfg; -typedef struct SDataStatis { - int16_t colId; - int16_t maxIndex; - int16_t minIndex; - int16_t numOfNull; - int64_t sum; - int64_t max; - int64_t min; -} SDataStatis; - -typedef struct STsdbQueryCond { - STimeWindow twindow; - int32_t order; // desc|asc order to iterate the data block - int32_t numOfCols; - SColumnInfo *colList; - bool loadExternalRows; // load external rows or not - int32_t type; // data block load type: -} STsdbQueryCond; - -typedef struct { - TSKEY lastKey; - uint64_t uid; -} STableKeyInfo; - +SMTbCursor *metaOpenTbCursor(SMeta *pMeta); +void metaCloseTbCursor(SMTbCursor *pTbCur); +char *metaTbCursorNext(SMTbCursor *pTbCur); + +// tsdb +typedef struct STsdb STsdb; +typedef struct SDataStatis SDataStatis; +typedef struct STsdbQueryCond STsdbQueryCond; +typedef void *tsdbReaderT; + +#define BLOCK_LOAD_OFFSET_SEQ_ORDER 1 +#define BLOCK_LOAD_TABLE_SEQ_ORDER 2 +#define BLOCK_LOAD_TABLE_RR_ORDER 3 + +tsdbReaderT *tsdbQueryTables(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *tableInfoGroup, uint64_t qId, + uint64_t taskId); +tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, uint64_t qId, + void *pMemRef); +int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT *pReader, STableBlockDistInfo *pTableBlockInfo); +bool isTsdbCacheLastRow(tsdbReaderT *pReader); +int32_t tsdbQuerySTableByTagCond(void *pMeta, uint64_t uid, TSKEY skey, const char *pTagCond, size_t len, + int16_t tagNameRelType, const char *tbnameCond, STableGroupInfo *pGroupInfo, + SColIndex *pColIndex, int32_t numOfCols, uint64_t reqId, uint64_t taskId); +int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT *pHandle); +bool tsdbNextDataBlock(tsdbReaderT pTsdbReadHandle); +void tsdbRetrieveDataBlockInfo(tsdbReaderT *pTsdbReadHandle, SDataBlockInfo *pBlockInfo); +int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SDataStatis **pBlockStatis); +SArray *tsdbRetrieveDataBlock(tsdbReaderT *pTsdbReadHandle, SArray *pColumnIdList); +void tsdbDestroyTableGroup(STableGroupInfo *pGroupList); +int32_t tsdbGetOneTableGroup(void *pMeta, uint64_t uid, TSKEY startKey, STableGroupInfo *pGroupInfo); +int32_t tsdbGetTableGroupFromIdList(STsdb *tsdb, SArray *pTableIdList, STableGroupInfo *pGroupInfo); + +// tq + +typedef struct STqReadHandle STqReadHandle; -typedef struct STable { - uint64_t tid; - uint64_t uid; - STSchema *pSchema; -} STable; +STqReadHandle *tqInitSubmitMsgScanner(SMeta *pMeta); -#define BLOCK_LOAD_OFFSET_SEQ_ORDER 1 -#define BLOCK_LOAD_TABLE_SEQ_ORDER 2 -#define BLOCK_LOAD_TABLE_RR_ORDER 3 +void tqReadHandleSetColIdList(STqReadHandle *pReadHandle, SArray *pColIdList); +int tqReadHandleSetTbUidList(STqReadHandle *pHandle, const SArray *tbUidList); +int tqReadHandleAddTbUidList(STqReadHandle *pHandle, const SArray *tbUidList); +int32_t tqReadHandleSetMsg(STqReadHandle *pHandle, SSubmitReq *pMsg, int64_t ver); +bool tqNextDataBlock(STqReadHandle *pHandle); +int tqRetrieveDataBlockInfo(STqReadHandle *pHandle, SDataBlockInfo *pBlockInfo); +SArray *tqRetrieveDataBlock(STqReadHandle *pHandle); -#define TABLE_TID(t) (t)->tid -#define TABLE_UID(t) (t)->uid +// need to reposition -// TYPES EXPOSED -typedef struct STsdb STsdb; +// structs +struct SMetaCfg { + uint64_t lruSize; +}; -typedef struct STsdbCfg { +struct STsdbCfg { int8_t precision; int8_t update; int8_t compression; @@ -112,15 +131,13 @@ typedef struct STsdbCfg { int32_t keep2; uint64_t lruCacheSize; SArray *retentions; -} STsdbCfg; - +}; -typedef struct { - // TODO +struct STqCfg { int32_t reserved; -} STqCfg; +}; -typedef struct { +struct SVnodeCfg { int32_t vgId; uint64_t dbId; STfs *pTfs; @@ -140,444 +157,31 @@ typedef struct { uint32_t hashBegin; uint32_t hashEnd; int8_t hashMethod; -} SVnodeCfg; - -typedef struct { - int64_t ver; - int64_t tbUid; - SHashObj *tbIdHash; - const SSubmitReq *pMsg; - SSubmitBlk *pBlock; - SSubmitMsgIter msgIter; - SSubmitBlkIter blkIter; - SMeta *pVnodeMeta; - SArray *pColIdList; // SArray - int32_t sver; - SSchemaWrapper *pSchemaWrapper; - STSchema *pSchema; -} STqReadHandle; - -/* ------------------------ SVnode ------------------------ */ -/** - * @brief Initialize the vnode module - * - * @return int 0 for success and -1 for failure - */ -int vnodeInit(); - -/** - * @brief Cleanup the vnode module - * - */ -void vnodeCleanup(); - -/** - * @brief Open a VNODE. - * - * @param path path of the vnode - * @param pVnodeCfg options of the vnode - * @return SVnode* The vnode object - */ -SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg); - -/** - * @brief Close a VNODE - * - * @param pVnode The vnode object to close - */ -void vnodeClose(SVnode *pVnode); - -/** - * @brief Destroy a VNODE. - * - * @param path Path of the VNODE. - */ -void vnodeDestroy(const char *path); - -/** - * @brief Process an array of write messages. - * - * @param pVnode The vnode object. - * @param pMsgs The array of SRpcMsg - */ -void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs); - -/** - * @brief Apply a write request message. - * - * @param pVnode The vnode object. - * @param pMsg The request message - * @param pRsp The response message - * @return int 0 for success, -1 for failure - */ -int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); - -/** - * @brief Process a consume message. - * - * @param pVnode The vnode object. - * @param pMsg The request message - * @param pRsp The response message - * @return int 0 for success, -1 for failure - */ -int vnodeProcessCMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); - -/** - * @brief Process the sync request - * - * @param pVnode - * @param pMsg - * @param pRsp - * @return int - */ -int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); - -/** - * @brief Process a query message. - * - * @param pVnode The vnode object. - * @param pMsg The request message - * @return int 0 for success, -1 for failure - */ -int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg); - -/** - * @brief Process a fetch message. - * - * @param pVnode The vnode object. - * @param pMsg The request message - * @return int 0 for success, -1 for failure - */ -int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo); - -/* ------------------------ SVnodeCfg ------------------------ */ -/** - * @brief Initialize VNODE options. - * - * @param pOptions The options object to be initialized. It should not be NULL. - */ -void vnodeOptionsInit(SVnodeCfg *pOptions); - -/** - * @brief Clear VNODE options. - * - * @param pOptions Options to clear. - */ -void vnodeOptionsClear(SVnodeCfg *pOptions); - -int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName); - -/* ------------------------ FOR COMPILE ------------------------ */ - -int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg); -int32_t vnodeCompact(SVnode *pVnode); -int32_t vnodeSync(SVnode *pVnode); -int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad); +}; -/* ------------------------- TQ READ --------------------------- */ +struct SDataStatis { + int16_t colId; + int16_t maxIndex; + int16_t minIndex; + int16_t numOfNull; + int64_t sum; + int64_t max; + int64_t min; +}; -enum { - TQ_STREAM_TOKEN__DATA = 1, - TQ_STREAM_TOKEN__WATERMARK, - TQ_STREAM_TOKEN__CHECKPOINT, +struct STsdbQueryCond { + STimeWindow twindow; + int32_t order; // desc|asc order to iterate the data block + int32_t numOfCols; + SColumnInfo *colList; + bool loadExternalRows; // load external rows or not + int32_t type; // data block load type: }; typedef struct { - int8_t type; - int8_t reserved[7]; - union { - void *data; - int64_t wmTs; - int64_t checkpointId; - }; -} STqStreamToken; - -STqReadHandle *tqInitSubmitMsgScanner(SMeta *pMeta); - -static FORCE_INLINE void tqReadHandleSetColIdList(STqReadHandle *pReadHandle, SArray *pColIdList) { - pReadHandle->pColIdList = pColIdList; -} - -// static FORCE_INLINE void tqReadHandleSetTbUid(STqReadHandle* pHandle, int64_t tbUid) { -// pHandle->tbUid = tbUid; -//} - -static FORCE_INLINE int tqReadHandleSetTbUidList(STqReadHandle *pHandle, const SArray *tbUidList) { - if (pHandle->tbIdHash) { - taosHashClear(pHandle->tbIdHash); - } - - pHandle->tbIdHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); - if (pHandle->tbIdHash == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - for (int i = 0; i < taosArrayGetSize(tbUidList); i++) { - int64_t *pKey = (int64_t *)taosArrayGet(tbUidList, i); - taosHashPut(pHandle->tbIdHash, pKey, sizeof(int64_t), NULL, 0); - } - - return 0; -} - -static FORCE_INLINE int tqReadHandleAddTbUidList(STqReadHandle *pHandle, const SArray *tbUidList) { - if (pHandle->tbIdHash == NULL) { - pHandle->tbIdHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); - if (pHandle->tbIdHash == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - } - - for (int i = 0; i < taosArrayGetSize(tbUidList); i++) { - int64_t *pKey = (int64_t *)taosArrayGet(tbUidList, i); - taosHashPut(pHandle->tbIdHash, pKey, sizeof(int64_t), NULL, 0); - } - - return 0; -} - -int32_t tqReadHandleSetMsg(STqReadHandle *pHandle, SSubmitReq *pMsg, int64_t ver); -bool tqNextDataBlock(STqReadHandle *pHandle); -int tqRetrieveDataBlockInfo(STqReadHandle *pHandle, SDataBlockInfo *pBlockInfo); -// return SArray -SArray *tqRetrieveDataBlock(STqReadHandle *pHandle); - -// meta.h -SMeta *metaOpen(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF); -void metaClose(SMeta *pMeta); -void metaRemove(const char *path); -int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg); -int metaDropTable(SMeta *pMeta, tb_uid_t uid); -int metaCommit(SMeta *pMeta); -int32_t metaCreateTSma(SMeta *pMeta, SSmaCfg *pCfg); -int32_t metaDropTSma(SMeta *pMeta, int64_t indexUid); -STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid); -STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid); -SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline); -STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver); -STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid); -STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid); -SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup); -int metaGetTbNum(SMeta *pMeta); -SMTbCursor *metaOpenTbCursor(SMeta *pMeta); -void metaCloseTbCursor(SMTbCursor *pTbCur); -char *metaTbCursorNext(SMTbCursor *pTbCur); -SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid); -void metaCloseCtbCurosr(SMCtbCursor *pCtbCur); -tb_uid_t metaCtbCursorNext(SMCtbCursor *pCtbCur); - -SMSmaCursor *metaOpenSmaCursor(SMeta *pMeta, tb_uid_t uid); -void metaCloseSmaCurosr(SMSmaCursor *pSmaCur); -const char *metaSmaCursorNext(SMSmaCursor *pSmaCur); - -// Options -void metaOptionsInit(SMetaCfg *pMetaCfg); -void metaOptionsClear(SMetaCfg *pMetaCfg); - -// query condition to build multi-table data block iterator -// STsdb -STsdb *tsdbOpen(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF, SMeta *pMeta, STfs *pTfs); -void tsdbClose(STsdb *); -void tsdbRemove(const char *path); -int tsdbInsertData(STsdb *pTsdb, SSubmitReq *pMsg, SSubmitRsp *pRsp); -int tsdbPrepareCommit(STsdb *pTsdb); -int tsdbCommit(STsdb *pTsdb); - - -int32_t tsdbInitSma(STsdb *pTsdb); -int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg); -int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg); -/** - * @brief When submit msg received, update the relative expired window synchronously. - * - * @param pTsdb - * @param msg - * @return int32_t - */ -int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, SSubmitReq *pMsg); - -/** - * @brief Insert tSma(Time-range-wise SMA) data from stream computing engine - * - * @param pTsdb - * @param indexUid - * @param msg - * @return int32_t - */ -int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg); - -/** - * @brief Drop tSma data and local cache. - * - * @param pTsdb - * @param indexUid - * @return int32_t - */ -int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid); - -/** - * @brief Insert RSma(Rollup SMA) data. - * - * @param pTsdb - * @param msg - * @return int32_t - */ -int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg); - -// TODO: This is the basic params, and should wrap the params to a queryHandle. -/** - * @brief Get tSma(Time-range-wise SMA) data. - * - * @param pTsdb - * @param pData - * @param indexUid - * @param querySKey - * @param nMaxResult - * @return int32_t - */ -int32_t tsdbGetTSmaData(STsdb *pTsdb, char *pData, int64_t indexUid, TSKEY querySKey, int32_t nMaxResult); - -// STsdbCfg -int tsdbOptionsInit(STsdbCfg *); -void tsdbOptionsClear(STsdbCfg *); - -typedef void* tsdbReaderT; - -/** - * Get the data block iterator, starting from position according to the query condition - * - * @param tsdb tsdb handle - * @param pCond query condition, including time window, result set order, and basic required columns for each block - * @param tableInfoGroup table object list in the form of set, grouped into different sets according to the - * group by condition - * @param qinfo query info handle from query processor - * @return - */ -tsdbReaderT *tsdbQueryTables(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *tableInfoGroup, uint64_t qId, uint64_t taskId); - -/** - * Get the last row of the given query time window for all the tables in STableGroupInfo object. - * Note that only one data block with only row will be returned while invoking retrieve data block function for - * all tables in this group. - * - * @param tsdb tsdb handle - * @param pCond query condition, including time window, result set order, and basic required columns for each block - * @param tableInfo table list. - * @return - */ -//tsdbReaderT tsdbQueryLastRow(STsdbRepo *tsdb, STsdbQueryCond *pCond, STableGroupInfo *tableInfo, uint64_t qId, -// SMemRef *pRef); - - -tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, uint64_t qId, void* pMemRef); - -int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* pReader, STableBlockDistInfo* pTableBlockInfo); - -bool isTsdbCacheLastRow(tsdbReaderT* pReader); - -/** - * - * @param tsdb - * @param uid - * @param skey - * @param pTagCond - * @param len - * @param tagNameRelType - * @param tbnameCond - * @param pGroupInfo - * @param pColIndex - * @param numOfCols - * @param reqId - * @return - */ -int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const char* pTagCond, size_t len, - int16_t tagNameRelType, const char* tbnameCond, STableGroupInfo* pGroupInfo, - SColIndex* pColIndex, int32_t numOfCols, uint64_t reqId, uint64_t taskId); -/** - * get num of rows in mem table - * - * @param pHandle - * @return row size - */ - -int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT* pHandle); - -/** - * move to next block if exists - * - * @param pTsdbReadHandle - * @return - */ -bool tsdbNextDataBlock(tsdbReaderT pTsdbReadHandle); - -/** - * Get current data block information - * - * @param pTsdbReadHandle - * @param pBlockInfo - * @return - */ -void tsdbRetrieveDataBlockInfo(tsdbReaderT *pTsdbReadHandle, SDataBlockInfo *pBlockInfo); - -/** - * - * Get the pre-calculated information w.r.t. current data block. - * - * In case of data block in cache, the pBlockStatis will always be NULL. - * If a block is not completed loaded from disk, the pBlockStatis will be NULL. - - * @pBlockStatis the pre-calculated value for current data blocks. if the block is a cache block, always return 0 - * @return - */ -int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SDataStatis **pBlockStatis); - -/** - * - * The query condition with primary timestamp is passed to iterator during its constructor function, - * the returned data block must be satisfied with the time window condition in any cases, - * which means the SData data block is not actually the completed disk data blocks. - * - * @param pTsdbReadHandle query handle - * @param pColumnIdList required data columns id list - * @return - */ -SArray *tsdbRetrieveDataBlock(tsdbReaderT *pTsdbReadHandle, SArray *pColumnIdList); - -/** - * destroy the created table group list, which is generated by tag query - * @param pGroupList - */ -void tsdbDestroyTableGroup(STableGroupInfo *pGroupList); - -/** - * create the table group result including only one table, used to handle the normal table query - * - * @param tsdb tsdbHandle - * @param uid table uid - * @param pGroupInfo the generated result - * @return - */ -int32_t tsdbGetOneTableGroup(void *pMeta, uint64_t uid, TSKEY startKey, STableGroupInfo *pGroupInfo); - -/** - * - * @param tsdb - * @param pTableIdList - * @param pGroupInfo - * @return - */ -int32_t tsdbGetTableGroupFromIdList(STsdb *tsdb, SArray *pTableIdList, STableGroupInfo *pGroupInfo); - -/** - * clean up the query handle - * @param queryHandle - */ -void tsdbCleanupReadHandle(tsdbReaderT queryHandle); - -int32_t tdScanAndConvertSubmitMsg(SSubmitReq *pMsg); - + TSKEY lastKey; + uint64_t uid; +} STableKeyInfo; #ifdef __cplusplus } diff --git a/source/dnode/vnode/src/inc/meta.h b/source/dnode/vnode/src/inc/meta.h index b04364daf861c32b33a5e4f7a13f56f9ccf25b29..94a1266f46a3f63a95982680a7d628523108091e 100644 --- a/source/dnode/vnode/src/inc/meta.h +++ b/source/dnode/vnode/src/inc/meta.h @@ -20,9 +20,48 @@ extern "C" { #endif -typedef struct SMetaCache SMetaCache; -typedef struct SMetaIdx SMetaIdx; -typedef struct SMetaDB SMetaDB; +typedef struct SMetaCache SMetaCache; +typedef struct SMetaIdx SMetaIdx; +typedef struct SMetaDB SMetaDB; +typedef struct SMCtbCursor SMCtbCursor; +typedef struct SMSmaCursor SMSmaCursor; + +// metaDebug ================== +// clang-format off +#define metaFatal(...) do { if (metaDebugFlag & DEBUG_FATAL) { taosPrintLog("META FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) +#define metaError(...) do { if (metaDebugFlag & DEBUG_ERROR) { taosPrintLog("META ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) +#define metaWarn(...) do { if (metaDebugFlag & DEBUG_WARN) { taosPrintLog("META WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) +#define metaInfo(...) do { if (metaDebugFlag & DEBUG_INFO) { taosPrintLog("META ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) +#define metaDebug(...) do { if (metaDebugFlag & DEBUG_DEBUG) { taosPrintLog("META ", DEBUG_DEBUG, metaDebugFlag, __VA_ARGS__); }} while(0) +#define metaTrace(...) do { if (metaDebugFlag & DEBUG_TRACE) { taosPrintLog("META ", DEBUG_TRACE, metaDebugFlag, __VA_ARGS__); }} while(0) +// clang-format on + +#define META_SUPER_TABLE TD_SUPER_TABLE +#define META_CHILD_TABLE TD_CHILD_TABLE +#define META_NORMAL_TABLE TD_NORMAL_TABLE + +SMeta* metaOpen(const char* path, const SMetaCfg* pMetaCfg, SMemAllocatorFactory* pMAF); +void metaClose(SMeta* pMeta); +void metaRemove(const char* path); +int metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg); +int metaDropTable(SMeta* pMeta, tb_uid_t uid); +int metaCommit(SMeta* pMeta); +int32_t metaCreateTSma(SMeta* pMeta, SSmaCfg* pCfg); +int32_t metaDropTSma(SMeta* pMeta, int64_t indexUid); +STbCfg* metaGetTbInfoByUid(SMeta* pMeta, tb_uid_t uid); +STbCfg* metaGetTbInfoByName(SMeta* pMeta, char* tbname, tb_uid_t* uid); +SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, bool isinline); +STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver); +void* metaGetSmaInfoByIndex(SMeta* pMeta, int64_t indexUid, bool isDecode); +STSmaWrapper* metaGetSmaInfoByTable(SMeta* pMeta, tb_uid_t uid); +SArray* metaGetSmaTbUids(SMeta* pMeta, bool isDup); +int metaGetTbNum(SMeta* pMeta); +SMSmaCursor* metaOpenSmaCursor(SMeta* pMeta, tb_uid_t uid); +void metaCloseSmaCursor(SMSmaCursor* pSmaCur); +int64_t metaSmaCursorNext(SMSmaCursor* pSmaCur); +SMCtbCursor* metaOpenCtbCursor(SMeta* pMeta, tb_uid_t uid); +void metaCloseCtbCurosr(SMCtbCursor* pCtbCur); +tb_uid_t metaCtbCursorNext(SMCtbCursor* pCtbCur); // SMetaDB int metaOpenDB(SMeta* pMeta); @@ -36,11 +75,6 @@ int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid); int metaOpenCache(SMeta* pMeta); void metaCloseCache(SMeta* pMeta); -// SMetaCfg -extern const SMetaCfg defaultMetaOptions; -// int metaValidateOptions(const SMetaCfg*); -void metaOptionsCopy(SMetaCfg* pDest, const SMetaCfg* pSrc); - // SMetaIdx int metaOpenIdx(SMeta* pMeta); void metaCloseIdx(SMeta* pMeta); @@ -62,6 +96,7 @@ tb_uid_t metaGenerateUid(SMeta* pMeta); struct SMeta { char* path; + SVnode* pVnode; SMetaCfg options; SMetaDB* pDB; SMetaIdx* pIdx; diff --git a/source/dnode/vnode/src/inc/tq.h b/source/dnode/vnode/src/inc/tq.h index bee443f48735561ca4852e23af7f734aac414b07..ce81006661b7529f7526d27f8a66bba3a26cccbc 100644 --- a/source/dnode/vnode/src/inc/tq.h +++ b/source/dnode/vnode/src/inc/tq.h @@ -20,48 +20,21 @@ extern "C" { #endif -// tqInt.h -#define tqFatal(...) \ - { \ - if (tqDebugFlag & DEBUG_FATAL) { \ - taosPrintLog("TQ FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \ - } \ - } - -#define tqError(...) \ - { \ - if (tqDebugFlag & DEBUG_ERROR) { \ - taosPrintLog("TQ ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \ - } \ - } - -#define tqWarn(...) \ - { \ - if (tqDebugFlag & DEBUG_WARN) { \ - taosPrintLog("TQ WARN ", DEBUG_WARN, 255, __VA_ARGS__); \ - } \ - } - -#define tqInfo(...) \ - { \ - if (tqDebugFlag & DEBUG_INFO) { \ - taosPrintLog("TQ ", DEBUG_INFO, 255, __VA_ARGS__); \ - } \ - } - -#define tqDebug(...) \ - { \ - if (tqDebugFlag & DEBUG_DEBUG) { \ - taosPrintLog("TQ ", DEBUG_DEBUG, tqDebugFlag, __VA_ARGS__); \ - } \ - } - -#define tqTrace(...) \ - { \ - if (tqDebugFlag & DEBUG_TRACE) { \ - taosPrintLog("TQ ", DEBUG_TRACE, tqDebugFlag, __VA_ARGS__); \ - } \ - } +// tqDebug =================== +// clang-format off +#define tqFatal(...) do { if (tqDebugFlag & DEBUG_FATAL) { taosPrintLog("TQ FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) +#define tqError(...) do { if (tqDebugFlag & DEBUG_ERROR) { taosPrintLog("TQ ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) +#define tqWarn(...) do { if (tqDebugFlag & DEBUG_WARN) { taosPrintLog("TQ WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) +#define tqInfo(...) do { if (tqDebugFlag & DEBUG_INFO) { taosPrintLog("TQ ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) +#define tqDebug(...) do { if (tqDebugFlag & DEBUG_DEBUG) { taosPrintLog("TQ ", DEBUG_DEBUG, tqDebugFlag, __VA_ARGS__); }} while(0) +#define tqTrace(...) do { if (tqDebugFlag & DEBUG_TRACE) { taosPrintLog("TQ ", DEBUG_TRACE, tqDebugFlag, __VA_ARGS__); }} while(0) +// clang-format on + +enum { + TQ_STREAM_TOKEN__DATA = 1, + TQ_STREAM_TOKEN__WATERMARK, + TQ_STREAM_TOKEN__CHECKPOINT, +}; #define TQ_BUFFER_SIZE 4 @@ -105,6 +78,31 @@ typedef enum { TQ_ITEM_READY, TQ_ITEM_PROCESS, TQ_ITEM_EMPTY } STqItemStatus; typedef struct STqOffsetCfg STqOffsetCfg; typedef struct STqOffsetStore STqOffsetStore; +struct STqReadHandle { + int64_t ver; + int64_t tbUid; + SHashObj* tbIdHash; + const SSubmitReq* pMsg; + SSubmitBlk* pBlock; + SSubmitMsgIter msgIter; + SSubmitBlkIter blkIter; + SMeta* pVnodeMeta; + SArray* pColIdList; // SArray + int32_t sver; + SSchemaWrapper* pSchemaWrapper; + STSchema* pSchema; +}; + +typedef struct { + int8_t type; + int8_t reserved[7]; + union { + void* data; + int64_t wmTs; + int64_t checkpointId; + }; +} STqStreamToken; + typedef struct { int16_t ver; int16_t action; @@ -248,6 +246,25 @@ typedef struct { static STqPushMgmt tqPushMgmt; +// init once +int tqInit(); +void tqCleanUp(); + +// open in each vnode +STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pMeta, STqCfg* tqConfig, + SMemAllocatorFactory* allocFac); +void tqClose(STQ*); +// required by vnode +int tqPushMsg(STQ*, void* msg, int32_t msgLen, tmsg_t msgType, int64_t version); +int tqCommit(STQ*); + +int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId); +int32_t tqProcessSetConnReq(STQ* pTq, char* msg); +int32_t tqProcessRebReq(STQ* pTq, char* msg); +int32_t tqProcessCancelConnReq(STQ* pTq, char* msg); +int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId); +int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); +int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId); int32_t tqSerializeConsumer(const STqConsumer*, STqSerializedHead**); int32_t tqDeserializeConsumer(STQ*, const STqSerializedHead*, STqConsumer**); diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index b85caad4c8bf97e29ea0c495c00ea4f5613480c3..d0e005f990739b75b8d77274b9a1f5111d63226b 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -20,10 +20,46 @@ extern "C" { #endif +// tsdbDebug ================ +// clang-format off +#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TSDB FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) +#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TSDB ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) +#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TSDB WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) +#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TSDB ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) +#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0) +#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) +// clang-format on + typedef struct SSmaStat SSmaStat; typedef struct SSmaEnv SSmaEnv; typedef struct SSmaEnvs SSmaEnvs; +typedef struct STable { + uint64_t tid; + uint64_t uid; + STSchema *pSchema; +} STable; + +#define TABLE_TID(t) (t)->tid +#define TABLE_UID(t) (t)->uid + +STsdb *tsdbOpen(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF, SMeta *pMeta, + STfs *pTfs); +void tsdbClose(STsdb *); +void tsdbRemove(const char *path); +int tsdbInsertData(STsdb *pTsdb, SSubmitReq *pMsg, SSubmitRsp *pRsp); +int tsdbPrepareCommit(STsdb *pTsdb); +int tsdbCommit(STsdb *pTsdb); +int32_t tsdbInitSma(STsdb *pTsdb); +int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg); +int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg); +int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, SSubmitReq *pMsg, int64_t version); +int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg); +int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid); +int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg); +void tsdbCleanupReadHandle(tsdbReaderT queryHandle); +int32_t tdScanAndConvertSubmitMsg(SSubmitReq *pMsg); + typedef enum { TSDB_FILE_HEAD = 0, // .head TSDB_FILE_DATA, // .data @@ -93,7 +129,7 @@ typedef struct STsdbMemTable { SMemAllocator *pMA; // Container SSkipList *pSlIdx; // SSkiplist - SHashObj * pHashIdx; + SHashObj *pHashIdx; } STsdbMemTable; typedef struct { @@ -105,33 +141,34 @@ typedef struct { // ================== typedef struct { STsdbFSMeta meta; // FS meta - SArray * df; // data file array - SArray * sf; // sma data file array v2f1900.index_name_1 + SArray *df; // data file array + SArray *sf; // sma data file array v2f1900.index_name_1 } SFSStatus; typedef struct { TdThreadRwlock lock; SFSStatus *cstatus; // current status - SHashObj * metaCache; // meta cache - SHashObj * metaCacheComp; // meta cache for compact + SHashObj *metaCache; // meta cache + SHashObj *metaCacheComp; // meta cache for compact bool intxn; SFSStatus *nstatus; // new status } STsdbFS; struct STsdb { int32_t vgId; + SVnode *pVnode; bool repoLocked; TdThreadMutex mutex; - char * path; + char *path; STsdbCfg config; - STsdbMemTable * mem; - STsdbMemTable * imem; + STsdbMemTable *mem; + STsdbMemTable *imem; SRtn rtn; SMemAllocatorFactory *pmaf; - STsdbFS * fs; - SMeta * pMeta; - STfs * pTfs; + STsdbFS *fs; + SMeta *pMeta; + STfs *pTfs; SSmaEnvs smaEnvs; }; @@ -153,16 +190,6 @@ static FORCE_INLINE STSchema *tsdbGetTableSchemaImpl(STable *pTable, bool lock, return pTable->pSchema; } -// tsdbLog -extern int32_t tsdbDebugFlag; - -#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TSDB FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) -#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TSDB ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) -#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TSDB WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) -#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TSDB ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) -#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0) -#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) - // tsdbMemTable.h typedef struct { int rowsInserted; @@ -174,10 +201,10 @@ typedef struct { TSKEY keyLast; } SMergeInfo; -static void * taosTMalloc(size_t size); -static void * taosTCalloc(size_t nmemb, size_t size); -static void * taosTRealloc(void *ptr, size_t size); -static void * taosTZfree(void *ptr); +static void *taosTMalloc(size_t size); +static void *taosTCalloc(size_t nmemb, size_t size); +static void *taosTRealloc(void *ptr, size_t size); +static void *taosTZfree(void *ptr); static size_t taosTSizeof(void *ptr); static void taosTMemset(void *ptr, int c); @@ -398,18 +425,18 @@ static FORCE_INLINE size_t tsdbBlockAggrSize(int nCols, uint32_t blkVer) { } } -int tsdbInitReadH(SReadH *pReadh, STsdb *pRepo); -void tsdbDestroyReadH(SReadH *pReadh); -int tsdbSetAndOpenReadFSet(SReadH *pReadh, SDFileSet *pSet); -void tsdbCloseAndUnsetFSet(SReadH *pReadh); -int tsdbLoadBlockIdx(SReadH *pReadh); -int tsdbSetReadTable(SReadH *pReadh, STable *pTable); -int tsdbLoadBlockInfo(SReadH *pReadh, void *pTarget); -int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlockInfo); -int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, const int16_t *colIds, - int numOfColsIds, bool mergeBitmap); -int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock); -int tsdbEncodeSBlockIdx(void **buf, SBlockIdx *pIdx); +int tsdbInitReadH(SReadH *pReadh, STsdb *pRepo); +void tsdbDestroyReadH(SReadH *pReadh); +int tsdbSetAndOpenReadFSet(SReadH *pReadh, SDFileSet *pSet); +void tsdbCloseAndUnsetFSet(SReadH *pReadh); +int tsdbLoadBlockIdx(SReadH *pReadh); +int tsdbSetReadTable(SReadH *pReadh, STable *pTable); +int tsdbLoadBlockInfo(SReadH *pReadh, void *pTarget); +int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlockInfo); +int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, const int16_t *colIds, int numOfColsIds, + bool mergeBitmap); +int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock); +int tsdbEncodeSBlockIdx(void **buf, SBlockIdx *pIdx); void *tsdbDecodeSBlockIdx(void *buf, SBlockIdx *pIdx); void tsdbGetBlockStatis(SReadH *pReadh, SDataStatis *pStatis, int numOfCols, SBlock *pBlock); @@ -448,7 +475,7 @@ static FORCE_INLINE void *taosTMalloc(size_t size) { static FORCE_INLINE void *taosTCalloc(size_t nmemb, size_t size) { size_t tsize = nmemb * size; - void * ret = taosTMalloc(tsize); + void *ret = taosTMalloc(tsize); if (ret == NULL) return NULL; taosTMemset(ret, 0); @@ -459,14 +486,14 @@ static FORCE_INLINE size_t taosTSizeof(void *ptr) { return (ptr) ? (*(size_t *)( static FORCE_INLINE void taosTMemset(void *ptr, int c) { memset(ptr, c, taosTSizeof(ptr)); } -static FORCE_INLINE void * taosTRealloc(void *ptr, size_t size) { +static FORCE_INLINE void *taosTRealloc(void *ptr, size_t size) { if (ptr == NULL) return taosTMalloc(size); if (size <= taosTSizeof(ptr)) return ptr; - void * tptr = (void *)((char *)ptr - sizeof(size_t)); + void *tptr = (void *)((char *)ptr - sizeof(size_t)); size_t tsize = size + sizeof(size_t); - void* tptr1 = taosMemoryRealloc(tptr, tsize); + void *tptr1 = taosMemoryRealloc(tptr, tsize); if (tptr1 == NULL) return NULL; tptr = tptr1; @@ -475,9 +502,9 @@ static FORCE_INLINE void * taosTRealloc(void *ptr, size_t size) { return (void *)((char *)tptr + sizeof(size_t)); } -static FORCE_INLINE void* taosTZfree(void* ptr) { +static FORCE_INLINE void *taosTZfree(void *ptr) { if (ptr) { - taosMemoryFree((void*)((char*)ptr - sizeof(size_t))); + taosMemoryFree((void *)((char *)ptr - sizeof(size_t))); } return NULL; } @@ -530,30 +557,30 @@ static FORCE_INLINE int tsdbGetFidLevel(int fid, SRtn *pRtn) { // void* tsdbGetSmaDataByKey(SDBFile* pDBF, void* key, uint32_t keySize, uint32_t* valueSize); // tsdbFile -#define TSDB_FILE_HEAD_SIZE 512 -#define TSDB_FILE_DELIMITER 0xF00AFA0F +#define TSDB_FILE_HEAD_SIZE 512 +#define TSDB_FILE_DELIMITER 0xF00AFA0F #define TSDB_FILE_INIT_MAGIC 0xFFFFFFFF -#define TSDB_IVLD_FID INT_MIN -#define TSDB_FILE_STATE_OK 0 -#define TSDB_FILE_STATE_BAD 1 - -#define TSDB_FILE_INFO(tf) (&((tf)->info)) -#define TSDB_FILE_F(tf) (&((tf)->f)) -#define TSDB_FILE_PFILE(tf) ((tf)->pFile) -#define TSDB_FILE_FULL_NAME(tf) (TSDB_FILE_F(tf)->aname) -#define TSDB_FILE_OPENED(tf) (TSDB_FILE_PFILE(tf) != NULL) -#define TSDB_FILE_CLOSED(tf) (!TSDB_FILE_OPENED(tf)) -#define TSDB_FILE_SET_CLOSED(f) (TSDB_FILE_PFILE(f) = NULL) -#define TSDB_FILE_LEVEL(tf) (TSDB_FILE_F(tf)->did.level) -#define TSDB_FILE_ID(tf) (TSDB_FILE_F(tf)->did.id) -#define TSDB_FILE_DID(tf) (TSDB_FILE_F(tf)->did) -#define TSDB_FILE_REL_NAME(tf) (TSDB_FILE_F(tf)->rname) -#define TSDB_FILE_ABS_NAME(tf) (TSDB_FILE_F(tf)->aname) -#define TSDB_FILE_FSYNC(tf) taosFsyncFile(TSDB_FILE_PFILE(tf)) -#define TSDB_FILE_STATE(tf) ((tf)->state) +#define TSDB_IVLD_FID INT_MIN +#define TSDB_FILE_STATE_OK 0 +#define TSDB_FILE_STATE_BAD 1 + +#define TSDB_FILE_INFO(tf) (&((tf)->info)) +#define TSDB_FILE_F(tf) (&((tf)->f)) +#define TSDB_FILE_PFILE(tf) ((tf)->pFile) +#define TSDB_FILE_FULL_NAME(tf) (TSDB_FILE_F(tf)->aname) +#define TSDB_FILE_OPENED(tf) (TSDB_FILE_PFILE(tf) != NULL) +#define TSDB_FILE_CLOSED(tf) (!TSDB_FILE_OPENED(tf)) +#define TSDB_FILE_SET_CLOSED(f) (TSDB_FILE_PFILE(f) = NULL) +#define TSDB_FILE_LEVEL(tf) (TSDB_FILE_F(tf)->did.level) +#define TSDB_FILE_ID(tf) (TSDB_FILE_F(tf)->did.id) +#define TSDB_FILE_DID(tf) (TSDB_FILE_F(tf)->did) +#define TSDB_FILE_REL_NAME(tf) (TSDB_FILE_F(tf)->rname) +#define TSDB_FILE_ABS_NAME(tf) (TSDB_FILE_F(tf)->aname) +#define TSDB_FILE_FSYNC(tf) taosFsyncFile(TSDB_FILE_PFILE(tf)) +#define TSDB_FILE_STATE(tf) ((tf)->state) #define TSDB_FILE_SET_STATE(tf, s) ((tf)->state = (s)) -#define TSDB_FILE_IS_OK(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_OK) -#define TSDB_FILE_IS_BAD(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_BAD) +#define TSDB_FILE_IS_OK(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_OK) +#define TSDB_FILE_IS_BAD(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_BAD) typedef int32_t TSDB_FILE_T; typedef enum { @@ -576,19 +603,18 @@ static FORCE_INLINE uint32_t tsdbGetDFSVersion(TSDB_FILE_T fType) { // latest v } } +void tsdbInitDFile(STsdb *pRepo, SDFile *pDFile, SDiskID did, int fid, uint32_t ver, TSDB_FILE_T ftype); +void tsdbInitDFileEx(SDFile *pDFile, SDFile *pODFile); +int tsdbEncodeSDFile(void **buf, SDFile *pDFile); +void *tsdbDecodeSDFile(STsdb *pRepo, void *buf, SDFile *pDFile); +int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader, TSDB_FILE_T fType); +int tsdbUpdateDFileHeader(SDFile *pDFile); +int tsdbLoadDFileHeader(SDFile *pDFile, SDFInfo *pInfo); +int tsdbParseDFilename(const char *fname, int *vid, int *fid, TSDB_FILE_T *ftype, uint32_t *version); -void tsdbInitDFile(STsdb *pRepo, SDFile* pDFile, SDiskID did, int fid, uint32_t ver, TSDB_FILE_T ftype); -void tsdbInitDFileEx(SDFile* pDFile, SDFile* pODFile); -int tsdbEncodeSDFile(void** buf, SDFile* pDFile); -void* tsdbDecodeSDFile(STsdb *pRepo, void* buf, SDFile* pDFile); -int tsdbCreateDFile(STsdb *pRepo, SDFile* pDFile, bool updateHeader, TSDB_FILE_T fType); -int tsdbUpdateDFileHeader(SDFile* pDFile); -int tsdbLoadDFileHeader(SDFile* pDFile, SDFInfo* pInfo); -int tsdbParseDFilename(const char* fname, int* vid, int* fid, TSDB_FILE_T* ftype, uint32_t* version); - -static FORCE_INLINE void tsdbSetDFileInfo(SDFile* pDFile, SDFInfo* pInfo) { pDFile->info = *pInfo; } +static FORCE_INLINE void tsdbSetDFileInfo(SDFile *pDFile, SDFInfo *pInfo) { pDFile->info = *pInfo; } -static FORCE_INLINE int tsdbOpenDFile(SDFile* pDFile, int flags) { +static FORCE_INLINE int tsdbOpenDFile(SDFile *pDFile, int flags) { ASSERT(!TSDB_FILE_OPENED(pDFile)); pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), flags); @@ -600,14 +626,14 @@ static FORCE_INLINE int tsdbOpenDFile(SDFile* pDFile, int flags) { return 0; } -static FORCE_INLINE void tsdbCloseDFile(SDFile* pDFile) { +static FORCE_INLINE void tsdbCloseDFile(SDFile *pDFile) { if (TSDB_FILE_OPENED(pDFile)) { taosCloseFile(&pDFile->pFile); TSDB_FILE_SET_CLOSED(pDFile); } } -static FORCE_INLINE int64_t tsdbSeekDFile(SDFile* pDFile, int64_t offset, int whence) { +static FORCE_INLINE int64_t tsdbSeekDFile(SDFile *pDFile, int64_t offset, int whence) { // ASSERT(TSDB_FILE_OPENED(pDFile)); int64_t loffset = taosLSeekFile(TSDB_FILE_PFILE(pDFile), offset, whence); @@ -619,7 +645,7 @@ static FORCE_INLINE int64_t tsdbSeekDFile(SDFile* pDFile, int64_t offset, int wh return loffset; } -static FORCE_INLINE int64_t tsdbWriteDFile(SDFile* pDFile, void* buf, int64_t nbyte) { +static FORCE_INLINE int64_t tsdbWriteDFile(SDFile *pDFile, void *buf, int64_t nbyte) { ASSERT(TSDB_FILE_OPENED(pDFile)); int64_t nwrite = taosWriteFile(pDFile->pFile, buf, nbyte); @@ -631,11 +657,11 @@ static FORCE_INLINE int64_t tsdbWriteDFile(SDFile* pDFile, void* buf, int64_t nb return nwrite; } -static FORCE_INLINE void tsdbUpdateDFileMagic(SDFile* pDFile, void* pCksm) { - pDFile->info.magic = taosCalcChecksum(pDFile->info.magic, (uint8_t*)(pCksm), sizeof(TSCKSUM)); +static FORCE_INLINE void tsdbUpdateDFileMagic(SDFile *pDFile, void *pCksm) { + pDFile->info.magic = taosCalcChecksum(pDFile->info.magic, (uint8_t *)(pCksm), sizeof(TSCKSUM)); } -static FORCE_INLINE int tsdbAppendDFile(SDFile* pDFile, void* buf, int64_t nbyte, int64_t* offset) { +static FORCE_INLINE int tsdbAppendDFile(SDFile *pDFile, void *buf, int64_t nbyte, int64_t *offset) { ASSERT(TSDB_FILE_OPENED(pDFile)); int64_t toffset; @@ -659,9 +685,9 @@ static FORCE_INLINE int tsdbAppendDFile(SDFile* pDFile, void* buf, int64_t nbyte return (int)nbyte; } -static FORCE_INLINE int tsdbRemoveDFile(SDFile* pDFile) { return tfsRemoveFile(TSDB_FILE_F(pDFile)); } +static FORCE_INLINE int tsdbRemoveDFile(SDFile *pDFile) { return tfsRemoveFile(TSDB_FILE_F(pDFile)); } -static FORCE_INLINE int64_t tsdbReadDFile(SDFile* pDFile, void* buf, int64_t nbyte) { +static FORCE_INLINE int64_t tsdbReadDFile(SDFile *pDFile, void *buf, int64_t nbyte) { ASSERT(TSDB_FILE_OPENED(pDFile)); int64_t nread = taosReadFile(pDFile->pFile, buf, nbyte); @@ -673,7 +699,7 @@ static FORCE_INLINE int64_t tsdbReadDFile(SDFile* pDFile, void* buf, int64_t nby return nread; } -static FORCE_INLINE int tsdbCopyDFile(SDFile* pSrc, SDFile* pDest) { +static FORCE_INLINE int tsdbCopyDFile(SDFile *pSrc, SDFile *pDest) { if (tfsCopyFile(TSDB_FILE_F(pSrc), TSDB_FILE_F(pDest)) < 0) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; @@ -700,12 +726,12 @@ typedef struct { #define TSDB_LATEST_FSET_VER 0 -#define TSDB_FSET_FID(s) ((s)->fid) -#define TSDB_FSET_STATE(s) ((s)->state) -#define TSDB_FSET_VER(s) ((s)->ver) +#define TSDB_FSET_FID(s) ((s)->fid) +#define TSDB_FSET_STATE(s) ((s)->state) +#define TSDB_FSET_VER(s) ((s)->ver) #define TSDB_DFILE_IN_SET(s, t) ((s)->files + (t)) -#define TSDB_FSET_LEVEL(s) TSDB_FILE_LEVEL(TSDB_DFILE_IN_SET(s, 0)) -#define TSDB_FSET_ID(s) TSDB_FILE_ID(TSDB_DFILE_IN_SET(s, 0)) +#define TSDB_FSET_LEVEL(s) TSDB_FILE_LEVEL(TSDB_DFILE_IN_SET(s, 0)) +#define TSDB_FSET_ID(s) TSDB_FILE_ID(TSDB_DFILE_IN_SET(s, 0)) #define TSDB_FSET_SET_CLOSED(s) \ do { \ for (TSDB_FILE_T ftype = TSDB_FILE_HEAD; ftype < TSDB_FILE_MAX; ftype++) { \ @@ -719,24 +745,24 @@ typedef struct { } \ } while (0); -void tsdbInitDFileSet(STsdb *pRepo, SDFileSet* pSet, SDiskID did, int fid, uint32_t ver); -void tsdbInitDFileSetEx(SDFileSet* pSet, SDFileSet* pOSet); -int tsdbEncodeDFileSet(void** buf, SDFileSet* pSet); -void* tsdbDecodeDFileSet(STsdb *pRepo, void* buf, SDFileSet* pSet); -int tsdbEncodeDFileSetEx(void** buf, SDFileSet* pSet); -void* tsdbDecodeDFileSetEx(void* buf, SDFileSet* pSet); -int tsdbApplyDFileSetChange(SDFileSet* from, SDFileSet* to); -int tsdbCreateDFileSet(STsdb *pRepo, SDFileSet* pSet, bool updateHeader); -int tsdbUpdateDFileSetHeader(SDFileSet* pSet); -int tsdbScanAndTryFixDFileSet(STsdb* pRepo, SDFileSet* pSet); - -static FORCE_INLINE void tsdbCloseDFileSet(SDFileSet* pSet) { +void tsdbInitDFileSet(STsdb *pRepo, SDFileSet *pSet, SDiskID did, int fid, uint32_t ver); +void tsdbInitDFileSetEx(SDFileSet *pSet, SDFileSet *pOSet); +int tsdbEncodeDFileSet(void **buf, SDFileSet *pSet); +void *tsdbDecodeDFileSet(STsdb *pRepo, void *buf, SDFileSet *pSet); +int tsdbEncodeDFileSetEx(void **buf, SDFileSet *pSet); +void *tsdbDecodeDFileSetEx(void *buf, SDFileSet *pSet); +int tsdbApplyDFileSetChange(SDFileSet *from, SDFileSet *to); +int tsdbCreateDFileSet(STsdb *pRepo, SDFileSet *pSet, bool updateHeader); +int tsdbUpdateDFileSetHeader(SDFileSet *pSet); +int tsdbScanAndTryFixDFileSet(STsdb *pRepo, SDFileSet *pSet); + +static FORCE_INLINE void tsdbCloseDFileSet(SDFileSet *pSet) { for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { tsdbCloseDFile(TSDB_DFILE_IN_SET(pSet, ftype)); } } -static FORCE_INLINE int tsdbOpenDFileSet(SDFileSet* pSet, int flags) { +static FORCE_INLINE int tsdbOpenDFileSet(SDFileSet *pSet, int flags) { for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { if (tsdbOpenDFile(TSDB_DFILE_IN_SET(pSet, ftype), flags) < 0) { tsdbCloseDFileSet(pSet); @@ -746,13 +772,13 @@ static FORCE_INLINE int tsdbOpenDFileSet(SDFileSet* pSet, int flags) { return 0; } -static FORCE_INLINE void tsdbRemoveDFileSet(SDFileSet* pSet) { +static FORCE_INLINE void tsdbRemoveDFileSet(SDFileSet *pSet) { for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { (void)tsdbRemoveDFile(TSDB_DFILE_IN_SET(pSet, ftype)); } } -static FORCE_INLINE int tsdbCopyDFileSet(SDFileSet* pSrc, SDFileSet* pDest) { +static FORCE_INLINE int tsdbCopyDFileSet(SDFileSet *pSrc, SDFileSet *pDest) { for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { if (tsdbCopyDFile(TSDB_DFILE_IN_SET(pSrc, ftype), TSDB_DFILE_IN_SET(pDest, ftype)) < 0) { tsdbRemoveDFileSet(pDest); @@ -763,12 +789,12 @@ static FORCE_INLINE int tsdbCopyDFileSet(SDFileSet* pSrc, SDFileSet* pDest) { return 0; } -static FORCE_INLINE void tsdbGetFidKeyRange(int days, int8_t precision, int fid, TSKEY* minKey, TSKEY* maxKey) { +static FORCE_INLINE void tsdbGetFidKeyRange(int days, int8_t precision, int fid, TSKEY *minKey, TSKEY *maxKey) { *minKey = fid * days * tsTickPerDay[precision]; *maxKey = *minKey + days * tsTickPerDay[precision] - 1; } -static FORCE_INLINE bool tsdbFSetIsOk(SDFileSet* pSet) { +static FORCE_INLINE bool tsdbFSetIsOk(SDFileSet *pSet) { for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { if (TSDB_FILE_IS_BAD(TSDB_DFILE_IN_SET(pSet, ftype))) { return false; @@ -809,25 +835,25 @@ typedef struct { */ #define FS_CURRENT_STATUS(pfs) ((pfs)->cstatus) -#define FS_NEW_STATUS(pfs) ((pfs)->nstatus) -#define FS_IN_TXN(pfs) (pfs)->intxn -#define FS_VERSION(pfs) ((pfs)->cstatus->meta.version) -#define FS_TXN_VERSION(pfs) ((pfs)->nstatus->meta.version) +#define FS_NEW_STATUS(pfs) ((pfs)->nstatus) +#define FS_IN_TXN(pfs) (pfs)->intxn +#define FS_VERSION(pfs) ((pfs)->cstatus->meta.version) +#define FS_TXN_VERSION(pfs) ((pfs)->nstatus->meta.version) typedef struct { int direction; uint64_t version; // current FS version - STsdbFS * pfs; + STsdbFS *pfs; int index; // used to position next fset when version the same int fid; // used to seek when version is changed SDFileSet *pSet; } SFSIter; -#define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC +#define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC #define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC STsdbFS *tsdbNewFS(const STsdbCfg *pCfg); -void * tsdbFreeFS(STsdbFS *pfs); +void *tsdbFreeFS(STsdbFS *pfs); int tsdbOpenFS(STsdb *pRepo); void tsdbCloseFS(STsdb *pRepo); void tsdbStartFSTxn(STsdb *pRepo, int64_t pointsAdd, int64_t storageAdd); @@ -872,7 +898,6 @@ static FORCE_INLINE int tsdbUnLockFS(STsdbFS *pFs) { // tsdbSma // #define TSDB_SMA_TEST // remove after test finished - // struct SSmaEnv { // TdThreadRwlock lock; // SDiskID did; @@ -888,7 +913,6 @@ static FORCE_INLINE int tsdbUnLockFS(STsdbFS *pFs) { // #define SMA_ENV_STAT(env) ((env)->pStat) // #define SMA_ENV_STAT_ITEMS(env) ((env)->pStat->smaStatItems) - // void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv); // void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv); // #if 0 @@ -931,9 +955,45 @@ static FORCE_INLINE int tsdbUnLockFS(STsdbFS *pFs) { // return 0; // } +typedef struct SSmaKey SSmaKey; + +struct SSmaKey { + TSKEY skey; + int64_t groupId; +}; + +typedef struct SDBFile SDBFile; + +struct SDBFile { + int32_t fid; + TDB *pDB; + char *path; +}; + +int32_t tsdbOpenDBEnv(TENV **ppEnv, const char *path); +int32_t tsdbCloseDBEnv(TENV *pEnv); +int32_t tsdbOpenDBF(TENV *pEnv, SDBFile *pDBF); +int32_t tsdbCloseDBF(SDBFile *pDBF); +int32_t tsdbSaveSmaToDB(SDBFile *pDBF, void *pKey, int32_t keyLen, void *pVal, int32_t valLen, TXN *txn); +void *tsdbGetSmaDataByKey(SDBFile *pDBF, const void *pKey, int32_t keyLen, int32_t *valLen); + +void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv); +void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv); +#if 0 +int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result); +int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin); +#endif + +// internal func +static FORCE_INLINE int32_t tsdbEncodeTSmaKey(int64_t groupId, TSKEY tsKey, void **pData) { + int32_t len = 0; + len += taosEncodeFixedI64(pData, tsKey); + len += taosEncodeFixedI64(pData, groupId); + return len; +} + #ifdef __cplusplus } #endif - #endif /*_TD_VNODE_TSDB_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h new file mode 100644 index 0000000000000000000000000000000000000000..1cdb38b65029c116d6d8b36f9600c3e45e8739f2 --- /dev/null +++ b/source/dnode/vnode/src/inc/vnd.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_VND_H_ +#define _TD_VND_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// vnodeDebug ==================== +// clang-format off +#define vFatal(...) do { if (vDebugFlag & DEBUG_FATAL) { taosPrintLog("VND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) +#define vError(...) do { if (vDebugFlag & DEBUG_ERROR) { taosPrintLog("VND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) +#define vWarn(...) do { if (vDebugFlag & DEBUG_WARN) { taosPrintLog("VND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) +#define vInfo(...) do { if (vDebugFlag & DEBUG_INFO) { taosPrintLog("VND ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) +#define vDebug(...) do { if (vDebugFlag & DEBUG_DEBUG) { taosPrintLog("VND ", DEBUG_DEBUG, vDebugFlag, __VA_ARGS__); }} while(0) +#define vTrace(...) do { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND ", DEBUG_TRACE, vDebugFlag, __VA_ARGS__); }} while(0) +// clang-format on + +// vnodeModule ==================== +int vnodeScheduleTask(int (*execute)(void*), void* arg); + +// vnodeQuery ==================== +int vnodeQueryOpen(SVnode* pVnode); +void vnodeQueryClose(SVnode* pVnode); +int vnodeGetTableMeta(SVnode* pVnode, SRpcMsg* pMsg); + +#if 1 +// SVBufPool +int vnodeOpenBufPool(SVnode* pVnode); +void vnodeCloseBufPool(SVnode* pVnode); +int vnodeBufPoolSwitch(SVnode* pVnode); +int vnodeBufPoolRecycle(SVnode* pVnode); +void* vnodeMalloc(SVnode* pVnode, uint64_t size); +bool vnodeBufPoolIsFull(SVnode* pVnode); + +SMemAllocatorFactory* vBufPoolGetMAF(SVnode* pVnode); + +// SVMemAllocator +typedef struct SVArenaNode { + TD_SLIST_NODE(SVArenaNode); + uint64_t size; // current node size + void* ptr; + char data[]; +} SVArenaNode; + +typedef struct SVMemAllocator { + T_REF_DECLARE() + TD_DLIST_NODE(SVMemAllocator); + uint64_t capacity; + uint64_t ssize; + uint64_t lsize; + SVArenaNode* pNode; + TD_SLIST(SVArenaNode) nlist; +} SVMemAllocator; + +SVMemAllocator* vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize); +void vmaDestroy(SVMemAllocator* pVMA); +void vmaReset(SVMemAllocator* pVMA); +void* vmaMalloc(SVMemAllocator* pVMA, uint64_t size); +void vmaFree(SVMemAllocator* pVMA, void* ptr); +bool vmaIsFull(SVMemAllocator* pVMA); + +// vnodeCfg.h +extern const SVnodeCfg defaultVnodeOptions; + +int vnodeValidateOptions(const SVnodeCfg*); +void vnodeOptionsCopy(SVnodeCfg* pDest, const SVnodeCfg* pSrc); + +// For commit +#define vnodeShouldCommit vnodeBufPoolIsFull +int vnodeSyncCommit(SVnode* pVnode); +int vnodeAsyncCommit(SVnode* pVnode); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_VND_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 6e1f00f93190c2220a0961e3ba491e69764d255e..f988df01cb0ec83f3e45985ceb609915aff5f917 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -17,50 +17,39 @@ #define _TD_VNODE_DEF_H_ #include "executor.h" +#include "filter.h" +#include "qworker.h" +#include "sync.h" #include "tchecksum.h" #include "tcoding.h" #include "tcompression.h" #include "tdatablock.h" +#include "tdbInt.h" #include "tfs.h" #include "tglobal.h" #include "tlist.h" #include "tlockfree.h" -#include "tmacro.h" +#include "tlosertree.h" #include "tmallocator.h" #include "tskiplist.h" +#include "tstream.h" #include "ttime.h" #include "ttimer.h" -#include "vnode.h" #include "wal.h" -#include "qworker.h" + +#include "vnode.h" #ifdef __cplusplus extern "C" { #endif -typedef struct STQ STQ; - +typedef struct SMeta SMeta; +typedef struct STsdb STsdb; +typedef struct STQ STQ; typedef struct SVState SVState; typedef struct SVBufPool SVBufPool; typedef struct SQWorkerMgmt SQHandle; -typedef struct SVnodeTask { - TD_DLIST_NODE(SVnodeTask); - void* arg; - int (*execute)(void*); -} SVnodeTask; - -typedef struct SVnodeMgr { - td_mode_flag_t vnodeInitFlag; - // For commit - bool stop; - uint16_t nthreads; - TdThread* threads; - TdThreadMutex mutex; - TdThreadCond hasTask; - TD_DLIST(SVnodeTask) queue; -} SVnodeMgr; - typedef struct { int8_t streamType; // sma or other int8_t dstType; @@ -76,8 +65,6 @@ typedef struct { SHashObj* pHash; // streamId -> SStreamSinkInfo } SSink; -extern SVnodeMgr vnodeMgr; - // SVState struct SVState { int64_t processed; @@ -102,118 +89,11 @@ struct SVnode { STfs* pTfs; }; -int vnodeScheduleTask(SVnodeTask* task); -int vnodeQueryOpen(SVnode* pVnode); -void vnodeQueryClose(SVnode* pVnode); - -#define vFatal(...) \ - do { \ - if (vDebugFlag & DEBUG_FATAL) { \ - taosPrintLog("VND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \ - } \ - } while (0) -#define vError(...) \ - do { \ - if (vDebugFlag & DEBUG_ERROR) { \ - taosPrintLog("VND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \ - } \ - } while (0) -#define vWarn(...) \ - do { \ - if (vDebugFlag & DEBUG_WARN) { \ - taosPrintLog("VND WARN ", DEBUG_WARN, 255, __VA_ARGS__); \ - } \ - } while (0) -#define vInfo(...) \ - do { \ - if (vDebugFlag & DEBUG_INFO) { \ - taosPrintLog("VND ", DEBUG_INFO, 255, __VA_ARGS__); \ - } \ - } while (0) -#define vDebug(...) \ - do { \ - if (vDebugFlag & DEBUG_DEBUG) { \ - taosPrintLog("VND ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); \ - } \ - } while (0) -#define vTrace(...) \ - do { \ - if (vDebugFlag & DEBUG_TRACE) { \ - taosPrintLog("VND ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); \ - } \ - } while (0) - -// vnodeCfg.h -extern const SVnodeCfg defaultVnodeOptions; - -int vnodeValidateOptions(const SVnodeCfg*); -void vnodeOptionsCopy(SVnodeCfg* pDest, const SVnodeCfg* pSrc); - -// For commit -#define vnodeShouldCommit vnodeBufPoolIsFull -int vnodeSyncCommit(SVnode* pVnode); -int vnodeAsyncCommit(SVnode* pVnode); - -// SVBufPool - -int vnodeOpenBufPool(SVnode* pVnode); -void vnodeCloseBufPool(SVnode* pVnode); -int vnodeBufPoolSwitch(SVnode* pVnode); -int vnodeBufPoolRecycle(SVnode* pVnode); -void* vnodeMalloc(SVnode* pVnode, uint64_t size); -bool vnodeBufPoolIsFull(SVnode* pVnode); - -SMemAllocatorFactory* vBufPoolGetMAF(SVnode* pVnode); - -// SVMemAllocator -typedef struct SVArenaNode { - TD_SLIST_NODE(SVArenaNode); - uint64_t size; // current node size - void* ptr; - char data[]; -} SVArenaNode; - -typedef struct SVMemAllocator { - T_REF_DECLARE() - TD_DLIST_NODE(SVMemAllocator); - uint64_t capacity; - uint64_t ssize; - uint64_t lsize; - SVArenaNode* pNode; - TD_SLIST(SVArenaNode) nlist; -} SVMemAllocator; - -SVMemAllocator* vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize); -void vmaDestroy(SVMemAllocator* pVMA); -void vmaReset(SVMemAllocator* pVMA); -void* vmaMalloc(SVMemAllocator* pVMA, uint64_t size); -void vmaFree(SVMemAllocator* pVMA, void* ptr); -bool vmaIsFull(SVMemAllocator* pVMA); - -// init once -int tqInit(); -void tqCleanUp(); - -// open in each vnode -STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pMeta, STqCfg* tqConfig, - SMemAllocatorFactory* allocFac); -void tqClose(STQ*); - -// required by vnode -int tqPushMsg(STQ*, void* msg, int32_t msgLen, tmsg_t msgType, int64_t version); -int tqCommit(STQ*); - -int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId); -int32_t tqProcessSetConnReq(STQ* pTq, char* msg); -int32_t tqProcessRebReq(STQ* pTq, char* msg); -int32_t tqProcessCancelConnReq(STQ* pTq, char* msg); -int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId); -int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); -int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId); - // sma void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data); +#include "vnd.h" + #include "meta.h" #include "tsdb.h" diff --git a/source/dnode/vnode/src/meta/metaBDBImpl.c b/source/dnode/vnode/src/meta/metaBDBImpl.c index caa101b5d064ef1cc636fe9e29c7a5dd6137ac85..249e48902936002397e0dcac09b0c7e03a0f1d56 100644 --- a/source/dnode/vnode/src/meta/metaBDBImpl.c +++ b/source/dnode/vnode/src/meta/metaBDBImpl.c @@ -16,10 +16,7 @@ #define ALLOW_FORBID_FUNC #include "db.h" -#include "metaDef.h" - -#include "tcoding.h" -#include "thash.h" +#include "vnodeInt.h" #define IMPL_WITH_LOCK 1 // #if IMPL_WITH_LOCK @@ -262,7 +259,7 @@ int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) { return 0; } -int metaRemoveSmaFromDb(SMeta *pMeta, int64_t indexUid) { +int metaRemoveSmaFromDb(SMeta *pMeta, int64_t indexUid) { // TODO #if 0 DBT key = {0}; @@ -667,8 +664,8 @@ STbCfg *metaGetTbInfoByName(SMeta *pMeta, char *tbname, tb_uid_t *uid) { return pTbCfg; } -STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) { - STSma * pCfg = NULL; +void *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid, bool isDecode) { + STSma *pCfg = NULL; SMetaDB *pDB = pMeta->pDB; DBT key = {0}; DBT value = {0}; @@ -711,9 +708,9 @@ static SSchemaWrapper *metaGetTableSchemaImpl(SMeta *pMeta, tb_uid_t uid, int32_ int ret; void *pBuf; // SSchema *pSchema; - SSchemaKey schemaKey = {uid, sver, 0}; - DBT key = {0}; - DBT value = {0}; + SSchemaKey schemaKey = {uid, sver, 0}; + DBT key = {0}; + DBT value = {0}; // Set key/value properties key.data = &schemaKey; @@ -761,14 +758,14 @@ SMTbCursor *metaOpenTbCursor(SMeta *pMeta) { } int metaGetTbNum(SMeta *pMeta) { - SMetaDB *pDB = pMeta->pDB; + SMetaDB *pDB = pMeta->pDB; DB_BTREE_STAT *sp1; pDB->pTbDB->stat(pDB->pNtbIdx, NULL, &sp1, 0); - + DB_BTREE_STAT *sp2; pDB->pTbDB->stat(pDB->pCtbIdx, NULL, &sp2, 0); - + return sp1->bt_nkeys + sp2->bt_nkeys; } @@ -920,7 +917,7 @@ SMSmaCursor *metaOpenSmaCursor(SMeta *pMeta, tb_uid_t uid) { return pCur; } -void metaCloseSmaCurosr(SMSmaCursor *pCur) { +void metaCloseSmaCursor(SMSmaCursor *pCur) { if (pCur) { if (pCur->pCur) { pCur->pCur->close(pCur->pCur); @@ -930,7 +927,8 @@ void metaCloseSmaCurosr(SMSmaCursor *pCur) { } } -const char *metaSmaCursorNext(SMSmaCursor *pCur) { +int64_t metaSmaCursorNext(SMSmaCursor *pCur) { +#if 0 DBT skey = {0}; DBT pkey = {0}; DBT pval = {0}; @@ -946,6 +944,8 @@ const char *metaSmaCursorNext(SMSmaCursor *pCur) { } else { return NULL; } +#endif + return 0; } STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { @@ -972,7 +972,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { ++pSW->number; STSma *tptr = (STSma *)taosMemoryRealloc(pSW->tSma, pSW->number * sizeof(STSma)); if (tptr == NULL) { - metaCloseSmaCurosr(pCur); + metaCloseSmaCursor(pCur); tdDestroyTSmaWrapper(pSW); taosMemoryFreeClear(pSW); return NULL; @@ -980,7 +980,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { pSW->tSma = tptr; pBuf = pval.data; if (tDecodeTSma(pBuf, pSW->tSma + pSW->number - 1) == NULL) { - metaCloseSmaCurosr(pCur); + metaCloseSmaCursor(pCur); tdDestroyTSmaWrapper(pSW); taosMemoryFreeClear(pSW); return NULL; @@ -990,8 +990,8 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { break; } - metaCloseSmaCurosr(pCur); - + metaCloseSmaCursor(pCur); + return pSW; } @@ -1004,7 +1004,7 @@ SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) { int ret; // TODO: lock? - ret = pDB->pCtbIdx->cursor(pDB->pSmaIdx, NULL, &pCur, 0); + ret = pDB->pSmaIdx->cursor(pDB->pSmaIdx, NULL, &pCur, 0); if (ret != 0) { return NULL; } diff --git a/source/dnode/vnode/src/meta/metaCache.c b/source/dnode/vnode/src/meta/metaCache.c deleted file mode 100644 index e1507a3757f017a67810e762123efbdf160ab513..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/meta/metaCache.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include "vnodeInt.h" - -struct SMetaCache { - // TODO -}; - -int metaOpenCache(SMeta *pMeta) { - // TODO - // if (pMeta->options.lruSize) { - // pMeta->pCache = rocksdb_cache_create_lru(pMeta->options.lruSize); - // if (pMeta->pCache == NULL) { - // // TODO: handle error - // return -1; - // } - // } - - return 0; -} - -void metaCloseCache(SMeta *pMeta) { - // if (pMeta->pCache) { - // rocksdb_cache_destroy(pMeta->pCache); - // pMeta->pCache = NULL; - // } -} \ No newline at end of file diff --git a/source/dnode/vnode/src/meta/metaCfg.c b/source/dnode/vnode/src/meta/metaCfg.c deleted file mode 100644 index a5fcb32698d3fdd9ac6795eaab789b6bfbb0bebb..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/meta/metaCfg.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include "vnodeInt.h" - -const SMetaCfg defaultMetaOptions = {.lruSize = 0}; - -/* ------------------------ EXPOSED METHODS ------------------------ */ -void metaOptionsInit(SMetaCfg *pMetaOptions) { metaOptionsCopy(pMetaOptions, &defaultMetaOptions); } - -void metaOptionsClear(SMetaCfg *pMetaOptions) { - // TODO -} - -int metaValidateOptions(const SMetaCfg *pMetaOptions) { - // TODO - return 0; -} - -void metaOptionsCopy(SMetaCfg *pDest, const SMetaCfg *pSrc) { memcpy(pDest, pSrc, sizeof(*pSrc)); } - -/* ------------------------ STATIC METHODS ------------------------ */ \ No newline at end of file diff --git a/source/dnode/vnode/src/meta/metaMain.c b/source/dnode/vnode/src/meta/metaMain.c index ac47c32cbf02131d353541eedb026a61b39bbdf1..dd60e56371bd3b2f589a75823504eba2492ecaa9 100644 --- a/source/dnode/vnode/src/meta/metaMain.c +++ b/source/dnode/vnode/src/meta/metaMain.c @@ -25,17 +25,6 @@ static void metaCloseImpl(SMeta *pMeta); SMeta *metaOpen(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF) { SMeta *pMeta = NULL; - // Set default options - if (pMetaCfg == NULL) { - pMetaCfg = &defaultMetaOptions; - } - - // // Validate the options - // if (metaValidateOptions(pMetaCfg) < 0) { - // // TODO: deal with error - // return NULL; - // } - // Allocate handle pMeta = metaNew(path, pMetaCfg, pMAF); if (pMeta == NULL) { @@ -80,9 +69,6 @@ static SMeta *metaNew(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorF return NULL; } - metaOptionsCopy(&(pMeta->options), pMetaCfg); - pMeta->pmaf = pMAF; - return pMeta; }; @@ -94,13 +80,6 @@ static void metaFree(SMeta *pMeta) { } static int metaOpenImpl(SMeta *pMeta) { - // Open meta cache - if (metaOpenCache(pMeta) < 0) { - // TODO: handle error - metaCloseImpl(pMeta); - return -1; - } - // Open meta db if (metaOpenDB(pMeta) < 0) { // TODO: handle error @@ -129,5 +108,4 @@ static void metaCloseImpl(SMeta *pMeta) { metaCloseUidGnrt(pMeta); metaCloseIdx(pMeta); metaCloseDB(pMeta); - metaCloseCache(pMeta); } \ No newline at end of file diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c deleted file mode 100644 index 6dea4a4e57392be988126c579648f39a8270b9bf..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ \ No newline at end of file diff --git a/source/dnode/vnode/src/meta/metaTDBImpl.c b/source/dnode/vnode/src/meta/metaTDBImpl.c index c78691e7c25099d3e96bac5f7412aba9ac7da230..9b9f54b5ba9016cc53f22ef7996f13ca98487fc9 100644 --- a/source/dnode/vnode/src/meta/metaTDBImpl.c +++ b/source/dnode/vnode/src/meta/metaTDBImpl.c @@ -15,13 +15,14 @@ #include "vnodeInt.h" -#include "tdbInt.h" typedef struct SPoolMem { int64_t size; struct SPoolMem *prev; struct SPoolMem *next; } SPoolMem; +#define META_TDB_SMA_TEST + static SPoolMem *openPool(); static void clearPool(SPoolMem *pPool); static void closePool(SPoolMem *pPool); @@ -38,6 +39,10 @@ struct SMetaDB { TDB *pNtbIdx; TDB *pCtbIdx; SPoolMem *pPool; +#ifdef META_TDB_SMA_TEST + TDB *pSmaDB; + TDB *pSmaIdx; +#endif }; typedef struct __attribute__((__packed__)) { @@ -55,6 +60,11 @@ typedef struct { tb_uid_t uid; } SCtbIdxKey; +typedef struct { + tb_uid_t uid; + int64_t smaUid; +} SSmaIdxKey; + static int metaEncodeTbInfo(void **buf, STbCfg *pTbCfg); static void *metaDecodeTbInfo(void *buf, STbCfg *pTbCfg); static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW); @@ -115,6 +125,17 @@ static inline int metaCtbIdxCmpr(const void *arg1, int len1, const void *arg2, i return metaUidCmpr(&pKey1->uid, sizeof(tb_uid_t), &pKey2->uid, sizeof(tb_uid_t)); } +static inline int metaSmaIdxCmpr(const void *arg1, int len1, const void *arg2, int len2) { + int c; + SSmaIdxKey *pKey1 = (SSmaIdxKey *)arg1; + SSmaIdxKey *pKey2 = (SSmaIdxKey *)arg2; + + c = metaUidCmpr(arg1, sizeof(tb_uid_t), arg2, sizeof(tb_uid_t)); + if (c) return c; + + return metaUidCmpr(&pKey1->smaUid, sizeof(int64_t), &pKey2->smaUid, sizeof(int64_t)); +} + int metaOpenDB(SMeta *pMeta) { SMetaDB *pMetaDb; int ret; @@ -143,6 +164,15 @@ int metaOpenDB(SMeta *pMeta) { return -1; } +#ifdef META_TDB_SMA_TEST + ret = tdbDbOpen("sma.db", sizeof(int64_t), TDB_VARIANT_LEN, metaUidCmpr, pMetaDb->pEnv, &(pMetaDb->pSmaDB)); + if (ret < 0) { + // TODO + ASSERT(0); + return -1; + } +#endif + // open schema DB ret = tdbDbOpen("schema.db", sizeof(SSchemaDbKey), TDB_VARIANT_LEN, metaSchemaKeyCmpr, pMetaDb->pEnv, &(pMetaDb->pSchemaDB)); @@ -180,6 +210,15 @@ int metaOpenDB(SMeta *pMeta) { return -1; } +#ifdef META_TDB_SMA_TEST + ret = tdbDbOpen("sma.idx", sizeof(SSmaIdxKey), 0, metaSmaIdxCmpr, pMetaDb->pEnv, &(pMetaDb->pSmaIdx)); + if (ret < 0) { + // TODO + ASSERT(0); + return -1; + } +#endif + pMetaDb->pPool = openPool(); tdbTxnOpen(&pMetaDb->txn, 0, poolMalloc, poolFree, pMetaDb->pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED); tdbBegin(pMetaDb->pEnv, NULL); @@ -193,10 +232,16 @@ void metaCloseDB(SMeta *pMeta) { tdbCommit(pMeta->pDB->pEnv, &pMeta->pDB->txn); tdbTxnClose(&pMeta->pDB->txn); clearPool(pMeta->pDB->pPool); +#ifdef META_TDB_SMA_TEST + tdbDbClose(pMeta->pDB->pSmaIdx); +#endif tdbDbClose(pMeta->pDB->pCtbIdx); tdbDbClose(pMeta->pDB->pNtbIdx); tdbDbClose(pMeta->pDB->pStbIdx); tdbDbClose(pMeta->pDB->pNameIdx); +#ifdef META_TDB_SMA_TEST + tdbDbClose(pMeta->pDB->pSmaDB); +#endif tdbDbClose(pMeta->pDB->pSchemaDB); tdbDbClose(pMeta->pDB->pTbDB); taosMemoryFree(pMeta->pDB); @@ -491,7 +536,6 @@ char *metaTbCursorNext(SMTbCursor *pTbCur) { taosMemoryFree(tbCfg.name); taosMemoryFree(tbCfg.stbCfg.pTagSchema); continue; - ; } else if (tbCfg.type == META_CHILD_TABLE) { kvRowFree(tbCfg.ctbCfg.pTag); } @@ -566,51 +610,325 @@ int metaGetTbNum(SMeta *pMeta) { return 0; } +struct SMSmaCursor { + TDBC *pCur; + tb_uid_t uid; + void *pKey; + void *pVal; + int kLen; + int vLen; +}; + STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) { // TODO - ASSERT(0); - return NULL; + // ASSERT(0); + // return NULL; +#ifdef META_TDB_SMA_TEST + STSmaWrapper *pSW = NULL; + + pSW = taosMemoryCalloc(1, sizeof(*pSW)); + if (pSW == NULL) { + return NULL; + } + + SMSmaCursor *pCur = metaOpenSmaCursor(pMeta, uid); + if (pCur == NULL) { + taosMemoryFree(pSW); + return NULL; + } + + void *pBuf = NULL; + SSmaIdxKey *pSmaIdxKey = NULL; + + while (true) { + // TODO: lock during iterate? + if (tdbDbNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) { + pSmaIdxKey = pCur->pKey; + ASSERT(pSmaIdxKey != NULL); + + void *pSmaVal = metaGetSmaInfoByIndex(pMeta, pSmaIdxKey->smaUid, false); + + if (pSmaVal == NULL) { + tsdbWarn("no tsma exists for indexUid: %" PRIi64, pSmaIdxKey->smaUid); + continue; + } + + ++pSW->number; + STSma *tptr = (STSma *)taosMemoryRealloc(pSW->tSma, pSW->number * sizeof(STSma)); + if (tptr == NULL) { + TDB_FREE(pSmaVal); + metaCloseSmaCursor(pCur); + tdDestroyTSmaWrapper(pSW); + taosMemoryFreeClear(pSW); + return NULL; + } + pSW->tSma = tptr; + pBuf = pSmaVal; + if (tDecodeTSma(pBuf, pSW->tSma + pSW->number - 1) == NULL) { + TDB_FREE(pSmaVal); + metaCloseSmaCursor(pCur); + tdDestroyTSmaWrapper(pSW); + taosMemoryFreeClear(pSW); + return NULL; + } + TDB_FREE(pSmaVal); + continue; + } + break; + } + + metaCloseSmaCursor(pCur); + + return pSW; + +#endif } int metaRemoveSmaFromDb(SMeta *pMeta, int64_t indexUid) { // TODO ASSERT(0); +#ifndef META_TDB_SMA_TEST + DBT key = {0}; + + key.data = (void *)indexName; + key.size = strlen(indexName); + + metaDBWLock(pMeta->pDB); + // TODO: No guarantee of consistence. + // Use transaction or DB->sync() for some guarantee. + pMeta->pDB->pSmaDB->del(pMeta->pDB->pSmaDB, NULL, &key, 0); + metaDBULock(pMeta->pDB); +#endif return 0; } int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) { // TODO - ASSERT(0); + // ASSERT(0); + +#ifdef META_TDB_SMA_TEST + int32_t ret = 0; + SMetaDB *pMetaDb = pMeta->pDB; + void *pBuf = NULL, *qBuf = NULL; + void *key = {0}, *val = {0}; + + // save sma info + int32_t len = tEncodeTSma(NULL, pSmaCfg); + pBuf = taosMemoryCalloc(1, len); + if (pBuf == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + key = (void *)&pSmaCfg->indexUid; + qBuf = pBuf; + tEncodeTSma(&qBuf, pSmaCfg); + val = pBuf; + + int32_t kLen = sizeof(pSmaCfg->indexUid); + int32_t vLen = POINTER_DISTANCE(qBuf, pBuf); + + ret = tdbDbInsert(pMeta->pDB->pSmaDB, key, kLen, val, vLen, &pMetaDb->txn); + if (ret < 0) { + taosMemoryFreeClear(pBuf); + return -1; + } + + // add sma idx + SSmaIdxKey smaIdxKey; + smaIdxKey.uid = pSmaCfg->tableUid; + smaIdxKey.smaUid = pSmaCfg->indexUid; + key = &smaIdxKey; + kLen = sizeof(smaIdxKey); + val = NULL; + vLen = 0; + + ret = tdbDbInsert(pMeta->pDB->pSmaIdx, key, kLen, val, vLen, &pMetaDb->txn); + if (ret < 0) { + taosMemoryFreeClear(pBuf); + return -1; + } + + // release + taosMemoryFreeClear(pBuf); + + if (pMeta->pDB->pPool->size > 0) { + metaCommit(pMeta); + } + +#endif return 0; } -STSma *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid) { +void *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid, bool isDecode) { // TODO - ASSERT(0); - return NULL; + // ASSERT(0); + // return NULL; +#ifdef META_TDB_SMA_TEST + SMetaDB *pDB = pMeta->pDB; + void *pKey = NULL; + void *pVal = NULL; + int kLen = 0; + int vLen = 0; + int ret = -1; + + // Set key + pKey = (void *)&indexUid; + kLen = sizeof(indexUid); + + // Query + ret = tdbDbGet(pDB->pSmaDB, pKey, kLen, &pVal, &vLen); + if (ret != 0 || !pVal) { + return NULL; + } + + if (!isDecode) { + // return raw value + return pVal; + } + + // Decode + STSma *pCfg = (STSma *)taosMemoryCalloc(1, sizeof(STSma)); + if (pCfg == NULL) { + taosMemoryFree(pVal); + return NULL; + } + + void *pBuf = pVal; + if (tDecodeTSma(pBuf, pCfg) == NULL) { + tdDestroyTSma(pCfg); + taosMemoryFree(pCfg); + TDB_FREE(pVal); + return NULL; + } + + TDB_FREE(pVal); + return pCfg; +#endif } -const char *metaSmaCursorNext(SMSmaCursor *pCur) { +/** + * @brief + * + * @param pMeta + * @param uid 0 means iterate all uids. + * @return SMSmaCursor* + */ +SMSmaCursor *metaOpenSmaCursor(SMeta *pMeta, tb_uid_t uid) { // TODO - ASSERT(0); - return NULL; + // ASSERT(0); + // return NULL; +#ifdef META_TDB_SMA_TEST + SMSmaCursor *pCur = NULL; + SMetaDB *pDB = pMeta->pDB; + int ret; + + pCur = (SMSmaCursor *)taosMemoryCalloc(1, sizeof(*pCur)); + if (pCur == NULL) { + return NULL; + } + + pCur->uid = uid; + ret = tdbDbcOpen(pDB->pSmaIdx, &(pCur->pCur)); + if ((ret != 0) || (pCur->pCur == NULL)) { + taosMemoryFree(pCur); + return NULL; + } + + if (uid != 0) { + // TODO: move to the specific uid + } + + return pCur; +#endif } -void metaCloseSmaCurosr(SMSmaCursor *pCur) { +/** + * @brief + * + * @param pCur + * @return int64_t smaIndexUid + */ +int64_t metaSmaCursorNext(SMSmaCursor *pCur) { // TODO - ASSERT(0); + // ASSERT(0); + // return NULL; +#ifdef META_TDB_SMA_TEST + int ret; + void *pBuf; + SSmaIdxKey *smaIdxKey; + + ret = tdbDbNext(pCur->pCur, &pCur->pKey, &pCur->kLen, &pCur->pVal, &pCur->vLen); + if (ret < 0) { + return 0; + } + smaIdxKey = pCur->pKey; + return smaIdxKey->smaUid; +#endif } -SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) { +void metaCloseSmaCursor(SMSmaCursor *pCur) { // TODO - // ASSERT(0); // comment this line to pass CI - return NULL; + // ASSERT(0); +#ifdef META_TDB_SMA_TEST + if (pCur) { + if (pCur->pCur) { + tdbDbcClose(pCur->pCur); + } + + taosMemoryFree(pCur); + } +#endif } -SMSmaCursor *metaOpenSmaCursor(SMeta *pMeta, tb_uid_t uid) { +SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) { // TODO - ASSERT(0); - return NULL; + // ASSERT(0); // comment this line to pass CI + // return NULL: +#ifdef META_TDB_SMA_TEST + SArray *pUids = NULL; + SMetaDB *pDB = pMeta->pDB; + void *pKey; + + // TODO: lock? + SMSmaCursor *pCur = metaOpenSmaCursor(pMeta, 0); + if (pCur == NULL) { + return NULL; + } + // TODO: lock? + + SSmaIdxKey *pSmaIdxKey = NULL; + tb_uid_t uid = 0; + while (true) { + // TODO: lock during iterate? + if (tdbDbNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) { + ASSERT(pSmaIdxKey != NULL); + pSmaIdxKey = pCur->pKey; + + if (pSmaIdxKey->uid == 0 || pSmaIdxKey->uid == uid) { + continue; + } + uid = pSmaIdxKey->uid; + + if (!pUids) { + pUids = taosArrayInit(16, sizeof(tb_uid_t)); + if (!pUids) { + metaCloseSmaCursor(pCur); + return NULL; + } + } + + taosArrayPush(pUids, &uid); + + continue; + } + break; + } + + metaCloseSmaCursor(pCur); + + return pUids; +#endif } static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW) { @@ -621,6 +939,7 @@ static int metaEncodeSchema(void **buf, SSchemaWrapper *pSW) { for (int i = 0; i < pSW->nCols; i++) { pSchema = pSW->pSchema + i; tlen += taosEncodeFixedI8(buf, pSchema->type); + tlen += taosEncodeFixedI8(buf, pSchema->index); tlen += taosEncodeFixedI16(buf, pSchema->colId); tlen += taosEncodeFixedI32(buf, pSchema->bytes); tlen += taosEncodeString(buf, pSchema->name); @@ -637,6 +956,7 @@ static void *metaDecodeSchema(void *buf, SSchemaWrapper *pSW) { for (int i = 0; i < pSW->nCols; i++) { pSchema = pSW->pSchema + i; buf = taosDecodeFixedI8(buf, &pSchema->type); + buf = taosSkipFixedLen(buf, sizeof(int8_t)); buf = taosDecodeFixedI16(buf, &pSchema->colId); buf = taosDecodeFixedI32(buf, &pSchema->bytes); buf = taosDecodeStringTo(buf, pSchema->name); diff --git a/source/dnode/vnode/src/meta/metaTbCfg.c b/source/dnode/vnode/src/meta/metaTbCfg.c deleted file mode 100644 index 8ecc808786992bfe436716105fec9640b404e680..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/meta/metaTbCfg.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include "vnodeInt.h" -#include "tcoding.h" - -int metaValidateTbCfg(SMeta *pMeta, const STbCfg *pTbOptions) { - // TODO - return 0; -} - -size_t metaEncodeTbObjFromTbOptions(const STbCfg *pTbOptions, void *pBuf, size_t bsize) { - void **ppBuf = &pBuf; - int tlen = 0; - - tlen += taosEncodeFixedU8(ppBuf, pTbOptions->type); - tlen += taosEncodeString(ppBuf, pTbOptions->name); - tlen += taosEncodeFixedU32(ppBuf, pTbOptions->ttl); - - switch (pTbOptions->type) { - case META_SUPER_TABLE: - tlen += taosEncodeFixedU64(ppBuf, pTbOptions->stbCfg.suid); - tlen += tdEncodeSchema(ppBuf, (STSchema *)pTbOptions->stbCfg.pTagSchema); - // TODO: encode schema version array - break; - case META_CHILD_TABLE: - tlen += taosEncodeFixedU64(ppBuf, pTbOptions->ctbCfg.suid); - break; - case META_NORMAL_TABLE: - // TODO: encode schema version array - break; - default: - break; - } - - return tlen; -} \ No newline at end of file diff --git a/source/dnode/vnode/src/meta/metaTbTag.c b/source/dnode/vnode/src/meta/metaTbTag.c deleted file mode 100644 index 6dea4a4e57392be988126c579648f39a8270b9bf..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/meta/metaTbTag.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ \ No newline at end of file diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 0d4acd4594e3bbe546fbba47ecd042ed8fd1eef4..bfcc5dd2bb78db54ec7162c682ddf639c0fd760a 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -13,9 +13,6 @@ * along with this program. If not, see . */ -#include "tcompare.h" -#include "tdatablock.h" -#include "tstream.h" #include "vnodeInt.h" int32_t tqInit() { return tqPushMgrInit(); } @@ -82,9 +79,9 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t versi memcpy(data, msg, msgLen); if (msgType == TDMT_VND_SUBMIT) { - // if (tsdbUpdateSmaWindow(pTq->pVnode->pTsdb, msg) != 0) { - // return -1; - // } + if (tsdbUpdateSmaWindow(pTq->pVnode->pTsdb, msg, version) != 0) { + return -1; + } } SRpcMsg req = { @@ -129,8 +126,8 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t versi int tqCommit(STQ* pTq) { return tqStorePersist(pTq->tqMeta); } int32_t tqGetTopicHandleSize(const STqTopic* pTopic) { - return strlen(pTopic->topicName) + strlen(pTopic->sql) + strlen(pTopic->logicalPlan) + strlen(pTopic->physicalPlan) + - strlen(pTopic->qmsg) + sizeof(int64_t) * 3; + return strlen(pTopic->topicName) + strlen(pTopic->sql) + strlen(pTopic->physicalPlan) + strlen(pTopic->qmsg) + + sizeof(int64_t) * 3; } int32_t tqGetConsumerHandleSize(const STqConsumer* pConsumer) { @@ -147,7 +144,6 @@ static FORCE_INLINE int32_t tEncodeSTqTopic(void** buf, const STqTopic* pTopic) int32_t tlen = 0; tlen += taosEncodeString(buf, pTopic->topicName); /*tlen += taosEncodeString(buf, pTopic->sql);*/ - /*tlen += taosEncodeString(buf, pTopic->logicalPlan);*/ /*tlen += taosEncodeString(buf, pTopic->physicalPlan);*/ tlen += taosEncodeString(buf, pTopic->qmsg); /*tlen += taosEncodeFixedI64(buf, pTopic->persistedOffset);*/ @@ -159,7 +155,6 @@ static FORCE_INLINE int32_t tEncodeSTqTopic(void** buf, const STqTopic* pTopic) static FORCE_INLINE const void* tDecodeSTqTopic(const void* buf, STqTopic* pTopic) { buf = taosDecodeStringTo(buf, pTopic->topicName); /*buf = taosDecodeString(buf, &pTopic->sql);*/ - /*buf = taosDecodeString(buf, &pTopic->logicalPlan);*/ /*buf = taosDecodeString(buf, &pTopic->physicalPlan);*/ buf = taosDecodeString(buf, &pTopic->qmsg); /*buf = taosDecodeFixedI64(buf, &pTopic->persistedOffset);*/ @@ -255,7 +250,7 @@ int32_t tqDeserializeConsumer(STQ* pTq, const STqSerializedHead* pHead, STqConsu return 0; } - +#if 0 int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { SMqPollReq* pReq = pMsg->pCont; int64_t consumerId = pReq->consumerId; @@ -433,6 +428,215 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { return 0; } +#endif + +int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { + SMqPollReq* pReq = pMsg->pCont; + int64_t consumerId = pReq->consumerId; + int64_t fetchOffset; + int64_t blockingTime = pReq->blockingTime; + int32_t reqEpoch = pReq->epoch; + + if (pReq->currentOffset == TMQ_CONF__RESET_OFFSET__EARLIEAST) { + fetchOffset = 0; + } else if (pReq->currentOffset == TMQ_CONF__RESET_OFFSET__LATEST) { + fetchOffset = walGetLastVer(pTq->pWal); + } else { + fetchOffset = pReq->currentOffset + 1; + } + + vDebug("tmq poll: consumer %ld (epoch %d) recv poll req in vg %d, req %ld %ld", consumerId, pReq->epoch, + pTq->pVnode->vgId, pReq->currentOffset, fetchOffset); + + SMqPollRspV2 rspV2 = {0}; + rspV2.dataLen = 0; + + STqConsumer* pConsumer = tqHandleGet(pTq->tqMeta, consumerId); + if (pConsumer == NULL) { + vWarn("tmq poll: consumer %ld (epoch %d) not found in vg %d", consumerId, pReq->epoch, pTq->pVnode->vgId); + pMsg->pCont = NULL; + pMsg->contLen = 0; + pMsg->code = -1; + tmsgSendRsp(pMsg); + return 0; + } + + int32_t consumerEpoch = atomic_load_32(&pConsumer->epoch); + while (consumerEpoch < reqEpoch) { + consumerEpoch = atomic_val_compare_exchange_32(&pConsumer->epoch, consumerEpoch, reqEpoch); + } + + STqTopic* pTopic = NULL; + int32_t topicSz = taosArrayGetSize(pConsumer->topics); + for (int32_t i = 0; i < topicSz; i++) { + STqTopic* topic = taosArrayGet(pConsumer->topics, i); + // TODO race condition + ASSERT(pConsumer->consumerId == consumerId); + if (strcmp(topic->topicName, pReq->topic) == 0) { + pTopic = topic; + break; + } + } + if (pTopic == NULL) { + vWarn("tmq poll: consumer %ld (epoch %d) topic %s not found in vg %d", consumerId, pReq->epoch, pReq->topic, + pTq->pVnode->vgId); + pMsg->pCont = NULL; + pMsg->contLen = 0; + pMsg->code = -1; + tmsgSendRsp(pMsg); + return 0; + } + + vDebug("poll topic %s from consumer %ld (epoch %d) vg %d", pTopic->topicName, consumerId, pReq->epoch, + pTq->pVnode->vgId); + + rspV2.reqOffset = pReq->currentOffset; + rspV2.skipLogNum = 0; + + while (1) { + /*if (fetchOffset > walGetLastVer(pTq->pWal) || walReadWithHandle(pTopic->pReadhandle, fetchOffset) < 0) {*/ + // TODO + consumerEpoch = atomic_load_32(&pConsumer->epoch); + if (consumerEpoch > reqEpoch) { + vDebug("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, found new consumer epoch %d discard req epoch %d", + consumerId, pReq->epoch, pTq->pVnode->vgId, fetchOffset, consumerEpoch, reqEpoch); + break; + } + SWalReadHead* pHead; + if (walReadWithHandle_s(pTopic->pReadhandle, fetchOffset, &pHead) < 0) { + // TODO: no more log, set timer to wait blocking time + // if data inserted during waiting, launch query and + // response to user + vDebug("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, no more log to return", consumerId, pReq->epoch, + pTq->pVnode->vgId, fetchOffset); + break; + } + vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d", consumerId, pReq->epoch, + pTq->pVnode->vgId, fetchOffset, pHead->msgType); + /*int8_t pos = fetchOffset % TQ_BUFFER_SIZE;*/ + /*pHead = pTopic->pReadhandle->pHead;*/ + if (pHead->msgType == TDMT_VND_SUBMIT) { + SSubmitReq* pCont = (SSubmitReq*)&pHead->body; + qTaskInfo_t task = pTopic->buffer.output[workerId].task; + ASSERT(task); + qSetStreamInput(task, pCont, STREAM_DATA_TYPE_SUBMIT_BLOCK); + SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock)); + while (1) { + SSDataBlock* pDataBlock = NULL; + uint64_t ts; + if (qExecTask(task, &pDataBlock, &ts) < 0) { + ASSERT(false); + } + if (pDataBlock == NULL) { + /*pos = fetchOffset % TQ_BUFFER_SIZE;*/ + break; + } + + taosArrayPush(pRes, pDataBlock); + } + + if (taosArrayGetSize(pRes) == 0) { + vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d skip log %ld since not wanted", consumerId, + pReq->epoch, pTq->pVnode->vgId, fetchOffset); + fetchOffset++; + rspV2.skipLogNum++; + taosArrayDestroy(pRes); + continue; + } + rspV2.rspOffset = fetchOffset; + + int32_t blockSz = taosArrayGetSize(pRes); + int32_t dataBlockStrLen = 0; + for (int32_t i = 0; i < blockSz; i++) { + SSDataBlock* pBlock = taosArrayGet(pRes, i); + dataBlockStrLen += sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock); + } + + void* dataBlockBuf = taosMemoryMalloc(dataBlockStrLen); + if (dataBlockBuf == NULL) { + pMsg->code = -1; + taosMemoryFree(pHead); + } + + rspV2.blockData = dataBlockBuf; + + int32_t pos; + rspV2.blockPos = taosArrayInit(blockSz, sizeof(int32_t)); + for (int32_t i = 0; i < blockSz; i++) { + pos = 0; + SSDataBlock* pBlock = taosArrayGet(pRes, i); + SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)dataBlockBuf; + pRetrieve->useconds = 0; + pRetrieve->precision = 0; + pRetrieve->compressed = 0; + pRetrieve->completed = 1; + pRetrieve->numOfRows = htonl(pBlock->info.rows); + blockCompressEncode(pBlock, pRetrieve->data, &pos, pBlock->info.numOfCols, false); + taosArrayPush(rspV2.blockPos, &rspV2.dataLen); + + int32_t totLen = sizeof(SRetrieveTableRsp) + pos; + pRetrieve->compLen = htonl(totLen); + rspV2.dataLen += totLen; + dataBlockBuf = POINTER_SHIFT(dataBlockBuf, totLen); + } + ASSERT(POINTER_DISTANCE(dataBlockBuf, rspV2.blockData) <= dataBlockStrLen); + + int32_t msgLen = sizeof(SMqRspHead) + tEncodeSMqPollRspV2(NULL, &rspV2); + void* buf = rpcMallocCont(msgLen); + + ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP; + ((SMqRspHead*)buf)->epoch = pReq->epoch; + ((SMqRspHead*)buf)->consumerId = consumerId; + + void* msgBodyBuf = POINTER_SHIFT(buf, sizeof(SMqRspHead)); + tEncodeSMqPollRspV2(&msgBodyBuf, &rspV2); + + /*rsp.pBlockData = pRes;*/ + + /*taosArrayDestroyEx(rsp.pBlockData, (void (*)(void*))tDeleteSSDataBlock);*/ + pMsg->pCont = buf; + pMsg->contLen = msgLen; + pMsg->code = 0; + vDebug("vg %d offset %ld msgType %d from consumer %ld (epoch %d) actual rsp", pTq->pVnode->vgId, fetchOffset, + pHead->msgType, consumerId, pReq->epoch); + tmsgSendRsp(pMsg); + taosMemoryFree(pHead); + return 0; + } else { + taosMemoryFree(pHead); + fetchOffset++; + rspV2.skipLogNum++; + } + } + + /*if (blockingTime != 0) {*/ + /*tqAddClientPusher(pTq->tqPushMgr, pMsg, consumerId, blockingTime);*/ + /*} else {*/ + + rspV2.rspOffset = fetchOffset - 1; + + int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqPollRspV2(NULL, &rspV2); + void* buf = rpcMallocCont(tlen); + if (buf == NULL) { + pMsg->code = -1; + return -1; + } + ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP; + ((SMqRspHead*)buf)->epoch = pReq->epoch; + ((SMqRspHead*)buf)->consumerId = consumerId; + + void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead)); + tEncodeSMqPollRspV2(&abuf, &rspV2); + pMsg->pCont = buf; + pMsg->contLen = tlen; + pMsg->code = 0; + tmsgSendRsp(pMsg); + vDebug("vg %d offset %ld from consumer %ld (epoch %d) not rsp", pTq->pVnode->vgId, fetchOffset, consumerId, + pReq->epoch); + /*}*/ + + return 0; +} int32_t tqProcessRebReq(STQ* pTq, char* msg) { SMqMVRebReq req = {0}; @@ -516,7 +720,6 @@ int32_t tqProcessSetConnReq(STQ* pTq, char* msg) { } strcpy(pTopic->topicName, req.topicName); pTopic->sql = req.sql; - pTopic->logicalPlan = req.logicalPlan; pTopic->physicalPlan = req.physicalPlan; pTopic->qmsg = req.qmsg; /*pTopic->committedOffset = -1;*/ diff --git a/source/dnode/vnode/src/tq/tqCommit.c b/source/dnode/vnode/src/tq/tqCommit.c index f2f48bbc8a69a022d0fc6b8a88c5a9a55d0b4ad6..8e59243a9c9ef41f60d6c835b9b26b45575acc0f 100644 --- a/source/dnode/vnode/src/tq/tqCommit.c +++ b/source/dnode/vnode/src/tq/tqCommit.c @@ -12,3 +12,5 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ + +#include "vnodeInt.h" diff --git a/source/dnode/vnode/src/tq/tqMetaStore.c b/source/dnode/vnode/src/tq/tqMetaStore.c index beb19f48f1f71a0b1b51cc18783d987aef9eaef3..357917e0ba4afce1127dc041ac00871ef0d2a6af 100644 --- a/source/dnode/vnode/src/tq/tqMetaStore.c +++ b/source/dnode/vnode/src/tq/tqMetaStore.c @@ -14,13 +14,13 @@ */ #include "vnodeInt.h" // TODO:replace by an abstract file layer -#include -#include -#include -#include "osDir.h" +// #include +// #include +// #include +// #include "osDir.h" #define TQ_META_NAME "tq.meta" -#define TQ_IDX_NAME "tq.idx" +#define TQ_IDX_NAME "tq.idx" static int32_t tqHandlePutCommitted(STqMetaStore*, int64_t key, void* value); static void* tqHandleGetUncommitted(STqMetaStore*, int64_t key); @@ -95,7 +95,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F tqError("failed to create dir:%s since %s ", name, terrstr()); } strcat(name, "/" TQ_IDX_NAME); - TdFilePtr pIdxFile = taosOpenFile(name, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_READ); + TdFilePtr pIdxFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ); if (pIdxFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); tqError("failed to open file:%s since %s ", name, terrstr()); @@ -113,7 +113,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F strcpy(name, path); strcat(name, "/" TQ_META_NAME); - TdFilePtr pFile = taosOpenFile(name, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_READ); + TdFilePtr pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); tqError("failed to open file:%s since %s", name, terrstr()); diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index c69f8ce09a346bcb3eeb8c9b17874b82bd7fc170..9282f7197e7b8a6e3d775ebdf34bca276871d664 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -13,8 +13,7 @@ * along with this program. If not, see . */ -#include "tdatablock.h" -#include "vnode.h" +#include "vnodeInt.h" STqReadHandle* tqInitSubmitMsgScanner(SMeta* pMeta) { STqReadHandle* pReadHandle = taosMemoryMalloc(sizeof(STqReadHandle)); @@ -88,7 +87,7 @@ int tqRetrieveDataBlockInfo(STqReadHandle* pHandle, SDataBlockInfo* pBlockInfo) pBlockInfo->numOfCols = taosArrayGetSize(pHandle->pColIdList); pBlockInfo->rows = pHandle->pBlock->numOfRows; -// pBlockInfo->uid = pHandle->pBlock->uid; // the uid can not be assigned to pBlockData. + // pBlockInfo->uid = pHandle->pBlock->uid; // the uid can not be assigned to pBlockData. return 0; } @@ -177,3 +176,41 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { } return pArray; } + +void tqReadHandleSetColIdList(STqReadHandle* pReadHandle, SArray* pColIdList) { pReadHandle->pColIdList = pColIdList; } + +int tqReadHandleSetTbUidList(STqReadHandle* pHandle, const SArray* tbUidList) { + if (pHandle->tbIdHash) { + taosHashClear(pHandle->tbIdHash); + } + + pHandle->tbIdHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); + if (pHandle->tbIdHash == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + for (int i = 0; i < taosArrayGetSize(tbUidList); i++) { + int64_t* pKey = (int64_t*)taosArrayGet(tbUidList, i); + taosHashPut(pHandle->tbIdHash, pKey, sizeof(int64_t), NULL, 0); + } + + return 0; +} + +int tqReadHandleAddTbUidList(STqReadHandle* pHandle, const SArray* tbUidList) { + if (pHandle->tbIdHash == NULL) { + pHandle->tbIdHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); + if (pHandle->tbIdHash == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + } + + for (int i = 0; i < taosArrayGetSize(tbUidList); i++) { + int64_t* pKey = (int64_t*)taosArrayGet(tbUidList, i); + taosHashPut(pHandle->tbIdHash, pKey, sizeof(int64_t), NULL, 0); + } + + return 0; +} diff --git a/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c b/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c deleted file mode 100644 index 0deef2e4c9f6de92b68a334434814fb27d3f1a99..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define ALLOW_FORBID_FUNC -#include "db.h" - -#include "taoserror.h" -#include "tcoding.h" -#include "thash.h" - -#define IMPL_WITH_LOCK 1 - -static int tsdbOpenBDBDb(DB **ppDB, DB_ENV *pEnv, const char *pFName, bool isDup); -static void tsdbCloseBDBDb(DB *pDB); - -#define BDB_PERR(info, code) fprintf(stderr, "%s:%d " info " reason: %s\n", __FILE__, __LINE__, db_strerror(code)) - -int32_t tsdbOpenDBF(TDBEnv pEnv, SDBFile *pDBF) { - // TDBEnv is shared by a group of SDBFile - if (!pEnv) { - terrno = TSDB_CODE_INVALID_PTR; - return -1; - } - - // Open DBF - if (tsdbOpenBDBDb(&(pDBF->pDB), pEnv, pDBF->path, false) < 0) { - terrno = TSDB_CODE_TDB_INIT_FAILED; - tsdbCloseBDBDb(pDBF->pDB); - return -1; - } - - return 0; -} - -void tsdbCloseDBF(SDBFile *pDBF) { - if (pDBF->pDB) { - tsdbCloseBDBDb(pDBF->pDB); - pDBF->pDB = NULL; - } - taosMemoryFreeClear(pDBF->path); -} - -int32_t tsdbOpenBDBEnv(DB_ENV **ppEnv, const char *path) { - int ret = 0; - DB_ENV *pEnv = NULL; - - if (path == NULL) return 0; - - ret = db_env_create(&pEnv, 0); - if (ret != 0) { - BDB_PERR("Failed to create tsdb env", ret); - return -1; - } - - ret = pEnv->open(pEnv, path, DB_CREATE | DB_INIT_CDB | DB_INIT_MPOOL, 0); - if (ret != 0) { - terrno = TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR; - tsdbWarn("Failed to open tsdb env for path %s since ret %d != 0", path ? path : "NULL", ret); - return -1; - } - - *ppEnv = pEnv; - - return 0; -} - -void tsdbCloseBDBEnv(DB_ENV *pEnv) { - if (pEnv) { - pEnv->close(pEnv, 0); - } -} - -static int tsdbOpenBDBDb(DB **ppDB, DB_ENV *pEnv, const char *pFName, bool isDup) { - int ret; - DB *pDB; - - ret = db_create(&(pDB), pEnv, 0); - if (ret != 0) { - BDB_PERR("Failed to create DBP", ret); - return -1; - } - - if (isDup) { - ret = pDB->set_flags(pDB, DB_DUPSORT); - if (ret != 0) { - BDB_PERR("Failed to set DB flags", ret); - return -1; - } - } - - ret = pDB->open(pDB, NULL, pFName, NULL, DB_BTREE, DB_CREATE, 0); - if (ret) { - BDB_PERR("Failed to open DBF", ret); - return -1; - } - - *ppDB = pDB; - - return 0; -} - -static void tsdbCloseBDBDb(DB *pDB) { - if (pDB) { - pDB->close(pDB, 0); - } -} - -int32_t tsdbSaveSmaToDB(SDBFile *pDBF, void *key, uint32_t keySize, void *data, uint32_t dataSize) { - int ret; - DBT key1 = {0}, value1 = {0}; - - key1.data = key; - key1.size = keySize; - - value1.data = data; - value1.size = dataSize; - - // TODO: lock - ret = pDBF->pDB->put(pDBF->pDB, NULL, &key1, &value1, 0); - if (ret) { - BDB_PERR("Failed to put data to DBF", ret); - // TODO: unlock - return -1; - } - // TODO: unlock - - return 0; -} - -void *tsdbGetSmaDataByKey(SDBFile *pDBF, void* key, uint32_t keySize, uint32_t *valueSize) { - void *result = NULL; - DBT key1 = {0}; - DBT value1 = {0}; - int ret; - - // Set key/value - key1.data = key; - key1.size = keySize; - - // Query - // TODO: lock - ret = pDBF->pDB->get(pDBF->pDB, NULL, &key1, &value1, 0); - // TODO: unlock - if (ret != 0) { - return NULL; - } - - result = taosMemoryCalloc(1, value1.size); - - if (result == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; - } - - *valueSize = value1.size; - memcpy(result, value1.data, value1.size); - - return result; -} \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 21ad1ec076f7916ea99504b82252fc5da4ebbc58..eb3266338720ae8e1222d54db16389b192e98b45 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -1298,7 +1298,7 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF int32_t tBitmaps = 0; int32_t tBitmapsLen = 0; if ((ncol != 0) && !TD_COL_ROWS_NORM(pBlockCol)) { - tBitmaps = sBitmaps; + tBitmaps = isSuper ? sBitmaps : nBitmaps; } #endif @@ -1678,10 +1678,11 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt ASSERT(pSchema != NULL); } - tdAppendSTSRowToDataCol(row, pSchema, pTarget, true); + tdAppendSTSRowToDataCol(row, pSchema, pTarget); tSkipListIterNext(pCommitIter->pIter); } else { +#if 0 if (update != TD_ROW_OVERWRITE_UPDATE) { // copy disk data for (int i = 0; i < pDataCols->numOfCols; ++i) { @@ -1706,6 +1707,43 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt } ++(*iter); tSkipListIterNext(pCommitIter->pIter); +#endif + // copy disk data + for (int i = 0; i < pDataCols->numOfCols; ++i) { + SCellVal sVal = {0}; + if (tdGetColDataOfRow(&sVal, pDataCols->cols + i, *iter, pDataCols->bitmapMode) < 0) { + TASSERT(0); + } + // TODO: tdAppendValToDataCol may fail + tdAppendValToDataCol(pTarget->cols + i, sVal.valType, sVal.val, pTarget->numOfRows, pTarget->maxPoints, + pTarget->bitmapMode); + } + + if (TD_SUPPORT_UPDATE(update)) { + // copy mem data(Multi-Version) + if (pSchema == NULL || schemaVersion(pSchema) != TD_ROW_SVER(row)) { + pSchema = tsdbGetTableSchemaImpl(pCommitIter->pTable, false, false, TD_ROW_SVER(row)); + ASSERT(pSchema != NULL); + } + + // TODO: merge with Multi-Version + STSRow *curRow = row; + + ++(*iter); + tSkipListIterNext(pCommitIter->pIter); + STSRow *nextRow = tsdbNextIterRow(pCommitIter->pIter); + + if (key2 < TD_ROW_KEY(nextRow)) { + tdAppendSTSRowToDataCol(row, pSchema, pTarget); + } else { + tdAppendSTSRowToDataCol(row, pSchema, pTarget); + } + // TODO: merge with Multi-Version + } else { + ++pTarget->numOfRows; + ++(*iter); + tSkipListIterNext(pCommitIter->pIter); + } } if (pTarget->numOfRows >= maxRows) break; diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index 1f42e906161fa1c81666a2c4391ccab906d0d7c6..bd3888864d17a9de59bbe3661464606e765fe7c1 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -13,9 +13,7 @@ * along with this program. If not, see . */ -#include #include "vnodeInt.h" -#include "os.h" typedef enum { TSDB_TXN_TEMP_FILE = 0, TSDB_TXN_CURR_FILE } TSDB_TXN_FILE_T; static const char *tsdbTxnFname[] = {"current.t", "current"}; @@ -97,8 +95,8 @@ static int tsdbEncodeDFileSetArray(void **buf, SArray *pArray) { return tlen; } -static void *tsdbDecodeDFileSetArray(STsdb*pRepo, void *buf, SArray *pArray) { - uint64_t nset = 0; +static void *tsdbDecodeDFileSetArray(STsdb *pRepo, void *buf, SArray *pArray) { + uint64_t nset = 0; taosArrayClear(pArray); @@ -122,7 +120,7 @@ static int tsdbEncodeFSStatus(void **buf, SFSStatus *pStatus) { return tlen; } -static void *tsdbDecodeFSStatus(STsdb*pRepo, void *buf, SFSStatus *pStatus) { +static void *tsdbDecodeFSStatus(STsdb *pRepo, void *buf, SFSStatus *pStatus) { tsdbResetFSStatus(pStatus); // pStatus->pmf = &(pStatus->mf); @@ -407,8 +405,8 @@ int tsdbUpdateDFileSet(STsdbFS *pfs, const SDFileSet *pSet) { return tsdbAddDFil static int tsdbSaveFSStatus(STsdb *pRepo, SFSStatus *pStatus) { SFSHeader fsheader; - void * pBuf = NULL; - void * ptr; + void *pBuf = NULL; + void *ptr; char hbuf[TSDB_FILE_HEAD_SIZE] = "\0"; char tfname[TSDB_FILENAME_LEN] = "\0"; char cfname[TSDB_FILENAME_LEN] = "\0"; @@ -416,7 +414,7 @@ static int tsdbSaveFSStatus(STsdb *pRepo, SFSStatus *pStatus) { tsdbGetTxnFname(pRepo, TSDB_TXN_TEMP_FILE, tfname); tsdbGetTxnFname(pRepo, TSDB_TXN_CURR_FILE, cfname); - TdFilePtr pFile = taosOpenFile(tfname, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(tfname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; @@ -592,7 +590,7 @@ void tsdbFSIterSeek(SFSIter *pIter, int fid) { } SDFileSet *tsdbFSIterNext(SFSIter *pIter) { - STsdbFS * pfs = pIter->pfs; + STsdbFS *pfs = pIter->pfs; SDFileSet *pSet; if (pIter->index < 0) { @@ -651,12 +649,12 @@ static void tsdbGetTxnFname(STsdb *pRepo, TSDB_TXN_FILE_T ftype, char fname[]) { } static int tsdbOpenFSFromCurrent(STsdb *pRepo) { - STsdbFS * pfs = REPO_FS(pRepo); + STsdbFS *pfs = REPO_FS(pRepo); TdFilePtr pFile = NULL; - void * buffer = NULL; + void *buffer = NULL; SFSHeader fsheader; char current[TSDB_FILENAME_LEN] = "\0"; - void * ptr; + void *ptr; tsdbGetTxnFname(pRepo, TSDB_TXN_CURR_FILE, current); @@ -746,7 +744,7 @@ _err: // Scan and try to fix incorrect files static int tsdbScanAndTryFixFS(STsdb *pRepo) { - STsdbFS * pfs = REPO_FS(pRepo); + STsdbFS *pfs = REPO_FS(pRepo); SFSStatus *pStatus = pfs->cstatus; // if (tsdbScanAndTryFixMFile(pRepo) < 0) { @@ -908,9 +906,9 @@ static int tsdbScanAndTryFixFS(STsdb *pRepo) { // } static int tsdbScanRootDir(STsdb *pRepo) { - char rootDir[TSDB_FILENAME_LEN]; - char bname[TSDB_FILENAME_LEN]; - STsdbFS * pfs = REPO_FS(pRepo); + char rootDir[TSDB_FILENAME_LEN]; + char bname[TSDB_FILENAME_LEN]; + STsdbFS *pfs = REPO_FS(pRepo); const STfsFile *pf; tsdbGetRootDir(REPO_ID(pRepo), rootDir); @@ -942,9 +940,9 @@ static int tsdbScanRootDir(STsdb *pRepo) { } static int tsdbScanDataDir(STsdb *pRepo) { - char dataDir[TSDB_FILENAME_LEN]; - char bname[TSDB_FILENAME_LEN]; - STsdbFS * pfs = REPO_FS(pRepo); + char dataDir[TSDB_FILENAME_LEN]; + char bname[TSDB_FILENAME_LEN]; + STsdbFS *pfs = REPO_FS(pRepo); const STfsFile *pf; tsdbGetDataDir(REPO_ID(pRepo), dataDir); @@ -1107,14 +1105,14 @@ static bool tsdbIsTFileInFS(STsdbFS *pfs, const STfsFile *pf) { // } static int tsdbRestoreDFileSet(STsdb *pRepo) { - char dataDir[TSDB_FILENAME_LEN]; - char bname[TSDB_FILENAME_LEN]; - STfsDir * tdir = NULL; + char dataDir[TSDB_FILENAME_LEN]; + char bname[TSDB_FILENAME_LEN]; + STfsDir *tdir = NULL; const STfsFile *pf = NULL; - const char * pattern = "^v[0-9]+f[0-9]+\\.(head|data|last|smad|smal)(-ver[0-9]+)?$"; - SArray * fArray = NULL; - regex_t regex; - STsdbFS * pfs = REPO_FS(pRepo); + const char *pattern = "^v[0-9]+f[0-9]+\\.(head|data|last|smad|smal)(-ver[0-9]+)?$"; + SArray *fArray = NULL; + regex_t regex; + STsdbFS *pfs = REPO_FS(pRepo); tsdbGetDataDir(REPO_ID(pRepo), dataDir); @@ -1327,7 +1325,7 @@ static int tsdbComparTFILE(const void *arg1, const void *arg2) { } static void tsdbScanAndTryFixDFilesHeader(STsdb *pRepo, int32_t *nExpired) { - STsdbFS * pfs = REPO_FS(pRepo); + STsdbFS *pfs = REPO_FS(pRepo); SFSStatus *pStatus = pfs->cstatus; SDFInfo info; diff --git a/source/dnode/vnode/src/tsdb/tsdbFile.c b/source/dnode/vnode/src/tsdb/tsdbFile.c index 6f96aff84820a9d92111ab545a7743fed570cfd8..8e5a6afc4dee400c9c33999bcd37e7ed41a9e1db 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFile.c +++ b/source/dnode/vnode/src/tsdb/tsdbFile.c @@ -360,7 +360,7 @@ static void *tsdbDecodeSDFileEx(void *buf, SDFile *pDFile) { int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader, TSDB_FILE_T fType) { ASSERT(pDFile->info.size == 0 && pDFile->info.magic == TSDB_FILE_INIT_MAGIC); - pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pDFile->pFile == NULL) { if (errno == ENOENT) { // Try to create directory recursively @@ -371,7 +371,7 @@ int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader, TSDB_FILE_T } taosMemoryFreeClear(s); - pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pDFile->pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index c657b2e9475c8d7ec8ebbda760b2ba306f2def97..5a477e646cb4ea2cf94cde85608dd813bb929a14 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -375,6 +375,8 @@ static int tsdbMemTableInsertTbData(STsdb *pTsdb, SSubmitBlk *pBlock, int32_t *p if (pMemTable->keyMin > keyMin) pMemTable->keyMin = keyMin; if (pMemTable->keyMax < keyMax) pMemTable->keyMax = keyMax; + (*pAffectedRows) += pBlock->numOfRows; + // STSRow* lastRow = NULL; // int64_t osize = SL_SIZE(pTableData->pData); // tsdbSetupSkipListHookFns(pTableData->pData, pRepo, pTable, &points, &lastRow); @@ -475,7 +477,7 @@ static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema * } } - tdAppendSTSRowToDataCol(row, *ppSchema, pCols, true); + tdAppendSTSRowToDataCol(row, *ppSchema, pCols); } return 0; diff --git a/source/dnode/vnode/src/tsdb/tsdbOptions.c b/source/dnode/vnode/src/tsdb/tsdbOptions.c index da7a1d393fa01ef8be07c5e8b0971dfe4677be27..2c57a7406e4733799c88b7a1286a64028249ea72 100644 --- a/source/dnode/vnode/src/tsdb/tsdbOptions.c +++ b/source/dnode/vnode/src/tsdb/tsdbOptions.c @@ -26,15 +26,6 @@ const STsdbCfg defautlTsdbOptions = {.precision = 0, .update = 0, .compression = TWO_STAGE_COMP}; -int tsdbOptionsInit(STsdbCfg *pTsdbOptions) { - // TODO - return 0; -} - -void tsdbOptionsClear(STsdbCfg *pTsdbOptions) { - // TODO -} - int tsdbValidateOptions(const STsdbCfg *pTsdbOptions) { // TODO return 0; diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 5677bb0615fcb59788ce46719c8e989fee3ea451..9509dfa462a9e53aae9d284f6b5c5254de92dfe3 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -14,20 +14,9 @@ */ #include "vnodeInt.h" -#include "tdatablock.h" -#include "os.h" -#include "talgo.h" -#include "tcompare.h" -#include "tdataformat.h" -#include "texception.h" - -#include "taosdef.h" -#include "tlosertree.h" -#include "vnodeInt.h" -#include "tmsg.h" -#define EXTRA_BYTES 2 -#define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC) +#define EXTRA_BYTES 2 +#define ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC) #define QH_GET_NUM_OF_COLS(handle) ((size_t)(taosArrayGetSize((handle)->pColumns))) #define GET_FILE_DATA_BLOCK_INFO(_checkInfo, _block) \ @@ -37,32 +26,32 @@ .uid = (_checkInfo)->tableId}) enum { - TSDB_QUERY_TYPE_ALL = 1, - TSDB_QUERY_TYPE_LAST = 2, + TSDB_QUERY_TYPE_ALL = 1, + TSDB_QUERY_TYPE_LAST = 2, }; enum { - TSDB_CACHED_TYPE_NONE = 0, + TSDB_CACHED_TYPE_NONE = 0, TSDB_CACHED_TYPE_LASTROW = 1, - TSDB_CACHED_TYPE_LAST = 2, + TSDB_CACHED_TYPE_LAST = 2, }; typedef struct SQueryFilePos { - int32_t fid; - int32_t slot; - int32_t pos; - int64_t lastKey; - int32_t rows; - bool mixBlock; - bool blockCompleted; + int32_t fid; + int32_t slot; + int32_t pos; + int64_t lastKey; + int32_t rows; + bool mixBlock; + bool blockCompleted; STimeWindow win; } SQueryFilePos; typedef struct SDataBlockLoadInfo { - SDFileSet* fileGroup; - int32_t slot; - uint64_t uid; - SArray* pLoadedCols; + SDFileSet* fileGroup; + int32_t slot; + uint64_t uid; + SArray* pLoadedCols; } SDataBlockLoadInfo; typedef struct SLoadCompBlockInfo { @@ -71,33 +60,33 @@ typedef struct SLoadCompBlockInfo { } SLoadCompBlockInfo; enum { - CHECKINFO_CHOSEN_MEM = 0, + CHECKINFO_CHOSEN_MEM = 0, CHECKINFO_CHOSEN_IMEM = 1, - CHECKINFO_CHOSEN_BOTH = 2 //for update=2(merge case) + CHECKINFO_CHOSEN_BOTH = 2 // for update=2(merge case) }; typedef struct STableCheckInfo { - uint64_t tableId; - TSKEY lastKey; - SBlockInfo* pCompInfo; - int32_t compSize; - int32_t numOfBlocks:29; // number of qualified data blocks not the original blocks - uint8_t chosen:2; // indicate which iterator should move forward - bool initBuf:1; // whether to initialize the in-memory skip list iterator or not - SSkipListIterator* iter; // mem buffer skip list iterator - SSkipListIterator* iiter; // imem buffer skip list iterator + uint64_t tableId; + TSKEY lastKey; + SBlockInfo* pCompInfo; + int32_t compSize; + int32_t numOfBlocks : 29; // number of qualified data blocks not the original blocks + uint8_t chosen : 2; // indicate which iterator should move forward + bool initBuf : 1; // whether to initialize the in-memory skip list iterator or not + SSkipListIterator* iter; // mem buffer skip list iterator + SSkipListIterator* iiter; // imem buffer skip list iterator } STableCheckInfo; typedef struct STableBlockInfo { - SBlock *compBlock; - STableCheckInfo *pTableCheckInfo; + SBlock* compBlock; + STableCheckInfo* pTableCheckInfo; } STableBlockInfo; typedef struct SBlockOrderSupporter { - int32_t numOfTables; - STableBlockInfo** pDataBlockInfo; - int32_t* blockIndexArray; - int32_t* numOfBlocksPerTable; + int32_t numOfTables; + STableBlockInfo** pDataBlockInfo; + int32_t* blockIndexArray; + int32_t* numOfBlocksPerTable; } SBlockOrderSupporter; typedef struct SIOCostSummary { @@ -109,37 +98,37 @@ typedef struct SIOCostSummary { } SIOCostSummary; typedef struct STsdbReadHandle { - STsdb* pTsdb; - SQueryFilePos cur; // current position - int16_t order; - STimeWindow window; // the primary query time window that applies to all queries - SDataStatis* statis; // query level statistics, only one table block statistics info exists at any time - int32_t numOfBlocks; - SArray* pColumns; // column list, SColumnInfoData array list - bool locateStart; - int32_t outputCapacity; - int32_t realNumOfRows; - SArray* pTableCheckInfo; // SArray - int32_t activeIndex; - bool checkFiles; // check file stage - int8_t cachelastrow; // check if last row cached - bool loadExternalRow; // load time window external data rows - bool currentLoadExternalRows; // current load external rows - int32_t loadType; // block load type - char *idStr; // query info handle, for debug purpose - int32_t type; // query type: retrieve all data blocks, 2. retrieve only last row, 3. retrieve direct prev|next rows - SDFileSet* pFileGroup; - SFSIter fileIter; - SReadH rhelper; - STableBlockInfo* pDataBlockInfo; - SDataCols *pDataCols; // in order to hold current file data block - int32_t allocSize; // allocated data block size - SArray *defaultLoadColumn;// default load column - SDataBlockLoadInfo dataBlockLoadInfo; /* record current block load information */ - SLoadCompBlockInfo compBlockLoadInfo; /* record current compblock information in SQueryAttr */ - - SArray *prev; // previous row which is before than time window - SArray *next; // next row which is after the query time window + STsdb* pTsdb; + SQueryFilePos cur; // current position + int16_t order; + STimeWindow window; // the primary query time window that applies to all queries + SDataStatis* statis; // query level statistics, only one table block statistics info exists at any time + int32_t numOfBlocks; + SArray* pColumns; // column list, SColumnInfoData array list + bool locateStart; + int32_t outputCapacity; + int32_t realNumOfRows; + SArray* pTableCheckInfo; // SArray + int32_t activeIndex; + bool checkFiles; // check file stage + int8_t cachelastrow; // check if last row cached + bool loadExternalRow; // load time window external data rows + bool currentLoadExternalRows; // current load external rows + int32_t loadType; // block load type + char* idStr; // query info handle, for debug purpose + int32_t type; // query type: retrieve all data blocks, 2. retrieve only last row, 3. retrieve direct prev|next rows + SDFileSet* pFileGroup; + SFSIter fileIter; + SReadH rhelper; + STableBlockInfo* pDataBlockInfo; + SDataCols* pDataCols; // in order to hold current file data block + int32_t allocSize; // allocated data block size + SArray* defaultLoadColumn; // default load column + SDataBlockLoadInfo dataBlockLoadInfo; /* record current block load information */ + SLoadCompBlockInfo compBlockLoadInfo; /* record current compblock information in SQueryAttr */ + + SArray* prev; // previous row which is before than time window + SArray* next; // next row which is after the query time window SIOCostSummary cost; } STsdbReadHandle; @@ -149,24 +138,27 @@ typedef struct STableGroupSupporter { SSchema* pTagSchema; } STableGroupSupporter; -static STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList); -static int32_t checkForCachedLastRow(STsdbReadHandle* pTsdbReadHandle, STableGroupInfo *groupList); -static int32_t checkForCachedLast(STsdbReadHandle* pTsdbReadHandle); +int32_t tsdbQueryTableList(void* pMeta, SArray* pRes, void* filterInfo); + +static STimeWindow updateLastrowForEachGroup(STableGroupInfo* groupList); +static int32_t checkForCachedLastRow(STsdbReadHandle* pTsdbReadHandle, STableGroupInfo* groupList); +static int32_t checkForCachedLast(STsdbReadHandle* pTsdbReadHandle); // static int32_t tsdbGetCachedLastRow(STable* pTable, STSRow** pRes, TSKEY* lastKey); static void changeQueryHandleForInterpQuery(tsdbReaderT pHandle); static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, SBlock* pBlock); static int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order); -static int32_t tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, STimeWindow* win, STsdbReadHandle* pTsdbReadHandle); +static int32_t tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, STimeWindow* win, + STsdbReadHandle* pTsdbReadHandle); static int32_t tsdbCheckInfoCompar(const void* key1, const void* key2); -//static int32_t doGetExternalRow(STsdbReadHandle* pTsdbReadHandle, int16_t type, void* pMemRef); -//static void* doFreeColumnInfoData(SArray* pColumnInfoData); -//static void* destroyTableCheckInfo(SArray* pTableCheckInfo); -static bool tsdbGetExternalRow(tsdbReaderT pHandle); +// static int32_t doGetExternalRow(STsdbReadHandle* pTsdbReadHandle, int16_t type, void* pMemRef); +// static void* doFreeColumnInfoData(SArray* pColumnInfoData); +// static void* destroyTableCheckInfo(SArray* pTableCheckInfo); +static bool tsdbGetExternalRow(tsdbReaderT pHandle); static void tsdbInitDataBlockLoadInfo(SDataBlockLoadInfo* pBlockLoadInfo) { pBlockLoadInfo->slot = -1; - pBlockLoadInfo->uid = 0; + pBlockLoadInfo->uid = 0; pBlockLoadInfo->fileGroup = NULL; } @@ -204,30 +196,32 @@ static SArray* getDefaultLoadColumns(STsdbReadHandle* pTsdbReadHandle, bool load } int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT* pHandle) { - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*) pHandle; + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; - int64_t rows = 0; - STsdbMemTable* pMemTable = NULL;//pTsdbReadHandle->pMemTable; - if (pMemTable == NULL) { return rows; } + int64_t rows = 0; + STsdbMemTable* pMemTable = NULL; // pTsdbReadHandle->pMemTable; + if (pMemTable == NULL) { + return rows; + } -// STableData* pMem = NULL; -// STableData* pIMem = NULL; + // STableData* pMem = NULL; + // STableData* pIMem = NULL; -// SMemTable* pMemT = pMemRef->snapshot.mem; -// SMemTable* pIMemT = pMemRef->snapshot.imem; + // SMemTable* pMemT = pMemRef->snapshot.mem; + // SMemTable* pIMemT = pMemRef->snapshot.imem; size_t size = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); for (int32_t i = 0; i < size; ++i) { STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); -// if (pMemT && pCheckInfo->tableId < pMemT->maxTables) { -// pMem = pMemT->tData[pCheckInfo->tableId]; -// rows += (pMem && pMem->uid == pCheckInfo->tableId) ? pMem->numOfRows : 0; -// } -// if (pIMemT && pCheckInfo->tableId < pIMemT->maxTables) { -// pIMem = pIMemT->tData[pCheckInfo->tableId]; -// rows += (pIMem && pIMem->uid == pCheckInfo->tableId) ? pIMem->numOfRows : 0; -// } + // if (pMemT && pCheckInfo->tableId < pMemT->maxTables) { + // pMem = pMemT->tData[pCheckInfo->tableId]; + // rows += (pMem && pMem->uid == pCheckInfo->tableId) ? pMem->numOfRows : 0; + // } + // if (pIMemT && pCheckInfo->tableId < pIMemT->maxTables) { + // pIMem = pIMemT->tData[pCheckInfo->tableId]; + // rows += (pIMem && pIMem->uid == pCheckInfo->tableId) ? pIMem->numOfRows : 0; + // } } return rows; } @@ -244,15 +238,15 @@ static SArray* createCheckInfoFromTableGroup(STsdbReadHandle* pTsdbReadHandle, S // todo apply the lastkey of table check to avoid to load header file for (int32_t i = 0; i < numOfGroup; ++i) { - SArray* group = *(SArray**) taosArrayGet(pGroupList->pGroupList, i); + SArray* group = *(SArray**)taosArrayGet(pGroupList->pGroupList, i); size_t gsize = taosArrayGetSize(group); assert(gsize > 0); for (int32_t j = 0; j < gsize; ++j) { - STableKeyInfo* pKeyInfo = (STableKeyInfo*) taosArrayGet(group, j); + STableKeyInfo* pKeyInfo = (STableKeyInfo*)taosArrayGet(group, j); - STableCheckInfo info = { .lastKey = pKeyInfo->lastKey, .tableId = pKeyInfo->uid}; + STableCheckInfo info = {.lastKey = pKeyInfo->lastKey, .tableId = pKeyInfo->uid}; if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { if (info.lastKey == INT64_MIN || info.lastKey < pTsdbReadHandle->window.skey) { info.lastKey = pTsdbReadHandle->window.skey; @@ -264,7 +258,8 @@ static SArray* createCheckInfoFromTableGroup(STsdbReadHandle* pTsdbReadHandle, S } taosArrayPush(pTableCheckInfo, &info); - tsdbDebug("%p check table uid:%"PRId64" from lastKey:%"PRId64" %s", pTsdbReadHandle, info.tableId, info.lastKey, pTsdbReadHandle->idStr); + tsdbDebug("%p check table uid:%" PRId64 " from lastKey:%" PRId64 " %s", pTsdbReadHandle, info.tableId, + info.lastKey, pTsdbReadHandle->idStr); } } @@ -279,10 +274,10 @@ static void resetCheckInfo(STsdbReadHandle* pTsdbReadHandle) { // todo apply the lastkey of table check to avoid to load header file for (int32_t i = 0; i < numOfTables; ++i) { - STableCheckInfo* pCheckInfo = (STableCheckInfo*) taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); + STableCheckInfo* pCheckInfo = (STableCheckInfo*)taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); pCheckInfo->lastKey = pTsdbReadHandle->window.skey; - pCheckInfo->iter = tSkipListDestroyIter(pCheckInfo->iter); - pCheckInfo->iiter = tSkipListDestroyIter(pCheckInfo->iiter); + pCheckInfo->iter = tSkipListDestroyIter(pCheckInfo->iter); + pCheckInfo->iiter = tSkipListDestroyIter(pCheckInfo->iiter); pCheckInfo->initBuf = false; if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { @@ -297,7 +292,7 @@ static void resetCheckInfo(STsdbReadHandle* pTsdbReadHandle) { static SArray* createCheckInfoFromCheckInfo(STableCheckInfo* pCheckInfo, TSKEY skey, SArray** psTable) { SArray* pNew = taosArrayInit(1, sizeof(STableCheckInfo)); - STableCheckInfo info = { .lastKey = skey}; + STableCheckInfo info = {.lastKey = skey}; info.tableId = pCheckInfo->tableId; taosArrayPush(pNew, &info); @@ -308,7 +303,7 @@ static bool emptyQueryTimewindow(STsdbReadHandle* pTsdbReadHandle) { assert(pTsdbReadHandle != NULL); STimeWindow* w = &pTsdbReadHandle->window; - bool asc = ASCENDING_TRAVERSE(pTsdbReadHandle->order); + bool asc = ASCENDING_TRAVERSE(pTsdbReadHandle->order); return ((asc && w->skey > w->ekey) || (!asc && w->ekey > w->skey)); } @@ -354,23 +349,23 @@ static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, STsdbQueryCond* pCond, goto _end; } - pReadHandle->order = pCond->order; - pReadHandle->pTsdb = tsdb; - pReadHandle->type = TSDB_QUERY_TYPE_ALL; - pReadHandle->cur.fid = INT32_MIN; - pReadHandle->cur.win = TSWINDOW_INITIALIZER; - pReadHandle->checkFiles = true; - pReadHandle->activeIndex = 0; // current active table index - pReadHandle->allocSize = 0; + pReadHandle->order = pCond->order; + pReadHandle->pTsdb = tsdb; + pReadHandle->type = TSDB_QUERY_TYPE_ALL; + pReadHandle->cur.fid = INT32_MIN; + pReadHandle->cur.win = TSWINDOW_INITIALIZER; + pReadHandle->checkFiles = true; + pReadHandle->activeIndex = 0; // current active table index + pReadHandle->allocSize = 0; pReadHandle->locateStart = false; - pReadHandle->loadType = pCond->type; + pReadHandle->loadType = pCond->type; - pReadHandle->outputCapacity = 4096;//((STsdb*)tsdb)->config.maxRowsPerFileBlock; + pReadHandle->outputCapacity = 4096; //((STsdb*)tsdb)->config.maxRowsPerFileBlock; pReadHandle->loadExternalRow = pCond->loadExternalRows; pReadHandle->currentLoadExternalRows = pCond->loadExternalRows; char buf[128] = {0}; - snprintf(buf, tListLen(buf), "TID:0x%"PRIx64" QID:0x%"PRIx64, taskId, qId); + snprintf(buf, tListLen(buf), "TID:0x%" PRIx64 " QID:0x%" PRIx64, taskId, qId); pReadHandle->idStr = strdup(buf); if (tsdbInitReadH(&pReadHandle->rhelper, (STsdb*)tsdb) != 0) { @@ -421,37 +416,39 @@ static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, STsdbQueryCond* pCond, return (tsdbReaderT)pReadHandle; - _end: +_end: tsdbCleanupReadHandle(pReadHandle); terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return NULL; } -tsdbReaderT* tsdbQueryTables(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, uint64_t qId, uint64_t taskId) { +tsdbReaderT* tsdbQueryTables(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, uint64_t qId, + uint64_t taskId) { STsdbReadHandle* pTsdbReadHandle = tsdbQueryTablesImpl(tsdb, pCond, qId, taskId); if (pTsdbReadHandle == NULL) { return NULL; } if (emptyQueryTimewindow(pTsdbReadHandle)) { - return (tsdbReaderT*) pTsdbReadHandle; + return (tsdbReaderT*)pTsdbReadHandle; } // todo apply the lastkey of table check to avoid to load header file pTsdbReadHandle->pTableCheckInfo = createCheckInfoFromTableGroup(pTsdbReadHandle, groupList); if (pTsdbReadHandle->pTableCheckInfo == NULL) { -// tsdbCleanupReadHandle(pTsdbReadHandle); + // tsdbCleanupReadHandle(pTsdbReadHandle); terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return NULL; } - tsdbDebug("%p total numOfTable:%" PRIzu " in this query, group %"PRIzu" %s", pTsdbReadHandle, taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo), - taosArrayGetSize(groupList->pGroupList), pTsdbReadHandle->idStr); + tsdbDebug("%p total numOfTable:%" PRIzu " in this query, group %" PRIzu " %s", pTsdbReadHandle, + taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo), taosArrayGetSize(groupList->pGroupList), + pTsdbReadHandle->idStr); - return (tsdbReaderT) pTsdbReadHandle; + return (tsdbReaderT)pTsdbReadHandle; } -void tsdbResetQueryHandle(tsdbReaderT queryHandle, STsdbQueryCond *pCond) { +void tsdbResetQueryHandle(tsdbReaderT queryHandle, STsdbQueryCond* pCond) { STsdbReadHandle* pTsdbReadHandle = queryHandle; if (emptyQueryTimewindow(pTsdbReadHandle)) { @@ -463,13 +460,13 @@ void tsdbResetQueryHandle(tsdbReaderT queryHandle, STsdbQueryCond *pCond) { return; } - pTsdbReadHandle->order = pCond->order; - pTsdbReadHandle->window = pCond->twindow; - pTsdbReadHandle->type = TSDB_QUERY_TYPE_ALL; - pTsdbReadHandle->cur.fid = -1; - pTsdbReadHandle->cur.win = TSWINDOW_INITIALIZER; - pTsdbReadHandle->checkFiles = true; - pTsdbReadHandle->activeIndex = 0; // current active table index + pTsdbReadHandle->order = pCond->order; + pTsdbReadHandle->window = pCond->twindow; + pTsdbReadHandle->type = TSDB_QUERY_TYPE_ALL; + pTsdbReadHandle->cur.fid = -1; + pTsdbReadHandle->cur.win = TSWINDOW_INITIALIZER; + pTsdbReadHandle->checkFiles = true; + pTsdbReadHandle->activeIndex = 0; // current active table index pTsdbReadHandle->locateStart = false; pTsdbReadHandle->loadExternalRow = pCond->loadExternalRows; @@ -488,16 +485,16 @@ void tsdbResetQueryHandle(tsdbReaderT queryHandle, STsdbQueryCond *pCond) { resetCheckInfo(pTsdbReadHandle); } -void tsdbResetQueryHandleForNewTable(tsdbReaderT queryHandle, STsdbQueryCond *pCond, STableGroupInfo* groupList) { +void tsdbResetQueryHandleForNewTable(tsdbReaderT queryHandle, STsdbQueryCond* pCond, STableGroupInfo* groupList) { STsdbReadHandle* pTsdbReadHandle = queryHandle; - pTsdbReadHandle->order = pCond->order; - pTsdbReadHandle->window = pCond->twindow; - pTsdbReadHandle->type = TSDB_QUERY_TYPE_ALL; - pTsdbReadHandle->cur.fid = -1; - pTsdbReadHandle->cur.win = TSWINDOW_INITIALIZER; - pTsdbReadHandle->checkFiles = true; - pTsdbReadHandle->activeIndex = 0; // current active table index + pTsdbReadHandle->order = pCond->order; + pTsdbReadHandle->window = pCond->twindow; + pTsdbReadHandle->type = TSDB_QUERY_TYPE_ALL; + pTsdbReadHandle->cur.fid = -1; + pTsdbReadHandle->cur.win = TSWINDOW_INITIALIZER; + pTsdbReadHandle->checkFiles = true; + pTsdbReadHandle->activeIndex = 0; // current active table index pTsdbReadHandle->locateStart = false; pTsdbReadHandle->loadExternalRow = pCond->loadExternalRows; @@ -514,21 +511,23 @@ void tsdbResetQueryHandleForNewTable(tsdbReaderT queryHandle, STsdbQueryCond *pC tsdbInitCompBlockLoadInfo(&pTsdbReadHandle->compBlockLoadInfo); SArray* pTable = NULL; -// STsdbMeta* pMeta = tsdbGetMeta(pTsdbReadHandle->pTsdb); + // STsdbMeta* pMeta = tsdbGetMeta(pTsdbReadHandle->pTsdb); -// pTsdbReadHandle->pTableCheckInfo = destroyTableCheckInfo(pTsdbReadHandle->pTableCheckInfo); + // pTsdbReadHandle->pTableCheckInfo = destroyTableCheckInfo(pTsdbReadHandle->pTableCheckInfo); - pTsdbReadHandle->pTableCheckInfo = NULL;//createCheckInfoFromTableGroup(pTsdbReadHandle, groupList, pMeta, &pTable); + pTsdbReadHandle->pTableCheckInfo = NULL; // createCheckInfoFromTableGroup(pTsdbReadHandle, groupList, pMeta, + // &pTable); if (pTsdbReadHandle->pTableCheckInfo == NULL) { -// tsdbCleanupReadHandle(pTsdbReadHandle); + // tsdbCleanupReadHandle(pTsdbReadHandle); terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; } -// pTsdbReadHandle->prev = doFreeColumnInfoData(pTsdbReadHandle->prev); -// pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); + // pTsdbReadHandle->prev = doFreeColumnInfoData(pTsdbReadHandle->prev); + // pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); } -tsdbReaderT tsdbQueryLastRow(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, uint64_t qId, uint64_t taskId) { +tsdbReaderT tsdbQueryLastRow(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, uint64_t qId, + uint64_t taskId) { pCond->twindow = updateLastrowForEachGroup(groupList); // no qualified table @@ -536,13 +535,13 @@ tsdbReaderT tsdbQueryLastRow(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo return NULL; } - STsdbReadHandle *pTsdbReadHandle = (STsdbReadHandle*) tsdbQueryTables(tsdb, pCond, groupList, qId, taskId); + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)tsdbQueryTables(tsdb, pCond, groupList, qId, taskId); if (pTsdbReadHandle == NULL) { return NULL; } int32_t code = checkForCachedLastRow(pTsdbReadHandle, groupList); - if (code != TSDB_CODE_SUCCESS) { // set the numOfTables to be 0 + if (code != TSDB_CODE_SUCCESS) { // set the numOfTables to be 0 terrno = code; return NULL; } @@ -551,7 +550,7 @@ tsdbReaderT tsdbQueryLastRow(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupInfo if (pTsdbReadHandle->cachelastrow) { pTsdbReadHandle->type = TSDB_QUERY_TYPE_LAST; } - + return pTsdbReadHandle; } @@ -576,12 +575,12 @@ tsdbReaderT tsdbQueryCacheLast(STsdb *tsdb, STsdbQueryCond *pCond, STableGroupIn } #endif -SArray* tsdbGetQueriedTableList(tsdbReaderT *pHandle) { +SArray* tsdbGetQueriedTableList(tsdbReaderT* pHandle) { assert(pHandle != NULL); - STsdbReadHandle *pTsdbReadHandle = (STsdbReadHandle*) pHandle; + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; - size_t size = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); + size_t size = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); SArray* res = taosArrayInit(size, POINTER_BYTES); return res; } @@ -594,18 +593,18 @@ static STableGroupInfo* trimTableGroup(STimeWindow* window, STableGroupInfo* pGr STableGroupInfo* pNew = taosMemoryCalloc(1, sizeof(STableGroupInfo)); pNew->pGroupList = taosArrayInit(numOfGroup, POINTER_BYTES); - for(int32_t i = 0; i < numOfGroup; ++i) { + for (int32_t i = 0; i < numOfGroup; ++i) { SArray* oneGroup = taosArrayGetP(pGroupList->pGroupList, i); - size_t numOfTables = taosArrayGetSize(oneGroup); + size_t numOfTables = taosArrayGetSize(oneGroup); SArray* px = taosArrayInit(4, sizeof(STableKeyInfo)); for (int32_t j = 0; j < numOfTables; ++j) { STableKeyInfo* pInfo = (STableKeyInfo*)taosArrayGet(oneGroup, j); -// if (window->skey <= pInfo->lastKey && ((STable*)pInfo->pTable)->lastKey != TSKEY_INITIAL_VAL) { -// taosArrayPush(px, pInfo); -// pNew->numOfTables += 1; -// break; -// } + // if (window->skey <= pInfo->lastKey && ((STable*)pInfo->pTable)->lastKey != TSKEY_INITIAL_VAL) { + // taosArrayPush(px, pInfo); + // pNew->numOfTables += 1; + // break; + // } } // there are no data in this group @@ -619,7 +618,8 @@ static STableGroupInfo* trimTableGroup(STimeWindow* window, STableGroupInfo* pGr return pNew; } -tsdbReaderT tsdbQueryRowsInExternalWindow(STsdb *tsdb, STsdbQueryCond* pCond, STableGroupInfo *groupList, uint64_t qId, uint64_t taskId) { +tsdbReaderT tsdbQueryRowsInExternalWindow(STsdb* tsdb, STsdbQueryCond* pCond, STableGroupInfo* groupList, uint64_t qId, + uint64_t taskId) { STableGroupInfo* pNew = trimTableGroup(&pCond->twindow, groupList); if (pNew->numOfTables == 0) { @@ -634,7 +634,7 @@ tsdbReaderT tsdbQueryRowsInExternalWindow(STsdb *tsdb, STsdbQueryCond* pCond, ST } } - STsdbReadHandle *pTsdbReadHandle = (STsdbReadHandle*) tsdbQueryTables(tsdb, pCond, pNew, qId, taskId); + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)tsdbQueryTables(tsdb, pCond, pNew, qId, taskId); pTsdbReadHandle->loadExternalRow = true; pTsdbReadHandle->currentLoadExternalRows = true; @@ -674,9 +674,9 @@ static bool initTableMemIterator(STsdbReadHandle* pHandle, STableCheckInfo* pChe return false; } - bool memEmpty = (pCheckInfo->iter == NULL) || (pCheckInfo->iter != NULL && !tSkipListIterNext(pCheckInfo->iter)); + bool memEmpty = (pCheckInfo->iter == NULL) || (pCheckInfo->iter != NULL && !tSkipListIterNext(pCheckInfo->iter)); bool imemEmpty = (pCheckInfo->iiter == NULL) || (pCheckInfo->iiter != NULL && !tSkipListIterNext(pCheckInfo->iiter)); - if (memEmpty && imemEmpty) { // buffer is empty + if (memEmpty && imemEmpty) { // buffer is empty return false; } @@ -687,8 +687,9 @@ static bool initTableMemIterator(STsdbReadHandle* pHandle, STableCheckInfo* pChe STSRow* row = (STSRow*)SL_GET_NODE_DATA(node); TSKEY key = TD_ROW_KEY(row); // first timestamp in buffer tsdbDebug("%p uid:%" PRId64 ", check data in mem from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64 - "-%" PRId64 ", lastKey:%" PRId64 ", numOfRows:%"PRId64", %s", - pHandle, pCheckInfo->tableId, key, order, (*pMem)->keyMin, (*pMem)->keyMax, pCheckInfo->lastKey, (*pMem)->nrows, pHandle->idStr); + "-%" PRId64 ", lastKey:%" PRId64 ", numOfRows:%" PRId64 ", %s", + pHandle, pCheckInfo->tableId, key, order, (*pMem)->keyMin, (*pMem)->keyMax, pCheckInfo->lastKey, + (*pMem)->nrows, pHandle->idStr); if (ASCENDING_TRAVERSE(order)) { assert(pCheckInfo->lastKey <= key); @@ -697,7 +698,7 @@ static bool initTableMemIterator(STsdbReadHandle* pHandle, STableCheckInfo* pChe } } else { - tsdbDebug("%p uid:%"PRId64", no data in mem, %s", pHandle, pCheckInfo->tableId, pHandle->idStr); + tsdbDebug("%p uid:%" PRId64 ", no data in mem, %s", pHandle, pCheckInfo->tableId, pHandle->idStr); } if (!imemEmpty) { @@ -707,8 +708,9 @@ static bool initTableMemIterator(STsdbReadHandle* pHandle, STableCheckInfo* pChe STSRow* row = (STSRow*)SL_GET_NODE_DATA(node); TSKEY key = TD_ROW_KEY(row); // first timestamp in buffer tsdbDebug("%p uid:%" PRId64 ", check data in imem from skey:%" PRId64 ", order:%d, ts range in buf:%" PRId64 - "-%" PRId64 ", lastKey:%" PRId64 ", numOfRows:%"PRId64", %s", - pHandle, pCheckInfo->tableId, key, order, (*pIMem)->keyMin, (*pIMem)->keyMax, pCheckInfo->lastKey, (*pIMem)->nrows, pHandle->idStr); + "-%" PRId64 ", lastKey:%" PRId64 ", numOfRows:%" PRId64 ", %s", + pHandle, pCheckInfo->tableId, key, order, (*pIMem)->keyMin, (*pIMem)->keyMax, pCheckInfo->lastKey, + (*pIMem)->nrows, pHandle->idStr); if (ASCENDING_TRAVERSE(order)) { assert(pCheckInfo->lastKey <= key); @@ -716,7 +718,7 @@ static bool initTableMemIterator(STsdbReadHandle* pHandle, STableCheckInfo* pChe assert(pCheckInfo->lastKey >= key); } } else { - tsdbDebug("%p uid:%"PRId64", no data in imem, %s", pHandle, pCheckInfo->tableId, pHandle->idStr); + tsdbDebug("%p uid:%" PRId64 ", no data in imem, %s", pHandle, pCheckInfo->tableId, pHandle->idStr); } return true; @@ -761,11 +763,10 @@ static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order, TSKEY r2 = TD_ROW_KEY(rimem); if (r1 == r2) { - if(update == TD_ROW_DISCARD_UPDATE){ + if (update == TD_ROW_DISCARD_UPDATE) { pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; tSkipListIterNext(pCheckInfo->iter); - } - else if(update == TD_ROW_OVERWRITE_UPDATE) { + } else if (update == TD_ROW_OVERWRITE_UPDATE) { pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; tSkipListIterNext(pCheckInfo->iiter); } else { @@ -775,8 +776,7 @@ static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order, } else if (r1 < r2 && ASCENDING_TRAVERSE(order)) { pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; return r1; - } - else { + } else { pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; return r2; } @@ -820,7 +820,7 @@ static STSRow* getSRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order, int tSkipListIterNext(pCheckInfo->iter); pCheckInfo->chosen = CHECKINFO_CHOSEN_IMEM; return rimem; - } else if(update == TD_ROW_OVERWRITE_UPDATE){ + } else if (update == TD_ROW_OVERWRITE_UPDATE) { tSkipListIterNext(pCheckInfo->iiter); pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; return rmem; @@ -864,7 +864,7 @@ static bool moveToNextRowInMem(STableCheckInfo* pCheckInfo) { if (pCheckInfo->iiter != NULL) { return tSkipListIterGet(pCheckInfo->iiter) != NULL; } - } else if (pCheckInfo->chosen == CHECKINFO_CHOSEN_IMEM){ + } else if (pCheckInfo->chosen == CHECKINFO_CHOSEN_IMEM) { if (pCheckInfo->iiter != NULL) { hasNext = tSkipListIterNext(pCheckInfo->iiter); } @@ -889,8 +889,8 @@ static bool moveToNextRowInMem(STableCheckInfo* pCheckInfo) { } static bool hasMoreDataInCache(STsdbReadHandle* pHandle) { - STsdbCfg *pCfg = &pHandle->pTsdb->config; - size_t size = taosArrayGetSize(pHandle->pTableCheckInfo); + STsdbCfg* pCfg = &pHandle->pTsdb->config; + size_t size = taosArrayGetSize(pHandle->pTableCheckInfo); assert(pHandle->activeIndex < size && pHandle->activeIndex >= 0 && size >= 1); pHandle->cur.fid = INT32_MIN; @@ -905,8 +905,8 @@ static bool hasMoreDataInCache(STsdbReadHandle* pHandle) { } pCheckInfo->lastKey = TD_ROW_KEY(row); // first timestamp in buffer - tsdbDebug("%p uid:%" PRId64", check data in buffer from skey:%" PRId64 ", order:%d, %s", pHandle, - pCheckInfo->tableId, pCheckInfo->lastKey, pHandle->order, pHandle->idStr); + tsdbDebug("%p uid:%" PRId64 ", check data in buffer from skey:%" PRId64 ", order:%d, %s", pHandle, + pCheckInfo->tableId, pCheckInfo->lastKey, pHandle->order, pHandle->idStr); // all data in mem are checked already. if ((pCheckInfo->lastKey > pHandle->window.ekey && ASCENDING_TRAVERSE(pHandle->order)) || @@ -914,7 +914,7 @@ static bool hasMoreDataInCache(STsdbReadHandle* pHandle) { return false; } - int32_t step = ASCENDING_TRAVERSE(pHandle->order)? 1:-1; + int32_t step = ASCENDING_TRAVERSE(pHandle->order) ? 1 : -1; STimeWindow* win = &pHandle->cur.win; pHandle->cur.rows = tsdbReadRowsFromCache(pCheckInfo, pHandle->window.ekey, pHandle->outputCapacity, win, pHandle); @@ -939,9 +939,9 @@ static int32_t getFileIdFromKey(TSKEY key, int32_t daysPerFile, int32_t precisio if (key < 0) { key -= (daysPerFile * tsTickPerDay[precision]); } - + int64_t fid = (int64_t)(key / (daysPerFile * tsTickPerDay[precision])); // set the starting fileId - if (fid < 0L && llabs(fid) > INT32_MAX) { // data value overflow for INT32 + if (fid < 0L && llabs(fid) > INT32_MAX) { // data value overflow for INT32 fid = INT32_MIN; } @@ -979,7 +979,7 @@ static int32_t binarySearchForBlock(SBlock* pBlock, int32_t numOfBlocks, TSKEY s return midSlot; } -static int32_t loadBlockInfo(STsdbReadHandle * pTsdbReadHandle, int32_t index, int32_t* numOfBlocks) { +static int32_t loadBlockInfo(STsdbReadHandle* pTsdbReadHandle, int32_t index, int32_t* numOfBlocks) { int32_t code = 0; STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, index); @@ -1022,9 +1022,11 @@ static int32_t loadBlockInfo(STsdbReadHandle * pTsdbReadHandle, int32_t index, i TSKEY s = TSKEY_INITIAL_VAL, e = TSKEY_INITIAL_VAL; if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { - assert(pCheckInfo->lastKey <= pTsdbReadHandle->window.ekey && pTsdbReadHandle->window.skey <= pTsdbReadHandle->window.ekey); + assert(pCheckInfo->lastKey <= pTsdbReadHandle->window.ekey && + pTsdbReadHandle->window.skey <= pTsdbReadHandle->window.ekey); } else { - assert(pCheckInfo->lastKey >= pTsdbReadHandle->window.ekey && pTsdbReadHandle->window.skey >= pTsdbReadHandle->window.ekey); + assert(pCheckInfo->lastKey >= pTsdbReadHandle->window.ekey && + pTsdbReadHandle->window.skey >= pTsdbReadHandle->window.ekey); } s = TMIN(pCheckInfo->lastKey, pTsdbReadHandle->window.ekey); @@ -1085,10 +1087,11 @@ static int32_t getFileCompInfo(STsdbReadHandle* pTsdbReadHandle, int32_t* numOfB return code; } -static int32_t doLoadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo, int32_t slotIndex) { +static int32_t doLoadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo, + int32_t slotIndex) { int64_t st = taosGetTimestampUs(); - STSchema *pSchema = metaGetTbTSchema(pTsdbReadHandle->pTsdb->pMeta, pCheckInfo->tableId, 0); + STSchema* pSchema = metaGetTbTSchema(pTsdbReadHandle->pTsdb->pMeta, pCheckInfo->tableId, 0); int32_t code = tdInitDataCols(pTsdbReadHandle->pDataCols, pSchema); if (code != TSDB_CODE_SUCCESS) { tsdbError("%p failed to malloc buf for pDataCols, %s", pTsdbReadHandle, pTsdbReadHandle->idStr); @@ -1112,7 +1115,8 @@ static int32_t doLoadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBl int16_t* colIds = pTsdbReadHandle->defaultLoadColumn->pData; - int32_t ret = tsdbLoadBlockDataCols(&(pTsdbReadHandle->rhelper), pBlock, pCheckInfo->pCompInfo, colIds, (int)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)), true); + int32_t ret = tsdbLoadBlockDataCols(&(pTsdbReadHandle->rhelper), pBlock, pCheckInfo->pCompInfo, colIds, + (int)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)), true); if (ret != TSDB_CODE_SUCCESS) { int32_t c = terrno; assert(c != TSDB_CODE_SUCCESS); @@ -1131,9 +1135,9 @@ static int32_t doLoadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBl pBlock->numOfRows = pCols->numOfRows; // Convert from TKEY to TSKEY for primary timestamp column if current block has timestamp before 1970-01-01T00:00:00Z - if(pBlock->keyFirst < 0 && colIds[0] == PRIMARYKEY_TIMESTAMP_COL_ID) { + if (pBlock->keyFirst < 0 && colIds[0] == PRIMARYKEY_TIMESTAMP_COL_ID) { int64_t* src = pCols->cols[0].pData; - for(int32_t i = 0; i < pBlock->numOfRows; ++i) { + for (int32_t i = 0; i < pBlock->numOfRows; ++i) { src[i] = tdGetKey(src[i]); } } @@ -1141,30 +1145,34 @@ static int32_t doLoadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBl int64_t elapsedTime = (taosGetTimestampUs() - st); pTsdbReadHandle->cost.blockLoadTime += elapsedTime; - tsdbDebug("%p load file block into buffer, index:%d, brange:%"PRId64"-%"PRId64", rows:%d, elapsed time:%"PRId64 " us, %s", - pTsdbReadHandle, slotIndex, pBlock->keyFirst, pBlock->keyLast, pBlock->numOfRows, elapsedTime, pTsdbReadHandle->idStr); + tsdbDebug("%p load file block into buffer, index:%d, brange:%" PRId64 "-%" PRId64 ", rows:%d, elapsed time:%" PRId64 + " us, %s", + pTsdbReadHandle, slotIndex, pBlock->keyFirst, pBlock->keyLast, pBlock->numOfRows, elapsedTime, + pTsdbReadHandle->idStr); return TSDB_CODE_SUCCESS; _error: pBlock->numOfRows = 0; - tsdbError("%p error occurs in loading file block, index:%d, brange:%"PRId64"-%"PRId64", rows:%d, %s", + tsdbError("%p error occurs in loading file block, index:%d, brange:%" PRId64 "-%" PRId64 ", rows:%d, %s", pTsdbReadHandle, slotIndex, pBlock->keyFirst, pBlock->keyLast, pBlock->numOfRows, pTsdbReadHandle->idStr); return terrno; } static int32_t getEndPosInDataBlock(STsdbReadHandle* pTsdbReadHandle, SDataBlockInfo* pBlockInfo); -static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, int32_t start, int32_t end); -static void moveDataToFront(STsdbReadHandle* pTsdbReadHandle, int32_t numOfRows, int32_t numOfCols); -static void doCheckGeneratedBlockRange(STsdbReadHandle* pTsdbReadHandle); -static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, SDataBlockInfo* pBlockInfo, int32_t endPos); - -static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo){ +static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, + int32_t start, int32_t end); +static void moveDataToFront(STsdbReadHandle* pTsdbReadHandle, int32_t numOfRows, int32_t numOfCols); +static void doCheckGeneratedBlockRange(STsdbReadHandle* pTsdbReadHandle); +static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, + SDataBlockInfo* pBlockInfo, int32_t endPos); + +static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo) { SQueryFilePos* cur = &pTsdbReadHandle->cur; STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config; SDataBlockInfo binfo = GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlock); TSKEY key; - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; /*bool hasData = */ initTableMemIterator(pTsdbReadHandle, pCheckInfo); assert(cur->pos >= 0 && cur->pos <= binfo.rows); @@ -1172,22 +1180,22 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* key = extractFirstTraverseKey(pCheckInfo, pTsdbReadHandle->order, pCfg->update); if (key != TSKEY_INITIAL_VAL) { - tsdbDebug("%p key in mem:%"PRId64", %s", pTsdbReadHandle, key, pTsdbReadHandle->idStr); + tsdbDebug("%p key in mem:%" PRId64 ", %s", pTsdbReadHandle, key, pTsdbReadHandle->idStr); } else { tsdbDebug("%p no data in mem, %s", pTsdbReadHandle, pTsdbReadHandle->idStr); } if ((ASCENDING_TRAVERSE(pTsdbReadHandle->order) && (key != TSKEY_INITIAL_VAL && key <= binfo.window.ekey)) || (!ASCENDING_TRAVERSE(pTsdbReadHandle->order) && (key != TSKEY_INITIAL_VAL && key >= binfo.window.skey))) { - if ((ASCENDING_TRAVERSE(pTsdbReadHandle->order) && (key != TSKEY_INITIAL_VAL && key < binfo.window.skey)) || (!ASCENDING_TRAVERSE(pTsdbReadHandle->order) && (key != TSKEY_INITIAL_VAL && key > binfo.window.ekey))) { - // do not load file block into buffer int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; - TSKEY maxKey = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? (binfo.window.skey - step):(binfo.window.ekey - step); - cur->rows = tsdbReadRowsFromCache(pCheckInfo, maxKey, pTsdbReadHandle->outputCapacity, &cur->win, pTsdbReadHandle); + TSKEY maxKey = + ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? (binfo.window.skey - step) : (binfo.window.ekey - step); + cur->rows = + tsdbReadRowsFromCache(pCheckInfo, maxKey, pTsdbReadHandle->outputCapacity, &cur->win, pTsdbReadHandle); pTsdbReadHandle->realNumOfRows = cur->rows; // update the last key value @@ -1201,7 +1209,6 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* return code; } - // return error, add test cases if ((code = doLoadFileDataBlock(pTsdbReadHandle, pBlock, pCheckInfo, cur->slot)) != TSDB_CODE_SUCCESS) { return code; @@ -1218,12 +1225,12 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* assert(pTsdbReadHandle->outputCapacity >= binfo.rows); int32_t endPos = getEndPosInDataBlock(pTsdbReadHandle, &binfo); - if ((cur->pos == 0 && endPos == binfo.rows -1 && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || + if ((cur->pos == 0 && endPos == binfo.rows - 1 && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || (cur->pos == (binfo.rows - 1) && endPos == 0 && (!ASCENDING_TRAVERSE(pTsdbReadHandle->order)))) { pTsdbReadHandle->realNumOfRows = binfo.rows; cur->rows = binfo.rows; - cur->win = binfo.window; + cur->win = binfo.window; cur->mixBlock = false; cur->blockCompleted = true; @@ -1234,29 +1241,31 @@ static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* cur->lastKey = binfo.window.skey - 1; cur->pos = -1; } - } else { // partially copy to dest buffer + } else { // partially copy to dest buffer copyAllRemainRowsFromFileBlock(pTsdbReadHandle, pCheckInfo, &binfo, endPos); cur->mixBlock = true; } assert(cur->blockCompleted); if (cur->rows == binfo.rows) { - tsdbDebug("%p whole file block qualified, brange:%"PRId64"-%"PRId64", rows:%d, lastKey:%"PRId64", %s", + tsdbDebug("%p whole file block qualified, brange:%" PRId64 "-%" PRId64 ", rows:%d, lastKey:%" PRId64 ", %s", pTsdbReadHandle, cur->win.skey, cur->win.ekey, cur->rows, cur->lastKey, pTsdbReadHandle->idStr); } else { - tsdbDebug("%p create data block from remain file block, brange:%"PRId64"-%"PRId64", rows:%d, total:%d, lastKey:%"PRId64", %s", - pTsdbReadHandle, cur->win.skey, cur->win.ekey, cur->rows, binfo.rows, cur->lastKey, pTsdbReadHandle->idStr); + tsdbDebug("%p create data block from remain file block, brange:%" PRId64 "-%" PRId64 + ", rows:%d, total:%d, lastKey:%" PRId64 ", %s", + pTsdbReadHandle, cur->win.skey, cur->win.ekey, cur->rows, binfo.rows, cur->lastKey, + pTsdbReadHandle->idStr); } - } return code; } -static int32_t loadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo, bool* exists) { +static int32_t loadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo, + bool* exists) { SQueryFilePos* cur = &pTsdbReadHandle->cur; - int32_t code = TSDB_CODE_SUCCESS; - bool asc = ASCENDING_TRAVERSE(pTsdbReadHandle->order); + int32_t code = TSDB_CODE_SUCCESS; + bool asc = ASCENDING_TRAVERSE(pTsdbReadHandle->order); if (asc) { // query ended in/started from current block @@ -1279,10 +1288,10 @@ static int32_t loadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBloc assert(pCheckInfo->lastKey <= pBlock->keyLast); doMergeTwoLevelData(pTsdbReadHandle, pCheckInfo, pBlock); } else { // the whole block is loaded in to buffer - cur->pos = asc? 0:(pBlock->numOfRows - 1); + cur->pos = asc ? 0 : (pBlock->numOfRows - 1); code = handleDataMergeIfNeeded(pTsdbReadHandle, pBlock, pCheckInfo); } - } else { //desc order, query ended in current block + } else { // desc order, query ended in current block if (pTsdbReadHandle->window.ekey > pBlock->keyFirst || pCheckInfo->lastKey < pBlock->keyLast) { if ((code = doLoadFileDataBlock(pTsdbReadHandle, pBlock, pCheckInfo, cur->slot)) != TSDB_CODE_SUCCESS) { *exists = false; @@ -1291,7 +1300,8 @@ static int32_t loadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBloc SDataCols* pTsCol = pTsdbReadHandle->rhelper.pDCols[0]; if (pCheckInfo->lastKey < pBlock->keyLast) { - cur->pos = binarySearchForKey(pTsCol->cols[0].pData, pBlock->numOfRows, pCheckInfo->lastKey, pTsdbReadHandle->order); + cur->pos = + binarySearchForKey(pTsCol->cols[0].pData, pBlock->numOfRows, pCheckInfo->lastKey, pTsdbReadHandle->order); } else { cur->pos = pBlock->numOfRows - 1; } @@ -1299,7 +1309,7 @@ static int32_t loadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBloc assert(pCheckInfo->lastKey >= pBlock->keyFirst); doMergeTwoLevelData(pTsdbReadHandle, pCheckInfo, pBlock); } else { - cur->pos = asc? 0:(pBlock->numOfRows-1); + cur->pos = asc ? 0 : (pBlock->numOfRows - 1); code = handleDataMergeIfNeeded(pTsdbReadHandle, pBlock, pCheckInfo); } } @@ -1370,11 +1380,12 @@ static int doBinarySearchKey(char* pValue, int num, TSKEY key, int order) { return midPos; } -static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, int32_t start, int32_t end) { - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 1 : -1; +static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, + int32_t start, int32_t end) { + int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; - TSKEY* tsArray = pCols->cols[0].pData; + TSKEY* tsArray = pCols->cols[0].pData; int32_t num = end - start + 1; assert(num >= 0); @@ -1385,9 +1396,9 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t int32_t requiredNumOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pColumns); - //data in buffer has greater timestamp, copy data in file block + // data in buffer has greater timestamp, copy data in file block int32_t i = 0, j = 0; - while(i < requiredNumOfCols && j < pCols->numOfCols) { + while (i < requiredNumOfCols && j < pCols->numOfCols) { SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); SDataCol* src = &pCols->cols[j]; @@ -1398,15 +1409,15 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t if (!isAllRowsNull(src) && pColInfo->info.colId == src->colId) { if (!IS_VAR_DATA_TYPE(pColInfo->info.type)) { // todo opt performance -// memmove(pData, (char*)src->pData + bytes * start, bytes * num); - for(int32_t k = start; k < num + start; ++k) { + // memmove(pData, (char*)src->pData + bytes * start, bytes * num); + for (int32_t k = start; k < num + start; ++k) { SCellVal sVal = {0}; if (tdGetColDataOfRow(&sVal, src, k, pCols->bitmapMode) < 0) { TASSERT(0); } if (sVal.valType == TD_VTYPE_NULL) { - colDataAppend(pColInfo, k, NULL, true); + colDataAppendNULL(pColInfo, k); } else { colDataAppend(pColInfo, k, sVal.val, false); } @@ -1415,28 +1426,32 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t // todo refactor, only copy one-by-one for (int32_t k = start; k < num + start; ++k) { SCellVal sVal = {0}; - if(tdGetColDataOfRow(&sVal, src, k, pCols->bitmapMode) < 0){ + if (tdGetColDataOfRow(&sVal, src, k, pCols->bitmapMode) < 0) { TASSERT(0); } - colDataAppend(pColInfo, k, sVal.val, false); + if (sVal.valType == TD_VTYPE_NULL) { + colDataAppendNULL(pColInfo, k); + } else { + colDataAppend(pColInfo, k, sVal.val, false); + } } } j++; i++; - } else { // pColInfo->info.colId < src->colId, it is a NULL data - for(int32_t k = start; k < num + start; ++k) { // TODO opt performance + } else { // pColInfo->info.colId < src->colId, it is a NULL data + for (int32_t k = start; k < num + start; ++k) { // TODO opt performance colDataAppend(pColInfo, k, NULL, true); } i++; } } - while (i < requiredNumOfCols) { // the remain columns are all null data + while (i < requiredNumOfCols) { // the remain columns are all null data SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); - for(int32_t k = start; k < num + start; ++k) { - colDataAppend(pColInfo, k, NULL, true); // TODO add a fast version to set a number of consecutive NULL value. + for (int32_t k = start; k < num + start; ++k) { + colDataAppend(pColInfo, k, NULL, true); // TODO add a fast version to set a number of consecutive NULL value. } i++; } @@ -1453,15 +1468,15 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit STSRow* row2, int32_t numOfCols, uint64_t uid, STSchema* pSchema1, STSchema* pSchema2, bool forceSetNull) { #if 1 - STSchema* pSchema; - STSRow* row; - int16_t colId; - int16_t offset; - - bool isRow1DataRow = TD_IS_TP_ROW(row1); - bool isRow2DataRow; - bool isChosenRowDataRow; - int32_t chosen_itr; + STSchema* pSchema; + STSRow* row; + int16_t colId; + int16_t offset; + + bool isRow1DataRow = TD_IS_TP_ROW(row1); + bool isRow2DataRow; + bool isChosenRowDataRow; + int32_t chosen_itr; SCellVal sVal = {0}; // the schema version info is embeded in STSRow @@ -1471,19 +1486,19 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit pSchema1 = metaGetTbTSchema(pTsdbReadHandle->pTsdb->pMeta, uid, TD_ROW_SVER(row1)); } - if(isRow1DataRow) { + if (isRow1DataRow) { numOfColsOfRow1 = schemaNCols(pSchema1); } else { numOfColsOfRow1 = tdRowGetNCols(row1); } int32_t numOfColsOfRow2 = 0; - if(row2) { + if (row2) { isRow2DataRow = TD_IS_TP_ROW(row2); if (pSchema2 == NULL) { pSchema2 = metaGetTbTSchema(pTsdbReadHandle->pTsdb->pMeta, uid, TD_ROW_SVER(row2)); } - if(isRow2DataRow) { + if (isRow2DataRow) { numOfColsOfRow2 = schemaNCols(pSchema2); } else { numOfColsOfRow2 = tdRowGetNCols(row2); @@ -1491,31 +1506,31 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit } int32_t i = 0, j = 0, k = 0; - while(i < numOfCols && (j < numOfColsOfRow1 || k < numOfColsOfRow2)) { + while (i < numOfCols && (j < numOfColsOfRow1 || k < numOfColsOfRow2)) { SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); int32_t colIdOfRow1; - if(j >= numOfColsOfRow1) { + if (j >= numOfColsOfRow1) { colIdOfRow1 = INT32_MAX; - } else if(isRow1DataRow) { + } else if (isRow1DataRow) { colIdOfRow1 = pSchema1->columns[j].colId; } else { - SKvRowIdx *pColIdx = tdKvRowColIdxAt(row1, j); + SKvRowIdx* pColIdx = tdKvRowColIdxAt(row1, j); colIdOfRow1 = pColIdx->colId; } int32_t colIdOfRow2; - if(k >= numOfColsOfRow2) { + if (k >= numOfColsOfRow2) { colIdOfRow2 = INT32_MAX; - } else if(isRow2DataRow) { + } else if (isRow2DataRow) { colIdOfRow2 = pSchema2->columns[k].colId; } else { - SKvRowIdx *pColIdx = tdKvRowColIdxAt(row2, k); + SKvRowIdx* pColIdx = tdKvRowColIdxAt(row2, k); colIdOfRow2 = pColIdx->colId; } - if(colIdOfRow1 == colIdOfRow2) { - if(colIdOfRow1 < pColInfo->info.colId) { + if (colIdOfRow1 == colIdOfRow2) { + if (colIdOfRow1 < pColInfo->info.colId) { j++; k++; continue; @@ -1524,8 +1539,8 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit pSchema = pSchema1; isChosenRowDataRow = isRow1DataRow; chosen_itr = j; - } else if(colIdOfRow1 < colIdOfRow2) { - if(colIdOfRow1 < pColInfo->info.colId) { + } else if (colIdOfRow1 < colIdOfRow2) { + if (colIdOfRow1 < pColInfo->info.colId) { j++; continue; } @@ -1534,7 +1549,7 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit isChosenRowDataRow = isRow1DataRow; chosen_itr = j; } else { - if(colIdOfRow2 < pColInfo->info.colId) { + if (colIdOfRow2 < pColInfo->info.colId) { k++; continue; } @@ -1543,12 +1558,12 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit chosen_itr = k; isChosenRowDataRow = isRow2DataRow; } - if(isChosenRowDataRow) { + if (isChosenRowDataRow) { colId = pSchema->columns[chosen_itr].colId; offset = pSchema->columns[chosen_itr].offset; tdSTpRowGetVal(row, colId, pSchema->columns[chosen_itr].type, pSchema->flen, offset, chosen_itr, &sVal); } else { - SKvRowIdx *pColIdx = tdKvRowColIdxAt(row, chosen_itr); + SKvRowIdx* pColIdx = tdKvRowColIdxAt(row, chosen_itr); colId = pColIdx->colId; offset = pColIdx->offset; tdSKvRowGetVal(row, colId, offset, chosen_itr, &sVal); @@ -1563,21 +1578,21 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit i++; - if(row == row1) { + if (row == row1) { j++; } else { k++; } } else { - if(forceSetNull) { + if (forceSetNull) { colDataAppend(pColInfo, numOfRows, NULL, true); } i++; } } - if(forceSetNull) { - while (i < numOfCols) { // the remain columns are all null data + if (forceSetNull) { + while (i < numOfCols) { // the remain columns are all null data SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); colDataAppend(pColInfo, numOfRows, NULL, true); i++; @@ -1594,15 +1609,16 @@ static void moveDataToFront(STsdbReadHandle* pTsdbReadHandle, int32_t numOfRows, // if the buffer is not full in case of descending order query, move the data in the front of the buffer if (numOfRows < pTsdbReadHandle->outputCapacity) { int32_t emptySize = pTsdbReadHandle->outputCapacity - numOfRows; - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); - memmove((char*)pColInfo->pData, (char*)pColInfo->pData + emptySize * pColInfo->info.bytes, numOfRows * pColInfo->info.bytes); + memmove((char*)pColInfo->pData, (char*)pColInfo->pData + emptySize * pColInfo->info.bytes, + numOfRows * pColInfo->info.bytes); } } } -static void getQualifiedRowsPos(STsdbReadHandle* pTsdbReadHandle, int32_t startPos, int32_t endPos, int32_t numOfExisted, - int32_t* start, int32_t* end) { +static void getQualifiedRowsPos(STsdbReadHandle* pTsdbReadHandle, int32_t startPos, int32_t endPos, + int32_t numOfExisted, int32_t* start, int32_t* end) { *start = -1; if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { @@ -1627,7 +1643,8 @@ static void getQualifiedRowsPos(STsdbReadHandle* pTsdbReadHandle, int32_t startP } } -static void updateInfoAfterMerge(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, int32_t numOfRows, int32_t endPos) { +static void updateInfoAfterMerge(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, int32_t numOfRows, + int32_t endPos) { SQueryFilePos* cur = &pTsdbReadHandle->cur; pCheckInfo->lastKey = cur->lastKey; @@ -1647,22 +1664,24 @@ static void doCheckGeneratedBlockRange(STsdbReadHandle* pTsdbReadHandle) { } SColumnInfoData* pColInfoData = taosArrayGet(pTsdbReadHandle->pColumns, 0); - assert(cur->win.skey == ((TSKEY*)pColInfoData->pData)[0] && cur->win.ekey == ((TSKEY*)pColInfoData->pData)[cur->rows-1]); + assert(cur->win.skey == ((TSKEY*)pColInfoData->pData)[0] && + cur->win.ekey == ((TSKEY*)pColInfoData->pData)[cur->rows - 1]); } else { cur->win = pTsdbReadHandle->window; - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 1:-1; + int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; cur->lastKey = pTsdbReadHandle->window.ekey + step; } } -static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, SDataBlockInfo* pBlockInfo, int32_t endPos) { +static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, + SDataBlockInfo* pBlockInfo, int32_t endPos) { SQueryFilePos* cur = &pTsdbReadHandle->cur; SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; - TSKEY* tsArray = pCols->cols[0].pData; + TSKEY* tsArray = pCols->cols[0].pData; - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 1:-1; + int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; int32_t numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)); int32_t pos = cur->pos; @@ -1678,7 +1697,7 @@ static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STa int32_t numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, 0, start, end); // the time window should always be ascending order: skey <= ekey - cur->win = (STimeWindow) {.skey = tsArray[start], .ekey = tsArray[end]}; + cur->win = (STimeWindow){.skey = tsArray[start], .ekey = tsArray[end]}; cur->mixBlock = (numOfRows != pBlockInfo->rows); cur->lastKey = tsArray[endPos] + step; cur->blockCompleted = true; @@ -1691,17 +1710,18 @@ static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, STa updateInfoAfterMerge(pTsdbReadHandle, pCheckInfo, numOfRows, pos); doCheckGeneratedBlockRange(pTsdbReadHandle); - tsdbDebug("%p uid:%" PRIu64", data block created, mixblock:%d, brange:%"PRIu64"-%"PRIu64" rows:%d, %s", - pTsdbReadHandle, pCheckInfo->tableId, cur->mixBlock, cur->win.skey, cur->win.ekey, cur->rows, pTsdbReadHandle->idStr); + tsdbDebug("%p uid:%" PRIu64 ", data block created, mixblock:%d, brange:%" PRIu64 "-%" PRIu64 " rows:%d, %s", + pTsdbReadHandle, pCheckInfo->tableId, cur->mixBlock, cur->win.skey, cur->win.ekey, cur->rows, + pTsdbReadHandle->idStr); } int32_t getEndPosInDataBlock(STsdbReadHandle* pTsdbReadHandle, SDataBlockInfo* pBlockInfo) { // NOTE: reverse the order to find the end position in data block int32_t endPos = -1; - int32_t order = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? TSDB_ORDER_DESC : TSDB_ORDER_ASC; + int32_t order = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC; SQueryFilePos* cur = &pTsdbReadHandle->cur; - SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; + SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; if (ASCENDING_TRAVERSE(pTsdbReadHandle->order) && pTsdbReadHandle->window.ekey >= pBlockInfo->window.ekey) { endPos = pBlockInfo->rows - 1; @@ -1722,37 +1742,39 @@ int32_t getEndPosInDataBlock(STsdbReadHandle* pTsdbReadHandle, SDataBlockInfo* p // be included in the query time window will be discarded static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, SBlock* pBlock) { SQueryFilePos* cur = &pTsdbReadHandle->cur; - SDataBlockInfo blockInfo = {0};//GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlock); + SDataBlockInfo blockInfo = {0}; // GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlock); STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config; initTableMemIterator(pTsdbReadHandle, pCheckInfo); SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; assert(pCols->cols[0].type == TSDB_DATA_TYPE_TIMESTAMP && pCols->cols[0].colId == PRIMARYKEY_TIMESTAMP_COL_ID && - cur->pos >= 0 && cur->pos < pBlock->numOfRows); + cur->pos >= 0 && cur->pos < pBlock->numOfRows); TSKEY* tsArray = pCols->cols[0].pData; - assert(pCols->numOfRows == pBlock->numOfRows && tsArray[0] == pBlock->keyFirst && tsArray[pBlock->numOfRows-1] == pBlock->keyLast); + assert(pCols->numOfRows == pBlock->numOfRows && tsArray[0] == pBlock->keyFirst && + tsArray[pBlock->numOfRows - 1] == pBlock->keyLast); // for search the endPos, so the order needs to reverse - int32_t order = (pTsdbReadHandle->order == TSDB_ORDER_ASC)? TSDB_ORDER_DESC:TSDB_ORDER_ASC; + int32_t order = (pTsdbReadHandle->order == TSDB_ORDER_ASC) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC; - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 1:-1; + int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; int32_t numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)); STable* pTable = NULL; int32_t endPos = getEndPosInDataBlock(pTsdbReadHandle, &blockInfo); - tsdbDebug("%p uid:%" PRIu64" start merge data block, file block range:%"PRIu64"-%"PRIu64" rows:%d, start:%d," + tsdbDebug("%p uid:%" PRIu64 " start merge data block, file block range:%" PRIu64 "-%" PRIu64 + " rows:%d, start:%d," "end:%d, %s", - pTsdbReadHandle, pCheckInfo->tableId, blockInfo.window.skey, blockInfo.window.ekey, - blockInfo.rows, cur->pos, endPos, pTsdbReadHandle->idStr); + pTsdbReadHandle, pCheckInfo->tableId, blockInfo.window.skey, blockInfo.window.ekey, blockInfo.rows, + cur->pos, endPos, pTsdbReadHandle->idStr); // compared with the data from in-memory buffer, to generate the correct timestamp array list int32_t numOfRows = 0; - int16_t rv1 = -1; - int16_t rv2 = -1; + int16_t rv1 = -1; + int16_t rv2 = -1; STSchema* pSchema1 = NULL; STSchema* pSchema2 = NULL; @@ -1778,49 +1800,53 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf break; } - if (((pos > endPos || tsArray[pos] > pTsdbReadHandle->window.ekey) && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || - ((pos < endPos || tsArray[pos] < pTsdbReadHandle->window.ekey) && !ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { + if (((pos > endPos || tsArray[pos] > pTsdbReadHandle->window.ekey) && + ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || + ((pos < endPos || tsArray[pos] < pTsdbReadHandle->window.ekey) && + !ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { break; } if ((key < tsArray[pos] && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || (key > tsArray[pos] && !ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { if (rv1 != TD_ROW_SVER(row1)) { -// pSchema1 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row1)); + // pSchema1 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row1)); rv1 = TD_ROW_SVER(row1); } - if(row2 && rv2 != TD_ROW_SVER(row2)) { -// pSchema2 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row2)); + if (row2 && rv2 != TD_ROW_SVER(row2)) { + // pSchema2 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row2)); rv2 = TD_ROW_SVER(row2); } - - mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, row1, row2, numOfCols, pCheckInfo->tableId, pSchema1, pSchema2, true); + + mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, row1, row2, numOfCols, + pCheckInfo->tableId, pSchema1, pSchema2, true); numOfRows += 1; if (cur->win.skey == TSKEY_INITIAL_VAL) { cur->win.skey = key; } cur->win.ekey = key; - cur->lastKey = key + step; + cur->lastKey = key + step; cur->mixBlock = true; moveToNextRowInMem(pCheckInfo); } else if (key == tsArray[pos]) { // data in buffer has the same timestamp of data in file block, ignore it if (pCfg->update) { - if(pCfg->update == TD_ROW_PARTIAL_UPDATE) { + if (pCfg->update == TD_ROW_PARTIAL_UPDATE) { doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, pos, pos); } if (rv1 != TD_ROW_SVER(row1)) { -// pSchema1 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row1)); + // pSchema1 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row1)); rv1 = TD_ROW_SVER(row1); } - if(row2 && rv2 != TD_ROW_SVER(row2)) { -// pSchema2 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row2)); + if (row2 && rv2 != TD_ROW_SVER(row2)) { + // pSchema2 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row2)); rv2 = TD_ROW_SVER(row2); } - + bool forceSetNull = pCfg->update != TD_ROW_PARTIAL_UPDATE; - mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, row1, row2, numOfCols, pCheckInfo->tableId, pSchema1, pSchema2, forceSetNull); + mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, row1, row2, numOfCols, + pCheckInfo->tableId, pSchema1, pSchema2, forceSetNull); numOfRows += 1; if (cur->win.skey == TSKEY_INITIAL_VAL) { cur->win.skey = key; @@ -1836,7 +1862,7 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf moveToNextRowInMem(pCheckInfo); } } else if ((key > tsArray[pos] && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || - (key < tsArray[pos] && !ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { + (key < tsArray[pos] && !ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { if (cur->win.skey == TSKEY_INITIAL_VAL) { cur->win.skey = tsArray[pos]; } @@ -1844,7 +1870,7 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf int32_t end = doBinarySearchKey(pCols->cols[0].pData, pCols->numOfRows, key, order); assert(end != -1); - if (tsArray[end] == key) { // the value of key in cache equals to the end timestamp value, ignore it + if (tsArray[end] == key) { // the value of key in cache equals to the end timestamp value, ignore it if (pCfg->update == TD_ROW_DISCARD_UPDATE) { moveToNextRowInMem(pCheckInfo); } else { @@ -1858,8 +1884,8 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, qstart, qend); pos += (qend - qstart + 1) * step; - cur->win.ekey = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? tsArray[qend]:tsArray[qstart]; - cur->lastKey = cur->win.ekey + step; + cur->win.ekey = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? tsArray[qend] : tsArray[qstart]; + cur->lastKey = cur->win.ekey + step; } } while (numOfRows < pTsdbReadHandle->outputCapacity); @@ -1884,8 +1910,8 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, start, end); pos += (end - start + 1) * step; - cur->win.ekey = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? tsArray[end]:tsArray[start]; - cur->lastKey = cur->win.ekey + step; + cur->win.ekey = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? tsArray[end] : tsArray[start]; + cur->lastKey = cur->win.ekey + step; cur->mixBlock = true; } } @@ -1903,8 +1929,9 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf updateInfoAfterMerge(pTsdbReadHandle, pCheckInfo, numOfRows, pos); doCheckGeneratedBlockRange(pTsdbReadHandle); - tsdbDebug("%p uid:%" PRIu64", data block created, mixblock:%d, brange:%"PRIu64"-%"PRIu64" rows:%d, %s", - pTsdbReadHandle, pCheckInfo->tableId, cur->mixBlock, cur->win.skey, cur->win.ekey, cur->rows, pTsdbReadHandle->idStr); + tsdbDebug("%p uid:%" PRIu64 ", data block created, mixblock:%d, brange:%" PRIu64 "-%" PRIu64 " rows:%d, %s", + pTsdbReadHandle, pCheckInfo->tableId, cur->mixBlock, cur->win.skey, cur->win.ekey, cur->rows, + pTsdbReadHandle->idStr); } int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order) { @@ -2000,7 +2027,7 @@ static int32_t dataBlockOrderCompar(const void* pLeft, const void* pRight, void* STableBlockInfo* pRightBlockInfoEx = &pSupporter->pDataBlockInfo[rightTableIndex][rightTableBlockIndex]; // assert(pLeftBlockInfoEx->compBlock->offset != pRightBlockInfoEx->compBlock->offset); -#if 0 // TODO: temporarily comment off requested by Dr. Liao +#if 0 // TODO: temporarily comment off requested by Dr. Liao if (pLeftBlockInfoEx->compBlock->offset == pRightBlockInfoEx->compBlock->offset && pLeftBlockInfoEx->compBlock->last == pRightBlockInfoEx->compBlock->last) { tsdbError("error in header file, two block with same offset:%" PRId64, (int64_t)pLeftBlockInfoEx->compBlock->offset); @@ -2020,7 +2047,7 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu return TSDB_CODE_TDB_OUT_OF_MEMORY; } - pTsdbReadHandle->pDataBlockInfo = (STableBlockInfo*) tmp; + pTsdbReadHandle->pDataBlockInfo = (STableBlockInfo*)tmp; } memset(pTsdbReadHandle->pDataBlockInfo, 0, size); @@ -2079,18 +2106,18 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu cleanBlockOrderSupporter(&sup, numOfQualTables); tsdbDebug("%p create data blocks info struct completed for 1 table, %d blocks not sorted %s", pTsdbReadHandle, cnt, - pTsdbReadHandle->idStr); + pTsdbReadHandle->idStr); return TSDB_CODE_SUCCESS; } tsdbDebug("%p create data blocks info struct completed, %d blocks in %d tables %s", pTsdbReadHandle, cnt, - numOfQualTables, pTsdbReadHandle->idStr); + numOfQualTables, pTsdbReadHandle->idStr); assert(cnt <= numOfBlocks && numOfQualTables <= numOfTables); // the pTableQueryInfo[j]->numOfBlocks may be 0 sup.numOfTables = numOfQualTables; SMultiwayMergeTreeInfo* pTree = NULL; - uint8_t ret = tMergeTreeCreate(&pTree, sup.numOfTables, &sup, dataBlockOrderCompar); + uint8_t ret = tMergeTreeCreate(&pTree, sup.numOfTables, &sup, dataBlockOrderCompar); if (ret != TSDB_CODE_SUCCESS) { cleanBlockOrderSupporter(&sup, numOfTables); return TSDB_CODE_TDB_OUT_OF_MEMORY; @@ -2129,11 +2156,11 @@ static int32_t createDataBlocksInfo(STsdbReadHandle* pTsdbReadHandle, int32_t nu static int32_t getFirstFileDataBlock(STsdbReadHandle* pTsdbReadHandle, bool* exists); -static int32_t getDataBlockRv(STsdbReadHandle* pTsdbReadHandle, STableBlockInfo* pNext, bool *exists) { - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 1 : -1; +static int32_t getDataBlockRv(STsdbReadHandle* pTsdbReadHandle, STableBlockInfo* pNext, bool* exists) { + int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; SQueryFilePos* cur = &pTsdbReadHandle->cur; - while(1) { + while (1) { int32_t code = loadFileDataBlock(pTsdbReadHandle, pNext->compBlock, pNext->pTableCheckInfo, exists); if (code != TSDB_CODE_SUCCESS || *exists) { return code; @@ -2161,7 +2188,7 @@ static int32_t getFirstFileDataBlock(STsdbReadHandle* pTsdbReadHandle, bool* exi int32_t numOfBlocks = 0; int32_t numOfTables = (int32_t)taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config; + STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config; STimeWindow win = TSWINDOW_INITIALIZER; while (true) { @@ -2211,7 +2238,8 @@ static int32_t getFirstFileDataBlock(STsdbReadHandle* pTsdbReadHandle, bool* exi } // todo return error code to query engine - if ((code = createDataBlocksInfo(pTsdbReadHandle, numOfBlocks, &pTsdbReadHandle->numOfBlocks)) != TSDB_CODE_SUCCESS) { + if ((code = createDataBlocksInfo(pTsdbReadHandle, numOfBlocks, &pTsdbReadHandle->numOfBlocks)) != + TSDB_CODE_SUCCESS) { break; } @@ -2233,7 +2261,7 @@ static int32_t getFirstFileDataBlock(STsdbReadHandle* pTsdbReadHandle, bool* exi } assert(pTsdbReadHandle->pFileGroup != NULL && pTsdbReadHandle->numOfBlocks > 0); - cur->slot = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 0:pTsdbReadHandle->numOfBlocks-1; + cur->slot = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 0 : pTsdbReadHandle->numOfBlocks - 1; cur->fid = pTsdbReadHandle->pFileGroup->fid; STableBlockInfo* pBlockInfo = &pTsdbReadHandle->pDataBlockInfo[cur->slot]; @@ -2246,18 +2274,18 @@ static bool isEndFileDataBlock(SQueryFilePos* cur, int32_t numOfBlocks, bool asc } static void moveToNextDataBlockInCurrentFile(STsdbReadHandle* pTsdbReadHandle) { - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 1 : -1; + int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; SQueryFilePos* cur = &pTsdbReadHandle->cur; assert(cur->slot < pTsdbReadHandle->numOfBlocks && cur->slot >= 0); cur->slot += step; - cur->mixBlock = false; + cur->mixBlock = false; cur->blockCompleted = false; } int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo* pTableBlockInfo) { - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*) queryHandle; + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)queryHandle; pTableBlockInfo->totalSize = 0; pTableBlockInfo->totalRows = 0; @@ -2279,7 +2307,7 @@ int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo* int32_t code = TSDB_CODE_SUCCESS; int32_t numOfBlocks = 0; int32_t numOfTables = (int32_t)taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - int defaultRows = 4096;//TSDB_DEFAULT_BLOCK_ROWS(pCfg->maxRowsPerFileBlock); + int defaultRows = 4096; // TSDB_DEFAULT_BLOCK_ROWS(pCfg->maxRowsPerFileBlock); STimeWindow win = TSWINDOW_INITIALIZER; bool ascTraverse = ASCENDING_TRAVERSE(pTsdbReadHandle->order); @@ -2296,7 +2324,8 @@ int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo* tsdbGetFidKeyRange(pCfg->daysPerFile, pCfg->precision, pTsdbReadHandle->pFileGroup->fid, &win.skey, &win.ekey); // current file are not overlapped with query time window, ignore remain files - if ((ascTraverse && win.skey > pTsdbReadHandle->window.ekey) || (!ascTraverse && win.ekey < pTsdbReadHandle->window.ekey)) { + if ((ascTraverse && win.skey > pTsdbReadHandle->window.ekey) || + (!ascTraverse && win.ekey < pTsdbReadHandle->window.ekey)) { tsdbUnLockFS(REPO_FS(pTsdbReadHandle->pTsdb)); tsdbDebug("%p remain files are not qualified for qrange:%" PRId64 "-%" PRId64 ", ignore, %s", pTsdbReadHandle, pTsdbReadHandle->window.skey, pTsdbReadHandle->window.ekey, pTsdbReadHandle->idStr); @@ -2349,9 +2378,9 @@ int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo* if (numOfRows < defaultRows) { pTableBlockInfo->numOfSmallBlocks += 1; } -// int32_t stepIndex = (numOfRows-1)/TSDB_BLOCK_DIST_STEP_ROWS; -// SFileBlockInfo *blockInfo = (SFileBlockInfo*)taosArrayGet(pTableBlockInfo->dataBlockInfos, stepIndex); -// blockInfo->numBlocksOfStep++; + // int32_t stepIndex = (numOfRows-1)/TSDB_BLOCK_DIST_STEP_ROWS; + // SFileBlockInfo *blockInfo = (SFileBlockInfo*)taosArrayGet(pTableBlockInfo->dataBlockInfos, stepIndex); + // blockInfo->numBlocksOfStep++; } } } @@ -2408,7 +2437,7 @@ static int32_t getDataBlocksInFiles(STsdbReadHandle* pTsdbReadHandle, bool* exis static bool doHasDataInBuffer(STsdbReadHandle* pTsdbReadHandle) { size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - + while (pTsdbReadHandle->activeIndex < numOfTables) { if (hasMoreDataInCache(pTsdbReadHandle)) { return true; @@ -2420,23 +2449,23 @@ static bool doHasDataInBuffer(STsdbReadHandle* pTsdbReadHandle) { return false; } -//todo not unref yet, since it is not support multi-group interpolation query +// todo not unref yet, since it is not support multi-group interpolation query static UNUSED_FUNC void changeQueryHandleForInterpQuery(tsdbReaderT pHandle) { // filter the queried time stamp in the first place - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*) pHandle; + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; // starts from the buffer in case of descending timestamp order check data blocks size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); int32_t i = 0; - while(i < numOfTables) { + while (i < numOfTables) { STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); // the first qualified table for interpolation query -// if ((pTsdbReadHandle->window.skey <= pCheckInfo->pTableObj->lastKey) && -// (pCheckInfo->pTableObj->lastKey != TSKEY_INITIAL_VAL)) { -// break; -// } + // if ((pTsdbReadHandle->window.skey <= pCheckInfo->pTableObj->lastKey) && + // (pCheckInfo->pTableObj->lastKey != TSKEY_INITIAL_VAL)) { + // break; + // } i++; } @@ -2446,7 +2475,7 @@ static UNUSED_FUNC void changeQueryHandleForInterpQuery(tsdbReaderT pHandle) { return; } - STableCheckInfo info = *(STableCheckInfo*) taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); + STableCheckInfo info = *(STableCheckInfo*)taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); taosArrayClear(pTsdbReadHandle->pTableCheckInfo); info.lastKey = pTsdbReadHandle->window.skey; @@ -2455,13 +2484,13 @@ static UNUSED_FUNC void changeQueryHandleForInterpQuery(tsdbReaderT pHandle) { static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, STimeWindow* win, STsdbReadHandle* pTsdbReadHandle) { - int numOfRows = 0; - int32_t numOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pColumns); + int numOfRows = 0; + int32_t numOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pColumns); STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config; win->skey = TSKEY_INITIAL_VAL; - int64_t st = taosGetTimestampUs(); - int16_t rv = -1; + int64_t st = taosGetTimestampUs(); + int16_t rv = -1; STSchema* pSchema = NULL; do { @@ -2471,9 +2500,10 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int } TSKEY key = TD_ROW_KEY(row); - if ((key > maxKey && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || (key < maxKey && !ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { - tsdbDebug("%p key:%"PRIu64" beyond qrange:%"PRId64" - %"PRId64", no more data in buffer", pTsdbReadHandle, key, pTsdbReadHandle->window.skey, - pTsdbReadHandle->window.ekey); + if ((key > maxKey && ASCENDING_TRAVERSE(pTsdbReadHandle->order)) || + (key < maxKey && !ASCENDING_TRAVERSE(pTsdbReadHandle->order))) { + tsdbDebug("%p key:%" PRIu64 " beyond qrange:%" PRId64 " - %" PRId64 ", no more data in buffer", pTsdbReadHandle, + key, pTsdbReadHandle->window.skey, pTsdbReadHandle->window.ekey); break; } @@ -2487,14 +2517,15 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int pSchema = metaGetTbTSchema(pTsdbReadHandle->pTsdb->pMeta, pCheckInfo->tableId, 0); rv = TD_ROW_SVER(row); } - mergeTwoRowFromMem(pTsdbReadHandle, maxRowsToRead, numOfRows, row, NULL, numOfCols, pCheckInfo->tableId, pSchema, NULL, true); + mergeTwoRowFromMem(pTsdbReadHandle, maxRowsToRead, numOfRows, row, NULL, numOfCols, pCheckInfo->tableId, pSchema, + NULL, true); if (++numOfRows >= maxRowsToRead) { moveToNextRowInMem(pCheckInfo); break; } - } while(moveToNextRowInMem(pCheckInfo)); + } while (moveToNextRowInMem(pCheckInfo)); assert(numOfRows <= maxRowsToRead); @@ -2502,15 +2533,16 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int if (!ASCENDING_TRAVERSE(pTsdbReadHandle->order) && numOfRows < maxRowsToRead) { int32_t emptySize = maxRowsToRead - numOfRows; - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); - memmove((char*)pColInfo->pData, (char*)pColInfo->pData + emptySize * pColInfo->info.bytes, numOfRows * pColInfo->info.bytes); + memmove((char*)pColInfo->pData, (char*)pColInfo->pData + emptySize * pColInfo->info.bytes, + numOfRows * pColInfo->info.bytes); } } int64_t elapsedTime = taosGetTimestampUs() - st; - tsdbDebug("%p build data block from cache completed, elapsed time:%"PRId64" us, numOfRows:%d, numOfCols:%d, %s", pTsdbReadHandle, - elapsedTime, numOfRows, numOfCols, pTsdbReadHandle->idStr); + tsdbDebug("%p build data block from cache completed, elapsed time:%" PRId64 " us, numOfRows:%d, numOfCols:%d, %s", + pTsdbReadHandle, elapsedTime, numOfRows, numOfCols, pTsdbReadHandle->idStr); return numOfRows; } @@ -2537,20 +2569,20 @@ static void destroyHelper(void* param) { return; } -// tQueryInfo* pInfo = (tQueryInfo*)param; -// if (pInfo->optr != TSDB_RELATION_IN) { -// taosMemoryFreeClear(pInfo->q); -// } else { -// taosHashCleanup((SHashObj *)(pInfo->q)); -// } + // tQueryInfo* pInfo = (tQueryInfo*)param; + // if (pInfo->optr != TSDB_RELATION_IN) { + // taosMemoryFreeClear(pInfo->q); + // } else { + // taosHashCleanup((SHashObj *)(pInfo->q)); + // } taosMemoryFree(param); } -#define TSDB_PREV_ROW 0x1 -#define TSDB_NEXT_ROW 0x2 +#define TSDB_PREV_ROW 0x1 +#define TSDB_NEXT_ROW 0x2 -static bool loadBlockOfActiveTable(STsdbReadHandle* pTsdbReadHandle) { +static bool loadBlockOfActiveTable(STsdbReadHandle* pTsdbReadHandle) { if (pTsdbReadHandle->checkFiles) { // check if the query range overlaps with the file data block bool exists = true; @@ -2562,13 +2594,13 @@ static bool loadBlockOfActiveTable(STsdbReadHandle* pTsdbReadHandle) { } if (exists) { - tsdbRetrieveDataBlock((tsdbReaderT*) pTsdbReadHandle, NULL); + tsdbRetrieveDataBlock((tsdbReaderT*)pTsdbReadHandle, NULL); if (pTsdbReadHandle->currentLoadExternalRows && pTsdbReadHandle->window.skey == pTsdbReadHandle->window.ekey) { SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, 0); assert(*(int64_t*)pColInfo->pData == pTsdbReadHandle->window.skey); } - pTsdbReadHandle->currentLoadExternalRows = false; // clear the flag, since the exact matched row is found. + pTsdbReadHandle->currentLoadExternalRows = false; // clear the flag, since the exact matched row is found. return exists; } @@ -2581,16 +2613,17 @@ static bool loadBlockOfActiveTable(STsdbReadHandle* pTsdbReadHandle) { } // current result is empty - if (pTsdbReadHandle->currentLoadExternalRows && pTsdbReadHandle->window.skey == pTsdbReadHandle->window.ekey && pTsdbReadHandle->cur.rows == 0) { -// STsdbMemTable* pMemRef = pTsdbReadHandle->pMemTable; + if (pTsdbReadHandle->currentLoadExternalRows && pTsdbReadHandle->window.skey == pTsdbReadHandle->window.ekey && + pTsdbReadHandle->cur.rows == 0) { + // STsdbMemTable* pMemRef = pTsdbReadHandle->pMemTable; -// doGetExternalRow(pTsdbReadHandle, TSDB_PREV_ROW, pMemRef); -// doGetExternalRow(pTsdbReadHandle, TSDB_NEXT_ROW, pMemRef); + // doGetExternalRow(pTsdbReadHandle, TSDB_PREV_ROW, pMemRef); + // doGetExternalRow(pTsdbReadHandle, TSDB_NEXT_ROW, pMemRef); bool result = tsdbGetExternalRow(pTsdbReadHandle); -// pTsdbReadHandle->prev = doFreeColumnInfoData(pTsdbReadHandle->prev); -// pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); + // pTsdbReadHandle->prev = doFreeColumnInfoData(pTsdbReadHandle->prev); + // pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); pTsdbReadHandle->currentLoadExternalRows = false; return result; @@ -2602,30 +2635,31 @@ static bool loadBlockOfActiveTable(STsdbReadHandle* pTsdbReadHandle) { static bool loadCachedLastRow(STsdbReadHandle* pTsdbReadHandle) { // the last row is cached in buffer, return it directly. // here note that the pTsdbReadHandle->window must be the TS_INITIALIZER - int32_t numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)); + int32_t numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pTsdbReadHandle)); size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); assert(numOfTables > 0 && numOfCols > 0); SQueryFilePos* cur = &pTsdbReadHandle->cur; - STSRow* pRow = NULL; - TSKEY key = TSKEY_INITIAL_VAL; - int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order)? 1:-1; + STSRow* pRow = NULL; + TSKEY key = TSKEY_INITIAL_VAL; + int32_t step = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? 1 : -1; if (++pTsdbReadHandle->activeIndex < numOfTables) { STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, pTsdbReadHandle->activeIndex); -// int32_t ret = tsdbGetCachedLastRow(pCheckInfo->pTableObj, &pRow, &key); -// if (ret != TSDB_CODE_SUCCESS) { -// return false; -// } - mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, 0, pRow, NULL, numOfCols, pCheckInfo->tableId, NULL, NULL, true); + // int32_t ret = tsdbGetCachedLastRow(pCheckInfo->pTableObj, &pRow, &key); + // if (ret != TSDB_CODE_SUCCESS) { + // return false; + // } + mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, 0, pRow, NULL, numOfCols, pCheckInfo->tableId, + NULL, NULL, true); taosMemoryFreeClear(pRow); // update the last key value pCheckInfo->lastKey = key + step; - cur->rows = 1; // only one row - cur->lastKey = key + step; + cur->rows = 1; // only one row + cur->lastKey = key + step; cur->mixBlock = true; cur->win.skey = key; cur->win.ekey = key; @@ -2636,9 +2670,7 @@ static bool loadCachedLastRow(STsdbReadHandle* pTsdbReadHandle) { return false; } - - -//static bool loadCachedLast(STsdbReadHandle* pTsdbReadHandle) { +// static bool loadCachedLast(STsdbReadHandle* pTsdbReadHandle) { // // the last row is cached in buffer, return it directly. // // here note that the pTsdbReadHandle->window must be the TS_INITIALIZER // int32_t tgNumOfCols = (int32_t)QH_GET_NUM_OF_COLS(pTsdbReadHandle); @@ -2658,8 +2690,8 @@ static bool loadCachedLastRow(STsdbReadHandle* pTsdbReadHandle) { // int32_t numOfCols = pTable->maxColNum; // // if (pTable->lastCols == NULL || pTable->maxColNum <= 0) { -// tsdbWarn("no last cached for table %s, uid:%" PRIu64 ",tid:%d", pTable->name->data, pTable->uid, pTable->tableId); -// continue; +// tsdbWarn("no last cached for table %s, uid:%" PRIu64 ",tid:%d", pTable->name->data, pTable->uid, +// pTable->tableId); continue; // } // // int32_t i = 0, j = 0; @@ -2794,7 +2826,7 @@ static bool loadDataBlockFromTableSeq(STsdbReadHandle* pTsdbReadHandle) { int64_t stime = taosGetTimestampUs(); - while(pTsdbReadHandle->activeIndex < numOfTables) { + while (pTsdbReadHandle->activeIndex < numOfTables) { if (loadBlockOfActiveTable(pTsdbReadHandle)) { return true; } @@ -2804,8 +2836,8 @@ static bool loadDataBlockFromTableSeq(STsdbReadHandle* pTsdbReadHandle) { pTsdbReadHandle->activeIndex += 1; pTsdbReadHandle->locateStart = false; - pTsdbReadHandle->checkFiles = true; - pTsdbReadHandle->cur.rows = 0; + pTsdbReadHandle->checkFiles = true; + pTsdbReadHandle->cur.rows = 0; pTsdbReadHandle->currentLoadExternalRows = pTsdbReadHandle->loadExternalRow; terrno = TSDB_CODE_SUCCESS; @@ -2819,15 +2851,16 @@ static bool loadDataBlockFromTableSeq(STsdbReadHandle* pTsdbReadHandle) { // handle data in cache situation bool tsdbNextDataBlock(tsdbReaderT pHandle) { - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*) pHandle; + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; - for(int32_t i = 0; i < taosArrayGetSize(pTsdbReadHandle->pColumns); ++i) { + for (int32_t i = 0; i < taosArrayGetSize(pTsdbReadHandle->pColumns); ++i) { SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); colInfoDataCleanup(pColInfo, pTsdbReadHandle->outputCapacity); } if (emptyQueryTimewindow(pTsdbReadHandle)) { - tsdbDebug("%p query window not overlaps with the data set, no result returned, %s", pTsdbReadHandle, pTsdbReadHandle->idStr); + tsdbDebug("%p query window not overlaps with the data set, no result returned, %s", pTsdbReadHandle, + pTsdbReadHandle->idStr); return false; } @@ -2837,15 +2870,15 @@ bool tsdbNextDataBlock(tsdbReaderT pHandle) { // TODO refactor: remove "type" if (pTsdbReadHandle->type == TSDB_QUERY_TYPE_LAST) { if (pTsdbReadHandle->cachelastrow == TSDB_CACHED_TYPE_LASTROW) { -// return loadCachedLastRow(pTsdbReadHandle); + // return loadCachedLastRow(pTsdbReadHandle); } else if (pTsdbReadHandle->cachelastrow == TSDB_CACHED_TYPE_LAST) { -// return loadCachedLast(pTsdbReadHandle); + // return loadCachedLast(pTsdbReadHandle); } } if (pTsdbReadHandle->loadType == BLOCK_LOAD_TABLE_SEQ_ORDER) { return loadDataBlockFromTableSeq(pTsdbReadHandle); - } else { // loadType == RR and Offset Order + } else { // loadType == RR and Offset Order if (pTsdbReadHandle->checkFiles) { // check if the query range overlaps with the file data block bool exists = true; @@ -2877,7 +2910,7 @@ bool tsdbNextDataBlock(tsdbReaderT pHandle) { } } -//static int32_t doGetExternalRow(STsdbReadHandle* pTsdbReadHandle, int16_t type, STsdbMemTable* pMemRef) { +// static int32_t doGetExternalRow(STsdbReadHandle* pTsdbReadHandle, int16_t type, STsdbMemTable* pMemRef) { // STsdbReadHandle* pSecQueryHandle = NULL; // // if (type == TSDB_PREV_ROW && pTsdbReadHandle->prev) { @@ -2982,14 +3015,14 @@ bool tsdbNextDataBlock(tsdbReaderT pHandle) { // memcpy((char*)pCol->pData, (char*)s->pData + s->info.bytes * pos, pCol->info.bytes); // } // -//out_of_memory: +// out_of_memory: // tsdbCleanupReadHandle(pSecQueryHandle); // return terrno; //} bool tsdbGetExternalRow(tsdbReaderT pHandle) { - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*) pHandle; - SQueryFilePos* cur = &pTsdbReadHandle->cur; + STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; + SQueryFilePos* cur = &pTsdbReadHandle->cur; cur->fid = INT32_MIN; cur->mixBlock = true; @@ -2998,7 +3031,7 @@ bool tsdbGetExternalRow(tsdbReaderT pHandle) { return false; } - int32_t numOfCols = (int32_t) QH_GET_NUM_OF_COLS(pTsdbReadHandle); + int32_t numOfCols = (int32_t)QH_GET_NUM_OF_COLS(pTsdbReadHandle); for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* pColInfoData = taosArrayGet(pTsdbReadHandle->pColumns, i); SColumnInfoData* first = taosArrayGet(pTsdbReadHandle->prev, i); @@ -3045,36 +3078,36 @@ bool tsdbGetExternalRow(tsdbReaderT pHandle) { //} bool isTsdbCacheLastRow(tsdbReaderT* pReader) { - return ((STsdbReadHandle *)pReader)->cachelastrow > TSDB_CACHED_TYPE_NONE; + return ((STsdbReadHandle*)pReader)->cachelastrow > TSDB_CACHED_TYPE_NONE; } -int32_t checkForCachedLastRow(STsdbReadHandle* pTsdbReadHandle, STableGroupInfo *groupList) { +int32_t checkForCachedLastRow(STsdbReadHandle* pTsdbReadHandle, STableGroupInfo* groupList) { assert(pTsdbReadHandle != NULL && groupList != NULL); -// TSKEY key = TSKEY_INITIAL_VAL; -// -// SArray* group = taosArrayGetP(groupList->pGroupList, 0); -// assert(group != NULL); -// -// STableKeyInfo* pInfo = (STableKeyInfo*)taosArrayGet(group, 0); -// -// int32_t code = 0; -// -// if (((STable*)pInfo->pTable)->lastRow) { -// code = tsdbGetCachedLastRow(pInfo->pTable, NULL, &key); -// if (code != TSDB_CODE_SUCCESS) { -// pTsdbReadHandle->cachelastrow = TSDB_CACHED_TYPE_NONE; -// } else { -// pTsdbReadHandle->cachelastrow = TSDB_CACHED_TYPE_LASTROW; -// } -// } -// -// // update the tsdb query time range -// if (pTsdbReadHandle->cachelastrow != TSDB_CACHED_TYPE_NONE) { -// pTsdbReadHandle->window = TSWINDOW_INITIALIZER; -// pTsdbReadHandle->checkFiles = false; -// pTsdbReadHandle->activeIndex = -1; // start from -1 -// } + // TSKEY key = TSKEY_INITIAL_VAL; + // + // SArray* group = taosArrayGetP(groupList->pGroupList, 0); + // assert(group != NULL); + // + // STableKeyInfo* pInfo = (STableKeyInfo*)taosArrayGet(group, 0); + // + // int32_t code = 0; + // + // if (((STable*)pInfo->pTable)->lastRow) { + // code = tsdbGetCachedLastRow(pInfo->pTable, NULL, &key); + // if (code != TSDB_CODE_SUCCESS) { + // pTsdbReadHandle->cachelastrow = TSDB_CACHED_TYPE_NONE; + // } else { + // pTsdbReadHandle->cachelastrow = TSDB_CACHED_TYPE_LASTROW; + // } + // } + // + // // update the tsdb query time range + // if (pTsdbReadHandle->cachelastrow != TSDB_CACHED_TYPE_NONE) { + // pTsdbReadHandle->window = TSWINDOW_INITIALIZER; + // pTsdbReadHandle->checkFiles = false; + // pTsdbReadHandle->activeIndex = -1; // start from -1 + // } return TSDB_CODE_SUCCESS; } @@ -3083,21 +3116,20 @@ int32_t checkForCachedLast(STsdbReadHandle* pTsdbReadHandle) { assert(pTsdbReadHandle != NULL); int32_t code = 0; -// if (pTsdbReadHandle->pTsdb && atomic_load_8(&pTsdbReadHandle->pTsdb->hasCachedLastColumn)){ -// pTsdbReadHandle->cachelastrow = TSDB_CACHED_TYPE_LAST; -// } + // if (pTsdbReadHandle->pTsdb && atomic_load_8(&pTsdbReadHandle->pTsdb->hasCachedLastColumn)){ + // pTsdbReadHandle->cachelastrow = TSDB_CACHED_TYPE_LAST; + // } // update the tsdb query time range if (pTsdbReadHandle->cachelastrow) { - pTsdbReadHandle->checkFiles = false; + pTsdbReadHandle->checkFiles = false; pTsdbReadHandle->activeIndex = -1; // start from -1 } return code; } - -STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList) { +STimeWindow updateLastrowForEachGroup(STableGroupInfo* groupList) { STimeWindow window = {INT64_MAX, INT64_MIN}; int32_t totalNumOfTable = 0; @@ -3105,24 +3137,24 @@ STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList) { // NOTE: starts from the buffer in case of descending timestamp order check data blocks size_t numOfGroups = taosArrayGetSize(groupList->pGroupList); - for(int32_t j = 0; j < numOfGroups; ++j) { + for (int32_t j = 0; j < numOfGroups; ++j) { SArray* pGroup = taosArrayGetP(groupList->pGroupList, j); TSKEY key = TSKEY_INITIAL_VAL; STableKeyInfo keyInfo = {0}; size_t numOfTables = taosArrayGetSize(pGroup); - for(int32_t i = 0; i < numOfTables; ++i) { - STableKeyInfo* pInfo = (STableKeyInfo*) taosArrayGet(pGroup, i); + for (int32_t i = 0; i < numOfTables; ++i) { + STableKeyInfo* pInfo = (STableKeyInfo*)taosArrayGet(pGroup, i); // if the lastKey equals to INT64_MIN, there is no data in this table - TSKEY lastKey = 0;//((STable*)(pInfo->pTable))->lastKey; + TSKEY lastKey = 0; //((STable*)(pInfo->pTable))->lastKey; if (key < lastKey) { key = lastKey; -// keyInfo.pTable = pInfo->pTable; + // keyInfo.pTable = pInfo->pTable; keyInfo.lastKey = key; - pInfo->lastKey = key; + pInfo->lastKey = key; if (key < window.skey) { window.skey = key; @@ -3135,18 +3167,18 @@ STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList) { } // more than one table in each group, only one table left for each group -// if (keyInfo.pTable != NULL) { -// totalNumOfTable++; -// if (taosArrayGetSize(pGroup) == 1) { -// // do nothing -// } else { -// taosArrayClear(pGroup); -// taosArrayPush(pGroup, &keyInfo); -// } -// } else { // mark all the empty groups, and remove it later -// taosArrayDestroy(pGroup); -// taosArrayPush(emptyGroup, &j); -// } + // if (keyInfo.pTable != NULL) { + // totalNumOfTable++; + // if (taosArrayGetSize(pGroup) == 1) { + // // do nothing + // } else { + // taosArrayClear(pGroup); + // taosArrayPush(pGroup, &keyInfo); + // } + // } else { // mark all the empty groups, and remove it later + // taosArrayDestroy(pGroup); + // taosArrayPush(emptyGroup, &j); + // } } // window does not being updated, so set the original @@ -3155,7 +3187,7 @@ STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList) { assert(totalNumOfTable == 0 && taosArrayGetSize(groupList->pGroupList) == numOfGroups); } - taosArrayRemoveBatch(groupList->pGroupList, TARRAY_GET_START(emptyGroup), (int32_t) taosArrayGetSize(emptyGroup)); + taosArrayRemoveBatch(groupList->pGroupList, TARRAY_GET_START(emptyGroup), (int32_t)taosArrayGetSize(emptyGroup)); taosArrayDestroy(emptyGroup); groupList->numOfTables = totalNumOfTable; @@ -3164,7 +3196,7 @@ STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList) { void tsdbRetrieveDataBlockInfo(tsdbReaderT* pTsdbReadHandle, SDataBlockInfo* pDataBlockInfo) { STsdbReadHandle* pHandle = (STsdbReadHandle*)pTsdbReadHandle; - SQueryFilePos* cur = &pHandle->cur; + SQueryFilePos* cur = &pHandle->cur; uint64_t uid = 0; @@ -3177,11 +3209,12 @@ void tsdbRetrieveDataBlockInfo(tsdbReaderT* pTsdbReadHandle, SDataBlockInfo* pDa uid = pCheckInfo->tableId; } - tsdbDebug("data block generated, uid:%"PRIu64" numOfRows:%d, tsrange:%"PRId64" - %"PRId64" %s", uid, cur->rows, cur->win.skey, - cur->win.ekey, pHandle->idStr); + tsdbDebug("data block generated, uid:%" PRIu64 " numOfRows:%d, tsrange:%" PRId64 " - %" PRId64 " %s", uid, cur->rows, + cur->win.skey, cur->win.ekey, pHandle->idStr); -// pDataBlockInfo->uid = uid; // block Id may be over write by assigning uid fro this data block. Do NOT assign the table uid - pDataBlockInfo->rows = cur->rows; + // pDataBlockInfo->uid = uid; // block Id may be over write by assigning uid fro this data block. Do NOT assign + // the table uid + pDataBlockInfo->rows = cur->rows; pDataBlockInfo->window = cur->win; pDataBlockInfo->numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pHandle)); } @@ -3190,7 +3223,7 @@ void tsdbRetrieveDataBlockInfo(tsdbReaderT* pTsdbReadHandle, SDataBlockInfo* pDa * return null for mixed data block, if not a complete file data block, the statistics value will always return NULL */ int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SDataStatis** pBlockStatis) { - STsdbReadHandle* pHandle = (STsdbReadHandle*) pTsdbReadHandle; + STsdbReadHandle* pHandle = (STsdbReadHandle*)pTsdbReadHandle; SQueryFilePos* c = &pHandle->cur; if (c->mixBlock) { @@ -3220,7 +3253,7 @@ int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SDataStati size_t numOfCols = QH_GET_NUM_OF_COLS(pHandle); memset(pHandle->statis, 0, numOfCols * sizeof(SDataStatis)); - for(int32_t i = 0; i < numOfCols; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { pHandle->statis[i].colId = colIds[i]; } @@ -3234,9 +3267,9 @@ int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SDataStati pPrimaryColStatis->min = pBlockInfo->compBlock->keyFirst; pPrimaryColStatis->max = pBlockInfo->compBlock->keyLast; - //update the number of NULL data rows - for(int32_t i = 1; i < numOfCols; ++i) { - if (pHandle->statis[i].numOfNull == -1) { // set the column data are all NULL + // update the number of NULL data rows + for (int32_t i = 1; i < numOfCols; ++i) { + if (pHandle->statis[i].numOfNull == -1) { // set the column data are all NULL pHandle->statis[i].numOfNull = pBlockInfo->compBlock->numOfRows; } } @@ -3286,9 +3319,10 @@ SArray* tsdbRetrieveDataBlock(tsdbReaderT* pTsdbReadHandle, SArray* pIdList) { int32_t emptySize = pHandle->outputCapacity - numOfRows; int32_t reqNumOfCols = (int32_t)taosArrayGetSize(pHandle->pColumns); - for(int32_t i = 0; i < reqNumOfCols; ++i) { + for (int32_t i = 0; i < reqNumOfCols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pHandle->pColumns, i); - memmove((char*)pColInfo->pData, (char*)pColInfo->pData + emptySize * pColInfo->info.bytes, numOfRows * pColInfo->info.bytes); + memmove((char*)pColInfo->pData, (char*)pColInfo->pData + emptySize * pColInfo->info.bytes, + numOfRows * pColInfo->info.bytes); } } @@ -3344,7 +3378,7 @@ void filterPrepare(void* expr, void* param) { #endif -static int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) { +static int32_t tableGroupComparFn(const void* p1, const void* p2, const void* param) { #if 0 STableGroupSupporter* pTableGroupSupp = (STableGroupSupporter*) param; STable* pTable1 = ((STableKeyInfo*) p1)->uid; @@ -3441,7 +3475,8 @@ void createTableGroupImpl(SArray* pGroups, SArray* pTableList, size_t numOfTable taosArrayPush(pGroups, &g); } -SArray* createTableGroup(SArray* pTableList, SSchemaWrapper* pTagSchema, SColIndex* pCols, int32_t numOfOrderCols, TSKEY skey) { +SArray* createTableGroup(SArray* pTableList, SSchemaWrapper* pTagSchema, SColIndex* pCols, int32_t numOfOrderCols, + TSKEY skey) { assert(pTableList != NULL); SArray* pTableGroup = taosArrayInit(1, POINTER_BYTES); @@ -3451,7 +3486,7 @@ SArray* createTableGroup(SArray* pTableList, SSchemaWrapper* pTagSchema, SColInd return pTableGroup; } - if (numOfOrderCols == 0 || size == 1) { // no group by tags clause or only one table + if (numOfOrderCols == 0 || size == 1) { // no group by tags clause or only one table SArray* sa = taosArrayDup(pTableList); if (sa == NULL) { taosArrayDestroy(pTableGroup); @@ -3473,7 +3508,7 @@ SArray* createTableGroup(SArray* pTableList, SSchemaWrapper* pTagSchema, SColInd return pTableGroup; } -//static bool tableFilterFp(const void* pNode, void* param) { +// static bool tableFilterFp(const void* pNode, void* param) { // tQueryInfo* pInfo = (tQueryInfo*) param; // // STable* pTable = (STable*)(SL_GET_NODE_DATA((SSkipListNode*)pNode)); @@ -3558,15 +3593,16 @@ SArray* createTableGroup(SArray* pTableList, SSchemaWrapper* pTagSchema, SColInd // return true; //} -//static void getTableListfromSkipList(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SExprTraverseSupp *param); +// static void getTableListfromSkipList(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SExprTraverseSupp +// *param); -//static int32_t doQueryTableList(STable* pSTable, SArray* pRes, tExprNode* pExpr) { -// // query according to the expression tree +// static int32_t doQueryTableList(STable* pSTable, SArray* pRes, tExprNode* pExpr) { +// // // query according to the expression tree // SExprTraverseSupp supp = { -// .nodeFilterFn = (__result_filter_fn_t) tableFilterFp, +// .nodeFilterFn = (__result_filter_fn_t)tableFilterFp, // .setupInfoFn = filterPrepare, // .pExtInfo = pSTable->tagSchema, -// }; +// }; // // getTableListfromSkipList(pExpr, pSTable->pIndex, pRes, &supp); // tExprTreeDestroy(pExpr, destroyHelper); @@ -3578,19 +3614,20 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch SColIndex* pColIndex, int32_t numOfCols, uint64_t reqId, uint64_t taskId) { STbCfg* pTbCfg = metaGetTbInfoByUid(pMeta, uid); if (pTbCfg == NULL) { - tsdbError("%p failed to get stable, uid:%"PRIu64", TID:0x%"PRIx64" QID:0x%"PRIx64, pMeta, uid, taskId, reqId); + tsdbError("%p failed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId); terrno = TSDB_CODE_TDB_INVALID_TABLE_ID; goto _error; } if (pTbCfg->type != META_SUPER_TABLE) { - tsdbError("%p query normal tag not allowed, uid:%" PRIu64 ", TID:0x%"PRIx64" QID:0x%"PRIx64, pMeta, uid, taskId, reqId); - terrno = TSDB_CODE_OPS_NOT_SUPPORT; //basically, this error is caused by invalid sql issued by client + tsdbError("%p query normal tag not allowed, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, + reqId); + terrno = TSDB_CODE_OPS_NOT_SUPPORT; // basically, this error is caused by invalid sql issued by client goto _error; } - //NOTE: not add ref count for super table - SArray* res = taosArrayInit(8, sizeof(STableKeyInfo)); + // NOTE: not add ref count for super table + SArray* res = taosArrayInit(8, sizeof(STableKeyInfo)); SSchemaWrapper* pTagSchema = metaGetTableSchema(pMeta, uid, 0, true); // no tags and tbname condition, all child tables of this stable are involved @@ -3600,66 +3637,44 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch goto _error; } - pGroupInfo->numOfTables = (uint32_t) taosArrayGetSize(res); - pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, skey); + pGroupInfo->numOfTables = (uint32_t)taosArrayGetSize(res); + pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, skey); - tsdbDebug("%p no table name/tag condition, all tables qualified, numOfTables:%u, group:%zu, TID:0x%"PRIx64" QID:0x%"PRIx64, pMeta, - pGroupInfo->numOfTables, taosArrayGetSize(pGroupInfo->pGroupList), taskId, reqId); + tsdbDebug("%p no table name/tag condition, all tables qualified, numOfTables:%u, group:%zu, TID:0x%" PRIx64 + " QID:0x%" PRIx64, + pMeta, pGroupInfo->numOfTables, taosArrayGetSize(pGroupInfo->pGroupList), taskId, reqId); taosArrayDestroy(res); return ret; } int32_t ret = TSDB_CODE_SUCCESS; -// tExprNode* expr = NULL; -// -// TRY(TSDB_MAX_TAG_CONDITIONS) { -// expr = exprTreeFromTableName(tbnameCond); -// if (expr == NULL) { -// expr = exprTreeFromBinary(pTagCond, len); -// } else { -// CLEANUP_PUSH_VOID_PTR_PTR(true, tExprTreeDestroy, expr, NULL); -// tExprNode* tagExpr = exprTreeFromBinary(pTagCond, len); -// if (tagExpr != NULL) { -// CLEANUP_PUSH_VOID_PTR_PTR(true, tExprTreeDestroy, tagExpr, NULL); -// tExprNode* tbnameExpr = expr; -// expr = taosMemoryCalloc(1, sizeof(tExprNode)); -// if (expr == NULL) { -// THROW( TSDB_CODE_TDB_OUT_OF_MEMORY ); -// } -// expr->nodeType = TSQL_NODE_EXPR; -// expr->_node.optr = (uint8_t)tagNameRelType; -// expr->_node.pLeft = tagExpr; -// expr->_node.pRight = tbnameExpr; -// } -// } -// CLEANUP_EXECUTE(); -// -// } CATCH( code ) { -// CLEANUP_EXECUTE(); -// terrno = code; -// tsdbUnlockRepoMeta(tsdb); // unlock tsdb in any cases -// -// goto _error; -// // TODO: more error handling -// } END_TRY -// -// doQueryTableList(pTable, res, expr); -// pGroupInfo->numOfTables = (uint32_t)taosArrayGetSize(res); -// pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, skey); -// -// tsdbDebug("%p stable tid:%d, uid:%"PRIu64" query, numOfTables:%u, belong to %" PRIzu " groups", tsdb, pTable->tableId, -// pTable->uid, pGroupInfo->numOfTables, taosArrayGetSize(pGroupInfo->pGroupList)); -// -// taosArrayDestroy(res); -// -// if (tsdbUnlockRepoMeta(tsdb) < 0) goto _error; -// return ret; - _error: + SFilterInfo* filterInfo = NULL; + ret = filterInitFromNode((SNode*)pTagCond, &filterInfo, 0); + if (ret != TSDB_CODE_SUCCESS) { + terrno = ret; + return ret; + } + ret = tsdbQueryTableList(pMeta, res, filterInfo); + pGroupInfo->numOfTables = (uint32_t)taosArrayGetSize(res); + pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, skey); + + // tsdbDebug("%p stable tid:%d, uid:%" PRIu64 " query, numOfTables:%u, belong to %" PRIzu " groups", tsdb, + // pTable->tableId, pTable->uid, pGroupInfo->numOfTables, taosArrayGetSize(pGroupInfo->pGroupList)); + + taosArrayDestroy(res); + return ret; + +_error: return terrno; } +int32_t tsdbQueryTableList(void* pMeta, SArray* pRes, void* filterInfo) { + // impl later + + return TSDB_CODE_SUCCESS; +} int32_t tsdbGetOneTableGroup(void* pMeta, uint64_t uid, TSKEY startKey, STableGroupInfo* pGroupInfo) { STbCfg* pTbCfg = metaGetTbInfoByUid(pMeta, uid); if (pTbCfg == NULL) { @@ -3678,7 +3693,7 @@ int32_t tsdbGetOneTableGroup(void* pMeta, uint64_t uid, TSKEY startKey, STableGr taosArrayPush(pGroupInfo->pGroupList, &group); return TSDB_CODE_SUCCESS; - _error: +_error: return terrno; } @@ -3757,7 +3772,6 @@ static void* destroyTableCheckInfo(SArray* pTableCheckInfo) { return NULL; } - void tsdbCleanupReadHandle(tsdbReaderT queryHandle) { STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)queryHandle; if (pTsdbReadHandle == NULL) { @@ -3771,7 +3785,7 @@ void tsdbCleanupReadHandle(tsdbReaderT queryHandle) { taosMemoryFreeClear(pTsdbReadHandle->statis); if (!emptyQueryTimewindow(pTsdbReadHandle)) { -// tsdbMayUnTakeMemSnapshot(pTsdbReadHandle); + // tsdbMayUnTakeMemSnapshot(pTsdbReadHandle); } else { assert(pTsdbReadHandle->pTableCheckInfo == NULL); } @@ -3790,8 +3804,10 @@ void tsdbCleanupReadHandle(tsdbReaderT queryHandle) { SIOCostSummary* pCost = &pTsdbReadHandle->cost; - tsdbDebug("%p :io-cost summary: head-file read cnt:%"PRIu64", head-file time:%"PRIu64" us, statis-info:%"PRId64" us, datablock:%" PRId64" us, check data:%"PRId64" us, %s", - pTsdbReadHandle, pCost->headFileLoad, pCost->headFileLoadTime, pCost->statisInfoLoadTime, pCost->blockLoadTime, pCost->checkForNextTime, pTsdbReadHandle->idStr); + tsdbDebug("%p :io-cost summary: head-file read cnt:%" PRIu64 ", head-file time:%" PRIu64 " us, statis-info:%" PRId64 + " us, datablock:%" PRId64 " us, check data:%" PRId64 " us, %s", + pTsdbReadHandle, pCost->headFileLoad, pCost->headFileLoadTime, pCost->statisInfoLoadTime, + pCost->blockLoadTime, pCost->checkForNextTime, pTsdbReadHandle->idStr); taosMemoryFreeClear(pTsdbReadHandle); } @@ -4045,37 +4061,37 @@ static void queryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, S } // Apply the filter expression to each node in the skiplist to acquire the qualified nodes in skip list -void getTableListfromSkipList(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SExprTraverseSupp *param) { - if (pExpr == NULL) { - return; - } - - tExprNode *pLeft = pExpr->_node.pLeft; - tExprNode *pRight = pExpr->_node.pRight; - - // column project - if (pLeft->nodeType != TSQL_NODE_EXPR && pRight->nodeType != TSQL_NODE_EXPR) { - assert(pLeft->nodeType == TSQL_NODE_COL && (pRight->nodeType == TSQL_NODE_VALUE || pRight->nodeType == TSQL_NODE_DUMMY)); - - param->setupInfoFn(pExpr, param->pExtInfo); - - tQueryInfo *pQueryInfo = pExpr->_node.info; - if (pQueryInfo->indexed && (pQueryInfo->optr != TSDB_RELATION_LIKE - && pQueryInfo->optr != TSDB_RELATION_MATCH && pQueryInfo->optr != TSDB_RELATION_NMATCH - && pQueryInfo->optr != TSDB_RELATION_IN)) { - queryIndexedColumn(pSkipList, pQueryInfo, result); - } else { - queryIndexlessColumn(pSkipList, pQueryInfo, result, param->nodeFilterFn); - } - - return; - } - - // The value of hasPK is always 0. - uint8_t weight = pLeft->_node.hasPK + pRight->_node.hasPK; - assert(weight == 0 && pSkipList != NULL && taosArrayGetSize(result) == 0); - - //apply the hierarchical filter expression to every node in skiplist to find the qualified nodes - applyFilterToSkipListNode(pSkipList, pExpr, result, param); -} +//void getTableListfromSkipList(tExprNode *pExpr, SSkipList *pSkipList, SArray *result, SExprTraverseSupp *param) { +// if (pExpr == NULL) { +// return; +// } +// +// tExprNode *pLeft = pExpr->_node.pLeft; +// tExprNode *pRight = pExpr->_node.pRight; +// +// // column project +// if (pLeft->nodeType != TSQL_NODE_EXPR && pRight->nodeType != TSQL_NODE_EXPR) { +// assert(pLeft->nodeType == TSQL_NODE_COL && (pRight->nodeType == TSQL_NODE_VALUE || pRight->nodeType == TSQL_NODE_DUMMY)); +// +// param->setupInfoFn(pExpr, param->pExtInfo); +// +// tQueryInfo *pQueryInfo = pExpr->_node.info; +// if (pQueryInfo->indexed && (pQueryInfo->optr != TSDB_RELATION_LIKE +// && pQueryInfo->optr != TSDB_RELATION_MATCH && pQueryInfo->optr != TSDB_RELATION_NMATCH +// && pQueryInfo->optr != TSDB_RELATION_IN)) { +// queryIndexedColumn(pSkipList, pQueryInfo, result); +// } else { +// queryIndexlessColumn(pSkipList, pQueryInfo, result, param->nodeFilterFn); +// } +// +// return; +// } +// +// // The value of hasPK is always 0. +// uint8_t weight = pLeft->_node.hasPK + pRight->_node.hasPK; +// assert(weight == 0 && pSkipList != NULL && taosArrayGetSize(result) == 0); +// +// //apply the hierarchical filter expression to every node in skiplist to find the qualified nodes +// applyFilterToSkipListNode(pSkipList, pExpr, result, param); +//} #endif diff --git a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c index 87459593b5604c66689199fbe9d10f18959d6114..e31ede09cc0aa2cefdacca42980783785de4ab1a 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c +++ b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c @@ -263,8 +263,9 @@ int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo) { for (int i = 1; i < pBlock->numOfSubBlocks; i++) { iBlock++; if (tsdbLoadBlockDataImpl(pReadh, iBlock, pReadh->pDCols[1]) < 0) return -1; + // TODO: use the real maxVersion to replace the UINT64_MAX to support Multi-Version if (tdMergeDataCols(pReadh->pDCols[0], pReadh->pDCols[1], pReadh->pDCols[1]->numOfRows, NULL, - update != TD_ROW_PARTIAL_UPDATE) < 0) + update != TD_ROW_PARTIAL_UPDATE, UINT64_MAX) < 0) return -1; } @@ -293,8 +294,9 @@ int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, for (int i = 1; i < pBlock->numOfSubBlocks; i++) { iBlock++; if (tsdbLoadBlockDataColsImpl(pReadh, iBlock, pReadh->pDCols[1], colIds, numOfColsIds) < 0) return -1; + // TODO: use the real maxVersion to replace the UINT64_MAX to support Multi-Version if (tdMergeDataCols(pReadh->pDCols[0], pReadh->pDCols[1], pReadh->pDCols[1]->numOfRows, NULL, - update != TD_ROW_PARTIAL_UPDATE) < 0) + update != TD_ROW_PARTIAL_UPDATE, UINT64_MAX) < 0) return -1; } @@ -304,6 +306,7 @@ int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, if (pDataCol->bitmap) { ASSERT(pDataCol->colId != PRIMARYKEY_TIMESTAMP_COL_ID); tdMergeBitmap(pDataCol->pBitmap, TD_BITMAP_BYTES(pReadh->pDCols[0]->numOfRows), pDataCol->pBitmap); + tdDataColsSetBitmapI(pReadh->pDCols[0]); } } } diff --git a/source/dnode/vnode/src/tsdb/tsdbSma.c b/source/dnode/vnode/src/tsdb/tsdbSma.c index 07b7d6216543b957d517d4833bf51010f487ba66..7de5a0d5a9cf0419246658857eb6e4131afeffe0 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSma.c +++ b/source/dnode/vnode/src/tsdb/tsdbSma.c @@ -38,6 +38,29 @@ typedef enum { SMA_STORAGE_LEVEL_DFILESET = 1 // use days of TS data e.g. vnode${N}/tsdb/tsma/sma_index_uid/v2f1906.tsma } ESmaStorageLevel; +typedef struct SPoolMem { + int64_t size; + struct SPoolMem *prev; + struct SPoolMem *next; +} SPoolMem; + +struct SSmaEnv { + TdThreadRwlock lock; + TXN txn; + SPoolMem *pPool; + SDiskID did; + TENV *dbEnv; // TODO: If it's better to put it in smaIndex level? + char *path; // relative path + SSmaStat *pStat; +}; + +#define SMA_ENV_LOCK(env) ((env)->lock) +#define SMA_ENV_DID(env) ((env)->did) +#define SMA_ENV_ENV(env) ((env)->dbEnv) +#define SMA_ENV_PATH(env) ((env)->path) +#define SMA_ENV_STAT(env) ((env)->pStat) +#define SMA_ENV_STAT_ITEMS(env) ((env)->pStat->smaStatItems) + typedef struct { STsdb *pTsdb; SDBFile dFile; @@ -82,8 +105,8 @@ struct SSmaStat { // declaration of static functions // expired window -static int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg); -static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey); +static int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t version); +static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey, int64_t version); static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat); static void *tsdbFreeSmaStatItem(SSmaStatItem *pSmaStatItem); static int32_t tsdbDestroySmaState(SSmaStat *pSmaStat); @@ -104,7 +127,8 @@ static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH); static int32_t tsdbInitTSmaReadH(STSmaReadH *pSmaH, STsdb *pTsdb, int64_t interval, int8_t intervalUnit); static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit); static int32_t tsdbSetRSmaDataFile(STSmaWriteH *pSmaH, int32_t fid); -static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t keyLen, void *pData, uint32_t dataLen); +static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, int32_t keyLen, void *pData, int32_t dataLen, + TXN *txn); static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit, int8_t precision, bool adjusted); static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLevel); static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, int64_t indexUid, int32_t fid); @@ -117,9 +141,121 @@ static int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, const char *msg); // mgmt interface static int32_t tsdbDropTSmaDataImpl(STsdb *pTsdb, int64_t indexUid); +// Pool Memory +static SPoolMem *openPool(); +static void clearPool(SPoolMem *pPool); +static void closePool(SPoolMem *pPool); +static void *poolMalloc(void *arg, size_t size); +static void poolFree(void *arg, void *ptr); + +static int tsdbSmaBeginCommit(SSmaEnv *pEnv); +static int tsdbSmaEndCommit(SSmaEnv *pEnv); + // implementation -static FORCE_INLINE int16_t tsdbTSmaAdd(STsdb *pTsdb, int16_t n) { return atomic_add_fetch_16(&REPO_TSMA_NUM(pTsdb), n); } -static FORCE_INLINE int16_t tsdbTSmaSub(STsdb *pTsdb, int16_t n) { return atomic_sub_fetch_16(&REPO_TSMA_NUM(pTsdb), n); } +static FORCE_INLINE int16_t tsdbTSmaAdd(STsdb *pTsdb, int16_t n) { + return atomic_add_fetch_16(&REPO_TSMA_NUM(pTsdb), n); +} +static FORCE_INLINE int16_t tsdbTSmaSub(STsdb *pTsdb, int16_t n) { + return atomic_sub_fetch_16(&REPO_TSMA_NUM(pTsdb), n); +} + +static FORCE_INLINE int32_t tsdbRLockSma(SSmaEnv *pEnv) { + int code = taosThreadRwlockRdlock(&(pEnv->lock)); + if (code != 0) { + terrno = TAOS_SYSTEM_ERROR(code); + return -1; + } + return 0; +} + +static FORCE_INLINE int32_t tsdbWLockSma(SSmaEnv *pEnv) { + int code = taosThreadRwlockWrlock(&(pEnv->lock)); + if (code != 0) { + terrno = TAOS_SYSTEM_ERROR(code); + return -1; + } + return 0; +} + +static FORCE_INLINE int32_t tsdbUnLockSma(SSmaEnv *pEnv) { + int code = taosThreadRwlockUnlock(&(pEnv->lock)); + if (code != 0) { + terrno = TAOS_SYSTEM_ERROR(code); + return -1; + } + return 0; +} + +static SPoolMem *openPool() { + SPoolMem *pPool = (SPoolMem *)tdbOsMalloc(sizeof(*pPool)); + + pPool->prev = pPool->next = pPool; + pPool->size = 0; + + return pPool; +} + +static void clearPool(SPoolMem *pPool) { + if (!pPool) return; + + SPoolMem *pMem; + + do { + pMem = pPool->next; + + if (pMem == pPool) break; + + pMem->next->prev = pMem->prev; + pMem->prev->next = pMem->next; + pPool->size -= pMem->size; + + tdbOsFree(pMem); + } while (1); + + assert(pPool->size == 0); +} + +static void closePool(SPoolMem *pPool) { + if (pPool) { + clearPool(pPool); + tdbOsFree(pPool); + } +} + +static void *poolMalloc(void *arg, size_t size) { + void *ptr = NULL; + SPoolMem *pPool = (SPoolMem *)arg; + SPoolMem *pMem; + + pMem = (SPoolMem *)tdbOsMalloc(sizeof(*pMem) + size); + if (pMem == NULL) { + assert(0); + } + + pMem->size = sizeof(*pMem) + size; + pMem->next = pPool->next; + pMem->prev = pPool; + + pPool->next->prev = pMem; + pPool->next = pMem; + pPool->size += pMem->size; + + ptr = (void *)(&pMem[1]); + return ptr; +} + +static void poolFree(void *arg, void *ptr) { + SPoolMem *pPool = (SPoolMem *)arg; + SPoolMem *pMem; + + pMem = &(((SPoolMem *)ptr)[-1]); + + pMem->next->prev = pMem->prev; + pMem->prev->next = pMem->next; + pPool->size -= pMem->size; + + tdbOsFree(pMem); +} int32_t tsdbInitSma(STsdb *pTsdb) { // tSma @@ -213,7 +349,12 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did) char aname[TSDB_FILENAME_LEN] = {0}; tfsAbsoluteName(pTsdb->pTfs, did, path, aname); - if (tsdbOpenBDBEnv(&pEnv->dbEnv, aname) != TSDB_CODE_SUCCESS) { + if (tsdbOpenDBEnv(&pEnv->dbEnv, aname) != TSDB_CODE_SUCCESS) { + tsdbFreeSmaEnv(pEnv); + return NULL; + } + + if ((pEnv->pPool = openPool()) == NULL) { tsdbFreeSmaEnv(pEnv); return NULL; } @@ -248,7 +389,8 @@ void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv) { taosMemoryFreeClear(pSmaEnv->pStat); taosMemoryFreeClear(pSmaEnv->path); taosThreadRwlockDestroy(&(pSmaEnv->lock)); - tsdbCloseBDBEnv(pSmaEnv->dbEnv); + tsdbCloseDBEnv(pSmaEnv->dbEnv); + closePool(pSmaEnv->pPool); } } @@ -402,7 +544,7 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) { return TSDB_CODE_SUCCESS; }; -static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey) { +static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t indexUid, int64_t winSKey, int64_t version) { SSmaStatItem *pItem = taosHashGet(pItemsHash, &indexUid, sizeof(indexUid)); if (pItem == NULL) { // TODO: use TSDB_SMA_STAT_EXPIRED and update by stream computing later @@ -414,7 +556,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t } // cache smaMeta - STSma *pSma = metaGetSmaInfoByIndex(pTsdb->pMeta, indexUid); + STSma *pSma = metaGetSmaInfoByIndex(pTsdb->pMeta, indexUid, true); if (pSma == NULL) { terrno = TSDB_CODE_TDB_NO_SMA_INDEX_IN_META; taosHashCleanup(pItem->expiredWindows); @@ -436,8 +578,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t return TSDB_CODE_FAILED; } - int8_t state = TSDB_SMA_STAT_EXPIRED; - if (taosHashPut(pItem->expiredWindows, &winSKey, sizeof(TSKEY), &state, sizeof(state)) != 0) { + if (taosHashPut(pItem->expiredWindows, &winSKey, sizeof(TSKEY), &version, sizeof(version)) != 0) { // If error occurs during taosHashPut expired windows, remove the smaIndex from pTsdb->pSmaStat, thus TSDB would // tell query module to query raw TS data. // N.B. @@ -464,7 +605,8 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t * @param msg SSubmitReq * @return int32_t */ -int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg) { +int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t version) { + // no time-range-sma, just return success if (atomic_load_16(&REPO_TSMA_NUM(pTsdb)) <= 0) { tsdbTrace("vgId:%d not update expire window since no tSma", REPO_ID(pTsdb)); return TSDB_CODE_SUCCESS; @@ -479,29 +621,11 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg) { return TSDB_CODE_FAILED; } -// TODO: decode the msg from Stream Computing module => start -#ifdef TSDB_SMA_TESTx - int64_t indexUid = SMA_TEST_INDEX_UID; - const int32_t SMA_TEST_EXPIRED_WINDOW_SIZE = 10; - TSKEY expiredWindows[SMA_TEST_EXPIRED_WINDOW_SIZE]; - TSKEY skey1 = 1646987196 * 1e3; - for (int32_t i = 0; i < SMA_TEST_EXPIRED_WINDOW_SIZE; ++i) { - expiredWindows[i] = skey1 + i; - } -#else - -#endif - // TODO: decode the msg <= end - if (tsdbCheckAndInitSmaEnv(pTsdb, TSDB_SMA_TYPE_TIME_RANGE) != TSDB_CODE_SUCCESS) { terrno = TSDB_CODE_TDB_INIT_FAILED; return TSDB_CODE_FAILED; } -#ifndef TSDB_SMA_TEST - TSKEY expiredWindows[SMA_TEST_EXPIRED_WINDOW_SIZE]; -#endif - // Firstly, assume that tSma can only be created on super table/normal table. // getActiveTimeWindow @@ -562,7 +686,11 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg) { TSKEY winSKey = taosTimeTruncate(TD_ROW_KEY(row), &interval, interval.precision); - tsdbSetExpiredWindow(pTsdb, pItemsHash, pTSma->indexUid, winSKey); + tsdbSetExpiredWindow(pTsdb, pItemsHash, pTSma->indexUid, winSKey, version); + + // TODO: release only when suid changes. + tdDestroyTSmaWrapper(pSW); + taosMemoryFreeClear(pSW); } } @@ -676,10 +804,12 @@ static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit) { * @param dataLen * @return int32_t */ -static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t keyLen, void *pData, uint32_t dataLen) { +static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, int32_t keyLen, void *pData, int32_t dataLen, + TXN *txn) { SDBFile *pDBFile = &pSmaH->dFile; + // TODO: insert sma data blocks into B+Tree(TDB) - if (tsdbSaveSmaToDB(pDBFile, smaKey, keyLen, pData, dataLen) != 0) { + if (tsdbSaveSmaToDB(pDBFile, smaKey, keyLen, pData, dataLen, txn) != 0) { tsdbWarn("vgId:%d insert sma data blocks into %s: smaKey %" PRIx64 "-%" PRIx64 ", dataLen %" PRIu32 " fail", REPO_ID(pSmaH->pTsdb), pDBFile->path, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), dataLen); return TSDB_CODE_FAILED; @@ -826,6 +956,30 @@ static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLe return daysPerFile; } +static int tsdbSmaBeginCommit(SSmaEnv *pEnv) { + TXN *pTxn = &pEnv->txn; + // start a new txn + tdbTxnOpen(pTxn, 0, poolMalloc, poolFree, pEnv->pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED); + if (tdbBegin(pEnv->dbEnv, pTxn) != 0) { + tsdbWarn("tsdbSma tdb begin commit fail"); + return -1; + } + return 0; +} + +static int tsdbSmaEndCommit(SSmaEnv *pEnv) { + TXN *pTxn = &pEnv->txn; + + // Commit current txn + if (tdbCommit(pEnv->dbEnv, pTxn) != 0) { + tsdbWarn("tsdbSma tdb end commit fail"); + return -1; + } + tdbTxnClose(pTxn); + clearPool(pEnv->pPool); + return 0; +} + /** * @brief Insert/Update Time-range-wise SMA data. * - If interval < SMA_STORAGE_SPLIT_HOURS(e.g. 24), save the SMA data as a part of DFileSet to e.g. @@ -841,12 +995,12 @@ static int32_t tsdbGetTSmaDays(STsdb *pTsdb, int64_t interval, int32_t storageLe static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char *msg) { STsdbCfg *pCfg = REPO_CFG(pTsdb); const SArray *pDataBlocks = (const SArray *)msg; - SSmaEnv *pEnv = atomic_load_ptr(&REPO_TSMA_ENV(pTsdb)); - if (pEnv == NULL) { - terrno = TSDB_CODE_INVALID_PTR; - tsdbWarn("vgId:%d insert tSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb)); - return terrno; + // For super table aggregation, the sma data is stored in vgroup calculated from the hash value of stable name. Thus + // the sma data would arrive ahead of the update-expired-window msg. + if (tsdbCheckAndInitSmaEnv(pTsdb, TSDB_SMA_TYPE_TIME_RANGE) != TSDB_CODE_SUCCESS) { + terrno = TSDB_CODE_TDB_INIT_FAILED; + return TSDB_CODE_FAILED; } if (pDataBlocks == NULL) { @@ -861,6 +1015,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char return TSDB_CODE_FAILED; } + SSmaEnv *pEnv = REPO_TSMA_ENV(pTsdb); SSmaStat *pStat = SMA_ENV_STAT(pEnv); SSmaStatItem *pItem = NULL; @@ -911,14 +1066,10 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char int64_t groupId = pDataBlock->info.groupId; for (int32_t j = 0; j < rows; ++j) { printf("|"); - TSKEY skey = 1649295200000; // TSKEY_INITIAL_VAL; // the start key of TS window by interval + TSKEY skey = TSKEY_INITIAL_VAL; // the start key of TS window by interval void *pSmaKey = &smaKey; bool isStartKey = false; - { - // just for debugging - isStartKey = true; - tsdbEncodeTSmaKey(groupId, skey, &pSmaKey); - } + int32_t tlen = 0; // reset the len pDataBuf = &dataBuf; // reset the buf for (int32_t k = 0; k < colNum; ++k) { @@ -929,7 +1080,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char if (!isStartKey) { isStartKey = true; skey = *(TSKEY *)var; - printf("==> skey = %" PRIi64 " groupId = %" PRIi64 "|", skey, groupId); + printf("= skey %" PRIi64 " groupId = %" PRIi64 "|", skey, groupId); tsdbEncodeTSmaKey(groupId, skey, &pSmaKey); } else { printf(" %" PRIi64 " |", *(int64_t *)var); @@ -1010,6 +1161,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char // TODO: tsdbStartTSmaCommit(); if (fid != tSmaH.dFile.fid) { if (tSmaH.dFile.fid != TSDB_IVLD_FID) { + tsdbSmaEndCommit(pEnv); tsdbCloseDBF(&tSmaH.dFile); } tsdbSetTSmaDataFile(&tSmaH, indexUid, fid); @@ -1020,12 +1172,14 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char tsdbUnRefSmaStat(pTsdb, pStat); return TSDB_CODE_FAILED; } + tsdbSmaBeginCommit(pEnv); } - if (tsdbInsertTSmaBlocks(&tSmaH, &smaKey, SMA_KEY_LEN, dataBuf, tlen) != 0) { + if (tsdbInsertTSmaBlocks(&tSmaH, &smaKey, SMA_KEY_LEN, dataBuf, tlen, &pEnv->txn) != 0) { tsdbWarn("vgId:%d insert tSma data blocks fail for index %" PRIi64 ", skey %" PRIi64 ", groupId %" PRIi64 " since %s", REPO_ID(pTsdb), indexUid, skey, groupId, tstrerror(terrno)); + tsdbSmaEndCommit(pEnv); tsdbDestroyTSmaWriteH(&tSmaH); tsdbUnRefSmaStat(pTsdb, pStat); return TSDB_CODE_FAILED; @@ -1044,9 +1198,10 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, int64_t indexUid, const char printf("\n"); } } - + tsdbSmaEndCommit(pEnv); // TODO: not commit for every insert tsdbDestroyTSmaWriteH(&tSmaH); tsdbUnRefSmaStat(pTsdb, pStat); + return TSDB_CODE_SUCCESS; } @@ -1370,8 +1525,8 @@ static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, char *pData, int64_t indexUid, tsdbDebug("vgId:%d get sma data from %s: smaKey %" PRIx64 "-%" PRIx64 ", keyLen %d", REPO_ID(pTsdb), tReadH.dFile.path, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), SMA_KEY_LEN); - void *result = NULL; - uint32_t valueSize = 0; + void *result = NULL; + int32_t valueSize = 0; if ((result = tsdbGetSmaDataByKey(&tReadH.dFile, smaKey, SMA_KEY_LEN, &valueSize)) == NULL) { tsdbWarn("vgId:%d get sma data failed from smaIndex %" PRIi64 ", smaKey %" PRIx64 "-%" PRIx64 " since %s", REPO_ID(pTsdb), indexUid, *(int64_t *)smaKey, *(int64_t *)POINTER_SHIFT(smaKey, 8), tstrerror(terrno)); @@ -1422,7 +1577,7 @@ int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg) { return -1; } tsdbDebug("vgId:%d TDMT_VND_CREATE_SMA msg received for %s:%" PRIi64, REPO_ID(pTsdb), vCreateSmaReq.tSma.indexName, - vCreateSmaReq.tSma.indexUid); + vCreateSmaReq.tSma.indexUid); // record current timezone of server side vCreateSmaReq.tSma.timezoneInt = tsTimezone; @@ -1464,7 +1619,7 @@ int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg) { return -1; } - tsdbTSmaSub(pTsdb, 1); + tsdbTSmaSub(pTsdb, 1); // TODO: return directly or go on follow steps? return TSDB_CODE_SUCCESS; @@ -1515,9 +1670,9 @@ int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg) { return code; } -int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, SSubmitReq *pMsg) { +int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, SSubmitReq *pMsg, int64_t version) { int32_t code = TSDB_CODE_SUCCESS; - if ((code = tsdbUpdateExpiredWindowImpl(pTsdb, pMsg)) < 0) { + if ((code = tsdbUpdateExpiredWindowImpl(pTsdb, pMsg, version)) < 0) { tsdbWarn("vgId:%d update expired sma window failed since %s", REPO_ID(pTsdb), tstrerror(terrno)); } return code; diff --git a/source/dnode/vnode/src/tsdb/tsdbTDBImpl.c b/source/dnode/vnode/src/tsdb/tsdbTDBImpl.c new file mode 100644 index 0000000000000000000000000000000000000000..ebfa1ecaeb7a044f67912c17a4e01400fc69ff2a --- /dev/null +++ b/source/dnode/vnode/src/tsdb/tsdbTDBImpl.c @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define ALLOW_FORBID_FUNC + +#include "vnodeInt.h" + +int32_t tsdbOpenDBEnv(TENV **ppEnv, const char *path) { + int ret = 0; + + if (path == NULL) return -1; + + ret = tdbEnvOpen(path, 4096, 256, ppEnv); // use as param + + if (ret != 0) { + tsdbError("Failed to create tsdb db env, ret = %d", ret); + return -1; + } + + return 0; +} + +int32_t tsdbCloseDBEnv(TENV *pEnv) { return tdbEnvClose(pEnv); } + +static inline int tsdbSmaKeyCmpr(const void *arg1, int len1, const void *arg2, int len2) { + const SSmaKey *pKey1 = (const SSmaKey *)arg1; + const SSmaKey *pKey2 = (const SSmaKey *)arg2; + + ASSERT(len1 == len2 && len1 == sizeof(SSmaKey)); + + if (pKey1->skey < pKey2->skey) { + return -1; + } else if (pKey1->skey > pKey2->skey) { + return 1; + } + if (pKey1->groupId < pKey2->groupId) { + return -1; + } else if (pKey1->groupId > pKey2->groupId) { + return 1; + } + + return 0; +} + +static int32_t tsdbOpenDBDb(TDB **ppDB, TENV *pEnv, const char *pFName) { + int ret; + FKeyComparator compFunc; + + // Create a database + compFunc = tsdbSmaKeyCmpr; + ret = tdbDbOpen(pFName, TDB_VARIANT_LEN, TDB_VARIANT_LEN, compFunc, pEnv, ppDB); + + return 0; +} + +static int32_t tsdbCloseDBDb(TDB *pDB) { return tdbDbClose(pDB); } + +int32_t tsdbOpenDBF(TENV *pEnv, SDBFile *pDBF) { + // TEnv is shared by a group of SDBFile + if (!pEnv || !pDBF) { + terrno = TSDB_CODE_INVALID_PTR; + return -1; + } + + // Open DBF + if (tsdbOpenDBDb(&(pDBF->pDB), pEnv, pDBF->path) < 0) { + terrno = TSDB_CODE_TDB_INIT_FAILED; + tsdbCloseDBDb(pDBF->pDB); + return -1; + } + + return 0; +} + +int32_t tsdbCloseDBF(SDBFile *pDBF) { + int32_t ret = 0; + if (pDBF->pDB) { + ret = tsdbCloseDBDb(pDBF->pDB); + pDBF->pDB = NULL; + } + taosMemoryFreeClear(pDBF->path); + return ret; +} + +int32_t tsdbSaveSmaToDB(SDBFile *pDBF, void *pKey, int32_t keyLen, void *pVal, int32_t valLen, TXN *txn) { + int32_t ret; + + ret = tdbDbInsert(pDBF->pDB, pKey, keyLen, pVal, valLen, txn); + if (ret < 0) { + tsdbError("Failed to create insert sma data into db, ret = %d", ret); + return -1; + } + + return 0; +} + +void *tsdbGetSmaDataByKey(SDBFile *pDBF, const void *pKey, int32_t keyLen, int32_t *valLen) { + void *pVal = NULL; + int ret; + + ret = tdbDbGet(pDBF->pDB, pKey, keyLen, &pVal, valLen); + + if (ret < 0) { + tsdbError("Failed to get sma data from db, ret = %d", ret); + return NULL; + } + + ASSERT(*valLen >= 0); + + // TODO: lock? + // TODO: Would the key/value be destoryed during return the data? + // TODO: How about the key is updated while value length is changed? The original value buffer would be freed + // automatically? + + return pVal; +} \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbWrite.c b/source/dnode/vnode/src/tsdb/tsdbWrite.c index abfcc675eac4df251ecb0da8ace6cfa627754d9a..910b5adc963559f712868937abfe1d5ad160b526 100644 --- a/source/dnode/vnode/src/tsdb/tsdbWrite.c +++ b/source/dnode/vnode/src/tsdb/tsdbWrite.c @@ -31,5 +31,5 @@ int tsdbInsertData(STsdb *pTsdb, SSubmitReq *pMsg, SSubmitRsp *pRsp) { return -1; } } - return tsdbMemTableInsert(pTsdb, pTsdb->mem, pMsg, NULL); + return tsdbMemTableInsert(pTsdb, pTsdb->mem, pMsg, pRsp); } \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeBufferPool2.c b/source/dnode/vnode/src/vnd/vnodeBufferPool2.c new file mode 100644 index 0000000000000000000000000000000000000000..d63c86734a4573112fd449dc8cb23e6a8f91af7e --- /dev/null +++ b/source/dnode/vnode/src/vnd/vnodeBufferPool2.c @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "vnodeInt.h" + +/* ------------------------ STRUCTURES ------------------------ */ + +static int vnodeBufPoolCreate(int size, SVBufPool **ppPool); +static int vnodeBufPoolDestroy(SVBufPool *pPool); + +int vnodeOpenBufPool(SVnode *pVnode, int64_t size) { + SVBufPool *pPool = NULL; + int ret; + + ASSERT(pVnode->pPool == NULL); + + for (int i = 0; i < 3; i++) { + // create pool + ret = vnodeBufPoolCreate(size, &pPool); + if (ret < 0) { + vError("vgId:%d failed to open vnode buffer pool since %s", TD_VNODE_ID(pVnode), tstrerror(terrno)); + vnodeCloseBufPool(pVnode); + return -1; + } + + // add pool to queue + pPool->next = pVnode->pPool; + pVnode->pPool = pPool; + } + + vDebug("vgId:%d vnode buffer pool is opened, pool size: %" PRId64, TD_VNODE_ID(pVnode), size); + + return 0; +} + +int vnodeCloseBufPool(SVnode *pVnode) { + SVBufPool *pPool; + + for (pPool = pVnode->pPool; pPool; pPool = pVnode->pPool) { + pVnode->pPool = pPool->next; + vnodeBufPoolDestroy(pPool); + } + + vDebug("vgId:%d vnode buffer pool is closed", TD_VNODE_ID(pVnode)); + + return 0; +} + +void vnodeBufPoolReset(SVBufPool *pPool) { + SVBufPoolNode *pNode; + + for (pNode = pPool->pTail; pNode->prev; pNode = pPool->pTail) { + ASSERT(pNode->pnext == &pPool->pTail); + pNode->prev->pnext = &pPool->pTail; + pPool->pTail = pNode->prev; + pPool->size = pPool->size - sizeof(*pNode) - pNode->size; + taosMemoryFree(pNode); + } + + ASSERT(pPool->size == pPool->ptr - pPool->node.data); + + pPool->size = 0; + pPool->ptr = pPool->node.data; +} + +void *vnodeBufPoolMalloc(SVBufPool *pPool, size_t size) { + SVBufPoolNode *pNode; + void *p; + + if (pPool->node.size >= pPool->ptr - pPool->node.data + size) { + // allocate from the anchor node + p = pPool->ptr; + pPool->ptr = pPool->ptr + size; + pPool->size += size; + } else { + // allocate a new node + pNode = taosMemoryMalloc(sizeof(*pNode) + size); + if (pNode == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + p = pNode->data; + pNode->size = size; + pNode->prev = pPool->pTail; + pNode->pnext = &pPool->pTail; + pPool->pTail->pnext = &pNode->prev; + pPool->pTail = pNode; + + pPool->size = pPool->size + sizeof(*pNode) + size; + } + + return p; +} + +void vnodeBufPoolFree(SVBufPool *pPool, void *p) { + uint8_t *ptr = (uint8_t *)p; + SVBufPoolNode *pNode; + + if (ptr < pPool->node.data || ptr >= pPool->node.data + pPool->node.size) { + pNode = &((SVBufPoolNode *)p)[-1]; + *pNode->pnext = pNode->prev; + pNode->prev->pnext = pNode->pnext; + + pPool->size = pPool->size - sizeof(*pNode) - pNode->size; + taosMemoryFree(pNode); + } +} + +// STATIC METHODS ------------------- +static int vnodeBufPoolCreate(int size, SVBufPool **ppPool) { + SVBufPool *pPool; + + pPool = taosMemoryMalloc(sizeof(SVBufPool) + size); + if (pPool == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + pPool->next = NULL; + pPool->nRef = 0; + pPool->size = 0; + pPool->ptr = pPool->node.data; + pPool->pTail = &pPool->node; + pPool->node.prev = NULL; + pPool->node.pnext = &pPool->pTail; + pPool->node.size = size; + + *ppPool = pPool; + return 0; +} + +static int vnodeBufPoolDestroy(SVBufPool *pPool) { + vnodeBufPoolReset(pPool); + taosMemoryFree(pPool); + return 0; +} \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeCfg.c b/source/dnode/vnode/src/vnd/vnodeCfg.c index 4a70738e864d7668781e99b1e6c708ee522c4e77..ef417cabc6d7e29959e3b5929527c1fca3688671 100644 --- a/source/dnode/vnode/src/vnd/vnodeCfg.c +++ b/source/dnode/vnode/src/vnd/vnodeCfg.c @@ -18,13 +18,6 @@ const SVnodeCfg defaultVnodeOptions = { .wsize = 96 * 1024 * 1024, .ssize = 1 * 1024 * 1024, .lsize = 1024, .walCfg = {.level = TAOS_WAL_WRITE}}; /* TODO */ -void vnodeOptionsInit(SVnodeCfg *pVnodeOptions) { /* TODO */ - vnodeOptionsCopy(pVnodeOptions, &defaultVnodeOptions); -} - -void vnodeOptionsClear(SVnodeCfg *pVnodeOptions) { /* TODO */ -} - int vnodeValidateOptions(const SVnodeCfg *pVnodeOptions) { // TODO return 0; @@ -36,14 +29,14 @@ void vnodeOptionsCopy(SVnodeCfg *pDest, const SVnodeCfg *pSrc) { int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) { uint32_t hashValue = 0; - + switch (pVnodeOptions->hashMethod) { default: hashValue = MurmurHash3_32(tableFName, strlen(tableFName)); break; } - // TODO OPEN THIS !!!!!!! + // TODO OPEN THIS !!!!!!! #if 0 if (hashValue < pVnodeOptions->hashBegin || hashValue > pVnodeOptions->hashEnd) { terrno = TSDB_CODE_VND_HASH_MISMATCH; @@ -53,5 +46,3 @@ int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) { return TSDB_CODE_SUCCESS; } - - diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index 1235637e198c62d73e2de99b7773406afc9d23af..b4c3725a5e9f402c911f828d21aeb92280006d96 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -24,16 +24,10 @@ int vnodeAsyncCommit(SVnode *pVnode) { vnodeWaitCommit(pVnode); vnodeBufPoolSwitch(pVnode); - SVnodeTask *pTask = (SVnodeTask *)taosMemoryMalloc(sizeof(*pTask)); - - pTask->execute = vnodeCommit; // TODO - pTask->arg = pVnode; // TODO - tsdbPrepareCommit(pVnode->pTsdb); - // metaPrepareCommit(pVnode->pMeta); - // walPreapareCommit(pVnode->pWal); - vnodeScheduleTask(pTask); + vnodeScheduleTask(vnodeCommit, pVnode); + return 0; } diff --git a/source/dnode/vnode/src/vnd/vnodeInt.c b/source/dnode/vnode/src/vnd/vnodeInt.c index 24294c4b58b58478ce0c001134eb22abca71b00b..10d8154a15dc40590648b2d661d6e6068897753e 100644 --- a/source/dnode/vnode/src/vnd/vnodeInt.c +++ b/source/dnode/vnode/src/vnd/vnodeInt.c @@ -14,7 +14,6 @@ */ #define _DEFAULT_SOURCE -#include "sync.h" #include "vnodeInt.h" // #include "vnodeInt.h" @@ -22,25 +21,4 @@ int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg) { return 0; } int32_t vnodeCompact(SVnode *pVnode) { return 0; } -int32_t vnodeSync(SVnode *pVnode) { return 0; } - -int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) { - pLoad->vgId = pVnode->vgId; - pLoad->role = TAOS_SYNC_STATE_LEADER; - pLoad->numOfTables = metaGetTbNum(pVnode->pMeta); - pLoad->numOfTimeSeries = 400; - pLoad->totalStorage = 300; - pLoad->compStorage = 200; - pLoad->pointsWritten = 100; - pLoad->numOfSelectReqs = 1; - pLoad->numOfInsertReqs = 3; - pLoad->numOfInsertSuccessReqs = 2; - pLoad->numOfBatchInsertReqs = 5; - pLoad->numOfBatchInsertSuccessReqs = 4; - return 0; -} - -int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { - /*vInfo("sync message is processed");*/ - return 0; -} +int32_t vnodeSync(SVnode *pVnode) { return 0; } \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeMgr.c b/source/dnode/vnode/src/vnd/vnodeMgr.c deleted file mode 100644 index 40f43bcd12cea110c02b84d295cf2b90df1a1ff8..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/vnd/vnodeMgr.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include "vnodeInt.h" -#include "tglobal.h" - -SVnodeMgr vnodeMgr = {.vnodeInitFlag = TD_MOD_UNINITIALIZED}; - -static void* loop(void* arg); - -int vnodeInit() { - if (TD_CHECK_AND_SET_MODE_INIT(&(vnodeMgr.vnodeInitFlag)) == TD_MOD_INITIALIZED) { - return 0; - } - - vnodeMgr.stop = false; - - // Start commit handers - vnodeMgr.nthreads = tsNumOfCommitThreads; - vnodeMgr.threads = taosMemoryCalloc(vnodeMgr.nthreads, sizeof(TdThread)); - if (vnodeMgr.threads == NULL) { - return -1; - } - - taosThreadMutexInit(&(vnodeMgr.mutex), NULL); - taosThreadCondInit(&(vnodeMgr.hasTask), NULL); - TD_DLIST_INIT(&(vnodeMgr.queue)); - - for (uint16_t i = 0; i < vnodeMgr.nthreads; i++) { - taosThreadCreate(&(vnodeMgr.threads[i]), NULL, loop, NULL); - // pthread_setname_np(vnodeMgr.threads[i], "VND Commit Thread"); - } - - if (walInit() < 0) { - return -1; - } - - return 0; -} - -void vnodeCleanup() { - if (TD_CHECK_AND_SET_MOD_CLEAR(&(vnodeMgr.vnodeInitFlag)) == TD_MOD_UNINITIALIZED) { - return; - } - - // Stop commit handler - taosThreadMutexLock(&(vnodeMgr.mutex)); - vnodeMgr.stop = true; - taosThreadCondBroadcast(&(vnodeMgr.hasTask)); - taosThreadMutexUnlock(&(vnodeMgr.mutex)); - - for (uint16_t i = 0; i < vnodeMgr.nthreads; i++) { - taosThreadJoin(vnodeMgr.threads[i], NULL); - } - - taosMemoryFreeClear(vnodeMgr.threads); - taosThreadCondDestroy(&(vnodeMgr.hasTask)); - taosThreadMutexDestroy(&(vnodeMgr.mutex)); -} - -int vnodeScheduleTask(SVnodeTask* pTask) { - taosThreadMutexLock(&(vnodeMgr.mutex)); - - TD_DLIST_APPEND(&(vnodeMgr.queue), pTask); - - taosThreadCondSignal(&(vnodeMgr.hasTask)); - - taosThreadMutexUnlock(&(vnodeMgr.mutex)); - - return 0; -} - -/* ------------------------ STATIC METHODS ------------------------ */ -static void* loop(void* arg) { - setThreadName("vnode-commit"); - - SVnodeTask* pTask; - for (;;) { - taosThreadMutexLock(&(vnodeMgr.mutex)); - for (;;) { - pTask = TD_DLIST_HEAD(&(vnodeMgr.queue)); - if (pTask == NULL) { - if (vnodeMgr.stop) { - taosThreadMutexUnlock(&(vnodeMgr.mutex)); - return NULL; - } else { - taosThreadCondWait(&(vnodeMgr.hasTask), &(vnodeMgr.mutex)); - } - } else { - TD_DLIST_POP(&(vnodeMgr.queue), pTask); - break; - } - } - - taosThreadMutexUnlock(&(vnodeMgr.mutex)); - - (*(pTask->execute))(pTask->arg); - taosMemoryFree(pTask); - } - - return NULL; -} \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeModule.c b/source/dnode/vnode/src/vnd/vnodeModule.c new file mode 100644 index 0000000000000000000000000000000000000000..2b5b46a45dacc5de5cff0c683ee0767b2ff52807 --- /dev/null +++ b/source/dnode/vnode/src/vnd/vnodeModule.c @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "vnodeInt.h" + +typedef struct SVnodeTask SVnodeTask; +struct SVnodeTask { + SVnodeTask* next; + SVnodeTask* prev; + int (*execute)(void*); + void* arg; +}; + +struct SVnodeGlobal { + int8_t init; + int8_t stop; + int nthreads; + TdThread* threads; + TdThreadMutex mutex; + TdThreadCond hasTask; + SVnodeTask queue; +}; + +struct SVnodeGlobal vnodeGlobal; + +static void* loop(void* arg); + +int vnodeInit(int nthreads) { + int8_t init; + int ret; + + init = atomic_val_compare_exchange_8(&(vnodeGlobal.init), 0, 1); + if (init) { + return 0; + } + + vnodeGlobal.stop = 0; + + vnodeGlobal.queue.next = &vnodeGlobal.queue; + vnodeGlobal.queue.prev = &vnodeGlobal.queue; + + vnodeGlobal.nthreads = nthreads; + vnodeGlobal.threads = taosMemoryCalloc(nthreads, sizeof(TdThread)); + if (vnodeGlobal.threads == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + vError("failed to init vnode module since: %s", tstrerror(terrno)); + return -1; + } + + taosThreadMutexInit(&vnodeGlobal.mutex, NULL); + taosThreadCondInit(&vnodeGlobal.hasTask, NULL); + + for (int i = 0; i < nthreads; i++) { + taosThreadCreate(&(vnodeGlobal.threads[i]), NULL, loop, NULL); + } + + if (walInit() < 0) { + return -1; + } + + return 0; +} + +void vnodeCleanup() { + int8_t init; + + init = atomic_val_compare_exchange_8(&(vnodeGlobal.init), 1, 0); + if (init == 0) return; + + // set stop + taosThreadMutexLock(&(vnodeGlobal.mutex)); + vnodeGlobal.stop = 1; + taosThreadCondBroadcast(&(vnodeGlobal.hasTask)); + taosThreadMutexUnlock(&(vnodeGlobal.mutex)); + + // wait for threads + for (int i = 0; i < vnodeGlobal.nthreads; i++) { + taosThreadJoin(vnodeGlobal.threads[i], NULL); + } + + // clear source + taosMemoryFreeClear(vnodeGlobal.threads); + taosThreadCondDestroy(&(vnodeGlobal.hasTask)); + taosThreadMutexDestroy(&(vnodeGlobal.mutex)); +} + +int vnodeScheduleTask(int (*execute)(void*), void* arg) { + SVnodeTask* pTask; + + ASSERT(!vnodeGlobal.stop); + + pTask = taosMemoryMalloc(sizeof(*pTask)); + if (pTask == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + pTask->execute = execute; + pTask->arg = arg; + + taosThreadMutexLock(&(vnodeGlobal.mutex)); + pTask->next = &vnodeGlobal.queue; + pTask->prev = vnodeGlobal.queue.prev; + vnodeGlobal.queue.prev->next = pTask; + vnodeGlobal.queue.prev = pTask; + taosThreadCondSignal(&(vnodeGlobal.hasTask)); + taosThreadMutexUnlock(&(vnodeGlobal.mutex)); + + return 0; +} + +/* ------------------------ STATIC METHODS ------------------------ */ +static void* loop(void* arg) { + SVnodeTask* pTask; + int ret; + + setThreadName("vnode-commit"); + + for (;;) { + taosThreadMutexLock(&(vnodeGlobal.mutex)); + for (;;) { + pTask = vnodeGlobal.queue.next; + if (pTask == &vnodeGlobal.queue) { + // no task + if (vnodeGlobal.stop) { + taosThreadMutexUnlock(&(vnodeGlobal.mutex)); + return NULL; + } else { + taosThreadCondWait(&(vnodeGlobal.hasTask), &(vnodeGlobal.mutex)); + } + } else { + // has task + pTask->prev->next = pTask->next; + pTask->next->prev = pTask->prev; + break; + } + } + + taosThreadMutexUnlock(&(vnodeGlobal.mutex)); + + pTask->execute(pTask->arg); + taosMemoryFree(pTask); + } + + return NULL; +} \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index f56ded9f15a114e349c4d6dbea39832a3010d2df..75079d50b285ff87bfed713e30d4adf7daba6862 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -13,73 +13,15 @@ * along with this program. If not, see . */ -#include "executor.h" #include "vnodeInt.h" -static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg); -static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg); - int vnodeQueryOpen(SVnode *pVnode) { return qWorkerInit(NODE_TYPE_VNODE, pVnode->vgId, NULL, (void **)&pVnode->pQuery, &pVnode->msgCb); } void vnodeQueryClose(SVnode *pVnode) { qWorkerDestroy((void **)&pVnode->pQuery); } -int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) { - vTrace("message in query queue is processing"); - SReadHandle handle = {.reader = pVnode->pTsdb, .meta = pVnode->pMeta, .config = &pVnode->config}; - - switch (pMsg->msgType) { - case TDMT_VND_QUERY: - return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg); - case TDMT_VND_QUERY_CONTINUE: - return qWorkerProcessCQueryMsg(&handle, pVnode->pQuery, pMsg); - default: - vError("unknown msg type:%d in query queue", pMsg->msgType); - return TSDB_CODE_VND_APP_ERROR; - } -} - -int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { - vTrace("message in fetch queue is processing"); - char *msgstr = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); - int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); - switch (pMsg->msgType) { - case TDMT_VND_FETCH: - return qWorkerProcessFetchMsg(pVnode, pVnode->pQuery, pMsg); - case TDMT_VND_FETCH_RSP: - return qWorkerProcessFetchRsp(pVnode, pVnode->pQuery, pMsg); - case TDMT_VND_RES_READY: - return qWorkerProcessReadyMsg(pVnode, pVnode->pQuery, pMsg); - case TDMT_VND_TASKS_STATUS: - return qWorkerProcessStatusMsg(pVnode, pVnode->pQuery, pMsg); - case TDMT_VND_CANCEL_TASK: - return qWorkerProcessCancelMsg(pVnode, pVnode->pQuery, pMsg); - case TDMT_VND_DROP_TASK: - return qWorkerProcessDropMsg(pVnode, pVnode->pQuery, pMsg); - case TDMT_VND_SHOW_TABLES: - return qWorkerProcessShowMsg(pVnode, pVnode->pQuery, pMsg); - case TDMT_VND_SHOW_TABLES_FETCH: - return vnodeGetTableList(pVnode, pMsg); - // return qWorkerProcessShowFetchMsg(pVnode->pMeta, pVnode->pQuery, pMsg); - case TDMT_VND_TABLE_META: - return vnodeGetTableMeta(pVnode, pMsg); - case TDMT_VND_CONSUME: - return tqProcessPollReq(pVnode->pTq, pMsg, pInfo->workerId); - case TDMT_VND_TASK_PIPE_EXEC: - case TDMT_VND_TASK_MERGE_EXEC: - return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen, 0); - case TDMT_VND_STREAM_TRIGGER: - return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen, 0); - case TDMT_VND_QUERY_HEARTBEAT: - return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg); - default: - vError("unknown msg type:%d in fetch queue", pMsg->msgType); - return TSDB_CODE_VND_APP_ERROR; - } -} - -static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) { +int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) { STbCfg *pTbCfg = NULL; STbCfg *pStbCfg = NULL; tb_uid_t uid; @@ -208,73 +150,18 @@ _exit: return TSDB_CODE_SUCCESS; } -static void freeItemHelper(void *pItem) { - char *p = *(char **)pItem; - taosMemoryFree(p); -} - -/** - * @param pVnode - * @param pMsg - * @param pRsp - */ -static int32_t vnodeGetTableList(SVnode *pVnode, SRpcMsg *pMsg) { - SMTbCursor *pCur = metaOpenTbCursor(pVnode->pMeta); - SArray *pArray = taosArrayInit(10, POINTER_BYTES); - - char *name = NULL; - int32_t totalLen = 0; - int32_t numOfTables = 0; - while ((name = metaTbCursorNext(pCur)) != NULL) { - if (numOfTables < 10000) { // TODO: temp get tables of vnode, and should del when show tables commad ok. - taosArrayPush(pArray, &name); - totalLen += strlen(name); - } else { - taosMemoryFreeClear(name); - } - - numOfTables++; - } - - // TODO: temp debug, and should del when show tables command ok - vInfo("====vgId:%d, numOfTables: %d", pVnode->vgId, numOfTables); - if (numOfTables > 10000) { - numOfTables = 10000; - } - - metaCloseTbCursor(pCur); - - int32_t rowLen = - (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE) + 8 + 2 + (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE) + 8 + 4; - // int32_t numOfTables = (int32_t)taosArrayGetSize(pArray); - - int32_t payloadLen = rowLen * numOfTables; - // SVShowTablesFetchReq *pFetchReq = pMsg->pCont; - - SVShowTablesFetchRsp *pFetchRsp = (SVShowTablesFetchRsp *)rpcMallocCont(sizeof(SVShowTablesFetchRsp) + payloadLen); - memset(pFetchRsp, 0, sizeof(SVShowTablesFetchRsp) + payloadLen); - - char *p = pFetchRsp->data; - for (int32_t i = 0; i < numOfTables; ++i) { - char *n = taosArrayGetP(pArray, i); - STR_TO_VARSTR(p, n); - - p += (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE); - // taosMemoryFree(n); - } - - pFetchRsp->numOfRows = htonl(numOfTables); - pFetchRsp->precision = 0; - - SRpcMsg rpcMsg = { - .handle = pMsg->handle, - .ahandle = pMsg->ahandle, - .pCont = pFetchRsp, - .contLen = sizeof(SVShowTablesFetchRsp) + payloadLen, - .code = 0, - }; - - tmsgSendRsp(&rpcMsg); - taosArrayDestroyEx(pArray, freeItemHelper); +int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) { + pLoad->vgId = pVnode->vgId; + pLoad->role = TAOS_SYNC_STATE_LEADER; + pLoad->numOfTables = metaGetTbNum(pVnode->pMeta); + pLoad->numOfTimeSeries = 400; + pLoad->totalStorage = 300; + pLoad->compStorage = 200; + pLoad->pointsWritten = 100; + pLoad->numOfSelectReqs = 1; + pLoad->numOfInsertReqs = 3; + pLoad->numOfInsertSuccessReqs = 2; + pLoad->numOfBatchInsertReqs = 5; + pLoad->numOfBatchInsertSuccessReqs = 4; return 0; } diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c new file mode 100644 index 0000000000000000000000000000000000000000..395f715b8fd1d7e3ceabcdc11c62242d2d5edce3 --- /dev/null +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -0,0 +1,302 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "vnodeInt.h" + +static int vnodeProcessCreateStbReq(SVnode *pVnode, void *pReq); +static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SRpcMsg **pRsp); +static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq); + +void vnodePreprocessWriteReqs(SVnode *pVnode, SArray *pMsgs) { + SNodeMsg *pMsg; + SRpcMsg *pRpc; + + for (int i = 0; i < taosArrayGetSize(pMsgs); i++) { + pMsg = *(SNodeMsg **)taosArrayGet(pMsgs, i); + pRpc = &pMsg->rpcMsg; + + // set request version + void *pBuf = POINTER_SHIFT(pRpc->pCont, sizeof(SMsgHead)); + int64_t ver = pVnode->state.processed++; + taosEncodeFixedI64(&pBuf, ver); + + if (walWrite(pVnode->pWal, ver, pRpc->msgType, pRpc->pCont, pRpc->contLen) < 0) { + // TODO: handle error + /*ASSERT(false);*/ + vError("vnode:%d write wal error since %s", pVnode->vgId, terrstr()); + } + } + + walFsync(pVnode->pWal, false); +} + +int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { + void *ptr = NULL; + int ret; + + if (pVnode->config.streamMode == 0) { + ptr = vnodeMalloc(pVnode, pMsg->contLen); + if (ptr == NULL) { + // TODO: handle error + } + + // TODO: copy here need to be extended + memcpy(ptr, pMsg->pCont, pMsg->contLen); + } + + // todo: change the interface here + int64_t ver; + taosDecodeFixedI64(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &ver); + if (tqPushMsg(pVnode->pTq, pMsg->pCont, pMsg->contLen, pMsg->msgType, ver) < 0) { + // TODO: handle error + } + + switch (pMsg->msgType) { + case TDMT_VND_CREATE_STB: + ret = vnodeProcessCreateStbReq(pVnode, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))); + return 0; + case TDMT_VND_CREATE_TABLE: + return vnodeProcessCreateTbReq(pVnode, pMsg, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), pRsp); + case TDMT_VND_ALTER_STB: + return vnodeProcessAlterStbReq(pVnode, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))); + case TDMT_VND_DROP_STB: + vTrace("vgId:%d, process drop stb req", pVnode->vgId); + break; + case TDMT_VND_DROP_TABLE: + break; + case TDMT_VND_SUBMIT: + /*printf("vnode %d write data %ld\n", pVnode->vgId, ver);*/ + if (pVnode->config.streamMode == 0) { + if (tsdbInsertData(pVnode->pTsdb, (SSubmitReq *)ptr, NULL) < 0) { + // TODO: handle error + } + } + break; + case TDMT_VND_MQ_SET_CONN: { + if (tqProcessSetConnReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { + // TODO: handle error + } + } break; + case TDMT_VND_MQ_REB: { + if (tqProcessRebReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { + } + } break; + case TDMT_VND_MQ_CANCEL_CONN: { + if (tqProcessCancelConnReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { + } + } break; + case TDMT_VND_TASK_DEPLOY: { + if (tqProcessTaskDeploy(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), + pMsg->contLen - sizeof(SMsgHead)) < 0) { + } + } break; + case TDMT_VND_TASK_WRITE_EXEC: { + if (tqProcessTaskExec(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), pMsg->contLen - sizeof(SMsgHead), + 0) < 0) { + } + } break; + case TDMT_VND_CREATE_SMA: { // timeRangeSMA + + if (tsdbCreateTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { + // TODO + } + // } break; + // case TDMT_VND_CANCEL_SMA: { // timeRangeSMA + // } break; + // case TDMT_VND_DROP_SMA: { // timeRangeSMA + // if (tsdbDropTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { + // // TODO + // } + + } break; + default: + ASSERT(0); + break; + } + + pVnode->state.applied = ver; + + // Check if it needs to commit + if (vnodeShouldCommit(pVnode)) { + // tsem_wait(&(pVnode->canCommit)); + if (vnodeAsyncCommit(pVnode) < 0) { + // TODO: handle error + } + } + + return 0; +} + +int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) { + vTrace("message in query queue is processing"); + SReadHandle handle = {.reader = pVnode->pTsdb, .meta = pVnode->pMeta, .config = &pVnode->config}; + + switch (pMsg->msgType) { + case TDMT_VND_QUERY: + return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg); + case TDMT_VND_QUERY_CONTINUE: + return qWorkerProcessCQueryMsg(&handle, pVnode->pQuery, pMsg); + default: + vError("unknown msg type:%d in query queue", pMsg->msgType); + return TSDB_CODE_VND_APP_ERROR; + } +} + +int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { + vTrace("message in fetch queue is processing"); + char *msgstr = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); + int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); + switch (pMsg->msgType) { + case TDMT_VND_FETCH: + return qWorkerProcessFetchMsg(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_FETCH_RSP: + return qWorkerProcessFetchRsp(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_RES_READY: + return qWorkerProcessReadyMsg(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_TASKS_STATUS: + return qWorkerProcessStatusMsg(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_CANCEL_TASK: + return qWorkerProcessCancelMsg(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_DROP_TASK: + return qWorkerProcessDropMsg(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_TABLE_META: + return vnodeGetTableMeta(pVnode, pMsg); + case TDMT_VND_CONSUME: + return tqProcessPollReq(pVnode->pTq, pMsg, pInfo->workerId); + case TDMT_VND_TASK_PIPE_EXEC: + case TDMT_VND_TASK_MERGE_EXEC: + return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen, 0); + case TDMT_VND_STREAM_TRIGGER: + return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen, 0); + case TDMT_VND_QUERY_HEARTBEAT: + return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg); + default: + vError("unknown msg type:%d in fetch queue", pMsg->msgType); + return TSDB_CODE_VND_APP_ERROR; + } +} + +// TODO: remove the function +void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { + // TODO + + // blockDebugShowData(data); + tsdbInsertTSmaData(((SVnode *)pVnode)->pTsdb, smaId, (const char *)data); +} + +int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { + /*vInfo("sync message is processed");*/ + return 0; +} + +static int vnodeProcessCreateStbReq(SVnode *pVnode, void *pReq) { + SVCreateTbReq vCreateTbReq = {0}; + tDeserializeSVCreateTbReq(pReq, &vCreateTbReq); + if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq)) < 0) { + // TODO + return -1; + } + + taosMemoryFree(vCreateTbReq.stbCfg.pSchema); + taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema); + if (vCreateTbReq.stbCfg.pRSmaParam) { + taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->pFuncIds); + taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam); + } + taosMemoryFree(vCreateTbReq.dbFName); + taosMemoryFree(vCreateTbReq.name); + + return 0; +} + +static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SRpcMsg **pRsp) { + SVCreateTbBatchReq vCreateTbBatchReq = {0}; + SVCreateTbBatchRsp vCreateTbBatchRsp = {0}; + tDeserializeSVCreateTbBatchReq(pReq, &vCreateTbBatchReq); + int reqNum = taosArrayGetSize(vCreateTbBatchReq.pArray); + for (int i = 0; i < reqNum; i++) { + SVCreateTbReq *pCreateTbReq = taosArrayGet(vCreateTbBatchReq.pArray, i); + + char tableFName[TSDB_TABLE_FNAME_LEN]; + SMsgHead *pHead = (SMsgHead *)pMsg->pCont; + sprintf(tableFName, "%s.%s", pCreateTbReq->dbFName, pCreateTbReq->name); + + int32_t code = vnodeValidateTableHash(&pVnode->config, tableFName); + if (code) { + SVCreateTbRsp rsp; + rsp.code = code; + + taosArrayPush(vCreateTbBatchRsp.rspList, &rsp); + } + + if (metaCreateTable(pVnode->pMeta, pCreateTbReq) < 0) { + // TODO: handle error + vError("vgId:%d, failed to create table: %s", pVnode->vgId, pCreateTbReq->name); + } + // TODO: to encapsule a free API + taosMemoryFree(pCreateTbReq->name); + taosMemoryFree(pCreateTbReq->dbFName); + if (pCreateTbReq->type == TD_SUPER_TABLE) { + taosMemoryFree(pCreateTbReq->stbCfg.pSchema); + taosMemoryFree(pCreateTbReq->stbCfg.pTagSchema); + if (pCreateTbReq->stbCfg.pRSmaParam) { + taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam->pFuncIds); + taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam); + } + } else if (pCreateTbReq->type == TD_CHILD_TABLE) { + taosMemoryFree(pCreateTbReq->ctbCfg.pTag); + } else { + taosMemoryFree(pCreateTbReq->ntbCfg.pSchema); + if (pCreateTbReq->ntbCfg.pRSmaParam) { + taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam->pFuncIds); + taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam); + } + } + } + + vTrace("vgId:%d process create %" PRIzu " tables", pVnode->vgId, taosArrayGetSize(vCreateTbBatchReq.pArray)); + taosArrayDestroy(vCreateTbBatchReq.pArray); + if (vCreateTbBatchRsp.rspList) { + int32_t contLen = tSerializeSVCreateTbBatchRsp(NULL, 0, &vCreateTbBatchRsp); + void *msg = rpcMallocCont(contLen); + tSerializeSVCreateTbBatchRsp(msg, contLen, &vCreateTbBatchRsp); + taosArrayDestroy(vCreateTbBatchRsp.rspList); + + *pRsp = taosMemoryCalloc(1, sizeof(SRpcMsg)); + (*pRsp)->msgType = TDMT_VND_CREATE_TABLE_RSP; + (*pRsp)->pCont = msg; + (*pRsp)->contLen = contLen; + (*pRsp)->handle = pMsg->handle; + (*pRsp)->ahandle = pMsg->ahandle; + } + + return 0; +} + +static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq) { + SVCreateTbReq vAlterTbReq = {0}; + vTrace("vgId:%d, process alter stb req", pVnode->vgId); + tDeserializeSVCreateTbReq(pReq, &vAlterTbReq); + // TODO: to encapsule a free API + taosMemoryFree(vAlterTbReq.stbCfg.pSchema); + taosMemoryFree(vAlterTbReq.stbCfg.pTagSchema); + if (vAlterTbReq.stbCfg.pRSmaParam) { + taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam->pFuncIds); + taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam); + } + taosMemoryFree(vAlterTbReq.dbFName); + taosMemoryFree(vAlterTbReq.name); + return 0; +} \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index bf2260c51cbaff653f12468745efa8a9206e69f4..16b881f00d58f27120ccd3fd0ecd229a84d7935b 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -15,277 +15,4 @@ #include "vnodeInt.h" -void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { - // TODO - - // blockDebugShowData(data); - // tsdbInsertTSmaData(((SVnode *)pVnode)->pTsdb, smaId, (const char *)data); -} - -void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { - SNodeMsg *pMsg; - SRpcMsg *pRpc; - - for (int i = 0; i < taosArrayGetSize(pMsgs); i++) { - pMsg = *(SNodeMsg **)taosArrayGet(pMsgs, i); - pRpc = &pMsg->rpcMsg; - - // set request version - void *pBuf = POINTER_SHIFT(pRpc->pCont, sizeof(SMsgHead)); - int64_t ver = pVnode->state.processed++; - taosEncodeFixedI64(&pBuf, ver); - - if (walWrite(pVnode->pWal, ver, pRpc->msgType, pRpc->pCont, pRpc->contLen) < 0) { - // TODO: handle error - /*ASSERT(false);*/ - vError("vnode:%d write wal error since %s", pVnode->vgId, terrstr()); - } - } - - walFsync(pVnode->pWal, false); - - // TODO: Integrate RAFT module here - - // No results are returned because error handling is difficult - // return 0; -} - -int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { - void *ptr = NULL; - - if (pVnode->config.streamMode == 0) { - ptr = vnodeMalloc(pVnode, pMsg->contLen); - if (ptr == NULL) { - // TODO: handle error - } - - // TODO: copy here need to be extended - memcpy(ptr, pMsg->pCont, pMsg->contLen); - } - - // todo: change the interface here - int64_t ver; - taosDecodeFixedI64(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &ver); - if (tqPushMsg(pVnode->pTq, pMsg->pCont, pMsg->contLen, pMsg->msgType, ver) < 0) { - // TODO: handle error - } - - switch (pMsg->msgType) { - case TDMT_VND_CREATE_STB: { - SVCreateTbReq vCreateTbReq = {0}; - tDeserializeSVCreateTbReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateTbReq); - if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq)) < 0) { - // TODO: handle error - } - - // TODO: to encapsule a free API - taosMemoryFree(vCreateTbReq.stbCfg.pSchema); - taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema); - if(vCreateTbReq.stbCfg.pRSmaParam) { - taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->pFuncIds); - taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam); - } - taosMemoryFree(vCreateTbReq.dbFName); - taosMemoryFree(vCreateTbReq.name); - break; - } - case TDMT_VND_CREATE_TABLE: { - SVCreateTbBatchReq vCreateTbBatchReq = {0}; - SVCreateTbBatchRsp vCreateTbBatchRsp = {0}; - tDeserializeSVCreateTbBatchReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateTbBatchReq); - int reqNum = taosArrayGetSize(vCreateTbBatchReq.pArray); - for (int i = 0; i < reqNum; i++) { - SVCreateTbReq *pCreateTbReq = taosArrayGet(vCreateTbBatchReq.pArray, i); - - char tableFName[TSDB_TABLE_FNAME_LEN]; - SMsgHead *pHead = (SMsgHead *)pMsg->pCont; - sprintf(tableFName, "%s.%s", pCreateTbReq->dbFName, pCreateTbReq->name); - - int32_t code = vnodeValidateTableHash(&pVnode->config, tableFName); - if (code) { - SVCreateTbRsp rsp; - rsp.code = code; - - taosArrayPush(vCreateTbBatchRsp.rspList, &rsp); - } - - if (metaCreateTable(pVnode->pMeta, pCreateTbReq) < 0) { - // TODO: handle error - vError("vgId:%d, failed to create table: %s", pVnode->vgId, pCreateTbReq->name); - } - // TODO: to encapsule a free API - taosMemoryFree(pCreateTbReq->name); - taosMemoryFree(pCreateTbReq->dbFName); - if (pCreateTbReq->type == TD_SUPER_TABLE) { - taosMemoryFree(pCreateTbReq->stbCfg.pSchema); - taosMemoryFree(pCreateTbReq->stbCfg.pTagSchema); - if (pCreateTbReq->stbCfg.pRSmaParam) { - taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam->pFuncIds); - taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam); - } - } else if (pCreateTbReq->type == TD_CHILD_TABLE) { - taosMemoryFree(pCreateTbReq->ctbCfg.pTag); - } else { - taosMemoryFree(pCreateTbReq->ntbCfg.pSchema); - if (pCreateTbReq->ntbCfg.pRSmaParam) { - taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam->pFuncIds); - taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam); - } - } - } - - vTrace("vgId:%d process create %" PRIzu " tables", pVnode->vgId, taosArrayGetSize(vCreateTbBatchReq.pArray)); - taosArrayDestroy(vCreateTbBatchReq.pArray); - if (vCreateTbBatchRsp.rspList) { - int32_t contLen = tSerializeSVCreateTbBatchRsp(NULL, 0, &vCreateTbBatchRsp); - void *msg = rpcMallocCont(contLen); - tSerializeSVCreateTbBatchRsp(msg, contLen, &vCreateTbBatchRsp); - taosArrayDestroy(vCreateTbBatchRsp.rspList); - - *pRsp = taosMemoryCalloc(1, sizeof(SRpcMsg)); - (*pRsp)->msgType = TDMT_VND_CREATE_TABLE_RSP; - (*pRsp)->pCont = msg; - (*pRsp)->contLen = contLen; - (*pRsp)->handle = pMsg->handle; - (*pRsp)->ahandle = pMsg->ahandle; - } - break; - } - case TDMT_VND_ALTER_STB: { - SVCreateTbReq vAlterTbReq = {0}; - vTrace("vgId:%d, process alter stb req", pVnode->vgId); - tDeserializeSVCreateTbReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vAlterTbReq); - // TODO: to encapsule a free API - taosMemoryFree(vAlterTbReq.stbCfg.pSchema); - taosMemoryFree(vAlterTbReq.stbCfg.pTagSchema); - if (vAlterTbReq.stbCfg.pRSmaParam) { - taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam->pFuncIds); - taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam); - } - taosMemoryFree(vAlterTbReq.dbFName); - taosMemoryFree(vAlterTbReq.name); - break; - } - case TDMT_VND_DROP_STB: - vTrace("vgId:%d, process drop stb req", pVnode->vgId); - break; - case TDMT_VND_DROP_TABLE: - // if (metaDropTable(pVnode->pMeta, vReq.dtReq.uid) < 0) { - // // TODO: handle error - // } - break; - case TDMT_VND_SUBMIT: - /*printf("vnode %d write data %ld\n", pVnode->vgId, ver);*/ - if (pVnode->config.streamMode == 0) { - if (tsdbInsertData(pVnode->pTsdb, (SSubmitReq *)ptr, NULL) < 0) { - // TODO: handle error - } - } - break; - case TDMT_VND_MQ_SET_CONN: { - if (tqProcessSetConnReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { - // TODO: handle error - } - } break; - case TDMT_VND_MQ_REB: { - if (tqProcessRebReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { - } - } break; - case TDMT_VND_MQ_CANCEL_CONN: { - if (tqProcessCancelConnReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { - } - } break; - case TDMT_VND_TASK_DEPLOY: { - if (tqProcessTaskDeploy(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), - pMsg->contLen - sizeof(SMsgHead)) < 0) { - } - } break; - case TDMT_VND_TASK_WRITE_EXEC: { - if (tqProcessTaskExec(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), pMsg->contLen - sizeof(SMsgHead), - 0) < 0) { - } - } break; - case TDMT_VND_CREATE_SMA: { // timeRangeSMA -#if 0 - - SSmaCfg vCreateSmaReq = {0}; - if (tDeserializeSVCreateTSmaReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateSmaReq) == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - vWarn("vgId:%d TDMT_VND_CREATE_SMA received but deserialize failed since %s", pVnode->config.vgId, - terrstr(terrno)); - return -1; - } - vDebug("vgId:%d TDMT_VND_CREATE_SMA msg received for %s:%" PRIi64, pVnode->config.vgId, - vCreateSmaReq.tSma.indexName, vCreateSmaReq.tSma.indexUid); - - // record current timezone of server side - vCreateSmaReq.tSma.timezoneInt = tsTimezone; - - if (metaCreateTSma(pVnode->pMeta, &vCreateSmaReq) < 0) { - // TODO: handle error - tdDestroyTSma(&vCreateSmaReq.tSma); - return -1; - } - - tsdbTSmaAdd(pVnode->pTsdb, 1); - - tdDestroyTSma(&vCreateSmaReq.tSma); - // TODO: return directly or go on follow steps? -#endif - // if (tsdbCreateTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { - // // TODO - // } - // } break; - // case TDMT_VND_CANCEL_SMA: { // timeRangeSMA - // } break; - // case TDMT_VND_DROP_SMA: { // timeRangeSMA - // if (tsdbDropTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { - // // TODO - // } -#if 0 - tsdbTSmaSub(pVnode->pTsdb, 1); - SVDropTSmaReq vDropSmaReq = {0}; - if (tDeserializeSVDropTSmaReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vDropSmaReq) == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - // TODO: send msg to stream computing to drop tSma - // if ((send msg to stream computing) < 0) { - // tdDestroyTSma(&vCreateSmaReq); - // return -1; - // } - // - - if (metaDropTSma(pVnode->pMeta, vDropSmaReq.indexUid) < 0) { - // TODO: handle error - return -1; - } - - if(tsdbDropTSmaData(pVnode->pTsdb, vDropSmaReq.indexUid) < 0) { - // TODO: handle error - return -1; - } - - // TODO: return directly or go on follow steps? -#endif - } break; - default: - ASSERT(0); - break; - } - - pVnode->state.applied = ver; - - // Check if it needs to commit - if (vnodeShouldCommit(pVnode)) { - // tsem_wait(&(pVnode->canCommit)); - if (vnodeAsyncCommit(pVnode) < 0) { - // TODO: handle error - } - } - - return 0; -} - /* ------------------------ STATIC METHODS ------------------------ */ diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index 6a4adfe4f8e33dfdc0f2c421af28beed783442f1..b0217a046280abb37065005d90d4cb5d70806fba 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -210,7 +210,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { // get value by indexName STSma *qSmaCfg = NULL; - qSmaCfg = metaGetSmaInfoByIndex(pMeta, indexUid1); + qSmaCfg = metaGetSmaInfoByIndex(pMeta, indexUid1, true); assert(qSmaCfg != NULL); printf("name1 = %s\n", qSmaCfg->indexName); printf("timezone1 = %" PRIi8 "\n", qSmaCfg->timezoneInt); @@ -221,7 +221,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { tdDestroyTSma(qSmaCfg); taosMemoryFreeClear(qSmaCfg); - qSmaCfg = metaGetSmaInfoByIndex(pMeta, indexUid2); + qSmaCfg = metaGetSmaInfoByIndex(pMeta, indexUid2, true); assert(qSmaCfg != NULL); printf("name2 = %s\n", qSmaCfg->indexName); printf("timezone2 = %" PRIi8 "\n", qSmaCfg->timezoneInt); @@ -233,11 +233,12 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { taosMemoryFreeClear(qSmaCfg); // get index name by table uid +#if 0 SMSmaCursor *pSmaCur = metaOpenSmaCursor(pMeta, tbUid); assert(pSmaCur != NULL); uint32_t indexCnt = 0; while (1) { - const char *indexName = metaSmaCursorNext(pSmaCur); + const char *indexName = (const char *)metaSmaCursorNext(pSmaCur); if (indexName == NULL) { break; } @@ -245,8 +246,8 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) { ++indexCnt; } EXPECT_EQ(indexCnt, nCntTSma); - metaCloseSmaCurosr(pSmaCur); - + metaCloseSmaCursor(pSmaCur); +#endif // get wrapper by table uid STSmaWrapper *pSW = metaGetSmaInfoByTable(pMeta, tbUid); assert(pSW != NULL); @@ -408,7 +409,7 @@ TEST(testCase, tSma_Data_Insert_Query_Test) { EXPECT_EQ(tdScanAndConvertSubmitMsg(pMsg), TSDB_CODE_SUCCESS); - EXPECT_EQ(tsdbUpdateSmaWindow(pTsdb, pMsg), 0); + EXPECT_EQ(tsdbUpdateSmaWindow(pTsdb, pMsg, 0), 0); // init const int32_t tSmaGroupSize = 4; diff --git a/source/libs/command/inc/commandInt.h b/source/libs/command/inc/commandInt.h index 23e4f2b24f725860c3aef2ae11cfb7a7bed0331d..452804ac91c8a92527b3fc596d8aa631ca184c33 100644 --- a/source/libs/command/inc/commandInt.h +++ b/source/libs/command/inc/commandInt.h @@ -44,6 +44,9 @@ extern "C" { #define EXPLAIN_OUTPUT_FORMAT "Output: " #define EXPLAIN_TIME_WINDOWS_FORMAT "Time Window: interval=%" PRId64 "%c offset=%" PRId64 "%c sliding=%" PRId64 "%c" #define EXPLAIN_WINDOW_FORMAT "Window: gap=%" PRId64 +#define EXPLAIN_RATIO_TIME_FORMAT "Ratio: %f" +#define EXPLAIN_PLANNING_TIME_FORMAT "Planning Time: %.3f ms" +#define EXPLAIN_EXEC_TIME_FORMAT "Execution Time: %.3f ms" //append area #define EXPLAIN_LEFT_PARENTHESIS_FORMAT " (" @@ -108,16 +111,19 @@ typedef struct SExplainCtx { #define EXPLAIN_ROW_NEW(level, ...) \ do { \ if (isVerboseLine) { \ - tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, "%*s", (level) * 2 + 3, ""); \ + tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE, "%*s", (level) * 2 + 3, ""); \ } else { \ - tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE, "%*s%s", (level) * 2, "", "-> "); \ + tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE, "%*s%s", (level) * 2, "", "-> "); \ } \ - tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - tlen, __VA_ARGS__); \ + tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE - tlen, __VA_ARGS__); \ } while (0) -#define EXPLAIN_ROW_APPEND(...) tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - tlen, __VA_ARGS__) +#define EXPLAIN_ROW_APPEND(...) tlen += snprintf(tbuf + VARSTR_HEADER_SIZE + tlen, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE - tlen, __VA_ARGS__) #define EXPLAIN_ROW_END() do { varDataSetLen(tbuf, tlen); tlen += VARSTR_HEADER_SIZE; isVerboseLine = true; } while (0) +#define EXPLAIN_SUM_ROW_NEW(...) tlen = snprintf(tbuf + VARSTR_HEADER_SIZE, TSDB_EXPLAIN_RESULT_ROW_SIZE - VARSTR_HEADER_SIZE, __VA_ARGS__) +#define EXPLAIN_SUM_ROW_END() do { varDataSetLen(tbuf, tlen); tlen += VARSTR_HEADER_SIZE; } while (0) + #ifdef __cplusplus } #endif diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 605d8f41da85209f5b1450f3912af8da60655884..e08e9cf276e24d010a1bd4432e86cc6132942a35 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -52,16 +52,14 @@ void qExplainFreeCtx(SExplainCtx *pCtx) { void *pIter = taosHashIterate(pCtx->groupHash, NULL); while (pIter) { SExplainGroup *group = (SExplainGroup *)pIter; - if (NULL == group->nodeExecInfo) { - continue; + if (group->nodeExecInfo) { + int32_t num = taosArrayGetSize(group->nodeExecInfo); + for (int32_t i = 0; i < num; ++i) { + SExplainRsp *rsp = taosArrayGet(group->nodeExecInfo, i); + taosMemoryFreeClear(rsp->subplanInfo); + } } - int32_t num = taosArrayGetSize(group->nodeExecInfo); - for (int32_t i = 0; i < num; ++i) { - SExplainRsp *rsp = taosArrayGet(group->nodeExecInfo, i); - taosMemoryFreeClear(rsp->subplanInfo); - } - pIter = taosHashIterate(pCtx->groupHash, pIter); } } @@ -641,7 +639,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i } case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:{ SIntervalPhysiNode *pIntNode = (SIntervalPhysiNode *)pNode; - EXPLAIN_ROW_NEW(level, EXPLAIN_INTERVAL_FORMAT, nodesGetNameFromColumnNode(pIntNode->pTspk)); + EXPLAIN_ROW_NEW(level, EXPLAIN_INTERVAL_FORMAT, nodesGetNameFromColumnNode(pIntNode->window.pTspk)); EXPLAIN_ROW_APPEND(EXPLAIN_LEFT_PARENTHESIS_FORMAT); if (pResNode->pExecInfo) { QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); @@ -896,9 +894,33 @@ _return: QRY_RET(code); } +int32_t qExplainAppendPlanRows(SExplainCtx *pCtx) { + if (EXPLAIN_MODE_ANALYZE != pCtx->mode) { + return TSDB_CODE_SUCCESS; + } + + int32_t tlen = 0; + char *tbuf = pCtx->tbuf; + + EXPLAIN_SUM_ROW_NEW(EXPLAIN_RATIO_TIME_FORMAT, pCtx->ratio); + EXPLAIN_SUM_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(pCtx, tbuf, tlen, 0)); + + EXPLAIN_SUM_ROW_NEW(EXPLAIN_PLANNING_TIME_FORMAT, (double)(pCtx->jobStartTs - pCtx->reqStartTs) / 1000.0); + EXPLAIN_SUM_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(pCtx, tbuf, tlen, 0)); + + EXPLAIN_SUM_ROW_NEW(EXPLAIN_EXEC_TIME_FORMAT, (double)(pCtx->jobDoneTs - pCtx->jobStartTs) / 1000.0); + EXPLAIN_SUM_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(pCtx, tbuf, tlen, 0)); + + return TSDB_CODE_SUCCESS; +} int32_t qExplainGenerateRsp(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp) { QRY_ERR_RET(qExplainAppendGroupResRows(pCtx, pCtx->rootGroupId, 0)); + + QRY_ERR_RET(qExplainAppendPlanRows(pCtx)); QRY_ERR_RET(qExplainGetRspFromCtx(pCtx, pRsp)); @@ -979,18 +1001,18 @@ _return: QRY_RET(code); } -int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int32_t startTs) { +int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs) { QRY_ERR_RET(qExplainPrepareCtx(pDag, pCtx)); (*pCtx)->reqStartTs = startTs; - (*pCtx)->jobStartTs = taosGetTimestampMs(); + (*pCtx)->jobStartTs = taosGetTimestampUs(); return TSDB_CODE_SUCCESS; } int32_t qExecExplainEnd(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp) { int32_t code = 0; - pCtx->jobDoneTs = taosGetTimestampMs(); + pCtx->jobDoneTs = taosGetTimestampUs(); atomic_store_8((int8_t *)&pCtx->execDone, true); diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 32a5140da2526c3bcd266aea4ed73ba5b689f0c4..cbd2dc66f5f9dfa8e2c7219ab2a67e659ec3779f 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -48,8 +48,6 @@ typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int #define GET_TABLEGROUP(q, _index) ((SArray*)taosArrayGetP((q)->tableqinfoGroupInfo.pGroupList, (_index))) -#define GET_NUM_OF_RESULTS(_r) (((_r)->outputBuf) == NULL ? 0 : ((_r)->outputBuf)->info.rows) - #define NEEDTO_COMPRESS_QUERY(size) ((size) > tsCompressColData ? 1 : 0) enum { @@ -84,21 +82,6 @@ typedef struct SResultInfo { // TODO refactor int32_t threshold; // result size threshold in rows. } SResultInfo; -typedef struct SColumnFilterElem { - int16_t bytes; // column length - __filter_func_t fp; - SColumnFilterInfo filterInfo; - void* q; -} SColumnFilterElem; - -typedef struct SSingleColumnFilterInfo { - void* pData; - void* pData2; // used for nchar column - int32_t numOfFilters; - SColumnInfo info; - SColumnFilterElem* pFilters; -} SSingleColumnFilterInfo; - typedef struct STableQueryInfo { TSKEY lastKey; // last check ts uint64_t uid; // table uid @@ -169,72 +152,44 @@ typedef struct SOperatorCostInfo { uint64_t totalCost; } SOperatorCostInfo; -typedef struct SOrder { - uint32_t order; - SColumn col; -} SOrder; - // The basic query information extracted from the SQueryInfo tree to support the // execution of query in a data node. typedef struct STaskAttr { - SLimit limit; - SLimit slimit; - - // todo comment it - bool stableQuery; // super table query or not - bool topBotQuery; // TODO used bitwise flag - bool groupbyColumn; // denote if this is a groupby normal column query - bool hasTagResults; // if there are tag values in final result or not - bool timeWindowInterpo; // if the time window start/end required interpolation - bool queryBlockDist; // if query data block distribution - bool stabledev; // super table stddev query - bool tsCompQuery; // is tscomp query - bool diffQuery; // is diff query - bool simpleAgg; - bool pointInterpQuery; // point interpolation query - bool needReverseScan; // need reverse scan - bool distinct; // distinct query or not - bool stateWindow; // window State on sub/normal table - bool createFilterOperator; // if filter operator is needed - bool multigroupResult; // multigroup result can exist in one SSDataBlock - int32_t interBufSize; // intermediate buffer sizse - - int32_t havingNum; // having expr number - - SOrder order; - int16_t numOfCols; - int16_t numOfTags; - - STimeWindow window; - SInterval interval; - int16_t precision; - int16_t numOfOutput; - int16_t fillType; - - int32_t srcRowSize; // todo extract struct - int32_t resultRowSize; - int32_t intermediateResultRowSize; // intermediate result row size, in case of top-k query. - int32_t maxTableColumnWidth; - int32_t tagLen; // tag value length of current query - - SExprInfo* pExpr1; - - SColumnInfo* tableCols; - SColumnInfo* tagColList; - int32_t numOfFilterCols; - int64_t* fillVal; - - SSingleColumnFilterInfo* pFilterInfo; + SLimit limit; + SLimit slimit; + bool stableQuery; // super table query or not + bool topBotQuery; // TODO used bitwise flag + bool groupbyColumn; // denote if this is a groupby normal column query + bool timeWindowInterpo; // if the time window start/end required interpolation + bool tsCompQuery; // is tscomp query + bool diffQuery; // is diff query + bool pointInterpQuery; // point interpolation query + int32_t havingNum; // having expr number + int16_t numOfCols; + int16_t numOfTags; + STimeWindow window; + SInterval interval; + int16_t precision; + int16_t numOfOutput; + int16_t fillType; + int32_t resultRowSize; + int32_t tagLen; // tag value length of current query + + SExprInfo *pExpr1; + SColumnInfo* tagColList; + int32_t numOfFilterCols; + int64_t* fillVal; void* tsdb; STableGroupInfo tableGroupInfo; // table list SArray int32_t vgId; - SArray* pUdfInfo; // no need to free } STaskAttr; struct SOperatorInfo; +struct SAggSupporter; +struct SOptrBasicInfo; -typedef void (*__optr_encode_fn_t)(struct SOperatorInfo* pOperator, char **result, int32_t *length); -typedef bool (*__optr_decode_fn_t)(struct SOperatorInfo* pOperator, char *result, int32_t length); +typedef void (*__optr_encode_fn_t)(struct SOperatorInfo* pOperator, struct SAggSupporter *pSup, struct SOptrBasicInfo *pInfo, char **result, int32_t *length); +typedef bool (*__optr_decode_fn_t)(struct SOperatorInfo* pOperator, struct SAggSupporter *pSup, struct SOptrBasicInfo *pInfo, char *result, int32_t length); typedef int32_t (*__optr_open_fn_t)(struct SOperatorInfo* pOptr); typedef SSDataBlock* (*__optr_fn_t)(struct SOperatorInfo* pOptr, bool* newgroup); @@ -250,7 +205,6 @@ typedef struct STaskIdInfo { typedef struct SExecTaskInfo { STaskIdInfo id; - char* content; uint32_t status; STimeWindow window; STaskCostInfo cost; @@ -260,7 +214,7 @@ typedef struct SExecTaskInfo { STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray structure char* sql; // query sql string jmp_buf env; // jump to this position when error happens. - EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model] + EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model] struct SOperatorInfo* pRoot; } SExecTaskInfo; @@ -295,7 +249,7 @@ typedef struct STaskRuntimeEnv { int64_t currentOffset; // dynamic offset value STableQueryInfo* current; - SResultInfo resultInfo; + SResultInfo resultInfo; SHashObj* pTableRetrieveTsMap; struct SUdfInfo* pUdfInfo; } STaskRuntimeEnv; @@ -337,25 +291,6 @@ typedef struct { SColumnInfo* colList; } SQueriedTableInfo; -typedef struct SQInfo { - void* signature; - uint64_t qId; - int32_t code; // error code to returned to client - int64_t owner; // if it is in execution - - STaskRuntimeEnv runtimeEnv; - STaskAttr query; - void* pBuf; // allocated buffer for STableQueryInfo, sizeof(STableQueryInfo)*numOfTables; - - TdThreadMutex lock; // used to synchronize the rsp/query threads - tsem_t ready; - int32_t dataReady; // denote if query result is ready or not - void* rspContext; // response context - int64_t startExecTs; // start to exec timestamp - char* sql; // query sql string - STaskCostInfo summary; -} SQInfo; - typedef enum { EX_SOURCE_DATA_NOT_READY = 0x1, EX_SOURCE_DATA_READY = 0x2, @@ -409,7 +344,7 @@ typedef struct STableScanInfo { SResultRowInfo* pResultRowInfo; int32_t* rowCellInfoOffset; SExprInfo* pExpr; - SSDataBlock block; + SSDataBlock* pResBlock; SArray* pColMatchInfo; int32_t numOfOutput; int64_t elapsedTime; @@ -449,13 +384,13 @@ typedef struct SSysTableScanInfo { int32_t accountId; bool showRewrite; - SNode* pCondition; // db_name filter condition, to discard data that are not in current database + SNode *pCondition; // db_name filter condition, to discard data that are not in current database void *pCur; // cursor for iterate the local table meta store. SArray *scanCols; // SArray scan column id list int32_t type; // show type, TODO remove it SName name; - SSDataBlock* pRes; + SSDataBlock *pRes; int32_t capacity; int64_t numOfBlocks; // extract basic running information. SLoadRemoteDataInfo loadInfo; @@ -521,24 +456,6 @@ typedef struct SProjectOperatorInfo { int64_t curOutput; } SProjectOperatorInfo; -typedef struct SSLimitOperatorInfo { - int64_t groupTotal; - int64_t currentGroupOffset; - int64_t rowsTotal; - int64_t currentOffset; - SLimit limit; - SLimit slimit; - char** prevRow; - SArray* orderColumnList; - bool hasPrev; - bool ignoreCurrentGroup; - bool multigroupResult; - SSDataBlock* pRes; // result buffer - SSDataBlock* pPrevBlock; - int64_t capacity; - int64_t threshold; -} SSLimitOperatorInfo; - typedef struct SFillOperatorInfo { struct SFillInfo* pFillInfo; SSDataBlock* pRes; @@ -551,10 +468,10 @@ typedef struct SFillOperatorInfo { } SFillOperatorInfo; typedef struct { - char *pData; - bool isNull; - int16_t type; - int32_t bytes; + char *pData; + bool isNull; + int16_t type; + int32_t bytes; } SGroupKeys, SStateKeys; typedef struct SGroupbyOperatorInfo { @@ -567,6 +484,9 @@ typedef struct SGroupbyOperatorInfo { int32_t groupKeyLen; // total group by column width SGroupResInfo groupResInfo; SAggSupporter aggSup; + SExprInfo* pScalarExprInfo; + int32_t numOfScalarExpr;// the number of scalar expression in group operator + SqlFunctionCtx*pScalarFuncCtx; } SGroupbyOperatorInfo; typedef struct SDataGroupInfo { @@ -577,19 +497,19 @@ typedef struct SDataGroupInfo { // The sort in partition may be needed later. typedef struct SPartitionOperatorInfo { - SOptrBasicInfo binfo; - SArray* pGroupCols; - SArray* pGroupColVals; // current group column values, SArray - char* keyBuf; // group by keys for hash - int32_t groupKeyLen; // total group by column width - SHashObj* pGroupSet; // quick locate the window object for each result - - SDiskbasedBuf* pBuf; // query result buffer based on blocked-wised disk file - int32_t rowCapacity; // maximum number of rows for each buffer page - int32_t* columnOffset; // start position for each column data - - void* pGroupIter; // group iterator - int32_t pageIndex; // page index of current group + SOptrBasicInfo binfo; + SArray* pGroupCols; + SArray* pGroupColVals; // current group column values, SArray + char* keyBuf; // group by keys for hash + int32_t groupKeyLen; // total group by column width + SHashObj* pGroupSet; // quick locate the window object for each result + + SDiskbasedBuf* pBuf; // query result buffer based on blocked-wised disk file + int32_t rowCapacity; // maximum number of rows for each buffer page + int32_t* columnOffset; // start position for each column data + + void* pGroupIter; // group iterator + int32_t pageIndex; // page index of current group } SPartitionOperatorInfo; typedef struct SWindowRowsSup { @@ -609,6 +529,12 @@ typedef struct SSessionAggOperatorInfo { SColumnInfoData timeWindowData; // query time window info for scalar function execution. } SSessionAggOperatorInfo; +typedef struct STimeSliceOperatorInfo { + SOptrBasicInfo binfo; + SInterval interval; + SGroupResInfo groupResInfo; // multiple results build supporter +} STimeSliceOperatorInfo; + typedef struct SStateWindowOperatorInfo { SOptrBasicInfo binfo; SAggSupporter aggSup; @@ -622,26 +548,21 @@ typedef struct SStateWindowOperatorInfo { } SStateWindowOperatorInfo; typedef struct SSortedMergeOperatorInfo { - SOptrBasicInfo binfo; - bool hasVarCol; + SOptrBasicInfo binfo; + bool hasVarCol; - SArray* pSortInfo; - int32_t numOfSources; - - SSortHandle *pSortHandle; - - int32_t bufPageSize; - uint32_t sortBufSize; // max buffer size for in-memory sort - - int32_t resultRowFactor; - bool hasGroupVal; - - SDiskbasedBuf *pTupleStore; // keep the final results - int32_t numOfResPerPage; - - char** groupVal; - SArray *groupInfo; - SAggSupporter aggSup; + SArray* pSortInfo; + int32_t numOfSources; + SSortHandle *pSortHandle; + int32_t bufPageSize; + uint32_t sortBufSize; // max buffer size for in-memory sort + int32_t resultRowFactor; + bool hasGroupVal; + SDiskbasedBuf *pTupleStore; // keep the final results + int32_t numOfResPerPage; + char** groupVal; + SArray *groupInfo; + SAggSupporter aggSup; } SSortedMergeOperatorInfo; typedef struct SSortOperatorInfo { @@ -665,24 +586,22 @@ int32_t operatorDummyOpenFn(SOperatorInfo* pOperator); void operatorDummyCloseFn(void* param, int32_t numOfCols); int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t num); int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, - int32_t numOfRows, SSDataBlock* pResultBlock, const char* pkey); -void toSDatablock(SGroupResInfo* pGroupResInfo, SDiskbasedBuf* pBuf, SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset); + int32_t numOfRows, SSDataBlock* pResultBlock, size_t keyBufSize, const char* pkey); +void toSDatablock(SSDataBlock* pBlock, int32_t rowCapacity, SGroupResInfo* pGroupResInfo, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, int32_t* rowCellOffset); void finalizeMultiTupleQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int32_t* rowCellInfoOffset); void doApplyFunctions(SqlFunctionCtx* pCtx, STimeWindow* pWin, SColumnInfoData* pTimeWindowData, int32_t offset, int32_t forwardStep, TSKEY* tsCol, int32_t numOfTotal, int32_t numOfOutput, int32_t order); -int32_t setGroupResultOutputBuf_rv(SOptrBasicInfo* binfo, int32_t numOfCols, char* pData, int16_t type, - int16_t bytes, int32_t groupId, SDiskbasedBuf* pBuf, SExecTaskInfo* pTaskInfo, SAggSupporter* pAggSup); +int32_t setGroupResultOutputBuf(SOptrBasicInfo* binfo, int32_t numOfCols, char* pData, int16_t type, int16_t bytes, int32_t groupId, SDiskbasedBuf* pBuf, SExecTaskInfo* pTaskInfo, SAggSupporter* pAggSup); void doDestroyBasicInfo(SOptrBasicInfo* pInfo, int32_t numOfOutput); int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadInfo, int32_t numOfRows, char* pData, int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total, SArray* pColList); void doSetOperatorCompleted(SOperatorInfo* pOperator); void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock); -SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity); -SSDataBlock* loadNextDataBlock(void* param); +SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset); SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo); SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfCols, int32_t repeatTime, - int32_t reverseTime, SArray* pColMatchInfo, SNode* pCondition, SExecTaskInfo* pTaskInfo); + int32_t reverseTime, SArray* pColMatchInfo, SSDataBlock* pResBlock, SNode* pCondition, SExecTaskInfo* pTaskInfo); SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); @@ -696,8 +615,8 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlot, const STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo); SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, int64_t gap, SExecTaskInfo* pTaskInfo); -SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, - SArray* pGroupColList, SNode* pCondition, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); +SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList, + SNode* pCondition, SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo* pTaskInfo); SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* pResBlock, SArray* pColList, SArray* pTableIdList, SExecTaskInfo* pTaskInfo); @@ -707,21 +626,22 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); +SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo); + #if 0 SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv); -SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, - SExprInfo* pExpr, int32_t numOfOutput); - SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput); -SOperatorInfo* createTagScanOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SExprInfo* pExpr, int32_t numOfOutput); +SOperatorInfo* createTagScanOperatorInfo(SReaderHandle* pReaderHandle, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pdownstream, int32_t numOfDownstream, SSchema* pSchema, int32_t numOfOutput); #endif +void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx, int32_t numOfOutput, SArray* pPseudoList); + void setInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order); void finalizeQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput); @@ -737,7 +657,6 @@ void setTaskKilled(SExecTaskInfo* pTaskInfo); void publishOperatorProfEvent(SOperatorInfo* operatorInfo, EQueryProfEventType eventType); void publishQueryAbortEvent(SExecTaskInfo* pTaskInfo, int32_t code); -void calculateOperatorProfResults(SQInfo* pQInfo); void queryCostStatis(SExecTaskInfo* pTaskInfo); void doDestroyTask(SExecTaskInfo* pTaskInfo); @@ -748,6 +667,9 @@ void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status); int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId, EOPTR_EXEC_MODEL model); int32_t getOperatorExplainExecInfo(SOperatorInfo *operatorInfo, SExplainExecInfo **pRes, int32_t *capacity, int32_t *resNum); +bool aggDecodeResultRow(SOperatorInfo* pOperator, SAggSupporter *pSup, SOptrBasicInfo *pInfo, char* result, int32_t length); +void aggEncodeResultRow(SOperatorInfo* pOperator, SAggSupporter *pSup, SOptrBasicInfo *pInfo, char **result, int32_t *length); + #ifdef __cplusplus } #endif diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index 1edebcd7db5168446fbe9c901d084d031703405f..e897bc8892e594368cc8a1b1d9a0f33d91f03c46 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -92,9 +92,7 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput, return false; } - // NOTE: there are four bytes of an integer more than the required buffer space. - // struct size + data payload + length for each column + bitmap length - pBuf->allocSize = sizeof(SRetrieveTableRsp) + blockDataGetSerialMetaSize(pInput->pData) + blockDataGetSize(pInput->pData); + pBuf->allocSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pInput->pData); pBuf->pData = taosMemoryMalloc(pBuf->allocSize); if (pBuf->pData == NULL) { diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 40e86c7840c43dccc801fe9117bb7273ad6ce461..1377b2f72916b9bb60acbf52ba0a329b23500795 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -337,11 +337,11 @@ int32_t tsDescOrder(const void* p1, const void* p2) { void orderTheResultRows(STaskRuntimeEnv* pRuntimeEnv) { __compar_fn_t fn = NULL; - if (pRuntimeEnv->pQueryAttr->order.order == TSDB_ORDER_ASC) { - fn = tsAscOrder; - } else { - fn = tsDescOrder; - } +// if (pRuntimeEnv->pQueryAttr->order.order == TSDB_ORDER_ASC) { +// fn = tsAscOrder; +// } else { +// fn = tsDescOrder; +// } taosArraySort(pRuntimeEnv->pResultRowArrayList, fn); } @@ -377,7 +377,7 @@ static int32_t mergeIntoGroupResultImplRv(STaskRuntimeEnv *pRuntimeEnv, SGroupRe static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv, SGroupResInfo* pGroupResInfo, SArray *pTableList, int32_t* rowCellInfoOffset) { - bool ascQuery = QUERY_IS_ASC_QUERY(pRuntimeEnv->pQueryAttr); + bool ascQuery = true; int32_t code = TSDB_CODE_SUCCESS; @@ -413,7 +413,8 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv goto _end; } - SCompSupporter cs = {pTableQueryInfoList, posList, pRuntimeEnv->pQueryAttr->order.order}; + int32_t order = TSDB_ORDER_ASC; + SCompSupporter cs = {pTableQueryInfoList, posList, order}; int32_t ret = tMergeTreeCreate(&pTree, numOfTables, &cs, tableResultComparFn); if (ret != TSDB_CODE_SUCCESS) { diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index 15203d91cafc3611fd316c91db8f0f4a895cfb02..4af7e563e6eb85dceae04be58c069c5087060b49 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -52,7 +52,7 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu for (int32_t i = 0; i < numOfBlocks; ++i) { SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i]; - SSDataBlock* p = createOneDataBlock(pDataBlock); + SSDataBlock* p = createOneDataBlock(pDataBlock, false); p->info = pDataBlock->info; taosArrayClear(p->pDataBlock); diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index ee5c6759890d8691c4025755d83705eed6fbf342..14acff320418e68602a20842333c4865f55bffb6 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -173,12 +173,12 @@ static void getNextTimeWindow(SInterval* pInterval, int32_t precision, int32_t o int mon = (int)(tm.tm_year * 12 + tm.tm_mon + interval * factor); tm.tm_year = mon / 12; tm.tm_mon = mon % 12; - tw->skey = convertTimePrecision((int64_t)mktime(&tm) * 1000L, TSDB_TIME_PRECISION_MILLI, precision); + tw->skey = convertTimePrecision((int64_t)taosMktime(&tm) * 1000L, TSDB_TIME_PRECISION_MILLI, precision); mon = (int)(mon + interval); tm.tm_year = mon / 12; tm.tm_mon = mon % 12; - tw->ekey = convertTimePrecision((int64_t)mktime(&tm) * 1000L, TSDB_TIME_PRECISION_MILLI, precision); + tw->ekey = convertTimePrecision((int64_t)taosMktime(&tm) * 1000L, TSDB_TIME_PRECISION_MILLI, precision); tw->ekey -= 1; } @@ -234,9 +234,8 @@ int32_t operatorDummyOpenFn(SOperatorInfo* pOperator) { void operatorDummyCloseFn(void* param, int32_t numOfCols) {} -static int32_t doCopyToSDataBlock(SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo, int32_t orderType, - SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset); - +static int32_t doCopyToSDataBlock(SSDataBlock* pBlock, int32_t rowCapacity, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo, + int32_t orderType, int32_t* rowCellOffset); static void initCtxOutputBuffer(SqlFunctionCtx* pCtx, int32_t size); static void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, int64_t keyFirst, int64_t keyLast, STimeWindow* win); @@ -300,10 +299,6 @@ SSDataBlock* createOutputBuf_rv1(SDataBlockDescNode* pNode) { } taosArrayPush(pBlock->pDataBlock, &idata); - - if (IS_VAR_DATA_TYPE(idata.info.type)) { - pBlock->info.hasVarCol = true; - } } return pBlock; @@ -363,7 +358,7 @@ static void prepareResultListBuffer(SResultRowInfo* pResultRowInfo, jmp_buf env) pResultRowInfo->pPosition = taosMemoryRealloc(pResultRowInfo->pPosition, newCapacity * sizeof(SResultRowPosition)); int32_t inc = (int32_t)newCapacity - pResultRowInfo->capacity; - memset(&pResultRowInfo->pPosition[pResultRowInfo->capacity], 0, sizeof(SResultRowPosition)); + memset(&pResultRowInfo->pPosition[pResultRowInfo->capacity], 0, sizeof(SResultRowPosition) * inc); pResultRowInfo->capacity = (int32_t)newCapacity; } @@ -419,7 +414,7 @@ SResultRow* getNewResultRow_rv(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, pData = getBufPage(pResultBuf, getPageId(pi)); pageId = getPageId(pi); - if (pData->num + interBufSize + sizeof(SResultRow) > getBufPageSize(pResultBuf)) { + if (pData->num + interBufSize > getBufPageSize(pResultBuf)) { // release current page first, and prepare the next one releaseBufPageInfo(pResultBuf, pi); @@ -439,7 +434,7 @@ SResultRow* getNewResultRow_rv(SDiskbasedBuf* pResultBuf, int64_t tableGroupId, pResultRow->pageId = pageId; pResultRow->offset = (int32_t)pData->num; - pData->num += interBufSize + sizeof(SResultRow); + pData->num += interBufSize; return pResultRow; } @@ -507,7 +502,7 @@ static SResultRow* doSetResultOutBufByKey_rv(SDiskbasedBuf* pResultBuf, SResultR // add a new result set for a new group SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset}; - taosHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos, POINTER_BYTES); + taosHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos, sizeof(SResultRowPosition)); SResultRowCell cell = {.groupId = tableGroupId, .pos = pos}; taosArrayPush(pSup->pResultRowArrayList, &cell); } else { @@ -995,7 +990,8 @@ static int32_t getNextQualifiedWindow(SInterval* pInterval, STimeWindow* pNext, static FORCE_INLINE TSKEY reviseWindowEkey(STaskAttr* pQueryAttr, STimeWindow* pWindow) { TSKEY ekey = -1; - if (QUERY_IS_ASC_QUERY(pQueryAttr)) { + int32_t order = TSDB_ORDER_ASC; + if (order == TSDB_ORDER_ASC) { ekey = pWindow->ekey; if (ekey > pQueryAttr->window.ekey) { ekey = pQueryAttr->window.ekey; @@ -1072,9 +1068,9 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, pCtx[i].size = pBlock->info.rows; pCtx[i].currentStage = MAIN_SCAN; - SExprInfo expr = pOperator->pExpr[i]; - for (int32_t j = 0; j < expr.base.numOfParams; ++j) { - SFunctParam *pFuncParam = &expr.base.pParam[j]; + SExprInfo* pOneExpr = &pOperator->pExpr[i]; + for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) { + SFunctParam *pFuncParam = &pOneExpr->base.pParam[j]; if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) { int32_t slotId = pFuncParam->pCol->slotId; pCtx[i].input.pData[j] = taosArrayGet(pBlock->pDataBlock, slotId); @@ -1149,19 +1145,21 @@ static void setPseudoOutputColInfo(SSDataBlock* pResult, SqlFunctionCtx* pCtx, S } } -static void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx, - int32_t numOfOutput, SArray* pPseudoList) { +void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx, int32_t numOfOutput, SArray* pPseudoList) { setPseudoOutputColInfo(pResult, pCtx, pPseudoList); pResult->info.groupId = pSrcBlock->info.groupId; for (int32_t k = 0; k < numOfOutput; ++k) { + int32_t outputSlotId = pExpr[k].base.resSchema.slotId; + SqlFunctionCtx* pfCtx = &pCtx[k]; + if (pExpr[k].pExpr->nodeType == QUERY_NODE_COLUMN) { // it is a project query - SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, k); - colDataAssign(pColInfoData, pCtx[k].input.pData[0], pCtx[k].input.numOfRows); + SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, outputSlotId); + colDataAssign(pColInfoData, pfCtx->input.pData[0], pfCtx->input.numOfRows); pResult->info.rows = pSrcBlock->info.rows; } else if (pExpr[k].pExpr->nodeType == QUERY_NODE_VALUE) { - SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, k); + SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, outputSlotId); for (int32_t i = 0; i < pSrcBlock->info.rows; ++i) { colDataAppend(pColInfoData, i, taosVariantGet(&pExpr[k].base.pParam[0].param, pExpr[k].base.pParam[0].param.nType), TSDB_DATA_TYPE_NULL == pExpr[k].base.pParam[0].param.nType); } @@ -1171,40 +1169,40 @@ static void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSData taosArrayPush(pBlockList, &pSrcBlock); SScalarParam dest = {0}; - dest.columnData = taosArrayGet(pResult->pDataBlock, k); + dest.columnData = taosArrayGet(pResult->pDataBlock, outputSlotId); scalarCalculate(pExpr[k].pExpr->_optrRoot.pRootNode, pBlockList, &dest); pResult->info.rows = dest.numOfRows; taosArrayDestroy(pBlockList); } else if (pExpr[k].pExpr->nodeType == QUERY_NODE_FUNCTION) { - ASSERT(!fmIsAggFunc(pCtx[k].functionId)); + ASSERT(!fmIsAggFunc(pfCtx->functionId)); - if (fmIsPseudoColumnFunc(pCtx[k].functionId)) { + if (fmIsPseudoColumnFunc(pfCtx->functionId)) { // do nothing - } else if (fmIsNonstandardSQLFunc(pCtx[k].functionId)) { + } else if (fmIsNonstandardSQLFunc(pfCtx->functionId)) { // todo set the correct timestamp column - pCtx[k].input.pPTS = taosArrayGet(pSrcBlock->pDataBlock, 1); + pfCtx->input.pPTS = taosArrayGet(pSrcBlock->pDataBlock, 1); SResultRowEntryInfo *pResInfo = GET_RES_INFO(&pCtx[k]); - pCtx[k].fpSet.init(&pCtx[k], pResInfo); + pfCtx->fpSet.init(&pCtx[k], pResInfo); - pCtx[k].pOutput = taosArrayGet(pResult->pDataBlock, k); - pCtx[k].offset = pResult->info.rows; // set the start offset + pfCtx->pOutput = taosArrayGet(pResult->pDataBlock, outputSlotId); + pfCtx->offset = pResult->info.rows; // set the start offset if (taosArrayGetSize(pPseudoList) > 0) { int32_t* outputColIndex = taosArrayGet(pPseudoList, 0); - pCtx[k].pTsOutput = (SColumnInfoData*)pCtx[*outputColIndex].pOutput; + pfCtx->pTsOutput = (SColumnInfoData*)pCtx[*outputColIndex].pOutput; } - int32_t numOfRows = pCtx[k].fpSet.process(&pCtx[k]); + int32_t numOfRows = pfCtx->fpSet.process(pfCtx); pResult->info.rows += numOfRows; } else { SArray* pBlockList = taosArrayInit(4, POINTER_BYTES); taosArrayPush(pBlockList, &pSrcBlock); SScalarParam dest = {0}; - dest.columnData = taosArrayGet(pResult->pDataBlock, k); + dest.columnData = taosArrayGet(pResult->pDataBlock, outputSlotId); scalarCalculate((SNode*)pExpr[k].pExpr->_function.pFunctNode, pBlockList, &dest); pResult->info.rows = dest.numOfRows; @@ -1687,12 +1685,13 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSessionAggOperator static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) { if (IS_VAR_DATA_TYPE(type)) { - if (pResultRow->key == NULL) { - pResultRow->key = taosMemoryMalloc(varDataTLen(pData)); - varDataCopy(pResultRow->key, pData); - } else { - assert(memcmp(pResultRow->key, pData, varDataTLen(pData)) == 0); - } + // todo disable this +// if (pResultRow->key == NULL) { +// pResultRow->key = taosMemoryMalloc(varDataTLen(pData)); +// varDataCopy(pResultRow->key, pData); +// } else { +// ASSERT(memcmp(pResultRow->key, pData, varDataTLen(pData)) == 0); +// } } else { int64_t v = -1; GET_TYPED_DATA(v, int64_t, type, pData); @@ -1702,9 +1701,8 @@ static void setResultRowKey(SResultRow* pResultRow, char* pData, int16_t type) { } } -int32_t setGroupResultOutputBuf_rv(SOptrBasicInfo* binfo, int32_t numOfCols, char* pData, int16_t type, - int16_t bytes, int32_t groupId, SDiskbasedBuf* pBuf, SExecTaskInfo* pTaskInfo, - SAggSupporter* pAggSup) { +int32_t setGroupResultOutputBuf(SOptrBasicInfo* binfo, int32_t numOfCols, char* pData, int16_t type, int16_t bytes, + int32_t groupId, SDiskbasedBuf* pBuf, SExecTaskInfo* pTaskInfo, SAggSupporter* pAggSup) { SResultRowInfo* pResultRowInfo = &binfo->resultRowInfo; SqlFunctionCtx* pCtx = binfo->pCtx; @@ -1813,7 +1811,7 @@ static int32_t setCtxTagColumnInfo(SqlFunctionCtx* pCtx, int32_t numOfOutput) { return TSDB_CODE_SUCCESS; } -static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset) { +SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset) { SqlFunctionCtx* pFuncCtx = (SqlFunctionCtx*)taosMemoryCalloc(numOfOutput, sizeof(SqlFunctionCtx)); if (pFuncCtx == NULL) { return NULL; @@ -1854,12 +1852,12 @@ static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t num pCtx->input.pData = taosMemoryCalloc(pFunct->numOfParams, POINTER_BYTES); pCtx->input.pColumnDataAgg = taosMemoryCalloc(pFunct->numOfParams, POINTER_BYTES); - pCtx->pTsOutput = NULL;//taosArrayInit(4, POINTER_BYTES); + pCtx->pTsOutput = NULL; pCtx->resDataInfo.bytes = pFunct->resSchema.bytes; pCtx->resDataInfo.type = pFunct->resSchema.type; pCtx->order = TSDB_ORDER_ASC; - pCtx->start.key = INT64_MIN; - pCtx->end.key = INT64_MIN; + pCtx->start.key = INT64_MIN; + pCtx->end.key = INT64_MIN; #if 0 for (int32_t j = 0; j < pCtx->numOfParams; ++j) { // int16_t type = pFunct->param[j].nType; @@ -1963,7 +1961,8 @@ static bool isCachedLastQuery(STaskAttr* pQueryAttr) { return false; } - if (pQueryAttr->order.order != TSDB_ORDER_DESC || !TSWINDOW_IS_EQUAL(pQueryAttr->window, TSWINDOW_DESC_INITIALIZER)) { + int32_t order = TSDB_ORDER_ASC; + if (order != TSDB_ORDER_DESC || !TSWINDOW_IS_EQUAL(pQueryAttr->window, TSWINDOW_DESC_INITIALIZER)) { return false; } @@ -2189,7 +2188,7 @@ static bool overlapWithTimeWindow(STaskAttr* pQueryAttr, SDataBlockInfo* pBlockI TSKEY sk = TMIN(pQueryAttr->window.skey, pQueryAttr->window.ekey); TSKEY ek = TMAX(pQueryAttr->window.skey, pQueryAttr->window.ekey); - if (QUERY_IS_ASC_QUERY(pQueryAttr)) { + if (true) { // getAlignQueryTimeWindow(pQueryAttr, pBlockInfo->window.skey, sk, ek, &w); assert(w.ekey >= pBlockInfo->window.skey); @@ -2259,57 +2258,6 @@ static int32_t doTSJoinFilter(STaskRuntimeEnv* pRuntimeEnv, TSKEY key, bool ascQ return TS_JOIN_TS_EQUAL; } -bool doFilterDataBlock(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols, int32_t numOfRows, int8_t* p) { - bool all = true; - - for (int32_t i = 0; i < numOfRows; ++i) { - bool qualified = false; - - for (int32_t k = 0; k < numOfFilterCols; ++k) { - char* pElem = (char*)pFilterInfo[k].pData + pFilterInfo[k].info.bytes * i; - - qualified = false; - for (int32_t j = 0; j < pFilterInfo[k].numOfFilters; ++j) { - SColumnFilterElem* pFilterElem = NULL; - // SColumnFilterElem* pFilterElem = &pFilterInfo[k].pFilters[j]; - - bool isnull = isNull(pElem, pFilterInfo[k].info.type); - if (isnull) { - // if (pFilterElem->fp == isNullOperator) { - // qualified = true; - // break; - // } else { - // continue; - // } - } else { - // if (pFilterElem->fp == notNullOperator) { - // qualified = true; - // break; - // } else if (pFilterElem->fp == isNullOperator) { - // continue; - // } - } - - if (pFilterElem->fp(pFilterElem, pElem, pElem, pFilterInfo[k].info.type)) { - qualified = true; - break; - } - } - - if (!qualified) { - break; - } - } - - p[i] = qualified ? 1 : 0; - if (!qualified) { - all = false; - } - } - - return all; -} - void doCompactSDataBlock(SSDataBlock* pBlock, int32_t numOfRows, int8_t* p) { int32_t len = 0; int32_t start = 0; @@ -2359,49 +2307,6 @@ void doCompactSDataBlock(SSDataBlock* pBlock, int32_t numOfRows, int8_t* p) { } } -void filterRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols, - SSDataBlock* pBlock, bool ascQuery) { - int32_t numOfRows = pBlock->info.rows; - - int8_t* p = taosMemoryCalloc(numOfRows, sizeof(int8_t)); - bool all = true; -#if 0 - if (pRuntimeEnv->pTsBuf != NULL) { - SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, 0); - - TSKEY* k = (TSKEY*) pColInfoData->pData; - for (int32_t i = 0; i < numOfRows; ++i) { - int32_t offset = ascQuery? i:(numOfRows - i - 1); - int32_t ret = doTSJoinFilter(pRuntimeEnv, k[offset], ascQuery); - if (ret == TS_JOIN_TAG_NOT_EQUALS) { - break; - } else if (ret == TS_JOIN_TS_NOT_EQUALS) { - all = false; - continue; - } else { - assert(ret == TS_JOIN_TS_EQUAL); - p[offset] = true; - } - - if (!tsBufNextPos(pRuntimeEnv->pTsBuf)) { - break; - } - } - - // save the cursor status - pRuntimeEnv->current->cur = tsBufGetCursor(pRuntimeEnv->pTsBuf); - } else { - all = doFilterDataBlock(pFilterInfo, numOfFilterCols, numOfRows, p); - } -#endif - - if (!all) { - doCompactSDataBlock(pBlock, numOfRows, p); - } - - taosMemoryFreeClear(p); -} - void filterColRowsInDataBlock(STaskRuntimeEnv* pRuntimeEnv, SSDataBlock* pBlock, bool ascQuery) { int32_t numOfRows = pBlock->info.rows; @@ -3133,7 +3038,7 @@ void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock) { bool keep = filterExecute(filter, pBlock, &rowRes, NULL, param1.numOfCols); filterFreeInfo(filter); - SSDataBlock* px = createOneDataBlock(pBlock); + SSDataBlock* px = createOneDataBlock(pBlock, false); blockDataEnsureCapacity(px, pBlock->info.rows); // todo extract method @@ -3333,8 +3238,7 @@ void setIntervalQueryRange(STaskRuntimeEnv* pRuntimeEnv, TSKEY key) { * @param pQInfo * @param result */ -static int32_t doCopyToSDataBlock(SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo, int32_t orderType, - SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset) { +int32_t doCopyToSDataBlock(SSDataBlock* pBlock, int32_t rowCapacity, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo, int32_t orderType, int32_t* rowCellOffset) { int32_t numOfRows = getNumOfTotalRes(pGroupResInfo); int32_t numOfResult = pBlock->info.rows; // there are already exists result rows @@ -3373,7 +3277,9 @@ static int32_t doCopyToSDataBlock(SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResI pGroupResInfo->index += 1; for (int32_t j = 0; j < pBlock->info.numOfCols; ++j) { - SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, j); + int32_t slotId = pExprInfo[j].base.resSchema.slotId; + + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId); SResultRowEntryInfo* pEntryInfo = getResultCell(pRow, j, rowCellOffset); char* in = GET_ROWCELL_INTERBUF(pEntryInfo); @@ -3394,8 +3300,8 @@ static int32_t doCopyToSDataBlock(SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResI return 0; } -void toSDatablock(SGroupResInfo* pGroupResInfo, SDiskbasedBuf* pBuf, SSDataBlock* pBlock, int32_t rowCapacity, - int32_t* rowCellOffset) { +void toSDatablock(SSDataBlock* pBlock, int32_t rowCapacity, SGroupResInfo* pGroupResInfo, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, + int32_t* rowCellOffset) { assert(pGroupResInfo->currentGroup <= pGroupResInfo->totalGroup); blockDataCleanup(pBlock); @@ -3404,7 +3310,7 @@ void toSDatablock(SGroupResInfo* pGroupResInfo, SDiskbasedBuf* pBuf, SSDataBlock } int32_t orderType = TSDB_ORDER_ASC; - doCopyToSDataBlock(pBuf, pGroupResInfo, orderType, pBlock, rowCapacity, rowCellOffset); + doCopyToSDataBlock(pBlock, rowCapacity, pExprInfo, pBuf, pGroupResInfo, orderType, rowCellOffset); // add condition (pBlock->info.rows >= 1) just to runtime happy blockDataUpdateTsWindow(pBlock); @@ -3510,22 +3416,22 @@ static void doOperatorExecProfOnce(SOperatorStackItem* item, SQueryProfEvent* ev } } -void calculateOperatorProfResults(SQInfo* pQInfo) { - if (pQInfo->summary.queryProfEvents == NULL) { - // qDebug("QInfo:0x%"PRIx64" query prof events array is null", pQInfo->qId); - return; - } - - if (pQInfo->summary.operatorProfResults == NULL) { - // qDebug("QInfo:0x%"PRIx64" operator prof results hash is null", pQInfo->qId); - return; - } +void calculateOperatorProfResults(void) { +// if (pQInfo->summary.queryProfEvents == NULL) { +// // qDebug("QInfo:0x%"PRIx64" query prof events array is null", pQInfo->qId); +// return; +// } +// +// if (pQInfo->summary.operatorProfResults == NULL) { +// // qDebug("QInfo:0x%"PRIx64" operator prof results hash is null", pQInfo->qId); +// return; +// } SArray* opStack = taosArrayInit(32, sizeof(SOperatorStackItem)); if (opStack == NULL) { return; } - +#if 0 size_t size = taosArrayGetSize(pQInfo->summary.queryProfEvents); SHashObj* profResults = pQInfo->summary.operatorProfResults; @@ -3548,7 +3454,7 @@ void calculateOperatorProfResults(SQInfo* pQInfo) { } } } - +#endif taosArrayDestroy(opStack); } @@ -4008,10 +3914,9 @@ static int32_t doSendFetchDataRequest(SExchangeInfo* pExchangeInfo, SExecTaskInf return TSDB_CODE_SUCCESS; } -// TODO if only one or two columnss required, how to extract data? -int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadInfo, int32_t numOfRows, - char* pData, int32_t compLen, int32_t numOfOutput, int64_t startTs, - uint64_t* total, SArray* pColList) { +// TODO if only one or two columns required, how to extract data? +int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadInfo, int32_t numOfRows, char* pData, + int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total, SArray* pColList) { blockDataEnsureCapacity(pRes, numOfRows); if (pColList == NULL) { // data from other sources @@ -4041,18 +3946,70 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI } } else { // extract data according to pColList ASSERT(numOfOutput == taosArrayGetSize(pColList)); + char* pStart = pData; + + int32_t numOfCols = htonl(*(int32_t*)pStart); + pStart += sizeof(int32_t); + + SSysTableSchema* pSchema = (SSysTableSchema*)pStart; + for(int32_t i = 0; i < numOfCols; ++i) { + SSysTableSchema* p = (SSysTableSchema*)pStart; + + p->colId = htons(p->colId); + p->bytes = htonl(p->bytes); + pStart += sizeof(SSysTableSchema); + } + + SSDataBlock block = {.pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)), .info.numOfCols = numOfCols}; + for(int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData idata = {0}; + idata.info.type = pSchema[i].type; + idata.info.bytes = pSchema[i].bytes; + idata.info.colId = pSchema[i].colId; + + taosArrayPush(block.pDataBlock, &idata); + if (IS_VAR_DATA_TYPE(idata.info.type)) { + block.info.hasVarCol = true; + } + } + + blockDataEnsureCapacity(&block, numOfRows); + + int32_t* colLen = (int32_t*) pStart; + pStart += sizeof(int32_t) * numOfCols; + + for (int32_t i = 0; i < numOfCols; ++i) { + colLen[i] = htonl(colLen[i]); + ASSERT(colLen[i] >= 0); + + SColumnInfoData* pColInfoData = taosArrayGet(block.pDataBlock, i); + if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { + pColInfoData->varmeta.length = colLen[i]; + pColInfoData->varmeta.allocLen = colLen[i]; + + memcpy(pColInfoData->varmeta.offset, pStart, sizeof(int32_t) * numOfRows); + pStart += sizeof(int32_t) * numOfRows; + + pColInfoData->pData = taosMemoryMalloc(colLen[i]); + } else { + memcpy(pColInfoData->nullbitmap, pStart, BitmapLen(numOfRows)); + pStart += BitmapLen(numOfRows); + } + + memcpy(pColInfoData->pData, pStart, colLen[i]); + pStart += colLen[i]; + } // data from mnode - for (int32_t i = 0; i < numOfOutput; ++i) { + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData* pSrc = taosArrayGet(block.pDataBlock, i); + for (int32_t j = 0; j < numOfOutput; ++j) { int16_t colIndex = *(int16_t*)taosArrayGet(pColList, j); + if (colIndex - 1 == i) { SColumnInfoData* pColInfoData = taosArrayGet(pRes->pDataBlock, j); - - for (int32_t k = 0; k < numOfRows; ++k) { - colDataAppend(pColInfoData, k, pData, false); - pData += pColInfoData->info.bytes; - } + colDataAssign(pColInfoData, pSrc, numOfRows); break; } } @@ -4441,33 +4398,7 @@ _error: return NULL; } -SSDataBlock* createResultDataBlock(const SArray* pExprInfo) { - SSDataBlock* pResBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); - if (pResBlock == NULL) { - return NULL; - } - - size_t numOfCols = taosArrayGetSize(pExprInfo); - pResBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); - - SArray* pResult = pResBlock->pDataBlock; - for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData colInfoData = {0}; - SExprInfo* p = taosArrayGetP(pExprInfo, i); - - SResSchema* pSchema = &p->base.resSchema; - colInfoData.info.type = pSchema->type; - colInfoData.info.colId = pSchema->colId; - colInfoData.info.bytes = pSchema->bytes; - colInfoData.info.scale = pSchema->scale; - colInfoData.info.precision = pSchema->precision; - taosArrayPush(pResult, &colInfoData); - } - - return pResBlock; -} - -static int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, const char* pKey); +static int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t keyBufSize, const char* pKey); static void cleanupAggSup(SAggSupporter* pAggSup); static void destroySortedMergeOperatorInfo(void* param, int32_t numOfOutput) { @@ -4483,13 +4414,6 @@ static void destroySortedMergeOperatorInfo(void* param, int32_t numOfOutput) { cleanupAggSup(&pInfo->aggSup); } -static void destroySlimitOperatorInfo(void* param, int32_t numOfOutput) { - SSLimitOperatorInfo* pInfo = (SSLimitOperatorInfo*)param; - taosArrayDestroy(pInfo->orderColumnList); - pInfo->pRes = blockDataDestroy(pInfo->pRes); - taosMemoryFreeClear(pInfo->prevRow); -} - static void assignExprInfo(SExprInfo* dst, const SExprInfo* src) { assert(dst != NULL && src != NULL); @@ -4689,7 +4613,7 @@ static SSDataBlock* doMerge(SOperatorInfo* pOperator) { SSortedMergeOperatorInfo* pInfo = pOperator->info; SSortHandle* pHandle = pInfo->pSortHandle; - SSDataBlock* pDataBlock = createOneDataBlock(pInfo->binfo.pRes); + SSDataBlock* pDataBlock = createOneDataBlock(pInfo->binfo.pRes, false); blockDataEnsureCapacity(pDataBlock, pInfo->binfo.capacity); while (1) { @@ -4780,7 +4704,7 @@ static int32_t initGroupCol(SExprInfo* pExprInfo, int32_t numOfCols, SArray* pGr SColumn* pCol = taosArrayGet(pGroupInfo, i); for (int32_t j = 0; j < numOfCols; ++j) { SExprInfo* pe = &pExprInfo[j]; - if (pe->base.resSchema.colId == pCol->colId) { + if (pe->base.resSchema.slotId == pCol->colId) { taosArrayPush(plist, pCol); taosArrayPush(pInfo->groupInfo, &j); len += pCol->bytes; @@ -4819,14 +4743,15 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t goto _error; } - pInfo->binfo.pCtx = createSqlFunctionCtx_rv(pExprInfo, num, &pInfo->binfo.rowCellInfoOffset); + pInfo->binfo.pCtx = createSqlFunctionCtx(pExprInfo, num, &pInfo->binfo.rowCellInfoOffset); initResultRowInfo(&pInfo->binfo.resultRowInfo, (int32_t)1); if (pInfo->binfo.pCtx == NULL || pInfo->binfo.pRes == NULL) { goto _error; } - int32_t code = doInitAggInfoSup(&pInfo->aggSup, pInfo->binfo.pCtx, num, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + int32_t code = doInitAggInfoSup(&pInfo->aggSup, pInfo->binfo.pCtx, num, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -4977,6 +4902,21 @@ static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) { // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pInfo->pCtx, pBlock, order); doAggregateImpl(pOperator, 0, pInfo->pCtx); + +#if 0 // test for encode/decode result info + if(pOperator->encodeResultRow){ + char *result = NULL; + int32_t length = 0; + SAggSupporter *pSup = &pAggInfo->aggSup; + pOperator->encodeResultRow(pOperator, pSup, pInfo, &result, &length); + taosHashClear(pSup->pResultRowHashTable); + pInfo->resultRowInfo.size = 0; + pOperator->decodeResultRow(pOperator, pSup, pInfo, result, length); + if(result){ + taosMemoryFree(result); + } + } +#endif } finalizeQueryResult(pInfo->pCtx, pOperator->numOfOutput); @@ -5005,24 +4945,33 @@ static SSDataBlock* getAggregateResult(SOperatorInfo* pOperator, bool* newgroup) return (blockDataGetNumOfRows(pInfo->pRes) != 0) ? pInfo->pRes : NULL; } -static void aggEncodeResultRow(SOperatorInfo* pOperator, char** result, int32_t* length) { - SAggOperatorInfo* pAggInfo = pOperator->info; - SAggSupporter* pSup = &pAggInfo->aggSup; - +void aggEncodeResultRow(SOperatorInfo* pOperator, SAggSupporter *pSup, SOptrBasicInfo *pInfo, char **result, int32_t *length) { int32_t size = taosHashGetSize(pSup->pResultRowHashTable); - size_t keyLen = POINTER_BYTES; // estimate the key length + size_t keyLen = sizeof(uint64_t) * 2; // estimate the key length int32_t totalSize = sizeof(int32_t) + size * (sizeof(int32_t) + keyLen + sizeof(int32_t) + pSup->resultRowSize); *result = taosMemoryCalloc(1, totalSize); if (*result == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return; + longjmp(pOperator->pTaskInfo->env, TSDB_CODE_OUT_OF_MEMORY); } *(int32_t*)(*result) = size; int32_t offset = sizeof(int32_t); + + // prepare memory + SResultRowPosition* pos = &pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.curPos]; + void* pPage = getBufPage(pSup->pResultBuf, pos->pageId); + SResultRow* pRow = (SResultRow*)((char*)pPage + pos->offset); + setBufPageDirty(pPage, true); + releaseBufPage(pSup->pResultBuf, pPage); + void* pIter = taosHashIterate(pSup->pResultRowHashTable, NULL); while (pIter) { void* key = taosHashGetKey(pIter, &keyLen); - SResultRow** p1 = (SResultRow**)pIter; + SResultRowPosition* p1 = (SResultRowPosition*)pIter; + + pPage = (SFilePage*) getBufPage(pSup->pResultBuf, p1->pageId); + pRow = (SResultRow*)((char*)pPage + p1->offset); + setBufPageDirty(pPage, true); + releaseBufPage(pSup->pResultBuf, pPage); // recalculate the result size int32_t realTotalSize = offset + sizeof(int32_t) + keyLen + sizeof(int32_t) + pSup->resultRowSize; @@ -5032,7 +4981,7 @@ static void aggEncodeResultRow(SOperatorInfo* pOperator, char** result, int32_t* terrno = TSDB_CODE_OUT_OF_MEMORY; taosMemoryFree(*result); *result = NULL; - return; + longjmp(pOperator->pTaskInfo->env, TSDB_CODE_OUT_OF_MEMORY); } else { *result = tmp; } @@ -5046,7 +4995,7 @@ static void aggEncodeResultRow(SOperatorInfo* pOperator, char** result, int32_t* // save value *(int32_t*)(*result + offset) = pSup->resultRowSize; offset += sizeof(int32_t); - memcpy(*result + offset, *p1, pSup->resultRowSize); + memcpy(*result + offset, pRow, pSup->resultRowSize); offset += pSup->resultRowSize; pIter = taosHashIterate(pSup->pResultRowHashTable, pIter); @@ -5058,15 +5007,11 @@ static void aggEncodeResultRow(SOperatorInfo* pOperator, char** result, int32_t* return; } -static bool aggDecodeResultRow(SOperatorInfo* pOperator, char* result, int32_t length) { +bool aggDecodeResultRow(SOperatorInfo* pOperator, SAggSupporter *pSup, SOptrBasicInfo *pInfo, char* result, int32_t length) { if (!result || length <= 0) { return false; } - SAggOperatorInfo* pAggInfo = pOperator->info; - SAggSupporter* pSup = &pAggInfo->aggSup; - SOptrBasicInfo* pInfo = &pAggInfo->binfo; - // int32_t size = taosHashGetSize(pSup->pResultRowHashTable); int32_t count = *(int32_t*)(result); @@ -5078,17 +5023,16 @@ static bool aggDecodeResultRow(SOperatorInfo* pOperator, char* result, int32_t l uint64_t tableGroupId = *(uint64_t*)(result + offset); SResultRow* resultRow = getNewResultRow_rv(pSup->pResultBuf, tableGroupId, pSup->resultRowSize); if (!resultRow) { - terrno = TSDB_CODE_TSC_INVALID_INPUT; - return false; + longjmp(pOperator->pTaskInfo->env, TSDB_CODE_TSC_INVALID_INPUT); } // add a new result set for a new group - taosHashPut(pSup->pResultRowHashTable, result + offset, keyLen, &resultRow, POINTER_BYTES); + SResultRowPosition pos = {.pageId = resultRow->pageId, .offset = resultRow->offset}; + taosHashPut(pSup->pResultRowHashTable, result + offset, keyLen, &pos, sizeof(SResultRowPosition)); offset += keyLen; int32_t valueLen = *(int32_t*)(result + offset); if (valueLen != pSup->resultRowSize) { - terrno = TSDB_CODE_TSC_INVALID_INPUT; - return false; + longjmp(pOperator->pTaskInfo->env, TSDB_CODE_TSC_INVALID_INPUT); } offset += sizeof(int32_t); int32_t pageId = resultRow->pageId; @@ -5099,13 +5043,13 @@ static bool aggDecodeResultRow(SOperatorInfo* pOperator, char* result, int32_t l offset += valueLen; initResultRow(resultRow); - pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.size++] = - (SResultRowPosition){.pageId = resultRow->pageId, .offset = resultRow->offset}; + prepareResultListBuffer(&pInfo->resultRowInfo, pOperator->pTaskInfo->env); + pInfo->resultRowInfo.curPos = pInfo->resultRowInfo.size; + pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.size++] = (SResultRowPosition) {.pageId = resultRow->pageId, .offset = resultRow->offset}; } if (offset != length) { - terrno = TSDB_CODE_TSC_INVALID_INPUT; - return false; + longjmp(pOperator->pTaskInfo->env, TSDB_CODE_TSC_INVALID_INPUT); } return true; } @@ -5120,9 +5064,7 @@ static SSDataBlock* doMultiTableAggregate(SOperatorInfo* pOperator, bool* newgro SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; if (pOperator->status == OP_RES_TO_RETURN) { - toSDatablock(&pAggInfo->groupResInfo, pAggInfo->pResultBuf, pInfo->pRes, pAggInfo->binfo.capacity, - pAggInfo->binfo.rowCellInfoOffset); - + toSDatablock(pInfo->pRes, pAggInfo->binfo.capacity, &pAggInfo->groupResInfo, pOperator->pExpr, pAggInfo->pResultBuf, pAggInfo->binfo.rowCellInfoOffset); if (pInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pAggInfo->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } @@ -5171,8 +5113,7 @@ static SSDataBlock* doMultiTableAggregate(SOperatorInfo* pOperator, bool* newgro updateNumOfRowsInResultRows(pInfo->pCtx, pOperator->numOfOutput, &pInfo->resultRowInfo, pInfo->rowCellInfoOffset); initGroupResInfo(&pAggInfo->groupResInfo, &pInfo->resultRowInfo); - toSDatablock(&pAggInfo->groupResInfo, pAggInfo->pResultBuf, pInfo->pRes, pAggInfo->binfo.capacity, - pAggInfo->binfo.rowCellInfoOffset); + toSDatablock(pInfo->pRes, pAggInfo->binfo.capacity, &pAggInfo->groupResInfo, pOperator->pExpr, pAggInfo->pResultBuf, pAggInfo->binfo.rowCellInfoOffset); if (pInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pAggInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); @@ -5187,6 +5128,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator, bool* newgroup) SSDataBlock* pRes = pInfo->pRes; blockDataCleanup(pRes); + #if 0 if (pProjectInfo->existDataBlock) { // TODO refactor SSDataBlock* pBlock = pProjectInfo->existDataBlock; @@ -5331,6 +5273,21 @@ static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) { // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order); hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, 0); + +#if 0 // test for encode/decode result info + if(pOperator->encodeResultRow){ + char *result = NULL; + int32_t length = 0; + SAggSupporter *pSup = &pInfo->aggSup; + pOperator->encodeResultRow(pOperator, pSup, &pInfo->binfo, &result, &length); + taosHashClear(pSup->pResultRowHashTable); + pInfo->binfo.resultRowInfo.size = 0; + pOperator->decodeResultRow(pOperator, pSup, &pInfo->binfo, result, length); + if(result){ + taosMemoryFree(result); + } + } +#endif } closeAllResultRows(&pInfo->binfo.resultRowInfo); @@ -5360,8 +5317,7 @@ static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator, bool* newgro } blockDataEnsureCapacity(pInfo->binfo.pRes, pInfo->binfo.capacity); - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pInfo->binfo.pRes, pInfo->binfo.capacity, - pInfo->binfo.rowCellInfoOffset); + toSDatablock(pInfo->binfo.pRes, pInfo->binfo.capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset); if (pInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); @@ -5379,8 +5335,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo *pOperator, bool* newgroup } if (pOperator->status == OP_RES_TO_RETURN) { - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pInfo->binfo.pRes, pInfo->binfo.capacity, - pInfo->binfo.rowCellInfoOffset); + toSDatablock(pInfo->binfo.pRes, pInfo->binfo.capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset); if (pInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } @@ -5415,8 +5370,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo *pOperator, bool* newgroup initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated); blockDataEnsureCapacity(pInfo->binfo.pRes, pInfo->binfo.capacity); - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pInfo->binfo.pRes, pInfo->binfo.capacity, - pInfo->binfo.rowCellInfoOffset); + toSDatablock(pInfo->binfo.pRes, pInfo->binfo.capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset); ASSERT(pInfo->binfo.pRes->info.rows > 0); pOperator->status = OP_RES_TO_RETURN; @@ -5429,58 +5383,48 @@ static SSDataBlock* doAllIntervalAgg(SOperatorInfo *pOperator, bool* newgroup) { return NULL; } - STableIntervalOperatorInfo* pIntervalInfo = pOperator->info; - - STaskRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; + STimeSliceOperatorInfo* pSliceInfo = pOperator->info; if (pOperator->status == OP_RES_TO_RETURN) { // toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes); - - if (pIntervalInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { + if (pSliceInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pSliceInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); } - return pIntervalInfo->binfo.pRes; + return pSliceInfo->binfo.pRes; } - STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t order = pQueryAttr->order.order; - STimeWindow win = pQueryAttr->window; - + int32_t order = TSDB_ORDER_ASC; +// STimeWindow win = pQueryAttr->window; SOperatorInfo* downstream = pOperator->pDownstream[0]; while (1) { publishOperatorProfEvent(downstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); SSDataBlock* pBlock = downstream->getNextFn(downstream, newgroup); publishOperatorProfEvent(downstream, QUERY_PROF_AFTER_OPERATOR_EXEC); - if (pBlock == NULL) { break; } // setTagValue(pOperator, pRuntimeEnv->current->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); - // the pDataBlock are always the same one, no need to call this again - setInputDataBlock(pOperator, pIntervalInfo->binfo.pCtx, pBlock, pQueryAttr->order.order); - hashAllIntervalAgg(pOperator, &pIntervalInfo->binfo.resultRowInfo, pBlock, 0); + setInputDataBlock(pOperator, pSliceInfo->binfo.pCtx, pBlock, order); + hashAllIntervalAgg(pOperator, &pSliceInfo->binfo.resultRowInfo, pBlock, 0); } // restore the value - pQueryAttr->order.order = order; - pQueryAttr->window = win; - pOperator->status = OP_RES_TO_RETURN; - closeAllResultRows(&pIntervalInfo->binfo.resultRowInfo); + closeAllResultRows(&pSliceInfo->binfo.resultRowInfo); setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED); - finalizeQueryResult(pIntervalInfo->binfo.pCtx, pOperator->numOfOutput); + finalizeQueryResult(pSliceInfo->binfo.pCtx, pOperator->numOfOutput); - initGroupResInfo(&pRuntimeEnv->groupResInfo, &pIntervalInfo->binfo.resultRowInfo); - // toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes); + initGroupResInfo(&pSliceInfo->groupResInfo, &pSliceInfo->binfo.resultRowInfo); + // toSDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pSliceInfo->pRes); - if (pIntervalInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { + if (pSliceInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pSliceInfo->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } - return pIntervalInfo->binfo.pRes->info.rows == 0 ? NULL : pIntervalInfo->binfo.pRes; + return pSliceInfo->binfo.pRes->info.rows == 0 ? NULL : pSliceInfo->binfo.pRes; } static SSDataBlock* doSTableIntervalAgg(SOperatorInfo* pOperator, bool* newgroup) { @@ -5502,8 +5446,6 @@ static SSDataBlock* doSTableIntervalAgg(SOperatorInfo* pOperator, bool* newgroup } STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t order = pQueryAttr->order.order; - SOperatorInfo* downstream = pOperator->pDownstream[0]; while (1) { @@ -5519,14 +5461,13 @@ static SSDataBlock* doSTableIntervalAgg(SOperatorInfo* pOperator, bool* newgroup STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current; // setTagValue(pOperator, pTableQueryInfo->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); - setInputDataBlock(pOperator, pIntervalInfo->binfo.pCtx, pBlock, pQueryAttr->order.order); + setInputDataBlock(pOperator, pIntervalInfo->binfo.pCtx, pBlock, TSDB_ORDER_ASC); setIntervalQueryRange(pRuntimeEnv, pBlock->info.window.skey); hashIntervalAgg(pOperator, &pTableQueryInfo->resInfo, pBlock, pTableQueryInfo->groupIndex); } pOperator->status = OP_RES_TO_RETURN; - pQueryAttr->order.order = order; // TODO : restore the order doCloseAllTimeWindow(pRuntimeEnv); setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED); @@ -5671,7 +5612,7 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator, bool* newgroup) { SOptrBasicInfo* pBInfo = &pInfo->binfo; if (pOperator->status == OP_RES_TO_RETURN) { - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, pBInfo->rowCellInfoOffset); + toSDatablock(pBInfo->pRes, pBInfo->capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pBInfo->rowCellInfoOffset); if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); return NULL; @@ -5703,7 +5644,7 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator, bool* newgroup) { initGroupResInfo(&pInfo->groupResInfo, &pBInfo->resultRowInfo); blockDataEnsureCapacity(pBInfo->pRes, pBInfo->capacity); - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, pBInfo->rowCellInfoOffset); + toSDatablock(pBInfo->pRes, pBInfo->capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pBInfo->rowCellInfoOffset); if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); } @@ -5720,7 +5661,7 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator, bool* newgroup) SOptrBasicInfo* pBInfo = &pInfo->binfo; if (pOperator->status == OP_RES_TO_RETURN) { - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, pBInfo->rowCellInfoOffset); + toSDatablock(pBInfo->pRes, pBInfo->capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pBInfo->rowCellInfoOffset); if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); return NULL; @@ -5752,7 +5693,7 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator, bool* newgroup) initGroupResInfo(&pInfo->groupResInfo, &pBInfo->resultRowInfo); blockDataEnsureCapacity(pBInfo->pRes, pBInfo->capacity); - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, pBInfo->rowCellInfoOffset); + toSDatablock(pBInfo->pRes, pBInfo->capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pBInfo->rowCellInfoOffset); if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { doSetOperatorCompleted(pOperator); } @@ -5760,7 +5701,6 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator, bool* newgroup) return pBInfo->pRes->info.rows == 0 ? NULL : pBInfo->pRes; } - static void doHandleRemainBlockForNewGroupImpl(SFillOperatorInfo* pInfo, SResultInfo* pResultInfo, bool* newgroup, SExecTaskInfo* pTaskInfo) { pInfo->totalInputRows = pInfo->existNewGroupBlock->info.rows; @@ -5900,11 +5840,11 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) { taosMemoryFreeClear(pOperator); } -int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, const char* pKey) { +int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t keyBufSize, const char* pKey) { _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY); pAggSup->resultRowSize = getResultRowSize(pCtx, numOfOutput); - pAggSup->keyBuf = taosMemoryCalloc(1, sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES); + pAggSup->keyBuf = taosMemoryCalloc(1, keyBufSize); pAggSup->pResultRowHashTable = taosHashInit(10, hashFn, true, HASH_NO_LOCK); pAggSup->pResultRowListSet = taosHashInit(100, hashFn, false, HASH_NO_LOCK); pAggSup->pResultRowArrayList = taosArrayInit(10, sizeof(SResultRowCell)); @@ -5931,12 +5871,12 @@ static void cleanupAggSup(SAggSupporter* pAggSup) { } int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, - int32_t numOfRows, SSDataBlock* pResultBlock, const char* pkey) { - pBasicInfo->pCtx = createSqlFunctionCtx_rv(pExprInfo, numOfCols, &pBasicInfo->rowCellInfoOffset); + int32_t numOfRows, SSDataBlock* pResultBlock, size_t keyBufSize, const char* pkey) { + pBasicInfo->pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pBasicInfo->rowCellInfoOffset); pBasicInfo->pRes = pResultBlock; pBasicInfo->capacity = numOfRows; - doInitAggInfoSup(pAggSup, pBasicInfo->pCtx, numOfCols, pkey); + doInitAggInfoSup(pAggSup, pBasicInfo->pCtx, numOfCols, keyBufSize, pkey); return TSDB_CODE_SUCCESS; } @@ -5975,7 +5915,8 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* //(int32_t)(getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery)); int32_t numOfRows = 1; - int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResultBlock, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResultBlock, keyBufSize, pTaskInfo->id.str); pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo); if (code != TSDB_CODE_SUCCESS || pInfo->pTableQueryInfo == NULL) { goto _error; @@ -6091,8 +6032,9 @@ SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SExprI SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo)); int32_t numOfRows = 1; + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; int32_t code = - initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, pTaskInfo->id.str); + initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, keyBufSize, pTaskInfo->id.str); pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo); if (code != TSDB_CODE_SUCCESS || pInfo->pTableQueryInfo == NULL) { goto _error; @@ -6152,7 +6094,8 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* p int32_t numOfCols = num; int32_t numOfRows = 4096; - initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, keyBufSize, pTaskInfo->id.str); setFunctionResultOutput(&pInfo->binfo, &pInfo->aggSup, MAIN_SCAN, pTaskInfo); pInfo->pPseudoColInfo = setRowTsColumnOutputInfo(pInfo->binfo.pCtx, numOfCols); @@ -6200,7 +6143,8 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pInfo->primaryTsIndex = primaryTsSlot; int32_t numOfRows = 4096; - int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, keyBufSize, pTaskInfo->id.str); initExecTimeWindowInfo(&pInfo->timeWindowData, &pInfo->win); // pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo); @@ -6222,6 +6166,8 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pOperator->getNextFn = doBuildIntervalResult; pOperator->getStreamResFn= doStreamIntervalAgg; pOperator->closeFn = destroyIntervalOperatorInfo; + pOperator->encodeResultRow = aggEncodeResultRow; + pOperator->decodeResultRow = aggDecodeResultRow; code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -6238,28 +6184,34 @@ _error: return NULL; } -SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, - SExprInfo* pExpr, int32_t numOfOutput) { - STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); +SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo) { + STimeSliceOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STimeSliceOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + if (pOperator == NULL || pInfo == NULL) { + goto _error; + } - // pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); - // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - - pOperator->name = "AllTimeIntervalAggOperator"; + pOperator->name = "TimeSliceOperator"; // pOperator->operatorType = OP_AllTimeWindow; pOperator->blockingOptr = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pExpr = pExpr; - pOperator->numOfOutput = numOfOutput; - pOperator->info = pInfo; - pOperator->getNextFn = doAllIntervalAgg; - pOperator->closeFn = destroyBasicOperatorInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->pExpr = pExprInfo; + pOperator->numOfOutput = numOfCols; + pOperator->info = pInfo; + pOperator->pTaskInfo = pTaskInfo; + pOperator->getNextFn = doAllIntervalAgg; + pOperator->closeFn = destroyBasicOperatorInfo; int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; + + _error: + taosMemoryFree(pInfo); + taosMemoryFree(pOperator); + pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; + return NULL; } SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo) { @@ -6270,8 +6222,8 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf } pInfo->colIndex = -1; - - initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExpr, numOfCols, 4096, pResBlock, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExpr, numOfCols, 4096, pResBlock, keyBufSize, pTaskInfo->id.str); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); pOperator->name = "StateWindowOperator"; @@ -6285,6 +6237,8 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf pOperator->info = pInfo; pOperator->getNextFn = doStateWindowAgg; pOperator->closeFn = destroyStateWindowOperatorInfo; + pOperator->encodeResultRow = aggEncodeResultRow; + pOperator->decodeResultRow = aggDecodeResultRow; int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; @@ -6303,7 +6257,8 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo } int32_t numOfRows = 4096; - int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, pTaskInfo->id.str); + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; + int32_t code = initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, numOfRows, pResBlock, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -6324,6 +6279,8 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo pOperator->info = pInfo; pOperator->getNextFn = doSessionWindowAgg; pOperator->closeFn = destroySWindowOperatorInfo; + pOperator->encodeResultRow = aggEncodeResultRow; + pOperator->decodeResultRow = aggDecodeResultRow; pOperator->pTaskInfo = pTaskInfo; code = appendDownstream(pOperator, &downstream, 1); @@ -6344,8 +6301,6 @@ SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntim SExprInfo* pExpr, int32_t numOfOutput) { STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); - // pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); - // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); @@ -6368,14 +6323,13 @@ SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRun SExprInfo* pExpr, int32_t numOfOutput) { STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); - // pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); - // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); pOperator->name = "AllMultiTableTimeIntervalOperator"; // pOperator->operatorType = OP_AllMultiTableTimeInterval; pOperator->blockingOptr = true; + pOperator->status = OP_NOT_OPENED; pOperator->pExpr = pExpr; pOperator->numOfOutput = numOfOutput; @@ -6643,45 +6597,13 @@ bool validateExprColumnInfo(SQueriedTableInfo* pTableInfo, SExprBasicInfo* pExpr return j != INT32_MIN; } -static int32_t deserializeColFilterInfo(SColumnFilterInfo* pColFilters, int16_t numOfFilters, char** pMsg) { - for (int32_t f = 0; f < numOfFilters; ++f) { - SColumnFilterInfo* pFilterMsg = (SColumnFilterInfo*)(*pMsg); - - SColumnFilterInfo* pColFilter = &pColFilters[f]; - pColFilter->filterstr = htons(pFilterMsg->filterstr); - - (*pMsg) += sizeof(SColumnFilterInfo); - - if (pColFilter->filterstr) { - pColFilter->len = htobe64(pFilterMsg->len); - - pColFilter->pz = - (int64_t)taosMemoryCalloc(1, (size_t)(pColFilter->len + 1 * TSDB_NCHAR_SIZE)); // note: null-terminator - if (pColFilter->pz == 0) { - return TSDB_CODE_QRY_OUT_OF_MEMORY; - } - - memcpy((void*)pColFilter->pz, (*pMsg), (size_t)pColFilter->len); - (*pMsg) += (pColFilter->len + 1); - } else { - pColFilter->lowerBndi = htobe64(pFilterMsg->lowerBndi); - pColFilter->upperBndi = htobe64(pFilterMsg->upperBndi); - } - - pColFilter->lowerRelOptr = htons(pFilterMsg->lowerRelOptr); - pColFilter->upperRelOptr = htons(pFilterMsg->upperRelOptr); - } - - return TSDB_CODE_SUCCESS; -} - static SResSchema createResSchema(int32_t type, int32_t bytes, int32_t slotId, int32_t scale, int32_t precision, const char* name) { SResSchema s = {0}; - s.scale = scale; - s.type = type; - s.bytes = bytes; - s.colId = slotId; + s.scale = scale; + s.type = type; + s.bytes = bytes; + s.slotId = slotId; s.precision = precision; strncpy(s.name, name, tListLen(s.name)); @@ -6723,7 +6645,7 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* pTargetNode = (STargetNode*)nodesListGetNode(pGroupKeys, i - numOfFuncs); } - SExprInfo* pExp = &pExprs[pTargetNode->slotId]; + SExprInfo* pExp = &pExprs[i]; pExp->pExpr = taosMemoryCalloc(1, sizeof(tExprNode)); pExp->pExpr->_function.num = 1; @@ -6843,8 +6765,10 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo int32_t numOfCols = 0; tsdbReaderT pDataReader = doCreateDataReader((STableScanPhysiNode*)pPhyNode, pHandle, pTableGroupInfo, (uint64_t)queryId, taskId); SArray* pColList = extractColMatchInfo(pScanPhyNode->pScanCols, pScanPhyNode->node.pOutputDataBlockDesc, &numOfCols); + SSDataBlock* pResBlock = createOutputBuf_rv1(pScanPhyNode->node.pOutputDataBlockDesc); + return createTableScanOperatorInfo(pDataReader, pScanPhyNode->order, numOfCols, pScanPhyNode->count, - pScanPhyNode->reverse, pColList, pScanPhyNode->node.pConditions, pTaskInfo); + pScanPhyNode->reverse, pColList, pResBlock, pScanPhyNode->node.pConditions, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == type) { SExchangePhysiNode* pExchange = (SExchangePhysiNode*)pPhyNode; SSDataBlock* pResBlock = createOutputBuf_rv1(pExchange->node.pOutputDataBlockDesc); @@ -6899,9 +6823,15 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo SExprInfo* pExprInfo = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &num); SSDataBlock* pResBlock = createOutputBuf_rv1(pPhyNode->pOutputDataBlockDesc); + SExprInfo* pScalarExprInfo = NULL; + int32_t numOfScalarExpr = 0; if (pAggNode->pGroupKeys != NULL) { SArray* pColList = extractColumnInfo(pAggNode->pGroupKeys); - return createGroupOperatorInfo(op, pExprInfo, num, pResBlock, pColList, pAggNode->node.pConditions, pTaskInfo, NULL); + if (pAggNode->pExprs != NULL) { + pScalarExprInfo = createExprInfo(pAggNode->pExprs, NULL, &numOfScalarExpr); + } + + return createGroupOperatorInfo(op, pExprInfo, num, pResBlock, pColList, pAggNode->node.pConditions, pScalarExprInfo, numOfScalarExpr, pTaskInfo, NULL); } else { return createAggregateOperatorInfo(op, pExprInfo, num, pResBlock, pTaskInfo, pTableGroupInfo); } @@ -6920,7 +6850,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo .precision = pIntervalPhyNode->precision }; - int32_t primaryTsSlotId = ((SColumnNode*) pIntervalPhyNode->pTspk)->slotId; + int32_t primaryTsSlotId = ((SColumnNode*) pIntervalPhyNode->window.pTspk)->slotId; return createIntervalOperatorInfo(op, pExprInfo, num, pResBlock, &interval, primaryTsSlotId, pTableGroupInfo, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_SORT == type) { SSortPhysiNode* pSortPhyNode = (SSortPhysiNode*)pPhyNode; @@ -7148,10 +7078,15 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod } *numOfOutputCols = 0; - int32_t num = LIST_LENGTH(pOutputNodeList->pSlots); for (int32_t i = 0; i < num; ++i) { SSlotDescNode* pNode = (SSlotDescNode*)nodesListGetNode(pOutputNodeList->pSlots, i); + // todo: add reserve flag check + if (pNode->slotId >= numOfCols) { // it is a column reserved for the arithmetic expression calculation + (*numOfOutputCols) += 1; + continue; + } + SColMatchInfo* info = taosArrayGet(pList, pNode->slotId); if (pNode->output) { (*numOfOutputCols) += 1; diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 3eb8ff1b7242f666a43af4a89225e33034a91aeb..cd79d719dad44f51cfa407889c06837bdf56850b 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -46,7 +46,7 @@ static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** int32_t numOfGroupCols = taosArrayGetSize(pGroupColList); for (int32_t i = 0; i < numOfGroupCols; ++i) { SColumn* pCol = taosArrayGet(pGroupColList, i); - (*keyLen) += pCol->bytes; + (*keyLen) += pCol->bytes; // actual data + null_flag SGroupKeys key = {0}; key.bytes = pCol->bytes; @@ -61,8 +61,9 @@ static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** } int32_t nullFlagSize = sizeof(int8_t) * numOfGroupCols; + (*keyLen) += nullFlagSize; - (*keyBuf) = taosMemoryCalloc(1, (*keyLen) + nullFlagSize); + (*keyBuf) = taosMemoryCalloc(1, (*keyLen)); if ((*keyBuf) == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -165,15 +166,20 @@ static int32_t buildGroupKeys(void* pKey, const SArray* pGroupColVals) { // assign the group keys or user input constant values if required static void doAssignGroupKeys(SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t totalRows, int32_t rowIndex) { for (int32_t i = 0; i < numOfOutput; ++i) { - if (pCtx[i].functionId == -1) { + if (pCtx[i].functionId == -1) { // select count(*),key from t group by key. SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[i]); SColumnInfoData* pColInfoData = pCtx[i].input.pData[0]; + // todo OPT all/all not NULL if (!colDataIsNull(pColInfoData, totalRows, rowIndex, NULL)) { char* dest = GET_ROWCELL_INTERBUF(pEntryInfo); char* data = colDataGetData(pColInfoData, rowIndex); - memcpy(dest, data, pColInfoData->info.bytes); + if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { + varDataCopy(dest, data); + } else { + memcpy(dest, data, pColInfoData->info.bytes); + } } else { // it is a NULL value pEntryInfo->isNullRes = 1; } @@ -221,7 +227,7 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) { } len = buildGroupKeys(pInfo->keyBuf, pInfo->pGroupColVals); - int32_t ret = setGroupResultOutputBuf_rv(&(pInfo->binfo), pOperator->numOfOutput, pInfo->keyBuf, TSDB_DATA_TYPE_VARCHAR, len, 0, pInfo->aggSup.pResultBuf, pTaskInfo, &pInfo->aggSup); + int32_t ret = setGroupResultOutputBuf(&(pInfo->binfo), pOperator->numOfOutput, pInfo->keyBuf, TSDB_DATA_TYPE_VARCHAR, len, 0, pInfo->aggSup.pResultBuf, pTaskInfo, &pInfo->aggSup); if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR); } @@ -238,7 +244,7 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) { if (num > 0) { len = buildGroupKeys(pInfo->keyBuf, pInfo->pGroupColVals); int32_t ret = - setGroupResultOutputBuf_rv(&(pInfo->binfo), pOperator->numOfOutput, pInfo->keyBuf, TSDB_DATA_TYPE_VARCHAR, len, + setGroupResultOutputBuf(&(pInfo->binfo), pOperator->numOfOutput, pInfo->keyBuf, TSDB_DATA_TYPE_VARCHAR, len, 0, pInfo->aggSup.pResultBuf, pTaskInfo, &pInfo->aggSup); if (ret != TSDB_CODE_SUCCESS) { longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR); @@ -259,7 +265,7 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou SSDataBlock* pRes = pInfo->binfo.pRes; if (pOperator->status == OP_RES_TO_RETURN) { - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pRes, pInfo->binfo.capacity, pInfo->binfo.rowCellInfoOffset); + toSDatablock(pRes, pInfo->binfo.capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset); if (pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) { pOperator->status = OP_EXEC_DONE; } @@ -279,6 +285,12 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order); + + // there is an scalar expression that needs to be calculated before apply the group aggregation. + if (pInfo->pScalarExprInfo != NULL) { + projectApplyFunctions(pInfo->pScalarExprInfo, pBlock, pBlock, pInfo->pScalarFuncCtx, pInfo->numOfScalarExpr, NULL); + } + // setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->binfo.pCtx, pOperator->numOfOutput); doHashGroupbyAgg(pOperator, pBlock); } @@ -299,7 +311,7 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou initGroupResInfo(&pInfo->groupResInfo, &pInfo->binfo.resultRowInfo); while(1) { - toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pRes, pInfo->binfo.capacity, pInfo->binfo.rowCellInfoOffset); + toSDatablock(pRes, pInfo->binfo.capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset); doFilter(pInfo->pCondition, pRes); bool hasRemain = hasRemainDataInCurrentGroup(&pInfo->groupResInfo); @@ -316,28 +328,34 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou return (pRes->info.rows == 0)? NULL:pRes; } -SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList, SNode* pCondition, SExecTaskInfo* pTaskInfo, - const STableGroupInfo* pTableGroupInfo) { +SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList, + SNode* pCondition, SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo) { SGroupbyOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SGroupbyOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } - pInfo->pGroupCols = pGroupColList; - pInfo->pCondition = pCondition; - initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, 4096, pResultBlock, pTaskInfo->id.str); - initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); + pInfo->pGroupCols = pGroupColList; + pInfo->pCondition = pCondition; + + pInfo->pScalarExprInfo = pScalarExprInfo; + pInfo->numOfScalarExpr = numOfScalarExpr; + pInfo->pScalarFuncCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pInfo->binfo.rowCellInfoOffset); + int32_t code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pGroupColList); if (code != TSDB_CODE_SUCCESS) { goto _error; } + initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfCols, 4096, pResultBlock, pInfo->groupKeyLen, pTaskInfo->id.str); + initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); + pOperator->name = "GroupbyAggOperator"; pOperator->blockingOptr = true; pOperator->status = OP_NOT_OPENED; - // pOperator->operatorType = OP_Groupby; + // pOperator->operatorType = OP_Groupby; pOperator->pExpr = pExprInfo; pOperator->numOfOutput = numOfCols; pOperator->info = pInfo; @@ -345,6 +363,8 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx pOperator->_openFn = operatorDummyOpenFn; pOperator->getNextFn = hashGroupbyAggregate; pOperator->closeFn = destroyGroupOperatorInfo; + pOperator->encodeResultRow = aggEncodeResultRow; + pOperator->decodeResultRow = aggDecodeResultRow; code = appendDownstream(pOperator, &downstream, 1); return pOperator; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 4179999c4b9f892fc6806f045cd513d2b6594211..0286b6e6e9803545720e9be7947a53e7e5134d3e 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -113,7 +113,7 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator, bool* newgroup) { STableScanInfo* pTableScanInfo = pOperator->info; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - SSDataBlock* pBlock = &pTableScanInfo->block; + SSDataBlock* pBlock = pTableScanInfo->pResBlock; STableGroupInfo* pTableGroupInfo = &pOperator->pTaskInfo->tableqinfoGroupInfo; *newgroup = false; @@ -218,7 +218,7 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) { } SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput, - int32_t repeatTime, int32_t reverseTime, SArray* pColMatchInfo, + int32_t repeatTime, int32_t reverseTime, SArray* pColMatchInfo, SSDataBlock* pResBlock, SNode* pCondition, SExecTaskInfo* pTaskInfo) { assert(repeatTime > 0); @@ -232,12 +232,7 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, return NULL; } - pInfo->block.pDataBlock = taosArrayInit(numOfOutput, sizeof(SColumnInfoData)); - for (int32_t i = 0; i < numOfOutput; ++i) { - SColumnInfoData idata = {0}; - taosArrayPush(pInfo->block.pDataBlock, &idata); - } - + pInfo->pResBlock = pResBlock; pInfo->pFilterNode = pCondition; pInfo->dataReader = pTsdbReadHandle; pInfo->times = repeatTime; @@ -263,16 +258,14 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, return pOperator; } -SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv) { +SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle) { STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); pInfo->dataReader = pTsdbReadHandle; pInfo->times = 1; pInfo->reverseTimes = 0; - pInfo->order = pRuntimeEnv->pQueryAttr->order.order; pInfo->current = 0; pInfo->prevGroupId = -1; - pRuntimeEnv->enableGroupData = true; SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); pOperator->name = "TableSeqScanOperator"; @@ -280,8 +273,6 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntim pOperator->blockingOptr = false; pOperator->status = OP_NOT_OPENED; pOperator->info = pInfo; - pOperator->numOfOutput = pRuntimeEnv->pQueryAttr->numOfCols; - pOperator->pRuntimeEnv = pRuntimeEnv; pOperator->getNextFn = doTableScanImpl; return pOperator; @@ -312,7 +303,7 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator, bool* newgroup) { tsdbGetFileBlocksDistInfo(pTableScanInfo->dataReader, &tableBlockDist); tableBlockDist.numOfRowsInMemTable = (int32_t) tsdbGetNumOfRowsInMemTable(pTableScanInfo->dataReader); - SSDataBlock* pBlock = &pTableScanInfo->block; + SSDataBlock* pBlock = pTableScanInfo->pResBlock; pBlock->info.rows = 1; pBlock->info.numOfCols = 1; @@ -343,13 +334,13 @@ SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo* } pInfo->dataReader = dataReader; - pInfo->block.pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); +// pInfo->block.pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); SColumnInfoData infoData = {0}; infoData.info.type = TSDB_DATA_TYPE_BINARY; infoData.info.bytes = 1024; infoData.info.colId = 0; - taosArrayPush(pInfo->block.pDataBlock, &infoData); +// taosArrayPush(pInfo->block.pDataBlock, &infoData); pOperator->name = "DataBlockInfoScanOperator"; // pOperator->operatorType = OP_TableBlockInfoScan; @@ -548,7 +539,7 @@ EDealRes getDBNameFromConditionWalker(SNode* pNode, void* pContext) { char* dbName = nodesGetValueFromNode(node); strncpy(pContext, varDataVal(dbName), varDataLen(dbName)); *((char*)pContext + varDataLen(dbName)) = 0; - return DEAL_RES_ERROR; // stop walk + return DEAL_RES_END; // stop walk } default: break; @@ -599,7 +590,7 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) { bool keep = filterExecute(filter, pInfo->pRes, &rowRes, NULL, param1.numOfCols); filterFreeInfo(filter); - SSDataBlock* px = createOneDataBlock(pInfo->pRes); + SSDataBlock* px = createOneDataBlock(pInfo->pRes, false); blockDataEnsureCapacity(px, pInfo->pRes->info.rows); // TODO refactor @@ -688,65 +679,70 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) { return NULL; } - int64_t startTs = taosGetTimestampUs(); + while (1) { + int64_t startTs = taosGetTimestampUs(); - pInfo->req.type = pInfo->type; - strncpy(pInfo->req.tb, tNameGetTableName(&pInfo->name), tListLen(pInfo->req.tb)); - if (pInfo->showRewrite) { - char dbName[TSDB_DB_NAME_LEN] = {0}; - getDBNameFromCondition(pInfo->pCondition, dbName); - sprintf(pInfo->req.db, "%d.%s", pInfo->accountId, dbName); - } + pInfo->req.type = pInfo->type; + strncpy(pInfo->req.tb, tNameGetTableName(&pInfo->name), tListLen(pInfo->req.tb)); - int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &pInfo->req); - char* buf1 = taosMemoryCalloc(1, contLen); - tSerializeSRetrieveTableReq(buf1, contLen, &pInfo->req); + if (pInfo->showRewrite) { + char dbName[TSDB_DB_NAME_LEN] = {0}; + getDBNameFromCondition(pInfo->pCondition, dbName); + sprintf(pInfo->req.db, "%d.%s", pInfo->accountId, dbName); + } - // send the fetch remote task result reques - SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); - if (NULL == pMsgSendInfo) { - qError("%s prepare message %d failed", GET_TASKID(pTaskInfo), (int32_t)sizeof(SMsgSendInfo)); - pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY; - return NULL; - } + int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &pInfo->req); + char* buf1 = taosMemoryCalloc(1, contLen); + tSerializeSRetrieveTableReq(buf1, contLen, &pInfo->req); - pMsgSendInfo->param = pOperator; - pMsgSendInfo->msgInfo.pData = buf1; - pMsgSendInfo->msgInfo.len = contLen; - pMsgSendInfo->msgType = TDMT_MND_SYSTABLE_RETRIEVE; - pMsgSendInfo->fp = loadSysTableContentCb; + // send the fetch remote task result reques + SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); + if (NULL == pMsgSendInfo) { + qError("%s prepare message %d failed", GET_TASKID(pTaskInfo), (int32_t)sizeof(SMsgSendInfo)); + pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY; + return NULL; + } - int64_t transporterId = 0; - int32_t code = asyncSendMsgToServer(pInfo->pTransporter, &pInfo->epSet, &transporterId, pMsgSendInfo); - tsem_wait(&pInfo->ready); + pMsgSendInfo->param = pOperator; + pMsgSendInfo->msgInfo.pData = buf1; + pMsgSendInfo->msgInfo.len = contLen; + pMsgSendInfo->msgType = TDMT_MND_SYSTABLE_RETRIEVE; + pMsgSendInfo->fp = loadSysTableContentCb; - if (pTaskInfo->code) { - return NULL; - } + int64_t transporterId = 0; + int32_t code = asyncSendMsgToServer(pInfo->pTransporter, &pInfo->epSet, &transporterId, pMsgSendInfo); + tsem_wait(&pInfo->ready); - SRetrieveMetaTableRsp* pRsp = pInfo->pRsp; - pInfo->req.showId = pRsp->handle; + if (pTaskInfo->code) { + qDebug("%s load meta data from mnode failed, totalRows:%" PRIu64 ", code:%s", GET_TASKID(pTaskInfo), + pInfo->loadInfo.totalRows, tstrerror(pTaskInfo->code)); + return NULL; + } - if (pRsp->numOfRows == 0 || pRsp->completed) { - pOperator->status = OP_EXEC_DONE; - } + SRetrieveMetaTableRsp* pRsp = pInfo->pRsp; + pInfo->req.showId = pRsp->handle; - if (pRsp->numOfRows == 0) { - // qDebug("%s vgId:%d, taskID:0x%"PRIx64" %d of total completed, rowsOfSource:%"PRIu64", totalRows:%"PRIu64" - // try next", - // GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pExchangeInfo->current + 1, - // pDataInfo->totalRows, pExchangeInfo->totalRows); - return NULL; - } + if (pRsp->numOfRows == 0 || pRsp->completed) { + pOperator->status = OP_EXEC_DONE; + qDebug("%s load meta data from mnode completed, rowsOfSource:%d, totalRows:%" PRIu64 " ", GET_TASKID(pTaskInfo), + pRsp->numOfRows, pInfo->loadInfo.totalRows); - SRetrieveMetaTableRsp* pTableRsp = pInfo->pRsp; - setSDataBlockFromFetchRsp(pInfo->pRes, &pInfo->loadInfo, pTableRsp->numOfRows, pTableRsp->data, pTableRsp->compLen, - pOperator->numOfOutput, startTs, NULL, pInfo->scanCols); + if (pRsp->numOfRows == 0) { + return NULL; + } + } - return doFilterResult(pInfo); - } + SRetrieveMetaTableRsp* pTableRsp = pInfo->pRsp; + setSDataBlockFromFetchRsp(pInfo->pRes, &pInfo->loadInfo, pTableRsp->numOfRows, pTableRsp->data, + pTableRsp->compLen, pOperator->numOfOutput, startTs, NULL, pInfo->scanCols); - return NULL; + // todo log the filter info + doFilterResult(pInfo); + if (pInfo->pRes->info.rows > 0) { + return pInfo->pRes; + } + } + } } SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataBlock* pResBlock, const SName* pName, @@ -761,21 +757,17 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB return NULL; } - pInfo->accountId = accountId; + pInfo->accountId = accountId; pInfo->showRewrite = showRewrite; - pInfo->pRes = pResBlock; - pInfo->capacity = 4096; - pInfo->pCondition = pCondition; - pInfo->scanCols = colList; + pInfo->pRes = pResBlock; + pInfo->capacity = 4096; + pInfo->pCondition = pCondition; + pInfo->scanCols = colList; // TODO remove it int32_t tableType = 0; const char* name = tNameGetTableName(pName); - if (strncasecmp(name, TSDB_INS_TABLE_USER_DATABASES, tListLen(pName->tname)) == 0) { - tableType = TSDB_MGMT_TABLE_DB; - } else if (strncasecmp(name, TSDB_INS_TABLE_USER_USERS, tListLen(pName->tname)) == 0) { - tableType = TSDB_MGMT_TABLE_USER; - } else if (strncasecmp(name, TSDB_INS_TABLE_DNODES, tListLen(pName->tname)) == 0) { + if (strncasecmp(name, TSDB_INS_TABLE_DNODES, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_DNODE; } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_MNODE; @@ -783,10 +775,14 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB tableType = TSDB_MGMT_TABLE_MODULE; } else if (strncasecmp(name, TSDB_INS_TABLE_QNODES, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_QNODE; - } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, tListLen(pName->tname)) == 0) { - tableType = TSDB_MGMT_TABLE_SNODE; } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_BNODE; + } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_SNODE; + } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_CLUSTER; + } else if (strncasecmp(name, TSDB_INS_TABLE_USER_DATABASES, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_DB; } else if (strncasecmp(name, TSDB_INS_TABLE_USER_FUNCTIONS, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_FUNC; } else if (strncasecmp(name, TSDB_INS_TABLE_USER_INDEXES, tListLen(pName->tname)) == 0) { @@ -797,11 +793,33 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB tableType = TSDB_MGMT_TABLE_STREAMS; } else if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLES, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_TABLE; - } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, tListLen(pName->tname)) == 0) { - tableType = TSDB_MGMT_TABLE_VGROUP; } else if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED, tListLen(pName->tname)) == 0) { // tableType = TSDB_MGMT_TABLE_DIST; - } else { + } else if (strncasecmp(name, TSDB_INS_TABLE_USER_USERS, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_USER; + } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_GRANTS; + } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_VGROUP; + } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_TOPICS; + } else if (strncasecmp(name, TSDB_INS_TABLE_CONSUMERS, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_CONSUMERS; + } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIBES, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_SUBSCRIBES; + } else if (strncasecmp(name, TSDB_INS_TABLE_TRANS, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_TRANS; + } else if (strncasecmp(name, TSDB_INS_TABLE_SMAS, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_SMAS; + } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_CONFIGS; + } else if (strncasecmp(name, TSDB_INS_TABLE_CONNS, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_CONNS; + } else if (strncasecmp(name, TSDB_INS_TABLE_QUERIES, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_QUERIES; + } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_VNODES; + }else { ASSERT(0); } @@ -838,15 +856,15 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB #endif } - pOperator->name = "SysTableScanOperator"; + pOperator->name = "SysTableScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN; pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfOutput = pResBlock->info.numOfCols; - pOperator->getNextFn = doSysTableScan; - pOperator->closeFn = destroySysScanOperator; - pOperator->pTaskInfo = pTaskInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfOutput = pResBlock->info.numOfCols; + pOperator->getNextFn = doSysTableScan; + pOperator->closeFn = destroySysScanOperator; + pOperator->pTaskInfo = pTaskInfo; return pOperator; } diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 885112d440aac01f5bdfad1018fd5bb2ca5feac7..2ac28200e79d3b365fc75d055f785e0a99963355 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -99,7 +99,7 @@ SSortHandle* tsortCreateSortHandle(SArray* pSortInfo, SArray* pIndexMap, int32_t pSortHandle->numOfPages = numOfPages; pSortHandle->pSortInfo = pSortInfo; pSortHandle->pIndexMap = pIndexMap; - pSortHandle->pDataBlock = createOneDataBlock(pBlock); + pSortHandle->pDataBlock = createOneDataBlock(pBlock, false); pSortHandle->pOrderedSource = taosArrayInit(4, POINTER_BYTES); pSortHandle->cmpParam.orderInfo = pSortInfo; @@ -206,7 +206,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { blockDataCleanup(pDataBlock); - SSDataBlock* pBlock = createOneDataBlock(pDataBlock); + SSDataBlock* pBlock = createOneDataBlock(pDataBlock, false); return doAddNewExternalMemSource(pHandle->pBuf, pHandle->pOrderedSource, pBlock, &pHandle->sourceId); } @@ -488,7 +488,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { tMergeTreeDestroy(pHandle->pMergeTree); pHandle->numOfCompletedSources = 0; - SSDataBlock* pBlock = createOneDataBlock(pHandle->pDataBlock); + SSDataBlock* pBlock = createOneDataBlock(pHandle->pDataBlock, false); code = doAddNewExternalMemSource(pHandle->pBuf, pResList, pBlock, &pHandle->sourceId); if (code != 0) { return code; @@ -531,7 +531,7 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) { } if (pHandle->pDataBlock == NULL) { - pHandle->pDataBlock = createOneDataBlock(pBlock); + pHandle->pDataBlock = createOneDataBlock(pBlock, false); } int32_t code = blockDataMerge(pHandle->pDataBlock, pBlock, pHandle->pIndexMap); diff --git a/source/libs/function/inc/builtins.h b/source/libs/function/inc/builtins.h index 2c0148e04fbe44c94ecba4c0d54a21793819bb98..814076fc349d20579365e28660021d76f08d1d6e 100644 --- a/source/libs/function/inc/builtins.h +++ b/source/libs/function/inc/builtins.h @@ -22,29 +22,33 @@ extern "C" { #include "functionMgt.h" -#define FUNCTION_NAME_MAX_LENGTH 16 +#define FUNCTION_NAME_MAX_LENGTH 32 #define FUNC_MGT_FUNC_CLASSIFICATION_MASK(n) (1 << n) -#define FUNC_MGT_AGG_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(0) -#define FUNC_MGT_SCALAR_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(1) -#define FUNC_MGT_NONSTANDARD_SQL_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(2) -#define FUNC_MGT_STRING_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(3) -#define FUNC_MGT_DATETIME_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(4) -#define FUNC_MGT_TIMELINE_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(5) -#define FUNC_MGT_TIMEORDER_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(6) -#define FUNC_MGT_PSEUDO_COLUMN_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(7) -#define FUNC_MGT_WINDOW_PC_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(8) +#define FUNC_MGT_AGG_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(0) +#define FUNC_MGT_SCALAR_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(1) +#define FUNC_MGT_NONSTANDARD_SQL_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(2) +#define FUNC_MGT_STRING_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(3) +#define FUNC_MGT_DATETIME_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(4) +#define FUNC_MGT_TIMELINE_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(5) +#define FUNC_MGT_TIMEORDER_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(6) +#define FUNC_MGT_PSEUDO_COLUMN_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(7) +#define FUNC_MGT_WINDOW_PC_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(8) +#define FUNC_MGT_SPECIAL_DATA_REQUIRED FUNC_MGT_FUNC_CLASSIFICATION_MASK(9) +#define FUNC_MGT_DYNAMIC_SCAN_OPTIMIZED FUNC_MGT_FUNC_CLASSIFICATION_MASK(10) #define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0) -typedef int32_t (*FCheckAndGetResultType)(SFunctionNode* pFunc); +typedef int32_t (*FTranslateFunc)(SFunctionNode* pFunc, char* pErrBuf, int32_t len); +typedef EFuncDataRequired (*FFuncDataRequired)(SFunctionNode* pFunc, STimeWindow* pTimeWindow); typedef struct SBuiltinFuncDefinition { char name[FUNCTION_NAME_MAX_LENGTH]; EFunctionType type; uint64_t classification; - FCheckAndGetResultType checkFunc; + FTranslateFunc translateFunc; + FFuncDataRequired dataRequiredFunc; FExecGetEnv getEnvFunc; FExecInit initFunc; FExecProcess processFunc; diff --git a/source/libs/function/inc/builtinsimpl.h b/source/libs/function/inc/builtinsimpl.h index 607bd279c15137550c5f3d738d463670b910e8fd..09c468b61037607a537a04385f88c189374370bb 100644 --- a/source/libs/function/inc/builtinsimpl.h +++ b/source/libs/function/inc/builtinsimpl.h @@ -21,10 +21,12 @@ extern "C" { #endif #include "function.h" +#include "functionMgt.h" bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); void functionFinalize(SqlFunctionCtx *pCtx); +EFuncDataRequired countDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow); bool getCountFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); int32_t countFunction(SqlFunctionCtx *pCtx); diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index aa7343f610c9a247cd69c54cf2d2b41892c48edb..49504b2cd4af16b1052a2b10ae65f5603c125b07 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -19,14 +19,364 @@ #include "taoserror.h" #include "tdatablock.h" -int32_t stubCheckAndGetResultType(SFunctionNode* pFunc); +static int32_t buildFuncErrMsg(char* pErrBuf, int32_t len, int32_t errCode, const char* pFormat, ...) { + va_list vArgList; + va_start(vArgList, pFormat); + vsnprintf(pErrBuf, len, pFormat, vArgList); + va_end(vArgList); + return errCode; +} + +static int32_t invaildFuncParaNumErrMsg(char* pErrBuf, int32_t len, const char* pFuncName) { + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_PARA_NUM, "Invalid number of arguments : %s", pFuncName); +} + +static int32_t invaildFuncParaTypeErrMsg(char* pErrBuf, int32_t len, const char* pFuncName) { + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_PARA_TYPE, "Inconsistent datatypes : %s", pFuncName); +} + +// There is only one parameter of numeric type, and the return type is parameter type +static int32_t translateInOutNum(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + if (!IS_NUMERIC_TYPE(paraType)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType }; + return TSDB_CODE_SUCCESS; +} + +// There is only one parameter of numeric type, and the return type is double type +static int32_t translateInNumOutDou(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + if (!IS_NUMERIC_TYPE(paraType)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + return TSDB_CODE_SUCCESS; +} + +// There are two parameters of numeric type, and the return type is double type +static int32_t translateIn2NumOutDou(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (2 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + if (!IS_NUMERIC_TYPE(para1Type) || !IS_NUMERIC_TYPE(para2Type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + return TSDB_CODE_SUCCESS; +} + +// There is only one parameter of string type, and the return type is parameter type +static int32_t translateInOutStr(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + SExprNode* pPara1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); + if (!IS_VAR_DATA_TYPE(pPara1->resType.type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = pPara1->resType.bytes, .type = pPara1->resType.type }; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateCount(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_BIGINT}; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateSum(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + if (!IS_NUMERIC_TYPE(paraType)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t resType = 0; + if (IS_SIGNED_NUMERIC_TYPE(paraType) || paraType == TSDB_DATA_TYPE_BOOL) { + resType = TSDB_DATA_TYPE_BIGINT; + } else if (IS_UNSIGNED_NUMERIC_TYPE(paraType)) { + resType = TSDB_DATA_TYPE_UBIGINT; + } else if (IS_FLOAT_TYPE(paraType)) { + resType = TSDB_DATA_TYPE_DOUBLE; + } + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[resType].bytes, .type = resType }; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateWduration(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + // pseudo column do not need to check parameters + pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_BIGINT}; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateTimePseudoColumn(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + // pseudo column do not need to check parameters + pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_TIMESTAMP}; + return TSDB_CODE_SUCCESS; +} + +static int32_t translatePercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (2 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + if (!IS_NUMERIC_TYPE(para1Type) || (!IS_SIGNED_NUMERIC_TYPE(para2Type) && !IS_UNSIGNED_NUMERIC_TYPE(para2Type))) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + return TSDB_CODE_SUCCESS; +} + +static bool validAperventileAlgo(const SValueNode* pVal) { + if (TSDB_DATA_TYPE_BINARY != pVal->node.resType.type) { + return false; + } + return (0 == strcasecmp(varDataVal(pVal->datum.p), "default") || 0 == strcasecmp(varDataVal(pVal->datum.p), "t-digest")); +} + +static int32_t translateApercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + int32_t paraNum = LIST_LENGTH(pFunc->pParameterList); + if (2 != paraNum && 3 != paraNum) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + if (!IS_NUMERIC_TYPE(para1Type) || !IS_INTEGER_TYPE(para2Type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + if (3 == paraNum) { + SNode* pPara3 = nodesListGetNode(pFunc->pParameterList, 2); + if (QUERY_NODE_VALUE != nodeType(pPara3) || !validAperventileAlgo((SValueNode*)pPara3)) { + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "Third parameter algorithm of apercentile must be 'default' or 't-digest'"); + } + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateTop(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + // todo + return TSDB_CODE_SUCCESS; +} + +static int32_t translateBottom(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + // todo + return TSDB_CODE_SUCCESS; +} + +static int32_t translateSpread(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + // todo + return TSDB_CODE_SUCCESS; +} + +static int32_t translateLastRow(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + // todo + return TSDB_CODE_SUCCESS; +} + +static int32_t translateFirstLast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + // first(*)/first(col_list) has been rewritten as first(col) + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0); + if (QUERY_NODE_COLUMN != nodeType(pPara)) { + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "The parameters of first/last can only be columns"); + } + + uint8_t paraType = ((SExprNode*)pPara)->resType.type; + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType }; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateLength(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + if (!IS_VAR_DATA_TYPE(((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_SMALLINT].bytes, .type = TSDB_DATA_TYPE_SMALLINT }; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, int32_t minParaNum, int32_t maxParaNum, int32_t primaryParaNo) { + int32_t paraNum = LIST_LENGTH(pFunc->pParameterList); + if (paraNum < minParaNum || paraNum > maxParaNum) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t resultType = TSDB_DATA_TYPE_NCHAR; + int32_t resultBytes = 0; + int32_t sepBytes = 0; + for (int32_t i = 0; i < LIST_LENGTH(pFunc->pParameterList); ++i) { + SNode* pPara = nodesListGetNode(pFunc->pParameterList, i); + uint8_t paraType = ((SExprNode*)pPara)->resType.type; + int32_t paraBytes = ((SExprNode*)pPara)->resType.bytes; + if (!IS_VAR_DATA_TYPE(paraType)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + if (i < primaryParaNo) { + sepBytes = paraBytes; + continue; + } + if (TSDB_DATA_TYPE_BINARY == paraType) { + resultType = TSDB_DATA_TYPE_BINARY; + } + resultBytes += paraBytes; + } + if (sepBytes > 0) { + resultBytes += sepBytes * (paraNum - 2); + } + + pFunc->node.resType = (SDataType) { .bytes = resultBytes, .type = resultType }; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateConcat(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + return translateConcatImpl(pFunc, pErrBuf, len, 2, 8, 0); +} + +static int32_t translateConcatWs(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + return translateConcatImpl(pFunc, pErrBuf, len, 3, 9, 1); +} + +static int32_t translateSubstr(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + int32_t paraNum = LIST_LENGTH(pFunc->pParameterList); + if (2 != paraNum && 3 != paraNum) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + SExprNode* pPara1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); + uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + if (!IS_VAR_DATA_TYPE(pPara1->resType.type) || !IS_INTEGER_TYPE(para2Type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + if (3 == paraNum) { + uint8_t para3Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + if (!IS_INTEGER_TYPE(para3Type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + } + + pFunc->node.resType = (SDataType) { .bytes = pPara1->resType.bytes, .type = pPara1->resType.type }; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateCast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + // The number of parameters has been limited by the syntax definition + uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + // The function return type has been set during syntax parsing + uint8_t para2Type = pFunc->node.resType.type; + if ((TSDB_DATA_TYPE_JSON == para1Type || TSDB_DATA_TYPE_BLOB == para1Type || TSDB_DATA_TYPE_MEDIUMBLOB == para1Type) || + (TSDB_DATA_TYPE_JSON == para2Type || TSDB_DATA_TYPE_BLOB == para2Type || TSDB_DATA_TYPE_MEDIUMBLOB == para2Type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + return TSDB_CODE_SUCCESS; +} + +static int32_t translateToIso8601(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + if (!IS_VAR_DATA_TYPE(paraType) && TSDB_DATA_TYPE_TIMESTAMP != paraType) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = 64, .type = TSDB_DATA_TYPE_BINARY}; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateToUnixtimestamp(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + if (!IS_VAR_DATA_TYPE(((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (2 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + if ((!IS_VAR_DATA_TYPE(para1Type) && TSDB_DATA_TYPE_TIMESTAMP != para1Type) || !IS_INTEGER_TYPE(para2Type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP}; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + int32_t paraNum = LIST_LENGTH(pFunc->pParameterList); + if (2 != paraNum && 3 != paraNum) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + if ((!IS_VAR_DATA_TYPE(para1Type) && TSDB_DATA_TYPE_TIMESTAMP != para1Type) || + (!IS_VAR_DATA_TYPE(para2Type) && TSDB_DATA_TYPE_TIMESTAMP != para2Type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + if (3 == paraNum) { + if (!IS_INTEGER_TYPE(((SExprNode*)nodesListGetNode(pFunc->pParameterList, 2))->resType.type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; + return TSDB_CODE_SUCCESS; +} const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "count", .type = FUNCTION_TYPE_COUNT, - .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, + .translateFunc = translateCount, + .dataRequiredFunc = countDataRequired, .getEnvFunc = getCountFuncEnv, .initFunc = functionSetup, .processFunc = countFunction, @@ -36,7 +386,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "sum", .type = FUNCTION_TYPE_SUM, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateSum, .getEnvFunc = getSumFuncEnv, .initFunc = functionSetup, .processFunc = sumFunction, @@ -46,7 +396,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "min", .type = FUNCTION_TYPE_MIN, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInOutNum, .getEnvFunc = getMinmaxFuncEnv, .initFunc = minFunctionSetup, .processFunc = minFunction, @@ -56,7 +406,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "max", .type = FUNCTION_TYPE_MAX, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInOutNum, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -66,7 +416,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "stddev", .type = FUNCTION_TYPE_STDDEV, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInNumOutDou, .getEnvFunc = getStddevFuncEnv, .initFunc = stddevFunctionSetup, .processFunc = stddevFunction, @@ -76,7 +426,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "percentile", .type = FUNCTION_TYPE_PERCENTILE, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translatePercentile, .getEnvFunc = getPercentileFuncEnv, .initFunc = percentileFunctionSetup, .processFunc = percentileFunction, @@ -86,7 +436,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "apercentile", .type = FUNCTION_TYPE_APERCENTILE, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateApercentile, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -96,7 +446,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "top", .type = FUNCTION_TYPE_TOP, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateTop, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -106,7 +456,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "bottom", .type = FUNCTION_TYPE_BOTTOM, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateBottom, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -116,7 +466,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "spread", .type = FUNCTION_TYPE_SPREAD, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateSpread, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -126,7 +476,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "last_row", .type = FUNCTION_TYPE_LAST_ROW, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateLastRow, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -136,7 +486,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "first", .type = FUNCTION_TYPE_FIRST, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateFirstLast, .getEnvFunc = getFirstLastFuncEnv, .initFunc = functionSetup, .processFunc = firstFunction, @@ -146,7 +496,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "last", .type = FUNCTION_TYPE_LAST, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateFirstLast, .getEnvFunc = getFirstLastFuncEnv, .initFunc = functionSetup, .processFunc = lastFunction, @@ -156,7 +506,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "diff", .type = FUNCTION_TYPE_DIFF, .classification = FUNC_MGT_NONSTANDARD_SQL_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInOutNum, .getEnvFunc = getDiffFuncEnv, .initFunc = diffFunctionSetup, .processFunc = diffFunction, @@ -166,7 +516,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "abs", .type = FUNCTION_TYPE_ABS, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInOutNum, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = absFunction, @@ -176,7 +526,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "log", .type = FUNCTION_TYPE_LOG, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateIn2NumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = logFunction, @@ -186,7 +536,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "pow", .type = FUNCTION_TYPE_POW, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateIn2NumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = powFunction, @@ -196,7 +546,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "sqrt", .type = FUNCTION_TYPE_SQRT, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInNumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = sqrtFunction, @@ -206,7 +556,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "ceil", .type = FUNCTION_TYPE_CEIL, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInOutNum, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = ceilFunction, @@ -216,7 +566,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "floor", .type = FUNCTION_TYPE_FLOOR, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInOutNum, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = floorFunction, @@ -226,7 +576,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "round", .type = FUNCTION_TYPE_ROUND, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInOutNum, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = roundFunction, @@ -236,7 +586,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "sin", .type = FUNCTION_TYPE_SIN, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInNumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = sinFunction, @@ -246,7 +596,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "cos", .type = FUNCTION_TYPE_COS, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInNumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = cosFunction, @@ -256,7 +606,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "tan", .type = FUNCTION_TYPE_TAN, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInNumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = tanFunction, @@ -266,7 +616,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "asin", .type = FUNCTION_TYPE_ASIN, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInNumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = asinFunction, @@ -276,7 +626,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "acos", .type = FUNCTION_TYPE_ACOS, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInNumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = acosFunction, @@ -286,7 +636,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "atan", .type = FUNCTION_TYPE_ATAN, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInNumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = atanFunction, @@ -296,7 +646,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "length", .type = FUNCTION_TYPE_LENGTH, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateLength, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = lengthFunction, @@ -306,7 +656,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "char_length", .type = FUNCTION_TYPE_CHAR_LENGTH, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateLength, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = charLengthFunction, @@ -316,7 +666,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "concat", .type = FUNCTION_TYPE_CONCAT, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateConcat, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = concatFunction, @@ -326,7 +676,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "concat_ws", .type = FUNCTION_TYPE_CONCAT_WS, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateConcatWs, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = concatWsFunction, @@ -336,7 +686,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "lower", .type = FUNCTION_TYPE_LOWER, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInOutStr, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = lowerFunction, @@ -346,7 +696,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "upper", .type = FUNCTION_TYPE_UPPER, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInOutStr, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = upperFunction, @@ -356,7 +706,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "ltrim", .type = FUNCTION_TYPE_LTRIM, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInOutStr, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = ltrimFunction, @@ -366,7 +716,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "rtrim", .type = FUNCTION_TYPE_RTRIM, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateInOutStr, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = rtrimFunction, @@ -376,7 +726,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "substr", .type = FUNCTION_TYPE_SUBSTR, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateSubstr, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = substrFunction, @@ -386,17 +736,57 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "cast", .type = FUNCTION_TYPE_CAST, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateCast, .getEnvFunc = NULL, .initFunc = NULL, - .sprocessFunc = NULL, + .sprocessFunc = castFunction, + .finalizeFunc = NULL + }, + { + .name = "to_iso8601", + .type = FUNCTION_TYPE_TO_ISO8601, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateToIso8601, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = toISO8601Function, + .finalizeFunc = NULL + }, + { + .name = "to_unixtimestamp", + .type = FUNCTION_TYPE_TO_UNIXTIMESTAMP, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateToUnixtimestamp, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = toUnixtimestampFunction, + .finalizeFunc = NULL + }, + { + .name = "timetruncate", + .type = FUNCTION_TYPE_TIMETRUNCATE, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateTimeTruncate, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = timeTruncateFunction, + .finalizeFunc = NULL + }, + { + .name = "timediff", + .type = FUNCTION_TYPE_TIMEDIFF, + .classification = FUNC_MGT_SCALAR_FUNC, + .translateFunc = translateTimeDiff, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = timeDiffFunction, .finalizeFunc = NULL }, { .name = "_rowts", .type = FUNCTION_TYPE_ROWTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateTimePseudoColumn, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = NULL, @@ -406,7 +796,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "tbname", .type = FUNCTION_TYPE_TBNAME, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = NULL, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = NULL, @@ -416,7 +806,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_qstartts", .type = FUNCTION_TYPE_QSTARTTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateTimePseudoColumn, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = qStartTsFunction, @@ -426,7 +816,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_qendts", .type = FUNCTION_TYPE_QENDTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateTimePseudoColumn, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = qEndTsFunction, @@ -436,7 +826,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_wstartts", .type = FUNCTION_TYPE_WSTARTTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateTimePseudoColumn, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = winStartTsFunction, @@ -446,7 +836,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_wendts", .type = FUNCTION_TYPE_QENDTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateTimePseudoColumn, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = winEndTsFunction, @@ -456,7 +846,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_wduration", .type = FUNCTION_TYPE_WDURATION, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateWduration, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = winDurFunction, @@ -466,7 +856,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "now", .type = FUNCTION_TYPE_NOW, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC, - .checkFunc = stubCheckAndGetResultType, + .translateFunc = translateTimePseudoColumn, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = winDurFunction, @@ -475,145 +865,3 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { }; const int32_t funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition)); - -int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) { - switch(pFunc->funcType) { - case FUNCTION_TYPE_WDURATION: - case FUNCTION_TYPE_COUNT: { - pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_BIGINT}; - break; - } - - case FUNCTION_TYPE_SUM: { - SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0); - int32_t paraType = pParam->node.resType.type; - - int32_t resType = 0; - if (IS_SIGNED_NUMERIC_TYPE(paraType)) { - resType = TSDB_DATA_TYPE_BIGINT; - } else if (IS_UNSIGNED_NUMERIC_TYPE(paraType)) { - resType = TSDB_DATA_TYPE_UBIGINT; - } else if (IS_FLOAT_TYPE(paraType)) { - resType = TSDB_DATA_TYPE_DOUBLE; - } else { - ASSERT(0); - } - - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[resType].bytes, .type = resType }; - break; - } - - case FUNCTION_TYPE_DIFF: - case FUNCTION_TYPE_FIRST: - case FUNCTION_TYPE_LAST: - case FUNCTION_TYPE_MIN: - case FUNCTION_TYPE_MAX: { - SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0); - int32_t paraType = pParam->node.resType.type; - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType }; - break; - } - - case FUNCTION_TYPE_ROWTS: - case FUNCTION_TYPE_QSTARTTS: - case FUNCTION_TYPE_QENDTS: - case FUNCTION_TYPE_WSTARTTS: - case FUNCTION_TYPE_WENDTS:{ - pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_TIMESTAMP}; - break; - } - - case FUNCTION_TYPE_ABS: - case FUNCTION_TYPE_CEIL: - case FUNCTION_TYPE_FLOOR: - case FUNCTION_TYPE_ROUND: { - SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0); - int32_t paraType = pParam->node.resType.type; - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType }; - break; - } - - case FUNCTION_TYPE_PERCENTILE: - case FUNCTION_TYPE_STDDEV: - case FUNCTION_TYPE_SIN: - case FUNCTION_TYPE_COS: - case FUNCTION_TYPE_TAN: - case FUNCTION_TYPE_ASIN: - case FUNCTION_TYPE_ACOS: - case FUNCTION_TYPE_ATAN: - case FUNCTION_TYPE_SQRT: - case FUNCTION_TYPE_LOG: - case FUNCTION_TYPE_POW: { - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; - break; - } - - case FUNCTION_TYPE_LENGTH: - case FUNCTION_TYPE_CHAR_LENGTH: { - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_SMALLINT].bytes, .type = TSDB_DATA_TYPE_SMALLINT }; - break; - } - - case FUNCTION_TYPE_CONCAT: - case FUNCTION_TYPE_CONCAT_WS: { - int32_t paraType, paraBytes = 0; - bool typeSet = false; - for (int32_t i = 0; i < pFunc->pParameterList->length; ++i) { - SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, i); - if (pParam->node.type == QUERY_NODE_COLUMN) { - if (typeSet == false) { - paraType = pParam->node.resType.type; - typeSet = true; - } else { - //columns have to be the same type - if (paraType != pParam->node.resType.type) { - return TSDB_CODE_FAILED; - } - } - paraBytes += pParam->node.resType.bytes; - } - } - - for (int32_t i = 0; i < pFunc->pParameterList->length; ++i) { - SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, i); - if (pParam->node.type == QUERY_NODE_VALUE) { - if (paraType == TSDB_DATA_TYPE_NCHAR) { - paraBytes += pParam->node.resType.bytes * TSDB_NCHAR_SIZE; - } else { - paraBytes += pParam->node.resType.bytes; - } - } - } - pFunc->node.resType = (SDataType) { .bytes = paraBytes, .type = paraType }; - break; - } - case FUNCTION_TYPE_LOWER: - case FUNCTION_TYPE_UPPER: - case FUNCTION_TYPE_LTRIM: - case FUNCTION_TYPE_RTRIM: - case FUNCTION_TYPE_SUBSTR: { - SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0); - int32_t paraType = pParam->node.resType.type; - int32_t paraBytes = pParam->node.resType.bytes; - pFunc->node.resType = (SDataType) { .bytes = paraBytes, .type = paraType }; - break; - } - case FUNCTION_TYPE_CAST: { - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT }; - break; - } - - case FUNCTION_TYPE_TBNAME: { - // todo - break; - } - - case FUNCTION_TYPE_NOW: - // todo - break; - default: - ASSERT(0); // to found the fault ASAP. - } - - return TSDB_CODE_SUCCESS; -} diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index bad40422c8d1f8157442727b256eadfcc3a95aea..50c65439c0d1c29d6018dc691f74641381f20935 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -55,6 +55,14 @@ void functionFinalize(SqlFunctionCtx *pCtx) { pResInfo->isNullRes = (pResInfo->numOfRes == 0)? 1:0; } +EFuncDataRequired countDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) { + SNode* pParam = nodesListGetNode(pFunc->pParameterList, 0); + if (QUERY_NODE_COLUMN == nodeType(pParam) && PRIMARYKEY_TIMESTAMP_COL_ID == ((SColumnNode*)pParam)->colId) { + return FUNC_DATA_REQUIRED_NO_NEEDED; + } + return FUNC_DATA_REQUIRED_STATIS_NEEDED; +} + bool getCountFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { pEnv->calcMemSize = sizeof(int64_t); return true; @@ -138,8 +146,8 @@ int32_t sumFunction(SqlFunctionCtx *pCtx) { int32_t start = pInput->startRowIndex; int32_t numOfRows = pInput->numOfRows; - if (IS_SIGNED_NUMERIC_TYPE(type)) { - if (type == TSDB_DATA_TYPE_TINYINT) { + if (IS_SIGNED_NUMERIC_TYPE(type) || type == TSDB_DATA_TYPE_BOOL) { + if (type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_BOOL) { LIST_ADD_N(pSumRes->isum, pCol, start, numOfRows, int8_t, numOfElem); } else if (type == TSDB_DATA_TYPE_SMALLINT) { LIST_ADD_N(pSumRes->isum, pCol, start, numOfRows, int16_t, numOfElem); @@ -212,6 +220,9 @@ bool maxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { case TSDB_DATA_TYPE_UTINYINT: *((uint8_t *)buf) = 0; break; + case TSDB_DATA_TYPE_BOOL: + *((int8_t*)buf) = 0; + break; default: assert(0); } @@ -255,6 +266,9 @@ bool minFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) { case TSDB_DATA_TYPE_DOUBLE: SET_DOUBLE_VAL(((double *)buf), DBL_MAX); break; + case TSDB_DATA_TYPE_BOOL: + *((int8_t*)buf) = 1; + break; default: assert(0); } @@ -385,8 +399,8 @@ int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) { int32_t start = pInput->startRowIndex; int32_t numOfRows = pInput->numOfRows; - if (IS_SIGNED_NUMERIC_TYPE(type)) { - if (type == TSDB_DATA_TYPE_TINYINT) { + if (IS_SIGNED_NUMERIC_TYPE(type) || type == TSDB_DATA_TYPE_BOOL) { + if (type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_BOOL) { LOOPCHECK_N(*(int8_t*)buf, pCol, pCtx, int8_t, numOfRows, start, isMinFunc, numOfElems); } else if (type == TSDB_DATA_TYPE_SMALLINT) { LOOPCHECK_N(*(int16_t*) buf, pCol, pCtx, int16_t, numOfRows, start, isMinFunc, numOfElems); diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index c50dea5a9d392beb353408e544daa6aedf3e777b..aec75a0365ef42c8a23b021af4050d18fd6246c6 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -69,11 +69,21 @@ int32_t fmGetFuncInfo(const char* pFuncName, int32_t* pFuncId, int32_t* pFuncTyp return TSDB_CODE_SUCCESS; } -int32_t fmGetFuncResultType(SFunctionNode* pFunc) { +int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { if (pFunc->funcId < 0 || pFunc->funcId >= funcMgtBuiltinsNum) { return TSDB_CODE_FAILED; } - return funcMgtBuiltins[pFunc->funcId].checkFunc(pFunc); + return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pErrBuf, len); +} + +EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) { + if (pFunc->funcId < 0 || pFunc->funcId >= funcMgtBuiltinsNum) { + return FUNC_DATA_REQUIRED_ALL_NEEDED; + } + if (NULL == funcMgtBuiltins[pFunc->funcId].dataRequiredFunc) { + return FUNC_DATA_REQUIRED_ALL_NEEDED; + } + return funcMgtBuiltins[pFunc->funcId].dataRequiredFunc(pFunc, pTimeWindow); } int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet) { @@ -120,6 +130,13 @@ bool fmIsNonstandardSQLFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_NONSTANDARD_SQL_FUNC); } +bool fmIsSpecialDataRequiredFunc(int32_t funcId) { + return isSpecificClassifyFunc(funcId, FUNC_MGT_SPECIAL_DATA_REQUIRED); +} + +bool fmIsDynamicScanOptimizedFunc(int32_t funcId) { + return isSpecificClassifyFunc(funcId, FUNC_MGT_DYNAMIC_SCAN_OPTIMIZED); +} void fmFuncMgtDestroy() { void* m = gFunMgtService.pFuncNameHashTable; diff --git a/source/libs/function/src/tfill.c b/source/libs/function/src/tfill.c index 1f7e83286b3c912db211d9e8b588e12dad9742b8..b6b53621877c7697b87470f7eacbcfb166f00bf2 100644 --- a/source/libs/function/src/tfill.c +++ b/source/libs/function/src/tfill.c @@ -541,7 +541,7 @@ struct SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfOutput, co pFillCol[i].col.bytes = pExprInfo->base.resSchema.bytes; pFillCol[i].col.type = (int8_t)pExprInfo->base.resSchema.type; pFillCol[i].col.offset = offset; - pFillCol[i].col.colId = pExprInfo->base.resSchema.colId; + pFillCol[i].col.colId = pExprInfo->base.resSchema.slotId; pFillCol[i].tagIndex = -2; pFillCol[i].flag = pExprInfo->base.pParam[0].pCol->flag; // always be the normal column for table query // pFillCol[i].functionId = pExprInfo->pExpr->_function.functionId; diff --git a/source/libs/index/src/indexFstCountingWriter.c b/source/libs/index/src/indexFstCountingWriter.c index 76ff4309b57f4b6a3d7553fcca5239eef4e6911c..1d4395aff6bb01eade0c27d9b26241aab1b5e005 100644 --- a/source/libs/index/src/indexFstCountingWriter.c +++ b/source/libs/index/src/indexFstCountingWriter.c @@ -92,7 +92,7 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int ctx->file.readOnly = readOnly; if (readOnly == false) { // ctx->file.pFile = open(path, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU | S_IRWXG | S_IRWXO); - ctx->file.pFile = taosOpenFile(path, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); + ctx->file.pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); taosFtruncateFile(ctx->file.pFile, 0); int64_t file_size; taosStatFile(path, &file_size, NULL); diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c index c90b1f58e84ecdd17a096c1f95c1357710ee234a..3ece089a2821a4e9db0a5e66853c01a224a2e78c 100644 --- a/source/libs/monitor/src/monMain.c +++ b/source/libs/monitor/src/monMain.c @@ -375,6 +375,9 @@ static void monGenDnodeJson(SMonInfo *pMonitor) { tjsonAddDoubleToObject(pJson, "vnodes_num", pStat->totalVnodes); tjsonAddDoubleToObject(pJson, "masters", pStat->masterNum); tjsonAddDoubleToObject(pJson, "has_mnode", pInfo->has_mnode); + tjsonAddDoubleToObject(pJson, "has_qnode", pInfo->has_qnode); + tjsonAddDoubleToObject(pJson, "has_snode", pInfo->has_snode); + tjsonAddDoubleToObject(pJson, "has_bnode", pInfo->has_bnode); } static void monGenDiskJson(SMonInfo *pMonitor) { @@ -530,7 +533,7 @@ void monSendReport() { if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; if (taosSendHttpReport(tsMonitor.cfg.server, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) { - uError("failed to send monitor msg since %s", terrstr()); + uError("failed to send monitor msg"); } taosMemoryFree(pCont); } diff --git a/source/libs/monitor/src/monMsg.c b/source/libs/monitor/src/monMsg.c index 3aafcf071d13983195babf421ed7b76f96dba6ac..adacbf479be27f60e3eb376007730cdf5bd5ef1f 100644 --- a/source/libs/monitor/src/monMsg.c +++ b/source/libs/monitor/src/monMsg.c @@ -194,9 +194,9 @@ int32_t tDecodeSMonVgroupInfo(SCoder *decoder, SMonVgroupInfo *pInfo) { if (tDecodeCStrTo(decoder, desc.database_name) < 0) return -1; if (tDecodeCStrTo(decoder, desc.status) < 0) return -1; for (int32_t j = 0; j < TSDB_MAX_REPLICA; ++j) { - SMonVnodeDesc vdesc = {0}; - if (tDecodeI32(decoder, &vdesc.dnode_id) < 0) return -1; - if (tDecodeCStrTo(decoder, vdesc.vnode_role) < 0) return -1; + SMonVnodeDesc *pVDesc = &desc.vnodes[j]; + if (tDecodeI32(decoder, &pVDesc->dnode_id) < 0) return -1; + if (tDecodeCStrTo(decoder, pVDesc->vnode_role) < 0) return -1; } taosArrayPush(pInfo->vgroups, &desc); } @@ -205,15 +205,15 @@ int32_t tDecodeSMonVgroupInfo(SCoder *decoder, SMonVgroupInfo *pInfo) { int32_t tEncodeSMonGrantInfo(SCoder *encoder, const SMonGrantInfo *pInfo) { if (tEncodeI32(encoder, pInfo->expire_time) < 0) return -1; - if (tEncodeI32(encoder, pInfo->timeseries_used) < 0) return -1; - if (tEncodeI32(encoder, pInfo->timeseries_total) < 0) return -1; + if (tEncodeI64(encoder, pInfo->timeseries_used) < 0) return -1; + if (tEncodeI64(encoder, pInfo->timeseries_total) < 0) return -1; return 0; } int32_t tDecodeSMonGrantInfo(SCoder *decoder, SMonGrantInfo *pInfo) { if (tDecodeI32(decoder, &pInfo->expire_time) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->timeseries_used) < 0) return -1; - if (tDecodeI32(decoder, &pInfo->timeseries_total) < 0) return -1; + if (tDecodeI64(decoder, &pInfo->timeseries_used) < 0) return -1; + if (tDecodeI64(decoder, &pInfo->timeseries_total) < 0) return -1; return 0; } diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index fe3b7cb8a092476d502fee707bdee3bd76925c0f..975036575de0a57ac3e038812599a3308e9df940 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -95,7 +95,6 @@ static void dataTypeCopy(const SDataType* pSrc, SDataType* pDst) { static void exprNodeCopy(const SExprNode* pSrc, SExprNode* pDst) { dataTypeCopy(&pSrc->resType, &pDst->resType); COPY_CHAR_ARRAY_FIELD(aliasName); - // CLONE_NODE_LIST_FIELD(pAssociationList); } static SNode* columnNodeCopy(const SColumnNode* pSrc, SColumnNode* pDst) { @@ -222,15 +221,19 @@ static SVgroupsInfo* vgroupsInfoClone(const SVgroupsInfo* pSrc) { } static SNode* logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) { + COPY_ALL_SCALAR_FIELDS; COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); CLONE_NODE_LIST_FIELD(pScanCols); CLONE_OBJECT_FIELD(pMeta, tableMetaClone); CLONE_OBJECT_FIELD(pVgroupList, vgroupsInfoClone); - COPY_SCALAR_FIELD(scanType); - COPY_SCALAR_FIELD(scanFlag); - COPY_SCALAR_FIELD(scanRange); - COPY_SCALAR_FIELD(tableName); - COPY_SCALAR_FIELD(showRewrite); + CLONE_NODE_LIST_FIELD(pDynamicScanFuncs); + return (SNode*)pDst; +} + +static SNode* logicJoinCopy(const SJoinLogicNode* pSrc, SJoinLogicNode* pDst) { + COPY_ALL_SCALAR_FIELDS; + COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); + CLONE_NODE_FIELD(pOnConditions); return (SNode*)pDst; } @@ -263,15 +266,8 @@ static SNode* logicExchangeCopy(const SExchangeLogicNode* pSrc, SExchangeLogicNo static SNode* logicWindowCopy(const SWindowLogicNode* pSrc, SWindowLogicNode* pDst) { COPY_ALL_SCALAR_FIELDS; COPY_BASE_OBJECT_FIELD(node, logicNodeCopy); - // COPY_SCALAR_FIELD(winType); CLONE_NODE_LIST_FIELD(pFuncs); - // COPY_SCALAR_FIELD(interval); - // COPY_SCALAR_FIELD(offset); - // COPY_SCALAR_FIELD(sliding); - // COPY_SCALAR_FIELD(intervalUnit); - // COPY_SCALAR_FIELD(slidingUnit); CLONE_NODE_FIELD(pFill); - // COPY_SCALAR_FIELD(sessionGap); CLONE_NODE_FIELD(pTspk); return (SNode*)pDst; } @@ -360,6 +356,8 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) { return downstreamSourceCopy((const SDownstreamSourceNode*)pNode, (SDownstreamSourceNode*)pDst); case QUERY_NODE_LOGIC_PLAN_SCAN: return logicScanCopy((const SScanLogicNode*)pNode, (SScanLogicNode*)pDst); + case QUERY_NODE_LOGIC_PLAN_JOIN: + return logicJoinCopy((const SJoinLogicNode*)pNode, (SJoinLogicNode*)pDst); case QUERY_NODE_LOGIC_PLAN_AGG: return logicAggCopy((const SAggLogicNode*)pNode, (SAggLogicNode*)pDst); case QUERY_NODE_LOGIC_PLAN_PROJECT: diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 7f91aeb16f056028ff59653ab83a1d4fdabb54c3..ce74748c0c76b49aaef5ec69c0a828b6d7cb5c8d 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -65,7 +65,7 @@ const char* nodesNodeName(ENodeType type) { case QUERY_NODE_TARGET: return "Target"; case QUERY_NODE_DATABLOCK_DESC: - return "TupleDesc"; + return "DataBlockDesc"; case QUERY_NODE_SLOT_DESC: return "SlotDesc"; case QUERY_NODE_COLUMN_DEF: @@ -132,30 +132,52 @@ const char* nodesNodeName(ENodeType type) { return "DropTopicStmt"; case QUERY_NODE_ALTER_LOCAL_STMT: return "AlterLocalStmt"; - case QUERY_NODE_SHOW_DATABASES_STMT: - return "ShowDatabaseStmt"; - case QUERY_NODE_SHOW_TABLES_STMT: - return "ShowTablesStmt"; - case QUERY_NODE_SHOW_STABLES_STMT: - return "ShowStablesStmt"; - case QUERY_NODE_SHOW_USERS_STMT: - return "ShowUsersStmt"; case QUERY_NODE_SHOW_DNODES_STMT: return "ShowDnodesStmt"; - case QUERY_NODE_SHOW_VGROUPS_STMT: - return "ShowVgroupsStmt"; case QUERY_NODE_SHOW_MNODES_STMT: return "ShowMnodesStmt"; case QUERY_NODE_SHOW_MODULES_STMT: return "ShowModulesStmt"; case QUERY_NODE_SHOW_QNODES_STMT: return "ShowQnodesStmt"; + case QUERY_NODE_SHOW_SNODES_STMT: + return "ShowSnodesStmt"; + case QUERY_NODE_SHOW_BNODES_STMT: + return "ShowBnodesStmt"; + case QUERY_NODE_SHOW_DATABASES_STMT: + return "ShowDatabaseStmt"; case QUERY_NODE_SHOW_FUNCTIONS_STMT: return "ShowFunctionsStmt"; case QUERY_NODE_SHOW_INDEXES_STMT: return "ShowIndexesStmt"; + case QUERY_NODE_SHOW_STABLES_STMT: + return "ShowStablesStmt"; case QUERY_NODE_SHOW_STREAMS_STMT: return "ShowStreamsStmt"; + case QUERY_NODE_SHOW_TABLES_STMT: + return "ShowTablesStmt"; + case QUERY_NODE_SHOW_USERS_STMT: + return "ShowUsersStmt"; + case QUERY_NODE_SHOW_LICENCE_STMT: + return "ShowGrantsStmt"; + case QUERY_NODE_SHOW_VGROUPS_STMT: + return "ShowVgroupsStmt"; + case QUERY_NODE_SHOW_TOPICS_STMT: + return "ShowTopicsStmt"; + case QUERY_NODE_SHOW_CONSUMERS_STMT: + return "ShowConsumersStmt"; + case QUERY_NODE_SHOW_SUBSCRIBES_STMT: + return "ShowSubscribesStmt"; + case QUERY_NODE_SHOW_TRANS_STMT: + return "ShowTransStmt"; + case QUERY_NODE_SHOW_SMAS_STMT: + return "ShowSmasStmt"; + case QUERY_NODE_SHOW_CONFIGS_STMT: + return "ShowConfigsStmt"; + case QUERY_NODE_SHOW_QUERIES_STMT: + return "ShowQueriesStmt"; + case QUERY_NODE_SHOW_VNODES_STMT: + return "ShowVnodeStmt"; case QUERY_NODE_LOGIC_PLAN_SCAN: return "LogicScan"; case QUERY_NODE_LOGIC_PLAN_JOIN: @@ -723,6 +745,9 @@ static int32_t jsonToPhysiTagScanNode(const SJson* pJson, void* pObj) { static const char* jkTableScanPhysiPlanScanFlag = "ScanFlag"; static const char* jkTableScanPhysiPlanStartKey = "StartKey"; static const char* jkTableScanPhysiPlanEndKey = "EndKey"; +static const char* jkTableScanPhysiPlanRatio = "Ratio"; +static const char* jkTableScanPhysiPlanDataRequired = "DataRequired"; +static const char* jkTableScanPhysiPlanDynamicScanFuncs = "DynamicScanFuncs"; static int32_t physiTableScanNodeToJson(const void* pObj, SJson* pJson) { const STableScanPhysiNode* pNode = (const STableScanPhysiNode*)pObj; @@ -737,6 +762,15 @@ static int32_t physiTableScanNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanEndKey, pNode->scanRange.ekey); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddDoubleToObject(pJson, jkTableScanPhysiPlanRatio, pNode->ratio); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanDataRequired, pNode->dataRequired); + } + if (TSDB_CODE_SUCCESS == code) { + code = nodeListToJson(pJson, jkTableScanPhysiPlanDynamicScanFuncs, pNode->pDynamicScanFuncs); + } return code; } @@ -754,6 +788,15 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = tjsonGetBigIntValue(pJson, jkTableScanPhysiPlanEndKey, &pNode->scanRange.ekey); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetDoubleValue(pJson, jkTableScanPhysiPlanRatio, &pNode->ratio); + } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetNumberValue(pJson, jkTableScanPhysiPlanDataRequired, pNode->dataRequired); + } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeList(pJson, jkTableScanPhysiPlanDynamicScanFuncs, &pNode->pDynamicScanFuncs); + } return code; } @@ -1060,6 +1103,7 @@ static int32_t jsonToPhysiSortNode(const SJson* pJson, void* pObj) { static const char* jkWindowPhysiPlanExprs = "Exprs"; static const char* jkWindowPhysiPlanFuncs = "Funcs"; +static const char* jkWindowPhysiPlanTsPk = "TsPk"; static int32_t physiWindowNodeToJson(const void* pObj, SJson* pJson) { const SWinodwPhysiNode* pNode = (const SWinodwPhysiNode*)pObj; @@ -1071,6 +1115,9 @@ static int32_t physiWindowNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = nodeListToJson(pJson, jkWindowPhysiPlanFuncs, pNode->pFuncs); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkWindowPhysiPlanTsPk, nodeToJson, pNode->pTspk); + } return code; } @@ -1085,6 +1132,9 @@ static int32_t jsonToPhysiWindowNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeList(pJson, jkWindowPhysiPlanFuncs, &pNode->pFuncs); } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkWindowPhysiPlanTsPk, (SNode**)&pNode->pTspk); + } return code; } @@ -1095,7 +1145,6 @@ static const char* jkIntervalPhysiPlanSliding = "Sliding"; static const char* jkIntervalPhysiPlanIntervalUnit = "intervalUnit"; static const char* jkIntervalPhysiPlanSlidingUnit = "slidingUnit"; static const char* jkIntervalPhysiPlanFill = "Fill"; -static const char* jkIntervalPhysiPlanTsPk = "TsPk"; static const char* jkIntervalPhysiPlanPrecision = "Precision"; static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) { @@ -1120,9 +1169,6 @@ static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddObject(pJson, jkIntervalPhysiPlanFill, nodeToJson, pNode->pFill); } - if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddObject(pJson, jkIntervalPhysiPlanTsPk, nodeToJson, pNode->pTspk); - } if (TSDB_CODE_SUCCESS == code) { code = tjsonAddIntegerToObject(pJson, jkIntervalPhysiPlanPrecision, pNode->precision); } @@ -1152,9 +1198,6 @@ static int32_t jsonToPhysiIntervalNode(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeObject(pJson, jkIntervalPhysiPlanFill, (SNode**)&pNode->pFill); } - if (TSDB_CODE_SUCCESS == code) { - code = jsonToNodeObject(pJson, jkIntervalPhysiPlanTsPk, (SNode**)&pNode->pTspk); - } if (TSDB_CODE_SUCCESS == code) { code = tjsonGetUTinyIntValue(pJson, jkIntervalPhysiPlanPrecision, &pNode->precision); } @@ -2291,7 +2334,7 @@ static int32_t jsonToDataBlockDescNode(const SJson* pJson, void* pObj) { code = jsonToNodeList(pJson, jkDataBlockDescSlots, &pNode->pSlots); } if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetSmallIntValue(pJson, jkDataBlockPrecision, &pNode->precision); + code = tjsonGetUTinyIntValue(pJson, jkDataBlockPrecision, &pNode->precision); } return code; @@ -2767,6 +2810,7 @@ int32_t nodesStringToList(const char* pStr, SNodeList** pList) { return TSDB_CODE_FAILED; } int32_t code = jsonToNodeListImpl(pJson, pList); + tjsonDelete(pJson); if (TSDB_CODE_SUCCESS != code) { nodesDestroyList(*pList); terrno = code; diff --git a/source/libs/nodes/src/nodesTraverseFuncs.c b/source/libs/nodes/src/nodesTraverseFuncs.c index 3c102879924872993ed81f056352bb59d6bc263d..99a08923bb3381d188f69dca33f29924c750fa0b 100644 --- a/source/libs/nodes/src/nodesTraverseFuncs.c +++ b/source/libs/nodes/src/nodesTraverseFuncs.c @@ -46,7 +46,7 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker case QUERY_NODE_OPERATOR: { SOperatorNode* pOpNode = (SOperatorNode*)pNode; res = walkNode(pOpNode->pLeft, order, walker, pContext); - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = walkNode(pOpNode->pRight, order, walker, pContext); } break; @@ -63,10 +63,10 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker case QUERY_NODE_JOIN_TABLE: { SJoinTableNode* pJoinTableNode = (SJoinTableNode*)pNode; res = walkNode(pJoinTableNode->pLeft, order, walker, pContext); - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = walkNode(pJoinTableNode->pRight, order, walker, pContext); } - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = walkNode(pJoinTableNode->pOnCond, order, walker, pContext); } break; @@ -77,13 +77,18 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker case QUERY_NODE_ORDER_BY_EXPR: res = walkNode(((SOrderByExprNode*)pNode)->pExpr, order, walker, pContext); break; - case QUERY_NODE_STATE_WINDOW: - res = walkNode(((SStateWindowNode*)pNode)->pExpr, order, walker, pContext); + case QUERY_NODE_STATE_WINDOW: { + SStateWindowNode* pState = (SStateWindowNode*)pNode; + res = walkNode(pState->pExpr, order, walker, pContext); + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { + res = walkNode(pState->pCol, order, walker, pContext); + } break; + } case QUERY_NODE_SESSION_WINDOW: { SSessionWindowNode* pSession = (SSessionWindowNode*)pNode; res = walkNode(pSession->pCol, order, walker, pContext); - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = walkNode(pSession->pGap, order, walker, pContext); } break; @@ -91,16 +96,16 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker case QUERY_NODE_INTERVAL_WINDOW: { SIntervalWindowNode* pInterval = (SIntervalWindowNode*)pNode; res = walkNode(pInterval->pInterval, order, walker, pContext); - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = walkNode(pInterval->pOffset, order, walker, pContext); } - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = walkNode(pInterval->pSliding, order, walker, pContext); } - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = walkNode(pInterval->pFill, order, walker, pContext); } - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = walkNode(pInterval->pCol, order, walker, pContext); } break; @@ -121,7 +126,7 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker break; } - if (DEAL_RES_ERROR != res && TRAVERSAL_POSTORDER == order) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res && TRAVERSAL_POSTORDER == order) { res = walker(pNode, pContext); } @@ -131,8 +136,9 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker static EDealRes walkList(SNodeList* pNodeList, ETraversalOrder order, FNodeWalker walker, void* pContext) { SNode* node; FOREACH(node, pNodeList) { - if (DEAL_RES_ERROR == walkNode(node, order, walker, pContext)) { - return DEAL_RES_ERROR; + EDealRes res = walkNode(node, order, walker, pContext); + if (DEAL_RES_ERROR == res || DEAL_RES_END == res) { + return res; } } return DEAL_RES_CONTINUE; @@ -180,7 +186,7 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit case QUERY_NODE_OPERATOR: { SOperatorNode* pOpNode = (SOperatorNode*)pNode; res = rewriteNode(&(pOpNode->pLeft), order, rewriter, pContext); - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = rewriteNode(&(pOpNode->pRight), order, rewriter, pContext); } break; @@ -197,10 +203,10 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit case QUERY_NODE_JOIN_TABLE: { SJoinTableNode* pJoinTableNode = (SJoinTableNode*)pNode; res = rewriteNode(&(pJoinTableNode->pLeft), order, rewriter, pContext); - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = rewriteNode(&(pJoinTableNode->pRight), order, rewriter, pContext); } - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = rewriteNode(&(pJoinTableNode->pOnCond), order, rewriter, pContext); } break; @@ -211,25 +217,35 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit case QUERY_NODE_ORDER_BY_EXPR: res = rewriteNode(&(((SOrderByExprNode*)pNode)->pExpr), order, rewriter, pContext); break; - case QUERY_NODE_STATE_WINDOW: - res = rewriteNode(&(((SStateWindowNode*)pNode)->pExpr), order, rewriter, pContext); + case QUERY_NODE_STATE_WINDOW: { + SStateWindowNode* pState = (SStateWindowNode*)pNode; + res = rewriteNode(&pState->pExpr, order, rewriter, pContext); + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { + res = rewriteNode(&pState->pCol, order, rewriter, pContext); + } break; - case QUERY_NODE_SESSION_WINDOW: - res = rewriteNode(&(((SSessionWindowNode*)pNode)->pCol), order, rewriter, pContext); + } + case QUERY_NODE_SESSION_WINDOW: { + SSessionWindowNode* pSession = (SSessionWindowNode*)pNode; + res = rewriteNode(&pSession->pCol, order, rewriter, pContext); + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { + res = rewriteNode(&pSession->pGap, order, rewriter, pContext); + } break; + } case QUERY_NODE_INTERVAL_WINDOW: { SIntervalWindowNode* pInterval = (SIntervalWindowNode*)pNode; res = rewriteNode(&(pInterval->pInterval), order, rewriter, pContext); - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = rewriteNode(&(pInterval->pOffset), order, rewriter, pContext); } - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = rewriteNode(&(pInterval->pSliding), order, rewriter, pContext); } - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = rewriteNode(&(pInterval->pFill), order, rewriter, pContext); } - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = rewriteNode(&(pInterval->pCol), order, rewriter, pContext); } break; @@ -250,7 +266,7 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit break; } - if (DEAL_RES_ERROR != res && TRAVERSAL_POSTORDER == order) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res && TRAVERSAL_POSTORDER == order) { res = rewriter(pRawNode, pContext); } @@ -260,8 +276,9 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit static EDealRes rewriteList(SNodeList* pNodeList, ETraversalOrder order, FNodeRewriter rewriter, void* pContext) { SNode** pNode; FOREACH_FOR_REWRITE(pNode, pNodeList) { - if (DEAL_RES_ERROR == rewriteNode(pNode, order, rewriter, pContext)) { - return DEAL_RES_ERROR; + EDealRes res = rewriteNode(pNode, order, rewriter, pContext); + if (DEAL_RES_ERROR == res || DEAL_RES_END == res) { + return res; } } return DEAL_RES_CONTINUE; diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index d21eec0a415f715050611450a030b2ffc9935e99..e1a486d8b110802f9131433a4f26e5ab793012c3 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -146,20 +146,29 @@ SNodeptr nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SDescribeStmt)); case QUERY_NODE_RESET_QUERY_CACHE_STMT: return makeNode(type, sizeof(SNode)); - case QUERY_NODE_SHOW_DATABASES_STMT: - case QUERY_NODE_SHOW_TABLES_STMT: - case QUERY_NODE_SHOW_STABLES_STMT: - case QUERY_NODE_SHOW_USERS_STMT: case QUERY_NODE_SHOW_DNODES_STMT: - case QUERY_NODE_SHOW_VGROUPS_STMT: case QUERY_NODE_SHOW_MNODES_STMT: case QUERY_NODE_SHOW_MODULES_STMT: case QUERY_NODE_SHOW_QNODES_STMT: + case QUERY_NODE_SHOW_SNODES_STMT: + case QUERY_NODE_SHOW_BNODES_STMT: + case QUERY_NODE_SHOW_DATABASES_STMT: case QUERY_NODE_SHOW_FUNCTIONS_STMT: case QUERY_NODE_SHOW_INDEXES_STMT: + case QUERY_NODE_SHOW_STABLES_STMT: case QUERY_NODE_SHOW_STREAMS_STMT: - case QUERY_NODE_SHOW_BNODES_STMT: - case QUERY_NODE_SHOW_SNODES_STMT: + case QUERY_NODE_SHOW_TABLES_STMT: + case QUERY_NODE_SHOW_USERS_STMT: + case QUERY_NODE_SHOW_LICENCE_STMT: + case QUERY_NODE_SHOW_VGROUPS_STMT: + case QUERY_NODE_SHOW_TOPICS_STMT: + case QUERY_NODE_SHOW_CONSUMERS_STMT: + case QUERY_NODE_SHOW_SUBSCRIBES_STMT: + case QUERY_NODE_SHOW_TRANS_STMT: + case QUERY_NODE_SHOW_SMAS_STMT: + case QUERY_NODE_SHOW_CONFIGS_STMT: + case QUERY_NODE_SHOW_QUERIES_STMT: + case QUERY_NODE_SHOW_VNODES_STMT: return makeNode(type, sizeof(SShowStmt)); case QUERY_NODE_LOGIC_PLAN_SCAN: return makeNode(type, sizeof(SScanLogicNode)); @@ -252,6 +261,7 @@ static void destroyWinodwPhysiNode(SWinodwPhysiNode* pNode) { destroyPhysiNode((SPhysiNode*)pNode); nodesDestroyList(pNode->pExprs); nodesDestroyList(pNode->pFuncs); + nodesDestroyNode(pNode->pTspk); } static void destroyScanPhysiNode(SScanPhysiNode* pNode) { @@ -593,7 +603,6 @@ void nodesDestroyNode(SNodeptr pNode) { SIntervalPhysiNode* pPhyNode = (SIntervalPhysiNode*)pNode; destroyWinodwPhysiNode((SWinodwPhysiNode*)pPhyNode); nodesDestroyNode(pPhyNode->pFill); - nodesDestroyNode(pPhyNode->pTspk); break; } case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW: @@ -694,6 +703,17 @@ int32_t nodesListMakeAppend(SNodeList** pList, SNodeptr pNode) { return nodesListAppend(*pList, pNode); } +int32_t nodesListMakeStrictAppend(SNodeList** pList, SNodeptr pNode) { + if (NULL == *pList) { + *pList = nodesMakeList(); + if (NULL == *pList) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return TSDB_CODE_OUT_OF_MEMORY; + } + } + return nodesListStrictAppend(*pList, pNode); +} + int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc) { if (NULL == pTarget || NULL == pSrc) { return TSDB_CODE_FAILED; diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index e78101421629d1ea9f9ef0ee521c737bb5840d4c..1fa3a186682d60d617c086efe978c07806307353 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -81,7 +81,6 @@ SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode); SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode); SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode); -SNodeList* addValueNodeFromTypeToList(SAstCreateContext* pCxt, SDataType dataType, SNodeList* pList); SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pColumnName); SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral); @@ -93,6 +92,7 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight); SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight); SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList); +SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt); SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList); SNode* createNodeListNodeEx(SAstCreateContext* pCxt, SNode* p1, SNode* p2); SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTableName, SToken* pTableAlias); diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 18bea4736c9c2ca253a8db4e64618fa9761b8d8f..3c3cea8ea34765e0af0166e710f556ccfe085b04 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -79,13 +79,13 @@ alter_account_option ::= USERS literal. alter_account_option ::= CONNS literal. { } alter_account_option ::= STATE literal. { } -/************************************************ create/alter/drop/show user *****************************************/ +/************************************************ create/alter/drop user **********************************************/ cmd ::= CREATE USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createCreateUserStmt(pCxt, &A, &B); } cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B); } cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PRIVILEGES, &B); } cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); } -/************************************************ create/drop/alter/show dnode ****************************************/ +/************************************************ create/drop/alter dnode *********************************************/ cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL); } cmd ::= CREATE DNODE dnode_host_name(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B); } cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); } @@ -124,7 +124,7 @@ cmd ::= DROP SNODE ON DNODE NK_INTEGER(A). cmd ::= CREATE MNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_MNODE_STMT, &A); } cmd ::= DROP MNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_MNODE_STMT, &A); } -/************************************************ create/drop/show/use database ***************************************/ +/************************************************ create/drop/use database ********************************************/ cmd ::= CREATE DATABASE not_exists_opt(A) db_name(B) db_options(C). { pCxt->pRootNode = createCreateDatabaseStmt(pCxt, A, &B, C); } cmd ::= DROP DATABASE exists_opt(A) db_name(B). { pCxt->pRootNode = createDropDatabaseStmt(pCxt, A, &B); } cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A); } @@ -332,6 +332,7 @@ cmd ::= SHOW ACCOUNTS. cmd ::= SHOW APPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); } cmd ::= SHOW CONNECTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT, NULL, NULL); } cmd ::= SHOW LICENCE. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); } +cmd ::= SHOW GRANTS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); } cmd ::= SHOW CREATE DATABASE db_name(A). { pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &A); } cmd ::= SHOW CREATE TABLE full_table_name(A). { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, A); } cmd ::= SHOW CREATE STABLE full_table_name(A). { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, A); } @@ -534,13 +535,7 @@ expression(A) ::= pseudo_column(B). expression(A) ::= column_reference(B). { A = B; } expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); } expression(A) ::= function_name(B) NK_LP NK_STAR(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, createNodeList(pCxt, createColumnNode(pCxt, NULL, &C)))); } -//for CAST function CAST(expr AS type_name) -expression(A) ::= function_name(B) NK_LP expression(C) AS type_name(D) NK_RP(E). { - SNodeList *p = createNodeList(pCxt, releaseRawExprNode(pCxt, C)); - p = addValueNodeFromTypeToList(pCxt, D, p); - A = createRawExprNodeExt(pCxt, &B, &E, createFunctionNode(pCxt, &B, p)); - } -//expression(A) ::= cast_expression(B). { A = B; } +expression(A) ::= CAST(B) NK_LP expression(C) AS type_name(D) NK_RP(E). { A = createRawExprNodeExt(pCxt, &B, &E, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, C), D)); } //expression(A) ::= case_expression(B). { A = B; } expression(A) ::= subquery(B). { A = B; } expression(A) ::= NK_LP(B) expression(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, releaseRawExprNode(pCxt, C)); } @@ -587,6 +582,7 @@ column_reference(A) ::= column_name(B). column_reference(A) ::= table_name(B) NK_DOT column_name(C). { A = createRawExprNodeExt(pCxt, &B, &C, createColumnNode(pCxt, &B, &C)); } pseudo_column(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } +pseudo_column(A) ::= TODAY(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } pseudo_column(A) ::= ROWTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } pseudo_column(A) ::= TBNAME(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } pseudo_column(A) ::= QSTARTTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 4908748f0dd533b0ae3ec938c923774124615c1b..accf99606a0bc5229f82b639bf7bd61a2f6cc9fb 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -207,7 +207,11 @@ SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) { CHECK_RAW_EXPR_NODE(pNode); SRawExprNode* pRawExpr = (SRawExprNode*)pNode; SNode* pExpr = pRawExpr->pNode; - strncpy(((SExprNode*)pExpr)->aliasName, pRawExpr->p, pRawExpr->n); + if (nodesIsExprNode(pExpr)) { + int32_t len = TMIN(sizeof(((SExprNode*)pExpr)->aliasName) - 1, pRawExpr->n); + strncpy(((SExprNode*)pExpr)->aliasName, pRawExpr->p, len); + ((SExprNode*)pExpr)->aliasName[len] = '\0'; + } taosMemoryFreeClear(pNode); return pExpr; } @@ -251,26 +255,6 @@ SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pC return (SNode*)col; } -SNodeList* addValueNodeFromTypeToList(SAstCreateContext* pCxt, SDataType dataType, SNodeList* pList) { - char buf[64] = {0}; - //add value node for type - snprintf(buf, sizeof(buf), "%u", dataType.type); - SToken token = {.type = TSDB_DATA_TYPE_TINYINT, .n = strlen(buf), .z = buf}; - SNode* pNode = createValueNode(pCxt, token.type, &token); - addNodeToList(pCxt, pList, pNode); - - //add value node for bytes - memset(buf, 0, sizeof(buf)); - snprintf(buf, sizeof(buf), "%u", dataType.bytes); - token.type = TSDB_DATA_TYPE_BIGINT; - token.n = strlen(buf); - token.z = buf; - pNode = createValueNode(pCxt, token.type, &token); - addNodeToList(pCxt, pList, pNode); - - return pList; -} - SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral) { SValueNode* val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); CHECK_OUT_OF_MEM(val); @@ -326,8 +310,26 @@ SNode* createLogicConditionNode(SAstCreateContext* pCxt, ELogicConditionType typ CHECK_OUT_OF_MEM(cond); cond->condType = type; cond->pParameterList = nodesMakeList(); - nodesListAppend(cond->pParameterList, pParam1); - nodesListAppend(cond->pParameterList, pParam2); + if ((QUERY_NODE_LOGIC_CONDITION == nodeType(pParam1) && type != ((SLogicConditionNode*)pParam1)->condType) || + (QUERY_NODE_LOGIC_CONDITION == nodeType(pParam2) && type != ((SLogicConditionNode*)pParam2)->condType)) { + nodesListAppend(cond->pParameterList, pParam1); + nodesListAppend(cond->pParameterList, pParam2); + } else { + if (QUERY_NODE_LOGIC_CONDITION == nodeType(pParam1)) { + nodesListAppendList(cond->pParameterList, ((SLogicConditionNode*)pParam1)->pParameterList); + ((SLogicConditionNode*)pParam1)->pParameterList = NULL; + nodesDestroyNode(pParam1); + } else { + nodesListAppend(cond->pParameterList, pParam1); + } + if (QUERY_NODE_LOGIC_CONDITION == nodeType(pParam2)) { + nodesListAppendList(cond->pParameterList, ((SLogicConditionNode*)pParam2)->pParameterList); + ((SLogicConditionNode*)pParam2)->pParameterList = NULL; + nodesDestroyNode(pParam2); + } else { + nodesListAppend(cond->pParameterList, pParam2); + } + } return (SNode*)cond; } @@ -358,6 +360,15 @@ SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNod return (SNode*)func; } +SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt) { + SFunctionNode* func = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); + CHECK_OUT_OF_MEM(func); + strcpy(func->functionName, "cast"); + func->node.resType = dt; + nodesListMakeAppend(&func->pParameterList, pExpr); + return (SNode*)func; +} + SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList) { SNodeListNode* list = (SNodeListNode*)nodesMakeNode(QUERY_NODE_NODE_LIST); CHECK_OUT_OF_MEM(list); @@ -456,6 +467,13 @@ SNode* createSessionWindowNode(SAstCreateContext* pCxt, SNode* pCol, SNode* pGap SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr) { SStateWindowNode* state = (SStateWindowNode*)nodesMakeNode(QUERY_NODE_STATE_WINDOW); CHECK_OUT_OF_MEM(state); + state->pCol = nodesMakeNode(QUERY_NODE_COLUMN); + if (NULL == state->pCol) { + nodesDestroyNode(state); + CHECK_OUT_OF_MEM(state->pCol); + } + ((SColumnNode*)state->pCol)->colId = PRIMARYKEY_TIMESTAMP_COL_ID; + strcpy(((SColumnNode*)state->pCol)->colName, PK_TS_COL_INTERNAL_NAME); state->pExpr = pExpr; return (SNode*)state; } @@ -498,8 +516,9 @@ SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, const SToken* p if (NULL == pNode || !pCxt->valid) { return pNode; } - uint32_t maxLen = sizeof(((SExprNode*)pNode)->aliasName); - strncpy(((SExprNode*)pNode)->aliasName, pAlias->z, pAlias->n > maxLen ? maxLen : pAlias->n); + int32_t len = TMIN(sizeof(((SExprNode*)pNode)->aliasName) - 1, pAlias->n); + strncpy(((SExprNode*)pNode)->aliasName, pAlias->z, len); + ((SExprNode*)pNode)->aliasName[len] = '\0'; return pNode; } @@ -584,34 +603,6 @@ SNode* createDatabaseOptions(SAstCreateContext* pCxt) { return (SNode*)pOptions; } -static bool checkAndSetKeepOption(SAstCreateContext* pCxt, SNodeList* pKeep, int32_t* pKeep0, int32_t* pKeep1, int32_t* pKeep2) { - int32_t numOfKeep = LIST_LENGTH(pKeep); - if (numOfKeep > 3 || numOfKeep < 1) { - snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid number of keep options"); - return false; - } - - int32_t daysToKeep0 = strtol(((SValueNode*)nodesListGetNode(pKeep, 0))->literal, NULL, 10); - int32_t daysToKeep1 = numOfKeep > 1 ? strtol(((SValueNode*)nodesListGetNode(pKeep, 1))->literal, NULL, 10) : daysToKeep0; - int32_t daysToKeep2 = numOfKeep > 2 ? strtol(((SValueNode*)nodesListGetNode(pKeep, 2))->literal, NULL, 10) : daysToKeep1; - if (daysToKeep0 < TSDB_MIN_KEEP || daysToKeep1 < TSDB_MIN_KEEP || daysToKeep2 < TSDB_MIN_KEEP || - daysToKeep0 > TSDB_MAX_KEEP || daysToKeep1 > TSDB_MAX_KEEP || daysToKeep2 > TSDB_MAX_KEEP) { - snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, - "invalid option keep: %d, %d, %d valid range: [%d, %d]", daysToKeep0, daysToKeep1, daysToKeep2, TSDB_MIN_KEEP, TSDB_MAX_KEEP); - return false; - } - - if (!((daysToKeep0 <= daysToKeep1) && (daysToKeep1 <= daysToKeep2))) { - snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid keep value, should be keep0 <= keep1 <= keep2"); - return false; - } - - *pKeep0 = daysToKeep0; - *pKeep1 = daysToKeep1; - *pKeep2 = daysToKeep2; - return true; -} - SNode* setDatabaseAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption) { switch (pAlterOption->type) { case DB_OPTION_BLOCKS: @@ -920,18 +911,6 @@ SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, S return (SNode*)pStmt; } -SNode* createShowCreateDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName) { - SNode* pStmt = nodesMakeNode(QUERY_NODE_SHOW_CREATE_DATABASE_STMT); - CHECK_OUT_OF_MEM(pStmt); - return pStmt; -} - -SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable) { - SNode* pStmt = nodesMakeNode(type); - CHECK_OUT_OF_MEM(pStmt); - return pStmt; -} - SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword) { char password[TSDB_USET_PASSWORD_LEN] = {0}; if (!checkUserName(pCxt, pUserName) || !checkPassword(pCxt, pPassword, password)) { diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c index 048830b80bfd431eaf34fad3cc536a8a3a476f26..ead3ec90ad3e1394afaf27a241e543c0db7759e2 100644 --- a/source/libs/parser/src/parCalcConst.c +++ b/source/libs/parser/src/parCalcConst.c @@ -45,7 +45,7 @@ static EDealRes calcConstOperator(SOperatorNode** pNode, void* pContext) { static EDealRes calcConstFunction(SFunctionNode** pNode, void* pContext) { SFunctionNode* pFunc = *pNode; - if (fmIsPseudoColumnFunc(pFunc->funcId)) { + if (!fmIsScalarFunc(pFunc->funcId)) { return DEAL_RES_CONTINUE; } SNode* pParam = NULL; @@ -61,6 +61,7 @@ static EDealRes calcConstLogicCond(SLogicConditionNode** pNode, void* pContext) SLogicConditionNode* pCond = *pNode; SNode* pParam = NULL; FOREACH(pParam, pCond->pParameterList) { + // todo calc "true and c1 > 10" if (QUERY_NODE_VALUE != nodeType(pParam)) { return DEAL_RES_CONTINUE; } @@ -142,7 +143,7 @@ static int32_t rewriteConditionForFromTable(SCalcConstContext* pCxt, SNode* pTab if (TSDB_CODE_SUCCESS == pCxt->code) { pCxt->code = rewriteConditionForFromTable(pCxt, pJoin->pRight); } - if (TSDB_CODE_SUCCESS == pCxt->code) { + if (TSDB_CODE_SUCCESS == pCxt->code && NULL != pJoin->pOnCond) { pCxt->code = rewriteCondition(pCxt, &pJoin->pOnCond); } } diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 9d945039b842ba1a1db626751e901d97a0f94aec..9e53eee5c8d16ce329487aed3e0ab60e38c3824f 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -312,6 +312,8 @@ static int parseTime(char **end, SToken *pToken, int16_t timePrec, int64_t *time if (pToken->type == TK_NOW) { ts = taosGetTimestamp(timePrec); + } else if (pToken->type == TK_TODAY) { + ts = taosGetTimestampToday(timePrec); } else if (pToken->type == TK_NK_INTEGER) { bool isSigned = false; toInteger(pToken->z, pToken->n, 10, &ts, &isSigned); @@ -325,6 +327,11 @@ static int parseTime(char **end, SToken *pToken, int16_t timePrec, int64_t *time for (int k = pToken->n; pToken->z[k] != '\0'; k++) { if (pToken->z[k] == ' ' || pToken->z[k] == '\t') continue; + if (pToken->z[k] == '(' && pToken->z[k + 1] == ')') { //for insert NOW()/TODAY() + *end = pTokenEnd = &pToken->z[k + 2]; + k++; + continue; + } if (pToken->z[k] == ',') { *end = pTokenEnd; *time = ts; @@ -371,8 +378,8 @@ static int parseTime(char **end, SToken *pToken, int16_t timePrec, int64_t *time } static FORCE_INLINE int32_t checkAndTrimValue(SToken* pToken, uint32_t type, char* tmpTokenBuf, SMsgBuf* pMsgBuf) { - if ((pToken->type != TK_NOW && pToken->type != TK_NK_INTEGER && pToken->type != TK_NK_STRING && pToken->type != TK_NK_FLOAT && pToken->type != TK_NK_BOOL && - pToken->type != TK_NULL && pToken->type != TK_NK_HEX && pToken->type != TK_NK_OCT && pToken->type != TK_NK_BIN) || + if ((pToken->type != TK_NOW && pToken->type != TK_TODAY && pToken->type != TK_NK_INTEGER && pToken->type != TK_NK_STRING && pToken->type != TK_NK_FLOAT && + pToken->type != TK_NK_BOOL && pToken->type != TK_NULL && pToken->type != TK_NK_HEX && pToken->type != TK_NK_OCT && pToken->type != TK_NK_BIN) || (pToken->n == 0) || (pToken->type == TK_NK_RP)) { return buildSyntaxErrMsg(pMsgBuf, "invalid data or symbol", pToken->z); } @@ -605,6 +612,12 @@ typedef struct SMemParam { static FORCE_INLINE int32_t MemRowAppend(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param) { SMemParam* pa = (SMemParam*)param; SRowBuilder* rb = pa->rb; + + if (value == NULL) { // it is a null data + tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset, pa->colIdx); + return TSDB_CODE_SUCCESS; + } + if (TSDB_DATA_TYPE_BINARY == pa->schema->type) { const char* rowEnd = tdRowEnd(rb->pBuf); STR_WITH_SIZE_TO_VARSTR(rowEnd, value, len); @@ -621,14 +634,9 @@ static FORCE_INLINE int32_t MemRowAppend(SMsgBuf* pMsgBuf, const void* value, in varDataSetLen(rowEnd, output); tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, false, pa->toffset, pa->colIdx); } else { - if (value == NULL) { // it is a null data - tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset, - pa->colIdx); - } else { - tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, value, false, pa->toffset, - pa->colIdx); - } + tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, value, false, pa->toffset, pa->colIdx); } + return TSDB_CODE_SUCCESS; } diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index daeb98b3e61024a9c8f393850e6700c827431bc7..0493771b61bea090534be3f5d4bdacae0da72f99 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -80,6 +80,7 @@ static SKeyword keywordTable[] = { {"FSYNC", TK_FSYNC}, {"FUNCTION", TK_FUNCTION}, {"FUNCTIONS", TK_FUNCTIONS}, + {"GRANTS", TK_GRANTS}, {"GROUP", TK_GROUP}, {"HAVING", TK_HAVING}, {"IF", TK_IF}, @@ -131,10 +132,10 @@ static SKeyword keywordTable[] = { {"PRECISION", TK_PRECISION}, {"PRIVILEGE", TK_PRIVILEGE}, {"PREV", TK_PREV}, - {"_QENDTS", TK_QENDTS}, + {"_QENDTS", TK_QENDTS}, {"QNODE", TK_QNODE}, {"QNODES", TK_QNODES}, - {"_QSTARTTS", TK_QSTARTTS}, + {"_QSTARTTS", TK_QSTARTTS}, {"QTIME", TK_QTIME}, {"QUERIES", TK_QUERIES}, {"QUERY", TK_QUERY}, @@ -144,7 +145,7 @@ static SKeyword keywordTable[] = { {"RESET", TK_RESET}, {"RETENTIONS", TK_RETENTIONS}, {"ROLLUP", TK_ROLLUP}, - {"_ROWTS", TK_ROWTS}, + {"_ROWTS", TK_ROWTS}, {"SCORES", TK_SCORES}, {"SELECT", TK_SELECT}, {"SESSION", TK_SESSION}, @@ -163,7 +164,7 @@ static SKeyword keywordTable[] = { {"STATE", TK_STATE}, {"STATE_WINDOW", TK_STATE_WINDOW}, {"STORAGE", TK_STORAGE}, - {"STREAM", TK_STREAM}, + {"STREAM", TK_STREAM}, {"STREAMS", TK_STREAMS}, {"STREAM_MODE", TK_STREAM_MODE}, {"SYNCDB", TK_SYNCDB}, @@ -174,6 +175,7 @@ static SKeyword keywordTable[] = { {"TBNAME", TK_TBNAME}, {"TIMESTAMP", TK_TIMESTAMP}, {"TINYINT", TK_TINYINT}, + {"TODAY", TK_TODAY}, {"TOPIC", TK_TOPIC}, {"TOPICS", TK_TOPICS}, {"TSERIES", TK_TSERIES}, @@ -192,8 +194,8 @@ static SKeyword keywordTable[] = { {"VGROUPS", TK_VGROUPS}, {"VNODES", TK_VNODES}, {"WAL", TK_WAL}, - {"_WDURATION", TK_WDURATION}, - {"_WENDTS", TK_WENDTS}, + {"_WDURATION", TK_WDURATION}, + {"_WENDTS", TK_WENDTS}, {"WHERE", TK_WHERE}, {"_WSTARTTS", TK_WSTARTTS}, // {"ID", TK_ID}, @@ -221,7 +223,6 @@ static SKeyword keywordTable[] = { // {"UMINUS", TK_UMINUS}, // {"UPLUS", TK_UPLUS}, // {"BITNOT", TK_BITNOT}, - // {"GRANTS", TK_GRANTS}, // {"DOT", TK_DOT}, // {"CTIME", TK_CTIME}, // {"LP", TK_LP}, diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 8885373b2b3b2d33e57e4740235cba994bbb8e6b..250c6c2fd19c682cd92bc3545a27d2cc841a84fb 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -21,7 +21,7 @@ #include "parUtil.h" #include "ttime.h" -#define GET_OPTION_VAL(pVal, defaultVal) (NULL == (pVal) ? (defaultVal) : ((SValueNode*)(pVal))->datum.i) +#define GET_OPTION_VAL(pVal, defaultVal) (NULL == (pVal) ? (defaultVal) : getBigintFromValueNode((SValueNode*)(pVal))) typedef struct STranslateContext { SParseContext* pParseCxt; @@ -380,6 +380,7 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode* pCol) { static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { uint8_t precision = (NULL != pCxt->pCurrStmt ? pCxt->pCurrStmt->precision : pVal->node.resType.precision); + pVal->node.resType.precision = precision; if (pVal->isDuration) { if (parseNatualDuration(pVal->literal, strlen(pVal->literal), &pVal->datum.i, &pVal->unit, precision) != TSDB_CODE_SUCCESS) { @@ -414,7 +415,6 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { pVal->datum.d = strtold(pVal->literal, &endPtr); break; } - case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_VARCHAR: case TSDB_DATA_TYPE_VARBINARY: { pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); @@ -432,6 +432,7 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { } break; } + case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_JSON: case TSDB_DATA_TYPE_DECIMAL: case TSDB_DATA_TYPE_BLOB: @@ -452,6 +453,9 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) { } pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE; pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; + } else { + pOp->node.resType.type = TSDB_DATA_TYPE_BOOL; + pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes; } return DEAL_RES_CONTINUE; } @@ -481,9 +485,9 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc) if (TSDB_CODE_SUCCESS != fmGetFuncInfo(pFunc->functionName, &pFunc->funcId, &pFunc->funcType)) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_FUNTION, pFunc->functionName); } - int32_t code = fmGetFuncResultType(pFunc); - if (TSDB_CODE_SUCCESS != code) { - return generateDealNodeErrMsg(pCxt, code, pFunc->functionName); + pCxt->errCode = fmGetFuncResultType(pFunc, pCxt->msgBuf.buf, pCxt->msgBuf.len); + if (TSDB_CODE_SUCCESS != pCxt->errCode) { + return DEAL_RES_ERROR; } if (fmIsAggFunc(pFunc->funcId) && beforeHaving(pCxt->currClause)) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION); @@ -758,7 +762,7 @@ static int32_t createAllColumns(STranslateContext* pCxt, SNodeList** pCols) { size_t nums = taosArrayGetSize(pTables); for (size_t i = 0; i < nums; ++i) { STableNode* pTable = taosArrayGetP(pTables, i); - int32_t code = createColumnNodeByTable(pCxt, pTable, *pCols); + int32_t code = createColumnNodeByTable(pCxt, pTable, *pCols); if (TSDB_CODE_SUCCESS != code) { return code; } @@ -825,11 +829,39 @@ static int32_t createFirstLastAllCols(STranslateContext* pCxt, SFunctionNode* pS return TSDB_CODE_SUCCESS; } +static bool isTableStar(SNode* pNode) { + return (QUERY_NODE_COLUMN == nodeType(pNode)) && (0 == strcmp(((SColumnNode*)pNode)->colName, "*")); +} + +static int32_t createTableAllCols(STranslateContext* pCxt, SColumnNode* pCol, SNodeList** pOutput) { + *pOutput = nodesMakeList(); + if (NULL == *pOutput) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY); + } + bool foundTable = false; + SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel); + size_t nums = taosArrayGetSize(pTables); + for (size_t i = 0; i < nums; ++i) { + STableNode* pTable = taosArrayGetP(pTables, i); + if (0 == strcmp(pTable->tableAlias, pCol->tableAlias)) { + int32_t code = createColumnNodeByTable(pCxt, pTable, *pOutput); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + foundTable = true; + break; + } + } + if (!foundTable) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_TABLE_NOT_EXIST, pCol->tableAlias); + } + return TSDB_CODE_SUCCESS; +} + static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) { if (NULL == pSelect->pProjectionList) { // select * ... return createAllColumns(pCxt, &pSelect->pProjectionList); } else { - // todo : t.* SNode* pNode = NULL; WHERE_EACH(pNode, pSelect->pProjectionList) { if (isFirstLastStar(pNode)) { @@ -840,6 +872,14 @@ static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) { INSERT_LIST(pSelect->pProjectionList, pFuncs); ERASE_NODE(pSelect->pProjectionList); continue; + } else if (isTableStar(pNode)) { + SNodeList* pCols = NULL; + if (TSDB_CODE_SUCCESS != createTableAllCols(pCxt, (SColumnNode*)pNode, &pCols)) { + return TSDB_CODE_OUT_OF_MEMORY; + } + INSERT_LIST(pSelect->pProjectionList, pCols); + ERASE_NODE(pSelect->pProjectionList); + continue; } WHERE_NEXT; } @@ -1041,6 +1081,27 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) { return code; } +static int64_t getUnitPerMinute(uint8_t precision) { + switch (precision) { + case TSDB_TIME_PRECISION_MILLI: + return MILLISECOND_PER_MINUTE; + case TSDB_TIME_PRECISION_MICRO: + return MILLISECOND_PER_MINUTE * 1000L; + case TSDB_TIME_PRECISION_NANO: + return NANOSECOND_PER_MINUTE; + default: + break; + } + return MILLISECOND_PER_MINUTE; +} + +static int64_t getBigintFromValueNode(SValueNode* pVal) { + if (pVal->isDuration) { + return pVal->datum.i / getUnitPerMinute(pVal->node.resType.precision); + } + return pVal->datum.i; +} + static int32_t buildCreateDbRetentions(const SNodeList* pRetentions, SCreateDbReq* pReq) { if (NULL != pRetentions) { pReq->pRetensions = taosArrayInit(LIST_LENGTH(pRetentions), sizeof(SRetention)); @@ -1098,7 +1159,10 @@ static int32_t checkRangeOption(STranslateContext* pCxt, const char* pName, SVal if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) { return pCxt->errCode; } - int64_t val = pVal->datum.i; + if (pVal->isDuration && (TIME_UNIT_MINUTE != pVal->unit && TIME_UNIT_HOUR != pVal->unit && TIME_UNIT_DAY != pVal->unit)) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_OPTION_UNIT, pName, pVal->unit); + } + int64_t val = getBigintFromValueNode(pVal); if (val < minVal || val > maxVal) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_RANGE_OPTION, pName, val, minVal, maxVal); } @@ -1187,9 +1251,18 @@ static int32_t checkKeepOption(STranslateContext* pCxt, SNodeList* pKeep) { } } - int32_t daysToKeep0 = ((SValueNode*)nodesListGetNode(pKeep, 0))->datum.i; - int32_t daysToKeep1 = ((SValueNode*)nodesListGetNode(pKeep, 1))->datum.i; - int32_t daysToKeep2 = ((SValueNode*)nodesListGetNode(pKeep, 2))->datum.i; + SValueNode* pKeep0 = (SValueNode*)nodesListGetNode(pKeep, 0); + SValueNode* pKeep1 = (SValueNode*)nodesListGetNode(pKeep, 1); + SValueNode* pKeep2 = (SValueNode*)nodesListGetNode(pKeep, 2); + if ((pKeep0->isDuration && (TIME_UNIT_MINUTE != pKeep0->unit && TIME_UNIT_HOUR != pKeep0->unit && TIME_UNIT_DAY != pKeep0->unit)) || + (pKeep1->isDuration && (TIME_UNIT_MINUTE != pKeep1->unit && TIME_UNIT_HOUR != pKeep1->unit && TIME_UNIT_DAY != pKeep1->unit)) || + (pKeep2->isDuration && (TIME_UNIT_MINUTE != pKeep2->unit && TIME_UNIT_HOUR != pKeep2->unit && TIME_UNIT_DAY != pKeep2->unit))) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_KEEP_UNIT, pKeep0->unit, pKeep1->unit, pKeep2->unit); + } + + int32_t daysToKeep0 = getBigintFromValueNode(pKeep0); + int32_t daysToKeep1 = getBigintFromValueNode(pKeep1); + int32_t daysToKeep2 = getBigintFromValueNode(pKeep2); if (daysToKeep0 < TSDB_MIN_KEEP || daysToKeep1 < TSDB_MIN_KEEP || daysToKeep2 < TSDB_MIN_KEEP || daysToKeep0 > TSDB_MAX_KEEP || daysToKeep1 > TSDB_MAX_KEEP || daysToKeep2 > TSDB_MAX_KEEP) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_KEEP_VALUE, daysToKeep0, daysToKeep1, daysToKeep2, @@ -1240,8 +1313,7 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, SDatabaseOptions* p code = checkRangeOption(pCxt, "compression", pOptions->pCompressionLevel, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL); } if (TSDB_CODE_SUCCESS == code) { - code = - checkRangeOption(pCxt, "daysPerFile", pOptions->pDaysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE); + code = checkRangeOption(pCxt, "daysPerFile", pOptions->pDaysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE); } if (TSDB_CODE_SUCCESS == code) { code = checkRangeOption(pCxt, "fsyncPeriod", pOptions->pFsyncPeriod, TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD); @@ -1294,6 +1366,25 @@ static int32_t checkCreateDatabase(STranslateContext* pCxt, SCreateDatabaseStmt* return checkDatabaseOptions(pCxt, pStmt->pOptions); } +typedef int32_t (*FSerializeFunc)(void *pBuf, int32_t bufLen, void *pReq); + +static int32_t buildCmdMsg(STranslateContext* pCxt, int16_t msgType, FSerializeFunc func, void* pReq) { + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); + if (NULL == pCxt->pCmdMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; + pCxt->pCmdMsg->msgType = msgType; + pCxt->pCmdMsg->msgLen = func(NULL, 0, pReq); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); + if (NULL == pCxt->pCmdMsg->pMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + func(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, pReq); + + return TSDB_CODE_SUCCESS; +} + static int32_t translateCreateDatabase(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt) { SCreateDbReq createReq = {0}; @@ -1303,18 +1394,7 @@ static int32_t translateCreateDatabase(STranslateContext* pCxt, SCreateDatabaseS } if (TSDB_CODE_SUCCESS == code) { - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_DB; - pCxt->pCmdMsg->msgLen = tSerializeSCreateDbReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSCreateDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); + code = buildCmdMsg(pCxt, TDMT_MND_CREATE_DB, (FSerializeFunc)tSerializeSCreateDbReq, &createReq); } return code; @@ -1322,25 +1402,12 @@ static int32_t translateCreateDatabase(STranslateContext* pCxt, SCreateDatabaseS static int32_t translateDropDatabase(STranslateContext* pCxt, SDropDatabaseStmt* pStmt) { SDropDbReq dropReq = {0}; - SName name = {0}; + SName name = {0}; tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); tNameGetFullDbName(&name, dropReq.db); dropReq.ignoreNotExists = pStmt->ignoreNotExists; - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_DROP_DB; - pCxt->pCmdMsg->msgLen = tSerializeSDropDbReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSDropDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_DROP_DB, (FSerializeFunc)tSerializeSDropDbReq, &dropReq); } static void buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt, SAlterDbReq* pReq) { @@ -1368,20 +1435,7 @@ static int32_t translateAlterDatabase(STranslateContext* pCxt, SAlterDatabaseStm SAlterDbReq alterReq = {0}; buildAlterDbReq(pCxt, pStmt, &alterReq); - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_ALTER_DB; - pCxt->pCmdMsg->msgLen = tSerializeSAlterDbReq(NULL, 0, &alterReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSAlterDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &alterReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_ALTER_DB, (FSerializeFunc)tSerializeSAlterDbReq, &alterReq); } static int32_t calcTypeBytes(SDataType dt) { @@ -1543,23 +1597,9 @@ static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableSt strcpy(tableName.tname, pStmt->tableName); tNameExtractFullName(&tableName, createReq.name); - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - tFreeSMCreateStbReq(&createReq); - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_STB; - pCxt->pCmdMsg->msgLen = tSerializeSMCreateStbReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - tFreeSMCreateStbReq(&createReq); - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSMCreateStbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); - + code = buildCmdMsg(pCxt, TDMT_MND_CREATE_STB, (FSerializeFunc)tSerializeSMCreateStbReq, &createReq); tFreeSMCreateStbReq(&createReq); - return TSDB_CODE_SUCCESS; + return code; } static int32_t doTranslateDropSuperTable(STranslateContext* pCxt, const SName* pTableName, bool ignoreNotExists) { @@ -1567,20 +1607,7 @@ static int32_t doTranslateDropSuperTable(STranslateContext* pCxt, const SName* p tNameExtractFullName(pTableName, dropReq.name); dropReq.igNotExists = ignoreNotExists; - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_DROP_STB; - pCxt->pCmdMsg->msgLen = tSerializeSMDropStbReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSMDropStbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_DROP_STB, (FSerializeFunc)tSerializeSMDropStbReq, &dropReq); } static int32_t translateDropTable(STranslateContext* pCxt, SDropTableStmt* pStmt) { @@ -1664,20 +1691,7 @@ static int32_t translateAlterTable(STranslateContext* pCxt, SAlterTableStmt* pSt } } - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_ALTER_STB; - pCxt->pCmdMsg->msgLen = tSerializeSMAlterStbReq(NULL, 0, &alterReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSMAlterStbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &alterReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_ALTER_STB, (FSerializeFunc)tSerializeSMAlterStbReq, &alterReq); } static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* pStmt) { @@ -1686,24 +1700,10 @@ static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* p tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); tNameExtractFullName(&name, usedbReq.db); int32_t code = getDBVgVersion(pCxt, usedbReq.db, &usedbReq.vgVersion, &usedbReq.dbId, &usedbReq.numOfTable); - if (TSDB_CODE_SUCCESS != code) { - return code; - } - - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_USE_DB; - pCxt->pCmdMsg->msgLen = tSerializeSUseDbReq(NULL, 0, &usedbReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; + if (TSDB_CODE_SUCCESS == code) { + code = buildCmdMsg(pCxt, TDMT_MND_USE_DB, (FSerializeFunc)tSerializeSUseDbReq, &usedbReq); } - tSerializeSUseDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &usedbReq); - - return TSDB_CODE_SUCCESS; + return code; } static int32_t translateCreateUser(STranslateContext* pCxt, SCreateUserStmt* pStmt) { @@ -1713,20 +1713,7 @@ static int32_t translateCreateUser(STranslateContext* pCxt, SCreateUserStmt* pSt createReq.superUser = 0; strcpy(createReq.pass, pStmt->password); - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_USER; - pCxt->pCmdMsg->msgLen = tSerializeSCreateUserReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSCreateUserReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_CREATE_USER, (FSerializeFunc)tSerializeSCreateUserReq, &createReq); } static int32_t translateAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt) { @@ -1739,40 +1726,14 @@ static int32_t translateAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt strcpy(alterReq.dbname, pCxt->pParseCxt->db); } - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_ALTER_USER; - pCxt->pCmdMsg->msgLen = tSerializeSAlterUserReq(NULL, 0, &alterReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSAlterUserReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &alterReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_ALTER_USER, (FSerializeFunc)tSerializeSAlterUserReq, &alterReq); } static int32_t translateDropUser(STranslateContext* pCxt, SDropUserStmt* pStmt) { SDropUserReq dropReq = {0}; strcpy(dropReq.user, pStmt->useName); - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_DROP_USER; - pCxt->pCmdMsg->msgLen = tSerializeSDropUserReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSDropUserReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_DROP_USER, (FSerializeFunc)tSerializeSDropUserReq, &dropReq); } static int32_t translateCreateDnode(STranslateContext* pCxt, SCreateDnodeStmt* pStmt) { @@ -1780,20 +1741,7 @@ static int32_t translateCreateDnode(STranslateContext* pCxt, SCreateDnodeStmt* p strcpy(createReq.fqdn, pStmt->fqdn); createReq.port = pStmt->port; - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_DNODE; - pCxt->pCmdMsg->msgLen = tSerializeSCreateDnodeReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSCreateDnodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_CREATE_DNODE, (FSerializeFunc)tSerializeSCreateDnodeReq, &createReq); } static int32_t translateDropDnode(STranslateContext* pCxt, SDropDnodeStmt* pStmt) { @@ -1802,20 +1750,7 @@ static int32_t translateDropDnode(STranslateContext* pCxt, SDropDnodeStmt* pStmt strcpy(dropReq.fqdn, pStmt->fqdn); dropReq.port = pStmt->port; - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_DROP_DNODE; - pCxt->pCmdMsg->msgLen = tSerializeSDropDnodeReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSDropDnodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_DROP_DNODE, (FSerializeFunc)tSerializeSDropDnodeReq, &dropReq); } static int32_t translateAlterDnode(STranslateContext* pCxt, SAlterDnodeStmt* pStmt) { @@ -1824,61 +1759,30 @@ static int32_t translateAlterDnode(STranslateContext* pCxt, SAlterDnodeStmt* pSt strcpy(cfgReq.config, pStmt->config); strcpy(cfgReq.value, pStmt->value); - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CONFIG_DNODE; - pCxt->pCmdMsg->msgLen = tSerializeSMCfgDnodeReq(NULL, 0, &cfgReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSMCfgDnodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &cfgReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_CONFIG_DNODE, (FSerializeFunc)tSerializeSMCfgDnodeReq, &cfgReq); } static int32_t nodeTypeToShowType(ENodeType nt) { - switch (nt) { - case QUERY_NODE_SHOW_APPS_STMT: - return 0; // todo - case QUERY_NODE_SHOW_CONNECTIONS_STMT: - return TSDB_MGMT_TABLE_CONNS; - case QUERY_NODE_SHOW_LICENCE_STMT: - return TSDB_MGMT_TABLE_GRANTS; - case QUERY_NODE_SHOW_QUERIES_STMT: - return TSDB_MGMT_TABLE_QUERIES; - case QUERY_NODE_SHOW_SCORES_STMT: - return 0; // todo - case QUERY_NODE_SHOW_TOPICS_STMT: - return 0; // todo - case QUERY_NODE_SHOW_VARIABLE_STMT: - return TSDB_MGMT_TABLE_VARIABLES; - default: - break; - } + // switch (nt) { + // case QUERY_NODE_SHOW_CONNECTIONS_STMT: + // return TSDB_MGMT_TABLE_CONNS; + // case QUERY_NODE_SHOW_LICENCE_STMT: + // return TSDB_MGMT_TABLE_GRANTS; + // case QUERY_NODE_SHOW_QUERIES_STMT: + // return TSDB_MGMT_TABLE_QUERIES; + // case QUERY_NODE_SHOW_TOPICS_STMT: + // return 0; // todo + // case QUERY_NODE_SHOW_VARIABLE_STMT: + // return TSDB_MGMT_TABLE_VARIABLES; + // default: + // break; + // } return 0; } static int32_t translateShow(STranslateContext* pCxt, SShowStmt* pStmt) { SShowReq showReq = {.type = nodeTypeToShowType(nodeType(pStmt))}; - - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_SHOW; - pCxt->pCmdMsg->msgLen = tSerializeSShowReq(NULL, 0, &showReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSShowReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &showReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_SHOW, (FSerializeFunc)tSerializeSShowReq, &showReq); } static int32_t getSmaIndexDstVgId(STranslateContext* pCxt, char* pTableName, int32_t* pVgId) { @@ -1998,61 +1902,25 @@ static int32_t translateCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt } SMCreateSmaReq createSmaReq = {0}; - int32_t code = buildCreateSmaReq(pCxt, pStmt, &createSmaReq); - if (TSDB_CODE_SUCCESS != code) { - return code; - } - - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_SMA; - pCxt->pCmdMsg->msgLen = tSerializeSMCreateSmaReq(NULL, 0, &createSmaReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; + if (TSDB_CODE_SUCCESS == code) { + code = buildCmdMsg(pCxt, TDMT_MND_CREATE_SMA, (FSerializeFunc)tSerializeSMCreateSmaReq, &createSmaReq); } - tSerializeSMCreateSmaReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createSmaReq); tFreeSMCreateSmaReq(&createSmaReq); - - return TSDB_CODE_SUCCESS; + return code; } static int32_t buildCreateFullTextReq(STranslateContext* pCxt, SCreateIndexStmt* pStmt, SMCreateFullTextReq* pReq) { // impl later return 0; } static int32_t translateCreateFullTextIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt) { - if (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pInterval) || - (NULL != pStmt->pOptions->pOffset && - DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pOffset)) || - (NULL != pStmt->pOptions->pSliding && - DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pSliding))) { - return pCxt->errCode; - } SMCreateFullTextReq createFTReq = {0}; - int32_t code = buildCreateFullTextReq(pCxt, pStmt, &createFTReq); - if (TSDB_CODE_SUCCESS != code) { - return code; - } - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_INDEX; - pCxt->pCmdMsg->msgLen = tSerializeSMCreateFullTextReq(NULL, 0, &createFTReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; + if (TSDB_CODE_SUCCESS == code) { + code = buildCmdMsg(pCxt, TDMT_MND_CREATE_INDEX, (FSerializeFunc)tSerializeSMCreateFullTextReq, &createFTReq); } - tSerializeSMCreateFullTextReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createFTReq); tFreeSMCreateFullTextReq(&createFTReq); - - return TSDB_CODE_SUCCESS; + return code; } static int32_t translateCreateIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt) { @@ -2060,7 +1928,6 @@ static int32_t translateCreateIndex(STranslateContext* pCxt, SCreateIndexStmt* p return translateCreateSmaIndex(pCxt, pStmt); } else if (INDEX_TYPE_FULLTEXT == pStmt->indexType) { return translateCreateFullTextIndex(pCxt, pStmt); - // todo fulltext index } return TSDB_CODE_FAILED; } @@ -2104,21 +1971,7 @@ static int16_t getCreateComponentNodeMsgType(ENodeType type) { static int32_t translateCreateComponentNode(STranslateContext* pCxt, SCreateComponentNodeStmt* pStmt) { SMCreateQnodeReq createReq = {.dnodeId = pStmt->dnodeId}; - - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = getCreateComponentNodeMsgType(nodeType(pStmt)); - pCxt->pCmdMsg->msgLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSCreateDropMQSBNodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, getCreateComponentNodeMsgType(nodeType(pStmt)), (FSerializeFunc)tSerializeSCreateDropMQSBNodeReq, &createReq); } static int16_t getDropComponentNodeMsgType(ENodeType type) { @@ -2139,21 +1992,7 @@ static int16_t getDropComponentNodeMsgType(ENodeType type) { static int32_t translateDropComponentNode(STranslateContext* pCxt, SDropComponentNodeStmt* pStmt) { SDDropQnodeReq dropReq = {.dnodeId = pStmt->dnodeId}; - - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = getDropComponentNodeMsgType(nodeType(pStmt)); - pCxt->pCmdMsg->msgLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSCreateDropMQSBNodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, getDropComponentNodeMsgType(nodeType(pStmt)), (FSerializeFunc)tSerializeSCreateDropMQSBNodeReq, &dropReq); } static int32_t translateCreateTopic(STranslateContext* pCxt, SCreateTopicStmt* pStmt) { @@ -2183,21 +2022,9 @@ static int32_t translateCreateTopic(STranslateContext* pCxt, SCreateTopicStmt* p tNameExtractFullName(&name, createReq.name); createReq.igExists = pStmt->ignoreExists; - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_TOPIC; - pCxt->pCmdMsg->msgLen = tSerializeSCMCreateTopicReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSCMCreateTopicReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); + int32_t code = buildCmdMsg(pCxt, TDMT_MND_CREATE_TOPIC, (FSerializeFunc)tSerializeSCMCreateTopicReq, &createReq); tFreeSCMCreateTopicReq(&createReq); - - return TSDB_CODE_SUCCESS; + return code; } static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt) { @@ -2209,20 +2036,7 @@ static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt tNameExtractFullName(&name, dropReq.name); dropReq.igNotExists = pStmt->ignoreNotExists; - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_DROP_TOPIC; - pCxt->pCmdMsg->msgLen = tSerializeSMDropTopicReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSMDropTopicReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_DROP_TOPIC, (FSerializeFunc)tSerializeSMDropTopicReq, &dropReq); } static int32_t translateAlterLocal(STranslateContext* pCxt, SAlterLocalStmt* pStmt) { @@ -2241,6 +2055,19 @@ static int32_t translateDescribe(STranslateContext* pCxt, SDescribeStmt* pStmt) return getTableMeta(pCxt, pStmt->dbName, pStmt->tableName, &pStmt->pMeta); } +static int32_t translateKillConnection(STranslateContext* pCxt, SKillStmt* pStmt) { + SKillConnReq killReq = {0}; + killReq.connId = pStmt->targetId; + return buildCmdMsg(pCxt, TDMT_MND_KILL_CONN, (FSerializeFunc)tSerializeSKillQueryReq, &killReq); +} + +static int32_t translateKillQuery(STranslateContext* pCxt, SKillStmt* pStmt) { + SKillQueryReq killReq = {0}; + killReq.queryId = pStmt->targetId; + return buildCmdMsg(pCxt, TDMT_MND_KILL_QUERY, (FSerializeFunc)tSerializeSKillQueryReq, &killReq); +} + + static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { int32_t code = TSDB_CODE_SUCCESS; switch (nodeType(pNode)) { @@ -2289,20 +2116,11 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_ALTER_DNODE_STMT: code = translateAlterDnode(pCxt, (SAlterDnodeStmt*)pNode); break; - case QUERY_NODE_SHOW_APPS_STMT: case QUERY_NODE_SHOW_CONNECTIONS_STMT: - case QUERY_NODE_SHOW_LICENCE_STMT: case QUERY_NODE_SHOW_QUERIES_STMT: - case QUERY_NODE_SHOW_SCORES_STMT: case QUERY_NODE_SHOW_TOPICS_STMT: - case QUERY_NODE_SHOW_VARIABLE_STMT: code = translateShow(pCxt, (SShowStmt*)pNode); break; - case QUERY_NODE_SHOW_CREATE_DATABASE_STMT: - case QUERY_NODE_SHOW_CREATE_TABLE_STMT: - case QUERY_NODE_SHOW_CREATE_STABLE_STMT: - // todo - break; case QUERY_NODE_CREATE_INDEX_STMT: code = translateCreateIndex(pCxt, (SCreateIndexStmt*)pNode); break; @@ -2336,6 +2154,12 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_DESCRIBE_STMT: code = translateDescribe(pCxt, (SDescribeStmt*)pNode); break; + case QUERY_NODE_KILL_CONNECTION_STMT: + code = translateKillConnection(pCxt, (SKillStmt*)pNode); + break; + case QUERY_NODE_KILL_QUERY_STMT: + code = translateKillQuery(pCxt, (SKillStmt*)pNode); + break; default: break; } @@ -2449,6 +2273,33 @@ static void destroyTranslateContext(STranslateContext* pCxt) { taosHashCleanup(pCxt->pTables); } +static const char* getSysDbName(ENodeType type) { + switch (type) { + case QUERY_NODE_SHOW_DATABASES_STMT: + case QUERY_NODE_SHOW_TABLES_STMT: + case QUERY_NODE_SHOW_STABLES_STMT: + case QUERY_NODE_SHOW_USERS_STMT: + case QUERY_NODE_SHOW_DNODES_STMT: + case QUERY_NODE_SHOW_VGROUPS_STMT: + case QUERY_NODE_SHOW_MNODES_STMT: + case QUERY_NODE_SHOW_MODULES_STMT: + case QUERY_NODE_SHOW_QNODES_STMT: + case QUERY_NODE_SHOW_FUNCTIONS_STMT: + case QUERY_NODE_SHOW_INDEXES_STMT: + case QUERY_NODE_SHOW_STREAMS_STMT: + case QUERY_NODE_SHOW_BNODES_STMT: + case QUERY_NODE_SHOW_SNODES_STMT: + case QUERY_NODE_SHOW_LICENCE_STMT: + return TSDB_INFORMATION_SCHEMA_DB; + case QUERY_NODE_SHOW_CONNECTIONS_STMT: + case QUERY_NODE_SHOW_QUERIES_STMT: + return TSDB_PERFORMANCE_SCHEMA_DB; + default: + break; + } + return NULL; +} + static const char* getSysTableName(ENodeType type) { switch (type) { case QUERY_NODE_SHOW_DATABASES_STMT: @@ -2479,6 +2330,11 @@ static const char* getSysTableName(ENodeType type) { return TSDB_INS_TABLE_BNODES; case QUERY_NODE_SHOW_SNODES_STMT: return TSDB_INS_TABLE_SNODES; + case QUERY_NODE_SHOW_LICENCE_STMT: + return TSDB_INS_TABLE_LICENCES; + case QUERY_NODE_SHOW_CONNECTIONS_STMT: + case QUERY_NODE_SHOW_QUERIES_STMT: + // todo default: break; } @@ -2497,7 +2353,7 @@ static int32_t createSelectStmtForShow(ENodeType showType, SSelectStmt** pStmt) nodesDestroyNode(pSelect); return TSDB_CODE_OUT_OF_MEMORY; } - strcpy(pTable->table.dbName, TSDB_INFORMATION_SCHEMA_DB); + strcpy(pTable->table.dbName, getSysDbName(showType)); strcpy(pTable->table.tableName, getSysTableName(showType)); strcpy(pTable->table.tableAlias, pTable->table.tableName); pSelect->pFromTable = (SNode*)pTable; @@ -2986,6 +2842,7 @@ static int32_t rewriteAlterTable(STranslateContext* pCxt, SQuery* pQuery) { static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { int32_t code = TSDB_CODE_SUCCESS; switch (nodeType(pQuery->pRoot)) { + case QUERY_NODE_SHOW_LICENCE_STMT: case QUERY_NODE_SHOW_DATABASES_STMT: case QUERY_NODE_SHOW_TABLES_STMT: case QUERY_NODE_SHOW_STABLES_STMT: @@ -3000,6 +2857,8 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_SHOW_STREAMS_STMT: case QUERY_NODE_SHOW_BNODES_STMT: case QUERY_NODE_SHOW_SNODES_STMT: + case QUERY_NODE_SHOW_CONNECTIONS_STMT: + case QUERY_NODE_SHOW_QUERIES_STMT: code = rewriteShow(pCxt, pQuery); break; case QUERY_NODE_CREATE_TABLE_STMT: diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 171324aa99680b2daa6456af8e66a0204d405aeb..efc807850f4c25fb27addd8b7b1f40e76467dc9c 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -31,10 +31,6 @@ static char* getSyntaxErrFormat(int32_t errCode) { return "Invalid value type : %s"; case TSDB_CODE_PAR_INVALID_FUNTION: return "Invalid function name : %s"; - case TSDB_CODE_PAR_FUNTION_PARA_NUM: - return "Invalid number of arguments : %s"; - case TSDB_CODE_PAR_FUNTION_PARA_TYPE: - return "Inconsistent datatypes : %s"; case TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION: return "There mustn't be aggregation"; case TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT: @@ -62,35 +58,39 @@ static char* getSyntaxErrFormat(int32_t errCode) { case TSDB_CODE_PAR_INTERVAL_VALUE_TOO_SMALL: return "This interval value is too small : %s"; case TSDB_CODE_PAR_DB_NOT_SPECIFIED: - return "db not specified"; + return "Database not specified"; case TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME: return "Invalid identifier name : %s"; case TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR: - return "corresponding super table not in this db"; + return "Corresponding super table not in this db"; case TSDB_CODE_PAR_INVALID_RANGE_OPTION: - return "invalid option %s: %"PRId64" valid range: [%d, %d]"; + return "Invalid option %s: %"PRId64" valid range: [%d, %d]"; case TSDB_CODE_PAR_INVALID_STR_OPTION: - return "invalid option %s: %s"; + return "Invalid option %s: %s"; case TSDB_CODE_PAR_INVALID_ENUM_OPTION: - return "invalid option %s: %"PRId64", only %d, %d allowed"; + return "Invalid option %s: %"PRId64", only %d, %d allowed"; case TSDB_CODE_PAR_INVALID_TTL_OPTION: - return "invalid option ttl: %"PRId64", should be greater than or equal to %d"; + return "Invalid option ttl: %"PRId64", should be greater than or equal to %d"; case TSDB_CODE_PAR_INVALID_KEEP_NUM: - return "invalid number of keep options"; + return "Invalid number of keep options"; case TSDB_CODE_PAR_INVALID_KEEP_ORDER: - return "invalid keep value, should be keep0 <= keep1 <= keep2"; + return "Invalid keep value, should be keep0 <= keep1 <= keep2"; case TSDB_CODE_PAR_INVALID_KEEP_VALUE: - return "invalid option keep: %d, %d, %d valid range: [%d, %d]"; + return "Invalid option keep: %d, %d, %d valid range: [%d, %d]"; case TSDB_CODE_PAR_INVALID_COMMENT_OPTION: - return "invalid option comment, length cannot exceed %d"; + return "Invalid option comment, length cannot exceed %d"; case TSDB_CODE_PAR_INVALID_F_RANGE_OPTION: - return "invalid option %s: %f valid range: [%d, %d]"; + return "Invalid option %s: %f valid range: [%d, %d]"; case TSDB_CODE_PAR_INVALID_ROLLUP_OPTION: - return "invalid option rollup: only one function is allowed"; + return "Invalid option rollup: only one function is allowed"; case TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION: - return "invalid option retentions"; + return "Invalid option retentions"; case TSDB_CODE_PAR_GROUPBY_WINDOW_COEXIST: return "GROUP BY and WINDOW-clause can't be used together"; + case TSDB_CODE_PAR_INVALID_OPTION_UNIT: + return "Invalid option %s unit: %c, only m, h, d allowed"; + case TSDB_CODE_PAR_INVALID_KEEP_UNIT: + return "Invalid option keep unit: %c, %c, %c, only m, h, d allowed"; case TSDB_CODE_OUT_OF_MEMORY: return "Out of memory"; default: diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index a8f764f0e166a158a7590afde11570025026b2f6..d3f5af3eb2aff825e956077b3b39adb6731d3fd1 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -100,24 +100,24 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 313 +#define YYNOCODE 316 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SToken yy21; - bool yy173; - EOrder yy256; - EFillMode yy268; - SDataType yy288; - SAlterOption yy289; - EJoinType yy440; - EOperatorType yy468; - SNodeList* yy476; - ENullOrder yy525; - SNode* yy564; - int32_t yy620; + SAlterOption yy21; + EFillMode yy22; + EOperatorType yy84; + bool yy121; + SDataType yy160; + ENullOrder yy281; + SToken yy409; + int32_t yy452; + SNodeList* yy488; + SNode* yy504; + EOrder yy522; + EJoinType yy556; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -132,18 +132,17 @@ typedef union { #define ParseCTX_PARAM #define ParseCTX_FETCH #define ParseCTX_STORE -#define YYNSTATE 547 -#define YYNRULE 409 -#define YYNRULE_WITH_ACTION 409 -#define YYNTOKEN 207 -#define YY_MAX_SHIFT 546 -#define YY_MIN_SHIFTREDUCE 806 -#define YY_MAX_SHIFTREDUCE 1214 -#define YY_ERROR_ACTION 1215 -#define YY_ACCEPT_ACTION 1216 -#define YY_NO_ACTION 1217 -#define YY_MIN_REDUCE 1218 -#define YY_MAX_REDUCE 1626 +#define YYNSTATE 550 +#define YYNRULE 411 +#define YYNTOKEN 210 +#define YY_MAX_SHIFT 549 +#define YY_MIN_SHIFTREDUCE 810 +#define YY_MAX_SHIFTREDUCE 1220 +#define YY_ERROR_ACTION 1221 +#define YY_ACCEPT_ACTION 1222 +#define YY_NO_ACTION 1223 +#define YY_MIN_REDUCE 1224 +#define YY_MAX_REDUCE 1634 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -210,481 +209,487 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (1529) +#define YY_ACTTAB_COUNT (1556) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 25, 194, 1478, 1327, 257, 449, 1494, 462, 269, 312, - /* 10 */ 277, 1427, 30, 28, 1474, 1481, 310, 1418, 1420, 1454, - /* 20 */ 266, 1478, 1050, 274, 429, 32, 31, 29, 27, 26, - /* 30 */ 1511, 21, 1338, 1474, 1480, 306, 461, 445, 1048, 238, - /* 40 */ 1478, 32, 31, 29, 27, 26, 1072, 448, 23, 100, - /* 50 */ 11, 1465, 1474, 1480, 1494, 289, 433, 1055, 32, 31, - /* 60 */ 29, 27, 26, 30, 28, 1157, 1605, 228, 1495, 1496, - /* 70 */ 1500, 266, 216, 1050, 1, 1368, 30, 28, 1511, 131, - /* 80 */ 1558, 137, 98, 1603, 266, 445, 1050, 1605, 1171, 1048, - /* 90 */ 52, 431, 127, 1551, 1552, 448, 1556, 543, 1555, 1465, - /* 100 */ 131, 11, 1048, 96, 1603, 1073, 1216, 50, 1055, 1049, - /* 110 */ 49, 1333, 380, 379, 11, 70, 1495, 1496, 1500, 1544, - /* 120 */ 461, 1055, 347, 1543, 1540, 1, 1219, 932, 485, 484, - /* 130 */ 483, 936, 482, 938, 939, 481, 941, 478, 1, 947, - /* 140 */ 475, 949, 950, 472, 469, 1051, 488, 84, 543, 1329, - /* 150 */ 83, 82, 81, 80, 79, 78, 77, 76, 75, 282, - /* 160 */ 1049, 543, 1054, 1074, 1075, 1101, 1102, 1103, 1104, 1105, - /* 170 */ 1106, 1107, 1108, 1049, 12, 1050, 462, 1070, 164, 30, - /* 180 */ 28, 117, 371, 1230, 132, 311, 382, 266, 376, 1050, - /* 190 */ 1605, 1048, 381, 405, 1465, 97, 1051, 377, 375, 157, - /* 200 */ 378, 1338, 155, 131, 373, 1048, 305, 1603, 304, 1051, - /* 210 */ 1055, 396, 461, 1054, 1074, 1075, 1101, 1102, 1103, 1104, - /* 220 */ 1105, 1106, 1107, 1108, 1055, 419, 1054, 1074, 1075, 1101, - /* 230 */ 1102, 1103, 1104, 1105, 1106, 1107, 1108, 406, 462, 1181, - /* 240 */ 132, 7, 1605, 30, 28, 447, 132, 72, 1074, 1075, - /* 250 */ 543, 266, 462, 1050, 368, 131, 894, 30, 28, 1603, - /* 260 */ 1076, 319, 1049, 1338, 543, 266, 12, 1050, 1605, 1048, - /* 270 */ 416, 1179, 1180, 1182, 1183, 896, 1049, 1338, 52, 424, - /* 280 */ 420, 131, 1494, 1048, 132, 1603, 84, 1605, 1055, 83, - /* 290 */ 82, 81, 80, 79, 78, 77, 76, 75, 1051, 1334, - /* 300 */ 1604, 333, 1055, 65, 1603, 7, 1511, 32, 31, 29, - /* 310 */ 27, 26, 1051, 445, 1511, 1054, 118, 101, 1241, 7, - /* 320 */ 1296, 445, 423, 448, 1330, 1494, 1316, 1465, 543, 1054, - /* 330 */ 1074, 1075, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, - /* 340 */ 1049, 132, 543, 119, 1495, 1496, 1500, 141, 140, 1511, - /* 350 */ 237, 132, 1070, 422, 1049, 462, 445, 122, 497, 326, - /* 360 */ 462, 1558, 338, 1465, 320, 1071, 448, 429, 1378, 346, - /* 370 */ 1465, 339, 1385, 265, 1240, 347, 1051, 189, 256, 1554, - /* 380 */ 1338, 434, 1618, 1383, 59, 1338, 229, 1495, 1496, 1500, - /* 390 */ 1051, 499, 100, 1054, 1074, 1075, 1101, 1102, 1103, 1104, - /* 400 */ 1105, 1106, 1107, 1108, 843, 1331, 842, 1054, 1074, 1075, - /* 410 */ 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 462, 1465, - /* 420 */ 30, 28, 1385, 1385, 844, 98, 1239, 1335, 266, 271, - /* 430 */ 1050, 1267, 114, 1419, 1383, 128, 1551, 1552, 1415, 1556, - /* 440 */ 29, 27, 26, 1338, 337, 139, 1048, 332, 331, 330, - /* 450 */ 329, 328, 1485, 325, 324, 323, 322, 318, 317, 316, - /* 460 */ 315, 314, 313, 462, 1483, 1055, 32, 31, 29, 27, - /* 470 */ 26, 1465, 459, 539, 538, 32, 31, 29, 27, 26, - /* 480 */ 250, 1323, 1, 519, 518, 517, 516, 281, 1338, 515, - /* 490 */ 514, 513, 102, 508, 507, 506, 505, 504, 503, 502, - /* 500 */ 501, 108, 1494, 462, 241, 543, 164, 511, 115, 462, - /* 510 */ 371, 300, 72, 241, 449, 270, 1341, 1049, 460, 374, - /* 520 */ 1428, 1325, 251, 115, 249, 248, 1511, 370, 1338, 1089, - /* 530 */ 1218, 1340, 373, 445, 1338, 842, 276, 1120, 32, 31, - /* 540 */ 29, 27, 26, 448, 115, 404, 1120, 1465, 9, 8, - /* 550 */ 1558, 366, 1340, 1051, 93, 92, 91, 90, 89, 88, - /* 560 */ 87, 86, 85, 225, 1495, 1496, 1500, 1314, 1553, 1122, - /* 570 */ 1054, 1074, 1075, 1101, 1102, 1103, 1104, 1105, 1106, 1107, - /* 580 */ 1108, 387, 1164, 279, 462, 1121, 1385, 1126, 1072, 462, - /* 590 */ 116, 115, 278, 208, 1121, 222, 395, 1383, 280, 1340, - /* 600 */ 1238, 1089, 868, 1125, 1237, 6, 1236, 220, 1270, 1338, - /* 610 */ 166, 22, 1125, 390, 1338, 1385, 497, 500, 384, 1310, - /* 620 */ 142, 869, 1133, 1494, 165, 1235, 1384, 24, 264, 1115, - /* 630 */ 1116, 1117, 1118, 1119, 1123, 1124, 24, 264, 1115, 1116, - /* 640 */ 1117, 1118, 1119, 1123, 1124, 1465, 1077, 1511, 1156, 1465, - /* 650 */ 42, 1465, 1234, 41, 445, 32, 31, 29, 27, 26, - /* 660 */ 382, 1233, 376, 106, 448, 1321, 381, 408, 1465, 97, - /* 670 */ 1465, 377, 375, 433, 378, 512, 510, 1494, 1232, 1229, - /* 680 */ 1228, 1227, 436, 67, 68, 1495, 1496, 1500, 1544, 1226, - /* 690 */ 273, 272, 240, 1540, 394, 9, 8, 1465, 1225, 1224, - /* 700 */ 1063, 1511, 1563, 1152, 1605, 1223, 1465, 392, 432, 1222, - /* 710 */ 48, 47, 309, 1221, 136, 297, 1056, 131, 448, 303, - /* 720 */ 437, 1603, 1465, 1465, 1465, 1465, 1465, 246, 1494, 295, - /* 730 */ 299, 291, 287, 133, 1465, 1055, 440, 444, 69, 1495, - /* 740 */ 1496, 1500, 1544, 1465, 1465, 1152, 259, 1540, 126, 169, - /* 750 */ 1465, 546, 1511, 44, 1465, 1231, 132, 1178, 1465, 432, - /* 760 */ 190, 159, 446, 175, 158, 213, 412, 1571, 95, 448, - /* 770 */ 64, 1494, 1257, 1465, 535, 463, 531, 527, 523, 212, - /* 780 */ 61, 161, 163, 1494, 160, 162, 487, 1059, 1252, 69, - /* 790 */ 1495, 1496, 1500, 1544, 383, 1511, 1494, 259, 1540, 126, - /* 800 */ 1250, 1297, 445, 1213, 1214, 66, 417, 1511, 206, 191, - /* 810 */ 385, 342, 448, 178, 445, 33, 1465, 180, 1572, 1127, - /* 820 */ 1511, 403, 388, 1064, 448, 1379, 33, 445, 1465, 1155, - /* 830 */ 1085, 1494, 231, 1495, 1496, 1500, 184, 448, 458, 1058, - /* 840 */ 1067, 1465, 365, 1494, 69, 1495, 1496, 1500, 1544, 1112, - /* 850 */ 1574, 438, 259, 1540, 1617, 1511, 1512, 70, 1495, 1496, - /* 860 */ 1500, 1544, 445, 1578, 430, 411, 1541, 1511, 171, 441, - /* 870 */ 1057, 193, 448, 1070, 445, 2, 1465, 33, 284, 435, - /* 880 */ 245, 1017, 197, 1034, 448, 168, 199, 94, 1465, 894, - /* 890 */ 247, 454, 69, 1495, 1496, 1500, 1544, 1026, 214, 288, - /* 900 */ 259, 1540, 1617, 1494, 69, 1495, 1496, 1500, 1544, 138, - /* 910 */ 1061, 1601, 259, 1540, 1617, 104, 321, 152, 429, 205, - /* 920 */ 125, 106, 1417, 1562, 327, 925, 364, 1511, 360, 356, - /* 930 */ 352, 151, 44, 467, 445, 335, 920, 953, 104, 1494, - /* 940 */ 340, 1060, 957, 100, 448, 334, 336, 1081, 1465, 341, - /* 950 */ 1494, 1080, 32, 31, 29, 27, 26, 53, 344, 144, - /* 960 */ 149, 1079, 433, 1511, 70, 1495, 1496, 1500, 1544, 343, - /* 970 */ 445, 345, 443, 1540, 1511, 105, 98, 147, 51, 963, - /* 980 */ 448, 445, 348, 429, 1465, 106, 187, 1551, 428, 962, - /* 990 */ 427, 448, 104, 1605, 150, 1465, 107, 1078, 413, 367, - /* 1000 */ 232, 1495, 1496, 1500, 1494, 369, 131, 1328, 100, 1494, - /* 1010 */ 1603, 233, 1495, 1496, 1500, 154, 148, 1324, 121, 156, - /* 1020 */ 145, 74, 372, 397, 109, 110, 1326, 1322, 1511, 111, - /* 1030 */ 112, 255, 425, 1511, 398, 445, 407, 143, 1494, 399, - /* 1040 */ 445, 98, 400, 1077, 170, 448, 173, 418, 409, 1465, - /* 1050 */ 448, 129, 1551, 1552, 1465, 1556, 1575, 263, 1585, 452, - /* 1060 */ 410, 1055, 1511, 1584, 1494, 119, 1495, 1496, 1500, 445, - /* 1070 */ 233, 1495, 1496, 1500, 176, 415, 5, 179, 1211, 448, - /* 1080 */ 258, 421, 1565, 1465, 426, 414, 267, 99, 1511, 4, - /* 1090 */ 1076, 1152, 1559, 124, 183, 445, 34, 185, 260, 233, - /* 1100 */ 1495, 1496, 1500, 442, 1619, 448, 1494, 439, 17, 1465, - /* 1110 */ 456, 1494, 186, 1526, 1426, 450, 192, 1494, 455, 1602, - /* 1120 */ 451, 1620, 1425, 201, 268, 234, 1495, 1496, 1500, 215, - /* 1130 */ 1511, 457, 203, 58, 1339, 1511, 60, 445, 217, 465, - /* 1140 */ 494, 1511, 445, 1311, 211, 1210, 542, 448, 445, 1315, - /* 1150 */ 40, 1465, 448, 223, 224, 219, 1465, 1459, 448, 1494, - /* 1160 */ 221, 1458, 1465, 283, 1455, 285, 286, 226, 1495, 1496, - /* 1170 */ 1500, 1494, 235, 1495, 1496, 1500, 1044, 1045, 227, 1495, - /* 1180 */ 1496, 1500, 134, 1511, 1494, 290, 1453, 1452, 292, 293, - /* 1190 */ 445, 294, 296, 1451, 298, 1511, 1442, 135, 301, 302, - /* 1200 */ 448, 1313, 445, 1029, 1465, 1028, 1436, 1435, 1511, 308, - /* 1210 */ 209, 307, 448, 1494, 493, 445, 1465, 1434, 1433, 1000, - /* 1220 */ 236, 1495, 1496, 1500, 1410, 448, 1409, 1408, 1407, 1465, - /* 1230 */ 1406, 1405, 1508, 1495, 1496, 1500, 495, 1511, 1404, 1494, - /* 1240 */ 1403, 1402, 1401, 1400, 445, 1507, 1495, 1496, 1500, 1399, - /* 1250 */ 1398, 1397, 1396, 1395, 448, 492, 491, 490, 1465, 489, - /* 1260 */ 103, 1394, 209, 1511, 1393, 1494, 493, 1392, 1391, 1390, - /* 1270 */ 445, 1389, 1388, 1494, 243, 1495, 1496, 1500, 1002, 1387, - /* 1280 */ 448, 1386, 1269, 1450, 1465, 1444, 1432, 1423, 495, 1511, - /* 1290 */ 146, 1317, 1268, 1266, 350, 861, 445, 1511, 349, 1494, - /* 1300 */ 1506, 1495, 1496, 1500, 445, 351, 448, 492, 491, 490, - /* 1310 */ 1465, 489, 1264, 353, 448, 1262, 354, 355, 1465, 359, - /* 1320 */ 1260, 363, 357, 1511, 358, 362, 244, 1495, 1496, 1500, - /* 1330 */ 445, 1249, 361, 1248, 242, 1495, 1496, 1500, 1245, 1319, - /* 1340 */ 448, 1494, 73, 970, 1465, 968, 153, 1318, 511, 893, - /* 1350 */ 1258, 892, 891, 1253, 890, 887, 886, 252, 253, 1251, - /* 1360 */ 239, 1495, 1496, 1500, 386, 1511, 509, 254, 389, 1244, - /* 1370 */ 391, 1243, 445, 393, 71, 1449, 43, 167, 1036, 1443, - /* 1380 */ 401, 1431, 448, 113, 1430, 402, 1465, 1422, 123, 172, - /* 1390 */ 14, 15, 37, 54, 1483, 174, 177, 3, 33, 38, - /* 1400 */ 182, 35, 230, 1495, 1496, 1500, 56, 1177, 120, 10, - /* 1410 */ 188, 181, 1199, 8, 20, 19, 1198, 1170, 55, 1113, - /* 1420 */ 261, 1203, 1421, 1202, 1149, 453, 36, 1148, 262, 202, - /* 1430 */ 204, 16, 1204, 466, 1065, 275, 470, 1087, 1086, 13, - /* 1440 */ 18, 198, 130, 196, 473, 1175, 200, 195, 61, 931, - /* 1450 */ 45, 57, 476, 479, 965, 959, 875, 540, 961, 1482, - /* 1460 */ 541, 544, 39, 882, 881, 468, 207, 954, 951, 948, - /* 1470 */ 471, 1265, 859, 474, 464, 942, 940, 477, 480, 496, - /* 1480 */ 900, 880, 879, 878, 877, 876, 895, 62, 897, 872, - /* 1490 */ 871, 870, 46, 63, 867, 866, 498, 486, 865, 210, - /* 1500 */ 1263, 864, 520, 521, 946, 525, 945, 944, 943, 522, - /* 1510 */ 524, 526, 1261, 528, 529, 1259, 530, 532, 533, 534, - /* 1520 */ 1247, 536, 537, 1246, 1242, 1052, 964, 218, 545, + /* 0 */ 452, 258, 1485, 270, 275, 452, 1434, 25, 195, 313, + /* 10 */ 465, 1435, 30, 28, 1481, 1488, 307, 1501, 1485, 311, + /* 20 */ 267, 1485, 1055, 1613, 1335, 32, 31, 29, 27, 26, + /* 30 */ 1481, 1487, 21, 1481, 1487, 1344, 1612, 1078, 1053, 239, + /* 40 */ 1611, 1518, 32, 31, 29, 27, 26, 1613, 447, 464, + /* 50 */ 11, 30, 28, 1163, 118, 407, 1236, 1060, 451, 267, + /* 60 */ 132, 1055, 1472, 1162, 1611, 30, 28, 435, 165, 1472, + /* 70 */ 431, 1075, 373, 267, 1, 1055, 465, 1053, 69, 1502, + /* 80 */ 1503, 1507, 1552, 542, 541, 73, 241, 1548, 1177, 11, + /* 90 */ 1501, 1053, 370, 1518, 375, 101, 1060, 546, 1613, 408, + /* 100 */ 447, 1344, 446, 11, 32, 31, 29, 27, 26, 1054, + /* 110 */ 1060, 132, 23, 1, 1518, 1611, 32, 31, 29, 27, + /* 120 */ 26, 434, 32, 31, 29, 27, 26, 1, 99, 119, + /* 130 */ 1613, 451, 424, 1302, 123, 1472, 546, 433, 128, 1559, + /* 140 */ 1560, 1077, 1564, 132, 464, 1384, 1056, 1611, 1054, 278, + /* 150 */ 546, 70, 1502, 1503, 1507, 1552, 1425, 1427, 349, 260, + /* 160 */ 1548, 127, 1054, 1059, 1079, 1080, 449, 1106, 1107, 1108, + /* 170 */ 1109, 1110, 1111, 1112, 1113, 1114, 29, 27, 26, 1094, + /* 180 */ 1580, 1079, 1080, 1222, 425, 1056, 85, 133, 1276, 84, + /* 190 */ 83, 82, 81, 80, 79, 78, 77, 76, 12, 1056, + /* 200 */ 382, 381, 1059, 1079, 1080, 449, 1106, 1107, 1108, 1109, + /* 210 */ 1110, 1111, 1112, 1113, 1114, 1118, 1059, 1079, 1080, 449, + /* 220 */ 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 30, + /* 230 */ 28, 1217, 442, 398, 1501, 53, 283, 267, 133, 1055, + /* 240 */ 384, 465, 378, 306, 1247, 305, 383, 1161, 97, 98, + /* 250 */ 73, 379, 377, 1322, 380, 1053, 1339, 376, 1518, 32, + /* 260 */ 31, 29, 27, 26, 1613, 434, 1344, 1613, 30, 28, + /* 270 */ 450, 1246, 1055, 133, 1060, 451, 267, 132, 1055, 1472, + /* 280 */ 132, 1611, 30, 28, 1611, 133, 421, 1501, 1053, 1472, + /* 290 */ 267, 7, 1055, 138, 1053, 70, 1502, 1503, 1507, 1552, + /* 300 */ 1216, 464, 349, 260, 1548, 127, 465, 1060, 1053, 1224, + /* 310 */ 898, 1518, 396, 1060, 546, 312, 1472, 191, 447, 51, + /* 320 */ 9, 8, 50, 414, 1579, 394, 1054, 1060, 451, 900, + /* 330 */ 7, 1344, 1472, 94, 93, 92, 91, 90, 89, 88, + /* 340 */ 87, 86, 426, 422, 7, 1225, 271, 546, 71, 1502, + /* 350 */ 1503, 1507, 1552, 546, 116, 12, 1551, 1548, 847, 1054, + /* 360 */ 846, 335, 1346, 1056, 500, 1054, 85, 546, 443, 84, + /* 370 */ 83, 82, 81, 80, 79, 78, 77, 76, 848, 1054, + /* 380 */ 1059, 1079, 1080, 449, 1106, 1107, 1108, 1109, 1110, 1111, + /* 390 */ 1112, 1113, 1114, 431, 1139, 1391, 1056, 32, 31, 29, + /* 400 */ 27, 26, 1056, 384, 133, 378, 1426, 142, 141, 383, + /* 410 */ 1245, 53, 98, 1059, 379, 377, 1056, 380, 101, 1059, + /* 420 */ 1079, 1080, 449, 1106, 1107, 1108, 1109, 1110, 1111, 1112, + /* 430 */ 1113, 1114, 1340, 1059, 1079, 1080, 449, 1106, 1107, 1108, + /* 440 */ 1109, 1110, 1111, 1112, 1113, 1114, 30, 28, 238, 438, + /* 450 */ 1075, 99, 1566, 1566, 267, 1472, 1055, 328, 60, 1422, + /* 460 */ 340, 129, 1559, 1560, 1244, 1564, 140, 1187, 133, 341, + /* 470 */ 1563, 1562, 1053, 32, 31, 29, 27, 26, 1076, 1337, + /* 480 */ 936, 488, 487, 486, 940, 485, 942, 943, 484, 945, + /* 490 */ 481, 1060, 951, 478, 953, 954, 475, 472, 389, 1391, + /* 500 */ 418, 1185, 1186, 1188, 1189, 257, 1391, 465, 1, 1472, + /* 510 */ 1389, 242, 465, 397, 431, 465, 320, 1390, 1243, 1571, + /* 520 */ 1158, 321, 1391, 115, 348, 465, 502, 167, 272, 1081, + /* 530 */ 392, 546, 1344, 1389, 1341, 386, 1094, 1344, 1082, 101, + /* 540 */ 1344, 166, 339, 1054, 1126, 334, 333, 332, 331, 330, + /* 550 */ 1344, 327, 326, 325, 324, 323, 319, 318, 317, 316, + /* 560 */ 315, 314, 1273, 1472, 117, 465, 503, 43, 1316, 223, + /* 570 */ 42, 66, 99, 1566, 462, 32, 31, 29, 27, 26, + /* 580 */ 1056, 221, 130, 1559, 1560, 102, 1564, 465, 6, 1242, + /* 590 */ 1344, 1561, 1336, 1127, 143, 491, 463, 1059, 1079, 1080, + /* 600 */ 449, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, + /* 610 */ 465, 1131, 1344, 242, 522, 521, 520, 519, 282, 209, + /* 620 */ 518, 517, 516, 103, 511, 510, 509, 508, 507, 506, + /* 630 */ 505, 504, 109, 1128, 1472, 1344, 549, 24, 265, 1121, + /* 640 */ 1122, 1123, 1124, 1125, 1129, 1130, 1126, 190, 1320, 437, + /* 650 */ 214, 1132, 277, 96, 1241, 1240, 176, 68, 280, 538, + /* 660 */ 116, 534, 530, 526, 213, 1391, 116, 846, 1346, 1239, + /* 670 */ 1238, 279, 515, 513, 1346, 251, 1389, 22, 1170, 1235, + /* 680 */ 116, 1234, 439, 368, 1077, 49, 48, 310, 1347, 137, + /* 690 */ 67, 1233, 1333, 207, 304, 1127, 298, 500, 1329, 1472, + /* 700 */ 1472, 165, 247, 465, 296, 373, 292, 288, 134, 1492, + /* 710 */ 1232, 300, 281, 1131, 1472, 1472, 1461, 252, 1231, 250, + /* 720 */ 249, 1490, 372, 461, 1472, 1501, 1472, 375, 1344, 1230, + /* 730 */ 1229, 1158, 1228, 133, 217, 1227, 1472, 1374, 1263, 24, + /* 740 */ 265, 1121, 1122, 1123, 1124, 1125, 1129, 1130, 1063, 1518, + /* 750 */ 1258, 413, 290, 514, 172, 1472, 447, 301, 1331, 158, + /* 760 */ 385, 1501, 156, 1472, 160, 162, 451, 159, 161, 1039, + /* 770 */ 1472, 169, 387, 1501, 1472, 1472, 164, 1472, 1256, 163, + /* 780 */ 1472, 9, 8, 1219, 1220, 1518, 70, 1502, 1503, 1507, + /* 790 */ 1552, 65, 447, 1327, 260, 1548, 1625, 1518, 406, 107, + /* 800 */ 390, 62, 451, 410, 447, 1586, 1472, 45, 179, 1062, + /* 810 */ 170, 1184, 181, 34, 451, 1501, 440, 1133, 1472, 1066, + /* 820 */ 448, 1501, 70, 1502, 1503, 1507, 1552, 490, 1237, 34, + /* 830 */ 260, 1548, 1625, 1090, 70, 1502, 1503, 1507, 1552, 1518, + /* 840 */ 192, 1609, 260, 1548, 1625, 1518, 447, 34, 1303, 419, + /* 850 */ 198, 1022, 447, 1570, 200, 95, 451, 344, 153, 457, + /* 860 */ 1472, 126, 451, 1385, 105, 435, 1472, 366, 206, 362, + /* 870 */ 358, 354, 152, 1501, 405, 185, 229, 1502, 1503, 1507, + /* 880 */ 1065, 872, 71, 1502, 1503, 1507, 1552, 367, 107, 45, + /* 890 */ 445, 1548, 929, 924, 1582, 470, 1613, 1518, 54, 957, + /* 900 */ 873, 150, 432, 105, 447, 1519, 106, 961, 107, 132, + /* 910 */ 967, 105, 966, 1611, 451, 108, 1075, 194, 1472, 2, + /* 920 */ 1501, 285, 289, 246, 248, 898, 1031, 215, 322, 139, + /* 930 */ 1424, 329, 337, 336, 120, 1502, 1503, 1507, 338, 342, + /* 940 */ 1086, 343, 1085, 431, 1518, 1084, 345, 145, 346, 347, + /* 950 */ 148, 447, 52, 350, 151, 1083, 369, 399, 149, 371, + /* 960 */ 122, 451, 146, 75, 1334, 1472, 401, 155, 101, 1330, + /* 970 */ 374, 256, 436, 1626, 400, 1501, 157, 110, 171, 144, + /* 980 */ 111, 71, 1502, 1503, 1507, 1552, 1332, 435, 1328, 112, + /* 990 */ 1549, 113, 402, 174, 1082, 274, 273, 409, 420, 1518, + /* 1000 */ 412, 99, 1501, 411, 1593, 1068, 447, 177, 455, 1592, + /* 1010 */ 1501, 188, 1559, 430, 1060, 429, 451, 5, 1613, 1583, + /* 1020 */ 1472, 1061, 417, 266, 180, 259, 1518, 423, 428, 100, + /* 1030 */ 4, 132, 416, 447, 1518, 1611, 234, 1502, 1503, 1507, + /* 1040 */ 1060, 447, 1158, 451, 1501, 1081, 1567, 1472, 35, 441, + /* 1050 */ 415, 451, 1501, 125, 1573, 1472, 261, 1501, 187, 444, + /* 1060 */ 186, 184, 17, 234, 1502, 1503, 1507, 1610, 1518, 1534, + /* 1070 */ 1433, 233, 1502, 1503, 1507, 447, 1518, 193, 453, 454, + /* 1080 */ 466, 1518, 1432, 447, 269, 451, 1501, 1628, 447, 1472, + /* 1090 */ 458, 460, 1064, 451, 459, 202, 204, 1472, 451, 216, + /* 1100 */ 264, 59, 1472, 427, 1345, 120, 1502, 1503, 1507, 61, + /* 1110 */ 1518, 1501, 468, 234, 1502, 1503, 1507, 447, 226, 1502, + /* 1120 */ 1503, 1507, 497, 218, 1317, 212, 545, 451, 41, 1069, + /* 1130 */ 220, 1472, 224, 225, 268, 1518, 1466, 222, 1465, 284, + /* 1140 */ 1462, 286, 447, 287, 1627, 1049, 1072, 234, 1502, 1503, + /* 1150 */ 1507, 1050, 451, 135, 291, 1460, 1472, 1501, 293, 295, + /* 1160 */ 294, 1459, 297, 1458, 299, 1501, 1449, 136, 302, 303, + /* 1170 */ 1034, 1443, 232, 1502, 1503, 1507, 1033, 1442, 308, 1441, + /* 1180 */ 309, 1518, 1440, 1005, 1417, 1416, 1415, 1414, 447, 1518, + /* 1190 */ 1413, 1412, 1411, 1501, 104, 1401, 447, 1410, 451, 1501, + /* 1200 */ 1007, 1395, 1472, 1409, 1408, 1407, 451, 1406, 1405, 1404, + /* 1210 */ 1472, 1403, 1402, 1400, 1399, 1398, 1397, 1518, 235, 1502, + /* 1220 */ 1503, 1507, 1396, 1518, 447, 1394, 227, 1502, 1503, 1507, + /* 1230 */ 447, 1393, 1392, 1275, 451, 1457, 1451, 1439, 1472, 1430, + /* 1240 */ 451, 147, 1323, 1274, 1472, 1501, 352, 865, 1272, 353, + /* 1250 */ 1501, 1270, 1268, 356, 236, 1502, 1503, 1507, 1501, 351, + /* 1260 */ 228, 1502, 1503, 1507, 355, 359, 357, 361, 1266, 1518, + /* 1270 */ 360, 365, 1255, 1254, 1518, 1251, 447, 364, 363, 1325, + /* 1280 */ 154, 447, 1518, 974, 972, 74, 451, 1324, 897, 447, + /* 1290 */ 1472, 451, 896, 895, 894, 1472, 891, 890, 1264, 451, + /* 1300 */ 1501, 514, 253, 1472, 1259, 254, 237, 1502, 1503, 1507, + /* 1310 */ 388, 1515, 1502, 1503, 1507, 512, 1257, 255, 1250, 1514, + /* 1320 */ 1502, 1503, 1507, 391, 1518, 1501, 1249, 393, 395, 72, + /* 1330 */ 1456, 447, 1041, 1450, 1501, 168, 403, 1438, 1437, 114, + /* 1340 */ 1429, 451, 173, 55, 14, 1472, 1490, 3, 34, 1518, + /* 1350 */ 15, 189, 39, 124, 36, 10, 447, 44, 1518, 178, + /* 1360 */ 121, 244, 1502, 1503, 1507, 447, 451, 404, 1183, 57, + /* 1370 */ 1472, 182, 183, 1205, 19, 451, 38, 1176, 1155, 1472, + /* 1380 */ 175, 56, 20, 1154, 37, 1210, 1513, 1502, 1503, 1507, + /* 1390 */ 16, 1204, 262, 1209, 1208, 245, 1502, 1503, 1507, 263, + /* 1400 */ 8, 131, 1501, 196, 1092, 33, 13, 1501, 1428, 1091, + /* 1410 */ 18, 203, 1119, 1501, 197, 205, 1181, 199, 201, 46, + /* 1420 */ 58, 1070, 40, 469, 456, 276, 1518, 1321, 1489, 473, + /* 1430 */ 476, 1518, 1319, 447, 62, 208, 467, 1518, 447, 958, + /* 1440 */ 471, 479, 955, 451, 447, 474, 477, 1472, 451, 952, + /* 1450 */ 946, 480, 1472, 944, 451, 482, 483, 950, 1472, 1501, + /* 1460 */ 935, 949, 948, 243, 1502, 1503, 1507, 489, 240, 1502, + /* 1470 */ 1503, 1507, 947, 969, 230, 1502, 1503, 1507, 63, 968, + /* 1480 */ 47, 64, 965, 1518, 963, 863, 499, 904, 210, 211, + /* 1490 */ 447, 501, 496, 210, 886, 885, 884, 496, 883, 882, + /* 1500 */ 451, 881, 880, 879, 1472, 901, 899, 876, 875, 874, + /* 1510 */ 871, 870, 869, 868, 498, 1271, 523, 1269, 524, 498, + /* 1520 */ 231, 1502, 1503, 1507, 527, 528, 525, 529, 1267, 531, + /* 1530 */ 532, 533, 1265, 495, 494, 493, 535, 492, 495, 494, + /* 1540 */ 493, 536, 492, 537, 1253, 539, 540, 1252, 1248, 543, + /* 1550 */ 544, 1223, 1057, 219, 547, 548, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 276, 277, 255, 235, 238, 251, 210, 216, 254, 216, - /* 10 */ 243, 257, 12, 13, 267, 268, 225, 250, 251, 0, - /* 20 */ 20, 255, 22, 238, 216, 12, 13, 14, 15, 16, - /* 30 */ 234, 2, 241, 267, 268, 260, 20, 241, 38, 246, - /* 40 */ 255, 12, 13, 14, 15, 16, 20, 251, 2, 241, - /* 50 */ 50, 255, 267, 268, 210, 36, 260, 57, 12, 13, - /* 60 */ 14, 15, 16, 12, 13, 14, 291, 271, 272, 273, - /* 70 */ 274, 20, 227, 22, 74, 230, 12, 13, 234, 304, - /* 80 */ 269, 47, 274, 308, 20, 241, 22, 291, 75, 38, - /* 90 */ 218, 283, 284, 285, 286, 251, 288, 97, 287, 255, - /* 100 */ 304, 50, 38, 231, 308, 20, 207, 73, 57, 109, - /* 110 */ 76, 239, 220, 221, 50, 271, 272, 273, 274, 275, - /* 120 */ 20, 57, 49, 279, 280, 74, 0, 88, 89, 90, - /* 130 */ 91, 92, 93, 94, 95, 96, 97, 98, 74, 100, - /* 140 */ 101, 102, 103, 104, 105, 145, 85, 21, 97, 210, - /* 150 */ 24, 25, 26, 27, 28, 29, 30, 31, 32, 260, - /* 160 */ 109, 97, 162, 163, 164, 165, 166, 167, 168, 169, - /* 170 */ 170, 171, 172, 109, 74, 22, 216, 20, 61, 12, - /* 180 */ 13, 209, 65, 211, 184, 225, 52, 20, 54, 22, - /* 190 */ 291, 38, 58, 216, 255, 61, 145, 63, 64, 78, - /* 200 */ 66, 241, 81, 304, 87, 38, 144, 308, 146, 145, - /* 210 */ 57, 260, 20, 162, 163, 164, 165, 166, 167, 168, - /* 220 */ 169, 170, 171, 172, 57, 135, 162, 163, 164, 165, - /* 230 */ 166, 167, 168, 169, 170, 171, 172, 260, 216, 162, - /* 240 */ 184, 74, 291, 12, 13, 14, 184, 225, 163, 164, - /* 250 */ 97, 20, 216, 22, 232, 304, 38, 12, 13, 308, - /* 260 */ 20, 225, 109, 241, 97, 20, 74, 22, 291, 38, - /* 270 */ 193, 194, 195, 196, 197, 57, 109, 241, 218, 189, - /* 280 */ 190, 304, 210, 38, 184, 308, 21, 291, 57, 24, - /* 290 */ 25, 26, 27, 28, 29, 30, 31, 32, 145, 239, - /* 300 */ 304, 67, 57, 215, 308, 74, 234, 12, 13, 14, - /* 310 */ 15, 16, 145, 241, 234, 162, 219, 229, 210, 74, - /* 320 */ 223, 241, 20, 251, 236, 210, 0, 255, 97, 162, - /* 330 */ 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, - /* 340 */ 109, 184, 97, 271, 272, 273, 274, 113, 114, 234, - /* 350 */ 18, 184, 20, 273, 109, 216, 241, 233, 49, 27, - /* 360 */ 216, 269, 30, 255, 225, 20, 251, 216, 244, 225, - /* 370 */ 255, 39, 234, 258, 210, 49, 145, 137, 240, 287, - /* 380 */ 241, 309, 310, 245, 215, 241, 271, 272, 273, 274, - /* 390 */ 145, 57, 241, 162, 163, 164, 165, 166, 167, 168, - /* 400 */ 169, 170, 171, 172, 20, 236, 22, 162, 163, 164, - /* 410 */ 165, 166, 167, 168, 169, 170, 171, 172, 216, 255, - /* 420 */ 12, 13, 234, 234, 40, 274, 210, 225, 20, 240, - /* 430 */ 22, 0, 137, 245, 245, 284, 285, 286, 241, 288, - /* 440 */ 14, 15, 16, 241, 112, 248, 38, 115, 116, 117, - /* 450 */ 118, 119, 74, 121, 122, 123, 124, 125, 126, 127, - /* 460 */ 128, 129, 130, 216, 86, 57, 12, 13, 14, 15, - /* 470 */ 16, 255, 225, 213, 214, 12, 13, 14, 15, 16, - /* 480 */ 35, 235, 74, 52, 53, 54, 55, 56, 241, 58, - /* 490 */ 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, - /* 500 */ 69, 70, 210, 216, 50, 97, 61, 71, 234, 216, - /* 510 */ 65, 75, 225, 50, 251, 226, 242, 109, 225, 232, - /* 520 */ 257, 235, 77, 234, 79, 80, 234, 82, 241, 75, - /* 530 */ 0, 242, 87, 241, 241, 22, 226, 83, 12, 13, - /* 540 */ 14, 15, 16, 251, 234, 263, 83, 255, 1, 2, - /* 550 */ 269, 38, 242, 145, 24, 25, 26, 27, 28, 29, - /* 560 */ 30, 31, 32, 271, 272, 273, 274, 0, 287, 131, - /* 570 */ 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, - /* 580 */ 172, 4, 14, 226, 216, 131, 234, 149, 20, 216, - /* 590 */ 18, 234, 240, 225, 131, 23, 19, 245, 225, 242, - /* 600 */ 210, 75, 38, 149, 210, 43, 210, 35, 0, 241, - /* 610 */ 33, 173, 149, 36, 241, 234, 49, 222, 41, 224, - /* 620 */ 48, 57, 75, 210, 47, 210, 245, 173, 174, 175, - /* 630 */ 176, 177, 178, 179, 180, 181, 173, 174, 175, 176, - /* 640 */ 177, 178, 179, 180, 181, 255, 20, 234, 4, 255, - /* 650 */ 73, 255, 210, 76, 241, 12, 13, 14, 15, 16, - /* 660 */ 52, 210, 54, 71, 251, 235, 58, 75, 255, 61, - /* 670 */ 255, 63, 64, 260, 66, 220, 221, 210, 210, 210, - /* 680 */ 210, 210, 3, 111, 271, 272, 273, 274, 275, 210, - /* 690 */ 12, 13, 279, 280, 21, 1, 2, 255, 210, 210, - /* 700 */ 22, 234, 182, 183, 291, 210, 255, 34, 241, 210, - /* 710 */ 138, 139, 140, 210, 142, 141, 38, 304, 251, 147, - /* 720 */ 71, 308, 255, 255, 255, 255, 255, 155, 210, 157, - /* 730 */ 156, 159, 160, 161, 255, 57, 71, 50, 271, 272, - /* 740 */ 273, 274, 275, 255, 255, 183, 279, 280, 281, 235, - /* 750 */ 255, 19, 234, 71, 255, 211, 184, 75, 255, 241, - /* 760 */ 293, 78, 235, 137, 81, 33, 299, 300, 36, 251, - /* 770 */ 74, 210, 0, 255, 42, 97, 44, 45, 46, 47, - /* 780 */ 84, 78, 78, 210, 81, 81, 235, 109, 0, 271, - /* 790 */ 272, 273, 274, 275, 22, 234, 210, 279, 280, 281, - /* 800 */ 0, 223, 241, 163, 164, 73, 302, 234, 76, 311, - /* 810 */ 22, 251, 251, 71, 241, 71, 255, 75, 300, 75, - /* 820 */ 234, 251, 22, 145, 251, 244, 71, 241, 255, 185, - /* 830 */ 75, 210, 271, 272, 273, 274, 296, 251, 106, 38, - /* 840 */ 162, 255, 213, 210, 271, 272, 273, 274, 275, 162, - /* 850 */ 270, 202, 279, 280, 281, 234, 234, 271, 272, 273, - /* 860 */ 274, 275, 241, 290, 289, 133, 280, 234, 136, 204, - /* 870 */ 38, 305, 251, 20, 241, 292, 255, 71, 216, 200, - /* 880 */ 266, 75, 71, 151, 251, 153, 75, 71, 255, 38, - /* 890 */ 220, 75, 271, 272, 273, 274, 275, 143, 261, 36, - /* 900 */ 279, 280, 281, 210, 271, 272, 273, 274, 275, 120, - /* 910 */ 109, 290, 279, 280, 281, 71, 216, 33, 216, 75, - /* 920 */ 36, 71, 216, 290, 249, 75, 42, 234, 44, 45, - /* 930 */ 46, 47, 71, 71, 241, 131, 75, 75, 71, 210, - /* 940 */ 216, 109, 75, 241, 251, 247, 247, 20, 255, 265, - /* 950 */ 210, 20, 12, 13, 14, 15, 16, 73, 241, 218, - /* 960 */ 76, 20, 260, 234, 271, 272, 273, 274, 275, 259, - /* 970 */ 241, 252, 279, 280, 234, 71, 274, 218, 218, 75, - /* 980 */ 251, 241, 216, 216, 255, 71, 284, 285, 286, 75, - /* 990 */ 288, 251, 71, 291, 218, 255, 75, 20, 258, 212, - /* 1000 */ 271, 272, 273, 274, 210, 234, 304, 234, 241, 210, - /* 1010 */ 308, 271, 272, 273, 274, 234, 132, 234, 134, 234, - /* 1020 */ 136, 216, 220, 241, 234, 234, 234, 234, 234, 234, - /* 1030 */ 234, 212, 303, 234, 265, 241, 259, 153, 210, 152, - /* 1040 */ 241, 274, 264, 20, 215, 251, 215, 192, 241, 255, - /* 1050 */ 251, 284, 285, 286, 255, 288, 270, 258, 301, 191, - /* 1060 */ 252, 57, 234, 301, 210, 271, 272, 273, 274, 241, - /* 1070 */ 271, 272, 273, 274, 256, 255, 199, 256, 138, 251, - /* 1080 */ 255, 255, 298, 255, 198, 187, 258, 241, 234, 186, - /* 1090 */ 20, 183, 269, 295, 297, 241, 120, 294, 206, 271, - /* 1100 */ 272, 273, 274, 203, 310, 251, 210, 201, 74, 255, - /* 1110 */ 253, 210, 282, 278, 256, 255, 306, 210, 134, 307, - /* 1120 */ 255, 312, 256, 241, 255, 271, 272, 273, 274, 230, - /* 1130 */ 234, 252, 215, 215, 241, 234, 74, 241, 216, 237, - /* 1140 */ 220, 234, 241, 224, 215, 205, 212, 251, 241, 0, - /* 1150 */ 262, 255, 251, 228, 228, 217, 255, 0, 251, 210, - /* 1160 */ 208, 0, 255, 64, 0, 38, 158, 271, 272, 273, - /* 1170 */ 274, 210, 271, 272, 273, 274, 38, 38, 271, 272, - /* 1180 */ 273, 274, 38, 234, 210, 158, 0, 0, 38, 38, - /* 1190 */ 241, 158, 38, 0, 38, 234, 0, 74, 149, 148, - /* 1200 */ 251, 0, 241, 109, 255, 145, 0, 0, 234, 141, - /* 1210 */ 61, 53, 251, 210, 65, 241, 255, 0, 0, 86, - /* 1220 */ 271, 272, 273, 274, 0, 251, 0, 0, 0, 255, - /* 1230 */ 0, 0, 271, 272, 273, 274, 87, 234, 0, 210, - /* 1240 */ 0, 0, 0, 0, 241, 271, 272, 273, 274, 0, - /* 1250 */ 0, 0, 0, 0, 251, 106, 107, 108, 255, 110, - /* 1260 */ 120, 0, 61, 234, 0, 210, 65, 0, 0, 0, - /* 1270 */ 241, 0, 0, 210, 271, 272, 273, 274, 22, 0, - /* 1280 */ 251, 0, 0, 0, 255, 0, 0, 0, 87, 234, - /* 1290 */ 43, 0, 0, 0, 36, 51, 241, 234, 38, 210, - /* 1300 */ 271, 272, 273, 274, 241, 43, 251, 106, 107, 108, - /* 1310 */ 255, 110, 0, 38, 251, 0, 36, 43, 255, 43, - /* 1320 */ 0, 43, 38, 234, 36, 36, 271, 272, 273, 274, - /* 1330 */ 241, 0, 38, 0, 271, 272, 273, 274, 0, 0, - /* 1340 */ 251, 210, 83, 38, 255, 22, 81, 0, 71, 38, - /* 1350 */ 0, 38, 38, 0, 38, 38, 38, 22, 22, 0, - /* 1360 */ 271, 272, 273, 274, 39, 234, 71, 22, 38, 0, - /* 1370 */ 22, 0, 241, 22, 20, 0, 137, 154, 38, 0, - /* 1380 */ 22, 0, 251, 150, 0, 137, 255, 0, 134, 43, - /* 1390 */ 188, 188, 137, 74, 86, 132, 75, 71, 71, 71, - /* 1400 */ 71, 182, 271, 272, 273, 274, 4, 75, 74, 188, - /* 1410 */ 86, 74, 38, 2, 71, 74, 38, 75, 74, 162, - /* 1420 */ 38, 38, 0, 38, 75, 135, 71, 75, 38, 43, - /* 1430 */ 132, 71, 75, 38, 22, 38, 38, 75, 75, 74, - /* 1440 */ 74, 74, 86, 75, 38, 75, 74, 86, 84, 22, - /* 1450 */ 74, 74, 38, 38, 38, 22, 22, 22, 38, 86, - /* 1460 */ 21, 21, 74, 38, 38, 74, 86, 75, 75, 75, - /* 1470 */ 74, 0, 51, 74, 85, 75, 75, 74, 74, 50, - /* 1480 */ 57, 38, 38, 38, 38, 38, 38, 74, 57, 38, - /* 1490 */ 38, 38, 74, 74, 38, 38, 72, 87, 38, 71, - /* 1500 */ 0, 38, 38, 36, 99, 36, 99, 99, 99, 43, - /* 1510 */ 38, 43, 0, 38, 36, 0, 43, 38, 36, 43, - /* 1520 */ 0, 38, 37, 0, 0, 22, 109, 22, 20, 313, - /* 1530 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1540 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1550 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1560 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1570 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1580 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1590 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1600 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1610 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1620 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1630 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1640 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1650 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1660 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1670 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1680 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1690 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1700 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1710 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1720 */ 313, 313, 313, 313, 313, 313, 313, 313, 313, 313, - /* 1730 */ 313, 313, 313, 313, 313, 313, + /* 0 */ 254, 241, 258, 257, 241, 254, 260, 279, 280, 219, + /* 10 */ 219, 260, 12, 13, 270, 271, 263, 213, 258, 228, + /* 20 */ 20, 258, 22, 294, 213, 12, 13, 14, 15, 16, + /* 30 */ 270, 271, 2, 270, 271, 244, 307, 20, 38, 249, + /* 40 */ 311, 237, 12, 13, 14, 15, 16, 294, 244, 20, + /* 50 */ 50, 12, 13, 14, 212, 219, 214, 57, 254, 20, + /* 60 */ 307, 22, 258, 4, 311, 12, 13, 263, 61, 258, + /* 70 */ 219, 20, 65, 20, 74, 22, 219, 38, 274, 275, + /* 80 */ 276, 277, 278, 216, 217, 228, 282, 283, 75, 50, + /* 90 */ 213, 38, 235, 237, 87, 244, 57, 97, 294, 263, + /* 100 */ 244, 244, 50, 50, 12, 13, 14, 15, 16, 109, + /* 110 */ 57, 307, 2, 74, 237, 311, 12, 13, 14, 15, + /* 120 */ 16, 244, 12, 13, 14, 15, 16, 74, 277, 222, + /* 130 */ 294, 254, 276, 226, 236, 258, 97, 286, 287, 288, + /* 140 */ 289, 20, 291, 307, 20, 247, 146, 311, 109, 246, + /* 150 */ 97, 274, 275, 276, 277, 278, 253, 254, 49, 282, + /* 160 */ 283, 284, 109, 163, 164, 165, 166, 167, 168, 169, + /* 170 */ 170, 171, 172, 173, 174, 175, 14, 15, 16, 75, + /* 180 */ 303, 164, 165, 210, 20, 146, 21, 187, 0, 24, + /* 190 */ 25, 26, 27, 28, 29, 30, 31, 32, 74, 146, + /* 200 */ 223, 224, 163, 164, 165, 166, 167, 168, 169, 170, + /* 210 */ 171, 172, 173, 174, 175, 163, 163, 164, 165, 166, + /* 220 */ 167, 168, 169, 170, 171, 172, 173, 174, 175, 12, + /* 230 */ 13, 139, 71, 263, 213, 221, 263, 20, 187, 22, + /* 240 */ 52, 219, 54, 145, 213, 147, 58, 188, 234, 61, + /* 250 */ 228, 63, 64, 0, 66, 38, 242, 235, 237, 12, + /* 260 */ 13, 14, 15, 16, 294, 244, 244, 294, 12, 13, + /* 270 */ 14, 213, 22, 187, 57, 254, 20, 307, 22, 258, + /* 280 */ 307, 311, 12, 13, 311, 187, 136, 213, 38, 258, + /* 290 */ 20, 74, 22, 47, 38, 274, 275, 276, 277, 278, + /* 300 */ 208, 20, 49, 282, 283, 284, 219, 57, 38, 0, + /* 310 */ 38, 237, 21, 57, 97, 228, 258, 296, 244, 73, + /* 320 */ 1, 2, 76, 302, 303, 34, 109, 57, 254, 57, + /* 330 */ 74, 244, 258, 24, 25, 26, 27, 28, 29, 30, + /* 340 */ 31, 32, 192, 193, 74, 0, 229, 97, 274, 275, + /* 350 */ 276, 277, 278, 97, 237, 74, 282, 283, 20, 109, + /* 360 */ 22, 67, 245, 146, 49, 109, 21, 97, 207, 24, + /* 370 */ 25, 26, 27, 28, 29, 30, 31, 32, 40, 109, + /* 380 */ 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, + /* 390 */ 173, 174, 175, 219, 75, 237, 146, 12, 13, 14, + /* 400 */ 15, 16, 146, 52, 187, 54, 248, 113, 114, 58, + /* 410 */ 213, 221, 61, 163, 63, 64, 146, 66, 244, 163, + /* 420 */ 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, + /* 430 */ 174, 175, 242, 163, 164, 165, 166, 167, 168, 169, + /* 440 */ 170, 171, 172, 173, 174, 175, 12, 13, 18, 3, + /* 450 */ 20, 277, 272, 272, 20, 258, 22, 27, 218, 244, + /* 460 */ 30, 287, 288, 289, 213, 291, 251, 163, 187, 39, + /* 470 */ 290, 290, 38, 12, 13, 14, 15, 16, 20, 239, + /* 480 */ 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, + /* 490 */ 98, 57, 100, 101, 102, 103, 104, 105, 4, 237, + /* 500 */ 196, 197, 198, 199, 200, 243, 237, 219, 74, 258, + /* 510 */ 248, 50, 219, 19, 219, 219, 228, 248, 213, 185, + /* 520 */ 186, 228, 237, 138, 228, 219, 57, 33, 243, 20, + /* 530 */ 36, 97, 244, 248, 228, 41, 75, 244, 20, 244, + /* 540 */ 244, 47, 112, 109, 83, 115, 116, 117, 118, 119, + /* 550 */ 244, 121, 122, 123, 124, 125, 126, 127, 128, 129, + /* 560 */ 130, 131, 0, 258, 18, 219, 225, 73, 227, 23, + /* 570 */ 76, 218, 277, 272, 228, 12, 13, 14, 15, 16, + /* 580 */ 146, 35, 287, 288, 289, 232, 291, 219, 43, 213, + /* 590 */ 244, 290, 239, 132, 48, 85, 228, 163, 164, 165, + /* 600 */ 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, + /* 610 */ 219, 150, 244, 50, 52, 53, 54, 55, 56, 228, + /* 620 */ 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, + /* 630 */ 68, 69, 70, 132, 258, 244, 19, 176, 177, 178, + /* 640 */ 179, 180, 181, 182, 183, 184, 83, 138, 0, 203, + /* 650 */ 33, 150, 229, 36, 213, 213, 138, 111, 229, 42, + /* 660 */ 237, 44, 45, 46, 47, 237, 237, 22, 245, 213, + /* 670 */ 213, 243, 223, 224, 245, 35, 248, 176, 14, 213, + /* 680 */ 237, 213, 71, 38, 20, 139, 140, 141, 245, 143, + /* 690 */ 73, 213, 238, 76, 148, 132, 142, 49, 238, 258, + /* 700 */ 258, 61, 156, 219, 158, 65, 160, 161, 162, 74, + /* 710 */ 213, 157, 228, 150, 258, 258, 0, 77, 213, 79, + /* 720 */ 80, 86, 82, 106, 258, 213, 258, 87, 244, 213, + /* 730 */ 213, 186, 213, 187, 230, 213, 258, 233, 0, 176, + /* 740 */ 177, 178, 179, 180, 181, 182, 183, 184, 38, 237, + /* 750 */ 0, 134, 36, 71, 137, 258, 244, 75, 238, 78, + /* 760 */ 22, 213, 81, 258, 78, 78, 254, 81, 81, 152, + /* 770 */ 258, 154, 22, 213, 258, 258, 78, 258, 0, 81, + /* 780 */ 258, 1, 2, 164, 165, 237, 274, 275, 276, 277, + /* 790 */ 278, 74, 244, 238, 282, 283, 284, 237, 266, 71, + /* 800 */ 22, 84, 254, 75, 244, 293, 258, 71, 71, 38, + /* 810 */ 238, 75, 75, 71, 254, 213, 205, 75, 258, 109, + /* 820 */ 238, 213, 274, 275, 276, 277, 278, 238, 214, 71, + /* 830 */ 282, 283, 284, 75, 274, 275, 276, 277, 278, 237, + /* 840 */ 314, 293, 282, 283, 284, 237, 244, 71, 226, 305, + /* 850 */ 71, 75, 244, 293, 75, 71, 254, 254, 33, 75, + /* 860 */ 258, 36, 254, 247, 71, 263, 258, 42, 75, 44, + /* 870 */ 45, 46, 47, 213, 254, 299, 274, 275, 276, 277, + /* 880 */ 109, 38, 274, 275, 276, 277, 278, 216, 71, 71, + /* 890 */ 282, 283, 75, 75, 273, 71, 294, 237, 73, 75, + /* 900 */ 57, 76, 292, 71, 244, 237, 71, 75, 71, 307, + /* 910 */ 75, 71, 75, 311, 254, 75, 20, 308, 258, 295, + /* 920 */ 213, 219, 36, 269, 223, 38, 144, 264, 219, 120, + /* 930 */ 219, 252, 132, 250, 274, 275, 276, 277, 250, 219, + /* 940 */ 20, 268, 20, 219, 237, 20, 262, 221, 244, 255, + /* 950 */ 221, 244, 221, 219, 221, 20, 215, 244, 133, 237, + /* 960 */ 135, 254, 137, 219, 237, 258, 153, 237, 244, 237, + /* 970 */ 223, 215, 312, 313, 268, 213, 237, 237, 218, 154, + /* 980 */ 237, 274, 275, 276, 277, 278, 237, 263, 237, 237, + /* 990 */ 283, 237, 267, 218, 20, 12, 13, 262, 195, 237, + /* 1000 */ 255, 277, 213, 244, 304, 22, 244, 259, 194, 304, + /* 1010 */ 213, 287, 288, 289, 57, 291, 254, 202, 294, 273, + /* 1020 */ 258, 38, 258, 261, 259, 258, 237, 258, 201, 244, + /* 1030 */ 189, 307, 190, 244, 237, 311, 274, 275, 276, 277, + /* 1040 */ 57, 244, 186, 254, 213, 20, 272, 258, 120, 204, + /* 1050 */ 261, 254, 213, 298, 301, 258, 209, 213, 285, 206, + /* 1060 */ 297, 300, 74, 274, 275, 276, 277, 310, 237, 281, + /* 1070 */ 259, 274, 275, 276, 277, 244, 237, 309, 258, 258, + /* 1080 */ 97, 237, 259, 244, 258, 254, 213, 315, 244, 258, + /* 1090 */ 135, 255, 109, 254, 256, 244, 218, 258, 254, 233, + /* 1100 */ 261, 218, 258, 306, 244, 274, 275, 276, 277, 74, + /* 1110 */ 237, 213, 240, 274, 275, 276, 277, 244, 274, 275, + /* 1120 */ 276, 277, 223, 219, 227, 218, 215, 254, 265, 146, + /* 1130 */ 220, 258, 231, 231, 261, 237, 0, 211, 0, 64, + /* 1140 */ 0, 38, 244, 159, 313, 38, 163, 274, 275, 276, + /* 1150 */ 277, 38, 254, 38, 159, 0, 258, 213, 38, 159, + /* 1160 */ 38, 0, 38, 0, 38, 213, 0, 74, 150, 149, + /* 1170 */ 109, 0, 274, 275, 276, 277, 146, 0, 53, 0, + /* 1180 */ 142, 237, 0, 86, 0, 0, 0, 0, 244, 237, + /* 1190 */ 0, 0, 0, 213, 120, 0, 244, 0, 254, 213, + /* 1200 */ 22, 0, 258, 0, 0, 0, 254, 0, 0, 0, + /* 1210 */ 258, 0, 0, 0, 0, 0, 0, 237, 274, 275, + /* 1220 */ 276, 277, 0, 237, 244, 0, 274, 275, 276, 277, + /* 1230 */ 244, 0, 0, 0, 254, 0, 0, 0, 258, 0, + /* 1240 */ 254, 43, 0, 0, 258, 213, 36, 51, 0, 43, + /* 1250 */ 213, 0, 0, 36, 274, 275, 276, 277, 213, 38, + /* 1260 */ 274, 275, 276, 277, 38, 38, 43, 43, 0, 237, + /* 1270 */ 36, 43, 0, 0, 237, 0, 244, 36, 38, 0, + /* 1280 */ 81, 244, 237, 38, 22, 83, 254, 0, 38, 244, + /* 1290 */ 258, 254, 38, 38, 38, 258, 38, 38, 0, 254, + /* 1300 */ 213, 71, 22, 258, 0, 22, 274, 275, 276, 277, + /* 1310 */ 39, 274, 275, 276, 277, 71, 0, 22, 0, 274, + /* 1320 */ 275, 276, 277, 38, 237, 213, 0, 22, 22, 20, + /* 1330 */ 0, 244, 38, 0, 213, 155, 22, 0, 0, 151, + /* 1340 */ 0, 254, 43, 74, 191, 258, 86, 71, 71, 237, + /* 1350 */ 191, 86, 71, 135, 185, 191, 244, 138, 237, 75, + /* 1360 */ 74, 274, 275, 276, 277, 244, 254, 138, 75, 4, + /* 1370 */ 258, 74, 71, 38, 74, 254, 138, 75, 75, 258, + /* 1380 */ 133, 74, 71, 75, 71, 75, 274, 275, 276, 277, + /* 1390 */ 71, 38, 38, 38, 38, 274, 275, 276, 277, 38, + /* 1400 */ 2, 86, 213, 86, 75, 74, 74, 213, 0, 75, + /* 1410 */ 74, 43, 163, 213, 75, 133, 75, 74, 74, 74, + /* 1420 */ 74, 22, 74, 38, 136, 38, 237, 0, 86, 38, + /* 1430 */ 38, 237, 0, 244, 84, 86, 85, 237, 244, 75, + /* 1440 */ 74, 38, 75, 254, 244, 74, 74, 258, 254, 75, + /* 1450 */ 75, 74, 258, 75, 254, 38, 74, 99, 258, 213, + /* 1460 */ 22, 99, 99, 274, 275, 276, 277, 87, 274, 275, + /* 1470 */ 276, 277, 99, 38, 274, 275, 276, 277, 74, 109, + /* 1480 */ 74, 74, 38, 237, 22, 51, 50, 57, 61, 71, + /* 1490 */ 244, 72, 65, 61, 38, 38, 38, 65, 38, 38, + /* 1500 */ 254, 38, 38, 22, 258, 57, 38, 38, 38, 38, + /* 1510 */ 38, 38, 38, 38, 87, 0, 38, 0, 36, 87, + /* 1520 */ 274, 275, 276, 277, 38, 36, 43, 43, 0, 38, + /* 1530 */ 36, 43, 0, 106, 107, 108, 38, 110, 106, 107, + /* 1540 */ 108, 36, 110, 43, 0, 38, 37, 0, 0, 22, + /* 1550 */ 21, 316, 22, 22, 21, 20, 316, 316, 316, 316, + /* 1560 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1570 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1580 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1590 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1600 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1610 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1620 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1630 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1640 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1650 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1660 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1670 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1680 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1690 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1700 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1710 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1720 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1730 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1740 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1750 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1760 */ 316, 316, 316, 316, 316, 316, }; -#define YY_SHIFT_COUNT (546) +#define YY_SHIFT_COUNT (549) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1524) +#define YY_SHIFT_MAX (1548) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 572, 0, 51, 64, 64, 64, 64, 167, 64, 64, - /* 10 */ 245, 408, 100, 231, 245, 245, 245, 245, 245, 245, - /* 20 */ 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, - /* 30 */ 245, 245, 245, 245, 192, 192, 192, 157, 678, 678, - /* 40 */ 62, 16, 16, 56, 678, 85, 85, 16, 16, 16, - /* 50 */ 16, 16, 16, 73, 26, 302, 56, 26, 16, 16, - /* 60 */ 26, 16, 26, 26, 26, 16, 309, 332, 454, 463, - /* 70 */ 463, 265, 445, 153, 134, 153, 153, 153, 153, 153, - /* 80 */ 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, - /* 90 */ 153, 153, 153, 153, 85, 384, 326, 218, 240, 240, - /* 100 */ 240, 567, 218, 345, 26, 26, 26, 61, 334, 39, - /* 110 */ 39, 39, 39, 39, 39, 39, 732, 126, 608, 940, - /* 120 */ 77, 85, 117, 85, 90, 513, 626, 520, 562, 520, - /* 130 */ 568, 679, 644, 853, 863, 851, 754, 853, 853, 789, - /* 140 */ 804, 804, 853, 927, 931, 73, 345, 941, 73, 73, - /* 150 */ 853, 73, 977, 26, 26, 26, 26, 26, 26, 26, - /* 160 */ 26, 26, 26, 26, 851, 853, 977, 345, 927, 887, - /* 170 */ 931, 309, 345, 941, 309, 1023, 855, 868, 1004, 855, - /* 180 */ 868, 1004, 1004, 877, 886, 898, 903, 908, 345, 1070, - /* 190 */ 976, 892, 900, 906, 1034, 26, 868, 1004, 1004, 868, - /* 200 */ 1004, 984, 345, 941, 309, 61, 309, 345, 1062, 851, - /* 210 */ 334, 853, 309, 977, 1529, 1529, 1529, 1529, 1529, 431, - /* 220 */ 884, 530, 577, 1149, 1201, 13, 29, 46, 526, 295, - /* 230 */ 643, 643, 643, 643, 643, 643, 643, 34, 234, 426, - /* 240 */ 547, 438, 426, 426, 426, 19, 574, 436, 121, 683, - /* 250 */ 703, 704, 772, 788, 800, 673, 592, 682, 742, 694, - /* 260 */ 640, 649, 665, 744, 687, 755, 378, 806, 811, 816, - /* 270 */ 844, 850, 801, 832, 861, 862, 867, 904, 914, 921, - /* 280 */ 696, 564, 1157, 1161, 1099, 1164, 1127, 1008, 1138, 1139, - /* 290 */ 1144, 1027, 1186, 1150, 1151, 1033, 1187, 1154, 1193, 1156, - /* 300 */ 1196, 1123, 1049, 1051, 1094, 1060, 1206, 1207, 1158, 1068, - /* 310 */ 1217, 1218, 1133, 1224, 1226, 1227, 1228, 1230, 1231, 1238, - /* 320 */ 1240, 1241, 1242, 1243, 1249, 1250, 1251, 1252, 1140, 1253, - /* 330 */ 1261, 1264, 1267, 1268, 1269, 1256, 1271, 1272, 1279, 1281, - /* 340 */ 1282, 1283, 1285, 1286, 1287, 1247, 1291, 1244, 1292, 1293, - /* 350 */ 1260, 1258, 1262, 1312, 1275, 1280, 1274, 1315, 1284, 1288, - /* 360 */ 1276, 1320, 1294, 1289, 1278, 1331, 1333, 1338, 1339, 1259, - /* 370 */ 1265, 1305, 1277, 1323, 1347, 1311, 1313, 1314, 1316, 1295, - /* 380 */ 1277, 1317, 1318, 1350, 1335, 1353, 1336, 1325, 1359, 1345, - /* 390 */ 1330, 1369, 1348, 1371, 1351, 1354, 1375, 1239, 1223, 1340, - /* 400 */ 1379, 1233, 1358, 1248, 1254, 1381, 1384, 1255, 1387, 1319, - /* 410 */ 1346, 1263, 1326, 1327, 1202, 1321, 1328, 1332, 1334, 1337, - /* 420 */ 1341, 1342, 1329, 1308, 1344, 1343, 1203, 1349, 1352, 1324, - /* 430 */ 1219, 1355, 1356, 1357, 1360, 1221, 1402, 1374, 1378, 1382, - /* 440 */ 1383, 1385, 1390, 1411, 1257, 1361, 1362, 1363, 1365, 1366, - /* 450 */ 1368, 1370, 1367, 1372, 1290, 1376, 1422, 1386, 1298, 1377, - /* 460 */ 1364, 1373, 1380, 1412, 1388, 1389, 1392, 1395, 1397, 1391, - /* 470 */ 1393, 1398, 1396, 1394, 1406, 1399, 1400, 1414, 1403, 1401, - /* 480 */ 1415, 1404, 1405, 1407, 1408, 1409, 1427, 1410, 1413, 1416, - /* 490 */ 1417, 1418, 1419, 1420, 1277, 1433, 1421, 1429, 1423, 1424, - /* 500 */ 1428, 1425, 1426, 1443, 1444, 1445, 1446, 1447, 1434, 1431, - /* 510 */ 1295, 1448, 1277, 1451, 1452, 1453, 1456, 1457, 1460, 1463, - /* 520 */ 1471, 1464, 1467, 1466, 1500, 1472, 1469, 1468, 1512, 1475, - /* 530 */ 1478, 1473, 1515, 1479, 1482, 1476, 1520, 1483, 1485, 1523, - /* 540 */ 1524, 1435, 1439, 1503, 1505, 1440, 1508, + /* 0 */ 546, 0, 39, 53, 53, 53, 53, 217, 53, 53, + /* 10 */ 270, 434, 281, 256, 270, 270, 270, 270, 270, 270, + /* 20 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, + /* 30 */ 270, 270, 270, 270, 270, 124, 124, 124, 51, 983, + /* 40 */ 983, 98, 29, 29, 86, 983, 17, 17, 29, 29, + /* 50 */ 29, 29, 29, 29, 109, 121, 164, 86, 121, 29, + /* 60 */ 29, 121, 29, 121, 121, 121, 29, 315, 430, 461, + /* 70 */ 563, 563, 165, 640, 250, 351, 250, 250, 250, 250, + /* 80 */ 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, + /* 90 */ 250, 250, 250, 250, 250, 17, 338, 253, 272, 509, + /* 100 */ 509, 509, 648, 272, 458, 121, 121, 121, 510, 469, + /* 110 */ 392, 392, 392, 392, 392, 392, 392, 617, 345, 188, + /* 120 */ 92, 304, 17, 7, 17, 150, 645, 518, 334, 545, + /* 130 */ 334, 664, 446, 59, 896, 886, 887, 782, 896, 896, + /* 140 */ 809, 800, 800, 896, 920, 922, 109, 458, 925, 109, + /* 150 */ 109, 896, 109, 935, 121, 121, 121, 121, 121, 121, + /* 160 */ 121, 121, 121, 121, 121, 887, 896, 935, 458, 920, + /* 170 */ 813, 922, 315, 458, 925, 315, 974, 803, 814, 957, + /* 180 */ 803, 814, 957, 957, 815, 827, 842, 841, 856, 458, + /* 190 */ 1025, 928, 847, 853, 845, 988, 121, 814, 957, 957, + /* 200 */ 814, 957, 955, 458, 925, 315, 510, 315, 458, 1035, + /* 210 */ 887, 469, 896, 315, 935, 1556, 1556, 1556, 1556, 1556, + /* 220 */ 562, 825, 309, 494, 1427, 1432, 13, 30, 110, 104, + /* 230 */ 385, 247, 247, 247, 247, 247, 247, 247, 246, 294, + /* 240 */ 162, 319, 501, 162, 162, 162, 716, 554, 682, 681, + /* 250 */ 686, 687, 698, 738, 750, 778, 291, 728, 736, 737, + /* 260 */ 780, 619, 611, 161, 742, 52, 758, 635, 776, 779, + /* 270 */ 784, 793, 817, 710, 771, 818, 824, 832, 835, 837, + /* 280 */ 840, 717, 843, 1136, 1138, 1075, 1140, 1103, 984, 1107, + /* 290 */ 1113, 1115, 995, 1155, 1120, 1122, 1000, 1161, 1124, 1163, + /* 300 */ 1126, 1166, 1093, 1018, 1020, 1061, 1030, 1171, 1177, 1125, + /* 310 */ 1038, 1179, 1182, 1097, 1184, 1185, 1186, 1187, 1190, 1191, + /* 320 */ 1192, 1197, 1203, 1204, 1205, 1207, 1208, 1209, 1211, 1212, + /* 330 */ 1074, 1195, 1213, 1214, 1215, 1216, 1222, 1178, 1201, 1225, + /* 340 */ 1231, 1232, 1233, 1235, 1236, 1237, 1239, 1198, 1242, 1196, + /* 350 */ 1243, 1248, 1221, 1210, 1206, 1251, 1226, 1217, 1223, 1252, + /* 360 */ 1227, 1234, 1224, 1268, 1240, 1241, 1228, 1272, 1273, 1275, + /* 370 */ 1279, 1202, 1199, 1245, 1230, 1262, 1287, 1250, 1254, 1255, + /* 380 */ 1256, 1244, 1230, 1258, 1259, 1298, 1280, 1304, 1283, 1271, + /* 390 */ 1316, 1295, 1285, 1318, 1305, 1326, 1306, 1309, 1330, 1219, + /* 400 */ 1180, 1294, 1333, 1188, 1314, 1229, 1218, 1337, 1338, 1238, + /* 410 */ 1340, 1269, 1299, 1247, 1276, 1277, 1153, 1284, 1281, 1293, + /* 420 */ 1286, 1297, 1300, 1302, 1301, 1260, 1307, 1311, 1159, 1303, + /* 430 */ 1308, 1265, 1169, 1313, 1315, 1310, 1319, 1164, 1365, 1335, + /* 440 */ 1353, 1354, 1355, 1356, 1361, 1398, 1249, 1317, 1329, 1331, + /* 450 */ 1334, 1332, 1336, 1339, 1341, 1343, 1344, 1288, 1345, 1408, + /* 460 */ 1368, 1282, 1346, 1350, 1342, 1349, 1399, 1348, 1351, 1364, + /* 470 */ 1385, 1387, 1366, 1367, 1391, 1371, 1374, 1392, 1372, 1375, + /* 480 */ 1403, 1377, 1378, 1417, 1382, 1358, 1362, 1363, 1373, 1438, + /* 490 */ 1380, 1404, 1435, 1370, 1406, 1407, 1444, 1230, 1462, 1434, + /* 500 */ 1436, 1430, 1419, 1418, 1456, 1457, 1458, 1460, 1461, 1463, + /* 510 */ 1464, 1481, 1448, 1244, 1468, 1230, 1469, 1470, 1471, 1472, + /* 520 */ 1473, 1474, 1475, 1515, 1478, 1482, 1483, 1517, 1486, 1489, + /* 530 */ 1484, 1528, 1491, 1494, 1488, 1532, 1498, 1505, 1500, 1544, + /* 540 */ 1507, 1509, 1547, 1548, 1527, 1529, 1530, 1531, 1533, 1535, }; -#define YY_REDUCE_COUNT (218) -#define YY_REDUCE_MIN (-276) -#define YY_REDUCE_MAX (1131) +#define YY_REDUCE_COUNT (219) +#define YY_REDUCE_MIN (-272) +#define YY_REDUCE_MAX (1246) static const short yy_reduce_ofst[] = { - /* 0 */ -101, 413, 467, 518, 573, 621, 633, -204, -156, 693, - /* 10 */ 72, 586, 702, 115, 740, 729, 794, 799, 828, 292, - /* 20 */ 561, 854, 896, 901, 907, 949, 961, 974, 1003, 1029, - /* 30 */ 1055, 1063, 1089, 1131, -192, 151, 767, -23, -234, -215, - /* 40 */ -225, 22, 287, -49, -253, -246, -233, -209, -40, 36, - /* 50 */ 139, 144, 202, -128, 138, 80, -4, 289, 247, 293, - /* 60 */ 189, 368, 310, 352, 357, 373, 88, -207, -276, -276, - /* 70 */ -276, -28, 124, -61, 97, 108, 164, 216, 390, 394, - /* 80 */ 396, 415, 442, 451, 468, 469, 470, 471, 479, 488, - /* 90 */ 489, 495, 499, 503, 263, 260, 60, -108, -189, 92, - /* 100 */ 281, 169, 455, 197, 274, 188, 381, -155, 395, -232, - /* 110 */ 246, 286, 430, 514, 527, 551, 282, 544, 578, 498, - /* 120 */ 504, 560, 581, 570, 540, 629, 580, 575, 575, 575, - /* 130 */ 622, 566, 583, 662, 614, 670, 637, 700, 706, 675, - /* 140 */ 698, 699, 724, 684, 710, 741, 717, 719, 759, 760, - /* 150 */ 766, 776, 787, 771, 773, 781, 783, 785, 790, 791, - /* 160 */ 792, 793, 795, 796, 802, 805, 819, 782, 769, 778, - /* 170 */ 777, 829, 807, 808, 831, 786, 757, 818, 820, 762, - /* 180 */ 821, 825, 826, 784, 797, 798, 803, 575, 846, 823, - /* 190 */ 830, 809, 812, 810, 835, 622, 858, 860, 865, 866, - /* 200 */ 869, 857, 882, 879, 917, 899, 918, 893, 902, 920, - /* 210 */ 919, 922, 929, 934, 888, 925, 926, 938, 952, + /* 0 */ -27, -196, 21, -123, 512, 548, 560, 602, 74, 608, + /* 10 */ 660, 707, 724, 762, 789, 797, 831, 839, 873, 844, + /* 20 */ 898, 944, 952, 980, 986, 1032, 1037, 1045, 1087, 1112, + /* 30 */ 1121, 1189, 1194, 1200, 1246, -149, 174, 295, -164, -240, + /* 40 */ -237, -247, -143, 22, -30, -256, -254, -97, -209, 87, + /* 50 */ 288, 293, 296, 306, 14, 262, -144, -271, 117, 346, + /* 60 */ 368, 285, 391, 423, 428, 429, 484, 353, -210, -272, + /* 70 */ -272, -272, -158, -102, -189, -93, 31, 58, 197, 251, + /* 80 */ 305, 376, 441, 442, 456, 457, 466, 468, 478, 497, + /* 90 */ 505, 516, 517, 519, 522, -249, -133, 190, -23, 180, + /* 100 */ 181, 301, 240, 449, 215, 443, 158, 269, 504, 341, + /* 110 */ 454, 460, 520, 555, 572, 582, 589, 532, 614, 622, + /* 120 */ 526, 544, 603, 616, 620, 576, 671, 621, 610, 610, + /* 130 */ 610, 668, 609, 624, 702, 654, 701, 663, 709, 711, + /* 140 */ 679, 683, 688, 720, 673, 684, 726, 704, 694, 729, + /* 150 */ 731, 734, 733, 741, 722, 727, 730, 732, 739, 740, + /* 160 */ 743, 749, 751, 752, 754, 747, 744, 756, 713, 706, + /* 170 */ 725, 735, 760, 759, 745, 775, 746, 700, 748, 764, + /* 180 */ 705, 765, 767, 769, 753, 761, 755, 763, 610, 785, + /* 190 */ 774, 773, 772, 757, 768, 788, 668, 811, 820, 821, + /* 200 */ 823, 826, 838, 851, 836, 878, 866, 883, 860, 872, + /* 210 */ 899, 897, 904, 907, 911, 863, 901, 902, 910, 926, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 10 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 20 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 30 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 40 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 50 */ 1215, 1215, 1215, 1274, 1215, 1215, 1215, 1215, 1215, 1215, - /* 60 */ 1215, 1215, 1215, 1215, 1215, 1215, 1272, 1411, 1215, 1546, - /* 70 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 80 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 90 */ 1215, 1215, 1215, 1215, 1215, 1215, 1274, 1215, 1557, 1557, - /* 100 */ 1557, 1272, 1215, 1215, 1215, 1215, 1215, 1367, 1215, 1215, - /* 110 */ 1215, 1215, 1215, 1215, 1215, 1215, 1445, 1215, 1215, 1621, - /* 120 */ 1215, 1215, 1320, 1215, 1581, 1215, 1573, 1549, 1563, 1550, - /* 130 */ 1215, 1606, 1566, 1215, 1215, 1215, 1437, 1215, 1215, 1416, - /* 140 */ 1413, 1413, 1215, 1215, 1215, 1274, 1215, 1215, 1274, 1274, - /* 150 */ 1215, 1274, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 160 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1447, - /* 170 */ 1215, 1272, 1215, 1215, 1272, 1215, 1588, 1586, 1215, 1588, - /* 180 */ 1586, 1215, 1215, 1600, 1596, 1579, 1577, 1563, 1215, 1215, - /* 190 */ 1215, 1624, 1612, 1608, 1215, 1215, 1586, 1215, 1215, 1586, - /* 200 */ 1215, 1424, 1215, 1215, 1272, 1215, 1272, 1215, 1336, 1215, - /* 210 */ 1215, 1215, 1272, 1215, 1439, 1370, 1370, 1275, 1220, 1215, - /* 220 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1509, - /* 230 */ 1510, 1599, 1598, 1509, 1523, 1522, 1521, 1215, 1215, 1504, - /* 240 */ 1215, 1215, 1505, 1503, 1502, 1215, 1215, 1215, 1215, 1215, - /* 250 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1547, - /* 260 */ 1215, 1609, 1613, 1215, 1215, 1215, 1484, 1215, 1215, 1215, - /* 270 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 280 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 290 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 300 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 310 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 320 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 330 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 340 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 350 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 360 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 370 */ 1215, 1215, 1381, 1215, 1215, 1215, 1215, 1215, 1215, 1301, - /* 380 */ 1300, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 390 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 400 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 410 */ 1215, 1215, 1570, 1580, 1215, 1215, 1215, 1215, 1215, 1215, - /* 420 */ 1215, 1215, 1215, 1484, 1215, 1597, 1215, 1556, 1552, 1215, - /* 430 */ 1215, 1548, 1215, 1215, 1607, 1215, 1215, 1215, 1215, 1215, - /* 440 */ 1215, 1215, 1215, 1542, 1215, 1215, 1215, 1215, 1215, 1215, - /* 450 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 460 */ 1215, 1483, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1364, - /* 470 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 480 */ 1215, 1215, 1349, 1347, 1346, 1345, 1215, 1342, 1215, 1215, - /* 490 */ 1215, 1215, 1215, 1215, 1372, 1215, 1215, 1215, 1215, 1215, - /* 500 */ 1295, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 510 */ 1286, 1215, 1285, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 520 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 530 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, 1215, - /* 540 */ 1215, 1215, 1215, 1215, 1215, 1215, 1215, + /* 0 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 10 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 20 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 30 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 40 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 50 */ 1221, 1221, 1221, 1221, 1280, 1221, 1221, 1221, 1221, 1221, + /* 60 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1278, 1418, 1221, + /* 70 */ 1554, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 80 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 90 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1280, 1221, 1565, + /* 100 */ 1565, 1565, 1278, 1221, 1221, 1221, 1221, 1221, 1373, 1221, + /* 110 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1452, 1221, 1221, + /* 120 */ 1629, 1221, 1221, 1326, 1221, 1589, 1221, 1581, 1557, 1571, + /* 130 */ 1558, 1221, 1614, 1574, 1221, 1221, 1221, 1444, 1221, 1221, + /* 140 */ 1423, 1420, 1420, 1221, 1221, 1221, 1280, 1221, 1221, 1280, + /* 150 */ 1280, 1221, 1280, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 160 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 170 */ 1454, 1221, 1278, 1221, 1221, 1278, 1221, 1596, 1594, 1221, + /* 180 */ 1596, 1594, 1221, 1221, 1608, 1604, 1587, 1585, 1571, 1221, + /* 190 */ 1221, 1221, 1632, 1620, 1616, 1221, 1221, 1594, 1221, 1221, + /* 200 */ 1594, 1221, 1431, 1221, 1221, 1278, 1221, 1278, 1221, 1342, + /* 210 */ 1221, 1221, 1221, 1278, 1221, 1446, 1376, 1376, 1281, 1226, + /* 220 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 230 */ 1221, 1517, 1607, 1606, 1516, 1531, 1530, 1529, 1221, 1221, + /* 240 */ 1511, 1221, 1221, 1512, 1510, 1509, 1221, 1221, 1221, 1221, + /* 250 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 260 */ 1555, 1221, 1617, 1621, 1221, 1221, 1221, 1491, 1221, 1221, + /* 270 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 280 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 290 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 300 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 310 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 320 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 330 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 340 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 350 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 360 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 370 */ 1221, 1221, 1221, 1221, 1387, 1221, 1221, 1221, 1221, 1221, + /* 380 */ 1221, 1307, 1306, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 390 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 400 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 410 */ 1221, 1221, 1221, 1221, 1578, 1588, 1221, 1221, 1221, 1221, + /* 420 */ 1221, 1221, 1221, 1221, 1221, 1491, 1221, 1605, 1221, 1564, + /* 430 */ 1560, 1221, 1221, 1556, 1221, 1221, 1615, 1221, 1221, 1221, + /* 440 */ 1221, 1221, 1221, 1221, 1221, 1550, 1221, 1221, 1221, 1221, + /* 450 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 460 */ 1221, 1221, 1221, 1221, 1490, 1221, 1221, 1221, 1221, 1221, + /* 470 */ 1221, 1221, 1370, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 480 */ 1221, 1221, 1221, 1221, 1221, 1355, 1353, 1352, 1351, 1221, + /* 490 */ 1348, 1221, 1221, 1221, 1221, 1221, 1221, 1378, 1221, 1221, + /* 500 */ 1221, 1221, 1221, 1301, 1221, 1221, 1221, 1221, 1221, 1221, + /* 510 */ 1221, 1221, 1221, 1292, 1221, 1291, 1221, 1221, 1221, 1221, + /* 520 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 530 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 540 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, }; /********** End of lemon-generated parsing tables *****************************/ @@ -916,194 +921,197 @@ static const char *const yyTokenName[] = { /* 122 */ "APPS", /* 123 */ "CONNECTIONS", /* 124 */ "LICENCE", - /* 125 */ "QUERIES", - /* 126 */ "SCORES", - /* 127 */ "TOPICS", - /* 128 */ "VARIABLES", - /* 129 */ "BNODES", - /* 130 */ "SNODES", - /* 131 */ "LIKE", - /* 132 */ "INDEX", - /* 133 */ "FULLTEXT", - /* 134 */ "FUNCTION", - /* 135 */ "INTERVAL", - /* 136 */ "TOPIC", - /* 137 */ "AS", - /* 138 */ "DESC", - /* 139 */ "DESCRIBE", - /* 140 */ "RESET", - /* 141 */ "QUERY", - /* 142 */ "EXPLAIN", - /* 143 */ "ANALYZE", - /* 144 */ "VERBOSE", - /* 145 */ "NK_BOOL", - /* 146 */ "RATIO", - /* 147 */ "COMPACT", - /* 148 */ "VNODES", - /* 149 */ "IN", - /* 150 */ "OUTPUTTYPE", - /* 151 */ "AGGREGATE", - /* 152 */ "BUFSIZE", - /* 153 */ "STREAM", - /* 154 */ "INTO", - /* 155 */ "KILL", - /* 156 */ "CONNECTION", - /* 157 */ "MERGE", - /* 158 */ "VGROUP", - /* 159 */ "REDISTRIBUTE", - /* 160 */ "SPLIT", - /* 161 */ "SYNCDB", - /* 162 */ "NULL", - /* 163 */ "FIRST", - /* 164 */ "LAST", - /* 165 */ "NOW", - /* 166 */ "ROWTS", - /* 167 */ "TBNAME", - /* 168 */ "QSTARTTS", - /* 169 */ "QENDTS", - /* 170 */ "WSTARTTS", - /* 171 */ "WENDTS", - /* 172 */ "WDURATION", - /* 173 */ "BETWEEN", - /* 174 */ "IS", - /* 175 */ "NK_LT", - /* 176 */ "NK_GT", - /* 177 */ "NK_LE", - /* 178 */ "NK_GE", - /* 179 */ "NK_NE", - /* 180 */ "MATCH", - /* 181 */ "NMATCH", - /* 182 */ "JOIN", - /* 183 */ "INNER", - /* 184 */ "SELECT", - /* 185 */ "DISTINCT", - /* 186 */ "WHERE", - /* 187 */ "PARTITION", - /* 188 */ "BY", - /* 189 */ "SESSION", - /* 190 */ "STATE_WINDOW", - /* 191 */ "SLIDING", - /* 192 */ "FILL", - /* 193 */ "VALUE", - /* 194 */ "NONE", - /* 195 */ "PREV", - /* 196 */ "LINEAR", - /* 197 */ "NEXT", - /* 198 */ "GROUP", - /* 199 */ "HAVING", - /* 200 */ "ORDER", - /* 201 */ "SLIMIT", - /* 202 */ "SOFFSET", - /* 203 */ "LIMIT", - /* 204 */ "OFFSET", - /* 205 */ "ASC", - /* 206 */ "NULLS", - /* 207 */ "cmd", - /* 208 */ "account_options", - /* 209 */ "alter_account_options", - /* 210 */ "literal", - /* 211 */ "alter_account_option", - /* 212 */ "user_name", - /* 213 */ "dnode_endpoint", - /* 214 */ "dnode_host_name", - /* 215 */ "not_exists_opt", - /* 216 */ "db_name", - /* 217 */ "db_options", - /* 218 */ "exists_opt", - /* 219 */ "alter_db_options", - /* 220 */ "integer_list", - /* 221 */ "variable_list", - /* 222 */ "retention_list", - /* 223 */ "alter_db_option", - /* 224 */ "retention", - /* 225 */ "full_table_name", - /* 226 */ "column_def_list", - /* 227 */ "tags_def_opt", - /* 228 */ "table_options", - /* 229 */ "multi_create_clause", - /* 230 */ "tags_def", - /* 231 */ "multi_drop_clause", - /* 232 */ "alter_table_clause", - /* 233 */ "alter_table_options", - /* 234 */ "column_name", - /* 235 */ "type_name", - /* 236 */ "create_subtable_clause", - /* 237 */ "specific_tags_opt", - /* 238 */ "literal_list", - /* 239 */ "drop_table_clause", - /* 240 */ "col_name_list", - /* 241 */ "table_name", - /* 242 */ "column_def", - /* 243 */ "func_name_list", - /* 244 */ "alter_table_option", - /* 245 */ "col_name", - /* 246 */ "db_name_cond_opt", - /* 247 */ "like_pattern_opt", - /* 248 */ "table_name_cond", - /* 249 */ "from_db_opt", - /* 250 */ "func_name", - /* 251 */ "function_name", - /* 252 */ "index_name", - /* 253 */ "index_options", - /* 254 */ "func_list", - /* 255 */ "duration_literal", - /* 256 */ "sliding_opt", - /* 257 */ "func", - /* 258 */ "expression_list", - /* 259 */ "topic_name", - /* 260 */ "query_expression", - /* 261 */ "analyze_opt", - /* 262 */ "explain_options", - /* 263 */ "agg_func_opt", - /* 264 */ "bufsize_opt", - /* 265 */ "stream_name", - /* 266 */ "dnode_list", - /* 267 */ "signed", - /* 268 */ "signed_literal", - /* 269 */ "table_alias", - /* 270 */ "column_alias", - /* 271 */ "expression", - /* 272 */ "pseudo_column", - /* 273 */ "column_reference", - /* 274 */ "subquery", - /* 275 */ "predicate", - /* 276 */ "compare_op", - /* 277 */ "in_op", - /* 278 */ "in_predicate_value", - /* 279 */ "boolean_value_expression", - /* 280 */ "boolean_primary", - /* 281 */ "common_expression", - /* 282 */ "from_clause", - /* 283 */ "table_reference_list", - /* 284 */ "table_reference", - /* 285 */ "table_primary", - /* 286 */ "joined_table", - /* 287 */ "alias_opt", - /* 288 */ "parenthesized_joined_table", - /* 289 */ "join_type", - /* 290 */ "search_condition", - /* 291 */ "query_specification", - /* 292 */ "set_quantifier_opt", - /* 293 */ "select_list", - /* 294 */ "where_clause_opt", - /* 295 */ "partition_by_clause_opt", - /* 296 */ "twindow_clause_opt", - /* 297 */ "group_by_clause_opt", - /* 298 */ "having_clause_opt", - /* 299 */ "select_sublist", - /* 300 */ "select_item", - /* 301 */ "fill_opt", - /* 302 */ "fill_mode", - /* 303 */ "group_by_list", - /* 304 */ "query_expression_body", - /* 305 */ "order_by_clause_opt", - /* 306 */ "slimit_clause_opt", - /* 307 */ "limit_clause_opt", - /* 308 */ "query_primary", - /* 309 */ "sort_specification_list", - /* 310 */ "sort_specification", - /* 311 */ "ordering_specification_opt", - /* 312 */ "null_ordering_opt", + /* 125 */ "GRANTS", + /* 126 */ "QUERIES", + /* 127 */ "SCORES", + /* 128 */ "TOPICS", + /* 129 */ "VARIABLES", + /* 130 */ "BNODES", + /* 131 */ "SNODES", + /* 132 */ "LIKE", + /* 133 */ "INDEX", + /* 134 */ "FULLTEXT", + /* 135 */ "FUNCTION", + /* 136 */ "INTERVAL", + /* 137 */ "TOPIC", + /* 138 */ "AS", + /* 139 */ "DESC", + /* 140 */ "DESCRIBE", + /* 141 */ "RESET", + /* 142 */ "QUERY", + /* 143 */ "EXPLAIN", + /* 144 */ "ANALYZE", + /* 145 */ "VERBOSE", + /* 146 */ "NK_BOOL", + /* 147 */ "RATIO", + /* 148 */ "COMPACT", + /* 149 */ "VNODES", + /* 150 */ "IN", + /* 151 */ "OUTPUTTYPE", + /* 152 */ "AGGREGATE", + /* 153 */ "BUFSIZE", + /* 154 */ "STREAM", + /* 155 */ "INTO", + /* 156 */ "KILL", + /* 157 */ "CONNECTION", + /* 158 */ "MERGE", + /* 159 */ "VGROUP", + /* 160 */ "REDISTRIBUTE", + /* 161 */ "SPLIT", + /* 162 */ "SYNCDB", + /* 163 */ "NULL", + /* 164 */ "FIRST", + /* 165 */ "LAST", + /* 166 */ "CAST", + /* 167 */ "NOW", + /* 168 */ "TODAY", + /* 169 */ "ROWTS", + /* 170 */ "TBNAME", + /* 171 */ "QSTARTTS", + /* 172 */ "QENDTS", + /* 173 */ "WSTARTTS", + /* 174 */ "WENDTS", + /* 175 */ "WDURATION", + /* 176 */ "BETWEEN", + /* 177 */ "IS", + /* 178 */ "NK_LT", + /* 179 */ "NK_GT", + /* 180 */ "NK_LE", + /* 181 */ "NK_GE", + /* 182 */ "NK_NE", + /* 183 */ "MATCH", + /* 184 */ "NMATCH", + /* 185 */ "JOIN", + /* 186 */ "INNER", + /* 187 */ "SELECT", + /* 188 */ "DISTINCT", + /* 189 */ "WHERE", + /* 190 */ "PARTITION", + /* 191 */ "BY", + /* 192 */ "SESSION", + /* 193 */ "STATE_WINDOW", + /* 194 */ "SLIDING", + /* 195 */ "FILL", + /* 196 */ "VALUE", + /* 197 */ "NONE", + /* 198 */ "PREV", + /* 199 */ "LINEAR", + /* 200 */ "NEXT", + /* 201 */ "GROUP", + /* 202 */ "HAVING", + /* 203 */ "ORDER", + /* 204 */ "SLIMIT", + /* 205 */ "SOFFSET", + /* 206 */ "LIMIT", + /* 207 */ "OFFSET", + /* 208 */ "ASC", + /* 209 */ "NULLS", + /* 210 */ "cmd", + /* 211 */ "account_options", + /* 212 */ "alter_account_options", + /* 213 */ "literal", + /* 214 */ "alter_account_option", + /* 215 */ "user_name", + /* 216 */ "dnode_endpoint", + /* 217 */ "dnode_host_name", + /* 218 */ "not_exists_opt", + /* 219 */ "db_name", + /* 220 */ "db_options", + /* 221 */ "exists_opt", + /* 222 */ "alter_db_options", + /* 223 */ "integer_list", + /* 224 */ "variable_list", + /* 225 */ "retention_list", + /* 226 */ "alter_db_option", + /* 227 */ "retention", + /* 228 */ "full_table_name", + /* 229 */ "column_def_list", + /* 230 */ "tags_def_opt", + /* 231 */ "table_options", + /* 232 */ "multi_create_clause", + /* 233 */ "tags_def", + /* 234 */ "multi_drop_clause", + /* 235 */ "alter_table_clause", + /* 236 */ "alter_table_options", + /* 237 */ "column_name", + /* 238 */ "type_name", + /* 239 */ "create_subtable_clause", + /* 240 */ "specific_tags_opt", + /* 241 */ "literal_list", + /* 242 */ "drop_table_clause", + /* 243 */ "col_name_list", + /* 244 */ "table_name", + /* 245 */ "column_def", + /* 246 */ "func_name_list", + /* 247 */ "alter_table_option", + /* 248 */ "col_name", + /* 249 */ "db_name_cond_opt", + /* 250 */ "like_pattern_opt", + /* 251 */ "table_name_cond", + /* 252 */ "from_db_opt", + /* 253 */ "func_name", + /* 254 */ "function_name", + /* 255 */ "index_name", + /* 256 */ "index_options", + /* 257 */ "func_list", + /* 258 */ "duration_literal", + /* 259 */ "sliding_opt", + /* 260 */ "func", + /* 261 */ "expression_list", + /* 262 */ "topic_name", + /* 263 */ "query_expression", + /* 264 */ "analyze_opt", + /* 265 */ "explain_options", + /* 266 */ "agg_func_opt", + /* 267 */ "bufsize_opt", + /* 268 */ "stream_name", + /* 269 */ "dnode_list", + /* 270 */ "signed", + /* 271 */ "signed_literal", + /* 272 */ "table_alias", + /* 273 */ "column_alias", + /* 274 */ "expression", + /* 275 */ "pseudo_column", + /* 276 */ "column_reference", + /* 277 */ "subquery", + /* 278 */ "predicate", + /* 279 */ "compare_op", + /* 280 */ "in_op", + /* 281 */ "in_predicate_value", + /* 282 */ "boolean_value_expression", + /* 283 */ "boolean_primary", + /* 284 */ "common_expression", + /* 285 */ "from_clause", + /* 286 */ "table_reference_list", + /* 287 */ "table_reference", + /* 288 */ "table_primary", + /* 289 */ "joined_table", + /* 290 */ "alias_opt", + /* 291 */ "parenthesized_joined_table", + /* 292 */ "join_type", + /* 293 */ "search_condition", + /* 294 */ "query_specification", + /* 295 */ "set_quantifier_opt", + /* 296 */ "select_list", + /* 297 */ "where_clause_opt", + /* 298 */ "partition_by_clause_opt", + /* 299 */ "twindow_clause_opt", + /* 300 */ "group_by_clause_opt", + /* 301 */ "having_clause_opt", + /* 302 */ "select_sublist", + /* 303 */ "select_item", + /* 304 */ "fill_opt", + /* 305 */ "fill_mode", + /* 306 */ "group_by_list", + /* 307 */ "query_expression_body", + /* 308 */ "order_by_clause_opt", + /* 309 */ "slimit_clause_opt", + /* 310 */ "limit_clause_opt", + /* 311 */ "query_primary", + /* 312 */ "sort_specification_list", + /* 313 */ "sort_specification", + /* 314 */ "ordering_specification_opt", + /* 315 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1295,231 +1303,233 @@ static const char *const yyRuleName[] = { /* 181 */ "cmd ::= SHOW APPS", /* 182 */ "cmd ::= SHOW CONNECTIONS", /* 183 */ "cmd ::= SHOW LICENCE", - /* 184 */ "cmd ::= SHOW CREATE DATABASE db_name", - /* 185 */ "cmd ::= SHOW CREATE TABLE full_table_name", - /* 186 */ "cmd ::= SHOW CREATE STABLE full_table_name", - /* 187 */ "cmd ::= SHOW QUERIES", - /* 188 */ "cmd ::= SHOW SCORES", - /* 189 */ "cmd ::= SHOW TOPICS", - /* 190 */ "cmd ::= SHOW VARIABLES", - /* 191 */ "cmd ::= SHOW BNODES", - /* 192 */ "cmd ::= SHOW SNODES", - /* 193 */ "db_name_cond_opt ::=", - /* 194 */ "db_name_cond_opt ::= db_name NK_DOT", - /* 195 */ "like_pattern_opt ::=", - /* 196 */ "like_pattern_opt ::= LIKE NK_STRING", - /* 197 */ "table_name_cond ::= table_name", - /* 198 */ "from_db_opt ::=", - /* 199 */ "from_db_opt ::= FROM db_name", - /* 200 */ "func_name_list ::= func_name", - /* 201 */ "func_name_list ::= func_name_list NK_COMMA col_name", - /* 202 */ "func_name ::= function_name", - /* 203 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", - /* 204 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", - /* 205 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", - /* 206 */ "index_options ::=", - /* 207 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", - /* 208 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", - /* 209 */ "func_list ::= func", - /* 210 */ "func_list ::= func_list NK_COMMA func", - /* 211 */ "func ::= function_name NK_LP expression_list NK_RP", - /* 212 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", - /* 213 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name", - /* 214 */ "cmd ::= DROP TOPIC exists_opt topic_name", - /* 215 */ "cmd ::= DESC full_table_name", - /* 216 */ "cmd ::= DESCRIBE full_table_name", - /* 217 */ "cmd ::= RESET QUERY CACHE", - /* 218 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", - /* 219 */ "analyze_opt ::=", - /* 220 */ "analyze_opt ::= ANALYZE", - /* 221 */ "explain_options ::=", - /* 222 */ "explain_options ::= explain_options VERBOSE NK_BOOL", - /* 223 */ "explain_options ::= explain_options RATIO NK_FLOAT", - /* 224 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", - /* 225 */ "cmd ::= CREATE agg_func_opt FUNCTION function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", - /* 226 */ "cmd ::= DROP FUNCTION function_name", - /* 227 */ "agg_func_opt ::=", - /* 228 */ "agg_func_opt ::= AGGREGATE", - /* 229 */ "bufsize_opt ::=", - /* 230 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", - /* 231 */ "cmd ::= CREATE STREAM stream_name INTO table_name AS query_expression", - /* 232 */ "cmd ::= DROP STREAM stream_name", - /* 233 */ "cmd ::= KILL CONNECTION NK_INTEGER", - /* 234 */ "cmd ::= KILL QUERY NK_INTEGER", - /* 235 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", - /* 236 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", - /* 237 */ "cmd ::= SPLIT VGROUP NK_INTEGER", - /* 238 */ "dnode_list ::= DNODE NK_INTEGER", - /* 239 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", - /* 240 */ "cmd ::= SYNCDB db_name REPLICA", - /* 241 */ "cmd ::= query_expression", - /* 242 */ "literal ::= NK_INTEGER", - /* 243 */ "literal ::= NK_FLOAT", - /* 244 */ "literal ::= NK_STRING", - /* 245 */ "literal ::= NK_BOOL", - /* 246 */ "literal ::= TIMESTAMP NK_STRING", - /* 247 */ "literal ::= duration_literal", - /* 248 */ "literal ::= NULL", - /* 249 */ "duration_literal ::= NK_VARIABLE", - /* 250 */ "signed ::= NK_INTEGER", - /* 251 */ "signed ::= NK_PLUS NK_INTEGER", - /* 252 */ "signed ::= NK_MINUS NK_INTEGER", - /* 253 */ "signed ::= NK_FLOAT", - /* 254 */ "signed ::= NK_PLUS NK_FLOAT", - /* 255 */ "signed ::= NK_MINUS NK_FLOAT", - /* 256 */ "signed_literal ::= signed", - /* 257 */ "signed_literal ::= NK_STRING", - /* 258 */ "signed_literal ::= NK_BOOL", - /* 259 */ "signed_literal ::= TIMESTAMP NK_STRING", - /* 260 */ "signed_literal ::= duration_literal", - /* 261 */ "signed_literal ::= NULL", - /* 262 */ "literal_list ::= signed_literal", - /* 263 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 264 */ "db_name ::= NK_ID", - /* 265 */ "table_name ::= NK_ID", - /* 266 */ "column_name ::= NK_ID", - /* 267 */ "function_name ::= NK_ID", - /* 268 */ "function_name ::= FIRST", - /* 269 */ "function_name ::= LAST", - /* 270 */ "table_alias ::= NK_ID", - /* 271 */ "column_alias ::= NK_ID", - /* 272 */ "user_name ::= NK_ID", - /* 273 */ "index_name ::= NK_ID", - /* 274 */ "topic_name ::= NK_ID", - /* 275 */ "stream_name ::= NK_ID", - /* 276 */ "expression ::= literal", - /* 277 */ "expression ::= pseudo_column", - /* 278 */ "expression ::= column_reference", - /* 279 */ "expression ::= function_name NK_LP expression_list NK_RP", - /* 280 */ "expression ::= function_name NK_LP NK_STAR NK_RP", - /* 281 */ "expression ::= function_name NK_LP expression AS type_name NK_RP", - /* 282 */ "expression ::= subquery", - /* 283 */ "expression ::= NK_LP expression NK_RP", - /* 284 */ "expression ::= NK_PLUS expression", - /* 285 */ "expression ::= NK_MINUS expression", - /* 286 */ "expression ::= expression NK_PLUS expression", - /* 287 */ "expression ::= expression NK_MINUS expression", - /* 288 */ "expression ::= expression NK_STAR expression", - /* 289 */ "expression ::= expression NK_SLASH expression", - /* 290 */ "expression ::= expression NK_REM expression", - /* 291 */ "expression_list ::= expression", - /* 292 */ "expression_list ::= expression_list NK_COMMA expression", - /* 293 */ "column_reference ::= column_name", - /* 294 */ "column_reference ::= table_name NK_DOT column_name", - /* 295 */ "pseudo_column ::= NOW", - /* 296 */ "pseudo_column ::= ROWTS", - /* 297 */ "pseudo_column ::= TBNAME", - /* 298 */ "pseudo_column ::= QSTARTTS", - /* 299 */ "pseudo_column ::= QENDTS", - /* 300 */ "pseudo_column ::= WSTARTTS", - /* 301 */ "pseudo_column ::= WENDTS", - /* 302 */ "pseudo_column ::= WDURATION", - /* 303 */ "predicate ::= expression compare_op expression", - /* 304 */ "predicate ::= expression BETWEEN expression AND expression", - /* 305 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 306 */ "predicate ::= expression IS NULL", - /* 307 */ "predicate ::= expression IS NOT NULL", - /* 308 */ "predicate ::= expression in_op in_predicate_value", - /* 309 */ "compare_op ::= NK_LT", - /* 310 */ "compare_op ::= NK_GT", - /* 311 */ "compare_op ::= NK_LE", - /* 312 */ "compare_op ::= NK_GE", - /* 313 */ "compare_op ::= NK_NE", - /* 314 */ "compare_op ::= NK_EQ", - /* 315 */ "compare_op ::= LIKE", - /* 316 */ "compare_op ::= NOT LIKE", - /* 317 */ "compare_op ::= MATCH", - /* 318 */ "compare_op ::= NMATCH", - /* 319 */ "in_op ::= IN", - /* 320 */ "in_op ::= NOT IN", - /* 321 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 322 */ "boolean_value_expression ::= boolean_primary", - /* 323 */ "boolean_value_expression ::= NOT boolean_primary", - /* 324 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 325 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 326 */ "boolean_primary ::= predicate", - /* 327 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 328 */ "common_expression ::= expression", - /* 329 */ "common_expression ::= boolean_value_expression", - /* 330 */ "from_clause ::= FROM table_reference_list", - /* 331 */ "table_reference_list ::= table_reference", - /* 332 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 333 */ "table_reference ::= table_primary", - /* 334 */ "table_reference ::= joined_table", - /* 335 */ "table_primary ::= table_name alias_opt", - /* 336 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 337 */ "table_primary ::= subquery alias_opt", - /* 338 */ "table_primary ::= parenthesized_joined_table", - /* 339 */ "alias_opt ::=", - /* 340 */ "alias_opt ::= table_alias", - /* 341 */ "alias_opt ::= AS table_alias", - /* 342 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 343 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 344 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 345 */ "join_type ::=", - /* 346 */ "join_type ::= INNER", - /* 347 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", - /* 348 */ "set_quantifier_opt ::=", - /* 349 */ "set_quantifier_opt ::= DISTINCT", - /* 350 */ "set_quantifier_opt ::= ALL", - /* 351 */ "select_list ::= NK_STAR", - /* 352 */ "select_list ::= select_sublist", - /* 353 */ "select_sublist ::= select_item", - /* 354 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 355 */ "select_item ::= common_expression", - /* 356 */ "select_item ::= common_expression column_alias", - /* 357 */ "select_item ::= common_expression AS column_alias", - /* 358 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 359 */ "where_clause_opt ::=", - /* 360 */ "where_clause_opt ::= WHERE search_condition", - /* 361 */ "partition_by_clause_opt ::=", - /* 362 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 363 */ "twindow_clause_opt ::=", - /* 364 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 365 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", - /* 366 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 367 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 368 */ "sliding_opt ::=", - /* 369 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 370 */ "fill_opt ::=", - /* 371 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 372 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 373 */ "fill_mode ::= NONE", - /* 374 */ "fill_mode ::= PREV", - /* 375 */ "fill_mode ::= NULL", - /* 376 */ "fill_mode ::= LINEAR", - /* 377 */ "fill_mode ::= NEXT", - /* 378 */ "group_by_clause_opt ::=", - /* 379 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 380 */ "group_by_list ::= expression", - /* 381 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 382 */ "having_clause_opt ::=", - /* 383 */ "having_clause_opt ::= HAVING search_condition", - /* 384 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 385 */ "query_expression_body ::= query_primary", - /* 386 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 387 */ "query_primary ::= query_specification", - /* 388 */ "order_by_clause_opt ::=", - /* 389 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 390 */ "slimit_clause_opt ::=", - /* 391 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 392 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 393 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 394 */ "limit_clause_opt ::=", - /* 395 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 396 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 397 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 398 */ "subquery ::= NK_LP query_expression NK_RP", - /* 399 */ "search_condition ::= common_expression", - /* 400 */ "sort_specification_list ::= sort_specification", - /* 401 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 402 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 403 */ "ordering_specification_opt ::=", - /* 404 */ "ordering_specification_opt ::= ASC", - /* 405 */ "ordering_specification_opt ::= DESC", - /* 406 */ "null_ordering_opt ::=", - /* 407 */ "null_ordering_opt ::= NULLS FIRST", - /* 408 */ "null_ordering_opt ::= NULLS LAST", + /* 184 */ "cmd ::= SHOW GRANTS", + /* 185 */ "cmd ::= SHOW CREATE DATABASE db_name", + /* 186 */ "cmd ::= SHOW CREATE TABLE full_table_name", + /* 187 */ "cmd ::= SHOW CREATE STABLE full_table_name", + /* 188 */ "cmd ::= SHOW QUERIES", + /* 189 */ "cmd ::= SHOW SCORES", + /* 190 */ "cmd ::= SHOW TOPICS", + /* 191 */ "cmd ::= SHOW VARIABLES", + /* 192 */ "cmd ::= SHOW BNODES", + /* 193 */ "cmd ::= SHOW SNODES", + /* 194 */ "db_name_cond_opt ::=", + /* 195 */ "db_name_cond_opt ::= db_name NK_DOT", + /* 196 */ "like_pattern_opt ::=", + /* 197 */ "like_pattern_opt ::= LIKE NK_STRING", + /* 198 */ "table_name_cond ::= table_name", + /* 199 */ "from_db_opt ::=", + /* 200 */ "from_db_opt ::= FROM db_name", + /* 201 */ "func_name_list ::= func_name", + /* 202 */ "func_name_list ::= func_name_list NK_COMMA col_name", + /* 203 */ "func_name ::= function_name", + /* 204 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", + /* 205 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", + /* 206 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", + /* 207 */ "index_options ::=", + /* 208 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", + /* 209 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", + /* 210 */ "func_list ::= func", + /* 211 */ "func_list ::= func_list NK_COMMA func", + /* 212 */ "func ::= function_name NK_LP expression_list NK_RP", + /* 213 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", + /* 214 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name", + /* 215 */ "cmd ::= DROP TOPIC exists_opt topic_name", + /* 216 */ "cmd ::= DESC full_table_name", + /* 217 */ "cmd ::= DESCRIBE full_table_name", + /* 218 */ "cmd ::= RESET QUERY CACHE", + /* 219 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", + /* 220 */ "analyze_opt ::=", + /* 221 */ "analyze_opt ::= ANALYZE", + /* 222 */ "explain_options ::=", + /* 223 */ "explain_options ::= explain_options VERBOSE NK_BOOL", + /* 224 */ "explain_options ::= explain_options RATIO NK_FLOAT", + /* 225 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", + /* 226 */ "cmd ::= CREATE agg_func_opt FUNCTION function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", + /* 227 */ "cmd ::= DROP FUNCTION function_name", + /* 228 */ "agg_func_opt ::=", + /* 229 */ "agg_func_opt ::= AGGREGATE", + /* 230 */ "bufsize_opt ::=", + /* 231 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", + /* 232 */ "cmd ::= CREATE STREAM stream_name INTO table_name AS query_expression", + /* 233 */ "cmd ::= DROP STREAM stream_name", + /* 234 */ "cmd ::= KILL CONNECTION NK_INTEGER", + /* 235 */ "cmd ::= KILL QUERY NK_INTEGER", + /* 236 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", + /* 237 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", + /* 238 */ "cmd ::= SPLIT VGROUP NK_INTEGER", + /* 239 */ "dnode_list ::= DNODE NK_INTEGER", + /* 240 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", + /* 241 */ "cmd ::= SYNCDB db_name REPLICA", + /* 242 */ "cmd ::= query_expression", + /* 243 */ "literal ::= NK_INTEGER", + /* 244 */ "literal ::= NK_FLOAT", + /* 245 */ "literal ::= NK_STRING", + /* 246 */ "literal ::= NK_BOOL", + /* 247 */ "literal ::= TIMESTAMP NK_STRING", + /* 248 */ "literal ::= duration_literal", + /* 249 */ "literal ::= NULL", + /* 250 */ "duration_literal ::= NK_VARIABLE", + /* 251 */ "signed ::= NK_INTEGER", + /* 252 */ "signed ::= NK_PLUS NK_INTEGER", + /* 253 */ "signed ::= NK_MINUS NK_INTEGER", + /* 254 */ "signed ::= NK_FLOAT", + /* 255 */ "signed ::= NK_PLUS NK_FLOAT", + /* 256 */ "signed ::= NK_MINUS NK_FLOAT", + /* 257 */ "signed_literal ::= signed", + /* 258 */ "signed_literal ::= NK_STRING", + /* 259 */ "signed_literal ::= NK_BOOL", + /* 260 */ "signed_literal ::= TIMESTAMP NK_STRING", + /* 261 */ "signed_literal ::= duration_literal", + /* 262 */ "signed_literal ::= NULL", + /* 263 */ "literal_list ::= signed_literal", + /* 264 */ "literal_list ::= literal_list NK_COMMA signed_literal", + /* 265 */ "db_name ::= NK_ID", + /* 266 */ "table_name ::= NK_ID", + /* 267 */ "column_name ::= NK_ID", + /* 268 */ "function_name ::= NK_ID", + /* 269 */ "function_name ::= FIRST", + /* 270 */ "function_name ::= LAST", + /* 271 */ "table_alias ::= NK_ID", + /* 272 */ "column_alias ::= NK_ID", + /* 273 */ "user_name ::= NK_ID", + /* 274 */ "index_name ::= NK_ID", + /* 275 */ "topic_name ::= NK_ID", + /* 276 */ "stream_name ::= NK_ID", + /* 277 */ "expression ::= literal", + /* 278 */ "expression ::= pseudo_column", + /* 279 */ "expression ::= column_reference", + /* 280 */ "expression ::= function_name NK_LP expression_list NK_RP", + /* 281 */ "expression ::= function_name NK_LP NK_STAR NK_RP", + /* 282 */ "expression ::= CAST NK_LP expression AS type_name NK_RP", + /* 283 */ "expression ::= subquery", + /* 284 */ "expression ::= NK_LP expression NK_RP", + /* 285 */ "expression ::= NK_PLUS expression", + /* 286 */ "expression ::= NK_MINUS expression", + /* 287 */ "expression ::= expression NK_PLUS expression", + /* 288 */ "expression ::= expression NK_MINUS expression", + /* 289 */ "expression ::= expression NK_STAR expression", + /* 290 */ "expression ::= expression NK_SLASH expression", + /* 291 */ "expression ::= expression NK_REM expression", + /* 292 */ "expression_list ::= expression", + /* 293 */ "expression_list ::= expression_list NK_COMMA expression", + /* 294 */ "column_reference ::= column_name", + /* 295 */ "column_reference ::= table_name NK_DOT column_name", + /* 296 */ "pseudo_column ::= NOW", + /* 297 */ "pseudo_column ::= TODAY", + /* 298 */ "pseudo_column ::= ROWTS", + /* 299 */ "pseudo_column ::= TBNAME", + /* 300 */ "pseudo_column ::= QSTARTTS", + /* 301 */ "pseudo_column ::= QENDTS", + /* 302 */ "pseudo_column ::= WSTARTTS", + /* 303 */ "pseudo_column ::= WENDTS", + /* 304 */ "pseudo_column ::= WDURATION", + /* 305 */ "predicate ::= expression compare_op expression", + /* 306 */ "predicate ::= expression BETWEEN expression AND expression", + /* 307 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 308 */ "predicate ::= expression IS NULL", + /* 309 */ "predicate ::= expression IS NOT NULL", + /* 310 */ "predicate ::= expression in_op in_predicate_value", + /* 311 */ "compare_op ::= NK_LT", + /* 312 */ "compare_op ::= NK_GT", + /* 313 */ "compare_op ::= NK_LE", + /* 314 */ "compare_op ::= NK_GE", + /* 315 */ "compare_op ::= NK_NE", + /* 316 */ "compare_op ::= NK_EQ", + /* 317 */ "compare_op ::= LIKE", + /* 318 */ "compare_op ::= NOT LIKE", + /* 319 */ "compare_op ::= MATCH", + /* 320 */ "compare_op ::= NMATCH", + /* 321 */ "in_op ::= IN", + /* 322 */ "in_op ::= NOT IN", + /* 323 */ "in_predicate_value ::= NK_LP expression_list NK_RP", + /* 324 */ "boolean_value_expression ::= boolean_primary", + /* 325 */ "boolean_value_expression ::= NOT boolean_primary", + /* 326 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 327 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 328 */ "boolean_primary ::= predicate", + /* 329 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 330 */ "common_expression ::= expression", + /* 331 */ "common_expression ::= boolean_value_expression", + /* 332 */ "from_clause ::= FROM table_reference_list", + /* 333 */ "table_reference_list ::= table_reference", + /* 334 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 335 */ "table_reference ::= table_primary", + /* 336 */ "table_reference ::= joined_table", + /* 337 */ "table_primary ::= table_name alias_opt", + /* 338 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 339 */ "table_primary ::= subquery alias_opt", + /* 340 */ "table_primary ::= parenthesized_joined_table", + /* 341 */ "alias_opt ::=", + /* 342 */ "alias_opt ::= table_alias", + /* 343 */ "alias_opt ::= AS table_alias", + /* 344 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 345 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 346 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 347 */ "join_type ::=", + /* 348 */ "join_type ::= INNER", + /* 349 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 350 */ "set_quantifier_opt ::=", + /* 351 */ "set_quantifier_opt ::= DISTINCT", + /* 352 */ "set_quantifier_opt ::= ALL", + /* 353 */ "select_list ::= NK_STAR", + /* 354 */ "select_list ::= select_sublist", + /* 355 */ "select_sublist ::= select_item", + /* 356 */ "select_sublist ::= select_sublist NK_COMMA select_item", + /* 357 */ "select_item ::= common_expression", + /* 358 */ "select_item ::= common_expression column_alias", + /* 359 */ "select_item ::= common_expression AS column_alias", + /* 360 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 361 */ "where_clause_opt ::=", + /* 362 */ "where_clause_opt ::= WHERE search_condition", + /* 363 */ "partition_by_clause_opt ::=", + /* 364 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 365 */ "twindow_clause_opt ::=", + /* 366 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 367 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", + /* 368 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 369 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 370 */ "sliding_opt ::=", + /* 371 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 372 */ "fill_opt ::=", + /* 373 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 374 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 375 */ "fill_mode ::= NONE", + /* 376 */ "fill_mode ::= PREV", + /* 377 */ "fill_mode ::= NULL", + /* 378 */ "fill_mode ::= LINEAR", + /* 379 */ "fill_mode ::= NEXT", + /* 380 */ "group_by_clause_opt ::=", + /* 381 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 382 */ "group_by_list ::= expression", + /* 383 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 384 */ "having_clause_opt ::=", + /* 385 */ "having_clause_opt ::= HAVING search_condition", + /* 386 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 387 */ "query_expression_body ::= query_primary", + /* 388 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 389 */ "query_primary ::= query_specification", + /* 390 */ "order_by_clause_opt ::=", + /* 391 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 392 */ "slimit_clause_opt ::=", + /* 393 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 394 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 395 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 396 */ "limit_clause_opt ::=", + /* 397 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 398 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 399 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 400 */ "subquery ::= NK_LP query_expression NK_RP", + /* 401 */ "search_condition ::= common_expression", + /* 402 */ "sort_specification_list ::= sort_specification", + /* 403 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 404 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 405 */ "ordering_specification_opt ::=", + /* 406 */ "ordering_specification_opt ::= ASC", + /* 407 */ "ordering_specification_opt ::= DESC", + /* 408 */ "null_ordering_opt ::=", + /* 409 */ "null_ordering_opt ::= NULLS FIRST", + /* 410 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -1646,156 +1656,156 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 207: /* cmd */ - case 210: /* literal */ - case 217: /* db_options */ - case 219: /* alter_db_options */ - case 224: /* retention */ - case 225: /* full_table_name */ - case 228: /* table_options */ - case 232: /* alter_table_clause */ - case 233: /* alter_table_options */ - case 236: /* create_subtable_clause */ - case 239: /* drop_table_clause */ - case 242: /* column_def */ - case 245: /* col_name */ - case 246: /* db_name_cond_opt */ - case 247: /* like_pattern_opt */ - case 248: /* table_name_cond */ - case 249: /* from_db_opt */ - case 250: /* func_name */ - case 253: /* index_options */ - case 255: /* duration_literal */ - case 256: /* sliding_opt */ - case 257: /* func */ - case 260: /* query_expression */ - case 262: /* explain_options */ - case 267: /* signed */ - case 268: /* signed_literal */ - case 271: /* expression */ - case 272: /* pseudo_column */ - case 273: /* column_reference */ - case 274: /* subquery */ - case 275: /* predicate */ - case 278: /* in_predicate_value */ - case 279: /* boolean_value_expression */ - case 280: /* boolean_primary */ - case 281: /* common_expression */ - case 282: /* from_clause */ - case 283: /* table_reference_list */ - case 284: /* table_reference */ - case 285: /* table_primary */ - case 286: /* joined_table */ - case 288: /* parenthesized_joined_table */ - case 290: /* search_condition */ - case 291: /* query_specification */ - case 294: /* where_clause_opt */ - case 296: /* twindow_clause_opt */ - case 298: /* having_clause_opt */ - case 300: /* select_item */ - case 301: /* fill_opt */ - case 304: /* query_expression_body */ - case 306: /* slimit_clause_opt */ - case 307: /* limit_clause_opt */ - case 308: /* query_primary */ - case 310: /* sort_specification */ + case 210: /* cmd */ + case 213: /* literal */ + case 220: /* db_options */ + case 222: /* alter_db_options */ + case 227: /* retention */ + case 228: /* full_table_name */ + case 231: /* table_options */ + case 235: /* alter_table_clause */ + case 236: /* alter_table_options */ + case 239: /* create_subtable_clause */ + case 242: /* drop_table_clause */ + case 245: /* column_def */ + case 248: /* col_name */ + case 249: /* db_name_cond_opt */ + case 250: /* like_pattern_opt */ + case 251: /* table_name_cond */ + case 252: /* from_db_opt */ + case 253: /* func_name */ + case 256: /* index_options */ + case 258: /* duration_literal */ + case 259: /* sliding_opt */ + case 260: /* func */ + case 263: /* query_expression */ + case 265: /* explain_options */ + case 270: /* signed */ + case 271: /* signed_literal */ + case 274: /* expression */ + case 275: /* pseudo_column */ + case 276: /* column_reference */ + case 277: /* subquery */ + case 278: /* predicate */ + case 281: /* in_predicate_value */ + case 282: /* boolean_value_expression */ + case 283: /* boolean_primary */ + case 284: /* common_expression */ + case 285: /* from_clause */ + case 286: /* table_reference_list */ + case 287: /* table_reference */ + case 288: /* table_primary */ + case 289: /* joined_table */ + case 291: /* parenthesized_joined_table */ + case 293: /* search_condition */ + case 294: /* query_specification */ + case 297: /* where_clause_opt */ + case 299: /* twindow_clause_opt */ + case 301: /* having_clause_opt */ + case 303: /* select_item */ + case 304: /* fill_opt */ + case 307: /* query_expression_body */ + case 309: /* slimit_clause_opt */ + case 310: /* limit_clause_opt */ + case 311: /* query_primary */ + case 313: /* sort_specification */ { - nodesDestroyNode((yypminor->yy564)); + nodesDestroyNode((yypminor->yy504)); } break; - case 208: /* account_options */ - case 209: /* alter_account_options */ - case 211: /* alter_account_option */ - case 264: /* bufsize_opt */ + case 211: /* account_options */ + case 212: /* alter_account_options */ + case 214: /* alter_account_option */ + case 267: /* bufsize_opt */ { } break; - case 212: /* user_name */ - case 213: /* dnode_endpoint */ - case 214: /* dnode_host_name */ - case 216: /* db_name */ - case 234: /* column_name */ - case 241: /* table_name */ - case 251: /* function_name */ - case 252: /* index_name */ - case 259: /* topic_name */ - case 265: /* stream_name */ - case 269: /* table_alias */ - case 270: /* column_alias */ - case 287: /* alias_opt */ + case 215: /* user_name */ + case 216: /* dnode_endpoint */ + case 217: /* dnode_host_name */ + case 219: /* db_name */ + case 237: /* column_name */ + case 244: /* table_name */ + case 254: /* function_name */ + case 255: /* index_name */ + case 262: /* topic_name */ + case 268: /* stream_name */ + case 272: /* table_alias */ + case 273: /* column_alias */ + case 290: /* alias_opt */ { } break; - case 215: /* not_exists_opt */ - case 218: /* exists_opt */ - case 261: /* analyze_opt */ - case 263: /* agg_func_opt */ - case 292: /* set_quantifier_opt */ + case 218: /* not_exists_opt */ + case 221: /* exists_opt */ + case 264: /* analyze_opt */ + case 266: /* agg_func_opt */ + case 295: /* set_quantifier_opt */ { } break; - case 220: /* integer_list */ - case 221: /* variable_list */ - case 222: /* retention_list */ - case 226: /* column_def_list */ - case 227: /* tags_def_opt */ - case 229: /* multi_create_clause */ - case 230: /* tags_def */ - case 231: /* multi_drop_clause */ - case 237: /* specific_tags_opt */ - case 238: /* literal_list */ - case 240: /* col_name_list */ - case 243: /* func_name_list */ - case 254: /* func_list */ - case 258: /* expression_list */ - case 266: /* dnode_list */ - case 293: /* select_list */ - case 295: /* partition_by_clause_opt */ - case 297: /* group_by_clause_opt */ - case 299: /* select_sublist */ - case 303: /* group_by_list */ - case 305: /* order_by_clause_opt */ - case 309: /* sort_specification_list */ + case 223: /* integer_list */ + case 224: /* variable_list */ + case 225: /* retention_list */ + case 229: /* column_def_list */ + case 230: /* tags_def_opt */ + case 232: /* multi_create_clause */ + case 233: /* tags_def */ + case 234: /* multi_drop_clause */ + case 240: /* specific_tags_opt */ + case 241: /* literal_list */ + case 243: /* col_name_list */ + case 246: /* func_name_list */ + case 257: /* func_list */ + case 261: /* expression_list */ + case 269: /* dnode_list */ + case 296: /* select_list */ + case 298: /* partition_by_clause_opt */ + case 300: /* group_by_clause_opt */ + case 302: /* select_sublist */ + case 306: /* group_by_list */ + case 308: /* order_by_clause_opt */ + case 312: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy476)); + nodesDestroyList((yypminor->yy488)); } break; - case 223: /* alter_db_option */ - case 244: /* alter_table_option */ + case 226: /* alter_db_option */ + case 247: /* alter_table_option */ { } break; - case 235: /* type_name */ + case 238: /* type_name */ { } break; - case 276: /* compare_op */ - case 277: /* in_op */ + case 279: /* compare_op */ + case 280: /* in_op */ { } break; - case 289: /* join_type */ + case 292: /* join_type */ { } break; - case 302: /* fill_mode */ + case 305: /* fill_mode */ { } break; - case 311: /* ordering_specification_opt */ + case 314: /* ordering_specification_opt */ { } break; - case 312: /* null_ordering_opt */ + case 315: /* null_ordering_opt */ { } @@ -1923,18 +1933,15 @@ static YYACTIONTYPE yy_find_shift_action( do{ i = yy_shift_ofst[stateno]; assert( i>=0 ); - assert( i<=YY_ACTTAB_COUNT ); - assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD ); + /* assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD ); */ assert( iLookAhead!=YYNOCODE ); assert( iLookAhead < YYNTOKEN ); i += iLookAhead; - assert( i<(int)YY_NLOOKAHEAD ); - if( yy_lookahead[i]!=iLookAhead ){ + if( i>=YY_NLOOKAHEAD || yy_lookahead[i]!=iLookAhead ){ #ifdef YYFALLBACK YYCODETYPE iFallback; /* Fallback token */ - assert( iLookAhead %s\n", @@ -1949,8 +1956,16 @@ static YYACTIONTYPE yy_find_shift_action( #ifdef YYWILDCARD { int j = i - iLookAhead + YYWILDCARD; - assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) ); - if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){ + if( +#if YY_SHIFT_MIN+YYWILDCARD<0 + j>=0 && +#endif +#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT + j0 + ){ #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", @@ -1964,7 +1979,6 @@ static YYACTIONTYPE yy_find_shift_action( #endif /* YYWILDCARD */ return yy_default[stateno]; }else{ - assert( i>=0 && iyytos; #ifndef NDEBUG if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ - yysize = yyRuleInfoNRhs[yyruleno]; + yysize = yyRuleInfo[yyruleno].nrhs; if( yysize ){ - fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", + fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n", yyTracePrompt, - yyruleno, yyRuleName[yyruleno], - yyrulenoyytos - yypParser->yystack)>yypParser->yyhwm ){ yypParser->yyhwm++; @@ -3000,11 +2603,11 @@ static YYACTIONTYPE yy_reduce( YYMINORTYPE yylhsminor; case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,208,&yymsp[0].minor); + yy_destructor(yypParser,211,&yymsp[0].minor); break; case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,209,&yymsp[0].minor); + yy_destructor(yypParser,212,&yymsp[0].minor); break; case 2: /* account_options ::= */ { } @@ -3018,20 +2621,20 @@ static YYACTIONTYPE yy_reduce( case 9: /* account_options ::= account_options USERS literal */ yytestcase(yyruleno==9); case 10: /* account_options ::= account_options CONNS literal */ yytestcase(yyruleno==10); case 11: /* account_options ::= account_options STATE literal */ yytestcase(yyruleno==11); -{ yy_destructor(yypParser,208,&yymsp[-2].minor); +{ yy_destructor(yypParser,211,&yymsp[-2].minor); { } - yy_destructor(yypParser,210,&yymsp[0].minor); + yy_destructor(yypParser,213,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ -{ yy_destructor(yypParser,211,&yymsp[0].minor); +{ yy_destructor(yypParser,214,&yymsp[0].minor); { } } break; case 13: /* alter_account_options ::= alter_account_options alter_account_option */ -{ yy_destructor(yypParser,209,&yymsp[-1].minor); +{ yy_destructor(yypParser,212,&yymsp[-1].minor); { } - yy_destructor(yypParser,211,&yymsp[0].minor); + yy_destructor(yypParser,214,&yymsp[0].minor); } break; case 14: /* alter_account_option ::= PASS literal */ @@ -3045,31 +2648,31 @@ static YYACTIONTYPE yy_reduce( case 22: /* alter_account_option ::= CONNS literal */ yytestcase(yyruleno==22); case 23: /* alter_account_option ::= STATE literal */ yytestcase(yyruleno==23); { } - yy_destructor(yypParser,210,&yymsp[0].minor); + yy_destructor(yypParser,213,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy21, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy409, &yymsp[0].minor.yy0); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy21, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy409, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } break; case 26: /* cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy21, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy409, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy21); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy409); } break; case 28: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy21, NULL); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy409, NULL); } break; case 29: /* cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy21, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy409, &yymsp[0].minor.yy0); } break; case 30: /* cmd ::= DROP DNODE NK_INTEGER */ { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; case 31: /* cmd ::= DROP DNODE dnode_endpoint */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy21); } +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy409); } break; case 32: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } @@ -3086,20 +2689,20 @@ static YYACTIONTYPE yy_reduce( case 36: /* dnode_endpoint ::= NK_STRING */ case 37: /* dnode_host_name ::= NK_ID */ yytestcase(yyruleno==37); case 38: /* dnode_host_name ::= NK_IPTOKEN */ yytestcase(yyruleno==38); - case 264: /* db_name ::= NK_ID */ yytestcase(yyruleno==264); - case 265: /* table_name ::= NK_ID */ yytestcase(yyruleno==265); - case 266: /* column_name ::= NK_ID */ yytestcase(yyruleno==266); - case 267: /* function_name ::= NK_ID */ yytestcase(yyruleno==267); - case 268: /* function_name ::= FIRST */ yytestcase(yyruleno==268); - case 269: /* function_name ::= LAST */ yytestcase(yyruleno==269); - case 270: /* table_alias ::= NK_ID */ yytestcase(yyruleno==270); - case 271: /* column_alias ::= NK_ID */ yytestcase(yyruleno==271); - case 272: /* user_name ::= NK_ID */ yytestcase(yyruleno==272); - case 273: /* index_name ::= NK_ID */ yytestcase(yyruleno==273); - case 274: /* topic_name ::= NK_ID */ yytestcase(yyruleno==274); - case 275: /* stream_name ::= NK_ID */ yytestcase(yyruleno==275); -{ yylhsminor.yy21 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy21 = yylhsminor.yy21; + case 265: /* db_name ::= NK_ID */ yytestcase(yyruleno==265); + case 266: /* table_name ::= NK_ID */ yytestcase(yyruleno==266); + case 267: /* column_name ::= NK_ID */ yytestcase(yyruleno==267); + case 268: /* function_name ::= NK_ID */ yytestcase(yyruleno==268); + case 269: /* function_name ::= FIRST */ yytestcase(yyruleno==269); + case 270: /* function_name ::= LAST */ yytestcase(yyruleno==270); + case 271: /* table_alias ::= NK_ID */ yytestcase(yyruleno==271); + case 272: /* column_alias ::= NK_ID */ yytestcase(yyruleno==272); + case 273: /* user_name ::= NK_ID */ yytestcase(yyruleno==273); + case 274: /* index_name ::= NK_ID */ yytestcase(yyruleno==274); + case 275: /* topic_name ::= NK_ID */ yytestcase(yyruleno==275); + case 276: /* stream_name ::= NK_ID */ yytestcase(yyruleno==276); +{ yylhsminor.yy409 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy409 = yylhsminor.yy409; break; case 39: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } @@ -3132,408 +2735,408 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_MNODE_STMT, &yymsp[0].minor.yy0); } break; case 49: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ -{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy173, &yymsp[-1].minor.yy21, yymsp[0].minor.yy564); } +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy121, &yymsp[-1].minor.yy409, yymsp[0].minor.yy504); } break; case 50: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy173, &yymsp[0].minor.yy21); } +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy121, &yymsp[0].minor.yy409); } break; case 51: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy21); } +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy409); } break; case 52: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy21, yymsp[0].minor.yy564); } +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy409, yymsp[0].minor.yy504); } break; case 53: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy173 = true; } +{ yymsp[-2].minor.yy121 = true; } break; case 54: /* not_exists_opt ::= */ case 56: /* exists_opt ::= */ yytestcase(yyruleno==56); - case 219: /* analyze_opt ::= */ yytestcase(yyruleno==219); - case 227: /* agg_func_opt ::= */ yytestcase(yyruleno==227); - case 348: /* set_quantifier_opt ::= */ yytestcase(yyruleno==348); -{ yymsp[1].minor.yy173 = false; } + case 220: /* analyze_opt ::= */ yytestcase(yyruleno==220); + case 228: /* agg_func_opt ::= */ yytestcase(yyruleno==228); + case 350: /* set_quantifier_opt ::= */ yytestcase(yyruleno==350); +{ yymsp[1].minor.yy121 = false; } break; case 55: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy173 = true; } +{ yymsp[-1].minor.yy121 = true; } break; case 57: /* db_options ::= */ -{ yymsp[1].minor.yy564 = createDatabaseOptions(pCxt); } +{ yymsp[1].minor.yy504 = createDatabaseOptions(pCxt); } break; case 58: /* db_options ::= db_options BLOCKS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pNumOfBlocks = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pNumOfBlocks = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 59: /* db_options ::= db_options CACHE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pCacheBlockSize = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pCacheBlockSize = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 60: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pCachelast = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pCachelast = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 61: /* db_options ::= db_options COMP NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pCompressionLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pCompressionLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 62: /* db_options ::= db_options DAYS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pDaysPerFile = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pDaysPerFile = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 63: /* db_options ::= db_options DAYS NK_VARIABLE */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 64: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pFsyncPeriod = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pFsyncPeriod = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 65: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pMaxRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pMaxRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 66: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pMinRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pMinRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 67: /* db_options ::= db_options KEEP integer_list */ case 68: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==68); -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pKeep = yymsp[0].minor.yy476; yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pKeep = yymsp[0].minor.yy488; yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 69: /* db_options ::= db_options PRECISION NK_STRING */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pPrecision = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pPrecision = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 70: /* db_options ::= db_options QUORUM NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pQuorum = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pQuorum = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 71: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pReplica = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pReplica = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 72: /* db_options ::= db_options TTL NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 73: /* db_options ::= db_options WAL NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pWalLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pWalLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 74: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pNumOfVgroups = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pNumOfVgroups = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 75: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pSingleStable = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pSingleStable = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 76: /* db_options ::= db_options STREAM_MODE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pStreamMode = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pStreamMode = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 77: /* db_options ::= db_options RETENTIONS retention_list */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy564)->pRetentions = yymsp[0].minor.yy476; yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pRetentions = yymsp[0].minor.yy488; yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 78: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy564 = createDatabaseOptions(pCxt); yylhsminor.yy564 = setDatabaseAlterOption(pCxt, yylhsminor.yy564, &yymsp[0].minor.yy289); } - yymsp[0].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createDatabaseOptions(pCxt); yylhsminor.yy504 = setDatabaseAlterOption(pCxt, yylhsminor.yy504, &yymsp[0].minor.yy21); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 79: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy564 = setDatabaseAlterOption(pCxt, yymsp[-1].minor.yy564, &yymsp[0].minor.yy289); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = setDatabaseAlterOption(pCxt, yymsp[-1].minor.yy504, &yymsp[0].minor.yy21); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 80: /* alter_db_option ::= BLOCKS NK_INTEGER */ -{ yymsp[-1].minor.yy289.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy289.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy21.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy21.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 81: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy289.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy289.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy21.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy21.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 82: /* alter_db_option ::= KEEP integer_list */ case 83: /* alter_db_option ::= KEEP variable_list */ yytestcase(yyruleno==83); -{ yymsp[-1].minor.yy289.type = DB_OPTION_KEEP; yymsp[-1].minor.yy289.pList = yymsp[0].minor.yy476; } +{ yymsp[-1].minor.yy21.type = DB_OPTION_KEEP; yymsp[-1].minor.yy21.pList = yymsp[0].minor.yy488; } break; case 84: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy289.type = DB_OPTION_WAL; yymsp[-1].minor.yy289.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy21.type = DB_OPTION_WAL; yymsp[-1].minor.yy21.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 85: /* alter_db_option ::= QUORUM NK_INTEGER */ -{ yymsp[-1].minor.yy289.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy289.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy21.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy21.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 86: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy289.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy289.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy21.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy21.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 87: /* alter_db_option ::= REPLICA NK_INTEGER */ -{ yymsp[-1].minor.yy289.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy289.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy21.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy21.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 88: /* integer_list ::= NK_INTEGER */ -{ yylhsminor.yy476 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy476 = yylhsminor.yy476; +{ yylhsminor.yy488 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy488 = yylhsminor.yy488; break; case 89: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ - case 239: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==239); -{ yylhsminor.yy476 = addNodeToList(pCxt, yymsp[-2].minor.yy476, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy476 = yylhsminor.yy476; + case 240: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==240); +{ yylhsminor.yy488 = addNodeToList(pCxt, yymsp[-2].minor.yy488, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy488 = yylhsminor.yy488; break; case 90: /* variable_list ::= NK_VARIABLE */ -{ yylhsminor.yy476 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy476 = yylhsminor.yy476; +{ yylhsminor.yy488 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy488 = yylhsminor.yy488; break; case 91: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ -{ yylhsminor.yy476 = addNodeToList(pCxt, yymsp[-2].minor.yy476, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy476 = yylhsminor.yy476; +{ yylhsminor.yy488 = addNodeToList(pCxt, yymsp[-2].minor.yy488, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy488 = yylhsminor.yy488; break; case 92: /* retention_list ::= retention */ case 112: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==112); case 115: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==115); case 122: /* column_def_list ::= column_def */ yytestcase(yyruleno==122); case 165: /* col_name_list ::= col_name */ yytestcase(yyruleno==165); - case 200: /* func_name_list ::= func_name */ yytestcase(yyruleno==200); - case 209: /* func_list ::= func */ yytestcase(yyruleno==209); - case 262: /* literal_list ::= signed_literal */ yytestcase(yyruleno==262); - case 353: /* select_sublist ::= select_item */ yytestcase(yyruleno==353); - case 400: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==400); -{ yylhsminor.yy476 = createNodeList(pCxt, yymsp[0].minor.yy564); } - yymsp[0].minor.yy476 = yylhsminor.yy476; + case 201: /* func_name_list ::= func_name */ yytestcase(yyruleno==201); + case 210: /* func_list ::= func */ yytestcase(yyruleno==210); + case 263: /* literal_list ::= signed_literal */ yytestcase(yyruleno==263); + case 355: /* select_sublist ::= select_item */ yytestcase(yyruleno==355); + case 402: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==402); +{ yylhsminor.yy488 = createNodeList(pCxt, yymsp[0].minor.yy504); } + yymsp[0].minor.yy488 = yylhsminor.yy488; break; case 93: /* retention_list ::= retention_list NK_COMMA retention */ case 123: /* column_def_list ::= column_def_list NK_COMMA column_def */ yytestcase(yyruleno==123); case 166: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==166); - case 201: /* func_name_list ::= func_name_list NK_COMMA col_name */ yytestcase(yyruleno==201); - case 210: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==210); - case 263: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==263); - case 354: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==354); - case 401: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==401); -{ yylhsminor.yy476 = addNodeToList(pCxt, yymsp[-2].minor.yy476, yymsp[0].minor.yy564); } - yymsp[-2].minor.yy476 = yylhsminor.yy476; + case 202: /* func_name_list ::= func_name_list NK_COMMA col_name */ yytestcase(yyruleno==202); + case 211: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==211); + case 264: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==264); + case 356: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==356); + case 403: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==403); +{ yylhsminor.yy488 = addNodeToList(pCxt, yymsp[-2].minor.yy488, yymsp[0].minor.yy504); } + yymsp[-2].minor.yy488 = yylhsminor.yy488; break; case 94: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ -{ yylhsminor.yy564 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 95: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ case 97: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==97); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy173, yymsp[-5].minor.yy564, yymsp[-3].minor.yy476, yymsp[-1].minor.yy476, yymsp[0].minor.yy564); } +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy121, yymsp[-5].minor.yy504, yymsp[-3].minor.yy488, yymsp[-1].minor.yy488, yymsp[0].minor.yy504); } break; case 96: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy476); } +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy488); } break; case 98: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy476); } +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy488); } break; case 99: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy173, yymsp[0].minor.yy564); } +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy121, yymsp[0].minor.yy504); } break; case 100: /* cmd ::= ALTER TABLE alter_table_clause */ case 101: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==101); - case 241: /* cmd ::= query_expression */ yytestcase(yyruleno==241); -{ pCxt->pRootNode = yymsp[0].minor.yy564; } + case 242: /* cmd ::= query_expression */ yytestcase(yyruleno==242); +{ pCxt->pRootNode = yymsp[0].minor.yy504; } break; case 102: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy564 = createAlterTableOption(pCxt, yymsp[-1].minor.yy564, yymsp[0].minor.yy564); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createAlterTableOption(pCxt, yymsp[-1].minor.yy504, yymsp[0].minor.yy504); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 103: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.yy564 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy564, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy21, yymsp[0].minor.yy288); } - yymsp[-4].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy504, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy409, yymsp[0].minor.yy160); } + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 104: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy564 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy564, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy21); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy504, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy409); } + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; case 105: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.yy564 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy564, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy21, yymsp[0].minor.yy288); } - yymsp[-4].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy504, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy409, yymsp[0].minor.yy160); } + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 106: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.yy564 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy564, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy21, &yymsp[0].minor.yy21); } - yymsp[-4].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy504, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy409, &yymsp[0].minor.yy409); } + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 107: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.yy564 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy564, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy21, yymsp[0].minor.yy288); } - yymsp[-4].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy504, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy409, yymsp[0].minor.yy160); } + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 108: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy564 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy564, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy21); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy504, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy409); } + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; case 109: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.yy564 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy564, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy21, yymsp[0].minor.yy288); } - yymsp[-4].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy504, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy409, yymsp[0].minor.yy160); } + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 110: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.yy564 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy564, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy21, &yymsp[0].minor.yy21); } - yymsp[-4].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy504, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy409, &yymsp[0].minor.yy409); } + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 111: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ -{ yylhsminor.yy564 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy564, &yymsp[-2].minor.yy21, yymsp[0].minor.yy564); } - yymsp[-5].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy504, &yymsp[-2].minor.yy409, yymsp[0].minor.yy504); } + yymsp[-5].minor.yy504 = yylhsminor.yy504; break; case 113: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ case 116: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==116); -{ yylhsminor.yy476 = addNodeToList(pCxt, yymsp[-1].minor.yy476, yymsp[0].minor.yy564); } - yymsp[-1].minor.yy476 = yylhsminor.yy476; +{ yylhsminor.yy488 = addNodeToList(pCxt, yymsp[-1].minor.yy488, yymsp[0].minor.yy504); } + yymsp[-1].minor.yy488 = yylhsminor.yy488; break; case 114: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ -{ yylhsminor.yy564 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy173, yymsp[-7].minor.yy564, yymsp[-5].minor.yy564, yymsp[-4].minor.yy476, yymsp[-1].minor.yy476); } - yymsp[-8].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy121, yymsp[-7].minor.yy504, yymsp[-5].minor.yy504, yymsp[-4].minor.yy488, yymsp[-1].minor.yy488); } + yymsp[-8].minor.yy504 = yylhsminor.yy504; break; case 117: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy564 = createDropTableClause(pCxt, yymsp[-1].minor.yy173, yymsp[0].minor.yy564); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createDropTableClause(pCxt, yymsp[-1].minor.yy121, yymsp[0].minor.yy504); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 118: /* specific_tags_opt ::= */ case 149: /* tags_def_opt ::= */ yytestcase(yyruleno==149); - case 361: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==361); - case 378: /* group_by_clause_opt ::= */ yytestcase(yyruleno==378); - case 388: /* order_by_clause_opt ::= */ yytestcase(yyruleno==388); -{ yymsp[1].minor.yy476 = NULL; } + case 363: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==363); + case 380: /* group_by_clause_opt ::= */ yytestcase(yyruleno==380); + case 390: /* order_by_clause_opt ::= */ yytestcase(yyruleno==390); +{ yymsp[1].minor.yy488 = NULL; } break; case 119: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy476 = yymsp[-1].minor.yy476; } +{ yymsp[-2].minor.yy488 = yymsp[-1].minor.yy488; } break; case 120: /* full_table_name ::= table_name */ -{ yylhsminor.yy564 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy21, NULL); } - yymsp[0].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy409, NULL); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 121: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy564 = createRealTableNode(pCxt, &yymsp[-2].minor.yy21, &yymsp[0].minor.yy21, NULL); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createRealTableNode(pCxt, &yymsp[-2].minor.yy409, &yymsp[0].minor.yy409, NULL); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 124: /* column_def ::= column_name type_name */ -{ yylhsminor.yy564 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy21, yymsp[0].minor.yy288, NULL); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy409, yymsp[0].minor.yy160, NULL); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 125: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy564 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy21, yymsp[-2].minor.yy288, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy409, yymsp[-2].minor.yy160, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; case 126: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_BOOL); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_BOOL); } break; case 127: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_TINYINT); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; case 128: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_SMALLINT); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; case 129: /* type_name ::= INT */ case 130: /* type_name ::= INTEGER */ yytestcase(yyruleno==130); -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_INT); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_INT); } break; case 131: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_BIGINT); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; case 132: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_FLOAT); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; case 133: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_DOUBLE); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; case 134: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy288 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy160 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; case 135: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; case 136: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy288 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy160 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; case 137: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy288 = createDataType(TSDB_DATA_TYPE_UTINYINT); } +{ yymsp[-1].minor.yy160 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; case 138: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy288 = createDataType(TSDB_DATA_TYPE_USMALLINT); } +{ yymsp[-1].minor.yy160 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; case 139: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy288 = createDataType(TSDB_DATA_TYPE_UINT); } +{ yymsp[-1].minor.yy160 = createDataType(TSDB_DATA_TYPE_UINT); } break; case 140: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy288 = createDataType(TSDB_DATA_TYPE_UBIGINT); } +{ yymsp[-1].minor.yy160 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; case 141: /* type_name ::= JSON */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_JSON); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_JSON); } break; case 142: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy288 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy160 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; case 143: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; case 144: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_BLOB); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_BLOB); } break; case 145: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy288 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy160 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; case 146: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy288 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 147: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy288 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-3].minor.yy160 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 148: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy288 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-5].minor.yy160 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 150: /* tags_def_opt ::= tags_def */ - case 352: /* select_list ::= select_sublist */ yytestcase(yyruleno==352); -{ yylhsminor.yy476 = yymsp[0].minor.yy476; } - yymsp[0].minor.yy476 = yylhsminor.yy476; + case 354: /* select_list ::= select_sublist */ yytestcase(yyruleno==354); +{ yylhsminor.yy488 = yymsp[0].minor.yy488; } + yymsp[0].minor.yy488 = yylhsminor.yy488; break; case 151: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy476 = yymsp[-1].minor.yy476; } +{ yymsp[-3].minor.yy488 = yymsp[-1].minor.yy488; } break; case 152: /* table_options ::= */ -{ yymsp[1].minor.yy564 = createTableOptions(pCxt); } +{ yymsp[1].minor.yy504 = createTableOptions(pCxt); } break; case 153: /* table_options ::= table_options COMMENT NK_STRING */ -{ ((STableOptions*)yymsp[-2].minor.yy564)->pComments = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((STableOptions*)yymsp[-2].minor.yy504)->pComments = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 154: /* table_options ::= table_options KEEP integer_list */ -{ ((STableOptions*)yymsp[-2].minor.yy564)->pKeep = yymsp[0].minor.yy476; yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((STableOptions*)yymsp[-2].minor.yy504)->pKeep = yymsp[0].minor.yy488; yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 155: /* table_options ::= table_options TTL NK_INTEGER */ -{ ((STableOptions*)yymsp[-2].minor.yy564)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((STableOptions*)yymsp[-2].minor.yy504)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 156: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ ((STableOptions*)yymsp[-4].minor.yy564)->pSma = yymsp[-1].minor.yy476; yylhsminor.yy564 = yymsp[-4].minor.yy564; } - yymsp[-4].minor.yy564 = yylhsminor.yy564; +{ ((STableOptions*)yymsp[-4].minor.yy504)->pSma = yymsp[-1].minor.yy488; yylhsminor.yy504 = yymsp[-4].minor.yy504; } + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 157: /* table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ -{ ((STableOptions*)yymsp[-4].minor.yy564)->pFuncs = yymsp[-1].minor.yy476; yylhsminor.yy564 = yymsp[-4].minor.yy564; } - yymsp[-4].minor.yy564 = yylhsminor.yy564; +{ ((STableOptions*)yymsp[-4].minor.yy504)->pFuncs = yymsp[-1].minor.yy488; yylhsminor.yy504 = yymsp[-4].minor.yy504; } + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 158: /* table_options ::= table_options FILE_FACTOR NK_FLOAT */ -{ ((STableOptions*)yymsp[-2].minor.yy564)->pFilesFactor = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((STableOptions*)yymsp[-2].minor.yy504)->pFilesFactor = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 159: /* table_options ::= table_options DELAY NK_INTEGER */ -{ ((STableOptions*)yymsp[-2].minor.yy564)->pDelay = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy564 = yymsp[-2].minor.yy564; } - yymsp[-2].minor.yy564 = yylhsminor.yy564; +{ ((STableOptions*)yymsp[-2].minor.yy504)->pDelay = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 160: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy564 = createTableOptions(pCxt); yylhsminor.yy564 = setTableAlterOption(pCxt, yylhsminor.yy564, &yymsp[0].minor.yy289); } - yymsp[0].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createTableOptions(pCxt); yylhsminor.yy504 = setTableAlterOption(pCxt, yylhsminor.yy504, &yymsp[0].minor.yy21); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 161: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy564 = setTableAlterOption(pCxt, yymsp[-1].minor.yy564, &yymsp[0].minor.yy289); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = setTableAlterOption(pCxt, yymsp[-1].minor.yy504, &yymsp[0].minor.yy21); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 162: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy289.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy289.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy21.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy21.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; case 163: /* alter_table_option ::= KEEP integer_list */ -{ yymsp[-1].minor.yy289.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy289.pList = yymsp[0].minor.yy476; } +{ yymsp[-1].minor.yy21.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy21.pList = yymsp[0].minor.yy488; } break; case 164: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy289.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy289.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy21.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy21.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 167: /* col_name ::= column_name */ -{ yylhsminor.yy564 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy21); } - yymsp[0].minor.yy564 = yylhsminor.yy564; +{ yylhsminor.yy504 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy409); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 168: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL, NULL); } @@ -3545,13 +3148,13 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL, NULL); } break; case 171: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy564, yymsp[0].minor.yy564); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy504, yymsp[0].minor.yy504); } break; case 172: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy564, yymsp[0].minor.yy564); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy504, yymsp[0].minor.yy504); } break; case 173: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy564, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy504, NULL); } break; case 174: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL, NULL); } @@ -3566,7 +3169,7 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT, NULL, NULL); } break; case 178: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy564, yymsp[0].minor.yy564); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy504, yymsp[0].minor.yy504); } break; case 179: /* cmd ::= SHOW STREAMS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); } @@ -3575,650 +3178,648 @@ static YYACTIONTYPE yy_reduce( { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } break; case 181: /* cmd ::= SHOW APPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); } +// { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); } break; case 182: /* cmd ::= SHOW CONNECTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT, NULL, NULL); } break; case 183: /* cmd ::= SHOW LICENCE */ + case 184: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==184); { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); } break; - case 184: /* cmd ::= SHOW CREATE DATABASE db_name */ -{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy21); } + case 185: /* cmd ::= SHOW CREATE DATABASE db_name */ +// { pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy29); } break; - case 185: /* cmd ::= SHOW CREATE TABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy564); } + case 186: /* cmd ::= SHOW CREATE TABLE full_table_name */ +// { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy182); } break; - case 186: /* cmd ::= SHOW CREATE STABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy564); } + case 187: /* cmd ::= SHOW CREATE STABLE full_table_name */ +// { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy182); } break; - case 187: /* cmd ::= SHOW QUERIES */ + case 188: /* cmd ::= SHOW QUERIES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT, NULL, NULL); } break; - case 188: /* cmd ::= SHOW SCORES */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT, NULL, NULL); } + case 189: /* cmd ::= SHOW SCORES */ +// { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT, NULL, NULL); } break; - case 189: /* cmd ::= SHOW TOPICS */ + case 190: /* cmd ::= SHOW TOPICS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT, NULL, NULL); } break; - case 190: /* cmd ::= SHOW VARIABLES */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLE_STMT, NULL, NULL); } + case 191: /* cmd ::= SHOW VARIABLES */ +// { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLE_STMT, NULL, NULL); } break; - case 191: /* cmd ::= SHOW BNODES */ + case 192: /* cmd ::= SHOW BNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT, NULL, NULL); } break; - case 192: /* cmd ::= SHOW SNODES */ + case 193: /* cmd ::= SHOW SNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT, NULL, NULL); } break; - case 193: /* db_name_cond_opt ::= */ - case 198: /* from_db_opt ::= */ yytestcase(yyruleno==198); -{ yymsp[1].minor.yy564 = createDefaultDatabaseCondValue(pCxt); } + case 194: /* db_name_cond_opt ::= */ + case 199: /* from_db_opt ::= */ yytestcase(yyruleno==199); +{ yymsp[1].minor.yy504 = createDefaultDatabaseCondValue(pCxt); } break; - case 194: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy21); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + case 195: /* db_name_cond_opt ::= db_name NK_DOT */ +{ yylhsminor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy409); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; - case 195: /* like_pattern_opt ::= */ - case 206: /* index_options ::= */ yytestcase(yyruleno==206); - case 359: /* where_clause_opt ::= */ yytestcase(yyruleno==359); - case 363: /* twindow_clause_opt ::= */ yytestcase(yyruleno==363); - case 368: /* sliding_opt ::= */ yytestcase(yyruleno==368); - case 370: /* fill_opt ::= */ yytestcase(yyruleno==370); - case 382: /* having_clause_opt ::= */ yytestcase(yyruleno==382); - case 390: /* slimit_clause_opt ::= */ yytestcase(yyruleno==390); - case 394: /* limit_clause_opt ::= */ yytestcase(yyruleno==394); -{ yymsp[1].minor.yy564 = NULL; } + case 196: /* like_pattern_opt ::= */ + case 207: /* index_options ::= */ yytestcase(yyruleno==207); + case 361: /* where_clause_opt ::= */ yytestcase(yyruleno==361); + case 365: /* twindow_clause_opt ::= */ yytestcase(yyruleno==365); + case 370: /* sliding_opt ::= */ yytestcase(yyruleno==370); + case 372: /* fill_opt ::= */ yytestcase(yyruleno==372); + case 384: /* having_clause_opt ::= */ yytestcase(yyruleno==384); + case 392: /* slimit_clause_opt ::= */ yytestcase(yyruleno==392); + case 396: /* limit_clause_opt ::= */ yytestcase(yyruleno==396); +{ yymsp[1].minor.yy504 = NULL; } break; - case 196: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + case 197: /* like_pattern_opt ::= LIKE NK_STRING */ +{ yymsp[-1].minor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; - case 197: /* table_name_cond ::= table_name */ -{ yylhsminor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy21); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 198: /* table_name_cond ::= table_name */ +{ yylhsminor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy409); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; - case 199: /* from_db_opt ::= FROM db_name */ -{ yymsp[-1].minor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy21); } + case 200: /* from_db_opt ::= FROM db_name */ +{ yymsp[-1].minor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy409); } break; - case 202: /* func_name ::= function_name */ -{ yylhsminor.yy564 = createFunctionNode(pCxt, &yymsp[0].minor.yy21, NULL); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 203: /* func_name ::= function_name */ +{ yylhsminor.yy504 = createFunctionNode(pCxt, &yymsp[0].minor.yy409, NULL); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; - case 203: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy173, &yymsp[-3].minor.yy21, &yymsp[-1].minor.yy21, NULL, yymsp[0].minor.yy564); } + case 204: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy121, &yymsp[-3].minor.yy409, &yymsp[-1].minor.yy409, NULL, yymsp[0].minor.yy504); } break; - case 204: /* cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy173, &yymsp[-5].minor.yy21, &yymsp[-3].minor.yy21, yymsp[-1].minor.yy476, NULL); } + case 205: /* cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy121, &yymsp[-5].minor.yy409, &yymsp[-3].minor.yy409, yymsp[-1].minor.yy488, NULL); } break; - case 205: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy173, &yymsp[-2].minor.yy21, &yymsp[0].minor.yy21); } + case 206: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ +{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy121, &yymsp[-2].minor.yy409, &yymsp[0].minor.yy409); } break; - case 207: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ -{ yymsp[-8].minor.yy564 = createIndexOption(pCxt, yymsp[-6].minor.yy476, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), NULL, yymsp[0].minor.yy564); } + case 208: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ +{ yymsp[-8].minor.yy504 = createIndexOption(pCxt, yymsp[-6].minor.yy488, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), NULL, yymsp[0].minor.yy504); } break; - case 208: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ -{ yymsp[-10].minor.yy564 = createIndexOption(pCxt, yymsp[-8].minor.yy476, releaseRawExprNode(pCxt, yymsp[-4].minor.yy564), releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), yymsp[0].minor.yy564); } + case 209: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ +{ yymsp[-10].minor.yy504 = createIndexOption(pCxt, yymsp[-8].minor.yy488, releaseRawExprNode(pCxt, yymsp[-4].minor.yy504), releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), yymsp[0].minor.yy504); } break; - case 211: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy564 = createFunctionNode(pCxt, &yymsp[-3].minor.yy21, yymsp[-1].minor.yy476); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; + case 212: /* func ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy504 = createFunctionNode(pCxt, &yymsp[-3].minor.yy409, yymsp[-1].minor.yy488); } + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; - case 212: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy173, &yymsp[-2].minor.yy21, yymsp[0].minor.yy564, NULL); } + case 213: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy121, &yymsp[-2].minor.yy409, yymsp[0].minor.yy504, NULL); } break; - case 213: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy173, &yymsp[-2].minor.yy21, NULL, &yymsp[0].minor.yy21); } + case 214: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy121, &yymsp[-2].minor.yy409, NULL, &yymsp[0].minor.yy409); } break; - case 214: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy173, &yymsp[0].minor.yy21); } + case 215: /* cmd ::= DROP TOPIC exists_opt topic_name */ +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy121, &yymsp[0].minor.yy409); } break; - case 215: /* cmd ::= DESC full_table_name */ - case 216: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==216); -{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy564); } + case 216: /* cmd ::= DESC full_table_name */ + case 217: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==217); +{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy504); } break; - case 217: /* cmd ::= RESET QUERY CACHE */ + case 218: /* cmd ::= RESET QUERY CACHE */ { pCxt->pRootNode = createResetQueryCacheStmt(pCxt); } break; - case 218: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ -{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy173, yymsp[-1].minor.yy564, yymsp[0].minor.yy564); } + case 219: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ +{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy121, yymsp[-1].minor.yy504, yymsp[0].minor.yy504); } break; - case 220: /* analyze_opt ::= ANALYZE */ - case 228: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==228); - case 349: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==349); -{ yymsp[0].minor.yy173 = true; } + case 221: /* analyze_opt ::= ANALYZE */ + case 229: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==229); + case 351: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==351); +{ yymsp[0].minor.yy121 = true; } break; - case 221: /* explain_options ::= */ -{ yymsp[1].minor.yy564 = createDefaultExplainOptions(pCxt); } + case 222: /* explain_options ::= */ +{ yymsp[1].minor.yy504 = createDefaultExplainOptions(pCxt); } break; - case 222: /* explain_options ::= explain_options VERBOSE NK_BOOL */ -{ yylhsminor.yy564 = setExplainVerbose(pCxt, yymsp[-2].minor.yy564, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 223: /* explain_options ::= explain_options VERBOSE NK_BOOL */ +{ yylhsminor.yy504 = setExplainVerbose(pCxt, yymsp[-2].minor.yy504, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 223: /* explain_options ::= explain_options RATIO NK_FLOAT */ -{ yylhsminor.yy564 = setExplainRatio(pCxt, yymsp[-2].minor.yy564, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 224: /* explain_options ::= explain_options RATIO NK_FLOAT */ +{ yylhsminor.yy504 = setExplainRatio(pCxt, yymsp[-2].minor.yy504, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 224: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ -{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy476); } + case 225: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ +{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy488); } break; - case 225: /* cmd ::= CREATE agg_func_opt FUNCTION function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ -{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-7].minor.yy173, &yymsp[-5].minor.yy21, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy288, yymsp[0].minor.yy620); } + case 226: /* cmd ::= CREATE agg_func_opt FUNCTION function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ +{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-7].minor.yy121, &yymsp[-5].minor.yy409, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy160, yymsp[0].minor.yy452); } break; - case 226: /* cmd ::= DROP FUNCTION function_name */ -{ pCxt->pRootNode = createDropFunctionStmt(pCxt, &yymsp[0].minor.yy21); } + case 227: /* cmd ::= DROP FUNCTION function_name */ +{ pCxt->pRootNode = createDropFunctionStmt(pCxt, &yymsp[0].minor.yy409); } break; - case 229: /* bufsize_opt ::= */ -{ yymsp[1].minor.yy620 = 0; } + case 230: /* bufsize_opt ::= */ +{ yymsp[1].minor.yy452 = 0; } break; - case 230: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ -{ yymsp[-1].minor.yy620 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 231: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ +{ yymsp[-1].minor.yy452 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 231: /* cmd ::= CREATE STREAM stream_name INTO table_name AS query_expression */ -{ pCxt->pRootNode = createCreateStreamStmt(pCxt, &yymsp[-4].minor.yy21, &yymsp[-2].minor.yy21, yymsp[0].minor.yy564); } + case 232: /* cmd ::= CREATE STREAM stream_name INTO table_name AS query_expression */ +{ pCxt->pRootNode = createCreateStreamStmt(pCxt, &yymsp[-4].minor.yy409, &yymsp[-2].minor.yy409, yymsp[0].minor.yy504); } break; - case 232: /* cmd ::= DROP STREAM stream_name */ -{ pCxt->pRootNode = createDropStreamStmt(pCxt, &yymsp[0].minor.yy21); } + case 233: /* cmd ::= DROP STREAM stream_name */ +{ pCxt->pRootNode = createDropStreamStmt(pCxt, &yymsp[0].minor.yy409); } break; - case 233: /* cmd ::= KILL CONNECTION NK_INTEGER */ + case 234: /* cmd ::= KILL CONNECTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &yymsp[0].minor.yy0); } break; - case 234: /* cmd ::= KILL QUERY NK_INTEGER */ + case 235: /* cmd ::= KILL QUERY NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_QUERY_STMT, &yymsp[0].minor.yy0); } break; - case 235: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + case 236: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 236: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ -{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy476); } + case 237: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ +{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy488); } break; - case 237: /* cmd ::= SPLIT VGROUP NK_INTEGER */ + case 238: /* cmd ::= SPLIT VGROUP NK_INTEGER */ { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 238: /* dnode_list ::= DNODE NK_INTEGER */ -{ yymsp[-1].minor.yy476 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - break; - case 240: /* cmd ::= SYNCDB db_name REPLICA */ -{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy21); } - break; - case 242: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy564 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy564 = yylhsminor.yy564; - break; - case 243: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy564 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy564 = yylhsminor.yy564; - break; - case 244: /* literal ::= NK_STRING */ -{ yylhsminor.yy564 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy564 = yylhsminor.yy564; - break; - case 245: /* literal ::= NK_BOOL */ -{ yylhsminor.yy564 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy564 = yylhsminor.yy564; - break; - case 246: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; - break; - case 247: /* literal ::= duration_literal */ - case 256: /* signed_literal ::= signed */ yytestcase(yyruleno==256); - case 276: /* expression ::= literal */ yytestcase(yyruleno==276); - case 277: /* expression ::= pseudo_column */ yytestcase(yyruleno==277); - case 278: /* expression ::= column_reference */ yytestcase(yyruleno==278); - case 282: /* expression ::= subquery */ yytestcase(yyruleno==282); - case 322: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==322); - case 326: /* boolean_primary ::= predicate */ yytestcase(yyruleno==326); - case 328: /* common_expression ::= expression */ yytestcase(yyruleno==328); - case 329: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==329); - case 331: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==331); - case 333: /* table_reference ::= table_primary */ yytestcase(yyruleno==333); - case 334: /* table_reference ::= joined_table */ yytestcase(yyruleno==334); - case 338: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==338); - case 385: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==385); - case 387: /* query_primary ::= query_specification */ yytestcase(yyruleno==387); -{ yylhsminor.yy564 = yymsp[0].minor.yy564; } - yymsp[0].minor.yy564 = yylhsminor.yy564; - break; - case 248: /* literal ::= NULL */ -{ yylhsminor.yy564 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL)); } - yymsp[0].minor.yy564 = yylhsminor.yy564; - break; - case 249: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy564 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy564 = yylhsminor.yy564; - break; - case 250: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy564 = yylhsminor.yy564; - break; - case 251: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - break; - case 252: /* signed ::= NK_MINUS NK_INTEGER */ + case 239: /* dnode_list ::= DNODE NK_INTEGER */ +{ yymsp[-1].minor.yy488 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + break; + case 241: /* cmd ::= SYNCDB db_name REPLICA */ +{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy409); } + break; + case 243: /* literal ::= NK_INTEGER */ +{ yylhsminor.yy504 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy504 = yylhsminor.yy504; + break; + case 244: /* literal ::= NK_FLOAT */ +{ yylhsminor.yy504 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy504 = yylhsminor.yy504; + break; + case 245: /* literal ::= NK_STRING */ +{ yylhsminor.yy504 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy504 = yylhsminor.yy504; + break; + case 246: /* literal ::= NK_BOOL */ +{ yylhsminor.yy504 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy504 = yylhsminor.yy504; + break; + case 247: /* literal ::= TIMESTAMP NK_STRING */ +{ yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; + break; + case 248: /* literal ::= duration_literal */ + case 257: /* signed_literal ::= signed */ yytestcase(yyruleno==257); + case 277: /* expression ::= literal */ yytestcase(yyruleno==277); + case 278: /* expression ::= pseudo_column */ yytestcase(yyruleno==278); + case 279: /* expression ::= column_reference */ yytestcase(yyruleno==279); + case 283: /* expression ::= subquery */ yytestcase(yyruleno==283); + case 324: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==324); + case 328: /* boolean_primary ::= predicate */ yytestcase(yyruleno==328); + case 330: /* common_expression ::= expression */ yytestcase(yyruleno==330); + case 331: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==331); + case 333: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==333); + case 335: /* table_reference ::= table_primary */ yytestcase(yyruleno==335); + case 336: /* table_reference ::= joined_table */ yytestcase(yyruleno==336); + case 340: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==340); + case 387: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==387); + case 389: /* query_primary ::= query_specification */ yytestcase(yyruleno==389); +{ yylhsminor.yy504 = yymsp[0].minor.yy504; } + yymsp[0].minor.yy504 = yylhsminor.yy504; + break; + case 249: /* literal ::= NULL */ +{ yylhsminor.yy504 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL)); } + yymsp[0].minor.yy504 = yylhsminor.yy504; + break; + case 250: /* duration_literal ::= NK_VARIABLE */ +{ yylhsminor.yy504 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy504 = yylhsminor.yy504; + break; + case 251: /* signed ::= NK_INTEGER */ +{ yylhsminor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy504 = yylhsminor.yy504; + break; + case 252: /* signed ::= NK_PLUS NK_INTEGER */ +{ yymsp[-1].minor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + break; + case 253: /* signed ::= NK_MINUS NK_INTEGER */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; - case 253: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 254: /* signed ::= NK_FLOAT */ +{ yylhsminor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; - case 254: /* signed ::= NK_PLUS NK_FLOAT */ -{ yymsp[-1].minor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + case 255: /* signed ::= NK_PLUS NK_FLOAT */ +{ yymsp[-1].minor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; - case 255: /* signed ::= NK_MINUS NK_FLOAT */ + case 256: /* signed ::= NK_MINUS NK_FLOAT */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; - case 257: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 258: /* signed_literal ::= NK_STRING */ +{ yylhsminor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; - case 258: /* signed_literal ::= NK_BOOL */ -{ yylhsminor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 259: /* signed_literal ::= NK_BOOL */ +{ yylhsminor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; - case 259: /* signed_literal ::= TIMESTAMP NK_STRING */ -{ yymsp[-1].minor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } + case 260: /* signed_literal ::= TIMESTAMP NK_STRING */ +{ yymsp[-1].minor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; - case 260: /* signed_literal ::= duration_literal */ - case 355: /* select_item ::= common_expression */ yytestcase(yyruleno==355); - case 399: /* search_condition ::= common_expression */ yytestcase(yyruleno==399); -{ yylhsminor.yy564 = releaseRawExprNode(pCxt, yymsp[0].minor.yy564); } - yymsp[0].minor.yy564 = yylhsminor.yy564; + case 261: /* signed_literal ::= duration_literal */ + case 357: /* select_item ::= common_expression */ yytestcase(yyruleno==357); + case 401: /* search_condition ::= common_expression */ yytestcase(yyruleno==401); +{ yylhsminor.yy504 = releaseRawExprNode(pCxt, yymsp[0].minor.yy504); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; - case 261: /* signed_literal ::= NULL */ -{ yymsp[0].minor.yy564 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } + case 262: /* signed_literal ::= NULL */ +{ yymsp[0].minor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } break; - case 279: /* expression ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy21, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy21, yymsp[-1].minor.yy476)); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; + case 280: /* expression ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy409, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy409, yymsp[-1].minor.yy488)); } + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; - case 280: /* expression ::= function_name NK_LP NK_STAR NK_RP */ -{ yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy21, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy21, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; + case 281: /* expression ::= function_name NK_LP NK_STAR NK_RP */ +{ yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy409, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy409, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; - case 281: /* expression ::= function_name NK_LP expression AS type_name NK_RP */ -{ - SNodeList *p = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy564)); - p = addValueNodeFromTypeToList(pCxt, yymsp[-1].minor.yy288, p); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy21, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-5].minor.yy21, p)); - } - yymsp[-5].minor.yy564 = yylhsminor.yy564; + case 282: /* expression ::= CAST NK_LP expression AS type_name NK_RP */ +{ yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy504), yymsp[-1].minor.yy160)); } + yymsp[-5].minor.yy504 = yylhsminor.yy504; break; - case 283: /* expression ::= NK_LP expression NK_RP */ - case 327: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==327); -{ yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy564)); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 284: /* expression ::= NK_LP expression NK_RP */ + case 329: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==329); +{ yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy504)); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 284: /* expression ::= NK_PLUS expression */ + case 285: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy564)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy504)); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; - case 285: /* expression ::= NK_MINUS expression */ + case 286: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy564), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy504), NULL)); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; - case 286: /* expression ::= expression NK_PLUS expression */ + case 287: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 287: /* expression ::= expression NK_MINUS expression */ + case 288: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 288: /* expression ::= expression NK_STAR expression */ + case 289: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 289: /* expression ::= expression NK_SLASH expression */ + case 290: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 290: /* expression ::= expression NK_REM expression */ + case 291: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; - break; - case 291: /* expression_list ::= expression */ -{ yylhsminor.yy476 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy564)); } - yymsp[0].minor.yy476 = yylhsminor.yy476; - break; - case 292: /* expression_list ::= expression_list NK_COMMA expression */ -{ yylhsminor.yy476 = addNodeToList(pCxt, yymsp[-2].minor.yy476, releaseRawExprNode(pCxt, yymsp[0].minor.yy564)); } - yymsp[-2].minor.yy476 = yylhsminor.yy476; - break; - case 293: /* column_reference ::= column_name */ -{ yylhsminor.yy564 = createRawExprNode(pCxt, &yymsp[0].minor.yy21, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy21)); } - yymsp[0].minor.yy564 = yylhsminor.yy564; - break; - case 294: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy21, &yymsp[0].minor.yy21, createColumnNode(pCxt, &yymsp[-2].minor.yy21, &yymsp[0].minor.yy21)); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; - break; - case 295: /* pseudo_column ::= NOW */ - case 296: /* pseudo_column ::= ROWTS */ yytestcase(yyruleno==296); - case 297: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==297); - case 298: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==298); - case 299: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==299); - case 300: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==300); - case 301: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==301); - case 302: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==302); -{ yylhsminor.yy564 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } - yymsp[0].minor.yy564 = yylhsminor.yy564; - break; - case 303: /* predicate ::= expression compare_op expression */ - case 308: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==308); + yymsp[-2].minor.yy504 = yylhsminor.yy504; + break; + case 292: /* expression_list ::= expression */ +{ yylhsminor.yy488 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy504)); } + yymsp[0].minor.yy488 = yylhsminor.yy488; + break; + case 293: /* expression_list ::= expression_list NK_COMMA expression */ +{ yylhsminor.yy488 = addNodeToList(pCxt, yymsp[-2].minor.yy488, releaseRawExprNode(pCxt, yymsp[0].minor.yy504)); } + yymsp[-2].minor.yy488 = yylhsminor.yy488; + break; + case 294: /* column_reference ::= column_name */ +{ yylhsminor.yy504 = createRawExprNode(pCxt, &yymsp[0].minor.yy409, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy409)); } + yymsp[0].minor.yy504 = yylhsminor.yy504; + break; + case 295: /* column_reference ::= table_name NK_DOT column_name */ +{ yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy409, &yymsp[0].minor.yy409, createColumnNode(pCxt, &yymsp[-2].minor.yy409, &yymsp[0].minor.yy409)); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; + break; + case 296: /* pseudo_column ::= NOW */ + case 297: /* pseudo_column ::= TODAY */ yytestcase(yyruleno==297); + case 298: /* pseudo_column ::= ROWTS */ yytestcase(yyruleno==298); + case 299: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==299); + case 300: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==300); + case 301: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==301); + case 302: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==302); + case 303: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==303); + case 304: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==304); +{ yylhsminor.yy504 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } + yymsp[0].minor.yy504 = yylhsminor.yy504; + break; + case 305: /* predicate ::= expression compare_op expression */ + case 310: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==310); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy468, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy84, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 304: /* predicate ::= expression BETWEEN expression AND expression */ + case 306: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy564), releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy504), releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-4].minor.yy564 = yylhsminor.yy564; + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; - case 305: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 307: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[-5].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[-5].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-5].minor.yy564 = yylhsminor.yy564; + yymsp[-5].minor.yy504 = yylhsminor.yy504; break; - case 306: /* predicate ::= expression IS NULL */ + case 308: /* predicate ::= expression IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), NULL)); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 307: /* predicate ::= expression IS NOT NULL */ + case 309: /* predicate ::= expression IS NOT NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy564), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy504), NULL)); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; - case 309: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy468 = OP_TYPE_LOWER_THAN; } + case 311: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy84 = OP_TYPE_LOWER_THAN; } break; - case 310: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy468 = OP_TYPE_GREATER_THAN; } + case 312: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy84 = OP_TYPE_GREATER_THAN; } break; - case 311: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy468 = OP_TYPE_LOWER_EQUAL; } + case 313: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy84 = OP_TYPE_LOWER_EQUAL; } break; - case 312: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy468 = OP_TYPE_GREATER_EQUAL; } + case 314: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy84 = OP_TYPE_GREATER_EQUAL; } break; - case 313: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy468 = OP_TYPE_NOT_EQUAL; } + case 315: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy84 = OP_TYPE_NOT_EQUAL; } break; - case 314: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy468 = OP_TYPE_EQUAL; } + case 316: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy84 = OP_TYPE_EQUAL; } break; - case 315: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy468 = OP_TYPE_LIKE; } + case 317: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy84 = OP_TYPE_LIKE; } break; - case 316: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy468 = OP_TYPE_NOT_LIKE; } + case 318: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy84 = OP_TYPE_NOT_LIKE; } break; - case 317: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy468 = OP_TYPE_MATCH; } + case 319: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy84 = OP_TYPE_MATCH; } break; - case 318: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy468 = OP_TYPE_NMATCH; } + case 320: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy84 = OP_TYPE_NMATCH; } break; - case 319: /* in_op ::= IN */ -{ yymsp[0].minor.yy468 = OP_TYPE_IN; } + case 321: /* in_op ::= IN */ +{ yymsp[0].minor.yy84 = OP_TYPE_IN; } break; - case 320: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy468 = OP_TYPE_NOT_IN; } + case 322: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy84 = OP_TYPE_NOT_IN; } break; - case 321: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy476)); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 323: /* in_predicate_value ::= NK_LP expression_list NK_RP */ +{ yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy488)); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 323: /* boolean_value_expression ::= NOT boolean_primary */ + case 325: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy564), NULL)); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy504), NULL)); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; - case 324: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 326: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 325: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 327: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy564); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy564); - yylhsminor.yy564 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 330: /* from_clause ::= FROM table_reference_list */ - case 360: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==360); - case 383: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==383); -{ yymsp[-1].minor.yy564 = yymsp[0].minor.yy564; } + case 332: /* from_clause ::= FROM table_reference_list */ + case 362: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==362); + case 385: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==385); +{ yymsp[-1].minor.yy504 = yymsp[0].minor.yy504; } break; - case 332: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy564 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy564, yymsp[0].minor.yy564, NULL); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 334: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy504 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy504, yymsp[0].minor.yy504, NULL); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 335: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy564 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy21, &yymsp[0].minor.yy21); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + case 337: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy504 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy409, &yymsp[0].minor.yy409); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; - case 336: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy564 = createRealTableNode(pCxt, &yymsp[-3].minor.yy21, &yymsp[-1].minor.yy21, &yymsp[0].minor.yy21); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; + case 338: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy504 = createRealTableNode(pCxt, &yymsp[-3].minor.yy409, &yymsp[-1].minor.yy409, &yymsp[0].minor.yy409); } + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; - case 337: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy564 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy564), &yymsp[0].minor.yy21); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + case 339: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy504 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy504), &yymsp[0].minor.yy409); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; - case 339: /* alias_opt ::= */ -{ yymsp[1].minor.yy21 = nil_token; } + case 341: /* alias_opt ::= */ +{ yymsp[1].minor.yy409 = nil_token; } break; - case 340: /* alias_opt ::= table_alias */ -{ yylhsminor.yy21 = yymsp[0].minor.yy21; } - yymsp[0].minor.yy21 = yylhsminor.yy21; + case 342: /* alias_opt ::= table_alias */ +{ yylhsminor.yy409 = yymsp[0].minor.yy409; } + yymsp[0].minor.yy409 = yylhsminor.yy409; break; - case 341: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy21 = yymsp[0].minor.yy21; } + case 343: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy409 = yymsp[0].minor.yy409; } break; - case 342: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 343: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==343); -{ yymsp[-2].minor.yy564 = yymsp[-1].minor.yy564; } + case 344: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 345: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==345); +{ yymsp[-2].minor.yy504 = yymsp[-1].minor.yy504; } break; - case 344: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy564 = createJoinTableNode(pCxt, yymsp[-4].minor.yy440, yymsp[-5].minor.yy564, yymsp[-2].minor.yy564, yymsp[0].minor.yy564); } - yymsp[-5].minor.yy564 = yylhsminor.yy564; + case 346: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy504 = createJoinTableNode(pCxt, yymsp[-4].minor.yy556, yymsp[-5].minor.yy504, yymsp[-2].minor.yy504, yymsp[0].minor.yy504); } + yymsp[-5].minor.yy504 = yylhsminor.yy504; break; - case 345: /* join_type ::= */ -{ yymsp[1].minor.yy440 = JOIN_TYPE_INNER; } + case 347: /* join_type ::= */ +{ yymsp[1].minor.yy556 = JOIN_TYPE_INNER; } break; - case 346: /* join_type ::= INNER */ -{ yymsp[0].minor.yy440 = JOIN_TYPE_INNER; } + case 348: /* join_type ::= INNER */ +{ yymsp[0].minor.yy556 = JOIN_TYPE_INNER; } break; - case 347: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + case 349: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause where_clause_opt partition_by_clause_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ { - yymsp[-8].minor.yy564 = createSelectStmt(pCxt, yymsp[-7].minor.yy173, yymsp[-6].minor.yy476, yymsp[-5].minor.yy564); - yymsp[-8].minor.yy564 = addWhereClause(pCxt, yymsp[-8].minor.yy564, yymsp[-4].minor.yy564); - yymsp[-8].minor.yy564 = addPartitionByClause(pCxt, yymsp[-8].minor.yy564, yymsp[-3].minor.yy476); - yymsp[-8].minor.yy564 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy564, yymsp[-2].minor.yy564); - yymsp[-8].minor.yy564 = addGroupByClause(pCxt, yymsp[-8].minor.yy564, yymsp[-1].minor.yy476); - yymsp[-8].minor.yy564 = addHavingClause(pCxt, yymsp[-8].minor.yy564, yymsp[0].minor.yy564); + yymsp[-8].minor.yy504 = createSelectStmt(pCxt, yymsp[-7].minor.yy121, yymsp[-6].minor.yy488, yymsp[-5].minor.yy504); + yymsp[-8].minor.yy504 = addWhereClause(pCxt, yymsp[-8].minor.yy504, yymsp[-4].minor.yy504); + yymsp[-8].minor.yy504 = addPartitionByClause(pCxt, yymsp[-8].minor.yy504, yymsp[-3].minor.yy488); + yymsp[-8].minor.yy504 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy504, yymsp[-2].minor.yy504); + yymsp[-8].minor.yy504 = addGroupByClause(pCxt, yymsp[-8].minor.yy504, yymsp[-1].minor.yy488); + yymsp[-8].minor.yy504 = addHavingClause(pCxt, yymsp[-8].minor.yy504, yymsp[0].minor.yy504); } break; - case 350: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy173 = false; } + case 352: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy121 = false; } break; - case 351: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy476 = NULL; } + case 353: /* select_list ::= NK_STAR */ +{ yymsp[0].minor.yy488 = NULL; } break; - case 356: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy564 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy564), &yymsp[0].minor.yy21); } - yymsp[-1].minor.yy564 = yylhsminor.yy564; + case 358: /* select_item ::= common_expression column_alias */ +{ yylhsminor.yy504 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy504), &yymsp[0].minor.yy409); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; - case 357: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy564 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), &yymsp[0].minor.yy21); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 359: /* select_item ::= common_expression AS column_alias */ +{ yylhsminor.yy504 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), &yymsp[0].minor.yy409); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 358: /* select_item ::= table_name NK_DOT NK_STAR */ -{ yylhsminor.yy564 = createColumnNode(pCxt, &yymsp[-2].minor.yy21, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 360: /* select_item ::= table_name NK_DOT NK_STAR */ +{ yylhsminor.yy504 = createColumnNode(pCxt, &yymsp[-2].minor.yy409, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 362: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 379: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==379); - case 389: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==389); -{ yymsp[-2].minor.yy476 = yymsp[0].minor.yy476; } + case 364: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 381: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==381); + case 391: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==391); +{ yymsp[-2].minor.yy488 = yymsp[0].minor.yy488; } break; - case 364: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -{ yymsp[-5].minor.yy564 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy564), releaseRawExprNode(pCxt, yymsp[-1].minor.yy564)); } + case 366: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ +{ yymsp[-5].minor.yy504 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy504), releaseRawExprNode(pCxt, yymsp[-1].minor.yy504)); } break; - case 365: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ -{ yymsp[-3].minor.yy564 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy564)); } + case 367: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ +{ yymsp[-3].minor.yy504 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy504)); } break; - case 366: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy564 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy564), NULL, yymsp[-1].minor.yy564, yymsp[0].minor.yy564); } + case 368: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy504 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy504), NULL, yymsp[-1].minor.yy504, yymsp[0].minor.yy504); } break; - case 367: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy564 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy564), releaseRawExprNode(pCxt, yymsp[-3].minor.yy564), yymsp[-1].minor.yy564, yymsp[0].minor.yy564); } + case 369: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy504 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy504), releaseRawExprNode(pCxt, yymsp[-3].minor.yy504), yymsp[-1].minor.yy504, yymsp[0].minor.yy504); } break; - case 369: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ -{ yymsp[-3].minor.yy564 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy564); } + case 371: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ +{ yymsp[-3].minor.yy504 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy504); } break; - case 371: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy564 = createFillNode(pCxt, yymsp[-1].minor.yy268, NULL); } + case 373: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy504 = createFillNode(pCxt, yymsp[-1].minor.yy22, NULL); } break; - case 372: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy564 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy476)); } + case 374: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy504 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy488)); } break; - case 373: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy268 = FILL_MODE_NONE; } + case 375: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy22 = FILL_MODE_NONE; } break; - case 374: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy268 = FILL_MODE_PREV; } + case 376: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy22 = FILL_MODE_PREV; } break; - case 375: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy268 = FILL_MODE_NULL; } + case 377: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy22 = FILL_MODE_NULL; } break; - case 376: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy268 = FILL_MODE_LINEAR; } + case 378: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy22 = FILL_MODE_LINEAR; } break; - case 377: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy268 = FILL_MODE_NEXT; } + case 379: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy22 = FILL_MODE_NEXT; } break; - case 380: /* group_by_list ::= expression */ -{ yylhsminor.yy476 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); } - yymsp[0].minor.yy476 = yylhsminor.yy476; + case 382: /* group_by_list ::= expression */ +{ yylhsminor.yy488 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } + yymsp[0].minor.yy488 = yylhsminor.yy488; break; - case 381: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy476 = addNodeToList(pCxt, yymsp[-2].minor.yy476, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy564))); } - yymsp[-2].minor.yy476 = yylhsminor.yy476; + case 383: /* group_by_list ::= group_by_list NK_COMMA expression */ +{ yylhsminor.yy488 = addNodeToList(pCxt, yymsp[-2].minor.yy488, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } + yymsp[-2].minor.yy488 = yylhsminor.yy488; break; - case 384: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 386: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy564 = addOrderByClause(pCxt, yymsp[-3].minor.yy564, yymsp[-2].minor.yy476); - yylhsminor.yy564 = addSlimitClause(pCxt, yylhsminor.yy564, yymsp[-1].minor.yy564); - yylhsminor.yy564 = addLimitClause(pCxt, yylhsminor.yy564, yymsp[0].minor.yy564); + yylhsminor.yy504 = addOrderByClause(pCxt, yymsp[-3].minor.yy504, yymsp[-2].minor.yy488); + yylhsminor.yy504 = addSlimitClause(pCxt, yylhsminor.yy504, yymsp[-1].minor.yy504); + yylhsminor.yy504 = addLimitClause(pCxt, yylhsminor.yy504, yymsp[0].minor.yy504); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; - case 386: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy564 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy564, yymsp[0].minor.yy564); } - yymsp[-3].minor.yy564 = yylhsminor.yy564; + case 388: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ +{ yylhsminor.yy504 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy504, yymsp[0].minor.yy504); } + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; - case 391: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 395: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==395); -{ yymsp[-1].minor.yy564 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 393: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 397: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==397); +{ yymsp[-1].minor.yy504 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 392: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 396: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==396); -{ yymsp[-3].minor.yy564 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 394: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 398: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==398); +{ yymsp[-3].minor.yy504 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 393: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 397: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==397); -{ yymsp[-3].minor.yy564 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 395: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 399: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==399); +{ yymsp[-3].minor.yy504 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 398: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy564 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy564); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 400: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy504); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 402: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy564 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy564), yymsp[-1].minor.yy256, yymsp[0].minor.yy525); } - yymsp[-2].minor.yy564 = yylhsminor.yy564; + case 404: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy504 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), yymsp[-1].minor.yy522, yymsp[0].minor.yy281); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; - case 403: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy256 = ORDER_ASC; } + case 405: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy522 = ORDER_ASC; } break; - case 404: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy256 = ORDER_ASC; } + case 406: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy522 = ORDER_ASC; } break; - case 405: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy256 = ORDER_DESC; } + case 407: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy522 = ORDER_DESC; } break; - case 406: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy525 = NULL_ORDER_DEFAULT; } + case 408: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy281 = NULL_ORDER_DEFAULT; } break; - case 407: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy525 = NULL_ORDER_FIRST; } + case 409: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy281 = NULL_ORDER_FIRST; } break; - case 408: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy525 = NULL_ORDER_LAST; } + case 410: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy281 = NULL_ORDER_LAST; } break; default: break; /********** End reduce actions ************************************************/ }; - assert( yyrulenoschema = table.release(); meta_[db][tbname]->schema->uid = id_++; + meta_[db][tbname]->schema->tableType = TSDB_CHILD_TABLE; SVgroupInfo vgroup = {.vgId = vgid, .hashBegin = 0, .hashEnd = 0,}; addEpIntoEpSet(&vgroup.epSet, "dnode_1", 6030); @@ -197,11 +198,11 @@ public: std::cout << "Table:" << table.first << std::endl; std::cout << SH("Field") << SH("Type") << SH("DataType") << IH("Bytes") << std::endl; std::cout << SL(3, 1) << std::endl; - int16_t numOfTags = schema->tableInfo.numOfTags; - int16_t numOfFields = numOfTags + schema->tableInfo.numOfColumns; + int16_t numOfColumns = schema->tableInfo.numOfColumns; + int16_t numOfFields = numOfColumns + schema->tableInfo.numOfTags; for (int16_t i = 0; i < numOfFields; ++i) { const SSchema* col = schema->schema + i; - std::cout << SF(std::string(col->name)) << SH(ftToString(i, numOfTags)) << SH(dtToString(col->type)) << IF(col->bytes) << std::endl; + std::cout << SF(std::string(col->name)) << SH(ftToString(i, numOfColumns)) << SH(dtToString(col->type)) << IF(col->bytes) << std::endl; } std::cout << std::endl; } @@ -262,8 +263,8 @@ private: return tDataTypes[type].name; } - std::string ftToString(int16_t colid, int16_t numOfTags) const { - return (0 == colid ? "column" : (colid <= numOfTags ? "tag" : "column")); + std::string ftToString(int16_t colid, int16_t numOfColumns) const { + return (0 == colid ? "column" : (colid <= numOfColumns ? "tag" : "column")); } STableMeta* getTableSchemaMeta(const std::string& db, const std::string& tbname) const { diff --git a/source/libs/parser/test/parserAstTest.cpp b/source/libs/parser/test/parserAstTest.cpp index d7e9b4a24dbe51e40f5f342521a1d525e206dac5..149c317bd4d8a1d6fd85fc9067fe12a141cdcc57 100644 --- a/source/libs/parser/test/parserAstTest.cpp +++ b/source/libs/parser/test/parserAstTest.cpp @@ -226,6 +226,16 @@ TEST_F(ParserTest, selectExpression) { ASSERT_TRUE(run()); } +TEST_F(ParserTest, selectCondition) { + setDatabase("root", "test"); + + bind("SELECT c1 FROM t1 where ts in (true, false)"); + ASSERT_TRUE(run()); + + bind("SELECT * FROM t1 where c1 > 10 and c1 is not null"); + ASSERT_TRUE(run()); +} + TEST_F(ParserTest, selectPseudoColumn) { setDatabase("root", "test"); diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 596bb64bac7e788acb5a6baf8b19522e78213abd..3c60b62434cc0e202771883cc8dc0d52249410be 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -200,6 +200,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect strcpy(pScan->tableName.tname, pRealTable->table.tableName); pScan->showRewrite = pCxt->pPlanCxt->showRewrite; pScan->ratio = pRealTable->ratio; + pScan->dataRequired = FUNC_DATA_REQUIRED_ALL_NEEDED; // set columns to scan SNodeList* pCols = NULL; @@ -488,6 +489,12 @@ static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindo pWindow->winType = WINDOW_TYPE_STATE; pWindow->pStateExpr = nodesCloneNode(pState->pExpr); + pWindow->pTspk = nodesCloneNode(pState->pCol); + if (NULL == pWindow->pTspk) { + nodesDestroyNode(pWindow); + return TSDB_CODE_OUT_OF_MEMORY; + } + return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode); } @@ -500,6 +507,12 @@ static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionW pWindow->winType = WINDOW_TYPE_SESSION; pWindow->sessionGap = ((SValueNode*)pSession->pGap)->datum.i; + pWindow->pTspk = nodesCloneNode(pSession->pCol); + if (NULL == pWindow->pTspk) { + nodesDestroyNode(pWindow); + return TSDB_CODE_OUT_OF_MEMORY; + } + return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode); } @@ -681,7 +694,6 @@ static int32_t createPartitionLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pS } return code; - return TSDB_CODE_SUCCESS; } static int32_t createDistinctLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) { diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 2a36e38ce1f7f84de807a4f2eeee1229fcdc41ec..19e6718fe8236149d3717f0e0f1344d83160c800 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -14,7 +14,439 @@ */ #include "planInt.h" +#include "functionMgt.h" + +#define OPTIMIZE_FLAG_MASK(n) (1 << n) + +#define OPTIMIZE_FLAG_OSD OPTIMIZE_FLAG_MASK(0) + +#define OPTIMIZE_FLAG_SET_MASK(val, mask) (val) |= (mask) +#define OPTIMIZE_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0) + +typedef struct SOptimizeContext { + bool optimized; +} SOptimizeContext; + +typedef int32_t (*FMatch)(SOptimizeContext* pCxt, SLogicNode* pLogicNode); +typedef int32_t (*FOptimize)(SOptimizeContext* pCxt, SLogicNode* pLogicNode); + +typedef struct SOptimizeRule { + char* pName; + FOptimize optimizeFunc; +} SOptimizeRule; + +typedef struct SOsdInfo { + SScanLogicNode* pScan; + SNodeList* pSdrFuncs; + SNodeList* pDsoFuncs; +} SOsdInfo; + +typedef struct SCpdIsMultiTableCondCxt { + SNodeList* pLeftCols; + SNodeList* pRightCols; + bool havaLeftCol; + bool haveRightCol; +} SCpdIsMultiTableCondCxt; + +typedef enum ECondAction { + COND_ACTION_STAY = 1, + COND_ACTION_PUSH_JOIN, + COND_ACTION_PUSH_LEFT_CHILD, + COND_ACTION_PUSH_RIGHT_CHILD + // after supporting outer join, there are other possibilities +} ECondAction; + +static bool osdMayBeOptimized(SLogicNode* pNode) { + if (OPTIMIZE_FLAG_TEST_MASK(pNode->optimizedFlag, OPTIMIZE_FLAG_OSD)) { + return false; + } + if (QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pNode)) { + return false; + } + if (NULL == pNode->pParent || + (QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && QUERY_NODE_LOGIC_PLAN_AGG == nodeType(pNode->pParent))) { + return false; + } + return true; +} + +static SLogicNode* osdFindPossibleScanNode(SLogicNode* pNode) { + if (osdMayBeOptimized(pNode)) { + return pNode; + } + SNode* pChild; + FOREACH(pChild, pNode->pChildren) { + SLogicNode* pScanNode = osdFindPossibleScanNode((SLogicNode*)pChild); + if (NULL != pScanNode) { + return pScanNode; + } + } + return NULL; +} + +static SNodeList* osdGetAllFuncs(SLogicNode* pNode) { + switch (nodeType(pNode)) { + case QUERY_NODE_LOGIC_PLAN_WINDOW: + return ((SWindowLogicNode*)pNode)->pFuncs; + case QUERY_NODE_LOGIC_PLAN_AGG: + return ((SAggLogicNode*)pNode)->pAggFuncs; + default: + break; + } + return NULL; +} + +static int32_t osdGetRelatedFuncs(SScanLogicNode* pScan, SNodeList** pSdrFuncs, SNodeList** pDsoFuncs) { + SNodeList* pAllFuncs = osdGetAllFuncs(pScan->node.pParent); + SNode* pFunc = NULL; + FOREACH(pFunc, pAllFuncs) { + int32_t code = TSDB_CODE_SUCCESS; + if (fmIsSpecialDataRequiredFunc(((SFunctionNode*)pFunc)->funcId)) { + code = nodesListMakeStrictAppend(pSdrFuncs, nodesCloneNode(pFunc)); + } else if (fmIsDynamicScanOptimizedFunc(((SFunctionNode*)pFunc)->funcId)) { + code = nodesListMakeStrictAppend(pDsoFuncs, nodesCloneNode(pFunc)); + } + if (TSDB_CODE_SUCCESS != code) { + nodesDestroyList(*pSdrFuncs); + nodesDestroyList(*pDsoFuncs); + return code; + } + } + return TSDB_CODE_SUCCESS; +} + +static int32_t osdMatch(SOptimizeContext* pCxt, SLogicNode* pLogicNode, SOsdInfo* pInfo) { + pInfo->pScan = (SScanLogicNode*)osdFindPossibleScanNode(pLogicNode); + if (NULL == pInfo->pScan) { + return TSDB_CODE_SUCCESS; + } + return osdGetRelatedFuncs(pInfo->pScan, &pInfo->pSdrFuncs, &pInfo->pDsoFuncs); +} + +static EFuncDataRequired osdPromoteDataRequired(EFuncDataRequired l , EFuncDataRequired r) { + switch (l) { + case FUNC_DATA_REQUIRED_ALL_NEEDED: + return l; + case FUNC_DATA_REQUIRED_STATIS_NEEDED: + return FUNC_DATA_REQUIRED_ALL_NEEDED == r ? r : l; + case FUNC_DATA_REQUIRED_NO_NEEDED: + return FUNC_DATA_REQUIRED_DISCARD == r ? l : r; + default: + break; + } + return r; +} + +static int32_t osdGetDataRequired(SNodeList* pFuncs) { + if (NULL == pFuncs) { + return FUNC_DATA_REQUIRED_ALL_NEEDED; + } + EFuncDataRequired dataRequired = FUNC_DATA_REQUIRED_DISCARD; + SNode* pFunc = NULL; + FOREACH(pFunc, pFuncs) { + dataRequired = osdPromoteDataRequired(dataRequired, fmFuncDataRequired((SFunctionNode*)pFunc, NULL)); + } + return dataRequired; +} + +static int32_t osdOptimize(SOptimizeContext* pCxt, SLogicNode* pLogicNode) { + SOsdInfo info = {0}; + int32_t code = osdMatch(pCxt, pLogicNode, &info); + if (TSDB_CODE_SUCCESS == code && (NULL != info.pDsoFuncs || NULL != info.pSdrFuncs)) { + info.pScan->dataRequired = osdGetDataRequired(info.pSdrFuncs); + info.pScan->pDynamicScanFuncs = info.pDsoFuncs; + OPTIMIZE_FLAG_SET_MASK(info.pScan->node.optimizedFlag, OPTIMIZE_FLAG_OSD); + pCxt->optimized = true; + } + nodesDestroyList(info.pSdrFuncs); + return code; +} + +static int32_t cpdOptimizeScanCondition(SOptimizeContext* pCxt, SScanLogicNode* pScan) { + // todo + return TSDB_CODE_SUCCESS; +} + +static bool belongThisTable(SNode* pCondCol, SNodeList* pTableCols) { + SNode* pTableCol = NULL; + FOREACH(pTableCol, pTableCols) { + if (nodesEqualNode(pCondCol, pTableCol)) { + return true; + } + } + return false; +} + +static EDealRes cpdIsMultiTableCondImpl(SNode* pNode, void* pContext) { + SCpdIsMultiTableCondCxt* pCxt = pContext; + if (QUERY_NODE_COLUMN == nodeType(pNode)) { + if (belongThisTable(pNode, pCxt->pLeftCols)) { + pCxt->havaLeftCol = true; + } else if (belongThisTable(pNode, pCxt->pRightCols)) { + pCxt->haveRightCol = true; + } + return pCxt->havaLeftCol && pCxt->haveRightCol ? DEAL_RES_END : DEAL_RES_CONTINUE; + } + return DEAL_RES_CONTINUE; +} + +static ECondAction cpdCondAction(EJoinType joinType, SNodeList* pLeftCols, SNodeList* pRightCols, SNode* pNode) { + SCpdIsMultiTableCondCxt cxt = { .pLeftCols = pLeftCols, .pRightCols = pRightCols, .havaLeftCol = false, .haveRightCol = false }; + nodesWalkExpr(pNode, cpdIsMultiTableCondImpl, &cxt); + return (JOIN_TYPE_INNER != joinType ? COND_ACTION_STAY : + (cxt.havaLeftCol && cxt.haveRightCol ? COND_ACTION_PUSH_JOIN : (cxt.havaLeftCol ? COND_ACTION_PUSH_LEFT_CHILD : COND_ACTION_PUSH_RIGHT_CHILD))); +} + +static int32_t cpdMakeCond(SNodeList** pConds, SNode** pCond) { + if (NULL == *pConds) { + return TSDB_CODE_SUCCESS; + } + + if (1 == LIST_LENGTH(*pConds)) { + *pCond = nodesListGetNode(*pConds, 0); + nodesClearList(*pConds); + } else { + SLogicConditionNode* pLogicCond = nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); + if (NULL == pLogicCond) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pLogicCond->condType = LOGIC_COND_TYPE_AND; + pLogicCond->pParameterList = *pConds; + *pCond = (SNode*)pLogicCond; + } + *pConds = NULL; -int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode) { return TSDB_CODE_SUCCESS; } + +static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, SNode** pRightChildCond) { + SLogicConditionNode* pLogicCond = (SLogicConditionNode*)pJoin->node.pConditions; + if (LOGIC_COND_TYPE_AND != pLogicCond->condType) { + return TSDB_CODE_SUCCESS; + } + + SNodeList* pLeftCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0))->pTargets; + SNodeList* pRightCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1))->pTargets; + int32_t code = TSDB_CODE_SUCCESS; + + SNodeList* pOnConds = NULL; + SNodeList* pLeftChildConds = NULL; + SNodeList* pRightChildConds = NULL; + SNodeList* pRemainConds = NULL; + SNode* pCond = NULL; + FOREACH(pCond, pLogicCond->pParameterList) { + ECondAction condAction = cpdCondAction(pJoin->joinType, pLeftCols, pRightCols, pCond); + if (COND_ACTION_PUSH_JOIN == condAction) { + code = nodesListMakeAppend(&pOnConds, nodesCloneNode(pCond)); + } else if (COND_ACTION_PUSH_LEFT_CHILD == condAction) { + code = nodesListMakeAppend(&pLeftChildConds, nodesCloneNode(pCond)); + } else if (COND_ACTION_PUSH_RIGHT_CHILD == condAction) { + code = nodesListMakeAppend(&pRightChildConds, nodesCloneNode(pCond)); + } else { + code = nodesListMakeAppend(&pRemainConds, nodesCloneNode(pCond)); + } + if (TSDB_CODE_SUCCESS != code) { + break; + } + } + + SNode* pTempOnCond = NULL; + SNode* pTempLeftChildCond = NULL; + SNode* pTempRightChildCond = NULL; + SNode* pTempRemainCond = NULL; + if (TSDB_CODE_SUCCESS == code) { + code = cpdMakeCond(&pOnConds, &pTempOnCond); + } + if (TSDB_CODE_SUCCESS == code) { + code = cpdMakeCond(&pLeftChildConds, &pTempLeftChildCond); + } + if (TSDB_CODE_SUCCESS == code) { + code = cpdMakeCond(&pRightChildConds, &pTempRightChildCond); + } + if (TSDB_CODE_SUCCESS == code) { + code = cpdMakeCond(&pRemainConds, &pTempRemainCond); + } + + if (TSDB_CODE_SUCCESS == code) { + *pOnCond = pTempOnCond; + *pLeftChildCond = pTempLeftChildCond; + *pRightChildCond = pTempRightChildCond; + nodesDestroyNode(pJoin->node.pConditions); + pJoin->node.pConditions = pTempRemainCond; + } else { + nodesDestroyList(pOnConds); + nodesDestroyList(pLeftChildConds); + nodesDestroyList(pRightChildConds); + nodesDestroyList(pRemainConds); + nodesDestroyNode(pTempOnCond); + nodesDestroyNode(pTempLeftChildCond); + nodesDestroyNode(pTempRightChildCond); + nodesDestroyNode(pTempRemainCond); + } + + return code; +} + +static int32_t cpdPartitionOpCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, SNode** pRightChildCond) { + SNodeList* pLeftCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0))->pTargets; + SNodeList* pRightCols = ((SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1))->pTargets; + ECondAction condAction = cpdCondAction(pJoin->joinType, pLeftCols, pRightCols, pJoin->node.pConditions); + if (COND_ACTION_STAY == condAction) { + return TSDB_CODE_SUCCESS; + } else if (COND_ACTION_PUSH_JOIN == condAction) { + *pOnCond = pJoin->node.pConditions; + } else if (COND_ACTION_PUSH_LEFT_CHILD == condAction) { + *pLeftChildCond = pJoin->node.pConditions; + } else if (COND_ACTION_PUSH_RIGHT_CHILD == condAction) { + *pRightChildCond = pJoin->node.pConditions; + } + pJoin->node.pConditions = NULL; + return TSDB_CODE_SUCCESS; +} + +static int32_t cpdPartitionCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode** pLeftChildCond, SNode** pRightChildCond) { + if (QUERY_NODE_LOGIC_CONDITION == nodeType(pJoin->node.pConditions)) { + return cpdPartitionLogicCond(pJoin, pOnCond, pLeftChildCond, pRightChildCond); + } else { + return cpdPartitionOpCond(pJoin, pOnCond, pLeftChildCond, pRightChildCond); + } +} + +static int32_t cpdCondAppend(SOptimizeContext* pCxt, SNode** pCond, SNode** pAdditionalCond) { + if (NULL == *pCond) { + TSWAP(*pCond, *pAdditionalCond, SNode*); + return TSDB_CODE_SUCCESS; + } + + int32_t code = TSDB_CODE_SUCCESS; + if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pCond)) { + code = nodesListAppend(((SLogicConditionNode*)*pCond)->pParameterList, *pAdditionalCond); + if (TSDB_CODE_SUCCESS == code) { + *pAdditionalCond = NULL; + } + } else { + SLogicConditionNode* pLogicCond = nodesMakeNode(QUERY_NODE_LOGIC_CONDITION); + if (NULL == pLogicCond) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pLogicCond->condType = LOGIC_COND_TYPE_AND; + code = nodesListMakeAppend(&pLogicCond->pParameterList, *pAdditionalCond); + if (TSDB_CODE_SUCCESS == code) { + *pAdditionalCond = NULL; + code = nodesListMakeAppend(&pLogicCond->pParameterList, *pCond); + } + if (TSDB_CODE_SUCCESS == code) { + *pCond = (SNode*)pLogicCond; + } else { + nodesDestroyNode(pLogicCond); + } + } + return code; +} + +static int32_t cpdPushCondToOnCond(SOptimizeContext* pCxt, SJoinLogicNode* pJoin, SNode** pCond) { + return cpdCondAppend(pCxt, &pJoin->pOnConditions, pCond); +} + +static int32_t cpdPushCondToScan(SOptimizeContext* pCxt, SScanLogicNode* pScan, SNode** pCond) { + return cpdCondAppend(pCxt, &pScan->node.pConditions, pCond); +} + +static int32_t cpdPushCondToChild(SOptimizeContext* pCxt, SLogicNode* pChild, SNode** pCond) { + switch (nodeType(pChild)) { + case QUERY_NODE_LOGIC_PLAN_SCAN: + return cpdPushCondToScan(pCxt, (SScanLogicNode*)pChild, pCond); + default: + break; + } + return TSDB_CODE_PLAN_INTERNAL_ERROR; +} + +static int32_t cpdPushJoinCondition(SOptimizeContext* pCxt, SJoinLogicNode* pJoin) { + if (NULL == pJoin->node.pConditions) { + return TSDB_CODE_SUCCESS; + } + + SNode* pOnCond = NULL; + SNode* pLeftChildCond = NULL; + SNode* pRightChildCond = NULL; + int32_t code = cpdPartitionCond(pJoin, &pOnCond, &pLeftChildCond, &pRightChildCond); + if (TSDB_CODE_SUCCESS == code && NULL != pOnCond) { + code = cpdPushCondToOnCond(pCxt, pJoin, &pOnCond); + } + if (TSDB_CODE_SUCCESS == code && NULL != pLeftChildCond) { + code = cpdPushCondToChild(pCxt, (SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 0), &pLeftChildCond); + } + if (TSDB_CODE_SUCCESS == code && NULL != pRightChildCond) { + code = cpdPushCondToChild(pCxt, (SLogicNode*)nodesListGetNode(pJoin->node.pChildren, 1), &pRightChildCond); + } + + if (TSDB_CODE_SUCCESS != code) { + nodesDestroyNode(pOnCond); + nodesDestroyNode(pLeftChildCond); + nodesDestroyNode(pRightChildCond); + } + + return code; +} + +static int32_t cpdPushAggCondition(SOptimizeContext* pCxt, SAggLogicNode* pAgg) { + // todo + return TSDB_CODE_SUCCESS; +} + +static int32_t cpdPushCondition(SOptimizeContext* pCxt, SLogicNode* pLogicNode) { + int32_t code = TSDB_CODE_SUCCESS; + switch (nodeType(pLogicNode)) { + case QUERY_NODE_LOGIC_PLAN_SCAN: + code = cpdOptimizeScanCondition(pCxt, (SScanLogicNode*)pLogicNode); + break; + case QUERY_NODE_LOGIC_PLAN_JOIN: + code = cpdPushJoinCondition(pCxt, (SJoinLogicNode*)pLogicNode); + break; + case QUERY_NODE_LOGIC_PLAN_AGG: + code = cpdPushAggCondition(pCxt, (SAggLogicNode*)pLogicNode); + break; + default: + break; + } + if (TSDB_CODE_SUCCESS == code) { + SNode* pChild = NULL; + FOREACH(pChild, pLogicNode->pChildren) { + code = cpdPushCondition(pCxt, (SLogicNode*)pChild); + if (TSDB_CODE_SUCCESS != code) { + break; + } + } + } + return code; +} + +static int32_t cpdOptimize(SOptimizeContext* pCxt, SLogicNode* pLogicNode) { + return cpdPushCondition(pCxt, pLogicNode); +} + +static const SOptimizeRule optimizeRuleSet[] = { + { .pName = "OptimizeScanData", .optimizeFunc = osdOptimize }, + { .pName = "ConditionPushDown", .optimizeFunc = cpdOptimize } +}; + +static const int32_t optimizeRuleNum = (sizeof(optimizeRuleSet) / sizeof(SOptimizeRule)); + +static int32_t applyOptimizeRule(SLogicNode* pLogicNode) { + SOptimizeContext cxt = { .optimized = false }; + do { + cxt.optimized = false; + for (int32_t i = 0; i < optimizeRuleNum; ++i) { + int32_t code = optimizeRuleSet[i].optimizeFunc(&cxt, pLogicNode); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + } + } while (cxt.optimized); + return TSDB_CODE_SUCCESS; +} + +int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode) { + return applyOptimizeRule(pLogicNode); +} diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 0c2cffa399844bb218b16ed1b7b058eec16e29f8..a45fabd8288556af8303eef94e41e420eec682ba 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -316,7 +316,18 @@ static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i return TSDB_CODE_SUCCESS; } -static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, ENodeType type) { +static uint8_t getPrecision(SNodeList* pChildren) { + if (1 == LIST_LENGTH(pChildren)) { + return (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc)->precision; + } else if (2 == LIST_LENGTH(pChildren)) { + uint8_t lp = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc)->precision; + uint8_t rp = (((SPhysiNode*)nodesListGetNode(pChildren, 1))->pOutputDataBlockDesc)->precision; + return (lp > rp ? rp : lp); + } + return 0; +} + +static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, uint8_t precision, SLogicNode* pLogicNode, ENodeType type) { SPhysiNode* pPhysiNode = (SPhysiNode*)nodesMakeNode(type); if (NULL == pPhysiNode) { return NULL; @@ -327,6 +338,7 @@ static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode nodesDestroyNode(pPhysiNode); return NULL; } + pPhysiNode->pOutputDataBlockDesc->precision = precision; return pPhysiNode; } @@ -405,7 +417,7 @@ static void vgroupInfoToNodeAddr(const SVgroupInfo* vg, SQueryNodeAddr* pNodeAdd } static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { - STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN); + STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN); if (NULL == pTagScan) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -413,7 +425,7 @@ static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* p } static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { - STableScanPhysiNode* pTableScan = (STableScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN); + STableScanPhysiNode* pTableScan = (STableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN); if (NULL == pTableScan) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -425,12 +437,18 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp taosArrayPush(pCxt->pExecNodeList, &pSubplan->execNode); pSubplan->execNodeStat.tableNum = pScanLogicNode->pVgroupList->vgroups[0].numOfTable; tNameGetFullDbName(&pScanLogicNode->tableName, pSubplan->dbFName); + pTableScan->dataRequired = pScanLogicNode->dataRequired; + pTableScan->pDynamicScanFuncs = nodesCloneList(pScanLogicNode->pDynamicScanFuncs); + if (NULL != pScanLogicNode->pDynamicScanFuncs && NULL == pTableScan->pDynamicScanFuncs) { + nodesDestroyNode(pTableScan); + return TSDB_CODE_OUT_OF_MEMORY; + } return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pTableScan, pPhyNode); } static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { - SSystemTableScanPhysiNode* pScan = (SSystemTableScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN); + SSystemTableScanPhysiNode* pScan = (SSystemTableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN); if (NULL == pScan) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -451,7 +469,7 @@ static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* } static int32_t createStreamScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) { - SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN); + SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN); if (NULL == pScan) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -474,58 +492,22 @@ static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, return TSDB_CODE_FAILED; } -static int32_t createColFromDataBlockDesc(SDataBlockDescNode* pDesc, SNodeList* pCols) { - SNode* pNode; - FOREACH(pNode, pDesc->pSlots) { - SSlotDescNode* pSlot = (SSlotDescNode*)pNode; - SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN); - if (NULL == pCol) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCol->node.resType = pSlot->dataType; - pCol->dataBlockId = pDesc->dataBlockId; - pCol->slotId = pSlot->slotId; - pCol->colId = -1; - int32_t code = nodesListStrictAppend(pCols, pCol); - if (TSDB_CODE_SUCCESS != code) { - return code; - } - } - return TSDB_CODE_SUCCESS; -} - -static int32_t createJoinOutputCols(SPhysiPlanContext* pCxt, SDataBlockDescNode* pLeftDesc, SDataBlockDescNode* pRightDesc, SNodeList** pList) { - SNodeList* pCols = nodesMakeList(); - if (NULL == pCols) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - int32_t code = createColFromDataBlockDesc(pLeftDesc, pCols); - if (TSDB_CODE_SUCCESS == code) { - code = createColFromDataBlockDesc(pRightDesc, pCols); - } - - if (TSDB_CODE_SUCCESS == code) { - *pList = pCols; - } else { - nodesDestroyList(pCols); - } - - return code; -} - static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode, SPhysiNode** pPhyNode) { - SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_JOIN); + SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_JOIN); if (NULL == pJoin) { return TSDB_CODE_OUT_OF_MEMORY; } SDataBlockDescNode* pLeftDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc; SDataBlockDescNode* pRightDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 1))->pOutputDataBlockDesc; + int32_t code = TSDB_CODE_SUCCESS; - int32_t code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pOnConditions, &pJoin->pOnConditions); + pJoin->joinType = pJoinLogicNode->joinType; + if (NULL != pJoinLogicNode->pOnConditions) { + code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pOnConditions, &pJoin->pOnConditions); + } if (TSDB_CODE_SUCCESS == code) { - code = createJoinOutputCols(pCxt, pLeftDesc, pRightDesc, &pJoin->pTargets); + code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->node.pTargets, &pJoin->pTargets); } if (TSDB_CODE_SUCCESS == code) { code = addDataBlockSlots(pCxt, pJoin->pTargets, pJoin->node.pOutputDataBlockDesc); @@ -656,7 +638,7 @@ static int32_t rewritePrecalcExpr(SPhysiPlanContext* pCxt, SNode* pNode, SNodeLi } static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SAggLogicNode* pAggLogicNode, SPhysiNode** pPhyNode) { - SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pAggLogicNode, QUERY_NODE_PHYSICAL_PLAN_AGG); + SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pAggLogicNode, QUERY_NODE_PHYSICAL_PLAN_AGG); if (NULL == pAgg) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -710,7 +692,7 @@ static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, } static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) { - SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pProjectLogicNode, QUERY_NODE_PHYSICAL_PLAN_PROJECT); + SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pProjectLogicNode, QUERY_NODE_PHYSICAL_PLAN_PROJECT); if (NULL == pProject) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -738,18 +720,18 @@ static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild } static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) { - SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE); + SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode(pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE); if (NULL == pExchange) { return TSDB_CODE_OUT_OF_MEMORY; } - + pExchange->srcGroupId = pExchangeLogicNode->srcGroupId; *pPhyNode = (SPhysiNode*)pExchange; return TSDB_CODE_SUCCESS; } static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) { - SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN); + SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN); if (NULL == pScan) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -803,6 +785,10 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* } } + if (TSDB_CODE_SUCCESS == code) { + code = setNodeSlotId(pCxt, pChildTupe->dataBlockId, -1, pWindowLogicNode->pTspk, &pWindow->pTspk); + } + if (TSDB_CODE_SUCCESS == code && NULL != pFuncs) { code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pFuncs, &pWindow->pFuncs); if (TSDB_CODE_SUCCESS == code) { @@ -820,7 +806,7 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList* } static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { - SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL); + SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL); if (NULL == pInterval) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -838,18 +824,11 @@ static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil return TSDB_CODE_OUT_OF_MEMORY; } - SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc); - int32_t code = setNodeSlotId(pCxt, pChildTupe->dataBlockId, -1, pWindowLogicNode->pTspk, &pInterval->pTspk); - if (TSDB_CODE_SUCCESS != code) { - nodesDestroyNode(pInterval); - return code; - } - return createWindowPhysiNodeFinalize(pCxt, pChildren, &pInterval->window, pWindowLogicNode, pPhyNode); } static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { - SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW); + SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW); if (NULL == pSession) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -860,7 +839,7 @@ static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* } static int32_t createStateWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) { - SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW); + SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW); if (NULL == pState) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -908,7 +887,7 @@ static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildr } static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SSortLogicNode* pSortLogicNode, SPhysiNode** pPhyNode) { - SSortPhysiNode* pSort = (SSortPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pSortLogicNode, QUERY_NODE_PHYSICAL_PLAN_SORT); + SSortPhysiNode* pSort = (SSortPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pSortLogicNode, QUERY_NODE_PHYSICAL_PLAN_SORT); if (NULL == pSort) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -947,7 +926,7 @@ static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren } static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SPartitionLogicNode* pPartLogicNode, SPhysiNode** pPhyNode) { - SPartitionPhysiNode* pPart = (SPartitionPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pPartLogicNode, QUERY_NODE_PHYSICAL_PLAN_PARTITION); + SPartitionPhysiNode* pPart = (SPartitionPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pPartLogicNode, QUERY_NODE_PHYSICAL_PLAN_PARTITION); if (NULL == pPart) { return TSDB_CODE_OUT_OF_MEMORY; } @@ -1229,6 +1208,7 @@ static void setExplainInfo(SPlanContext* pCxt, SQueryPlan* pPlan) { SExplainStmt* pStmt = (SExplainStmt*)pCxt->pAstRoot; pPlan->explainInfo.mode = pStmt->analyze ? EXPLAIN_MODE_ANALYZE : EXPLAIN_MODE_STATIC; pPlan->explainInfo.verbose = pStmt->pOptions->verbose; + pPlan->explainInfo.ratio = pStmt->pOptions->ratio; } else { pPlan->explainInfo.mode = EXPLAIN_MODE_DISABLE; } diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c index 3ce225ababe943b0a17a7cb8889669ed42c1054f..e54cf339347ce7955c830149b6f0e4f6655ef84e 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -18,23 +18,20 @@ #define SPLIT_FLAG_MASK(n) (1 << n) #define SPLIT_FLAG_STS SPLIT_FLAG_MASK(0) +#define SPLIT_FLAG_CTJ SPLIT_FLAG_MASK(1) #define SPLIT_FLAG_SET_MASK(val, mask) (val) |= (mask) #define SPLIT_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0) typedef struct SSplitContext { - int32_t errCode; int32_t groupId; - bool match; - void* pInfo; + bool split; } SSplitContext; -typedef int32_t (*FMatch)(SSplitContext* pCxt, SLogicSubplan* pSubplan); -typedef int32_t (*FSplit)(SSplitContext* pCxt); +typedef int32_t (*FSplit)(SSplitContext* pCxt, SLogicSubplan* pSubplan); typedef struct SSplitRule { char* pName; - FMatch matchFunc; FSplit splitFunc; } SSplitRule; @@ -43,48 +40,14 @@ typedef struct SStsInfo { SLogicSubplan* pSubplan; } SStsInfo; -static SLogicNode* stsMatchByNode(SLogicNode* pNode) { - if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode) && - NULL != ((SScanLogicNode*)pNode)->pVgroupList && ((SScanLogicNode*)pNode)->pVgroupList->numOfVgroups > 1) { - return pNode; - } - SNode* pChild; - FOREACH(pChild, pNode->pChildren) { - SLogicNode* pSplitNode = stsMatchByNode((SLogicNode*)pChild); - if (NULL != pSplitNode) { - return pSplitNode; - } - } - return NULL; -} +typedef struct SCtjInfo { + SScanLogicNode* pScan; + SLogicSubplan* pSubplan; +} SCtjInfo; -static int32_t stsMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan) { - if (SPLIT_FLAG_TEST_MASK(pSubplan->splitFlag, SPLIT_FLAG_STS)) { - return TSDB_CODE_SUCCESS; - } - SLogicNode* pSplitNode = stsMatchByNode(pSubplan->pNode); - if (NULL != pSplitNode) { - SStsInfo* pInfo = taosMemoryCalloc(1, sizeof(SStsInfo)); - if (NULL == pInfo) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pInfo->pScan = (SScanLogicNode*)pSplitNode; - pInfo->pSubplan = pSubplan; - pCxt->pInfo = pInfo; - pCxt->match = true; - return TSDB_CODE_SUCCESS; - } - SNode* pChild; - FOREACH(pChild, pSubplan->pChildren) { - int32_t code = stsMatch(pCxt, (SLogicSubplan*)pChild); - if (TSDB_CODE_SUCCESS != code || pCxt->match) { - return code; - } - } - return TSDB_CODE_SUCCESS; -} +typedef bool (*FSplFindSplitNode)(SLogicSubplan* pSubplan, SStsInfo* pInfo); -static SLogicSubplan* stsCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode* pScan) { +static SLogicSubplan* splCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode* pScan, int32_t flag) { SLogicSubplan* pSubplan = nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN); if (NULL == pSubplan) { return NULL; @@ -93,16 +56,17 @@ static SLogicSubplan* stsCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode* pSubplan->subplanType = SUBPLAN_TYPE_SCAN; pSubplan->pNode = (SLogicNode*)nodesCloneNode(pScan); TSWAP(pSubplan->pVgroupList, ((SScanLogicNode*)pSubplan->pNode)->pVgroupList, SVgroupsInfo*); - SPLIT_FLAG_SET_MASK(pSubplan->splitFlag, SPLIT_FLAG_STS); + SPLIT_FLAG_SET_MASK(pSubplan->splitFlag, flag); return pSubplan; } -static int32_t stsCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SScanLogicNode* pScan) { +static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SScanLogicNode* pScan, ESubplanType subplanType) { SExchangeLogicNode* pExchange = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_EXCHANGE); if (NULL == pExchange) { return TSDB_CODE_OUT_OF_MEMORY; } pExchange->srcGroupId = pCxt->groupId; + pExchange->precision = pScan->pMeta->tableInfo.precision; pExchange->node.pTargets = nodesCloneList(pScan->node.pTargets); if (NULL == pExchange->node.pTargets) { return TSDB_CODE_OUT_OF_MEMORY; @@ -127,46 +91,135 @@ static int32_t stsCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubpla return TSDB_CODE_FAILED; } -static int32_t stsSplit(SSplitContext* pCxt) { - SStsInfo* pInfo = pCxt->pInfo; - if (NULL == pInfo->pSubplan->pChildren) { - pInfo->pSubplan->pChildren = nodesMakeList(); - if (NULL == pInfo->pSubplan->pChildren) { +static bool splMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan, int32_t flag, FSplFindSplitNode func, void* pInfo) { + if (!SPLIT_FLAG_TEST_MASK(pSubplan->splitFlag, flag)) { + if (func(pSubplan, pInfo)) { + return true; + } + } + SNode* pChild; + FOREACH(pChild, pSubplan->pChildren) { + if (splMatch(pCxt, (SLogicSubplan*)pChild, flag, func, pInfo)) { + return true; + } + } + return false; +} + +static SLogicNode* stsMatchByNode(SLogicNode* pNode) { + if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode) && + NULL != ((SScanLogicNode*)pNode)->pVgroupList && ((SScanLogicNode*)pNode)->pVgroupList->numOfVgroups > 1) { + return pNode; + } + SNode* pChild; + FOREACH(pChild, pNode->pChildren) { + SLogicNode* pSplitNode = stsMatchByNode((SLogicNode*)pChild); + if (NULL != pSplitNode) { + return pSplitNode; + } + } + return NULL; +} + +static bool stsFindSplitNode(SLogicSubplan* pSubplan, SStsInfo* pInfo) { + SLogicNode* pSplitNode = stsMatchByNode(pSubplan->pNode); + if (NULL != pSplitNode) { + pInfo->pScan = (SScanLogicNode*)pSplitNode; + pInfo->pSubplan = pSubplan; + } + return NULL != pSplitNode; +} + +static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { + SStsInfo info = {0}; + if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_STS, stsFindSplitNode, &info)) { + return TSDB_CODE_SUCCESS; + } + if (NULL == info.pSubplan->pChildren) { + info.pSubplan->pChildren = nodesMakeList(); + if (NULL == info.pSubplan->pChildren) { return TSDB_CODE_OUT_OF_MEMORY; } } - int32_t code = nodesListStrictAppend(pInfo->pSubplan->pChildren, stsCreateScanSubplan(pCxt, pInfo->pScan)); + int32_t code = nodesListStrictAppend(info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_STS)); if (TSDB_CODE_SUCCESS == code) { - code = stsCreateExchangeNode(pCxt, pInfo->pSubplan, pInfo->pScan); + code = splCreateExchangeNode(pCxt, info.pSubplan, info.pScan, SUBPLAN_TYPE_MERGE); } ++(pCxt->groupId); - taosMemoryFreeClear(pCxt->pInfo); + pCxt->split = true; + return code; +} + +static bool ctjIsSingleTable(int8_t tableType) { + return (TSDB_CHILD_TABLE == tableType || TSDB_NORMAL_TABLE == tableType); +} + +static SLogicNode* ctjMatchByNode(SLogicNode* pNode) { + if (QUERY_NODE_LOGIC_PLAN_JOIN == nodeType(pNode)) { + SLogicNode* pLeft = (SLogicNode*)nodesListGetNode(pNode->pChildren, 0); + SLogicNode* pRight = (SLogicNode*)nodesListGetNode(pNode->pChildren, 1); + if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pLeft) && ctjIsSingleTable(((SScanLogicNode*)pLeft)->pMeta->tableType) && + QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pRight) && ctjIsSingleTable(((SScanLogicNode*)pRight)->pMeta->tableType)) { + return pRight; + } + } + SNode* pChild; + FOREACH(pChild, pNode->pChildren) { + SLogicNode* pSplitNode = ctjMatchByNode((SLogicNode*)pChild); + if (NULL != pSplitNode) { + return pSplitNode; + } + } + return NULL; +} + +static bool ctjFindSplitNode(SLogicSubplan* pSubplan, SStsInfo* pInfo) { + SLogicNode* pSplitNode = ctjMatchByNode(pSubplan->pNode); + if (NULL != pSplitNode) { + pInfo->pScan = (SScanLogicNode*)pSplitNode; + pInfo->pSubplan = pSubplan; + } + return NULL != pSplitNode; +} + +static int32_t ctjSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { + SCtjInfo info = {0}; + if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_CTJ, ctjFindSplitNode, &info)) { + return TSDB_CODE_SUCCESS; + } + if (NULL == info.pSubplan->pChildren) { + info.pSubplan->pChildren = nodesMakeList(); + if (NULL == info.pSubplan->pChildren) { + return TSDB_CODE_OUT_OF_MEMORY; + } + } + int32_t code = nodesListStrictAppend(info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_CTJ)); + if (TSDB_CODE_SUCCESS == code) { + code = splCreateExchangeNode(pCxt, info.pSubplan, info.pScan, info.pSubplan->subplanType); + } + ++(pCxt->groupId); + pCxt->split = true; return code; } static const SSplitRule splitRuleSet[] = { - { .pName = "SuperTableScan", .matchFunc = stsMatch, .splitFunc = stsSplit } + { .pName = "SuperTableScan", .splitFunc = stsSplit }, + { .pName = "ChildTableJoin", .splitFunc = ctjSplit }, }; static const int32_t splitRuleNum = (sizeof(splitRuleSet) / sizeof(SSplitRule)); static int32_t applySplitRule(SLogicSubplan* pSubplan) { - SSplitContext cxt = { .errCode = TSDB_CODE_SUCCESS, .groupId = pSubplan->id.groupId + 1, .match = false, .pInfo = NULL }; - bool split = false; + SSplitContext cxt = { .groupId = pSubplan->id.groupId + 1, .split = false }; do { - split = false; + cxt.split = false; for (int32_t i = 0; i < splitRuleNum; ++i) { - cxt.match = false; - int32_t code = splitRuleSet[i].matchFunc(&cxt, pSubplan); - if (TSDB_CODE_SUCCESS == code && cxt.match) { - code = splitRuleSet[i].splitFunc(&cxt); - split = true; - } + int32_t code = splitRuleSet[i].splitFunc(&cxt, pSubplan); if (TSDB_CODE_SUCCESS != code) { return code; } } - } while (split); + } while (cxt.split); return TSDB_CODE_SUCCESS; } @@ -200,6 +253,7 @@ int32_t splitLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SLogicSubplan pSubplan->subplanType = SUBPLAN_TYPE_SCAN; } pSubplan->id.queryId = pCxt->queryId; + pSubplan->id.groupId = 1; setLogicNodeParent(pSubplan->pNode); int32_t code = applySplitRule(pSubplan); diff --git a/source/libs/planner/test/plannerTest.cpp b/source/libs/planner/test/plannerTest.cpp index 697c562b1ea1f28a44a23ba93ca4b14888854a17..48aa89eae6721f4fcd7ab3566c565330230b88cf 100644 --- a/source/libs/planner/test/plannerTest.cpp +++ b/source/libs/planner/test/plannerTest.cpp @@ -70,6 +70,12 @@ protected: cout << "unformatted logic plan : " << endl; cout << toString((const SNode*)pLogicNode, false) << endl; + code = optimizeLogicPlan(&cxt, pLogicNode); + if (code != TSDB_CODE_SUCCESS) { + cout << "sql:[" << cxt_.pSql << "] optimizeLogicPlan code:" << code << ", strerror:" << tstrerror(code) << endl; + return false; + } + SLogicSubplan* pLogicSubplan = nullptr; code = splitLogicPlan(&cxt, pLogicNode, &pLogicSubplan); if (code != TSDB_CODE_SUCCESS) { @@ -150,7 +156,7 @@ private: SQuery* query_; }; -TEST_F(PlannerTest, simple) { +TEST_F(PlannerTest, selectBasic) { setDatabase("root", "test"); bind("SELECT * FROM t1"); @@ -164,37 +170,50 @@ TEST_F(PlannerTest, selectConstant) { ASSERT_TRUE(run()); } -TEST_F(PlannerTest, stSimple) { +TEST_F(PlannerTest, selectStableBasic) { setDatabase("root", "test"); bind("SELECT * FROM st1"); ASSERT_TRUE(run()); } -TEST_F(PlannerTest, groupBy) { +TEST_F(PlannerTest, selectJoin) { setDatabase("root", "test"); - bind("SELECT count(*) FROM t1"); + bind("SELECT t1.c1, t2.c2 FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); ASSERT_TRUE(run()); - bind("SELECT c1, max(c3), min(c2), count(*) FROM t1 GROUP BY c1"); + bind("SELECT t1.*, t2.* FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); ASSERT_TRUE(run()); - bind("SELECT c1 + c3, c1 + count(*) FROM t1 where c2 = 'abc' GROUP BY c1, c3"); + bind("SELECT t1.c1, t2.c1 FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1 and t1.c2 = 'abc' and t2.c2 = 'qwe'"); ASSERT_TRUE(run()); +} - bind("SELECT c1 + c3, sum(c4 * c5) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3"); +TEST_F(PlannerTest, selectGroupBy) { + setDatabase("root", "test"); + + bind("SELECT count(*) FROM t1"); ASSERT_TRUE(run()); + + // bind("SELECT c1, max(c3), min(c2), count(*) FROM t1 GROUP BY c1"); + // ASSERT_TRUE(run()); + + // bind("SELECT c1 + c3, c1 + count(*) FROM t1 where c2 = 'abc' GROUP BY c1, c3"); + // ASSERT_TRUE(run()); + + // bind("SELECT c1 + c3, sum(c4 * c5) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3"); + // ASSERT_TRUE(run()); } -TEST_F(PlannerTest, subquery) { +TEST_F(PlannerTest, selectSubquery) { setDatabase("root", "test"); bind("SELECT count(*) FROM (SELECT c1 + c3 a, c1 + count(*) b FROM t1 where c2 = 'abc' GROUP BY c1, c3) where a > 100 group by b"); ASSERT_TRUE(run()); } -TEST_F(PlannerTest, interval) { +TEST_F(PlannerTest, selectInterval) { setDatabase("root", "test"); bind("SELECT count(*) FROM t1 interval(10s)"); @@ -210,14 +229,14 @@ TEST_F(PlannerTest, interval) { ASSERT_TRUE(run()); } -TEST_F(PlannerTest, sessionWindow) { +TEST_F(PlannerTest, selectSessionWindow) { setDatabase("root", "test"); bind("SELECT count(*) FROM t1 session(ts, 10s)"); ASSERT_TRUE(run()); } -TEST_F(PlannerTest, stateWindow) { +TEST_F(PlannerTest, selectStateWindow) { setDatabase("root", "test"); bind("SELECT count(*) FROM t1 state_window(c1)"); @@ -227,7 +246,7 @@ TEST_F(PlannerTest, stateWindow) { ASSERT_TRUE(run()); } -TEST_F(PlannerTest, partitionBy) { +TEST_F(PlannerTest, selectPartitionBy) { setDatabase("root", "test"); bind("SELECT * FROM t1 partition by c1"); @@ -243,7 +262,7 @@ TEST_F(PlannerTest, partitionBy) { ASSERT_TRUE(run()); } -TEST_F(PlannerTest, orderBy) { +TEST_F(PlannerTest, selectOrderBy) { setDatabase("root", "test"); bind("SELECT c1 FROM t1 order by c1"); @@ -259,7 +278,7 @@ TEST_F(PlannerTest, orderBy) { ASSERT_TRUE(run()); } -TEST_F(PlannerTest, groupByOrderBy) { +TEST_F(PlannerTest, selectGroupByOrderBy) { setDatabase("root", "test"); bind("select count(*), sum(c1) from t1 order by sum(c1)"); @@ -269,7 +288,7 @@ TEST_F(PlannerTest, groupByOrderBy) { ASSERT_TRUE(run()); } -TEST_F(PlannerTest, distinct) { +TEST_F(PlannerTest, selectDistinct) { setDatabase("root", "test"); bind("SELECT distinct c1 FROM t1"); @@ -282,7 +301,7 @@ TEST_F(PlannerTest, distinct) { ASSERT_TRUE(run()); } -TEST_F(PlannerTest, limit) { +TEST_F(PlannerTest, selectLimit) { setDatabase("root", "test"); bind("SELECT * FROM t1 limit 2"); @@ -295,7 +314,7 @@ TEST_F(PlannerTest, limit) { ASSERT_TRUE(run()); } -TEST_F(PlannerTest, slimit) { +TEST_F(PlannerTest, selectSlimit) { setDatabase("root", "test"); bind("SELECT * FROM t1 partition by c1 slimit 2"); diff --git a/source/libs/qworker/inc/qworkerInt.h b/source/libs/qworker/inc/qworkerInt.h index cfd4a3ec7b9410c343d11cd74d0845f6b46bf237..d62f9f04b88c94f93294d4a66a0765c00477a9eb 100644 --- a/source/libs/qworker/inc/qworkerInt.h +++ b/source/libs/qworker/inc/qworkerInt.h @@ -79,6 +79,7 @@ typedef struct SQWConnInfo { typedef struct SQWMsg { void *node; + int32_t code; char *msg; int32_t msgLen; SQWConnInfo connInfo; diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index f0f04a8a9bc538de54cb4f493c97fc66ab63427c..67871dfe6241b0b1c3e48856f6068e96d4d09916 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -536,6 +536,8 @@ int32_t qwDropTask(QW_FPARAMS_DEF) { QW_ERR_RET(qwDropTaskStatus(QW_FPARAMS())); QW_ERR_RET(qwDropTaskCtx(QW_FPARAMS())); + QW_TASK_DLOG_E("task is dropped"); + return TSDB_CODE_SUCCESS; } @@ -1239,8 +1241,10 @@ int32_t qwProcessDrop(QW_FPARAMS_DEF, SQWMsg *qwMsg) { QW_ERR_JRET(qwKillTaskHandle(QW_FPARAMS(), ctx)); qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_DROPPING); } else if (ctx->phase > 0) { - qwBuildAndSendDropRsp(&qwMsg->connInfo, code); - QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code)); + if (0 == qwMsg->code) { + qwBuildAndSendDropRsp(&qwMsg->connInfo, code); + QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code)); + } QW_ERR_JRET(qwDropTask(QW_FPARAMS())); rsped = true; @@ -1273,7 +1277,7 @@ _return: qwReleaseTaskCtx(mgmt, ctx); } - if (TSDB_CODE_SUCCESS != code) { + if ((TSDB_CODE_SUCCESS != code) && (0 == qwMsg->code)) { qwBuildAndSendDropRsp(&qwMsg->connInfo, code); QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code)); } diff --git a/source/libs/qworker/src/qworkerMsg.c b/source/libs/qworker/src/qworkerMsg.c index bf8f97aa4c8b482cfad3568a10705ce0753080f6..15a42d3a3157411ba3a9bbbdaa6d0576d41ce7d4 100644 --- a/source/libs/qworker/src/qworkerMsg.c +++ b/source/libs/qworker/src/qworkerMsg.c @@ -549,7 +549,7 @@ int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) { uint64_t tId = msg->taskId; int64_t rId = msg->refId; - SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0}; + SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0, .code = pMsg->code}; qwMsg.connInfo.handle = pMsg->handle; qwMsg.connInfo.ahandle = pMsg->ahandle; diff --git a/source/libs/scalar/inc/sclInt.h b/source/libs/scalar/inc/sclInt.h index 58b62bb05e40ff80f50a59601fd1256eb4cc00e3..3d59ffd93d7ac7e59ac1aa9e81023f3d2cb30636 100644 --- a/source/libs/scalar/inc/sclInt.h +++ b/source/libs/scalar/inc/sclInt.h @@ -46,8 +46,9 @@ typedef struct SScalarCtx { int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out); SColumnInfoData* createColumnInfoData(SDataType* pType, int32_t numOfRows); -#define GET_PARAM_TYPE(_c) ((_c)->columnData->info.type) -#define GET_PARAM_BYTES(_c) ((_c)->columnData->info.bytes) +#define GET_PARAM_TYPE(_c) ((_c)->columnData->info.type) +#define GET_PARAM_BYTES(_c) ((_c)->columnData->info.bytes) +#define GET_PARAM_PRECISON(_c) ((_c)->columnData->info.precision) void sclFreeParam(SScalarParam *param); diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 2e47e19023d0f292569d599da8e9c5a92f4c0d83..191143de1274f7e715f68e577e4bd2cae54449f4 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -1748,7 +1748,6 @@ int32_t fltInitValFieldData(SFilterInfo *info) { SFilterField* fi = right; SValueNode* var = (SValueNode *)fi->desc; - if (var == NULL) { assert(fi->data != NULL); continue; @@ -1767,13 +1766,18 @@ int32_t fltInitValFieldData(SFilterInfo *info) { } SDataType *dType = &var->node.resType; + size_t bytes = 0; if (type == TSDB_DATA_TYPE_BINARY) { size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes : MAX_NUM_STR_SIZE; - fi->data = taosMemoryCalloc(1, len + 1 + VARSTR_HEADER_SIZE); + bytes = len + 1 + VARSTR_HEADER_SIZE; + + fi->data = taosMemoryCalloc(1, bytes); } else if (type == TSDB_DATA_TYPE_NCHAR) { - size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes : MAX_NUM_STR_SIZE; - fi->data = taosMemoryCalloc(1, (len + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE); + size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes : MAX_NUM_STR_SIZE; + bytes = (len + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; + + fi->data = taosMemoryCalloc(1, bytes); } else if (type != TSDB_DATA_TYPE_JSON){ if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { //TIME RANGE /* @@ -1797,8 +1801,11 @@ int32_t fltInitValFieldData(SFilterInfo *info) { } else { SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; out.columnData->info.type = type; - out.columnData->info.bytes = tDataTypes[type].bytes; - ASSERT(!IS_VAR_DATA_TYPE(type)); + if (IS_VAR_DATA_TYPE(type)) { + out.columnData->info.bytes = bytes; + } else { + out.columnData->info.bytes = tDataTypes[type].bytes; + } // todo refactor the convert int32_t code = doConvertDataType(var, &out); @@ -2985,13 +2992,13 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDa for (int32_t i = 0; i < numOfRows; ++i) { uint32_t uidx = info->groups[0].unitIdxs[0]; void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i); - if (colData == NULL || colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL)) { + if (colData == NULL || colDataIsNull_s((SColumnInfoData *)info->cunits[uidx].colData, i)) { (*p)[i] = 0; all = false; continue; } - // match/nmatch for nchar type need convert from ucs4 to mbs + // match/nmatch for nchar type need convert from ucs4 to mbs if(info->cunits[uidx].dataType == TSDB_DATA_TYPE_NCHAR && (info->cunits[uidx].optr == OP_TYPE_MATCH || info->cunits[uidx].optr == OP_TYPE_NMATCH)){ char *newColData = taosMemoryCalloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1); int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(colData), varDataLen(colData), varDataVal(newColData)); @@ -3222,19 +3229,13 @@ int32_t fltInitFromNode(SNode* tree, SFilterInfo *info, uint32_t options) { info->unitFlags = taosMemoryMalloc(info->unitNum * sizeof(*info->unitFlags)); filterDumpInfoToString(info, "Final", 0); - return code; _return: - qInfo("init from node failed, code:%d", code); - return code; } - - - bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t numOfCols, int32_t numOfRows) { if (FILTER_EMPTY_RES(info)) { return false; diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index f97e5a2d2a4831b4f321ece50512108ed46bb8eb..116dfdd5d5831451798ddaefddfae7f80f19ba86 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -46,7 +46,6 @@ int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out) { colDataAppend(in.columnData, 0, nodesGetValueFromNode(pValueNode), false); colInfoDataEnsureCapacity(out->columnData, 1); - int32_t code = vectorConvertImpl(&in, out); sclFreeParam(&in); diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 0956c2add56970ff23d99498a3599fcbdcd1f075..a3806893c775ccf7456f95aa84130d9c6c498ae4 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -1,6 +1,7 @@ #include "function.h" #include "scalar.h" #include "tdatablock.h" +#include "ttime.h" #include "sclInt.h" #include "sclvector.h" @@ -330,6 +331,19 @@ static int32_t concatCopyHelper(const char *input, char *output, bool hasNcharCo return TSDB_CODE_SUCCESS; } +static int32_t getNumOfNullEntries(SColumnInfoData *pColumnInfoData, int32_t numOfRows) { + int32_t numOfNulls = 0; + if (!pColumnInfoData->hasNull) { + return numOfNulls; + } + for (int i = 0; i < numOfRows; ++i) { + if (pColumnInfoData->varmeta.offset[i] == -1) { + numOfNulls++; + } + } + return numOfNulls; +} + int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { if (inputNum < 2 || inputNum > 8) { // concat accpet 2-8 input strings return TSDB_CODE_FAILED; @@ -362,10 +376,12 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu if (hasNcharCol && (GET_PARAM_TYPE(&pInput[i]) == TSDB_DATA_TYPE_VARCHAR)) { factor = TSDB_NCHAR_SIZE; } + + int32_t numOfNulls = getNumOfNullEntries(pInputData[i], pInput[i].numOfRows); if (pInput[i].numOfRows == 1) { - inputLen += (pInputData[i]->varmeta.length - VARSTR_HEADER_SIZE) * factor * numOfRows; + inputLen += (pInputData[i]->varmeta.length - VARSTR_HEADER_SIZE) * factor * (numOfRows - numOfNulls); } else { - inputLen += pInputData[i]->varmeta.length - numOfRows * VARSTR_HEADER_SIZE; + inputLen += pInputData[i]->varmeta.length - (numOfRows - numOfNulls) * VARSTR_HEADER_SIZE; } } @@ -443,13 +459,15 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p if (hasNcharCol && (GET_PARAM_TYPE(&pInput[i]) == TSDB_DATA_TYPE_VARCHAR)) { factor = TSDB_NCHAR_SIZE; } + + int32_t numOfNulls = getNumOfNullEntries(pInputData[i], pInput[i].numOfRows); if (i == 0) { // calculate required separator space - inputLen += (pInputData[0]->varmeta.length - VARSTR_HEADER_SIZE) * numOfRows * (inputNum - 2) * factor; + inputLen += (pInputData[0]->varmeta.length - VARSTR_HEADER_SIZE) * (numOfRows - numOfNulls) * (inputNum - 2) * factor; } else if (pInput[i].numOfRows == 1) { - inputLen += (pInputData[i]->varmeta.length - VARSTR_HEADER_SIZE) * numOfRows * factor; + inputLen += (pInputData[i]->varmeta.length - VARSTR_HEADER_SIZE) * (numOfRows - numOfNulls) * factor; } else { - inputLen += pInputData[i]->varmeta.length - numOfRows * VARSTR_HEADER_SIZE; + inputLen += pInputData[i]->varmeta.length - (numOfRows - numOfNulls) * VARSTR_HEADER_SIZE; } } @@ -647,6 +665,599 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu return TSDB_CODE_SUCCESS; } +int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + if (inputNum!= 3) { + return TSDB_CODE_FAILED; + } + + int16_t inputType = pInput[0].columnData->info.type; + int16_t outputType = *(int16_t *)pInput[1].columnData->pData; + if (outputType != TSDB_DATA_TYPE_BIGINT && outputType != TSDB_DATA_TYPE_UBIGINT && + outputType != TSDB_DATA_TYPE_VARCHAR && outputType != TSDB_DATA_TYPE_NCHAR && + outputType != TSDB_DATA_TYPE_TIMESTAMP) { + return TSDB_CODE_FAILED; + } + int64_t outputLen = *(int64_t *)pInput[2].columnData->pData; + + char *input = NULL; + char *outputBuf = taosMemoryCalloc(outputLen * pInput[0].numOfRows, 1); + char *output = outputBuf; + if (IS_VAR_DATA_TYPE(inputType)) { + input = pInput[0].columnData->pData + pInput[0].columnData->varmeta.offset[0]; + } else { + input = pInput[0].columnData->pData; + } + + for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { + if (colDataIsNull_s(pInput[0].columnData, i)) { + colDataAppendNULL(pOutput->columnData, i); + continue; + } + + switch(outputType) { + case TSDB_DATA_TYPE_BIGINT: { + if (inputType == TSDB_DATA_TYPE_BINARY) { + memcpy(output, varDataVal(input), varDataLen(input)); + *(int64_t *)output = strtoll(output, NULL, 10); + } else if (inputType == TSDB_DATA_TYPE_NCHAR) { + char *newBuf = taosMemoryCalloc(1, outputLen * TSDB_NCHAR_SIZE + 1); + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf); + if (len < 0) { + taosMemoryFree(newBuf); + return TSDB_CODE_FAILED; + } + newBuf[len] = 0; + *(int64_t *)output = strtoll(newBuf, NULL, 10); + taosMemoryFree(newBuf); + } else { + GET_TYPED_DATA(*(int64_t *)output, int64_t, inputType, input); + } + break; + } + case TSDB_DATA_TYPE_UBIGINT: { + if (inputType == TSDB_DATA_TYPE_BINARY) { + memcpy(output, varDataVal(input), varDataLen(input)); + *(uint64_t *)output = strtoull(output, NULL, 10); + } else if (inputType == TSDB_DATA_TYPE_NCHAR) { + char *newBuf = taosMemoryCalloc(1, outputLen * TSDB_NCHAR_SIZE + 1); + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf); + if (len < 0) { + taosMemoryFree(newBuf); + return TSDB_CODE_FAILED; + } + newBuf[len] = 0; + *(uint64_t *)output = strtoull(newBuf, NULL, 10); + taosMemoryFree(newBuf); + } else { + GET_TYPED_DATA(*(uint64_t *)output, uint64_t, inputType, input); + } + break; + } + case TSDB_DATA_TYPE_TIMESTAMP: { + if (inputType == TSDB_DATA_TYPE_BINARY || inputType == TSDB_DATA_TYPE_NCHAR) { + //not support + return TSDB_CODE_FAILED; + } else { + GET_TYPED_DATA(*(int64_t *)output, int64_t, inputType, input); + } + break; + } + case TSDB_DATA_TYPE_BINARY: { + if (inputType == TSDB_DATA_TYPE_BOOL) { + int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputLen - VARSTR_HEADER_SIZE), *(int8_t *)input ? "true" : "false"); + varDataSetLen(output, len); + } else if (inputType == TSDB_DATA_TYPE_BINARY) { + int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputLen - VARSTR_HEADER_SIZE), varDataVal(input)); + varDataSetLen(output, len); + } else if (inputType == TSDB_DATA_TYPE_BINARY || inputType == TSDB_DATA_TYPE_NCHAR) { + //not support + return TSDB_CODE_FAILED; + } else { + char tmp[400] = {0}; + NUM_TO_STRING(inputType, input, sizeof(tmp), tmp); + int32_t len = (int32_t)strlen(tmp); + len = (outputLen - VARSTR_HEADER_SIZE) > len ? len : (outputLen - VARSTR_HEADER_SIZE); + memcpy(varDataVal(output), tmp, len); + varDataSetLen(output, len); + } + break; + } + case TSDB_DATA_TYPE_NCHAR: { + int32_t outputCharLen = (outputLen - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE; + if (inputType == TSDB_DATA_TYPE_BOOL) { + char tmp[8] = {0}; + int32_t len = sprintf(tmp, "%.*s", outputCharLen, *(int8_t *)input ? "true" : "false" ); + bool ret = taosMbsToUcs4(tmp, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len); + if (!ret) { + return TSDB_CODE_FAILED; + } + varDataSetLen(output, len); + } else if (inputType == TSDB_DATA_TYPE_BINARY) { + int32_t len = outputCharLen > varDataLen(input) ? varDataLen(input) : outputCharLen; + bool ret = taosMbsToUcs4(input + VARSTR_HEADER_SIZE, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len); + if (!ret) { + return TSDB_CODE_FAILED; + } + varDataSetLen(output, len); + } else if (inputType == TSDB_DATA_TYPE_NCHAR) { + int32_t len = MIN(outputLen, varDataLen(input) + VARSTR_HEADER_SIZE); + memcpy(output, input, len); + varDataSetLen(output, len - VARSTR_HEADER_SIZE); + } else { + char tmp[400] = {0}; + NUM_TO_STRING(inputType, input, sizeof(tmp), tmp); + int32_t len = (int32_t)strlen(tmp); + len = outputCharLen > len ? len : outputCharLen; + bool ret = taosMbsToUcs4(tmp, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len); + if (!ret) { + return TSDB_CODE_FAILED; + } + varDataSetLen(output, len); + } + break; + } + default: { + return TSDB_CODE_FAILED; + } + } + + colDataAppend(pOutput->columnData, i, output, false); + if (IS_VAR_DATA_TYPE(inputType)) { + input += varDataTLen(input); + } else { + input += tDataTypes[inputType].bytes; + } + if (IS_VAR_DATA_TYPE(outputType)) { + output += varDataTLen(output); + } else { + output += tDataTypes[outputType].bytes; + } + } + + pOutput->numOfRows = pInput->numOfRows; + taosMemoryFree(outputBuf); + return TSDB_CODE_SUCCESS; +} + +int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + int32_t type = GET_PARAM_TYPE(pInput); + if (type != TSDB_DATA_TYPE_BIGINT && type != TSDB_DATA_TYPE_TIMESTAMP) { + return TSDB_CODE_FAILED; + } + + if (inputNum != 1) { + return TSDB_CODE_FAILED; + } + + char *input = pInput[0].columnData->pData; + for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { + if (colDataIsNull_s(pInput[0].columnData, i)) { + colDataAppendNULL(pOutput->columnData, i); + continue; + } + + char fraction[20] = {0}; + bool hasFraction = false; + NUM_TO_STRING(type, input, sizeof(fraction), fraction); + int32_t tsDigits = (int32_t)strlen(fraction); + + char buf[64] = {0}; + int64_t timeVal; + GET_TYPED_DATA(timeVal, int64_t, type, input); + if (tsDigits > TSDB_TIME_PRECISION_SEC_DIGITS) { + if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal / 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal / (1000 * 1000); + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / (1000 * 1000 * 1000); + } else { + assert(0); + } + hasFraction = true; + memmove(fraction, fraction + TSDB_TIME_PRECISION_SEC_DIGITS, TSDB_TIME_PRECISION_SEC_DIGITS); + } + + struct tm *tmInfo = taosLocalTime((const time_t *)&timeVal, NULL); + strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z", tmInfo); + int32_t len = (int32_t)strlen(buf); + + if (hasFraction) { + int32_t fracLen = (int32_t)strlen(fraction) + 1; + char *tzInfo = strchr(buf, '+'); + if (tzInfo) { + memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo)); + } else { + tzInfo = strchr(buf, '-'); + memmove(tzInfo + fracLen, tzInfo, strlen(tzInfo)); + } + + char tmp[32]; + sprintf(tmp, ".%s", fraction); + memcpy(tzInfo, tmp, fracLen); + len += fracLen; + } + + memmove(buf + VARSTR_HEADER_SIZE, buf, len); + varDataSetLen(buf, len); + + colDataAppend(pOutput->columnData, i, buf, false); + input += tDataTypes[type].bytes; + } + + pOutput->numOfRows = pInput->numOfRows; + + return TSDB_CODE_SUCCESS; +} + +int32_t toUnixtimestampFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + int32_t type = GET_PARAM_TYPE(pInput); + int32_t timePrec = GET_PARAM_PRECISON(pInput); + if (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR) { + return TSDB_CODE_FAILED; + } + + if (inputNum != 1) { + return TSDB_CODE_FAILED; + } + + char *input = pInput[0].columnData->pData + pInput[0].columnData->varmeta.offset[0]; + for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { + if (colDataIsNull_s(pInput[0].columnData, i)) { + colDataAppendNULL(pOutput->columnData, i); + continue; + } + + int64_t timeVal = 0; + convertStringToTimestamp(type, input, timePrec, &timeVal); + + colDataAppend(pOutput->columnData, i, (char *)&timeVal, false); + input += varDataTLen(input); + } + + pOutput->numOfRows = pInput->numOfRows; + + return TSDB_CODE_SUCCESS; +} + +int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + int32_t type = GET_PARAM_TYPE(&pInput[0]); + int32_t timePrec = GET_PARAM_PRECISON(&pInput[0]); + if (inputNum != 2) { + return TSDB_CODE_FAILED; + } + + if (type != TSDB_DATA_TYPE_BIGINT && type != TSDB_DATA_TYPE_TIMESTAMP && + type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR) { + return TSDB_CODE_FAILED; + } + + if (GET_PARAM_TYPE(&pInput[1]) != TSDB_DATA_TYPE_BIGINT) { //time_unit + return TSDB_CODE_FAILED; + } + + int64_t timeUnit, timeVal = 0; + GET_TYPED_DATA(timeUnit, int64_t, GET_PARAM_TYPE(&pInput[1]), pInput[1].columnData->pData); + + int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : + (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); + + char *input = NULL; + if (IS_VAR_DATA_TYPE(type)) { + input = pInput[0].columnData->pData + pInput[0].columnData->varmeta.offset[0]; + } else { + input = pInput[0].columnData->pData; + } + + for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { + if (colDataIsNull_s(pInput[0].columnData, i)) { + colDataAppendNULL(pOutput->columnData, i); + continue; + } + + if (IS_VAR_DATA_TYPE(type)) { /* datetime format strings */ + convertStringToTimestamp(type, input, TSDB_TIME_PRECISION_NANO, &timeVal); + //If converted value is less than 10digits in second, use value in second instead + int64_t timeValSec = timeVal / 1000000000; + if (timeValSec < 1000000000) { + timeVal = timeValSec; + } + } else if (type == TSDB_DATA_TYPE_BIGINT) { /* unix timestamp */ + GET_TYPED_DATA(timeVal, int64_t, type, input); + } else if (type == TSDB_DATA_TYPE_TIMESTAMP) { /* timestamp column*/ + GET_TYPED_DATA(timeVal, int64_t, type, input); + int64_t timeValSec = timeVal / factor; + if (timeValSec < 1000000000) { + timeVal = timeValSec; + } + } + + char buf[20] = {0}; + NUM_TO_STRING(TSDB_DATA_TYPE_BIGINT, &timeVal, sizeof(buf), buf); + int32_t tsDigits = (int32_t)strlen(buf); + timeUnit = timeUnit * 1000 / factor; + + switch (timeUnit) { + case 0: { /* 1u */ + if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000 * 1000; + //} else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + // //timeVal = timeVal / 1000; + } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { + timeVal = timeVal * factor; + } else { + timeVal = timeVal * 1; + } + break; + } + case 1: { /* 1a */ + if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal * 1; + } else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal / 1000 * 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000000 * 1000000; + } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS){ + timeVal = timeVal * factor; + } else { + assert(0); + } + break; + } + case 1000: { /* 1s */ + if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal / 1000 * 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal / 1000000 * 1000000; + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000000000 * 1000000000; + } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { + timeVal = timeVal * factor; + } else { + assert(0); + } + break; + } + case 60000: { /* 1m */ + if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal / 1000 / 60 * 60 * 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal / 1000000 / 60 * 60 * 1000000; + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000000000 / 60 * 60 * 1000000000; + } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { + timeVal = timeVal * factor / factor / 60 * 60 * factor; + } else { + assert(0); + } + break; + } + case 3600000: { /* 1h */ + if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal / 1000 / 3600 * 3600 * 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal / 1000000 / 3600 * 3600 * 1000000; + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000000000 / 3600 * 3600 * 1000000000; + } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { + timeVal = timeVal * factor / factor / 3600 * 3600 * factor; + } else { + assert(0); + } + break; + } + case 86400000: { /* 1d */ + if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal / 1000 / 86400 * 86400 * 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal / 1000000 / 86400 * 86400 * 1000000; + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000000000 / 86400 * 86400 * 1000000000; + } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { + timeVal = timeVal * factor / factor / 86400* 86400 * factor; + } else { + assert(0); + } + break; + } + case 604800000: { /* 1w */ + if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal / 1000 / 604800 * 604800 * 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal / 1000000 / 604800 * 604800 * 1000000; + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000000000 / 604800 * 604800 * 1000000000; + } else if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { + timeVal = timeVal * factor / factor / 604800 * 604800* factor; + } else { + assert(0); + } + break; + } + default: { + timeVal = timeVal * 1; + break; + } + } + + //truncate the timestamp to db precision + switch (timePrec) { + case TSDB_TIME_PRECISION_MILLI: { + if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal / 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000000; + } + break; + } + case TSDB_TIME_PRECISION_MICRO: { + if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal = timeVal / 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal * 1000; + } + break; + } + case TSDB_TIME_PRECISION_NANO: { + if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal = timeVal * 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal = timeVal * 1000000; + } + break; + } + } + + colDataAppend(pOutput->columnData, i, (char *)&timeVal, false); + if (IS_VAR_DATA_TYPE(type)) { + input += varDataTLen(input); + } else { + input += tDataTypes[type].bytes; + } + } + + pOutput->numOfRows = pInput->numOfRows; + + return TSDB_CODE_SUCCESS; +} + +int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + if (inputNum != 2 && inputNum != 3) { + return TSDB_CODE_FAILED; + } + + int32_t timePrec = GET_PARAM_PRECISON(&pInput[0]); + int64_t timeUnit = -1, timeVal[2] = {0}; + if (inputNum == 3) { + if (GET_PARAM_TYPE(&pInput[2]) != TSDB_DATA_TYPE_BIGINT) { + return TSDB_CODE_FAILED; + } + GET_TYPED_DATA(timeUnit, int64_t, GET_PARAM_TYPE(&pInput[2]), pInput[2].columnData->pData); + } + + char *input[2]; + for (int32_t k = 0; k < 2; ++k) { + int32_t type = GET_PARAM_TYPE(&pInput[k]); + if (type != TSDB_DATA_TYPE_BIGINT && type != TSDB_DATA_TYPE_TIMESTAMP && + type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR) { + return TSDB_CODE_FAILED; + } + + if (IS_VAR_DATA_TYPE(type)) { + input[k] = pInput[k].columnData->pData + pInput[k].columnData->varmeta.offset[0]; + } else { + input[k] = pInput[k].columnData->pData; + } + } + + for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { + for (int32_t k = 0; k < 2; ++k) { + if (colDataIsNull_s(pInput[0].columnData, i)) { + colDataAppendNULL(pOutput->columnData, i); + continue; + } + + int32_t type = GET_PARAM_TYPE(&pInput[k]); + if (IS_VAR_DATA_TYPE(type)) { /* datetime format strings */ + convertStringToTimestamp(type, input[k], TSDB_TIME_PRECISION_NANO, &timeVal[k]); + } else if (type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_TIMESTAMP) { /* unix timestamp or ts column*/ + GET_TYPED_DATA(timeVal[k], int64_t, type, input[k]); + if (type == TSDB_DATA_TYPE_TIMESTAMP) { + int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : + (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); + int64_t timeValSec = timeVal[k] / factor; + if (timeValSec < 1000000000) { + timeVal[k] = timeValSec; + } + } + + char buf[20] = {0}; + NUM_TO_STRING(TSDB_DATA_TYPE_BIGINT, &timeVal[k], sizeof(buf), buf); + int32_t tsDigits = (int32_t)strlen(buf); + if (tsDigits <= TSDB_TIME_PRECISION_SEC_DIGITS) { + timeVal[k] = timeVal[k] * 1000000000; + } else if (tsDigits == TSDB_TIME_PRECISION_MILLI_DIGITS) { + timeVal[k] = timeVal[k] * 1000000; + } else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) { + timeVal[k] = timeVal[k] * 1000; + } else if (tsDigits == TSDB_TIME_PRECISION_NANO_DIGITS) { + timeVal[k] = timeVal[k]; + } + } + + if (pInput[k].numOfRows != 1) { + if (IS_VAR_DATA_TYPE(type)) { + input[k] += varDataTLen(input[k]); + } else { + input[k] += tDataTypes[type].bytes; + } + } + } + + int64_t result = (timeVal[0] >= timeVal[1]) ? (timeVal[0] - timeVal[1]) : + (timeVal[1] - timeVal[0]); + + if (timeUnit < 0) { // if no time unit given use db precision + switch(timePrec) { + case TSDB_TIME_PRECISION_MILLI: { + result = result / 1000000; + break; + } + case TSDB_TIME_PRECISION_MICRO: { + result = result / 1000; + break; + } + case TSDB_TIME_PRECISION_NANO: { + result = result / 1; + break; + } + } + } else { + int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : + (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); + timeUnit = timeUnit * 1000 / factor; + switch(timeUnit) { + case 0: { /* 1u */ + result = result / 1000; + break; + } + case 1: { /* 1a */ + result = result / 1000000; + break; + } + case 1000: { /* 1s */ + result = result / 1000000000; + break; + } + case 60000: { /* 1m */ + result = result / 1000000000 / 60; + break; + } + case 3600000: { /* 1h */ + result = result / 1000000000 / 3600; + break; + } + case 86400000: { /* 1d */ + result = result / 1000000000 / 86400; + break; + } + case 604800000: { /* 1w */ + result = result / 1000000000 / 604800; + break; + } + default: { + break; + } + } + } + + colDataAppend(pOutput->columnData, i, (char *)&result, false); + } + + pOutput->numOfRows = pInput->numOfRows; + + return TSDB_CODE_SUCCESS; +} int32_t atanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { return doScalarFunctionUnique(pInput, inputNum, pOutput, atan); diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 4bce8f33f24365eb8a62175ff32c049dcb1b1b15..05456790a5ecd1988fbec7ee24672055b941a8e6 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -177,9 +177,24 @@ static FORCE_INLINE void varToBool(char *buf, SScalarParam* pOut, int32_t rowInd colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*) &v); } +static FORCE_INLINE void varToNchar(char* buf, SScalarParam* pOut, int32_t rowIndex) { + int32_t len = 0; + int32_t inputLen = varDataLen(buf); + + char* t = taosMemoryCalloc(1,(inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE); + /*int32_t resLen = */taosMbsToUcs4(varDataVal(buf), inputLen, (TdUcs4*) varDataVal(t), pOut->columnData->info.bytes, &len); + varDataSetLen(t, len); + + colDataAppend(pOut->columnData, rowIndex, t, false); + taosMemoryFree(t); +} + +//TODO opt performance, tmp is not needed. int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType) { int32_t bufSize = pIn->columnData->info.bytes; - char *tmp = taosMemoryMalloc(bufSize); + char *tmp = taosMemoryMalloc(bufSize + VARSTR_HEADER_SIZE); + + bool vton = false; _bufConverteFunc func = NULL; if (TSDB_DATA_TYPE_BOOL == outType) { @@ -190,6 +205,9 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in func = varToUnsigned; } else if (IS_FLOAT_TYPE(outType)) { func = varToFloat; + } else if (outType == TSDB_DATA_TYPE_NCHAR) { + func = varToNchar; + vton = true; } else { sclError("invalid convert outType:%d", outType); return TSDB_CODE_QRY_APP_ERROR; @@ -197,26 +215,30 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in pOut->numOfRows = pIn->numOfRows; for (int32_t i = 0; i < pIn->numOfRows; ++i) { - if (colDataIsNull(pIn->columnData, pIn->numOfRows, i, NULL)) { + if (colDataIsNull_s(pIn->columnData, i)) { colDataAppendNULL(pOut->columnData, i); continue; } char* data = colDataGetData(pIn->columnData, i); - if (TSDB_DATA_TYPE_BINARY == inType) { - memcpy(tmp, varDataVal(data), varDataLen(data)); - tmp[varDataLen(data)] = 0; + if (vton) { + memcpy(tmp, data, varDataTLen(data)); } else { - ASSERT (varDataLen(data) <= bufSize); - - int len = taosUcs4ToMbs((TdUcs4*)varDataVal(data), varDataLen(data), tmp); - if (len < 0){ - sclError("castConvert taosUcs4ToMbs error 1"); - taosMemoryFreeClear(tmp); - return TSDB_CODE_QRY_APP_ERROR; + if (TSDB_DATA_TYPE_VARCHAR == inType) { + memcpy(tmp, varDataVal(data), varDataLen(data)); + tmp[varDataLen(data)] = 0; + } else { + ASSERT(varDataLen(data) <= bufSize); + + int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(data), varDataLen(data), tmp); + if (len < 0) { + sclError("castConvert taosUcs4ToMbs error 1"); + taosMemoryFreeClear(tmp); + return TSDB_CODE_QRY_APP_ERROR; + } + + tmp[len] = 0; } - - tmp[len] = 0; } (*func)(tmp, pOut, i); diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 11f8e880a669170130155d4a7683dd71cf5421d9..c5258afcc18bc1e23333cee63a8fc88c18b6ea28 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -1100,6 +1100,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch SSubmitRsp *rsp = (SSubmitRsp *)msg; SCH_ERR_JRET(rsp->code); } + SCH_ERR_JRET(rspCode); SSubmitRsp *rsp = (SSubmitRsp *)msg; @@ -1298,7 +1299,6 @@ int32_t schHandleCallback(void *param, const SDataBuf *pMsg, int32_t msgType, in SCH_ERR_JRET(schHandleResponseMsg(pJob, pTask, msgType, pMsg->pData, pMsg->len, rspCode)); _return: - if (pJob) { schReleaseJob(pParam->refId); } diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index c9054d088e1536eeb7c7f7208ab230231eb7c93c..d6f2e91de7739efd535a23427168180fe2aabc86 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -57,7 +57,7 @@ SRaftStore *raftStoreOpen(const char *path) { static int32_t raftStoreInit(SRaftStore *pRaftStore) { assert(pRaftStore != NULL); - pRaftStore->pFile = taosOpenFile(pRaftStore->path, TD_FILE_CTEATE | TD_FILE_WRITE); + pRaftStore->pFile = taosOpenFile(pRaftStore->path, TD_FILE_CREATE | TD_FILE_WRITE); assert(pRaftStore->pFile != NULL); pRaftStore->currentTerm = 0; diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 9df749bec76f13e386ec874913eb797dc75c315d..8a95635ddc6a4cb8d6bba41061e1e31a8654ef0e 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -1196,21 +1196,22 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { return -1; } - // TODO: vLen may be zero - pVal = TDB_REALLOC(*ppVal, cd.vLen); - if (pVal == NULL) { - TDB_FREE(pKey); - return -1; - } - *ppKey = pKey; - *ppVal = pVal; - *kLen = cd.kLen; - *vLen = cd.vLen; - memcpy(pKey, cd.pKey, cd.kLen); - memcpy(pVal, cd.pVal, cd.vLen); + + if (ppVal) { + // TODO: vLen may be zero + pVal = TDB_REALLOC(*ppVal, cd.vLen); + if (pVal == NULL) { + TDB_FREE(pKey); + return -1; + } + + *ppVal = pVal; + *vLen = cd.vLen; + memcpy(pVal, cd.pVal, cd.vLen); + } ret = tdbBtcMoveToNext(pBtc); if (ret < 0) { diff --git a/source/libs/tdb/src/inc/tdbOs.h b/source/libs/tdb/src/inc/tdbOs.h index 1d87285091a5d37b43c29dde1119ac94de205000..503e109adbbaaad62a8db7f4b25611bed2b95075 100644 --- a/source/libs/tdb/src/inc/tdbOs.h +++ b/source/libs/tdb/src/inc/tdbOs.h @@ -37,7 +37,7 @@ extern "C" { /* file */ typedef TdFilePtr tdb_fd_t; -#define TDB_O_CREAT TD_FILE_CTEATE +#define TDB_O_CREAT TD_FILE_CREATE #define TDB_O_WRITE TD_FILE_WRITE #define TDB_O_READ TD_FILE_READ #define TDB_O_TRUNC TD_FILE_TRUNC diff --git a/source/libs/tfs/test/tfsTest.cpp b/source/libs/tfs/test/tfsTest.cpp index 1a093c3877a3c47e73af34cfc729887062d98e3a..58c3a83aff60bf1852534d73ebea8292264a15f1 100644 --- a/source/libs/tfs/test/tfsTest.cpp +++ b/source/libs/tfs/test/tfsTest.cpp @@ -231,7 +231,7 @@ TEST_F(TfsTest, 04_File) { EXPECT_EQ(tfsMkdir(pTfs, "t3"), 0); // FILE *fp = fopen(f1.aname, "w"); - TdFilePtr pFile = taosOpenFile(f1.aname, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(f1.aname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); ASSERT_NE(pFile, nullptr); taosWriteFile(pFile, "12345678", 5); taosCloseFile(&pFile); @@ -640,7 +640,7 @@ TEST_F(TfsTest, 05_MultiDisk) { EXPECT_EQ(tfsMkdir(pTfs, "t3"), 0); // FILE *fp = fopen(f1.aname, "w"); - TdFilePtr pFile = taosOpenFile(f1.aname, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(f1.aname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); ASSERT_NE(pFile, nullptr); taosWriteFile(pFile, "12345678", 5); taosCloseFile(&pFile); diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index cd1fbf8e0e20d0eec0da0faba075df34ec5477e0..c747e6933923ef970097d8ea0bcf11a6335b897a 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -164,8 +164,8 @@ int32_t taosSendHttpReport(const char* server, uint16_t port, char* pCont, int32 wb[1] = uv_buf_init((char*)pCont, contLen); connect->data = wb; - uv_tcp_connect(connect, &socket_tcp, (const struct sockaddr*)&dest, clientConnCb); terrno = 0; + uv_tcp_connect(connect, &socket_tcp, (const struct sockaddr*)&dest, clientConnCb); uv_run(loop, UV_RUN_DEFAULT); uv_loop_close(loop); taosMemoryFree(connect); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index d456cb23a4626b65d5fb08193dc632228da909c5..c655c0bfc942ed886f9492f8da07ad5a1982e7da 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -129,6 +129,12 @@ static void transDestroyConnCtx(STransConnCtx* ctx); static SCliThrdObj* createThrdObj(); static void destroyThrdObj(SCliThrdObj* pThrd); +// snprintf may cause performance problem +#define CONN_CONSTRUCT_HASH_KEY(key, ip, port) \ + do { \ + snprintf(key, sizeof(key), "%s:%d", ip, (int)port); \ + } while (0) + #define CONN_HOST_THREAD_INDEX(conn) (conn ? ((SCliConn*)conn)->hThrdIdx : -1) #define CONN_PERSIST_TIME(para) (para * 1000 * 10) #define CONN_GET_HOST_THREAD(conn) (conn ? ((SCliConn*)conn)->hostThrd : NULL) @@ -206,8 +212,10 @@ static void destroyThrdObj(SCliThrdObj* pThrd); } \ } while (0) -#define CONN_NO_PERSIST_BY_APP(conn) (((conn)->status == ConnNormal || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1) -#define CONN_RELEASE_BY_SERVER(conn) (((conn)->status == ConnRelease || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1) +#define CONN_NO_PERSIST_BY_APP(conn) \ + (((conn)->status == ConnNormal || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1) +#define CONN_RELEASE_BY_SERVER(conn) \ + (((conn)->status == ConnRelease || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1) #define REQUEST_NO_RESP(msg) ((msg)->noResp == 1) #define REQUEST_PERSIS_HANDLE(msg) ((msg)->persistHandle == 1) @@ -282,8 +290,9 @@ void cliHandleResp(SCliConn* conn) { tDebug("%s cli conn %p ref by app", CONN_GET_INST_LABEL(conn), conn); } - tDebug("%s cli conn %p %s received from %s:%d, local info: %s:%d, msg size: %d", pTransInst->label, conn, TMSG_INFO(pHead->msgType), - taosInetNtoa(conn->addr.sin_addr), ntohs(conn->addr.sin_port), taosInetNtoa(conn->locaddr.sin_addr), ntohs(conn->locaddr.sin_port), transMsg.contLen); + tDebug("%s cli conn %p %s received from %s:%d, local info: %s:%d, msg size: %d", pTransInst->label, conn, + TMSG_INFO(pHead->msgType), taosInetNtoa(conn->addr.sin_addr), ntohs(conn->addr.sin_port), + taosInetNtoa(conn->locaddr.sin_addr), ntohs(conn->locaddr.sin_port), transMsg.contLen); conn->secured = pHead->secured; @@ -349,10 +358,12 @@ void cliHandleExcept(SCliConn* pConn) { if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(pConn)) { transMsg.ahandle = transCtxDumpVal(&pConn->ctx, transMsg.msgType); - tDebug("%s cli conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.ahandle, TMSG_INFO(transMsg.msgType)); + tDebug("%s cli conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.ahandle, + TMSG_INFO(transMsg.msgType)); if (transMsg.ahandle == NULL) { transMsg.ahandle = transCtxDumpBrokenlinkVal(&pConn->ctx, (int32_t*)&(transMsg.msgType)); - tDebug("%s cli conn %p construct ahandle %p due to brokenlink", CONN_GET_INST_LABEL(pConn), pConn, transMsg.ahandle); + tDebug("%s cli conn %p construct ahandle %p due to brokenlink", CONN_GET_INST_LABEL(pConn), pConn, + transMsg.ahandle); } } else { transMsg.ahandle = pCtx ? pCtx->ahandle : NULL; @@ -423,8 +434,7 @@ void* destroyConnPool(void* pool) { static SCliConn* getConnFromPool(void* pool, char* ip, uint32_t port) { char key[128] = {0}; - tstrncpy(key, ip, strlen(ip)); - tstrncpy(key + strlen(key), (char*)(&port), sizeof(port)); + CONN_CONSTRUCT_HASH_KEY(key, ip, port); SHashObj* pPool = pool; SConnList* plist = taosHashGet(pPool, key, strlen(key)); @@ -456,8 +466,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { conn->status = ConnInPool; char key[128] = {0}; - tstrncpy(key, conn->ip, strlen(conn->ip)); - tstrncpy(key + strlen(key), (char*)(&conn->port), sizeof(conn->port)); + CONN_CONSTRUCT_HASH_KEY(key, conn->ip, conn->port); tTrace("cli conn %p added to conn pool, read buf cap: %d", conn, conn->readBuf.cap); SConnList* plist = taosHashGet((SHashObj*)pool, key, strlen(key)); @@ -626,8 +635,9 @@ void cliSend(SCliConn* pConn) { pHead->release = REQUEST_RELEASE_HANDLE(pCliMsg) ? 1 : 0; uv_buf_t wb = uv_buf_init((char*)pHead, msgLen); - tDebug("%s cli conn %p %s is send to %s:%d, local info %s:%d", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pHead->msgType), - taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), taosInetNtoa(pConn->locaddr.sin_addr), ntohs(pConn->locaddr.sin_port)); + tDebug("%s cli conn %p %s is send to %s:%d, local info %s:%d", CONN_GET_INST_LABEL(pConn), pConn, + TMSG_INFO(pHead->msgType), taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), + taosInetNtoa(pConn->locaddr.sin_addr), ntohs(pConn->locaddr.sin_port)); if (pHead->persist == 1) { CONN_SET_PERSIST_BY_APP(pConn); diff --git a/source/libs/transport/src/transSrv.c b/source/libs/transport/src/transSrv.c index 79c72b3a35b36cb5abe9763523863fc42b324563..c5a74d4840fdeea828a4e251e6839dc8eeeceffa 100644 --- a/source/libs/transport/src/transSrv.c +++ b/source/libs/transport/src/transSrv.c @@ -147,8 +147,8 @@ static void (*transAsyncHandle[])(SSrvMsg* msg, SWorkThrdObj* thrd) = {uvHandleR static void uvDestroyConn(uv_handle_t* handle); // server and worker thread -static void* workerThread(void* arg); -static void* acceptThread(void* arg); +static void* transWorkerThread(void* arg); +static void* transAcceptThread(void* arg); // add handle loop static bool addHandleToWorkloop(void* arg); @@ -538,7 +538,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { } } -void* acceptThread(void* arg) { +void* transAcceptThread(void* arg) { // opt setThreadName("trans-accept"); SServerObj* srv = (SServerObj*)arg; @@ -596,7 +596,7 @@ static bool addHandleToAcceptloop(void* arg) { } return true; } -void* workerThread(void* arg) { +void* transWorkerThread(void* arg) { setThreadName("trans-worker"); SWorkThrdObj* pThrd = (SWorkThrdObj*)arg; uv_run(pThrd->loop, UV_RUN_DEFAULT); @@ -686,7 +686,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, if (false == addHandleToWorkloop(thrd)) { goto End; } - int err = taosThreadCreate(&(thrd->thread), NULL, workerThread, (void*)(thrd)); + int err = taosThreadCreate(&(thrd->thread), NULL, transWorkerThread, (void*)(thrd)); if (err == 0) { tDebug("sucess to create worker-thread %d", i); // printf("thread %d create\n", i); @@ -698,7 +698,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, if (false == addHandleToAcceptloop(srv)) { goto End; } - int err = taosThreadCreate(&srv->thread, NULL, acceptThread, (void*)srv); + int err = taosThreadCreate(&srv->thread, NULL, transAcceptThread, (void*)srv); if (err == 0) { tDebug("success to create accept-thread"); } else { diff --git a/source/libs/transport/test/pushServer.c b/source/libs/transport/test/pushServer.c index f4ad73f743a10eb20b726ba27ed6f44dbc0e1e2b..3099998f57e74ff73b6af4fd8bd8e3882f0879ee 100644 --- a/source/libs/transport/test/pushServer.c +++ b/source/libs/transport/test/pushServer.c @@ -181,7 +181,7 @@ int main(int argc, char *argv[]) { tInfo("RPC server is running, ctrl-c to exit"); if (commit) { - pDataFile = taosOpenFile(dataName, TD_FILE_APPEND | TD_FILE_CTEATE | TD_FILE_WRITE); + pDataFile = taosOpenFile(dataName, TD_FILE_APPEND | TD_FILE_CREATE | TD_FILE_WRITE); if (pDataFile == NULL) tInfo("failed to open data file, reason:%s", strerror(errno)); } qhandle = taosOpenQueue(); diff --git a/source/libs/transport/test/rserver.c b/source/libs/transport/test/rserver.c index 8ed3bbc96074647f17769b65a5046b0a1e341966..14d109dc5a2720ff723fdc485cb103514f90cf3a 100644 --- a/source/libs/transport/test/rserver.c +++ b/source/libs/transport/test/rserver.c @@ -177,7 +177,7 @@ int main(int argc, char *argv[]) { tInfo("RPC server is running, ctrl-c to exit"); if (commit) { - pDataFile = taosOpenFile(dataName, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); + pDataFile = taosOpenFile(dataName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pDataFile == NULL) tInfo("failed to open data file, reason:%s", strerror(errno)); } qhandle = taosOpenQueue(); diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 36323cdffa68412ec144f29e543337d2e770077b..9f8fe8d84dbf1b9916992292212559ef6ca06c99 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -360,7 +360,7 @@ int walSaveMeta(SWal* pWal) { int metaVer = walFindCurMetaVer(pWal); char fnameStr[WAL_FILE_LEN]; walBuildMetaName(pWal, metaVer + 1, fnameStr); - TdFilePtr pMataFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE); + TdFilePtr pMataFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE); if (pMataFile == NULL) { return -1; } diff --git a/source/libs/wal/src/walSeek.c b/source/libs/wal/src/walSeek.c index 413dcb47f0663b21a38e5642b8d92a18fb88edde..a6f238af6b2e86a810a2ac2d7056fdf2e4a94748 100644 --- a/source/libs/wal/src/walSeek.c +++ b/source/libs/wal/src/walSeek.c @@ -56,13 +56,13 @@ int walSetWrite(SWal* pWal) { char fnameStr[WAL_FILE_LEN]; walBuildIdxName(pWal, fileFirstVer, fnameStr); - pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); + pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pIdxTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; } walBuildLogName(pWal, fileFirstVer, fnameStr); - pLogTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); + pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pLogTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; @@ -102,14 +102,14 @@ int walChangeWrite(SWal* pWal, int64_t ver) { int64_t fileFirstVer = pFileInfo->firstVer; walBuildIdxName(pWal, fileFirstVer, fnameStr); - pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); + pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pIdxTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); pWal->pWriteIdxTFile = NULL; return -1; } walBuildLogName(pWal, fileFirstVer, fnameStr); - pLogTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); + pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pLogTFile == NULL) { taosCloseFile(&pIdxTFile); terrno = TAOS_SYSTEM_ERROR(errno); diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index a578c6f3685c2cfdce8870b04daa5508ab411c29..81f2d82ea5515eea9bb57e6dd3d43d8c131ce86f 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -216,13 +216,13 @@ int walRoll(SWal *pWal) { int64_t newFileFirstVersion = pWal->vers.lastVer + 1; char fnameStr[WAL_FILE_LEN]; walBuildIdxName(pWal, newFileFirstVersion, fnameStr); - pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); + pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pIdxTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; } walBuildLogName(pWal, newFileFirstVersion, fnameStr); - pLogTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND); + pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pLogTFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index b4058b3c0ed3218694e24ad6ce429064d329ff03..a955fb3b0a88d53beae43e49ed03df735388c0d2 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -76,6 +76,47 @@ int32_t taosMkDir(const char *dirname) { return code; } +int32_t taosMulMkDir(const char *dirname) { + if (dirname == NULL) return -1; + char *temp = strdup(dirname); + char *pos = temp; + int32_t code = 0; + + if (strncmp(temp, "/", 1) == 0) { + pos += 1; + } else if (strncmp(temp, "./", 2) == 0) { + pos += 2; + } + + for ( ; *pos != '\0'; pos++) { + if (*pos == '/') { + *pos = '\0'; + code = mkdir(temp, 0755); + if (code < 0 && errno != EEXIST) { + free(temp); + return code; + } + *pos = '/'; + } + } + + if (*(pos - 1) != '/') { + code = mkdir(temp, 0755); + if (code < 0 && errno != EEXIST) { + free(temp); + return code; + } + } + free(temp); + + // int32_t code = mkdir(dirname, 0755); + if (code < 0 && errno == EEXIST) { + return 0; + } + + return code; +} + void taosRemoveOldFiles(const char *dirname, int32_t keepDays) { DIR *dir = opendir(dirname); if (dir == NULL) return; diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index a7855539a44a1a08ed0ab0c958066a13353a9284..4b55d4912cba3157186b3a6aaf557e964866a4ca 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -129,7 +129,7 @@ int64_t taosCopyFile(const char *from, const char *to) { if (pFileFrom == NULL) goto _err; // fidto = open(to, O_WRONLY | O_CREAT | O_EXCL, 0755); - TdFilePtr pFileTo = taosOpenFile(to, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_EXCL); + TdFilePtr pFileTo = taosOpenFile(to, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_EXCL); if (pFileTo == NULL) goto _err; while (true) { @@ -246,7 +246,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { } } else { int access = O_BINARY; - access |= (tdFileOptions & TD_FILE_CTEATE) ? O_CREAT : 0; + access |= (tdFileOptions & TD_FILE_CREATE) ? O_CREAT : 0; if ((tdFileOptions & TD_FILE_WRITE) && (tdFileOptions & TD_FILE_READ)) { access |= O_RDWR; } else if (tdFileOptions & TD_FILE_WRITE) { @@ -768,7 +768,7 @@ int32_t taosUmaskFile(int32_t maskVal) { } int32_t taosGetErrorFile(TdFilePtr pFile) { return errno; } -int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict__ ptrBuf) { +int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) { if (pFile == NULL) { return -1; } diff --git a/source/os/src/osProc.c b/source/os/src/osProc.c index 1cdd41ad78e448caed56a412b340399f624ba4a5..b6de638ac2e4c9fe851d7c73515a9d509ef2ae95 100644 --- a/source/os/src/osProc.c +++ b/source/os/src/osProc.c @@ -24,7 +24,7 @@ int32_t taosNewProc(char **args) { if (pid == 0) { args[0] = tsProcPath; // close(STDIN_FILENO); - close(STDOUT_FILENO); + // close(STDOUT_FILENO); // close(STDERR_FILENO); return execvp(tsProcPath, args); } else { diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index 26de26ab6778e327d787a97ad538111dcfcf2781..4ffbc13fb3b33aa9d4e44b55e53caf3aa6476713 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -369,53 +369,33 @@ int32_t taosGetCpuCores(float *numOfCores) { #endif } -int32_t taosGetCpuUsage(double *cpu_system, double *cpu_engine) { -#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) - *cpu_system = 0; - *cpu_engine = 0; - return 0; -#elif defined(_TD_DARWIN_64) +void taosGetCpuUsage(double *cpu_system, double *cpu_engine) { + static int64_t lastSysUsed = 0; + static int64_t lastSysTotal = 0; + static int64_t lastProcTotal = 0; + static int64_t curSysUsed = 0; + static int64_t curSysTotal = 0; + static int64_t curProcTotal = 0; + *cpu_system = 0; *cpu_engine = 0; - return 0; -#else - static uint64_t lastSysUsed = 0; - static uint64_t lastSysTotal = 0; - static uint64_t lastProcTotal = 0; - - SysCpuInfo sysCpu; - ProcCpuInfo procCpu; - if (taosGetSysCpuInfo(&sysCpu) != 0) { - return -1; - } - if (taosGetProcCpuInfo(&procCpu) != 0) { - return -1; - } - uint64_t curSysUsed = sysCpu.user + sysCpu.nice + sysCpu.system; - uint64_t curSysTotal = curSysUsed + sysCpu.idle; - uint64_t curProcTotal = procCpu.utime + procCpu.stime + procCpu.cutime + procCpu.cstime; + SysCpuInfo sysCpu = {0}; + ProcCpuInfo procCpu = {0}; + if (taosGetSysCpuInfo(&sysCpu) == 0 && taosGetProcCpuInfo(&procCpu) == 0) { + curSysUsed = sysCpu.user + sysCpu.nice + sysCpu.system; + curSysTotal = curSysUsed + sysCpu.idle; + curProcTotal = procCpu.utime + procCpu.stime + procCpu.cutime + procCpu.cstime; - if (lastSysUsed == 0 || lastSysTotal == 0 || lastProcTotal == 0) { - lastSysUsed = curSysUsed > 1 ? curSysUsed : 1; - lastSysTotal = curSysTotal > 1 ? curSysTotal : 1; - lastProcTotal = curProcTotal > 1 ? curProcTotal : 1; - return -1; - } + if (curSysTotal > lastSysTotal && curSysUsed >= lastSysUsed && curProcTotal >= lastProcTotal) { + *cpu_engine = (curSysUsed - lastSysUsed) / (double)(curSysTotal - lastSysTotal) * 100; + *cpu_system = (curProcTotal - lastProcTotal) / (double)(curSysTotal - lastSysTotal) * 100; + } - if (curSysTotal == lastSysTotal) { - return -1; + lastSysUsed = curSysUsed; + lastSysTotal = curSysTotal; + lastProcTotal = curProcTotal; } - - *cpu_engine = (curSysUsed - lastSysUsed) / (double)(curSysTotal - lastSysTotal) * 100; - *cpu_system = (curProcTotal - lastProcTotal) / (double)(curSysTotal - lastSysTotal) * 100; - - lastSysUsed = curSysUsed; - lastSysTotal = curSysTotal; - lastProcTotal = curProcTotal; - - return 0; -#endif } int32_t taosGetTotalMemory(int64_t *totalKB) { @@ -618,7 +598,6 @@ void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, i static int64_t last_wchars = 0; static int64_t last_read_bytes = 0; static int64_t last_write_bytes = 0; - static int64_t cur_rchars = 0; static int64_t cur_wchars = 0; static int64_t cur_read_bytes = 0; @@ -632,6 +611,11 @@ void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, i last_wchars = cur_wchars; last_read_bytes = cur_read_bytes; last_write_bytes = cur_write_bytes; + } else { + *rchars = 0; + *wchars = 0; + *read_bytes = 0; + *write_bytes = 0; } } @@ -693,7 +677,6 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) { void taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) { static int64_t last_receive_bytes = 0; static int64_t last_transmit_bytes = 0; - static int64_t cur_receive_bytes = 0; static int64_t cur_transmit_bytes = 0; if (taosGetCardInfo(&cur_receive_bytes, &cur_transmit_bytes) == 0) { @@ -701,6 +684,9 @@ void taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) { *transmit_bytes = cur_transmit_bytes - last_transmit_bytes; last_receive_bytes = cur_receive_bytes; last_transmit_bytes = cur_transmit_bytes; + } else { + *receive_bytes = 0; + *transmit_bytes = 0; } } diff --git a/source/os/src/osSystem.c b/source/os/src/osSystem.c index a36b3d41d032387d7f6730371d62eabd8052ebfe..665f6370e1c35e17c3fdef1f66217ffd3095c3e1 100644 --- a/source/os/src/osSystem.c +++ b/source/os/src/osSystem.c @@ -29,6 +29,8 @@ struct termios oldtio; #endif +typedef struct FILE TdCmd; + void* taosLoadDll(const char* filename) { #if defined(WINDOWS) return NULL; @@ -178,3 +180,33 @@ void resetTerminalMode() { } #endif } + +TdCmdPtr taosOpenCmd(const char *cmd) { + if (cmd == NULL) return NULL; + return (TdCmdPtr)popen(cmd, "r"); +} + +int64_t taosGetLineCmd(TdCmdPtr pCmd, char ** __restrict ptrBuf) { + if (pCmd == NULL) { + return -1; + } + + size_t len = 0; + return getline(ptrBuf, &len, (FILE*)pCmd); +} + +int32_t taosEOFCmd(TdCmdPtr pCmd) { + if (pCmd == NULL) { + return 0; + } + return feof((FILE*)pCmd); +} + +int64_t taosCloseCmd(TdCmdPtr *ppCmd) { + if (ppCmd == NULL || *ppCmd == NULL) { + return 0; + } + pclose((FILE*)(*ppCmd)); + *ppCmd = NULL; + return 0; +} diff --git a/source/os/src/osTime.c b/source/os/src/osTime.c index 2b0de948805c7a02ea98a849b8f75b7ff372d6e4..9ea49b364e902f48febe0f85f4cf90e8425fe6ad 100644 --- a/source/os/src/osTime.c +++ b/source/os/src/osTime.c @@ -406,7 +406,18 @@ FORCE_INLINE int32_t taosGetTimeOfDay(struct timeval *tv) { #endif } +time_t taosTime(time_t *t) { + return time(t); +} + +time_t taosMktime(struct tm *timep) { + return mktime(timep); +} + struct tm *taosLocalTime(const time_t *timep, struct tm *result) { + if (result == NULL) { + return localtime(timep); + } #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) localtime_s(result, timep); #else diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 46e2d567ce053c74895eec11dd9032e8e3bd3663..b37b1b2f69707951d02f85e5c201a31b7684b660 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -199,7 +199,7 @@ static void *taosThreadToOpenNewFile(void *param) { taosUmaskFile(0); - TdFilePtr pFile = taosOpenFile(name, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { tsLogObj.openInProgress = 0; tsLogObj.lines = tsLogObj.maxLines - 1000; @@ -348,7 +348,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) { taosThreadMutexInit(&tsLogObj.logMutex, NULL); taosUmaskFile(0); - tsLogObj.logHandle->pFile = taosOpenFile(fileName, TD_FILE_CTEATE | TD_FILE_WRITE); + tsLogObj.logHandle->pFile = taosOpenFile(fileName, TD_FILE_CREATE | TD_FILE_WRITE); if (tsLogObj.logHandle->pFile == NULL) { printf("\nfailed to open log file:%s, reason:%s\n", fileName, strerror(errno)); @@ -699,7 +699,7 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) { goto cmp_end; } - TdFilePtr pFile = taosOpenFile(destFileName, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(destFileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { ret = -2; goto cmp_end; diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index 48cf97a11fc4540f7105df25f677f5740018766b..1ad12ef43a0154aa1df6ab748701542cba34aaba 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -48,7 +48,7 @@ struct SDiskbasedBuf { }; static int32_t createDiskFile(SDiskbasedBuf* pBuf) { - pBuf->pFile = taosOpenFile(pBuf->path, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL); + pBuf->pFile = taosOpenFile(pBuf->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL); if (pBuf->pFile == NULL) { return TAOS_SYSTEM_ERROR(errno); } diff --git a/source/util/src/tprocess.c b/source/util/src/tprocess.c index 2cafd3f7f6c9b6f9916f6314788a06e8346982ef..ae7b3d6f1f9552d91c8ea50faba183260fa7d578 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -154,7 +154,7 @@ static void taosProcCleanupQueue(SProcQueue *pQueue) { } static int32_t taosProcQueuePush(SProcObj *pProc, SProcQueue *pQueue, const char *pHead, int16_t rawHeadLen, - const char *pBody, int32_t rawBodyLen, int64_t handle, ProcFuncType ftype) { + const char *pBody, int32_t rawBodyLen, int64_t handle, EProcFuncType ftype) { if (rawHeadLen == 0 || pHead == NULL) { terrno = TSDB_CODE_INVALID_PARA; return -1; @@ -171,7 +171,7 @@ static int32_t taosProcQueuePush(SProcObj *pProc, SProcQueue *pQueue, const char return -1; } - if (handle != 0 && ftype == PROC_REQ) { + if (handle != 0 && ftype == PROC_FUNC_REQ) { if (taosHashPut(pProc->hash, &handle, sizeof(int64_t), &handle, sizeof(int64_t)) != 0) { taosThreadMutexUnlock(&pQueue->mutex); terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -232,7 +232,7 @@ static int32_t taosProcQueuePush(SProcObj *pProc, SProcQueue *pQueue, const char } static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHeadLen, void **ppBody, int32_t *pBodyLen, - ProcFuncType *pFuncType, ProcMallocFp mallocHeadFp, ProcFreeFp freeHeadFp, + EProcFuncType *pFuncType, ProcMallocFp mallocHeadFp, ProcFreeFp freeHeadFp, ProcMallocFp mallocBodyFp, ProcFreeFp freeBodyFp) { tsem_wait(&pQueue->sem); @@ -309,7 +309,7 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHea *ppBody = pBody; *pHeadLen = rawHeadLen; *pBodyLen = rawBodyLen; - *pFuncType = (ProcFuncType)ftype; + *pFuncType = (EProcFuncType)ftype; uTrace("proc:%s, pop msg at pos:%d ftype:%d remain:%d, head:%d %p body:%d %p", pQueue->name, pos, ftype, pQueue->items, rawHeadLen, pHead, rawBodyLen, pBody); @@ -364,7 +364,7 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) { static void taosProcThreadLoop(SProcObj *pProc) { void *pHead, *pBody; int16_t headLen; - ProcFuncType ftype; + EProcFuncType ftype; int32_t bodyLen; SProcQueue *pQueue; ProcConsumeFp consumeFp; @@ -454,8 +454,8 @@ void taosProcCleanup(SProcObj *pProc) { } int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, - void *handle, ProcFuncType ftype) { - if (ftype != PROC_REQ) { + void *handle, EProcFuncType ftype) { + if (ftype != PROC_FUNC_REQ) { terrno = TSDB_CODE_INVALID_PARA; return -1; } @@ -482,7 +482,7 @@ void taosProcCloseHandles(SProcObj *pProc, void (*HandleFp)(void *handle)) { } void taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, - ProcFuncType ftype) { + EProcFuncType ftype) { int32_t retry = 0; while (taosProcQueuePush(pProc, pProc->pParentQueue, pHead, headLen, pBody, bodyLen, 0, ftype) != 0) { uWarn("proc:%s, failed to put to queue:%p since %s, retry:%d", pProc->name, pProc->pParentQueue, terrstr(), retry); diff --git a/source/util/test/procTest.cpp b/source/util/test/procTest.cpp index 54aaf496735c6657508ce2e995f97da3aa1fe612..e05008e8e14598a3c9f3534811d1707f889f999a 100644 --- a/source/util/test/procTest.cpp +++ b/source/util/test/procTest.cpp @@ -89,7 +89,7 @@ TEST_F(UtilTesProc, 00_Init_Cleanup) { taosDropShm(&shm); } -void ConsumeChild1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, ProcFuncType ftype) { +void ConsumeChild1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) { STestMsg msg; memcpy(&msg, pHead, headLen); char body[2000] = {0}; @@ -120,20 +120,20 @@ TEST_F(UtilTesProc, 01_Push_Pop_Child) { SProcObj *cproc = taosProcInit(&cfg); ASSERT_NE(cproc, nullptr); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_RSP), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_REGIST), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_RELEASE), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, NULL, 12, body, 0, 0, PROC_REQ), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_REQ), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, shm.size, body, 0, 0, PROC_REQ), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, shm.size, 0, PROC_REQ), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_FUNC_RSP), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_FUNC_REGIST), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_FUNC_RELEASE), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, NULL, 12, body, 0, 0, PROC_FUNC_REQ), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_FUNC_REQ), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, shm.size, body, 0, 0, PROC_FUNC_REQ), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, shm.size, 0, PROC_FUNC_REQ), 0); for (int32_t j = 0; j < 1000; j++) { int32_t i = 0; for (i = 0; i < 20; ++i) { - ASSERT_EQ(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, 0, PROC_REQ), 0); + ASSERT_EQ(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, 0, PROC_FUNC_REQ), 0); } - ASSERT_NE(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, 0, PROC_REQ), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, 0, PROC_FUNC_REQ), 0); cfg.isChild = true; cfg.name = "1235_p"; @@ -147,7 +147,7 @@ TEST_F(UtilTesProc, 01_Push_Pop_Child) { taosDropShm(&shm); } -void ConsumeParent1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, ProcFuncType ftype) { +void ConsumeParent1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) { STestMsg msg; memcpy(&msg, pHead, headLen); char body[2000] = {0}; @@ -186,7 +186,7 @@ TEST_F(UtilTesProc, 02_Push_Pop_Parent) { for (int32_t j = 0; j < 1000; j++) { int32_t i = 0; for (i = 0; i < 20; ++i) { - taosProcPutToParentQ(pproc, &head, sizeof(STestMsg), body, i, PROC_REQ); + taosProcPutToParentQ(pproc, &head, sizeof(STestMsg), body, i, PROC_FUNC_REQ); } taosProcRun(cproc); @@ -198,7 +198,7 @@ TEST_F(UtilTesProc, 02_Push_Pop_Parent) { taosDropShm(&shm); } -void ConsumeChild3(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, ProcFuncType ftype) { +void ConsumeChild3(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) { STestMsg msg; memcpy(&msg, pHead, headLen); char body[2000] = {0}; @@ -236,7 +236,7 @@ TEST_F(UtilTesProc, 03_Handle) { int32_t i = 0; for (i = 0; i < 20; ++i) { head.handle = (void *)((int64_t)i); - ASSERT_EQ(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, (void *)((int64_t)i), PROC_REQ), 0); + ASSERT_EQ(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, (void *)((int64_t)i), PROC_FUNC_REQ), 0); } cfg.isChild = true; diff --git a/tests/pytest/concurrent_inquiry.sh b/tests/pytest/concurrent_inquiry.sh index 6ac15fb46fd727ca56b1aef7e7137ef822e5244a..4cb1709bef4d6a7c363db83dcedde7eb725ec0c4 100755 --- a/tests/pytest/concurrent_inquiry.sh +++ b/tests/pytest/concurrent_inquiry.sh @@ -35,11 +35,11 @@ CURR_DIR=`pwd` IN_TDINTERNAL="community" if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then TAOS_DIR=$CURR_DIR/../../.. - TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1` + TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1` LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6,7|rev`/lib else TAOS_DIR=$CURR_DIR/../.. - TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1` + TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1` LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6|rev`/lib fi diff --git a/tests/pytest/crash_gen.sh b/tests/pytest/crash_gen.sh index 127e13c5be1ea562cbe536bbb05f6ecd5844b0ea..1c28abfdf4bd82e7ab559f19db6012c7ac72874f 100755 --- a/tests/pytest/crash_gen.sh +++ b/tests/pytest/crash_gen.sh @@ -35,11 +35,11 @@ CURR_DIR=`pwd` IN_TDINTERNAL="community" if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then TAOS_DIR=$CURR_DIR/../../.. - TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1` + TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1` LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6,7|rev`/lib else TAOS_DIR=$CURR_DIR/../.. - TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1` + TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1` LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6|rev`/lib fi diff --git a/tests/pytest/insert/bigint.py b/tests/pytest/insert/bigint.py index 7c7d2d0f9507e8688dd73bcefe88632361c80c70..5431cf8106fdbcd74bdd310de45039badb3bce7f 100644 --- a/tests/pytest/insert/bigint.py +++ b/tests/pytest/insert/bigint.py @@ -54,10 +54,6 @@ class TDTestCase: tdSql.checkData(0, 1, 9223372036854770000) tdLog.info('drop database db') tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) # convert end def stop(self): diff --git a/tests/pytest/insert/binary.py b/tests/pytest/insert/binary.py index 0cbb7876c6194041a160f8fee7271f0c76d3b90c..ffd1d6cb8cb716dabf0e5299d070cf8d7d73daf4 100644 --- a/tests/pytest/insert/binary.py +++ b/tests/pytest/insert/binary.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +import platform import sys from util.log import * from util.cases import * @@ -13,6 +14,23 @@ class TDTestCase: tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) + def getPath(self, tool="taos"): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + paths = [] + for root, dirs, files in os.walk(projPath): + if ((tool) in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + paths.append(os.path.join(root, tool)) + break + return paths[0] + def run(self): tdSql.prepare() @@ -53,16 +71,27 @@ class TDTestCase: tdLog.info("tdSql.checkData(0, 0, '34567')") tdSql.checkData(0, 0, '34567') tdLog.info("insert into tb values (now+4a, \"'';\")") - config_dir = subprocess.check_output(str("ps -ef |grep dnode1|grep -v grep |awk '{print $NF}'"), stderr=subprocess.STDOUT, shell=True).decode('utf-8').replace('\n', '') - result = ''.join(os.popen(r"""taos -s "insert into db.tb values (now+4a, \"'';\")" -c %s"""%(config_dir)).readlines()) - if "Query OK" not in result: tdLog.exit("err:insert '';") - tdLog.info('drop database db') - tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) -# convert end + + if platform.system() == "Linux": + config_dir = subprocess.check_output( + str("ps -ef |grep dnode1|grep -v grep |awk '{print $NF}'"), + stderr=subprocess.STDOUT, + shell=True).decode('utf-8').replace( + '\n', + '') + + binPath = self.getPath("taos") + if (binPath == ""): + tdLog.exit("taos not found!") + else: + tdLog.info("taos found: %s" % binPath) + + result = ''.join( + os.popen( + r"""%s -s "insert into db.tb values (now+4a, \"'';\")" -c %s""" % + (binPath, (config_dir))).readlines()) + if "Query OK" not in result: + tdLog.exit("err:insert '';") def stop(self): tdSql.close() diff --git a/tests/pytest/insert/double.py b/tests/pytest/insert/double.py index 1b66ed1c44c7cec645be1f0f23866c7f06501ebc..2699f4b0e95897de47d461f885690e2b8a7863d7 100644 --- a/tests/pytest/insert/double.py +++ b/tests/pytest/insert/double.py @@ -75,10 +75,6 @@ class TDTestCase: tdSql.checkData(0, 1, 2.000000000) tdLog.info('drop database db') tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) # convert end def stop(self): diff --git a/tests/pytest/insert/smallint.py b/tests/pytest/insert/smallint.py index 16322e9aeb801ae92b75b920922991206a4b2e35..1a1eab6a98912639aa845e7aae552fdd49278a5b 100644 --- a/tests/pytest/insert/smallint.py +++ b/tests/pytest/insert/smallint.py @@ -91,10 +91,6 @@ class TDTestCase: tdSql.checkData(0, 1, 2) tdLog.info('drop database db') tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) # convert end def stop(self): diff --git a/tests/pytest/insert/timestamp.py b/tests/pytest/insert/timestamp.py new file mode 100644 index 0000000000000000000000000000000000000000..d5ddffcfafbade7b59fb32269a58b5ae0c9c0fdc --- /dev/null +++ b/tests/pytest/insert/timestamp.py @@ -0,0 +1,93 @@ +################################################################### +# 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 + +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + self.ts = 1607281690000 + + def run(self): + tdSql.prepare() + + # TS-806 + tdLog.info("test case for TS-806") + + # Case 1 + tdSql.execute("create table t1(ts timestamp, c1 int)") + tdSql.execute("insert into t1(c1, ts) values(1, %d)" % self.ts) + tdSql.query("select * from t1") + tdSql.checkRows(1) + + # Case 2 + tdSql.execute( + "insert into t1(c1, ts) values(2, %d)(3, %d)" % + (self.ts + 1000, self.ts + 2000)) + tdSql.query("select * from t1") + tdSql.checkRows(3) + + # Case 3 + tdSql.execute("create table t2(ts timestamp, c1 timestamp)") + tdSql.execute( + " insert into t2(c1, ts) values(%d, %d)" % + (self.ts, self.ts + 5000)) + tdSql.query("select * from t2") + tdSql.checkRows(1) + + tdSql.execute( + " insert into t2(c1, ts) values(%d, %d)(%d, %d)" % + (self.ts, self.ts + 6000, self.ts + 3000, self.ts + 8000)) + tdSql.query("select * from t2") + tdSql.checkRows(3) + + # Case 4 + tdSql.execute( + "create table stb(ts timestamp, c1 int, c2 binary(20)) tags(tstag timestamp, t1 int)") + tdSql.execute( + "insert into tb1(c2, ts, c1) using stb(t1, tstag) tags(1, now) values('test', %d, 1)" % + self.ts) + tdSql.query("select * from stb") + tdSql.checkRows(1) + + # Case 5 + tdSql.execute( + "insert into tb1(c2, ts, c1) using stb(t1, tstag) tags(1, now) values('test', now, 1) tb2(c1, ts) using stb tags(now + 2m, 1000) values(1, now - 1h)") + tdSql.query("select * from stb") + tdSql.checkRows(3) + + tdSql.execute(" insert into tb1(c2, ts, c1) using stb(t1, tstag) tags(1, now) values('test', now + 10s, 1) tb2(c1, ts) using stb(tstag) tags(now + 2m) values(1, now - 3h)(2, now - 2h)") + tdSql.query("select * from stb") + tdSql.checkRows(6) + + # Case 6 + tdSql.execute( + "create table stb2 (ts timestamp, c1 timestamp, c2 timestamp) tags(t1 timestamp, t2 timestamp)") + tdSql.execute(" insert into tb4(c1, c2, ts) using stb2(t2, t1) tags(now, now + 1h) values(now + 1s, now + 2s, now + 3s)(now -1s, now - 2s, now - 3s) tb5(c2, ts, c1) using stb2(t2) tags(now + 1h) values(now, now, now)") + tdSql.query("select * from stb2") + tdSql.checkRows(3) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/insert/tinyint.py b/tests/pytest/insert/tinyint.py index a10c999e8c2f0fe070347651f9246e3734104eca..a27b60aa724a93c7ccd40d521f0ee09c066c53d3 100644 --- a/tests/pytest/insert/tinyint.py +++ b/tests/pytest/insert/tinyint.py @@ -91,10 +91,6 @@ class TDTestCase: tdSql.checkData(0, 1, 2) tdLog.info('drop database db') tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) # convert end def stop(self): diff --git a/tests/pytest/insert/unsignedBigint.py b/tests/pytest/insert/unsignedBigint.py index b222f2cd0195e14fddf1f10662447cef97f0e841..0e99afa14207ed7e4426483c2276ec9b643f5873 100644 --- a/tests/pytest/insert/unsignedBigint.py +++ b/tests/pytest/insert/unsignedBigint.py @@ -93,10 +93,6 @@ class TDTestCase: tdSql.checkData(0, 1, 2) tdLog.info('drop database db') tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) # convert end def stop(self): diff --git a/tests/pytest/insert/unsignedInt.py b/tests/pytest/insert/unsignedInt.py index ed18999bc415022da34788a79e9045a5f67cf8ee..f38964677f99b945a136fe9e9ae58073edaba102 100644 --- a/tests/pytest/insert/unsignedInt.py +++ b/tests/pytest/insert/unsignedInt.py @@ -93,10 +93,6 @@ class TDTestCase: tdSql.checkData(0, 1, 2) tdLog.info('drop database db') tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) # convert end def stop(self): diff --git a/tests/pytest/insert/unsignedSmallint.py b/tests/pytest/insert/unsignedSmallint.py index 9893c470ce1a53a05138dd9d5c18e2b0a9f21374..815390868b530ed4321b23ee8776421941640176 100644 --- a/tests/pytest/insert/unsignedSmallint.py +++ b/tests/pytest/insert/unsignedSmallint.py @@ -93,10 +93,6 @@ class TDTestCase: tdSql.checkData(0, 1, 2) tdLog.info('drop database db') tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) # convert end def stop(self): diff --git a/tests/pytest/insert/unsignedTinyint.py b/tests/pytest/insert/unsignedTinyint.py index 5bdfe7580b198ccaffcab7005e88aa72e1c437af..200ac00eb00b673339cd35601e8ed0f7663f06b0 100644 --- a/tests/pytest/insert/unsignedTinyint.py +++ b/tests/pytest/insert/unsignedTinyint.py @@ -91,10 +91,6 @@ class TDTestCase: tdSql.checkData(0, 1, 2) tdLog.info('drop database db') tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) def stop(self): diff --git a/tests/pytest/perf_gen.sh b/tests/pytest/perf_gen.sh index d28b5422f8ba4d4683c78020e45d2085385c4b4f..13a667fd3801b1e0828d5704caec63c09a1c4518 100755 --- a/tests/pytest/perf_gen.sh +++ b/tests/pytest/perf_gen.sh @@ -35,11 +35,11 @@ CURR_DIR=`pwd` IN_TDINTERNAL="community" if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then TAOS_DIR=$CURR_DIR/../../.. - TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1` + TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1` LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6,7|rev`/lib else TAOS_DIR=$CURR_DIR/../.. - TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1` + TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1` LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6|rev`/lib fi diff --git a/tests/pytest/smoketest.sh b/tests/pytest/smoketest.sh index cbe80882fbb6dfb6cfa9695f66d0b22d09068ae5..7ac5d4f6d375d194077af80e2a89f0d34a8c32d1 100755 --- a/tests/pytest/smoketest.sh +++ b/tests/pytest/smoketest.sh @@ -4,10 +4,32 @@ ulimit -c unlimited # insert python3 ./test.py $1 -f insert/basic.py python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/bool.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/tinyint.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/smallint.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/int.py +python3 ./test.py $1 -s && sleep 1 python3 ./test.py $1 -f insert/bigint.py python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/float.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/double.py +python3 ./test.py $1 -s && sleep 1 python3 ./test.py $1 -f insert/nchar.py python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/timestamp.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/unsignedTinyint.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/unsignedSmallint.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/unsignedInt.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/unsignedBigint.py +python3 ./test.py $1 -s && sleep 1 python3 ./test.py $1 -f insert/multi.py python3 ./test.py $1 -s && sleep 1 diff --git a/tests/pytest/test.sh b/tests/pytest/test.sh index 4e74341f7075b50329a49aa3eccd09f68b733f20..fd3010f4cbc7e518a7692dbdb78fa3da2103b543 100755 --- a/tests/pytest/test.sh +++ b/tests/pytest/test.sh @@ -11,7 +11,7 @@ if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then else TAOS_DIR=$CURR_DIR/../.. fi -TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1` LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6|rev`/lib export PYTHONPATH=$(pwd)/../../src/connector/python export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB_DIR diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 2d181673377b128cc7920b8130ccc4574a4140f6..3df1d4287b663d37837029390a438d01fabf137b 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -31,7 +31,9 @@ ./test.sh -f tsim/query/interval.sim ./test.sh -f tsim/query/interval-offset.sim ./test.sh -f tsim/query/scalarFunction.sim -./test.sh -f tsim/query/charScalarFunction.sim +#./test.sh -f tsim/query/charScalarFunction.sim +./test.sh -f tsim/query/explain.sim +./test.sh -f tsim/query/session.sim # ---- qnode ./test.sh -f tsim/qnode/basic1.sim @@ -43,7 +45,7 @@ ./test.sh -f tsim/bnode/basic1.sim # ---- mnode -./test.sh -f tsim/bnode/basic1.sim +./test.sh -f tsim/mnode/basic1.sim # ---- show ./test.sh -f tsim/show/basic.sim @@ -54,8 +56,17 @@ # ---- tmq ./test.sh -f tsim/tmq/basic.sim ./test.sh -f tsim/tmq/basic1.sim -./test.sh -f tsim/tmq/oneTopic.sim -./test.sh -f tsim/tmq/multiTopic.sim +#./test.sh -f tsim/tmq/oneTopic.sim +#./test.sh -f tsim/tmq/multiTopic.sim + +#./test.sh -f tsim/tmq/mainConsumerInMultiTopic.sim +#./test.sh -f tsim/tmq/mainConsumerInOneTopic.sim + +#fail ./test.sh -f tsim/tmq/main2Con1Cgrp1TopicFrCtb.sim +#fail ./test.sh -f tsim/tmq/main2Con1Cgrp1TopicFrStb.sim +#./test.sh -f tsim/tmq/main2Con1Cgrp2TopicFrCtb.sim +#./test.sh -f tsim/tmq/main2Con1Cgrp2TopicFrStb.sim + # --- stable ./test.sh -f tsim/stable/disk.sim @@ -69,7 +80,17 @@ # --- for multi process mode ./test.sh -f tsim/user/basic1.sim -m -./test.sh -f tsim/stable/vnode3.sim -m +./test.sh -f tsim/db/basic3.sim -m +./test.sh -f tsim/db/error1.sim -m +./test.sh -f tsim/insert/backquote.sim -m +./test.sh -f tsim/parser/fourArithmetic-basic.sim -m +./test.sh -f tsim/query/interval-offset.sim -m ./test.sh -f tsim/tmq/basic.sim -m +./test.sh -f tsim/stable/vnode3.sim -m +./test.sh -f tsim/qnode/basic1.sim -m +./test.sh -f tsim/mnode/basic1.sim -m + +# --- sma +./test.sh -f tsim/sma/tsmaCreateInsertData.sim #======================b1-end=============== diff --git a/tests/script/sh/cfg.sh b/tests/script/sh/cfg.sh index 7d4d747e54bab9ed98b42ab1902f8580e17fca6c..ac7e81e87b61042b748c9f52ac8c3b08a4ee1dc2 100755 --- a/tests/script/sh/cfg.sh +++ b/tests/script/sh/cfg.sh @@ -43,7 +43,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -52,9 +52,9 @@ else fi if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/clear.sh b/tests/script/sh/clear.sh index 4ee296cf058370552b14c31b67006830e84847dd..197020c92812f72a82698bd84427acaa7e5a3c1a 100755 --- a/tests/script/sh/clear.sh +++ b/tests/script/sh/clear.sh @@ -46,7 +46,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -55,9 +55,9 @@ else fi if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index 38b6d9aadbbfbc8ad3e0cd7c37f56961e4f3f25c..29a495113f8bc0c3b61271d0193408290924f330 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -41,7 +41,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" diff --git a/tests/script/sh/exec-default.sh b/tests/script/sh/exec-default.sh index f648315c6745f63cfba9eb06ecfd53a9ccef1fed..cca8dd0c3424b3e5d7482a8908af48bfd1aa2dc3 100755 --- a/tests/script/sh/exec-default.sh +++ b/tests/script/sh/exec-default.sh @@ -52,7 +52,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -61,9 +61,9 @@ else fi if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/exec-no-random-fail.sh b/tests/script/sh/exec-no-random-fail.sh index e01b18a8e6bb0d4631a28c64c6accd57bceb9076..72b2035af5105ed24b510cfa2bfb032654672f14 100755 --- a/tests/script/sh/exec-no-random-fail.sh +++ b/tests/script/sh/exec-no-random-fail.sh @@ -52,7 +52,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -61,9 +61,9 @@ else fi if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/exec-random-fail.sh b/tests/script/sh/exec-random-fail.sh index 1f31899e3ac26861fc1860d10cb0a4899ff7bf36..5ed71af05d1c428a7a59d2212f06339a951e8234 100755 --- a/tests/script/sh/exec-random-fail.sh +++ b/tests/script/sh/exec-random-fail.sh @@ -52,7 +52,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -61,9 +61,9 @@ else fi if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/exec.sh b/tests/script/sh/exec.sh index 1a9a6a2c5220184b99a6fe864372f585fd5c56bc..50ded73555690db1cf8d2a94014efdd51079c284 100755 --- a/tests/script/sh/exec.sh +++ b/tests/script/sh/exec.sh @@ -56,7 +56,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" diff --git a/tests/script/sh/exec_tarbitrator.sh b/tests/script/sh/exec_tarbitrator.sh index e985bd65856025b2db8dfef724fdc652b2a03392..1b91d999a7bb4e74ebb12a51ea365b70f59c5256 100755 --- a/tests/script/sh/exec_tarbitrator.sh +++ b/tests/script/sh/exec_tarbitrator.sh @@ -49,7 +49,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -58,9 +58,9 @@ else fi if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/move_dnode.sh b/tests/script/sh/move_dnode.sh index d3650c18ad0f49185ce1e1268273b8a44e3cdc14..4aa2daa3973fb52ff4680c7a146bcbf1905ae64f 100755 --- a/tests/script/sh/move_dnode.sh +++ b/tests/script/sh/move_dnode.sh @@ -18,7 +18,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -27,9 +27,9 @@ else fi if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/mv_old_data.sh b/tests/script/sh/mv_old_data.sh index 3f4be6714fd757ee60d21ee97be5d411e3f95bdd..2c99bc11c4990603845a135775e0826eaafc5b7c 100755 --- a/tests/script/sh/mv_old_data.sh +++ b/tests/script/sh/mv_old_data.sh @@ -18,7 +18,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -27,9 +27,9 @@ else fi if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/test.sh b/tests/script/test.sh index 8b77575e1845d4bff7b62d6b5351263912a34a5d..f5a9e4187bb85ea4f0ddeadde92dec0bfc0a6fd0 100755 --- a/tests/script/test.sh +++ b/tests/script/test.sh @@ -51,7 +51,7 @@ else fi TOP_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -125,8 +125,8 @@ ulimit -c unlimited if [ -n "$FILE_NAME" ]; then echo "------------------------------------------------------------------------" if [ $VALGRIND -eq 1 ]; then - echo valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=${CODE_DIR}/../script/valgrind.log $PROGRAM -c $CFG_DIR -f $FILE_NAME - valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=${CODE_DIR}/../script/valgrind.log $PROGRAM -c $CFG_DIR -f $FILE_NAME + echo valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=${CODE_DIR}/../script/valgrind.log $PROGRAM -c $CFG_DIR -f $FILE_NAME -v + valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=${CODE_DIR}/../script/valgrind.log $PROGRAM -c $CFG_DIR -f $FILE_NAME -v else if [[ $MULTIPROCESS -eq 1 ]];then echo "ExcuteCmd(multiprocess):" $PROGRAM -m -c $CFG_DIR -f $FILE_NAME diff --git a/tests/script/tmp/back.sim b/tests/script/tmp/back.sim new file mode 100644 index 0000000000000000000000000000000000000000..9202e90594bc3bed6e4b63f2ac1f863af91620be --- /dev/null +++ b/tests/script/tmp/back.sim @@ -0,0 +1,6 @@ +sql connect +$x = 1 +begin: + sql insert into db.tb values(now, $x ) -x begin + $x = $x + 1 +goto begin diff --git a/tests/script/tmp/data.sim b/tests/script/tmp/data.sim new file mode 100644 index 0000000000000000000000000000000000000000..faac5b28289099c4050579f51099cfda716ad887 --- /dev/null +++ b/tests/script/tmp/data.sim @@ -0,0 +1,14 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sql connect + +sql create database db +sql create table db.tb (ts timestamp, i int) +sql insert into db.tb values(now, 1) + +print ======== start back +run_back tmp/back.sim + +sleep 2000 +return -1 diff --git a/tests/script/tmp/monitor.sim b/tests/script/tmp/monitor.sim new file mode 100644 index 0000000000000000000000000000000000000000..ba98bec2d05ef9c976ac93c8092b2d5051caf62e --- /dev/null +++ b/tests/script/tmp/monitor.sim @@ -0,0 +1,35 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c monitorfqdn -v localhost +system sh/cfg.sh -n dnode1 -c monitorport -v 80 +system sh/cfg.sh -n dnode1 -c monitorInterval -v 1 +system sh/cfg.sh -n dnode1 -c monitorComp -v 1 +#system sh/cfg.sh -n dnode1 -c supportVnodes -v 128 + +system sh/exec.sh -n dnode1 -s start +sql connect + +print =============== show dnodes +sleep 2000 +sql create database db vgroups 2; +sleep 2000 + +print =============== create drop qnode 1 +sql create qnode on dnode 1 +sql create snode on dnode 1 +sql create bnode on dnode 1 + +return +print =============== restart +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + + +return +system sh/deploy.sh -n dnode2 -i 2 +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s start + +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT diff --git a/tests/script/tsim/db/alter_option.sim b/tests/script/tsim/db/alter_option.sim index f79bf88ad23ab676210c24c680e62e63c2ba928e..9c7b2f5424331febdbba7bcd886ac3e38e3a8374 100644 --- a/tests/script/tsim/db/alter_option.sim +++ b/tests/script/tsim/db/alter_option.sim @@ -74,7 +74,7 @@ print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $d print ====> dataX_db print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $rows != 2 then +if $rows != 3 then return -1 endi if $data0_db != db then # name diff --git a/tests/script/tsim/db/basic1.sim b/tests/script/tsim/db/basic1.sim index c07ebd040002b864b6533f42d929ed898b890331..49568d64ed3086409b903beb25a853ecba07314c 100644 --- a/tests/script/tsim/db/basic1.sim +++ b/tests/script/tsim/db/basic1.sim @@ -6,19 +6,19 @@ sql connect print =============== create database sql create database d1 vgroups 2 sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi -if $data00 != d1 then +if $data20 != d1 then return -1 endi -if $data02 != 2 then +if $data22 != 2 then return -1 endi -if $data03 != 0 then +if $data23 != 0 then return -1 endi @@ -40,7 +40,7 @@ endi print =============== drop database sql drop database d1 sql show databases -if $rows != 1 then +if $rows != 2 then return -1 endi @@ -49,7 +49,7 @@ sql create database d2 vgroups 2 sql create database d3 vgroups 3 sql create database d4 vgroups 4 sql show databases -if $rows != 4 then +if $rows != 5 then return -1 endi @@ -111,19 +111,19 @@ print =============== drop database sql drop database d2 sql drop database d3 sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi -if $data00 != d4 then +if $data20 != d4 then return -1 endi -if $data02 != 4 then +if $data22 != 4 then return -1 endi -if $data03 != 0 then +if $data23 != 0 then return -1 endi @@ -154,7 +154,7 @@ system sh/exec.sh -n dnode1 -s start print =============== show databases sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi diff --git a/tests/script/tsim/db/basic2.sim b/tests/script/tsim/db/basic2.sim index e9222c8d320a0b77567fa67d100eb60ae35cd5f5..0d34506b009a4105c7cf5eb8fbdbff2e48f0ce24 100644 --- a/tests/script/tsim/db/basic2.sim +++ b/tests/script/tsim/db/basic2.sim @@ -33,15 +33,15 @@ sql show databases print rows: $rows print $data00 $data01 $data02 $data03 print $data10 $data11 $data12 $data13 -if $rows != 2 then +if $rows != 3 then return -1 endi -if $data00 != d1 then +if $data20 != d1 then return -1 endi -if $data02 != 2 then # vgroups +if $data22 != 2 then # vgroups return -1 endi @@ -62,7 +62,7 @@ sql create table t2 (ts timestamp, i int); sql create table t3 (ts timestamp, i int); sql show databases -if $rows != 3 then +if $rows != 4 then return -1 endi diff --git a/tests/script/tsim/db/basic3.sim b/tests/script/tsim/db/basic3.sim index 52a587cc16c1d49236cb32512e46383406b930ab..62d160f1c42c4f3674449582801f34359cad4eca 100644 --- a/tests/script/tsim/db/basic3.sim +++ b/tests/script/tsim/db/basic3.sim @@ -29,15 +29,15 @@ sql create table d1.t3 (ts timestamp, i int); sql create table d1.t4 (ts timestamp, i int); sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi -if $data00 != d1 then +if $data20 != d1 then return -1 endi -if $data02 != 2 then +if $data22 != 2 then return -1 endi @@ -57,7 +57,7 @@ sql create table d2.t2 (ts timestamp, i int); sql create table d2.t3 (ts timestamp, i int); sql show databases -if $rows != 3 then +if $rows != 4 then return -1 endi diff --git a/tests/script/tsim/db/basic6.sim b/tests/script/tsim/db/basic6.sim index a768a0da38c49cbd5f38a33e29fb3ffa43903bd8..4d0a1e9ee9c6f08632ed9fedbeabe04ad9ec498d 100644 --- a/tests/script/tsim/db/basic6.sim +++ b/tests/script/tsim/db/basic6.sim @@ -20,31 +20,31 @@ sql show databases print $data0_1 $data1_1 $data2_1 $data3_1 $data4_1 $data5_1 $data6_1 $data7_1 $data8_1 $data9_1 print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 -if $rows != 2 then +if $rows != 3 then return -1 endi -if $data00 != $db then +if $data20 != $db then return -1 endi -if $data02 != 8 then +if $data22 != 8 then return -1 endi -if $data03 != 0 then +if $data23 != 0 then return -1 endi -if $data04 != 1 then +if $data24 != 1 then return -1 endi -if $data06 != 2880 then +if $data26 != 2880 then return -1 endi -if $data07 != 3650,3650,3650 then +if $data27 != 3650,3650,3650 then return -1 endi -if $data08 != 32 then +if $data28 != 32 then return -1 endi -if $data09 != 12 then +if $data29 != 12 then return -1 endi @@ -52,14 +52,14 @@ print =============== step2 sql_error create database $db sql create database if not exists $db sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi print =============== step3 sql drop database $db sql show databases -if $rows != 1 then +if $rows != 2 then return -1 endi @@ -70,16 +70,16 @@ print =============== step5 sql create database $db replica 1 days 21600 keep 2160000 sql show databases print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 -if $data00 != $db then +if $data20 != $db then return -1 endi -if $data03 != 0 then +if $data23 != 0 then return -1 endi -if $data04 != 1 then +if $data24 != 1 then return -1 endi -if $data06 != 21600 then +if $data26 != 21600 then return -1 endi @@ -314,7 +314,7 @@ endi sql drop database $db sql show databases -if $rows != 0 then +if $rows != 2 then return -1 endi diff --git a/tests/script/tsim/db/create_all_options.sim b/tests/script/tsim/db/create_all_options.sim index 7f39474f4d93bb6c320811da61a6f6f853c3f4b0..4dda6cd00f3e77a864217e4ae722326a81d771e3 100644 --- a/tests/script/tsim/db/create_all_options.sim +++ b/tests/script/tsim/db/create_all_options.sim @@ -99,7 +99,7 @@ sql create database db sql show databases print rows: $rows print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db -if $rows != 2 then +if $rows != 3 then return -1 endi if $data0_db != db then # name @@ -112,6 +112,7 @@ if $data3_db != 0 then # ntables return -1 endi if $data4_db != 1 then # replica + print expect 1, actual: $data4_db return -1 endi if $data5_db != 1 then # quorum diff --git a/tests/script/tsim/db/error1.sim b/tests/script/tsim/db/error1.sim index 6f62228ae73d5dc34f908ed969c0f6ff15d62392..3460647bc9f3a9c1605624cdc65faf2eb4be7c69 100644 --- a/tests/script/tsim/db/error1.sim +++ b/tests/script/tsim/db/error1.sim @@ -42,19 +42,19 @@ re-create1: sql create database d1 vgroups 2 -x re-create1 sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi -if $data00 != d1 then +if $data20 != d1 then return -1 endi -if $data02 != 2 then +if $data22 != 2 then return -1 endi -if $data03 != 0 then +if $data23 != 0 then return -1 endi @@ -62,7 +62,7 @@ print ========== stop dnode2 system sh/exec.sh -n dnode2 -s stop -x SIGKILL sleep 1000 -print =============== create database +print =============== drop database sql_error drop database d1 print ========== start dnode2 @@ -81,19 +81,19 @@ re-create2: sql create database d1 vgroups 5 -x re-create2 sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi -if $data00 != d1 then +if $data20 != d1 then return -1 endi -if $data02 != 5 then +if $data22 != 5 then return -1 endi -if $data03 != 0 then +if $data23 != 0 then return -1 endi diff --git a/tests/script/tsim/dnode/basic1.sim b/tests/script/tsim/dnode/basic1.sim index 6f0d5f88b812c52f2e355ab51c63f9950df1d653..51399e905003f8ec00f21a9c7d0edc66fa7e469e 100644 --- a/tests/script/tsim/dnode/basic1.sim +++ b/tests/script/tsim/dnode/basic1.sim @@ -85,7 +85,7 @@ sql create database d1 vgroups 4; sql create database d2; sql show databases -if $rows != 3 then +if $rows != 4 then return -1 endi diff --git a/tests/script/tsim/insert/backquote.sim b/tests/script/tsim/insert/backquote.sim index 71f35fabb28f657f556b97d9d592a01bca1451c9..819b1aea13d74243c997a03d585e2c9163db635f 100644 --- a/tests/script/tsim/insert/backquote.sim +++ b/tests/script/tsim/insert/backquote.sim @@ -12,16 +12,16 @@ print rows: $rows print $data00 $data01 print $data10 $data11 print $data20 $data21 -if $rows != 3 then +if $rows != 4 then return -1 endi -if $data00 != database then +if $data20 != database then return -1 endi -if $data10 != DataBase then +if $data30 != DataBase then return -1 endi -if $data20 != information_schema then +if $data00 != information_schema then return -1 endi @@ -206,16 +206,16 @@ print rows: $rows print $data00 $data01 print $data10 $data11 print $data20 $data21 -if $rows != 3 then +if $rows != 4 then return -1 endi -if $data00 != database then +if $data20 != database then return -1 endi -if $data10 != DataBase then +if $data30 != DataBase then return -1 endi -if $data20 != information_schema then +if $data00 != information_schema then return -1 endi diff --git a/tests/script/tsim/insert/basic0.sim b/tests/script/tsim/insert/basic0.sim index da74eb95e81f95ea0dd7fcffab3706632a37ff88..1ae8b372dc4825c85d166346b1b4fb022a8f5fbf 100644 --- a/tests/script/tsim/insert/basic0.sim +++ b/tests/script/tsim/insert/basic0.sim @@ -7,7 +7,7 @@ sql connect print =============== create database sql create database d0 sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi diff --git a/tests/script/tsim/insert/basic1.sim b/tests/script/tsim/insert/basic1.sim index 3a3f8d000ebaabe5a4f8dd163bd47b23917aa770..d98407b380247cc43e1b641fcfe97914c09b2a15 100644 --- a/tests/script/tsim/insert/basic1.sim +++ b/tests/script/tsim/insert/basic1.sim @@ -7,7 +7,7 @@ sql connect print =============== create database sql create database d1 sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi diff --git a/tests/script/tsim/insert/null.sim b/tests/script/tsim/insert/null.sim index fbaef8cc94105b06c0b44b67ea23e57a2346c9cd..fab5335ac5badf03e0434fb8dbbae7a6550c9aa0 100644 --- a/tests/script/tsim/insert/null.sim +++ b/tests/script/tsim/insert/null.sim @@ -7,7 +7,7 @@ sql connect print =============== create database sql create database d0 sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi diff --git a/tests/script/tsim/mnode/basic1.sim b/tests/script/tsim/mnode/basic1.sim index 74ec44328d2cd5332044d2e23c19f1735041402c..e3d27d0c132d2f45838a1ac786d551be9bafac06 100644 --- a/tests/script/tsim/mnode/basic1.sim +++ b/tests/script/tsim/mnode/basic1.sim @@ -75,7 +75,6 @@ if $data02 != master then return -1 endi -return print =============== create drop mnode 1 sql_error create mnode on dnode 1 sql_error drop mnode on dnode 1 diff --git a/tests/script/tsim/parser/fourArithmetic-basic.sim b/tests/script/tsim/parser/fourArithmetic-basic.sim index bb35df5a906721e05a465f5736e8b4e253b167a9..ebe20924be6988728f67c0ca36bca9ebbfda3f48 100644 --- a/tests/script/tsim/parser/fourArithmetic-basic.sim +++ b/tests/script/tsim/parser/fourArithmetic-basic.sim @@ -28,7 +28,7 @@ print =============== create database sql create database $dbNamme vgroups 1 sql show databases print $data00 $data01 $data02 -if $rows != 2 then +if $rows != 3 then return -1 endi diff --git a/tests/script/tsim/query/charScalarFunction.sim b/tests/script/tsim/query/charScalarFunction.sim index 13108fecb7a651972f02ecd566721c67b4c8a0a3..046812599754b9832da716788342d96956cad5aa 100644 --- a/tests/script/tsim/query/charScalarFunction.sim +++ b/tests/script/tsim/query/charScalarFunction.sim @@ -83,6 +83,14 @@ sql insert into ntb5 values ("2022-01-01 00:00:00.000" , "0123456789" , "0123456 sql insert into ctb5 values ("2022-01-01 00:00:00.001" , NULL , NULL ) sql insert into ntb5 values ("2022-01-01 00:00:00.001" , NULL , NULL ) +sql create table stb3 (ts timestamp, c1 binary(64), c2 nchar(64), c3 nchar(64) ) tags (t1 nchar(64)) +sql create table ctb6 using stb3 tags("tag-nchar-6") +sql create table ntb6 (ts timestamp, c1 binary(64), c2 nchar(64), c3 nchar(64) ) +sql insert into ctb6 values ("2022-01-01 00:00:00.000" , "0123456789" , "中文测试1" , "中文测试2" ) +sql insert into ntb6 values ("2022-01-01 00:00:00.000" , "0123456789" , "中文测试01", "中文测试01" ) +sql insert into ctb6 values ("2022-01-01 00:00:00.001" , NULL , NULL, NULL ) +sql insert into ntb6 values ("2022-01-01 00:00:00.001" , NULL , NULL, NULL ) + $loop_test = 0 loop_test_pos: @@ -150,6 +158,210 @@ if $data01 != 12 then return -1 endi +print ====> select c2 ,length(c2), char_length(c2) from ctb6 +sql select c2 ,length(c2), char_length(c2) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 20 then + return -1 +endi +if $data02 != 5 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2 ,length(c2),char_length(c2) from ntb6 +sql select c2 ,length(c2),char_length(c2) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 24 then + return -1 +endi +if $data02 != 6 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2 ,lower(c2), upper(c2) from ctb6 +sql select c2 ,lower(c2), upper(c2) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 中文测试1 then + return -1 +endi +if $data02 != 中文测试1 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2 ,lower(c2), upper(c2) from ntb6 +sql select c2 ,lower(c2), upper(c2) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 中文测试01 then + return -1 +endi +if $data02 != 中文测试01 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2, ltrim(c2), ltrim(c2) from ctb6 +sql select c2, ltrim(c2), ltrim(c2) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 中文测试1 then + return -1 +endi +if $data02 != 中文测试1 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2, ltrim(c2), ltrim(c2) from ntb6 +sql select c2, ltrim(c2), ltrim(c2) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data01 != 中文测试01 then + return -1 +endi +if $data02 != 中文测试01 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +print ====> select c2, c3 , concat(c2,c3) from ctb6 +sql select c2, c3 , concat(c2,c3) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data02 != 中文测试1中文测试2 then + return -1 +endi +if $data12 != NULL then + return -1 +endi + +print ====> select c2, c3 , concat(c2,c3) from ntb6 +sql select c2, c3 , concat(c2,c3) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data02 != 中文测试01中文测试01 then + return -1 +endi +if $data12 != NULL then + return -1 +endi + +print ====> select c2, c3 , concat_ws('_', c2, c3) from ctb6 +sql select c2, c3 , concat_ws('_', c2, c3) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data02 != 中文测试1_中文测试2 then + return -1 +endi +# if $data12 != NULL then +# return -1 +# endi + +print ====> select c2, c3 , concat_ws('_', c2, c3) from ntb6 +sql select c2, c3 , concat_ws('_', c2, c3) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 $data02 +print ====> $data10 $data11 $data12 +if $rows != 2 then + return -1 +endi +if $data02 != 中文测试01_中文测试01 then + return -1 +endi +# if $data12 != NULL then +# return -1 +# endi + +print ====> select c2, substr(c2,1, 4) from ctb6 +sql select c2, substr(c2,1, 4) from ctb6 +print ====> rows: $rows +print ====> $data00 $data01 +print ====> $data10 $data11 +if $rows != 2 then + return -1 +endi +if $data00 != 中文测试1 then + return -1 +endi +if $data01 != 中文测试 then + return -1 +endi +# if $data11 != NULL then +# return -1 +# endi + +print ====> select c2, substr(c2,1, 4) from ntb6 +sql select c2, substr(c2,1, 4) from ntb6 +print ====> rows: $rows +print ====> $data00 $data01 +print ====> $data10 $data11 +if $rows != 2 then + return -1 +endi +if $data00 != 中文测试01 then + return -1 +endi +if $data01 != 中文测试 then + return -1 +endi +if $data11 != NULL then + return -1 +endi + #sql_error select c1, length(t1), c2, length(t2) from ctb0 print ====> char_length @@ -493,7 +705,7 @@ if $loop_test == 0 then print =============== stop and restart taosd system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s start - + $loop_cnt = 0 check_dnode_ready_0: $loop_cnt = $loop_cnt + 1 @@ -511,7 +723,7 @@ if $loop_test == 0 then goto check_dnode_ready_0 endi - $loop_test = 1 + $loop_test = 1 goto loop_test_pos endi diff --git a/tests/script/tsim/query/complex_group.sim b/tests/script/tsim/query/complex_group.sim new file mode 100644 index 0000000000000000000000000000000000000000..6c9a7c5a7a96c1b8572c1abde35d7a6964a38cc3 --- /dev/null +++ b/tests/script/tsim/query/complex_group.sim @@ -0,0 +1,476 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database +sql create database db +sql show databases +if $rows != 3 then + return -1 +endi + +sql use db + +print =============== create super table and child table +sql create table stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) +sql show stables +print $rows $data00 $data01 $data02 +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb1 tags ( 1 ) +sql create table ct2 using stb1 tags ( 2 ) +sql create table ct3 using stb1 tags ( 3 ) +sql create table ct4 using stb1 tags ( 4 ) +sql show tables +print $rows $data00 $data10 $data20 +if $rows != 4 then + return -1 +endi + +print =============== insert data into child table ct1 (s) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+7a ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+8a ) + +print =============== insert data into child table ct2 (d) +sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+6a ) +sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+7a ) + +print =============== insert data into child table ct3 (n) +sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + +print =============== insert data into child table ct4 (y) +sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct4 values ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct4 values ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) +sql insert into ct4 values ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + +print ================ start query ====================== + + +print ================ query 1 group by filter +sql select count(*) from ct3 group by c1 +print ====> sql : select count(*) from ct3 group by c1 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +sql select count(*) from ct3 group by c2 +print ====> sql : select count(*) from ct3 group by c2 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +sql select count(*) from ct3 group by c3 +print ====> sql : select count(*) from ct3 group by c3 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +sql select count(*) from ct3 group by c4 +print ====> sql : select count(*) from ct3 group by c4 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +sql select count(*) from ct3 group by c5 +print ====> sql : select count(*) from ct3 group by c5 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +sql select count(*) from ct3 group by c6 +print ====> sql : select count(*) from ct3 group by c6 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +sql select count(*) from ct3 group by c7 +print ====> sql : select count(*) from ct3 group by c7 +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql select count(*) from ct3 group by c8 +print ====> sql : select count(*) from ct3 group by c8 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +sql select count(*) from ct3 group by c9 +print ====> sql : select count(*) from ct3 group by c9 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +sql select count(*) from ct3 group by c10 +print ====> sql : select count(*) from ct3 group by c10 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +print ================ query 2 complex with group by +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +#================================================= +print =============== stop and restart taosd +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready_0 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +print ================ query 1 group by filter +sql select count(*) from ct3 group by c1 +print ====> sql : select count(*) from ct3 group by c1 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +sql select count(*) from ct3 group by c2 +print ====> sql : select count(*) from ct3 group by c2 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +sql select count(*) from ct3 group by c3 +print ====> sql : select count(*) from ct3 group by c3 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +sql select count(*) from ct3 group by c4 +print ====> sql : select count(*) from ct3 group by c4 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +sql select count(*) from ct3 group by c5 +print ====> sql : select count(*) from ct3 group by c5 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +sql select count(*) from ct3 group by c6 +print ====> sql : select count(*) from ct3 group by c6 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +sql select count(*) from ct3 group by c7 +print ====> sql : select count(*) from ct3 group by c7 +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql select count(*) from ct3 group by c8 +print ====> sql : select count(*) from ct3 group by c8 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +sql select count(*) from ct3 group by c9 +print ====> sql : select count(*) from ct3 group by c9 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +sql select count(*) from ct3 group by c10 +print ====> sql : select count(*) from ct3 group by c10 +print ====> rows: $rows +if $rows != 9 then + return -1 +endi + +print ================ query 2 complex with group by +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/query/complex_having.sim b/tests/script/tsim/query/complex_having.sim new file mode 100644 index 0000000000000000000000000000000000000000..86d4f7d4ca109035f1f9420debf449d18a5f89b9 --- /dev/null +++ b/tests/script/tsim/query/complex_having.sim @@ -0,0 +1,386 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database +sql create database db +sql show databases +if $rows != 3 then + return -1 +endi + +sql use db + +print =============== create super table and child table +sql create table stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) +sql show stables +print $rows $data00 $data01 $data02 +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb1 tags ( 1 ) +sql create table ct2 using stb1 tags ( 2 ) +sql create table ct3 using stb1 tags ( 3 ) +sql create table ct4 using stb1 tags ( 4 ) +sql show tables +print $rows $data00 $data10 $data20 +if $rows != 4 then + return -1 +endi + +print =============== insert data into child table ct1 (s) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+7a ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+8a ) + +print =============== insert data into child table ct4 (y) +sql insert into ct4 values ( '2019-01-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct4 values ( '2019-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct4 values ( '2019-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct4 values ( '2020-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct4 values ( '2020-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct4 values ( '2020-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct4 values ( '2020-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct4 values ( '2021-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct4 values ( '2021-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct4 values ( '2021-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) +sql insert into ct4 values ( '2022-02-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) +sql insert into ct4 values ( '2022-05-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + + +print ================ start query ====================== + +print ================ query 1 having condition +sql select c1 from ct1 group by c1 having count(c1) +sql select c1 from ct4 group by c1 having count(c1) +sql select count(c1) from ct1 group by c1 having count(c1) + +sql select sum(c1) ,count(c7) from ct4 group by c7 having count(c7) > 1 ; +print ====> sql : select sum(c1) ,count(c7) from ct4 group by c7 having count(c7) > 1 ; +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select sum(c1) ,count(c7) from ct4 group by c7 having count(c1) < sum(c1) ; +print ====> sql : select sum(c1) ,count(c7) from ct4 group by c7 having count(c7) > 1 ; +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 2 and sum(c1) > 2 ; +print ====> sql : select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 2 and sum(c1) > 2 ; +print ====> rows: $rows +if $rows != 7 then + return -1 +endi + +sql select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 1 or sum(c1) > 2 ; +print ====> sql : select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 1 or sum(c1) > 2 ; +print ====> rows: $rows +if $rows != 7 then + return -1 +endi + + +print ================ query 1 complex with having condition + +sql select count(c1) from ct4 where c1 > 2 group by c7 having count(c1) > 1 limit 1 offset 0 +print ====> sql : select count(c1) from ct4 where c1 > 2 group by c7 having count(c1) > 1 limit 1 offset 0 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select abs(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select acos(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select asin(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select atan(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select cos(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select floor(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select round(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select sin(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select tan(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 20 then + return -1 +endi + +#================================================= +print =============== stop and restart taosd +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready_0 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 20 then + return -1 +endi + +print ================ query 1 having condition +sql select c1 from ct1 group by c1 having count(c1) +sql select c1 from ct4 group by c1 having count(c1) +sql select count(c1) from ct1 group by c1 having count(c1) + +sql select sum(c1) ,count(c7) from ct4 group by c7 having count(c7) > 1 ; +print ====> sql : select sum(c1) ,count(c7) from ct4 group by c7 having count(c7) > 1 ; +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select sum(c1) ,count(c7) from ct4 group by c7 having count(c1) < sum(c1) ; +print ====> sql : select sum(c1) ,count(c7) from ct4 group by c7 having count(c7) > 1 ; +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 2 and sum(c1) > 2 ; +print ====> sql : select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 2 and sum(c1) > 2 ; +print ====> rows: $rows +if $rows != 7 then + return -1 +endi + +sql select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 1 or sum(c1) > 2 ; +print ====> sql : select sum(c1) ,count(c1) from ct4 group by c1 having count(c7) < 1 or sum(c1) > 2 ; +print ====> rows: $rows +if $rows != 7 then + return -1 +endi + + +print ================ query 1 complex with having condition + +sql select count(c1) from ct4 where c1 > 2 group by c7 having count(c1) > 1 limit 1 offset 0 +print ====> sql : select count(c1) from ct4 where c1 > 2 group by c7 having count(c1) > 1 limit 1 offset 0 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select abs(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select acos(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select asin(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select atan(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select cos(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select floor(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select round(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select sin(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct4 where c1 > 2 group by c1 having abs(c1) > 1 limit 1 offset 1 +print ====> sql : select tan(c1) from ct4 where c1 > 2 group by c7 having abs(c1) > 1 limit 1 offset 1 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/query/complex_limit.sim b/tests/script/tsim/query/complex_limit.sim new file mode 100644 index 0000000000000000000000000000000000000000..1691f2d443a70cd7124e9cc53a63f633b3cf3b40 --- /dev/null +++ b/tests/script/tsim/query/complex_limit.sim @@ -0,0 +1,530 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database +sql create database db +sql use db + +print =============== create super table and child table +sql create table stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) +sql show stables +print $rows $data00 $data01 $data02 +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb1 tags ( 1 ) +sql create table ct2 using stb1 tags ( 2 ) +sql create table ct3 using stb1 tags ( 3 ) +sql create table ct4 using stb1 tags ( 4 ) +sql show tables +print $rows $data00 $data10 $data20 +if $rows != 4 then + return -1 +endi + +print =============== insert data into child table ct1 (s) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+7a ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+8a ) + +print =============== insert data into child table ct2 (d) +sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+6a ) +sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+7a ) + +print =============== insert data into child table ct3 (n) +sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + +print =============== insert data into child table ct4 (y) +sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct4 values ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct4 values ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) +sql insert into ct4 values ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + +print ================ start query ====================== +print ================ query 1 limit/offset +sql select * from ct1 limit 1 +print ====> sql : select * from ct1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi + +sql select * from ct1 limit 9 +print ====> sql : select * from ct1 limit 9 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct1 limit 1 offset 2 +print ====> sql : select * from ct1 limit 1 offset 2 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi + +sql select * from ct1 limit 2 offset 1 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi +if $data01 != 8 then + return -1 +endi + +sql select * from ct1 limit 2 offset 7 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data11 != 3 then + return -1 +endi + +sql select * from ct1 limit 2 offset 10 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + +sql select c1 from stb1 limit 1 +print ====> sql : select c1 from stb1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 50 +print ====> sql : select c1 from stb1 limit 50 +print ====> rows: $rows +if $rows != 33 then + return -1 +endi + +sql select c1 from stb1 limit 1 offset 2 +print ====> sql : select c1 from stb1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 1 +print ====> sql : select c1 from stb1 limit 2 offset 1 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 32 +print ====> sql : select c1 from stb1 limit 2 offset 32 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 40 +print ====> sql : select c1 from stb1 limit 2 offset 40 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + + +print ================ query 2 complex with limit +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +#================================================= +print =============== stop and restart taosd +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready_0 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +print ================ query 1 limit/offset +sql select * from ct1 limit 1 +print ====> sql : select * from ct1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi + +sql select * from ct1 limit 9 +print ====> sql : select * from ct1 limit 9 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct1 limit 1 offset 2 +print ====> sql : select * from ct1 limit 1 offset 2 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi + +sql select * from ct1 limit 2 offset 1 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi +if $data01 != 8 then + return -1 +endi + +sql select * from ct1 limit 2 offset 7 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data11 != 3 then + return -1 +endi + +sql select * from ct1 limit 2 offset 10 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + +sql select c1 from stb1 limit 1 +print ====> sql : select c1 from stb1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 50 +print ====> sql : select c1 from stb1 limit 50 +print ====> rows: $rows +if $rows != 33 then + return -1 +endi + +sql select c1 from stb1 limit 1 offset 2 +print ====> sql : select c1 from stb1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 1 +print ====> sql : select c1 from stb1 limit 2 offset 1 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 32 +print ====> sql : select c1 from stb1 limit 2 offset 32 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 40 +print ====> sql : select c1 from stb1 limit 2 offset 40 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + + +print ================ query 2 complex with limit +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/query/complex_select.sim b/tests/script/tsim/query/complex_select.sim new file mode 100644 index 0000000000000000000000000000000000000000..1ebcb2f49a2c2ee3aa3e6b42efa9e8e70fccb1d6 --- /dev/null +++ b/tests/script/tsim/query/complex_select.sim @@ -0,0 +1,580 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database +sql create database db +sql use db + +print =============== create super table and child table +sql create table stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) +sql show stables +print $rows $data00 $data01 $data02 +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb1 tags ( 1 ) +sql create table ct2 using stb1 tags ( 2 ) +sql create table ct3 using stb1 tags ( 3 ) +sql create table ct4 using stb1 tags ( 4 ) +sql show tables +print $rows $data00 $data10 $data20 +if $rows != 4 then + return -1 +endi + +print =============== insert data into child table ct1 (s) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+7a ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+8a ) + +print =============== insert data into child table ct2 (d) +sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+6a ) +sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+7a ) + +print =============== insert data into child table ct3 (n) +sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + +print =============== insert data into child table ct4 (y) +sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct4 values ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct4 values ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) +sql insert into ct4 values ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + +print ================ start query ====================== +print ================ query 1 limit/offset +sql select * from ct1 limit 1 +print ====> sql : select * from ct1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi + +sql select * from ct1 limit 9 +print ====> sql : select * from ct1 limit 9 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct1 limit 1 offset 2 +print ====> sql : select * from ct1 limit 1 offset 2 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 3 then + return -1 +endi + +sql select * from ct1 limit 2 offset 7 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi +if $data01 != 8 then + return -1 +endi + +sql select * from ct1 limit 2 offset 7 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data11 != 3 then + return -1 +endi + +sql select * from ct1 limit 2 offset 10 +print ====> sql : select * from ct1 limit 2 offset 7 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + +sql select c1 from stb1 limit 1 +print ====> sql : select c1 from stb1 limit 1 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 50 +print ====> sql : select c1 from stb1 limit 50 +print ====> rows: $rows +if $rows != 33 then + return -1 +endi + +sql select c1 from stb1 limit 1 offset 2 +print ====> sql : select c1 from stb1 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 1 +print ====> sql : select c1 from stb1 limit 2 offset 1 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 32 +print ====> sql : select c1 from stb1 limit 2 offset 32 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select c1 from stb1 limit 2 offset 40 +print ====> sql : select c1 from stb1 limit 2 offset 40 +print ====> rows: $rows +if $rows != 0 then + return -1 +endi + +print ================ query 2 where condition +sql select * from ct3 where c1 < 5 +print ====> sql : select * from ct3 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 > 5 and c1 <= 6 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 8 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> sql : select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +sql_error select ts from ct3 where ts != 0 +sql select * from ct3 where ts <> 0 +print ====> sql : select * from ct3 where ts <> 0 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c1 between 1 and 3 +print ====> sql : select * from ct3 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql_error select * from ct3 where c7 between false and true + +sql select * from ct3 where c1 in (1,2,3) +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql select * from ct3 where c1 in (‘true','false') +print ====> sql : select * from ct3 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c9 like "_char_" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c8 like "bi%" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select c1 from stb1 where c1 < 5 +print ====> sql : select c1 from stb1 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 16 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select c1 from stb1 where stb1 > 5 and c1 <= 6 +print ====> sql : select c1 from stb1 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 4 then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : sselect c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 32 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> sql : select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 17 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +sql_error select ts from stb1 where ts != 0 +sql select c1 from stb1 where ts <> 0 +print ====> sql : select c1 from stb1 where ts <> 0 +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c1 between 1 and 3 +print ====> sql : select c1 from stb1 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql_error select c1 from stb1 where c7 between false and true + +sql select c1 from stb1 where c1 in (1,2,3) +print ====> sql : select c1 from stb1 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql select c1 from stb1 where c1 in (‘true','false') +print ====> sql : select c1 from stb1 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c9 like "_char_" +print ====> sql : select c1 from stb1 where c9 like "_char_" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c8 like "bi%" +print ====> sql : select c1 from stb1 where c8 like "bi%" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + + +print ================ query 3 group by filter +sql select count(*) from ct3 group by c1 +print ====> sql : select count(*) from ct3 group by c1 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c2 +print ====> sql : select count(*) from ct3 group by c2 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c3 +print ====> sql : select count(*) from ct3 group by c3 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c4 +print ====> sql : select count(*) from ct3 group by c4 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c5 +print ====> sql : select count(*) from ct3 group by c5 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c6 +print ====> sql : select count(*) from ct3 group by c6 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c7 +print ====> sql : select count(*) from ct3 group by c7 +print ====> rows: $rows +if $rows != 2 then + return -1 +endi + +sql select count(*) from ct3 group by c8 +print ====> sql : select count(*) from ct3 group by c8 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c9 +print ====> sql : select count(*) from ct3 group by c9 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select count(*) from ct3 group by c10 +print ====> sql : select count(*) from ct3 group by c10 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +print ================ query 4 scalar function + where + group by + limit/offset +sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +#================================================= +print =============== stop and restart taosd +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready_0 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/query/complex_where.sim b/tests/script/tsim/query/complex_where.sim new file mode 100644 index 0000000000000000000000000000000000000000..7cd576400f544379d50c7b777a701abefed4950b --- /dev/null +++ b/tests/script/tsim/query/complex_where.sim @@ -0,0 +1,691 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +print =============== create database +sql create database db +sql show databases +if $rows != 3 then + return -1 +endi + +sql use db + +print =============== create super table and child table +sql create table stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) +sql show stables +print $rows $data00 $data01 $data02 +if $rows != 1 then + return -1 +endi + +sql create table ct1 using stb1 tags ( 1 ) +sql create table ct2 using stb1 tags ( 2 ) +sql create table ct3 using stb1 tags ( 3 ) +sql create table ct4 using stb1 tags ( 4 ) +sql show tables +print $rows $data00 $data10 $data20 +if $rows != 4 then + return -1 +endi + +print =============== insert data into child table ct1 (s) +sql insert into ct1 values ( '2022-01-01 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct1 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct1 values ( '2022-01-01 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct1 values ( '2022-01-01 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct1 values ( '2022-01-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct1 values ( '2022-01-01 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct1 values ( '2022-01-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+7a ) +sql insert into ct1 values ( '2022-01-01 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+8a ) + +print =============== insert data into child table ct2 (d) +sql insert into ct2 values ( '2022-01-01 01:00:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct2 values ( '2022-01-01 10:00:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct2 values ( '2022-01-01 20:00:01.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct2 values ( '2022-01-02 10:00:01.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct2 values ( '2022-01-02 20:00:01.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct2 values ( '2022-01-03 10:00:01.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", now+6a ) +sql insert into ct2 values ( '2022-01-03 20:00:01.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", now+7a ) + +print =============== insert data into child table ct3 (n) +sql insert into ct3 values ( '2021-12-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) +sql insert into ct3 values ( '2021-12-31 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct3 values ( '2022-01-01 01:01:06.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct3 values ( '2022-01-07 01:01:10.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct3 values ( '2022-01-31 01:01:16.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct3 values ( '2022-02-01 01:01:20.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct3 values ( '2022-02-28 01:01:26.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct3 values ( '2022-03-01 01:01:30.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct3 values ( '2022-03-08 01:01:36.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + +print =============== insert data into child table ct4 (y) +sql insert into ct4 values ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now+1a ) +sql insert into ct4 values ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now+2a ) +sql insert into ct4 values ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now+3a ) +sql insert into ct4 values ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now+4a ) +sql insert into ct4 values ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now+5a ) +sql insert into ct4 values ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now+6a ) +sql insert into ct4 values ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) +sql insert into ct4 values ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) +sql insert into ct4 values ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + +print ================ start query ====================== +print ================ query 1 where condition +sql select * from ct3 where c1 < 5 +print ====> sql : select * from ct3 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 > 5 and c1 <= 6 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 8 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> sql : select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +sql_error select ts from ct3 where ts != 0 +sql select * from ct3 where ts <> 0 +print ====> sql : select * from ct3 where ts <> 0 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c1 between 1 and 3 +print ====> sql : select * from ct3 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql_error select * from ct3 where c7 between false and true + +sql select * from ct3 where c1 in (1,2,3) +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql select * from ct3 where c1 in (‘true','false') +print ====> sql : select * from ct3 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c9 like "_char_" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c8 like "bi%" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select c1 from stb1 where c1 < 5 +print ====> sql : select c1 from stb1 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 16 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select c1 from stb1 where c1 > 5 and c1 <= 6 +print ====> sql : select c1 from stb1 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 3 then + return -1 +endi +if $data00 != 6 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : sselect c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 32 then + return -1 +endi +if $data00 != 1 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> sql : select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 17 then + return -1 +endi +if $data00 != 5 then + return -1 +endi + +sql_error select ts from stb1 where ts != 0 +sql select c1 from stb1 where ts <> 0 +print ====> sql : select c1 from stb1 where ts <> 0 +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c1 between 1 and 3 +print ====> sql : select c1 from stb1 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql select c1 from stb1 where c7 between false and true + +sql select c1 from stb1 where c1 in (1,2,3) +print ====> sql : select c1 from stb1 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql select c1 from stb1 where c1 in (‘true','false') +print ====> sql : select c1 from stb1 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c9 like "_char_" +print ====> sql : select c1 from stb1 where c9 like "_char_" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c8 like "bi%" +print ====> sql : select c1 from stb1 where c8 like "bi%" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + + +print ================ query 2 complex with where +sql select count(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +#================================================= +print =============== stop and restart taosd +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready_0: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi + +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready_0 +endi + +print =================== count all rows +sql select count(c1) from stb1 +print ====> sql : select count(c1) from stb1 +print ====> rows: $data00 +if $data00 != 33 then + return -1 +endi + +print ================ query 1 where condition +sql select * from ct3 where c1 < 5 +print ====> sql : select * from ct3 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 > 5 and c1 <= 6 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 1 then + return -1 +endi +if $data01 != 6 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : select * from ct3 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 8 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> sql : select * from ct3 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06, $data07, $data08, $data09 +if $rows != 4 then + return -1 +endi +if $data01 != 5 then + return -1 +endi + +sql_error select ts from ct3 where ts != 0 +sql select * from ct3 where ts <> 0 +print ====> sql : select * from ct3 where ts <> 0 +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c1 between 1 and 3 +print ====> sql : select * from ct3 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql_error select * from ct3 where c7 between false and true + +sql select * from ct3 where c1 in (1,2,3) +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 3 then + return -1 +endi + +sql select * from ct3 where c1 in (‘true','false') +print ====> sql : select * from ct3 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c9 like "_char_" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select * from ct3 where c8 like "bi%" +print ====> sql : select * from ct3 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 8 then + return -1 +endi + +sql select c1 from stb1 where c1 < 5 +print ====> sql : select c1 from stb1 where c1 < 5 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 16 then + return -1 +endi +if $data01 != 1 then + return -1 +endi + +sql select c1 from stb1 where c1 > 5 and c1 <= 6 +print ====> sql : select c1 from stb1 where c1 > 5 and c1 <= 6 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 3 then + return -1 +endi +if $data00 != 6 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> sql : sselect c1 from stb1 where c1 >= 5 or c1 != 4 or c1 <> 3 or c1 = 2 +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 32 then + return -1 +endi +if $data00 != 1 then + return -1 +endi + +sql select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> sql : select c1 from stb1 where c1 >= 5 and c1 is not NULL +print ====> rows: $rows +print ====> rows0: $data00 +if $rows != 17 then + return -1 +endi +if $data00 != 5 then + return -1 +endi + +sql_error select ts from stb1 where ts != 0 +sql select c1 from stb1 where ts <> 0 +print ====> sql : select c1 from stb1 where ts <> 0 +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c1 between 1 and 3 +print ====> sql : select c1 from stb1 where c1 between 1 and 3 +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql select c1 from stb1 where c7 between false and true + +sql select c1 from stb1 where c1 in (1,2,3) +print ====> sql : select c1 from stb1 where c1 in (1,2,3) +print ====> rows: $rows +if $rows != 12 then + return -1 +endi + +sql select c1 from stb1 where c1 in (‘true','false') +print ====> sql : select c1 from stb1 where c1 in (‘true','false') +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c9 like "_char_" +print ====> sql : select c1 from stb1 where c9 like "_char_" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + +sql select c1 from stb1 where c8 like "bi%" +print ====> sql : select c1 from stb1 where c8 like "bi%" +print ====> rows: $rows +if $rows != 32 then + return -1 +endi + + +print ================ query 2 complex with where +sql select count(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select abs(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select acos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select asin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select atan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select ceil(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select cos(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select floor(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select log(c1,10) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select pow(c1,3) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select round(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sqrt(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select sin(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +sql select tan(c1) from ct3 where c1 > 2 group by c1 limit 1 offset 1 +print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +print ====> rows: $rows +if $rows != 1 then + return -1 +endi + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/tsim/query/diff.sim b/tests/script/tsim/query/diff.sim index ebbd4709441e589507d077f8c3fc4fcc3a09f420..7bfeeeba7fd856392cbb0e46331d22a4fba31c41 100644 --- a/tests/script/tsim/query/diff.sim +++ b/tests/script/tsim/query/diff.sim @@ -63,20 +63,21 @@ print =============== step2 $i = 1 $tb = $tbPrefix . $i -print ===> select diff(tbcol) from $tb -sql select diff(tbcol) from $tb +print ===> select _rowts, diff(tbcol) from $tb +sql select _rowts, diff(tbcol) from $tb print ===> rows: $rows print ===> $data00 $data01 $data02 $data03 $data04 $data05 print ===> $data10 $data11 $data12 $data13 $data14 $data15 -if $data11 != 1 then +if $data11 != 1 then + print expect 1, actual: $data11 return -1 endi print =============== step3 $cc = 4 * 60000 $ms = 1601481600000 + $cc -print ===> select diff(tbcol) from $tb where ts > $ms -sql select diff(tbcol) from $tb where ts > $ms +print ===> select _rowts, diff(tbcol) from $tb where ts > $ms +sql select _rowts, diff(tbcol) from $tb where ts > $ms print ===> rows: $rows print ===> $data00 $data01 $data02 $data03 $data04 $data05 print ===> $data10 $data11 $data12 $data13 $data14 $data15 @@ -86,8 +87,8 @@ endi $cc = 4 * 60000 $ms = 1601481600000 + $cc -print ===> select diff(tbcol) from $tb where ts <= $ms -sql select diff(tbcol) from $tb where ts <= $ms +print ===> select _rowts, diff(tbcol) from $tb where ts <= $ms +sql select _rowts, diff(tbcol) from $tb where ts <= $ms print ===> rows: $rows print ===> $data00 $data01 $data02 $data03 $data04 $data05 print ===> $data10 $data11 $data12 $data13 $data14 $data15 @@ -96,8 +97,8 @@ if $data11 != 1 then endi print =============== step4 -print ===> select diff(tbcol) as b from $tb -sql select diff(tbcol) as b from $tb +print ===> select _rowts, diff(tbcol) as b from $tb +sql select _rowts, diff(tbcol) as b from $tb print ===> rows: $rows print ===> $data00 $data01 $data02 $data03 $data04 $data05 print ===> $data10 $data11 $data12 $data13 $data14 $data15 @@ -105,24 +106,24 @@ if $data11 != 1 then return -1 endi -print =============== step5 -print ===> select diff(tbcol) as b from $tb interval(1m) -sql select diff(tbcol) as b from $tb interval(1m) -x step5 - return -1 -step5: - -print =============== step6 -$cc = 4 * 60000 -$ms = 1601481600000 + $cc -print ===> select diff(tbcol) as b from $tb where ts <= $ms interval(1m) -sql select diff(tbcol) as b from $tb where ts <= $ms interval(1m) -x step6 - return -1 +#print =============== step5 +#print ===> select diff(tbcol) as b from $tb interval(1m) +#sql select diff(tbcol) as b from $tb interval(1m) -x step5 +# return -1 +#step5: +# +#print =============== step6 +#$cc = 4 * 60000 +#$ms = 1601481600000 + $cc +#print ===> select diff(tbcol) as b from $tb where ts <= $ms interval(1m) +#sql select diff(tbcol) as b from $tb where ts <= $ms interval(1m) -x step6 +# return -1 step6: print =============== clear sql drop database $db sql show databases -if $rows != 0 then +if $rows != 2 then return -1 endi diff --git a/tests/script/tsim/query/explain.sim b/tests/script/tsim/query/explain.sim new file mode 100644 index 0000000000000000000000000000000000000000..3358b24e838a219f49b2ef5a1151d69e2eae0eb0 --- /dev/null +++ b/tests/script/tsim/query/explain.sim @@ -0,0 +1,102 @@ +system sh/stop_dnodes.sh + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c wallevel -v 2 +system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1 + +print ========= start dnode1 as master +system sh/exec.sh -n dnode1 -s start +sleep 2000 +sql connect + +print ======== step1 +sql create database db1 vgroups 3; +sql use db1; +sql show databases; +sql create stable st1 (ts timestamp, f1 int, f2 binary(200)) tags(t1 int); +sql create stable st2 (ts timestamp, f1 int, f2 binary(200)) tags(t1 int); +sql create table tb1 using st1 tags(1); +sql insert into tb1 values (now, 1, "Hash Join (cost=230.47..713.98 rows=101 width=488) (actual time=0.711..7.427 rows=100 loops=1)"); + +sql create table tb2 using st1 tags(2); +sql insert into tb2 values (now, 2, "Seq Scan on tenk2 t2 (cost=0.00..445.00 rows=10000 width=244) (actual time=0.007..2.583 rows=10000 loops=1)"); +sql create table tb3 using st1 tags(3); +sql insert into tb3 values (now, 3, "Hash (cost=229.20..229.20 rows=101 width=244) (actual time=0.659..0.659 rows=100 loops=1)"); +sql create table tb4 using st1 tags(4); +sql insert into tb4 values (now, 4, "Bitmap Heap Scan on tenk1 t1 (cost=5.07..229.20 rows=101 width=244) (actual time=0.080..0.526 rows=100 loops=1)"); + +sql create table tb1 using st2 tags(1); +sql insert into tb1 values (now, 1, "Hash Join (cost=230.47..713.98 rows=101 width=488) (actual time=0.711..7.427 rows=100 loops=1)"); + +sql create table tb2 using st2 tags(2); +sql insert into tb2 values (now, 2, "Seq Scan on tenk2 t2 (cost=0.00..445.00 rows=10000 width=244) (actual time=0.007..2.583 rows=10000 loops=1)"); +sql create table tb3 using st2 tags(3); +sql insert into tb3 values (now, 3, "Hash (cost=229.20..229.20 rows=101 width=244) (actual time=0.659..0.659 rows=100 loops=1)"); +sql create table tb4 using st2 tags(4); +sql insert into tb4 values (now, 4, "Bitmap Heap Scan on tenk1 t1 (cost=5.07..229.20 rows=101 width=244) (actual time=0.080..0.526 rows=100 loops=1)"); + + +print ======== step2 +sql explain select * from st1 where -2; +sql explain select ts from tb1; +sql explain select * from st1; +sql explain select * from st1 order by ts; +sql explain select * from information_schema.user_stables; +sql explain select count(*),sum(f1) from tb1; +sql explain select count(*),sum(f1) from st1; +sql explain select count(*),sum(f1) from st1 group by f1; +sql explain select count(f1) from tb1 interval(1s, 2d) sliding(3s) fill(prev); +sql explain select min(f1) from st1 interval(1m, 2a) sliding(3n); + +print ======== step3 +sql explain verbose true select * from st1 where -2; +sql explain verbose true select ts from tb1 where f1 > 0; +sql explain verbose true select * from st1 where f1 > 0 and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00'; +sql explain verbose true select * from information_schema.user_stables where db_name='db2'; +sql explain verbose true select count(*),sum(f1) from st1 where f1 > 0 and ts > '2021-10-31 00:00:00' group by f1 having sum(f1) > 0; + +print ======== step4 +sql explain analyze select ts from st1 where -2; +sql explain analyze select ts from tb1; +sql explain analyze select ts from st1; +sql explain analyze select ts from st1; +sql explain analyze select ts from st1 order by ts; +sql explain analyze select * from information_schema.user_stables; +sql explain analyze select count(*),sum(f1) from tb1; +sql explain analyze select count(*),sum(f1) from st1; +sql explain analyze select count(*),sum(f1) from st1 group by f1; +sql explain analyze select count(f1) from tb1 interval(1s, 2d) sliding(3s) fill(prev); +sql explain analyze select min(f1) from st1 interval(3n, 2a) sliding(1n); + +print ======== step5 +sql explain analyze verbose true select ts from st1 where -2; +sql explain analyze verbose true select ts from tb1; +sql explain analyze verbose true select ts from st1; +sql explain analyze verbose true select ts from st1; +sql explain analyze verbose true select ts from st1 order by ts; +sql explain analyze verbose true select * from information_schema.user_stables; +sql explain analyze verbose true select count(*),sum(f1) from tb1; +sql explain analyze verbose true select count(*),sum(f1) from st1; +sql explain analyze verbose true select count(*),sum(f1) from st1 group by f1; +sql explain analyze verbose true select count(f1) from tb1 interval(1s, 2d) sliding(3s) fill(prev); +sql explain analyze verbose true select ts from tb1 where f1 > 0; +sql explain analyze verbose true select f1 from st1 where f1 > 0 and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00'; +sql explain analyze verbose true select * from information_schema.user_stables where db_name='db2'; +sql explain analyze verbose true select count(*),sum(f1) from st1 where f1 > 0 and ts > '2021-10-31 00:00:00' group by f1 having sum(f1) > 0; +sql explain analyze verbose true select min(f1) from st1 interval(3n, 2a) sliding(1n); +sql explain analyze verbose true select * from (select min(f1),count(*) a from st1 where f1 > 0) where a < 0; + +#not pass case +#sql explain verbose true select count(*),sum(f1) as aa from tb1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' order by aa; +#sql explain verbose true select * from st1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' order by ts; +#sql explain verbose true select count(*),sum(f1) from st1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' order by ts; +#sql explain verbose true select count(f1) from tb1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' interval(1s, 2d) sliding(3s) order by ts; +#sql explain verbose true select min(f1) from st1 where (f1 > 0 or f1 < -1) and ts > '2020-10-31 00:00:00' and ts < '2021-10-31 00:00:00' interval(1m, 2a) sliding(3n) fill(linear) order by ts; +#sql explain select max(f1) from tb1 SESSION(ts, 1s); +#sql explain select max(f1) from st1 SESSION(ts, 1s); +#sql explain select * from tb1, tb2 where tb1.ts=tb2.ts; +#sql explain select * from st1, st2 where tb1.ts=tb2.ts; +#sql explain analyze verbose true select sum(a+b) from (select _rowts, min(f1) b,count(*) a from st1 where f1 > 0 interval(1a)) where a < 0 interval(1s); + + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/query/interval-offset.sim b/tests/script/tsim/query/interval-offset.sim index 796944745a015dae93488b427d909b309c969d2e..e222077fa43ecdff80d99011dfef99f83ca8d694 100644 --- a/tests/script/tsim/query/interval-offset.sim +++ b/tests/script/tsim/query/interval-offset.sim @@ -6,11 +6,6 @@ sql connect print =============== create database sql create database d0 -sql show databases -if $rows != 2 then - return -1 -endi - sql use d0 print =============== create super table and child table diff --git a/tests/script/tsim/query/session.sim b/tests/script/tsim/query/session.sim index c1d3437e4a80fa5d5760280f266f52518af18b3d..3aee8386257b316f3c1d9f93af8d5b1b0d97ecb3 100644 --- a/tests/script/tsim/query/session.sim +++ b/tests/script/tsim/query/session.sim @@ -77,6 +77,8 @@ sql INSERT INTO dev_002 VALUES('2020-05-13 10:00:00.51', 7) $loop_test = 0 loop_test_pos: +sql use $dbNamme + # session(ts,5a) print ====> select count(*) from dev_001 session(ts,5a) sql select _wstartts, count(*) from dev_001 session(ts,5a) @@ -98,15 +100,15 @@ if $data01 != 2 then return -1 endi - -print ====> select count(*) from (select * from dev_001) session(ts,5a) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,5a) -if $rows != 15 then - return -1 -endi -if $data01 != 2 then - return -1 -endi +# +#print ====> select count(*) from (select * from dev_001) session(ts,5a) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,5a) +#if $rows != 15 then +# return -1 +#endi +#if $data01 != 2 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1s) sql select _wstartts, count(*) from dev_001 session(ts,1s) @@ -117,14 +119,14 @@ if $data01 != 5 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1s) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1s) -if $rows != 12 then - return -1 -endi -if $data01 != 5 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1s) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1s) +#if $rows != 12 then +# return -1 +#endi +#if $data01 != 5 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1000a) sql select _wstartts, count(*) from dev_001 session(ts,1000a) @@ -135,14 +137,14 @@ if $data01 != 5 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1000a) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1000a) -if $rows != 12 then - return -1 -endi -if $data01 != 5 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1000a) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1000a) +#if $rows != 12 then +# return -1 +#endi +#if $data01 != 5 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1m) sql select _wstartts, count(*) from dev_001 session(ts,1m) @@ -153,14 +155,14 @@ if $data01 != 8 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1m) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1m) -if $rows != 9 then - return -1 -endi -if $data01 != 8 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1m) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1m) +#if $rows != 9 then +# return -1 +#endi +#if $data01 != 8 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1h) sql select _wstartts, count(*) from dev_001 session(ts,1h) @@ -171,14 +173,14 @@ if $data01 != 11 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1h) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1h) -if $rows != 6 then - return -1 -endi -if $data01 != 11 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1h) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1h) +#if $rows != 6 then +# return -1 +#endi +#if $data01 != 11 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1d) sql select _wstartts, count(*) from dev_001 session(ts,1d) @@ -189,14 +191,14 @@ if $data01 != 13 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1d) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1d) -if $rows != 4 then - return -1 -endi -if $data01 != 13 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1d) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1d) +#if $rows != 4 then +# return -1 +#endi +#if $data01 != 13 then +# return -1 +#endi print ====> select count(*) from dev_001 session(ts,1w) sql select _wstartts, count(*) from dev_001 session(ts,1w) @@ -207,18 +209,18 @@ if $data01 != 15 then return -1 endi -print ====> select count(*) from (select * from dev_001) session(ts,1w) -sql select _wstartts, count(*) from (select * from dev_001) session(ts,1w) -if $rows != 2 then - return -1 -endi -if $data01 != 15 then - return -1 -endi +#print ====> select count(*) from (select * from dev_001) session(ts,1w) +#sql select _wstartts, count(*) from (select * from dev_001) session(ts,1w) +#if $rows != 2 then +# return -1 +#endi +#if $data01 != 15 then +# return -1 +#endi -print ====> leastsquares not supported yet. -print ====> select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1),spread(tagtype),stddev(tagtype),percentile(tagtype,0) from dev_001 where ts <'2020-05-20 0:0:0' session(ts,1d) +#print ====> leastsquares not supported yet. +#print ====> select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1),spread(tagtype),stddev(tagtype),percentile(tagtype,0) from dev_001 where ts <'2020-05-20 0:0:0' session(ts,1d) #sql select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1),spread(tagtype),stddev(tagtype),percentile(tagtype,0) from dev_001 where ts <'2020-05-20 0:0:0' session(ts,1d) #if $rows != 2 then # return -1 @@ -254,7 +256,7 @@ print ====> select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtyp # $data0-11 != 1 # $data1-11 != 14 -print ====> select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1) from (select * from dev_001 where ts <'2020-05-20 0:0:0') session(ts,1d) +#print ====> select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1) from (select * from dev_001 where ts <'2020-05-20 0:0:0') session(ts,1d) #sql select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtype),min(tagtype),max(tagtype),leastsquares(tagtype, 1, 1) from (select * from dev_001 where ts <'2020-05-20 0:0:0') session(ts,1d) #if $rows != 2 then # return -1 @@ -285,14 +287,14 @@ print ====> select count(*),first(tagtype),last(tagtype),avg(tagtype),sum(tagtyp #endi print ================> syntax error check not active ================> reactive -#sql_error select * from dev_001 session(ts,1w) -#sql_error select count(*) from st session(ts,1w) -#sql_error select count(*) from dev_001 group by tagtype session(ts,1w) -#sql_error select count(*) from dev_001 session(ts,1n) -#sql_error select count(*) from dev_001 session(ts,1y) -#sql_error select count(*) from dev_001 session(ts,0s) -#sql_error select count(*) from dev_001 session(i,1y) -#sql_error select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0:0' +sql_error select * from dev_001 session(ts,1w) +sql select count(*) from st session(ts,1w) +sql_error select count(*) from dev_001 group by tagtype session(ts,1w) +sql select count(*) from dev_001 session(ts,1n) +sql select count(*) from dev_001 session(ts,1y) +sql select count(*) from dev_001 session(ts,0s) +sql_error select count(*) from dev_001 session(i,1y) +sql_error select count(*) from dev_001 session(ts,1d) where ts <'2020-05-20 0:0:0' print ====> create database d1 precision 'us' sql create database d1 precision 'us' @@ -301,17 +303,22 @@ sql create table dev_001 (ts timestamp ,i timestamp ,j int) sql insert into dev_001 values(1623046993681000,now,1)(1623046993681001,now+1s,2)(1623046993681002,now+2s,3)(1623046993681004,now+5s,4) print ====> select count(*) from dev_001 session(ts,1u) sql select _wstartts, count(*) from dev_001 session(ts,1u) -if $rows != 2 then +print rows: $rows +print $data00 $data01 $data02 $data03 +print $data10 $data11 $data12 $data13 +print $data20 $data21 $data22 $data23 +print $data30 $data31 $data32 $data33 +if $rows != 4 then print expect 2, actual: $rows return -1 endi -if $data01 != 3 then +if $data01 != 1 then return -1 endi #sql_error select count(*) from dev_001 session(i,1s) -#sql create table secondts(ts timestamp,t2 timestamp,i int) +sql create table secondts(ts timestamp,t2 timestamp,i int) #sql_error select count(*) from secondts session(t2,2s) if $loop_test == 0 then diff --git a/tests/script/tsim/show/basic.sim b/tests/script/tsim/show/basic.sim index cc926861422518d4cfb5fffcd5f2f9d273950f22..0c0670ff7f6a8337ee918ead9ab734a31d8f3482 100644 --- a/tests/script/tsim/show/basic.sim +++ b/tests/script/tsim/show/basic.sim @@ -28,8 +28,8 @@ sql connect # select */column from information_schema.xxxx; xxxx include: # dnodes, mnodes, modules, qnodes, -# user_databases, user_functions, user_indexes, user_stables, user_streams, -# user_tables, user_table_distributed, user_users, vgroups, +# user_databases, user_functions, user_indexes, user_stables, user_streams, +# user_tables, user_table_distributed, user_users, vgroups, print =============== add dnode2 into cluster sql create dnode $hostname port 7200 @@ -53,7 +53,7 @@ endi #sql show modules #sql show qnodes sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi #sql show functions @@ -90,7 +90,7 @@ endi #sql select * from information_schema.`modules` #sql select * from information_schema.`qnodes` sql select * from information_schema.user_databases -if $rows != 2 then +if $rows != 3 then return -1 endi #sql select * from information_schema.user_functions @@ -151,7 +151,7 @@ endi #sql show modules #sql show qnodes sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi #sql show functions @@ -188,7 +188,7 @@ endi #sql select * from information_schema.`modules` #sql select * from information_schema.`qnodes` sql select * from information_schema.user_databases -if $rows != 2 then +if $rows != 3 then return -1 endi #sql select * from information_schema.user_functions diff --git a/tests/script/tsim/sma/tsmaCreateInsertData.sim b/tests/script/tsim/sma/tsmaCreateInsertData.sim new file mode 100644 index 0000000000000000000000000000000000000000..b7a127e1b0d67f9af620919740dae87e649c82cd --- /dev/null +++ b/tests/script/tsim/sma/tsmaCreateInsertData.sim @@ -0,0 +1,41 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sleep 50 +sql connect + +print =============== create database +sql create database d1 +sql use d1 + +print =============== create super table, include column type for count/sum/min/max/first +sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int unsigned) + +sql show stables +if $rows != 1 then + return -1 +endi + +print =============== create child table +sql create table ct1 using stb tags(1000) + +sql show tables +if $rows != 1 then + return -1 +endi + +print =============== insert data, mode1: one row one table in sql +sql insert into ct1 values(now+0s, 10, 2.0, 3.0) +sql insert into ct1 values(now+1s, 11, 2.1, 3.1)(now+2s, -12, -2.2, -3.2)(now+3s, -13, -2.3, -3.3) + + +print =============== create sma index from super table +sql create sma index sma_index_name1 on stb function(max(c1),max(c2),min(c1)) interval(5m,10s) sliding(2m) +print $data00 $data01 $data02 $data03 + +print =============== trigger stream to execute sma aggr task and insert sma data into sma store +sql insert into ct1 values(now+5s, 20, 20.0, 30.0) +#=================================================================== + + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/stable/disk.sim b/tests/script/tsim/stable/disk.sim index 0e33c2066d32d9cab37b651cba961d712ec78959..9f445cb6a823d404abe632a6cf6c14015a39b30c 100644 --- a/tests/script/tsim/stable/disk.sim +++ b/tests/script/tsim/stable/disk.sim @@ -199,7 +199,7 @@ print =============== step11 print =============== clear sql drop database $db sql show databases -if $rows != 1 then +if $rows != 2 then return -1 endi diff --git a/tests/script/tsim/stable/dnode3.sim b/tests/script/tsim/stable/dnode3.sim index c2243b1ac8b078818a0b174744e24480ca26d089..e388bd9b3159711f1cbac91a39d89a77513afcd0 100644 --- a/tests/script/tsim/stable/dnode3.sim +++ b/tests/script/tsim/stable/dnode3.sim @@ -206,7 +206,7 @@ print =============== step11 print =============== clear sql drop database $db sql show databases -if $rows != 1 then +if $rows != 2 then return -1 endi diff --git a/tests/script/tsim/stable/metrics.sim b/tests/script/tsim/stable/metrics.sim index 948af72d09771626eed3fe0189a656515c820aeb..c49de0e8038bc5583f65d6f2e696b5eb9f1a5db5 100644 --- a/tests/script/tsim/stable/metrics.sim +++ b/tests/script/tsim/stable/metrics.sim @@ -4,7 +4,7 @@ system sh/cfg.sh -n dnode1 -c walLevel -v 1 system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 4 system sh/exec.sh -n dnode1 -s start -sleep 2000 +sleep 1000 sql connect $dbPrefix = m_me_db @@ -95,8 +95,8 @@ $i = 2 $tb = $tbPrefix . $i sql insert into $tb values (now + 1m , 1 ) -print sleep 8000 -sleep 8000 +print sleep 2000 +sleep 2000 print =============== step6 @@ -130,7 +130,7 @@ endi sql drop database $db sql show databases -if $rows != 1 then +if $rows != 2 then return -1 endi diff --git a/tests/script/tsim/stable/refcount.sim b/tests/script/tsim/stable/refcount.sim index 1f0048309087e4a048dd9271b4946646a5cf239d..fffa6f75a4adfe2b52b1a7d1b587f6bf7a182ba4 100644 --- a/tests/script/tsim/stable/refcount.sim +++ b/tests/script/tsim/stable/refcount.sim @@ -20,7 +20,7 @@ sql insert into d1.t2 values(now, 1); sql drop database d1; sql show databases; -if $rows != 1 then +if $rows != 2 then return -1 endi @@ -49,7 +49,7 @@ endi sql drop database d2; sql show databases; -if $rows != 1 then +if $rows != 2 then return -1 endi @@ -78,7 +78,7 @@ endi sql drop database d3; sql show databases; -if $rows != 1 then +if $rows != 2 then return -1 endi @@ -106,7 +106,7 @@ endi sql drop database d4; sql show databases; -if $rows != 1 then +if $rows != 2 then return -1 endi @@ -123,7 +123,7 @@ sql insert into d5.t1 values(now, 1); sql drop database d5; sql show databases; -if $rows != 1 then +if $rows != 2 then return -1 endi diff --git a/tests/script/tsim/stable/show.sim b/tests/script/tsim/stable/show.sim index 8ebb765a7817061b3a706c11845cc7db6a60008d..823aefe9d86954dc8a3af85359ec02a475182aae 100644 --- a/tests/script/tsim/stable/show.sim +++ b/tests/script/tsim/stable/show.sim @@ -27,8 +27,9 @@ while $m < 128 $filter = ' . $tb $filter = $filter . ' sql show stables like $filter - # print sql : show stables like $filter ==> $rows + print sql : show stables like $filter if $rows != 1 then + print expect 1, actual: $rows return -1 endi $m = $m + 1 diff --git a/tests/script/tsim/stable/vnode3.sim b/tests/script/tsim/stable/vnode3.sim index 2d408b4191d43c31ab21eb724da6d197d96b0af8..97a8203883cc5f427ccc355cf5898b1e3ebe6cd2 100644 --- a/tests/script/tsim/stable/vnode3.sim +++ b/tests/script/tsim/stable/vnode3.sim @@ -174,7 +174,7 @@ print =============== step11 print =============== clear sql drop database $db sql show databases -if $rows != 1 then +if $rows != 2 then return -1 endi diff --git a/tests/script/tsim/table/basic1.sim b/tests/script/tsim/table/basic1.sim index bdb49cc9cdcd79739df3e547f6e98d8b052c6f0f..75cd0c8744412d0b36258ca9819763bd42da59c0 100644 --- a/tests/script/tsim/table/basic1.sim +++ b/tests/script/tsim/table/basic1.sim @@ -29,7 +29,7 @@ endi print =============== create database sql create database d1 sql show databases -if $rows != 5 then +if $rows != 6 then return -1 endi diff --git a/tests/script/tsim/tmq/basic.sim b/tests/script/tsim/tmq/basic.sim index 1eeec46d5386b6ae89521c59260f8ab84f0748eb..9f5584796542ab83576ceb74878daa5f987f6f9c 100644 --- a/tests/script/tsim/tmq/basic.sim +++ b/tests/script/tsim/tmq/basic.sim @@ -50,10 +50,10 @@ endi sql show databases print ===> $rows $data00 $data01 $data02 $data03 -if $rows != 2 then +if $rows != 3 then return -1 endi -if $data00 != tmqdb then +if $data20 != tmqdb then return -1 endi diff --git a/tests/script/tsim/tmq/basic1.sim b/tests/script/tsim/tmq/basic1.sim index bc827d79f418a253a2618d6c79654667adf30df9..ec33e89e84c2827ac3088811e546d97d5ead06b0 100644 --- a/tests/script/tsim/tmq/basic1.sim +++ b/tests/script/tsim/tmq/basic1.sim @@ -36,12 +36,6 @@ sql connect $dbNamme = d0 print =============== create database , vgroup 1 sql create database $dbNamme vgroups 1 -sql show databases -print $data00 $data01 $data02 -if $rows != 2 then - return -1 -endi - sql use $dbNamme print =============== create super table diff --git a/tests/script/tsim/tmq/insertDataV1.sim b/tests/script/tsim/tmq/insertDataV1.sim new file mode 100644 index 0000000000000000000000000000000000000000..0df74d53f860b2b3db55e7957b111c0d5e818e89 --- /dev/null +++ b/tests/script/tsim/tmq/insertDataV1.sim @@ -0,0 +1,44 @@ + +sql connect + +print ================ insert data +$dbNamme = d0 +$tbPrefix = ct +$tbNum = 10 +$rowNum = 100 +$tstart = 1640966400000 # 2022-01-01 00:00:00.000 + +sql use $dbNamme + +$loop_cnt = 0 + +loop_insert: +print ====> loop $loop_cnt insert +$loop_cnt = $loop_cnt + 1 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + + $x = 0 + while $x < $rowNum + $binary = ' . binary + $binary = $binary . $i + $binary = $binary . ' + + #print ====> insert into $tb values ($tstart , $i , $x , $binary ) + #print ====> insert into ntb values ($tstart , $i , $x , $binary ) + sql insert into $tb values ($tstart , $i , $x , $binary ) + sql insert into ntb values ($tstart , 999 , 999 , 'binary-ntb' ) + $tstart = $tstart + 1 + $x = $x + 1 + endw + + print ====> insert rows: $rowNum into $tb and ntb + + $i = $i + 1 +# $tstart = 1640966400000 +endw +goto loop_insert + + diff --git a/tests/script/tsim/tmq/insertDataV4.sim b/tests/script/tsim/tmq/insertDataV4.sim new file mode 100644 index 0000000000000000000000000000000000000000..dbd52f56b8b79afceafe3c9faede8ebe99bc94a3 --- /dev/null +++ b/tests/script/tsim/tmq/insertDataV4.sim @@ -0,0 +1,44 @@ + +sql connect + +print ================ insert data +$dbNamme = d1 +$tbPrefix = ct +$tbNum = 10 +$rowNum = 100 +$tstart = 1640966400000 # 2022-01-01 00:00:00.000 + +sql use $dbNamme + +$loop_cnt = 0 + +loop_insert: +print ====> loop $loop_cnt insert +$loop_cnt = $loop_cnt + 1 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + + $x = 0 + while $x < $rowNum + $binary = ' . binary + $binary = $binary . $i + $binary = $binary . ' + + #print ====> insert into $tb values ($tstart , $i , $x , $binary ) + #print ====> insert into ntb values ($tstart , $i , $x , $binary ) + sql insert into $tb values ($tstart , $i , $x , $binary ) + sql insert into ntb values ($tstart , 999 , 999 , 'binary-ntb' ) + $tstart = $tstart + 1 + $x = $x + 1 + endw + + #print ====> insert rows: $rowNum into $tb and ntb + + $i = $i + 1 +# $tstart = 1640966400000 +endw +goto loop_insert + + diff --git a/tests/script/tsim/tmq/insertFixedDataV2.sim b/tests/script/tsim/tmq/insertFixedDataV2.sim new file mode 100644 index 0000000000000000000000000000000000000000..a93be3e5a678fd1ba0880b871c186cc334717f27 --- /dev/null +++ b/tests/script/tsim/tmq/insertFixedDataV2.sim @@ -0,0 +1,51 @@ + +sql connect + +print ================ insert data +$dbNamme = d0 +$tbPrefix = ct +$tbNum = 10 +$rowNum = 100 +$tstart = 1640966400000 # 2022-01-01 00:00:00.000 + +$loopInsertNum = 10 + +sql use $dbNamme + +$loopIndex = 0 + +loop_insert: +print ====> loop $loopIndex insert +$loopIndex = $loopIndex + 1 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + + $x = 0 + while $x < $rowNum + $binary = ' . binary + $binary = $binary . $i + $binary = $binary . ' + + #print ====> insert into $tb values ($tstart , $i , $x , $binary ) + #print ====> insert into ntb values ($tstart , $i , $x , $binary ) + sql insert into $tb values ($tstart , $i , $x , $binary ) + sql insert into ntb values ($tstart , 999 , 999 , 'binary-ntb' ) + $tstart = $tstart + 1 + $x = $x + 1 + endw + + #print ====> insert rows: $rowNum into $tb and ntb + + $i = $i + 1 +# $tstart = 1640966400000 +endw + + +if $loopIndex < $loopInsertNum then + goto loop_insert +endi + +print ====> insert data end =========== + diff --git a/tests/script/tsim/tmq/insertFixedDataV4.sim b/tests/script/tsim/tmq/insertFixedDataV4.sim new file mode 100644 index 0000000000000000000000000000000000000000..9f7f86747f8bc88c1fe9fa2f4a3810588f6b8691 --- /dev/null +++ b/tests/script/tsim/tmq/insertFixedDataV4.sim @@ -0,0 +1,51 @@ + +sql connect + +print ================ insert data +$dbNamme = d1 +$tbPrefix = ct +$tbNum = 10 +$rowNum = 100 +$tstart = 1640966400000 # 2022-01-01 00:00:00.000 + +$loopInsertNum = 10 + +sql use $dbNamme + +$loopIndex = 0 + +loop_insert: +print ====> loop $loopIndex insert +$loopIndex = $loopIndex + 1 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + + $x = 0 + while $x < $rowNum + $binary = ' . binary + $binary = $binary . $i + $binary = $binary . ' + + #print ====> insert into $tb values ($tstart , $i , $x , $binary ) + #print ====> insert into ntb values ($tstart , $i , $x , $binary ) + sql insert into $tb values ($tstart , $i , $x , $binary ) + sql insert into ntb values ($tstart , 999 , 999 , 'binary-ntb' ) + $tstart = $tstart + 1 + $x = $x + 1 + endw + + #print ====> insert rows: $rowNum into $tb and ntb + + $i = $i + 1 +# $tstart = 1640966400000 +endw + + +if $loopIndex < $loopInsertNum then + goto loop_insert +endi + +print ====> insert data end =========== + diff --git a/tests/script/tsim/tmq/main2Con1Cgrp1TopicFrCtb.sim b/tests/script/tsim/tmq/main2Con1Cgrp1TopicFrCtb.sim new file mode 100644 index 0000000000000000000000000000000000000000..68c2d5a89100b14462b71d50e8c04048164df04b --- /dev/null +++ b/tests/script/tsim/tmq/main2Con1Cgrp1TopicFrCtb.sim @@ -0,0 +1,236 @@ +#### test scenario, please refer to https://jira.taosdata.com:18090/pages/viewpage.action?pageId=135120406 +# scene1: vgroups=2, one topic for two consumers, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene2: vgroups=2, multi topics for two consumers, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene3: vgroups=4, one topic for two consumers, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene4: vgroups=4, multi topics for two consumers, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# notes1: Scalar function: ABS/ACOS/ASIN/ATAN/CEIL/COS/FLOOR/LOG/POW/ROUND/SIN/SQRT/TAN +# The above use cases are combined with where filter conditions, such as: where ts > "2017-08-12 18:25:58.128Z" and sin(a) > 0.5; +# +# notes2: not support aggregate functions(such as sum/count/min/max) and time-windows(interval). +# +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## +######## This test case include scene1 and scene3 +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## + +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +$loop_cnt = 0 +$vgroups = 2 +$dbNamme = d0 +loop_vgroups: +print =============== create database $dbNamme vgroups $vgroups +sql create database $dbNamme vgroups $vgroups +sql show databases +sql use $dbNamme + +print =============== create super table +sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int) + +sql show stables +if $rows != 1 then + return -1 +endi + +print =============== create child table +$tbPrefix = ct +$tbNum = 100 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using stb tags( $i ) + $i = $i + 1 +endw + +print =============== create normal table +sql create table ntb (ts timestamp, c1 int, c2 float, c3 binary(10)) + +print =============== create topics from child table + +sql create topic topic_ctb_column as select ts, c1, c3 from ct0 +sql create topic topic_ctb_all as select * from ct0 +sql create topic topic_ctb_function as select ts, abs(c1), sin(c2) from ct0 + +#sql create topic topic_ntb_column as select ts, c1, c3 from ntb +#sql create topic topic_ntb_all as select * from ntb +#sql create topic topic_ntb_function as select ts, abs(c1), sin(c2) from ntb + +sql show tables +if $rows != 101 then + return -1 +endi + +print =============== run_back insert data + +if $loop_cnt == 0 then + run_back tsim/tmq/insertFixedDataV2.sim +else + run_back tsim/tmq/insertFixedDataV4.sim +endi + +#sleep 1000 + +#$rowNum = 1000 +#$tstart = 1640966400000 # 2022-01-01 00:00:00.000 +# +#$i = 0 +#while $i < $tbNum +# $tb = $tbPrefix . $i +# +# $x = 0 +# while $x < $rowNum +# $c = $x / 10 +# $c = $c * 10 +# $c = $x - $c +# +# $binary = ' . binary +# $binary = $binary . $c +# $binary = $binary . ' +# +# sql insert into $tb values ($tstart , $c , $x , $binary ) +# sql insert into ntb values ($tstart , $c , $x , $binary ) +# $tstart = $tstart + 1 +# $x = $x + 1 +# endw +# +# $i = $i + 1 +# $tstart = 1640966400000 +#endw + +#root@trd02 /home $ tmq_sim --help +# -c Configuration directory, default is +# -d The name of the database for cosumer, no default +# -t The topic string for cosumer, no default +# -k The key-value string for cosumer, no default +# -g showMsgFlag, default is 0 +# + +$tbNum = 10 +$consumeDelay = 10 +$expectMsgCntFromCtb = 300 +$expectMsgCntFromStb = $expectMsgCntFromCtb * $tbNum +print consumeDelay: $consumeDelay +print insert data child num: $tbNum +print expectMsgCntFromCtb: $expectMsgCntFromCtb +print expectMsgCntFromStb: $expectMsgCntFromStb + +# supported key: +# group.id: +# enable.auto.commit: +# auto.offset.reset: +# td.connect.ip: +# td.connect.user:root +# td.connect.pass:taosdata +# td.connect.port:6030 +# td.connect.db:db + +$expect_result = @{consume success: @ +$expect_result = $expect_result . $rowNum +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_column" -k1 "group.id:tg2" -t "topic_ctb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 0 +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_column" -k1 "group.id:tg2" -t "topic_ctb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 0 +print cmd result----> $system_content +if $system_content != success then + return -1 +endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_all" -k1 "group.id:tg2" -t "topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 0 +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_all" -k1 "group.id:tg2" -t "topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 0 +print cmd result----> $system_content +if $system_content != success then + return -1 +endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_function" -k1 "group.id:tg2" -t "topic_ctb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 0 +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_function" -k1 "group.id:tg2" -t "topic_ctb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 0 +print cmd result----> $system_content +if $system_content != success then + return -1 +endi + +#$expect_result = @{consume success: @ +#$expect_result = $expect_result . $totalMsgCnt +#$expect_result = $expect_result . @, @ +#$expect_result = $expect_result . 0} +#print expect_result----> $expect_result +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_column" -k1 "group.id:tg2" -t "topic_ntb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_column" -k1 "group.id:tg2" -t "topic_ntb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_all" -k1 "group.id:tg2" -t "topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_all" -k1 "group.id:tg2" -t "topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_function" -k1 "group.id:tg2" -t "topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_function" -k1 "group.id:tg2" -t "topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +#$expect_result = @{consume success: @ +#$expect_result = $expect_result . $expectConsumeMsgCnt +#$expect_result = $expect_result . @, @ +#$expect_result = $expect_result . 0} +#print expect_result----> $expect_result +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_column" -k1 "group.id:tg2" -t "topic_stb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_column" -k1 "group.id:tg2" -t "topic_stb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +##print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_all" -k1 "group.id:tg2" -t "topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +##system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_all" -k1 "group.id:tg2" -t "topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +##print cmd result----> $system_content +###if $system_content != @{consume success: 10000, 0}@ then +##if $system_content != success then +## return -1 +##endi +# +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_function" -k1 "group.id:tg2" -t "topic_stb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_function" -k1 "group.id:tg2" -t "topic_stb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +#print cmd result----> $system_content +##if $system_content != @{consume success: 10000, 0}@ then +#if $system_content != success then +# return -1 +#endi + +if $loop_cnt == 0 then + $loop_cnt = 1 + $vgroups = 4 + $dbNamme = d1 + goto loop_vgroups +endi + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/tmq/main2Con1Cgrp1TopicFrStb.sim b/tests/script/tsim/tmq/main2Con1Cgrp1TopicFrStb.sim new file mode 100644 index 0000000000000000000000000000000000000000..1b98bcdd5db54a1733bb7c0b45329b3de6f1776c --- /dev/null +++ b/tests/script/tsim/tmq/main2Con1Cgrp1TopicFrStb.sim @@ -0,0 +1,240 @@ +#### test scenario, please refer to https://jira.taosdata.com:18090/pages/viewpage.action?pageId=135120406 +# scene1: vgroups=2, one topic for two consumers, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene2: vgroups=2, multi topics for two consumers, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene3: vgroups=4, one topic for two consumers, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene4: vgroups=4, multi topics for two consumers, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# notes1: Scalar function: ABS/ACOS/ASIN/ATAN/CEIL/COS/FLOOR/LOG/POW/ROUND/SIN/SQRT/TAN +# The above use cases are combined with where filter conditions, such as: where ts > "2017-08-12 18:25:58.128Z" and sin(a) > 0.5; +# +# notes2: not support aggregate functions(such as sum/count/min/max) and time-windows(interval). +# +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## +######## This test case include scene1 and scene3 +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## + +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +$loop_cnt = 0 +$vgroups = 2 +$dbNamme = d0 +loop_vgroups: +print =============== create database $dbNamme vgroups $vgroups +sql create database $dbNamme vgroups $vgroups +sql use $dbNamme + +print =============== create super table +sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int) + +sql show stables +if $rows != 1 then + return -1 +endi + +print =============== create child table +$tbPrefix = ct +$tbNum = 100 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using stb tags( $i ) + $i = $i + 1 +endw + +print =============== create normal table +sql create table ntb (ts timestamp, c1 int, c2 float, c3 binary(10)) + +print =============== create multi topics. notes: now only support: +print =============== 1. columns from stb/ctb/ntb; 2. * from ctb/ntb; 3. function from stb/ctb/ntb +print =============== will support: * from stb + +sql create topic topic_stb_column as select ts, c1, c3 from stb +#sql create topic topic_stb_all as select * from stb +sql create topic topic_stb_function as select ts, abs(c1), sin(c2) from stb + +sql create topic topic_ctb_column as select ts, c1, c3 from ct0 +sql create topic topic_ctb_all as select * from ct0 +sql create topic topic_ctb_function as select ts, abs(c1), sin(c2) from ct0 + +sql create topic topic_ntb_column as select ts, c1, c3 from ntb +sql create topic topic_ntb_all as select * from ntb +sql create topic topic_ntb_function as select ts, abs(c1), sin(c2) from ntb + +sql show tables +if $rows != 101 then + return -1 +endi + +print =============== run_back insert data + +if $loop_cnt == 0 then + run_back tsim/tmq/insertFixedDataV2.sim +else + run_back tsim/tmq/insertFixedDataV4.sim +endi + +#sleep 1000 + +#$rowNum = 1000 +#$tstart = 1640966400000 # 2022-01-01 00:00:00.000 +# +#$i = 0 +#while $i < $tbNum +# $tb = $tbPrefix . $i +# +# $x = 0 +# while $x < $rowNum +# $c = $x / 10 +# $c = $c * 10 +# $c = $x - $c +# +# $binary = ' . binary +# $binary = $binary . $c +# $binary = $binary . ' +# +# sql insert into $tb values ($tstart , $c , $x , $binary ) +# sql insert into ntb values ($tstart , $c , $x , $binary ) +# $tstart = $tstart + 1 +# $x = $x + 1 +# endw +# +# $i = $i + 1 +# $tstart = 1640966400000 +#endw + +#root@trd02 /home $ tmq_sim --help +# -c Configuration directory, default is +# -d The name of the database for cosumer, no default +# -t The topic string for cosumer, no default +# -k The key-value string for cosumer, no default +# -g showMsgFlag, default is 0 +# + +$tbNum = 10 +$consumeDelay = 10 +$expectMsgCntFromCtb = 300 +$expectMsgCntFromStb = $expectMsgCntFromCtb * $tbNum +print consumeDelay: $consumeDelay +print insert data child num: $tbNum +print expectMsgCntFromCtb: $expectMsgCntFromCtb +print expectMsgCntFromStb: $expectMsgCntFromStb + +# supported key: +# group.id: +# enable.auto.commit: +# auto.offset.reset: +# td.connect.ip: +# td.connect.user:root +# td.connect.pass:taosdata +# td.connect.port:6030 +# td.connect.db:db + +#$expect_result = @{consume success: @ +#$expect_result = $expect_result . $rowNum +#$expect_result = $expect_result . @, @ +#$expect_result = $expect_result . 0} +#print expect_result----> $expect_result +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_column" -k1 "group.id:tg2" -t "topic_ctb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_column" -k1 "group.id:tg2" -t "topic_ctb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_all" -k1 "group.id:tg2" -t "topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_all" -k1 "group.id:tg2" -t "topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_function" -k1 "group.id:tg2" -t "topic_ctb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_function" -k1 "group.id:tg2" -t "topic_ctb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +#$expect_result = @{consume success: @ +#$expect_result = $expect_result . $totalMsgCnt +#$expect_result = $expect_result . @, @ +#$expect_result = $expect_result . 0} +#print expect_result----> $expect_result +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_column" -k1 "group.id:tg2" -t "topic_ntb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_column" -k1 "group.id:tg2" -t "topic_ntb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_all" -k1 "group.id:tg2" -t "topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_all" -k1 "group.id:tg2" -t "topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_function" -k1 "group.id:tg2" -t "topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_function" -k1 "group.id:tg2" -t "topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi + +$expect_result = @{consume success: @ +$expect_result = $expect_result . $expectConsumeMsgCnt +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_column" -k1 "group.id:tg2" -t "topic_stb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_column" -k1 "group.id:tg2" -t "topic_stb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +print cmd result----> $system_content +if $system_content != success then + return -1 +endi + +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_all" -k1 "group.id:tg2" -t "topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_all" -k1 "group.id:tg2" -t "topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +#print cmd result----> $system_content +##if $system_content != @{consume success: 10000, 0}@ then +#if $system_content != success then +# return -1 +#endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_function" -k1 "group.id:tg2" -t "topic_stb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_function" -k1 "group.id:tg2" -t "topic_stb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +print cmd result----> $system_content +#if $system_content != @{consume success: 10000, 0}@ then +if $system_content != success then + return -1 +endi +if $loop_cnt == 0 then + $loop_cnt = 1 + $vgroups = 4 + $dbNamme = d1 + goto loop_vgroups +endi + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/tmq/main2Con1Cgrp2TopicFrCtb.sim b/tests/script/tsim/tmq/main2Con1Cgrp2TopicFrCtb.sim new file mode 100644 index 0000000000000000000000000000000000000000..9f2b204b60d4b107a27f81ed36420ab8ac16e674 --- /dev/null +++ b/tests/script/tsim/tmq/main2Con1Cgrp2TopicFrCtb.sim @@ -0,0 +1,235 @@ +#### test scenario, please refer to https://jira.taosdata.com:18090/pages/viewpage.action?pageId=135120406 +# scene1: vgroups=2, one topic for two consumers, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene2: vgroups=2, multi topics for two consumers, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene3: vgroups=4, one topic for two consumers, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene4: vgroups=4, multi topics for two consumers, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# notes1: Scalar function: ABS/ACOS/ASIN/ATAN/CEIL/COS/FLOOR/LOG/POW/ROUND/SIN/SQRT/TAN +# The above use cases are combined with where filter conditions, such as: where ts > "2017-08-12 18:25:58.128Z" and sin(a) > 0.5; +# +# notes2: not support aggregate functions(such as sum/count/min/max) and time-windows(interval). +# +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## +######## This test case include scene1 and scene3 +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## + +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +$loop_cnt = 0 +$vgroups = 2 +$dbNamme = d0 +loop_vgroups: +print =============== create database $dbNamme vgroups $vgroups +sql create database $dbNamme vgroups $vgroups +sql use $dbNamme + +print =============== create super table +sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int) + +sql show stables +if $rows != 1 then + return -1 +endi + +print =============== create child table +$tbPrefix = ct +$tbNum = 100 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using stb tags( $i ) + $i = $i + 1 +endw + +print =============== create normal table +sql create table ntb (ts timestamp, c1 int, c2 float, c3 binary(10)) + +print =============== create topics from child table + +sql create topic topic_ctb_column as select ts, c1, c3 from ct0 +sql create topic topic_ctb_all as select * from ct0 +sql create topic topic_ctb_function as select ts, abs(c1), sin(c2) from ct0 + +#sql create topic topic_ntb_column as select ts, c1, c3 from ntb +#sql create topic topic_ntb_all as select * from ntb +#sql create topic topic_ntb_function as select ts, abs(c1), sin(c2) from ntb + +sql show tables +if $rows != 101 then + return -1 +endi + +print =============== run_back insert data + +if $loop_cnt == 0 then + run_back tsim/tmq/insertFixedDataV2.sim +else + run_back tsim/tmq/insertFixedDataV4.sim +endi + +#sleep 1000 + +#$rowNum = 1000 +#$tstart = 1640966400000 # 2022-01-01 00:00:00.000 +# +#$i = 0 +#while $i < $tbNum +# $tb = $tbPrefix . $i +# +# $x = 0 +# while $x < $rowNum +# $c = $x / 10 +# $c = $c * 10 +# $c = $x - $c +# +# $binary = ' . binary +# $binary = $binary . $c +# $binary = $binary . ' +# +# sql insert into $tb values ($tstart , $c , $x , $binary ) +# sql insert into ntb values ($tstart , $c , $x , $binary ) +# $tstart = $tstart + 1 +# $x = $x + 1 +# endw +# +# $i = $i + 1 +# $tstart = 1640966400000 +#endw + +#root@trd02 /home $ tmq_sim --help +# -c Configuration directory, default is +# -d The name of the database for cosumer, no default +# -t The topic string for cosumer, no default +# -k The key-value string for cosumer, no default +# -g showMsgFlag, default is 0 +# + +$tbNum = 10 +$consumeDelay = 10 +$expectMsgCntFromCtb = 300 +$expectMsgCntFromStb = $expectMsgCntFromCtb * $tbNum +print consumeDelay: $consumeDelay +print insert data child num: $tbNum +print expectMsgCntFromCtb: $expectMsgCntFromCtb +print expectMsgCntFromStb: $expectMsgCntFromStb + +# supported key: +# group.id: +# enable.auto.commit: +# auto.offset.reset: +# td.connect.ip: +# td.connect.user:root +# td.connect.pass:taosdata +# td.connect.port:6030 +# td.connect.db:db + +$expect_result = @{consume success: @ +$expect_result = $expect_result . $rowNum +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_all" -k1 "group.id:tg2" -t "topic_ctb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 1 +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_all" -k1 "group.id:tg2" -t "topic_ctb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 1 +print cmd result----> $system_content +if $system_content != success then + return -1 +endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_function" -k1 "group.id:tg2" -t "topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 1 +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_function" -k1 "group.id:tg2" -t "topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 1 +print cmd result----> $system_content +if $system_content != success then + return -1 +endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_column" -k1 "group.id:tg2" -t "topic_ctb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 1 +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_column" -k1 "group.id:tg2" -t "topic_ctb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 1 +print cmd result----> $system_content +if $system_content != success then + return -1 +endi + +#$expect_result = @{consume success: @ +#$expect_result = $expect_result . $totalMsgCnt +#$expect_result = $expect_result . @, @ +#$expect_result = $expect_result . 0} +#print expect_result----> $expect_result +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_column" -k1 "group.id:tg2" -t "topic_ntb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 1 +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_column" -k1 "group.id:tg2" -t "topic_ntb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 1 +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_all" -k1 "group.id:tg2" -t "topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_all" -k1 "group.id:tg2" -t "topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_function" -k1 "group.id:tg2" -t "topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_function" -k1 "group.id:tg2" -t "topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +#$expect_result = @{consume success: @ +#$expect_result = $expect_result . $expectConsumeMsgCnt +#$expect_result = $expect_result . @, @ +#$expect_result = $expect_result . 0} +#print expect_result----> $expect_result +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_column" -k1 "group.id:tg2" -t "topic_stb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_column" -k1 "group.id:tg2" -t "topic_stb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +##print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_all" -k1 "group.id:tg2" -t "topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +##system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_all" -k1 "group.id:tg2" -t "topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +##print cmd result----> $system_content +###if $system_content != @{consume success: 10000, 0}@ then +##if $system_content != success then +## return -1 +##endi +# +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_function" -k1 "group.id:tg2" -t "topic_stb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_function" -k1 "group.id:tg2" -t "topic_stb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +#print cmd result----> $system_content +##if $system_content != @{consume success: 10000, 0}@ then +#if $system_content != success then +# return -1 +#endi + +if $loop_cnt == 0 then + $loop_cnt = 1 + $vgroups = 4 + $dbNamme = d1 + goto loop_vgroups +endi + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/tmq/main2Con1Cgrp2TopicFrStb.sim b/tests/script/tsim/tmq/main2Con1Cgrp2TopicFrStb.sim new file mode 100644 index 0000000000000000000000000000000000000000..45dd4fd1876ac63734205ca020e23d8c42435688 --- /dev/null +++ b/tests/script/tsim/tmq/main2Con1Cgrp2TopicFrStb.sim @@ -0,0 +1,240 @@ +#### test scenario, please refer to https://jira.taosdata.com:18090/pages/viewpage.action?pageId=135120406 +# scene1: vgroups=2, one topic for two consumers, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene2: vgroups=2, multi topics for two consumers, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene3: vgroups=4, one topic for two consumers, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene4: vgroups=4, multi topics for two consumers, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# notes1: Scalar function: ABS/ACOS/ASIN/ATAN/CEIL/COS/FLOOR/LOG/POW/ROUND/SIN/SQRT/TAN +# The above use cases are combined with where filter conditions, such as: where ts > "2017-08-12 18:25:58.128Z" and sin(a) > 0.5; +# +# notes2: not support aggregate functions(such as sum/count/min/max) and time-windows(interval). +# +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## +######## This test case include scene1 and scene3 +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## + +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +$loop_cnt = 0 +$vgroups = 2 +$dbNamme = d0 +loop_vgroups: +print =============== create database $dbNamme vgroups $vgroups +sql create database $dbNamme vgroups $vgroups +sql use $dbNamme + +print =============== create super table +sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int) + +sql show stables +if $rows != 1 then + return -1 +endi + +print =============== create child table +$tbPrefix = ct +$tbNum = 100 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using stb tags( $i ) + $i = $i + 1 +endw + +print =============== create normal table +sql create table ntb (ts timestamp, c1 int, c2 float, c3 binary(10)) + +print =============== create multi topics. notes: now only support: +print =============== 1. columns from stb/ctb/ntb; 2. * from ctb/ntb; 3. function from stb/ctb/ntb +print =============== will support: * from stb + +sql create topic topic_stb_column as select ts, c1, c3 from stb +#sql create topic topic_stb_all as select * from stb +sql create topic topic_stb_function as select ts, abs(c1), sin(c2) from stb + +sql create topic topic_ctb_column as select ts, c1, c3 from ct0 +sql create topic topic_ctb_all as select * from ct0 +sql create topic topic_ctb_function as select ts, abs(c1), sin(c2) from ct0 + +sql create topic topic_ntb_column as select ts, c1, c3 from ntb +sql create topic topic_ntb_all as select * from ntb +sql create topic topic_ntb_function as select ts, abs(c1), sin(c2) from ntb + +sql show tables +if $rows != 101 then + return -1 +endi + +print =============== run_back insert data + +if $loop_cnt == 0 then + run_back tsim/tmq/insertFixedDataV2.sim +else + run_back tsim/tmq/insertFixedDataV4.sim +endi + +#sleep 1000 + +#$rowNum = 1000 +#$tstart = 1640966400000 # 2022-01-01 00:00:00.000 +# +#$i = 0 +#while $i < $tbNum +# $tb = $tbPrefix . $i +# +# $x = 0 +# while $x < $rowNum +# $c = $x / 10 +# $c = $c * 10 +# $c = $x - $c +# +# $binary = ' . binary +# $binary = $binary . $c +# $binary = $binary . ' +# +# sql insert into $tb values ($tstart , $c , $x , $binary ) +# sql insert into ntb values ($tstart , $c , $x , $binary ) +# $tstart = $tstart + 1 +# $x = $x + 1 +# endw +# +# $i = $i + 1 +# $tstart = 1640966400000 +#endw + +#root@trd02 /home $ tmq_sim --help +# -c Configuration directory, default is +# -d The name of the database for cosumer, no default +# -t The topic string for cosumer, no default +# -k The key-value string for cosumer, no default +# -g showMsgFlag, default is 0 +# + +$tbNum = 10 +$consumeDelay = 10 +$expectMsgCntFromCtb = 300 +$expectMsgCntFromStb = $expectMsgCntFromCtb * $tbNum +print consumeDelay: $consumeDelay +print insert data child num: $tbNum +print expectMsgCntFromCtb: $expectMsgCntFromCtb +print expectMsgCntFromStb: $expectMsgCntFromStb + +# supported key: +# group.id: +# enable.auto.commit: +# auto.offset.reset: +# td.connect.ip: +# td.connect.user:root +# td.connect.pass:taosdata +# td.connect.port:6030 +# td.connect.db:db + +#$expect_result = @{consume success: @ +#$expect_result = $expect_result . $rowNum +#$expect_result = $expect_result . @, @ +#$expect_result = $expect_result . 0} +#print expect_result----> $expect_result +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_column" -k1 "group.id:tg2" -t "topic_ctb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_column" -k1 "group.id:tg2" -t "topic_ctb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_all" -k1 "group.id:tg2" -t "topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_all" -k1 "group.id:tg2" -t "topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_function" -k1 "group.id:tg2" -t "topic_ctb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ctb_function" -k1 "group.id:tg2" -t "topic_ctb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +#$expect_result = @{consume success: @ +#$expect_result = $expect_result . $totalMsgCnt +#$expect_result = $expect_result . @, @ +#$expect_result = $expect_result . 0} +#print expect_result----> $expect_result +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_column" -k1 "group.id:tg2" -t "topic_ntb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_column" -k1 "group.id:tg2" -t "topic_ntb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_all" -k1 "group.id:tg2" -t "topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_all" -k1 "group.id:tg2" -t "topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi +# +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_function" -k1 "group.id:tg2" -t "topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_ntb_function" -k1 "group.id:tg2" -t "topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +#print cmd result----> $system_content +#if $system_content != success then +# return -1 +#endi + +$expect_result = @{consume success: @ +$expect_result = $expect_result . $expectMsgCntFromStb +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_function" -k1 "group.id:tg2" -t "topic_stb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb -j 1 +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_function" -k1 "group.id:tg2" -t "topic_stb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb -j 1 +print cmd result----> $system_content +if $system_content != success then + return -1 +endi + +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_all" -k1 "group.id:tg2" -t "topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb -j 1 +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_all" -k1 "group.id:tg2" -t "topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb -j 1 +#print cmd result----> $system_content +##if $system_content != @{consume success: 10000, 0}@ then +#if $system_content != success then +# return -1 +#endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_column" -k1 "group.id:tg2" -t "topic_stb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb -j 1 +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_column" -k1 "group.id:tg2" -t "topic_stb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb -j 1 +print cmd result----> $system_content +#if $system_content != @{consume success: 10000, 0}@ then +if $system_content != success then + return -1 +endi +if $loop_cnt == 0 then + $loop_cnt = 1 + $vgroups = 4 + $dbNamme = d1 + goto loop_vgroups +endi + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/tmq/mainConsumerInMultiTopic.sim b/tests/script/tsim/tmq/mainConsumerInMultiTopic.sim new file mode 100644 index 0000000000000000000000000000000000000000..2e2534d104ae270c221b5fa02bdc0f0c44e07bf5 --- /dev/null +++ b/tests/script/tsim/tmq/mainConsumerInMultiTopic.sim @@ -0,0 +1,213 @@ +#### test scenario, please refer to https://jira.taosdata.com:18090/pages/viewpage.action?pageId=135120406 +# scene1: vgroups=1, one topic for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene2: vgroups=1, multi topics for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene3: vgroups=4, one topic for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene4: vgroups=4, multi topics for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# notes1: Scalar function: ABS/ACOS/ASIN/ATAN/CEIL/COS/FLOOR/LOG/POW/ROUND/SIN/SQRT/TAN +# The above use cases are combined with where filter conditions, such as: where ts > "2017-08-12 18:25:58.128Z" and sin(a) > 0.5; +# +# notes2: not support aggregate functions(such as sum/count/min/max) and time-windows(interval). +# +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## +######## This test case include scene2 and scene4 +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## + +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +$loop_cnt = 0 +$vgroups = 1 +$dbNamme = d0 +loop_vgroups: +print =============== create database $dbNamme vgroups $vgroups +sql create database $dbNamme vgroups $vgroups +sql use $dbNamme + +print =============== create super table +sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int) + +sql show stables +if $rows != 1 then + return -1 +endi + +print =============== create child table +$tbPrefix = ct +$tbNum = 100 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using stb tags( $i ) + $i = $i + 1 +endw + +print =============== create normal table +sql create table ntb (ts timestamp, c1 int, c2 float, c3 binary(10)) + +print =============== create multi topics. notes: now only support: +print =============== 1. columns from stb/ctb/ntb; 2. * from ctb/ntb; 3. function from stb/ctb/ntb +print =============== will support: * from stb + +sql create topic topic_stb_column as select ts, c1, c3 from stb +#sql create topic topic_stb_all as select * from stb +sql create topic topic_stb_function as select ts, abs(c1), sin(c2) from stb + +sql create topic topic_ctb_column as select ts, c1, c3 from ct0 +sql create topic topic_ctb_all as select * from ct0 +sql create topic topic_ctb_function as select ts, abs(c1), sin(c2) from ct0 + +sql create topic topic_ntb_column as select ts, c1, c3 from ntb +sql create topic topic_ntb_all as select * from ntb +sql create topic topic_ntb_function as select ts, abs(c1), sin(c2) from ntb + +sql show tables +if $rows != 101 then + return -1 +endi + +print =============== run_back insert data + +if $loop_cnt == 0 then + run_back tsim/tmq/insertFixedDataV2.sim +else + run_back tsim/tmq/insertFixedDataV4.sim +endi + +#sleep 1000 + +#$rowNum = 1000 +#$tstart = 1640966400000 # 2022-01-01 00:00:00.000 +# +#$i = 0 +#while $i < $tbNum +# $tb = $tbPrefix . $i +# +# $x = 0 +# while $x < $rowNum +# $c = $x / 10 +# $c = $c * 10 +# $c = $x - $c +# +# $binary = ' . binary +# $binary = $binary . $c +# $binary = $binary . ' +# +# sql insert into $tb values ($tstart , $c , $x , $binary ) +# sql insert into ntb values ($tstart , $c , $x , $binary ) +# $tstart = $tstart + 1 +# $x = $x + 1 +# endw +# +# $i = $i + 1 +# $tstart = 1640966400000 +#endw + +#root@trd02 /home $ tmq_sim --help +# -c Configuration directory, default is +# -d The name of the database for cosumer, no default +# -t The topic string for cosumer, no default +# -k The key-value string for cosumer, no default +# -g showMsgFlag, default is 0 +# + +$tbNum = 10 +$consumeDelay = 5 +$expectMsgCntFromCtb = 1000 +$expectMsgCntFromNtb = 1000 +$expectMsgCntFromStb = $expectMsgCntFromCtb * $tbNum +print consumeDelay: $consumeDelay +print insert data child num: $tbNum +print expectMsgCntFromCtb: $expectMsgCntFromCtb +print expectMsgCntFromStb: $expectMsgCntFromStb + + +# supported key: +# group.id: +# enable.auto.commit: +# auto.offset.reset: +# td.connect.ip: +# td.connect.user:root +# td.connect.pass:taosdata +# td.connect.port:6030 +# td.connect.db:db + +$numOfTopics = 2 +$expectMsgCntFromStb = $expectMsgCntFromStb * $numOfTopics +$expect_result = @{consume success: @ +$expect_result = $expect_result . $expectMsgCntFromStb +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column, topic_stb_function, topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column, topic_stb_function, topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column, topic_stb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column, topic_stb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +print cmd result----> $system_content +#if $system_content != @{consume success: 20000, 0}@ then +if $system_content != $expect_result then + print expect @{consume success: 20000, 0}@ , actual @system_content + return -1 +endi + +$numOfTopics = 3 +$expectMsgCntFromCtb = $expectMsgCntFromCtb * $numOfTopics +$expect_result = @{consume success: @ +$expect_result = $expect_result . $expectMsgCntFromCtb +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column, topic_ctb_function, topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column, topic_ctb_function, topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +print cmd result----> $system_content +#if $system_content != @{consume success: 300, 0}@ then +if $system_content != $expect_result then + return -1 +endi + +$numOfTopics = 3 +$expectMsgCntFromNtb = $expectMsgCntFromNtb * $tbNum +$expectMsgCntFromNtb = $expectMsgCntFromNtb * $numOfTopics +$expect_result = @{consume success: @ +$expect_result = $expect_result . $expectMsgCntFromNtb +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column, topic_ntb_all, topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromNtb +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column, topic_ntb_all, topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromNtb +print cmd result----> $system_content +#if $system_content != @{consume success: 30000, 0}@ then +if $system_content != $expect_result then + return -1 +endi + +if $loop_cnt == 0 then + $loop_cnt = 1 + $vgroups = 4 + $dbNamme = d1 + goto loop_vgroups +endi + + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/tmq/mainConsumerInOneTopic.sim b/tests/script/tsim/tmq/mainConsumerInOneTopic.sim new file mode 100644 index 0000000000000000000000000000000000000000..d3077238781be7e027553b69738a7be41a97ee9d --- /dev/null +++ b/tests/script/tsim/tmq/mainConsumerInOneTopic.sim @@ -0,0 +1,242 @@ +#### test scenario, please refer to https://jira.taosdata.com:18090/pages/viewpage.action?pageId=135120406 +# scene1: vgroups=1, one topic for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene2: vgroups=1, multi topics for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene3: vgroups=4, one topic for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene4: vgroups=4, multi topics for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# notes1: Scalar function: ABS/ACOS/ASIN/ATAN/CEIL/COS/FLOOR/LOG/POW/ROUND/SIN/SQRT/TAN +# The above use cases are combined with where filter conditions, such as: where ts > "2017-08-12 18:25:58.128Z" and sin(a) > 0.5; +# +# notes2: not support aggregate functions(such as sum/count/min/max) and time-windows(interval). +# +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## +######## This test case include scene1 and scene3 +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## + +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +$loop_cnt = 0 +$vgroups = 1 +$dbNamme = d0 +loop_vgroups: +print =============== create database $dbNamme vgroups $vgroups +sql create database $dbNamme vgroups $vgroups +sql use $dbNamme + +print =============== create super table +sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int) + +sql show stables +if $rows != 1 then + return -1 +endi + +print =============== create child table +$tbPrefix = ct +$tbNum = 100 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using stb tags( $i ) + $i = $i + 1 +endw + +print =============== create normal table +sql create table ntb (ts timestamp, c1 int, c2 float, c3 binary(10)) + +print =============== create multi topics. notes: now only support: +print =============== 1. columns from stb/ctb/ntb; 2. * from ctb/ntb; 3. function from stb/ctb/ntb +print =============== will support: * from stb + +sql create topic topic_stb_column as select ts, c1, c3 from stb +#sql create topic topic_stb_all as select * from stb +sql create topic topic_stb_function as select ts, abs(c1), sin(c2) from stb + +sql create topic topic_ctb_column as select ts, c1, c3 from ct0 +sql create topic topic_ctb_all as select * from ct0 +sql create topic topic_ctb_function as select ts, abs(c1), sin(c2) from ct0 + +sql create topic topic_ntb_column as select ts, c1, c3 from ntb +sql create topic topic_ntb_all as select * from ntb +sql create topic topic_ntb_function as select ts, abs(c1), sin(c2) from ntb + +sql show tables +if $rows != 101 then + return -1 +endi + +print =============== run_back insert data + +if $loop_cnt == 0 then + run_back tsim/tmq/insertFixedDataV2.sim +else + run_back tsim/tmq/insertFixedDataV4.sim +endi + +#sleep 1000 + +#$rowNum = 1000 +#$tstart = 1640966400000 # 2022-01-01 00:00:00.000 +# +#$i = 0 +#while $i < $tbNum +# $tb = $tbPrefix . $i +# +# $x = 0 +# while $x < $rowNum +# $c = $x / 10 +# $c = $c * 10 +# $c = $x - $c +# +# $binary = ' . binary +# $binary = $binary . $c +# $binary = $binary . ' +# +# sql insert into $tb values ($tstart , $c , $x , $binary ) +# sql insert into ntb values ($tstart , $c , $x , $binary ) +# $tstart = $tstart + 1 +# $x = $x + 1 +# endw +# +# $i = $i + 1 +# $tstart = 1640966400000 +#endw + +#root@trd02 /home $ tmq_sim --help +# -c Configuration directory, default is +# -d The name of the database for cosumer, no default +# -t The topic string for cosumer, no default +# -k The key-value string for cosumer, no default +# -g showMsgFlag, default is 0 +# + +$tbNum = 10 +$consumeDelay = 5 +$expectMsgCntFromCtb = 1000 +$expectMsgCntFromStb = $expectMsgCntFromCtb * $tbNum +print consumeDelay: $consumeDelay +print insert data child num: $tbNum +print expectMsgCntFromCtb: $expectMsgCntFromCtb +print expectMsgCntFromStb: $expectMsgCntFromStb + + +# supported key: +# group.id: +# enable.auto.commit: +# auto.offset.reset: +# td.connect.ip: +# td.connect.user:root +# td.connect.pass:taosdata +# td.connect.port:6030 +# td.connect.db:db + +$expect_result = @{consume success: @ +$expect_result = $expect_result . $expectMsgCntFromStb +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +print cmd result----> $system_content +if $system_content != $expect_result then + return -1 +endi + +#print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +#system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +#print cmd result----> $system_content +##if $system_content != @{consume success: 10000, 0}@ then +#if $system_content != $expect_result then +# return -1 +#endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_stb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb +print cmd result----> $system_content +#if $system_content != @{consume success: 10000, 0}@ then +if $system_content != $expect_result then + return -1 +endi + +$expect_result = @{consume success: @ +$expect_result = $expect_result . $expectMsgCntFromCtb +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +print cmd result----> $system_content +if $system_content != $expect_result then + return -1 +endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +print cmd result----> $system_content +if $system_content != $expect_result then + return -1 +endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +print cmd result----> $system_content +if $system_content != $expect_result then + return -1 +endi + +$expect_result = @{consume success: @ +$expect_result = $expect_result . $expectMsgCntFromStb +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +print cmd result----> $system_content +if $system_content != $expect_result then + return -1 +endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +print cmd result----> $system_content +if $system_content != $expect_result then + return -1 +endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb +print cmd result----> $system_content +if $system_content != $expect_result then + return -1 +endi + +if $loop_cnt == 0 then + $loop_cnt = 1 + $vgroups = 4 + $dbNamme = d1 + goto loop_vgroups +endi + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/tmq/multiTopic.sim b/tests/script/tsim/tmq/multiTopic.sim index cd977e5909aad30ded0f06b4d0f83090671bdded..0ce630479969959eed1723a1ec453245dfae717d 100644 --- a/tests/script/tsim/tmq/multiTopic.sim +++ b/tests/script/tsim/tmq/multiTopic.sim @@ -48,24 +48,24 @@ print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $d print $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29 if $loop_cnt == 0 then - if $rows != 2 then + if $rows != 3 then return -1 endi - if $data02 != 1 then # vgroups + if $data22 != 1 then # vgroups print vgroups: $data02 return -1 endi else - if $rows != 3 then + if $rows != 4 then return -1 endi - if $data00 == d1 then - if $data02 != 4 then # vgroups + if $data20 == d1 then + if $data22 != 4 then # vgroups print vgroups: $data02 return -1 endi else - if $data12 != 4 then # vgroups + if $data32 != 4 then # vgroups print vgroups: $data12 return -1 endi diff --git a/tests/script/tsim/tmq/oneTopic.sim b/tests/script/tsim/tmq/oneTopic.sim index 8e8d00977c4060eadaf389f54ccfb9f1dd6e6a6e..e3f9d727b92b960370fcb435e87089dbae330f26 100644 --- a/tests/script/tsim/tmq/oneTopic.sim +++ b/tests/script/tsim/tmq/oneTopic.sim @@ -48,24 +48,24 @@ print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $d print $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29 if $loop_cnt == 0 then - if $rows != 2 then + if $rows != 3 then return -1 endi - if $data02 != 1 then # vgroups + if $data22 != 1 then # vgroups print vgroups: $data02 return -1 endi else - if $rows != 3 then + if $rows != 4 then return -1 endi - if $data00 == d1 then - if $data02 != 4 then # vgroups + if $data20 == d1 then + if $data22 != 4 then # vgroups print vgroups: $data02 return -1 endi else - if $data12 != 4 then # vgroups + if $data32 != 4 then # vgroups print vgroups: $data12 return -1 endi diff --git a/tests/script/tsim/tmq/overlapTopic2Con1Cgrp.sim b/tests/script/tsim/tmq/overlapTopic2Con1Cgrp.sim new file mode 100644 index 0000000000000000000000000000000000000000..62ec3149be1da9bde6c0345922649cfd07559a1e --- /dev/null +++ b/tests/script/tsim/tmq/overlapTopic2Con1Cgrp.sim @@ -0,0 +1,240 @@ +#### test scenario, please refer to https://jira.taosdata.com:18090/pages/viewpage.action?pageId=135120406 +# scene1: vgroups=1, one topic for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene2: vgroups=1, multi topics for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene3: vgroups=4, one topic for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# scene4: vgroups=4, multi topics for one consumer, include: columns from stb/ctb/ntb, * from stb/ctb/ntb, Scalar function from stb/ctb/ntb +# notes1: Scalar function: ABS/ACOS/ASIN/ATAN/CEIL/COS/FLOOR/LOG/POW/ROUND/SIN/SQRT/TAN +# The above use cases are combined with where filter conditions, such as: where ts > "2017-08-12 18:25:58.128Z" and sin(a) > 0.5; +# +# notes2: not support aggregate functions(such as sum/count/min/max) and time-windows(interval). +# +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## +######## This test case include scene2 and scene4 +######## ######## ######## ######## ######## ######## ######## ######## ######## ######## + +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 +system sh/exec.sh -n dnode1 -s start + +$loop_cnt = 0 +check_dnode_ready: + $loop_cnt = $loop_cnt + 1 + sleep 200 + if $loop_cnt == 10 then + print ====> dnode not ready! + return -1 + endi +sql show dnodes +print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05 +if $data00 != 1 then + return -1 +endi +if $data04 != ready then + goto check_dnode_ready +endi + +sql connect + +$loop_cnt = 0 +$vgroups = 1 +$dbNamme = d0 +loop_vgroups: +print =============== create database $dbNamme vgroups $vgroups +sql create database $dbNamme vgroups $vgroups +sql show databases +print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 +print $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19 +print $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29 + +if $loop_cnt == 0 then + if $rows != 2 then + return -1 + endi + if $data02 != 1 then # vgroups + print vgroups: $data02 + return -1 + endi +else + if $rows != 3 then + return -1 + endi + if $data00 == d1 then + if $data02 != 4 then # vgroups + print vgroups: $data02 + return -1 + endi + else + if $data12 != 4 then # vgroups + print vgroups: $data12 + return -1 + endi + endi +endi + +sql use $dbNamme + +print =============== create super table +sql create table if not exists stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int) + +sql show stables +if $rows != 1 then + return -1 +endi + +print =============== create child table +$tbPrefix = ct +$tbNum = 10 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + sql create table $tb using stb tags( $i ) + $i = $i + 1 +endw + +print =============== create normal table +sql create table ntb (ts timestamp, c1 int, c2 float, c3 binary(10)) + +print =============== create multi topics. notes: now only support: +print =============== 1. columns from stb/ctb/ntb; 2. * from ctb/ntb; 3. function from stb/ctb/ntb +print =============== will support: * from stb + +sql create topic topic_stb_column as select ts, c1, c3 from stb +sql create topic topic_stb_all as select sqrt(c1) from stb +sql create topic topic_stb_function as select ts, abs(c1), sin(c2) from stb + +sql create topic topic_ctb_column as select ts, c1, c3 from ct0 +sql create topic topic_ctb_all as select * from ct0 +sql create topic topic_ctb_function as select ts, abs(c1), sin(c2) from ct0 + +sql create topic topic_ntb_column as select ts, c1, c3 from ntb +sql create topic topic_ntb_all as select * from ntb +sql create topic topic_ntb_function as select ts, abs(c1), sin(c2) from ntb + +sql show tables +if $rows != 11 then + return -1 +endi + +print =============== insert data +$rowNum = 100 +$tstart = 1640966400000 # 2022-01-01 00:00:00.000 + +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i + + $x = 0 + while $x < $rowNum + $c = $x / 10 + $c = $c * 10 + $c = $x - $c + + $binary = ' . binary + $binary = $binary . $c + $binary = $binary . ' + + sql insert into $tb values ($tstart , $c , $x , $binary ) + sql insert into ntb values ($tstart , $c , $x , $binary ) + $tstart = $tstart + 1 + $x = $x + 1 + endw + + $i = $i + 1 +# $tstart = 1640966400000 +endw + +#root@trd02 /home $ tmq_sim --help +# -c Configuration directory, default is +# -d The name of the database for cosumer, no default +# -t The topic string for cosumer, no default +# -k The key-value string for cosumer, no default +# -g showMsgFlag, default is 0 +# + +$consumeDelay = 2 + +$expectMsgCntFromCtb = $rowNum +$expectMsgCntFromStb = $rowNum * $tbNum +$expectMsgCntFromNtb = $rowNum * $tbNum +print expectMsgCntFromCtb: $expectMsgCntFromCtb +print expectMsgCntFromStb: $expectMsgCntFromStb +print expectMsgCntFromNtb: $expectMsgCntFromNtb + +# supported key: +# group.id: +# enable.auto.commit: +# auto.offset.reset: +# td.connect.ip: +# td.connect.user:root +# td.connect.pass:taosdata +# td.connect.port:6030 +# td.connect.db:db + +$numOfTopics = 3 +$totalMsgCntOfmultiTopics = $expectMsgCntFromStb * $numOfTopics +$expect_result = @{consume success: @ +$expect_result = $expect_result . $totalMsgCntOfmultiTopics +$expect_result = $expect_result . @, @ +$expect_result = $expect_result . 0} +print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_column, topic_stb_function" -k1 "group.id:tg2" -t "topic_stb_function, topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb -j 2 +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_column, topic_stb_function" -k1 "group.id:tg2" -t "topic_stb_function, topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb -j 2 +print cmd result----> $system_content +if $system_content != success then + return -1 +endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_column, topic_stb_function" -k1 "group.id:tg1" -t "topic_stb_function, topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb -j 3 +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t1 "topic_stb_column, topic_stb_function" -k1 "group.id:tg1" -t "topic_stb_function, topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromStb -j 3 +print cmd result----> $system_content +if $system_content != success then + return -1 +endi + +#$numOfTopics = 3 +#$totalMsgCntOfmultiTopics = $rowNum * $numOfTopics +#$expect_result = @{consume success: @ +#$expect_result = $expect_result . $totalMsgCntOfmultiTopics +#$expect_result = $expect_result . @, @ +#$expect_result = $expect_result . 0} +#print expect_result----> $expect_result +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column, topic_ctb_function, topic_ctb_all" -k "group.id:tg2" -t "topic_ctb_column, topic_ctb_function, topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 4 +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column, topic_ctb_function, topic_ctb_all" -k "group.id:tg2" -t "topic_ctb_column, topic_ctb_function, topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 4 +print cmd result----> $system_content +if $system_content != success then + return -1 +endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column, topic_ctb_function" -k "group.id:tg1" -t "topic_ctb_function, topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 3 +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ctb_column, topic_ctb_function" -k "group.id:tg1" -t "topic_ctb_function, topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromCtb -j 3 +print cmd result----> $system_content +if $system_content != success then + return -1 +endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column, topic_ntb_function, topic_ntb_all" -k "group.id:tg2" -t "topic_ntb_column, topic_ntb_function, topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromNtb -j 4 +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column, topic_ntb_function, topic_ntb_all" -k "group.id:tg2" -t "topic_ntb_column, topic_ntb_function, topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromNtb -j 4 +print cmd result----> $system_content +if $system_content != success then + return -1 +endi + +print cmd===> system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column, topic_ntb_function" -k "group.id:tg1" -t "topic_ntb_function, topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromNtb -j 3 +system_content ../../debug/tests/test/c/tmq_sim -c ../../sim/tsim/cfg -d $dbNamme -t "topic_ntb_column, topic_ntb_function" -k "group.id:tg1" -t "topic_ntb_function, topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectMsgCntFromNtb -j 3 +print cmd result----> $system_content +if $system_content != success then + return -1 +endi + + +if $loop_cnt == 0 then + $loop_cnt = 1 + $vgroups = 4 + $dbNamme = d1 + goto loop_vgroups +endi + + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/test/c/tmqDemo.c b/tests/test/c/tmqDemo.c index d339166d74dea334e03a79a93e524e725294d5be..2b3e9963f08bf21f2a8b527c31a7bfde5d016d4b 100644 --- a/tests/test/c/tmqDemo.c +++ b/tests/test/c/tmqDemo.c @@ -13,76 +13,74 @@ * along with this program. If not, see . */ -// clang-format off - #include +#include #include +#include #include -#include #include #include +#include #include -#include -#include #include "taos.h" #include "taoserror.h" #include "tlog.h" -#define GREEN "\033[1;32m" -#define NC "\033[0m" +#define GREEN "\033[1;32m" +#define NC "\033[0m" #define min(a, b) (((a) < (b)) ? (a) : (b)) -#define MAX_SQL_STR_LEN (1024 * 1024) -#define MAX_ROW_STR_LEN (16 * 1024) +#define MAX_SQL_STR_LEN (1024 * 1024) +#define MAX_ROW_STR_LEN (16 * 1024) enum _RUN_MODE { - TMQ_RUN_INSERT_AND_CONSUME, - TMQ_RUN_ONLY_INSERT, - TMQ_RUN_ONLY_CONSUME, - TMQ_RUN_MODE_BUTT + TMQ_RUN_INSERT_AND_CONSUME, + TMQ_RUN_ONLY_INSERT, + TMQ_RUN_ONLY_CONSUME, + TMQ_RUN_MODE_BUTT, }; typedef struct { - char dbName[32]; - char stbName[64]; - char resultFileName[256]; - char vnodeWalPath[256]; - int32_t numOfThreads; - int32_t numOfTables; - int32_t numOfVgroups; - int32_t runMode; - int32_t numOfColumn; - double ratio; - int32_t batchNumOfRow; - int32_t totalRowsOfPerTbl; - int64_t startTimestamp; - int32_t showMsgFlag; - int32_t simCase; - - int32_t totalRowsOfT2; + char dbName[32]; + char stbName[64]; + char resultFileName[256]; + char vnodeWalPath[256]; + int32_t numOfThreads; + int32_t numOfTables; + int32_t numOfVgroups; + int32_t runMode; + int32_t numOfColumn; + double ratio; + int32_t batchNumOfRow; + int32_t totalRowsOfPerTbl; + int64_t startTimestamp; + int32_t showMsgFlag; + int32_t simCase; + + int32_t totalRowsOfT2; } SConfInfo; static SConfInfo g_stConfInfo = { "tmqdb", "stb", - "./tmqResult.txt", // output_file + "./tmqResult.txt", // output_file "", // /data2/dnode/data/vnode/vnode2/wal", - 1, // threads - 1, // tables - 1, // vgroups - 0, // run mode - 1, // columns - 1, // ratio - 1, // batch size - 10000, // total rows for per table - 0, // 2020-01-01 00:00:00.000 - 0, // show consume msg switch - 0, // if run in sim case + 1, // threads + 1, // tables + 1, // vgroups + 0, // run mode + 1, // columns + 1, // ratio + 1, // batch size + 10000, // total rows for per table + 0, // 2020-01-01 00:00:00.000 + 0, // show consume msg switch + 0, // if run in sim case 10000, }; -char* g_pRowValue = NULL; +char* g_pRowValue = NULL; TdFilePtr g_fp = NULL; static void printHelp() { @@ -125,10 +123,8 @@ static void printHelp() { exit(EXIT_SUCCESS); } -void parseArgument(int32_t argc, char *argv[]) { - +void parseArgument(int32_t argc, char* argv[]) { g_stConfInfo.startTimestamp = 1640966400000; // 2020-01-01 00:00:00.000 - for (int32_t i = 1; i < argc; i++) { if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { @@ -156,7 +152,7 @@ void parseArgument(int32_t argc, char *argv[]) { g_stConfInfo.batchNumOfRow = atoi(argv[++i]); } else if (strcmp(argv[i], "-r") == 0) { g_stConfInfo.totalRowsOfPerTbl = atoi(argv[++i]); - } else if (strcmp(argv[i], "-l") == 0) { + } else if (strcmp(argv[i], "-l") == 0) { g_stConfInfo.numOfColumn = atoi(argv[++i]); } else if (strcmp(argv[i], "-q") == 0) { g_stConfInfo.ratio = atof(argv[++i]); @@ -168,7 +164,7 @@ void parseArgument(int32_t argc, char *argv[]) { g_stConfInfo.simCase = atol(argv[++i]); } else { printf("%s unknow para: %s %s", GREEN, argv[++i], NC); - exit(-1); + exit(-1); } } @@ -191,73 +187,71 @@ void parseArgument(int32_t argc, char *argv[]) { pPrint("%s totalRowsOfT2:%d %s", GREEN, g_stConfInfo.totalRowsOfT2, NC); pPrint("%s startTimestamp:%" PRId64" %s", GREEN, g_stConfInfo.startTimestamp, NC); pPrint("%s showMsgFlag:%d %s", GREEN, g_stConfInfo.showMsgFlag, NC); -#endif +#endif } -static int running = 1; -static void msg_process(tmq_message_t* message) { tmqShowMsg(message); } +static int running = 1; +/*static void msg_process(tmq_message_t* message) { tmqShowMsg(message); }*/ // calc dir size (not include itself 4096Byte) -int64_t getDirectorySize(char *dir) -{ - TdDirPtr pDir; - TdDirEntryPtr pDirEntry; - int64_t totalSize=0; - - if ((pDir = taosOpenDir(dir)) == NULL) { - fprintf(stderr, "Cannot open dir: %s\n", dir); - return -1; - } +int64_t getDirectorySize(char* dir) { + TdDirPtr pDir; + TdDirEntryPtr pDirEntry; + int64_t totalSize = 0; - //lstat(dir, &statbuf); - //totalSize+=statbuf.st_size; - - while ((pDirEntry = taosReadDir(pDir)) != NULL) { - char subdir[1024]; - char* fileName = taosGetDirEntryName(pDirEntry); - sprintf(subdir, "%s/%s", dir, fileName); - - //printf("===d_name: %s\n", entry->d_name); - if (taosIsDir(subdir)) { - if (strcmp(".", fileName) == 0 || strcmp("..", fileName) == 0) { - continue; - } - - int64_t subDirSize = getDirectorySize(subdir); - totalSize+=subDirSize; - } else if (0 == strcmp(strchr(fileName, '.'), ".log")) { // only calc .log file size, and not include .idx file - int64_t file_size = 0; - taosStatFile(subdir, &file_size, NULL); - totalSize+=file_size; - } + if ((pDir = taosOpenDir(dir)) == NULL) { + fprintf(stderr, "Cannot open dir: %s\n", dir); + return -1; + } + + // lstat(dir, &statbuf); + // totalSize+=statbuf.st_size; + + while ((pDirEntry = taosReadDir(pDir)) != NULL) { + char subdir[1024]; + char* fileName = taosGetDirEntryName(pDirEntry); + sprintf(subdir, "%s/%s", dir, fileName); + + // printf("===d_name: %s\n", entry->d_name); + if (taosIsDir(subdir)) { + if (strcmp(".", fileName) == 0 || strcmp("..", fileName) == 0) { + continue; + } + + int64_t subDirSize = getDirectorySize(subdir); + totalSize += subDirSize; + } else if (0 == strcmp(strchr(fileName, '.'), ".log")) { // only calc .log file size, and not include .idx file + int64_t file_size = 0; + taosStatFile(subdir, &file_size, NULL); + totalSize += file_size; } + } - taosCloseDir(pDir); - return totalSize; + taosCloseDir(pDir); + return totalSize; } - -int queryDB(TAOS *taos, char *command) { - TAOS_RES *pRes = taos_query(taos, command); - int code = taos_errno(pRes); - //if ((code != 0) && (code != TSDB_CODE_RPC_AUTH_REQUIRED)) { - if (code != 0) { - pError("failed to reason:%s, sql: %s", tstrerror(code), command); - taos_free_result(pRes); - return -1; - } - taos_free_result(pRes); - return 0 ; +int queryDB(TAOS* taos, char* command) { + TAOS_RES* pRes = taos_query(taos, command); + int code = taos_errno(pRes); + // if ((code != 0) && (code != TSDB_CODE_RPC_AUTH_REQUIRED)) { + if (code != 0) { + pError("failed to reason:%s, sql: %s", tstrerror(code), command); + taos_free_result(pRes); + return -1; + } + taos_free_result(pRes); + return 0; } int32_t init_env() { char sqlStr[1024] = {0}; - + TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0); if (pConn == NULL) { return -1; } - + sprintf(sqlStr, "create database if not exists %s vgroups %d", g_stConfInfo.dbName, g_stConfInfo.numOfVgroups); TAOS_RES* pRes = taos_query(pConn, sqlStr); if (taos_errno(pRes) != 0) { @@ -282,19 +276,19 @@ int32_t init_env() { int32_t dataLen = 0; int32_t sqlLen = 0; - sqlLen += sprintf(sqlStr+sqlLen, "create stable if not exists %s (ts timestamp, ", g_stConfInfo.stbName); + sqlLen += sprintf(sqlStr + sqlLen, "create stable if not exists %s (ts timestamp, ", g_stConfInfo.stbName); for (int32_t i = 0; i < g_stConfInfo.numOfColumn; i++) { - if (i == g_stConfInfo.numOfColumn - 1) { - sqlLen += sprintf(sqlStr+sqlLen, "c%d int) ", i); - memcpy(g_pRowValue + dataLen, "66778899", strlen("66778899")); - dataLen += strlen("66778899"); - } else { - sqlLen += sprintf(sqlStr+sqlLen, "c%d int, ", i); - memcpy(g_pRowValue + dataLen, "66778899, ", strlen("66778899, ")); - dataLen += strlen("66778899, "); - } - } - sqlLen += sprintf(sqlStr+sqlLen, "tags (t0 int)"); + if (i == g_stConfInfo.numOfColumn - 1) { + sqlLen += sprintf(sqlStr + sqlLen, "c%d int) ", i); + memcpy(g_pRowValue + dataLen, "66778899", strlen("66778899")); + dataLen += strlen("66778899"); + } else { + sqlLen += sprintf(sqlStr + sqlLen, "c%d int, ", i); + memcpy(g_pRowValue + dataLen, "66778899, ", strlen("66778899, ")); + dataLen += strlen("66778899, "); + } + } + sqlLen += sprintf(sqlStr + sqlLen, "tags (t0 int)"); pRes = taos_query(pConn, sqlStr); if (taos_errno(pRes) != 0) { @@ -313,7 +307,7 @@ int32_t init_env() { taos_free_result(pRes); } - //const char* sql = "select * from tu1"; + // const char* sql = "select * from tu1"; sprintf(sqlStr, "create topic test_stb_topic_1 as select ts,c0 from %s", g_stConfInfo.stbName); /*pRes = tmq_create_topic(pConn, "test_stb_topic_1", sqlStr, strlen(sqlStr));*/ pRes = taos_query(pConn, sqlStr); @@ -327,6 +321,7 @@ int32_t init_env() { } tmq_t* build_consumer() { +#if 0 char sqlStr[1024] = {0}; TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0); @@ -338,10 +333,16 @@ tmq_t* build_consumer() { printf("error in use db, reason:%s\n", taos_errstr(pRes)); } taos_free_result(pRes); +#endif tmq_conf_t* conf = tmq_conf_new(); tmq_conf_set(conf, "group.id", "tg2"); - tmq_t* tmq = tmq_consumer_new(pConn, conf, NULL, 0); + tmq_conf_set(conf, "td.connect.user", "root"); + tmq_conf_set(conf, "td.connect.pass", "taosdata"); + tmq_conf_set(conf, "td.connect.db", g_stConfInfo.dbName); + tmq_t* tmq = tmq_consumer_new1(conf, NULL, 0); + assert(tmq); + tmq_conf_destroy(conf); return tmq; } @@ -363,9 +364,9 @@ void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) { } while (running) { - tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 1); + TAOS_RES* tmqmessage = tmq_consumer_poll(tmq, 1); if (tmqmessage) { - msg_process(tmqmessage); + /*msg_process(tmqmessage);*/ tmq_message_destroy(tmqmessage); if ((++msg_count % MIN_COMMIT_COUNT) == 0) tmq_commit(tmq, NULL, 0); @@ -392,24 +393,24 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics, int32_t totalMsgs, int64_t walLog int32_t skipLogNum = 0; int64_t startTime = taosGetTimestampUs(); while (running) { - tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 3000); + TAOS_RES* tmqmessage = tmq_consumer_poll(tmq, 3000); if (tmqmessage) { batchCnt++; - skipLogNum += tmqGetSkipLogNum(tmqmessage); - if (0 != g_stConfInfo.showMsgFlag) { - msg_process(tmqmessage); - } + /*skipLogNum += tmqGetSkipLogNum(tmqmessage);*/ + if (0 != g_stConfInfo.showMsgFlag) { + /*msg_process(tmqmessage);*/ + } tmq_message_destroy(tmqmessage); } else { break; } } int64_t endTime = taosGetTimestampUs(); - double consumeTime = (double)(endTime - startTime) / 1000000; + double consumeTime = (double)(endTime - startTime) / 1000000; if (batchCnt != totalMsgs) { - printf("%s inserted msgs: %d and consume msgs: %d mismatch %s", GREEN, totalMsgs, batchCnt, NC); - /*exit(-1);*/ + printf("%s inserted msgs: %d and consume msgs: %d mismatch %s", GREEN, totalMsgs, batchCnt, NC); + /*exit(-1);*/ } if (0 == g_stConfInfo.simCase) { @@ -417,12 +418,14 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics, int32_t totalMsgs, int64_t walLog } else { printf("{consume success: %d}", totalMsgs); } - taosFprintfFile(g_fp, "|%10d | %10.3f | %8.2f | %10.2f| %10.2f |\n", batchCnt, consumeTime, (double)batchCnt / consumeTime, (double)walLogSize / (1024 * 1024.0) / consumeTime, (double)walLogSize / 1024.0 / batchCnt); + taosFprintfFile(g_fp, "|%10d | %10.3f | %8.2f | %10.2f| %10.2f |\n", batchCnt, consumeTime, + (double)batchCnt / consumeTime, (double)walLogSize / (1024 * 1024.0) / consumeTime, + (double)walLogSize / 1024.0 / batchCnt); err = tmq_consumer_close(tmq); if (err) { fprintf(stderr, "%% Failed to close consumer: %s\n", tmq_err2str(err)); - exit(-1); + exit(-1); } } @@ -430,7 +433,7 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics, int32_t totalMsgs, int64_t walLog int32_t syncWriteData() { TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0); if (pConn == NULL) { - return -1; + return -1; } char sqlStr[1024] = {0}; @@ -449,11 +452,11 @@ int32_t syncWriteData() { } int32_t totalMsgs = 0; - + int64_t time_counter = g_stConfInfo.startTimestamp; for (int i = 0; i < g_stConfInfo.totalRowsOfPerTbl;) { for (int tID = 0; tID <= g_stConfInfo.numOfTables - 1; tID++) { - int inserted = i; + int inserted = i; int64_t tmp_time = time_counter; int32_t data_len = 0; @@ -465,22 +468,22 @@ int32_t syncWriteData() { k++; if (inserted >= g_stConfInfo.totalRowsOfPerTbl) { - break; + break; } - if (data_len > MAX_SQL_STR_LEN - MAX_ROW_STR_LEN) { + if (data_len > MAX_SQL_STR_LEN - MAX_ROW_STR_LEN) { break; - } + } } int code = queryDB(pConn, buffer); - if (0 != code){ + if (0 != code) { fprintf(stderr, "insert data error!\n"); - taosMemoryFreeClear(buffer); - return -1; - } + taosMemoryFreeClear(buffer); + return -1; + } - totalMsgs++; + totalMsgs++; if (tID == g_stConfInfo.numOfTables - 1) { i = inserted; @@ -492,12 +495,11 @@ int32_t syncWriteData() { return totalMsgs; } - // sync insertion int32_t syncWriteDataByRatio() { TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0); if (pConn == NULL) { - return -1; + return -1; } char sqlStr[1024] = {0}; @@ -518,27 +520,27 @@ int32_t syncWriteDataByRatio() { int32_t totalMsgs = 0; int32_t insertedOfT1 = 0; - int32_t insertedOfT2 = 0; + int32_t insertedOfT2 = 0; int64_t tsOfT1 = g_stConfInfo.startTimestamp; int64_t tsOfT2 = g_stConfInfo.startTimestamp; int64_t tmp_time; - + for (;;) { - if ((insertedOfT1 >= g_stConfInfo.totalRowsOfPerTbl) && (insertedOfT2 >= g_stConfInfo.totalRowsOfT2)) { + if ((insertedOfT1 >= g_stConfInfo.totalRowsOfPerTbl) && (insertedOfT2 >= g_stConfInfo.totalRowsOfT2)) { break; - } - + } + for (int tID = 0; tID <= g_stConfInfo.numOfTables - 1; tID++) { if (0 == tID) { - tmp_time = tsOfT1; + tmp_time = tsOfT1; if (insertedOfT1 >= g_stConfInfo.totalRowsOfPerTbl) { - continue; + continue; } - } else if (1 == tID){ - tmp_time = tsOfT2; + } else if (1 == tID) { + tmp_time = tsOfT2; if (insertedOfT2 >= g_stConfInfo.totalRowsOfT2) { - continue; + continue; } } @@ -548,79 +550,86 @@ int32_t syncWriteDataByRatio() { for (k = 0; k < g_stConfInfo.batchNumOfRow;) { data_len += sprintf(buffer + data_len, "(%" PRId64 ", %s) ", tmp_time++, g_pRowValue); k++; - if (0 == tID) { + if (0 == tID) { insertedOfT1++; - if (insertedOfT1 >= g_stConfInfo.totalRowsOfPerTbl) { - break; - } - } else if (1 == tID){ + if (insertedOfT1 >= g_stConfInfo.totalRowsOfPerTbl) { + break; + } + } else if (1 == tID) { insertedOfT2++; - if (insertedOfT2 >= g_stConfInfo.totalRowsOfT2) { - break; - } - } + if (insertedOfT2 >= g_stConfInfo.totalRowsOfT2) { + break; + } + } - if (data_len > MAX_SQL_STR_LEN - MAX_ROW_STR_LEN) { + if (data_len > MAX_SQL_STR_LEN - MAX_ROW_STR_LEN) { break; - } + } } int code = queryDB(pConn, buffer); - if (0 != code){ + if (0 != code) { fprintf(stderr, "insert data error!\n"); - taosMemoryFreeClear(buffer); - return -1; - } - + taosMemoryFreeClear(buffer); + return -1; + } + if (0 == tID) { - tsOfT1 = tmp_time; - } else if (1 == tID){ - tsOfT2 = tmp_time; + tsOfT1 = tmp_time; + } else if (1 == tID) { + tsOfT2 = tmp_time; } - totalMsgs++; + totalMsgs++; } } - pPrint("expect insert rows: T1[%d] T2[%d], actual insert rows: T1[%d] T2[%d]\n", g_stConfInfo.totalRowsOfPerTbl, g_stConfInfo.totalRowsOfT2, insertedOfT1, insertedOfT2); + pPrint("expect insert rows: T1[%d] T2[%d], actual insert rows: T1[%d] T2[%d]\n", g_stConfInfo.totalRowsOfPerTbl, + g_stConfInfo.totalRowsOfT2, insertedOfT1, insertedOfT2); taosMemoryFreeClear(buffer); return totalMsgs; } void printParaIntoFile() { // FILE *fp = fopen(g_stConfInfo.resultFileName, "a"); - TdFilePtr pFile = taosOpenFile(g_stConfInfo.resultFileName, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_STREAM); + TdFilePtr pFile = + taosOpenFile(g_stConfInfo.resultFileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_STREAM); if (NULL == pFile) { fprintf(stderr, "Failed to open %s for save result\n", g_stConfInfo.resultFileName); - exit -1; + exit - 1; }; g_fp = pFile; - time_t tTime = taosGetTimestampSec(); - struct tm tm = *localtime(&tTime); + time_t tTime = taosGetTimestampSec(); + struct tm tm = *taosLocalTime(&tTime, NULL); taosFprintfFile(pFile, "###################################################################\n"); - taosFprintfFile(pFile, "# configDir: %s\n", configDir); - taosFprintfFile(pFile, "# dbName: %s\n", g_stConfInfo.dbName); - taosFprintfFile(pFile, "# stbName: %s\n", g_stConfInfo.stbName); - taosFprintfFile(pFile, "# vnodeWalPath: %s\n", g_stConfInfo.vnodeWalPath); - taosFprintfFile(pFile, "# numOfTables: %d\n", g_stConfInfo.numOfTables); - taosFprintfFile(pFile, "# numOfThreads: %d\n", g_stConfInfo.numOfThreads); - taosFprintfFile(pFile, "# numOfVgroups: %d\n", g_stConfInfo.numOfVgroups); - taosFprintfFile(pFile, "# runMode: %d\n", g_stConfInfo.runMode); - taosFprintfFile(pFile, "# ratio: %f\n", g_stConfInfo.ratio); - taosFprintfFile(pFile, "# numOfColumn: %d\n", g_stConfInfo.numOfColumn); - taosFprintfFile(pFile, "# batchNumOfRow: %d\n", g_stConfInfo.batchNumOfRow); - taosFprintfFile(pFile, "# totalRowsOfPerTbl: %d\n", g_stConfInfo.totalRowsOfPerTbl); - taosFprintfFile(pFile, "# totalRowsOfT2: %d\n", g_stConfInfo.totalRowsOfT2); + taosFprintfFile(pFile, "# configDir: %s\n", configDir); + taosFprintfFile(pFile, "# dbName: %s\n", g_stConfInfo.dbName); + taosFprintfFile(pFile, "# stbName: %s\n", g_stConfInfo.stbName); + taosFprintfFile(pFile, "# vnodeWalPath: %s\n", g_stConfInfo.vnodeWalPath); + taosFprintfFile(pFile, "# numOfTables: %d\n", g_stConfInfo.numOfTables); + taosFprintfFile(pFile, "# numOfThreads: %d\n", g_stConfInfo.numOfThreads); + taosFprintfFile(pFile, "# numOfVgroups: %d\n", g_stConfInfo.numOfVgroups); + taosFprintfFile(pFile, "# runMode: %d\n", g_stConfInfo.runMode); + taosFprintfFile(pFile, "# ratio: %f\n", g_stConfInfo.ratio); + taosFprintfFile(pFile, "# numOfColumn: %d\n", g_stConfInfo.numOfColumn); + taosFprintfFile(pFile, "# batchNumOfRow: %d\n", g_stConfInfo.batchNumOfRow); + taosFprintfFile(pFile, "# totalRowsOfPerTbl: %d\n", g_stConfInfo.totalRowsOfPerTbl); + taosFprintfFile(pFile, "# totalRowsOfT2: %d\n", g_stConfInfo.totalRowsOfT2); taosFprintfFile(pFile, "# Test 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); + tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); taosFprintfFile(pFile, "###################################################################\n"); - taosFprintfFile(pFile, "|-------------------------------insert info-----------------------------|--------------------------------consume info---------------------------------|\n"); - taosFprintfFile(pFile, "|batch size| insert msgs | insert time(s) | msgs/s | walLogSize(MB) | consume msgs | consume time(s) | msgs/s | MB/s | avg msg size(KB) |\n"); + taosFprintfFile(pFile, + "|-------------------------------insert " + "info-----------------------------|--------------------------------consume " + "info---------------------------------|\n"); + taosFprintfFile(pFile, + "|batch size| insert msgs | insert time(s) | msgs/s | walLogSize(MB) | consume msgs | consume " + "time(s) | msgs/s | MB/s | avg msg size(KB) |\n"); taosFprintfFile(g_fp, "|%10d", g_stConfInfo.batchNumOfRow); } -int main(int32_t argc, char *argv[]) { +int main(int32_t argc, char* argv[]) { parseArgument(argc, argv); printParaIntoFile(); @@ -630,70 +639,70 @@ int main(int32_t argc, char *argv[]) { code = init_env(); if (code != 0) { fprintf(stderr, "%% init_env error!\n"); - return -1; + return -1; } int32_t totalMsgs = 0; if (g_stConfInfo.runMode != TMQ_RUN_ONLY_CONSUME) { - int64_t startTs = taosGetTimestampUs(); if (1 == g_stConfInfo.ratio) { - totalMsgs = syncWriteData(); + totalMsgs = syncWriteData(); } else { - totalMsgs = syncWriteDataByRatio(); - } - + totalMsgs = syncWriteDataByRatio(); + } + if (totalMsgs <= 0) { - pError("inset data error!\n"); + pError("inset data error!\n"); return -1; - } - int64_t endTs = taosGetTimestampUs(); - int64_t delay = endTs - startTs; - - int32_t totalRows = 0; - if (1 == g_stConfInfo.ratio) { - totalRows = g_stConfInfo.totalRowsOfPerTbl * g_stConfInfo.numOfTables; - } else { - totalRows = g_stConfInfo.totalRowsOfPerTbl * (1 + g_stConfInfo.ratio); - } - - float seconds = delay / 1000000.0; - float rowsSpeed = totalRows / seconds; - float msgsSpeed = totalMsgs / seconds; - - - if ((0 == g_stConfInfo.simCase) && (strlen(g_stConfInfo.vnodeWalPath))) { - walLogSize = getDirectorySize(g_stConfInfo.vnodeWalPath); - if (walLogSize <= 0) { - printf("%s size incorrect!", g_stConfInfo.vnodeWalPath); - exit(-1); - } else { - pPrint(".log file size in vnode2/wal: %.3f MBytes\n", (double)walLogSize/(1024 * 1024.0)); - } - } - - if (0 == g_stConfInfo.simCase) { - pPrint("insert result: %d rows, %d msgs, time:%.3f sec, speed:%.1f rows/second, %.1f msgs/second\n", totalRows, totalMsgs, seconds, rowsSpeed, msgsSpeed); } - taosFprintfFile(g_fp, "|%10d | %10.3f | %8.2f | %10.3f ", totalMsgs, seconds, msgsSpeed, (double)walLogSize/(1024 * 1024.0)); + int64_t endTs = taosGetTimestampUs(); + int64_t delay = endTs - startTs; + + int32_t totalRows = 0; + if (1 == g_stConfInfo.ratio) { + totalRows = g_stConfInfo.totalRowsOfPerTbl * g_stConfInfo.numOfTables; + } else { + totalRows = g_stConfInfo.totalRowsOfPerTbl * (1 + g_stConfInfo.ratio); + } + + float seconds = delay / 1000000.0; + float rowsSpeed = totalRows / seconds; + float msgsSpeed = totalMsgs / seconds; + + if ((0 == g_stConfInfo.simCase) && (strlen(g_stConfInfo.vnodeWalPath))) { + walLogSize = getDirectorySize(g_stConfInfo.vnodeWalPath); + if (walLogSize <= 0) { + printf("%s size incorrect!", g_stConfInfo.vnodeWalPath); + exit(-1); + } else { + pPrint(".log file size in vnode2/wal: %.3f MBytes\n", (double)walLogSize / (1024 * 1024.0)); + } + } + + if (0 == g_stConfInfo.simCase) { + pPrint("insert result: %d rows, %d msgs, time:%.3f sec, speed:%.1f rows/second, %.1f msgs/second\n", totalRows, + totalMsgs, seconds, rowsSpeed, msgsSpeed); + } + taosFprintfFile(g_fp, "|%10d | %10.3f | %8.2f | %10.3f ", totalMsgs, seconds, msgsSpeed, + (double)walLogSize / (1024 * 1024.0)); } if (g_stConfInfo.runMode == TMQ_RUN_ONLY_INSERT) { return 0; } - - tmq_t* tmq = build_consumer(); + + tmq_t* tmq = build_consumer(); tmq_list_t* topic_list = build_topic_list(); - if ((NULL == tmq) || (NULL == topic_list)){ + if ((NULL == tmq) || (NULL == topic_list)) { return -1; } - + perf_loop(tmq, topic_list, totalMsgs, walLogSize); taosMemoryFreeClear(g_pRowValue); - taosFprintfFile(g_fp, "\n"); - taosCloseFile(&g_fp); + taosFprintfFile(g_fp, "\n"); + taosCloseFile(&g_fp); return 0; } diff --git a/tests/test/c/tmqSim.c b/tests/test/c/tmqSim.c index 236d1e2eed9360c80d3f0ba6193f47555f6ff47a..eaca8f151e9311fa113de29b6f1be838716f1239 100644 --- a/tests/test/c/tmqSim.c +++ b/tests/test/c/tmqSim.c @@ -13,49 +13,65 @@ * along with this program. If not, see . */ -// clang-format off - #include +#include #include +#include #include -#include #include #include +#include #include -#include -#include #include "taos.h" #include "taoserror.h" #include "tlog.h" -#define GREEN "\033[1;32m" -#define NC "\033[0m" +#define GREEN "\033[1;32m" +#define NC "\033[0m" #define min(a, b) (((a) < (b)) ? (a) : (b)) -#define MAX_SQL_STR_LEN (1024 * 1024) -#define MAX_ROW_STR_LEN (16 * 1024) +#define MAX_SQL_STR_LEN (1024 * 1024) +#define MAX_ROW_STR_LEN (16 * 1024) + +typedef struct { + int32_t expectMsgCnt; + int32_t consumeMsgCnt; + TdThread thread; +} SThreadInfo; typedef struct { - // input from argvs - char dbName[32]; - char topicString[256]; - char keyString[1024]; - int32_t showMsgFlag; - - // save result after parse agrvs - int32_t numOfTopic; - char topics[32][64]; - - int32_t numOfKey; - char key[32][64]; - char value[32][64]; + // input from argvs + char dbName[32]; + char topicString[256]; + char keyString[1024]; + char topicString1[256]; + char keyString1[1024]; + int32_t showMsgFlag; + int32_t consumeDelay; // unit s + int32_t consumeMsgCnt; + int32_t checkMode; + + // save result after parse agrvs + int32_t numOfTopic; + char topics[32][64]; + + int32_t numOfKey; + char key[32][64]; + char value[32][64]; + + int32_t numOfTopic1; + char topics1[32][64]; + + int32_t numOfKey1; + char key1[32][64]; + char value1[32][64]; } SConfInfo; static SConfInfo g_stConfInfo; -//char* g_pRowValue = NULL; -//TdFilePtr g_fp = NULL; +// char* g_pRowValue = NULL; +// TdFilePtr g_fp = NULL; static void printHelp() { char indent[10] = " "; @@ -69,15 +85,27 @@ static void printHelp() { printf("%s%s%s\n", indent, indent, "The topic string for cosumer, no default "); printf("%s%s\n", indent, "-k"); printf("%s%s%s\n", indent, indent, "The key-value string for cosumer, no default "); + printf("%s%s\n", indent, "-t1"); + printf("%s%s%s\n", indent, indent, "The topic1 string for cosumer, no default "); + printf("%s%s\n", indent, "-k1"); + printf("%s%s%s\n", indent, indent, "The key1-value1 string for cosumer, no default "); printf("%s%s\n", indent, "-g"); printf("%s%s%s%d\n", indent, indent, "showMsgFlag, default is ", g_stConfInfo.showMsgFlag); + printf("%s%s\n", indent, "-y"); + printf("%s%s%s%d\n", indent, indent, "consume delay, default is s", g_stConfInfo.consumeDelay); + printf("%s%s\n", indent, "-m"); + printf("%s%s%s%d\n", indent, indent, "consume msg count, default is s", g_stConfInfo.consumeMsgCnt); + printf("%s%s\n", indent, "-j"); + printf("%s%s%s%d\n", indent, indent, "check mode, default is s", g_stConfInfo.checkMode); exit(EXIT_SUCCESS); } -void parseArgument(int32_t argc, char *argv[]) { - +void parseArgument(int32_t argc, char* argv[]) { memset(&g_stConfInfo, 0, sizeof(SConfInfo)); - + g_stConfInfo.showMsgFlag = 0; + g_stConfInfo.consumeDelay = 8000; + g_stConfInfo.consumeMsgCnt = 0; + for (int32_t i = 1; i < argc; i++) { if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { printHelp(); @@ -90,105 +118,144 @@ void parseArgument(int32_t argc, char *argv[]) { strcpy(g_stConfInfo.topicString, argv[++i]); } else if (strcmp(argv[i], "-k") == 0) { strcpy(g_stConfInfo.keyString, argv[++i]); + } else if (strcmp(argv[i], "-t1") == 0) { + strcpy(g_stConfInfo.topicString1, argv[++i]); + } else if (strcmp(argv[i], "-k1") == 0) { + strcpy(g_stConfInfo.keyString1, argv[++i]); } else if (strcmp(argv[i], "-g") == 0) { g_stConfInfo.showMsgFlag = atol(argv[++i]); + } else if (strcmp(argv[i], "-y") == 0) { + g_stConfInfo.consumeDelay = atol(argv[++i]); + } else if (strcmp(argv[i], "-m") == 0) { + g_stConfInfo.consumeMsgCnt = atol(argv[++i]); + } else if (strcmp(argv[i], "-j") == 0) { + g_stConfInfo.checkMode = atol(argv[++i]); } else { printf("%s unknow para: %s %s", GREEN, argv[++i], NC); - exit(-1); + exit(-1); } } + if (0 == g_stConfInfo.consumeMsgCnt) { + g_stConfInfo.consumeMsgCnt = 0x7fffffff; + } + #if 0 pPrint("%s configDir:%s %s", GREEN, configDir, NC); pPrint("%s dbName:%s %s", GREEN, g_stConfInfo.dbName, NC); pPrint("%s topicString:%s %s", GREEN, g_stConfInfo.topicString, NC); pPrint("%s keyString:%s %s", GREEN, g_stConfInfo.keyString, NC); pPrint("%s showMsgFlag:%d %s", GREEN, g_stConfInfo.showMsgFlag, NC); -#endif +#endif } -void splitStr(char **arr, char *str, const char *del) { - char *s = strtok(str, del); - while(s != NULL) { +void splitStr(char** arr, char* str, const char* del) { + char* s = strtok(str, del); + while (s != NULL) { *arr++ = s; s = strtok(NULL, del); } } -void ltrim(char *str) -{ - if (str == NULL || *str == '\0') - { - return; - } - int len = 0; - char *p = str; - while (*p != '\0' && isspace(*p)) - { - ++p; ++len; - } - memmove(str, p, strlen(str) - len + 1); - //return str; +void ltrim(char* str) { + if (str == NULL || *str == '\0') { + return; + } + int len = 0; + char* p = str; + while (*p != '\0' && isspace(*p)) { + ++p; + ++len; + } + memmove(str, p, strlen(str) - len + 1); + // return str; } - void parseInputString() { - //printf("topicString: %s\n", g_stConfInfo.topicString); - //printf("keyString: %s\n\n", g_stConfInfo.keyString); + // printf("topicString: %s\n", g_stConfInfo.topicString); + // printf("keyString: %s\n\n", g_stConfInfo.keyString); - char *token; + char* token; const char delim[2] = ","; const char ch = ':'; token = strtok(g_stConfInfo.topicString, delim); - while(token != NULL) { - //printf("%s\n", token ); - strcpy(g_stConfInfo.topics[g_stConfInfo.numOfTopic], token); + while (token != NULL) { + // printf("%s\n", token ); + strcpy(g_stConfInfo.topics[g_stConfInfo.numOfTopic], token); ltrim(g_stConfInfo.topics[g_stConfInfo.numOfTopic]); - //printf("%s\n", g_stConfInfo.topics[g_stConfInfo.numOfTopic]); - g_stConfInfo.numOfTopic++; - + // printf("%s\n", g_stConfInfo.topics[g_stConfInfo.numOfTopic]); + g_stConfInfo.numOfTopic++; + + token = strtok(NULL, delim); + } + + token = strtok(g_stConfInfo.topicString1, delim); + while (token != NULL) { + // printf("%s\n", token ); + strcpy(g_stConfInfo.topics1[g_stConfInfo.numOfTopic1], token); + ltrim(g_stConfInfo.topics1[g_stConfInfo.numOfTopic1]); + // printf("%s\n", g_stConfInfo.topics[g_stConfInfo.numOfTopic]); + g_stConfInfo.numOfTopic1++; + token = strtok(NULL, delim); } token = strtok(g_stConfInfo.keyString, delim); - while(token != NULL) { - //printf("%s\n", token ); - { - char* pstr = token; - ltrim(pstr); - char *ret = strchr(pstr, ch); - memcpy(g_stConfInfo.key[g_stConfInfo.numOfKey], pstr, ret-pstr); - strcpy(g_stConfInfo.value[g_stConfInfo.numOfKey], ret+1); - //printf("key: %s, value: %s\n", g_stConfInfo.key[g_stConfInfo.numOfKey], g_stConfInfo.value[g_stConfInfo.numOfKey]); - g_stConfInfo.numOfKey++; + while (token != NULL) { + // printf("%s\n", token ); + { + char* pstr = token; + ltrim(pstr); + char* ret = strchr(pstr, ch); + memcpy(g_stConfInfo.key[g_stConfInfo.numOfKey], pstr, ret - pstr); + strcpy(g_stConfInfo.value[g_stConfInfo.numOfKey], ret + 1); + // printf("key: %s, value: %s\n", g_stConfInfo.key[g_stConfInfo.numOfKey], + // g_stConfInfo.value[g_stConfInfo.numOfKey]); + g_stConfInfo.numOfKey++; } - + token = strtok(NULL, delim); } -} + token = strtok(g_stConfInfo.keyString1, delim); + while (token != NULL) { + // printf("%s\n", token ); + { + char* pstr = token; + ltrim(pstr); + char* ret = strchr(pstr, ch); + memcpy(g_stConfInfo.key1[g_stConfInfo.numOfKey1], pstr, ret - pstr); + strcpy(g_stConfInfo.value1[g_stConfInfo.numOfKey1], ret + 1); + // printf("key: %s, value: %s\n", g_stConfInfo.key[g_stConfInfo.numOfKey], + // g_stConfInfo.value[g_stConfInfo.numOfKey]); + g_stConfInfo.numOfKey1++; + } -static int running = 1; -static void msg_process(tmq_message_t* message) { tmqShowMsg(message); } + token = strtok(NULL, delim); + } +} +static int running = 1; +/*static void msg_process(tmq_message_t* message) { tmqShowMsg(message); }*/ -int queryDB(TAOS *taos, char *command) { - TAOS_RES *pRes = taos_query(taos, command); - int code = taos_errno(pRes); - //if ((code != 0) && (code != TSDB_CODE_RPC_AUTH_REQUIRED)) { - if (code != 0) { - pError("failed to reason:%s, sql: %s", tstrerror(code), command); - taos_free_result(pRes); - return -1; - } - taos_free_result(pRes); - return 0 ; +int queryDB(TAOS* taos, char* command) { + TAOS_RES* pRes = taos_query(taos, command); + int code = taos_errno(pRes); + // if ((code != 0) && (code != TSDB_CODE_RPC_AUTH_REQUIRED)) { + if (code != 0) { + pError("failed to reason:%s, sql: %s", tstrerror(code), command); + taos_free_result(pRes); + return -1; + } + taos_free_result(pRes); + return 0; } tmq_t* build_consumer() { +#if 0 char sqlStr[1024] = {0}; - + TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0); assert(pConn != NULL); @@ -196,29 +263,75 @@ tmq_t* build_consumer() { TAOS_RES* pRes = taos_query(pConn, sqlStr); if (taos_errno(pRes) != 0) { printf("error in use db, reason:%s\n", taos_errstr(pRes)); - taos_free_result(pRes); - exit(-1); + taos_free_result(pRes); + exit(-1); } taos_free_result(pRes); +#endif tmq_conf_t* conf = tmq_conf_new(); - //tmq_conf_set(conf, "group.id", "tg2"); + // tmq_conf_set(conf, "group.id", "tg2"); for (int32_t i = 0; i < g_stConfInfo.numOfKey; i++) { tmq_conf_set(conf, g_stConfInfo.key[i], g_stConfInfo.value[i]); } - tmq_t* tmq = tmq_consumer_new(pConn, conf, NULL, 0); + tmq_conf_set(conf, "td.connect.user", "root"); + tmq_conf_set(conf, "td.connect.pass", "taosdata"); + tmq_conf_set(conf, "td.connect.db", g_stConfInfo.dbName); + tmq_t* tmq = tmq_consumer_new1(conf, NULL, 0); + assert(tmq); + tmq_conf_destroy(conf); return tmq; } tmq_list_t* build_topic_list() { tmq_list_t* topic_list = tmq_list_new(); - //tmq_list_append(topic_list, "test_stb_topic_1"); + // tmq_list_append(topic_list, "test_stb_topic_1"); for (int32_t i = 0; i < g_stConfInfo.numOfTopic; i++) { tmq_list_append(topic_list, g_stConfInfo.topics[i]); } return topic_list; } +tmq_t* build_consumer_x() { +#if 0 + char sqlStr[1024] = {0}; + + TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + sprintf(sqlStr, "use %s", g_stConfInfo.dbName); + TAOS_RES* pRes = taos_query(pConn, sqlStr); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + exit(-1); + } + taos_free_result(pRes); +#endif + + tmq_conf_t* conf = tmq_conf_new(); + // tmq_conf_set(conf, "group.id", "tg2"); + for (int32_t i = 0; i < g_stConfInfo.numOfKey1; i++) { + tmq_conf_set(conf, g_stConfInfo.key1[i], g_stConfInfo.value1[i]); + } + tmq_conf_set(conf, "td.connect.user", "root"); + tmq_conf_set(conf, "td.connect.pass", "taosdata"); + tmq_conf_set(conf, "td.connect.db", g_stConfInfo.dbName); + tmq_t* tmq = tmq_consumer_new1(conf, NULL, 0); + assert(tmq); + tmq_conf_destroy(conf); + return tmq; +} + +tmq_list_t* build_topic_list_x() { + tmq_list_t* topic_list = tmq_list_new(); + // tmq_list_append(topic_list, "test_stb_topic_1"); + for (int32_t i = 0; i < g_stConfInfo.numOfTopic1; i++) { + tmq_list_append(topic_list, g_stConfInfo.topics1[i]); + } + return topic_list; +} + void loop_consume(tmq_t* tmq) { tmq_resp_err_t err; @@ -226,21 +339,21 @@ void loop_consume(tmq_t* tmq) { int32_t totalRows = 0; int32_t skipLogNum = 0; while (running) { - tmq_message_t* tmqMsg = tmq_consumer_poll(tmq, 8000); + TAOS_RES* tmqMsg = tmq_consumer_poll(tmq, 8000); if (tmqMsg) { - totalMsgs++; + totalMsgs++; - #if 0 +#if 0 TAOS_ROW row; while (NULL != (row = tmq_get_row(tmqMsg))) { totalRows++; } - #endif - - skipLogNum += tmqGetSkipLogNum(tmqMsg); - if (0 != g_stConfInfo.showMsgFlag) { - msg_process(tmqMsg); - } +#endif + + /*skipLogNum += tmqGetSkipLogNum(tmqMsg);*/ + if (0 != g_stConfInfo.showMsgFlag) { + /*msg_process(tmqMsg);*/ + } tmq_message_destroy(tmqMsg); } else { break; @@ -250,29 +363,126 @@ void loop_consume(tmq_t* tmq) { err = tmq_consumer_close(tmq); if (err) { printf("tmq_consumer_close() fail, reason: %s\n", tmq_err2str(err)); - exit(-1); + exit(-1); } - + printf("{consume success: %d, %d}", totalMsgs, totalRows); } -int main(int32_t argc, char *argv[]) { +int32_t parallel_consume(tmq_t* tmq, int threadLable) { + tmq_resp_err_t err; + + int32_t totalMsgs = 0; + int32_t totalRows = 0; + int32_t skipLogNum = 0; + while (running) { + TAOS_RES* tmqMsg = tmq_consumer_poll(tmq, g_stConfInfo.consumeDelay * 1000); + if (tmqMsg) { + totalMsgs++; + + // printf("threadFlag: %d, totalMsgs: %d\n", threadLable, totalMsgs); + +#if 0 + TAOS_ROW row; + while (NULL != (row = tmq_get_row(tmqMsg))) { + totalRows++; + } +#endif + + /*skipLogNum += tmqGetSkipLogNum(tmqMsg);*/ + if (0 != g_stConfInfo.showMsgFlag) { + /*msg_process(tmqMsg);*/ + } + tmq_message_destroy(tmqMsg); + + if (totalMsgs >= g_stConfInfo.consumeMsgCnt) { + break; + } + } else { + break; + } + } + + err = tmq_consumer_close(tmq); + if (err) { + printf("tmq_consumer_close() fail, reason: %s\n", tmq_err2str(err)); + exit(-1); + } + + // printf("%d", totalMsgs); // output to sim for check result + return totalMsgs; +} + +void* threadFunc(void* param) { + int32_t totalMsgs = 0; + + SThreadInfo* pInfo = (SThreadInfo*)param; + + tmq_t* tmq = build_consumer_x(); + tmq_list_t* topic_list = build_topic_list_x(); + if ((NULL == tmq) || (NULL == topic_list)) { + return NULL; + } + + tmq_resp_err_t err = tmq_subscribe(tmq, topic_list); + if (err) { + printf("tmq_subscribe() fail, reason: %s\n", tmq_err2str(err)); + exit(-1); + } + + // if (0 == g_stConfInfo.consumeMsgCnt) { + // loop_consume(tmq); + // } else { + pInfo->consumeMsgCnt = parallel_consume(tmq, 1); + //} + + err = tmq_unsubscribe(tmq); + if (err) { + printf("tmq_unsubscribe() fail, reason: %s\n", tmq_err2str(err)); + pInfo->consumeMsgCnt = -1; + return NULL; + } + + return NULL; +} + +int main(int32_t argc, char* argv[]) { parseArgument(argc, argv); parseInputString(); - - tmq_t* tmq = build_consumer(); + + int32_t numOfThreads = 1; + TdThreadAttr thattr; + taosThreadAttrInit(&thattr); + taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE); + SThreadInfo* pInfo = (SThreadInfo*)taosMemoryCalloc(numOfThreads, sizeof(SThreadInfo)); + + if (g_stConfInfo.numOfTopic1) { + // pthread_create one thread to consume + for (int32_t i = 0; i < numOfThreads; ++i) { + pInfo[i].expectMsgCnt = 0; + pInfo[i].consumeMsgCnt = 0; + taosThreadCreate(&(pInfo[i].thread), &thattr, threadFunc, (void*)(pInfo + i)); + } + } + + int32_t totalMsgs = 0; + tmq_t* tmq = build_consumer(); tmq_list_t* topic_list = build_topic_list(); - if ((NULL == tmq) || (NULL == topic_list)){ + if ((NULL == tmq) || (NULL == topic_list)) { return -1; } - + tmq_resp_err_t err = tmq_subscribe(tmq, topic_list); if (err) { printf("tmq_subscribe() fail, reason: %s\n", tmq_err2str(err)); exit(-1); } - - loop_consume(tmq); + + if (0 == g_stConfInfo.numOfTopic1) { + loop_consume(tmq); + } else { + totalMsgs = parallel_consume(tmq, 0); + } err = tmq_unsubscribe(tmq); if (err) { @@ -280,6 +490,50 @@ int main(int32_t argc, char *argv[]) { exit(-1); } + if (g_stConfInfo.numOfTopic1) { + for (int32_t i = 0; i < numOfThreads; i++) { + taosThreadJoin(pInfo[i].thread, NULL); + } + + // printf("consumer: %d, cosumer1: %d\n", totalMsgs, pInfo->consumeMsgCnt); + if (0 == g_stConfInfo.checkMode) { + if ((totalMsgs + pInfo->consumeMsgCnt) == g_stConfInfo.consumeMsgCnt) { + printf("success"); + } else { + printf("fail, consumer msg cnt: %d, %d", totalMsgs, pInfo->consumeMsgCnt); + } + } else if (1 == g_stConfInfo.checkMode) { + if ((totalMsgs == g_stConfInfo.consumeMsgCnt) && (pInfo->consumeMsgCnt == g_stConfInfo.consumeMsgCnt)) { + printf("success"); + } else { + printf("fail, consumer msg cnt: %d, %d", totalMsgs, pInfo->consumeMsgCnt); + } + } else if (2 == g_stConfInfo.checkMode) { + if ((totalMsgs + pInfo->consumeMsgCnt) == 3 * g_stConfInfo.consumeMsgCnt) { + printf("success"); + } else { + printf("fail, consumer msg cnt: %d, %d", totalMsgs, pInfo->consumeMsgCnt); + } + } else if (3 == g_stConfInfo.checkMode) { + if ((totalMsgs == 2 * g_stConfInfo.consumeMsgCnt) && (pInfo->consumeMsgCnt == 2 * g_stConfInfo.consumeMsgCnt)) { + printf("success"); + } else { + printf("fail, consumer msg cnt: %d, %d", totalMsgs, pInfo->consumeMsgCnt); + } + } else if (4 == g_stConfInfo.checkMode) { + if (((totalMsgs == 0) && (pInfo->consumeMsgCnt == 3 * g_stConfInfo.consumeMsgCnt)) || + ((pInfo->consumeMsgCnt == 0) && (totalMsgs == 3 * g_stConfInfo.consumeMsgCnt)) || + ((pInfo->consumeMsgCnt == g_stConfInfo.consumeMsgCnt) && (totalMsgs == 2 * g_stConfInfo.consumeMsgCnt)) || + ((pInfo->consumeMsgCnt == 2 * g_stConfInfo.consumeMsgCnt) && (totalMsgs == g_stConfInfo.consumeMsgCnt))) { + printf("success"); + } else { + printf("fail, consumer msg cnt: %d, %d", totalMsgs, pInfo->consumeMsgCnt); + } + } else { + printf("fail, check mode unknow. consumer msg cnt: %d, %d", totalMsgs, pInfo->consumeMsgCnt); + } + } + return 0; } diff --git a/tests/tsim/inc/simInt.h b/tests/tsim/inc/simInt.h index a667139de1934fab479c8ed2c3d857b7ee111dea..c8b13736c7cb752c7fa52500f132ede02988089e 100644 --- a/tests/tsim/inc/simInt.h +++ b/tests/tsim/inc/simInt.h @@ -156,6 +156,7 @@ extern int32_t simDebugFlag; extern char simScriptDir[]; extern bool abortExecution; extern bool useMultiProcess; +extern bool useValgrind; SScript *simParseScript(char *fileName); SScript *simProcessCallOver(SScript *script); diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index 9a0b48197a9d38a8da7aafe9952ab7a87ddd51d8..5a18084fff254de271c4c68a2472c283de331797 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -22,7 +22,7 @@ void simLogSql(char *sql, bool useSharp) { sprintf(filename, "%s/sim.sql", simScriptDir); if (pFile == NULL) { // fp = fopen(filename, "w"); - pFile = taosOpenFile(filename, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); + pFile = taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); if (pFile == NULL) { fprintf(stderr, "ERROR: failed to open file: %s\n", filename); return; @@ -340,6 +340,10 @@ bool simExecuteSystemCmd(SScript *script, char *option) { simReplaceStr(buf, "deploy.sh", "deploy.sh -m"); } + if (useValgrind) { + simReplaceStr(buf, "exec.sh", "exec.sh -v"); + } + simLogSql(buf, true); int32_t code = system(buf); int32_t repeatTimes = 0; @@ -678,7 +682,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { if (tt < 0) tt = 0; #endif - tp = localtime(&tt); + tp = taosLocalTime(&tt, NULL); strftime(timeStr, 64, "%y-%m-%d %H:%M:%S", tp); if (precision == TSDB_TIME_PRECISION_MILLI) { sprintf(value, "%s.%03d", timeStr, (int32_t)(*((int64_t *)row[i]) % 1000)); @@ -773,7 +777,7 @@ bool simExecuteRestfulCmd(SScript *script, char *rest) { char filename[256]; sprintf(filename, "%s/tmp.sql", simScriptDir); // fp = fopen(filename, "w"); - pFile = taosOpenFile(filename, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); + pFile = taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); if (pFile == NULL) { fprintf(stderr, "ERROR: failed to open file: %s\n", filename); return false; diff --git a/tests/tsim/src/simMain.c b/tests/tsim/src/simMain.c index 8898f1b201da5e41db81982a8261a2d792888912..713e46df58e8957be2593eb5d78698ed46e5a69b 100644 --- a/tests/tsim/src/simMain.c +++ b/tests/tsim/src/simMain.c @@ -19,6 +19,7 @@ bool simExecSuccess = false; bool abortExecution = false; bool useMultiProcess = false; +bool useValgrind = false; void simHandleSignal(int32_t signo, void *sigInfo, void *context) { simSystemCleanUp(); @@ -35,6 +36,8 @@ int32_t main(int32_t argc, char *argv[]) { strcpy(scriptFile, argv[++i]); } else if (strcmp(argv[i], "-m") == 0) { useMultiProcess = true; + } else if (strcmp(argv[i], "-v") == 0) { + useValgrind = true; } else { printf("usage: %s [options] \n", argv[0]); printf(" [-c config]: config directory, default is: %s\n", configDir); diff --git a/tests/tsim/src/simSystem.c b/tests/tsim/src/simSystem.c index eb5fb682642dce2601167f671370d9a2320c3b8b..5bbcceada5591454c6dcb639d6ee22112baf6073 100644 --- a/tests/tsim/src/simSystem.c +++ b/tests/tsim/src/simSystem.c @@ -80,24 +80,24 @@ SScript *simProcessCallOver(SScript *script) { simExecSuccess = false; simInfo("script:" FAILED_PREFIX "%s" FAILED_POSTFIX ", " FAILED_PREFIX "failed" FAILED_POSTFIX ", error:%s", script->fileName, script->error); - return NULL; } else { simExecSuccess = true; simInfo("script:" SUCCESS_PREFIX "%s" SUCCESS_POSTFIX ", " SUCCESS_PREFIX "success" SUCCESS_POSTFIX, script->fileName); - simCloseTaosdConnect(script); - simScriptSucced++; - simScriptPos--; - - simFreeScript(script); - if (simScriptPos == -1) { - simInfo("----------------------------------------------------------------------"); - simInfo("Simulation Test Done, " SUCCESS_PREFIX "%d" SUCCESS_POSTFIX " Passed:\n", simScriptSucced); - return NULL; - } + } - return simScriptList[simScriptPos]; + simCloseTaosdConnect(script); + simScriptSucced++; + simScriptPos--; + simFreeScript(script); + + if (simScriptPos == -1 && simExecSuccess) { + simInfo("----------------------------------------------------------------------"); + simInfo("Simulation Test Done, " SUCCESS_PREFIX "%d" SUCCESS_POSTFIX " Passed:\n", simScriptSucced); + return NULL; } + + return simScriptList[simScriptPos]; } else { simDebug("script:%s, is stopped", script->fileName); simFreeScript(script); diff --git a/tools/shell/src/backup/shellCheck.c b/tools/shell/src/backup/shellCheck.c index dc18ecd3f8d877a4bb158cffee9a6cda02edd221..d1f0683fea51df5c4d3d4ff977cf218988c42ec3 100644 --- a/tools/shell/src/backup/shellCheck.c +++ b/tools/shell/src/backup/shellCheck.c @@ -116,7 +116,7 @@ static void *shellCheckThreadFp(void *arg) { char file[32] = {0}; snprintf(file, 32, "tb%d.txt", pThread->threadIndex); - TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC); + TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (!fp) { fprintf(stdout, "failed to open %s, reason:%s", file, strerror(errno)); return NULL; diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 47d47f023df21d8114f2c736350c0a6ce5ed1767..1809d99209b89fc77a7b1fdd7dd2dec13cc993c6 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -26,6 +26,7 @@ #include "tglobal.h" #include "ttypes.h" #include "tutil.h" +#include "tconfig.h" #include #include @@ -90,6 +91,11 @@ TAOS *shellInit(SShellArguments *_args) { _args->user = TSDB_DEFAULT_USER; } + SConfig *pCfg = cfgInit(); + if (NULL == pCfg) return NULL; + + if (0 != taosAddClientLogCfg(pCfg)) return NULL; + // Connect to the database. TAOS *con = NULL; if (_args->auth == NULL) { @@ -446,7 +452,7 @@ static char *formatTimestamp(char *buf, int64_t val, int precision) { } } - struct tm *ptm = localtime(&tt); + struct tm *ptm = taosLocalTime(&tt, NULL); size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", ptm); if (precision == TSDB_TIME_PRECISION_NANO) { @@ -518,7 +524,7 @@ static int dumpResultToFile(const char *fname, TAOS_RES *tres) { } // FILE *fp = fopen(full_path.we_wordv[0], "w"); - TdFilePtr pFile = taosOpenFile(full_path.we_wordv[0], TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); + TdFilePtr pFile = taosOpenFile(full_path.we_wordv[0], TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); if (pFile == NULL) { fprintf(stderr, "ERROR: failed to open file: %s\n", full_path.we_wordv[0]); wordfree(&full_path); @@ -935,7 +941,7 @@ void write_history() { get_history_path(f_history); // FILE *f = fopen(f_history, "w"); - TdFilePtr pFile = taosOpenFile(f_history, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); + TdFilePtr pFile = taosOpenFile(f_history, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); if (pFile == NULL) { #ifndef WINDOWS fprintf(stderr, "Failed to open file %s for write, reason:%s\n", f_history, strerror(errno)); diff --git a/tools/taos-tools b/tools/taos-tools index 33cdfe4f90a209f105c1b6091439798a9cde1e93..bf6c766986c61ff4fc80421fdea682a8fd4b5b32 160000 --- a/tools/taos-tools +++ b/tools/taos-tools @@ -1 +1 @@ -Subproject commit 33cdfe4f90a209f105c1b6091439798a9cde1e93 +Subproject commit bf6c766986c61ff4fc80421fdea682a8fd4b5b32