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/example/src/tmq.c b/example/src/tmq.c index ca80c8fe5a12fcf11d8c90088ec399d47b708756..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; } @@ -166,11 +183,11 @@ void basic_consume_loop(tmq_t* tmq, tmq_list_t* topics) { 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++; - printf("get data\n"); - msg_process(tmqmessage); + /*printf("get data\n");*/ + /*msg_process(tmqmessage);*/ tmq_message_destroy(tmqmessage); /*} else {*/ /*break;*/ @@ -198,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); @@ -226,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/tdatablock.h b/include/common/tdatablock.h index 5e5a8826e5893641c69a9ad17d83b66d255a8ed8..15f3246013c5d289aa6689d55de162c435153344 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -199,20 +199,19 @@ 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 blockEstimateEncodeSize(const SSDataBlock* pBlock) { - return blockDataGetSerialMetaSize(pBlock) + (int32_t)ceil(blockDataGetSerialRowSize(pBlock) * pBlock->info.rows); +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, diff --git a/include/common/tmsg.h b/include/common/tmsg.h index bd4485dc9467e3751df29037c1b9a1b86006a186..e67c94f5ad2d59ca37d420e1a87a79bdef8316a7 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -332,6 +332,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]; @@ -346,6 +347,7 @@ typedef struct { int64_t clusterId; int32_t connId; int8_t superUser; + int8_t connType; SEpSet epSet; char sVersion[128]; } SConnectRsp; @@ -485,7 +487,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; @@ -745,8 +747,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; @@ -760,6 +762,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; @@ -773,7 +776,7 @@ typedef struct { } SDnodeEp; typedef struct { - int64_t dver; + int64_t dnodeVer; SDnodeCfg dnodeCfg; SArray* pDnodeEps; // Array of SDnodeEp } SStatusRsp; @@ -953,9 +956,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); @@ -2365,11 +2373,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 { @@ -2384,6 +2391,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]; @@ -2421,8 +2475,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; } @@ -2440,8 +2493,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/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 f5b9c23ee67cb63f45c6afea0c33a1be1ae82280..7840d1825661b97eb194f41cd0bf108c8ee7883e 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -182,47 +182,48 @@ #define TK_FIRST 164 #define TK_LAST 165 #define TK_NOW 166 -#define TK_ROWTS 167 -#define TK_TBNAME 168 -#define TK_QSTARTTS 169 -#define TK_QENDTS 170 -#define TK_WSTARTTS 171 -#define TK_WENDTS 172 -#define TK_WDURATION 173 -#define TK_BETWEEN 174 -#define TK_IS 175 -#define TK_NK_LT 176 -#define TK_NK_GT 177 -#define TK_NK_LE 178 -#define TK_NK_GE 179 -#define TK_NK_NE 180 -#define TK_MATCH 181 -#define TK_NMATCH 182 -#define TK_JOIN 183 -#define TK_INNER 184 -#define TK_SELECT 185 -#define TK_DISTINCT 186 -#define TK_WHERE 187 -#define TK_PARTITION 188 -#define TK_BY 189 -#define TK_SESSION 190 -#define TK_STATE_WINDOW 191 -#define TK_SLIDING 192 -#define TK_FILL 193 -#define TK_VALUE 194 -#define TK_NONE 195 -#define TK_PREV 196 -#define TK_LINEAR 197 -#define TK_NEXT 198 -#define TK_GROUP 199 -#define TK_HAVING 200 -#define TK_ORDER 201 -#define TK_SLIMIT 202 -#define TK_SOFFSET 203 -#define TK_LIMIT 204 -#define TK_OFFSET 205 -#define TK_ASC 206 -#define TK_NULLS 207 +#define TK_TODAY 167 +#define TK_ROWTS 168 +#define TK_TBNAME 169 +#define TK_QSTARTTS 170 +#define TK_QENDTS 171 +#define TK_WSTARTTS 172 +#define TK_WENDTS 173 +#define TK_WDURATION 174 +#define TK_BETWEEN 175 +#define TK_IS 176 +#define TK_NK_LT 177 +#define TK_NK_GT 178 +#define TK_NK_LE 179 +#define TK_NK_GE 180 +#define TK_NK_NE 181 +#define TK_MATCH 182 +#define TK_NMATCH 183 +#define TK_JOIN 184 +#define TK_INNER 185 +#define TK_SELECT 186 +#define TK_DISTINCT 187 +#define TK_WHERE 188 +#define TK_PARTITION 189 +#define TK_BY 190 +#define TK_SESSION 191 +#define TK_STATE_WINDOW 192 +#define TK_SLIDING 193 +#define TK_FILL 194 +#define TK_VALUE 195 +#define TK_NONE 196 +#define TK_PREV 197 +#define TK_LINEAR 198 +#define TK_NEXT 199 +#define TK_GROUP 200 +#define TK_HAVING 201 +#define TK_ORDER 202 +#define TK_SLIMIT 203 +#define TK_SOFFSET 204 +#define TK_LIMIT 205 +#define TK_OFFSET 206 +#define TK_ASC 207 +#define TK_NULLS 208 #define TK_NK_SPACE 300 #define TK_NK_COMMENT 301 diff --git a/include/common/ttypes.h b/include/common/ttypes.h index 11120211240540dd1e963fc1a5276e52941bef26..9bc057805436ca695c20dfdce18bcd0ba89da3c7 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -24,7 +24,6 @@ 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; 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..9e5f8a4ddd213434de9b4f162d777a529a3796c2 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -68,6 +68,7 @@ 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. @@ -102,6 +103,12 @@ 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/function/functionMgt.h b/include/libs/function/functionMgt.h index 9d1b2c9ea07ad10c4ac167747d21c20b88b03c4c..148a9f77d6081596332ac1dc4244e86317d69427 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, diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index 3a1d7954a719761f9e70097c849dafd9f2638765..4ffacf3787e201b2de55bcbf1f952c1c666ed057 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -231,6 +231,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/scalar/scalar.h b/include/libs/scalar/scalar.h index cd9c6f5bf2bee3f7684bf6873bee9f3bf200881e..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); @@ -75,6 +75,9 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp /* 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); diff --git a/include/os/osFile.h b/include/os/osFile.h index 89b58cdd65b22ab926e479d3d3d111ff6b4460ff..36ca6fb8bb507cb604aca8399011960f9a14ca1d 100644 --- a/include/os/osFile.h +++ b/include/os/osFile.h @@ -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/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/tdef.h b/include/util/tdef.h index 0289bb0df7aefab223175a0dafd62021d40735ef..9c68b8d6ed8f4b111282f68235d419d5713d2c49 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -100,6 +100,7 @@ extern const int32_t TYPE_BYTES[15]; #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" @@ -117,6 +118,7 @@ extern const int32_t TYPE_BYTES[15]; #define TSDB_INS_TABLE_VGROUPS "vgroups" #define TSDB_INS_TABLE_BNODES "bnodes" #define TSDB_INS_TABLE_SNODES "snodes" +#define TSDB_INS_TABLE_LICENCES "grants" #define TSDB_INDEX_TYPE_SMA "SMA" #define TSDB_INDEX_TYPE_FULLTEXT "FULLTEXT" 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 185b5824d956908aed375bd5efd629da21892a29..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 { @@ -132,9 +137,9 @@ typedef struct STscObj { char pass[TSDB_PASSWORD_LEN]; char db[TSDB_DB_FNAME_LEN]; char ver[128]; + int8_t connType; 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 @@ -194,12 +199,12 @@ enum { #define TD_RES_QUERY(res) (*(int8_t*)res == RES_TYPE__QUERY) #define TD_RES_TMQ(res) (*(int8_t*)res == RES_TYPE__TMQ) -typedef struct SMqRspObj { +typedef struct { int8_t resType; char* topic; - void* vg; SArray* res; // SArray int32_t resIter; + int32_t vgId; } SMqRspObj; typedef struct SRequestObj { @@ -272,14 +277,14 @@ 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); + uint16_t port, int connType); 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); -void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4); +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); diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index d389fc34c681f8f335b2857feede3f1f9bce603a..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; } @@ -438,7 +439,7 @@ static int32_t hbCreateThread() { if (taosThreadCreate(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; - } + } taosThreadAttrDestroy(&thAttr); return 0; } @@ -568,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}; @@ -578,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 63bb3637cf2fc1dac7b7379afefc72b2f1b9f5a4..96a7230ff3df8ef336d457b8a23231522f2ad216 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -11,7 +11,7 @@ #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 bool stringLengthCheck(const char* str, size_t maxsize) { @@ -40,10 +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); + 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; } @@ -111,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) { @@ -193,13 +193,6 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) { 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); @@ -425,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; @@ -439,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); @@ -462,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; @@ -485,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)); @@ -570,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, @@ -602,113 +596,52 @@ 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, bool convertUcs4) { +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, convertUcs4); - 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; diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 040ddde63099be572f3d3facf2b947cb52124235..e293c8923d3d5f1b329cbe71cb5f7e44ef301820 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -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) { @@ -168,24 +170,28 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { return NULL; } - return doFetchRow(pRequest, true, true); + return doFetchRows(pRequest, true, true); } else if (TD_RES_TMQ(res)) { - SMqRspObj *msg = ((SMqRspObj *)res); + SMqRspObj *msg = ((SMqRspObj *)res); + if (msg->resIter == -1) msg->resIter++; SReqResultInfo *pResultInfo = taosArrayGet(msg->res, msg->resIter); - - doSetOneRowPtr(pResultInfo); - pResultInfo->current += 1; - - if (pResultInfo->row == NULL) { - msg->resIter++; - 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; + } } - return pResultInfo->row; - } else { // assert to avoid uninitialization error ASSERT(0); @@ -404,7 +410,11 @@ bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) { } SResultColumn *pCol = &pResultInfo->pCol[col]; - return colDataIsNull_f(pCol->nullbitmap, row); + 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; } @@ -430,7 +440,7 @@ int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) { return 0; } - doFetchRow(pRequest, false, true); + doFetchRows(pRequest, false, true); // TODO refactor SReqResultInfo *pResultInfo = &pRequest->body.resInfo; @@ -457,25 +467,7 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) { if (res == NULL) { return 0; } - 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 0; - } - - doFetchRow(pRequest, false, false); - - SReqResultInfo *pResultInfo = &pRequest->body.resInfo; - - pResultInfo->current = pResultInfo->numOfRows; - (*numOfRows) = pResultInfo->numOfRows; - (*pData) = (void *)pResultInfo->pData; - - return 0; - - } else if (TD_RES_TMQ(res)) { + if (TD_RES_TMQ(res)) { SReqResultInfo *pResultInfo = tmqGetNextResInfo(res); if (pResultInfo == NULL) return -1; @@ -483,11 +475,24 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) { (*numOfRows) = pResultInfo->numOfRows; (*pData) = (void *)pResultInfo->pData; return 0; + } - } else { - ASSERT(0); - return -1; + 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; } + + doFetchRows(pRequest, false, false); + + SReqResultInfo *pResultInfo = &pRequest->body.resInfo; + + pResultInfo->current = pResultInfo->numOfRows; + (*numOfRows) = pResultInfo->numOfRows; + (*pData) = (void *)pResultInfo->pData; + + return 0; } int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) { diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 99c6e815515f26a932559b7eaca12fdf63188082..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 dbe78782f5dd66284167a89fb731d944ab519fa0..478e328a165e04903544590bdb48b4303b5cef74 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -27,11 +27,22 @@ struct tmq_message_t { SMqPollRsp msg; char* topic; - void* vg; 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; }; @@ -108,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; @@ -133,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; @@ -244,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) @@ -338,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; @@ -764,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) { @@ -777,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; @@ -827,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); @@ -874,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");*/ @@ -894,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; @@ -932,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); @@ -1015,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);*/ } @@ -1152,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; @@ -1258,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; @@ -1296,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 { @@ -1314,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); @@ -1382,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) { @@ -1402,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(); @@ -1546,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; @@ -1553,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; } @@ -1563,4 +1626,27 @@ const char* tmq_err2str(tmq_resp_err_t err) { return "fail"; } -char* tmq_get_topic_name(tmq_message_t* message) { return "not implemented yet"; } +char* tmq_get_topic_name(TAOS_RES* res) { + if (TD_RES_TMQ(res)) { + SMqRspObj* pRspObj = (SMqRspObj*)res; + return pRspObj->topic; + } else { + return NULL; + } +} + +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 fd2abbb5595bdd6df254b0f3bbb3ab26b56bf806..2730723a1734bd37c0da324538fbba48bb4f34ec 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -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)); @@ -653,6 +652,7 @@ TEST(testCase, projection_query_stables) { taos_free_result(pRes); taos_close(pConn); } + #endif TEST(testCase, agg_query_tables) { @@ -662,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 length('abc') 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); @@ -673,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/tglobal.c b/source/common/src/tglobal.c index 58bc7235a1a14f1be58ca88d0d08f500f4c78092..2ab8af31b1a74bcb44b2b61bf0a7267fb0446b04 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; } @@ -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; } diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 08010db1d8ec27fc6fc0231da306f6a0fe640cab..821f24eedcd74c5b823f2bcf23c21afb20ec089c 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -870,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; @@ -915,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; @@ -960,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); @@ -967,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; @@ -998,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; @@ -2182,7 +2184,7 @@ 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 (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); @@ -2199,7 +2201,7 @@ 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 (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); @@ -2532,6 +2534,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; @@ -2548,6 +2551,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; @@ -2567,6 +2571,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); @@ -2585,6 +2590,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/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/dnode/mgmt/CMakeLists.txt b/source/dnode/mgmt/CMakeLists.txt index 297e3a08d7277d6e75eb0bcc612b27cb22d6be64..49ea54e92835f1173e80fef46f6184f258ebdb5e 100644 --- a/source/dnode/mgmt/CMakeLists.txt +++ b/source/dnode/mgmt/CMakeLists.txt @@ -1,36 +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 (TD_GRANT) - TARGET_LINK_LIBRARIES(taosd grant) -ENDIF () -IF (TD_USB_DONGLE) - TARGET_LINK_LIBRARIES(taosd usb_dongle) -else() -ENDIF () - -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 66ab2a6dcd1964a19fee3a133785e005bce24322..3f5c22dd8488870cca64b1c831d1a4d3a7cf6b1a 100644 --- a/source/dnode/mgmt/exe/dndMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -14,47 +14,46 @@ */ #define _DEFAULT_SOURCE -#include "dndInt.h" +#include "dmImp.h" #include "tconfig.h" -#include "tgrant.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) { @@ -73,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) { @@ -90,11 +89,9 @@ static int32_t dndParseArgs(int32_t argc, char const *argv[]) { return 0; } -static void dndGenerateGrant() { - grantParseParameter(); -} +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 c1964ac8c42a39fbd2c81be5af0f4fddfb62e825..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,41 +144,41 @@ 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_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { @@ -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 73% rename from source/dnode/mgmt/dm/dmMonitor.c rename to source/dnode/mgmt/implement/src/dmMonitor.c index 6edf85106bcbfcc5f8d0cc6e2449ea50da2b56c4..b0774cd66f1620dedfaabe38c1a08a66808ca857 100644 --- a/source/dnode/mgmt/dm/dmMonitor.c +++ b/source/dnode/mgmt/implement/src/dmMonitor.c @@ -14,17 +14,17 @@ */ #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); + 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; @@ -55,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; @@ -64,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); } @@ -79,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); } @@ -98,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); } @@ -115,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); } @@ -132,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); } @@ -161,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); @@ -169,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 58% rename from source/dnode/mgmt/main/dndTransport.c rename to source/dnode/mgmt/implement/src/dmTransport.c index bcebd521b604027a4d0f4d9a36453f97ea79c5df..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,28 +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; + uint16_t msgType = pRpc->msgType; if (pEpSet && pEpSet->numOfEps > 0 && msgType == TDMT_MND_STATUS_RSP) { - dndUpdateMnodeEpSet(pWrapper->pDnode, pEpSet); + 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); @@ -78,13 +92,13 @@ 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()); + 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; if (code == TSDB_CODE_NODE_NOT_DEPLOYED || code == TSDB_CODE_NODE_OFFLINE) { @@ -101,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}; @@ -141,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) { @@ -155,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; -} - -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; + dmProcessRpcMsg(pWrapper, pMsg, pEpSet); } -static int32_t dndInitServer(SDnode *pDnode) { - STransMgmt *pMgmt = &pDnode->trans; +int32_t dmInitMsgHandle(SDnode *pDnode) { + SDnodeTrans *pTrans = &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) { @@ -318,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]); @@ -332,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; } } } @@ -344,33 +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) { +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) { - dmSendRedirectRsp(pWrapper->pMgmt, pRsp); + 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) { @@ -380,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); @@ -436,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); @@ -445,27 +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 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; @@ -473,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 a38fe87b59ea93015eb78acb40159072efb3e1e0..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/inc/dndInt.h +++ /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 . - */ - -#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; - EProcType procType; - 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 67% rename from source/dnode/mgmt/main/dndFile.c rename to source/dnode/mgmt/interface/src/dmFile.c index 905624f072aa538d2bd005d8ebddb5ed7a2d56b5..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}; @@ -117,7 +117,7 @@ _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); @@ -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_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 51569d2ed4640e995f7c33e5e38bf69cec11be97..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/main/dndExec.c +++ /dev/null @@ -1,357 +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; -} - -static int32_t dndInitNodeProc(SMgmtWrapper *pWrapper) { - int32_t shmsize = tsMnodeShmSize; - if (pWrapper->ntype == VNODES) { - 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->shm, 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->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; - } - - return 0; -} - -static int32_t dndNewNodeProc(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 int32_t dndRunNodeProc(SMgmtWrapper *pWrapper) { - if (pWrapper->pDnode->ntype == NODE_MAX) { - dInfo("node:%s, should be started manually", pWrapper->name); - } else { - if (dndNewNodeProc(pWrapper, pWrapper->ntype) != 0) { - return -1; - } - } - - if (taosProcRun(pWrapper->pProc) != 0) { - dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr()); - return -1; - } - - return 0; -} - -static int32_t dndOpenNodeImp(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; -} - -int32_t dndOpenNode(SMgmtWrapper *pWrapper) { - SDnode *pDnode = pWrapper->pDnode; - if (pDnode->procType == PROC_SINGLE) { - return dndOpenNodeImp(pWrapper); - } else if (pDnode->procType == PROC_PARENT) { - if (dndInitNodeProc(pWrapper) != 0) return -1; - if (dndWriteShmFile(pDnode) != 0) return -1; - if (dndRunNodeProc(pWrapper) != 0) return -1; - } - return 0; -} - -static void dndCloseNodeImp(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); -} - -void dndCloseNode(SMgmtWrapper *pWrapper) { - if (pWrapper->pDnode->procType == 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); - } - } - dndCloseNodeImp(pWrapper); -} - -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"); - pDnode->procType = PROC_SINGLE; - - for (EDndType n = DNODE; n < NODE_MAX; ++n) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - pWrapper->required = dndRequireNode(pWrapper); - if (!pWrapper->required) continue; - - if (dndOpenNodeImp(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"); - pDnode->procType = PROC_PARENT; - - SMgmtWrapper *pDWrapper = &pDnode->wrappers[DNODE]; - if (dndOpenNodeImp(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; - if (dndInitNodeProc(pWrapper) != 0) 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 (dndRunNodeProc(pWrapper) != 0) 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); - dndNewNodeProc(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); - pDnode->procType = PROC_CHILD; - - 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 (dndOpenNodeImp(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 d406b0c02e99d438d20539f0125ac589a23c77ed..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_NOT_DEPLOYED; - 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_NOT_DEPLOYED; - 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 91% rename from source/dnode/mgmt/inc/bmInt.h rename to source/dnode/mgmt/mgmt_bnode/inc/bmInt.h index 3158fe7d34f37616745927925354dfdde18453ba..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" @@ -33,10 +33,6 @@ typedef struct SBnodeMgmt { 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 d11059260317d287398320902e5889a72c71a463..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 dndOpenNode(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,16 +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 { - // dndCloseNode(pWrapper); - 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 78% rename from source/dnode/mgmt/mm/mmFile.c rename to source/dnode/mgmt/mgmt_mnode/src/mmFile.c index 44027780defe0f6f2852a62ee599520330595922..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,9 +105,11 @@ 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_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { @@ -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..91c4724372456cf8672ceaeca2fde316858dffc0 --- /dev/null +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -0,0 +1,210 @@ +/* + * 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_SHOW, mmProcessReadMsg, 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 71% rename from source/dnode/mgmt/mm/mmInt.c rename to source/dnode/mgmt/mgmt_mnode/src/mmInt.c index 49886621ecde417f0a80cd9482428e331f23e2a1..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,44 +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"); - if (pMgmt->pWrapper->procType == PROC_CHILD) { - pMgmt->pDnode->dnodeId = 1; - } - 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; } @@ -142,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()); @@ -206,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"); @@ -225,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 4fda72759ae94d881226433acc7c73478b7190a4..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 dndOpenNode(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,28 +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 { - // dndCloseNode(pWrapper); - 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 100% rename from source/dnode/mgmt/qm/qmWorker.c rename to source/dnode/mgmt/mgmt_qnode/src/qmWorker.c 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 5b30dc04bc8d979168b9b008d922d40d44cb3471..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 dndOpenNode(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,20 +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); - // return dndCloseNode(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 100% rename from source/dnode/mgmt/vm/vmFile.c rename to source/dnode/mgmt/mgmt_vnode/src/vmFile.c 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 100% rename from source/dnode/mgmt/vm/vmWorker.c rename to source/dnode/mgmt/mgmt_vnode/src/vmWorker.c diff --git a/source/dnode/mgmt/mm/mmHandle.c b/source/dnode/mgmt/mm/mmHandle.c deleted file mode 100644 index 63240c32249033ba254617ee4f09a92035b52697..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/mm/mmHandle.c +++ /dev/null @@ -1,200 +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 { - // dndCloseNode(pWrapper); - 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, dnodeId:%d input:%d", terrstr(), pDnode->dnodeId, alterReq.dnodeId); - 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/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/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..a805aecd7c73d6d0ea172757f4c365b3cf9a6312 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}; @@ -62,7 +62,7 @@ void Testbase::Cleanup() { client.Cleanup(); taosMsleep(10); server.Stop(); - dndCleanup(); + dmCleanup(); } void Testbase::Restart() { @@ -133,17 +133,17 @@ const char* Testbase::GetMetaTbName() { return metaRsp.tbName; } void Testbase::SendShowRetrieveReq() { SRetrieveTableReq retrieveReq = {0}; retrieveReq.showId = showId; - retrieveReq.free = 0; +// retrieveReq.free = 0; 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); +// 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; 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..e827dd5131872b956d8dea9c4d3e4a6f02a9fc81 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -385,14 +385,14 @@ typedef struct { int16_t numOfColumns; int32_t rowSize; int32_t numOfRows; - int32_t numOfReads; 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]; - char payload[]; } SShowObj; typedef struct { 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/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/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..effb0be4be8a254614327fdfc349bc71c33af556 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -56,9 +56,9 @@ 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) { @@ -354,7 +354,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 +405,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)); @@ -669,7 +669,7 @@ static int32_t mndGetConfigMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp * 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 +694,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 +733,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 index cdf3271789041dd427cbc88955ad62fe17d7d6e7..cab1e241e22da7e29c200bb27f1b9e5adc16fb52 100644 --- a/source/dnode/mnode/impl/src/mndGrant.c +++ b/source/dnode/mnode/impl/src/mndGrant.c @@ -14,18 +14,26 @@ */ #define _DEFAULT_SOURCE -#ifndef _GRANT #include "os.h" #include "taoserror.h" -#include "tgrant.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 grantInit() { return TSDB_CODE_SUCCESS; } -void grantCleanUp() {} +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 \ No newline at end of file +#endif + +void mndGenerateMachineCode() { grantParseParameter(); } diff --git a/source/dnode/mnode/impl/src/mndInfoSchema.c b/source/dnode/mnode/impl/src/mndInfoSchema.c index d60e7f5cf9022be4708e2ff93fa7bf78ac7aaef7..b210ee0d4fc79102e48dd34acc93e2b13b7b8ef9 100644 --- a/source/dnode/mnode/impl/src/mndInfoSchema.c +++ b/source/dnode/mnode/impl/src/mndInfoSchema.c @@ -23,54 +23,54 @@ //!!!! 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 +79,61 @@ 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 = "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}, @@ -146,23 +146,39 @@ static const SInfosTableSchema userTblDistSchema[] = { {.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 +186,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 +204,10 @@ 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 SInfosTableMeta infosMeta[] = { @@ -211,6 +227,7 @@ static const SInfosTableMeta infosMeta[] = { {TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED, userTblDistSchema, tListLen(userTblDistSchema)}, {TSDB_INS_TABLE_USER_USERS, userUsersSchema, tListLen(userUsersSchema)}, {TSDB_INS_TABLE_VGROUPS, vgroupsSchema, tListLen(vgroupsSchema)}, + {TSDB_INS_TABLE_LICENCES, grantsSchema, tListLen(grantsSchema)}, }; // connection/application/ @@ -286,7 +303,7 @@ int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char * } 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; 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/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 320671c332b72545303c978e736d446eca970905..556e17ad2db0583dc0f6595deb9b2776760d35f0 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -23,13 +23,14 @@ #include "tglobal.h" #include "version.h" -#define QUERY_ID_SIZE 20 -#define QUERY_OBJ_ID_SIZE 18 +#define QUERY_ID_SIZE 20 +#define QUERY_OBJ_ID_SIZE 18 #define SUBQUERY_INFO_SIZE 6 -#define QUERY_SAVE_SIZE 20 +#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 +45,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); @@ -77,9 +78,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 +94,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 +103,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 +161,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 +212,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 +224,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 +346,6 @@ static int32_t mndProcessHeartBeatReq(SNodeMsg *pReq) { return -1; } - SClientHbBatchRsp batchRsp = {0}; batchRsp.rsps = taosArrayInit(0, sizeof(SClientHbRsp)); @@ -685,7 +687,7 @@ static int32_t mndRetrieveConns(SNodeMsg *pReq, SShowObj *pShow, char *data, int numOfRows++; } - pShow->numOfReads += numOfRows; + pShow->numOfRows += numOfRows; return numOfRows; } @@ -903,8 +905,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 +918,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..d9f4f142df786ccef1ef523c107ccbc364f03a21 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,10 @@ 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; + int32_t rowsToRead = SHOW_STEP_SIZE; int32_t size = 0; int32_t rowsRead = 0; @@ -225,15 +139,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)); + 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,8 +158,6 @@ 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]; @@ -257,61 +168,87 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { 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:%s", pShow->id, mndShowStr(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((SShowObj*) pShow)) { + mDebug("show:0x%" PRIx64 ", read finished, numOfRows:%d", pShow->id, pShow->numOfRows); + rowsRead = 0; + } else { + rowsRead = (*retrieveFp)(pReq, (SShowObj *)pShow, pBlock, rowsToRead); + if (rowsRead < 0) { + terrno = rowsRead; + mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); + mndReleaseShowObj((SShowObj *)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; + // numOfCols + sizeof(SSysTableSchema) * numOfCols + data payload + 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); 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; - 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); @@ -320,6 +257,7 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { mndReleaseShowObj((SShowObj*) pShow, false); } + blockDataDestroy(pBlock); return TSDB_CODE_SUCCESS; } @@ -379,7 +317,7 @@ char *mndShowStr(int32_t showType) { } static bool mndCheckRetrieveFinished(SShowObj *pShow) { - if (pShow->pIter == NULL && pShow->numOfReads != 0) { + if (pShow->pIter == NULL && pShow->numOfRows != 0) { return true; } return false; diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index f56c72d93e3aa4f0b7eb98b4de214e01daabedd2..70e41a73b78248141f004c076463d268b1e2d3d2 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) { @@ -765,14 +764,12 @@ static int32_t mndGetSmaMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMe 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 +787,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..a7285162fad34eca10eddd004f60ea137d31d3a7 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -58,7 +58,7 @@ 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); +// mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TP, mndRetrieveStream); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TP, mndCancelGetNextStream); return sdbSetTable(pMnode->pSdb, table); @@ -515,8 +515,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..e1461c0ebaa8af79b7df32347c553319572c5620 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++) { @@ -459,12 +475,12 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { 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); @@ -500,7 +516,7 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { pConsumerEp->oldConsumerId = pConsumerEp->consumerId; pConsumerEp->consumerId = pSubConsumer->consumerId; - //TODO + // TODO pConsumerEp->epoch = 0; taosArrayPush(pSubConsumer->vgInfo, pConsumerEp); diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 4d7f00c24c04fb357d0766f570b5c245a7099490..65a304e9511a3bdf5819c067e355ad1fc9aef219 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -35,7 +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,7 +52,7 @@ 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); +// mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TP, mndRetrieveTopic); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TP, mndCancelGetNextTopic); return sdbSetTable(pMnode->pSdb, table); @@ -595,8 +594,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..e1bf4b1b7d2b5eb4001ff5447b6d1c7aef48d34e 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -74,7 +74,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); } @@ -1370,8 +1370,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/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 bd2e4213d574ec3d4086038b0e8776d266f91071..f43f0b427e618d38a718990e2046c37c48584cf7 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -10,26 +10,23 @@ target_sources( "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/vnodeMgr.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 diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 113501a26b41fba6846a3299e13a946189e36188..7ed0092d36dff9bd37cbf460793454ad5836e52d 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 vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs); +int vnodeApplyWMsg(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..d43503c1ca71df097dd45015e3930c0190dff7b7 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); 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..6fbf265d2ccb1034c40b1f8dc5a56ee729a15fa1 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,16 +141,16 @@ 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; @@ -123,15 +159,15 @@ struct STsdb { int32_t vgId; 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 +189,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 +200,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 +424,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 +474,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 +485,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 +501,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 +556,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 +602,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 +625,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 +644,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 +656,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 +684,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 +698,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 +725,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 +744,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 +771,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 +788,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 +834,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 +897,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 +912,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 @@ -935,5 +958,4 @@ static FORCE_INLINE int tsdbUnLockFS(STsdbFS *pFs) { } #endif - #endif /*_TD_VNODE_TSDB_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/tsdbSma.h b/source/dnode/vnode/src/inc/tsdbSma.h new file mode 100644 index 0000000000000000000000000000000000000000..ce03fa7c678b888e6374cb23ba060f463e1c39c6 --- /dev/null +++ b/source/dnode/vnode/src/inc/tsdbSma.h @@ -0,0 +1,68 @@ +/* + * 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_VNODE_TSDB_SMA_H_ +#define _TD_VNODE_TSDB_SMA_H_ + +#include "tdbInt.h" + +#ifdef __cplusplus +extern "C" { +#endif + +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_SMA_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..6957cfdb73a02d1a82a6313bc15433829f283001 --- /dev/null +++ b/source/dnode/vnode/src/inc/vnd.h @@ -0,0 +1,92 @@ +/* + * 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); + +#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..c956184fc9fd64081c62e0bfdee92460b687a704 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -17,6 +17,9 @@ #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" @@ -25,42 +28,28 @@ #include "tglobal.h" #include "tlist.h" #include "tlockfree.h" +#include "tlosertree.h" #include "tmacro.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,124 +89,19 @@ 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" #include "tq.h" +#include "tsdbSma.h" + #ifdef __cplusplus } #endif 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 e3acba7eb6017449e5664d124578699ebd97a078..9b9f54b5ba9016cc53f22ef7996f13ca98487fc9 100644 --- a/source/dnode/vnode/src/meta/metaTDBImpl.c +++ b/source/dnode/vnode/src/meta/metaTDBImpl.c @@ -15,29 +15,34 @@ #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); -static void * poolMalloc(void *arg, size_t size); +static void *poolMalloc(void *arg, size_t size); static void poolFree(void *arg, void *ptr); struct SMetaDB { TXN txn; - TENV * pEnv; - TDB * pTbDB; - TDB * pSchemaDB; - TDB * pNameIdx; - TDB * pStbIdx; - TDB * pNtbIdx; - TDB * pCtbIdx; + TENV *pEnv; + TDB *pTbDB; + TDB *pSchemaDB; + TDB *pNameIdx; + TDB *pStbIdx; + TDB *pNtbIdx; + TDB *pCtbIdx; SPoolMem *pPool; +#ifdef META_TDB_SMA_TEST + TDB *pSmaDB; + TDB *pSmaIdx; +#endif }; typedef struct __attribute__((__packed__)) { @@ -46,7 +51,7 @@ typedef struct __attribute__((__packed__)) { } SSchemaDbKey; typedef struct { - char * name; + char *name; tb_uid_t uid; } SNameIdxKey; @@ -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); @@ -205,14 +250,14 @@ void metaCloseDB(SMeta *pMeta) { int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg) { tb_uid_t uid; - SMetaDB * pMetaDb; - void * pKey; - void * pVal; + SMetaDB *pMetaDb; + void *pKey; + void *pVal; int kLen; int vLen; int ret; char buf[512]; - void * pBuf; + void *pBuf; SCtbIdxKey ctbIdxKey; SSchemaDbKey schemaDbKey; SSchemaWrapper schemaWrapper; @@ -329,11 +374,11 @@ int metaRemoveTableFromDb(SMeta *pMeta, tb_uid_t uid) { STbCfg *metaGetTbInfoByUid(SMeta *pMeta, tb_uid_t uid) { int ret; SMetaDB *pMetaDb = pMeta->pDB; - void * pKey; - void * pVal; + void *pKey; + void *pVal; int kLen; int vLen; - STbCfg * pTbCfg; + STbCfg *pTbCfg; // Fetch pKey = &uid; @@ -385,14 +430,14 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo } static SSchemaWrapper *metaGetTableSchemaImpl(SMeta *pMeta, tb_uid_t uid, int32_t sver, bool isinline, bool isGetEx) { - void * pKey; - void * pVal; + void *pKey; + void *pVal; int kLen; int vLen; int ret; SSchemaDbKey schemaDbKey; SSchemaWrapper *pSchemaWrapper; - void * pBuf; + void *pBuf; // fetch schemaDbKey.uid = uid; @@ -419,9 +464,9 @@ STSchema *metaGetTbTSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver) { tb_uid_t quid; SSchemaWrapper *pSW; STSchemaBuilder sb; - SSchemaEx * pSchema; - STSchema * pTSchema; - STbCfg * pTbCfg; + SSchemaEx *pSchema; + STSchema *pTSchema; + STbCfg *pTbCfg; pTbCfg = metaGetTbInfoByUid(pMeta, uid); if (pTbCfg->type == META_CHILD_TABLE) { @@ -452,7 +497,7 @@ struct SMTbCursor { SMTbCursor *metaOpenTbCursor(SMeta *pMeta) { SMTbCursor *pTbCur = NULL; - SMetaDB * pDB = pMeta->pDB; + SMetaDB *pDB = pMeta->pDB; pTbCur = (SMTbCursor *)taosMemoryCalloc(1, sizeof(*pTbCur)); if (pTbCur == NULL) { @@ -474,12 +519,12 @@ void metaCloseTbCursor(SMTbCursor *pTbCur) { } char *metaTbCursorNext(SMTbCursor *pTbCur) { - void * pKey = NULL; - void * pVal = NULL; + void *pKey = NULL; + void *pVal = NULL; int kLen; int vLen; int ret; - void * pBuf; + void *pBuf; STbCfg tbCfg; for (;;) { @@ -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); } @@ -503,17 +547,17 @@ char *metaTbCursorNext(SMTbCursor *pTbCur) { } struct SMCtbCursor { - TDBC * pCur; + TDBC *pCur; tb_uid_t suid; - void * pKey; - void * pVal; + void *pKey; + void *pVal; int kLen; int vLen; }; SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid) { SMCtbCursor *pCtbCur = NULL; - SMetaDB * pDB = pMeta->pDB; + SMetaDB *pDB = pMeta->pDB; int ret; pCtbCur = (SMCtbCursor *)taosMemoryCalloc(1, sizeof(*pCtbCur)); @@ -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) { @@ -783,7 +1101,7 @@ static void closePool(SPoolMem *pPool) { } static void *poolMalloc(void *arg, size_t size) { - void * ptr = NULL; + void *ptr = NULL; SPoolMem *pPool = (SPoolMem *)arg; SPoolMem *pMem; 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..f57103aab431eb1d1365e7b79dee660f808a2213 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 = { @@ -255,7 +252,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 +430,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}; 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 84f12f93c618cfe5c2843b4271fe07904877442b..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); 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 index 0deef2e4c9f6de92b68a334434814fb27d3f1a99..acd9c2dcaa72d39dab0576d7ab809e49eb5c24ee 100644 --- a/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c +++ b/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c @@ -16,9 +16,7 @@ #define ALLOW_FORBID_FUNC #include "db.h" -#include "taoserror.h" -#include "tcoding.h" -#include "thash.h" +#include "vnodeInt.h" #define IMPL_WITH_LOCK 1 @@ -139,7 +137,7 @@ int32_t tsdbSaveSmaToDB(SDBFile *pDBF, void *key, uint32_t keySize, void *data, return 0; } -void *tsdbGetSmaDataByKey(SDBFile *pDBF, void* key, uint32_t keySize, uint32_t *valueSize) { +void *tsdbGetSmaDataByKey(SDBFile *pDBF, void *key, uint32_t keySize, uint32_t *valueSize) { void *result = NULL; DBT key1 = {0}; DBT value1 = {0}; diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index eff350ddda33e63bfae95e4dfd71ec76d8481801..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"; @@ -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/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 550e7cd183934681889b8c1e38d6ed5c81617596..9509dfa462a9e53aae9d284f6b5c5254de92dfe3 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -13,18 +13,6 @@ * along with this program. If not, see . */ -#include "os.h" -#include "talgo.h" -#include "tcompare.h" -#include "tdatablock.h" -#include "tdataformat.h" -#include "texception.h" -#include "vnodeInt.h" - -#include "filter.h" -#include "taosdef.h" -#include "tlosertree.h" -#include "tmsg.h" #include "vnodeInt.h" #define EXTRA_BYTES 2 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..519ecd3fa06952609c522f4ef937b8b953bc1948 --- /dev/null +++ b/source/dnode/vnode/src/tsdb/tsdbTDBImpl.c @@ -0,0 +1,137 @@ +/* + * 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 *result; + void *pVal; + 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); + + result = taosMemoryMalloc(*valLen); + + if (result == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + // 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? + memcpy(result, pVal, *valLen); + + return result; +} \ 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..270dc377b97968a28798a96eae37f69c990de8dd 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" 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..87ce471de9b2f6a91ee9b07d444bab384eb1dbc5 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -13,10 +13,8 @@ * 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) { @@ -57,11 +55,6 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { 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: @@ -207,74 +200,3 @@ _exit: tmsgSendRsp(&rpcMsg); 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); - return 0; -} diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index bf2260c51cbaff653f12468745efa8a9206e69f4..24b5d4bae50774f8d7aea3039ad72cf679bb6a87 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -19,7 +19,7 @@ void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { // TODO // blockDebugShowData(data); - // tsdbInsertTSmaData(((SVnode *)pVnode)->pTsdb, smaId, (const char *)data); + tsdbInsertTSmaData(((SVnode *)pVnode)->pTsdb, smaId, (const char *)data); } void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { @@ -81,7 +81,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { // TODO: to encapsule a free API taosMemoryFree(vCreateTbReq.stbCfg.pSchema); taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema); - if(vCreateTbReq.stbCfg.pRSmaParam) { + if (vCreateTbReq.stbCfg.pRSmaParam) { taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->pFuncIds); taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam); } @@ -232,16 +232,16 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { 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 (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}; 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/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 37bc4b771fed9cd414884ac2b894b26b1dbd1ce6..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,66 +152,36 @@ 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; @@ -252,7 +205,6 @@ typedef struct STaskIdInfo { typedef struct SExecTaskInfo { STaskIdInfo id; - char* content; uint32_t status; STimeWindow window; STaskCostInfo cost; @@ -262,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; @@ -297,7 +249,7 @@ typedef struct STaskRuntimeEnv { int64_t currentOffset; // dynamic offset value STableQueryInfo* current; - SResultInfo resultInfo; + SResultInfo resultInfo; SHashObj* pTableRetrieveTsMap; struct SUdfInfo* pUdfInfo; } STaskRuntimeEnv; @@ -339,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, @@ -451,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; @@ -523,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; @@ -553,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 { @@ -582,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 { @@ -633,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 { @@ -680,8 +590,7 @@ int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, SExprInf 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, @@ -748,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); diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index 626cb1b5f0d9c8fc1598807e429bee6338bc76c4..e897bc8892e594368cc8a1b1d9a0f33d91f03c46 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -92,7 +92,7 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput, return false; } - pBuf->allocSize = sizeof(SRetrieveTableRsp) + blockEstimateEncodeSize(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 0eac50782200c29bba13b19a75e7cb941118a18e..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; } @@ -990,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; @@ -1700,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; @@ -1961,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; } @@ -2187,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); @@ -2257,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; @@ -2357,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; @@ -3131,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 @@ -3509,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; @@ -3547,7 +3454,7 @@ void calculateOperatorProfResults(SQInfo* pQInfo) { } } } - +#endif taosArrayDestroy(opStack); } @@ -4007,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 @@ -4040,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; } } @@ -4456,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); @@ -4662,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) { @@ -5495,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) { @@ -5512,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); diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index c8a6697d4e944c44923ba0a09f8f995a266eeeef..cd79d719dad44f51cfa407889c06837bdf56850b 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -227,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); } @@ -244,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); diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index f1502df7437b57dc72091611ed661cb49653ba1a..59ef31b2ff494ae766463908a8a16f62e5cc442a 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -258,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"; @@ -275,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; @@ -543,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; @@ -594,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 @@ -683,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, @@ -756,12 +757,12 @@ 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; @@ -772,6 +773,8 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB tableType = TSDB_MGMT_TABLE_USER; } else if (strncasecmp(name, TSDB_INS_TABLE_DNODES, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_DNODE; + } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_GRANTS; } else if (strncasecmp(name, TSDB_INS_TABLE_MNODES, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_MNODE; } else if (strncasecmp(name, TSDB_INS_TABLE_MODULES, tListLen(pName->tname)) == 0) { @@ -796,6 +799,8 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB 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 if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_CLUSTER; } else { ASSERT(0); } @@ -833,15 +838,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 ab5a02c438ba7975a73718e15fa34b7c477dd67d..624a2953c935997c5c35708a21dbe223c29db62a 100644 --- a/source/libs/function/inc/builtins.h +++ b/source/libs/function/inc/builtins.h @@ -22,7 +22,7 @@ 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) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 55f38e9005b0e507ed88124e7cc3ae8bf8c16334..27067fc966288943aaf074f38ecf27a71b1a5be3 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -403,6 +403,36 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .sprocessFunc = toISO8601Function, .finalizeFunc = NULL }, + { + .name = "to_unixtimestamp", + .type = FUNCTION_TYPE_TO_UNIXTIMESTAMP, + .classification = FUNC_MGT_SCALAR_FUNC, + .checkFunc = checkAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = toUnixtimestampFunction, + .finalizeFunc = NULL + }, + { + .name = "timetruncate", + .type = FUNCTION_TYPE_TIMETRUNCATE, + .classification = FUNC_MGT_SCALAR_FUNC, + .checkFunc = checkAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = timeTruncateFunction, + .finalizeFunc = NULL + }, + { + .name = "timediff", + .type = FUNCTION_TYPE_TIMEDIFF, + .classification = FUNC_MGT_SCALAR_FUNC, + .checkFunc = checkAndGetResultType, + .getEnvFunc = NULL, + .initFunc = NULL, + .sprocessFunc = timeDiffFunction, + .finalizeFunc = NULL + }, { .name = "_rowts", .type = FUNCTION_TYPE_ROWTS, @@ -621,6 +651,19 @@ int32_t checkAndGetResultType(SFunctionNode* pFunc) { } case FUNCTION_TYPE_TO_ISO8601: { pFunc->node.resType = (SDataType) { .bytes = 64, .type = TSDB_DATA_TYPE_BINARY}; + break; + } + case FUNCTION_TYPE_TO_UNIXTIMESTAMP: { + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; + break; + } + case FUNCTION_TYPE_TIMETRUNCATE: { + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP}; + break; + } + case FUNCTION_TYPE_TIMEDIFF: { + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; + break; } case FUNCTION_TYPE_TBNAME: { diff --git a/source/libs/nodes/src/nodesTraverseFuncs.c b/source/libs/nodes/src/nodesTraverseFuncs.c index 4a782cce08edebff0cc46837c34b18e29d58fb3d..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; @@ -80,7 +80,7 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker case QUERY_NODE_STATE_WINDOW: { SStateWindowNode* pState = (SStateWindowNode*)pNode; res = walkNode(pState->pExpr, order, walker, pContext); - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = walkNode(pState->pCol, order, walker, pContext); } break; @@ -88,7 +88,7 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker 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; @@ -96,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; @@ -126,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); } @@ -136,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; @@ -185,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; @@ -202,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; @@ -219,7 +220,7 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit case QUERY_NODE_STATE_WINDOW: { SStateWindowNode* pState = (SStateWindowNode*)pNode; res = rewriteNode(&pState->pExpr, order, rewriter, pContext); - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = rewriteNode(&pState->pCol, order, rewriter, pContext); } break; @@ -227,7 +228,7 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit case QUERY_NODE_SESSION_WINDOW: { SSessionWindowNode* pSession = (SSessionWindowNode*)pNode; res = rewriteNode(&pSession->pCol, order, rewriter, pContext); - if (DEAL_RES_ERROR != res) { + if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { res = rewriteNode(&pSession->pGap, order, rewriter, pContext); } break; @@ -235,16 +236,16 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit 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; @@ -265,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); } @@ -275,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/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 94aec0e744db52a35b730d9378ed3490992e642a..12ae5819b47d509e07fc59b6fd98a9d719eca40f 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -588,6 +588,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 0dcf04ecc0f71a8910e2b5cdf996b43fb79d7070..498b700be3c28d735e3fe99c612fc46730136447 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -336,8 +336,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; } diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index c9a0f4114e68cde442e769ca68f7998042c23d20..9bc81d8fba5445266870a310d1e51a5c03a9bcc4 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); } diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index 5c2f10f810df14ae078c31f3f01734d2faa1c44d..0493771b61bea090534be3f5d4bdacae0da72f99 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -175,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}, diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index bd461c762213cd8fd9adfc4245c15ac6d95501a7..e143761e4dd06468012593e07056ff2e0b6f24fb 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -2377,7 +2377,6 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* 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: @@ -2565,6 +2564,8 @@ 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; default: break; } @@ -3080,6 +3081,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: diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 610f6b92633ee44af1da5119bb732b8363d820c6..b1f8a24a83cb638777fbeba6b2a6c4c05b22600e 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 314 +#define YYNOCODE 315 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - ENullOrder yy69; - SNode* yy140; - EFillMode yy174; - SAlterOption yy181; - SNodeList* yy220; - EJoinType yy224; - EOrder yy238; - SToken yy253; - bool yy273; - SDataType yy368; - EOperatorType yy480; - int32_t yy528; + SToken yy29; + bool yy47; + EFillMode yy144; + EJoinType yy162; + SNode* yy182; + EOrder yy218; + SNodeList* yy334; + EOperatorType yy380; + ENullOrder yy487; + SAlterOption yy515; + int32_t yy550; + SDataType yy574; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -133,16 +133,17 @@ typedef union { #define ParseCTX_FETCH #define ParseCTX_STORE #define YYNSTATE 548 -#define YYNRULE 410 -#define YYNTOKEN 208 +#define YYNRULE 411 +#define YYNRULE_WITH_ACTION 411 +#define YYNTOKEN 209 #define YY_MAX_SHIFT 547 -#define YY_MIN_SHIFTREDUCE 807 -#define YY_MAX_SHIFTREDUCE 1216 -#define YY_ERROR_ACTION 1217 -#define YY_ACCEPT_ACTION 1218 -#define YY_NO_ACTION 1219 -#define YY_MIN_REDUCE 1220 -#define YY_MAX_REDUCE 1629 +#define YY_MIN_SHIFTREDUCE 808 +#define YY_MAX_SHIFTREDUCE 1218 +#define YY_ERROR_ACTION 1219 +#define YY_ACCEPT_ACTION 1220 +#define YY_NO_ACTION 1221 +#define YY_MIN_REDUCE 1222 +#define YY_MAX_REDUCE 1632 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -209,483 +210,483 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (1533) +#define YY_ACTTAB_COUNT (1539) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 463, 25, 194, 52, 257, 306, 1497, 9, 8, 72, - /* 10 */ 277, 388, 30, 28, 463, 274, 369, 1421, 1423, 270, - /* 20 */ 266, 1481, 1052, 310, 1336, 1340, 396, 115, 1072, 1481, - /* 30 */ 1514, 1497, 1481, 1477, 1483, 1342, 1608, 446, 1050, 1340, - /* 40 */ 166, 1477, 1484, 391, 1477, 1483, 462, 449, 385, 131, - /* 50 */ 11, 1468, 406, 1606, 165, 1514, 312, 1057, 29, 27, - /* 60 */ 26, 348, 446, 30, 28, 1159, 463, 119, 1498, 1499, - /* 70 */ 1503, 266, 449, 1052, 1, 72, 1468, 30, 28, 265, - /* 80 */ 42, 1135, 375, 41, 462, 266, 238, 1052, 1497, 1050, - /* 90 */ 1331, 1340, 229, 1498, 1499, 1503, 407, 544, 540, 539, - /* 100 */ 1075, 11, 462, 1050, 450, 435, 1621, 269, 1057, 1051, - /* 110 */ 1430, 463, 1514, 381, 380, 11, 30, 28, 430, 446, - /* 120 */ 311, 117, 1057, 1232, 266, 1, 1052, 1608, 1608, 449, - /* 130 */ 513, 511, 1243, 1468, 430, 1468, 1340, 1124, 12, 1, - /* 140 */ 131, 1607, 1050, 100, 1606, 1606, 1053, 1318, 544, 70, - /* 150 */ 1498, 1499, 1503, 1547, 420, 1128, 12, 1546, 1543, 100, - /* 160 */ 1051, 1057, 544, 1056, 1076, 1077, 1103, 1104, 1105, 1106, - /* 170 */ 1107, 1108, 1109, 1110, 1051, 463, 98, 1468, 7, 22, - /* 180 */ 1242, 30, 28, 448, 319, 132, 128, 1554, 1555, 266, - /* 190 */ 1559, 1052, 98, 132, 118, 132, 348, 1053, 1298, 1387, - /* 200 */ 1340, 544, 129, 1554, 1555, 256, 1559, 1050, 425, 421, - /* 210 */ 1385, 1053, 1074, 1051, 1056, 1076, 1077, 1103, 1104, 1105, - /* 220 */ 1106, 1107, 1108, 1109, 1110, 1468, 1057, 1221, 1056, 1076, - /* 230 */ 1077, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 305, - /* 240 */ 844, 304, 843, 7, 1076, 1077, 9, 8, 84, 132, - /* 250 */ 1053, 83, 82, 81, 80, 79, 78, 77, 76, 75, - /* 260 */ 845, 32, 31, 29, 27, 26, 544, 1056, 1076, 1077, - /* 270 */ 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1051, 132, - /* 280 */ 424, 1418, 52, 30, 28, 237, 65, 1072, 139, 132, - /* 290 */ 383, 266, 377, 1052, 327, 96, 382, 339, 1241, 97, - /* 300 */ 101, 378, 376, 1335, 379, 216, 340, 1332, 1370, 1050, - /* 310 */ 32, 31, 29, 27, 26, 1053, 84, 1566, 1154, 83, - /* 320 */ 82, 81, 80, 79, 78, 77, 76, 75, 1057, 1220, - /* 330 */ 334, 1183, 1056, 1076, 1077, 1103, 1104, 1105, 1106, 1107, - /* 340 */ 1108, 1109, 1110, 1468, 1078, 7, 164, 445, 241, 137, - /* 350 */ 372, 895, 498, 93, 92, 91, 90, 89, 88, 87, - /* 360 */ 86, 85, 417, 1181, 1182, 1184, 1185, 501, 544, 1312, - /* 370 */ 897, 1079, 374, 1091, 250, 50, 141, 140, 49, 338, - /* 380 */ 1051, 1122, 333, 332, 331, 330, 329, 430, 326, 325, - /* 390 */ 324, 323, 322, 318, 317, 316, 315, 314, 313, 463, - /* 400 */ 164, 30, 28, 489, 372, 1561, 463, 450, 320, 266, - /* 410 */ 1561, 1052, 100, 1431, 1387, 347, 251, 1053, 249, 248, - /* 420 */ 271, 371, 1514, 1558, 1340, 1385, 374, 1050, 1557, 446, - /* 430 */ 1123, 1340, 1215, 1216, 1056, 1076, 1077, 1103, 1104, 1105, - /* 440 */ 1106, 1107, 1108, 1109, 1110, 98, 1057, 1269, 1127, 32, - /* 450 */ 31, 29, 27, 26, 432, 127, 1554, 1555, 1317, 1559, - /* 460 */ 1114, 423, 189, 1, 1073, 32, 31, 29, 27, 26, - /* 470 */ 1561, 59, 24, 264, 1117, 1118, 1119, 1120, 1121, 1125, - /* 480 */ 1126, 32, 31, 29, 27, 26, 544, 241, 1556, 175, - /* 490 */ 1166, 157, 1333, 122, 155, 1158, 1074, 1240, 1051, 520, - /* 500 */ 519, 518, 517, 281, 1380, 516, 515, 514, 102, 509, - /* 510 */ 508, 507, 506, 505, 504, 503, 502, 108, 159, 209, - /* 520 */ 1122, 158, 500, 494, 933, 486, 485, 484, 937, 483, - /* 530 */ 939, 940, 482, 942, 479, 1053, 948, 476, 950, 951, - /* 540 */ 473, 470, 1468, 1239, 1173, 496, 116, 1329, 1218, 1316, - /* 550 */ 6, 222, 1056, 1076, 1077, 1103, 1104, 1105, 1106, 1107, - /* 560 */ 1108, 1109, 1110, 220, 493, 492, 491, 21, 490, 1123, - /* 570 */ 161, 437, 23, 160, 843, 1238, 142, 32, 31, 29, - /* 580 */ 27, 26, 32, 31, 29, 27, 26, 1127, 1468, 115, - /* 590 */ 367, 1325, 1213, 152, 1272, 1327, 125, 1343, 498, 463, - /* 600 */ 463, 282, 365, 397, 361, 357, 353, 151, 1337, 460, - /* 610 */ 1387, 24, 264, 1117, 1118, 1119, 1120, 1121, 1125, 1126, - /* 620 */ 1468, 1422, 1323, 169, 1340, 1340, 297, 276, 447, 463, - /* 630 */ 273, 272, 1608, 53, 1608, 115, 149, 1237, 461, 67, - /* 640 */ 1065, 299, 1497, 1342, 1457, 131, 383, 131, 377, 1606, - /* 650 */ 163, 1606, 382, 162, 1340, 97, 1058, 378, 376, 1212, - /* 660 */ 379, 32, 31, 29, 27, 26, 1514, 48, 47, 309, - /* 670 */ 1387, 136, 405, 446, 512, 1057, 303, 1157, 300, 1259, - /* 680 */ 289, 1386, 1468, 449, 246, 1497, 295, 1468, 291, 287, - /* 690 */ 133, 1154, 434, 148, 279, 121, 106, 145, 1497, 1236, - /* 700 */ 409, 384, 115, 68, 1498, 1499, 1503, 1547, 488, 1514, - /* 710 */ 1342, 240, 1543, 132, 143, 464, 433, 32, 31, 29, - /* 720 */ 27, 26, 1514, 1608, 1091, 395, 449, 1061, 463, 446, - /* 730 */ 1468, 1235, 1234, 1299, 441, 438, 131, 208, 393, 449, - /* 740 */ 1606, 1497, 463, 1468, 1468, 1231, 69, 1498, 1499, 1503, - /* 750 */ 1547, 280, 1387, 1340, 259, 1543, 126, 1254, 278, 119, - /* 760 */ 1498, 1499, 1503, 1385, 1066, 1514, 547, 1340, 190, 436, - /* 770 */ 430, 1233, 433, 1230, 413, 1574, 1468, 1468, 1060, 386, - /* 780 */ 213, 1069, 449, 95, 1052, 1252, 1468, 1229, 1228, 536, - /* 790 */ 1468, 532, 528, 524, 212, 100, 1227, 44, 1622, 1226, - /* 800 */ 1050, 1180, 69, 1498, 1499, 1503, 1547, 389, 191, 178, - /* 810 */ 259, 1543, 126, 180, 434, 1225, 1224, 418, 1468, 1057, - /* 820 */ 66, 1223, 33, 206, 1497, 33, 1129, 1059, 98, 1087, - /* 830 */ 343, 1575, 1468, 1468, 1488, 1381, 404, 64, 187, 1554, - /* 840 */ 429, 1468, 428, 114, 1468, 1608, 1486, 61, 1514, 1063, - /* 850 */ 44, 1497, 33, 459, 921, 446, 1019, 366, 131, 544, - /* 860 */ 1468, 1468, 1606, 184, 1577, 449, 1468, 439, 442, 1468, - /* 870 */ 197, 1051, 94, 104, 199, 1514, 455, 205, 1497, 106, - /* 880 */ 1515, 412, 446, 926, 171, 69, 1498, 1499, 1503, 1547, - /* 890 */ 431, 2, 449, 259, 1543, 1620, 1468, 193, 1062, 1036, - /* 900 */ 1072, 168, 1514, 468, 1581, 869, 104, 954, 1053, 446, - /* 910 */ 958, 284, 69, 1498, 1499, 1503, 1547, 288, 245, 449, - /* 920 */ 259, 1543, 1620, 1468, 870, 1056, 105, 895, 1497, 247, - /* 930 */ 964, 1604, 106, 104, 1028, 214, 963, 107, 321, 69, - /* 940 */ 1498, 1499, 1503, 1547, 1420, 138, 328, 259, 1543, 1620, - /* 950 */ 336, 335, 1514, 1497, 337, 1083, 341, 342, 1565, 446, - /* 960 */ 1082, 344, 144, 1081, 345, 346, 1080, 147, 51, 449, - /* 970 */ 349, 150, 368, 1468, 398, 399, 370, 1514, 434, 1330, - /* 980 */ 1497, 154, 411, 400, 446, 1326, 255, 74, 401, 228, - /* 990 */ 1498, 1499, 1503, 156, 449, 373, 109, 408, 1468, 110, - /* 1000 */ 1328, 1324, 111, 112, 1514, 1079, 1497, 170, 173, 1608, - /* 1010 */ 419, 446, 1588, 410, 70, 1498, 1499, 1503, 1547, 453, - /* 1020 */ 1057, 449, 131, 1544, 5, 1468, 1606, 1578, 183, 176, - /* 1030 */ 1514, 416, 1497, 1587, 179, 1568, 258, 446, 422, 427, - /* 1040 */ 1497, 70, 1498, 1499, 1503, 1547, 415, 449, 1154, 444, - /* 1050 */ 1543, 1468, 4, 99, 414, 1078, 1514, 1562, 34, 260, - /* 1060 */ 443, 186, 440, 446, 1514, 17, 1429, 233, 1498, 1499, - /* 1070 */ 1503, 446, 124, 449, 1497, 1529, 451, 1468, 185, 452, - /* 1080 */ 456, 449, 203, 1428, 268, 1468, 201, 1497, 263, 58, - /* 1090 */ 457, 458, 1341, 232, 1498, 1499, 1503, 1623, 1514, 1497, - /* 1100 */ 192, 233, 1498, 1499, 1503, 446, 1605, 466, 215, 1313, - /* 1110 */ 60, 1514, 495, 217, 211, 449, 543, 40, 446, 1468, - /* 1120 */ 219, 223, 267, 1514, 224, 426, 221, 1462, 449, 1461, - /* 1130 */ 446, 283, 1468, 1497, 1458, 233, 1498, 1499, 1503, 285, - /* 1140 */ 449, 286, 1046, 1047, 1468, 134, 290, 1456, 225, 1498, - /* 1150 */ 1499, 1503, 292, 293, 294, 1455, 296, 1514, 1454, 1497, - /* 1160 */ 231, 1498, 1499, 1503, 446, 1445, 298, 135, 301, 302, - /* 1170 */ 1031, 1030, 1439, 1438, 449, 307, 308, 1437, 1468, 103, - /* 1180 */ 1002, 1413, 1412, 1514, 1436, 1497, 1411, 1410, 1409, 1408, - /* 1190 */ 446, 1407, 1406, 1405, 234, 1498, 1499, 1503, 1404, 1403, - /* 1200 */ 449, 1402, 1401, 1400, 1468, 1004, 1391, 1390, 1389, 1514, - /* 1210 */ 1497, 1399, 1398, 1397, 1396, 1395, 446, 1394, 1393, 1392, - /* 1220 */ 226, 1498, 1499, 1503, 1388, 1271, 449, 1453, 1447, 1435, - /* 1230 */ 1468, 1426, 1319, 146, 1514, 1497, 862, 1270, 1268, 352, - /* 1240 */ 1266, 446, 350, 356, 1497, 351, 235, 1498, 1499, 1503, - /* 1250 */ 1264, 449, 1262, 360, 354, 1468, 355, 359, 1251, 1514, - /* 1260 */ 358, 362, 363, 1250, 1247, 1321, 446, 969, 1514, 1320, - /* 1270 */ 1260, 227, 1498, 1499, 1503, 446, 449, 364, 73, 1497, - /* 1280 */ 1468, 971, 894, 252, 893, 449, 892, 891, 1255, 1468, - /* 1290 */ 253, 888, 887, 1253, 387, 254, 236, 1498, 1499, 1503, - /* 1300 */ 390, 1246, 392, 1514, 512, 1511, 1498, 1499, 1503, 1245, - /* 1310 */ 446, 153, 510, 1497, 394, 71, 1452, 167, 43, 1038, - /* 1320 */ 449, 1446, 113, 1434, 1468, 402, 1433, 1425, 172, 14, - /* 1330 */ 54, 3, 403, 1486, 177, 37, 35, 1514, 33, 15, - /* 1340 */ 1510, 1498, 1499, 1503, 446, 38, 1179, 1497, 10, 120, - /* 1350 */ 181, 19, 188, 1172, 449, 182, 1497, 55, 1468, 56, - /* 1360 */ 20, 1151, 1497, 1201, 8, 1150, 1206, 36, 130, 174, - /* 1370 */ 123, 1514, 1200, 16, 243, 1498, 1499, 1503, 446, 261, - /* 1380 */ 1514, 1315, 1205, 1204, 262, 195, 1514, 446, 449, 1089, - /* 1390 */ 1497, 13, 1468, 446, 1088, 196, 18, 449, 1424, 1177, - /* 1400 */ 202, 1468, 1115, 449, 198, 200, 45, 1468, 1509, 1498, - /* 1410 */ 1499, 1503, 57, 61, 1514, 454, 1497, 244, 1498, 1499, - /* 1420 */ 1503, 446, 1485, 242, 1498, 1499, 1503, 204, 207, 1067, - /* 1430 */ 39, 449, 465, 955, 467, 1468, 952, 275, 469, 471, - /* 1440 */ 1514, 472, 209, 949, 474, 475, 494, 446, 943, 477, - /* 1450 */ 478, 239, 1498, 1499, 1503, 941, 480, 449, 481, 947, - /* 1460 */ 932, 1468, 946, 62, 945, 944, 487, 966, 496, 46, - /* 1470 */ 962, 63, 960, 860, 497, 499, 901, 230, 1498, 1499, - /* 1480 */ 1503, 965, 883, 210, 882, 881, 880, 493, 492, 491, - /* 1490 */ 879, 490, 878, 877, 876, 896, 898, 873, 872, 871, - /* 1500 */ 868, 867, 866, 865, 1267, 521, 522, 1265, 1263, 523, - /* 1510 */ 526, 525, 527, 529, 530, 1261, 534, 533, 1249, 531, - /* 1520 */ 535, 537, 538, 1248, 1244, 541, 542, 1219, 1054, 1219, - /* 1530 */ 546, 218, 545, + /* 0 */ 450, 257, 1483, 269, 25, 194, 1432, 117, 122, 1234, + /* 10 */ 312, 1331, 30, 28, 1479, 1486, 306, 1499, 1483, 1382, + /* 20 */ 266, 462, 1053, 21, 1075, 32, 31, 29, 27, 26, + /* 30 */ 1479, 1485, 23, 32, 31, 29, 27, 26, 1051, 274, + /* 40 */ 238, 1516, 32, 31, 29, 27, 26, 1611, 446, 1073, + /* 50 */ 11, 30, 28, 1161, 348, 406, 1483, 1058, 449, 266, + /* 60 */ 131, 1053, 1470, 1320, 1609, 30, 28, 434, 1479, 1485, + /* 70 */ 430, 9, 8, 266, 1, 1053, 463, 1051, 68, 1500, + /* 80 */ 1501, 1505, 1550, 540, 539, 72, 240, 1546, 1175, 11, + /* 90 */ 1499, 1051, 369, 424, 450, 100, 1058, 544, 1611, 407, + /* 100 */ 1433, 1342, 1261, 11, 32, 31, 29, 27, 26, 1052, + /* 110 */ 1058, 131, 348, 1, 1516, 1609, 32, 31, 29, 27, + /* 120 */ 26, 433, 118, 1389, 384, 277, 1300, 1, 98, 256, + /* 130 */ 1611, 449, 1423, 1425, 1387, 1470, 544, 432, 127, 1557, + /* 140 */ 1558, 270, 1562, 131, 498, 1137, 1054, 1609, 1052, 115, + /* 150 */ 544, 69, 1500, 1501, 1505, 1550, 845, 1344, 844, 259, + /* 160 */ 1546, 126, 1052, 1057, 1077, 1078, 1104, 1105, 1106, 1107, + /* 170 */ 1108, 1109, 1110, 1111, 1112, 164, 846, 381, 380, 372, + /* 180 */ 1578, 462, 1564, 1220, 84, 1054, 132, 83, 82, 81, + /* 190 */ 80, 79, 78, 77, 76, 75, 29, 27, 26, 1054, + /* 200 */ 1561, 374, 1057, 1077, 1078, 1104, 1105, 1106, 1107, 1108, + /* 210 */ 1109, 1110, 1111, 1112, 1319, 132, 1057, 1077, 1078, 1104, + /* 220 */ 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1318, 30, + /* 230 */ 28, 547, 305, 1564, 304, 12, 282, 266, 383, 1053, + /* 240 */ 377, 896, 132, 1215, 382, 213, 462, 97, 95, 378, + /* 250 */ 376, 1560, 379, 115, 536, 1051, 532, 528, 524, 212, + /* 260 */ 898, 1345, 32, 31, 29, 27, 26, 1611, 30, 28, + /* 270 */ 448, 1499, 463, 132, 1058, 209, 266, 498, 1053, 494, + /* 280 */ 131, 310, 30, 28, 1609, 66, 52, 1076, 206, 1074, + /* 290 */ 266, 7, 1053, 1333, 1051, 1516, 65, 1342, 1516, 96, + /* 300 */ 12, 496, 433, 1245, 334, 446, 463, 1337, 1051, 489, + /* 310 */ 101, 1214, 449, 1058, 544, 311, 1470, 1334, 459, 438, + /* 320 */ 493, 492, 491, 1185, 490, 1092, 1052, 1058, 513, 511, + /* 330 */ 7, 1342, 69, 1500, 1501, 1505, 1550, 423, 1470, 395, + /* 340 */ 259, 1546, 126, 1274, 7, 1222, 412, 132, 1470, 171, + /* 350 */ 141, 140, 393, 544, 190, 417, 1183, 1184, 1186, 1187, + /* 360 */ 413, 1577, 500, 1054, 1037, 1052, 168, 544, 1244, 93, + /* 370 */ 92, 91, 90, 89, 88, 87, 86, 85, 1327, 1052, + /* 380 */ 1057, 1077, 1078, 1104, 1105, 1106, 1107, 1108, 1109, 1110, + /* 390 */ 1111, 1112, 1079, 430, 1389, 383, 52, 377, 1611, 1329, + /* 400 */ 271, 382, 1054, 132, 97, 1387, 378, 376, 1243, 379, + /* 410 */ 1242, 1610, 405, 1470, 1241, 1609, 1054, 1338, 100, 1057, + /* 420 */ 1077, 1078, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, + /* 430 */ 1112, 1077, 1078, 1057, 1077, 1078, 1104, 1105, 1106, 1107, + /* 440 */ 1108, 1109, 1110, 1111, 1112, 430, 30, 28, 237, 420, + /* 450 */ 1073, 98, 439, 1470, 266, 1470, 1053, 327, 59, 1470, + /* 460 */ 339, 128, 1557, 1558, 1420, 1562, 1080, 1160, 397, 340, + /* 470 */ 100, 139, 1051, 32, 31, 29, 27, 26, 437, 1335, + /* 480 */ 934, 486, 485, 484, 938, 483, 940, 941, 482, 943, + /* 490 */ 479, 1058, 949, 476, 951, 952, 473, 470, 1223, 1611, + /* 500 */ 1569, 1156, 1564, 98, 425, 421, 9, 8, 1, 463, + /* 510 */ 189, 241, 131, 129, 1557, 1558, 1609, 1562, 319, 84, + /* 520 */ 1559, 1240, 83, 82, 81, 80, 79, 78, 77, 76, + /* 530 */ 75, 544, 216, 1325, 1342, 1372, 1092, 32, 31, 29, + /* 540 */ 27, 26, 338, 1052, 1124, 333, 332, 331, 330, 329, + /* 550 */ 1239, 326, 325, 324, 323, 322, 318, 317, 316, 315, + /* 560 */ 314, 313, 1271, 137, 116, 463, 1470, 1238, 501, 222, + /* 570 */ 1314, 1389, 1389, 6, 320, 32, 31, 29, 27, 26, + /* 580 */ 1054, 220, 1424, 1388, 175, 1168, 169, 447, 1237, 50, + /* 590 */ 1342, 1075, 49, 1125, 142, 1470, 488, 1057, 1077, 1078, + /* 600 */ 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1235, + /* 610 */ 1236, 1129, 1470, 241, 520, 519, 518, 517, 281, 1233, + /* 620 */ 516, 515, 514, 102, 509, 508, 507, 506, 505, 504, + /* 630 */ 503, 502, 108, 1470, 1232, 1499, 24, 264, 1119, 1120, + /* 640 */ 1121, 1122, 1123, 1127, 1128, 463, 1124, 463, 1231, 463, + /* 650 */ 1159, 844, 276, 463, 72, 1470, 347, 67, 1339, 1516, + /* 660 */ 115, 375, 460, 114, 1470, 279, 446, 367, 1344, 1256, + /* 670 */ 1342, 870, 1342, 115, 1342, 463, 449, 436, 1342, 1470, + /* 680 */ 1470, 1344, 1230, 1229, 461, 48, 47, 309, 1499, 136, + /* 690 */ 871, 386, 463, 1470, 303, 1125, 119, 1500, 1501, 1505, + /* 700 */ 1342, 208, 246, 297, 295, 1389, 291, 287, 133, 1301, + /* 710 */ 512, 278, 1516, 1129, 300, 1156, 1387, 1342, 299, 446, + /* 720 */ 157, 1053, 463, 155, 1499, 1228, 1227, 1470, 1470, 449, + /* 730 */ 445, 280, 132, 1470, 435, 1624, 1126, 1051, 24, 264, + /* 740 */ 1119, 1120, 1121, 1122, 1123, 1127, 1128, 1342, 1516, 69, + /* 750 */ 1500, 1501, 1505, 1550, 1130, 446, 1058, 259, 1546, 1623, + /* 760 */ 1499, 1459, 1226, 152, 1225, 449, 125, 191, 1584, 1470, + /* 770 */ 1470, 1470, 365, 343, 361, 357, 353, 151, 159, 22, + /* 780 */ 161, 158, 418, 160, 1516, 69, 1500, 1501, 1505, 1550, + /* 790 */ 1254, 446, 441, 259, 1546, 1623, 544, 289, 1217, 1218, + /* 800 */ 1383, 449, 250, 53, 1607, 1470, 149, 1470, 1052, 1470, + /* 810 */ 1499, 163, 389, 106, 162, 44, 178, 409, 404, 1182, + /* 820 */ 180, 69, 1500, 1501, 1505, 1550, 1490, 184, 164, 259, + /* 830 */ 1546, 1623, 372, 366, 1516, 33, 1580, 1499, 1488, 1131, + /* 840 */ 1568, 446, 431, 1116, 251, 1054, 249, 248, 1061, 371, + /* 850 */ 1517, 449, 1499, 33, 374, 1470, 193, 1088, 1073, 1060, + /* 860 */ 434, 1516, 1057, 148, 2, 121, 33, 145, 446, 284, + /* 870 */ 1020, 228, 1500, 1501, 1505, 288, 1516, 197, 449, 1499, + /* 880 */ 245, 199, 1470, 446, 143, 94, 273, 272, 104, 455, + /* 890 */ 896, 1611, 205, 449, 247, 1029, 1066, 1470, 70, 1500, + /* 900 */ 1501, 1505, 1550, 1516, 131, 321, 1549, 1546, 1609, 214, + /* 910 */ 446, 1422, 1059, 70, 1500, 1501, 1505, 1550, 64, 1064, + /* 920 */ 449, 444, 1546, 430, 1470, 106, 328, 442, 61, 927, + /* 930 */ 1063, 1058, 44, 468, 104, 138, 922, 955, 959, 336, + /* 940 */ 70, 1500, 1501, 1505, 1550, 335, 105, 337, 100, 1547, + /* 950 */ 965, 1084, 341, 106, 104, 1499, 342, 964, 107, 1083, + /* 960 */ 144, 345, 344, 1082, 346, 349, 147, 434, 51, 150, + /* 970 */ 1081, 464, 368, 370, 1332, 154, 373, 1328, 74, 1516, + /* 980 */ 399, 98, 1499, 1062, 400, 401, 446, 255, 408, 156, + /* 990 */ 1499, 187, 1557, 429, 170, 428, 449, 173, 1611, 109, + /* 1000 */ 1470, 110, 1330, 265, 1326, 111, 1516, 112, 1080, 411, + /* 1010 */ 419, 131, 1591, 446, 1516, 1609, 229, 1500, 1501, 1505, + /* 1020 */ 1067, 446, 398, 449, 410, 453, 1058, 1470, 1581, 416, + /* 1030 */ 414, 449, 176, 179, 1499, 1470, 5, 1070, 1590, 415, + /* 1040 */ 258, 422, 427, 233, 1500, 1501, 1505, 4, 99, 1079, + /* 1050 */ 1571, 232, 1500, 1501, 1505, 185, 183, 1156, 1516, 124, + /* 1060 */ 1565, 34, 443, 260, 17, 446, 1431, 1532, 1499, 186, + /* 1070 */ 440, 1430, 456, 457, 60, 449, 1499, 451, 458, 1470, + /* 1080 */ 452, 1499, 268, 426, 201, 203, 1343, 466, 58, 221, + /* 1090 */ 1626, 1315, 1516, 211, 192, 119, 1500, 1501, 1505, 446, + /* 1100 */ 1516, 1608, 215, 495, 217, 1516, 543, 446, 223, 449, + /* 1110 */ 40, 1464, 446, 1470, 224, 219, 263, 449, 1463, 283, + /* 1120 */ 1460, 1470, 449, 1499, 267, 285, 1470, 1047, 1499, 233, + /* 1130 */ 1500, 1501, 1505, 388, 1625, 286, 1499, 233, 1500, 1501, + /* 1140 */ 1505, 1048, 225, 1500, 1501, 1505, 290, 1516, 396, 1458, + /* 1150 */ 134, 294, 1516, 292, 446, 293, 1457, 296, 1456, 446, + /* 1160 */ 1516, 298, 166, 1447, 449, 391, 135, 446, 1470, 449, + /* 1170 */ 385, 301, 302, 1470, 1317, 1441, 165, 449, 1032, 1031, + /* 1180 */ 1499, 1470, 1440, 307, 231, 1500, 1501, 1505, 308, 234, + /* 1190 */ 1500, 1501, 1505, 1439, 1438, 1499, 1003, 226, 1500, 1501, + /* 1200 */ 1505, 1415, 42, 1414, 1516, 41, 1499, 1413, 1412, 1411, + /* 1210 */ 1410, 446, 1409, 1408, 1407, 1406, 1405, 1404, 1403, 1516, + /* 1220 */ 1402, 449, 1401, 1400, 103, 1470, 446, 1399, 1398, 1397, + /* 1230 */ 1516, 1499, 1396, 1395, 1394, 209, 449, 446, 1393, 494, + /* 1240 */ 1470, 235, 1500, 1501, 1505, 1392, 1005, 449, 1391, 1390, + /* 1250 */ 1273, 1470, 1455, 1449, 1437, 1516, 227, 1500, 1501, 1505, + /* 1260 */ 1428, 496, 446, 1321, 146, 1499, 1272, 236, 1500, 1501, + /* 1270 */ 1505, 1270, 449, 350, 352, 351, 1470, 863, 1499, 1268, + /* 1280 */ 493, 492, 491, 356, 490, 354, 1266, 355, 1264, 1516, + /* 1290 */ 1253, 359, 1513, 1500, 1501, 1505, 446, 358, 1252, 360, + /* 1300 */ 362, 363, 1516, 1249, 364, 1323, 449, 972, 73, 446, + /* 1310 */ 1470, 153, 1499, 512, 970, 1322, 895, 510, 894, 449, + /* 1320 */ 1499, 893, 892, 1470, 1262, 1499, 1512, 1500, 1501, 1505, + /* 1330 */ 252, 889, 888, 1257, 253, 387, 1516, 1255, 254, 243, + /* 1340 */ 1500, 1501, 1505, 446, 1516, 390, 1248, 392, 1247, 1516, + /* 1350 */ 394, 446, 71, 449, 1454, 167, 446, 1470, 1039, 1448, + /* 1360 */ 402, 449, 113, 1436, 1435, 1470, 449, 1499, 1427, 54, + /* 1370 */ 1470, 123, 1499, 1511, 1500, 1501, 1505, 172, 14, 43, + /* 1380 */ 3, 244, 1500, 1501, 1505, 33, 242, 1500, 1501, 1505, + /* 1390 */ 38, 1516, 177, 1181, 15, 403, 1516, 120, 446, 1488, + /* 1400 */ 174, 181, 37, 446, 19, 56, 1174, 182, 449, 55, + /* 1410 */ 20, 1203, 1470, 449, 36, 1153, 1152, 1470, 16, 1208, + /* 1420 */ 1202, 35, 261, 1207, 1206, 262, 8, 13, 239, 1500, + /* 1430 */ 1501, 1505, 1090, 230, 1500, 1501, 1505, 188, 130, 1117, + /* 1440 */ 1089, 195, 196, 18, 1426, 1179, 198, 454, 10, 200, + /* 1450 */ 45, 202, 57, 1068, 204, 61, 956, 39, 467, 275, + /* 1460 */ 1487, 471, 469, 207, 465, 953, 472, 474, 950, 475, + /* 1470 */ 477, 944, 478, 480, 942, 933, 481, 62, 967, 948, + /* 1480 */ 46, 63, 961, 963, 487, 861, 497, 902, 947, 499, + /* 1490 */ 946, 877, 884, 945, 883, 882, 210, 881, 899, 880, + /* 1500 */ 879, 878, 897, 874, 873, 872, 869, 1269, 868, 966, + /* 1510 */ 867, 866, 521, 522, 523, 1267, 525, 526, 527, 1265, + /* 1520 */ 529, 530, 531, 1263, 533, 534, 535, 1251, 537, 538, + /* 1530 */ 1250, 1246, 541, 542, 1221, 1055, 218, 545, 546, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 217, 277, 278, 219, 239, 261, 211, 1, 2, 226, - /* 10 */ 244, 4, 12, 13, 217, 239, 233, 251, 252, 227, - /* 20 */ 20, 256, 22, 226, 240, 242, 19, 235, 20, 256, - /* 30 */ 235, 211, 256, 268, 269, 243, 292, 242, 38, 242, - /* 40 */ 33, 268, 269, 36, 268, 269, 20, 252, 41, 305, - /* 50 */ 50, 256, 217, 309, 47, 235, 217, 57, 14, 15, - /* 60 */ 16, 49, 242, 12, 13, 14, 217, 272, 273, 274, - /* 70 */ 275, 20, 252, 22, 74, 226, 256, 12, 13, 259, - /* 80 */ 73, 75, 233, 76, 20, 20, 247, 22, 211, 38, - /* 90 */ 211, 242, 272, 273, 274, 275, 261, 97, 214, 215, - /* 100 */ 20, 50, 20, 38, 252, 310, 311, 255, 57, 109, - /* 110 */ 258, 217, 235, 221, 222, 50, 12, 13, 217, 242, - /* 120 */ 226, 210, 57, 212, 20, 74, 22, 292, 292, 252, - /* 130 */ 221, 222, 211, 256, 217, 256, 242, 132, 74, 74, - /* 140 */ 305, 305, 38, 242, 309, 309, 146, 0, 97, 272, - /* 150 */ 273, 274, 275, 276, 136, 150, 74, 280, 281, 242, - /* 160 */ 109, 57, 97, 163, 164, 165, 166, 167, 168, 169, - /* 170 */ 170, 171, 172, 173, 109, 217, 275, 256, 74, 174, - /* 180 */ 211, 12, 13, 14, 226, 185, 285, 286, 287, 20, - /* 190 */ 289, 22, 275, 185, 220, 185, 49, 146, 224, 235, - /* 200 */ 242, 97, 285, 286, 287, 241, 289, 38, 190, 191, - /* 210 */ 246, 146, 20, 109, 163, 164, 165, 166, 167, 168, - /* 220 */ 169, 170, 171, 172, 173, 256, 57, 0, 163, 164, - /* 230 */ 165, 166, 167, 168, 169, 170, 171, 172, 173, 145, - /* 240 */ 20, 147, 22, 74, 164, 165, 1, 2, 21, 185, - /* 250 */ 146, 24, 25, 26, 27, 28, 29, 30, 31, 32, - /* 260 */ 40, 12, 13, 14, 15, 16, 97, 163, 164, 165, - /* 270 */ 166, 167, 168, 169, 170, 171, 172, 173, 109, 185, - /* 280 */ 20, 242, 219, 12, 13, 18, 216, 20, 249, 185, - /* 290 */ 52, 20, 54, 22, 27, 232, 58, 30, 211, 61, - /* 300 */ 230, 63, 64, 240, 66, 228, 39, 237, 231, 38, - /* 310 */ 12, 13, 14, 15, 16, 146, 21, 183, 184, 24, - /* 320 */ 25, 26, 27, 28, 29, 30, 31, 32, 57, 0, - /* 330 */ 67, 163, 163, 164, 165, 166, 167, 168, 169, 170, - /* 340 */ 171, 172, 173, 256, 20, 74, 61, 50, 50, 47, - /* 350 */ 65, 38, 49, 24, 25, 26, 27, 28, 29, 30, - /* 360 */ 31, 32, 194, 195, 196, 197, 198, 223, 97, 225, - /* 370 */ 57, 20, 87, 75, 35, 73, 113, 114, 76, 112, - /* 380 */ 109, 83, 115, 116, 117, 118, 119, 217, 121, 122, - /* 390 */ 123, 124, 125, 126, 127, 128, 129, 130, 131, 217, - /* 400 */ 61, 12, 13, 85, 65, 270, 217, 252, 226, 20, - /* 410 */ 270, 22, 242, 258, 235, 226, 77, 146, 79, 80, - /* 420 */ 241, 82, 235, 288, 242, 246, 87, 38, 288, 242, - /* 430 */ 132, 242, 164, 165, 163, 164, 165, 166, 167, 168, - /* 440 */ 169, 170, 171, 172, 173, 275, 57, 0, 150, 12, - /* 450 */ 13, 14, 15, 16, 284, 285, 286, 287, 0, 289, - /* 460 */ 163, 274, 138, 74, 20, 12, 13, 14, 15, 16, - /* 470 */ 270, 216, 174, 175, 176, 177, 178, 179, 180, 181, - /* 480 */ 182, 12, 13, 14, 15, 16, 97, 50, 288, 138, - /* 490 */ 14, 78, 237, 234, 81, 4, 20, 211, 109, 52, - /* 500 */ 53, 54, 55, 56, 245, 58, 59, 60, 61, 62, - /* 510 */ 63, 64, 65, 66, 67, 68, 69, 70, 78, 61, - /* 520 */ 83, 81, 57, 65, 88, 89, 90, 91, 92, 93, - /* 530 */ 94, 95, 96, 97, 98, 146, 100, 101, 102, 103, - /* 540 */ 104, 105, 256, 211, 75, 87, 18, 236, 208, 0, - /* 550 */ 43, 23, 163, 164, 165, 166, 167, 168, 169, 170, - /* 560 */ 171, 172, 173, 35, 106, 107, 108, 2, 110, 132, - /* 570 */ 78, 3, 2, 81, 22, 211, 48, 12, 13, 14, - /* 580 */ 15, 16, 12, 13, 14, 15, 16, 150, 256, 235, - /* 590 */ 38, 236, 139, 33, 0, 236, 36, 243, 49, 217, - /* 600 */ 217, 261, 42, 261, 44, 45, 46, 47, 226, 226, - /* 610 */ 235, 174, 175, 176, 177, 178, 179, 180, 181, 182, - /* 620 */ 256, 246, 236, 236, 242, 242, 142, 227, 236, 217, - /* 630 */ 12, 13, 292, 73, 292, 235, 76, 211, 226, 111, - /* 640 */ 22, 157, 211, 243, 0, 305, 52, 305, 54, 309, - /* 650 */ 78, 309, 58, 81, 242, 61, 38, 63, 64, 206, - /* 660 */ 66, 12, 13, 14, 15, 16, 235, 139, 140, 141, - /* 670 */ 235, 143, 264, 242, 71, 57, 148, 186, 75, 0, - /* 680 */ 36, 246, 256, 252, 156, 211, 158, 256, 160, 161, - /* 690 */ 162, 184, 261, 133, 227, 135, 71, 137, 211, 211, - /* 700 */ 75, 22, 235, 272, 273, 274, 275, 276, 236, 235, - /* 710 */ 243, 280, 281, 185, 154, 97, 242, 12, 13, 14, - /* 720 */ 15, 16, 235, 292, 75, 21, 252, 109, 217, 242, - /* 730 */ 256, 211, 211, 224, 71, 71, 305, 226, 34, 252, - /* 740 */ 309, 211, 217, 256, 256, 211, 272, 273, 274, 275, - /* 750 */ 276, 226, 235, 242, 280, 281, 282, 0, 241, 272, - /* 760 */ 273, 274, 275, 246, 146, 235, 19, 242, 294, 201, - /* 770 */ 217, 212, 242, 211, 300, 301, 256, 256, 38, 22, - /* 780 */ 33, 163, 252, 36, 22, 0, 256, 211, 211, 42, - /* 790 */ 256, 44, 45, 46, 47, 242, 211, 71, 311, 211, - /* 800 */ 38, 75, 272, 273, 274, 275, 276, 22, 312, 71, - /* 810 */ 280, 281, 282, 75, 261, 211, 211, 303, 256, 57, - /* 820 */ 73, 211, 71, 76, 211, 71, 75, 38, 275, 75, - /* 830 */ 252, 301, 256, 256, 74, 245, 252, 74, 285, 286, - /* 840 */ 287, 256, 289, 138, 256, 292, 86, 84, 235, 109, - /* 850 */ 71, 211, 71, 106, 75, 242, 75, 214, 305, 97, - /* 860 */ 256, 256, 309, 297, 271, 252, 256, 203, 205, 256, - /* 870 */ 71, 109, 71, 71, 75, 235, 75, 75, 211, 71, - /* 880 */ 235, 134, 242, 75, 137, 272, 273, 274, 275, 276, - /* 890 */ 290, 293, 252, 280, 281, 282, 256, 306, 109, 152, - /* 900 */ 20, 154, 235, 71, 291, 38, 71, 75, 146, 242, - /* 910 */ 75, 217, 272, 273, 274, 275, 276, 36, 267, 252, - /* 920 */ 280, 281, 282, 256, 57, 163, 71, 38, 211, 221, - /* 930 */ 75, 291, 71, 71, 144, 262, 75, 75, 217, 272, - /* 940 */ 273, 274, 275, 276, 217, 120, 250, 280, 281, 282, - /* 950 */ 132, 248, 235, 211, 248, 20, 217, 266, 291, 242, - /* 960 */ 20, 260, 219, 20, 242, 253, 20, 219, 219, 252, - /* 970 */ 217, 219, 213, 256, 242, 266, 235, 235, 261, 235, - /* 980 */ 211, 235, 253, 153, 242, 235, 213, 217, 265, 272, - /* 990 */ 273, 274, 275, 235, 252, 221, 235, 260, 256, 235, - /* 1000 */ 235, 235, 235, 235, 235, 20, 211, 216, 216, 292, - /* 1010 */ 193, 242, 302, 242, 272, 273, 274, 275, 276, 192, - /* 1020 */ 57, 252, 305, 281, 200, 256, 309, 271, 298, 257, - /* 1030 */ 235, 256, 211, 302, 257, 299, 256, 242, 256, 199, - /* 1040 */ 211, 272, 273, 274, 275, 276, 188, 252, 184, 280, - /* 1050 */ 281, 256, 187, 242, 259, 20, 235, 270, 120, 207, - /* 1060 */ 204, 283, 202, 242, 235, 74, 257, 272, 273, 274, - /* 1070 */ 275, 242, 296, 252, 211, 279, 256, 256, 295, 256, - /* 1080 */ 135, 252, 216, 257, 256, 256, 242, 211, 259, 216, - /* 1090 */ 254, 253, 242, 272, 273, 274, 275, 313, 235, 211, - /* 1100 */ 307, 272, 273, 274, 275, 242, 308, 238, 231, 225, - /* 1110 */ 74, 235, 221, 217, 216, 252, 213, 263, 242, 256, - /* 1120 */ 218, 229, 259, 235, 229, 304, 209, 0, 252, 0, - /* 1130 */ 242, 64, 256, 211, 0, 272, 273, 274, 275, 38, - /* 1140 */ 252, 159, 38, 38, 256, 38, 159, 0, 272, 273, - /* 1150 */ 274, 275, 38, 38, 159, 0, 38, 235, 0, 211, - /* 1160 */ 272, 273, 274, 275, 242, 0, 38, 74, 150, 149, - /* 1170 */ 109, 146, 0, 0, 252, 53, 142, 0, 256, 120, - /* 1180 */ 86, 0, 0, 235, 0, 211, 0, 0, 0, 0, - /* 1190 */ 242, 0, 0, 0, 272, 273, 274, 275, 0, 0, - /* 1200 */ 252, 0, 0, 0, 256, 22, 0, 0, 0, 235, - /* 1210 */ 211, 0, 0, 0, 0, 0, 242, 0, 0, 0, - /* 1220 */ 272, 273, 274, 275, 0, 0, 252, 0, 0, 0, - /* 1230 */ 256, 0, 0, 43, 235, 211, 51, 0, 0, 43, - /* 1240 */ 0, 242, 38, 43, 211, 36, 272, 273, 274, 275, - /* 1250 */ 0, 252, 0, 43, 38, 256, 36, 36, 0, 235, - /* 1260 */ 38, 38, 36, 0, 0, 0, 242, 22, 235, 0, - /* 1270 */ 0, 272, 273, 274, 275, 242, 252, 43, 83, 211, - /* 1280 */ 256, 38, 38, 22, 38, 252, 38, 38, 0, 256, - /* 1290 */ 22, 38, 38, 0, 39, 22, 272, 273, 274, 275, - /* 1300 */ 38, 0, 22, 235, 71, 272, 273, 274, 275, 0, - /* 1310 */ 242, 81, 71, 211, 22, 20, 0, 155, 138, 38, - /* 1320 */ 252, 0, 151, 0, 256, 22, 0, 0, 43, 189, - /* 1330 */ 74, 71, 138, 86, 75, 138, 183, 235, 71, 189, - /* 1340 */ 272, 273, 274, 275, 242, 71, 75, 211, 189, 74, - /* 1350 */ 74, 74, 86, 75, 252, 71, 211, 74, 256, 4, - /* 1360 */ 71, 75, 211, 38, 2, 75, 75, 71, 86, 133, - /* 1370 */ 135, 235, 38, 71, 272, 273, 274, 275, 242, 38, - /* 1380 */ 235, 0, 38, 38, 38, 86, 235, 242, 252, 75, - /* 1390 */ 211, 74, 256, 242, 75, 75, 74, 252, 0, 75, - /* 1400 */ 43, 256, 163, 252, 74, 74, 74, 256, 272, 273, - /* 1410 */ 274, 275, 74, 84, 235, 136, 211, 272, 273, 274, - /* 1420 */ 275, 242, 86, 272, 273, 274, 275, 133, 86, 22, - /* 1430 */ 74, 252, 85, 75, 38, 256, 75, 38, 74, 38, - /* 1440 */ 235, 74, 61, 75, 38, 74, 65, 242, 75, 38, - /* 1450 */ 74, 272, 273, 274, 275, 75, 38, 252, 74, 99, - /* 1460 */ 22, 256, 99, 74, 99, 99, 87, 38, 87, 74, - /* 1470 */ 38, 74, 22, 51, 50, 72, 57, 272, 273, 274, - /* 1480 */ 275, 109, 38, 71, 38, 38, 38, 106, 107, 108, - /* 1490 */ 38, 110, 38, 38, 22, 38, 57, 38, 38, 38, - /* 1500 */ 38, 38, 38, 38, 0, 38, 36, 0, 0, 43, - /* 1510 */ 36, 38, 43, 38, 36, 0, 36, 38, 0, 43, - /* 1520 */ 43, 38, 37, 0, 0, 22, 21, 314, 22, 314, - /* 1530 */ 20, 22, 21, 314, 314, 314, 314, 314, 314, 314, - /* 1540 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1550 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1560 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1570 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1580 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1590 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1600 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1610 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1620 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1630 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1640 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1650 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1660 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1670 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1680 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1690 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1700 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1710 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1720 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1730 */ 314, 314, 314, 314, 314, 314, 314, 314, 314, 314, - /* 1740 */ 314, + /* 0 */ 253, 240, 257, 256, 278, 279, 259, 211, 235, 213, + /* 10 */ 218, 237, 12, 13, 269, 270, 262, 212, 257, 246, + /* 20 */ 20, 20, 22, 2, 20, 12, 13, 14, 15, 16, + /* 30 */ 269, 270, 2, 12, 13, 14, 15, 16, 38, 240, + /* 40 */ 248, 236, 12, 13, 14, 15, 16, 293, 243, 20, + /* 50 */ 50, 12, 13, 14, 49, 218, 257, 57, 253, 20, + /* 60 */ 306, 22, 257, 0, 310, 12, 13, 262, 269, 270, + /* 70 */ 218, 1, 2, 20, 74, 22, 218, 38, 273, 274, + /* 80 */ 275, 276, 277, 215, 216, 227, 281, 282, 75, 50, + /* 90 */ 212, 38, 234, 20, 253, 243, 57, 97, 293, 262, + /* 100 */ 259, 243, 0, 50, 12, 13, 14, 15, 16, 109, + /* 110 */ 57, 306, 49, 74, 236, 310, 12, 13, 14, 15, + /* 120 */ 16, 243, 221, 236, 22, 245, 225, 74, 276, 242, + /* 130 */ 293, 253, 252, 253, 247, 257, 97, 285, 286, 287, + /* 140 */ 288, 228, 290, 306, 49, 75, 146, 310, 109, 236, + /* 150 */ 97, 273, 274, 275, 276, 277, 20, 244, 22, 281, + /* 160 */ 282, 283, 109, 163, 164, 165, 166, 167, 168, 169, + /* 170 */ 170, 171, 172, 173, 174, 61, 40, 222, 223, 65, + /* 180 */ 302, 20, 271, 209, 21, 146, 186, 24, 25, 26, + /* 190 */ 27, 28, 29, 30, 31, 32, 14, 15, 16, 146, + /* 200 */ 289, 87, 163, 164, 165, 166, 167, 168, 169, 170, + /* 210 */ 171, 172, 173, 174, 0, 186, 163, 164, 165, 166, + /* 220 */ 167, 168, 169, 170, 171, 172, 173, 174, 0, 12, + /* 230 */ 13, 19, 145, 271, 147, 74, 262, 20, 52, 22, + /* 240 */ 54, 38, 186, 139, 58, 33, 20, 61, 36, 63, + /* 250 */ 64, 289, 66, 236, 42, 38, 44, 45, 46, 47, + /* 260 */ 57, 244, 12, 13, 14, 15, 16, 293, 12, 13, + /* 270 */ 14, 212, 218, 186, 57, 61, 20, 49, 22, 65, + /* 280 */ 306, 227, 12, 13, 310, 73, 220, 20, 76, 20, + /* 290 */ 20, 74, 22, 212, 38, 236, 217, 243, 236, 233, + /* 300 */ 74, 87, 243, 212, 67, 243, 218, 241, 38, 85, + /* 310 */ 231, 207, 253, 57, 97, 227, 257, 238, 106, 71, + /* 320 */ 106, 107, 108, 163, 110, 75, 109, 57, 222, 223, + /* 330 */ 74, 243, 273, 274, 275, 276, 277, 275, 257, 21, + /* 340 */ 281, 282, 283, 0, 74, 0, 134, 186, 257, 137, + /* 350 */ 113, 114, 34, 97, 295, 195, 196, 197, 198, 199, + /* 360 */ 301, 302, 57, 146, 152, 109, 154, 97, 212, 24, + /* 370 */ 25, 26, 27, 28, 29, 30, 31, 32, 237, 109, + /* 380 */ 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, + /* 390 */ 173, 174, 20, 218, 236, 52, 220, 54, 293, 237, + /* 400 */ 242, 58, 146, 186, 61, 247, 63, 64, 212, 66, + /* 410 */ 212, 306, 265, 257, 212, 310, 146, 241, 243, 163, + /* 420 */ 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, + /* 430 */ 174, 164, 165, 163, 164, 165, 166, 167, 168, 169, + /* 440 */ 170, 171, 172, 173, 174, 218, 12, 13, 18, 136, + /* 450 */ 20, 276, 204, 257, 20, 257, 22, 27, 217, 257, + /* 460 */ 30, 286, 287, 288, 243, 290, 20, 4, 262, 39, + /* 470 */ 243, 250, 38, 12, 13, 14, 15, 16, 3, 238, + /* 480 */ 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, + /* 490 */ 98, 57, 100, 101, 102, 103, 104, 105, 0, 293, + /* 500 */ 184, 185, 271, 276, 191, 192, 1, 2, 74, 218, + /* 510 */ 138, 50, 306, 286, 287, 288, 310, 290, 227, 21, + /* 520 */ 289, 212, 24, 25, 26, 27, 28, 29, 30, 31, + /* 530 */ 32, 97, 229, 237, 243, 232, 75, 12, 13, 14, + /* 540 */ 15, 16, 112, 109, 83, 115, 116, 117, 118, 119, + /* 550 */ 212, 121, 122, 123, 124, 125, 126, 127, 128, 129, + /* 560 */ 130, 131, 0, 47, 18, 218, 257, 212, 224, 23, + /* 570 */ 226, 236, 236, 43, 227, 12, 13, 14, 15, 16, + /* 580 */ 146, 35, 247, 247, 138, 14, 237, 237, 212, 73, + /* 590 */ 243, 20, 76, 132, 48, 257, 237, 163, 164, 165, + /* 600 */ 166, 167, 168, 169, 170, 171, 172, 173, 174, 213, + /* 610 */ 212, 150, 257, 50, 52, 53, 54, 55, 56, 212, + /* 620 */ 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, + /* 630 */ 68, 69, 70, 257, 212, 212, 175, 176, 177, 178, + /* 640 */ 179, 180, 181, 182, 183, 218, 83, 218, 212, 218, + /* 650 */ 187, 22, 228, 218, 227, 257, 227, 111, 227, 236, + /* 660 */ 236, 234, 227, 138, 257, 228, 243, 38, 244, 0, + /* 670 */ 243, 38, 243, 236, 243, 218, 253, 202, 243, 257, + /* 680 */ 257, 244, 212, 212, 227, 139, 140, 141, 212, 143, + /* 690 */ 57, 22, 218, 257, 148, 132, 273, 274, 275, 276, + /* 700 */ 243, 227, 156, 142, 158, 236, 160, 161, 162, 225, + /* 710 */ 71, 242, 236, 150, 75, 185, 247, 243, 157, 243, + /* 720 */ 78, 22, 218, 81, 212, 212, 212, 257, 257, 253, + /* 730 */ 50, 227, 186, 257, 311, 312, 132, 38, 175, 176, + /* 740 */ 177, 178, 179, 180, 181, 182, 183, 243, 236, 273, + /* 750 */ 274, 275, 276, 277, 150, 243, 57, 281, 282, 283, + /* 760 */ 212, 0, 212, 33, 212, 253, 36, 313, 292, 257, + /* 770 */ 257, 257, 42, 253, 44, 45, 46, 47, 78, 175, + /* 780 */ 78, 81, 304, 81, 236, 273, 274, 275, 276, 277, + /* 790 */ 0, 243, 71, 281, 282, 283, 97, 36, 164, 165, + /* 800 */ 246, 253, 35, 73, 292, 257, 76, 257, 109, 257, + /* 810 */ 212, 78, 22, 71, 81, 71, 71, 75, 253, 75, + /* 820 */ 75, 273, 274, 275, 276, 277, 74, 298, 61, 281, + /* 830 */ 282, 283, 65, 215, 236, 71, 272, 212, 86, 75, + /* 840 */ 292, 243, 291, 163, 77, 146, 79, 80, 38, 82, + /* 850 */ 236, 253, 212, 71, 87, 257, 307, 75, 20, 38, + /* 860 */ 262, 236, 163, 133, 294, 135, 71, 137, 243, 218, + /* 870 */ 75, 273, 274, 275, 276, 36, 236, 71, 253, 212, + /* 880 */ 268, 75, 257, 243, 154, 71, 12, 13, 71, 75, + /* 890 */ 38, 293, 75, 253, 222, 144, 22, 257, 273, 274, + /* 900 */ 275, 276, 277, 236, 306, 218, 281, 282, 310, 263, + /* 910 */ 243, 218, 38, 273, 274, 275, 276, 277, 74, 109, + /* 920 */ 253, 281, 282, 218, 257, 71, 251, 206, 84, 75, + /* 930 */ 109, 57, 71, 71, 71, 120, 75, 75, 75, 132, + /* 940 */ 273, 274, 275, 276, 277, 249, 71, 249, 243, 282, + /* 950 */ 75, 20, 218, 71, 71, 212, 267, 75, 75, 20, + /* 960 */ 220, 243, 261, 20, 254, 218, 220, 262, 220, 220, + /* 970 */ 20, 97, 214, 236, 236, 236, 222, 236, 218, 236, + /* 980 */ 267, 276, 212, 109, 153, 266, 243, 214, 261, 236, + /* 990 */ 212, 286, 287, 288, 217, 290, 253, 217, 293, 236, + /* 1000 */ 257, 236, 236, 260, 236, 236, 236, 236, 20, 254, + /* 1010 */ 194, 306, 303, 243, 236, 310, 273, 274, 275, 276, + /* 1020 */ 146, 243, 243, 253, 243, 193, 57, 257, 272, 257, + /* 1030 */ 260, 253, 258, 258, 212, 257, 201, 163, 303, 189, + /* 1040 */ 257, 257, 200, 273, 274, 275, 276, 188, 243, 20, + /* 1050 */ 300, 273, 274, 275, 276, 296, 299, 185, 236, 297, + /* 1060 */ 271, 120, 205, 208, 74, 243, 258, 280, 212, 284, + /* 1070 */ 203, 258, 135, 255, 74, 253, 212, 257, 254, 257, + /* 1080 */ 257, 212, 257, 305, 243, 217, 243, 239, 217, 210, + /* 1090 */ 314, 226, 236, 217, 308, 273, 274, 275, 276, 243, + /* 1100 */ 236, 309, 232, 222, 218, 236, 214, 243, 230, 253, + /* 1110 */ 264, 0, 243, 257, 230, 219, 260, 253, 0, 64, + /* 1120 */ 0, 257, 253, 212, 260, 38, 257, 38, 212, 273, + /* 1130 */ 274, 275, 276, 4, 312, 159, 212, 273, 274, 275, + /* 1140 */ 276, 38, 273, 274, 275, 276, 159, 236, 19, 0, + /* 1150 */ 38, 159, 236, 38, 243, 38, 0, 38, 0, 243, + /* 1160 */ 236, 38, 33, 0, 253, 36, 74, 243, 257, 253, + /* 1170 */ 41, 150, 149, 257, 0, 0, 47, 253, 109, 146, + /* 1180 */ 212, 257, 0, 53, 273, 274, 275, 276, 142, 273, + /* 1190 */ 274, 275, 276, 0, 0, 212, 86, 273, 274, 275, + /* 1200 */ 276, 0, 73, 0, 236, 76, 212, 0, 0, 0, + /* 1210 */ 0, 243, 0, 0, 0, 0, 0, 0, 0, 236, + /* 1220 */ 0, 253, 0, 0, 120, 257, 243, 0, 0, 0, + /* 1230 */ 236, 212, 0, 0, 0, 61, 253, 243, 0, 65, + /* 1240 */ 257, 273, 274, 275, 276, 0, 22, 253, 0, 0, + /* 1250 */ 0, 257, 0, 0, 0, 236, 273, 274, 275, 276, + /* 1260 */ 0, 87, 243, 0, 43, 212, 0, 273, 274, 275, + /* 1270 */ 276, 0, 253, 38, 43, 36, 257, 51, 212, 0, + /* 1280 */ 106, 107, 108, 43, 110, 38, 0, 36, 0, 236, + /* 1290 */ 0, 36, 273, 274, 275, 276, 243, 38, 0, 43, + /* 1300 */ 38, 36, 236, 0, 43, 0, 253, 38, 83, 243, + /* 1310 */ 257, 81, 212, 71, 22, 0, 38, 71, 38, 253, + /* 1320 */ 212, 38, 38, 257, 0, 212, 273, 274, 275, 276, + /* 1330 */ 22, 38, 38, 0, 22, 39, 236, 0, 22, 273, + /* 1340 */ 274, 275, 276, 243, 236, 38, 0, 22, 0, 236, + /* 1350 */ 22, 243, 20, 253, 0, 155, 243, 257, 38, 0, + /* 1360 */ 22, 253, 151, 0, 0, 257, 253, 212, 0, 74, + /* 1370 */ 257, 135, 212, 273, 274, 275, 276, 43, 190, 138, + /* 1380 */ 71, 273, 274, 275, 276, 71, 273, 274, 275, 276, + /* 1390 */ 71, 236, 75, 75, 190, 138, 236, 74, 243, 86, + /* 1400 */ 133, 74, 138, 243, 74, 4, 75, 71, 253, 74, + /* 1410 */ 71, 38, 257, 253, 71, 75, 75, 257, 71, 75, + /* 1420 */ 38, 184, 38, 38, 38, 38, 2, 74, 273, 274, + /* 1430 */ 275, 276, 75, 273, 274, 275, 276, 86, 86, 163, + /* 1440 */ 75, 86, 75, 74, 0, 75, 74, 136, 190, 74, + /* 1450 */ 74, 43, 74, 22, 133, 84, 75, 74, 38, 38, + /* 1460 */ 86, 38, 74, 86, 85, 75, 74, 38, 75, 74, + /* 1470 */ 38, 75, 74, 38, 75, 22, 74, 74, 38, 99, + /* 1480 */ 74, 74, 22, 38, 87, 51, 50, 57, 99, 72, + /* 1490 */ 99, 22, 38, 99, 38, 38, 71, 38, 57, 38, + /* 1500 */ 38, 38, 38, 38, 38, 38, 38, 0, 38, 109, + /* 1510 */ 38, 38, 38, 36, 43, 0, 38, 36, 43, 0, + /* 1520 */ 38, 36, 43, 0, 38, 36, 43, 0, 38, 37, + /* 1530 */ 0, 0, 22, 21, 315, 22, 22, 21, 20, 315, + /* 1540 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1550 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1560 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1570 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1580 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1590 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1600 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1610 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1620 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1630 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1640 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1650 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1660 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1670 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1680 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1690 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1700 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1710 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1720 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1730 */ 315, 315, 315, 315, 315, 315, 315, 315, 315, 315, + /* 1740 */ 315, 315, 315, 315, 315, 315, 315, 315, }; #define YY_SHIFT_COUNT (547) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1524) +#define YY_SHIFT_MAX (1531) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 528, 0, 51, 65, 65, 65, 65, 104, 65, 65, - /* 10 */ 271, 389, 64, 169, 271, 271, 271, 271, 271, 271, - /* 20 */ 271, 271, 271, 271, 271, 271, 271, 271, 271, 271, - /* 30 */ 271, 271, 271, 271, 82, 82, 82, 8, 618, 618, - /* 40 */ 94, 26, 26, 10, 618, 80, 80, 26, 26, 26, - /* 50 */ 26, 26, 26, 12, 192, 260, 10, 192, 26, 26, - /* 60 */ 192, 26, 192, 192, 192, 26, 303, 267, 298, 437, - /* 70 */ 437, 295, 339, 762, 238, 762, 762, 762, 762, 762, - /* 80 */ 762, 762, 762, 762, 762, 762, 762, 762, 762, 762, - /* 90 */ 762, 762, 762, 762, 80, 220, 147, 313, 324, 324, - /* 100 */ 324, 549, 313, 444, 192, 192, 192, 318, 465, 436, - /* 110 */ 436, 436, 436, 436, 436, 436, 747, 227, 594, 453, - /* 120 */ 168, 80, 285, 80, 18, 552, 351, 134, 507, 134, - /* 130 */ 476, 568, 491, 880, 881, 889, 790, 880, 880, 825, - /* 140 */ 818, 818, 880, 935, 940, 12, 444, 943, 12, 12, - /* 150 */ 880, 12, 946, 192, 192, 192, 192, 192, 192, 192, - /* 160 */ 192, 192, 192, 192, 889, 880, 946, 444, 935, 830, - /* 170 */ 940, 303, 444, 943, 303, 985, 817, 827, 963, 817, - /* 180 */ 827, 963, 963, 824, 840, 858, 865, 864, 444, 1035, - /* 190 */ 938, 852, 856, 860, 991, 192, 827, 963, 963, 827, - /* 200 */ 963, 945, 444, 943, 303, 318, 303, 444, 1036, 889, - /* 210 */ 465, 880, 303, 946, 1533, 1533, 1533, 1533, 1533, 447, - /* 220 */ 560, 329, 7, 458, 1381, 469, 565, 570, 649, 705, - /* 230 */ 249, 249, 249, 249, 249, 249, 249, 302, 263, 44, - /* 240 */ 6, 5, 44, 44, 44, 644, 484, 603, 413, 440, - /* 250 */ 492, 572, 679, 757, 785, 704, 625, 726, 738, 245, - /* 260 */ 268, 664, 663, 751, 297, 754, 760, 781, 799, 801, - /* 270 */ 802, 808, 740, 789, 779, 832, 835, 855, 861, 862, - /* 280 */ 763, 867, 1127, 1129, 1067, 1134, 1101, 982, 1104, 1105, - /* 290 */ 1107, 987, 1147, 1114, 1115, 995, 1155, 1118, 1158, 1128, - /* 300 */ 1165, 1093, 1018, 1020, 1061, 1025, 1172, 1173, 1122, 1034, - /* 310 */ 1177, 1184, 1094, 1181, 1182, 1186, 1187, 1188, 1189, 1191, - /* 320 */ 1192, 1193, 1198, 1199, 1201, 1202, 1203, 1211, 1212, 1059, - /* 330 */ 1213, 1214, 1215, 1217, 1218, 1219, 1183, 1206, 1207, 1208, - /* 340 */ 1224, 1225, 1227, 1228, 1229, 1231, 1190, 1232, 1185, 1237, - /* 350 */ 1238, 1204, 1209, 1196, 1240, 1216, 1220, 1200, 1250, 1222, - /* 360 */ 1221, 1210, 1252, 1223, 1226, 1234, 1258, 1263, 1264, 1265, - /* 370 */ 1195, 1230, 1243, 1233, 1245, 1269, 1244, 1246, 1248, 1249, - /* 380 */ 1241, 1233, 1253, 1254, 1270, 1261, 1288, 1268, 1255, 1293, - /* 390 */ 1273, 1262, 1301, 1280, 1309, 1292, 1295, 1316, 1180, 1162, - /* 400 */ 1281, 1321, 1171, 1303, 1194, 1235, 1323, 1326, 1197, 1327, - /* 410 */ 1256, 1285, 1236, 1260, 1267, 1140, 1259, 1274, 1271, 1275, - /* 420 */ 1276, 1277, 1278, 1284, 1247, 1283, 1289, 1150, 1286, 1290, - /* 430 */ 1266, 1153, 1296, 1282, 1291, 1302, 1159, 1355, 1325, 1334, - /* 440 */ 1341, 1344, 1345, 1346, 1362, 1239, 1299, 1314, 1319, 1317, - /* 450 */ 1322, 1320, 1324, 1330, 1331, 1279, 1332, 1398, 1357, 1294, - /* 460 */ 1338, 1329, 1336, 1342, 1407, 1356, 1347, 1358, 1396, 1399, - /* 470 */ 1364, 1361, 1401, 1367, 1368, 1406, 1371, 1373, 1411, 1376, - /* 480 */ 1380, 1418, 1384, 1360, 1363, 1365, 1366, 1438, 1379, 1389, - /* 490 */ 1429, 1372, 1395, 1397, 1432, 1233, 1450, 1422, 1424, 1419, - /* 500 */ 1403, 1412, 1444, 1446, 1447, 1448, 1452, 1454, 1455, 1472, - /* 510 */ 1439, 1241, 1457, 1233, 1459, 1460, 1461, 1462, 1463, 1464, - /* 520 */ 1465, 1504, 1467, 1470, 1466, 1507, 1473, 1474, 1469, 1508, - /* 530 */ 1475, 1478, 1476, 1515, 1479, 1480, 1477, 1518, 1483, 1485, - /* 540 */ 1523, 1524, 1503, 1505, 1506, 1509, 1511, 1510, + /* 0 */ 546, 0, 39, 53, 53, 53, 53, 217, 53, 53, + /* 10 */ 270, 434, 161, 256, 270, 270, 270, 270, 270, 270, + /* 20 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, + /* 30 */ 270, 270, 270, 270, 226, 226, 226, 29, 874, 874, + /* 40 */ 87, 1, 1, 56, 874, 267, 267, 1, 1, 1, + /* 50 */ 1, 1, 1, 5, 4, 73, 56, 4, 1, 1, + /* 60 */ 4, 1, 4, 4, 4, 1, 95, 430, 461, 563, + /* 70 */ 563, 163, 767, 699, 186, 699, 699, 699, 699, 699, + /* 80 */ 699, 699, 699, 699, 699, 699, 699, 699, 699, 699, + /* 90 */ 699, 699, 699, 699, 267, 136, 63, 203, 372, 372, + /* 100 */ 372, 228, 203, 269, 4, 4, 4, 224, 305, 392, + /* 110 */ 392, 392, 392, 392, 392, 392, 212, 498, 343, 104, + /* 120 */ 160, 267, 114, 267, 313, 629, 446, 316, 530, 316, + /* 130 */ 571, 475, 463, 838, 839, 852, 751, 838, 838, 815, + /* 140 */ 807, 807, 838, 931, 939, 5, 269, 943, 5, 5, + /* 150 */ 838, 5, 950, 4, 4, 4, 4, 4, 4, 4, + /* 160 */ 4, 4, 4, 4, 852, 838, 950, 269, 931, 831, + /* 170 */ 939, 95, 269, 943, 95, 988, 816, 832, 969, 816, + /* 180 */ 832, 969, 969, 835, 842, 850, 859, 872, 269, 1029, + /* 190 */ 941, 855, 857, 867, 990, 4, 832, 969, 969, 832, + /* 200 */ 969, 937, 269, 943, 95, 224, 95, 269, 1000, 852, + /* 210 */ 305, 838, 95, 950, 1539, 1539, 1539, 1539, 1539, 562, + /* 220 */ 730, 345, 1129, 214, 1174, 13, 21, 30, 250, 525, + /* 230 */ 92, 92, 92, 92, 92, 92, 92, 516, 237, 182, + /* 240 */ 70, 604, 182, 182, 182, 761, 561, 639, 642, 700, + /* 250 */ 702, 733, 102, 669, 790, 318, 742, 744, 745, 505, + /* 260 */ 634, 248, 721, 764, 680, 782, 752, 795, 806, 814, + /* 270 */ 817, 854, 810, 821, 861, 862, 863, 875, 882, 883, + /* 280 */ 844, 633, 1111, 1118, 1055, 1120, 1087, 976, 1089, 1103, + /* 290 */ 1112, 987, 1149, 1115, 1117, 992, 1156, 1119, 1158, 1123, + /* 300 */ 1163, 1092, 1021, 1023, 1069, 1033, 1175, 1182, 1130, 1046, + /* 310 */ 1193, 1194, 1110, 1201, 1203, 1207, 1208, 1209, 1210, 1212, + /* 320 */ 1213, 1214, 1215, 1216, 1217, 1218, 1220, 1222, 1223, 1104, + /* 330 */ 1227, 1228, 1229, 1232, 1233, 1234, 1224, 1238, 1245, 1248, + /* 340 */ 1249, 1250, 1252, 1253, 1254, 1260, 1221, 1263, 1226, 1266, + /* 350 */ 1271, 1235, 1239, 1231, 1279, 1247, 1251, 1240, 1286, 1259, + /* 360 */ 1255, 1256, 1288, 1262, 1265, 1261, 1290, 1298, 1303, 1305, + /* 370 */ 1225, 1230, 1269, 1242, 1292, 1315, 1278, 1280, 1283, 1284, + /* 380 */ 1246, 1242, 1293, 1294, 1324, 1308, 1333, 1312, 1296, 1337, + /* 390 */ 1316, 1307, 1346, 1325, 1348, 1328, 1332, 1354, 1241, 1200, + /* 400 */ 1320, 1359, 1211, 1338, 1257, 1236, 1363, 1364, 1264, 1368, + /* 410 */ 1295, 1334, 1267, 1309, 1314, 1188, 1317, 1319, 1318, 1323, + /* 420 */ 1327, 1330, 1331, 1336, 1313, 1335, 1339, 1204, 1340, 1341, + /* 430 */ 1351, 1237, 1343, 1352, 1344, 1347, 1258, 1401, 1373, 1382, + /* 440 */ 1384, 1385, 1386, 1387, 1424, 1276, 1355, 1357, 1365, 1353, + /* 450 */ 1369, 1367, 1370, 1372, 1375, 1311, 1376, 1444, 1408, 1321, + /* 460 */ 1378, 1371, 1374, 1377, 1431, 1383, 1379, 1381, 1420, 1421, + /* 470 */ 1388, 1390, 1423, 1392, 1393, 1429, 1395, 1396, 1432, 1398, + /* 480 */ 1399, 1435, 1402, 1380, 1389, 1391, 1394, 1453, 1397, 1403, + /* 490 */ 1440, 1400, 1406, 1407, 1445, 1242, 1460, 1434, 1436, 1430, + /* 500 */ 1417, 1425, 1454, 1456, 1457, 1459, 1461, 1462, 1463, 1469, + /* 510 */ 1441, 1246, 1464, 1242, 1465, 1466, 1467, 1468, 1470, 1472, + /* 520 */ 1473, 1507, 1474, 1477, 1471, 1515, 1478, 1481, 1475, 1519, + /* 530 */ 1482, 1485, 1479, 1523, 1486, 1489, 1483, 1527, 1490, 1492, + /* 540 */ 1530, 1531, 1510, 1512, 1513, 1514, 1516, 1518, }; #define YY_REDUCE_COUNT (218) -#define YY_REDUCE_MIN (-276) -#define YY_REDUCE_MAX (1205) +#define YY_REDUCE_MIN (-274) +#define YY_REDUCE_MAX (1160) static const short yy_reduce_ofst[] = { - /* 0 */ 340, 431, 474, 530, 613, 640, 667, 717, -123, 769, - /* 10 */ -205, 742, 553, -180, 795, 821, 487, 829, 863, 876, - /* 20 */ 888, 922, 948, 974, 999, 1024, 1033, 1068, 1102, 1136, - /* 30 */ 1145, 1151, 1179, 1205, 170, -99, -83, -165, -235, -224, - /* 40 */ -256, -217, -151, 342, -227, -148, -234, -203, -106, -42, - /* 50 */ 182, 189, 382, 63, -36, 187, -164, -208, 383, 412, - /* 60 */ 179, 511, 400, 517, 467, 525, 70, -161, -276, -276, - /* 70 */ -276, -89, 259, -121, -26, -79, -31, 87, 286, 332, - /* 80 */ 364, 426, 488, 520, 521, 534, 562, 576, 577, 585, - /* 90 */ 588, 604, 605, 610, 155, -116, -216, -108, 135, 140, - /* 100 */ 200, 255, -91, 39, 354, 375, 435, 77, 144, 311, - /* 110 */ 355, 359, 386, 387, 392, 472, 408, 559, 509, 496, - /* 120 */ 514, 578, 590, 584, 566, 643, 593, 600, 600, 600, - /* 130 */ 645, 591, 598, 694, 651, 708, 673, 721, 727, 696, - /* 140 */ 703, 706, 739, 691, 701, 743, 722, 712, 748, 749, - /* 150 */ 753, 752, 759, 741, 744, 746, 750, 758, 761, 764, - /* 160 */ 765, 766, 767, 768, 774, 770, 773, 732, 709, 723, - /* 170 */ 737, 791, 771, 729, 792, 756, 710, 772, 775, 731, - /* 180 */ 777, 780, 782, 736, 730, 776, 783, 600, 811, 787, - /* 190 */ 778, 784, 798, 793, 796, 645, 809, 820, 823, 826, - /* 200 */ 828, 836, 844, 838, 866, 877, 873, 850, 869, 891, - /* 210 */ 884, 896, 898, 903, 854, 892, 895, 902, 917, + /* 0 */ -26, -195, 59, -122, 476, 512, 548, 598, 625, 640, + /* 10 */ 423, 667, 705, 743, 770, 778, 822, 856, 864, 869, + /* 20 */ 911, 916, 924, 968, 983, 994, 1019, 1053, 1066, 1100, + /* 30 */ 1108, 1113, 1155, 1160, -148, 175, 227, -163, -239, -201, + /* 40 */ -246, -142, 427, 206, -255, -253, -120, 54, 88, 291, + /* 50 */ 347, 429, 431, 66, -113, 62, 105, -87, 435, 457, + /* 60 */ 158, 474, 424, 469, 437, 504, 79, -208, -274, -274, + /* 70 */ -274, -204, -227, 81, -99, 91, 156, 196, 198, 202, + /* 80 */ 309, 338, 355, 376, 398, 407, 422, 436, 470, 471, + /* 90 */ 513, 514, 550, 552, -159, -132, 176, -45, -89, -38, + /* 100 */ 231, 241, 106, 221, 17, 335, 336, 303, 344, -226, + /* 110 */ 141, 162, 296, 349, 350, 359, 147, 396, 484, 454, + /* 120 */ 478, 520, 554, 565, 529, 618, 564, 551, 551, 551, + /* 130 */ 614, 549, 570, 651, 612, 672, 646, 687, 693, 675, + /* 140 */ 696, 698, 734, 689, 701, 740, 718, 710, 746, 748, + /* 150 */ 747, 749, 758, 737, 738, 739, 741, 753, 763, 765, + /* 160 */ 766, 768, 769, 771, 754, 760, 773, 779, 713, 719, + /* 170 */ 727, 777, 781, 755, 780, 756, 709, 774, 772, 735, + /* 180 */ 775, 783, 784, 750, 757, 762, 759, 551, 805, 789, + /* 190 */ 785, 776, 792, 786, 787, 614, 808, 820, 823, 813, + /* 200 */ 825, 818, 841, 824, 868, 870, 871, 843, 848, 881, + /* 210 */ 865, 886, 876, 892, 846, 878, 884, 896, 879, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 10 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 20 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 30 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 40 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 50 */ 1217, 1217, 1217, 1276, 1217, 1217, 1217, 1217, 1217, 1217, - /* 60 */ 1217, 1217, 1217, 1217, 1217, 1217, 1274, 1414, 1217, 1549, - /* 70 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 80 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 90 */ 1217, 1217, 1217, 1217, 1217, 1217, 1276, 1217, 1560, 1560, - /* 100 */ 1560, 1274, 1217, 1217, 1217, 1217, 1217, 1369, 1217, 1217, - /* 110 */ 1217, 1217, 1217, 1217, 1217, 1217, 1448, 1217, 1217, 1624, - /* 120 */ 1217, 1217, 1322, 1217, 1584, 1217, 1576, 1552, 1566, 1553, - /* 130 */ 1217, 1609, 1569, 1217, 1217, 1217, 1440, 1217, 1217, 1419, - /* 140 */ 1416, 1416, 1217, 1217, 1217, 1276, 1217, 1217, 1276, 1276, - /* 150 */ 1217, 1276, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 160 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1450, - /* 170 */ 1217, 1274, 1217, 1217, 1274, 1217, 1591, 1589, 1217, 1591, - /* 180 */ 1589, 1217, 1217, 1603, 1599, 1582, 1580, 1566, 1217, 1217, - /* 190 */ 1217, 1627, 1615, 1611, 1217, 1217, 1589, 1217, 1217, 1589, - /* 200 */ 1217, 1427, 1217, 1217, 1274, 1217, 1274, 1217, 1338, 1217, - /* 210 */ 1217, 1217, 1274, 1217, 1442, 1372, 1372, 1277, 1222, 1217, - /* 220 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1512, - /* 230 */ 1513, 1602, 1601, 1512, 1526, 1525, 1524, 1217, 1217, 1507, - /* 240 */ 1217, 1217, 1508, 1506, 1505, 1217, 1217, 1217, 1217, 1217, - /* 250 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1550, - /* 260 */ 1217, 1612, 1616, 1217, 1217, 1217, 1487, 1217, 1217, 1217, - /* 270 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 280 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 290 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 300 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 310 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 320 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 330 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 340 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 350 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 360 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 370 */ 1217, 1217, 1217, 1383, 1217, 1217, 1217, 1217, 1217, 1217, - /* 380 */ 1303, 1302, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 390 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 400 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 410 */ 1217, 1217, 1217, 1573, 1583, 1217, 1217, 1217, 1217, 1217, - /* 420 */ 1217, 1217, 1217, 1217, 1487, 1217, 1600, 1217, 1559, 1555, - /* 430 */ 1217, 1217, 1551, 1217, 1217, 1610, 1217, 1217, 1217, 1217, - /* 440 */ 1217, 1217, 1217, 1217, 1545, 1217, 1217, 1217, 1217, 1217, - /* 450 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 460 */ 1217, 1217, 1486, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 470 */ 1366, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 480 */ 1217, 1217, 1217, 1351, 1349, 1348, 1347, 1217, 1344, 1217, - /* 490 */ 1217, 1217, 1217, 1217, 1217, 1374, 1217, 1217, 1217, 1217, - /* 500 */ 1217, 1297, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 510 */ 1217, 1288, 1217, 1287, 1217, 1217, 1217, 1217, 1217, 1217, - /* 520 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 530 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, - /* 540 */ 1217, 1217, 1217, 1217, 1217, 1217, 1217, 1217, + /* 0 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 10 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 20 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 30 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 40 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 50 */ 1219, 1219, 1219, 1278, 1219, 1219, 1219, 1219, 1219, 1219, + /* 60 */ 1219, 1219, 1219, 1219, 1219, 1219, 1276, 1416, 1219, 1552, + /* 70 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 80 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 90 */ 1219, 1219, 1219, 1219, 1219, 1219, 1278, 1219, 1563, 1563, + /* 100 */ 1563, 1276, 1219, 1219, 1219, 1219, 1219, 1371, 1219, 1219, + /* 110 */ 1219, 1219, 1219, 1219, 1219, 1219, 1450, 1219, 1219, 1627, + /* 120 */ 1219, 1219, 1324, 1219, 1587, 1219, 1579, 1555, 1569, 1556, + /* 130 */ 1219, 1612, 1572, 1219, 1219, 1219, 1442, 1219, 1219, 1421, + /* 140 */ 1418, 1418, 1219, 1219, 1219, 1278, 1219, 1219, 1278, 1278, + /* 150 */ 1219, 1278, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 160 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1452, + /* 170 */ 1219, 1276, 1219, 1219, 1276, 1219, 1594, 1592, 1219, 1594, + /* 180 */ 1592, 1219, 1219, 1606, 1602, 1585, 1583, 1569, 1219, 1219, + /* 190 */ 1219, 1630, 1618, 1614, 1219, 1219, 1592, 1219, 1219, 1592, + /* 200 */ 1219, 1429, 1219, 1219, 1276, 1219, 1276, 1219, 1340, 1219, + /* 210 */ 1219, 1219, 1276, 1219, 1444, 1374, 1374, 1279, 1224, 1219, + /* 220 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1514, + /* 230 */ 1515, 1605, 1604, 1514, 1529, 1528, 1527, 1219, 1219, 1509, + /* 240 */ 1219, 1219, 1510, 1508, 1507, 1219, 1219, 1219, 1219, 1219, + /* 250 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1553, + /* 260 */ 1219, 1615, 1619, 1219, 1219, 1219, 1489, 1219, 1219, 1219, + /* 270 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 280 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 290 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 300 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 310 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 320 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 330 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 340 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 350 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 360 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 370 */ 1219, 1219, 1219, 1385, 1219, 1219, 1219, 1219, 1219, 1219, + /* 380 */ 1305, 1304, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 390 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 400 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 410 */ 1219, 1219, 1219, 1576, 1586, 1219, 1219, 1219, 1219, 1219, + /* 420 */ 1219, 1219, 1219, 1219, 1489, 1219, 1603, 1219, 1562, 1558, + /* 430 */ 1219, 1219, 1554, 1219, 1219, 1613, 1219, 1219, 1219, 1219, + /* 440 */ 1219, 1219, 1219, 1219, 1548, 1219, 1219, 1219, 1219, 1219, + /* 450 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 460 */ 1219, 1219, 1488, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 470 */ 1368, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 480 */ 1219, 1219, 1219, 1353, 1351, 1350, 1349, 1219, 1346, 1219, + /* 490 */ 1219, 1219, 1219, 1219, 1219, 1376, 1219, 1219, 1219, 1219, + /* 500 */ 1219, 1299, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 510 */ 1219, 1290, 1219, 1289, 1219, 1219, 1219, 1219, 1219, 1219, + /* 520 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 530 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, + /* 540 */ 1219, 1219, 1219, 1219, 1219, 1219, 1219, 1219, }; /********** End of lemon-generated parsing tables *****************************/ @@ -959,153 +960,154 @@ static const char *const yyTokenName[] = { /* 164 */ "FIRST", /* 165 */ "LAST", /* 166 */ "NOW", - /* 167 */ "ROWTS", - /* 168 */ "TBNAME", - /* 169 */ "QSTARTTS", - /* 170 */ "QENDTS", - /* 171 */ "WSTARTTS", - /* 172 */ "WENDTS", - /* 173 */ "WDURATION", - /* 174 */ "BETWEEN", - /* 175 */ "IS", - /* 176 */ "NK_LT", - /* 177 */ "NK_GT", - /* 178 */ "NK_LE", - /* 179 */ "NK_GE", - /* 180 */ "NK_NE", - /* 181 */ "MATCH", - /* 182 */ "NMATCH", - /* 183 */ "JOIN", - /* 184 */ "INNER", - /* 185 */ "SELECT", - /* 186 */ "DISTINCT", - /* 187 */ "WHERE", - /* 188 */ "PARTITION", - /* 189 */ "BY", - /* 190 */ "SESSION", - /* 191 */ "STATE_WINDOW", - /* 192 */ "SLIDING", - /* 193 */ "FILL", - /* 194 */ "VALUE", - /* 195 */ "NONE", - /* 196 */ "PREV", - /* 197 */ "LINEAR", - /* 198 */ "NEXT", - /* 199 */ "GROUP", - /* 200 */ "HAVING", - /* 201 */ "ORDER", - /* 202 */ "SLIMIT", - /* 203 */ "SOFFSET", - /* 204 */ "LIMIT", - /* 205 */ "OFFSET", - /* 206 */ "ASC", - /* 207 */ "NULLS", - /* 208 */ "cmd", - /* 209 */ "account_options", - /* 210 */ "alter_account_options", - /* 211 */ "literal", - /* 212 */ "alter_account_option", - /* 213 */ "user_name", - /* 214 */ "dnode_endpoint", - /* 215 */ "dnode_host_name", - /* 216 */ "not_exists_opt", - /* 217 */ "db_name", - /* 218 */ "db_options", - /* 219 */ "exists_opt", - /* 220 */ "alter_db_options", - /* 221 */ "integer_list", - /* 222 */ "variable_list", - /* 223 */ "retention_list", - /* 224 */ "alter_db_option", - /* 225 */ "retention", - /* 226 */ "full_table_name", - /* 227 */ "column_def_list", - /* 228 */ "tags_def_opt", - /* 229 */ "table_options", - /* 230 */ "multi_create_clause", - /* 231 */ "tags_def", - /* 232 */ "multi_drop_clause", - /* 233 */ "alter_table_clause", - /* 234 */ "alter_table_options", - /* 235 */ "column_name", - /* 236 */ "type_name", - /* 237 */ "create_subtable_clause", - /* 238 */ "specific_tags_opt", - /* 239 */ "literal_list", - /* 240 */ "drop_table_clause", - /* 241 */ "col_name_list", - /* 242 */ "table_name", - /* 243 */ "column_def", - /* 244 */ "func_name_list", - /* 245 */ "alter_table_option", - /* 246 */ "col_name", - /* 247 */ "db_name_cond_opt", - /* 248 */ "like_pattern_opt", - /* 249 */ "table_name_cond", - /* 250 */ "from_db_opt", - /* 251 */ "func_name", - /* 252 */ "function_name", - /* 253 */ "index_name", - /* 254 */ "index_options", - /* 255 */ "func_list", - /* 256 */ "duration_literal", - /* 257 */ "sliding_opt", - /* 258 */ "func", - /* 259 */ "expression_list", - /* 260 */ "topic_name", - /* 261 */ "query_expression", - /* 262 */ "analyze_opt", - /* 263 */ "explain_options", - /* 264 */ "agg_func_opt", - /* 265 */ "bufsize_opt", - /* 266 */ "stream_name", - /* 267 */ "dnode_list", - /* 268 */ "signed", - /* 269 */ "signed_literal", - /* 270 */ "table_alias", - /* 271 */ "column_alias", - /* 272 */ "expression", - /* 273 */ "pseudo_column", - /* 274 */ "column_reference", - /* 275 */ "subquery", - /* 276 */ "predicate", - /* 277 */ "compare_op", - /* 278 */ "in_op", - /* 279 */ "in_predicate_value", - /* 280 */ "boolean_value_expression", - /* 281 */ "boolean_primary", - /* 282 */ "common_expression", - /* 283 */ "from_clause", - /* 284 */ "table_reference_list", - /* 285 */ "table_reference", - /* 286 */ "table_primary", - /* 287 */ "joined_table", - /* 288 */ "alias_opt", - /* 289 */ "parenthesized_joined_table", - /* 290 */ "join_type", - /* 291 */ "search_condition", - /* 292 */ "query_specification", - /* 293 */ "set_quantifier_opt", - /* 294 */ "select_list", - /* 295 */ "where_clause_opt", - /* 296 */ "partition_by_clause_opt", - /* 297 */ "twindow_clause_opt", - /* 298 */ "group_by_clause_opt", - /* 299 */ "having_clause_opt", - /* 300 */ "select_sublist", - /* 301 */ "select_item", - /* 302 */ "fill_opt", - /* 303 */ "fill_mode", - /* 304 */ "group_by_list", - /* 305 */ "query_expression_body", - /* 306 */ "order_by_clause_opt", - /* 307 */ "slimit_clause_opt", - /* 308 */ "limit_clause_opt", - /* 309 */ "query_primary", - /* 310 */ "sort_specification_list", - /* 311 */ "sort_specification", - /* 312 */ "ordering_specification_opt", - /* 313 */ "null_ordering_opt", + /* 167 */ "TODAY", + /* 168 */ "ROWTS", + /* 169 */ "TBNAME", + /* 170 */ "QSTARTTS", + /* 171 */ "QENDTS", + /* 172 */ "WSTARTTS", + /* 173 */ "WENDTS", + /* 174 */ "WDURATION", + /* 175 */ "BETWEEN", + /* 176 */ "IS", + /* 177 */ "NK_LT", + /* 178 */ "NK_GT", + /* 179 */ "NK_LE", + /* 180 */ "NK_GE", + /* 181 */ "NK_NE", + /* 182 */ "MATCH", + /* 183 */ "NMATCH", + /* 184 */ "JOIN", + /* 185 */ "INNER", + /* 186 */ "SELECT", + /* 187 */ "DISTINCT", + /* 188 */ "WHERE", + /* 189 */ "PARTITION", + /* 190 */ "BY", + /* 191 */ "SESSION", + /* 192 */ "STATE_WINDOW", + /* 193 */ "SLIDING", + /* 194 */ "FILL", + /* 195 */ "VALUE", + /* 196 */ "NONE", + /* 197 */ "PREV", + /* 198 */ "LINEAR", + /* 199 */ "NEXT", + /* 200 */ "GROUP", + /* 201 */ "HAVING", + /* 202 */ "ORDER", + /* 203 */ "SLIMIT", + /* 204 */ "SOFFSET", + /* 205 */ "LIMIT", + /* 206 */ "OFFSET", + /* 207 */ "ASC", + /* 208 */ "NULLS", + /* 209 */ "cmd", + /* 210 */ "account_options", + /* 211 */ "alter_account_options", + /* 212 */ "literal", + /* 213 */ "alter_account_option", + /* 214 */ "user_name", + /* 215 */ "dnode_endpoint", + /* 216 */ "dnode_host_name", + /* 217 */ "not_exists_opt", + /* 218 */ "db_name", + /* 219 */ "db_options", + /* 220 */ "exists_opt", + /* 221 */ "alter_db_options", + /* 222 */ "integer_list", + /* 223 */ "variable_list", + /* 224 */ "retention_list", + /* 225 */ "alter_db_option", + /* 226 */ "retention", + /* 227 */ "full_table_name", + /* 228 */ "column_def_list", + /* 229 */ "tags_def_opt", + /* 230 */ "table_options", + /* 231 */ "multi_create_clause", + /* 232 */ "tags_def", + /* 233 */ "multi_drop_clause", + /* 234 */ "alter_table_clause", + /* 235 */ "alter_table_options", + /* 236 */ "column_name", + /* 237 */ "type_name", + /* 238 */ "create_subtable_clause", + /* 239 */ "specific_tags_opt", + /* 240 */ "literal_list", + /* 241 */ "drop_table_clause", + /* 242 */ "col_name_list", + /* 243 */ "table_name", + /* 244 */ "column_def", + /* 245 */ "func_name_list", + /* 246 */ "alter_table_option", + /* 247 */ "col_name", + /* 248 */ "db_name_cond_opt", + /* 249 */ "like_pattern_opt", + /* 250 */ "table_name_cond", + /* 251 */ "from_db_opt", + /* 252 */ "func_name", + /* 253 */ "function_name", + /* 254 */ "index_name", + /* 255 */ "index_options", + /* 256 */ "func_list", + /* 257 */ "duration_literal", + /* 258 */ "sliding_opt", + /* 259 */ "func", + /* 260 */ "expression_list", + /* 261 */ "topic_name", + /* 262 */ "query_expression", + /* 263 */ "analyze_opt", + /* 264 */ "explain_options", + /* 265 */ "agg_func_opt", + /* 266 */ "bufsize_opt", + /* 267 */ "stream_name", + /* 268 */ "dnode_list", + /* 269 */ "signed", + /* 270 */ "signed_literal", + /* 271 */ "table_alias", + /* 272 */ "column_alias", + /* 273 */ "expression", + /* 274 */ "pseudo_column", + /* 275 */ "column_reference", + /* 276 */ "subquery", + /* 277 */ "predicate", + /* 278 */ "compare_op", + /* 279 */ "in_op", + /* 280 */ "in_predicate_value", + /* 281 */ "boolean_value_expression", + /* 282 */ "boolean_primary", + /* 283 */ "common_expression", + /* 284 */ "from_clause", + /* 285 */ "table_reference_list", + /* 286 */ "table_reference", + /* 287 */ "table_primary", + /* 288 */ "joined_table", + /* 289 */ "alias_opt", + /* 290 */ "parenthesized_joined_table", + /* 291 */ "join_type", + /* 292 */ "search_condition", + /* 293 */ "query_specification", + /* 294 */ "set_quantifier_opt", + /* 295 */ "select_list", + /* 296 */ "where_clause_opt", + /* 297 */ "partition_by_clause_opt", + /* 298 */ "twindow_clause_opt", + /* 299 */ "group_by_clause_opt", + /* 300 */ "having_clause_opt", + /* 301 */ "select_sublist", + /* 302 */ "select_item", + /* 303 */ "fill_opt", + /* 304 */ "fill_mode", + /* 305 */ "group_by_list", + /* 306 */ "query_expression_body", + /* 307 */ "order_by_clause_opt", + /* 308 */ "slimit_clause_opt", + /* 309 */ "limit_clause_opt", + /* 310 */ "query_primary", + /* 311 */ "sort_specification_list", + /* 312 */ "sort_specification", + /* 313 */ "ordering_specification_opt", + /* 314 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1410,119 +1412,120 @@ static const char *const yyRuleName[] = { /* 294 */ "column_reference ::= column_name", /* 295 */ "column_reference ::= table_name NK_DOT column_name", /* 296 */ "pseudo_column ::= NOW", - /* 297 */ "pseudo_column ::= ROWTS", - /* 298 */ "pseudo_column ::= TBNAME", - /* 299 */ "pseudo_column ::= QSTARTTS", - /* 300 */ "pseudo_column ::= QENDTS", - /* 301 */ "pseudo_column ::= WSTARTTS", - /* 302 */ "pseudo_column ::= WENDTS", - /* 303 */ "pseudo_column ::= WDURATION", - /* 304 */ "predicate ::= expression compare_op expression", - /* 305 */ "predicate ::= expression BETWEEN expression AND expression", - /* 306 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 307 */ "predicate ::= expression IS NULL", - /* 308 */ "predicate ::= expression IS NOT NULL", - /* 309 */ "predicate ::= expression in_op in_predicate_value", - /* 310 */ "compare_op ::= NK_LT", - /* 311 */ "compare_op ::= NK_GT", - /* 312 */ "compare_op ::= NK_LE", - /* 313 */ "compare_op ::= NK_GE", - /* 314 */ "compare_op ::= NK_NE", - /* 315 */ "compare_op ::= NK_EQ", - /* 316 */ "compare_op ::= LIKE", - /* 317 */ "compare_op ::= NOT LIKE", - /* 318 */ "compare_op ::= MATCH", - /* 319 */ "compare_op ::= NMATCH", - /* 320 */ "in_op ::= IN", - /* 321 */ "in_op ::= NOT IN", - /* 322 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 323 */ "boolean_value_expression ::= boolean_primary", - /* 324 */ "boolean_value_expression ::= NOT boolean_primary", - /* 325 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 326 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 327 */ "boolean_primary ::= predicate", - /* 328 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 329 */ "common_expression ::= expression", - /* 330 */ "common_expression ::= boolean_value_expression", - /* 331 */ "from_clause ::= FROM table_reference_list", - /* 332 */ "table_reference_list ::= table_reference", - /* 333 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 334 */ "table_reference ::= table_primary", - /* 335 */ "table_reference ::= joined_table", - /* 336 */ "table_primary ::= table_name alias_opt", - /* 337 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 338 */ "table_primary ::= subquery alias_opt", - /* 339 */ "table_primary ::= parenthesized_joined_table", - /* 340 */ "alias_opt ::=", - /* 341 */ "alias_opt ::= table_alias", - /* 342 */ "alias_opt ::= AS table_alias", - /* 343 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 344 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 345 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 346 */ "join_type ::=", - /* 347 */ "join_type ::= INNER", - /* 348 */ "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", - /* 349 */ "set_quantifier_opt ::=", - /* 350 */ "set_quantifier_opt ::= DISTINCT", - /* 351 */ "set_quantifier_opt ::= ALL", - /* 352 */ "select_list ::= NK_STAR", - /* 353 */ "select_list ::= select_sublist", - /* 354 */ "select_sublist ::= select_item", - /* 355 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 356 */ "select_item ::= common_expression", - /* 357 */ "select_item ::= common_expression column_alias", - /* 358 */ "select_item ::= common_expression AS column_alias", - /* 359 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 360 */ "where_clause_opt ::=", - /* 361 */ "where_clause_opt ::= WHERE search_condition", - /* 362 */ "partition_by_clause_opt ::=", - /* 363 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 364 */ "twindow_clause_opt ::=", - /* 365 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 366 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", - /* 367 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 368 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 369 */ "sliding_opt ::=", - /* 370 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 371 */ "fill_opt ::=", - /* 372 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 373 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 374 */ "fill_mode ::= NONE", - /* 375 */ "fill_mode ::= PREV", - /* 376 */ "fill_mode ::= NULL", - /* 377 */ "fill_mode ::= LINEAR", - /* 378 */ "fill_mode ::= NEXT", - /* 379 */ "group_by_clause_opt ::=", - /* 380 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 381 */ "group_by_list ::= expression", - /* 382 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 383 */ "having_clause_opt ::=", - /* 384 */ "having_clause_opt ::= HAVING search_condition", - /* 385 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 386 */ "query_expression_body ::= query_primary", - /* 387 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 388 */ "query_primary ::= query_specification", - /* 389 */ "order_by_clause_opt ::=", - /* 390 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 391 */ "slimit_clause_opt ::=", - /* 392 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 393 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 394 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 395 */ "limit_clause_opt ::=", - /* 396 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 397 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 398 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 399 */ "subquery ::= NK_LP query_expression NK_RP", - /* 400 */ "search_condition ::= common_expression", - /* 401 */ "sort_specification_list ::= sort_specification", - /* 402 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 403 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 404 */ "ordering_specification_opt ::=", - /* 405 */ "ordering_specification_opt ::= ASC", - /* 406 */ "ordering_specification_opt ::= DESC", - /* 407 */ "null_ordering_opt ::=", - /* 408 */ "null_ordering_opt ::= NULLS FIRST", - /* 409 */ "null_ordering_opt ::= NULLS LAST", + /* 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 */ @@ -1649,156 +1652,156 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 208: /* cmd */ - case 211: /* literal */ - case 218: /* db_options */ - case 220: /* alter_db_options */ - case 225: /* retention */ - case 226: /* full_table_name */ - case 229: /* table_options */ - case 233: /* alter_table_clause */ - case 234: /* alter_table_options */ - case 237: /* create_subtable_clause */ - case 240: /* drop_table_clause */ - case 243: /* column_def */ - case 246: /* col_name */ - case 247: /* db_name_cond_opt */ - case 248: /* like_pattern_opt */ - case 249: /* table_name_cond */ - case 250: /* from_db_opt */ - case 251: /* func_name */ - case 254: /* index_options */ - case 256: /* duration_literal */ - case 257: /* sliding_opt */ - case 258: /* func */ - case 261: /* query_expression */ - case 263: /* explain_options */ - case 268: /* signed */ - case 269: /* signed_literal */ - case 272: /* expression */ - case 273: /* pseudo_column */ - case 274: /* column_reference */ - case 275: /* subquery */ - case 276: /* predicate */ - case 279: /* in_predicate_value */ - case 280: /* boolean_value_expression */ - case 281: /* boolean_primary */ - case 282: /* common_expression */ - case 283: /* from_clause */ - case 284: /* table_reference_list */ - case 285: /* table_reference */ - case 286: /* table_primary */ - case 287: /* joined_table */ - case 289: /* parenthesized_joined_table */ - case 291: /* search_condition */ - case 292: /* query_specification */ - case 295: /* where_clause_opt */ - case 297: /* twindow_clause_opt */ - case 299: /* having_clause_opt */ - case 301: /* select_item */ - case 302: /* fill_opt */ - case 305: /* query_expression_body */ - case 307: /* slimit_clause_opt */ - case 308: /* limit_clause_opt */ - case 309: /* query_primary */ - case 311: /* sort_specification */ + case 209: /* cmd */ + case 212: /* literal */ + case 219: /* db_options */ + case 221: /* alter_db_options */ + case 226: /* retention */ + case 227: /* full_table_name */ + case 230: /* table_options */ + case 234: /* alter_table_clause */ + case 235: /* alter_table_options */ + case 238: /* create_subtable_clause */ + case 241: /* drop_table_clause */ + case 244: /* column_def */ + case 247: /* col_name */ + case 248: /* db_name_cond_opt */ + case 249: /* like_pattern_opt */ + case 250: /* table_name_cond */ + case 251: /* from_db_opt */ + case 252: /* func_name */ + case 255: /* index_options */ + case 257: /* duration_literal */ + case 258: /* sliding_opt */ + case 259: /* func */ + case 262: /* query_expression */ + case 264: /* explain_options */ + case 269: /* signed */ + case 270: /* signed_literal */ + case 273: /* expression */ + case 274: /* pseudo_column */ + case 275: /* column_reference */ + case 276: /* subquery */ + case 277: /* predicate */ + case 280: /* in_predicate_value */ + case 281: /* boolean_value_expression */ + case 282: /* boolean_primary */ + case 283: /* common_expression */ + case 284: /* from_clause */ + case 285: /* table_reference_list */ + case 286: /* table_reference */ + case 287: /* table_primary */ + case 288: /* joined_table */ + case 290: /* parenthesized_joined_table */ + case 292: /* search_condition */ + case 293: /* query_specification */ + case 296: /* where_clause_opt */ + case 298: /* twindow_clause_opt */ + case 300: /* having_clause_opt */ + case 302: /* select_item */ + case 303: /* fill_opt */ + case 306: /* query_expression_body */ + case 308: /* slimit_clause_opt */ + case 309: /* limit_clause_opt */ + case 310: /* query_primary */ + case 312: /* sort_specification */ { - nodesDestroyNode((yypminor->yy140)); + nodesDestroyNode((yypminor->yy182)); } break; - case 209: /* account_options */ - case 210: /* alter_account_options */ - case 212: /* alter_account_option */ - case 265: /* bufsize_opt */ + case 210: /* account_options */ + case 211: /* alter_account_options */ + case 213: /* alter_account_option */ + case 266: /* bufsize_opt */ { } break; - case 213: /* user_name */ - case 214: /* dnode_endpoint */ - case 215: /* dnode_host_name */ - case 217: /* db_name */ - case 235: /* column_name */ - case 242: /* table_name */ - case 252: /* function_name */ - case 253: /* index_name */ - case 260: /* topic_name */ - case 266: /* stream_name */ - case 270: /* table_alias */ - case 271: /* column_alias */ - case 288: /* alias_opt */ + case 214: /* user_name */ + case 215: /* dnode_endpoint */ + case 216: /* dnode_host_name */ + case 218: /* db_name */ + case 236: /* column_name */ + case 243: /* table_name */ + case 253: /* function_name */ + case 254: /* index_name */ + case 261: /* topic_name */ + case 267: /* stream_name */ + case 271: /* table_alias */ + case 272: /* column_alias */ + case 289: /* alias_opt */ { } break; - case 216: /* not_exists_opt */ - case 219: /* exists_opt */ - case 262: /* analyze_opt */ - case 264: /* agg_func_opt */ - case 293: /* set_quantifier_opt */ + case 217: /* not_exists_opt */ + case 220: /* exists_opt */ + case 263: /* analyze_opt */ + case 265: /* agg_func_opt */ + case 294: /* set_quantifier_opt */ { } break; - case 221: /* integer_list */ - case 222: /* variable_list */ - case 223: /* retention_list */ - case 227: /* column_def_list */ - case 228: /* tags_def_opt */ - case 230: /* multi_create_clause */ - case 231: /* tags_def */ - case 232: /* multi_drop_clause */ - case 238: /* specific_tags_opt */ - case 239: /* literal_list */ - case 241: /* col_name_list */ - case 244: /* func_name_list */ - case 255: /* func_list */ - case 259: /* expression_list */ - case 267: /* dnode_list */ - case 294: /* select_list */ - case 296: /* partition_by_clause_opt */ - case 298: /* group_by_clause_opt */ - case 300: /* select_sublist */ - case 304: /* group_by_list */ - case 306: /* order_by_clause_opt */ - case 310: /* sort_specification_list */ + case 222: /* integer_list */ + case 223: /* variable_list */ + case 224: /* retention_list */ + case 228: /* column_def_list */ + case 229: /* tags_def_opt */ + case 231: /* multi_create_clause */ + case 232: /* tags_def */ + case 233: /* multi_drop_clause */ + case 239: /* specific_tags_opt */ + case 240: /* literal_list */ + case 242: /* col_name_list */ + case 245: /* func_name_list */ + case 256: /* func_list */ + case 260: /* expression_list */ + case 268: /* dnode_list */ + case 295: /* select_list */ + case 297: /* partition_by_clause_opt */ + case 299: /* group_by_clause_opt */ + case 301: /* select_sublist */ + case 305: /* group_by_list */ + case 307: /* order_by_clause_opt */ + case 311: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy220)); + nodesDestroyList((yypminor->yy334)); } break; - case 224: /* alter_db_option */ - case 245: /* alter_table_option */ + case 225: /* alter_db_option */ + case 246: /* alter_table_option */ { } break; - case 236: /* type_name */ + case 237: /* type_name */ { } break; - case 277: /* compare_op */ - case 278: /* in_op */ + case 278: /* compare_op */ + case 279: /* in_op */ { } break; - case 290: /* join_type */ + case 291: /* join_type */ { } break; - case 303: /* fill_mode */ + case 304: /* fill_mode */ { } break; - case 312: /* ordering_specification_opt */ + case 313: /* ordering_specification_opt */ { } break; - case 313: /* null_ordering_opt */ + case 314: /* null_ordering_opt */ { } @@ -1926,15 +1929,18 @@ static YYACTIONTYPE yy_find_shift_action( do{ i = yy_shift_ofst[stateno]; assert( i>=0 ); - /* assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD ); */ + assert( i<=YY_ACTTAB_COUNT ); + assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD ); assert( iLookAhead!=YYNOCODE ); assert( iLookAhead < YYNTOKEN ); i += iLookAhead; - if( i>=YY_NLOOKAHEAD || yy_lookahead[i]!=iLookAhead ){ + assert( i<(int)YY_NLOOKAHEAD ); + if( yy_lookahead[i]!=iLookAhead ){ #ifdef YYFALLBACK YYCODETYPE iFallback; /* Fallback token */ - if( iLookAhead %s\n", @@ -1949,16 +1955,8 @@ static YYACTIONTYPE yy_find_shift_action( #ifdef YYWILDCARD { int j = i - iLookAhead + YYWILDCARD; - if( -#if YY_SHIFT_MIN+YYWILDCARD<0 - j>=0 && -#endif -#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT - j0 - ){ + assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) ); + if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){ #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", @@ -1972,6 +1970,7 @@ 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 = yyRuleInfo[yyruleno].nrhs; + yysize = yyRuleInfoNRhs[yyruleno]; if( yysize ){ - fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n", + fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", yyTracePrompt, - yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno); + yyruleno, yyRuleName[yyruleno], + yyrulenoyytos - yypParser->yystack)>yypParser->yyhwm ){ yypParser->yyhwm++; @@ -2595,11 +3010,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,209,&yymsp[0].minor); + yy_destructor(yypParser,210,&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,210,&yymsp[0].minor); + yy_destructor(yypParser,211,&yymsp[0].minor); break; case 2: /* account_options ::= */ { } @@ -2613,20 +3028,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,209,&yymsp[-2].minor); +{ yy_destructor(yypParser,210,&yymsp[-2].minor); { } - yy_destructor(yypParser,211,&yymsp[0].minor); + yy_destructor(yypParser,212,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ -{ yy_destructor(yypParser,212,&yymsp[0].minor); +{ yy_destructor(yypParser,213,&yymsp[0].minor); { } } break; case 13: /* alter_account_options ::= alter_account_options alter_account_option */ -{ yy_destructor(yypParser,210,&yymsp[-1].minor); +{ yy_destructor(yypParser,211,&yymsp[-1].minor); { } - yy_destructor(yypParser,212,&yymsp[0].minor); + yy_destructor(yypParser,213,&yymsp[0].minor); } break; case 14: /* alter_account_option ::= PASS literal */ @@ -2640,31 +3055,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,211,&yymsp[0].minor); + yy_destructor(yypParser,212,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy253, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy29, &yymsp[0].minor.yy0); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy253, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy29, 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.yy253, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy29, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy253); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy29); } break; case 28: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy253, NULL); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy29, NULL); } break; case 29: /* cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy253, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy29, &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.yy253); } +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy29); } break; case 32: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } @@ -2693,8 +3108,8 @@ static YYACTIONTYPE yy_reduce( 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.yy253 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy253 = yylhsminor.yy253; +{ yylhsminor.yy29 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy29 = yylhsminor.yy29; break; case 39: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } @@ -2727,156 +3142,156 @@ 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.yy273, &yymsp[-1].minor.yy253, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy47, &yymsp[-1].minor.yy29, yymsp[0].minor.yy182); } break; case 50: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy273, &yymsp[0].minor.yy253); } +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy47, &yymsp[0].minor.yy29); } break; case 51: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy253); } +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy29); } break; case 52: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy253, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy29, yymsp[0].minor.yy182); } break; case 53: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy273 = true; } +{ yymsp[-2].minor.yy47 = true; } break; case 54: /* not_exists_opt ::= */ case 56: /* exists_opt ::= */ yytestcase(yyruleno==56); case 220: /* analyze_opt ::= */ yytestcase(yyruleno==220); case 228: /* agg_func_opt ::= */ yytestcase(yyruleno==228); - case 349: /* set_quantifier_opt ::= */ yytestcase(yyruleno==349); -{ yymsp[1].minor.yy273 = false; } + case 350: /* set_quantifier_opt ::= */ yytestcase(yyruleno==350); +{ yymsp[1].minor.yy47 = false; } break; case 55: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy273 = true; } +{ yymsp[-1].minor.yy47 = true; } break; case 57: /* db_options ::= */ -{ yymsp[1].minor.yy140 = createDatabaseOptions(pCxt); } +{ yymsp[1].minor.yy182 = createDatabaseOptions(pCxt); } break; case 58: /* db_options ::= db_options BLOCKS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pNumOfBlocks = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pNumOfBlocks = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 59: /* db_options ::= db_options CACHE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pCacheBlockSize = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pCacheBlockSize = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 60: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pCachelast = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pCachelast = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 61: /* db_options ::= db_options COMP NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pCompressionLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pCompressionLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 62: /* db_options ::= db_options DAYS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pDaysPerFile = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pDaysPerFile = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 63: /* db_options ::= db_options DAYS NK_VARIABLE */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 64: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pFsyncPeriod = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pFsyncPeriod = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 65: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pMaxRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pMaxRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 66: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pMinRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pMinRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; 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.yy140)->pKeep = yymsp[0].minor.yy220; yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pKeep = yymsp[0].minor.yy334; yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 69: /* db_options ::= db_options PRECISION NK_STRING */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pPrecision = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pPrecision = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 70: /* db_options ::= db_options QUORUM NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pQuorum = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pQuorum = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 71: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pReplica = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pReplica = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 72: /* db_options ::= db_options TTL NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 73: /* db_options ::= db_options WAL NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pWalLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pWalLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 74: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pNumOfVgroups = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pNumOfVgroups = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 75: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pSingleStable = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pSingleStable = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 76: /* db_options ::= db_options STREAM_MODE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pStreamMode = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pStreamMode = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 77: /* db_options ::= db_options RETENTIONS retention_list */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy140)->pRetentions = yymsp[0].minor.yy220; yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pRetentions = yymsp[0].minor.yy334; yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 78: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy140 = createDatabaseOptions(pCxt); yylhsminor.yy140 = setDatabaseAlterOption(pCxt, yylhsminor.yy140, &yymsp[0].minor.yy181); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createDatabaseOptions(pCxt); yylhsminor.yy182 = setDatabaseAlterOption(pCxt, yylhsminor.yy182, &yymsp[0].minor.yy515); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 79: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy140 = setDatabaseAlterOption(pCxt, yymsp[-1].minor.yy140, &yymsp[0].minor.yy181); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = setDatabaseAlterOption(pCxt, yymsp[-1].minor.yy182, &yymsp[0].minor.yy515); } + yymsp[-1].minor.yy182 = yylhsminor.yy182; break; case 80: /* alter_db_option ::= BLOCKS NK_INTEGER */ -{ yymsp[-1].minor.yy181.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy181.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy515.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy515.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 81: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy181.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy181.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy515.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy515.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.yy181.type = DB_OPTION_KEEP; yymsp[-1].minor.yy181.pList = yymsp[0].minor.yy220; } +{ yymsp[-1].minor.yy515.type = DB_OPTION_KEEP; yymsp[-1].minor.yy515.pList = yymsp[0].minor.yy334; } break; case 84: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy181.type = DB_OPTION_WAL; yymsp[-1].minor.yy181.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy515.type = DB_OPTION_WAL; yymsp[-1].minor.yy515.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 85: /* alter_db_option ::= QUORUM NK_INTEGER */ -{ yymsp[-1].minor.yy181.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy181.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy515.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy515.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 86: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy181.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy181.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy515.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy515.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 87: /* alter_db_option ::= REPLICA NK_INTEGER */ -{ yymsp[-1].minor.yy181.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy181.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy515.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy515.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 88: /* integer_list ::= NK_INTEGER */ -{ yylhsminor.yy220 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy220 = yylhsminor.yy220; +{ yylhsminor.yy334 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy334 = yylhsminor.yy334; break; case 89: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ case 240: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==240); -{ yylhsminor.yy220 = addNodeToList(pCxt, yymsp[-2].minor.yy220, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy220 = yylhsminor.yy220; +{ yylhsminor.yy334 = addNodeToList(pCxt, yymsp[-2].minor.yy334, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy334 = yylhsminor.yy334; break; case 90: /* variable_list ::= NK_VARIABLE */ -{ yylhsminor.yy220 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy220 = yylhsminor.yy220; +{ yylhsminor.yy334 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy334 = yylhsminor.yy334; break; case 91: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ -{ yylhsminor.yy220 = addNodeToList(pCxt, yymsp[-2].minor.yy220, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy220 = yylhsminor.yy220; +{ yylhsminor.yy334 = addNodeToList(pCxt, yymsp[-2].minor.yy334, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy334 = yylhsminor.yy334; break; case 92: /* retention_list ::= retention */ case 112: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==112); @@ -2886,10 +3301,10 @@ static YYACTIONTYPE yy_reduce( 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 354: /* select_sublist ::= select_item */ yytestcase(yyruleno==354); - case 401: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==401); -{ yylhsminor.yy220 = createNodeList(pCxt, yymsp[0].minor.yy140); } - yymsp[0].minor.yy220 = yylhsminor.yy220; + case 355: /* select_sublist ::= select_item */ yytestcase(yyruleno==355); + case 402: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==402); +{ yylhsminor.yy334 = createNodeList(pCxt, yymsp[0].minor.yy182); } + yymsp[0].minor.yy334 = yylhsminor.yy334; 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); @@ -2897,238 +3312,238 @@ static YYACTIONTYPE yy_reduce( 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 355: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==355); - case 402: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==402); -{ yylhsminor.yy220 = addNodeToList(pCxt, yymsp[-2].minor.yy220, yymsp[0].minor.yy140); } - yymsp[-2].minor.yy220 = yylhsminor.yy220; + 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.yy334 = addNodeToList(pCxt, yymsp[-2].minor.yy334, yymsp[0].minor.yy182); } + yymsp[-2].minor.yy334 = yylhsminor.yy334; break; case 94: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ -{ yylhsminor.yy140 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy182 = yylhsminor.yy182; 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.yy273, yymsp[-5].minor.yy140, yymsp[-3].minor.yy220, yymsp[-1].minor.yy220, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy47, yymsp[-5].minor.yy182, yymsp[-3].minor.yy334, yymsp[-1].minor.yy334, yymsp[0].minor.yy182); } break; case 96: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy220); } +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy334); } break; case 98: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy220); } +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy334); } break; case 99: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy273, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy47, yymsp[0].minor.yy182); } break; case 100: /* cmd ::= ALTER TABLE alter_table_clause */ case 101: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==101); case 242: /* cmd ::= query_expression */ yytestcase(yyruleno==242); -{ pCxt->pRootNode = yymsp[0].minor.yy140; } +{ pCxt->pRootNode = yymsp[0].minor.yy182; } break; case 102: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy140 = createAlterTableOption(pCxt, yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createAlterTableOption(pCxt, yymsp[-1].minor.yy182, yymsp[0].minor.yy182); } + yymsp[-1].minor.yy182 = yylhsminor.yy182; break; case 103: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.yy140 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy253, yymsp[0].minor.yy368); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy182, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy29, yymsp[0].minor.yy574); } + yymsp[-4].minor.yy182 = yylhsminor.yy182; break; case 104: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy140 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy140, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy253); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy182, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy29); } + yymsp[-3].minor.yy182 = yylhsminor.yy182; break; case 105: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.yy140 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy253, yymsp[0].minor.yy368); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy182, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy29, yymsp[0].minor.yy574); } + yymsp[-4].minor.yy182 = yylhsminor.yy182; break; case 106: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.yy140 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy253, &yymsp[0].minor.yy253); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy182, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy29, &yymsp[0].minor.yy29); } + yymsp[-4].minor.yy182 = yylhsminor.yy182; break; case 107: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.yy140 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy253, yymsp[0].minor.yy368); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy182, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy29, yymsp[0].minor.yy574); } + yymsp[-4].minor.yy182 = yylhsminor.yy182; break; case 108: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy140 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy140, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy253); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy182, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy29); } + yymsp[-3].minor.yy182 = yylhsminor.yy182; break; case 109: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.yy140 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy253, yymsp[0].minor.yy368); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy182, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy29, yymsp[0].minor.yy574); } + yymsp[-4].minor.yy182 = yylhsminor.yy182; break; case 110: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.yy140 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy140, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy253, &yymsp[0].minor.yy253); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy182, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy29, &yymsp[0].minor.yy29); } + yymsp[-4].minor.yy182 = yylhsminor.yy182; break; case 111: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ -{ yylhsminor.yy140 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy140, &yymsp[-2].minor.yy253, yymsp[0].minor.yy140); } - yymsp[-5].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy182, &yymsp[-2].minor.yy29, yymsp[0].minor.yy182); } + yymsp[-5].minor.yy182 = yylhsminor.yy182; 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.yy220 = addNodeToList(pCxt, yymsp[-1].minor.yy220, yymsp[0].minor.yy140); } - yymsp[-1].minor.yy220 = yylhsminor.yy220; +{ yylhsminor.yy334 = addNodeToList(pCxt, yymsp[-1].minor.yy334, yymsp[0].minor.yy182); } + yymsp[-1].minor.yy334 = yylhsminor.yy334; 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.yy140 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy273, yymsp[-7].minor.yy140, yymsp[-5].minor.yy140, yymsp[-4].minor.yy220, yymsp[-1].minor.yy220); } - yymsp[-8].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy47, yymsp[-7].minor.yy182, yymsp[-5].minor.yy182, yymsp[-4].minor.yy334, yymsp[-1].minor.yy334); } + yymsp[-8].minor.yy182 = yylhsminor.yy182; break; case 117: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy140 = createDropTableClause(pCxt, yymsp[-1].minor.yy273, yymsp[0].minor.yy140); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createDropTableClause(pCxt, yymsp[-1].minor.yy47, yymsp[0].minor.yy182); } + yymsp[-1].minor.yy182 = yylhsminor.yy182; break; case 118: /* specific_tags_opt ::= */ case 149: /* tags_def_opt ::= */ yytestcase(yyruleno==149); - case 362: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==362); - case 379: /* group_by_clause_opt ::= */ yytestcase(yyruleno==379); - case 389: /* order_by_clause_opt ::= */ yytestcase(yyruleno==389); -{ yymsp[1].minor.yy220 = 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.yy334 = NULL; } break; case 119: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy220 = yymsp[-1].minor.yy220; } +{ yymsp[-2].minor.yy334 = yymsp[-1].minor.yy334; } break; case 120: /* full_table_name ::= table_name */ -{ yylhsminor.yy140 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy253, NULL); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy29, NULL); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 121: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy140 = createRealTableNode(pCxt, &yymsp[-2].minor.yy253, &yymsp[0].minor.yy253, NULL); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createRealTableNode(pCxt, &yymsp[-2].minor.yy29, &yymsp[0].minor.yy29, NULL); } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 124: /* column_def ::= column_name type_name */ -{ yylhsminor.yy140 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy253, yymsp[0].minor.yy368, NULL); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy29, yymsp[0].minor.yy574, NULL); } + yymsp[-1].minor.yy182 = yylhsminor.yy182; break; case 125: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy140 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy253, yymsp[-2].minor.yy368, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy29, yymsp[-2].minor.yy574, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy182 = yylhsminor.yy182; break; case 126: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_BOOL); } +{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_BOOL); } break; case 127: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_TINYINT); } +{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; case 128: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_SMALLINT); } +{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; case 129: /* type_name ::= INT */ case 130: /* type_name ::= INTEGER */ yytestcase(yyruleno==130); -{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_INT); } +{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_INT); } break; case 131: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_BIGINT); } +{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; case 132: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_FLOAT); } +{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; case 133: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_DOUBLE); } +{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; case 134: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy368 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy574 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; case 135: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } +{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; case 136: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy368 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy574 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; case 137: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy368 = createDataType(TSDB_DATA_TYPE_UTINYINT); } +{ yymsp[-1].minor.yy574 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; case 138: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy368 = createDataType(TSDB_DATA_TYPE_USMALLINT); } +{ yymsp[-1].minor.yy574 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; case 139: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy368 = createDataType(TSDB_DATA_TYPE_UINT); } +{ yymsp[-1].minor.yy574 = createDataType(TSDB_DATA_TYPE_UINT); } break; case 140: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy368 = createDataType(TSDB_DATA_TYPE_UBIGINT); } +{ yymsp[-1].minor.yy574 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; case 141: /* type_name ::= JSON */ -{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_JSON); } +{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_JSON); } break; case 142: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy368 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy574 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; case 143: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } +{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; case 144: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_BLOB); } +{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_BLOB); } break; case 145: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy368 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy574 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; case 146: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy368 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 147: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy368 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-3].minor.yy574 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 148: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy368 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-5].minor.yy574 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 150: /* tags_def_opt ::= tags_def */ - case 353: /* select_list ::= select_sublist */ yytestcase(yyruleno==353); -{ yylhsminor.yy220 = yymsp[0].minor.yy220; } - yymsp[0].minor.yy220 = yylhsminor.yy220; + case 354: /* select_list ::= select_sublist */ yytestcase(yyruleno==354); +{ yylhsminor.yy334 = yymsp[0].minor.yy334; } + yymsp[0].minor.yy334 = yylhsminor.yy334; break; case 151: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy220 = yymsp[-1].minor.yy220; } +{ yymsp[-3].minor.yy334 = yymsp[-1].minor.yy334; } break; case 152: /* table_options ::= */ -{ yymsp[1].minor.yy140 = createTableOptions(pCxt); } +{ yymsp[1].minor.yy182 = createTableOptions(pCxt); } break; case 153: /* table_options ::= table_options COMMENT NK_STRING */ -{ ((STableOptions*)yymsp[-2].minor.yy140)->pComments = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((STableOptions*)yymsp[-2].minor.yy182)->pComments = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 154: /* table_options ::= table_options KEEP integer_list */ -{ ((STableOptions*)yymsp[-2].minor.yy140)->pKeep = yymsp[0].minor.yy220; yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((STableOptions*)yymsp[-2].minor.yy182)->pKeep = yymsp[0].minor.yy334; yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 155: /* table_options ::= table_options TTL NK_INTEGER */ -{ ((STableOptions*)yymsp[-2].minor.yy140)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((STableOptions*)yymsp[-2].minor.yy182)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 156: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ ((STableOptions*)yymsp[-4].minor.yy140)->pSma = yymsp[-1].minor.yy220; yylhsminor.yy140 = yymsp[-4].minor.yy140; } - yymsp[-4].minor.yy140 = yylhsminor.yy140; +{ ((STableOptions*)yymsp[-4].minor.yy182)->pSma = yymsp[-1].minor.yy334; yylhsminor.yy182 = yymsp[-4].minor.yy182; } + yymsp[-4].minor.yy182 = yylhsminor.yy182; break; case 157: /* table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ -{ ((STableOptions*)yymsp[-4].minor.yy140)->pFuncs = yymsp[-1].minor.yy220; yylhsminor.yy140 = yymsp[-4].minor.yy140; } - yymsp[-4].minor.yy140 = yylhsminor.yy140; +{ ((STableOptions*)yymsp[-4].minor.yy182)->pFuncs = yymsp[-1].minor.yy334; yylhsminor.yy182 = yymsp[-4].minor.yy182; } + yymsp[-4].minor.yy182 = yylhsminor.yy182; break; case 158: /* table_options ::= table_options FILE_FACTOR NK_FLOAT */ -{ ((STableOptions*)yymsp[-2].minor.yy140)->pFilesFactor = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((STableOptions*)yymsp[-2].minor.yy182)->pFilesFactor = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 159: /* table_options ::= table_options DELAY NK_INTEGER */ -{ ((STableOptions*)yymsp[-2].minor.yy140)->pDelay = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy140 = yymsp[-2].minor.yy140; } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ ((STableOptions*)yymsp[-2].minor.yy182)->pDelay = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 160: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy140 = createTableOptions(pCxt); yylhsminor.yy140 = setTableAlterOption(pCxt, yylhsminor.yy140, &yymsp[0].minor.yy181); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createTableOptions(pCxt); yylhsminor.yy182 = setTableAlterOption(pCxt, yylhsminor.yy182, &yymsp[0].minor.yy515); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 161: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy140 = setTableAlterOption(pCxt, yymsp[-1].minor.yy140, &yymsp[0].minor.yy181); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = setTableAlterOption(pCxt, yymsp[-1].minor.yy182, &yymsp[0].minor.yy515); } + yymsp[-1].minor.yy182 = yylhsminor.yy182; break; case 162: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy181.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy181.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy515.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy515.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; case 163: /* alter_table_option ::= KEEP integer_list */ -{ yymsp[-1].minor.yy181.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy181.pList = yymsp[0].minor.yy220; } +{ yymsp[-1].minor.yy515.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy515.pList = yymsp[0].minor.yy334; } break; case 164: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy181.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy181.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy515.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy515.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 167: /* col_name ::= column_name */ -{ yylhsminor.yy140 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy253); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy29); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 168: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL, NULL); } @@ -3140,13 +3555,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.yy140, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy182, yymsp[0].minor.yy182); } 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.yy140, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy182, yymsp[0].minor.yy182); } break; case 173: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy140, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy182, NULL); } break; case 174: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL, NULL); } @@ -3161,7 +3576,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.yy140, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy182, yymsp[0].minor.yy182); } break; case 179: /* cmd ::= SHOW STREAMS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); } @@ -3180,13 +3595,13 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); } break; case 185: /* cmd ::= SHOW CREATE DATABASE db_name */ -{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy253); } +{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy29); } break; case 186: /* cmd ::= SHOW CREATE TABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy182); } break; case 187: /* cmd ::= SHOW CREATE STABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy182); } break; case 188: /* cmd ::= SHOW QUERIES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT, NULL, NULL); } @@ -3208,111 +3623,111 @@ static YYACTIONTYPE yy_reduce( break; case 194: /* db_name_cond_opt ::= */ case 199: /* from_db_opt ::= */ yytestcase(yyruleno==199); -{ yymsp[1].minor.yy140 = createDefaultDatabaseCondValue(pCxt); } +{ yymsp[1].minor.yy182 = createDefaultDatabaseCondValue(pCxt); } break; case 195: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy253); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy29); } + yymsp[-1].minor.yy182 = yylhsminor.yy182; break; case 196: /* like_pattern_opt ::= */ case 207: /* index_options ::= */ yytestcase(yyruleno==207); - case 360: /* where_clause_opt ::= */ yytestcase(yyruleno==360); - case 364: /* twindow_clause_opt ::= */ yytestcase(yyruleno==364); - case 369: /* sliding_opt ::= */ yytestcase(yyruleno==369); - case 371: /* fill_opt ::= */ yytestcase(yyruleno==371); - case 383: /* having_clause_opt ::= */ yytestcase(yyruleno==383); - case 391: /* slimit_clause_opt ::= */ yytestcase(yyruleno==391); - case 395: /* limit_clause_opt ::= */ yytestcase(yyruleno==395); -{ yymsp[1].minor.yy140 = NULL; } + 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.yy182 = NULL; } break; case 197: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; case 198: /* table_name_cond ::= table_name */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy253); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy29); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 200: /* from_db_opt ::= FROM db_name */ -{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy253); } +{ yymsp[-1].minor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy29); } break; case 203: /* func_name ::= function_name */ -{ yylhsminor.yy140 = createFunctionNode(pCxt, &yymsp[0].minor.yy253, NULL); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createFunctionNode(pCxt, &yymsp[0].minor.yy29, NULL); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; 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.yy273, &yymsp[-3].minor.yy253, &yymsp[-1].minor.yy253, NULL, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy47, &yymsp[-3].minor.yy29, &yymsp[-1].minor.yy29, NULL, yymsp[0].minor.yy182); } break; 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.yy273, &yymsp[-5].minor.yy253, &yymsp[-3].minor.yy253, yymsp[-1].minor.yy220, NULL); } +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy47, &yymsp[-5].minor.yy29, &yymsp[-3].minor.yy29, yymsp[-1].minor.yy334, NULL); } break; case 206: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy273, &yymsp[-2].minor.yy253, &yymsp[0].minor.yy253); } +{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy47, &yymsp[-2].minor.yy29, &yymsp[0].minor.yy29); } break; case 208: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ -{ yymsp[-8].minor.yy140 = createIndexOption(pCxt, yymsp[-6].minor.yy220, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), NULL, yymsp[0].minor.yy140); } +{ yymsp[-8].minor.yy182 = createIndexOption(pCxt, yymsp[-6].minor.yy334, releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), NULL, yymsp[0].minor.yy182); } break; 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.yy140 = createIndexOption(pCxt, yymsp[-8].minor.yy220, releaseRawExprNode(pCxt, yymsp[-4].minor.yy140), releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), yymsp[0].minor.yy140); } +{ yymsp[-10].minor.yy182 = createIndexOption(pCxt, yymsp[-8].minor.yy334, releaseRawExprNode(pCxt, yymsp[-4].minor.yy182), releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), yymsp[0].minor.yy182); } break; case 212: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy140 = createFunctionNode(pCxt, &yymsp[-3].minor.yy253, yymsp[-1].minor.yy220); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createFunctionNode(pCxt, &yymsp[-3].minor.yy29, yymsp[-1].minor.yy334); } + yymsp[-3].minor.yy182 = yylhsminor.yy182; break; case 213: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy273, &yymsp[-2].minor.yy253, yymsp[0].minor.yy140, NULL); } +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy47, &yymsp[-2].minor.yy29, yymsp[0].minor.yy182, NULL); } break; case 214: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy273, &yymsp[-2].minor.yy253, NULL, &yymsp[0].minor.yy253); } +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy47, &yymsp[-2].minor.yy29, NULL, &yymsp[0].minor.yy29); } break; case 215: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy273, &yymsp[0].minor.yy253); } +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy47, &yymsp[0].minor.yy29); } break; case 216: /* cmd ::= DESC full_table_name */ case 217: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==217); -{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy182); } break; case 218: /* cmd ::= RESET QUERY CACHE */ { pCxt->pRootNode = createResetQueryCacheStmt(pCxt); } break; case 219: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ -{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy273, yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy47, yymsp[-1].minor.yy182, yymsp[0].minor.yy182); } break; case 221: /* analyze_opt ::= ANALYZE */ case 229: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==229); - case 350: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==350); -{ yymsp[0].minor.yy273 = true; } + case 351: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==351); +{ yymsp[0].minor.yy47 = true; } break; case 222: /* explain_options ::= */ -{ yymsp[1].minor.yy140 = createDefaultExplainOptions(pCxt); } +{ yymsp[1].minor.yy182 = createDefaultExplainOptions(pCxt); } break; case 223: /* explain_options ::= explain_options VERBOSE NK_BOOL */ -{ yylhsminor.yy140 = setExplainVerbose(pCxt, yymsp[-2].minor.yy140, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = setExplainVerbose(pCxt, yymsp[-2].minor.yy182, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 224: /* explain_options ::= explain_options RATIO NK_FLOAT */ -{ yylhsminor.yy140 = setExplainRatio(pCxt, yymsp[-2].minor.yy140, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = setExplainRatio(pCxt, yymsp[-2].minor.yy182, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 225: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ -{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy220); } +{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy334); } break; 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.yy273, &yymsp[-5].minor.yy253, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy368, yymsp[0].minor.yy528); } +{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-7].minor.yy47, &yymsp[-5].minor.yy29, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy574, yymsp[0].minor.yy550); } break; case 227: /* cmd ::= DROP FUNCTION function_name */ -{ pCxt->pRootNode = createDropFunctionStmt(pCxt, &yymsp[0].minor.yy253); } +{ pCxt->pRootNode = createDropFunctionStmt(pCxt, &yymsp[0].minor.yy29); } break; case 230: /* bufsize_opt ::= */ -{ yymsp[1].minor.yy528 = 0; } +{ yymsp[1].minor.yy550 = 0; } break; case 231: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ -{ yymsp[-1].minor.yy528 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yymsp[-1].minor.yy550 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; case 232: /* cmd ::= CREATE STREAM stream_name INTO table_name AS query_expression */ -{ pCxt->pRootNode = createCreateStreamStmt(pCxt, &yymsp[-4].minor.yy253, &yymsp[-2].minor.yy253, yymsp[0].minor.yy140); } +{ pCxt->pRootNode = createCreateStreamStmt(pCxt, &yymsp[-4].minor.yy29, &yymsp[-2].minor.yy29, yymsp[0].minor.yy182); } break; case 233: /* cmd ::= DROP STREAM stream_name */ -{ pCxt->pRootNode = createDropStreamStmt(pCxt, &yymsp[0].minor.yy253); } +{ pCxt->pRootNode = createDropStreamStmt(pCxt, &yymsp[0].minor.yy29); } break; case 234: /* cmd ::= KILL CONNECTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &yymsp[0].minor.yy0); } @@ -3324,36 +3739,36 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; case 237: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ -{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy220); } +{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy334); } break; case 238: /* cmd ::= SPLIT VGROUP NK_INTEGER */ { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &yymsp[0].minor.yy0); } break; case 239: /* dnode_list ::= DNODE NK_INTEGER */ -{ yymsp[-1].minor.yy220 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } +{ yymsp[-1].minor.yy334 = 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.yy253); } +{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy29); } break; case 243: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 244: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 245: /* literal ::= NK_STRING */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 246: /* literal ::= NK_BOOL */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 247: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy182 = yylhsminor.yy182; break; case 248: /* literal ::= duration_literal */ case 257: /* signed_literal ::= signed */ yytestcase(yyruleno==257); @@ -3361,460 +3776,461 @@ static YYACTIONTYPE yy_reduce( case 278: /* expression ::= pseudo_column */ yytestcase(yyruleno==278); case 279: /* expression ::= column_reference */ yytestcase(yyruleno==279); case 283: /* expression ::= subquery */ yytestcase(yyruleno==283); - case 323: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==323); - case 327: /* boolean_primary ::= predicate */ yytestcase(yyruleno==327); - case 329: /* common_expression ::= expression */ yytestcase(yyruleno==329); - case 330: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==330); - case 332: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==332); - case 334: /* table_reference ::= table_primary */ yytestcase(yyruleno==334); - case 335: /* table_reference ::= joined_table */ yytestcase(yyruleno==335); - case 339: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==339); - case 386: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==386); - case 388: /* query_primary ::= query_specification */ yytestcase(yyruleno==388); -{ yylhsminor.yy140 = yymsp[0].minor.yy140; } - yymsp[0].minor.yy140 = yylhsminor.yy140; + 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.yy182 = yymsp[0].minor.yy182; } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 249: /* literal ::= NULL */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL)); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 250: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 251: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 252: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy182 = 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.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + yymsp[-1].minor.yy182 = yylhsminor.yy182; break; case 254: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 255: /* signed ::= NK_PLUS NK_FLOAT */ -{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; 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.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + yymsp[-1].minor.yy182 = yylhsminor.yy182; break; case 258: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 259: /* signed_literal ::= NK_BOOL */ -{ yylhsminor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 260: /* signed_literal ::= TIMESTAMP NK_STRING */ -{ yymsp[-1].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; case 261: /* signed_literal ::= duration_literal */ - case 356: /* select_item ::= common_expression */ yytestcase(yyruleno==356); - case 400: /* search_condition ::= common_expression */ yytestcase(yyruleno==400); -{ yylhsminor.yy140 = releaseRawExprNode(pCxt, yymsp[0].minor.yy140); } - yymsp[0].minor.yy140 = yylhsminor.yy140; + case 357: /* select_item ::= common_expression */ yytestcase(yyruleno==357); + case 401: /* search_condition ::= common_expression */ yytestcase(yyruleno==401); +{ yylhsminor.yy182 = releaseRawExprNode(pCxt, yymsp[0].minor.yy182); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 262: /* signed_literal ::= NULL */ -{ yymsp[0].minor.yy140 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } +{ yymsp[0].minor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } break; case 280: /* expression ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy253, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy253, yymsp[-1].minor.yy220)); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy29, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy29, yymsp[-1].minor.yy334)); } + yymsp[-3].minor.yy182 = yylhsminor.yy182; break; case 281: /* expression ::= function_name NK_LP NK_STAR NK_RP */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy253, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy253, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy29, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy29, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } + yymsp[-3].minor.yy182 = yylhsminor.yy182; break; case 282: /* expression ::= function_name NK_LP expression AS type_name NK_RP */ { - SNodeList *p = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy140)); - p = addValueNodeFromTypeToList(pCxt, yymsp[-1].minor.yy368, p); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy253, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-5].minor.yy253, p)); + SNodeList *p = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy182)); + p = addValueNodeFromTypeToList(pCxt, yymsp[-1].minor.yy574, p); + yylhsminor.yy182 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy29, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-5].minor.yy29, p)); } - yymsp[-5].minor.yy140 = yylhsminor.yy140; + yymsp[-5].minor.yy182 = yylhsminor.yy182; break; case 284: /* expression ::= NK_LP expression NK_RP */ - case 328: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==328); -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy140)); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 329: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==329); +{ yylhsminor.yy182 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy182)); } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 285: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy140)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy182); + yylhsminor.yy182 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy182)); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + yymsp[-1].minor.yy182 = yylhsminor.yy182; break; case 286: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy140), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy182); + yylhsminor.yy182 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy182), NULL)); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + yymsp[-1].minor.yy182 = yylhsminor.yy182; break; case 287: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy182); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy182); + yylhsminor.yy182 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), releaseRawExprNode(pCxt, yymsp[0].minor.yy182))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 288: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy182); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy182); + yylhsminor.yy182 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), releaseRawExprNode(pCxt, yymsp[0].minor.yy182))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 289: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy182); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy182); + yylhsminor.yy182 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), releaseRawExprNode(pCxt, yymsp[0].minor.yy182))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 290: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy182); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy182); + yylhsminor.yy182 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), releaseRawExprNode(pCxt, yymsp[0].minor.yy182))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 291: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy182); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy182); + yylhsminor.yy182 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), releaseRawExprNode(pCxt, yymsp[0].minor.yy182))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 292: /* expression_list ::= expression */ -{ yylhsminor.yy220 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy140)); } - yymsp[0].minor.yy220 = yylhsminor.yy220; +{ yylhsminor.yy334 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy182)); } + yymsp[0].minor.yy334 = yylhsminor.yy334; break; case 293: /* expression_list ::= expression_list NK_COMMA expression */ -{ yylhsminor.yy220 = addNodeToList(pCxt, yymsp[-2].minor.yy220, releaseRawExprNode(pCxt, yymsp[0].minor.yy140)); } - yymsp[-2].minor.yy220 = yylhsminor.yy220; +{ yylhsminor.yy334 = addNodeToList(pCxt, yymsp[-2].minor.yy334, releaseRawExprNode(pCxt, yymsp[0].minor.yy182)); } + yymsp[-2].minor.yy334 = yylhsminor.yy334; break; case 294: /* column_reference ::= column_name */ -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy253, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy253)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createRawExprNode(pCxt, &yymsp[0].minor.yy29, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy29)); } + yymsp[0].minor.yy182 = yylhsminor.yy182; break; case 295: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy253, &yymsp[0].minor.yy253, createColumnNode(pCxt, &yymsp[-2].minor.yy253, &yymsp[0].minor.yy253)); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; +{ yylhsminor.yy182 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy29, &yymsp[0].minor.yy29, createColumnNode(pCxt, &yymsp[-2].minor.yy29, &yymsp[0].minor.yy29)); } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; case 296: /* pseudo_column ::= NOW */ - case 297: /* pseudo_column ::= ROWTS */ yytestcase(yyruleno==297); - case 298: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==298); - case 299: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==299); - case 300: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==300); - case 301: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==301); - case 302: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==302); - case 303: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==303); -{ yylhsminor.yy140 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } - yymsp[0].minor.yy140 = yylhsminor.yy140; - break; - case 304: /* predicate ::= expression compare_op expression */ - case 309: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==309); + 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.yy182 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } + yymsp[0].minor.yy182 = yylhsminor.yy182; + 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.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy480, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy182); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy182); + yylhsminor.yy182 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy380, releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), releaseRawExprNode(pCxt, yymsp[0].minor.yy182))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; - case 305: /* predicate ::= expression BETWEEN expression AND expression */ + case 306: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy140), releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy182); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy182); + yylhsminor.yy182 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy182), releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), releaseRawExprNode(pCxt, yymsp[0].minor.yy182))); } - yymsp[-4].minor.yy140 = yylhsminor.yy140; + yymsp[-4].minor.yy182 = yylhsminor.yy182; break; - case 306: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 307: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[-5].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy182); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy182); + yylhsminor.yy182 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), releaseRawExprNode(pCxt, yymsp[-5].minor.yy182), releaseRawExprNode(pCxt, yymsp[0].minor.yy182))); } - yymsp[-5].minor.yy140 = yylhsminor.yy140; + yymsp[-5].minor.yy182 = yylhsminor.yy182; break; - case 307: /* predicate ::= expression IS NULL */ + case 308: /* predicate ::= expression IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy182); + yylhsminor.yy182 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), NULL)); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; - case 308: /* predicate ::= expression IS NOT NULL */ + case 309: /* predicate ::= expression IS NOT NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy140), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy182); + yylhsminor.yy182 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy182), NULL)); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + yymsp[-3].minor.yy182 = yylhsminor.yy182; break; - case 310: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy480 = OP_TYPE_LOWER_THAN; } + case 311: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy380 = OP_TYPE_LOWER_THAN; } break; - case 311: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy480 = OP_TYPE_GREATER_THAN; } + case 312: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy380 = OP_TYPE_GREATER_THAN; } break; - case 312: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy480 = OP_TYPE_LOWER_EQUAL; } + case 313: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy380 = OP_TYPE_LOWER_EQUAL; } break; - case 313: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy480 = OP_TYPE_GREATER_EQUAL; } + case 314: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy380 = OP_TYPE_GREATER_EQUAL; } break; - case 314: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy480 = OP_TYPE_NOT_EQUAL; } + case 315: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy380 = OP_TYPE_NOT_EQUAL; } break; - case 315: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy480 = OP_TYPE_EQUAL; } + case 316: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy380 = OP_TYPE_EQUAL; } break; - case 316: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy480 = OP_TYPE_LIKE; } + case 317: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy380 = OP_TYPE_LIKE; } break; - case 317: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy480 = OP_TYPE_NOT_LIKE; } + case 318: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy380 = OP_TYPE_NOT_LIKE; } break; - case 318: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy480 = OP_TYPE_MATCH; } + case 319: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy380 = OP_TYPE_MATCH; } break; - case 319: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy480 = OP_TYPE_NMATCH; } + case 320: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy380 = OP_TYPE_NMATCH; } break; - case 320: /* in_op ::= IN */ -{ yymsp[0].minor.yy480 = OP_TYPE_IN; } + case 321: /* in_op ::= IN */ +{ yymsp[0].minor.yy380 = OP_TYPE_IN; } break; - case 321: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy480 = OP_TYPE_NOT_IN; } + case 322: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy380 = OP_TYPE_NOT_IN; } break; - case 322: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy220)); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 323: /* in_predicate_value ::= NK_LP expression_list NK_RP */ +{ yylhsminor.yy182 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy334)); } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; - case 324: /* boolean_value_expression ::= NOT boolean_primary */ + case 325: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy140), NULL)); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy182); + yylhsminor.yy182 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy182), NULL)); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + yymsp[-1].minor.yy182 = yylhsminor.yy182; break; - case 325: /* 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.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy182); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy182); + yylhsminor.yy182 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), releaseRawExprNode(pCxt, yymsp[0].minor.yy182))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; - case 326: /* 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.yy140); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy140); - yylhsminor.yy140 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy182); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy182); + yylhsminor.yy182 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), releaseRawExprNode(pCxt, yymsp[0].minor.yy182))); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; - case 331: /* from_clause ::= FROM table_reference_list */ - case 361: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==361); - case 384: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==384); -{ yymsp[-1].minor.yy140 = yymsp[0].minor.yy140; } + 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.yy182 = yymsp[0].minor.yy182; } break; - case 333: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy140 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy140, yymsp[0].minor.yy140, NULL); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 334: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy182 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy182, yymsp[0].minor.yy182, NULL); } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; - case 336: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy140 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy253, &yymsp[0].minor.yy253); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 337: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy182 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy29, &yymsp[0].minor.yy29); } + yymsp[-1].minor.yy182 = yylhsminor.yy182; break; - case 337: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy140 = createRealTableNode(pCxt, &yymsp[-3].minor.yy253, &yymsp[-1].minor.yy253, &yymsp[0].minor.yy253); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + case 338: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy182 = createRealTableNode(pCxt, &yymsp[-3].minor.yy29, &yymsp[-1].minor.yy29, &yymsp[0].minor.yy29); } + yymsp[-3].minor.yy182 = yylhsminor.yy182; break; - case 338: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy140 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy140), &yymsp[0].minor.yy253); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 339: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy182 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy182), &yymsp[0].minor.yy29); } + yymsp[-1].minor.yy182 = yylhsminor.yy182; break; - case 340: /* alias_opt ::= */ -{ yymsp[1].minor.yy253 = nil_token; } + case 341: /* alias_opt ::= */ +{ yymsp[1].minor.yy29 = nil_token; } break; - case 341: /* alias_opt ::= table_alias */ -{ yylhsminor.yy253 = yymsp[0].minor.yy253; } - yymsp[0].minor.yy253 = yylhsminor.yy253; + case 342: /* alias_opt ::= table_alias */ +{ yylhsminor.yy29 = yymsp[0].minor.yy29; } + yymsp[0].minor.yy29 = yylhsminor.yy29; break; - case 342: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy253 = yymsp[0].minor.yy253; } + case 343: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy29 = yymsp[0].minor.yy29; } break; - case 343: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 344: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==344); -{ yymsp[-2].minor.yy140 = yymsp[-1].minor.yy140; } + 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.yy182 = yymsp[-1].minor.yy182; } break; - case 345: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy140 = createJoinTableNode(pCxt, yymsp[-4].minor.yy224, yymsp[-5].minor.yy140, yymsp[-2].minor.yy140, yymsp[0].minor.yy140); } - yymsp[-5].minor.yy140 = yylhsminor.yy140; + case 346: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy182 = createJoinTableNode(pCxt, yymsp[-4].minor.yy162, yymsp[-5].minor.yy182, yymsp[-2].minor.yy182, yymsp[0].minor.yy182); } + yymsp[-5].minor.yy182 = yylhsminor.yy182; break; - case 346: /* join_type ::= */ -{ yymsp[1].minor.yy224 = JOIN_TYPE_INNER; } + case 347: /* join_type ::= */ +{ yymsp[1].minor.yy162 = JOIN_TYPE_INNER; } break; - case 347: /* join_type ::= INNER */ -{ yymsp[0].minor.yy224 = JOIN_TYPE_INNER; } + case 348: /* join_type ::= INNER */ +{ yymsp[0].minor.yy162 = JOIN_TYPE_INNER; } break; - case 348: /* 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.yy140 = createSelectStmt(pCxt, yymsp[-7].minor.yy273, yymsp[-6].minor.yy220, yymsp[-5].minor.yy140); - yymsp[-8].minor.yy140 = addWhereClause(pCxt, yymsp[-8].minor.yy140, yymsp[-4].minor.yy140); - yymsp[-8].minor.yy140 = addPartitionByClause(pCxt, yymsp[-8].minor.yy140, yymsp[-3].minor.yy220); - yymsp[-8].minor.yy140 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy140, yymsp[-2].minor.yy140); - yymsp[-8].minor.yy140 = addGroupByClause(pCxt, yymsp[-8].minor.yy140, yymsp[-1].minor.yy220); - yymsp[-8].minor.yy140 = addHavingClause(pCxt, yymsp[-8].minor.yy140, yymsp[0].minor.yy140); + yymsp[-8].minor.yy182 = createSelectStmt(pCxt, yymsp[-7].minor.yy47, yymsp[-6].minor.yy334, yymsp[-5].minor.yy182); + yymsp[-8].minor.yy182 = addWhereClause(pCxt, yymsp[-8].minor.yy182, yymsp[-4].minor.yy182); + yymsp[-8].minor.yy182 = addPartitionByClause(pCxt, yymsp[-8].minor.yy182, yymsp[-3].minor.yy334); + yymsp[-8].minor.yy182 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy182, yymsp[-2].minor.yy182); + yymsp[-8].minor.yy182 = addGroupByClause(pCxt, yymsp[-8].minor.yy182, yymsp[-1].minor.yy334); + yymsp[-8].minor.yy182 = addHavingClause(pCxt, yymsp[-8].minor.yy182, yymsp[0].minor.yy182); } break; - case 351: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy273 = false; } + case 352: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy47 = false; } break; - case 352: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy220 = NULL; } + case 353: /* select_list ::= NK_STAR */ +{ yymsp[0].minor.yy334 = NULL; } break; - case 357: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy140 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy140), &yymsp[0].minor.yy253); } - yymsp[-1].minor.yy140 = yylhsminor.yy140; + case 358: /* select_item ::= common_expression column_alias */ +{ yylhsminor.yy182 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy182), &yymsp[0].minor.yy29); } + yymsp[-1].minor.yy182 = yylhsminor.yy182; break; - case 358: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy140 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), &yymsp[0].minor.yy253); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 359: /* select_item ::= common_expression AS column_alias */ +{ yylhsminor.yy182 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), &yymsp[0].minor.yy29); } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; - case 359: /* select_item ::= table_name NK_DOT NK_STAR */ -{ yylhsminor.yy140 = createColumnNode(pCxt, &yymsp[-2].minor.yy253, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 360: /* select_item ::= table_name NK_DOT NK_STAR */ +{ yylhsminor.yy182 = createColumnNode(pCxt, &yymsp[-2].minor.yy29, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; - case 363: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 380: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==380); - case 390: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==390); -{ yymsp[-2].minor.yy220 = yymsp[0].minor.yy220; } + 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.yy334 = yymsp[0].minor.yy334; } break; - case 365: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -{ yymsp[-5].minor.yy140 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy140), releaseRawExprNode(pCxt, yymsp[-1].minor.yy140)); } + case 366: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ +{ yymsp[-5].minor.yy182 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy182), releaseRawExprNode(pCxt, yymsp[-1].minor.yy182)); } break; - case 366: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ -{ yymsp[-3].minor.yy140 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy140)); } + case 367: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ +{ yymsp[-3].minor.yy182 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy182)); } break; - case 367: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy140 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy140), NULL, yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } + case 368: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy182 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy182), NULL, yymsp[-1].minor.yy182, yymsp[0].minor.yy182); } break; - case 368: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy140 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy140), releaseRawExprNode(pCxt, yymsp[-3].minor.yy140), yymsp[-1].minor.yy140, yymsp[0].minor.yy140); } + case 369: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy182 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy182), releaseRawExprNode(pCxt, yymsp[-3].minor.yy182), yymsp[-1].minor.yy182, yymsp[0].minor.yy182); } break; - case 370: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ -{ yymsp[-3].minor.yy140 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy140); } + case 371: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ +{ yymsp[-3].minor.yy182 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy182); } break; - case 372: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy140 = createFillNode(pCxt, yymsp[-1].minor.yy174, NULL); } + case 373: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy182 = createFillNode(pCxt, yymsp[-1].minor.yy144, NULL); } break; - case 373: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy140 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy220)); } + case 374: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy182 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy334)); } break; - case 374: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy174 = FILL_MODE_NONE; } + case 375: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy144 = FILL_MODE_NONE; } break; - case 375: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy174 = FILL_MODE_PREV; } + case 376: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy144 = FILL_MODE_PREV; } break; - case 376: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy174 = FILL_MODE_NULL; } + case 377: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy144 = FILL_MODE_NULL; } break; - case 377: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy174 = FILL_MODE_LINEAR; } + case 378: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy144 = FILL_MODE_LINEAR; } break; - case 378: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy174 = FILL_MODE_NEXT; } + case 379: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy144 = FILL_MODE_NEXT; } break; - case 381: /* group_by_list ::= expression */ -{ yylhsminor.yy220 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } - yymsp[0].minor.yy220 = yylhsminor.yy220; + case 382: /* group_by_list ::= expression */ +{ yylhsminor.yy334 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy182))); } + yymsp[0].minor.yy334 = yylhsminor.yy334; break; - case 382: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy220 = addNodeToList(pCxt, yymsp[-2].minor.yy220, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy140))); } - yymsp[-2].minor.yy220 = yylhsminor.yy220; + case 383: /* group_by_list ::= group_by_list NK_COMMA expression */ +{ yylhsminor.yy334 = addNodeToList(pCxt, yymsp[-2].minor.yy334, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy182))); } + yymsp[-2].minor.yy334 = yylhsminor.yy334; break; - case 385: /* 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.yy140 = addOrderByClause(pCxt, yymsp[-3].minor.yy140, yymsp[-2].minor.yy220); - yylhsminor.yy140 = addSlimitClause(pCxt, yylhsminor.yy140, yymsp[-1].minor.yy140); - yylhsminor.yy140 = addLimitClause(pCxt, yylhsminor.yy140, yymsp[0].minor.yy140); + yylhsminor.yy182 = addOrderByClause(pCxt, yymsp[-3].minor.yy182, yymsp[-2].minor.yy334); + yylhsminor.yy182 = addSlimitClause(pCxt, yylhsminor.yy182, yymsp[-1].minor.yy182); + yylhsminor.yy182 = addLimitClause(pCxt, yylhsminor.yy182, yymsp[0].minor.yy182); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + yymsp[-3].minor.yy182 = yylhsminor.yy182; break; - case 387: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy140 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy140, yymsp[0].minor.yy140); } - yymsp[-3].minor.yy140 = yylhsminor.yy140; + case 388: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ +{ yylhsminor.yy182 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy182, yymsp[0].minor.yy182); } + yymsp[-3].minor.yy182 = yylhsminor.yy182; break; - case 392: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 396: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==396); -{ yymsp[-1].minor.yy140 = 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.yy182 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 393: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 397: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==397); -{ yymsp[-3].minor.yy140 = 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.yy182 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 394: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 398: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==398); -{ yymsp[-3].minor.yy140 = 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.yy182 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 399: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy140 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy140); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 400: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy182 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy182); } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; - case 403: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy140 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy140), yymsp[-1].minor.yy238, yymsp[0].minor.yy69); } - yymsp[-2].minor.yy140 = yylhsminor.yy140; + case 404: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy182 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), yymsp[-1].minor.yy218, yymsp[0].minor.yy487); } + yymsp[-2].minor.yy182 = yylhsminor.yy182; break; - case 404: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy238 = ORDER_ASC; } + case 405: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy218 = ORDER_ASC; } break; - case 405: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy238 = ORDER_ASC; } + case 406: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy218 = ORDER_ASC; } break; - case 406: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy238 = ORDER_DESC; } + case 407: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy218 = ORDER_DESC; } break; - case 407: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy69 = NULL_ORDER_DEFAULT; } + case 408: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy487 = NULL_ORDER_DEFAULT; } break; - case 408: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy69 = NULL_ORDER_FIRST; } + case 409: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy487 = NULL_ORDER_FIRST; } break; - case 409: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy69 = NULL_ORDER_LAST; } + case 410: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy487 = 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/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 1d8400e1ebe0c96d8531cba65786a0d72c8b1787..3c60b62434cc0e202771883cc8dc0d52249410be 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -694,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 c56e113d4072743f776749e43cc22f5357832e1d..19e6718fe8236149d3717f0e0f1344d83160c800 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -41,6 +41,21 @@ typedef struct SOsdInfo { 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; @@ -152,36 +167,229 @@ static int32_t cpdOptimizeScanCondition(SOptimizeContext* pCxt, SScanLogicNode* return TSDB_CODE_SUCCESS; } -static int32_t cpdPartitionCondition(SJoinLogicNode* pJoin, SNodeList** pMultiTableCond, SNodeList** pSingleTableCond) { - // 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 int32_t cpdPushJoinCondToOnCond(SOptimizeContext* pCxt, SJoinLogicNode* pJoin, SNodeList* pMultiTableCond) { - // todo - return TSDB_CODE_SUCCESS; +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 int32_t cpdPushJoinCondToChildren(SOptimizeContext* pCxt, SJoinLogicNode* pJoin, SNodeList* pSingleTableCond) { - // todo +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; + return TSDB_CODE_SUCCESS; } -static int32_t cpdPushJoinCondition(SOptimizeContext* pCxt, SJoinLogicNode* pJoin) { - if (NULL != pJoin->node.pConditions) { - SNodeList* pMultiTableCond = NULL; - SNodeList* pSingleTableCond = NULL; - int32_t code = cpdPartitionCondition(pJoin, &pMultiTableCond, &pSingleTableCond); - if (TSDB_CODE_SUCCESS == code && NULL != pMultiTableCond) { - code = cpdPushJoinCondToOnCond(pCxt, pJoin, pMultiTableCond); +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 && NULL != pSingleTableCond) { - code = cpdPushJoinCondToChildren(pCxt, pJoin, pSingleTableCond); + 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; diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c index 0b21052955a6cb6609f2e838444e121714274373..e54cf339347ce7955c830149b6f0e4f6655ef84e 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -18,6 +18,7 @@ #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) @@ -39,43 +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 void stsFindSplitNode(SLogicSubplan* pSubplan, SStsInfo* pInfo) { - SLogicNode* pSplitNode = stsMatchByNode(pSubplan->pNode); - if (NULL != pSplitNode) { - pInfo->pScan = (SScanLogicNode*)pSplitNode; - pInfo->pSubplan = pSubplan; - } -} -static void stsMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan, SStsInfo* pInfo) { - if (!SPLIT_FLAG_TEST_MASK(pSubplan->splitFlag, SPLIT_FLAG_STS)) { - stsFindSplitNode(pSubplan, pInfo); - } - SNode* pChild; - FOREACH(pChild, pSubplan->pChildren) { - stsMatch(pCxt, (SLogicSubplan*)pChild, pInfo); - if (NULL != pInfo->pScan) { - break; - } - } - return; -} +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; @@ -84,11 +56,11 @@ 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; @@ -119,10 +91,100 @@ static int32_t stsCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubpla return TSDB_CODE_FAILED; } +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}; - stsMatch(pCxt, pSubplan, &info); - if (NULL == info.pScan) { + 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(info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_STS)); + if (TSDB_CODE_SUCCESS == code) { + code = splCreateExchangeNode(pCxt, info.pSubplan, info.pScan, SUBPLAN_TYPE_MERGE); + } + ++(pCxt->groupId); + 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) { @@ -131,9 +193,9 @@ static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { return TSDB_CODE_OUT_OF_MEMORY; } } - int32_t code = nodesListStrictAppend(info.pSubplan->pChildren, stsCreateScanSubplan(pCxt, info.pScan)); + int32_t code = nodesListStrictAppend(info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_CTJ)); if (TSDB_CODE_SUCCESS == code) { - code = stsCreateExchangeNode(pCxt, info.pSubplan, info.pScan); + code = splCreateExchangeNode(pCxt, info.pSubplan, info.pScan, info.pSubplan->subplanType); } ++(pCxt->groupId); pCxt->split = true; @@ -141,7 +203,8 @@ static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { } static const SSplitRule splitRuleSet[] = { - { .pName = "SuperTableScan", .splitFunc = stsSplit } + { .pName = "SuperTableScan", .splitFunc = stsSplit }, + { .pName = "ChildTableJoin", .splitFunc = ctjSplit }, }; static const int32_t splitRuleNum = (sizeof(splitRuleSet) / sizeof(SSplitRule)); diff --git a/source/libs/planner/test/plannerTest.cpp b/source/libs/planner/test/plannerTest.cpp index fd0084c01ecd8ae830ba615cfa26d2d490fcf68e..69c76fc3aef0433656d046abf9a226506d4970fd 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) { @@ -174,13 +180,13 @@ TEST_F(PlannerTest, selectStableBasic) { TEST_F(PlannerTest, selectJoin) { setDatabase("root", "test"); - bind("SELECT * FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); - ASSERT_TRUE(run()); + // bind("SELECT t1.c1, t2.c2 FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); + // ASSERT_TRUE(run()); - bind("SELECT * FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1"); - ASSERT_TRUE(run()); + // bind("SELECT t1.*, t2.* FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); + // ASSERT_TRUE(run()); - bind("SELECT t1.* FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1"); + 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()); } 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/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 0ab0052624fdcf57cd67a1f3552daade82e3b493..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; } } @@ -840,7 +858,7 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam * memmove(fraction, fraction + TSDB_TIME_PRECISION_SEC_DIGITS, TSDB_TIME_PRECISION_SEC_DIGITS); } - struct tm *tmInfo = localtime((const time_t *)&timeVal); + 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); @@ -872,6 +890,375 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam * 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/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/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/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/os/src/osFile.c b/source/os/src/osFile.c index 4bd6b9e5cdb5b0b86ebcb7985a0f7349672495e7..4b55d4912cba3157186b3a6aaf557e964866a4ca 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -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/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/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/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/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/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 c5c041be91719f7385e623ffa78e99fa9b6e8ff7..8dc7fb920effa5554fd0fc77d11fdd27971e8e95 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -56,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 @@ -72,7 +81,8 @@ # --- for multi process mode ./test.sh -f tsim/user/basic1.sim -m ./test.sh -f tsim/db/basic3.sim -m -./test.sh -f tsim/insert/backquote.sim +./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 @@ -80,4 +90,7 @@ ./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..7721f21db7470b223ef7d4e4317b9e36a75349f8 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=" 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/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/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 index 3a1ec523fe8f449fc884e8e3867dadde32898715..6c9a7c5a7a96c1b8572c1abde35d7a6964a38cc3 100644 --- a/tests/script/tsim/query/complex_group.sim +++ b/tests/script/tsim/query/complex_group.sim @@ -25,7 +25,7 @@ sql connect print =============== create database sql create database db sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi @@ -97,167 +97,167 @@ 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 != 8 then +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 != 8 then +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 != 8 then +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 != 8 then +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 != 8 then +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 != 8 then +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 != 2 then +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 != 8 then +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 != 8 then +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 != 8 then +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 2 +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 c7 limit 1 offset 1 -print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 @@ -307,170 +307,170 @@ 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 != 8 then +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 != 8 then +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 != 8 then +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 != 8 then +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 != 8 then +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 != 8 then +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 != 2 then +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 != 8 then +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 != 8 then +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 != 8 then +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 2 +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 c7 limit 1 offset 1 -print ====> sql : select abs(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select acos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select asin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select atan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select ceil(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select cos(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select floor(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select log(c1,10) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select pow(c1,3) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select round(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select sqrt(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select sin(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 c7 limit 1 offset 1 -print ====> sql : select tan(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 2 +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 +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 index 10283153d89c1cd6839db0b1cdc24b7f562fd623..86d4f7d4ca109035f1f9420debf449d18a5f89b9 100644 --- a/tests/script/tsim/query/complex_having.sim +++ b/tests/script/tsim/query/complex_having.sim @@ -25,7 +25,7 @@ sql connect print =============== create database sql create database db sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi diff --git a/tests/script/tsim/query/complex_limit.sim b/tests/script/tsim/query/complex_limit.sim index ac251356859c3c6865f4088843d37168aa87bc56..1691f2d443a70cd7124e9cc53a63f633b3cf3b40 100644 --- a/tests/script/tsim/query/complex_limit.sim +++ b/tests/script/tsim/query/complex_limit.sim @@ -24,11 +24,6 @@ sql connect print =============== create database sql create database db -sql show databases -if $rows != 2 then - return -1 -endi - sql use db print =============== create super table and child table diff --git a/tests/script/tsim/query/complex_select.sim b/tests/script/tsim/query/complex_select.sim index 1696d22da7798d3268385a5a7cbde7b3bbff9d6c..1ebcb2f49a2c2ee3aa3e6b42efa9e8e70fccb1d6 100644 --- a/tests/script/tsim/query/complex_select.sim +++ b/tests/script/tsim/query/complex_select.sim @@ -24,11 +24,6 @@ sql connect print =============== create database sql create database db -sql show databases -if $rows != 2 then - return -1 -endi - sql use db print =============== create super table and child table @@ -114,14 +109,14 @@ print ====> rows0: $data00, $data01, $data02, $data03, $data04, $data05, $data06 if $rows != 1 then return -1 endi -if $data01 != 2 then +if $data01 != 3 then return -1 endi -sql select * from ct1 limit 2 offset 1 +sql select * from ct1 limit 2 offset 7 print ====> sql : select * from ct1 limit 2 offset 7 print ====> rows: $rows -if $rows != 2 then +if $rows != 1 then return -1 endi if $data01 != 8 then diff --git a/tests/script/tsim/query/complex_where.sim b/tests/script/tsim/query/complex_where.sim index 7a5de85a3c39cc8cffcba644125a321ea5e2f619..7cd576400f544379d50c7b777a701abefed4950b 100644 --- a/tests/script/tsim/query/complex_where.sim +++ b/tests/script/tsim/query/complex_where.sim @@ -25,7 +25,7 @@ sql connect print =============== create database sql create database db sql show databases -if $rows != 2 then +if $rows != 3 then return -1 endi @@ -192,14 +192,14 @@ if $data01 != 1 then return -1 endi -sql select c1 from stb1 where stb1 > 5 and c1 <= 6 +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 != 4 then +if $rows != 3 then return -1 endi -if $data01 != 6 then +if $data00 != 6 then return -1 endi @@ -210,7 +210,7 @@ print ====> rows0: $data00 if $rows != 32 then return -1 endi -if $data01 != 1 then +if $data00 != 1 then return -1 endi @@ -221,7 +221,7 @@ print ====> rows0: $data00 if $rows != 17 then return -1 endi -if $data01 != 5 then +if $data00 != 5 then return -1 endi @@ -240,7 +240,7 @@ 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 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) @@ -272,98 +272,98 @@ endi print ================ query 2 complex with where -sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 @@ -510,14 +510,14 @@ if $data01 != 1 then return -1 endi -sql select c1 from stb1 where stb1 > 5 and c1 <= 6 +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 != 4 then +if $rows != 3 then return -1 endi -if $data01 != 6 then +if $data00 != 6 then return -1 endi @@ -528,7 +528,7 @@ print ====> rows0: $data00 if $rows != 32 then return -1 endi -if $data01 != 1 then +if $data00 != 1 then return -1 endi @@ -539,7 +539,7 @@ print ====> rows0: $data00 if $rows != 17 then return -1 endi -if $data01 != 5 then +if $data00 != 5 then return -1 endi @@ -558,7 +558,7 @@ 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 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) @@ -590,98 +590,98 @@ endi print ================ query 2 complex with where -sql select count(c1) from ct3 where c1 > 2 group by c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 c7 limit 1 offset 1 +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 diff --git a/tests/script/tsim/query/diff.sim b/tests/script/tsim/query/diff.sim index c55b080e4439613bb28182d6b75e1420e3efa84c..7bfeeeba7fd856392cbb0e46331d22a4fba31c41 100644 --- a/tests/script/tsim/query/diff.sim +++ b/tests/script/tsim/query/diff.sim @@ -123,7 +123,7 @@ step6: 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/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 282d83bc276bbc82e4555c80a43da3ffc7d459e0..3aee8386257b316f3c1d9f93af8d5b1b0d97ecb3 100644 --- a/tests/script/tsim/query/session.sim +++ b/tests/script/tsim/query/session.sim @@ -256,7 +256,7 @@ endi # $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 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 index a349c55dbdd9facc451e8bba3d91fae9a2110736..0df74d53f860b2b3db55e7957b111c0d5e818e89 100644 --- a/tests/script/tsim/tmq/insertDataV1.sim +++ b/tests/script/tsim/tmq/insertDataV1.sim @@ -22,23 +22,19 @@ while $i < $tbNum $x = 0 while $x < $rowNum - $c = $x / 10 - $c = $c * 10 - $c = $x - $c - $binary = ' . binary - $binary = $binary . $c + $binary = $binary . $i $binary = $binary . ' - #print ====> insert into $tb values ($tstart , $c , $x , $binary ) - #print ====> insert into ntb values ($tstart , $c , $x , $binary ) - sql insert into $tb values ($tstart , $c , $x , $binary ) - sql insert into ntb values ($tstart , $c , $x , $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 + print ====> insert rows: $rowNum into $tb and ntb $i = $i + 1 # $tstart = 1640966400000 diff --git a/tests/script/tsim/tmq/insertDataV4.sim b/tests/script/tsim/tmq/insertDataV4.sim index 72c1358e7f30e750ef0f3bbba8d15bf27513dbb2..dbd52f56b8b79afceafe3c9faede8ebe99bc94a3 100644 --- a/tests/script/tsim/tmq/insertDataV4.sim +++ b/tests/script/tsim/tmq/insertDataV4.sim @@ -22,18 +22,14 @@ while $i < $tbNum $x = 0 while $x < $rowNum - $c = $x / 10 - $c = $c * 10 - $c = $x - $c - $binary = ' . binary - $binary = $binary . $c + $binary = $binary . $i $binary = $binary . ' - #print ====> insert into $tb values ($tstart , $c , $x , $binary ) - #print ====> insert into ntb values ($tstart , $c , $x , $binary ) - sql insert into $tb values ($tstart , $c , $x , $binary ) - sql insert into ntb values ($tstart , $c , $x , $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 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 index 0df7a8ba57de9a25e75d079fe6898af0e99e1b9f..2e2534d104ae270c221b5fa02bdc0f0c44e07bf5 100644 --- a/tests/script/tsim/tmq/mainConsumerInMultiTopic.sim +++ b/tests/script/tsim/tmq/mainConsumerInMultiTopic.sim @@ -42,36 +42,6 @@ $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 @@ -120,9 +90,9 @@ endi print =============== run_back insert data if $loop_cnt == 0 then - run_back tsim/tmq/insertDataV1.sim + run_back tsim/tmq/insertFixedDataV2.sim else - run_back tsim/tmq/insertDataV4.sim + run_back tsim/tmq/insertFixedDataV4.sim endi #sleep 1000 @@ -162,9 +132,16 @@ endi # -g showMsgFlag, default is 0 # -$consumeDelay = 50 -$consumeMsgCntFromTopic = 1000 -print consumeMsgCntFromTopic: $consumeMsgCntFromTopic , consumeDelay: $consumeDelay +$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: @@ -177,49 +154,51 @@ print consumeMsgCntFromTopic: $consumeMsgCntFromTopic , consumeDelay: $consumeDe # td.connect.db:db $numOfTopics = 2 -$expectConsumeMsgCnt = $consumeMsgCntFromTopic * $numOfTopics +$expectMsgCntFromStb = $expectMsgCntFromStb * $numOfTopics $expect_result = @{consume success: @ -$expect_result = $expect_result . $expectConsumeMsgCnt +$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 $expectConsumeMsgCnt -#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 $expectConsumeMsgCnt -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 $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +#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 +if $system_content != $expect_result then + print expect @{consume success: 20000, 0}@ , actual @system_content return -1 endi $numOfTopics = 3 -$expectConsumeMsgCnt = $consumeMsgCntFromTopic * $numOfTopics +$expectMsgCntFromCtb = $expectMsgCntFromCtb * $numOfTopics $expect_result = @{consume success: @ -$expect_result = $expect_result . $expectConsumeMsgCnt +$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 $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +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 < $expectConsumeMsgCnt then +if $system_content != $expect_result then return -1 endi $numOfTopics = 3 -$expectConsumeMsgCnt = $consumeMsgCntFromTopic * $numOfTopics +$expectMsgCntFromNtb = $expectMsgCntFromNtb * $tbNum +$expectMsgCntFromNtb = $expectMsgCntFromNtb * $numOfTopics $expect_result = @{consume success: @ -$expect_result = $expect_result . $expectConsumeMsgCnt +$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 $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +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 < $expectConsumeMsgCnt then +if $system_content != $expect_result then return -1 endi diff --git a/tests/script/tsim/tmq/mainConsumerInOneTopic.sim b/tests/script/tsim/tmq/mainConsumerInOneTopic.sim index b9a867921e79d7323c59e6759381b2f70d39baf5..d3077238781be7e027553b69738a7be41a97ee9d 100644 --- a/tests/script/tsim/tmq/mainConsumerInOneTopic.sim +++ b/tests/script/tsim/tmq/mainConsumerInOneTopic.sim @@ -42,36 +42,6 @@ $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 @@ -120,9 +90,9 @@ endi print =============== run_back insert data if $loop_cnt == 0 then - run_back tsim/tmq/insertDataV1.sim + run_back tsim/tmq/insertFixedDataV2.sim else - run_back tsim/tmq/insertDataV4.sim + run_back tsim/tmq/insertFixedDataV4.sim endi #sleep 1000 @@ -162,9 +132,15 @@ endi # -g showMsgFlag, default is 0 # -$consumeDelay = 50 -$expectConsumeMsgCnt = 1000 -print expectConsumeMsgCnt: $expectConsumeMsgCnt , consumeDelay: $consumeDelay +$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: @@ -177,82 +153,82 @@ print expectConsumeMsgCnt: $expectConsumeMsgCnt , consumeDelay: $consumeDelay # td.connect.db:db $expect_result = @{consume success: @ -$expect_result = $expect_result . $expectConsumeMsgCnt +$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 $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +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 < $expectConsumeMsgCnt 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_all" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt -#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 $expectConsumeMsgCnt +#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 < $expectConsumeMsgCnt 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 $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +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 < $expectConsumeMsgCnt then +if $system_content != $expect_result then return -1 endi $expect_result = @{consume success: @ -$expect_result = $expect_result . $rowNum +$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 $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +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 < $expectConsumeMsgCnt 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_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +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 < $expectConsumeMsgCnt 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_ctb_function" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +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 < $expectConsumeMsgCnt then +if $system_content != $expect_result then return -1 endi $expect_result = @{consume success: @ -$expect_result = $expect_result . $totalMsgCnt +$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 $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +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 < $expectConsumeMsgCnt 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_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +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 < $expectConsumeMsgCnt 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_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +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 < $expectConsumeMsgCnt then +if $system_content != $expect_result then return -1 endi 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/consumerMain.sim b/tests/script/tsim/tmq/overlapTopic2Con1Cgrp.sim similarity index 57% rename from tests/script/tsim/tmq/consumerMain.sim rename to tests/script/tsim/tmq/overlapTopic2Con1Cgrp.sim index 51b90971fd76a3e61d6d8baaab4f0776757dd5c2..62ec3149be1da9bde6c0345922649cfd07559a1e 100644 --- a/tests/script/tsim/tmq/consumerMain.sim +++ b/tests/script/tsim/tmq/overlapTopic2Con1Cgrp.sim @@ -9,7 +9,7 @@ # notes2: not support aggregate functions(such as sum/count/min/max) and time-windows(interval). # ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## -######## This test case include scene1 and scene3 +######## This test case include scene2 and scene4 ######## ######## ######## ######## ######## ######## ######## ######## ######## ######## system sh/stop_dnodes.sh @@ -84,7 +84,7 @@ endi print =============== create child table $tbPrefix = ct -$tbNum = 2 +$tbNum = 10 $i = 0 while $i < $tbNum @@ -101,7 +101,7 @@ print =============== 1. columns from stb/ctb/ntb; 2. * from ctb/ntb; 3. functio 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_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 @@ -113,46 +113,37 @@ 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 != 3 then +if $rows != 11 then return -1 endi -print =============== run_back insert data +print =============== insert data +$rowNum = 100 +$tstart = 1640966400000 # 2022-01-01 00:00:00.000 -if $loop_cnt == 0 then - run_back tsim/tmq/insertDataV1.sim -else - run_back tsim/tmq/insertDataV4.sim -endi +$i = 0 +while $i < $tbNum + $tb = $tbPrefix . $i -sleep 1000 + $x = 0 + while $x < $rowNum + $c = $x / 10 + $c = $c * 10 + $c = $x - $c -#$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 + $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 +endw #root@trd02 /home $ tmq_sim --help # -c Configuration directory, default is @@ -162,9 +153,14 @@ sleep 1000 # -g showMsgFlag, default is 0 # -$consumeDelay = 5000 -$expectConsumeMsgCnt = 1000 -print expectConsumeMsgCnt: $expectConsumeMsgCnt, consumeDelay: $consumeDelay +$consumeDelay = 2 + +$expectMsgCntFromCtb = $rowNum +$expectMsgCntFromStb = $rowNum * $tbNum +$expectMsgCntFromNtb = $rowNum * $tbNum +print expectMsgCntFromCtb: $expectMsgCntFromCtb +print expectMsgCntFromStb: $expectMsgCntFromStb +print expectMsgCntFromNtb: $expectMsgCntFromNtb # supported key: # group.id: @@ -175,86 +171,63 @@ print expectConsumeMsgCnt: $expectConsumeMsgCnt, consumeDelay: $consumeDelay # 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 . $expectConsumeMsgCnt +$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_stb_column" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +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 >= $expect_result 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 -t "topic_stb_all" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt -#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 $expectConsumeMsgCnt -#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 $expectConsumeMsgCnt -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 $expectConsumeMsgCnt -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 . $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 -t "topic_ctb_column" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +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 >= $expect_result 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 -t "topic_ctb_all" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +#$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 >= $expect_result 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 -t "topic_ctb_function" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +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 >= $expect_result then +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 -t "topic_ntb_column" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +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 >= $expect_result 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 -t "topic_ntb_all" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt -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 $expectConsumeMsgCnt +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 >= $expect_result 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 -t "topic_ntb_function" -k "group.id:tg2" -y $consumeDelay -m $expectConsumeMsgCnt -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 $expectConsumeMsgCnt -print cmd result----> $system_content -if $system_content >= $expect_result then - return -1 -endi if $loop_cnt == 0 then $loop_cnt = 1 diff --git a/tests/test/c/tmqDemo.c b/tests/test/c/tmqDemo.c index 45a9d31f4cf09eb82f0962aba21c10335b1dd4b3..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_CREATE | 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 dc375dd35a68cbac2efedfd10404a31b1711da79..eaca8f151e9311fa113de29b6f1be838716f1239 100644 --- a/tests/test/c/tmqSim.c +++ b/tests/test/c/tmqSim.c @@ -13,51 +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 { - // input from argvs - char dbName[32]; - char topicString[256]; - char keyString[1024]; - int32_t showMsgFlag; - int32_t consumeDelay; // unit s - int32_t consumeMsgCnt; - - // 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 expectMsgCnt; + int32_t consumeMsgCnt; + TdThread thread; +} SThreadInfo; + +typedef struct { + // 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] = " "; @@ -71,22 +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.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(); @@ -99,109 +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); @@ -209,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; @@ -239,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; @@ -263,40 +363,41 @@ 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); } - -void parallel_consume(tmq_t* tmq) { +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) { - tmq_message_t* tmqMsg = tmq_consumer_poll(tmq, g_stConfInfo.consumeDelay * 1000); + TAOS_RES* tmqMsg = tmq_consumer_poll(tmq, g_stConfInfo.consumeDelay * 1000); if (tmqMsg) { - totalMsgs++; + totalMsgs++; - #if 0 + // 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); - } +#endif + + /*skipLogNum += tmqGetSkipLogNum(tmqMsg);*/ + if (0 != g_stConfInfo.showMsgFlag) { + /*msg_process(tmqMsg);*/ + } tmq_message_destroy(tmqMsg); - if (totalMsgs >= g_stConfInfo.consumeMsgCnt) { + if (totalMsgs >= g_stConfInfo.consumeMsgCnt) { break; - } + } } else { break; } @@ -305,32 +406,82 @@ void parallel_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("%d", totalMsgs); // output to sim for check result + + // printf("%d", totalMsgs); // output to sim for check result + return totalMsgs; } -int main(int32_t argc, char *argv[]) { +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); } - if (0 == g_stConfInfo.consumeMsgCnt) { + if (0 == g_stConfInfo.numOfTopic1) { loop_consume(tmq); } else { - parallel_consume(tmq); + totalMsgs = parallel_consume(tmq, 0); } err = tmq_unsubscribe(tmq); @@ -339,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/src/simExe.c b/tests/tsim/src/simExe.c index 8ef5c816c803d8c6b34b4c85f9244047dc1db20f..d71323336292cccf3d4cdb951c3ce457bded0667 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -678,7 +678,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)); 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/shellEngine.c b/tools/shell/src/shellEngine.c index 5a96a2a87dc8655ebbb305e10264889729b62f6d..83fa2ef843c50ef3a6305312a52d8e42ce8e9651 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -416,7 +416,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) {