diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 01172ae9c915090f50c830a131ea7c910deb0d30..a23ebdecfd527b55c72bc1e042b84de51b25885b 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -7,4 +7,4 @@ FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT} # [Optional] Uncomment this section to install additional packages. # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ # && apt-get -y install --no-install-recommends -RUN apt-get update && apt-get -y install tree vim +RUN apt-get update && apt-get -y install tree vim tmux diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index cb05c84d722c69b3e42290aff1d2699081fb33d4..f9ad25e27512623d772f183a28c7abc59b127d11 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -32,7 +32,7 @@ // Use 'forwardPorts' to make a list of ports inside the container available locally. // "forwardPorts": [], // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "gcc -v", + "postCreateCommand": "wget https://raw.githubusercontent.com/hzcheng/config/master/.tmux.conf -P /root", // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. "remoteUser": "root" } \ No newline at end of file diff --git a/cmake/cmake.define b/cmake/cmake.define index b89860e29f7251c47cd343d2e012d375b582b703..53d25e10977f73716957ffded17c0409c6ac9865 100644 --- a/cmake/cmake.define +++ b/cmake/cmake.define @@ -46,16 +46,20 @@ IF (TD_WINDOWS) ENDIF () ELSE () - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") - #SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3") - #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3") - -MESSAGE("System processor ID: ${CMAKE_SYSTEM_PROCESSOR}") -IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") - ADD_DEFINITIONS("-D_TD_ARM_") -ELSE () - ADD_DEFINITIONS("-msse4.2 -mfma") -ENDIF () + IF (${SANITIZER} MATCHES "true") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -static-libasan -g3") + MESSAGE(STATUS "Will compile with Address Sanitizer!") + ELSE () + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") + ENDIF () + + MESSAGE("System processor ID: ${CMAKE_SYSTEM_PROCESSOR}") + IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64") + ADD_DEFINITIONS("-D_TD_ARM_") + ELSE () + ADD_DEFINITIONS("-msse4.2 -mfma") + ENDIF () ENDIF () diff --git a/example/src/demoapi.c b/example/src/demoapi.c index ede13b4bb8bcfbe90810d5bad252219ba0c251a4..b1efdb21b961da2046906f269fc63527ce45f710 100644 --- a/example/src/demoapi.c +++ b/example/src/demoapi.c @@ -65,22 +65,32 @@ static void prepare_data(TAOS* taos) { usleep(100000); taos_select_db(taos, "test"); - res = taos_query(taos, "create table meters(ts timestamp, f float, n int, b binary(20)) tags(area int, localtion binary(20));"); + res = taos_query(taos, "create table meters(ts timestamp, f float, n int, b binary(20), c nchar(20)) tags(area int, city binary(20), dist nchar(20));"); taos_free_result(res); char command[1024] = {0}; for (int64_t i = 0; i < g_num_of_tb; i ++) { - sprintf(command, "create table t%"PRId64" using meters tags(%"PRId64", '%s');", - i, i, (i%2)?"beijing":"shanghai"); +// sprintf(command, "create table t%"PRId64" using meters tags(%"PRId64", '%s', '%s');", +// i, i, (i%2)?"beijing":"shanghai", (i%2)?"朝阳区":"黄浦区"); + sprintf(command, "create table t%"PRId64" using meters tags(%"PRId64", '%s', '%s');", + i, i, (i%2)?"beijing":"shanghai", (i%2)?"chaoyang":"huangpu"); res = taos_query(taos, command); + if ((res) && (0 == taos_errno(res))) { + okPrint("t%" PRId64 " created\n", i); + } else { + errorPrint("%s() LN%d: %s\n", + __func__, __LINE__, taos_errstr(res)); + } taos_free_result(res); int64_t j = 0; int64_t total = 0; int64_t affected; for (; j < g_num_of_rec -1; j ++) { - sprintf(command, "insert into t%"PRId64" values(%" PRId64 ", %f, %"PRId64", '%c%d')", - i, 1650000000000+j, (float)j, j, 'a'+(int)j%10, rand()); + sprintf(command, "insert into t%"PRId64" " + "values(%" PRId64 ", %f, %"PRId64", '%c%d', '%c%d')", + i, 1650000000000+j, (float)j, j, 'a'+(int)j%25, rand(), + 'z' - (int)j%25, rand()); res = taos_query(taos, command); if ((res) && (0 == taos_errno(res))) { affected = taos_affected_rows(res); @@ -91,7 +101,7 @@ static void prepare_data(TAOS* taos) { } taos_free_result(res); } - sprintf(command, "insert into t%"PRId64" values(%" PRId64 ", NULL, NULL, NULL)", + sprintf(command, "insert into t%"PRId64" values(%" PRId64 ", NULL, NULL, NULL, NULL)", i, 1650000000000+j+1); res = taos_query(taos, command); if ((res) && (0 == taos_errno(res))) { @@ -107,12 +117,16 @@ static void prepare_data(TAOS* taos) { } } -static int print_result(TAOS_RES* res, int block) { +static int print_result(char *tbname, TAOS_RES* res, int block) { int64_t num_rows = 0; TAOS_ROW row = NULL; int num_fields = taos_num_fields(res); TAOS_FIELD* fields = taos_fetch_fields(res); + for (int f = 0; f < num_fields; f++) { + printf("fields[%d].name=%s, fields[%d].type=%d, fields[%d].bytes=%d\n", + f, fields[f].name, f, fields[f].type, f, fields[f].bytes); + } if (block) { warnPrint("%s() LN%d, call taos_fetch_block()\n", __func__, __LINE__); int rows = 0; @@ -126,6 +140,16 @@ static int print_result(TAOS_RES* res, int block) { taos_print_row(temp, row, fields, num_fields); puts(temp); num_rows ++; + + int* lengths = taos_fetch_lengths(res); + if (lengths) { + for (int c = 0; c < num_fields; c++) { + printf("length of column %d is %d\n", c, lengths[c]); + } + } else { + errorPrint("%s() LN%d: %s's lengths is NULL\n", + __func__, __LINE__, tbname); + } } } @@ -134,28 +158,21 @@ static int print_result(TAOS_RES* res, int block) { static void verify_query(TAOS* taos) { // TODO: select count(tbname) from stable once stable query work + // + char tbname[193] = {0}; char command[1024] = {0}; for (int64_t i = 0; i < g_num_of_tb; i++) { - sprintf(command, "select * from t%"PRId64"", i); + sprintf(tbname, "t%"PRId64"", i); + sprintf(command, "select * from %s", tbname); TAOS_RES* res = taos_query(taos, command); if (res) { if (0 == taos_errno(res)) { int field_count = taos_field_count(res); printf("field_count: %d\n", field_count); - int* lengths = taos_fetch_lengths(res); - if (lengths) { - for (int c = 0; c < field_count; c++) { - printf("length of column %d is %d\n", c, lengths[c]); - } - } else { - errorPrint("%s() LN%d: t%"PRId64"'s lengths is NULL\n", - __func__, __LINE__, i); - } - - int64_t rows = print_result(res, i % 2); - printf("rows is: %"PRId64"\n", rows); + int64_t rows = print_result(tbname, res, i % 2); + printf("rows is: %"PRId64"\n", rows); } else { errorPrint("%s() LN%d: %s\n", diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 6f933c663eba534250bc9cb77cfd545212551dd8..15f3246013c5d289aa6689d55de162c435153344 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -203,11 +203,10 @@ void colInfoDataCleanup(SColumnInfoData* pColumn, uint32_t numOfRows); void blockDataCleanup(SSDataBlock* pDataBlock); size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize); -void* blockDataDestroy(SSDataBlock* pBlock); 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); diff --git a/include/common/tmsg.h b/include/common/tmsg.h index ee81ed20426a56d64f5496a8d0e1d7bdd54500ff..4e89beabcb34a1522b2b370c40d964774984ebef 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -84,30 +84,31 @@ enum { typedef enum _mgmt_table { TSDB_MGMT_TABLE_START, - TSDB_MGMT_TABLE_ACCT, - TSDB_MGMT_TABLE_USER, - TSDB_MGMT_TABLE_DB, - TSDB_MGMT_TABLE_TABLE, TSDB_MGMT_TABLE_DNODE, TSDB_MGMT_TABLE_MNODE, + TSDB_MGMT_TABLE_MODULE, TSDB_MGMT_TABLE_QNODE, TSDB_MGMT_TABLE_SNODE, TSDB_MGMT_TABLE_BNODE, - TSDB_MGMT_TABLE_VGROUP, + TSDB_MGMT_TABLE_CLUSTER, + TSDB_MGMT_TABLE_DB, + TSDB_MGMT_TABLE_FUNC, + TSDB_MGMT_TABLE_INDEX, TSDB_MGMT_TABLE_STB, - TSDB_MGMT_TABLE_MODULE, - TSDB_MGMT_TABLE_QUERIES, TSDB_MGMT_TABLE_STREAMS, - TSDB_MGMT_TABLE_VARIABLES, - TSDB_MGMT_TABLE_CONNS, - TSDB_MGMT_TABLE_TRANS, + TSDB_MGMT_TABLE_TABLE, + TSDB_MGMT_TABLE_USER, TSDB_MGMT_TABLE_GRANTS, + TSDB_MGMT_TABLE_VGROUP, + TSDB_MGMT_TABLE_TOPICS, + TSDB_MGMT_TABLE_CONSUMERS, + TSDB_MGMT_TABLE_SUBSCRIBES, + TSDB_MGMT_TABLE_TRANS, + TSDB_MGMT_TABLE_SMAS, + TSDB_MGMT_TABLE_CONFIGS, + TSDB_MGMT_TABLE_CONNS, + TSDB_MGMT_TABLE_QUERIES, TSDB_MGMT_TABLE_VNODES, - TSDB_MGMT_TABLE_CLUSTER, - TSDB_MGMT_TABLE_STREAMTABLES, - TSDB_MGMT_TABLE_TP, - TSDB_MGMT_TABLE_FUNC, - TSDB_MGMT_TABLE_INDEX, TSDB_MGMT_TABLE_MAX, } EShowType; @@ -361,7 +362,7 @@ typedef struct { int32_t maxTimeSeries; int32_t maxStreams; int32_t accessState; // Configured only by command - int64_t maxStorage; // In unit of GB + int64_t maxStorage; } SCreateAcctReq, SAlterAcctReq; int32_t tSerializeSCreateAcctReq(void* buf, int32_t bufLen, SCreateAcctReq* pReq); @@ -745,8 +746,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 +761,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 +775,7 @@ typedef struct { } SDnodeEp; typedef struct { - int64_t dver; + int64_t dnodeVer; SDnodeCfg dnodeCfg; SArray* pDnodeEps; // Array of SDnodeEp } SStatusRsp; @@ -1899,7 +1901,6 @@ typedef struct { char topicName[TSDB_TOPIC_FNAME_LEN]; char cgroup[TSDB_CGROUP_LEN]; char* sql; - char* logicalPlan; char* physicalPlan; char* qmsg; } SMqSetCVgReq; @@ -1913,7 +1914,6 @@ static FORCE_INLINE int32_t tEncodeSMqSetCVgReq(void** buf, const SMqSetCVgReq* tlen += taosEncodeString(buf, pReq->topicName); tlen += taosEncodeString(buf, pReq->cgroup); tlen += taosEncodeString(buf, pReq->sql); - tlen += taosEncodeString(buf, pReq->logicalPlan); tlen += taosEncodeString(buf, pReq->physicalPlan); tlen += taosEncodeString(buf, pReq->qmsg); return tlen; @@ -1927,7 +1927,6 @@ static FORCE_INLINE void* tDecodeSMqSetCVgReq(void* buf, SMqSetCVgReq* pReq) { buf = taosDecodeStringTo(buf, pReq->topicName); buf = taosDecodeStringTo(buf, pReq->cgroup); buf = taosDecodeString(buf, &pReq->sql); - buf = taosDecodeString(buf, &pReq->logicalPlan); buf = taosDecodeString(buf, &pReq->physicalPlan); buf = taosDecodeString(buf, &pReq->qmsg); return buf; diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index 7840d1825661b97eb194f41cd0bf108c8ee7883e..23dd4b38ffb576af35354d56729b7964c0845a20 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -181,49 +181,50 @@ #define TK_NULL 163 #define TK_FIRST 164 #define TK_LAST 165 -#define TK_NOW 166 -#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_CAST 166 +#define TK_NOW 167 +#define TK_TODAY 168 +#define TK_ROWTS 169 +#define TK_TBNAME 170 +#define TK_QSTARTTS 171 +#define TK_QENDTS 172 +#define TK_WSTARTTS 173 +#define TK_WENDTS 174 +#define TK_WDURATION 175 +#define TK_BETWEEN 176 +#define TK_IS 177 +#define TK_NK_LT 178 +#define TK_NK_GT 179 +#define TK_NK_LE 180 +#define TK_NK_GE 181 +#define TK_NK_NE 182 +#define TK_MATCH 183 +#define TK_NMATCH 184 +#define TK_JOIN 185 +#define TK_INNER 186 +#define TK_SELECT 187 +#define TK_DISTINCT 188 +#define TK_WHERE 189 +#define TK_PARTITION 190 +#define TK_BY 191 +#define TK_SESSION 192 +#define TK_STATE_WINDOW 193 +#define TK_SLIDING 194 +#define TK_FILL 195 +#define TK_VALUE 196 +#define TK_NONE 197 +#define TK_PREV 198 +#define TK_LINEAR 199 +#define TK_NEXT 200 +#define TK_GROUP 201 +#define TK_HAVING 202 +#define TK_ORDER 203 +#define TK_SLIMIT 204 +#define TK_SOFFSET 205 +#define TK_LIMIT 206 +#define TK_OFFSET 207 +#define TK_ASC 208 +#define TK_NULLS 209 #define TK_NK_SPACE 300 #define TK_NK_COMMENT 301 diff --git a/include/common/ttypes.h b/include/common/ttypes.h index 1bce57f1911884b71aca5706ffa1307ef2a57802..23b260849dc382ffaca7466b782d21698dd8b93d 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -181,6 +181,7 @@ typedef struct { #define IS_SIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_TINYINT && (_t) <= TSDB_DATA_TYPE_BIGINT) #define IS_UNSIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_UTINYINT && (_t) <= TSDB_DATA_TYPE_UBIGINT) #define IS_FLOAT_TYPE(_t) ((_t) == TSDB_DATA_TYPE_FLOAT || (_t) == TSDB_DATA_TYPE_DOUBLE) +#define IS_INTEGER_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t))) #define IS_NUMERIC_TYPE(_t) ((IS_SIGNED_NUMERIC_TYPE(_t)) || (IS_UNSIGNED_NUMERIC_TYPE(_t)) || (IS_FLOAT_TYPE(_t))) #define IS_MATHABLE_TYPE(_t) (IS_NUMERIC_TYPE(_t) || (_t) == (TSDB_DATA_TYPE_BOOL) || (_t) == (TSDB_DATA_TYPE_TIMESTAMP)) diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index e4f4bdf8f994c31df6f31ce6df1347e384df5de6..b48fd232045a03608b593511982476d329f5d05f 100644 --- a/include/dnode/mgmt/dnode.h +++ b/include/dnode/mgmt/dnode.h @@ -30,12 +30,12 @@ typedef struct SDnode SDnode; * * @return int32_t 0 for success and -1 for failure */ -int32_t dndInit(); +int32_t dmInit(); /** * @brief Clear the environment */ -void dndCleanup(); +void dmCleanup(); /* ------------------------ SDnode ----------------------- */ typedef struct { @@ -51,7 +51,7 @@ typedef struct { int8_t ntype; } SDnodeOpt; -typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_CHILD } EDndEvent; +typedef enum { DND_EVENT_START = 0, DND_EVENT_STOP = 1, DND_EVENT_CHILD = 2 } EDndEvent; /** * @brief Initialize and start the dnode. @@ -59,21 +59,21 @@ typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_CHILD } EDndEvent; * @param pOption Option of the dnode. * @return SDnode* The dnode object. */ -SDnode *dndCreate(const SDnodeOpt *pOption); +SDnode *dmCreate(const SDnodeOpt *pOption); /** * @brief Stop and cleanup the dnode. * * @param pDnode The dnode object to close. */ -void dndClose(SDnode *pDnode); +void dmClose(SDnode *pDnode); /** * @brief Run dnode until specific event is receive. * * @param pDnode The dnode object to run. */ -int32_t dndRun(SDnode *pDnode); +int32_t dmRun(SDnode *pDnode); /** * @brief Handle event in the dnode. @@ -81,7 +81,7 @@ int32_t dndRun(SDnode *pDnode); * @param pDnode The dnode object to close. * @param event The event to handle. */ -void dndHandleEvent(SDnode *pDnode, EDndEvent event); +void dmSetEvent(SDnode *pDnode, EDndEvent event); #ifdef __cplusplus } diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 08ab63e55abb4498e058c8e014387c1046a76621..98481259194ba6f87e99e7c465d21c84244747ef 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -68,31 +68,18 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption); * @param pMnode The mnode object. */ int32_t mndStart(SMnode *pMnode); +void mndStop(SMnode *pMnode); /** * @brief Get mnode monitor info. * * @param pMnode The mnode object. - * @param pClusterInfo - * @param pVgroupInfo - * @param pGrantInfo + * @param pCluster + * @param pVgroup + * @param pGrant * @return int32_t 0 for success, -1 for failure. */ -int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgroupInfo *pVgroupInfo, - SMonGrantInfo *pGrantInfo); - -/** - * @brief Get user authentication info. - * - * @param pMnode The mnode object. - * @param user - * @param spi - * @param encrypt - * @param secret - * @param ckey - * @return int32_t 0 for success, -1 for failure. - */ -int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey); +int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pCluster, SMonVgroupInfo *pVgroup, SMonGrantInfo *pGrant); /** * @brief Process the read, write, sync request. @@ -102,6 +89,11 @@ int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, cha */ int32_t mndProcessMsg(SNodeMsg *pMsg); +/** + * @brief Generate machine code + */ +void mndGenerateMachineCode(); + #ifdef __cplusplus } #endif diff --git a/include/libs/function/functionMgt.h b/include/libs/function/functionMgt.h index 148a9f77d6081596332ac1dc4244e86317d69427..a471de3147a999afbec8346afb08ebc833699b12 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -123,7 +123,7 @@ void fmFuncMgtDestroy(); int32_t fmGetFuncInfo(const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType); -int32_t fmGetFuncResultType(SFunctionNode* pFunc); +int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len); bool fmIsAggFunc(int32_t funcId); bool fmIsScalarFunc(int32_t funcId); diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 7d0d0137ec12e9ae311dcfd6a23c4521486db7d7..e1a63bd66bdea3567a5671abf3869b09db71cb21 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -267,6 +267,11 @@ typedef struct SDescribeStmt { STableMeta* pMeta; } SDescribeStmt; +typedef struct SKillStmt { + ENodeType type; + int32_t targetId; +} SKillStmt; + #ifdef __cplusplus } #endif diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index 4ffacf3787e201b2de55bcbf1f952c1c666ed057..02636a178e403e82d4d6c0ac9be8279b70f510d5 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -52,7 +52,8 @@ extern "C" { for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); (NULL != cell ? (node = &(cell->pNode), true) : (node = NULL, false)); cell = cell->pNext) typedef enum ENodeType { - // Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN, VALUE, OPERATOR, FUNCTION and so on. + // Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN, + // VALUE, OPERATOR, FUNCTION and so on. QUERY_NODE_COLUMN = 1, QUERY_NODE_VALUE, QUERY_NODE_OPERATOR, @@ -69,7 +70,7 @@ typedef enum ENodeType { QUERY_NODE_INTERVAL_WINDOW, QUERY_NODE_NODE_LIST, QUERY_NODE_FILL, - QUERY_NODE_RAW_EXPR, // Only be used in parser module. + QUERY_NODE_RAW_EXPR, // Only be used in parser module. QUERY_NODE_TARGET, QUERY_NODE_DATABLOCK_DESC, QUERY_NODE_SLOT_DESC, @@ -126,30 +127,30 @@ typedef enum ENodeType { QUERY_NODE_REDISTRIBUTE_VGROUP_STMT, QUERY_NODE_SPLIT_VGROUP_STMT, QUERY_NODE_SYNCDB_STMT, - QUERY_NODE_SHOW_DATABASES_STMT, - QUERY_NODE_SHOW_TABLES_STMT, - QUERY_NODE_SHOW_STABLES_STMT, - QUERY_NODE_SHOW_USERS_STMT, QUERY_NODE_SHOW_DNODES_STMT, - QUERY_NODE_SHOW_VGROUPS_STMT, QUERY_NODE_SHOW_MNODES_STMT, QUERY_NODE_SHOW_MODULES_STMT, QUERY_NODE_SHOW_QNODES_STMT, + QUERY_NODE_SHOW_SNODES_STMT, + QUERY_NODE_SHOW_BNODES_STMT, + QUERY_NODE_SHOW_DATABASES_STMT, QUERY_NODE_SHOW_FUNCTIONS_STMT, QUERY_NODE_SHOW_INDEXES_STMT, + QUERY_NODE_SHOW_STABLES_STMT, QUERY_NODE_SHOW_STREAMS_STMT, - QUERY_NODE_SHOW_APPS_STMT, - QUERY_NODE_SHOW_CONNECTIONS_STMT, + QUERY_NODE_SHOW_TABLES_STMT, + QUERY_NODE_SHOW_USERS_STMT, QUERY_NODE_SHOW_LICENCE_STMT, - QUERY_NODE_SHOW_CREATE_DATABASE_STMT, - QUERY_NODE_SHOW_CREATE_TABLE_STMT, - QUERY_NODE_SHOW_CREATE_STABLE_STMT, - QUERY_NODE_SHOW_QUERIES_STMT, - QUERY_NODE_SHOW_SCORES_STMT, + QUERY_NODE_SHOW_VGROUPS_STMT, QUERY_NODE_SHOW_TOPICS_STMT, - QUERY_NODE_SHOW_VARIABLE_STMT, - QUERY_NODE_SHOW_BNODES_STMT, - QUERY_NODE_SHOW_SNODES_STMT, + QUERY_NODE_SHOW_CONSUMERS_STMT, + QUERY_NODE_SHOW_SUBSCRIBES_STMT, + QUERY_NODE_SHOW_TRANS_STMT, + QUERY_NODE_SHOW_SMAS_STMT, + QUERY_NODE_SHOW_CONFIGS_STMT, + QUERY_NODE_SHOW_CONNECTIONS_STMT, + QUERY_NODE_SHOW_QUERIES_STMT, + QUERY_NODE_SHOW_VNODES_STMT, QUERY_NODE_KILL_CONNECTION_STMT, QUERY_NODE_KILL_QUERY_STMT, diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 60535e2f493a3bcb1769f067fb7e13a6fb715452..e31eea1b157cf73ac54c7dd42e2c7c803c26d83f 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -566,8 +566,6 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_AMBIGUOUS_COLUMN TAOS_DEF_ERROR_CODE(0, 0x2603) #define TSDB_CODE_PAR_WRONG_VALUE_TYPE TAOS_DEF_ERROR_CODE(0, 0x2604) #define TSDB_CODE_PAR_INVALID_FUNTION TAOS_DEF_ERROR_CODE(0, 0x2605) -#define TSDB_CODE_PAR_FUNTION_PARA_NUM TAOS_DEF_ERROR_CODE(0, 0x2606) -#define TSDB_CODE_PAR_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2607) #define TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION TAOS_DEF_ERROR_CODE(0, 0x2608) #define TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT TAOS_DEF_ERROR_CODE(0, 0x2609) #define TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION TAOS_DEF_ERROR_CODE(0, 0x260A) @@ -601,7 +599,12 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_INVALID_KEEP_UNIT TAOS_DEF_ERROR_CODE(0, 0x2626) //planner -#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700) +#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700) + +//function +#define TSDB_CODE_FUNC_FUNTION_ERROR TAOS_DEF_ERROR_CODE(0, 0x2800) +#define TSDB_CODE_FUNC_FUNTION_PARA_NUM TAOS_DEF_ERROR_CODE(0, 0x2801) +#define TSDB_CODE_FUNC_FUNTION_PARA_TYPE TAOS_DEF_ERROR_CODE(0, 0x2802) #ifdef __cplusplus } diff --git a/include/util/tdef.h b/include/util/tdef.h index db09e43517867981d40ed2402eb2983e28ffcee6..5fc30540ee6ad58563795dd1d04c0ef92406d109 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -106,6 +106,7 @@ extern const int32_t TYPE_BYTES[15]; #define TSDB_INS_TABLE_MODULES "modules" #define TSDB_INS_TABLE_QNODES "qnodes" #define TSDB_INS_TABLE_BNODES "bnodes" +#define TSDB_INS_TABLE_SNODES "snodes" #define TSDB_INS_TABLE_CLUSTER "cluster" #define TSDB_INS_TABLE_USER_DATABASES "user_databases" #define TSDB_INS_TABLE_USER_FUNCTIONS "user_functions" @@ -115,10 +116,17 @@ extern const int32_t TYPE_BYTES[15]; #define TSDB_INS_TABLE_USER_TABLES "user_tables" #define TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED "user_table_distributed" #define TSDB_INS_TABLE_USER_USERS "user_users" -#define TSDB_INS_TABLE_VGROUPS "vgroups" -#define TSDB_INS_TABLE_BNODES "bnodes" -#define TSDB_INS_TABLE_SNODES "snodes" #define TSDB_INS_TABLE_LICENCES "grants" +#define TSDB_INS_TABLE_VGROUPS "vgroups" +#define TSDB_INS_TABLE_TOPICS "topics" +#define TSDB_INS_TABLE_CONSUMERS "consumers" +#define TSDB_INS_TABLE_SUBSCRIBES "subscribes" +#define TSDB_INS_TABLE_TRANS "trans" +#define TSDB_INS_TABLE_SMAS "smas" +#define TSDB_INS_TABLE_CONFIGS "configs" +#define TSDB_INS_TABLE_CONNS "connections" +#define TSDB_INS_TABLE_QUERIES "queries" +#define TSDB_INS_TABLE_VNODES "vnodes" #define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema" #define TSDB_PERFS_TABLE_CONNECTIONS "connections" @@ -505,6 +513,15 @@ enum { #define QNODE_HANDLE 1 #define DEFAULT_HANDLE 0 +#define TSDB_CONFIG_OPTION_LEN 16 +#define TSDB_CONIIG_VALUE_LEN 48 +#define TSDB_CONFIG_NUMBER 8 + +#define QUERY_ID_SIZE 20 +#define QUERY_OBJ_ID_SIZE 18 +#define SUBQUERY_INFO_SIZE 6 +#define QUERY_SAVE_SIZE 20 + #define MAX_NUM_STR_SIZE 40 diff --git a/include/util/tencode.h b/include/util/tencode.h index cdde378b69f7954c168fb633b83139967b37545c..7c877ae4283fc662cf5cd43d59b571e931b08a02 100644 --- a/include/util/tencode.h +++ b/include/util/tencode.h @@ -18,7 +18,6 @@ #include "tcoding.h" #include "tfreelist.h" -#include "tmacro.h" #ifdef __cplusplus extern "C" { diff --git a/include/util/tmacro.h b/include/util/tmacro.h deleted file mode 100644 index 07c6e6509e4d5eedd7c14a830922b8347111f6e8..0000000000000000000000000000000000000000 --- a/include/util/tmacro.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_UTIL_MACRO_H_ -#define _TD_UTIL_MACRO_H_ - -#include "os.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// Module init/clear MACRO definitions -#define TD_MOD_UNINITIALIZED 0 -#define TD_MOD_INITIALIZED 1 - -typedef int8_t td_mode_flag_t; - -#define TD_CHECK_AND_SET_MODE_INIT(FLAG) atomic_val_compare_exchange_8((FLAG), TD_MOD_UNINITIALIZED, TD_MOD_INITIALIZED) -#define TD_CHECK_AND_SET_MOD_CLEAR(FLAG) atomic_val_compare_exchange_8((FLAG), TD_MOD_INITIALIZED, TD_MOD_UNINITIALIZED) - -#define TD_IS_NULL(PTR) ((PTR) == NULL) - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_UTIL_MACRO_H_*/ \ No newline at end of file diff --git a/include/util/tprocess.h b/include/util/tprocess.h index c5f33140dd701fe5f4c301d733ec96c7c2bf780c..2b0fd89aa5a02c4c9a388a1a3a2973f433a4614d 100644 --- a/include/util/tprocess.h +++ b/include/util/tprocess.h @@ -22,13 +22,13 @@ extern "C" { #endif -typedef enum { PROC_REQ = 1, PROC_RSP, PROC_REGIST, PROC_RELEASE } ProcFuncType; +typedef enum { PROC_FUNC_REQ = 1, PROC_FUNC_RSP, PROC_FUNC_REGIST, PROC_FUNC_RELEASE } EProcFuncType; typedef struct SProcObj SProcObj; typedef void *(*ProcMallocFp)(int32_t contLen); typedef void *(*ProcFreeFp)(void *pCont); typedef void (*ProcConsumeFp)(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, - ProcFuncType ftype); + EProcFuncType ftype); typedef struct { ProcConsumeFp childConsumeFp; @@ -53,11 +53,11 @@ int32_t taosProcRun(SProcObj *pProc); void taosProcStop(SProcObj *pProc); int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, - void *handle, ProcFuncType ftype); + void *handle, EProcFuncType ftype); void taosProcRemoveHandle(SProcObj *pProc, void *handle); void taosProcCloseHandles(SProcObj *pProc, void (*HandleFp)(void *handle)); void taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, - ProcFuncType ftype); + EProcFuncType ftype); #ifdef __cplusplus } diff --git a/packaging/install.sh b/packaging/install.sh index 6642f8922170824d08ba5fe5e698f1057f1d9ccb..9ce7fc326a9685aa40ad3a08b70f78656770c792 100755 --- a/packaging/install.sh +++ b/packaging/install.sh @@ -460,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() { diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 953da056eace2621c816ece0046ba21708bc3196..75b45373648bbb0336c082577a592721ff76c069 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -603,12 +603,15 @@ 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; } } } diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index a5fd0b49ecdd042b533161686f92b3908343b932..ae8a31f367c730ac6e7f3bc4ab1c05640e964c8e 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -413,7 +413,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; } @@ -466,37 +470,35 @@ 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) { + if (TD_RES_TMQ(res)) { + SReqResultInfo *pResultInfo = tmqGetNextResInfo(res); + if (pResultInfo == NULL) { + (*numOfRows) = 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; + } - } else if (TD_RES_TMQ(res)) { - SReqResultInfo *pResultInfo = tmqGetNextResInfo(res); - if (pResultInfo == NULL) return -1; + SRequestObj *pRequest = (SRequestObj *)res; - pResultInfo->current = pResultInfo->numOfRows; - (*numOfRows) = pResultInfo->numOfRows; - (*pData) = (void *)pResultInfo->pData; + 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; - - } else { - ASSERT(0); - return -1; } + + 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/test/clientTests.cpp b/source/client/test/clientTests.cpp index f5d8d7ec67be194a2aeb685359af0c7d65958ecf..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,6 +673,10 @@ 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); diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index dad5805c6698b1c43920e9e4f854ab01d8217e29..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; } diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 58bc7235a1a14f1be58ca88d0d08f500f4c78092..9226e9aa37e25e8ce7c8faed5345588c84229d74 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -189,7 +189,7 @@ static int32_t taosSetTfsCfg(SConfig *pCfg) { tsDiskCfgNum = 1; taosAddDataDir(0, pItem->str, 0, 1); tstrncpy(tsDataDir, pItem->str, PATH_MAX); - if (taosMkDir(tsDataDir) != 0) { + if (taosMulMkDir(tsDataDir) != 0) { uError("failed to create dataDir:%s since %s", tsDataDir, terrstr()); return -1; } @@ -200,12 +200,12 @@ static int32_t taosSetTfsCfg(SConfig *pCfg) { memcpy(&tsDiskCfg[index], pCfg, sizeof(SDiskCfg)); if (pCfg->level == 0 && pCfg->primary == 1) { tstrncpy(tsDataDir, pCfg->dir, PATH_MAX); - if (taosMkDir(tsDataDir) != 0) { + if (taosMulMkDir(tsDataDir) != 0) { uError("failed to create dataDir:%s since %s", tsDataDir, terrstr()); return -1; } } - if (taosMkDir(pCfg->dir) != 0) { + if (taosMulMkDir(pCfg->dir) != 0) { uError("failed to create tfsDir:%s since %s", tsDataDir, terrstr()); return -1; } @@ -486,7 +486,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) { tstrncpy(tsTempDir, cfgGetItem(pCfg, "tempDir")->str, PATH_MAX); taosExpandDir(tsTempDir, tsTempDir, PATH_MAX); tsTempSpace.reserved = cfgGetItem(pCfg, "minimalTempDirGB")->fval; - if (taosMkDir(tsTempDir) != 0) { + if (taosMulMkDir(tsTempDir) != 0) { uError("failed to create tempDir:%s since %s", tsTempDir, terrstr()); return -1; } @@ -495,7 +495,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) { tsRpcTimer = cfgGetItem(pCfg, "rpcTimer")->i32; tsRpcMaxTime = cfgGetItem(pCfg, "rpcMaxTime")->i32; tsRpcForceTcp = cfgGetItem(pCfg, "rpcForceTcp")->i32; - tsShellActivityTimer = cfgGetItem(pCfg, "shellActivityTimer")->bval; + tsShellActivityTimer = cfgGetItem(pCfg, "shellActivityTimer")->i32; tsCompressMsgSize = cfgGetItem(pCfg, "compressMsgSize")->i32; tsCompressColData = cfgGetItem(pCfg, "compressColData")->i32; tsMaxWildCardsLen = cfgGetItem(pCfg, "maxWildCardsLength")->i32; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 99f173501be7bb0fb903feb423b499a859154295..3e37c52c26207ee5134c1c41f2d71132dd1c47a2 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -981,7 +981,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; @@ -1026,7 +1026,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; @@ -1071,6 +1071,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); @@ -1078,7 +1080,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; @@ -1109,7 +1111,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; @@ -2293,7 +2295,6 @@ int32_t tSerializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableReq if (tStartEncode(&encoder) < 0) return -1; if (tEncodeI64(&encoder, pReq->showId) < 0) return -1; if (tEncodeI32(&encoder, pReq->type) < 0) return -1; -// if (tEncodeI8(&encoder, pReq->free) < 0) return -1; if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; if (tEncodeCStr(&encoder, pReq->tb) < 0) return -1; tEndEncode(&encoder); @@ -2310,7 +2311,6 @@ int32_t tDeserializeSRetrieveTableReq(void *buf, int32_t bufLen, SRetrieveTableR if (tStartDecode(&decoder) < 0) return -1; if (tDecodeI64(&decoder, &pReq->showId) < 0) return -1; if (tDecodeI32(&decoder, &pReq->type) < 0) return -1; -// if (tDecodeI8(&decoder, &pReq->free) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->tb) < 0) return -1; tEndDecode(&decoder); diff --git a/source/dnode/mgmt/CMakeLists.txt b/source/dnode/mgmt/CMakeLists.txt index e002bbe444a15a9766c5828583c52ef346243617..49ea54e92835f1173e80fef46f6184f258ebdb5e 100644 --- a/source/dnode/mgmt/CMakeLists.txt +++ b/source/dnode/mgmt/CMakeLists.txt @@ -1,29 +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 "${TD_SOURCE_DIR}/source/dnode/mnode/impl/inc" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/implement/inc" ) target_link_libraries(taosd dnode) - -if(${BUILD_TEST}) - add_subdirectory(test) -endif(${BUILD_TEST}) diff --git a/source/dnode/mgmt/dm/dmHandle.c b/source/dnode/mgmt/dm/dmHandle.c deleted file mode 100644 index 46d94fb8449bfd9ef8d6a8c77f92779832c4c91e..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/dm/dmHandle.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "dmInt.h" - -void dmSendStatusReq(SDnodeMgmt *pMgmt) { - SDnode *pDnode = pMgmt->pDnode; - SStatusReq req = {0}; - - taosRLockLatch(&pMgmt->latch); - req.sver = tsVersion; - req.dver = pMgmt->dver; - req.dnodeId = pDnode->dnodeId; - req.clusterId = pDnode->clusterId; - req.rebootTime = pDnode->rebootTime; - req.updateTime = pMgmt->updateTime; - req.numOfCores = tsNumOfCores; - req.numOfSupportVnodes = pDnode->numOfSupportVnodes; - tstrncpy(req.dnodeEp, pDnode->localEp, TSDB_EP_LEN); - - req.clusterCfg.statusInterval = tsStatusInterval; - req.clusterCfg.checkTime = 0; - char timestr[32] = "1970-01-01 00:00:00.00"; - (void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0); - memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN); - memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN); - memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN); - taosRUnLockLatch(&pMgmt->latch); - - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, VNODES); - if (pWrapper != NULL) { - SMonVloadInfo info = {0}; - dmGetVnodeLoads(pWrapper, &info); - req.pVloads = info.pVloads; - dndReleaseWrapper(pWrapper); - } - - int32_t contLen = tSerializeSStatusReq(NULL, 0, &req); - void *pHead = rpcMallocCont(contLen); - tSerializeSStatusReq(pHead, contLen, &req); - taosArrayDestroy(req.pVloads); - - SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .ahandle = (void *)0x9527}; - pMgmt->statusSent = 1; - - dTrace("send req:%s to mnode, app:%p", TMSG_INFO(rpcMsg.msgType), rpcMsg.ahandle); - SEpSet epSet = {0}; - dmGetMnodeEpSet(pMgmt, &epSet); - tmsgSendReq(&pMgmt->msgCb, &epSet, &rpcMsg); -} - -static void dmUpdateDnodeCfg(SDnodeMgmt *pMgmt, SDnodeCfg *pCfg) { - SDnode *pDnode = pMgmt->pDnode; - - if (pDnode->dnodeId == 0) { - dInfo("set dnodeId:%d clusterId:%" PRId64, pCfg->dnodeId, pCfg->clusterId); - taosWLockLatch(&pMgmt->latch); - pDnode->dnodeId = pCfg->dnodeId; - pDnode->clusterId = pCfg->clusterId; - dmWriteFile(pMgmt); - taosWUnLockLatch(&pMgmt->latch); - } -} - -int32_t dmProcessStatusRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { - SDnode *pDnode = pMgmt->pDnode; - SRpcMsg *pRsp = &pMsg->rpcMsg; - - if (pRsp->code != TSDB_CODE_SUCCESS) { - if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pDnode->dropped && pDnode->dnodeId > 0) { - dInfo("dnode:%d, set to dropped since not exist in mnode", pDnode->dnodeId); - pDnode->dropped = 1; - dmWriteFile(pMgmt); - } - } else { - SStatusRsp statusRsp = {0}; - if (pRsp->pCont != NULL && pRsp->contLen != 0 && - tDeserializeSStatusRsp(pRsp->pCont, pRsp->contLen, &statusRsp) == 0) { - pMgmt->dver = statusRsp.dver; - dmUpdateDnodeCfg(pMgmt, &statusRsp.dnodeCfg); - dmUpdateDnodeEps(pMgmt, statusRsp.pDnodeEps); - } - tFreeSStatusRsp(&statusRsp); - } - - pMgmt->statusSent = 0; - return TSDB_CODE_SUCCESS; -} - -int32_t dmProcessAuthRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { - SRpcMsg *pRsp = &pMsg->rpcMsg; - dError("auth rsp is received, but not supported yet"); - return 0; -} - -int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { - SRpcMsg *pRsp = &pMsg->rpcMsg; - dError("grant rsp is received, but not supported yet"); - return 0; -} - -int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SNodeMsg *pMsg) { - SRpcMsg *pReq = &pMsg->rpcMsg; - SDCfgDnodeReq *pCfg = pReq->pCont; - dError("config req is received, but not supported yet"); - return TSDB_CODE_OPS_NOT_SUPPORT; -} - -static int32_t dmProcessCreateNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg *pMsg) { - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, ntype); - if (pWrapper != NULL) { - dndReleaseWrapper(pWrapper); - terrno = TSDB_CODE_NODE_ALREADY_DEPLOYED; - dError("failed to create node since %s", terrstr()); - return -1; - } - - pWrapper = &pDnode->wrappers[ntype]; - - if (taosMkDir(pWrapper->path) != 0) { - terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to create dir:%s since %s", pWrapper->path, terrstr()); - return -1; - } - - int32_t code = (*pWrapper->fp.createMsgFp)(pWrapper, pMsg); - if (code != 0) { - dError("node:%s, failed to open since %s", pWrapper->name, terrstr()); - } else { - dDebug("node:%s, has been opened", pWrapper->name); - pWrapper->deployed = true; - } - - return code; -} - -static int32_t dmProcessDropNodeMsg(SDnode *pDnode, EDndType ntype, SNodeMsg *pMsg) { - SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, ntype); - if (pWrapper == NULL) { - terrno = TSDB_CODE_NODE_NOT_DEPLOYED; - dError("failed to drop node since %s", terrstr()); - return -1; - } - - taosWLockLatch(&pWrapper->latch); - pWrapper->deployed = false; - - int32_t code = (*pWrapper->fp.dropMsgFp)(pWrapper, pMsg); - if (code != 0) { - pWrapper->deployed = true; - dError("node:%s, failed to drop since %s", pWrapper->name, terrstr()); - } else { - pWrapper->deployed = false; - dDebug("node:%s, has been dropped", pWrapper->name); - } - - taosWUnLockLatch(&pWrapper->latch); - dndReleaseWrapper(pWrapper); - return code; -} - -int32_t dmProcessCDnodeReq(SDnode *pDnode, SNodeMsg *pMsg) { - switch (pMsg->rpcMsg.msgType) { - case TDMT_DND_CREATE_MNODE: - return dmProcessCreateNodeMsg(pDnode, MNODE, pMsg); - case TDMT_DND_DROP_MNODE: - return dmProcessDropNodeMsg(pDnode, MNODE, pMsg); - case TDMT_DND_CREATE_QNODE: - return dmProcessCreateNodeMsg(pDnode, QNODE, pMsg); - case TDMT_DND_DROP_QNODE: - return dmProcessDropNodeMsg(pDnode, QNODE, pMsg); - case TDMT_DND_CREATE_SNODE: - return dmProcessCreateNodeMsg(pDnode, SNODE, pMsg); - case TDMT_DND_DROP_SNODE: - return dmProcessDropNodeMsg(pDnode, SNODE, pMsg); - case TDMT_DND_CREATE_BNODE: - return dmProcessCreateNodeMsg(pDnode, BNODE, pMsg); - case TDMT_DND_DROP_BNODE: - return dmProcessDropNodeMsg(pDnode, BNODE, pMsg); - default: - terrno = TSDB_CODE_MSG_NOT_PROCESSED; - return -1; - } -} - -void dmInitMsgHandle(SMgmtWrapper *pWrapper) { - // Requests handled by DNODE - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_NETWORK_TEST, dmProcessMgmtMsg, DEFAULT_HANDLE); - - // Requests handled by MNODE - dndSetMsgHandle(pWrapper, TDMT_MND_STATUS_RSP, dmProcessMonitorMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_GRANT_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_MND_AUTH_RSP, dmProcessMgmtMsg, DEFAULT_HANDLE); -} diff --git a/source/dnode/mgmt/dm/dmInt.c b/source/dnode/mgmt/dm/dmInt.c deleted file mode 100644 index c710af9006feefd5284f8106ac79af8261ddf818..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/dm/dmInt.c +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "dmInt.h" - -void dmGetMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet) { - taosRLockLatch(&pMgmt->latch); - *pEpSet = pMgmt->mnodeEpSet; - taosRUnLockLatch(&pMgmt->latch); -} - -void dmUpdateMnodeEpSet(SDnodeMgmt *pMgmt, SEpSet *pEpSet) { - dInfo("mnode is changed, num:%d use:%d", pEpSet->numOfEps, pEpSet->inUse); - - taosWLockLatch(&pMgmt->latch); - pMgmt->mnodeEpSet = *pEpSet; - for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { - dInfo("mnode index:%d %s:%u", i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port); - } - - taosWUnLockLatch(&pMgmt->latch); -} - -void dmGetDnodeEp(SMgmtWrapper *pWrapper, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) { - SDnodeMgmt *pMgmt = pWrapper->pMgmt; - taosRLockLatch(&pMgmt->latch); - - SDnodeEp *pDnodeEp = taosHashGet(pMgmt->dnodeHash, &dnodeId, sizeof(int32_t)); - if (pDnodeEp != NULL) { - if (pPort != NULL) { - *pPort = pDnodeEp->ep.port; - } - if (pFqdn != NULL) { - tstrncpy(pFqdn, pDnodeEp->ep.fqdn, TSDB_FQDN_LEN); - } - if (pEp != NULL) { - snprintf(pEp, TSDB_EP_LEN, "%s:%u", pDnodeEp->ep.fqdn, pDnodeEp->ep.port); - } - } - - taosRUnLockLatch(&pMgmt->latch); -} - -void dmSendRedirectRsp(SDnodeMgmt *pMgmt, const SRpcMsg *pReq) { - SDnode *pDnode = pMgmt->pDnode; - - SEpSet epSet = {0}; - dmGetMnodeEpSet(pMgmt, &epSet); - - dDebug("RPC %p, req is redirected, num:%d use:%d", pReq->handle, epSet.numOfEps, epSet.inUse); - for (int32_t i = 0; i < epSet.numOfEps; ++i) { - dDebug("mnode index:%d %s:%u", i, epSet.eps[i].fqdn, epSet.eps[i].port); - if (strcmp(epSet.eps[i].fqdn, pDnode->localFqdn) == 0 && epSet.eps[i].port == pDnode->serverPort) { - epSet.inUse = (i + 1) % epSet.numOfEps; - } - - epSet.eps[i].port = htons(epSet.eps[i].port); - } - - rpcSendRedirectRsp(pReq->handle, &epSet); -} - -static int32_t dmStart(SMgmtWrapper *pWrapper) { - dDebug("dnode-mgmt start to run"); - return dmStartThread(pWrapper->pMgmt); -} - -static int32_t dmInit(SMgmtWrapper *pWrapper) { - SDnode *pDnode = pWrapper->pDnode; - SDnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeMgmt)); - dInfo("dnode-mgmt start to init"); - - pDnode->dnodeId = 0; - pDnode->dropped = 0; - pDnode->clusterId = 0; - pMgmt->path = pWrapper->path; - pMgmt->pDnode = pDnode; - pMgmt->pWrapper = pWrapper; - taosInitRWLatch(&pMgmt->latch); - - pMgmt->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); - if (pMgmt->dnodeHash == NULL) { - dError("failed to init dnode hash"); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - if (dmReadFile(pMgmt) != 0) { - dError("failed to read file since %s", terrstr()); - return -1; - } - - if (pDnode->dropped) { - dError("dnode will not start since its already dropped"); - return -1; - } - - if (dmStartWorker(pMgmt) != 0) { - return -1; - } - - if (dndInitTrans(pDnode) != 0) { - dError("failed to init transport since %s", terrstr()); - return -1; - } - - pWrapper->pMgmt = pMgmt; - pMgmt->msgCb = dndCreateMsgcb(pWrapper); - - dInfo("dnode-mgmt is initialized"); - return 0; -} - -static void dmCleanup(SMgmtWrapper *pWrapper) { - SDnodeMgmt *pMgmt = pWrapper->pMgmt; - if (pMgmt == NULL) return; - - dInfo("dnode-mgmt start to clean up"); - SDnode *pDnode = pMgmt->pDnode; - dmStopWorker(pMgmt); - - taosWLockLatch(&pMgmt->latch); - - if (pMgmt->dnodeEps != NULL) { - taosArrayDestroy(pMgmt->dnodeEps); - pMgmt->dnodeEps = NULL; - } - - if (pMgmt->dnodeHash != NULL) { - taosHashCleanup(pMgmt->dnodeHash); - pMgmt->dnodeHash = NULL; - } - - taosWUnLockLatch(&pMgmt->latch); - - taosMemoryFree(pMgmt); - pWrapper->pMgmt = NULL; - dndCleanupTrans(pDnode); - - dInfo("dnode-mgmt is cleaned up"); -} - -static int32_t dmRequire(SMgmtWrapper *pWrapper, bool *required) { - *required = true; - return 0; -} - -void dmSetMgmtFp(SMgmtWrapper *pWrapper) { - SMgmtFp mgmtFp = {0}; - mgmtFp.openFp = dmInit; - mgmtFp.closeFp = dmCleanup; - mgmtFp.startFp = dmStart; - mgmtFp.requiredFp = dmRequire; - - dmInitMsgHandle(pWrapper); - pWrapper->name = "dnode"; - pWrapper->fp = mgmtFp; -} diff --git a/source/dnode/mgmt/dm/dmWorker.c b/source/dnode/mgmt/dm/dmWorker.c deleted file mode 100644 index 7009469c00dae45ec100f08718bdd22239edbeba..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/dm/dmWorker.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "dmInt.h" - -static void *dmThreadRoutine(void *param) { - SDnodeMgmt *pMgmt = param; - SDnode *pDnode = pMgmt->pDnode; - int64_t lastStatusTime = taosGetTimestampMs(); - int64_t lastMonitorTime = lastStatusTime; - - setThreadName("dnode-hb"); - - while (true) { - taosThreadTestCancel(); - taosMsleep(200); - if (dndGetStatus(pDnode) != DND_STAT_RUNNING || pDnode->dropped) { - continue; - } - - int64_t curTime = taosGetTimestampMs(); - float statusInterval = (curTime - lastStatusTime) / 1000.0f; - if (statusInterval >= tsStatusInterval && !pMgmt->statusSent) { - dmSendStatusReq(pMgmt); - lastStatusTime = curTime; - } - - float monitorInterval = (curTime - lastMonitorTime) / 1000.0f; - if (monitorInterval >= tsMonitorInterval) { - dmSendMonitorReport(pDnode); - lastMonitorTime = curTime; - } - } - return TSDB_CODE_SUCCESS; -} - -int32_t dmStartThread(SDnodeMgmt *pMgmt) { - pMgmt->threadId = taosCreateThread(dmThreadRoutine, pMgmt); - if (pMgmt->threadId == NULL) { - dError("failed to init dnode thread"); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - return 0; -} - -static void dmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) { - SDnodeMgmt *pMgmt = pInfo->ahandle; - - SDnode *pDnode = pMgmt->pDnode; - SRpcMsg *pRpc = &pMsg->rpcMsg; - int32_t code = -1; - dTrace("msg:%p, will be processed in dnode queue", pMsg); - - switch (pRpc->msgType) { - case TDMT_DND_CONFIG_DNODE: - code = dmProcessConfigReq(pMgmt, pMsg); - break; - case TDMT_MND_STATUS_RSP: - code = dmProcessStatusRsp(pMgmt, pMsg); - break; - case TDMT_MND_AUTH_RSP: - code = dmProcessAuthRsp(pMgmt, pMsg); - break; - case TDMT_MND_GRANT_RSP: - code = dmProcessGrantRsp(pMgmt, pMsg); - break; - default: - code = dmProcessCDnodeReq(pMgmt->pDnode, pMsg); - break; - } - - if (pRpc->msgType & 1u) { - if (code != 0) code = terrno; - SRpcMsg rsp = {.handle = pRpc->handle, .ahandle = pRpc->ahandle, .code = code}; - rpcSendResponse(&rsp); - } - - dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code)); - rpcFreeCont(pMsg->rpcMsg.pCont); - taosFreeQitem(pMsg); -} - -int32_t dmStartWorker(SDnodeMgmt *pMgmt) { - SSingleWorkerCfg mcfg = {.min = 1, .max = 1, .name = "dnode-mgmt", .fp = (FItem)dmProcessQueue, .param = pMgmt}; - if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mcfg) != 0) { - dError("failed to start dnode mgmt worker since %s", terrstr()); - return -1; - } - - SSingleWorkerCfg scfg = {.min = 1, .max = 1, .name = "dnode-monitor", .fp = (FItem)dmProcessQueue, .param = pMgmt}; - if (tSingleWorkerInit(&pMgmt->monitorWorker, &scfg) != 0) { - dError("failed to start dnode monitor worker since %s", terrstr()); - return -1; - } - - dDebug("dnode workers are initialized"); - return 0; -} - -void dmStopWorker(SDnodeMgmt *pMgmt) { - tSingleWorkerCleanup(&pMgmt->mgmtWorker); - tSingleWorkerCleanup(&pMgmt->monitorWorker); - - if (pMgmt->threadId != NULL) { - taosDestoryThread(pMgmt->threadId); - pMgmt->threadId = NULL; - } - dDebug("dnode workers are closed"); -} - -int32_t dmProcessMgmtMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SDnodeMgmt *pMgmt = pWrapper->pMgmt; - SSingleWorker *pWorker = &pMgmt->mgmtWorker; - - dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); - taosWriteQitem(pWorker->queue, pMsg); - return 0; -} - -int32_t dmProcessMonitorMsg(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SDnodeMgmt *pMgmt = pWrapper->pMgmt; - SSingleWorker *pWorker = &pMgmt->monitorWorker; - - dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); - taosWriteQitem(pWorker->queue, pMsg); - return 0; -} diff --git a/source/dnode/mgmt/exe/dndMain.c b/source/dnode/mgmt/exe/dmMain.c similarity index 69% rename from source/dnode/mgmt/exe/dndMain.c rename to source/dnode/mgmt/exe/dmMain.c index ae2b7343198b25af97fade9eb0e13953b7c842c7..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 "mndGrant.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() { - parseGrantParameter(); -} +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..38885333c9253badd1d9af26cb6ee74510269c80 --- /dev/null +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#define _DEFAULT_SOURCE +#include "mmInt.h" + +void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo) { + SMnodeMgmt *pMgmt = pWrapper->pMgmt; + mndGetMonitorInfo(pMgmt->pMnode, &mmInfo->cluster, &mmInfo->vgroup, &mmInfo->grant); +} + +int32_t mmProcessGetMonMmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { + SMonMmInfo mmInfo = {0}; + mmGetMonitorInfo(pWrapper, &mmInfo); + dmGetMonitorSysInfo(&mmInfo.sys); + monGetLogs(&mmInfo.log); + + int32_t rspLen = tSerializeSMonMmInfo(NULL, 0, &mmInfo); + if (rspLen < 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + void *pRsp = rpcMallocCont(rspLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + tSerializeSMonMmInfo(pRsp, rspLen, &mmInfo); + pReq->pRsp = pRsp; + pReq->rspLen = rspLen; + tFreeSMonMmInfo(&mmInfo); + return 0; +} + +int32_t mmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SDnode *pDnode = pWrapper->pDnode; + SRpcMsg *pReq = &pMsg->rpcMsg; + + SDCreateMnodeReq createReq = {0}; + if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + if (createReq.replica <= 1 || createReq.dnodeId != pDnode->data.dnodeId) { + terrno = TSDB_CODE_INVALID_OPTION; + dError("failed to create mnode since %s", terrstr()); + return -1; + } + + bool deployed = true; + if (mmWriteFile(pWrapper, &createReq, deployed) != 0) { + dError("failed to write mnode file since %s", terrstr()); + return -1; + } + + return 0; +} + +int32_t mmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { + SDnode *pDnode = pWrapper->pDnode; + SRpcMsg *pReq = &pMsg->rpcMsg; + + SDDropMnodeReq dropReq = {0}; + if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + if (dropReq.dnodeId != pDnode->data.dnodeId) { + terrno = TSDB_CODE_INVALID_OPTION; + dError("failed to drop mnode since %s", terrstr()); + return -1; + } + + bool deployed = false; + if (mmWriteFile(pWrapper, NULL, deployed) != 0) { + dError("failed to write mnode file since %s", terrstr()); + return -1; + } + + return 0; +} + +int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) { + SDnode *pDnode = pMgmt->pDnode; + SRpcMsg *pReq = &pMsg->rpcMsg; + + SDAlterMnodeReq alterReq = {0}; + if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &alterReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + if (alterReq.dnodeId != pDnode->data.dnodeId) { + terrno = TSDB_CODE_INVALID_OPTION; + dError("failed to alter mnode since %s, dnodeId:%d input:%d", terrstr(), pDnode->data.dnodeId, alterReq.dnodeId); + return -1; + } else { + return mmAlter(pMgmt, &alterReq); + } +} + +void mmInitMsgHandle(SMgmtWrapper *pWrapper) { + dmSetMsgHandle(pWrapper, TDMT_MON_MM_INFO, mmProcessMonitorMsg, DEFAULT_HANDLE); + + // Requests handled by DNODE + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_MNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_QNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_QNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_SNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_SNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_BNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_BNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_CONFIG_DNODE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + + // Requests handled by MNODE + dmSetMsgHandle(pWrapper, TDMT_MND_CONNECT, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_ACCT, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_USER, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_USER, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_USER, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_GET_USER_AUTH, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CONFIG_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_DNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_QNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_SNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_BNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_USE_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_SYNC_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_COMPACT_DB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_RETRIEVE_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_FUNC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_STB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_STB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_STB, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_SMA, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_SMA, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_TABLE_META, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_VGROUP_LIST, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_KILL_QUERY, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_KILL_CONN, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_HEARTBEAT, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_SYSTABLE_RETRIEVE, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_STATUS, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_KILL_TRANS, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_GRANT, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_AUTH, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_MNODE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_ALTER_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_DROP_TOPIC, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_SUBSCRIBE, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_MQ_COMMIT_OFFSET, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_GET_SUB_EP, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_STREAM, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_GET_DB_CFG, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_MND_GET_INDEX, mmProcessReadMsg, DEFAULT_HANDLE); + + // Requests handled by VNODE + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_REB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_STB_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); + + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY, mmProcessQueryMsg, MNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, mmProcessQueryMsg, MNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_FETCH, mmProcessQueryMsg, MNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, mmProcessQueryMsg, MNODE_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, mmProcessQueryMsg, MNODE_HANDLE); +} diff --git a/source/dnode/mgmt/mm/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c similarity index 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 96fb4d20e40d7f41b83ea5c34676258aa99567ba..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,27 +78,32 @@ int32_t qmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { return -1; } - if (dropReq.dnodeId != pDnode->dnodeId) { + if (dropReq.dnodeId != pDnode->data.dnodeId) { terrno = TSDB_CODE_INVALID_OPTION; dError("failed to drop qnode since %s", terrstr()); return -1; - } else { - // 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); + 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 72% rename from source/dnode/mgmt/vm/vmHandle.c rename to source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 3623654218209319a8642a8dcd7a97805272603b..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,52 +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_MQ_SET_CONN, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_CONSUME, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, (NodeMsgFp)vmProcessMergeMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_TASK_WRITE_EXEC, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); - - dndSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); - dndSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_SUBMIT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_FETCH, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_UPDATE_TAG_VAL, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TABLE_META, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TABLES_META, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CONSUME, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_QUERY, (NodeMsgFp)vmProcessQueryMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CONNECT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_DISCONNECT, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_RES_READY, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_ALTER_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_STB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_TABLE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CANCEL_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_CONSUME, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, (NodeMsgFp)vmProcessMergeMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_TASK_WRITE_EXEC, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, (NodeMsgFp)vmProcessFetchMsg, DEFAULT_HANDLE); + + dmSetMsgHandle(pWrapper, TDMT_DND_CREATE_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_ALTER_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_DROP_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_SYNC_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_DND_COMPACT_VNODE, vmProcessMgmtMsg, DEFAULT_HANDLE); } diff --git a/source/dnode/mgmt/vm/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c similarity index 97% rename from source/dnode/mgmt/vm/vmInt.c rename to source/dnode/mgmt/mgmt_vnode/src/vmInt.c index 6a1a5c3987ccb50c1a0008e29298e2d67148061b..1b8e0eb961e4d43800557a16ee8c9c212f422eb2 100644 --- a/source/dnode/mgmt/vm/vmInt.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c @@ -126,9 +126,9 @@ static void *vmOpenVnodeFunc(void *param) { char stepDesc[TSDB_STEP_DESC_LEN] = {0}; snprintf(stepDesc, TSDB_STEP_DESC_LEN, "vgId:%d, start to restore, %d of %d have been opened", pCfg->vgId, pMgmt->state.openVnodes, pMgmt->state.totalVnodes); - dndReportStartup(pDnode, "open-vnodes", stepDesc); + dmReportStartup(pDnode, "open-vnodes", stepDesc); - SMsgCb msgCb = dndCreateMsgcb(pMgmt->pWrapper); + SMsgCb msgCb = pMgmt->pDnode->data.msgCb; msgCb.pWrapper = pMgmt->pWrapper; msgCb.queueFps[QUERY_QUEUE] = vmPutMsgToQueryQueue; msgCb.queueFps[FETCH_QUEUE] = vmPutMsgToFetchQueue; @@ -278,11 +278,11 @@ static int32_t vmInit(SMgmtWrapper *pWrapper) { taosInitRWLatch(&pMgmt->latch); SDiskCfg dCfg = {0}; - tstrncpy(dCfg.dir, pDnode->dataDir, TSDB_FILENAME_LEN); + tstrncpy(dCfg.dir, pDnode->data.dataDir, TSDB_FILENAME_LEN); dCfg.level = 0; dCfg.primary = 1; - SDiskCfg *pDisks = pDnode->disks; - int32_t numOfDisks = pDnode->numOfDisks; + SDiskCfg *pDisks = pDnode->data.disks; + int32_t numOfDisks = pDnode->data.numOfDisks; if (numOfDisks <= 0 || pDisks == NULL) { pDisks = &dCfg; numOfDisks = 1; @@ -299,7 +299,7 @@ static int32_t vmInit(SMgmtWrapper *pWrapper) { goto _OVER; } - if (vnodeInit() != 0) { + if (vnodeInit(tsNumOfCommitThreads) != 0) { dError("failed to init vnode since %s", terrstr()); goto _OVER; } @@ -329,7 +329,7 @@ _OVER: static int32_t vmRequire(SMgmtWrapper *pWrapper, bool *required) { SDnode *pDnode = pWrapper->pDnode; - *required = pDnode->numOfSupportVnodes > 0; + *required = pDnode->data.supportVnodes > 0; return 0; } diff --git a/source/dnode/mgmt/vm/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c similarity index 98% rename from source/dnode/mgmt/vm/vmWorker.c rename to source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index ff92cf880b0107f2544d0ef58664fc41c65464f7..2fb29ce944ac4e5f0ee7e6386a76111af6dc4942 100644 --- a/source/dnode/mgmt/vm/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -115,7 +115,7 @@ static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO } } - vnodeProcessWMsgs(pVnode->pImpl, pArray); + vnodePreprocessWriteReqs(pVnode->pImpl, pArray); numOfMsgs = taosArrayGetSize(pArray); for (int32_t i = 0; i < numOfMsgs; i++) { @@ -123,7 +123,7 @@ static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO SRpcMsg *pRpc = &pMsg->rpcMsg; SRpcMsg *pRsp = NULL; - int32_t code = vnodeApplyWMsg(pVnode->pImpl, pRpc, &pRsp); + int32_t code = vnodeProcessWriteReq(pVnode->pImpl, pRpc, &pRsp); if (pRsp != NULL) { pRsp->ahandle = pRpc->ahandle; tmsgSendRsp(pRsp); @@ -153,7 +153,7 @@ static void vmProcessApplyQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO // todo SRpcMsg *pRsp = NULL; - (void)vnodeApplyWMsg(pVnode->pImpl, &pMsg->rpcMsg, &pRsp); + (void)vnodeProcessWriteReq(pVnode->pImpl, &pMsg->rpcMsg, &pRsp); } } diff --git a/source/dnode/mgmt/mm/mmHandle.c b/source/dnode/mgmt/mm/mmHandle.c deleted file mode 100644 index c4b99c2bc9726a3f9013931fb53a91f3fbda56c0..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/mm/mmHandle.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "mmInt.h" - -void mmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonMmInfo *mmInfo) { - SMnodeMgmt *pMgmt = pWrapper->pMgmt; - mndGetMonitorInfo(pMgmt->pMnode, &mmInfo->cluster, &mmInfo->vgroup, &mmInfo->grant); -} - -int32_t mmProcessGetMonMmInfoReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) { - SMonMmInfo mmInfo = {0}; - mmGetMonitorInfo(pWrapper, &mmInfo); - dmGetMonitorSysInfo(&mmInfo.sys); - monGetLogs(&mmInfo.log); - - int32_t rspLen = tSerializeSMonMmInfo(NULL, 0, &mmInfo); - if (rspLen < 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - void *pRsp = rpcMallocCont(rspLen); - if (pRsp == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - tSerializeSMonMmInfo(pRsp, rspLen, &mmInfo); - pReq->pRsp = pRsp; - pReq->rspLen = rspLen; - tFreeSMonMmInfo(&mmInfo); - return 0; -} - -int32_t mmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SDnode *pDnode = pWrapper->pDnode; - SRpcMsg *pReq = &pMsg->rpcMsg; - - SDCreateMnodeReq createReq = {0}; - if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &createReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - if (createReq.replica <= 1 || createReq.dnodeId != pDnode->dnodeId) { - terrno = TSDB_CODE_INVALID_OPTION; - dError("failed to create mnode since %s", terrstr()); - return -1; - } else { - return mmOpenFromMsg(pWrapper, &createReq); - } -} - -int32_t mmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) { - SDnode *pDnode = pWrapper->pDnode; - SRpcMsg *pReq = &pMsg->rpcMsg; - - SDDropMnodeReq dropReq = {0}; - if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - if (dropReq.dnodeId != pDnode->dnodeId) { - terrno = TSDB_CODE_INVALID_OPTION; - dError("failed to drop mnode since %s", terrstr()); - return -1; - } else { - // 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_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/inc/sut.h b/source/dnode/mgmt/test/sut/inc/sut.h index 1dd68574fec694231fb2d903e41ca35873a67518..268f779fcf81900d990b4327efbdc9be1f482442 100644 --- a/source/dnode/mgmt/test/sut/inc/sut.h +++ b/source/dnode/mgmt/test/sut/inc/sut.h @@ -20,7 +20,6 @@ #include "os.h" #include "dnode.h" -#include "tmsg.h" #include "tdataformat.h" #include "tglobal.h" #include "tmsg.h" @@ -48,92 +47,61 @@ class Testbase { int32_t connId; public: - void SendShowMetaReq(int8_t showType, const char* db); - void SendShowRetrieveReq(); - - STableMetaRsp* GetShowMeta(); - SRetrieveTableRsp* GetRetrieveRsp(); + int32_t SendShowReq(int8_t showType, const char *tb, const char* db); + int32_t GetShowRows(); +#if 0 int32_t GetMetaNum(); const char* GetMetaTbName(); - int32_t GetMetaColId(int32_t index); - int8_t GetMetaType(int32_t index); - int32_t GetMetaBytes(int32_t index); - const char* GetMetaName(int32_t index); - - const char* GetShowName(); - int32_t GetShowRows(); - int8_t GetShowInt8(); - int16_t GetShowInt16(); - int32_t GetShowInt32(); - int64_t GetShowInt64(); - int64_t GetShowTimestamp(); - const char* GetShowBinary(int32_t len); + int8_t GetMetaType(int32_t col); + int32_t GetMetaBytes(int32_t col); + const char* GetMetaName(int32_t col); + + int8_t GetShowInt8(int32_t row, int32_t col); + int16_t GetShowInt16(int32_t row, int32_t col); + int32_t GetShowInt32(int32_t row, int32_t col); + int64_t GetShowInt64(int32_t row, int32_t col); + int64_t GetShowTimestamp(int32_t row, int32_t col); + const char* GetShowBinary(int32_t row, int32_t col); +#endif private: - int64_t showId; - STableMetaRsp metaRsp; - SRetrieveTableRsp* pRetrieveRsp; - char* pData; - int32_t pos; + SRetrieveMetaTableRsp* showRsp; }; +#if 0 + #define CHECK_META(tbName, numOfColumns) \ { \ EXPECT_EQ(test.GetMetaNum(), numOfColumns); \ EXPECT_STREQ(test.GetMetaTbName(), tbName); \ } -#define CHECK_SCHEMA(colId, type, bytes, colName) \ - { \ - EXPECT_EQ(test.GetMetaType(colId), type); \ - EXPECT_EQ(test.GetMetaBytes(colId), bytes); \ - EXPECT_STREQ(test.GetMetaName(colId), colName); \ - } - -#define CheckBinary(val, len) \ - { EXPECT_STREQ(test.GetShowBinary(len), val); } - -#define CheckBinaryByte(b, len) \ +#define CHECK_SCHEMA(col, type, bytes, colName) \ { \ - char* bytes = (char*)taosMemoryCalloc(1, len); \ - for (int32_t i = 0; i < len - 1; ++i) { \ - bytes[i] = b; \ - } \ - EXPECT_STREQ(test.GetShowBinary(len), bytes); \ + EXPECT_EQ(test.GetMetaType(col), type); \ + EXPECT_EQ(test.GetMetaBytes(col), bytes); \ + EXPECT_STREQ(test.GetMetaName(col), colName); \ } +#define CheckBinary(row, col, val) \ + { EXPECT_STREQ(test.GetShowBinary(row, col), val); } + #define CheckInt8(val) \ - { EXPECT_EQ(test.GetShowInt8(), val); } + { EXPECT_EQ(test.GetShowInt8(row, col), val); } #define CheckInt16(val) \ - { EXPECT_EQ(test.GetShowInt16(), val); } + { EXPECT_EQ(test.GetShowInt16(row, col), val); } #define CheckInt32(val) \ - { EXPECT_EQ(test.GetShowInt32(), val); } + { EXPECT_EQ(test.GetShowInt32row, col(), val); } #define CheckInt64(val) \ - { EXPECT_EQ(test.GetShowInt64(), val); } + { EXPECT_EQ(test.GetShowInt64(row, col), val); } #define CheckTimestamp() \ - { EXPECT_GT(test.GetShowTimestamp(), 0); } - -#define IgnoreBinary(len) \ - { test.GetShowBinary(len); } - -#define IgnoreInt8() \ - { test.GetShowInt8(); } - -#define IgnoreInt16() \ - { test.GetShowInt16(); } - -#define IgnoreInt32() \ - { test.GetShowInt32(); } - -#define IgnoreInt64() \ - { test.GetShowInt64(); } + { EXPECT_GT(test.GetShowTimestamp(row, col), 0); } -#define IgnoreTimestamp() \ - { test.GetShowTimestamp(); } +#endif #endif /* _TD_TEST_BASE_H_ */ diff --git a/source/dnode/mgmt/test/sut/src/server.cpp b/source/dnode/mgmt/test/sut/src/server.cpp index c5379c6d174dce3f4dce5f1cba834e93a5549207..91db59757bf4508d633fd76fb86471707682ec00 100644 --- a/source/dnode/mgmt/test/sut/src/server.cpp +++ b/source/dnode/mgmt/test/sut/src/server.cpp @@ -17,7 +17,7 @@ void* serverLoop(void* param) { SDnode* pDnode = (SDnode*)param; - dndRun(pDnode); + dmRun(pDnode); return NULL; } @@ -36,7 +36,7 @@ bool TestServer::DoStart() { SDnodeOpt option = BuildOption(path, fqdn, port, firstEp); taosMkDir(path); - pDnode = dndCreate(&option); + pDnode = dmCreate(&option); if (pDnode == NULL) { return false; } @@ -68,11 +68,11 @@ bool TestServer::Start(const char* path, const char* fqdn, uint16_t port, const } void TestServer::Stop() { - dndHandleEvent(pDnode, DND_EVENT_STOP); + dmSetEvent(pDnode, DND_EVENT_STOP); taosThreadJoin(threadId, NULL); if (pDnode != NULL) { - dndClose(pDnode); + dmClose(pDnode); pDnode = NULL; } } diff --git a/source/dnode/mgmt/test/sut/src/sut.cpp b/source/dnode/mgmt/test/sut/src/sut.cpp index 01532e66f970662fd25728e9bb8b308f4506196f..9b4c4798653858ad22beb7ed637da3b6352674f4 100644 --- a/source/dnode/mgmt/test/sut/src/sut.cpp +++ b/source/dnode/mgmt/test/sut/src/sut.cpp @@ -40,7 +40,7 @@ void Testbase::InitLog(const char* path) { } void Testbase::Init(const char* path, int16_t port) { - dndInit(); + dmInit(); char fqdn[] = "localhost"; char firstEp[TSDB_EP_LEN] = {0}; @@ -49,20 +49,18 @@ void Testbase::Init(const char* path, int16_t port) { InitLog("/tmp/td"); server.Start(path, fqdn, port, firstEp); client.Init("root", "taosdata", fqdn, port); - - tFreeSTableMetaRsp(&metaRsp); - showId = 0; - pData = 0; - pos = 0; - pRetrieveRsp = NULL; + showRsp = NULL; } void Testbase::Cleanup() { - tFreeSTableMetaRsp(&metaRsp); + if (showRsp != NULL) { + rpcFreeCont(showRsp); + showRsp = NULL; + } client.Cleanup(); taosMsleep(10); server.Stop(); - dndCleanup(); + dmCleanup(); } void Testbase::Restart() { @@ -84,112 +82,40 @@ SRpcMsg* Testbase::SendReq(tmsg_t msgType, void* pCont, int32_t contLen) { return client.SendReq(&rpcMsg); } -void Testbase::SendShowMetaReq(int8_t showType, const char* db) { - SShowReq showReq = {0}; - showReq.type = showType; - strcpy(showReq.db, db); - - int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq); - void* pReq = rpcMallocCont(contLen); - tSerializeSShowReq(pReq, contLen, &showReq); - tFreeSShowReq(&showReq); - - SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW, pReq, contLen); - ASSERT(pRsp->pCont != nullptr); - - if (pRsp->contLen == 0) return; - - SShowRsp showRsp = {0}; - tDeserializeSShowRsp(pRsp->pCont, pRsp->contLen, &showRsp); - tFreeSTableMetaRsp(&metaRsp); - metaRsp = showRsp.tableMeta; - showId = showRsp.showId; -} - -int32_t Testbase::GetMetaColId(int32_t index) { - SSchema* pSchema = &metaRsp.pSchemas[index]; - return pSchema->colId; -} - -int8_t Testbase::GetMetaType(int32_t index) { - SSchema* pSchema = &metaRsp.pSchemas[index]; - return pSchema->type; -} - -int32_t Testbase::GetMetaBytes(int32_t index) { - SSchema* pSchema = &metaRsp.pSchemas[index]; - return pSchema->bytes; -} - -const char* Testbase::GetMetaName(int32_t index) { - SSchema* pSchema = &metaRsp.pSchemas[index]; - return pSchema->name; -} - -int32_t Testbase::GetMetaNum() { return metaRsp.numOfColumns; } - -const char* Testbase::GetMetaTbName() { return metaRsp.tbName; } +int32_t Testbase::SendShowReq(int8_t showType, const char *tb, const char* db) { + if (showRsp != NULL) { + rpcFreeCont(showRsp); + showRsp = NULL; + } -void Testbase::SendShowRetrieveReq() { SRetrieveTableReq retrieveReq = {0}; - retrieveReq.showId = showId; -// retrieveReq.free = 0; + retrieveReq.type = showType; + strcpy(retrieveReq.db, db); + strcpy(retrieveReq.tb, tb); int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &retrieveReq); void* pReq = rpcMallocCont(contLen); tSerializeSRetrieveTableReq(pReq, contLen, &retrieveReq); -// SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW_RETRIEVE, pReq, contLen); -// pRetrieveRsp = (SRetrieveTableRsp*)pRsp->pCont; -// pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); -// pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); -// pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen); - - pData = pRetrieveRsp->data; - pos = 0; -} - -const char* Testbase::GetShowName() { return metaRsp.tbName; } - -int8_t Testbase::GetShowInt8() { - int8_t data = *((int8_t*)(pData + pos)); - pos += sizeof(int8_t); - return data; -} - -int16_t Testbase::GetShowInt16() { - int16_t data = *((int16_t*)(pData + pos)); - pos += sizeof(int16_t); - return data; -} + SRpcMsg* pRsp = SendReq(TDMT_MND_SYSTABLE_RETRIEVE, pReq, contLen); + ASSERT(pRsp->pCont != nullptr); -int32_t Testbase::GetShowInt32() { - int32_t data = *((int32_t*)(pData + pos)); - pos += sizeof(int32_t); - return data; -} + if (pRsp->contLen == 0) return -1; -int64_t Testbase::GetShowInt64() { - int64_t data = *((int64_t*)(pData + pos)); - pos += sizeof(int64_t); - return data; -} + showRsp = (SRetrieveMetaTableRsp*)pRsp->pCont; + showRsp->handle = htobe64(showRsp->handle); // show Id + showRsp->useconds = htobe64(showRsp->useconds); + showRsp->numOfRows = htonl(showRsp->numOfRows); + showRsp->compLen = htonl(showRsp->compLen); + if (showRsp->numOfRows <= 0) return -1; -int64_t Testbase::GetShowTimestamp() { - int64_t data = *((int64_t*)(pData + pos)); - pos += sizeof(int64_t); - return data; + return 0; } -const char* Testbase::GetShowBinary(int32_t len) { - pos += sizeof(VarDataLenT); - char* data = (char*)(pData + pos); - pos += len; - return data; +int32_t Testbase::GetShowRows() { + if (showRsp != NULL) { + return showRsp->numOfRows; + } else { + return 0; + } } - -int32_t Testbase::GetShowRows() { return pRetrieveRsp->numOfRows; } - -STableMetaRsp* Testbase::GetShowMeta() { return &metaRsp; } - -SRetrieveTableRsp* Testbase::GetRetrieveRsp() { return pRetrieveRsp; } diff --git a/source/dnode/mgmt/test/vnode/CMakeLists.txt b/source/dnode/mgmt/test/vnode/CMakeLists.txt index e2cd868513c9e0dd0fe265e61f62ba9da45ab2c6..34402286aa6f0426dce70e17fd30625c357a17cc 100644 --- a/source/dnode/mgmt/test/vnode/CMakeLists.txt +++ b/source/dnode/mgmt/test/vnode/CMakeLists.txt @@ -1,5 +1,5 @@ -aux_source_directory(. VNODE_SRC) -add_executable(dvnodeTest ${VNODE_SRC}) +aux_source_directory(. DND_VNODE_TEST_SRC) +add_executable(dvnodeTest ${DND_VNODE_TEST_SRC}) target_link_libraries( dvnodeTest PUBLIC sut diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index e827dd5131872b956d8dea9c4d3e4a6f02a9fc81..5b96416fd719ea5b50ddc275f5165a50c4d4f535 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -213,7 +213,7 @@ typedef struct { int32_t maxConsumers; int32_t maxConns; int32_t maxTopics; - int64_t maxStorage; // In unit of GB + int64_t maxStorage; int32_t accessState; // Configured only by command } SAcctCfg; @@ -379,20 +379,20 @@ typedef struct { } SFuncObj; typedef struct { - int64_t id; - int8_t type; - int8_t replica; - int16_t numOfColumns; - int32_t rowSize; - int32_t numOfRows; - int32_t payloadLen; - void* pIter; - SMnode* pMnode; + int64_t id; + int8_t type; + int8_t replica; + int16_t numOfColumns; + int32_t rowSize; + int32_t numOfRows; + int32_t payloadLen; + void* pIter; + SMnode* pMnode; STableMetaRsp* pMeta; - bool sysDbRsp; - char db[TSDB_DB_FNAME_LEN]; - int16_t offset[TSDB_MAX_COLUMNS]; - int32_t bytes[TSDB_MAX_COLUMNS]; + bool sysDbRsp; + char db[TSDB_DB_FNAME_LEN]; + int16_t offset[TSDB_MAX_COLUMNS]; + int32_t bytes[TSDB_MAX_COLUMNS]; } SShowObj; typedef struct { @@ -625,14 +625,14 @@ static FORCE_INLINE void* tDecodeSubscribeObj(void* buf, SMqSubscribeObj* pSub) static FORCE_INLINE void tDeleteSMqSubscribeObj(SMqSubscribeObj* pSub) { if (pSub->consumers) { - //taosArrayDestroyEx(pSub->consumers, (void (*)(void*))tDeleteSMqSubConsumer); - // taosArrayDestroy(pSub->consumers); + // taosArrayDestroyEx(pSub->consumers, (void (*)(void*))tDeleteSMqSubConsumer); + // taosArrayDestroy(pSub->consumers); pSub->consumers = NULL; } if (pSub->unassignedVg) { - //taosArrayDestroyEx(pSub->unassignedVg, (void (*)(void*))tDeleteSMqConsumerEp); - // taosArrayDestroy(pSub->unassignedVg); + // taosArrayDestroyEx(pSub->unassignedVg, (void (*)(void*))tDeleteSMqConsumerEp); + // taosArrayDestroy(pSub->unassignedVg); pSub->unassignedVg = NULL; } } @@ -647,8 +647,9 @@ typedef struct { int32_t version; SRWLatch lock; int32_t sqlLen; + int32_t astLen; char* sql; - char* logicalPlan; + char* ast; char* physicalPlan; SSchemaWrapper schema; } SMqTopicObj; diff --git a/source/dnode/mnode/impl/inc/mndGrant.h b/source/dnode/mnode/impl/inc/mndGrant.h index a2ff5ea6ce0068ad73192e491367de926a552ea7..ad3dc7f79d2d9925e223880bde05560f1587fb11 100644 --- a/source/dnode/mnode/impl/inc/mndGrant.h +++ b/source/dnode/mnode/impl/inc/mndGrant.h @@ -44,7 +44,6 @@ void grantReset(EGrantType grant, uint64_t value); void grantAdd(EGrantType grant, uint64_t value); void grantRestore(EGrantType grant, uint64_t value); -void parseGrantParameter(); #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/inc/mndInfoSchema.h b/source/dnode/mnode/impl/inc/mndInfoSchema.h index 7db41254027c3c2924e094ae806bbcc8907f0981..3aea99a909e02796dfbd9862c56339f9f1ba27c4 100644 --- a/source/dnode/mnode/impl/inc/mndInfoSchema.h +++ b/source/dnode/mnode/impl/inc/mndInfoSchema.h @@ -23,20 +23,20 @@ extern "C" { #endif typedef struct SInfosTableSchema { - char *name; - int32_t type; - int32_t bytes; + const char *name; + const int32_t type; + const int32_t bytes; } SInfosTableSchema; typedef struct SInfosTableMeta { - char *name; + const char *name; const SInfosTableSchema *schema; - int32_t colNum; + const int32_t colNum; } SInfosTableMeta; -int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp); int32_t mndInitInfos(SMnode *pMnode); -void mndCleanupInfos(SMnode *pMnode); +void mndCleanupInfos(SMnode *pMnode); +int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndShow.h b/source/dnode/mnode/impl/inc/mndShow.h index a269fa35c1ded912ce3be8d463df23132184fb5c..03f901e9c412e1ddf466cf336190d4fe7a590b0c 100644 --- a/source/dnode/mnode/impl/inc/mndShow.h +++ b/source/dnode/mnode/impl/inc/mndShow.h @@ -26,8 +26,6 @@ int32_t mndInitShow(SMnode *pMnode); void mndCleanupShow(SMnode *pMnode); void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp); void mndAddShowFreeIterHandle(SMnode *pMnode, EShowType msgType, ShowFreeIterFp fp); -void mndVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_t capacity, SShowObj *pShow); -char *mndShowStr(int32_t showType); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index 68c8c6d12744b79433b5f00a3bfe3f97dab0495b..25bf20fa0d5d53e1352fb838d620d916392f814f 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -17,7 +17,7 @@ #include "mndAcct.h" #include "mndShow.h" -#define TSDB_ACCT_VER_NUMBER 1 +#define TSDB_ACCT_VER_NUMBER 1 #define TSDB_ACCT_RESERVE_SIZE 128 static int32_t mndCreateDefaultAcct(SMnode *pMnode); @@ -80,32 +80,32 @@ static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) { terrno = TSDB_CODE_OUT_OF_MEMORY; SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, TSDB_ACCT_VER_NUMBER, sizeof(SAcctObj) + TSDB_ACCT_RESERVE_SIZE); - if (pRaw == NULL) goto ACCT_ENCODE_OVER; + if (pRaw == NULL) goto _OVER; int32_t dataPos = 0; - SDB_SET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN, ACCT_ENCODE_OVER) - SDB_SET_INT64(pRaw, dataPos, pAcct->createdTime, ACCT_ENCODE_OVER) - SDB_SET_INT64(pRaw, dataPos, pAcct->updateTime, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->acctId, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->status, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxUsers, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxDbs, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStbs, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTbs, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTimeSeries, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStreams, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxFuncs, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxConsumers, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxConns, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTopics, ACCT_ENCODE_OVER) - SDB_SET_INT64(pRaw, dataPos, pAcct->cfg.maxStorage, ACCT_ENCODE_OVER) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.accessState, ACCT_ENCODE_OVER) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, ACCT_ENCODE_OVER) - SDB_SET_DATALEN(pRaw, dataPos, ACCT_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN, _OVER) + SDB_SET_INT64(pRaw, dataPos, pAcct->createdTime, _OVER) + SDB_SET_INT64(pRaw, dataPos, pAcct->updateTime, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->acctId, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->status, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxUsers, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxDbs, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStbs, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTbs, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTimeSeries, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStreams, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxFuncs, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxConsumers, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxConns, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTopics, _OVER) + SDB_SET_INT64(pRaw, dataPos, pAcct->cfg.maxStorage, _OVER) + SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.accessState, _OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, _OVER) + SDB_SET_DATALEN(pRaw, dataPos, _OVER) terrno = 0; -ACCT_ENCODE_OVER: +_OVER: if (terrno != 0) { mError("acct:%s, failed to encode to raw:%p since %s", pAcct->acct, pRaw, terrstr()); sdbFreeRaw(pRaw); @@ -120,42 +120,42 @@ static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) { terrno = TSDB_CODE_OUT_OF_MEMORY; int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto ACCT_DECODE_OVER; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto _OVER; if (sver != TSDB_ACCT_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - goto ACCT_DECODE_OVER; + goto _OVER; } SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj)); - if (pRow == NULL) goto ACCT_DECODE_OVER; + if (pRow == NULL) goto _OVER; SAcctObj *pAcct = sdbGetRowObj(pRow); - if (pAcct == NULL) goto ACCT_DECODE_OVER; + if (pAcct == NULL) goto _OVER; int32_t dataPos = 0; - SDB_GET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN, ACCT_DECODE_OVER) - SDB_GET_INT64(pRaw, dataPos, &pAcct->createdTime, ACCT_DECODE_OVER) - SDB_GET_INT64(pRaw, dataPos, &pAcct->updateTime, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->acctId, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->status, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxUsers, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxDbs, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStbs, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTbs, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTimeSeries, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStreams, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxFuncs, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxConsumers, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxConns, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTopics, ACCT_DECODE_OVER) - SDB_GET_INT64(pRaw, dataPos, &pAcct->cfg.maxStorage, ACCT_DECODE_OVER) - SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.accessState, ACCT_DECODE_OVER) - SDB_GET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, ACCT_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN, _OVER) + SDB_GET_INT64(pRaw, dataPos, &pAcct->createdTime, _OVER) + SDB_GET_INT64(pRaw, dataPos, &pAcct->updateTime, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->acctId, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->status, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxUsers, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxDbs, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStbs, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTbs, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTimeSeries, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStreams, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxFuncs, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxConsumers, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxConns, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTopics, _OVER) + SDB_GET_INT64(pRaw, dataPos, &pAcct->cfg.maxStorage, _OVER) + SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.accessState, _OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, _OVER) terrno = 0; -ACCT_DECODE_OVER: +_OVER: if (terrno != 0) { mError("acct:%s, failed to decode from raw:%p since %s", pAcct->acct, pRaw, terrstr()); taosMemoryFreeClear(pRow); diff --git a/source/dnode/mnode/impl/src/mndAuth.c b/source/dnode/mnode/impl/src/mndAuth.c index 20dd7f1378ff857dd21c63cb6472668ce4ff2556..fc94ec364590872d87577211e8e8f8780673f643 100644 --- a/source/dnode/mnode/impl/src/mndAuth.c +++ b/source/dnode/mnode/impl/src/mndAuth.c @@ -26,22 +26,22 @@ int32_t mndInitAuth(SMnode *pMnode) { void mndCleanupAuth(SMnode *pMnode) {} -int32_t mndRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) { - SUserObj *pUser = mndAcquireUser(pMnode, user); +static int32_t mndRetriveAuth(SMnode *pMnode, SAuthRsp *pRsp) { + SUserObj *pUser = mndAcquireUser(pMnode, pRsp->user); if (pUser == NULL) { - *secret = 0; - mError("user:%s, failed to auth user since %s", user, terrstr()); + *pRsp->secret = 0; + mError("user:%s, failed to auth user since %s", pRsp->user, terrstr()); return -1; } - *spi = 1; - *encrypt = 0; - *ckey = 0; + pRsp->spi = 1; + pRsp->encrypt = 0; + *pRsp->ckey = 0; - memcpy(secret, pUser->pass, TSDB_PASSWORD_LEN); + memcpy(pRsp->secret, pUser->pass, TSDB_PASSWORD_LEN); mndReleaseUser(pMnode, pUser); - mDebug("user:%s, auth info is returned", user); + mDebug("user:%s, auth info is returned", pRsp->user); return 0; } @@ -55,14 +55,19 @@ static int32_t mndProcessAuthReq(SNodeMsg *pReq) { SAuthReq authRsp = {0}; memcpy(authRsp.user, authReq.user, TSDB_USER_LEN); - int32_t code = - mndRetriveAuth(pReq->pNode, authRsp.user, &authRsp.spi, &authRsp.encrypt, authRsp.secret, authRsp.ckey); + int32_t code = mndRetriveAuth(pReq->pNode, &authRsp); mTrace("user:%s, auth req received, spi:%d encrypt:%d ruser:%s", pReq->user, authRsp.spi, authRsp.encrypt, authRsp.user); int32_t contLen = tSerializeSAuthReq(NULL, 0, &authRsp); void *pRsp = rpcMallocCont(contLen); + if (pRsp == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + tSerializeSAuthReq(pRsp, contLen, &authRsp); + pReq->pRsp = pRsp; pReq->rspLen = contLen; return code; @@ -95,11 +100,11 @@ int32_t mndCheckAlterUserAuth(SUserObj *pOperUser, SUserObj *pUser, SDbObj *pDb, } } - if (pAlter->alterType == TSDB_ALTER_USER_CLEAR_WRITE_DB || pAlter->alterType == TSDB_ALTER_USER_CLEAR_READ_DB) { - if (pOperUser->superUser) { - return 0; - } + if (pAlter->alterType == TSDB_ALTER_USER_CLEAR_WRITE_DB || pAlter->alterType == TSDB_ALTER_USER_CLEAR_READ_DB) { + if (pOperUser->superUser) { + return 0; } + } if (pAlter->alterType == TSDB_ALTER_USER_ADD_READ_DB || pAlter->alterType == TSDB_ALTER_USER_REMOVE_READ_DB || pAlter->alterType == TSDB_ALTER_USER_ADD_WRITE_DB || pAlter->alterType == TSDB_ALTER_USER_REMOVE_WRITE_DB) { @@ -176,4 +181,4 @@ int32_t mndCheckReadAuth(SUserObj *pOperUser, SDbObj *pDb) { terrno = TSDB_CODE_MND_NO_RIGHTS; return -1; -} \ No newline at end of file +} diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index fc6ec86c4981aea0466abbb18566eb026b24199c..5ce87a413c7ac3c2637c1fd3f60e9451d3212b45 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -24,9 +24,6 @@ #define TSDB_DNODE_VER_NUMBER 1 #define TSDB_DNODE_RESERVE_SIZE 64 -#define TSDB_CONFIG_OPTION_LEN 16 -#define TSDB_CONIIG_VALUE_LEN 48 -#define TSDB_CONFIG_NUMBER 8 static const char *offlineReason[] = { "", @@ -55,7 +52,6 @@ static int32_t mndProcessConfigDnodeReq(SNodeMsg *pReq); static int32_t mndProcessConfigDnodeRsp(SNodeMsg *pRsp); static int32_t mndProcessStatusReq(SNodeMsg *pReq); -static int32_t mndGetConfigMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); static int32_t mndRetrieveConfigs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); static void mndCancelGetNextConfig(SMnode *pMnode, void *pIter); static int32_t mndRetrieveDnodes(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows); @@ -77,8 +73,8 @@ int32_t mndInitDnode(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_DND_CONFIG_DNODE_RSP, mndProcessConfigDnodeRsp); mndSetMsgHandle(pMnode, TDMT_MND_STATUS, mndProcessStatusReq); - mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_VARIABLES, mndRetrieveConfigs); - mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_VARIABLES, mndCancelGetNextConfig); + mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONFIGS, mndRetrieveConfigs); + mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CONFIGS, mndCancelGetNextConfig); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_DNODE, mndRetrieveDnodes); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_DNODE, mndCancelGetNextDnode); @@ -354,7 +350,7 @@ static int32_t mndProcessStatusReq(SNodeMsg *pReq) { int64_t curMs = taosGetTimestampMs(); bool online = mndIsDnodeOnline(pMnode, pDnode, curMs); - bool dnodeChanged = (statusReq.dver != sdbGetTableVer(pMnode->pSdb, SDB_DNODE)); + bool dnodeChanged = (statusReq.dnodeVer != sdbGetTableVer(pMnode->pSdb, SDB_DNODE)); bool reboot = (pDnode->rebootTime != statusReq.rebootTime); bool needCheck = !online || dnodeChanged || reboot; @@ -405,7 +401,7 @@ static int32_t mndProcessStatusReq(SNodeMsg *pReq) { pDnode->numOfSupportVnodes = statusReq.numOfSupportVnodes; SStatusRsp statusRsp = {0}; - statusRsp.dver = sdbGetTableVer(pMnode->pSdb, SDB_DNODE); + statusRsp.dnodeVer = sdbGetTableVer(pMnode->pSdb, SDB_DNODE); statusRsp.dnodeCfg.dnodeId = pDnode->id; statusRsp.dnodeCfg.clusterId = pMnode->clusterId; statusRsp.pDnodeEps = taosArrayInit(mndGetDnodeSize(pMnode), sizeof(SDnodeEp)); @@ -638,37 +634,6 @@ static int32_t mndProcessConfigDnodeRsp(SNodeMsg *pRsp) { return TSDB_CODE_SUCCESS; } -static int32_t mndGetConfigMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "name"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_CONIIG_VALUE_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "value"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = TSDB_CONFIG_NUMBER; - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - - return 0; -} - static int32_t mndRetrieveConfigs(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; int32_t totalRows = 0; diff --git a/source/dnode/mnode/impl/src/mndGrant.c b/source/dnode/mnode/impl/src/mndGrant.c index 15aa55ef83beba6d0dcf62e25a430ddb8ed4c9cb..cab1e241e22da7e29c200bb27f1b9e5adc16fb52 100644 --- a/source/dnode/mnode/impl/src/mndGrant.c +++ b/source/dnode/mnode/impl/src/mndGrant.c @@ -18,10 +18,15 @@ #include "taoserror.h" #include "mndGrant.h" #include "mndInt.h" +#include "mndShow.h" #ifndef _GRANT +static int32_t mndRetrieveGrant(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { return TSDB_CODE_OPS_NOT_SUPPORT; } -int32_t mndInitGrant(SMnode *pMnode) { return TSDB_CODE_SUCCESS; } +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; } @@ -31,4 +36,4 @@ void grantRestore(EGrantType grant, uint64_t value) {} #endif -void parseGrantParameter() { grantParseParameter(); } \ No newline at end of file +void mndGenerateMachineCode() { grantParseParameter(); } diff --git a/source/dnode/mnode/impl/src/mndInfoSchema.c b/source/dnode/mnode/impl/src/mndInfoSchema.c index e2ec97b310dc9b8f0a43ea05d8bdef3206d8e2bf..55eb1ca4bd4b3f133acd35a49c37caf3188faa4a 100644 --- a/source/dnode/mnode/impl/src/mndInfoSchema.c +++ b/source/dnode/mnode/impl/src/mndInfoSchema.c @@ -17,7 +17,10 @@ #include "mndInfoSchema.h" #include "mndInt.h" -//!!!! Note: only APPEND columns in below tables, NO insert !!!! +#define SYSTABLE_SCH_TABLE_NAME_LEN ((TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE) +#define SYSTABLE_SCH_DB_NAME_LEN ((TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE) +#define SYSTABLE_SCH_COL_NAME_LEN ((TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE) + 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_VARCHAR}, @@ -27,6 +30,7 @@ static const SInfosTableSchema dnodesSchema[] = { {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, {.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_VARCHAR}, @@ -34,31 +38,37 @@ static const SInfosTableSchema mnodesSchema[] = { {.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_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_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_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_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_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_VARCHAR}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, @@ -81,9 +91,9 @@ static const SInfosTableSchema userDBSchema[] = { {.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_VARCHAR}, - // {.name = "update", .bytes = 1, .type = - // TSDB_DATA_TYPE_TINYINT}, // disable update + // {.name = "update", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT}, // disable update }; + static const SInfosTableSchema userFuncSchema[] = { {.name = "name", .bytes = 32, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, @@ -91,6 +101,7 @@ static const SInfosTableSchema userFuncSchema[] = { {.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_VARCHAR}, {.name = "table_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, @@ -100,6 +111,7 @@ static const SInfosTableSchema userIdxSchema[] = { {.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_VARCHAR}, {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, @@ -109,6 +121,7 @@ static const SInfosTableSchema userStbsSchema[] = { {.name = "last_update", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, {.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_VARCHAR}, {.name = "user_name", .bytes = 23, .type = TSDB_DATA_TYPE_VARCHAR}, @@ -116,6 +129,7 @@ static const SInfosTableSchema userStreamsSchema[] = { {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, {.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_VARCHAR}, {.name = "db_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, @@ -127,6 +141,7 @@ static const SInfosTableSchema userTblsSchema[] = { {.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_VARCHAR}, {.name = "table_name", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, @@ -142,12 +157,14 @@ static const SInfosTableSchema userTblDistSchema[] = { {.name = "rows_in_mem", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "seek_header_time", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, }; + static const SInfosTableSchema userUsersSchema[] = { {.name = "name", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_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_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}, @@ -164,6 +181,7 @@ static const SInfosTableSchema grantsSchema[] = { {.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_VARCHAR}, @@ -207,14 +225,62 @@ static const SInfosTableSchema subscribeSchema[] = { {.name = "client_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, }; +static const SInfosTableSchema smaSchema[] = { + {.name = "sma_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "stable_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SInfosTableSchema transSchema[] = { + {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "created_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "stage", .bytes = TSDB_TRANS_STAGE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "db", .bytes = SYSTABLE_SCH_DB_NAME_LEN, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "type", .bytes = TSDB_TRANS_TYPE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "last_exec_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "last_error", .bytes = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SInfosTableSchema configSchema[] = { + {.name = "name", .bytes = TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "value", .bytes = TSDB_CONIIG_VALUE_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + +static const SInfosTableSchema connSchema[] = { + {.name = "connId", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "user", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "program", .bytes = TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "ip:port", .bytes = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "login_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "last_access", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, +}; + +static const SInfosTableSchema querySchema[] = { + {.name = "queryId", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "connId", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "user", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "ip:port", .bytes = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "qid", .bytes = 22 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "created_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, + {.name = "time", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, + {.name = "sql_obj_id", .bytes = QUERY_OBJ_ID_SIZE + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "ep", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "stable_query", .bytes = 1, .type = TSDB_DATA_TYPE_BOOL}, + {.name = "sub_queries", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, + {.name = "sub_query_info", .bytes = TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "sql", .bytes = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, +}; + static const SInfosTableMeta infosMeta[] = { {TSDB_INS_TABLE_DNODES, dnodesSchema, tListLen(dnodesSchema)}, {TSDB_INS_TABLE_MNODES, mnodesSchema, tListLen(mnodesSchema)}, {TSDB_INS_TABLE_MODULES, modulesSchema, tListLen(modulesSchema)}, {TSDB_INS_TABLE_QNODES, qnodesSchema, tListLen(qnodesSchema)}, + {TSDB_INS_TABLE_SNODES, snodesSchema, tListLen(snodesSchema)}, {TSDB_INS_TABLE_BNODES, bnodesSchema, tListLen(bnodesSchema)}, {TSDB_INS_TABLE_CLUSTER, clusterSchema, tListLen(clusterSchema)}, - {TSDB_INS_TABLE_SNODES, snodesSchema, tListLen(snodesSchema)}, {TSDB_INS_TABLE_USER_DATABASES, userDBSchema, tListLen(userDBSchema)}, {TSDB_INS_TABLE_USER_FUNCTIONS, userFuncSchema, tListLen(userFuncSchema)}, {TSDB_INS_TABLE_USER_INDEXES, userIdxSchema, tListLen(userIdxSchema)}, @@ -223,12 +289,19 @@ static const SInfosTableMeta infosMeta[] = { {TSDB_INS_TABLE_USER_TABLES, userTblsSchema, tListLen(userTblsSchema)}, {TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED, userTblDistSchema, tListLen(userTblDistSchema)}, {TSDB_INS_TABLE_USER_USERS, userUsersSchema, tListLen(userUsersSchema)}, - {TSDB_INS_TABLE_VGROUPS, vgroupsSchema, tListLen(vgroupsSchema)}, {TSDB_INS_TABLE_LICENCES, grantsSchema, tListLen(grantsSchema)}, + {TSDB_INS_TABLE_VGROUPS, vgroupsSchema, tListLen(vgroupsSchema)}, + {TSDB_INS_TABLE_TOPICS, topicSchema, tListLen(topicSchema)}, + {TSDB_INS_TABLE_CONSUMERS, consumerSchema, tListLen(consumerSchema)}, + {TSDB_INS_TABLE_SUBSCRIBES, subscribeSchema, tListLen(subscribeSchema)}, + {TSDB_INS_TABLE_TRANS, transSchema, tListLen(transSchema)}, + {TSDB_INS_TABLE_SMAS, smaSchema, tListLen(smaSchema)}, + {TSDB_INS_TABLE_CONFIGS, configSchema, tListLen(configSchema)}, + {TSDB_INS_TABLE_CONNS, connSchema, tListLen(connSchema)}, + {TSDB_INS_TABLE_QUERIES, querySchema, tListLen(querySchema)}, }; -// connection/application/ -int32_t mndInitInfosTableSchema(const SInfosTableSchema *pSrc, int32_t colNum, SSchema **pDst) { +static int32_t mndInitInfosTableSchema(const SInfosTableSchema *pSrc, int32_t colNum, SSchema **pDst) { SSchema *schema = taosMemoryCalloc(colNum, sizeof(SSchema)); if (NULL == schema) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -236,40 +309,39 @@ int32_t mndInitInfosTableSchema(const SInfosTableSchema *pSrc, int32_t colNum, S } for (int32_t i = 0; i < colNum; ++i) { - strcpy(schema[i].name, pSrc[i].name); - + tstrncpy(schema[i].name, pSrc[i].name, sizeof(schema[i].name)); schema[i].type = pSrc[i].type; schema[i].colId = i + 1; schema[i].bytes = pSrc[i].bytes; } *pDst = schema; - return TSDB_CODE_SUCCESS; + return 0; } -int32_t mndInsInitMeta(SHashObj *hash) { +static int32_t mndInsInitMeta(SHashObj *hash) { STableMetaRsp meta = {0}; - strcpy(meta.dbFName, TSDB_INFORMATION_SCHEMA_DB); + tstrncpy(meta.dbFName, TSDB_INFORMATION_SCHEMA_DB, sizeof(meta.dbFName)); meta.tableType = TSDB_SYSTEM_TABLE; meta.sversion = 1; meta.tversion = 1; for (int32_t i = 0; i < tListLen(infosMeta); ++i) { - strcpy(meta.tbName, infosMeta[i].name); + tstrncpy(meta.tbName, infosMeta[i].name, sizeof(meta.tbName)); meta.numOfColumns = infosMeta[i].colNum; if (mndInitInfosTableSchema(infosMeta[i].schema, infosMeta[i].colNum, &meta.pSchemas)) { return -1; } - if (taosHashPut(hash, meta.tbName, strlen(meta.tbName), &meta, sizeof(meta))) { + if (taosHashPut(hash, meta.tbName, strlen(meta.tbName) + 1, &meta, sizeof(meta))) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } } - return TSDB_CODE_SUCCESS; + return 0; } int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp) { @@ -278,24 +350,23 @@ int32_t mndBuildInsTableSchema(SMnode *pMnode, const char *dbFName, const char * return -1; } - STableMetaRsp *meta = (STableMetaRsp *)taosHashGet(pMnode->infosMeta, tbName, strlen(tbName)); - if (NULL == meta) { + STableMetaRsp *pMeta = taosHashGet(pMnode->infosMeta, tbName, strlen(tbName) + 1); + if (NULL == pMeta) { mError("invalid information schema table name:%s", tbName); terrno = TSDB_CODE_MND_INVALID_INFOS_TBL; return -1; } - *pRsp = *meta; + *pRsp = *pMeta; - pRsp->pSchemas = taosMemoryCalloc(meta->numOfColumns, sizeof(SSchema)); + pRsp->pSchemas = taosMemoryCalloc(pMeta->numOfColumns, sizeof(SSchema)); if (pRsp->pSchemas == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; pRsp->pSchemas = NULL; return -1; } - memcpy(pRsp->pSchemas, meta->pSchemas, meta->numOfColumns * sizeof(SSchema)); - + memcpy(pRsp->pSchemas, pMeta->pSchemas, pMeta->numOfColumns * sizeof(SSchema)); return 0; } @@ -314,16 +385,12 @@ void mndCleanupInfos(SMnode *pMnode) { return; } - void *pIter = taosHashIterate(pMnode->infosMeta, NULL); - while (pIter) { - STableMetaRsp *meta = (STableMetaRsp *)pIter; - - taosMemoryFreeClear(meta->pSchemas); - - pIter = taosHashIterate(pMnode->infosMeta, pIter); + STableMetaRsp *pMeta = taosHashIterate(pMnode->infosMeta, NULL); + while (pMeta) { + taosMemoryFreeClear(pMeta->pSchemas); + pMeta = taosHashIterate(pMnode->infosMeta, pMeta); } taosHashCleanup(pMnode->infosMeta); pMnode->infosMeta = NULL; } - diff --git a/source/dnode/mnode/impl/src/mndOffset.c b/source/dnode/mnode/impl/src/mndOffset.c index 22dad48772b2024cb2bb96243de070300aec4e0a..31c16e1e1d1349a11ce89c2ee325f99af9735156 100644 --- a/source/dnode/mnode/impl/src/mndOffset.c +++ b/source/dnode/mnode/impl/src/mndOffset.c @@ -201,6 +201,7 @@ static int32_t mndOffsetActionDelete(SSdb *pSdb, SMqOffsetObj *pOffset) { static int32_t mndOffsetActionUpdate(SSdb *pSdb, SMqOffsetObj *pOldOffset, SMqOffsetObj *pNewOffset) { mTrace("offset:%s, perform update action", pOldOffset->key); + pOldOffset->offset = pNewOffset->offset; return 0; } diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index f169fb4b216ace6986c08262a8f931f8efbbdd60..826a73afc68915c3b161b9896a2bc58677bd409d 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -23,11 +23,6 @@ #include "tglobal.h" #include "version.h" -#define QUERY_ID_SIZE 20 -#define QUERY_OBJ_ID_SIZE 18 -#define SUBQUERY_INFO_SIZE 6 -#define QUERY_SAVE_SIZE 20 - typedef struct { uint32_t id; int8_t connType; @@ -56,9 +51,7 @@ static int32_t mndProcessHeartBeatReq(SNodeMsg *pReq); static int32_t mndProcessConnectReq(SNodeMsg *pReq); static int32_t mndProcessKillQueryReq(SNodeMsg *pReq); static int32_t mndProcessKillConnReq(SNodeMsg *pReq); -static int32_t mndGetConnsMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); static int32_t mndRetrieveConns(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); -static int32_t mndGetQueryMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); static int32_t mndRetrieveQueries(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextQuery(SMnode *pMnode, void *pIter); @@ -551,81 +544,6 @@ static int32_t mndProcessKillConnReq(SNodeMsg *pReq) { } } -static int32_t mndGetConnsMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - SMnode *pMnode = pReq->pNode; - SProfileMgmt *pMgmt = &pMnode->profileMgmt; - - SUserObj *pUser = mndAcquireUser(pMnode, pReq->user); - if (pUser == NULL) return 0; - if (!pUser->superUser) { - mndReleaseUser(pMnode, pUser); - terrno = TSDB_CODE_MND_NO_RIGHTS; - return -1; - } - mndReleaseUser(pMnode, pUser); - - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "connId"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "user"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - // app name - pShow->bytes[cols] = TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "program"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - // app pid - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "pid"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "ip:port"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "login_time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "last_access"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = taosCacheGetNumOfObj(pMgmt->cache); - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - - return 0; -} - static int32_t mndRetrieveConns(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { SMnode *pMnode = pReq->pNode; int32_t numOfRows = 0; @@ -685,121 +603,6 @@ static int32_t mndRetrieveConns(SNodeMsg *pReq, SShowObj *pShow, char *data, int return numOfRows; } -static int32_t mndGetQueryMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - SMnode *pMnode = pReq->pNode; - SProfileMgmt *pMgmt = &pMnode->profileMgmt; - - SUserObj *pUser = mndAcquireUser(pMnode, pReq->user); - if (pUser == NULL) return 0; - if (!pUser->superUser) { - mndReleaseUser(pMnode, pUser); - terrno = TSDB_CODE_MND_NO_RIGHTS; - return -1; - } - mndReleaseUser(pMnode, pUser); - - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "queryId"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "connId"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "user"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "ip:port"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 22 + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "qid"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "created_time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_BIGINT; - strcpy(pSchema[cols].name, "time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = QUERY_OBJ_ID_SIZE + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "sql_obj_id"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "pid"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "ep"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 1; - pSchema[cols].type = TSDB_DATA_TYPE_BOOL; - strcpy(pSchema[cols].name, "stable_query"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "sub_queries"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "sub_query_info"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "sql"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = 1000000; - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - - return 0; -} - static int32_t mndRetrieveQueries(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { SMnode *pMnode = pReq->pNode; int32_t numOfRows = 0; diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index d9f4f142df786ccef1ef523c107ccbc364f03a21..617cebf61d4b69c1e0a321b3d1f1eda16b4befec 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -115,6 +115,7 @@ static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) { static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { SMnode *pMnode = pReq->pNode; SShowMgmt *pMgmt = &pMnode->showMgmt; + SShowObj *pShow = NULL; int32_t rowsToRead = SHOW_STEP_SIZE; int32_t size = 0; int32_t rowsRead = 0; @@ -125,8 +126,6 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { return -1; } - SShowObj* pShow = NULL; - if (retrieveReq.showId == 0) { SShowReq req = {0}; req.type = retrieveReq.type; @@ -139,11 +138,11 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { return -1; } - pShow->pMeta = (STableMetaRsp *)taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb)); + pShow->pMeta = (STableMetaRsp *)taosHashGet(pMnode->infosMeta, retrieveReq.tb, strlen(retrieveReq.tb) + 1); pShow->numOfColumns = pShow->pMeta->numOfColumns; int32_t offset = 0; - for(int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) { + for (int32_t i = 0; i < pShow->pMeta->numOfColumns; ++i) { pShow->offset[i] = offset; int32_t bytes = pShow->pMeta->pSchemas[i].bytes; @@ -162,26 +161,25 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { ShowRetrieveFp retrieveFp = pMgmt->retrieveFps[pShow->type]; if (retrieveFp == NULL) { - mndReleaseShowObj((SShowObj*) pShow, false); + mndReleaseShowObj(pShow, false); terrno = TSDB_CODE_MSG_NOT_PROCESSED; mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr()); return -1; } - mDebug("show:0x%" PRIx64 ", start retrieve data, type:%s", pShow->id, mndShowStr(pShow->type)); - - int32_t numOfCols = pShow->pMeta->numOfColumns; + mDebug("show:0x%" PRIx64 ", start retrieve data, type:%d", pShow->id, pShow->type); - SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); + 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) { + for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData idata = {0}; - SSchema* p = &pShow->pMeta->pSchemas[i]; + SSchema *p = &pShow->pMeta->pSchemas[i]; idata.info.bytes = p->bytes; - idata.info.type = p->type; + idata.info.type = p->type; idata.info.colId = p->colId; taosArrayPush(pBlock->pDataBlock, &idata); @@ -191,15 +189,15 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { } blockDataEnsureCapacity(pBlock, rowsToRead); - if (mndCheckRetrieveFinished((SShowObj*) pShow)) { + if (mndCheckRetrieveFinished(pShow)) { mDebug("show:0x%" PRIx64 ", read finished, numOfRows:%d", pShow->id, pShow->numOfRows); rowsRead = 0; } else { - rowsRead = (*retrieveFp)(pReq, (SShowObj *)pShow, pBlock, rowsToRead); + rowsRead = (*retrieveFp)(pReq, pShow, pBlock, rowsToRead); if (rowsRead < 0) { terrno = rowsRead; mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); - mndReleaseShowObj((SShowObj *)pShow, true); + mndReleaseShowObj(pShow, true); return -1; } @@ -207,13 +205,12 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d numOfRows:%d", pShow->id, rowsRead, pShow->numOfRows); } - // numOfCols + sizeof(SSysTableSchema) * numOfCols + data payload - size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns + blockDataGetSize(pBlock) - + blockDataGetSerialMetaSize(pBlock); + size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * pShow->pMeta->numOfColumns + + blockDataGetSize(pBlock) + blockDataGetSerialMetaSize(pBlock); SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size); if (pRsp == NULL) { - mndReleaseShowObj((SShowObj*) pShow, false); + mndReleaseShowObj(pShow, false); terrno = TSDB_CODE_OUT_OF_MEMORY; mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr()); blockDataDestroy(pBlock); @@ -222,9 +219,8 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { pRsp->handle = htobe64(pShow->id); - // if free flag is set, client wants to clean the resources if (rowsRead > 0) { - char * pStart = pRsp->data; + char *pStart = pRsp->data; SSchema *ps = pShow->pMeta->pSchemas; *(int32_t *)pStart = htonl(pShow->pMeta->numOfColumns); @@ -245,77 +241,22 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) { 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 || rowsRead < rowsToRead) { pRsp->completed = 1; mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); - mndReleaseShowObj((SShowObj*) pShow, true); + mndReleaseShowObj(pShow, true); } else { mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id); - mndReleaseShowObj((SShowObj*) pShow, false); + mndReleaseShowObj(pShow, false); } blockDataDestroy(pBlock); return TSDB_CODE_SUCCESS; } -char *mndShowStr(int32_t showType) { - switch (showType) { - case TSDB_MGMT_TABLE_ACCT: - return "show accounts"; - case TSDB_MGMT_TABLE_USER: - return "show users"; - case TSDB_MGMT_TABLE_DB: - return "show databases"; - case TSDB_MGMT_TABLE_TABLE: - return "show tables"; - case TSDB_MGMT_TABLE_DNODE: - return "show dnodes"; - case TSDB_MGMT_TABLE_MNODE: - return "show mnodes"; - case TSDB_MGMT_TABLE_QNODE: - return "show qnodes"; - case TSDB_MGMT_TABLE_SNODE: - return "show snodes"; - case TSDB_MGMT_TABLE_BNODE: - return "show bnodes"; - case TSDB_MGMT_TABLE_VGROUP: - return "show vgroups"; - case TSDB_MGMT_TABLE_STB: - return "show stables"; - case TSDB_MGMT_TABLE_MODULE: - return "show modules"; - case TSDB_MGMT_TABLE_QUERIES: - return "show queries"; - case TSDB_MGMT_TABLE_STREAMS: - return "show streams"; - case TSDB_MGMT_TABLE_VARIABLES: - return "show configs"; - case TSDB_MGMT_TABLE_CONNS: - return "show connections"; - case TSDB_MGMT_TABLE_TRANS: - return "show trans"; - case TSDB_MGMT_TABLE_GRANTS: - return "show grants"; - case TSDB_MGMT_TABLE_VNODES: - return "show vnodes"; - case TSDB_MGMT_TABLE_CLUSTER: - return "show cluster"; - case TSDB_MGMT_TABLE_STREAMTABLES: - return "show streamtables"; - case TSDB_MGMT_TABLE_TP: - return "show topics"; - case TSDB_MGMT_TABLE_FUNC: - return "show functions"; - case TSDB_MGMT_TABLE_INDEX: - return "show indexes"; - default: - return "undefined"; - } -} - static bool mndCheckRetrieveFinished(SShowObj *pShow) { if (pShow->pIter == NULL && pShow->numOfRows != 0) { return true; @@ -323,14 +264,6 @@ static bool mndCheckRetrieveFinished(SShowObj *pShow) { return false; } -void mndVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_t capacity, SShowObj *pShow) { - if (rows < capacity) { - for (int32_t i = 0; i < numOfCols; ++i) { - memmove(data + pShow->offset[i] * rows, data + pShow->offset[i] * capacity, pShow->bytes[i] * rows); - } - } -} - void mndAddShowRetrieveHandle(SMnode *pMnode, EShowType showType, ShowRetrieveFp fp) { SShowMgmt *pMgmt = &pMnode->showMgmt; pMgmt->retrieveFps[showType] = fp; diff --git a/source/dnode/mnode/impl/src/mndSma.c b/source/dnode/mnode/impl/src/mndSma.c index 70e41a73b78248141f004c076463d268b1e2d3d2..1e68e8e9c5a27d8294f8e1f86fdd8f62687690f9 100644 --- a/source/dnode/mnode/impl/src/mndSma.c +++ b/source/dnode/mnode/impl/src/mndSma.c @@ -724,46 +724,6 @@ static int32_t mndProcessVDropSmaRsp(SNodeMsg *pRsp) { return 0; } -static int32_t mndGetSmaMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - SMnode *pMnode = pReq->pNode; - SSdb *pSdb = pMnode->pSdb; - - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = TSDB_INDEX_NAME_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "name"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "create_time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "stb"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = sdbGetSize(pSdb, SDB_SMA); - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - - return 0; -} - static int32_t mndRetrieveSma(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock* pBlock, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index a7285162fad34eca10eddd004f60ea137d31d3a7..a0ee8ff44cad00ff56d5927e98fe0d75bd391d9f 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -58,8 +58,8 @@ int32_t mndInitStream(SMnode *pMnode) { /*mndSetMsgHandle(pMnode, TDMT_MND_DROP_STREAM, mndProcessDropStreamReq);*/ /*mndSetMsgHandle(pMnode, TDMT_MND_DROP_STREAM_RSP, mndProcessDropStreamInRsp);*/ -// mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TP, mndRetrieveStream); - mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TP, mndCancelGetNextStream); + // mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndRetrieveStream); + mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndCancelGetNextStream); return sdbSetTable(pMnode->pSdb, table); } @@ -421,50 +421,6 @@ static int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfS return 0; } -static int32_t mndGetStreamMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - SMnode *pMnode = pReq->pNode; - SSdb *pSdb = pMnode->pSdb; - - if (mndGetNumOfStreams(pMnode, pShow->db, &pShow->numOfRows) != 0) { - return -1; - } - - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "name"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "create_time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "sql"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = sdbGetSize(pSdb, SDB_STREAM); - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - - return 0; -} - static int32_t mndRetrieveStream(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index e1461c0ebaa8af79b7df32347c553319572c5620..3a31b0abb9ef47e78772d9a8612155b7ed344382 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -469,6 +469,7 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { ASSERT(pConsumerEp != NULL); ASSERT(pConsumerEp->consumerId == pSubConsumer->consumerId); taosArrayPush(pSub->unassignedVg, pConsumerEp); + mDebug("mq rebalance: vg %d push to unassignedVg", pConsumerEp->vgId); } SMqConsumerObj *pRebConsumer = mndAcquireConsumer(pMnode, pSubConsumer->consumerId); @@ -512,6 +513,7 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { while (taosArrayGetSize(pSubConsumer->vgInfo) < vgThisConsumerAfterRb) { SMqConsumerEp *pConsumerEp = taosArrayPop(pSub->unassignedVg); + mDebug("mq rebalance: vg %d pop from unassignedVg", pConsumerEp->vgId); ASSERT(pConsumerEp != NULL); pConsumerEp->oldConsumerId = pConsumerEp->consumerId; @@ -570,7 +572,6 @@ static int32_t mndPersistMqSetConnReq(SMnode *pMnode, STrans *pTrans, const SMqT .vgId = vgId, .consumerId = pConsumerEp->consumerId, .sql = pTopic->sql, - .logicalPlan = pTopic->logicalPlan, .physicalPlan = pTopic->physicalPlan, .qmsg = pConsumerEp->qmsg, }; diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 65a304e9511a3bdf5819c067e355ad1fc9aef219..b9c42fe899a2bd798ba039b514483b3e38a8c907 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -26,7 +26,7 @@ #include "parser.h" #include "tname.h" -#define MND_TOPIC_VER_NUMBER 1 +#define MND_TOPIC_VER_NUMBER 1 #define MND_TOPIC_RESERVE_SIZE 64 static int32_t mndTopicActionInsert(SSdb *pSdb, SMqTopicObj *pTopic); @@ -35,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 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); @@ -52,8 +51,8 @@ int32_t mndInitTopic(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_MND_DROP_TOPIC, mndProcessDropTopicReq); mndSetMsgHandle(pMnode, TDMT_VND_DROP_TOPIC_RSP, mndProcessDropTopicInRsp); -// mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TP, mndRetrieveTopic); - mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TP, mndCancelGetNextTopic); + // mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndRetrieveTopic); + mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndCancelGetNextTopic); return sdbSetTable(pMnode->pSdb, table); } @@ -63,11 +62,10 @@ void mndCleanupTopic(SMnode *pMnode) {} SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) { terrno = TSDB_CODE_OUT_OF_MEMORY; - int32_t logicalPlanLen = strlen(pTopic->logicalPlan) + 1; int32_t physicalPlanLen = strlen(pTopic->physicalPlan) + 1; - int32_t swLen = taosEncodeSSchemaWrapper(NULL, &pTopic->schema); + int32_t schemaLen = taosEncodeSSchemaWrapper(NULL, &pTopic->schema); int32_t size = - sizeof(SMqTopicObj) + logicalPlanLen + physicalPlanLen + pTopic->sqlLen + swLen + MND_TOPIC_RESERVE_SIZE; + sizeof(SMqTopicObj) + physicalPlanLen + pTopic->sqlLen + pTopic->astLen + schemaLen + MND_TOPIC_RESERVE_SIZE; SSdbRaw *pRaw = sdbAllocRaw(SDB_TOPIC, MND_TOPIC_VER_NUMBER, size); if (pRaw == NULL) goto TOPIC_ENCODE_OVER; @@ -81,19 +79,19 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) { SDB_SET_INT32(pRaw, dataPos, pTopic->version, TOPIC_ENCODE_OVER); SDB_SET_INT32(pRaw, dataPos, pTopic->sqlLen, TOPIC_ENCODE_OVER); SDB_SET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen, TOPIC_ENCODE_OVER); - SDB_SET_INT32(pRaw, dataPos, logicalPlanLen, TOPIC_ENCODE_OVER); - SDB_SET_BINARY(pRaw, dataPos, pTopic->logicalPlan, logicalPlanLen, TOPIC_ENCODE_OVER); + SDB_SET_INT32(pRaw, dataPos, pTopic->astLen, TOPIC_ENCODE_OVER); + SDB_SET_BINARY(pRaw, dataPos, pTopic->ast, pTopic->astLen, TOPIC_ENCODE_OVER); SDB_SET_INT32(pRaw, dataPos, physicalPlanLen, TOPIC_ENCODE_OVER); SDB_SET_BINARY(pRaw, dataPos, pTopic->physicalPlan, physicalPlanLen, TOPIC_ENCODE_OVER); - void *swBuf = taosMemoryMalloc(swLen); + void *swBuf = taosMemoryMalloc(schemaLen); if (swBuf == NULL) { goto TOPIC_ENCODE_OVER; } void *aswBuf = swBuf; taosEncodeSSchemaWrapper(&aswBuf, &pTopic->schema); - SDB_SET_INT32(pRaw, dataPos, swLen, TOPIC_ENCODE_OVER); - SDB_SET_BINARY(pRaw, dataPos, swBuf, swLen, TOPIC_ENCODE_OVER); + SDB_SET_INT32(pRaw, dataPos, schemaLen, TOPIC_ENCODE_OVER); + SDB_SET_BINARY(pRaw, dataPos, swBuf, schemaLen, TOPIC_ENCODE_OVER); SDB_SET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE, TOPIC_ENCODE_OVER); SDB_SET_DATALEN(pRaw, dataPos, TOPIC_ENCODE_OVER); @@ -137,23 +135,25 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { SDB_GET_INT64(pRaw, dataPos, &pTopic->uid, TOPIC_DECODE_OVER); SDB_GET_INT64(pRaw, dataPos, &pTopic->dbUid, TOPIC_DECODE_OVER); SDB_GET_INT32(pRaw, dataPos, &pTopic->version, TOPIC_DECODE_OVER); - SDB_GET_INT32(pRaw, dataPos, &pTopic->sqlLen, TOPIC_DECODE_OVER); - pTopic->sql = taosMemoryCalloc(pTopic->sqlLen + 1, sizeof(char)); + SDB_GET_INT32(pRaw, dataPos, &pTopic->sqlLen, TOPIC_DECODE_OVER); + pTopic->sql = taosMemoryCalloc(pTopic->sqlLen, sizeof(char)); + if (pTopic->sql == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto TOPIC_DECODE_OVER; + } SDB_GET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen, TOPIC_DECODE_OVER); - SDB_GET_INT32(pRaw, dataPos, &len, TOPIC_DECODE_OVER); - pTopic->logicalPlan = taosMemoryCalloc(len + 1, sizeof(char)); - if (pTopic->logicalPlan == NULL) { + SDB_GET_INT32(pRaw, dataPos, &pTopic->astLen, TOPIC_DECODE_OVER); + pTopic->ast = taosMemoryCalloc(pTopic->astLen, sizeof(char)); + if (pTopic->ast == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto TOPIC_DECODE_OVER; } - SDB_GET_BINARY(pRaw, dataPos, pTopic->logicalPlan, len, TOPIC_DECODE_OVER); - + SDB_GET_BINARY(pRaw, dataPos, pTopic->ast, pTopic->astLen, TOPIC_DECODE_OVER); SDB_GET_INT32(pRaw, dataPos, &len, TOPIC_DECODE_OVER); - pTopic->physicalPlan = taosMemoryCalloc(len + 1, sizeof(char)); + pTopic->physicalPlan = taosMemoryCalloc(len, sizeof(char)); if (pTopic->physicalPlan == NULL) { - taosMemoryFree(pTopic->logicalPlan); terrno = TSDB_CODE_OUT_OF_MEMORY; goto TOPIC_DECODE_OVER; } @@ -257,6 +257,7 @@ static int32_t mndCheckCreateTopicReq(SCMCreateTopicReq *pCreate) { return 0; } +#if 0 static int32_t mndGetPlanString(const SCMCreateTopicReq *pCreate, char **pStr) { if (NULL == pCreate->ast) { return TSDB_CODE_SUCCESS; @@ -279,6 +280,7 @@ static int32_t mndGetPlanString(const SCMCreateTopicReq *pCreate, char **pStr) { terrno = code; return code; } +#endif static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq *pCreate, SDbObj *pDb) { mDebug("topic:%s to create", pCreate->name); @@ -290,32 +292,39 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq topicObj.uid = mndGenerateUid(pCreate->name, strlen(pCreate->name)); topicObj.dbUid = pDb->uid; topicObj.version = 1; - topicObj.sql = pCreate->sql; - topicObj.physicalPlan = ""; - topicObj.logicalPlan = ""; - topicObj.sqlLen = strlen(pCreate->sql); - - char *pPlanStr = NULL; - if (TSDB_CODE_SUCCESS != mndGetPlanString(pCreate, &pPlanStr)) { - mError("topic:%s, failed to get plan since %s", pCreate->name, terrstr()); + topicObj.sql = strdup(pCreate->sql); + topicObj.sqlLen = strlen(pCreate->sql) + 1; + topicObj.ast = strdup(pCreate->ast); + topicObj.astLen = strlen(pCreate->ast) + 1; + + SNode *pAst = NULL; + if (nodesStringToNode(pCreate->ast, &pAst) != 0) { + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); return -1; } - if (NULL != pPlanStr) { - topicObj.physicalPlan = pPlanStr; - } - SNode *pAst = NULL; - if (nodesStringToNode(pCreate->ast, &pAst) < 0) { + SQueryPlan *pPlan = NULL; + + SPlanContext cxt = {.pAstRoot = pAst, .topicQuery = true}; + if (qCreateQueryPlan(&cxt, &pPlan, NULL) != 0) { + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); return -1; } + if (qExtractResultSchema(pAst, &topicObj.schema.nCols, &topicObj.schema.pSchema) != 0) { + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + + if (nodesNodeToString(pPlan, false, &topicObj.physicalPlan, NULL) != 0) { + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); return -1; } STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_TOPIC, &pReq->rpcMsg); if (pTrans == NULL) { mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); - taosMemoryFreeClear(pPlanStr); + taosMemoryFreeClear(topicObj.physicalPlan); return -1; } mDebug("trans:%d, used to create topic:%s", pTrans->id, pCreate->name); @@ -323,7 +332,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq SSdbRaw *pRedoRaw = mndTopicActionEncode(&topicObj); if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr()); - taosMemoryFreeClear(pPlanStr); + taosMemoryFreeClear(topicObj.physicalPlan); mndTransDrop(pTrans); return -1; } @@ -331,12 +340,12 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq if (mndTransPrepare(pMnode, pTrans) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - taosMemoryFreeClear(pPlanStr); + taosMemoryFreeClear(topicObj.physicalPlan); mndTransDrop(pTrans); return -1; } - taosMemoryFreeClear(pPlanStr); + taosMemoryFreeClear(topicObj.physicalPlan); mndTransDrop(pTrans); return 0; } @@ -500,50 +509,6 @@ static int32_t mndGetNumOfTopics(SMnode *pMnode, char *dbName, int32_t *pNumOfTo return 0; } -static int32_t mndGetTopicMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - SMnode *pMnode = pReq->pNode; - SSdb *pSdb = pMnode->pSdb; - - if (mndGetNumOfTopics(pMnode, pShow->db, &pShow->numOfRows) != 0) { - return -1; - } - - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "name"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "create_time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "sql"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = sdbGetSize(pSdb, SDB_TOPIC); - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - - return 0; -} - static int32_t mndRetrieveTopic(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index e1bf4b1b7d2b5eb4001ff5447b6d1c7aef48d34e..537ddc03c3df0bc999ae07c86d059ef2582ec409 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -58,7 +58,6 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans); static int32_t mndProcessTransReq(SNodeMsg *pReq); static int32_t mndProcessKillTransReq(SNodeMsg *pReq); -static int32_t mndGetTransMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta); static int32_t mndRetrieveTrans(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter); @@ -1260,69 +1259,6 @@ void mndTransPullup(SMnode *pMnode) { sdbWriteFile(pMnode->pSdb); } -static int32_t mndGetTransMeta(SNodeMsg *pReq, SShowObj *pShow, STableMetaRsp *pMeta) { - SMnode *pMnode = pReq->pNode; - SSdb *pSdb = pMnode->pSdb; - - int32_t cols = 0; - SSchema *pSchema = pMeta->pSchemas; - - pShow->bytes[cols] = 4; - pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "id"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "create_time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_TRANS_STAGE_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "stage"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = (TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "db"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = TSDB_TRANS_TYPE_LEN + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "type"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = 8; - pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; - strcpy(pSchema[cols].name, "last_exec_time"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pShow->bytes[cols] = (TSDB_TRANS_ERROR_LEN - 1) + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "last_error"); - pSchema[cols].bytes = pShow->bytes[cols]; - cols++; - - pMeta->numOfColumns = cols; - pShow->numOfColumns = cols; - - pShow->offset[0] = 0; - for (int32_t i = 1; i < cols; ++i) { - pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; - } - - pShow->numOfRows = sdbGetSize(pSdb, SDB_TRANS); - pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; - strcpy(pMeta->tbName, mndShowStr(pShow->type)); - return 0; -} - static int32_t mndRetrieveTrans(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { SMnode *pMnode = pReq->pNode; SSdb *pSdb = pMnode->pSdb; diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index ab3bec8b6f476996dfc28a1f335aac30a02160f0..3ac1c522b24b1f5581095ac0ab7e005346693d8c 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -224,7 +224,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; } @@ -350,6 +349,8 @@ int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption) { int32_t mndStart(SMnode *pMnode) { return mndInitTimer(pMnode); } +void mndStop(SMnode *pMnode) { return mndCleanupTimer(pMnode); } + int32_t mndProcessMsg(SNodeMsg *pMsg) { SMnode *pMnode = pMsg->pNode; SRpcMsg *pRpc = &pMsg->rpcMsg; diff --git a/source/dnode/mnode/impl/test/CMakeLists.txt b/source/dnode/mnode/impl/test/CMakeLists.txt index d2aa44f37246362ed4a7e6ed48273edf4f921b8f..9b669b303ad0b3c2f30b6f5162bf1d44f35f6d3e 100644 --- a/source/dnode/mnode/impl/test/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/CMakeLists.txt @@ -1,17 +1,17 @@ enable_testing() #add_subdirectory(user) -#add_subdirectory(acct) +add_subdirectory(acct) #add_subdirectory(trans) #add_subdirectory(qnode) #add_subdirectory(snode) -#add_subdirectory(bnode) +add_subdirectory(bnode) #add_subdirectory(show) #add_subdirectory(profile) -add_subdirectory(dnode) +#add_subdirectory(dnode) #add_subdirectory(mnode) -add_subdirectory(db) -add_subdirectory(stb) +#add_subdirectory(db) +#add_subdirectory(stb) #add_subdirectory(sma) #add_subdirectory(func) #add_subdirectory(topic) diff --git a/source/dnode/mnode/impl/test/acct/CMakeLists.txt b/source/dnode/mnode/impl/test/acct/CMakeLists.txt index 8c8bf54bc4f59b7146f479abded66ab8fa1c271f..40f8b0726e28446170a71bbbccde979376448fbb 100644 --- a/source/dnode/mnode/impl/test/acct/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/acct/CMakeLists.txt @@ -1,11 +1,11 @@ -aux_source_directory(. ACCT_SRC) -add_executable(mnode_test_acct ${ACCT_SRC}) +aux_source_directory(. MNODE_ACCT_TEST_SRC) +add_executable(acctTest ${MNODE_ACCT_TEST_SRC}) target_link_libraries( - mnode_test_acct + acctTest PUBLIC sut ) add_test( - NAME mnode_test_acct - COMMAND mnode_test_acct + NAME acctTest + COMMAND acctTest ) diff --git a/source/dnode/mnode/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp index 2bc4f40614409c2dfbe99b6bd524dfcda361ee26..0260b5f59ebf1468be576a9192566b0bbb7d1698 100644 --- a/source/dnode/mnode/impl/test/acct/acct.cpp +++ b/source/dnode/mnode/impl/test/acct/acct.cpp @@ -54,17 +54,3 @@ TEST_F(MndTestAcct, 03_Drop_Acct) { ASSERT_NE(pRsp, nullptr); ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); } - -TEST_F(MndTestAcct, 04_Show_Acct) { - SShowReq showReq = {0}; - showReq.type = TSDB_MGMT_TABLE_ACCT; - - int32_t contLen = tSerializeSShowReq(NULL, 0, &showReq); - void* pReq = rpcMallocCont(contLen); - tSerializeSShowReq(pReq, contLen, &showReq); - tFreeSShowReq(&showReq); - - SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen); - ASSERT_NE(pRsp, nullptr); - ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_MSG_TYPE); -} \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/bnode/CMakeLists.txt b/source/dnode/mnode/impl/test/bnode/CMakeLists.txt index b58b1a856bd4201de19a9c5898786cb2c2814886..310e022a911d4c7cde35e1c804f6c13be696b4f1 100644 --- a/source/dnode/mnode/impl/test/bnode/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/bnode/CMakeLists.txt @@ -1,11 +1,11 @@ -aux_source_directory(. STEST_SRC) -add_executable(mnode_test_bnode ${STEST_SRC}) +aux_source_directory(. MNODE_BNODE_TEST_SRC) +add_executable(mbnodeTest ${MNODE_BNODE_TEST_SRC}) target_link_libraries( - mnode_test_bnode + mbnodeTest PUBLIC sut ) add_test( - NAME mnode_test_bnode - COMMAND mnode_test_bnode + NAME mbnodeTest + COMMAND mbnodeTest ) diff --git a/source/dnode/mnode/impl/test/bnode/bnode.cpp b/source/dnode/mnode/impl/test/bnode/mbnode.cpp similarity index 88% rename from source/dnode/mnode/impl/test/bnode/bnode.cpp rename to source/dnode/mnode/impl/test/bnode/mbnode.cpp index 33816520f2c4d19eb70d296c7a307316cfc06ebf..5e08a9995dde914e0488078e8403b0c39924963f 100644 --- a/source/dnode/mnode/impl/test/bnode/bnode.cpp +++ b/source/dnode/mnode/impl/test/bnode/mbnode.cpp @@ -39,14 +39,7 @@ Testbase MndTestBnode::test; TestServer MndTestBnode::server2; TEST_F(MndTestBnode, 01_Show_Bnode) { - test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, ""); - CHECK_META("show bnodes", 3); - - CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); - CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint"); - CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - - test.SendShowRetrieveReq(); + test.SendShowReq(TSDB_MGMT_TABLE_BNODE, "bnodes", ""); EXPECT_EQ(test.GetShowRows(), 0); } @@ -76,14 +69,8 @@ TEST_F(MndTestBnode, 02_Create_Bnode) { ASSERT_NE(pRsp, nullptr); ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, ""); - CHECK_META("show bnodes", 3); - test.SendShowRetrieveReq(); + test.SendShowReq(TSDB_MGMT_TABLE_BNODE, "bnodes", ""); EXPECT_EQ(test.GetShowRows(), 1); - - CheckInt16(1); - CheckBinary("localhost:9018", TSDB_EP_LEN); - CheckTimestamp(); } { @@ -115,8 +102,7 @@ TEST_F(MndTestBnode, 03_Drop_Bnode) { ASSERT_EQ(pRsp->code, 0); taosMsleep(1300); - test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); - test.SendShowRetrieveReq(); + test.SendShowReq(TSDB_MGMT_TABLE_DNODE, "dnodes", ""); EXPECT_EQ(test.GetShowRows(), 2); } @@ -132,16 +118,8 @@ TEST_F(MndTestBnode, 03_Drop_Bnode) { ASSERT_NE(pRsp, nullptr); ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, ""); - test.SendShowRetrieveReq(); + test.SendShowReq(TSDB_MGMT_TABLE_BNODE, "bnodes", ""); EXPECT_EQ(test.GetShowRows(), 2); - - CheckInt16(1); - CheckInt16(2); - CheckBinary("localhost:9018", TSDB_EP_LEN); - CheckBinary("localhost:9019", TSDB_EP_LEN); - CheckTimestamp(); - CheckTimestamp(); } { @@ -156,13 +134,8 @@ TEST_F(MndTestBnode, 03_Drop_Bnode) { ASSERT_NE(pRsp, nullptr); ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, ""); - test.SendShowRetrieveReq(); + test.SendShowReq(TSDB_MGMT_TABLE_BNODE, "bnodes", ""); EXPECT_EQ(test.GetShowRows(), 1); - - CheckInt16(1); - CheckBinary("localhost:9018", TSDB_EP_LEN); - CheckTimestamp(); } { diff --git a/source/dnode/mnode/impl/test/db/CMakeLists.txt b/source/dnode/mnode/impl/test/db/CMakeLists.txt index d1e38854e6f0e7a181c0801bfd76b7249b03a226..1a5b4d39363ebd258b7a6c3976d4f2d4901766b1 100644 --- a/source/dnode/mnode/impl/test/db/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/db/CMakeLists.txt @@ -1,7 +1,7 @@ -aux_source_directory(. DB_SRC) -add_executable(mnode_test_db ${DB_SRC}) +aux_source_directory(. MNODE_DB_TEST_SRC) +add_executable(dbTest ${MNODE_DB_TEST_SRC}) target_link_libraries( - mnode_test_db + dbTest PUBLIC sut ) diff --git a/source/dnode/mnode/impl/test/dnode/CMakeLists.txt b/source/dnode/mnode/impl/test/dnode/CMakeLists.txt index 77cc6f0b5dbefe7dcf4c7de2e836188e19c51c13..16e08d6c35d3fe85a4cbb8e5e981150c61acb79b 100644 --- a/source/dnode/mnode/impl/test/dnode/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/dnode/CMakeLists.txt @@ -1,7 +1,7 @@ -aux_source_directory(. DTEST_SRC) -add_executable(mnode_test_dnode ${DTEST_SRC}) +aux_source_directory(. MNODE_DNODE_TEST_SRC) +add_executable(mdnodeTest ${MNODE_DNODE_TEST_SRC}) target_link_libraries( - mnode_test_dnode + mdnodeTest PUBLIC sut ) diff --git a/source/dnode/mnode/impl/test/dnode/dnode.cpp b/source/dnode/mnode/impl/test/dnode/mdnode.cpp similarity index 100% rename from source/dnode/mnode/impl/test/dnode/dnode.cpp rename to source/dnode/mnode/impl/test/dnode/mdnode.cpp diff --git a/source/dnode/mnode/impl/test/stb/CMakeLists.txt b/source/dnode/mnode/impl/test/stb/CMakeLists.txt index eca922acc43da5f3fd737c8add16854c6a781e99..70e20d3411667cd293c98a137cf52b81ba908ff0 100644 --- a/source/dnode/mnode/impl/test/stb/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/stb/CMakeLists.txt @@ -1,7 +1,7 @@ -aux_source_directory(. STB_SRC) -add_executable(mnode_test_stb ${STB_SRC}) +aux_source_directory(. MNODE_STB_TEST_SRC) +add_executable(stbTest ${MNODE_STB_TEST_SRC}) target_link_libraries( - mnode_test_stb + stbTest PUBLIC sut ) diff --git a/source/dnode/mnode/impl/test/topic/topic.cpp b/source/dnode/mnode/impl/test/topic/topic.cpp index 5d603ab5b2059f384975234ad46a0c5af877d968..2111d61e3f1838bc25ebc00ccb3d968496b81c66 100644 --- a/source/dnode/mnode/impl/test/topic/topic.cpp +++ b/source/dnode/mnode/impl/test/topic/topic.cpp @@ -88,6 +88,8 @@ void* MndTestTopic::BuildDropTopicReq(const char* topicName, int32_t* pContLen) } TEST_F(MndTestTopic, 01_Create_Topic) { + // TODO add valid ast for unit test +#if 0 const char* dbname = "1.d1"; const char* topicName = "1.d1.t1"; @@ -99,7 +101,7 @@ TEST_F(MndTestTopic, 01_Create_Topic) { ASSERT_EQ(pRsp->code, 0); } - { test.SendShowMetaReq(TSDB_MGMT_TABLE_TP, ""); } + { test.SendShowMetaReq(TSDB_MGMT_TABLE_TOPICS, ""); } { int32_t contLen = 0; @@ -126,7 +128,7 @@ TEST_F(MndTestTopic, 01_Create_Topic) { } { - test.SendShowMetaReq(TSDB_MGMT_TABLE_TP, dbname); + test.SendShowMetaReq(TSDB_MGMT_TABLE_TOPICS, dbname); CHECK_META("show topics", 3); CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, "name"); @@ -143,7 +145,7 @@ TEST_F(MndTestTopic, 01_Create_Topic) { // restart test.Restart(); - test.SendShowMetaReq(TSDB_MGMT_TABLE_TP, dbname); + test.SendShowMetaReq(TSDB_MGMT_TABLE_TOPICS, dbname); test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); @@ -167,8 +169,9 @@ TEST_F(MndTestTopic, 01_Create_Topic) { ASSERT_NE(pRsp, nullptr); ASSERT_EQ(pRsp->code, TSDB_CODE_MND_TOPIC_NOT_EXIST); - test.SendShowMetaReq(TSDB_MGMT_TABLE_TP, dbname); + test.SendShowMetaReq(TSDB_MGMT_TABLE_TOPICS, dbname); test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 0); } +#endif } diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index 4b8aa5dfaf4cd5d08cb0c20ba9d9da50b66cf1b0..3ab007e3a2335685c2bcf4f262e324ee875a2a6b 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -6,30 +6,26 @@ target_sources( # vnode "src/vnd/vnodeArenaMAImpl.c" "src/vnd/vnodeBufferPool.c" + # "src/vnd/vnodeBufferPool2.c" "src/vnd/vnodeCfg.c" "src/vnd/vnodeCommit.c" "src/vnd/vnodeInt.c" "src/vnd/vnodeMain.c" - "src/vnd/vnodeMgr.c" "src/vnd/vnodeQuery.c" "src/vnd/vnodeStateMgr.c" "src/vnd/vnodeWrite.c" + "src/vnd/vnodeModule.c" + "src/vnd/vnodeSvr.c" # meta # "src/meta/metaBDBImpl.c" - "src/meta/metaCache.c" - "src/meta/metaCfg.c" "src/meta/metaIdx.c" "src/meta/metaMain.c" - "src/meta/metaQuery.c" "src/meta/metaTable.c" - "src/meta/metaTbCfg.c" - "src/meta/metaTbTag.c" "src/meta/metaTbUid.c" "src/meta/metaTDBImpl.c" # tsdb - # "src/tsdb/tsdbBDBImpl.c" "src/tsdb/tsdbTDBImpl.c" "src/tsdb/tsdbCommit.c" "src/tsdb/tsdbCompact.c" diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 6e85c4df649e73d0814570b4fc6b36693baaa30e..76fc09ca1df69902f3df9249a920abbbdd779d02 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -47,8 +47,8 @@ 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); +void vnodePreprocessWriteReqs(SVnode *pVnode, SArray *pMsgs); +int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); int vnodeProcessCMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg); @@ -60,34 +60,15 @@ int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad); int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName); // meta -typedef struct SMeta SMeta; // todo: remove -typedef struct SMTbCursor SMTbCursor; // todo: remove -typedef struct SMCtbCursor SMCtbCursor; // todo: remove -typedef struct SMSmaCursor SMSmaCursor; // todo: remove - -#define META_SUPER_TABLE TD_SUPER_TABLE -#define META_CHILD_TABLE TD_CHILD_TABLE -#define META_NORMAL_TABLE TD_NORMAL_TABLE +typedef struct SMeta SMeta; // todo: remove +typedef struct SMTbCursor SMTbCursor; typedef SVCreateTbReq STbCfg; typedef SVCreateTSmaReq SSmaCfg; -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); -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 metaCloseSmaCursor(SMSmaCursor *pSmaCur); -int64_t metaSmaCursorNext(SMSmaCursor *pSmaCur); +SMTbCursor *metaOpenTbCursor(SMeta *pMeta); +void metaCloseTbCursor(SMTbCursor *pTbCur); +char *metaTbCursorNext(SMTbCursor *pTbCur); // tsdb typedef struct STsdb STsdb; @@ -98,18 +79,7 @@ typedef void *tsdbReaderT; #define BLOCK_LOAD_OFFSET_SEQ_ORDER 1 #define BLOCK_LOAD_TABLE_SEQ_ORDER 2 #define BLOCK_LOAD_TABLE_RR_ORDER 3 -#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); + 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, @@ -127,18 +97,8 @@ SArray *tsdbRetrieveDataBlock(tsdbReaderT *pTsdbReadHandle, SArray *pColumn 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); -void tsdbCleanupReadHandle(tsdbReaderT queryHandle); -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); // tq -enum { - TQ_STREAM_TOKEN__DATA = 1, - TQ_STREAM_TOKEN__WATERMARK, - TQ_STREAM_TOKEN__CHECKPOINT, -}; typedef struct STqReadHandle STqReadHandle; @@ -153,9 +113,6 @@ int tqRetrieveDataBlockInfo(STqReadHandle *pHandle, SDataBlockInfo *pBlockIn SArray *tqRetrieveDataBlock(STqReadHandle *pHandle); // need to reposition -typedef struct SMgmtWrapper SMgmtWrapper; - -int32_t tdScanAndConvertSubmitMsg(SSubmitReq *pMsg); // structs struct SMetaCfg { @@ -202,21 +159,6 @@ struct SVnodeCfg { int8_t hashMethod; }; -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; -}; - struct SDataStatis { int16_t colId; int16_t maxIndex; @@ -241,22 +183,6 @@ typedef struct { uint64_t uid; } STableKeyInfo; -typedef struct STable { - uint64_t tid; - uint64_t uid; - STSchema *pSchema; -} STable; - -typedef struct { - int8_t type; - int8_t reserved[7]; - union { - void *data; - int64_t wmTs; - int64_t checkpointId; - }; -} STqStreamToken; - #ifdef __cplusplus } #endif diff --git a/source/dnode/vnode/src/inc/meta.h b/source/dnode/vnode/src/inc/meta.h index b3553f5d2d256703267a6cb8650cac86b860ce0e..94a1266f46a3f63a95982680a7d628523108091e 100644 --- a/source/dnode/vnode/src/inc/meta.h +++ b/source/dnode/vnode/src/inc/meta.h @@ -20,20 +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; -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); +// 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); @@ -47,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); @@ -73,6 +96,7 @@ tb_uid_t metaGenerateUid(SMeta* pMeta); struct SMeta { char* path; + SVnode* pVnode; SMetaCfg options; SMetaDB* pDB; SMetaIdx* pIdx; diff --git a/source/dnode/vnode/src/inc/tq.h b/source/dnode/vnode/src/inc/tq.h index bee443f48735561ca4852e23af7f734aac414b07..ce81006661b7529f7526d27f8a66bba3a26cccbc 100644 --- a/source/dnode/vnode/src/inc/tq.h +++ b/source/dnode/vnode/src/inc/tq.h @@ -20,48 +20,21 @@ extern "C" { #endif -// tqInt.h -#define tqFatal(...) \ - { \ - if (tqDebugFlag & DEBUG_FATAL) { \ - taosPrintLog("TQ FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \ - } \ - } - -#define tqError(...) \ - { \ - if (tqDebugFlag & DEBUG_ERROR) { \ - taosPrintLog("TQ ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \ - } \ - } - -#define tqWarn(...) \ - { \ - if (tqDebugFlag & DEBUG_WARN) { \ - taosPrintLog("TQ WARN ", DEBUG_WARN, 255, __VA_ARGS__); \ - } \ - } - -#define tqInfo(...) \ - { \ - if (tqDebugFlag & DEBUG_INFO) { \ - taosPrintLog("TQ ", DEBUG_INFO, 255, __VA_ARGS__); \ - } \ - } - -#define tqDebug(...) \ - { \ - if (tqDebugFlag & DEBUG_DEBUG) { \ - taosPrintLog("TQ ", DEBUG_DEBUG, tqDebugFlag, __VA_ARGS__); \ - } \ - } - -#define tqTrace(...) \ - { \ - if (tqDebugFlag & DEBUG_TRACE) { \ - taosPrintLog("TQ ", DEBUG_TRACE, tqDebugFlag, __VA_ARGS__); \ - } \ - } +// tqDebug =================== +// clang-format off +#define tqFatal(...) do { if (tqDebugFlag & DEBUG_FATAL) { taosPrintLog("TQ FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) +#define tqError(...) do { if (tqDebugFlag & DEBUG_ERROR) { taosPrintLog("TQ ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) +#define tqWarn(...) do { if (tqDebugFlag & DEBUG_WARN) { taosPrintLog("TQ WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) +#define tqInfo(...) do { if (tqDebugFlag & DEBUG_INFO) { taosPrintLog("TQ ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) +#define tqDebug(...) do { if (tqDebugFlag & DEBUG_DEBUG) { taosPrintLog("TQ ", DEBUG_DEBUG, tqDebugFlag, __VA_ARGS__); }} while(0) +#define tqTrace(...) do { if (tqDebugFlag & DEBUG_TRACE) { taosPrintLog("TQ ", DEBUG_TRACE, tqDebugFlag, __VA_ARGS__); }} while(0) +// clang-format on + +enum { + TQ_STREAM_TOKEN__DATA = 1, + TQ_STREAM_TOKEN__WATERMARK, + TQ_STREAM_TOKEN__CHECKPOINT, +}; #define TQ_BUFFER_SIZE 4 @@ -105,6 +78,31 @@ typedef enum { TQ_ITEM_READY, TQ_ITEM_PROCESS, TQ_ITEM_EMPTY } STqItemStatus; typedef struct STqOffsetCfg STqOffsetCfg; typedef struct STqOffsetStore STqOffsetStore; +struct STqReadHandle { + int64_t ver; + int64_t tbUid; + SHashObj* tbIdHash; + const SSubmitReq* pMsg; + SSubmitBlk* pBlock; + SSubmitMsgIter msgIter; + SSubmitBlkIter blkIter; + SMeta* pVnodeMeta; + SArray* pColIdList; // SArray + int32_t sver; + SSchemaWrapper* pSchemaWrapper; + STSchema* pSchema; +}; + +typedef struct { + int8_t type; + int8_t reserved[7]; + union { + void* data; + int64_t wmTs; + int64_t checkpointId; + }; +} STqStreamToken; + typedef struct { int16_t ver; int16_t action; @@ -248,6 +246,25 @@ typedef struct { static STqPushMgmt tqPushMgmt; +// init once +int tqInit(); +void tqCleanUp(); + +// open in each vnode +STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pMeta, STqCfg* tqConfig, + SMemAllocatorFactory* allocFac); +void tqClose(STQ*); +// required by vnode +int tqPushMsg(STQ*, void* msg, int32_t msgLen, tmsg_t msgType, int64_t version); +int tqCommit(STQ*); + +int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId); +int32_t tqProcessSetConnReq(STQ* pTq, char* msg); +int32_t tqProcessRebReq(STQ* pTq, char* msg); +int32_t tqProcessCancelConnReq(STQ* pTq, char* msg); +int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId); +int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); +int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId); int32_t tqSerializeConsumer(const STqConsumer*, STqSerializedHead**); int32_t tqDeserializeConsumer(STQ*, const STqSerializedHead*, STqConsumer**); diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index b85caad4c8bf97e29ea0c495c00ea4f5613480c3..d0e005f990739b75b8d77274b9a1f5111d63226b 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -20,10 +20,46 @@ extern "C" { #endif +// tsdbDebug ================ +// clang-format off +#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TSDB FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) +#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TSDB ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) +#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TSDB WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) +#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TSDB ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) +#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0) +#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) +// clang-format on + typedef struct SSmaStat SSmaStat; typedef struct SSmaEnv SSmaEnv; typedef struct SSmaEnvs SSmaEnvs; +typedef struct STable { + uint64_t tid; + uint64_t uid; + STSchema *pSchema; +} STable; + +#define TABLE_TID(t) (t)->tid +#define TABLE_UID(t) (t)->uid + +STsdb *tsdbOpen(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF, SMeta *pMeta, + STfs *pTfs); +void tsdbClose(STsdb *); +void tsdbRemove(const char *path); +int tsdbInsertData(STsdb *pTsdb, SSubmitReq *pMsg, SSubmitRsp *pRsp); +int tsdbPrepareCommit(STsdb *pTsdb); +int tsdbCommit(STsdb *pTsdb); +int32_t tsdbInitSma(STsdb *pTsdb); +int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg); +int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg); +int32_t tsdbUpdateSmaWindow(STsdb *pTsdb, SSubmitReq *pMsg, int64_t version); +int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg); +int32_t tsdbDropTSmaData(STsdb *pTsdb, int64_t indexUid); +int32_t tsdbInsertRSmaData(STsdb *pTsdb, char *msg); +void tsdbCleanupReadHandle(tsdbReaderT queryHandle); +int32_t tdScanAndConvertSubmitMsg(SSubmitReq *pMsg); + typedef enum { TSDB_FILE_HEAD = 0, // .head TSDB_FILE_DATA, // .data @@ -93,7 +129,7 @@ typedef struct STsdbMemTable { SMemAllocator *pMA; // Container SSkipList *pSlIdx; // SSkiplist - SHashObj * pHashIdx; + SHashObj *pHashIdx; } STsdbMemTable; typedef struct { @@ -105,33 +141,34 @@ typedef struct { // ================== typedef struct { STsdbFSMeta meta; // FS meta - SArray * df; // data file array - SArray * sf; // sma data file array v2f1900.index_name_1 + SArray *df; // data file array + SArray *sf; // sma data file array v2f1900.index_name_1 } SFSStatus; typedef struct { TdThreadRwlock lock; SFSStatus *cstatus; // current status - SHashObj * metaCache; // meta cache - SHashObj * metaCacheComp; // meta cache for compact + SHashObj *metaCache; // meta cache + SHashObj *metaCacheComp; // meta cache for compact bool intxn; SFSStatus *nstatus; // new status } STsdbFS; struct STsdb { int32_t vgId; + SVnode *pVnode; bool repoLocked; TdThreadMutex mutex; - char * path; + char *path; STsdbCfg config; - STsdbMemTable * mem; - STsdbMemTable * imem; + STsdbMemTable *mem; + STsdbMemTable *imem; SRtn rtn; SMemAllocatorFactory *pmaf; - STsdbFS * fs; - SMeta * pMeta; - STfs * pTfs; + STsdbFS *fs; + SMeta *pMeta; + STfs *pTfs; SSmaEnvs smaEnvs; }; @@ -153,16 +190,6 @@ static FORCE_INLINE STSchema *tsdbGetTableSchemaImpl(STable *pTable, bool lock, return pTable->pSchema; } -// tsdbLog -extern int32_t tsdbDebugFlag; - -#define tsdbFatal(...) do { if (tsdbDebugFlag & DEBUG_FATAL) { taosPrintLog("TSDB FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) -#define tsdbError(...) do { if (tsdbDebugFlag & DEBUG_ERROR) { taosPrintLog("TSDB ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) -#define tsdbWarn(...) do { if (tsdbDebugFlag & DEBUG_WARN) { taosPrintLog("TSDB WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) -#define tsdbInfo(...) do { if (tsdbDebugFlag & DEBUG_INFO) { taosPrintLog("TSDB ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) -#define tsdbDebug(...) do { if (tsdbDebugFlag & DEBUG_DEBUG) { taosPrintLog("TSDB ", DEBUG_DEBUG, tsdbDebugFlag, __VA_ARGS__); }} while(0) -#define tsdbTrace(...) do { if (tsdbDebugFlag & DEBUG_TRACE) { taosPrintLog("TSDB ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0) - // tsdbMemTable.h typedef struct { int rowsInserted; @@ -174,10 +201,10 @@ typedef struct { TSKEY keyLast; } SMergeInfo; -static void * taosTMalloc(size_t size); -static void * taosTCalloc(size_t nmemb, size_t size); -static void * taosTRealloc(void *ptr, size_t size); -static void * taosTZfree(void *ptr); +static void *taosTMalloc(size_t size); +static void *taosTCalloc(size_t nmemb, size_t size); +static void *taosTRealloc(void *ptr, size_t size); +static void *taosTZfree(void *ptr); static size_t taosTSizeof(void *ptr); static void taosTMemset(void *ptr, int c); @@ -398,18 +425,18 @@ static FORCE_INLINE size_t tsdbBlockAggrSize(int nCols, uint32_t blkVer) { } } -int tsdbInitReadH(SReadH *pReadh, STsdb *pRepo); -void tsdbDestroyReadH(SReadH *pReadh); -int tsdbSetAndOpenReadFSet(SReadH *pReadh, SDFileSet *pSet); -void tsdbCloseAndUnsetFSet(SReadH *pReadh); -int tsdbLoadBlockIdx(SReadH *pReadh); -int tsdbSetReadTable(SReadH *pReadh, STable *pTable); -int tsdbLoadBlockInfo(SReadH *pReadh, void *pTarget); -int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlockInfo); -int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, const int16_t *colIds, - int numOfColsIds, bool mergeBitmap); -int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock); -int tsdbEncodeSBlockIdx(void **buf, SBlockIdx *pIdx); +int tsdbInitReadH(SReadH *pReadh, STsdb *pRepo); +void tsdbDestroyReadH(SReadH *pReadh); +int tsdbSetAndOpenReadFSet(SReadH *pReadh, SDFileSet *pSet); +void tsdbCloseAndUnsetFSet(SReadH *pReadh); +int tsdbLoadBlockIdx(SReadH *pReadh); +int tsdbSetReadTable(SReadH *pReadh, STable *pTable); +int tsdbLoadBlockInfo(SReadH *pReadh, void *pTarget); +int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlockInfo); +int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, const int16_t *colIds, int numOfColsIds, + bool mergeBitmap); +int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock); +int tsdbEncodeSBlockIdx(void **buf, SBlockIdx *pIdx); void *tsdbDecodeSBlockIdx(void *buf, SBlockIdx *pIdx); void tsdbGetBlockStatis(SReadH *pReadh, SDataStatis *pStatis, int numOfCols, SBlock *pBlock); @@ -448,7 +475,7 @@ static FORCE_INLINE void *taosTMalloc(size_t size) { static FORCE_INLINE void *taosTCalloc(size_t nmemb, size_t size) { size_t tsize = nmemb * size; - void * ret = taosTMalloc(tsize); + void *ret = taosTMalloc(tsize); if (ret == NULL) return NULL; taosTMemset(ret, 0); @@ -459,14 +486,14 @@ static FORCE_INLINE size_t taosTSizeof(void *ptr) { return (ptr) ? (*(size_t *)( static FORCE_INLINE void taosTMemset(void *ptr, int c) { memset(ptr, c, taosTSizeof(ptr)); } -static FORCE_INLINE void * taosTRealloc(void *ptr, size_t size) { +static FORCE_INLINE void *taosTRealloc(void *ptr, size_t size) { if (ptr == NULL) return taosTMalloc(size); if (size <= taosTSizeof(ptr)) return ptr; - void * tptr = (void *)((char *)ptr - sizeof(size_t)); + void *tptr = (void *)((char *)ptr - sizeof(size_t)); size_t tsize = size + sizeof(size_t); - void* tptr1 = taosMemoryRealloc(tptr, tsize); + void *tptr1 = taosMemoryRealloc(tptr, tsize); if (tptr1 == NULL) return NULL; tptr = tptr1; @@ -475,9 +502,9 @@ static FORCE_INLINE void * taosTRealloc(void *ptr, size_t size) { return (void *)((char *)tptr + sizeof(size_t)); } -static FORCE_INLINE void* taosTZfree(void* ptr) { +static FORCE_INLINE void *taosTZfree(void *ptr) { if (ptr) { - taosMemoryFree((void*)((char*)ptr - sizeof(size_t))); + taosMemoryFree((void *)((char *)ptr - sizeof(size_t))); } return NULL; } @@ -530,30 +557,30 @@ static FORCE_INLINE int tsdbGetFidLevel(int fid, SRtn *pRtn) { // void* tsdbGetSmaDataByKey(SDBFile* pDBF, void* key, uint32_t keySize, uint32_t* valueSize); // tsdbFile -#define TSDB_FILE_HEAD_SIZE 512 -#define TSDB_FILE_DELIMITER 0xF00AFA0F +#define TSDB_FILE_HEAD_SIZE 512 +#define TSDB_FILE_DELIMITER 0xF00AFA0F #define TSDB_FILE_INIT_MAGIC 0xFFFFFFFF -#define TSDB_IVLD_FID INT_MIN -#define TSDB_FILE_STATE_OK 0 -#define TSDB_FILE_STATE_BAD 1 - -#define TSDB_FILE_INFO(tf) (&((tf)->info)) -#define TSDB_FILE_F(tf) (&((tf)->f)) -#define TSDB_FILE_PFILE(tf) ((tf)->pFile) -#define TSDB_FILE_FULL_NAME(tf) (TSDB_FILE_F(tf)->aname) -#define TSDB_FILE_OPENED(tf) (TSDB_FILE_PFILE(tf) != NULL) -#define TSDB_FILE_CLOSED(tf) (!TSDB_FILE_OPENED(tf)) -#define TSDB_FILE_SET_CLOSED(f) (TSDB_FILE_PFILE(f) = NULL) -#define TSDB_FILE_LEVEL(tf) (TSDB_FILE_F(tf)->did.level) -#define TSDB_FILE_ID(tf) (TSDB_FILE_F(tf)->did.id) -#define TSDB_FILE_DID(tf) (TSDB_FILE_F(tf)->did) -#define TSDB_FILE_REL_NAME(tf) (TSDB_FILE_F(tf)->rname) -#define TSDB_FILE_ABS_NAME(tf) (TSDB_FILE_F(tf)->aname) -#define TSDB_FILE_FSYNC(tf) taosFsyncFile(TSDB_FILE_PFILE(tf)) -#define TSDB_FILE_STATE(tf) ((tf)->state) +#define TSDB_IVLD_FID INT_MIN +#define TSDB_FILE_STATE_OK 0 +#define TSDB_FILE_STATE_BAD 1 + +#define TSDB_FILE_INFO(tf) (&((tf)->info)) +#define TSDB_FILE_F(tf) (&((tf)->f)) +#define TSDB_FILE_PFILE(tf) ((tf)->pFile) +#define TSDB_FILE_FULL_NAME(tf) (TSDB_FILE_F(tf)->aname) +#define TSDB_FILE_OPENED(tf) (TSDB_FILE_PFILE(tf) != NULL) +#define TSDB_FILE_CLOSED(tf) (!TSDB_FILE_OPENED(tf)) +#define TSDB_FILE_SET_CLOSED(f) (TSDB_FILE_PFILE(f) = NULL) +#define TSDB_FILE_LEVEL(tf) (TSDB_FILE_F(tf)->did.level) +#define TSDB_FILE_ID(tf) (TSDB_FILE_F(tf)->did.id) +#define TSDB_FILE_DID(tf) (TSDB_FILE_F(tf)->did) +#define TSDB_FILE_REL_NAME(tf) (TSDB_FILE_F(tf)->rname) +#define TSDB_FILE_ABS_NAME(tf) (TSDB_FILE_F(tf)->aname) +#define TSDB_FILE_FSYNC(tf) taosFsyncFile(TSDB_FILE_PFILE(tf)) +#define TSDB_FILE_STATE(tf) ((tf)->state) #define TSDB_FILE_SET_STATE(tf, s) ((tf)->state = (s)) -#define TSDB_FILE_IS_OK(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_OK) -#define TSDB_FILE_IS_BAD(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_BAD) +#define TSDB_FILE_IS_OK(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_OK) +#define TSDB_FILE_IS_BAD(tf) (TSDB_FILE_STATE(tf) == TSDB_FILE_STATE_BAD) typedef int32_t TSDB_FILE_T; typedef enum { @@ -576,19 +603,18 @@ static FORCE_INLINE uint32_t tsdbGetDFSVersion(TSDB_FILE_T fType) { // latest v } } +void tsdbInitDFile(STsdb *pRepo, SDFile *pDFile, SDiskID did, int fid, uint32_t ver, TSDB_FILE_T ftype); +void tsdbInitDFileEx(SDFile *pDFile, SDFile *pODFile); +int tsdbEncodeSDFile(void **buf, SDFile *pDFile); +void *tsdbDecodeSDFile(STsdb *pRepo, void *buf, SDFile *pDFile); +int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader, TSDB_FILE_T fType); +int tsdbUpdateDFileHeader(SDFile *pDFile); +int tsdbLoadDFileHeader(SDFile *pDFile, SDFInfo *pInfo); +int tsdbParseDFilename(const char *fname, int *vid, int *fid, TSDB_FILE_T *ftype, uint32_t *version); -void tsdbInitDFile(STsdb *pRepo, SDFile* pDFile, SDiskID did, int fid, uint32_t ver, TSDB_FILE_T ftype); -void tsdbInitDFileEx(SDFile* pDFile, SDFile* pODFile); -int tsdbEncodeSDFile(void** buf, SDFile* pDFile); -void* tsdbDecodeSDFile(STsdb *pRepo, void* buf, SDFile* pDFile); -int tsdbCreateDFile(STsdb *pRepo, SDFile* pDFile, bool updateHeader, TSDB_FILE_T fType); -int tsdbUpdateDFileHeader(SDFile* pDFile); -int tsdbLoadDFileHeader(SDFile* pDFile, SDFInfo* pInfo); -int tsdbParseDFilename(const char* fname, int* vid, int* fid, TSDB_FILE_T* ftype, uint32_t* version); - -static FORCE_INLINE void tsdbSetDFileInfo(SDFile* pDFile, SDFInfo* pInfo) { pDFile->info = *pInfo; } +static FORCE_INLINE void tsdbSetDFileInfo(SDFile *pDFile, SDFInfo *pInfo) { pDFile->info = *pInfo; } -static FORCE_INLINE int tsdbOpenDFile(SDFile* pDFile, int flags) { +static FORCE_INLINE int tsdbOpenDFile(SDFile *pDFile, int flags) { ASSERT(!TSDB_FILE_OPENED(pDFile)); pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), flags); @@ -600,14 +626,14 @@ static FORCE_INLINE int tsdbOpenDFile(SDFile* pDFile, int flags) { return 0; } -static FORCE_INLINE void tsdbCloseDFile(SDFile* pDFile) { +static FORCE_INLINE void tsdbCloseDFile(SDFile *pDFile) { if (TSDB_FILE_OPENED(pDFile)) { taosCloseFile(&pDFile->pFile); TSDB_FILE_SET_CLOSED(pDFile); } } -static FORCE_INLINE int64_t tsdbSeekDFile(SDFile* pDFile, int64_t offset, int whence) { +static FORCE_INLINE int64_t tsdbSeekDFile(SDFile *pDFile, int64_t offset, int whence) { // ASSERT(TSDB_FILE_OPENED(pDFile)); int64_t loffset = taosLSeekFile(TSDB_FILE_PFILE(pDFile), offset, whence); @@ -619,7 +645,7 @@ static FORCE_INLINE int64_t tsdbSeekDFile(SDFile* pDFile, int64_t offset, int wh return loffset; } -static FORCE_INLINE int64_t tsdbWriteDFile(SDFile* pDFile, void* buf, int64_t nbyte) { +static FORCE_INLINE int64_t tsdbWriteDFile(SDFile *pDFile, void *buf, int64_t nbyte) { ASSERT(TSDB_FILE_OPENED(pDFile)); int64_t nwrite = taosWriteFile(pDFile->pFile, buf, nbyte); @@ -631,11 +657,11 @@ static FORCE_INLINE int64_t tsdbWriteDFile(SDFile* pDFile, void* buf, int64_t nb return nwrite; } -static FORCE_INLINE void tsdbUpdateDFileMagic(SDFile* pDFile, void* pCksm) { - pDFile->info.magic = taosCalcChecksum(pDFile->info.magic, (uint8_t*)(pCksm), sizeof(TSCKSUM)); +static FORCE_INLINE void tsdbUpdateDFileMagic(SDFile *pDFile, void *pCksm) { + pDFile->info.magic = taosCalcChecksum(pDFile->info.magic, (uint8_t *)(pCksm), sizeof(TSCKSUM)); } -static FORCE_INLINE int tsdbAppendDFile(SDFile* pDFile, void* buf, int64_t nbyte, int64_t* offset) { +static FORCE_INLINE int tsdbAppendDFile(SDFile *pDFile, void *buf, int64_t nbyte, int64_t *offset) { ASSERT(TSDB_FILE_OPENED(pDFile)); int64_t toffset; @@ -659,9 +685,9 @@ static FORCE_INLINE int tsdbAppendDFile(SDFile* pDFile, void* buf, int64_t nbyte return (int)nbyte; } -static FORCE_INLINE int tsdbRemoveDFile(SDFile* pDFile) { return tfsRemoveFile(TSDB_FILE_F(pDFile)); } +static FORCE_INLINE int tsdbRemoveDFile(SDFile *pDFile) { return tfsRemoveFile(TSDB_FILE_F(pDFile)); } -static FORCE_INLINE int64_t tsdbReadDFile(SDFile* pDFile, void* buf, int64_t nbyte) { +static FORCE_INLINE int64_t tsdbReadDFile(SDFile *pDFile, void *buf, int64_t nbyte) { ASSERT(TSDB_FILE_OPENED(pDFile)); int64_t nread = taosReadFile(pDFile->pFile, buf, nbyte); @@ -673,7 +699,7 @@ static FORCE_INLINE int64_t tsdbReadDFile(SDFile* pDFile, void* buf, int64_t nby return nread; } -static FORCE_INLINE int tsdbCopyDFile(SDFile* pSrc, SDFile* pDest) { +static FORCE_INLINE int tsdbCopyDFile(SDFile *pSrc, SDFile *pDest) { if (tfsCopyFile(TSDB_FILE_F(pSrc), TSDB_FILE_F(pDest)) < 0) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; @@ -700,12 +726,12 @@ typedef struct { #define TSDB_LATEST_FSET_VER 0 -#define TSDB_FSET_FID(s) ((s)->fid) -#define TSDB_FSET_STATE(s) ((s)->state) -#define TSDB_FSET_VER(s) ((s)->ver) +#define TSDB_FSET_FID(s) ((s)->fid) +#define TSDB_FSET_STATE(s) ((s)->state) +#define TSDB_FSET_VER(s) ((s)->ver) #define TSDB_DFILE_IN_SET(s, t) ((s)->files + (t)) -#define TSDB_FSET_LEVEL(s) TSDB_FILE_LEVEL(TSDB_DFILE_IN_SET(s, 0)) -#define TSDB_FSET_ID(s) TSDB_FILE_ID(TSDB_DFILE_IN_SET(s, 0)) +#define TSDB_FSET_LEVEL(s) TSDB_FILE_LEVEL(TSDB_DFILE_IN_SET(s, 0)) +#define TSDB_FSET_ID(s) TSDB_FILE_ID(TSDB_DFILE_IN_SET(s, 0)) #define TSDB_FSET_SET_CLOSED(s) \ do { \ for (TSDB_FILE_T ftype = TSDB_FILE_HEAD; ftype < TSDB_FILE_MAX; ftype++) { \ @@ -719,24 +745,24 @@ typedef struct { } \ } while (0); -void tsdbInitDFileSet(STsdb *pRepo, SDFileSet* pSet, SDiskID did, int fid, uint32_t ver); -void tsdbInitDFileSetEx(SDFileSet* pSet, SDFileSet* pOSet); -int tsdbEncodeDFileSet(void** buf, SDFileSet* pSet); -void* tsdbDecodeDFileSet(STsdb *pRepo, void* buf, SDFileSet* pSet); -int tsdbEncodeDFileSetEx(void** buf, SDFileSet* pSet); -void* tsdbDecodeDFileSetEx(void* buf, SDFileSet* pSet); -int tsdbApplyDFileSetChange(SDFileSet* from, SDFileSet* to); -int tsdbCreateDFileSet(STsdb *pRepo, SDFileSet* pSet, bool updateHeader); -int tsdbUpdateDFileSetHeader(SDFileSet* pSet); -int tsdbScanAndTryFixDFileSet(STsdb* pRepo, SDFileSet* pSet); - -static FORCE_INLINE void tsdbCloseDFileSet(SDFileSet* pSet) { +void tsdbInitDFileSet(STsdb *pRepo, SDFileSet *pSet, SDiskID did, int fid, uint32_t ver); +void tsdbInitDFileSetEx(SDFileSet *pSet, SDFileSet *pOSet); +int tsdbEncodeDFileSet(void **buf, SDFileSet *pSet); +void *tsdbDecodeDFileSet(STsdb *pRepo, void *buf, SDFileSet *pSet); +int tsdbEncodeDFileSetEx(void **buf, SDFileSet *pSet); +void *tsdbDecodeDFileSetEx(void *buf, SDFileSet *pSet); +int tsdbApplyDFileSetChange(SDFileSet *from, SDFileSet *to); +int tsdbCreateDFileSet(STsdb *pRepo, SDFileSet *pSet, bool updateHeader); +int tsdbUpdateDFileSetHeader(SDFileSet *pSet); +int tsdbScanAndTryFixDFileSet(STsdb *pRepo, SDFileSet *pSet); + +static FORCE_INLINE void tsdbCloseDFileSet(SDFileSet *pSet) { for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { tsdbCloseDFile(TSDB_DFILE_IN_SET(pSet, ftype)); } } -static FORCE_INLINE int tsdbOpenDFileSet(SDFileSet* pSet, int flags) { +static FORCE_INLINE int tsdbOpenDFileSet(SDFileSet *pSet, int flags) { for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { if (tsdbOpenDFile(TSDB_DFILE_IN_SET(pSet, ftype), flags) < 0) { tsdbCloseDFileSet(pSet); @@ -746,13 +772,13 @@ static FORCE_INLINE int tsdbOpenDFileSet(SDFileSet* pSet, int flags) { return 0; } -static FORCE_INLINE void tsdbRemoveDFileSet(SDFileSet* pSet) { +static FORCE_INLINE void tsdbRemoveDFileSet(SDFileSet *pSet) { for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { (void)tsdbRemoveDFile(TSDB_DFILE_IN_SET(pSet, ftype)); } } -static FORCE_INLINE int tsdbCopyDFileSet(SDFileSet* pSrc, SDFileSet* pDest) { +static FORCE_INLINE int tsdbCopyDFileSet(SDFileSet *pSrc, SDFileSet *pDest) { for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { if (tsdbCopyDFile(TSDB_DFILE_IN_SET(pSrc, ftype), TSDB_DFILE_IN_SET(pDest, ftype)) < 0) { tsdbRemoveDFileSet(pDest); @@ -763,12 +789,12 @@ static FORCE_INLINE int tsdbCopyDFileSet(SDFileSet* pSrc, SDFileSet* pDest) { return 0; } -static FORCE_INLINE void tsdbGetFidKeyRange(int days, int8_t precision, int fid, TSKEY* minKey, TSKEY* maxKey) { +static FORCE_INLINE void tsdbGetFidKeyRange(int days, int8_t precision, int fid, TSKEY *minKey, TSKEY *maxKey) { *minKey = fid * days * tsTickPerDay[precision]; *maxKey = *minKey + days * tsTickPerDay[precision] - 1; } -static FORCE_INLINE bool tsdbFSetIsOk(SDFileSet* pSet) { +static FORCE_INLINE bool tsdbFSetIsOk(SDFileSet *pSet) { for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { if (TSDB_FILE_IS_BAD(TSDB_DFILE_IN_SET(pSet, ftype))) { return false; @@ -809,25 +835,25 @@ typedef struct { */ #define FS_CURRENT_STATUS(pfs) ((pfs)->cstatus) -#define FS_NEW_STATUS(pfs) ((pfs)->nstatus) -#define FS_IN_TXN(pfs) (pfs)->intxn -#define FS_VERSION(pfs) ((pfs)->cstatus->meta.version) -#define FS_TXN_VERSION(pfs) ((pfs)->nstatus->meta.version) +#define FS_NEW_STATUS(pfs) ((pfs)->nstatus) +#define FS_IN_TXN(pfs) (pfs)->intxn +#define FS_VERSION(pfs) ((pfs)->cstatus->meta.version) +#define FS_TXN_VERSION(pfs) ((pfs)->nstatus->meta.version) typedef struct { int direction; uint64_t version; // current FS version - STsdbFS * pfs; + STsdbFS *pfs; int index; // used to position next fset when version the same int fid; // used to seek when version is changed SDFileSet *pSet; } SFSIter; -#define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC +#define TSDB_FS_ITER_FORWARD TSDB_ORDER_ASC #define TSDB_FS_ITER_BACKWARD TSDB_ORDER_DESC STsdbFS *tsdbNewFS(const STsdbCfg *pCfg); -void * tsdbFreeFS(STsdbFS *pfs); +void *tsdbFreeFS(STsdbFS *pfs); int tsdbOpenFS(STsdb *pRepo); void tsdbCloseFS(STsdb *pRepo); void tsdbStartFSTxn(STsdb *pRepo, int64_t pointsAdd, int64_t storageAdd); @@ -872,7 +898,6 @@ static FORCE_INLINE int tsdbUnLockFS(STsdbFS *pFs) { // tsdbSma // #define TSDB_SMA_TEST // remove after test finished - // struct SSmaEnv { // TdThreadRwlock lock; // SDiskID did; @@ -888,7 +913,6 @@ static FORCE_INLINE int tsdbUnLockFS(STsdbFS *pFs) { // #define SMA_ENV_STAT(env) ((env)->pStat) // #define SMA_ENV_STAT_ITEMS(env) ((env)->pStat->smaStatItems) - // void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv); // void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv); // #if 0 @@ -931,9 +955,45 @@ static FORCE_INLINE int tsdbUnLockFS(STsdbFS *pFs) { // return 0; // } +typedef struct SSmaKey SSmaKey; + +struct SSmaKey { + TSKEY skey; + int64_t groupId; +}; + +typedef struct SDBFile SDBFile; + +struct SDBFile { + int32_t fid; + TDB *pDB; + char *path; +}; + +int32_t tsdbOpenDBEnv(TENV **ppEnv, const char *path); +int32_t tsdbCloseDBEnv(TENV *pEnv); +int32_t tsdbOpenDBF(TENV *pEnv, SDBFile *pDBF); +int32_t tsdbCloseDBF(SDBFile *pDBF); +int32_t tsdbSaveSmaToDB(SDBFile *pDBF, void *pKey, int32_t keyLen, void *pVal, int32_t valLen, TXN *txn); +void *tsdbGetSmaDataByKey(SDBFile *pDBF, const void *pKey, int32_t keyLen, int32_t *valLen); + +void tsdbDestroySmaEnv(SSmaEnv *pSmaEnv); +void *tsdbFreeSmaEnv(SSmaEnv *pSmaEnv); +#if 0 +int32_t tsdbGetTSmaStatus(STsdb *pTsdb, STSma *param, void *result); +int32_t tsdbRemoveTSmaData(STsdb *pTsdb, STSma *param, STimeWindow *pWin); +#endif + +// internal func +static FORCE_INLINE int32_t tsdbEncodeTSmaKey(int64_t groupId, TSKEY tsKey, void **pData) { + int32_t len = 0; + len += taosEncodeFixedI64(pData, tsKey); + len += taosEncodeFixedI64(pData, groupId); + return len; +} + #ifdef __cplusplus } #endif - #endif /*_TD_VNODE_TSDB_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/tsdbSma.h b/source/dnode/vnode/src/inc/tsdbSma.h deleted file mode 100644 index ce03fa7c678b888e6374cb23ba060f463e1c39c6..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/inc/tsdbSma.h +++ /dev/null @@ -1,68 +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_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..1cdb38b65029c116d6d8b36f9600c3e45e8739f2 --- /dev/null +++ b/source/dnode/vnode/src/inc/vnd.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef _TD_VND_H_ +#define _TD_VND_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// vnodeDebug ==================== +// clang-format off +#define vFatal(...) do { if (vDebugFlag & DEBUG_FATAL) { taosPrintLog("VND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) +#define vError(...) do { if (vDebugFlag & DEBUG_ERROR) { taosPrintLog("VND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) +#define vWarn(...) do { if (vDebugFlag & DEBUG_WARN) { taosPrintLog("VND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) +#define vInfo(...) do { if (vDebugFlag & DEBUG_INFO) { taosPrintLog("VND ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) +#define vDebug(...) do { if (vDebugFlag & DEBUG_DEBUG) { taosPrintLog("VND ", DEBUG_DEBUG, vDebugFlag, __VA_ARGS__); }} while(0) +#define vTrace(...) do { if (vDebugFlag & DEBUG_TRACE) { taosPrintLog("VND ", DEBUG_TRACE, vDebugFlag, __VA_ARGS__); }} while(0) +// clang-format on + +// vnodeModule ==================== +int vnodeScheduleTask(int (*execute)(void*), void* arg); + +// vnodeQuery ==================== +int vnodeQueryOpen(SVnode* pVnode); +void vnodeQueryClose(SVnode* pVnode); +int vnodeGetTableMeta(SVnode* pVnode, SRpcMsg* pMsg); + +#if 1 +// SVBufPool +int vnodeOpenBufPool(SVnode* pVnode); +void vnodeCloseBufPool(SVnode* pVnode); +int vnodeBufPoolSwitch(SVnode* pVnode); +int vnodeBufPoolRecycle(SVnode* pVnode); +void* vnodeMalloc(SVnode* pVnode, uint64_t size); +bool vnodeBufPoolIsFull(SVnode* pVnode); + +SMemAllocatorFactory* vBufPoolGetMAF(SVnode* pVnode); + +// SVMemAllocator +typedef struct SVArenaNode { + TD_SLIST_NODE(SVArenaNode); + uint64_t size; // current node size + void* ptr; + char data[]; +} SVArenaNode; + +typedef struct SVMemAllocator { + T_REF_DECLARE() + TD_DLIST_NODE(SVMemAllocator); + uint64_t capacity; + uint64_t ssize; + uint64_t lsize; + SVArenaNode* pNode; + TD_SLIST(SVArenaNode) nlist; +} SVMemAllocator; + +SVMemAllocator* vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize); +void vmaDestroy(SVMemAllocator* pVMA); +void vmaReset(SVMemAllocator* pVMA); +void* vmaMalloc(SVMemAllocator* pVMA, uint64_t size); +void vmaFree(SVMemAllocator* pVMA, void* ptr); +bool vmaIsFull(SVMemAllocator* pVMA); + +// vnodeCfg.h +extern const SVnodeCfg defaultVnodeOptions; + +int vnodeValidateOptions(const SVnodeCfg*); +void vnodeOptionsCopy(SVnodeCfg* pDest, const SVnodeCfg* pSrc); + +// For commit +#define vnodeShouldCommit vnodeBufPoolIsFull +int vnodeSyncCommit(SVnode* pVnode); +int vnodeAsyncCommit(SVnode* pVnode); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_VND_H_*/ \ No newline at end of file diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 7168493666e6e521bbac25246e99b47ab86cedd0..f988df01cb0ec83f3e45985ceb609915aff5f917 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -24,47 +24,32 @@ #include "tcoding.h" #include "tcompression.h" #include "tdatablock.h" +#include "tdbInt.h" #include "tfs.h" #include "tglobal.h" #include "tlist.h" #include "tlockfree.h" #include "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 "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; @@ -80,8 +65,6 @@ typedef struct { SHashObj* pHash; // streamId -> SStreamSinkInfo } SSink; -extern SVnodeMgr vnodeMgr; - // SVState struct SVState { int64_t processed; @@ -106,126 +89,17 @@ 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/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 371c20f157f61f34e68717b13f66070478fb2ae2..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/meta/metaCfg.c +++ /dev/null @@ -1,29 +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 ------------------------ */ - -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 5022d0e050020da393503659e4cd4803ff83e09e..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ /dev/null @@ -1,16 +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" \ No newline at end of file diff --git a/source/dnode/vnode/src/meta/metaTbCfg.c b/source/dnode/vnode/src/meta/metaTbCfg.c deleted file mode 100644 index 9d5012c17f3fe08e2abd6efc844d453090b0cb0b..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/meta/metaTbCfg.c +++ /dev/null @@ -1,48 +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" - -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 5022d0e050020da393503659e4cd4803ff83e09e..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/meta/metaTbTag.c +++ /dev/null @@ -1,16 +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" \ 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 f57103aab431eb1d1365e7b79dee660f808a2213..bfcc5dd2bb78db54ec7162c682ddf639c0fd760a 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -126,8 +126,8 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t versi int tqCommit(STQ* pTq) { return tqStorePersist(pTq->tqMeta); } int32_t tqGetTopicHandleSize(const STqTopic* pTopic) { - return strlen(pTopic->topicName) + strlen(pTopic->sql) + strlen(pTopic->logicalPlan) + strlen(pTopic->physicalPlan) + - strlen(pTopic->qmsg) + sizeof(int64_t) * 3; + return strlen(pTopic->topicName) + strlen(pTopic->sql) + strlen(pTopic->physicalPlan) + strlen(pTopic->qmsg) + + sizeof(int64_t) * 3; } int32_t tqGetConsumerHandleSize(const STqConsumer* pConsumer) { @@ -144,7 +144,6 @@ static FORCE_INLINE int32_t tEncodeSTqTopic(void** buf, const STqTopic* pTopic) int32_t tlen = 0; tlen += taosEncodeString(buf, pTopic->topicName); /*tlen += taosEncodeString(buf, pTopic->sql);*/ - /*tlen += taosEncodeString(buf, pTopic->logicalPlan);*/ /*tlen += taosEncodeString(buf, pTopic->physicalPlan);*/ tlen += taosEncodeString(buf, pTopic->qmsg); /*tlen += taosEncodeFixedI64(buf, pTopic->persistedOffset);*/ @@ -156,7 +155,6 @@ static FORCE_INLINE int32_t tEncodeSTqTopic(void** buf, const STqTopic* pTopic) static FORCE_INLINE const void* tDecodeSTqTopic(const void* buf, STqTopic* pTopic) { buf = taosDecodeStringTo(buf, pTopic->topicName); /*buf = taosDecodeString(buf, &pTopic->sql);*/ - /*buf = taosDecodeString(buf, &pTopic->logicalPlan);*/ /*buf = taosDecodeString(buf, &pTopic->physicalPlan);*/ buf = taosDecodeString(buf, &pTopic->qmsg); /*buf = taosDecodeFixedI64(buf, &pTopic->persistedOffset);*/ @@ -722,7 +720,6 @@ int32_t tqProcessSetConnReq(STQ* pTq, char* msg) { } strcpy(pTopic->topicName, req.topicName); pTopic->sql = req.sql; - pTopic->logicalPlan = req.logicalPlan; pTopic->physicalPlan = req.physicalPlan; pTopic->qmsg = req.qmsg; /*pTopic->committedOffset = -1;*/ diff --git a/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c b/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c deleted file mode 100644 index acd9c2dcaa72d39dab0576d7ab809e49eb5c24ee..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/tsdb/tsdbBDBImpl.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define ALLOW_FORBID_FUNC -#include "db.h" - -#include "vnodeInt.h" - -#define IMPL_WITH_LOCK 1 - -static int tsdbOpenBDBDb(DB **ppDB, DB_ENV *pEnv, const char *pFName, bool isDup); -static void tsdbCloseBDBDb(DB *pDB); - -#define BDB_PERR(info, code) fprintf(stderr, "%s:%d " info " reason: %s\n", __FILE__, __LINE__, db_strerror(code)) - -int32_t tsdbOpenDBF(TDBEnv pEnv, SDBFile *pDBF) { - // TDBEnv is shared by a group of SDBFile - if (!pEnv) { - terrno = TSDB_CODE_INVALID_PTR; - return -1; - } - - // Open DBF - if (tsdbOpenBDBDb(&(pDBF->pDB), pEnv, pDBF->path, false) < 0) { - terrno = TSDB_CODE_TDB_INIT_FAILED; - tsdbCloseBDBDb(pDBF->pDB); - return -1; - } - - return 0; -} - -void tsdbCloseDBF(SDBFile *pDBF) { - if (pDBF->pDB) { - tsdbCloseBDBDb(pDBF->pDB); - pDBF->pDB = NULL; - } - taosMemoryFreeClear(pDBF->path); -} - -int32_t tsdbOpenBDBEnv(DB_ENV **ppEnv, const char *path) { - int ret = 0; - DB_ENV *pEnv = NULL; - - if (path == NULL) return 0; - - ret = db_env_create(&pEnv, 0); - if (ret != 0) { - BDB_PERR("Failed to create tsdb env", ret); - return -1; - } - - ret = pEnv->open(pEnv, path, DB_CREATE | DB_INIT_CDB | DB_INIT_MPOOL, 0); - if (ret != 0) { - terrno = TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR; - tsdbWarn("Failed to open tsdb env for path %s since ret %d != 0", path ? path : "NULL", ret); - return -1; - } - - *ppEnv = pEnv; - - return 0; -} - -void tsdbCloseBDBEnv(DB_ENV *pEnv) { - if (pEnv) { - pEnv->close(pEnv, 0); - } -} - -static int tsdbOpenBDBDb(DB **ppDB, DB_ENV *pEnv, const char *pFName, bool isDup) { - int ret; - DB *pDB; - - ret = db_create(&(pDB), pEnv, 0); - if (ret != 0) { - BDB_PERR("Failed to create DBP", ret); - return -1; - } - - if (isDup) { - ret = pDB->set_flags(pDB, DB_DUPSORT); - if (ret != 0) { - BDB_PERR("Failed to set DB flags", ret); - return -1; - } - } - - ret = pDB->open(pDB, NULL, pFName, NULL, DB_BTREE, DB_CREATE, 0); - if (ret) { - BDB_PERR("Failed to open DBF", ret); - return -1; - } - - *ppDB = pDB; - - return 0; -} - -static void tsdbCloseBDBDb(DB *pDB) { - if (pDB) { - pDB->close(pDB, 0); - } -} - -int32_t tsdbSaveSmaToDB(SDBFile *pDBF, void *key, uint32_t keySize, void *data, uint32_t dataSize) { - int ret; - DBT key1 = {0}, value1 = {0}; - - key1.data = key; - key1.size = keySize; - - value1.data = data; - value1.size = dataSize; - - // TODO: lock - ret = pDBF->pDB->put(pDBF->pDB, NULL, &key1, &value1, 0); - if (ret) { - BDB_PERR("Failed to put data to DBF", ret); - // TODO: unlock - return -1; - } - // TODO: unlock - - return 0; -} - -void *tsdbGetSmaDataByKey(SDBFile *pDBF, void *key, uint32_t keySize, uint32_t *valueSize) { - void *result = NULL; - DBT key1 = {0}; - DBT value1 = {0}; - int ret; - - // Set key/value - key1.data = key; - key1.size = keySize; - - // Query - // TODO: lock - ret = pDBF->pDB->get(pDBF->pDB, NULL, &key1, &value1, 0); - // TODO: unlock - if (ret != 0) { - return NULL; - } - - result = taosMemoryCalloc(1, value1.size); - - if (result == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; - } - - *valueSize = value1.size; - memcpy(result, value1.data, value1.size); - - return result; -} \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index 54115003cfc8a497743f17598efcb9656a0d7e2f..5a477e646cb4ea2cf94cde85608dd813bb929a14 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -375,6 +375,8 @@ static int tsdbMemTableInsertTbData(STsdb *pTsdb, SSubmitBlk *pBlock, int32_t *p if (pMemTable->keyMin > keyMin) pMemTable->keyMin = keyMin; if (pMemTable->keyMax < keyMax) pMemTable->keyMax = keyMax; + (*pAffectedRows) += pBlock->numOfRows; + // STSRow* lastRow = NULL; // int64_t osize = SL_SIZE(pTableData->pData); // tsdbSetupSkipListHookFns(pTableData->pData, pRepo, pTable, &points, &lastRow); diff --git a/source/dnode/vnode/src/tsdb/tsdbTDBImpl.c b/source/dnode/vnode/src/tsdb/tsdbTDBImpl.c index 519ecd3fa06952609c522f4ef937b8b953bc1948..ebfa1ecaeb7a044f67912c17a4e01400fc69ff2a 100644 --- a/source/dnode/vnode/src/tsdb/tsdbTDBImpl.c +++ b/source/dnode/vnode/src/tsdb/tsdbTDBImpl.c @@ -107,8 +107,7 @@ int32_t tsdbSaveSmaToDB(SDBFile *pDBF, void *pKey, int32_t keyLen, void *pVal, i } void *tsdbGetSmaDataByKey(SDBFile *pDBF, const void *pKey, int32_t keyLen, int32_t *valLen) { - void *result; - void *pVal; + void *pVal = NULL; int ret; ret = tdbDbGet(pDBF->pDB, pKey, keyLen, &pVal, valLen); @@ -120,18 +119,10 @@ void *tsdbGetSmaDataByKey(SDBFile *pDBF, const void *pKey, int32_t keyLen, int32 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; + return pVal; } \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbWrite.c b/source/dnode/vnode/src/tsdb/tsdbWrite.c index abfcc675eac4df251ecb0da8ace6cfa627754d9a..910b5adc963559f712868937abfe1d5ad160b526 100644 --- a/source/dnode/vnode/src/tsdb/tsdbWrite.c +++ b/source/dnode/vnode/src/tsdb/tsdbWrite.c @@ -31,5 +31,5 @@ int tsdbInsertData(STsdb *pTsdb, SSubmitReq *pMsg, SSubmitRsp *pRsp) { return -1; } } - return tsdbMemTableInsert(pTsdb, pTsdb->mem, pMsg, NULL); + return tsdbMemTableInsert(pTsdb, pTsdb->mem, pMsg, pRsp); } \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeBufferPool2.c b/source/dnode/vnode/src/vnd/vnodeBufferPool2.c new file mode 100644 index 0000000000000000000000000000000000000000..d63c86734a4573112fd449dc8cb23e6a8f91af7e --- /dev/null +++ b/source/dnode/vnode/src/vnd/vnodeBufferPool2.c @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "vnodeInt.h" + +/* ------------------------ STRUCTURES ------------------------ */ + +static int vnodeBufPoolCreate(int size, SVBufPool **ppPool); +static int vnodeBufPoolDestroy(SVBufPool *pPool); + +int vnodeOpenBufPool(SVnode *pVnode, int64_t size) { + SVBufPool *pPool = NULL; + int ret; + + ASSERT(pVnode->pPool == NULL); + + for (int i = 0; i < 3; i++) { + // create pool + ret = vnodeBufPoolCreate(size, &pPool); + if (ret < 0) { + vError("vgId:%d failed to open vnode buffer pool since %s", TD_VNODE_ID(pVnode), tstrerror(terrno)); + vnodeCloseBufPool(pVnode); + return -1; + } + + // add pool to queue + pPool->next = pVnode->pPool; + pVnode->pPool = pPool; + } + + vDebug("vgId:%d vnode buffer pool is opened, pool size: %" PRId64, TD_VNODE_ID(pVnode), size); + + return 0; +} + +int vnodeCloseBufPool(SVnode *pVnode) { + SVBufPool *pPool; + + for (pPool = pVnode->pPool; pPool; pPool = pVnode->pPool) { + pVnode->pPool = pPool->next; + vnodeBufPoolDestroy(pPool); + } + + vDebug("vgId:%d vnode buffer pool is closed", TD_VNODE_ID(pVnode)); + + return 0; +} + +void vnodeBufPoolReset(SVBufPool *pPool) { + SVBufPoolNode *pNode; + + for (pNode = pPool->pTail; pNode->prev; pNode = pPool->pTail) { + ASSERT(pNode->pnext == &pPool->pTail); + pNode->prev->pnext = &pPool->pTail; + pPool->pTail = pNode->prev; + pPool->size = pPool->size - sizeof(*pNode) - pNode->size; + taosMemoryFree(pNode); + } + + ASSERT(pPool->size == pPool->ptr - pPool->node.data); + + pPool->size = 0; + pPool->ptr = pPool->node.data; +} + +void *vnodeBufPoolMalloc(SVBufPool *pPool, size_t size) { + SVBufPoolNode *pNode; + void *p; + + if (pPool->node.size >= pPool->ptr - pPool->node.data + size) { + // allocate from the anchor node + p = pPool->ptr; + pPool->ptr = pPool->ptr + size; + pPool->size += size; + } else { + // allocate a new node + pNode = taosMemoryMalloc(sizeof(*pNode) + size); + if (pNode == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + p = pNode->data; + pNode->size = size; + pNode->prev = pPool->pTail; + pNode->pnext = &pPool->pTail; + pPool->pTail->pnext = &pNode->prev; + pPool->pTail = pNode; + + pPool->size = pPool->size + sizeof(*pNode) + size; + } + + return p; +} + +void vnodeBufPoolFree(SVBufPool *pPool, void *p) { + uint8_t *ptr = (uint8_t *)p; + SVBufPoolNode *pNode; + + if (ptr < pPool->node.data || ptr >= pPool->node.data + pPool->node.size) { + pNode = &((SVBufPoolNode *)p)[-1]; + *pNode->pnext = pNode->prev; + pNode->prev->pnext = pNode->pnext; + + pPool->size = pPool->size - sizeof(*pNode) - pNode->size; + taosMemoryFree(pNode); + } +} + +// STATIC METHODS ------------------- +static int vnodeBufPoolCreate(int size, SVBufPool **ppPool) { + SVBufPool *pPool; + + pPool = taosMemoryMalloc(sizeof(SVBufPool) + size); + if (pPool == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + pPool->next = NULL; + pPool->nRef = 0; + pPool->size = 0; + pPool->ptr = pPool->node.data; + pPool->pTail = &pPool->node; + pPool->node.prev = NULL; + pPool->node.pnext = &pPool->pTail; + pPool->node.size = size; + + *ppPool = pPool; + return 0; +} + +static int vnodeBufPoolDestroy(SVBufPool *pPool) { + vnodeBufPoolReset(pPool); + taosMemoryFree(pPool); + return 0; +} \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/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 270dc377b97968a28798a96eae37f69c990de8dd..10d8154a15dc40590648b2d661d6e6068897753e 100644 --- a/source/dnode/vnode/src/vnd/vnodeInt.c +++ b/source/dnode/vnode/src/vnd/vnodeInt.c @@ -21,25 +21,4 @@ int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg) { return 0; } int32_t vnodeCompact(SVnode *pVnode) { return 0; } -int32_t vnodeSync(SVnode *pVnode) { return 0; } - -int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) { - pLoad->vgId = pVnode->vgId; - pLoad->role = TAOS_SYNC_STATE_LEADER; - pLoad->numOfTables = metaGetTbNum(pVnode->pMeta); - pLoad->numOfTimeSeries = 400; - pLoad->totalStorage = 300; - pLoad->compStorage = 200; - pLoad->pointsWritten = 100; - pLoad->numOfSelectReqs = 1; - pLoad->numOfInsertReqs = 3; - pLoad->numOfInsertSuccessReqs = 2; - pLoad->numOfBatchInsertReqs = 5; - pLoad->numOfBatchInsertSuccessReqs = 4; - return 0; -} - -int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { - /*vInfo("sync message is processed");*/ - return 0; -} +int32_t vnodeSync(SVnode *pVnode) { return 0; } \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeMgr.c b/source/dnode/vnode/src/vnd/vnodeMgr.c deleted file mode 100644 index df5e2ceffa9d865df5b14e66daa5ef7c96006da4..0000000000000000000000000000000000000000 --- a/source/dnode/vnode/src/vnd/vnodeMgr.c +++ /dev/null @@ -1,113 +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" - -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 87ce471de9b2f6a91ee9b07d444bab384eb1dbc5..75079d50b285ff87bfed713e30d4adf7daba6862 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -15,64 +15,13 @@ #include "vnodeInt.h" -static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg); - int vnodeQueryOpen(SVnode *pVnode) { return qWorkerInit(NODE_TYPE_VNODE, pVnode->vgId, NULL, (void **)&pVnode->pQuery, &pVnode->msgCb); } void vnodeQueryClose(SVnode *pVnode) { qWorkerDestroy((void **)&pVnode->pQuery); } -int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) { - vTrace("message in query queue is processing"); - SReadHandle handle = {.reader = pVnode->pTsdb, .meta = pVnode->pMeta, .config = &pVnode->config}; - - switch (pMsg->msgType) { - case TDMT_VND_QUERY: - return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg); - case TDMT_VND_QUERY_CONTINUE: - return qWorkerProcessCQueryMsg(&handle, pVnode->pQuery, pMsg); - default: - vError("unknown msg type:%d in query queue", pMsg->msgType); - return TSDB_CODE_VND_APP_ERROR; - } -} - -int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { - vTrace("message in fetch queue is processing"); - char *msgstr = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); - int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); - switch (pMsg->msgType) { - case TDMT_VND_FETCH: - return qWorkerProcessFetchMsg(pVnode, pVnode->pQuery, pMsg); - case TDMT_VND_FETCH_RSP: - return qWorkerProcessFetchRsp(pVnode, pVnode->pQuery, pMsg); - case TDMT_VND_RES_READY: - return qWorkerProcessReadyMsg(pVnode, pVnode->pQuery, pMsg); - case TDMT_VND_TASKS_STATUS: - return qWorkerProcessStatusMsg(pVnode, pVnode->pQuery, pMsg); - case TDMT_VND_CANCEL_TASK: - return qWorkerProcessCancelMsg(pVnode, pVnode->pQuery, pMsg); - case TDMT_VND_DROP_TASK: - return qWorkerProcessDropMsg(pVnode, pVnode->pQuery, pMsg); - case TDMT_VND_TABLE_META: - return vnodeGetTableMeta(pVnode, pMsg); - case TDMT_VND_CONSUME: - return tqProcessPollReq(pVnode->pTq, pMsg, pInfo->workerId); - case TDMT_VND_TASK_PIPE_EXEC: - case TDMT_VND_TASK_MERGE_EXEC: - return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen, 0); - case TDMT_VND_STREAM_TRIGGER: - return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen, 0); - case TDMT_VND_QUERY_HEARTBEAT: - return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg); - default: - vError("unknown msg type:%d in fetch queue", pMsg->msgType); - return TSDB_CODE_VND_APP_ERROR; - } -} - -static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) { +int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) { STbCfg *pTbCfg = NULL; STbCfg *pStbCfg = NULL; tb_uid_t uid; @@ -200,3 +149,19 @@ _exit: tmsgSendRsp(&rpcMsg); return TSDB_CODE_SUCCESS; } + +int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) { + pLoad->vgId = pVnode->vgId; + pLoad->role = TAOS_SYNC_STATE_LEADER; + pLoad->numOfTables = metaGetTbNum(pVnode->pMeta); + pLoad->numOfTimeSeries = 400; + pLoad->totalStorage = 300; + pLoad->compStorage = 200; + pLoad->pointsWritten = 100; + pLoad->numOfSelectReqs = 1; + pLoad->numOfInsertReqs = 3; + pLoad->numOfInsertSuccessReqs = 2; + pLoad->numOfBatchInsertReqs = 5; + pLoad->numOfBatchInsertSuccessReqs = 4; + return 0; +} diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c new file mode 100644 index 0000000000000000000000000000000000000000..395f715b8fd1d7e3ceabcdc11c62242d2d5edce3 --- /dev/null +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -0,0 +1,302 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "vnodeInt.h" + +static int vnodeProcessCreateStbReq(SVnode *pVnode, void *pReq); +static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SRpcMsg **pRsp); +static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq); + +void vnodePreprocessWriteReqs(SVnode *pVnode, SArray *pMsgs) { + SNodeMsg *pMsg; + SRpcMsg *pRpc; + + for (int i = 0; i < taosArrayGetSize(pMsgs); i++) { + pMsg = *(SNodeMsg **)taosArrayGet(pMsgs, i); + pRpc = &pMsg->rpcMsg; + + // set request version + void *pBuf = POINTER_SHIFT(pRpc->pCont, sizeof(SMsgHead)); + int64_t ver = pVnode->state.processed++; + taosEncodeFixedI64(&pBuf, ver); + + if (walWrite(pVnode->pWal, ver, pRpc->msgType, pRpc->pCont, pRpc->contLen) < 0) { + // TODO: handle error + /*ASSERT(false);*/ + vError("vnode:%d write wal error since %s", pVnode->vgId, terrstr()); + } + } + + walFsync(pVnode->pWal, false); +} + +int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { + void *ptr = NULL; + int ret; + + if (pVnode->config.streamMode == 0) { + ptr = vnodeMalloc(pVnode, pMsg->contLen); + if (ptr == NULL) { + // TODO: handle error + } + + // TODO: copy here need to be extended + memcpy(ptr, pMsg->pCont, pMsg->contLen); + } + + // todo: change the interface here + int64_t ver; + taosDecodeFixedI64(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &ver); + if (tqPushMsg(pVnode->pTq, pMsg->pCont, pMsg->contLen, pMsg->msgType, ver) < 0) { + // TODO: handle error + } + + switch (pMsg->msgType) { + case TDMT_VND_CREATE_STB: + ret = vnodeProcessCreateStbReq(pVnode, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))); + return 0; + case TDMT_VND_CREATE_TABLE: + return vnodeProcessCreateTbReq(pVnode, pMsg, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), pRsp); + case TDMT_VND_ALTER_STB: + return vnodeProcessAlterStbReq(pVnode, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))); + case TDMT_VND_DROP_STB: + vTrace("vgId:%d, process drop stb req", pVnode->vgId); + break; + case TDMT_VND_DROP_TABLE: + break; + case TDMT_VND_SUBMIT: + /*printf("vnode %d write data %ld\n", pVnode->vgId, ver);*/ + if (pVnode->config.streamMode == 0) { + if (tsdbInsertData(pVnode->pTsdb, (SSubmitReq *)ptr, NULL) < 0) { + // TODO: handle error + } + } + break; + case TDMT_VND_MQ_SET_CONN: { + if (tqProcessSetConnReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { + // TODO: handle error + } + } break; + case TDMT_VND_MQ_REB: { + if (tqProcessRebReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { + } + } break; + case TDMT_VND_MQ_CANCEL_CONN: { + if (tqProcessCancelConnReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { + } + } break; + case TDMT_VND_TASK_DEPLOY: { + if (tqProcessTaskDeploy(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), + pMsg->contLen - sizeof(SMsgHead)) < 0) { + } + } break; + case TDMT_VND_TASK_WRITE_EXEC: { + if (tqProcessTaskExec(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), pMsg->contLen - sizeof(SMsgHead), + 0) < 0) { + } + } break; + case TDMT_VND_CREATE_SMA: { // timeRangeSMA + + if (tsdbCreateTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { + // TODO + } + // } break; + // case TDMT_VND_CANCEL_SMA: { // timeRangeSMA + // } break; + // case TDMT_VND_DROP_SMA: { // timeRangeSMA + // if (tsdbDropTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { + // // TODO + // } + + } break; + default: + ASSERT(0); + break; + } + + pVnode->state.applied = ver; + + // Check if it needs to commit + if (vnodeShouldCommit(pVnode)) { + // tsem_wait(&(pVnode->canCommit)); + if (vnodeAsyncCommit(pVnode) < 0) { + // TODO: handle error + } + } + + return 0; +} + +int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) { + vTrace("message in query queue is processing"); + SReadHandle handle = {.reader = pVnode->pTsdb, .meta = pVnode->pMeta, .config = &pVnode->config}; + + switch (pMsg->msgType) { + case TDMT_VND_QUERY: + return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg); + case TDMT_VND_QUERY_CONTINUE: + return qWorkerProcessCQueryMsg(&handle, pVnode->pQuery, pMsg); + default: + vError("unknown msg type:%d in query queue", pMsg->msgType); + return TSDB_CODE_VND_APP_ERROR; + } +} + +int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { + vTrace("message in fetch queue is processing"); + char *msgstr = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); + int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); + switch (pMsg->msgType) { + case TDMT_VND_FETCH: + return qWorkerProcessFetchMsg(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_FETCH_RSP: + return qWorkerProcessFetchRsp(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_RES_READY: + return qWorkerProcessReadyMsg(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_TASKS_STATUS: + return qWorkerProcessStatusMsg(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_CANCEL_TASK: + return qWorkerProcessCancelMsg(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_DROP_TASK: + return qWorkerProcessDropMsg(pVnode, pVnode->pQuery, pMsg); + case TDMT_VND_TABLE_META: + return vnodeGetTableMeta(pVnode, pMsg); + case TDMT_VND_CONSUME: + return tqProcessPollReq(pVnode->pTq, pMsg, pInfo->workerId); + case TDMT_VND_TASK_PIPE_EXEC: + case TDMT_VND_TASK_MERGE_EXEC: + return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen, 0); + case TDMT_VND_STREAM_TRIGGER: + return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen, 0); + case TDMT_VND_QUERY_HEARTBEAT: + return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg); + default: + vError("unknown msg type:%d in fetch queue", pMsg->msgType); + return TSDB_CODE_VND_APP_ERROR; + } +} + +// TODO: remove the function +void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { + // TODO + + // blockDebugShowData(data); + tsdbInsertTSmaData(((SVnode *)pVnode)->pTsdb, smaId, (const char *)data); +} + +int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { + /*vInfo("sync message is processed");*/ + return 0; +} + +static int vnodeProcessCreateStbReq(SVnode *pVnode, void *pReq) { + SVCreateTbReq vCreateTbReq = {0}; + tDeserializeSVCreateTbReq(pReq, &vCreateTbReq); + if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq)) < 0) { + // TODO + return -1; + } + + taosMemoryFree(vCreateTbReq.stbCfg.pSchema); + taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema); + if (vCreateTbReq.stbCfg.pRSmaParam) { + taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->pFuncIds); + taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam); + } + taosMemoryFree(vCreateTbReq.dbFName); + taosMemoryFree(vCreateTbReq.name); + + return 0; +} + +static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SRpcMsg **pRsp) { + SVCreateTbBatchReq vCreateTbBatchReq = {0}; + SVCreateTbBatchRsp vCreateTbBatchRsp = {0}; + tDeserializeSVCreateTbBatchReq(pReq, &vCreateTbBatchReq); + int reqNum = taosArrayGetSize(vCreateTbBatchReq.pArray); + for (int i = 0; i < reqNum; i++) { + SVCreateTbReq *pCreateTbReq = taosArrayGet(vCreateTbBatchReq.pArray, i); + + char tableFName[TSDB_TABLE_FNAME_LEN]; + SMsgHead *pHead = (SMsgHead *)pMsg->pCont; + sprintf(tableFName, "%s.%s", pCreateTbReq->dbFName, pCreateTbReq->name); + + int32_t code = vnodeValidateTableHash(&pVnode->config, tableFName); + if (code) { + SVCreateTbRsp rsp; + rsp.code = code; + + taosArrayPush(vCreateTbBatchRsp.rspList, &rsp); + } + + if (metaCreateTable(pVnode->pMeta, pCreateTbReq) < 0) { + // TODO: handle error + vError("vgId:%d, failed to create table: %s", pVnode->vgId, pCreateTbReq->name); + } + // TODO: to encapsule a free API + taosMemoryFree(pCreateTbReq->name); + taosMemoryFree(pCreateTbReq->dbFName); + if (pCreateTbReq->type == TD_SUPER_TABLE) { + taosMemoryFree(pCreateTbReq->stbCfg.pSchema); + taosMemoryFree(pCreateTbReq->stbCfg.pTagSchema); + if (pCreateTbReq->stbCfg.pRSmaParam) { + taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam->pFuncIds); + taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam); + } + } else if (pCreateTbReq->type == TD_CHILD_TABLE) { + taosMemoryFree(pCreateTbReq->ctbCfg.pTag); + } else { + taosMemoryFree(pCreateTbReq->ntbCfg.pSchema); + if (pCreateTbReq->ntbCfg.pRSmaParam) { + taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam->pFuncIds); + taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam); + } + } + } + + vTrace("vgId:%d process create %" PRIzu " tables", pVnode->vgId, taosArrayGetSize(vCreateTbBatchReq.pArray)); + taosArrayDestroy(vCreateTbBatchReq.pArray); + if (vCreateTbBatchRsp.rspList) { + int32_t contLen = tSerializeSVCreateTbBatchRsp(NULL, 0, &vCreateTbBatchRsp); + void *msg = rpcMallocCont(contLen); + tSerializeSVCreateTbBatchRsp(msg, contLen, &vCreateTbBatchRsp); + taosArrayDestroy(vCreateTbBatchRsp.rspList); + + *pRsp = taosMemoryCalloc(1, sizeof(SRpcMsg)); + (*pRsp)->msgType = TDMT_VND_CREATE_TABLE_RSP; + (*pRsp)->pCont = msg; + (*pRsp)->contLen = contLen; + (*pRsp)->handle = pMsg->handle; + (*pRsp)->ahandle = pMsg->ahandle; + } + + return 0; +} + +static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq) { + SVCreateTbReq vAlterTbReq = {0}; + vTrace("vgId:%d, process alter stb req", pVnode->vgId); + tDeserializeSVCreateTbReq(pReq, &vAlterTbReq); + // TODO: to encapsule a free API + taosMemoryFree(vAlterTbReq.stbCfg.pSchema); + taosMemoryFree(vAlterTbReq.stbCfg.pTagSchema); + if (vAlterTbReq.stbCfg.pRSmaParam) { + taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam->pFuncIds); + taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam); + } + taosMemoryFree(vAlterTbReq.dbFName); + taosMemoryFree(vAlterTbReq.name); + return 0; +} \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeWrite.c b/source/dnode/vnode/src/vnd/vnodeWrite.c index 24b5d4bae50774f8d7aea3039ad72cf679bb6a87..16b881f00d58f27120ccd3fd0ecd229a84d7935b 100644 --- a/source/dnode/vnode/src/vnd/vnodeWrite.c +++ b/source/dnode/vnode/src/vnd/vnodeWrite.c @@ -15,277 +15,4 @@ #include "vnodeInt.h" -void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { - // TODO - - // blockDebugShowData(data); - tsdbInsertTSmaData(((SVnode *)pVnode)->pTsdb, smaId, (const char *)data); -} - -void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { - SNodeMsg *pMsg; - SRpcMsg *pRpc; - - for (int i = 0; i < taosArrayGetSize(pMsgs); i++) { - pMsg = *(SNodeMsg **)taosArrayGet(pMsgs, i); - pRpc = &pMsg->rpcMsg; - - // set request version - void *pBuf = POINTER_SHIFT(pRpc->pCont, sizeof(SMsgHead)); - int64_t ver = pVnode->state.processed++; - taosEncodeFixedI64(&pBuf, ver); - - if (walWrite(pVnode->pWal, ver, pRpc->msgType, pRpc->pCont, pRpc->contLen) < 0) { - // TODO: handle error - /*ASSERT(false);*/ - vError("vnode:%d write wal error since %s", pVnode->vgId, terrstr()); - } - } - - walFsync(pVnode->pWal, false); - - // TODO: Integrate RAFT module here - - // No results are returned because error handling is difficult - // return 0; -} - -int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { - void *ptr = NULL; - - if (pVnode->config.streamMode == 0) { - ptr = vnodeMalloc(pVnode, pMsg->contLen); - if (ptr == NULL) { - // TODO: handle error - } - - // TODO: copy here need to be extended - memcpy(ptr, pMsg->pCont, pMsg->contLen); - } - - // todo: change the interface here - int64_t ver; - taosDecodeFixedI64(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &ver); - if (tqPushMsg(pVnode->pTq, pMsg->pCont, pMsg->contLen, pMsg->msgType, ver) < 0) { - // TODO: handle error - } - - switch (pMsg->msgType) { - case TDMT_VND_CREATE_STB: { - SVCreateTbReq vCreateTbReq = {0}; - tDeserializeSVCreateTbReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateTbReq); - if (metaCreateTable(pVnode->pMeta, &(vCreateTbReq)) < 0) { - // TODO: handle error - } - - // TODO: to encapsule a free API - taosMemoryFree(vCreateTbReq.stbCfg.pSchema); - taosMemoryFree(vCreateTbReq.stbCfg.pTagSchema); - if (vCreateTbReq.stbCfg.pRSmaParam) { - taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam->pFuncIds); - taosMemoryFree(vCreateTbReq.stbCfg.pRSmaParam); - } - taosMemoryFree(vCreateTbReq.dbFName); - taosMemoryFree(vCreateTbReq.name); - break; - } - case TDMT_VND_CREATE_TABLE: { - SVCreateTbBatchReq vCreateTbBatchReq = {0}; - SVCreateTbBatchRsp vCreateTbBatchRsp = {0}; - tDeserializeSVCreateTbBatchReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateTbBatchReq); - int reqNum = taosArrayGetSize(vCreateTbBatchReq.pArray); - for (int i = 0; i < reqNum; i++) { - SVCreateTbReq *pCreateTbReq = taosArrayGet(vCreateTbBatchReq.pArray, i); - - char tableFName[TSDB_TABLE_FNAME_LEN]; - SMsgHead *pHead = (SMsgHead *)pMsg->pCont; - sprintf(tableFName, "%s.%s", pCreateTbReq->dbFName, pCreateTbReq->name); - - int32_t code = vnodeValidateTableHash(&pVnode->config, tableFName); - if (code) { - SVCreateTbRsp rsp; - rsp.code = code; - - taosArrayPush(vCreateTbBatchRsp.rspList, &rsp); - } - - if (metaCreateTable(pVnode->pMeta, pCreateTbReq) < 0) { - // TODO: handle error - vError("vgId:%d, failed to create table: %s", pVnode->vgId, pCreateTbReq->name); - } - // TODO: to encapsule a free API - taosMemoryFree(pCreateTbReq->name); - taosMemoryFree(pCreateTbReq->dbFName); - if (pCreateTbReq->type == TD_SUPER_TABLE) { - taosMemoryFree(pCreateTbReq->stbCfg.pSchema); - taosMemoryFree(pCreateTbReq->stbCfg.pTagSchema); - if (pCreateTbReq->stbCfg.pRSmaParam) { - taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam->pFuncIds); - taosMemoryFree(pCreateTbReq->stbCfg.pRSmaParam); - } - } else if (pCreateTbReq->type == TD_CHILD_TABLE) { - taosMemoryFree(pCreateTbReq->ctbCfg.pTag); - } else { - taosMemoryFree(pCreateTbReq->ntbCfg.pSchema); - if (pCreateTbReq->ntbCfg.pRSmaParam) { - taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam->pFuncIds); - taosMemoryFree(pCreateTbReq->ntbCfg.pRSmaParam); - } - } - } - - vTrace("vgId:%d process create %" PRIzu " tables", pVnode->vgId, taosArrayGetSize(vCreateTbBatchReq.pArray)); - taosArrayDestroy(vCreateTbBatchReq.pArray); - if (vCreateTbBatchRsp.rspList) { - int32_t contLen = tSerializeSVCreateTbBatchRsp(NULL, 0, &vCreateTbBatchRsp); - void *msg = rpcMallocCont(contLen); - tSerializeSVCreateTbBatchRsp(msg, contLen, &vCreateTbBatchRsp); - taosArrayDestroy(vCreateTbBatchRsp.rspList); - - *pRsp = taosMemoryCalloc(1, sizeof(SRpcMsg)); - (*pRsp)->msgType = TDMT_VND_CREATE_TABLE_RSP; - (*pRsp)->pCont = msg; - (*pRsp)->contLen = contLen; - (*pRsp)->handle = pMsg->handle; - (*pRsp)->ahandle = pMsg->ahandle; - } - break; - } - case TDMT_VND_ALTER_STB: { - SVCreateTbReq vAlterTbReq = {0}; - vTrace("vgId:%d, process alter stb req", pVnode->vgId); - tDeserializeSVCreateTbReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vAlterTbReq); - // TODO: to encapsule a free API - taosMemoryFree(vAlterTbReq.stbCfg.pSchema); - taosMemoryFree(vAlterTbReq.stbCfg.pTagSchema); - if (vAlterTbReq.stbCfg.pRSmaParam) { - taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam->pFuncIds); - taosMemoryFree(vAlterTbReq.stbCfg.pRSmaParam); - } - taosMemoryFree(vAlterTbReq.dbFName); - taosMemoryFree(vAlterTbReq.name); - break; - } - case TDMT_VND_DROP_STB: - vTrace("vgId:%d, process drop stb req", pVnode->vgId); - break; - case TDMT_VND_DROP_TABLE: - // if (metaDropTable(pVnode->pMeta, vReq.dtReq.uid) < 0) { - // // TODO: handle error - // } - break; - case TDMT_VND_SUBMIT: - /*printf("vnode %d write data %ld\n", pVnode->vgId, ver);*/ - if (pVnode->config.streamMode == 0) { - if (tsdbInsertData(pVnode->pTsdb, (SSubmitReq *)ptr, NULL) < 0) { - // TODO: handle error - } - } - break; - case TDMT_VND_MQ_SET_CONN: { - if (tqProcessSetConnReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { - // TODO: handle error - } - } break; - case TDMT_VND_MQ_REB: { - if (tqProcessRebReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { - } - } break; - case TDMT_VND_MQ_CANCEL_CONN: { - if (tqProcessCancelConnReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { - } - } break; - case TDMT_VND_TASK_DEPLOY: { - if (tqProcessTaskDeploy(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), - pMsg->contLen - sizeof(SMsgHead)) < 0) { - } - } break; - case TDMT_VND_TASK_WRITE_EXEC: { - if (tqProcessTaskExec(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), pMsg->contLen - sizeof(SMsgHead), - 0) < 0) { - } - } break; - case TDMT_VND_CREATE_SMA: { // timeRangeSMA -#if 0 - - SSmaCfg vCreateSmaReq = {0}; - if (tDeserializeSVCreateTSmaReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vCreateSmaReq) == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - vWarn("vgId:%d TDMT_VND_CREATE_SMA received but deserialize failed since %s", pVnode->config.vgId, - terrstr(terrno)); - return -1; - } - vDebug("vgId:%d TDMT_VND_CREATE_SMA msg received for %s:%" PRIi64, pVnode->config.vgId, - vCreateSmaReq.tSma.indexName, vCreateSmaReq.tSma.indexUid); - - // record current timezone of server side - vCreateSmaReq.tSma.timezoneInt = tsTimezone; - - if (metaCreateTSma(pVnode->pMeta, &vCreateSmaReq) < 0) { - // TODO: handle error - tdDestroyTSma(&vCreateSmaReq.tSma); - return -1; - } - - tsdbTSmaAdd(pVnode->pTsdb, 1); - - tdDestroyTSma(&vCreateSmaReq.tSma); - // TODO: return directly or go on follow steps? -#endif - if (tsdbCreateTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { - // TODO - } - // } break; - // case TDMT_VND_CANCEL_SMA: { // timeRangeSMA - // } break; - // case TDMT_VND_DROP_SMA: { // timeRangeSMA - // if (tsdbDropTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { - // // TODO - // } -#if 0 - tsdbTSmaSub(pVnode->pTsdb, 1); - SVDropTSmaReq vDropSmaReq = {0}; - if (tDeserializeSVDropTSmaReq(POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), &vDropSmaReq) == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - // TODO: send msg to stream computing to drop tSma - // if ((send msg to stream computing) < 0) { - // tdDestroyTSma(&vCreateSmaReq); - // return -1; - // } - // - - if (metaDropTSma(pVnode->pMeta, vDropSmaReq.indexUid) < 0) { - // TODO: handle error - return -1; - } - - if(tsdbDropTSmaData(pVnode->pTsdb, vDropSmaReq.indexUid) < 0) { - // TODO: handle error - return -1; - } - - // TODO: return directly or go on follow steps? -#endif - } break; - default: - ASSERT(0); - break; - } - - pVnode->state.applied = ver; - - // Check if it needs to commit - if (vnodeShouldCommit(pVnode)) { - // tsem_wait(&(pVnode->canCommit)); - if (vnodeAsyncCommit(pVnode) < 0) { - // TODO: handle error - } - } - - return 0; -} - /* ------------------------ STATIC METHODS ------------------------ */ diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index cb787e77a62c83e7c1670c09f43e0adc17cbfb07..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, @@ -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/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 afcffa3d286d3bcefbcac96b24a63911db567eea..14acff320418e68602a20842333c4865f55bffb6 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -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); } @@ -4507,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); @@ -4713,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) { @@ -5546,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) { @@ -5563,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 f7f1d470bbf1ccb7bd087929e6b1747dfc020ff9..0286b6e6e9803545720e9be7947a53e7e5134d3e 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; @@ -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,71 +679,70 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) { return NULL; } - int64_t startTs = taosGetTimestampUs(); + while (1) { + int64_t startTs = taosGetTimestampUs(); - _retry: - 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; + } + } - doFilterResult(pInfo); - if (pInfo->pRes->info.rows == 0) { - goto _retry; - } + SRetrieveMetaTableRsp* pTableRsp = pInfo->pRsp; + setSDataBlockFromFetchRsp(pInfo->pRes, &pInfo->loadInfo, pTableRsp->numOfRows, pTableRsp->data, + pTableRsp->compLen, pOperator->numOfOutput, startTs, NULL, pInfo->scanCols); - return pInfo->pRes; + // todo log the filter info + doFilterResult(pInfo); + if (pInfo->pRes->info.rows > 0) { + return pInfo->pRes; + } + } } - - return NULL; } SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataBlock* pResBlock, const SName* pName, @@ -772,24 +767,22 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB // TODO remove it int32_t tableType = 0; const char* name = tNameGetTableName(pName); - if (strncasecmp(name, TSDB_INS_TABLE_USER_DATABASES, tListLen(pName->tname)) == 0) { - tableType = TSDB_MGMT_TABLE_DB; - } else if (strncasecmp(name, TSDB_INS_TABLE_USER_USERS, tListLen(pName->tname)) == 0) { - tableType = TSDB_MGMT_TABLE_USER; - } else if (strncasecmp(name, TSDB_INS_TABLE_DNODES, tListLen(pName->tname)) == 0) { + if (strncasecmp(name, TSDB_INS_TABLE_DNODES, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_DNODE; - } else if (strncasecmp(name, TSDB_INS_TABLE_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) { tableType = TSDB_MGMT_TABLE_MODULE; } else if (strncasecmp(name, TSDB_INS_TABLE_QNODES, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_QNODE; - } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, tListLen(pName->tname)) == 0) { - tableType = TSDB_MGMT_TABLE_SNODE; } else if (strncasecmp(name, TSDB_INS_TABLE_BNODES, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_BNODE; + } else if (strncasecmp(name, TSDB_INS_TABLE_SNODES, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_SNODE; + } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_CLUSTER; + } else if (strncasecmp(name, TSDB_INS_TABLE_USER_DATABASES, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_DB; } else if (strncasecmp(name, TSDB_INS_TABLE_USER_FUNCTIONS, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_FUNC; } else if (strncasecmp(name, TSDB_INS_TABLE_USER_INDEXES, tListLen(pName->tname)) == 0) { @@ -800,13 +793,33 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB tableType = TSDB_MGMT_TABLE_STREAMS; } else if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLES, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_TABLE; - } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, tListLen(pName->tname)) == 0) { - tableType = TSDB_MGMT_TABLE_VGROUP; } else if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLE_DISTRIBUTED, tListLen(pName->tname)) == 0) { // tableType = TSDB_MGMT_TABLE_DIST; - } else if (strncasecmp(name, TSDB_INS_TABLE_CLUSTER, tListLen(pName->tname)) == 0) { - tableType = TSDB_MGMT_TABLE_CLUSTER; - } else { + } else if (strncasecmp(name, TSDB_INS_TABLE_USER_USERS, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_USER; + } else if (strncasecmp(name, TSDB_INS_TABLE_LICENCES, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_GRANTS; + } else if (strncasecmp(name, TSDB_INS_TABLE_VGROUPS, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_VGROUP; + } else if (strncasecmp(name, TSDB_INS_TABLE_TOPICS, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_TOPICS; + } else if (strncasecmp(name, TSDB_INS_TABLE_CONSUMERS, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_CONSUMERS; + } else if (strncasecmp(name, TSDB_INS_TABLE_SUBSCRIBES, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_SUBSCRIBES; + } else if (strncasecmp(name, TSDB_INS_TABLE_TRANS, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_TRANS; + } else if (strncasecmp(name, TSDB_INS_TABLE_SMAS, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_SMAS; + } else if (strncasecmp(name, TSDB_INS_TABLE_CONFIGS, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_CONFIGS; + } else if (strncasecmp(name, TSDB_INS_TABLE_CONNS, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_CONNS; + } else if (strncasecmp(name, TSDB_INS_TABLE_QUERIES, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_QUERIES; + } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, tListLen(pName->tname)) == 0) { + tableType = TSDB_MGMT_TABLE_VNODES; + }else { ASSERT(0); } 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 624a2953c935997c5c35708a21dbe223c29db62a..814076fc349d20579365e28660021d76f08d1d6e 100644 --- a/source/libs/function/inc/builtins.h +++ b/source/libs/function/inc/builtins.h @@ -40,14 +40,14 @@ extern "C" { #define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0) -typedef int32_t (*FCheckAndGetResultType)(SFunctionNode* pFunc); +typedef int32_t (*FTranslateFunc)(SFunctionNode* pFunc, char* pErrBuf, int32_t len); typedef EFuncDataRequired (*FFuncDataRequired)(SFunctionNode* pFunc, STimeWindow* pTimeWindow); typedef struct SBuiltinFuncDefinition { char name[FUNCTION_NAME_MAX_LENGTH]; EFunctionType type; uint64_t classification; - FCheckAndGetResultType checkFunc; + FTranslateFunc translateFunc; FFuncDataRequired dataRequiredFunc; FExecGetEnv getEnvFunc; FExecInit initFunc; diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 27067fc966288943aaf074f38ecf27a71b1a5be3..49504b2cd4af16b1052a2b10ae65f5603c125b07 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -19,14 +19,363 @@ #include "taoserror.h" #include "tdatablock.h" -int32_t checkAndGetResultType(SFunctionNode* pFunc); +static int32_t buildFuncErrMsg(char* pErrBuf, int32_t len, int32_t errCode, const char* pFormat, ...) { + va_list vArgList; + va_start(vArgList, pFormat); + vsnprintf(pErrBuf, len, pFormat, vArgList); + va_end(vArgList); + return errCode; +} + +static int32_t invaildFuncParaNumErrMsg(char* pErrBuf, int32_t len, const char* pFuncName) { + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_PARA_NUM, "Invalid number of arguments : %s", pFuncName); +} + +static int32_t invaildFuncParaTypeErrMsg(char* pErrBuf, int32_t len, const char* pFuncName) { + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_PARA_TYPE, "Inconsistent datatypes : %s", pFuncName); +} + +// There is only one parameter of numeric type, and the return type is parameter type +static int32_t translateInOutNum(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + if (!IS_NUMERIC_TYPE(paraType)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType }; + return TSDB_CODE_SUCCESS; +} + +// There is only one parameter of numeric type, and the return type is double type +static int32_t translateInNumOutDou(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + if (!IS_NUMERIC_TYPE(paraType)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + return TSDB_CODE_SUCCESS; +} + +// There are two parameters of numeric type, and the return type is double type +static int32_t translateIn2NumOutDou(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (2 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + if (!IS_NUMERIC_TYPE(para1Type) || !IS_NUMERIC_TYPE(para2Type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + return TSDB_CODE_SUCCESS; +} + +// There is only one parameter of string type, and the return type is parameter type +static int32_t translateInOutStr(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + SExprNode* pPara1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); + if (!IS_VAR_DATA_TYPE(pPara1->resType.type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = pPara1->resType.bytes, .type = pPara1->resType.type }; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateCount(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_BIGINT}; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateSum(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + if (!IS_NUMERIC_TYPE(paraType)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t resType = 0; + if (IS_SIGNED_NUMERIC_TYPE(paraType) || paraType == TSDB_DATA_TYPE_BOOL) { + resType = TSDB_DATA_TYPE_BIGINT; + } else if (IS_UNSIGNED_NUMERIC_TYPE(paraType)) { + resType = TSDB_DATA_TYPE_UBIGINT; + } else if (IS_FLOAT_TYPE(paraType)) { + resType = TSDB_DATA_TYPE_DOUBLE; + } + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[resType].bytes, .type = resType }; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateWduration(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + // pseudo column do not need to check parameters + pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_BIGINT}; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateTimePseudoColumn(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + // pseudo column do not need to check parameters + pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_TIMESTAMP}; + return TSDB_CODE_SUCCESS; +} + +static int32_t translatePercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (2 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + if (!IS_NUMERIC_TYPE(para1Type) || (!IS_SIGNED_NUMERIC_TYPE(para2Type) && !IS_UNSIGNED_NUMERIC_TYPE(para2Type))) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + return TSDB_CODE_SUCCESS; +} + +static bool validAperventileAlgo(const SValueNode* pVal) { + if (TSDB_DATA_TYPE_BINARY != pVal->node.resType.type) { + return false; + } + return (0 == strcasecmp(varDataVal(pVal->datum.p), "default") || 0 == strcasecmp(varDataVal(pVal->datum.p), "t-digest")); +} + +static int32_t translateApercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + int32_t paraNum = LIST_LENGTH(pFunc->pParameterList); + if (2 != paraNum && 3 != paraNum) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + if (!IS_NUMERIC_TYPE(para1Type) || !IS_INTEGER_TYPE(para2Type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + if (3 == paraNum) { + SNode* pPara3 = nodesListGetNode(pFunc->pParameterList, 2); + if (QUERY_NODE_VALUE != nodeType(pPara3) || !validAperventileAlgo((SValueNode*)pPara3)) { + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "Third parameter algorithm of apercentile must be 'default' or 't-digest'"); + } + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateTop(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + // todo + return TSDB_CODE_SUCCESS; +} + +static int32_t translateBottom(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + // todo + return TSDB_CODE_SUCCESS; +} + +static int32_t translateSpread(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + // todo + return TSDB_CODE_SUCCESS; +} + +static int32_t translateLastRow(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + // todo + return TSDB_CODE_SUCCESS; +} + +static int32_t translateFirstLast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + // first(*)/first(col_list) has been rewritten as first(col) + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0); + if (QUERY_NODE_COLUMN != nodeType(pPara)) { + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, "The parameters of first/last can only be columns"); + } + + uint8_t paraType = ((SExprNode*)pPara)->resType.type; + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType }; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateLength(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + if (!IS_VAR_DATA_TYPE(((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_SMALLINT].bytes, .type = TSDB_DATA_TYPE_SMALLINT }; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, int32_t minParaNum, int32_t maxParaNum, int32_t primaryParaNo) { + int32_t paraNum = LIST_LENGTH(pFunc->pParameterList); + if (paraNum < minParaNum || paraNum > maxParaNum) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t resultType = TSDB_DATA_TYPE_NCHAR; + int32_t resultBytes = 0; + int32_t sepBytes = 0; + for (int32_t i = 0; i < LIST_LENGTH(pFunc->pParameterList); ++i) { + SNode* pPara = nodesListGetNode(pFunc->pParameterList, i); + uint8_t paraType = ((SExprNode*)pPara)->resType.type; + int32_t paraBytes = ((SExprNode*)pPara)->resType.bytes; + if (!IS_VAR_DATA_TYPE(paraType)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + if (i < primaryParaNo) { + sepBytes = paraBytes; + continue; + } + if (TSDB_DATA_TYPE_BINARY == paraType) { + resultType = TSDB_DATA_TYPE_BINARY; + } + resultBytes += paraBytes; + } + if (sepBytes > 0) { + resultBytes += sepBytes * (paraNum - 2); + } + + pFunc->node.resType = (SDataType) { .bytes = resultBytes, .type = resultType }; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateConcat(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + return translateConcatImpl(pFunc, pErrBuf, len, 2, 8, 0); +} + +static int32_t translateConcatWs(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + return translateConcatImpl(pFunc, pErrBuf, len, 3, 9, 1); +} + +static int32_t translateSubstr(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + int32_t paraNum = LIST_LENGTH(pFunc->pParameterList); + if (2 != paraNum && 3 != paraNum) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + SExprNode* pPara1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); + uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + if (!IS_VAR_DATA_TYPE(pPara1->resType.type) || !IS_INTEGER_TYPE(para2Type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + if (3 == paraNum) { + uint8_t para3Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + if (!IS_INTEGER_TYPE(para3Type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + } + + pFunc->node.resType = (SDataType) { .bytes = pPara1->resType.bytes, .type = pPara1->resType.type }; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateCast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + // The number of parameters has been limited by the syntax definition + uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + // The function return type has been set during syntax parsing + uint8_t para2Type = pFunc->node.resType.type; + if ((TSDB_DATA_TYPE_JSON == para1Type || TSDB_DATA_TYPE_BLOB == para1Type || TSDB_DATA_TYPE_MEDIUMBLOB == para1Type) || + (TSDB_DATA_TYPE_JSON == para2Type || TSDB_DATA_TYPE_BLOB == para2Type || TSDB_DATA_TYPE_MEDIUMBLOB == para2Type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + return TSDB_CODE_SUCCESS; +} + +static int32_t translateToIso8601(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + if (!IS_VAR_DATA_TYPE(paraType) && TSDB_DATA_TYPE_TIMESTAMP != paraType) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = 64, .type = TSDB_DATA_TYPE_BINARY}; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateToUnixtimestamp(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (1 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + if (!IS_VAR_DATA_TYPE(((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + if (2 != LIST_LENGTH(pFunc->pParameterList)) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + if ((!IS_VAR_DATA_TYPE(para1Type) && TSDB_DATA_TYPE_TIMESTAMP != para1Type) || !IS_INTEGER_TYPE(para2Type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP}; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { + int32_t paraNum = LIST_LENGTH(pFunc->pParameterList); + if (2 != paraNum && 3 != paraNum) { + return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); + } + + uint8_t para1Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type; + uint8_t para2Type = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 1))->resType.type; + if ((!IS_VAR_DATA_TYPE(para1Type) && TSDB_DATA_TYPE_TIMESTAMP != para1Type) || + (!IS_VAR_DATA_TYPE(para2Type) && TSDB_DATA_TYPE_TIMESTAMP != para2Type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + if (3 == paraNum) { + if (!IS_INTEGER_TYPE(((SExprNode*)nodesListGetNode(pFunc->pParameterList, 2))->resType.type)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } + } + + pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT}; + return TSDB_CODE_SUCCESS; +} const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "count", .type = FUNCTION_TYPE_COUNT, .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED, - .checkFunc = checkAndGetResultType, + .translateFunc = translateCount, .dataRequiredFunc = countDataRequired, .getEnvFunc = getCountFuncEnv, .initFunc = functionSetup, @@ -37,7 +386,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "sum", .type = FUNCTION_TYPE_SUM, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateSum, .getEnvFunc = getSumFuncEnv, .initFunc = functionSetup, .processFunc = sumFunction, @@ -47,7 +396,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "min", .type = FUNCTION_TYPE_MIN, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInOutNum, .getEnvFunc = getMinmaxFuncEnv, .initFunc = minFunctionSetup, .processFunc = minFunction, @@ -57,7 +406,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "max", .type = FUNCTION_TYPE_MAX, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInOutNum, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -67,7 +416,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "stddev", .type = FUNCTION_TYPE_STDDEV, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInNumOutDou, .getEnvFunc = getStddevFuncEnv, .initFunc = stddevFunctionSetup, .processFunc = stddevFunction, @@ -77,7 +426,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "percentile", .type = FUNCTION_TYPE_PERCENTILE, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translatePercentile, .getEnvFunc = getPercentileFuncEnv, .initFunc = percentileFunctionSetup, .processFunc = percentileFunction, @@ -87,7 +436,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "apercentile", .type = FUNCTION_TYPE_APERCENTILE, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateApercentile, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -97,7 +446,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "top", .type = FUNCTION_TYPE_TOP, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateTop, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -107,7 +456,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "bottom", .type = FUNCTION_TYPE_BOTTOM, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateBottom, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -117,7 +466,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "spread", .type = FUNCTION_TYPE_SPREAD, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateSpread, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -127,7 +476,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "last_row", .type = FUNCTION_TYPE_LAST_ROW, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateLastRow, .getEnvFunc = getMinmaxFuncEnv, .initFunc = maxFunctionSetup, .processFunc = maxFunction, @@ -137,7 +486,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "first", .type = FUNCTION_TYPE_FIRST, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateFirstLast, .getEnvFunc = getFirstLastFuncEnv, .initFunc = functionSetup, .processFunc = firstFunction, @@ -147,7 +496,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "last", .type = FUNCTION_TYPE_LAST, .classification = FUNC_MGT_AGG_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateFirstLast, .getEnvFunc = getFirstLastFuncEnv, .initFunc = functionSetup, .processFunc = lastFunction, @@ -157,7 +506,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "diff", .type = FUNCTION_TYPE_DIFF, .classification = FUNC_MGT_NONSTANDARD_SQL_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInOutNum, .getEnvFunc = getDiffFuncEnv, .initFunc = diffFunctionSetup, .processFunc = diffFunction, @@ -167,7 +516,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "abs", .type = FUNCTION_TYPE_ABS, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInOutNum, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = absFunction, @@ -177,7 +526,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "log", .type = FUNCTION_TYPE_LOG, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateIn2NumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = logFunction, @@ -187,7 +536,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "pow", .type = FUNCTION_TYPE_POW, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateIn2NumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = powFunction, @@ -197,7 +546,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "sqrt", .type = FUNCTION_TYPE_SQRT, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInNumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = sqrtFunction, @@ -207,7 +556,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "ceil", .type = FUNCTION_TYPE_CEIL, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInOutNum, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = ceilFunction, @@ -217,7 +566,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "floor", .type = FUNCTION_TYPE_FLOOR, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInOutNum, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = floorFunction, @@ -227,7 +576,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "round", .type = FUNCTION_TYPE_ROUND, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInOutNum, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = roundFunction, @@ -237,7 +586,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "sin", .type = FUNCTION_TYPE_SIN, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInNumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = sinFunction, @@ -247,7 +596,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "cos", .type = FUNCTION_TYPE_COS, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInNumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = cosFunction, @@ -257,7 +606,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "tan", .type = FUNCTION_TYPE_TAN, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInNumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = tanFunction, @@ -267,7 +616,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "asin", .type = FUNCTION_TYPE_ASIN, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInNumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = asinFunction, @@ -277,7 +626,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "acos", .type = FUNCTION_TYPE_ACOS, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInNumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = acosFunction, @@ -287,7 +636,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "atan", .type = FUNCTION_TYPE_ATAN, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInNumOutDou, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = atanFunction, @@ -297,7 +646,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "length", .type = FUNCTION_TYPE_LENGTH, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateLength, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = lengthFunction, @@ -307,7 +656,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "char_length", .type = FUNCTION_TYPE_CHAR_LENGTH, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateLength, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = charLengthFunction, @@ -317,7 +666,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "concat", .type = FUNCTION_TYPE_CONCAT, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateConcat, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = concatFunction, @@ -327,7 +676,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "concat_ws", .type = FUNCTION_TYPE_CONCAT_WS, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateConcatWs, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = concatWsFunction, @@ -337,7 +686,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "lower", .type = FUNCTION_TYPE_LOWER, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInOutStr, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = lowerFunction, @@ -347,7 +696,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "upper", .type = FUNCTION_TYPE_UPPER, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInOutStr, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = upperFunction, @@ -357,7 +706,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "ltrim", .type = FUNCTION_TYPE_LTRIM, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInOutStr, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = ltrimFunction, @@ -367,7 +716,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "rtrim", .type = FUNCTION_TYPE_RTRIM, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateInOutStr, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = rtrimFunction, @@ -377,7 +726,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "substr", .type = FUNCTION_TYPE_SUBSTR, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateSubstr, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = substrFunction, @@ -387,7 +736,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "cast", .type = FUNCTION_TYPE_CAST, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateCast, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = castFunction, @@ -397,7 +746,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "to_iso8601", .type = FUNCTION_TYPE_TO_ISO8601, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateToIso8601, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = toISO8601Function, @@ -407,7 +756,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "to_unixtimestamp", .type = FUNCTION_TYPE_TO_UNIXTIMESTAMP, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateToUnixtimestamp, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = toUnixtimestampFunction, @@ -417,7 +766,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "timetruncate", .type = FUNCTION_TYPE_TIMETRUNCATE, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateTimeTruncate, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = timeTruncateFunction, @@ -427,7 +776,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "timediff", .type = FUNCTION_TYPE_TIMEDIFF, .classification = FUNC_MGT_SCALAR_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateTimeDiff, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = timeDiffFunction, @@ -437,7 +786,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_rowts", .type = FUNCTION_TYPE_ROWTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateTimePseudoColumn, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = NULL, @@ -447,7 +796,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "tbname", .type = FUNCTION_TYPE_TBNAME, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = NULL, .getEnvFunc = NULL, .initFunc = NULL, .sprocessFunc = NULL, @@ -457,7 +806,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_qstartts", .type = FUNCTION_TYPE_QSTARTTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateTimePseudoColumn, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = qStartTsFunction, @@ -467,7 +816,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_qendts", .type = FUNCTION_TYPE_QENDTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateTimePseudoColumn, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = qEndTsFunction, @@ -477,7 +826,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_wstartts", .type = FUNCTION_TYPE_WSTARTTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateTimePseudoColumn, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = winStartTsFunction, @@ -487,7 +836,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_wendts", .type = FUNCTION_TYPE_QENDTS, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateTimePseudoColumn, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = winEndTsFunction, @@ -497,7 +846,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "_wduration", .type = FUNCTION_TYPE_WDURATION, .classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateWduration, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = winDurFunction, @@ -507,7 +856,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .name = "now", .type = FUNCTION_TYPE_NOW, .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC, - .checkFunc = checkAndGetResultType, + .translateFunc = translateTimePseudoColumn, .getEnvFunc = getTimePseudoFuncEnv, .initFunc = NULL, .sprocessFunc = winDurFunction, @@ -516,167 +865,3 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { }; const int32_t funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition)); - -int32_t checkAndGetResultType(SFunctionNode* pFunc) { - switch(pFunc->funcType) { - case FUNCTION_TYPE_WDURATION: - case FUNCTION_TYPE_COUNT: { - pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_BIGINT}; - break; - } - - case FUNCTION_TYPE_SUM: { - SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0); - int32_t paraType = pParam->node.resType.type; - - int32_t resType = 0; - if (IS_SIGNED_NUMERIC_TYPE(paraType) || paraType == TSDB_DATA_TYPE_BOOL) { - resType = TSDB_DATA_TYPE_BIGINT; - } else if (IS_UNSIGNED_NUMERIC_TYPE(paraType)) { - resType = TSDB_DATA_TYPE_UBIGINT; - } else if (IS_FLOAT_TYPE(paraType)) { - resType = TSDB_DATA_TYPE_DOUBLE; - } else { - ASSERT(0); - } - - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[resType].bytes, .type = resType }; - break; - } - - case FUNCTION_TYPE_DIFF: - case FUNCTION_TYPE_FIRST: - case FUNCTION_TYPE_LAST: - case FUNCTION_TYPE_MIN: - case FUNCTION_TYPE_MAX: { - SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0); - int32_t paraType = pParam->node.resType.type; - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType }; - break; - } - - case FUNCTION_TYPE_ROWTS: - case FUNCTION_TYPE_QSTARTTS: - case FUNCTION_TYPE_QENDTS: - case FUNCTION_TYPE_WSTARTTS: - case FUNCTION_TYPE_WENDTS:{ - pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_TIMESTAMP}; - break; - } - - case FUNCTION_TYPE_ABS: - case FUNCTION_TYPE_CEIL: - case FUNCTION_TYPE_FLOOR: - case FUNCTION_TYPE_ROUND: { - SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0); - int32_t paraType = pParam->node.resType.type; - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType }; - break; - } - - case FUNCTION_TYPE_PERCENTILE: - case FUNCTION_TYPE_STDDEV: - case FUNCTION_TYPE_SIN: - case FUNCTION_TYPE_COS: - case FUNCTION_TYPE_TAN: - case FUNCTION_TYPE_ASIN: - case FUNCTION_TYPE_ACOS: - case FUNCTION_TYPE_ATAN: - case FUNCTION_TYPE_SQRT: - case FUNCTION_TYPE_LOG: - case FUNCTION_TYPE_POW: { - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE }; - break; - } - - case FUNCTION_TYPE_LENGTH: - case FUNCTION_TYPE_CHAR_LENGTH: { - pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_SMALLINT].bytes, .type = TSDB_DATA_TYPE_SMALLINT }; - break; - } - - case FUNCTION_TYPE_CONCAT: - case FUNCTION_TYPE_CONCAT_WS: { - int32_t paraType, paraBytes = 0; - bool typeSet = false; - for (int32_t i = 0; i < pFunc->pParameterList->length; ++i) { - SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, i); - if (pParam->node.type == QUERY_NODE_COLUMN) { - if (typeSet == false) { - paraType = pParam->node.resType.type; - typeSet = true; - } else { - //columns have to be the same type - if (paraType != pParam->node.resType.type) { - return TSDB_CODE_FAILED; - } - } - paraBytes += pParam->node.resType.bytes; - } - } - - for (int32_t i = 0; i < pFunc->pParameterList->length; ++i) { - SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, i); - if (pParam->node.type == QUERY_NODE_VALUE) { - if (paraType == TSDB_DATA_TYPE_NCHAR) { - paraBytes += pParam->node.resType.bytes * TSDB_NCHAR_SIZE; - } else { - paraBytes += pParam->node.resType.bytes; - } - } - } - pFunc->node.resType = (SDataType) { .bytes = paraBytes, .type = paraType }; - break; - } - case FUNCTION_TYPE_LOWER: - case FUNCTION_TYPE_UPPER: - case FUNCTION_TYPE_LTRIM: - case FUNCTION_TYPE_RTRIM: - case FUNCTION_TYPE_SUBSTR: { - SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0); - int32_t paraType = pParam->node.resType.type; - int32_t paraBytes = pParam->node.resType.bytes; - pFunc->node.resType = (SDataType) { .bytes = paraBytes, .type = paraType }; - break; - } - case FUNCTION_TYPE_CAST: { - //type - SValueNode* pParam = nodesListGetNode(pFunc->pParameterList, 1); - int32_t paraType = pParam->datum.i; - //bytes - pParam = nodesListGetNode(pFunc->pParameterList, 2); - int32_t paraBytes = pParam->datum.i; - pFunc->node.resType = (SDataType) { .bytes = paraBytes, .type = paraType}; - break; - } - 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: { - // todo - break; - } - - case FUNCTION_TYPE_NOW: - // todo - break; - default: - ASSERT(0); // to found the fault ASAP. - } - - return TSDB_CODE_SUCCESS; -} diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index ea9b3bdf18481dec906b170a7e52351aa3528034..aec75a0365ef42c8a23b021af4050d18fd6246c6 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -69,11 +69,11 @@ int32_t fmGetFuncInfo(const char* pFuncName, int32_t* pFuncId, int32_t* pFuncTyp return TSDB_CODE_SUCCESS; } -int32_t fmGetFuncResultType(SFunctionNode* pFunc) { +int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { if (pFunc->funcId < 0 || pFunc->funcId >= funcMgtBuiltinsNum) { return TSDB_CODE_FAILED; } - return funcMgtBuiltins[pFunc->funcId].checkFunc(pFunc); + return funcMgtBuiltins[pFunc->funcId].translateFunc(pFunc, pErrBuf, len); } EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) { diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 8ab76f57147471c9d987cce1e0c65f60fb219a49..ce74748c0c76b49aaef5ec69c0a828b6d7cb5c8d 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -132,30 +132,52 @@ const char* nodesNodeName(ENodeType type) { return "DropTopicStmt"; case QUERY_NODE_ALTER_LOCAL_STMT: return "AlterLocalStmt"; - case QUERY_NODE_SHOW_DATABASES_STMT: - return "ShowDatabaseStmt"; - case QUERY_NODE_SHOW_TABLES_STMT: - return "ShowTablesStmt"; - case QUERY_NODE_SHOW_STABLES_STMT: - return "ShowStablesStmt"; - case QUERY_NODE_SHOW_USERS_STMT: - return "ShowUsersStmt"; case QUERY_NODE_SHOW_DNODES_STMT: return "ShowDnodesStmt"; - case QUERY_NODE_SHOW_VGROUPS_STMT: - return "ShowVgroupsStmt"; case QUERY_NODE_SHOW_MNODES_STMT: return "ShowMnodesStmt"; case QUERY_NODE_SHOW_MODULES_STMT: return "ShowModulesStmt"; case QUERY_NODE_SHOW_QNODES_STMT: return "ShowQnodesStmt"; + case QUERY_NODE_SHOW_SNODES_STMT: + return "ShowSnodesStmt"; + case QUERY_NODE_SHOW_BNODES_STMT: + return "ShowBnodesStmt"; + case QUERY_NODE_SHOW_DATABASES_STMT: + return "ShowDatabaseStmt"; case QUERY_NODE_SHOW_FUNCTIONS_STMT: return "ShowFunctionsStmt"; case QUERY_NODE_SHOW_INDEXES_STMT: return "ShowIndexesStmt"; + case QUERY_NODE_SHOW_STABLES_STMT: + return "ShowStablesStmt"; case QUERY_NODE_SHOW_STREAMS_STMT: return "ShowStreamsStmt"; + case QUERY_NODE_SHOW_TABLES_STMT: + return "ShowTablesStmt"; + case QUERY_NODE_SHOW_USERS_STMT: + return "ShowUsersStmt"; + case QUERY_NODE_SHOW_LICENCE_STMT: + return "ShowGrantsStmt"; + case QUERY_NODE_SHOW_VGROUPS_STMT: + return "ShowVgroupsStmt"; + case QUERY_NODE_SHOW_TOPICS_STMT: + return "ShowTopicsStmt"; + case QUERY_NODE_SHOW_CONSUMERS_STMT: + return "ShowConsumersStmt"; + case QUERY_NODE_SHOW_SUBSCRIBES_STMT: + return "ShowSubscribesStmt"; + case QUERY_NODE_SHOW_TRANS_STMT: + return "ShowTransStmt"; + case QUERY_NODE_SHOW_SMAS_STMT: + return "ShowSmasStmt"; + case QUERY_NODE_SHOW_CONFIGS_STMT: + return "ShowConfigsStmt"; + case QUERY_NODE_SHOW_QUERIES_STMT: + return "ShowQueriesStmt"; + case QUERY_NODE_SHOW_VNODES_STMT: + return "ShowVnodeStmt"; case QUERY_NODE_LOGIC_PLAN_SCAN: return "LogicScan"; case QUERY_NODE_LOGIC_PLAN_JOIN: diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 772aa71eb2d781840ea363e6dca84aaeabb6210c..8731b26c4a15900a862390b9ab37d3d90e81f34f 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -146,30 +146,29 @@ SNodeptr nodesMakeNode(ENodeType type) { return makeNode(type, sizeof(SDescribeStmt)); case QUERY_NODE_RESET_QUERY_CACHE_STMT: return makeNode(type, sizeof(SNode)); - case QUERY_NODE_SHOW_DATABASES_STMT: - case QUERY_NODE_SHOW_TABLES_STMT: - case QUERY_NODE_SHOW_STABLES_STMT: - case QUERY_NODE_SHOW_USERS_STMT: case QUERY_NODE_SHOW_DNODES_STMT: - case QUERY_NODE_SHOW_VGROUPS_STMT: case QUERY_NODE_SHOW_MNODES_STMT: case QUERY_NODE_SHOW_MODULES_STMT: case QUERY_NODE_SHOW_QNODES_STMT: + case QUERY_NODE_SHOW_SNODES_STMT: + case QUERY_NODE_SHOW_BNODES_STMT: + case QUERY_NODE_SHOW_DATABASES_STMT: case QUERY_NODE_SHOW_FUNCTIONS_STMT: case QUERY_NODE_SHOW_INDEXES_STMT: + case QUERY_NODE_SHOW_STABLES_STMT: case QUERY_NODE_SHOW_STREAMS_STMT: - case QUERY_NODE_SHOW_APPS_STMT: - case QUERY_NODE_SHOW_CONNECTIONS_STMT: + case QUERY_NODE_SHOW_TABLES_STMT: + case QUERY_NODE_SHOW_USERS_STMT: case QUERY_NODE_SHOW_LICENCE_STMT: - case QUERY_NODE_SHOW_CREATE_DATABASE_STMT: - case QUERY_NODE_SHOW_CREATE_TABLE_STMT: - case QUERY_NODE_SHOW_CREATE_STABLE_STMT: - case QUERY_NODE_SHOW_QUERIES_STMT: - case QUERY_NODE_SHOW_SCORES_STMT: + case QUERY_NODE_SHOW_VGROUPS_STMT: case QUERY_NODE_SHOW_TOPICS_STMT: - case QUERY_NODE_SHOW_VARIABLE_STMT: - case QUERY_NODE_SHOW_BNODES_STMT: - case QUERY_NODE_SHOW_SNODES_STMT: + case QUERY_NODE_SHOW_CONSUMERS_STMT: + case QUERY_NODE_SHOW_SUBSCRIBES_STMT: + case QUERY_NODE_SHOW_TRANS_STMT: + case QUERY_NODE_SHOW_SMAS_STMT: + case QUERY_NODE_SHOW_CONFIGS_STMT: + case QUERY_NODE_SHOW_QUERIES_STMT: + case QUERY_NODE_SHOW_VNODES_STMT: return makeNode(type, sizeof(SShowStmt)); case QUERY_NODE_LOGIC_PLAN_SCAN: return makeNode(type, sizeof(SScanLogicNode)); diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index e78101421629d1ea9f9ef0ee521c737bb5840d4c..1fa3a186682d60d617c086efe978c07806307353 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -81,7 +81,6 @@ SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode); SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode); SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode); -SNodeList* addValueNodeFromTypeToList(SAstCreateContext* pCxt, SDataType dataType, SNodeList* pList); SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pColumnName); SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral); @@ -93,6 +92,7 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight); SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight); SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList); +SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt); SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList); SNode* createNodeListNodeEx(SAstCreateContext* pCxt, SNode* p1, SNode* p2); SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTableName, SToken* pTableAlias); diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 12ae5819b47d509e07fc59b6fd98a9d719eca40f..3c3cea8ea34765e0af0166e710f556ccfe085b04 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -535,13 +535,7 @@ expression(A) ::= pseudo_column(B). expression(A) ::= column_reference(B). { A = B; } expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); } expression(A) ::= function_name(B) NK_LP NK_STAR(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, createNodeList(pCxt, createColumnNode(pCxt, NULL, &C)))); } -//for CAST function CAST(expr AS type_name) -expression(A) ::= function_name(B) NK_LP expression(C) AS type_name(D) NK_RP(E). { - SNodeList *p = createNodeList(pCxt, releaseRawExprNode(pCxt, C)); - p = addValueNodeFromTypeToList(pCxt, D, p); - A = createRawExprNodeExt(pCxt, &B, &E, createFunctionNode(pCxt, &B, p)); - } -//expression(A) ::= cast_expression(B). { A = B; } +expression(A) ::= CAST(B) NK_LP expression(C) AS type_name(D) NK_RP(E). { A = createRawExprNodeExt(pCxt, &B, &E, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, C), D)); } //expression(A) ::= case_expression(B). { A = B; } expression(A) ::= subquery(B). { A = B; } expression(A) ::= NK_LP(B) expression(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, releaseRawExprNode(pCxt, C)); } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 4d09dfee192b90d8a8a45478c81b2a3b9a4ef120..accf99606a0bc5229f82b639bf7bd61a2f6cc9fb 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -208,7 +208,9 @@ SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) { SRawExprNode* pRawExpr = (SRawExprNode*)pNode; SNode* pExpr = pRawExpr->pNode; if (nodesIsExprNode(pExpr)) { - strncpy(((SExprNode*)pExpr)->aliasName, pRawExpr->p, pRawExpr->n); + int32_t len = TMIN(sizeof(((SExprNode*)pExpr)->aliasName) - 1, pRawExpr->n); + strncpy(((SExprNode*)pExpr)->aliasName, pRawExpr->p, len); + ((SExprNode*)pExpr)->aliasName[len] = '\0'; } taosMemoryFreeClear(pNode); return pExpr; @@ -253,33 +255,6 @@ SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pC return (SNode*)col; } -SNodeList* addValueNodeFromTypeToList(SAstCreateContext* pCxt, SDataType dataType, SNodeList* pList) { - char buf[64] = {0}; - //add value node for type - snprintf(buf, sizeof(buf), "%u", dataType.type); - SToken token = {.type = TSDB_DATA_TYPE_SMALLINT, .n = strlen(buf), .z = buf}; - SNode* pNode = createValueNode(pCxt, token.type, &token); - addNodeToList(pCxt, pList, pNode); - - //add value node for bytes - memset(buf, 0, sizeof(buf)); - int32_t bytes; - if (IS_VAR_DATA_TYPE(dataType.type)) { - bytes = (dataType.type == TSDB_DATA_TYPE_NCHAR) ? dataType.bytes * TSDB_NCHAR_SIZE : dataType.bytes; - bytes += VARSTR_HEADER_SIZE; - } else { - bytes = dataType.bytes; - } - snprintf(buf, sizeof(buf), "%d", bytes); - token.type = TSDB_DATA_TYPE_BIGINT; - token.n = strlen(buf); - token.z = buf; - pNode = createValueNode(pCxt, token.type, &token); - addNodeToList(pCxt, pList, pNode); - - return pList; -} - SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral) { SValueNode* val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); CHECK_OUT_OF_MEM(val); @@ -385,6 +360,15 @@ SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNod return (SNode*)func; } +SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt) { + SFunctionNode* func = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION); + CHECK_OUT_OF_MEM(func); + strcpy(func->functionName, "cast"); + func->node.resType = dt; + nodesListMakeAppend(&func->pParameterList, pExpr); + return (SNode*)func; +} + SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList) { SNodeListNode* list = (SNodeListNode*)nodesMakeNode(QUERY_NODE_NODE_LIST); CHECK_OUT_OF_MEM(list); @@ -927,18 +911,6 @@ SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, S return (SNode*)pStmt; } -SNode* createShowCreateDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName) { - SNode* pStmt = nodesMakeNode(QUERY_NODE_SHOW_CREATE_DATABASE_STMT); - CHECK_OUT_OF_MEM(pStmt); - return pStmt; -} - -SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable) { - SNode* pStmt = nodesMakeNode(type); - CHECK_OUT_OF_MEM(pStmt); - return pStmt; -} - SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword) { char password[TSDB_USET_PASSWORD_LEN] = {0}; if (!checkUserName(pCxt, pUserName) || !checkPassword(pCxt, pPassword, password)) { diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 7919fcedd1f12c827644625b102573f6041fdd09..250c6c2fd19c682cd92bc3545a27d2cc841a84fb 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -415,7 +415,6 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { pVal->datum.d = strtold(pVal->literal, &endPtr); break; } - case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_VARCHAR: case TSDB_DATA_TYPE_VARBINARY: { pVal->datum.p = taosMemoryCalloc(1, pVal->node.resType.bytes + VARSTR_HEADER_SIZE + 1); @@ -433,6 +432,7 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) { } break; } + case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_JSON: case TSDB_DATA_TYPE_DECIMAL: case TSDB_DATA_TYPE_BLOB: @@ -485,9 +485,9 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc) if (TSDB_CODE_SUCCESS != fmGetFuncInfo(pFunc->functionName, &pFunc->funcId, &pFunc->funcType)) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_FUNTION, pFunc->functionName); } - int32_t code = fmGetFuncResultType(pFunc); - if (TSDB_CODE_SUCCESS != code) { - return generateDealNodeErrMsg(pCxt, code, pFunc->functionName); + pCxt->errCode = fmGetFuncResultType(pFunc, pCxt->msgBuf.buf, pCxt->msgBuf.len); + if (TSDB_CODE_SUCCESS != pCxt->errCode) { + return DEAL_RES_ERROR; } if (fmIsAggFunc(pFunc->funcId) && beforeHaving(pCxt->currClause)) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION); @@ -1366,6 +1366,25 @@ static int32_t checkCreateDatabase(STranslateContext* pCxt, SCreateDatabaseStmt* return checkDatabaseOptions(pCxt, pStmt->pOptions); } +typedef int32_t (*FSerializeFunc)(void *pBuf, int32_t bufLen, void *pReq); + +static int32_t buildCmdMsg(STranslateContext* pCxt, int16_t msgType, FSerializeFunc func, void* pReq) { + pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); + if (NULL == pCxt->pCmdMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; + pCxt->pCmdMsg->msgType = msgType; + pCxt->pCmdMsg->msgLen = func(NULL, 0, pReq); + pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); + if (NULL == pCxt->pCmdMsg->pMsg) { + return TSDB_CODE_OUT_OF_MEMORY; + } + func(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, pReq); + + return TSDB_CODE_SUCCESS; +} + static int32_t translateCreateDatabase(STranslateContext* pCxt, SCreateDatabaseStmt* pStmt) { SCreateDbReq createReq = {0}; @@ -1375,18 +1394,7 @@ static int32_t translateCreateDatabase(STranslateContext* pCxt, SCreateDatabaseS } if (TSDB_CODE_SUCCESS == code) { - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_DB; - pCxt->pCmdMsg->msgLen = tSerializeSCreateDbReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSCreateDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); + code = buildCmdMsg(pCxt, TDMT_MND_CREATE_DB, (FSerializeFunc)tSerializeSCreateDbReq, &createReq); } return code; @@ -1394,25 +1402,12 @@ static int32_t translateCreateDatabase(STranslateContext* pCxt, SCreateDatabaseS static int32_t translateDropDatabase(STranslateContext* pCxt, SDropDatabaseStmt* pStmt) { SDropDbReq dropReq = {0}; - SName name = {0}; + SName name = {0}; tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); tNameGetFullDbName(&name, dropReq.db); dropReq.ignoreNotExists = pStmt->ignoreNotExists; - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_DROP_DB; - pCxt->pCmdMsg->msgLen = tSerializeSDropDbReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSDropDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_DROP_DB, (FSerializeFunc)tSerializeSDropDbReq, &dropReq); } static void buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt, SAlterDbReq* pReq) { @@ -1440,20 +1435,7 @@ static int32_t translateAlterDatabase(STranslateContext* pCxt, SAlterDatabaseStm SAlterDbReq alterReq = {0}; buildAlterDbReq(pCxt, pStmt, &alterReq); - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_ALTER_DB; - pCxt->pCmdMsg->msgLen = tSerializeSAlterDbReq(NULL, 0, &alterReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSAlterDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &alterReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_ALTER_DB, (FSerializeFunc)tSerializeSAlterDbReq, &alterReq); } static int32_t calcTypeBytes(SDataType dt) { @@ -1615,23 +1597,9 @@ static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableSt strcpy(tableName.tname, pStmt->tableName); tNameExtractFullName(&tableName, createReq.name); - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - tFreeSMCreateStbReq(&createReq); - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_STB; - pCxt->pCmdMsg->msgLen = tSerializeSMCreateStbReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - tFreeSMCreateStbReq(&createReq); - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSMCreateStbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); - + code = buildCmdMsg(pCxt, TDMT_MND_CREATE_STB, (FSerializeFunc)tSerializeSMCreateStbReq, &createReq); tFreeSMCreateStbReq(&createReq); - return TSDB_CODE_SUCCESS; + return code; } static int32_t doTranslateDropSuperTable(STranslateContext* pCxt, const SName* pTableName, bool ignoreNotExists) { @@ -1639,20 +1607,7 @@ static int32_t doTranslateDropSuperTable(STranslateContext* pCxt, const SName* p tNameExtractFullName(pTableName, dropReq.name); dropReq.igNotExists = ignoreNotExists; - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_DROP_STB; - pCxt->pCmdMsg->msgLen = tSerializeSMDropStbReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSMDropStbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_DROP_STB, (FSerializeFunc)tSerializeSMDropStbReq, &dropReq); } static int32_t translateDropTable(STranslateContext* pCxt, SDropTableStmt* pStmt) { @@ -1736,20 +1691,7 @@ static int32_t translateAlterTable(STranslateContext* pCxt, SAlterTableStmt* pSt } } - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_ALTER_STB; - pCxt->pCmdMsg->msgLen = tSerializeSMAlterStbReq(NULL, 0, &alterReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSMAlterStbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &alterReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_ALTER_STB, (FSerializeFunc)tSerializeSMAlterStbReq, &alterReq); } static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* pStmt) { @@ -1758,24 +1700,10 @@ static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* p tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); tNameExtractFullName(&name, usedbReq.db); int32_t code = getDBVgVersion(pCxt, usedbReq.db, &usedbReq.vgVersion, &usedbReq.dbId, &usedbReq.numOfTable); - if (TSDB_CODE_SUCCESS != code) { - return code; - } - - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_USE_DB; - pCxt->pCmdMsg->msgLen = tSerializeSUseDbReq(NULL, 0, &usedbReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; + if (TSDB_CODE_SUCCESS == code) { + code = buildCmdMsg(pCxt, TDMT_MND_USE_DB, (FSerializeFunc)tSerializeSUseDbReq, &usedbReq); } - tSerializeSUseDbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &usedbReq); - - return TSDB_CODE_SUCCESS; + return code; } static int32_t translateCreateUser(STranslateContext* pCxt, SCreateUserStmt* pStmt) { @@ -1785,20 +1713,7 @@ static int32_t translateCreateUser(STranslateContext* pCxt, SCreateUserStmt* pSt createReq.superUser = 0; strcpy(createReq.pass, pStmt->password); - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_USER; - pCxt->pCmdMsg->msgLen = tSerializeSCreateUserReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSCreateUserReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_CREATE_USER, (FSerializeFunc)tSerializeSCreateUserReq, &createReq); } static int32_t translateAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt) { @@ -1811,40 +1726,14 @@ static int32_t translateAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt strcpy(alterReq.dbname, pCxt->pParseCxt->db); } - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_ALTER_USER; - pCxt->pCmdMsg->msgLen = tSerializeSAlterUserReq(NULL, 0, &alterReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSAlterUserReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &alterReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_ALTER_USER, (FSerializeFunc)tSerializeSAlterUserReq, &alterReq); } static int32_t translateDropUser(STranslateContext* pCxt, SDropUserStmt* pStmt) { SDropUserReq dropReq = {0}; strcpy(dropReq.user, pStmt->useName); - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_DROP_USER; - pCxt->pCmdMsg->msgLen = tSerializeSDropUserReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSDropUserReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_DROP_USER, (FSerializeFunc)tSerializeSDropUserReq, &dropReq); } static int32_t translateCreateDnode(STranslateContext* pCxt, SCreateDnodeStmt* pStmt) { @@ -1852,20 +1741,7 @@ static int32_t translateCreateDnode(STranslateContext* pCxt, SCreateDnodeStmt* p strcpy(createReq.fqdn, pStmt->fqdn); createReq.port = pStmt->port; - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_DNODE; - pCxt->pCmdMsg->msgLen = tSerializeSCreateDnodeReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSCreateDnodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_CREATE_DNODE, (FSerializeFunc)tSerializeSCreateDnodeReq, &createReq); } static int32_t translateDropDnode(STranslateContext* pCxt, SDropDnodeStmt* pStmt) { @@ -1874,20 +1750,7 @@ static int32_t translateDropDnode(STranslateContext* pCxt, SDropDnodeStmt* pStmt strcpy(dropReq.fqdn, pStmt->fqdn); dropReq.port = pStmt->port; - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_DROP_DNODE; - pCxt->pCmdMsg->msgLen = tSerializeSDropDnodeReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSDropDnodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_DROP_DNODE, (FSerializeFunc)tSerializeSDropDnodeReq, &dropReq); } static int32_t translateAlterDnode(STranslateContext* pCxt, SAlterDnodeStmt* pStmt) { @@ -1896,61 +1759,30 @@ static int32_t translateAlterDnode(STranslateContext* pCxt, SAlterDnodeStmt* pSt strcpy(cfgReq.config, pStmt->config); strcpy(cfgReq.value, pStmt->value); - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CONFIG_DNODE; - pCxt->pCmdMsg->msgLen = tSerializeSMCfgDnodeReq(NULL, 0, &cfgReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSMCfgDnodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &cfgReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_CONFIG_DNODE, (FSerializeFunc)tSerializeSMCfgDnodeReq, &cfgReq); } static int32_t nodeTypeToShowType(ENodeType nt) { - switch (nt) { - case QUERY_NODE_SHOW_APPS_STMT: - return 0; // todo - case QUERY_NODE_SHOW_CONNECTIONS_STMT: - return TSDB_MGMT_TABLE_CONNS; - case QUERY_NODE_SHOW_LICENCE_STMT: - return TSDB_MGMT_TABLE_GRANTS; - case QUERY_NODE_SHOW_QUERIES_STMT: - return TSDB_MGMT_TABLE_QUERIES; - case QUERY_NODE_SHOW_SCORES_STMT: - return 0; // todo - case QUERY_NODE_SHOW_TOPICS_STMT: - return 0; // todo - case QUERY_NODE_SHOW_VARIABLE_STMT: - return TSDB_MGMT_TABLE_VARIABLES; - default: - break; - } + // switch (nt) { + // case QUERY_NODE_SHOW_CONNECTIONS_STMT: + // return TSDB_MGMT_TABLE_CONNS; + // case QUERY_NODE_SHOW_LICENCE_STMT: + // return TSDB_MGMT_TABLE_GRANTS; + // case QUERY_NODE_SHOW_QUERIES_STMT: + // return TSDB_MGMT_TABLE_QUERIES; + // case QUERY_NODE_SHOW_TOPICS_STMT: + // return 0; // todo + // case QUERY_NODE_SHOW_VARIABLE_STMT: + // return TSDB_MGMT_TABLE_VARIABLES; + // default: + // break; + // } return 0; } static int32_t translateShow(STranslateContext* pCxt, SShowStmt* pStmt) { SShowReq showReq = {.type = nodeTypeToShowType(nodeType(pStmt))}; - - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_SHOW; - pCxt->pCmdMsg->msgLen = tSerializeSShowReq(NULL, 0, &showReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSShowReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &showReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_SHOW, (FSerializeFunc)tSerializeSShowReq, &showReq); } static int32_t getSmaIndexDstVgId(STranslateContext* pCxt, char* pTableName, int32_t* pVgId) { @@ -2070,61 +1902,25 @@ static int32_t translateCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt } SMCreateSmaReq createSmaReq = {0}; - int32_t code = buildCreateSmaReq(pCxt, pStmt, &createSmaReq); - if (TSDB_CODE_SUCCESS != code) { - return code; - } - - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_SMA; - pCxt->pCmdMsg->msgLen = tSerializeSMCreateSmaReq(NULL, 0, &createSmaReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; + if (TSDB_CODE_SUCCESS == code) { + code = buildCmdMsg(pCxt, TDMT_MND_CREATE_SMA, (FSerializeFunc)tSerializeSMCreateSmaReq, &createSmaReq); } - tSerializeSMCreateSmaReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createSmaReq); tFreeSMCreateSmaReq(&createSmaReq); - - return TSDB_CODE_SUCCESS; + return code; } static int32_t buildCreateFullTextReq(STranslateContext* pCxt, SCreateIndexStmt* pStmt, SMCreateFullTextReq* pReq) { // impl later return 0; } static int32_t translateCreateFullTextIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt) { - if (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pInterval) || - (NULL != pStmt->pOptions->pOffset && - DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pOffset)) || - (NULL != pStmt->pOptions->pSliding && - DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pSliding))) { - return pCxt->errCode; - } SMCreateFullTextReq createFTReq = {0}; - int32_t code = buildCreateFullTextReq(pCxt, pStmt, &createFTReq); - if (TSDB_CODE_SUCCESS != code) { - return code; - } - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_INDEX; - pCxt->pCmdMsg->msgLen = tSerializeSMCreateFullTextReq(NULL, 0, &createFTReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; + if (TSDB_CODE_SUCCESS == code) { + code = buildCmdMsg(pCxt, TDMT_MND_CREATE_INDEX, (FSerializeFunc)tSerializeSMCreateFullTextReq, &createFTReq); } - tSerializeSMCreateFullTextReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createFTReq); tFreeSMCreateFullTextReq(&createFTReq); - - return TSDB_CODE_SUCCESS; + return code; } static int32_t translateCreateIndex(STranslateContext* pCxt, SCreateIndexStmt* pStmt) { @@ -2132,7 +1928,6 @@ static int32_t translateCreateIndex(STranslateContext* pCxt, SCreateIndexStmt* p return translateCreateSmaIndex(pCxt, pStmt); } else if (INDEX_TYPE_FULLTEXT == pStmt->indexType) { return translateCreateFullTextIndex(pCxt, pStmt); - // todo fulltext index } return TSDB_CODE_FAILED; } @@ -2176,21 +1971,7 @@ static int16_t getCreateComponentNodeMsgType(ENodeType type) { static int32_t translateCreateComponentNode(STranslateContext* pCxt, SCreateComponentNodeStmt* pStmt) { SMCreateQnodeReq createReq = {.dnodeId = pStmt->dnodeId}; - - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = getCreateComponentNodeMsgType(nodeType(pStmt)); - pCxt->pCmdMsg->msgLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSCreateDropMQSBNodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, getCreateComponentNodeMsgType(nodeType(pStmt)), (FSerializeFunc)tSerializeSCreateDropMQSBNodeReq, &createReq); } static int16_t getDropComponentNodeMsgType(ENodeType type) { @@ -2211,21 +1992,7 @@ static int16_t getDropComponentNodeMsgType(ENodeType type) { static int32_t translateDropComponentNode(STranslateContext* pCxt, SDropComponentNodeStmt* pStmt) { SDDropQnodeReq dropReq = {.dnodeId = pStmt->dnodeId}; - - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = getDropComponentNodeMsgType(nodeType(pStmt)); - pCxt->pCmdMsg->msgLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSCreateDropMQSBNodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, getDropComponentNodeMsgType(nodeType(pStmt)), (FSerializeFunc)tSerializeSCreateDropMQSBNodeReq, &dropReq); } static int32_t translateCreateTopic(STranslateContext* pCxt, SCreateTopicStmt* pStmt) { @@ -2255,21 +2022,9 @@ static int32_t translateCreateTopic(STranslateContext* pCxt, SCreateTopicStmt* p tNameExtractFullName(&name, createReq.name); createReq.igExists = pStmt->ignoreExists; - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_CREATE_TOPIC; - pCxt->pCmdMsg->msgLen = tSerializeSCMCreateTopicReq(NULL, 0, &createReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSCMCreateTopicReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &createReq); + int32_t code = buildCmdMsg(pCxt, TDMT_MND_CREATE_TOPIC, (FSerializeFunc)tSerializeSCMCreateTopicReq, &createReq); tFreeSCMCreateTopicReq(&createReq); - - return TSDB_CODE_SUCCESS; + return code; } static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt) { @@ -2281,20 +2036,7 @@ static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt tNameExtractFullName(&name, dropReq.name); dropReq.igNotExists = pStmt->ignoreNotExists; - pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); - if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; - pCxt->pCmdMsg->msgType = TDMT_MND_DROP_TOPIC; - pCxt->pCmdMsg->msgLen = tSerializeSMDropTopicReq(NULL, 0, &dropReq); - pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); - if (NULL == pCxt->pCmdMsg->pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; - } - tSerializeSMDropTopicReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq); - - return TSDB_CODE_SUCCESS; + return buildCmdMsg(pCxt, TDMT_MND_DROP_TOPIC, (FSerializeFunc)tSerializeSMDropTopicReq, &dropReq); } static int32_t translateAlterLocal(STranslateContext* pCxt, SAlterLocalStmt* pStmt) { @@ -2313,6 +2055,19 @@ static int32_t translateDescribe(STranslateContext* pCxt, SDescribeStmt* pStmt) return getTableMeta(pCxt, pStmt->dbName, pStmt->tableName, &pStmt->pMeta); } +static int32_t translateKillConnection(STranslateContext* pCxt, SKillStmt* pStmt) { + SKillConnReq killReq = {0}; + killReq.connId = pStmt->targetId; + return buildCmdMsg(pCxt, TDMT_MND_KILL_CONN, (FSerializeFunc)tSerializeSKillQueryReq, &killReq); +} + +static int32_t translateKillQuery(STranslateContext* pCxt, SKillStmt* pStmt) { + SKillQueryReq killReq = {0}; + killReq.queryId = pStmt->targetId; + return buildCmdMsg(pCxt, TDMT_MND_KILL_QUERY, (FSerializeFunc)tSerializeSKillQueryReq, &killReq); +} + + static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { int32_t code = TSDB_CODE_SUCCESS; switch (nodeType(pNode)) { @@ -2361,19 +2116,11 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_ALTER_DNODE_STMT: code = translateAlterDnode(pCxt, (SAlterDnodeStmt*)pNode); break; - case QUERY_NODE_SHOW_APPS_STMT: case QUERY_NODE_SHOW_CONNECTIONS_STMT: case QUERY_NODE_SHOW_QUERIES_STMT: - case QUERY_NODE_SHOW_SCORES_STMT: case QUERY_NODE_SHOW_TOPICS_STMT: - case QUERY_NODE_SHOW_VARIABLE_STMT: code = translateShow(pCxt, (SShowStmt*)pNode); break; - case QUERY_NODE_SHOW_CREATE_DATABASE_STMT: - case QUERY_NODE_SHOW_CREATE_TABLE_STMT: - case QUERY_NODE_SHOW_CREATE_STABLE_STMT: - // todo - break; case QUERY_NODE_CREATE_INDEX_STMT: code = translateCreateIndex(pCxt, (SCreateIndexStmt*)pNode); break; @@ -2407,6 +2154,12 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_DESCRIBE_STMT: code = translateDescribe(pCxt, (SDescribeStmt*)pNode); break; + case QUERY_NODE_KILL_CONNECTION_STMT: + code = translateKillConnection(pCxt, (SKillStmt*)pNode); + break; + case QUERY_NODE_KILL_QUERY_STMT: + code = translateKillQuery(pCxt, (SKillStmt*)pNode); + break; default: break; } @@ -2520,6 +2273,33 @@ static void destroyTranslateContext(STranslateContext* pCxt) { taosHashCleanup(pCxt->pTables); } +static const char* getSysDbName(ENodeType type) { + switch (type) { + case QUERY_NODE_SHOW_DATABASES_STMT: + case QUERY_NODE_SHOW_TABLES_STMT: + case QUERY_NODE_SHOW_STABLES_STMT: + case QUERY_NODE_SHOW_USERS_STMT: + case QUERY_NODE_SHOW_DNODES_STMT: + case QUERY_NODE_SHOW_VGROUPS_STMT: + case QUERY_NODE_SHOW_MNODES_STMT: + case QUERY_NODE_SHOW_MODULES_STMT: + case QUERY_NODE_SHOW_QNODES_STMT: + case QUERY_NODE_SHOW_FUNCTIONS_STMT: + case QUERY_NODE_SHOW_INDEXES_STMT: + case QUERY_NODE_SHOW_STREAMS_STMT: + case QUERY_NODE_SHOW_BNODES_STMT: + case QUERY_NODE_SHOW_SNODES_STMT: + case QUERY_NODE_SHOW_LICENCE_STMT: + return TSDB_INFORMATION_SCHEMA_DB; + case QUERY_NODE_SHOW_CONNECTIONS_STMT: + case QUERY_NODE_SHOW_QUERIES_STMT: + return TSDB_PERFORMANCE_SCHEMA_DB; + default: + break; + } + return NULL; +} + static const char* getSysTableName(ENodeType type) { switch (type) { case QUERY_NODE_SHOW_DATABASES_STMT: @@ -2552,6 +2332,9 @@ static const char* getSysTableName(ENodeType type) { return TSDB_INS_TABLE_SNODES; case QUERY_NODE_SHOW_LICENCE_STMT: return TSDB_INS_TABLE_LICENCES; + case QUERY_NODE_SHOW_CONNECTIONS_STMT: + case QUERY_NODE_SHOW_QUERIES_STMT: + // todo default: break; } @@ -2570,7 +2353,7 @@ static int32_t createSelectStmtForShow(ENodeType showType, SSelectStmt** pStmt) nodesDestroyNode(pSelect); return TSDB_CODE_OUT_OF_MEMORY; } - strcpy(pTable->table.dbName, TSDB_INFORMATION_SCHEMA_DB); + strcpy(pTable->table.dbName, getSysDbName(showType)); strcpy(pTable->table.tableName, getSysTableName(showType)); strcpy(pTable->table.tableAlias, pTable->table.tableName); pSelect->pFromTable = (SNode*)pTable; @@ -3074,6 +2857,8 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_SHOW_STREAMS_STMT: case QUERY_NODE_SHOW_BNODES_STMT: case QUERY_NODE_SHOW_SNODES_STMT: + case QUERY_NODE_SHOW_CONNECTIONS_STMT: + case QUERY_NODE_SHOW_QUERIES_STMT: code = rewriteShow(pCxt, pQuery); break; case QUERY_NODE_CREATE_TABLE_STMT: diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 85d574d9e7e4d79c9a26e8d32f3ea503b9e90e93..efc807850f4c25fb27addd8b7b1f40e76467dc9c 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -31,10 +31,6 @@ static char* getSyntaxErrFormat(int32_t errCode) { return "Invalid value type : %s"; case TSDB_CODE_PAR_INVALID_FUNTION: return "Invalid function name : %s"; - case TSDB_CODE_PAR_FUNTION_PARA_NUM: - return "Invalid number of arguments : %s"; - case TSDB_CODE_PAR_FUNTION_PARA_TYPE: - return "Inconsistent datatypes : %s"; case TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION: return "There mustn't be aggregation"; case TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT: diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index b1f8a24a83cb638777fbeba6b2a6c4c05b22600e..d3f5af3eb2aff825e956077b3b39adb6731d3fd1 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -100,24 +100,24 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 315 +#define YYNOCODE 316 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - 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; + SAlterOption yy21; + EFillMode yy22; + EOperatorType yy84; + bool yy121; + SDataType yy160; + ENullOrder yy281; + SToken yy409; + int32_t yy452; + SNodeList* yy488; + SNode* yy504; + EOrder yy522; + EJoinType yy556; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -132,18 +132,17 @@ typedef union { #define ParseCTX_PARAM #define ParseCTX_FETCH #define ParseCTX_STORE -#define YYNSTATE 548 +#define YYNSTATE 550 #define YYNRULE 411 -#define YYNRULE_WITH_ACTION 411 -#define YYNTOKEN 209 -#define YY_MAX_SHIFT 547 -#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 +#define YYNTOKEN 210 +#define YY_MAX_SHIFT 549 +#define YY_MIN_SHIFTREDUCE 810 +#define YY_MAX_SHIFTREDUCE 1220 +#define YY_ERROR_ACTION 1221 +#define YY_ACCEPT_ACTION 1222 +#define YY_NO_ACTION 1223 +#define YY_MIN_REDUCE 1224 +#define YY_MAX_REDUCE 1634 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -210,483 +209,487 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (1539) +#define YY_ACTTAB_COUNT (1556) static const YYACTIONTYPE yy_action[] = { - /* 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, + /* 0 */ 452, 258, 1485, 270, 275, 452, 1434, 25, 195, 313, + /* 10 */ 465, 1435, 30, 28, 1481, 1488, 307, 1501, 1485, 311, + /* 20 */ 267, 1485, 1055, 1613, 1335, 32, 31, 29, 27, 26, + /* 30 */ 1481, 1487, 21, 1481, 1487, 1344, 1612, 1078, 1053, 239, + /* 40 */ 1611, 1518, 32, 31, 29, 27, 26, 1613, 447, 464, + /* 50 */ 11, 30, 28, 1163, 118, 407, 1236, 1060, 451, 267, + /* 60 */ 132, 1055, 1472, 1162, 1611, 30, 28, 435, 165, 1472, + /* 70 */ 431, 1075, 373, 267, 1, 1055, 465, 1053, 69, 1502, + /* 80 */ 1503, 1507, 1552, 542, 541, 73, 241, 1548, 1177, 11, + /* 90 */ 1501, 1053, 370, 1518, 375, 101, 1060, 546, 1613, 408, + /* 100 */ 447, 1344, 446, 11, 32, 31, 29, 27, 26, 1054, + /* 110 */ 1060, 132, 23, 1, 1518, 1611, 32, 31, 29, 27, + /* 120 */ 26, 434, 32, 31, 29, 27, 26, 1, 99, 119, + /* 130 */ 1613, 451, 424, 1302, 123, 1472, 546, 433, 128, 1559, + /* 140 */ 1560, 1077, 1564, 132, 464, 1384, 1056, 1611, 1054, 278, + /* 150 */ 546, 70, 1502, 1503, 1507, 1552, 1425, 1427, 349, 260, + /* 160 */ 1548, 127, 1054, 1059, 1079, 1080, 449, 1106, 1107, 1108, + /* 170 */ 1109, 1110, 1111, 1112, 1113, 1114, 29, 27, 26, 1094, + /* 180 */ 1580, 1079, 1080, 1222, 425, 1056, 85, 133, 1276, 84, + /* 190 */ 83, 82, 81, 80, 79, 78, 77, 76, 12, 1056, + /* 200 */ 382, 381, 1059, 1079, 1080, 449, 1106, 1107, 1108, 1109, + /* 210 */ 1110, 1111, 1112, 1113, 1114, 1118, 1059, 1079, 1080, 449, + /* 220 */ 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 30, + /* 230 */ 28, 1217, 442, 398, 1501, 53, 283, 267, 133, 1055, + /* 240 */ 384, 465, 378, 306, 1247, 305, 383, 1161, 97, 98, + /* 250 */ 73, 379, 377, 1322, 380, 1053, 1339, 376, 1518, 32, + /* 260 */ 31, 29, 27, 26, 1613, 434, 1344, 1613, 30, 28, + /* 270 */ 450, 1246, 1055, 133, 1060, 451, 267, 132, 1055, 1472, + /* 280 */ 132, 1611, 30, 28, 1611, 133, 421, 1501, 1053, 1472, + /* 290 */ 267, 7, 1055, 138, 1053, 70, 1502, 1503, 1507, 1552, + /* 300 */ 1216, 464, 349, 260, 1548, 127, 465, 1060, 1053, 1224, + /* 310 */ 898, 1518, 396, 1060, 546, 312, 1472, 191, 447, 51, + /* 320 */ 9, 8, 50, 414, 1579, 394, 1054, 1060, 451, 900, + /* 330 */ 7, 1344, 1472, 94, 93, 92, 91, 90, 89, 88, + /* 340 */ 87, 86, 426, 422, 7, 1225, 271, 546, 71, 1502, + /* 350 */ 1503, 1507, 1552, 546, 116, 12, 1551, 1548, 847, 1054, + /* 360 */ 846, 335, 1346, 1056, 500, 1054, 85, 546, 443, 84, + /* 370 */ 83, 82, 81, 80, 79, 78, 77, 76, 848, 1054, + /* 380 */ 1059, 1079, 1080, 449, 1106, 1107, 1108, 1109, 1110, 1111, + /* 390 */ 1112, 1113, 1114, 431, 1139, 1391, 1056, 32, 31, 29, + /* 400 */ 27, 26, 1056, 384, 133, 378, 1426, 142, 141, 383, + /* 410 */ 1245, 53, 98, 1059, 379, 377, 1056, 380, 101, 1059, + /* 420 */ 1079, 1080, 449, 1106, 1107, 1108, 1109, 1110, 1111, 1112, + /* 430 */ 1113, 1114, 1340, 1059, 1079, 1080, 449, 1106, 1107, 1108, + /* 440 */ 1109, 1110, 1111, 1112, 1113, 1114, 30, 28, 238, 438, + /* 450 */ 1075, 99, 1566, 1566, 267, 1472, 1055, 328, 60, 1422, + /* 460 */ 340, 129, 1559, 1560, 1244, 1564, 140, 1187, 133, 341, + /* 470 */ 1563, 1562, 1053, 32, 31, 29, 27, 26, 1076, 1337, + /* 480 */ 936, 488, 487, 486, 940, 485, 942, 943, 484, 945, + /* 490 */ 481, 1060, 951, 478, 953, 954, 475, 472, 389, 1391, + /* 500 */ 418, 1185, 1186, 1188, 1189, 257, 1391, 465, 1, 1472, + /* 510 */ 1389, 242, 465, 397, 431, 465, 320, 1390, 1243, 1571, + /* 520 */ 1158, 321, 1391, 115, 348, 465, 502, 167, 272, 1081, + /* 530 */ 392, 546, 1344, 1389, 1341, 386, 1094, 1344, 1082, 101, + /* 540 */ 1344, 166, 339, 1054, 1126, 334, 333, 332, 331, 330, + /* 550 */ 1344, 327, 326, 325, 324, 323, 319, 318, 317, 316, + /* 560 */ 315, 314, 1273, 1472, 117, 465, 503, 43, 1316, 223, + /* 570 */ 42, 66, 99, 1566, 462, 32, 31, 29, 27, 26, + /* 580 */ 1056, 221, 130, 1559, 1560, 102, 1564, 465, 6, 1242, + /* 590 */ 1344, 1561, 1336, 1127, 143, 491, 463, 1059, 1079, 1080, + /* 600 */ 449, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, + /* 610 */ 465, 1131, 1344, 242, 522, 521, 520, 519, 282, 209, + /* 620 */ 518, 517, 516, 103, 511, 510, 509, 508, 507, 506, + /* 630 */ 505, 504, 109, 1128, 1472, 1344, 549, 24, 265, 1121, + /* 640 */ 1122, 1123, 1124, 1125, 1129, 1130, 1126, 190, 1320, 437, + /* 650 */ 214, 1132, 277, 96, 1241, 1240, 176, 68, 280, 538, + /* 660 */ 116, 534, 530, 526, 213, 1391, 116, 846, 1346, 1239, + /* 670 */ 1238, 279, 515, 513, 1346, 251, 1389, 22, 1170, 1235, + /* 680 */ 116, 1234, 439, 368, 1077, 49, 48, 310, 1347, 137, + /* 690 */ 67, 1233, 1333, 207, 304, 1127, 298, 500, 1329, 1472, + /* 700 */ 1472, 165, 247, 465, 296, 373, 292, 288, 134, 1492, + /* 710 */ 1232, 300, 281, 1131, 1472, 1472, 1461, 252, 1231, 250, + /* 720 */ 249, 1490, 372, 461, 1472, 1501, 1472, 375, 1344, 1230, + /* 730 */ 1229, 1158, 1228, 133, 217, 1227, 1472, 1374, 1263, 24, + /* 740 */ 265, 1121, 1122, 1123, 1124, 1125, 1129, 1130, 1063, 1518, + /* 750 */ 1258, 413, 290, 514, 172, 1472, 447, 301, 1331, 158, + /* 760 */ 385, 1501, 156, 1472, 160, 162, 451, 159, 161, 1039, + /* 770 */ 1472, 169, 387, 1501, 1472, 1472, 164, 1472, 1256, 163, + /* 780 */ 1472, 9, 8, 1219, 1220, 1518, 70, 1502, 1503, 1507, + /* 790 */ 1552, 65, 447, 1327, 260, 1548, 1625, 1518, 406, 107, + /* 800 */ 390, 62, 451, 410, 447, 1586, 1472, 45, 179, 1062, + /* 810 */ 170, 1184, 181, 34, 451, 1501, 440, 1133, 1472, 1066, + /* 820 */ 448, 1501, 70, 1502, 1503, 1507, 1552, 490, 1237, 34, + /* 830 */ 260, 1548, 1625, 1090, 70, 1502, 1503, 1507, 1552, 1518, + /* 840 */ 192, 1609, 260, 1548, 1625, 1518, 447, 34, 1303, 419, + /* 850 */ 198, 1022, 447, 1570, 200, 95, 451, 344, 153, 457, + /* 860 */ 1472, 126, 451, 1385, 105, 435, 1472, 366, 206, 362, + /* 870 */ 358, 354, 152, 1501, 405, 185, 229, 1502, 1503, 1507, + /* 880 */ 1065, 872, 71, 1502, 1503, 1507, 1552, 367, 107, 45, + /* 890 */ 445, 1548, 929, 924, 1582, 470, 1613, 1518, 54, 957, + /* 900 */ 873, 150, 432, 105, 447, 1519, 106, 961, 107, 132, + /* 910 */ 967, 105, 966, 1611, 451, 108, 1075, 194, 1472, 2, + /* 920 */ 1501, 285, 289, 246, 248, 898, 1031, 215, 322, 139, + /* 930 */ 1424, 329, 337, 336, 120, 1502, 1503, 1507, 338, 342, + /* 940 */ 1086, 343, 1085, 431, 1518, 1084, 345, 145, 346, 347, + /* 950 */ 148, 447, 52, 350, 151, 1083, 369, 399, 149, 371, + /* 960 */ 122, 451, 146, 75, 1334, 1472, 401, 155, 101, 1330, + /* 970 */ 374, 256, 436, 1626, 400, 1501, 157, 110, 171, 144, + /* 980 */ 111, 71, 1502, 1503, 1507, 1552, 1332, 435, 1328, 112, + /* 990 */ 1549, 113, 402, 174, 1082, 274, 273, 409, 420, 1518, + /* 1000 */ 412, 99, 1501, 411, 1593, 1068, 447, 177, 455, 1592, + /* 1010 */ 1501, 188, 1559, 430, 1060, 429, 451, 5, 1613, 1583, + /* 1020 */ 1472, 1061, 417, 266, 180, 259, 1518, 423, 428, 100, + /* 1030 */ 4, 132, 416, 447, 1518, 1611, 234, 1502, 1503, 1507, + /* 1040 */ 1060, 447, 1158, 451, 1501, 1081, 1567, 1472, 35, 441, + /* 1050 */ 415, 451, 1501, 125, 1573, 1472, 261, 1501, 187, 444, + /* 1060 */ 186, 184, 17, 234, 1502, 1503, 1507, 1610, 1518, 1534, + /* 1070 */ 1433, 233, 1502, 1503, 1507, 447, 1518, 193, 453, 454, + /* 1080 */ 466, 1518, 1432, 447, 269, 451, 1501, 1628, 447, 1472, + /* 1090 */ 458, 460, 1064, 451, 459, 202, 204, 1472, 451, 216, + /* 1100 */ 264, 59, 1472, 427, 1345, 120, 1502, 1503, 1507, 61, + /* 1110 */ 1518, 1501, 468, 234, 1502, 1503, 1507, 447, 226, 1502, + /* 1120 */ 1503, 1507, 497, 218, 1317, 212, 545, 451, 41, 1069, + /* 1130 */ 220, 1472, 224, 225, 268, 1518, 1466, 222, 1465, 284, + /* 1140 */ 1462, 286, 447, 287, 1627, 1049, 1072, 234, 1502, 1503, + /* 1150 */ 1507, 1050, 451, 135, 291, 1460, 1472, 1501, 293, 295, + /* 1160 */ 294, 1459, 297, 1458, 299, 1501, 1449, 136, 302, 303, + /* 1170 */ 1034, 1443, 232, 1502, 1503, 1507, 1033, 1442, 308, 1441, + /* 1180 */ 309, 1518, 1440, 1005, 1417, 1416, 1415, 1414, 447, 1518, + /* 1190 */ 1413, 1412, 1411, 1501, 104, 1401, 447, 1410, 451, 1501, + /* 1200 */ 1007, 1395, 1472, 1409, 1408, 1407, 451, 1406, 1405, 1404, + /* 1210 */ 1472, 1403, 1402, 1400, 1399, 1398, 1397, 1518, 235, 1502, + /* 1220 */ 1503, 1507, 1396, 1518, 447, 1394, 227, 1502, 1503, 1507, + /* 1230 */ 447, 1393, 1392, 1275, 451, 1457, 1451, 1439, 1472, 1430, + /* 1240 */ 451, 147, 1323, 1274, 1472, 1501, 352, 865, 1272, 353, + /* 1250 */ 1501, 1270, 1268, 356, 236, 1502, 1503, 1507, 1501, 351, + /* 1260 */ 228, 1502, 1503, 1507, 355, 359, 357, 361, 1266, 1518, + /* 1270 */ 360, 365, 1255, 1254, 1518, 1251, 447, 364, 363, 1325, + /* 1280 */ 154, 447, 1518, 974, 972, 74, 451, 1324, 897, 447, + /* 1290 */ 1472, 451, 896, 895, 894, 1472, 891, 890, 1264, 451, + /* 1300 */ 1501, 514, 253, 1472, 1259, 254, 237, 1502, 1503, 1507, + /* 1310 */ 388, 1515, 1502, 1503, 1507, 512, 1257, 255, 1250, 1514, + /* 1320 */ 1502, 1503, 1507, 391, 1518, 1501, 1249, 393, 395, 72, + /* 1330 */ 1456, 447, 1041, 1450, 1501, 168, 403, 1438, 1437, 114, + /* 1340 */ 1429, 451, 173, 55, 14, 1472, 1490, 3, 34, 1518, + /* 1350 */ 15, 189, 39, 124, 36, 10, 447, 44, 1518, 178, + /* 1360 */ 121, 244, 1502, 1503, 1507, 447, 451, 404, 1183, 57, + /* 1370 */ 1472, 182, 183, 1205, 19, 451, 38, 1176, 1155, 1472, + /* 1380 */ 175, 56, 20, 1154, 37, 1210, 1513, 1502, 1503, 1507, + /* 1390 */ 16, 1204, 262, 1209, 1208, 245, 1502, 1503, 1507, 263, + /* 1400 */ 8, 131, 1501, 196, 1092, 33, 13, 1501, 1428, 1091, + /* 1410 */ 18, 203, 1119, 1501, 197, 205, 1181, 199, 201, 46, + /* 1420 */ 58, 1070, 40, 469, 456, 276, 1518, 1321, 1489, 473, + /* 1430 */ 476, 1518, 1319, 447, 62, 208, 467, 1518, 447, 958, + /* 1440 */ 471, 479, 955, 451, 447, 474, 477, 1472, 451, 952, + /* 1450 */ 946, 480, 1472, 944, 451, 482, 483, 950, 1472, 1501, + /* 1460 */ 935, 949, 948, 243, 1502, 1503, 1507, 489, 240, 1502, + /* 1470 */ 1503, 1507, 947, 969, 230, 1502, 1503, 1507, 63, 968, + /* 1480 */ 47, 64, 965, 1518, 963, 863, 499, 904, 210, 211, + /* 1490 */ 447, 501, 496, 210, 886, 885, 884, 496, 883, 882, + /* 1500 */ 451, 881, 880, 879, 1472, 901, 899, 876, 875, 874, + /* 1510 */ 871, 870, 869, 868, 498, 1271, 523, 1269, 524, 498, + /* 1520 */ 231, 1502, 1503, 1507, 527, 528, 525, 529, 1267, 531, + /* 1530 */ 532, 533, 1265, 495, 494, 493, 535, 492, 495, 494, + /* 1540 */ 493, 536, 492, 537, 1253, 539, 540, 1252, 1248, 543, + /* 1550 */ 544, 1223, 1057, 219, 547, 548, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 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, + /* 0 */ 254, 241, 258, 257, 241, 254, 260, 279, 280, 219, + /* 10 */ 219, 260, 12, 13, 270, 271, 263, 213, 258, 228, + /* 20 */ 20, 258, 22, 294, 213, 12, 13, 14, 15, 16, + /* 30 */ 270, 271, 2, 270, 271, 244, 307, 20, 38, 249, + /* 40 */ 311, 237, 12, 13, 14, 15, 16, 294, 244, 20, + /* 50 */ 50, 12, 13, 14, 212, 219, 214, 57, 254, 20, + /* 60 */ 307, 22, 258, 4, 311, 12, 13, 263, 61, 258, + /* 70 */ 219, 20, 65, 20, 74, 22, 219, 38, 274, 275, + /* 80 */ 276, 277, 278, 216, 217, 228, 282, 283, 75, 50, + /* 90 */ 213, 38, 235, 237, 87, 244, 57, 97, 294, 263, + /* 100 */ 244, 244, 50, 50, 12, 13, 14, 15, 16, 109, + /* 110 */ 57, 307, 2, 74, 237, 311, 12, 13, 14, 15, + /* 120 */ 16, 244, 12, 13, 14, 15, 16, 74, 277, 222, + /* 130 */ 294, 254, 276, 226, 236, 258, 97, 286, 287, 288, + /* 140 */ 289, 20, 291, 307, 20, 247, 146, 311, 109, 246, + /* 150 */ 97, 274, 275, 276, 277, 278, 253, 254, 49, 282, + /* 160 */ 283, 284, 109, 163, 164, 165, 166, 167, 168, 169, + /* 170 */ 170, 171, 172, 173, 174, 175, 14, 15, 16, 75, + /* 180 */ 303, 164, 165, 210, 20, 146, 21, 187, 0, 24, + /* 190 */ 25, 26, 27, 28, 29, 30, 31, 32, 74, 146, + /* 200 */ 223, 224, 163, 164, 165, 166, 167, 168, 169, 170, + /* 210 */ 171, 172, 173, 174, 175, 163, 163, 164, 165, 166, + /* 220 */ 167, 168, 169, 170, 171, 172, 173, 174, 175, 12, + /* 230 */ 13, 139, 71, 263, 213, 221, 263, 20, 187, 22, + /* 240 */ 52, 219, 54, 145, 213, 147, 58, 188, 234, 61, + /* 250 */ 228, 63, 64, 0, 66, 38, 242, 235, 237, 12, + /* 260 */ 13, 14, 15, 16, 294, 244, 244, 294, 12, 13, + /* 270 */ 14, 213, 22, 187, 57, 254, 20, 307, 22, 258, + /* 280 */ 307, 311, 12, 13, 311, 187, 136, 213, 38, 258, + /* 290 */ 20, 74, 22, 47, 38, 274, 275, 276, 277, 278, + /* 300 */ 208, 20, 49, 282, 283, 284, 219, 57, 38, 0, + /* 310 */ 38, 237, 21, 57, 97, 228, 258, 296, 244, 73, + /* 320 */ 1, 2, 76, 302, 303, 34, 109, 57, 254, 57, + /* 330 */ 74, 244, 258, 24, 25, 26, 27, 28, 29, 30, + /* 340 */ 31, 32, 192, 193, 74, 0, 229, 97, 274, 275, + /* 350 */ 276, 277, 278, 97, 237, 74, 282, 283, 20, 109, + /* 360 */ 22, 67, 245, 146, 49, 109, 21, 97, 207, 24, + /* 370 */ 25, 26, 27, 28, 29, 30, 31, 32, 40, 109, /* 380 */ 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, - /* 390 */ 173, 174, 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, + /* 390 */ 173, 174, 175, 219, 75, 237, 146, 12, 13, 14, + /* 400 */ 15, 16, 146, 52, 187, 54, 248, 113, 114, 58, + /* 410 */ 213, 221, 61, 163, 63, 64, 146, 66, 244, 163, /* 420 */ 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, - /* 430 */ 174, 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, + /* 430 */ 174, 175, 242, 163, 164, 165, 166, 167, 168, 169, + /* 440 */ 170, 171, 172, 173, 174, 175, 12, 13, 18, 3, + /* 450 */ 20, 277, 272, 272, 20, 258, 22, 27, 218, 244, + /* 460 */ 30, 287, 288, 289, 213, 291, 251, 163, 187, 39, + /* 470 */ 290, 290, 38, 12, 13, 14, 15, 16, 20, 239, /* 480 */ 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, - /* 490 */ 98, 57, 100, 101, 102, 103, 104, 105, 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, + /* 490 */ 98, 57, 100, 101, 102, 103, 104, 105, 4, 237, + /* 500 */ 196, 197, 198, 199, 200, 243, 237, 219, 74, 258, + /* 510 */ 248, 50, 219, 19, 219, 219, 228, 248, 213, 185, + /* 520 */ 186, 228, 237, 138, 228, 219, 57, 33, 243, 20, + /* 530 */ 36, 97, 244, 248, 228, 41, 75, 244, 20, 244, + /* 540 */ 244, 47, 112, 109, 83, 115, 116, 117, 118, 119, + /* 550 */ 244, 121, 122, 123, 124, 125, 126, 127, 128, 129, + /* 560 */ 130, 131, 0, 258, 18, 219, 225, 73, 227, 23, + /* 570 */ 76, 218, 277, 272, 228, 12, 13, 14, 15, 16, + /* 580 */ 146, 35, 287, 288, 289, 232, 291, 219, 43, 213, + /* 590 */ 244, 290, 239, 132, 48, 85, 228, 163, 164, 165, + /* 600 */ 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, + /* 610 */ 219, 150, 244, 50, 52, 53, 54, 55, 56, 228, /* 620 */ 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, - /* 630 */ 68, 69, 70, 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, + /* 630 */ 68, 69, 70, 132, 258, 244, 19, 176, 177, 178, + /* 640 */ 179, 180, 181, 182, 183, 184, 83, 138, 0, 203, + /* 650 */ 33, 150, 229, 36, 213, 213, 138, 111, 229, 42, + /* 660 */ 237, 44, 45, 46, 47, 237, 237, 22, 245, 213, + /* 670 */ 213, 243, 223, 224, 245, 35, 248, 176, 14, 213, + /* 680 */ 237, 213, 71, 38, 20, 139, 140, 141, 245, 143, + /* 690 */ 73, 213, 238, 76, 148, 132, 142, 49, 238, 258, + /* 700 */ 258, 61, 156, 219, 158, 65, 160, 161, 162, 74, + /* 710 */ 213, 157, 228, 150, 258, 258, 0, 77, 213, 79, + /* 720 */ 80, 86, 82, 106, 258, 213, 258, 87, 244, 213, + /* 730 */ 213, 186, 213, 187, 230, 213, 258, 233, 0, 176, + /* 740 */ 177, 178, 179, 180, 181, 182, 183, 184, 38, 237, + /* 750 */ 0, 134, 36, 71, 137, 258, 244, 75, 238, 78, + /* 760 */ 22, 213, 81, 258, 78, 78, 254, 81, 81, 152, + /* 770 */ 258, 154, 22, 213, 258, 258, 78, 258, 0, 81, + /* 780 */ 258, 1, 2, 164, 165, 237, 274, 275, 276, 277, + /* 790 */ 278, 74, 244, 238, 282, 283, 284, 237, 266, 71, + /* 800 */ 22, 84, 254, 75, 244, 293, 258, 71, 71, 38, + /* 810 */ 238, 75, 75, 71, 254, 213, 205, 75, 258, 109, + /* 820 */ 238, 213, 274, 275, 276, 277, 278, 238, 214, 71, + /* 830 */ 282, 283, 284, 75, 274, 275, 276, 277, 278, 237, + /* 840 */ 314, 293, 282, 283, 284, 237, 244, 71, 226, 305, + /* 850 */ 71, 75, 244, 293, 75, 71, 254, 254, 33, 75, + /* 860 */ 258, 36, 254, 247, 71, 263, 258, 42, 75, 44, + /* 870 */ 45, 46, 47, 213, 254, 299, 274, 275, 276, 277, + /* 880 */ 109, 38, 274, 275, 276, 277, 278, 216, 71, 71, + /* 890 */ 282, 283, 75, 75, 273, 71, 294, 237, 73, 75, + /* 900 */ 57, 76, 292, 71, 244, 237, 71, 75, 71, 307, + /* 910 */ 75, 71, 75, 311, 254, 75, 20, 308, 258, 295, + /* 920 */ 213, 219, 36, 269, 223, 38, 144, 264, 219, 120, + /* 930 */ 219, 252, 132, 250, 274, 275, 276, 277, 250, 219, + /* 940 */ 20, 268, 20, 219, 237, 20, 262, 221, 244, 255, + /* 950 */ 221, 244, 221, 219, 221, 20, 215, 244, 133, 237, + /* 960 */ 135, 254, 137, 219, 237, 258, 153, 237, 244, 237, + /* 970 */ 223, 215, 312, 313, 268, 213, 237, 237, 218, 154, + /* 980 */ 237, 274, 275, 276, 277, 278, 237, 263, 237, 237, + /* 990 */ 283, 237, 267, 218, 20, 12, 13, 262, 195, 237, + /* 1000 */ 255, 277, 213, 244, 304, 22, 244, 259, 194, 304, + /* 1010 */ 213, 287, 288, 289, 57, 291, 254, 202, 294, 273, + /* 1020 */ 258, 38, 258, 261, 259, 258, 237, 258, 201, 244, + /* 1030 */ 189, 307, 190, 244, 237, 311, 274, 275, 276, 277, + /* 1040 */ 57, 244, 186, 254, 213, 20, 272, 258, 120, 204, + /* 1050 */ 261, 254, 213, 298, 301, 258, 209, 213, 285, 206, + /* 1060 */ 297, 300, 74, 274, 275, 276, 277, 310, 237, 281, + /* 1070 */ 259, 274, 275, 276, 277, 244, 237, 309, 258, 258, + /* 1080 */ 97, 237, 259, 244, 258, 254, 213, 315, 244, 258, + /* 1090 */ 135, 255, 109, 254, 256, 244, 218, 258, 254, 233, + /* 1100 */ 261, 218, 258, 306, 244, 274, 275, 276, 277, 74, + /* 1110 */ 237, 213, 240, 274, 275, 276, 277, 244, 274, 275, + /* 1120 */ 276, 277, 223, 219, 227, 218, 215, 254, 265, 146, + /* 1130 */ 220, 258, 231, 231, 261, 237, 0, 211, 0, 64, + /* 1140 */ 0, 38, 244, 159, 313, 38, 163, 274, 275, 276, + /* 1150 */ 277, 38, 254, 38, 159, 0, 258, 213, 38, 159, + /* 1160 */ 38, 0, 38, 0, 38, 213, 0, 74, 150, 149, + /* 1170 */ 109, 0, 274, 275, 276, 277, 146, 0, 53, 0, + /* 1180 */ 142, 237, 0, 86, 0, 0, 0, 0, 244, 237, + /* 1190 */ 0, 0, 0, 213, 120, 0, 244, 0, 254, 213, + /* 1200 */ 22, 0, 258, 0, 0, 0, 254, 0, 0, 0, + /* 1210 */ 258, 0, 0, 0, 0, 0, 0, 237, 274, 275, + /* 1220 */ 276, 277, 0, 237, 244, 0, 274, 275, 276, 277, + /* 1230 */ 244, 0, 0, 0, 254, 0, 0, 0, 258, 0, + /* 1240 */ 254, 43, 0, 0, 258, 213, 36, 51, 0, 43, + /* 1250 */ 213, 0, 0, 36, 274, 275, 276, 277, 213, 38, + /* 1260 */ 274, 275, 276, 277, 38, 38, 43, 43, 0, 237, + /* 1270 */ 36, 43, 0, 0, 237, 0, 244, 36, 38, 0, + /* 1280 */ 81, 244, 237, 38, 22, 83, 254, 0, 38, 244, + /* 1290 */ 258, 254, 38, 38, 38, 258, 38, 38, 0, 254, + /* 1300 */ 213, 71, 22, 258, 0, 22, 274, 275, 276, 277, + /* 1310 */ 39, 274, 275, 276, 277, 71, 0, 22, 0, 274, + /* 1320 */ 275, 276, 277, 38, 237, 213, 0, 22, 22, 20, + /* 1330 */ 0, 244, 38, 0, 213, 155, 22, 0, 0, 151, + /* 1340 */ 0, 254, 43, 74, 191, 258, 86, 71, 71, 237, + /* 1350 */ 191, 86, 71, 135, 185, 191, 244, 138, 237, 75, + /* 1360 */ 74, 274, 275, 276, 277, 244, 254, 138, 75, 4, + /* 1370 */ 258, 74, 71, 38, 74, 254, 138, 75, 75, 258, + /* 1380 */ 133, 74, 71, 75, 71, 75, 274, 275, 276, 277, + /* 1390 */ 71, 38, 38, 38, 38, 274, 275, 276, 277, 38, + /* 1400 */ 2, 86, 213, 86, 75, 74, 74, 213, 0, 75, + /* 1410 */ 74, 43, 163, 213, 75, 133, 75, 74, 74, 74, + /* 1420 */ 74, 22, 74, 38, 136, 38, 237, 0, 86, 38, + /* 1430 */ 38, 237, 0, 244, 84, 86, 85, 237, 244, 75, + /* 1440 */ 74, 38, 75, 254, 244, 74, 74, 258, 254, 75, + /* 1450 */ 75, 74, 258, 75, 254, 38, 74, 99, 258, 213, + /* 1460 */ 22, 99, 99, 274, 275, 276, 277, 87, 274, 275, + /* 1470 */ 276, 277, 99, 38, 274, 275, 276, 277, 74, 109, + /* 1480 */ 74, 74, 38, 237, 22, 51, 50, 57, 61, 71, + /* 1490 */ 244, 72, 65, 61, 38, 38, 38, 65, 38, 38, + /* 1500 */ 254, 38, 38, 22, 258, 57, 38, 38, 38, 38, + /* 1510 */ 38, 38, 38, 38, 87, 0, 38, 0, 36, 87, + /* 1520 */ 274, 275, 276, 277, 38, 36, 43, 43, 0, 38, + /* 1530 */ 36, 43, 0, 106, 107, 108, 38, 110, 106, 107, + /* 1540 */ 108, 36, 110, 43, 0, 38, 37, 0, 0, 22, + /* 1550 */ 21, 316, 22, 22, 21, 20, 316, 316, 316, 316, + /* 1560 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1570 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1580 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1590 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1600 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1610 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1620 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1630 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1640 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1650 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1660 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1670 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1680 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1690 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1700 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1710 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1720 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1730 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1740 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1750 */ 316, 316, 316, 316, 316, 316, 316, 316, 316, 316, + /* 1760 */ 316, 316, 316, 316, 316, 316, }; -#define YY_SHIFT_COUNT (547) +#define YY_SHIFT_COUNT (549) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1531) +#define YY_SHIFT_MAX (1548) static const unsigned short int yy_shift_ofst[] = { /* 0 */ 546, 0, 39, 53, 53, 53, 53, 217, 53, 53, - /* 10 */ 270, 434, 161, 256, 270, 270, 270, 270, 270, 270, + /* 10 */ 270, 434, 281, 256, 270, 270, 270, 270, 270, 270, /* 20 */ 270, 270, 270, 270, 270, 270, 270, 270, 270, 270, - /* 30 */ 270, 270, 270, 270, 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, + /* 30 */ 270, 270, 270, 270, 270, 124, 124, 124, 51, 983, + /* 40 */ 983, 98, 29, 29, 86, 983, 17, 17, 29, 29, + /* 50 */ 29, 29, 29, 29, 109, 121, 164, 86, 121, 29, + /* 60 */ 29, 121, 29, 121, 121, 121, 29, 315, 430, 461, + /* 70 */ 563, 563, 165, 640, 250, 351, 250, 250, 250, 250, + /* 80 */ 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, + /* 90 */ 250, 250, 250, 250, 250, 17, 338, 253, 272, 509, + /* 100 */ 509, 509, 648, 272, 458, 121, 121, 121, 510, 469, + /* 110 */ 392, 392, 392, 392, 392, 392, 392, 617, 345, 188, + /* 120 */ 92, 304, 17, 7, 17, 150, 645, 518, 334, 545, + /* 130 */ 334, 664, 446, 59, 896, 886, 887, 782, 896, 896, + /* 140 */ 809, 800, 800, 896, 920, 922, 109, 458, 925, 109, + /* 150 */ 109, 896, 109, 935, 121, 121, 121, 121, 121, 121, + /* 160 */ 121, 121, 121, 121, 121, 887, 896, 935, 458, 920, + /* 170 */ 813, 922, 315, 458, 925, 315, 974, 803, 814, 957, + /* 180 */ 803, 814, 957, 957, 815, 827, 842, 841, 856, 458, + /* 190 */ 1025, 928, 847, 853, 845, 988, 121, 814, 957, 957, + /* 200 */ 814, 957, 955, 458, 925, 315, 510, 315, 458, 1035, + /* 210 */ 887, 469, 896, 315, 935, 1556, 1556, 1556, 1556, 1556, + /* 220 */ 562, 825, 309, 494, 1427, 1432, 13, 30, 110, 104, + /* 230 */ 385, 247, 247, 247, 247, 247, 247, 247, 246, 294, + /* 240 */ 162, 319, 501, 162, 162, 162, 716, 554, 682, 681, + /* 250 */ 686, 687, 698, 738, 750, 778, 291, 728, 736, 737, + /* 260 */ 780, 619, 611, 161, 742, 52, 758, 635, 776, 779, + /* 270 */ 784, 793, 817, 710, 771, 818, 824, 832, 835, 837, + /* 280 */ 840, 717, 843, 1136, 1138, 1075, 1140, 1103, 984, 1107, + /* 290 */ 1113, 1115, 995, 1155, 1120, 1122, 1000, 1161, 1124, 1163, + /* 300 */ 1126, 1166, 1093, 1018, 1020, 1061, 1030, 1171, 1177, 1125, + /* 310 */ 1038, 1179, 1182, 1097, 1184, 1185, 1186, 1187, 1190, 1191, + /* 320 */ 1192, 1197, 1203, 1204, 1205, 1207, 1208, 1209, 1211, 1212, + /* 330 */ 1074, 1195, 1213, 1214, 1215, 1216, 1222, 1178, 1201, 1225, + /* 340 */ 1231, 1232, 1233, 1235, 1236, 1237, 1239, 1198, 1242, 1196, + /* 350 */ 1243, 1248, 1221, 1210, 1206, 1251, 1226, 1217, 1223, 1252, + /* 360 */ 1227, 1234, 1224, 1268, 1240, 1241, 1228, 1272, 1273, 1275, + /* 370 */ 1279, 1202, 1199, 1245, 1230, 1262, 1287, 1250, 1254, 1255, + /* 380 */ 1256, 1244, 1230, 1258, 1259, 1298, 1280, 1304, 1283, 1271, + /* 390 */ 1316, 1295, 1285, 1318, 1305, 1326, 1306, 1309, 1330, 1219, + /* 400 */ 1180, 1294, 1333, 1188, 1314, 1229, 1218, 1337, 1338, 1238, + /* 410 */ 1340, 1269, 1299, 1247, 1276, 1277, 1153, 1284, 1281, 1293, + /* 420 */ 1286, 1297, 1300, 1302, 1301, 1260, 1307, 1311, 1159, 1303, + /* 430 */ 1308, 1265, 1169, 1313, 1315, 1310, 1319, 1164, 1365, 1335, + /* 440 */ 1353, 1354, 1355, 1356, 1361, 1398, 1249, 1317, 1329, 1331, + /* 450 */ 1334, 1332, 1336, 1339, 1341, 1343, 1344, 1288, 1345, 1408, + /* 460 */ 1368, 1282, 1346, 1350, 1342, 1349, 1399, 1348, 1351, 1364, + /* 470 */ 1385, 1387, 1366, 1367, 1391, 1371, 1374, 1392, 1372, 1375, + /* 480 */ 1403, 1377, 1378, 1417, 1382, 1358, 1362, 1363, 1373, 1438, + /* 490 */ 1380, 1404, 1435, 1370, 1406, 1407, 1444, 1230, 1462, 1434, + /* 500 */ 1436, 1430, 1419, 1418, 1456, 1457, 1458, 1460, 1461, 1463, + /* 510 */ 1464, 1481, 1448, 1244, 1468, 1230, 1469, 1470, 1471, 1472, + /* 520 */ 1473, 1474, 1475, 1515, 1478, 1482, 1483, 1517, 1486, 1489, + /* 530 */ 1484, 1528, 1491, 1494, 1488, 1532, 1498, 1505, 1500, 1544, + /* 540 */ 1507, 1509, 1547, 1548, 1527, 1529, 1530, 1531, 1533, 1535, }; -#define YY_REDUCE_COUNT (218) -#define YY_REDUCE_MIN (-274) -#define YY_REDUCE_MAX (1160) +#define YY_REDUCE_COUNT (219) +#define YY_REDUCE_MIN (-272) +#define YY_REDUCE_MAX (1246) static const short yy_reduce_ofst[] = { - /* 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, + /* 0 */ -27, -196, 21, -123, 512, 548, 560, 602, 74, 608, + /* 10 */ 660, 707, 724, 762, 789, 797, 831, 839, 873, 844, + /* 20 */ 898, 944, 952, 980, 986, 1032, 1037, 1045, 1087, 1112, + /* 30 */ 1121, 1189, 1194, 1200, 1246, -149, 174, 295, -164, -240, + /* 40 */ -237, -247, -143, 22, -30, -256, -254, -97, -209, 87, + /* 50 */ 288, 293, 296, 306, 14, 262, -144, -271, 117, 346, + /* 60 */ 368, 285, 391, 423, 428, 429, 484, 353, -210, -272, + /* 70 */ -272, -272, -158, -102, -189, -93, 31, 58, 197, 251, + /* 80 */ 305, 376, 441, 442, 456, 457, 466, 468, 478, 497, + /* 90 */ 505, 516, 517, 519, 522, -249, -133, 190, -23, 180, + /* 100 */ 181, 301, 240, 449, 215, 443, 158, 269, 504, 341, + /* 110 */ 454, 460, 520, 555, 572, 582, 589, 532, 614, 622, + /* 120 */ 526, 544, 603, 616, 620, 576, 671, 621, 610, 610, + /* 130 */ 610, 668, 609, 624, 702, 654, 701, 663, 709, 711, + /* 140 */ 679, 683, 688, 720, 673, 684, 726, 704, 694, 729, + /* 150 */ 731, 734, 733, 741, 722, 727, 730, 732, 739, 740, + /* 160 */ 743, 749, 751, 752, 754, 747, 744, 756, 713, 706, + /* 170 */ 725, 735, 760, 759, 745, 775, 746, 700, 748, 764, + /* 180 */ 705, 765, 767, 769, 753, 761, 755, 763, 610, 785, + /* 190 */ 774, 773, 772, 757, 768, 788, 668, 811, 820, 821, + /* 200 */ 823, 826, 838, 851, 836, 878, 866, 883, 860, 872, + /* 210 */ 899, 897, 904, 907, 911, 863, 901, 902, 910, 926, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 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, + /* 0 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 10 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 20 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 30 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 40 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 50 */ 1221, 1221, 1221, 1221, 1280, 1221, 1221, 1221, 1221, 1221, + /* 60 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1278, 1418, 1221, + /* 70 */ 1554, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 80 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 90 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1280, 1221, 1565, + /* 100 */ 1565, 1565, 1278, 1221, 1221, 1221, 1221, 1221, 1373, 1221, + /* 110 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1452, 1221, 1221, + /* 120 */ 1629, 1221, 1221, 1326, 1221, 1589, 1221, 1581, 1557, 1571, + /* 130 */ 1558, 1221, 1614, 1574, 1221, 1221, 1221, 1444, 1221, 1221, + /* 140 */ 1423, 1420, 1420, 1221, 1221, 1221, 1280, 1221, 1221, 1280, + /* 150 */ 1280, 1221, 1280, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 160 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 170 */ 1454, 1221, 1278, 1221, 1221, 1278, 1221, 1596, 1594, 1221, + /* 180 */ 1596, 1594, 1221, 1221, 1608, 1604, 1587, 1585, 1571, 1221, + /* 190 */ 1221, 1221, 1632, 1620, 1616, 1221, 1221, 1594, 1221, 1221, + /* 200 */ 1594, 1221, 1431, 1221, 1221, 1278, 1221, 1278, 1221, 1342, + /* 210 */ 1221, 1221, 1221, 1278, 1221, 1446, 1376, 1376, 1281, 1226, + /* 220 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 230 */ 1221, 1517, 1607, 1606, 1516, 1531, 1530, 1529, 1221, 1221, + /* 240 */ 1511, 1221, 1221, 1512, 1510, 1509, 1221, 1221, 1221, 1221, + /* 250 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 260 */ 1555, 1221, 1617, 1621, 1221, 1221, 1221, 1491, 1221, 1221, + /* 270 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 280 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 290 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 300 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 310 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 320 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 330 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 340 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 350 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 360 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 370 */ 1221, 1221, 1221, 1221, 1387, 1221, 1221, 1221, 1221, 1221, + /* 380 */ 1221, 1307, 1306, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 390 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 400 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 410 */ 1221, 1221, 1221, 1221, 1578, 1588, 1221, 1221, 1221, 1221, + /* 420 */ 1221, 1221, 1221, 1221, 1221, 1491, 1221, 1605, 1221, 1564, + /* 430 */ 1560, 1221, 1221, 1556, 1221, 1221, 1615, 1221, 1221, 1221, + /* 440 */ 1221, 1221, 1221, 1221, 1221, 1550, 1221, 1221, 1221, 1221, + /* 450 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 460 */ 1221, 1221, 1221, 1221, 1490, 1221, 1221, 1221, 1221, 1221, + /* 470 */ 1221, 1221, 1370, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 480 */ 1221, 1221, 1221, 1221, 1221, 1355, 1353, 1352, 1351, 1221, + /* 490 */ 1348, 1221, 1221, 1221, 1221, 1221, 1221, 1378, 1221, 1221, + /* 500 */ 1221, 1221, 1221, 1301, 1221, 1221, 1221, 1221, 1221, 1221, + /* 510 */ 1221, 1221, 1221, 1292, 1221, 1291, 1221, 1221, 1221, 1221, + /* 520 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 530 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, + /* 540 */ 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, 1221, }; /********** End of lemon-generated parsing tables *****************************/ @@ -959,155 +962,156 @@ static const char *const yyTokenName[] = { /* 163 */ "NULL", /* 164 */ "FIRST", /* 165 */ "LAST", - /* 166 */ "NOW", - /* 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", + /* 166 */ "CAST", + /* 167 */ "NOW", + /* 168 */ "TODAY", + /* 169 */ "ROWTS", + /* 170 */ "TBNAME", + /* 171 */ "QSTARTTS", + /* 172 */ "QENDTS", + /* 173 */ "WSTARTTS", + /* 174 */ "WENDTS", + /* 175 */ "WDURATION", + /* 176 */ "BETWEEN", + /* 177 */ "IS", + /* 178 */ "NK_LT", + /* 179 */ "NK_GT", + /* 180 */ "NK_LE", + /* 181 */ "NK_GE", + /* 182 */ "NK_NE", + /* 183 */ "MATCH", + /* 184 */ "NMATCH", + /* 185 */ "JOIN", + /* 186 */ "INNER", + /* 187 */ "SELECT", + /* 188 */ "DISTINCT", + /* 189 */ "WHERE", + /* 190 */ "PARTITION", + /* 191 */ "BY", + /* 192 */ "SESSION", + /* 193 */ "STATE_WINDOW", + /* 194 */ "SLIDING", + /* 195 */ "FILL", + /* 196 */ "VALUE", + /* 197 */ "NONE", + /* 198 */ "PREV", + /* 199 */ "LINEAR", + /* 200 */ "NEXT", + /* 201 */ "GROUP", + /* 202 */ "HAVING", + /* 203 */ "ORDER", + /* 204 */ "SLIMIT", + /* 205 */ "SOFFSET", + /* 206 */ "LIMIT", + /* 207 */ "OFFSET", + /* 208 */ "ASC", + /* 209 */ "NULLS", + /* 210 */ "cmd", + /* 211 */ "account_options", + /* 212 */ "alter_account_options", + /* 213 */ "literal", + /* 214 */ "alter_account_option", + /* 215 */ "user_name", + /* 216 */ "dnode_endpoint", + /* 217 */ "dnode_host_name", + /* 218 */ "not_exists_opt", + /* 219 */ "db_name", + /* 220 */ "db_options", + /* 221 */ "exists_opt", + /* 222 */ "alter_db_options", + /* 223 */ "integer_list", + /* 224 */ "variable_list", + /* 225 */ "retention_list", + /* 226 */ "alter_db_option", + /* 227 */ "retention", + /* 228 */ "full_table_name", + /* 229 */ "column_def_list", + /* 230 */ "tags_def_opt", + /* 231 */ "table_options", + /* 232 */ "multi_create_clause", + /* 233 */ "tags_def", + /* 234 */ "multi_drop_clause", + /* 235 */ "alter_table_clause", + /* 236 */ "alter_table_options", + /* 237 */ "column_name", + /* 238 */ "type_name", + /* 239 */ "create_subtable_clause", + /* 240 */ "specific_tags_opt", + /* 241 */ "literal_list", + /* 242 */ "drop_table_clause", + /* 243 */ "col_name_list", + /* 244 */ "table_name", + /* 245 */ "column_def", + /* 246 */ "func_name_list", + /* 247 */ "alter_table_option", + /* 248 */ "col_name", + /* 249 */ "db_name_cond_opt", + /* 250 */ "like_pattern_opt", + /* 251 */ "table_name_cond", + /* 252 */ "from_db_opt", + /* 253 */ "func_name", + /* 254 */ "function_name", + /* 255 */ "index_name", + /* 256 */ "index_options", + /* 257 */ "func_list", + /* 258 */ "duration_literal", + /* 259 */ "sliding_opt", + /* 260 */ "func", + /* 261 */ "expression_list", + /* 262 */ "topic_name", + /* 263 */ "query_expression", + /* 264 */ "analyze_opt", + /* 265 */ "explain_options", + /* 266 */ "agg_func_opt", + /* 267 */ "bufsize_opt", + /* 268 */ "stream_name", + /* 269 */ "dnode_list", + /* 270 */ "signed", + /* 271 */ "signed_literal", + /* 272 */ "table_alias", + /* 273 */ "column_alias", + /* 274 */ "expression", + /* 275 */ "pseudo_column", + /* 276 */ "column_reference", + /* 277 */ "subquery", + /* 278 */ "predicate", + /* 279 */ "compare_op", + /* 280 */ "in_op", + /* 281 */ "in_predicate_value", + /* 282 */ "boolean_value_expression", + /* 283 */ "boolean_primary", + /* 284 */ "common_expression", + /* 285 */ "from_clause", + /* 286 */ "table_reference_list", + /* 287 */ "table_reference", + /* 288 */ "table_primary", + /* 289 */ "joined_table", + /* 290 */ "alias_opt", + /* 291 */ "parenthesized_joined_table", + /* 292 */ "join_type", + /* 293 */ "search_condition", + /* 294 */ "query_specification", + /* 295 */ "set_quantifier_opt", + /* 296 */ "select_list", + /* 297 */ "where_clause_opt", + /* 298 */ "partition_by_clause_opt", + /* 299 */ "twindow_clause_opt", + /* 300 */ "group_by_clause_opt", + /* 301 */ "having_clause_opt", + /* 302 */ "select_sublist", + /* 303 */ "select_item", + /* 304 */ "fill_opt", + /* 305 */ "fill_mode", + /* 306 */ "group_by_list", + /* 307 */ "query_expression_body", + /* 308 */ "order_by_clause_opt", + /* 309 */ "slimit_clause_opt", + /* 310 */ "limit_clause_opt", + /* 311 */ "query_primary", + /* 312 */ "sort_specification_list", + /* 313 */ "sort_specification", + /* 314 */ "ordering_specification_opt", + /* 315 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1397,7 +1401,7 @@ static const char *const yyRuleName[] = { /* 279 */ "expression ::= column_reference", /* 280 */ "expression ::= function_name NK_LP expression_list NK_RP", /* 281 */ "expression ::= function_name NK_LP NK_STAR NK_RP", - /* 282 */ "expression ::= function_name NK_LP expression AS type_name NK_RP", + /* 282 */ "expression ::= CAST NK_LP expression AS type_name NK_RP", /* 283 */ "expression ::= subquery", /* 284 */ "expression ::= NK_LP expression NK_RP", /* 285 */ "expression ::= NK_PLUS expression", @@ -1652,156 +1656,156 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - 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 */ + case 210: /* cmd */ + case 213: /* literal */ + case 220: /* db_options */ + case 222: /* alter_db_options */ + case 227: /* retention */ + case 228: /* full_table_name */ + case 231: /* table_options */ + case 235: /* alter_table_clause */ + case 236: /* alter_table_options */ + case 239: /* create_subtable_clause */ + case 242: /* drop_table_clause */ + case 245: /* column_def */ + case 248: /* col_name */ + case 249: /* db_name_cond_opt */ + case 250: /* like_pattern_opt */ + case 251: /* table_name_cond */ + case 252: /* from_db_opt */ + case 253: /* func_name */ + case 256: /* index_options */ + case 258: /* duration_literal */ + case 259: /* sliding_opt */ + case 260: /* func */ + case 263: /* query_expression */ + case 265: /* explain_options */ + case 270: /* signed */ + case 271: /* signed_literal */ + case 274: /* expression */ + case 275: /* pseudo_column */ + case 276: /* column_reference */ + case 277: /* subquery */ + case 278: /* predicate */ + case 281: /* in_predicate_value */ + case 282: /* boolean_value_expression */ + case 283: /* boolean_primary */ + case 284: /* common_expression */ + case 285: /* from_clause */ + case 286: /* table_reference_list */ + case 287: /* table_reference */ + case 288: /* table_primary */ + case 289: /* joined_table */ + case 291: /* parenthesized_joined_table */ + case 293: /* search_condition */ + case 294: /* query_specification */ + case 297: /* where_clause_opt */ + case 299: /* twindow_clause_opt */ + case 301: /* having_clause_opt */ + case 303: /* select_item */ + case 304: /* fill_opt */ + case 307: /* query_expression_body */ + case 309: /* slimit_clause_opt */ + case 310: /* limit_clause_opt */ + case 311: /* query_primary */ + case 313: /* sort_specification */ { - nodesDestroyNode((yypminor->yy182)); + nodesDestroyNode((yypminor->yy504)); } break; - case 210: /* account_options */ - case 211: /* alter_account_options */ - case 213: /* alter_account_option */ - case 266: /* bufsize_opt */ + case 211: /* account_options */ + case 212: /* alter_account_options */ + case 214: /* alter_account_option */ + case 267: /* bufsize_opt */ { } break; - 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 */ + case 215: /* user_name */ + case 216: /* dnode_endpoint */ + case 217: /* dnode_host_name */ + case 219: /* db_name */ + case 237: /* column_name */ + case 244: /* table_name */ + case 254: /* function_name */ + case 255: /* index_name */ + case 262: /* topic_name */ + case 268: /* stream_name */ + case 272: /* table_alias */ + case 273: /* column_alias */ + case 290: /* alias_opt */ { } break; - case 217: /* not_exists_opt */ - case 220: /* exists_opt */ - case 263: /* analyze_opt */ - case 265: /* agg_func_opt */ - case 294: /* set_quantifier_opt */ + case 218: /* not_exists_opt */ + case 221: /* exists_opt */ + case 264: /* analyze_opt */ + case 266: /* agg_func_opt */ + case 295: /* set_quantifier_opt */ { } break; - case 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 */ + case 223: /* integer_list */ + case 224: /* variable_list */ + case 225: /* retention_list */ + case 229: /* column_def_list */ + case 230: /* tags_def_opt */ + case 232: /* multi_create_clause */ + case 233: /* tags_def */ + case 234: /* multi_drop_clause */ + case 240: /* specific_tags_opt */ + case 241: /* literal_list */ + case 243: /* col_name_list */ + case 246: /* func_name_list */ + case 257: /* func_list */ + case 261: /* expression_list */ + case 269: /* dnode_list */ + case 296: /* select_list */ + case 298: /* partition_by_clause_opt */ + case 300: /* group_by_clause_opt */ + case 302: /* select_sublist */ + case 306: /* group_by_list */ + case 308: /* order_by_clause_opt */ + case 312: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy334)); + nodesDestroyList((yypminor->yy488)); } break; - case 225: /* alter_db_option */ - case 246: /* alter_table_option */ + case 226: /* alter_db_option */ + case 247: /* alter_table_option */ { } break; - case 237: /* type_name */ + case 238: /* type_name */ { } break; - case 278: /* compare_op */ - case 279: /* in_op */ + case 279: /* compare_op */ + case 280: /* in_op */ { } break; - case 291: /* join_type */ + case 292: /* join_type */ { } break; - case 304: /* fill_mode */ + case 305: /* fill_mode */ { } break; - case 313: /* ordering_specification_opt */ + case 314: /* ordering_specification_opt */ { } break; - case 314: /* null_ordering_opt */ + case 315: /* null_ordering_opt */ { } @@ -1929,18 +1933,15 @@ static YYACTIONTYPE yy_find_shift_action( do{ i = yy_shift_ofst[stateno]; assert( i>=0 ); - assert( i<=YY_ACTTAB_COUNT ); - assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD ); + /* assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD ); */ assert( iLookAhead!=YYNOCODE ); assert( iLookAhead < YYNTOKEN ); i += iLookAhead; - assert( i<(int)YY_NLOOKAHEAD ); - if( yy_lookahead[i]!=iLookAhead ){ + if( i>=YY_NLOOKAHEAD || yy_lookahead[i]!=iLookAhead ){ #ifdef YYFALLBACK YYCODETYPE iFallback; /* Fallback token */ - assert( iLookAhead %s\n", @@ -1955,8 +1956,16 @@ static YYACTIONTYPE yy_find_shift_action( #ifdef YYWILDCARD { int j = i - iLookAhead + YYWILDCARD; - assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) ); - if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){ + if( +#if YY_SHIFT_MIN+YYWILDCARD<0 + j>=0 && +#endif +#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT + j0 + ){ #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", @@ -1970,7 +1979,6 @@ static YYACTIONTYPE yy_find_shift_action( #endif /* YYWILDCARD */ return yy_default[stateno]; }else{ - assert( i>=0 && iyytos; #ifndef NDEBUG if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ - yysize = yyRuleInfoNRhs[yyruleno]; + yysize = yyRuleInfo[yyruleno].nrhs; if( yysize ){ - fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", + fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n", yyTracePrompt, - yyruleno, yyRuleName[yyruleno], - yyrulenoyytos - yypParser->yystack)>yypParser->yyhwm ){ yypParser->yyhwm++; @@ -3010,11 +2603,11 @@ static YYACTIONTYPE yy_reduce( YYMINORTYPE yylhsminor; case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,210,&yymsp[0].minor); + yy_destructor(yypParser,211,&yymsp[0].minor); break; case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,211,&yymsp[0].minor); + yy_destructor(yypParser,212,&yymsp[0].minor); break; case 2: /* account_options ::= */ { } @@ -3028,20 +2621,20 @@ static YYACTIONTYPE yy_reduce( case 9: /* account_options ::= account_options USERS literal */ yytestcase(yyruleno==9); case 10: /* account_options ::= account_options CONNS literal */ yytestcase(yyruleno==10); case 11: /* account_options ::= account_options STATE literal */ yytestcase(yyruleno==11); -{ yy_destructor(yypParser,210,&yymsp[-2].minor); +{ yy_destructor(yypParser,211,&yymsp[-2].minor); { } - yy_destructor(yypParser,212,&yymsp[0].minor); + yy_destructor(yypParser,213,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ -{ yy_destructor(yypParser,213,&yymsp[0].minor); +{ yy_destructor(yypParser,214,&yymsp[0].minor); { } } break; case 13: /* alter_account_options ::= alter_account_options alter_account_option */ -{ yy_destructor(yypParser,211,&yymsp[-1].minor); +{ yy_destructor(yypParser,212,&yymsp[-1].minor); { } - yy_destructor(yypParser,213,&yymsp[0].minor); + yy_destructor(yypParser,214,&yymsp[0].minor); } break; case 14: /* alter_account_option ::= PASS literal */ @@ -3055,31 +2648,31 @@ static YYACTIONTYPE yy_reduce( case 22: /* alter_account_option ::= CONNS literal */ yytestcase(yyruleno==22); case 23: /* alter_account_option ::= STATE literal */ yytestcase(yyruleno==23); { } - yy_destructor(yypParser,212,&yymsp[0].minor); + yy_destructor(yypParser,213,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy29, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy409, &yymsp[0].minor.yy0); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy29, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy409, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } break; case 26: /* cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy29, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy409, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy29); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy409); } break; case 28: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy29, NULL); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy409, NULL); } break; case 29: /* cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy29, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy409, &yymsp[0].minor.yy0); } break; case 30: /* cmd ::= DROP DNODE NK_INTEGER */ { pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy0); } break; case 31: /* cmd ::= DROP DNODE dnode_endpoint */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy29); } +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy409); } break; case 32: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } @@ -3108,8 +2701,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.yy29 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy29 = yylhsminor.yy29; +{ yylhsminor.yy409 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy409 = yylhsminor.yy409; break; case 39: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } @@ -3142,156 +2735,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.yy47, &yymsp[-1].minor.yy29, yymsp[0].minor.yy182); } +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy121, &yymsp[-1].minor.yy409, yymsp[0].minor.yy504); } break; case 50: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy47, &yymsp[0].minor.yy29); } +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy121, &yymsp[0].minor.yy409); } break; case 51: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy29); } +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy409); } break; case 52: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy29, yymsp[0].minor.yy182); } +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy409, yymsp[0].minor.yy504); } break; case 53: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy47 = true; } +{ yymsp[-2].minor.yy121 = 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 350: /* set_quantifier_opt ::= */ yytestcase(yyruleno==350); -{ yymsp[1].minor.yy47 = false; } +{ yymsp[1].minor.yy121 = false; } break; case 55: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy47 = true; } +{ yymsp[-1].minor.yy121 = true; } break; case 57: /* db_options ::= */ -{ yymsp[1].minor.yy182 = createDatabaseOptions(pCxt); } +{ yymsp[1].minor.yy504 = createDatabaseOptions(pCxt); } break; case 58: /* db_options ::= db_options BLOCKS NK_INTEGER */ -{ ((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; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pNumOfBlocks = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 59: /* db_options ::= db_options CACHE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.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; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pCacheBlockSize = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 60: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.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; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pCachelast = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 61: /* db_options ::= db_options COMP NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.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; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pCompressionLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 62: /* db_options ::= db_options DAYS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.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; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pDaysPerFile = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 63: /* db_options ::= db_options DAYS NK_VARIABLE */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, &yymsp[0].minor.yy0); yylhsminor.yy182 = yymsp[-2].minor.yy182; } - yymsp[-2].minor.yy182 = yylhsminor.yy182; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 64: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.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; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pFsyncPeriod = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 65: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.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; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pMaxRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 66: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.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; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pMinRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 67: /* db_options ::= db_options KEEP integer_list */ case 68: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==68); -{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pKeep = yymsp[0].minor.yy334; yylhsminor.yy182 = yymsp[-2].minor.yy182; } - yymsp[-2].minor.yy182 = yylhsminor.yy182; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pKeep = yymsp[0].minor.yy488; yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 69: /* db_options ::= db_options PRECISION NK_STRING */ -{ ((SDatabaseOptions*)yymsp[-2].minor.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; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pPrecision = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 70: /* db_options ::= db_options QUORUM NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.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; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pQuorum = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 71: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.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; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pReplica = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 72: /* db_options ::= db_options TTL NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.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; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 73: /* db_options ::= db_options WAL NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.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; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pWalLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 74: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.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; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pNumOfVgroups = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 75: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.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; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pSingleStable = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 76: /* db_options ::= db_options STREAM_MODE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.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; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pStreamMode = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 77: /* db_options ::= db_options RETENTIONS retention_list */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy182)->pRetentions = yymsp[0].minor.yy334; yylhsminor.yy182 = yymsp[-2].minor.yy182; } - yymsp[-2].minor.yy182 = yylhsminor.yy182; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy504)->pRetentions = yymsp[0].minor.yy488; yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 78: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy182 = createDatabaseOptions(pCxt); yylhsminor.yy182 = setDatabaseAlterOption(pCxt, yylhsminor.yy182, &yymsp[0].minor.yy515); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createDatabaseOptions(pCxt); yylhsminor.yy504 = setDatabaseAlterOption(pCxt, yylhsminor.yy504, &yymsp[0].minor.yy21); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 79: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy182 = setDatabaseAlterOption(pCxt, yymsp[-1].minor.yy182, &yymsp[0].minor.yy515); } - yymsp[-1].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = setDatabaseAlterOption(pCxt, yymsp[-1].minor.yy504, &yymsp[0].minor.yy21); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 80: /* alter_db_option ::= BLOCKS NK_INTEGER */ -{ yymsp[-1].minor.yy515.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy515.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy21.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy21.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 81: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy515.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy515.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy21.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy21.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 82: /* alter_db_option ::= KEEP integer_list */ case 83: /* alter_db_option ::= KEEP variable_list */ yytestcase(yyruleno==83); -{ yymsp[-1].minor.yy515.type = DB_OPTION_KEEP; yymsp[-1].minor.yy515.pList = yymsp[0].minor.yy334; } +{ yymsp[-1].minor.yy21.type = DB_OPTION_KEEP; yymsp[-1].minor.yy21.pList = yymsp[0].minor.yy488; } break; case 84: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy515.type = DB_OPTION_WAL; yymsp[-1].minor.yy515.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy21.type = DB_OPTION_WAL; yymsp[-1].minor.yy21.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 85: /* alter_db_option ::= QUORUM NK_INTEGER */ -{ yymsp[-1].minor.yy515.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy515.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy21.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy21.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 86: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy515.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy515.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy21.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy21.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 87: /* alter_db_option ::= REPLICA NK_INTEGER */ -{ yymsp[-1].minor.yy515.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy515.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy21.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy21.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 88: /* integer_list ::= NK_INTEGER */ -{ yylhsminor.yy334 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy334 = yylhsminor.yy334; +{ yylhsminor.yy488 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy488 = yylhsminor.yy488; break; case 89: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ case 240: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==240); -{ yylhsminor.yy334 = addNodeToList(pCxt, yymsp[-2].minor.yy334, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy334 = yylhsminor.yy334; +{ yylhsminor.yy488 = addNodeToList(pCxt, yymsp[-2].minor.yy488, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy488 = yylhsminor.yy488; break; case 90: /* variable_list ::= NK_VARIABLE */ -{ yylhsminor.yy334 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy334 = yylhsminor.yy334; +{ yylhsminor.yy488 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy488 = yylhsminor.yy488; break; case 91: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ -{ yylhsminor.yy334 = addNodeToList(pCxt, yymsp[-2].minor.yy334, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy334 = yylhsminor.yy334; +{ yylhsminor.yy488 = addNodeToList(pCxt, yymsp[-2].minor.yy488, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy488 = yylhsminor.yy488; break; case 92: /* retention_list ::= retention */ case 112: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==112); @@ -3303,8 +2896,8 @@ static YYACTIONTYPE yy_reduce( case 263: /* literal_list ::= signed_literal */ yytestcase(yyruleno==263); case 355: /* select_sublist ::= select_item */ yytestcase(yyruleno==355); case 402: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==402); -{ yylhsminor.yy334 = createNodeList(pCxt, yymsp[0].minor.yy182); } - yymsp[0].minor.yy334 = yylhsminor.yy334; +{ yylhsminor.yy488 = createNodeList(pCxt, yymsp[0].minor.yy504); } + yymsp[0].minor.yy488 = yylhsminor.yy488; break; case 93: /* retention_list ::= retention_list NK_COMMA retention */ case 123: /* column_def_list ::= column_def_list NK_COMMA column_def */ yytestcase(yyruleno==123); @@ -3314,236 +2907,236 @@ static YYACTIONTYPE yy_reduce( case 264: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==264); case 356: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==356); case 403: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==403); -{ yylhsminor.yy334 = addNodeToList(pCxt, yymsp[-2].minor.yy334, yymsp[0].minor.yy182); } - yymsp[-2].minor.yy334 = yylhsminor.yy334; +{ yylhsminor.yy488 = addNodeToList(pCxt, yymsp[-2].minor.yy488, yymsp[0].minor.yy504); } + yymsp[-2].minor.yy488 = yylhsminor.yy488; break; case 94: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ -{ yylhsminor.yy182 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 95: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ case 97: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==97); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy47, yymsp[-5].minor.yy182, yymsp[-3].minor.yy334, yymsp[-1].minor.yy334, yymsp[0].minor.yy182); } +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy121, yymsp[-5].minor.yy504, yymsp[-3].minor.yy488, yymsp[-1].minor.yy488, yymsp[0].minor.yy504); } break; case 96: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy334); } +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy488); } break; case 98: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy334); } +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy488); } break; case 99: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy47, yymsp[0].minor.yy182); } +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy121, yymsp[0].minor.yy504); } break; case 100: /* cmd ::= ALTER TABLE alter_table_clause */ case 101: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==101); case 242: /* cmd ::= query_expression */ yytestcase(yyruleno==242); -{ pCxt->pRootNode = yymsp[0].minor.yy182; } +{ pCxt->pRootNode = yymsp[0].minor.yy504; } break; case 102: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy182 = createAlterTableOption(pCxt, yymsp[-1].minor.yy182, yymsp[0].minor.yy182); } - yymsp[-1].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createAlterTableOption(pCxt, yymsp[-1].minor.yy504, yymsp[0].minor.yy504); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 103: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.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; +{ yylhsminor.yy504 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy504, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy409, yymsp[0].minor.yy160); } + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 104: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy182 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy182, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy29); } - yymsp[-3].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy504, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy409); } + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; case 105: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.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; +{ yylhsminor.yy504 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy504, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy409, yymsp[0].minor.yy160); } + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 106: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.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; +{ yylhsminor.yy504 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy504, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy409, &yymsp[0].minor.yy409); } + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 107: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.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; +{ yylhsminor.yy504 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy504, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy409, yymsp[0].minor.yy160); } + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 108: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy182 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy182, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy29); } - yymsp[-3].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy504, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy409); } + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; case 109: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.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; +{ yylhsminor.yy504 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy504, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy409, yymsp[0].minor.yy160); } + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 110: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.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; +{ yylhsminor.yy504 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy504, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy409, &yymsp[0].minor.yy409); } + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 111: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ -{ yylhsminor.yy182 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy182, &yymsp[-2].minor.yy29, yymsp[0].minor.yy182); } - yymsp[-5].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy504, &yymsp[-2].minor.yy409, yymsp[0].minor.yy504); } + yymsp[-5].minor.yy504 = yylhsminor.yy504; break; case 113: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ case 116: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==116); -{ yylhsminor.yy334 = addNodeToList(pCxt, yymsp[-1].minor.yy334, yymsp[0].minor.yy182); } - yymsp[-1].minor.yy334 = yylhsminor.yy334; +{ yylhsminor.yy488 = addNodeToList(pCxt, yymsp[-1].minor.yy488, yymsp[0].minor.yy504); } + yymsp[-1].minor.yy488 = yylhsminor.yy488; break; case 114: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ -{ yylhsminor.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; +{ yylhsminor.yy504 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy121, yymsp[-7].minor.yy504, yymsp[-5].minor.yy504, yymsp[-4].minor.yy488, yymsp[-1].minor.yy488); } + yymsp[-8].minor.yy504 = yylhsminor.yy504; break; case 117: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy182 = createDropTableClause(pCxt, yymsp[-1].minor.yy47, yymsp[0].minor.yy182); } - yymsp[-1].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createDropTableClause(pCxt, yymsp[-1].minor.yy121, yymsp[0].minor.yy504); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 118: /* specific_tags_opt ::= */ case 149: /* tags_def_opt ::= */ yytestcase(yyruleno==149); case 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; } +{ yymsp[1].minor.yy488 = NULL; } break; case 119: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy334 = yymsp[-1].minor.yy334; } +{ yymsp[-2].minor.yy488 = yymsp[-1].minor.yy488; } break; case 120: /* full_table_name ::= table_name */ -{ yylhsminor.yy182 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy29, NULL); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy409, NULL); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 121: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy182 = createRealTableNode(pCxt, &yymsp[-2].minor.yy29, &yymsp[0].minor.yy29, NULL); } - yymsp[-2].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createRealTableNode(pCxt, &yymsp[-2].minor.yy409, &yymsp[0].minor.yy409, NULL); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 124: /* column_def ::= column_name type_name */ -{ yylhsminor.yy182 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy29, yymsp[0].minor.yy574, NULL); } - yymsp[-1].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy409, yymsp[0].minor.yy160, NULL); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 125: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy182 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy29, yymsp[-2].minor.yy574, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy409, yymsp[-2].minor.yy160, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; case 126: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_BOOL); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_BOOL); } break; case 127: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_TINYINT); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; case 128: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_SMALLINT); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; case 129: /* type_name ::= INT */ case 130: /* type_name ::= INTEGER */ yytestcase(yyruleno==130); -{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_INT); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_INT); } break; case 131: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_BIGINT); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; case 132: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_FLOAT); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; case 133: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_DOUBLE); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; case 134: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy574 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy160 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; case 135: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; case 136: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy574 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy160 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; case 137: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy574 = createDataType(TSDB_DATA_TYPE_UTINYINT); } +{ yymsp[-1].minor.yy160 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; case 138: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy574 = createDataType(TSDB_DATA_TYPE_USMALLINT); } +{ yymsp[-1].minor.yy160 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; case 139: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy574 = createDataType(TSDB_DATA_TYPE_UINT); } +{ yymsp[-1].minor.yy160 = createDataType(TSDB_DATA_TYPE_UINT); } break; case 140: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy574 = createDataType(TSDB_DATA_TYPE_UBIGINT); } +{ yymsp[-1].minor.yy160 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; case 141: /* type_name ::= JSON */ -{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_JSON); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_JSON); } break; case 142: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy574 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy160 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; case 143: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; case 144: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_BLOB); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_BLOB); } break; case 145: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy574 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy160 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; case 146: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy574 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[0].minor.yy160 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 147: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy574 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-3].minor.yy160 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 148: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy574 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-5].minor.yy160 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 150: /* tags_def_opt ::= tags_def */ case 354: /* select_list ::= select_sublist */ yytestcase(yyruleno==354); -{ yylhsminor.yy334 = yymsp[0].minor.yy334; } - yymsp[0].minor.yy334 = yylhsminor.yy334; +{ yylhsminor.yy488 = yymsp[0].minor.yy488; } + yymsp[0].minor.yy488 = yylhsminor.yy488; break; case 151: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy334 = yymsp[-1].minor.yy334; } +{ yymsp[-3].minor.yy488 = yymsp[-1].minor.yy488; } break; case 152: /* table_options ::= */ -{ yymsp[1].minor.yy182 = createTableOptions(pCxt); } +{ yymsp[1].minor.yy504 = createTableOptions(pCxt); } break; case 153: /* table_options ::= table_options COMMENT NK_STRING */ -{ ((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; +{ ((STableOptions*)yymsp[-2].minor.yy504)->pComments = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 154: /* table_options ::= table_options KEEP integer_list */ -{ ((STableOptions*)yymsp[-2].minor.yy182)->pKeep = yymsp[0].minor.yy334; yylhsminor.yy182 = yymsp[-2].minor.yy182; } - yymsp[-2].minor.yy182 = yylhsminor.yy182; +{ ((STableOptions*)yymsp[-2].minor.yy504)->pKeep = yymsp[0].minor.yy488; yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 155: /* table_options ::= table_options TTL NK_INTEGER */ -{ ((STableOptions*)yymsp[-2].minor.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; +{ ((STableOptions*)yymsp[-2].minor.yy504)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 156: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ ((STableOptions*)yymsp[-4].minor.yy182)->pSma = yymsp[-1].minor.yy334; yylhsminor.yy182 = yymsp[-4].minor.yy182; } - yymsp[-4].minor.yy182 = yylhsminor.yy182; +{ ((STableOptions*)yymsp[-4].minor.yy504)->pSma = yymsp[-1].minor.yy488; yylhsminor.yy504 = yymsp[-4].minor.yy504; } + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 157: /* table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ -{ ((STableOptions*)yymsp[-4].minor.yy182)->pFuncs = yymsp[-1].minor.yy334; yylhsminor.yy182 = yymsp[-4].minor.yy182; } - yymsp[-4].minor.yy182 = yylhsminor.yy182; +{ ((STableOptions*)yymsp[-4].minor.yy504)->pFuncs = yymsp[-1].minor.yy488; yylhsminor.yy504 = yymsp[-4].minor.yy504; } + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 158: /* table_options ::= table_options FILE_FACTOR NK_FLOAT */ -{ ((STableOptions*)yymsp[-2].minor.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; +{ ((STableOptions*)yymsp[-2].minor.yy504)->pFilesFactor = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 159: /* table_options ::= table_options DELAY NK_INTEGER */ -{ ((STableOptions*)yymsp[-2].minor.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; +{ ((STableOptions*)yymsp[-2].minor.yy504)->pDelay = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy504 = yymsp[-2].minor.yy504; } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 160: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy182 = createTableOptions(pCxt); yylhsminor.yy182 = setTableAlterOption(pCxt, yylhsminor.yy182, &yymsp[0].minor.yy515); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createTableOptions(pCxt); yylhsminor.yy504 = setTableAlterOption(pCxt, yylhsminor.yy504, &yymsp[0].minor.yy21); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 161: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy182 = setTableAlterOption(pCxt, yymsp[-1].minor.yy182, &yymsp[0].minor.yy515); } - yymsp[-1].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = setTableAlterOption(pCxt, yymsp[-1].minor.yy504, &yymsp[0].minor.yy21); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 162: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy515.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy515.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy21.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy21.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; case 163: /* alter_table_option ::= KEEP integer_list */ -{ yymsp[-1].minor.yy515.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy515.pList = yymsp[0].minor.yy334; } +{ yymsp[-1].minor.yy21.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy21.pList = yymsp[0].minor.yy488; } break; case 164: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy515.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy515.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy21.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy21.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 167: /* col_name ::= column_name */ -{ yylhsminor.yy182 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy29); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy409); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 168: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL, NULL); } @@ -3555,13 +3148,13 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL, NULL); } break; case 171: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy182, yymsp[0].minor.yy182); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy504, yymsp[0].minor.yy504); } break; case 172: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy182, yymsp[0].minor.yy182); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy504, yymsp[0].minor.yy504); } break; case 173: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy182, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy504, NULL); } break; case 174: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL, NULL); } @@ -3576,7 +3169,7 @@ static YYACTIONTYPE yy_reduce( { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT, NULL, NULL); } break; case 178: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy182, yymsp[0].minor.yy182); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy504, yymsp[0].minor.yy504); } break; case 179: /* cmd ::= SHOW STREAMS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); } @@ -3585,7 +3178,7 @@ static YYACTIONTYPE yy_reduce( { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } break; case 181: /* cmd ::= SHOW APPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); } +// { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); } break; case 182: /* cmd ::= SHOW CONNECTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT, NULL, NULL); } @@ -3595,25 +3188,25 @@ 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.yy29); } +// { 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.yy182); } +// { 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.yy182); } +// { 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); } break; case 189: /* cmd ::= SHOW SCORES */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT, NULL, NULL); } +// { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT, NULL, NULL); } break; case 190: /* cmd ::= SHOW TOPICS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT, NULL, NULL); } break; case 191: /* cmd ::= SHOW VARIABLES */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLE_STMT, NULL, NULL); } +// { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLE_STMT, NULL, NULL); } break; case 192: /* cmd ::= SHOW BNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT, NULL, NULL); } @@ -3623,11 +3216,11 @@ static YYACTIONTYPE yy_reduce( break; case 194: /* db_name_cond_opt ::= */ case 199: /* from_db_opt ::= */ yytestcase(yyruleno==199); -{ yymsp[1].minor.yy182 = createDefaultDatabaseCondValue(pCxt); } +{ yymsp[1].minor.yy504 = createDefaultDatabaseCondValue(pCxt); } break; case 195: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy29); } - yymsp[-1].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy409); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 196: /* like_pattern_opt ::= */ case 207: /* index_options ::= */ yytestcase(yyruleno==207); @@ -3638,96 +3231,96 @@ static YYACTIONTYPE yy_reduce( 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; } +{ yymsp[1].minor.yy504 = NULL; } break; case 197: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; case 198: /* table_name_cond ::= table_name */ -{ yylhsminor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy29); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy409); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 200: /* from_db_opt ::= FROM db_name */ -{ yymsp[-1].minor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy29); } +{ yymsp[-1].minor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy409); } break; case 203: /* func_name ::= function_name */ -{ yylhsminor.yy182 = createFunctionNode(pCxt, &yymsp[0].minor.yy29, NULL); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createFunctionNode(pCxt, &yymsp[0].minor.yy409, NULL); } + yymsp[0].minor.yy504 = yylhsminor.yy504; 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.yy47, &yymsp[-3].minor.yy29, &yymsp[-1].minor.yy29, NULL, yymsp[0].minor.yy182); } +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy121, &yymsp[-3].minor.yy409, &yymsp[-1].minor.yy409, NULL, yymsp[0].minor.yy504); } break; case 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.yy47, &yymsp[-5].minor.yy29, &yymsp[-3].minor.yy29, yymsp[-1].minor.yy334, NULL); } +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_FULLTEXT, yymsp[-6].minor.yy121, &yymsp[-5].minor.yy409, &yymsp[-3].minor.yy409, yymsp[-1].minor.yy488, NULL); } break; case 206: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy47, &yymsp[-2].minor.yy29, &yymsp[0].minor.yy29); } +{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy121, &yymsp[-2].minor.yy409, &yymsp[0].minor.yy409); } break; case 208: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ -{ yymsp[-8].minor.yy182 = createIndexOption(pCxt, yymsp[-6].minor.yy334, releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), NULL, yymsp[0].minor.yy182); } +{ yymsp[-8].minor.yy504 = createIndexOption(pCxt, yymsp[-6].minor.yy488, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), NULL, yymsp[0].minor.yy504); } 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.yy182 = createIndexOption(pCxt, yymsp[-8].minor.yy334, releaseRawExprNode(pCxt, yymsp[-4].minor.yy182), releaseRawExprNode(pCxt, yymsp[-2].minor.yy182), yymsp[0].minor.yy182); } +{ yymsp[-10].minor.yy504 = createIndexOption(pCxt, yymsp[-8].minor.yy488, releaseRawExprNode(pCxt, yymsp[-4].minor.yy504), releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), yymsp[0].minor.yy504); } break; case 212: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy182 = createFunctionNode(pCxt, &yymsp[-3].minor.yy29, yymsp[-1].minor.yy334); } - yymsp[-3].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createFunctionNode(pCxt, &yymsp[-3].minor.yy409, yymsp[-1].minor.yy488); } + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; case 213: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy47, &yymsp[-2].minor.yy29, yymsp[0].minor.yy182, NULL); } +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy121, &yymsp[-2].minor.yy409, yymsp[0].minor.yy504, NULL); } break; case 214: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy47, &yymsp[-2].minor.yy29, NULL, &yymsp[0].minor.yy29); } +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy121, &yymsp[-2].minor.yy409, NULL, &yymsp[0].minor.yy409); } break; case 215: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy47, &yymsp[0].minor.yy29); } +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy121, &yymsp[0].minor.yy409); } 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.yy182); } +{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy504); } 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.yy47, yymsp[-1].minor.yy182, yymsp[0].minor.yy182); } +{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy121, yymsp[-1].minor.yy504, yymsp[0].minor.yy504); } break; case 221: /* analyze_opt ::= ANALYZE */ case 229: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==229); case 351: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==351); -{ yymsp[0].minor.yy47 = true; } +{ yymsp[0].minor.yy121 = true; } break; case 222: /* explain_options ::= */ -{ yymsp[1].minor.yy182 = createDefaultExplainOptions(pCxt); } +{ yymsp[1].minor.yy504 = createDefaultExplainOptions(pCxt); } break; case 223: /* explain_options ::= explain_options VERBOSE NK_BOOL */ -{ yylhsminor.yy182 = setExplainVerbose(pCxt, yymsp[-2].minor.yy182, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = setExplainVerbose(pCxt, yymsp[-2].minor.yy504, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 224: /* explain_options ::= explain_options RATIO NK_FLOAT */ -{ yylhsminor.yy182 = setExplainRatio(pCxt, yymsp[-2].minor.yy182, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = setExplainRatio(pCxt, yymsp[-2].minor.yy504, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 225: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ -{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy334); } +{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy488); } 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.yy47, &yymsp[-5].minor.yy29, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy574, yymsp[0].minor.yy550); } +{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-7].minor.yy121, &yymsp[-5].minor.yy409, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy160, yymsp[0].minor.yy452); } break; case 227: /* cmd ::= DROP FUNCTION function_name */ -{ pCxt->pRootNode = createDropFunctionStmt(pCxt, &yymsp[0].minor.yy29); } +{ pCxt->pRootNode = createDropFunctionStmt(pCxt, &yymsp[0].minor.yy409); } break; case 230: /* bufsize_opt ::= */ -{ yymsp[1].minor.yy550 = 0; } +{ yymsp[1].minor.yy452 = 0; } break; case 231: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ -{ yymsp[-1].minor.yy550 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +{ yymsp[-1].minor.yy452 = 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.yy29, &yymsp[-2].minor.yy29, yymsp[0].minor.yy182); } +{ pCxt->pRootNode = createCreateStreamStmt(pCxt, &yymsp[-4].minor.yy409, &yymsp[-2].minor.yy409, yymsp[0].minor.yy504); } break; case 233: /* cmd ::= DROP STREAM stream_name */ -{ pCxt->pRootNode = createDropStreamStmt(pCxt, &yymsp[0].minor.yy29); } +{ pCxt->pRootNode = createDropStreamStmt(pCxt, &yymsp[0].minor.yy409); } break; case 234: /* cmd ::= KILL CONNECTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &yymsp[0].minor.yy0); } @@ -3739,36 +3332,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.yy334); } +{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy488); } 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.yy334 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } +{ yymsp[-1].minor.yy488 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } break; case 241: /* cmd ::= SYNCDB db_name REPLICA */ -{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy29); } +{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy409); } break; case 243: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy182 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 244: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy182 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 245: /* literal ::= NK_STRING */ -{ yylhsminor.yy182 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 246: /* literal ::= NK_BOOL */ -{ yylhsminor.yy182 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 247: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.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; +{ yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 248: /* literal ::= duration_literal */ case 257: /* signed_literal ::= signed */ yytestcase(yyruleno==257); @@ -3786,157 +3379,153 @@ static YYACTIONTYPE yy_reduce( 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; +{ yylhsminor.yy504 = yymsp[0].minor.yy504; } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 249: /* literal ::= NULL */ -{ yylhsminor.yy182 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL)); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL)); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 250: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy182 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 251: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 252: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 253: /* signed ::= NK_MINUS NK_INTEGER */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy182 = yylhsminor.yy182; + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 254: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 255: /* signed ::= NK_PLUS NK_FLOAT */ -{ yymsp[-1].minor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy504 = 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.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy182 = yylhsminor.yy182; + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 258: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 259: /* signed_literal ::= NK_BOOL */ -{ yylhsminor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 260: /* signed_literal ::= TIMESTAMP NK_STRING */ -{ yymsp[-1].minor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; case 261: /* signed_literal ::= duration_literal */ case 357: /* select_item ::= common_expression */ yytestcase(yyruleno==357); case 401: /* search_condition ::= common_expression */ yytestcase(yyruleno==401); -{ yylhsminor.yy182 = releaseRawExprNode(pCxt, yymsp[0].minor.yy182); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = releaseRawExprNode(pCxt, yymsp[0].minor.yy504); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 262: /* signed_literal ::= NULL */ -{ yymsp[0].minor.yy182 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } +{ yymsp[0].minor.yy504 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } break; case 280: /* expression ::= function_name NK_LP expression_list NK_RP */ -{ 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; +{ yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy409, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy409, yymsp[-1].minor.yy488)); } + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; case 281: /* expression ::= function_name NK_LP NK_STAR NK_RP */ -{ 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; +{ yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy409, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy409, createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[-1].minor.yy0)))); } + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; - case 282: /* expression ::= function_name NK_LP expression AS type_name NK_RP */ -{ - 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.yy182 = yylhsminor.yy182; + case 282: /* expression ::= CAST NK_LP expression AS type_name NK_RP */ +{ yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy504), yymsp[-1].minor.yy160)); } + yymsp[-5].minor.yy504 = yylhsminor.yy504; break; case 284: /* expression ::= NK_LP expression NK_RP */ 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; +{ yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy504)); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 285: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy182); - yylhsminor.yy182 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy182)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy504)); } - yymsp[-1].minor.yy182 = yylhsminor.yy182; + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 286: /* expression ::= NK_MINUS expression */ { - 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)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy504), NULL)); } - yymsp[-1].minor.yy182 = yylhsminor.yy182; + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 287: /* expression ::= expression NK_PLUS expression */ { - 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))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-2].minor.yy182 = yylhsminor.yy182; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 288: /* expression ::= expression NK_MINUS expression */ { - 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))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-2].minor.yy182 = yylhsminor.yy182; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 289: /* expression ::= expression NK_STAR expression */ { - 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))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-2].minor.yy182 = yylhsminor.yy182; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 290: /* expression ::= expression NK_SLASH expression */ { - 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))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-2].minor.yy182 = yylhsminor.yy182; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 291: /* expression ::= expression NK_REM expression */ { - 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))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-2].minor.yy182 = yylhsminor.yy182; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 292: /* expression_list ::= expression */ -{ yylhsminor.yy334 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy182)); } - yymsp[0].minor.yy334 = yylhsminor.yy334; +{ yylhsminor.yy488 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy504)); } + yymsp[0].minor.yy488 = yylhsminor.yy488; break; case 293: /* expression_list ::= expression_list NK_COMMA expression */ -{ yylhsminor.yy334 = addNodeToList(pCxt, yymsp[-2].minor.yy334, releaseRawExprNode(pCxt, yymsp[0].minor.yy182)); } - yymsp[-2].minor.yy334 = yylhsminor.yy334; +{ yylhsminor.yy488 = addNodeToList(pCxt, yymsp[-2].minor.yy488, releaseRawExprNode(pCxt, yymsp[0].minor.yy504)); } + yymsp[-2].minor.yy488 = yylhsminor.yy488; break; case 294: /* column_reference ::= column_name */ -{ yylhsminor.yy182 = createRawExprNode(pCxt, &yymsp[0].minor.yy29, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy29)); } - yymsp[0].minor.yy182 = yylhsminor.yy182; +{ yylhsminor.yy504 = createRawExprNode(pCxt, &yymsp[0].minor.yy409, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy409)); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 295: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.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; +{ yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy409, &yymsp[0].minor.yy409, createColumnNode(pCxt, &yymsp[-2].minor.yy409, &yymsp[0].minor.yy409)); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 296: /* pseudo_column ::= NOW */ case 297: /* pseudo_column ::= TODAY */ yytestcase(yyruleno==297); @@ -3947,290 +3536,290 @@ static YYACTIONTYPE yy_reduce( 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; +{ yylhsminor.yy504 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } + yymsp[0].minor.yy504 = yylhsminor.yy504; break; case 305: /* predicate ::= expression compare_op expression */ case 310: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==310); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.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))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy84, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-2].minor.yy182 = yylhsminor.yy182; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 306: /* predicate ::= expression BETWEEN expression AND expression */ { - 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))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy504), releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-4].minor.yy182 = yylhsminor.yy182; + yymsp[-4].minor.yy504 = yylhsminor.yy504; break; case 307: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - 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))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[-5].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-5].minor.yy182 = yylhsminor.yy182; + yymsp[-5].minor.yy504 = yylhsminor.yy504; break; case 308: /* predicate ::= expression IS 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)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), NULL)); } - yymsp[-2].minor.yy182 = yylhsminor.yy182; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 309: /* predicate ::= expression IS NOT 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)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy504), NULL)); } - yymsp[-3].minor.yy182 = yylhsminor.yy182; + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; case 311: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy380 = OP_TYPE_LOWER_THAN; } +{ yymsp[0].minor.yy84 = OP_TYPE_LOWER_THAN; } break; case 312: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy380 = OP_TYPE_GREATER_THAN; } +{ yymsp[0].minor.yy84 = OP_TYPE_GREATER_THAN; } break; case 313: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy380 = OP_TYPE_LOWER_EQUAL; } +{ yymsp[0].minor.yy84 = OP_TYPE_LOWER_EQUAL; } break; case 314: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy380 = OP_TYPE_GREATER_EQUAL; } +{ yymsp[0].minor.yy84 = OP_TYPE_GREATER_EQUAL; } break; case 315: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy380 = OP_TYPE_NOT_EQUAL; } +{ yymsp[0].minor.yy84 = OP_TYPE_NOT_EQUAL; } break; case 316: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy380 = OP_TYPE_EQUAL; } +{ yymsp[0].minor.yy84 = OP_TYPE_EQUAL; } break; case 317: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy380 = OP_TYPE_LIKE; } +{ yymsp[0].minor.yy84 = OP_TYPE_LIKE; } break; case 318: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy380 = OP_TYPE_NOT_LIKE; } +{ yymsp[-1].minor.yy84 = OP_TYPE_NOT_LIKE; } break; case 319: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy380 = OP_TYPE_MATCH; } +{ yymsp[0].minor.yy84 = OP_TYPE_MATCH; } break; case 320: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy380 = OP_TYPE_NMATCH; } +{ yymsp[0].minor.yy84 = OP_TYPE_NMATCH; } break; case 321: /* in_op ::= IN */ -{ yymsp[0].minor.yy380 = OP_TYPE_IN; } +{ yymsp[0].minor.yy84 = OP_TYPE_IN; } break; case 322: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy380 = OP_TYPE_NOT_IN; } +{ yymsp[-1].minor.yy84 = OP_TYPE_NOT_IN; } break; 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; +{ yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy488)); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 325: /* boolean_value_expression ::= NOT boolean_primary */ { - 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)); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy504), NULL)); } - yymsp[-1].minor.yy182 = yylhsminor.yy182; + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 326: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - 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))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-2].minor.yy182 = yylhsminor.yy182; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 327: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { - 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))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy504); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy504); + yylhsminor.yy504 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } - yymsp[-2].minor.yy182 = yylhsminor.yy182; + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; 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; } +{ yymsp[-1].minor.yy504 = yymsp[0].minor.yy504; } break; 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; +{ yylhsminor.yy504 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy504, yymsp[0].minor.yy504, NULL); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; 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; +{ yylhsminor.yy504 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy409, &yymsp[0].minor.yy409); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; 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; +{ yylhsminor.yy504 = createRealTableNode(pCxt, &yymsp[-3].minor.yy409, &yymsp[-1].minor.yy409, &yymsp[0].minor.yy409); } + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; 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; +{ yylhsminor.yy504 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy504), &yymsp[0].minor.yy409); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; case 341: /* alias_opt ::= */ -{ yymsp[1].minor.yy29 = nil_token; } +{ yymsp[1].minor.yy409 = nil_token; } break; case 342: /* alias_opt ::= table_alias */ -{ yylhsminor.yy29 = yymsp[0].minor.yy29; } - yymsp[0].minor.yy29 = yylhsminor.yy29; +{ yylhsminor.yy409 = yymsp[0].minor.yy409; } + yymsp[0].minor.yy409 = yylhsminor.yy409; break; case 343: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy29 = yymsp[0].minor.yy29; } +{ yymsp[-1].minor.yy409 = yymsp[0].minor.yy409; } break; 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; } +{ yymsp[-2].minor.yy504 = yymsp[-1].minor.yy504; } break; 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; +{ yylhsminor.yy504 = createJoinTableNode(pCxt, yymsp[-4].minor.yy556, yymsp[-5].minor.yy504, yymsp[-2].minor.yy504, yymsp[0].minor.yy504); } + yymsp[-5].minor.yy504 = yylhsminor.yy504; break; case 347: /* join_type ::= */ -{ yymsp[1].minor.yy162 = JOIN_TYPE_INNER; } +{ yymsp[1].minor.yy556 = JOIN_TYPE_INNER; } break; case 348: /* join_type ::= INNER */ -{ yymsp[0].minor.yy162 = JOIN_TYPE_INNER; } +{ yymsp[0].minor.yy556 = JOIN_TYPE_INNER; } break; 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.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); + yymsp[-8].minor.yy504 = createSelectStmt(pCxt, yymsp[-7].minor.yy121, yymsp[-6].minor.yy488, yymsp[-5].minor.yy504); + yymsp[-8].minor.yy504 = addWhereClause(pCxt, yymsp[-8].minor.yy504, yymsp[-4].minor.yy504); + yymsp[-8].minor.yy504 = addPartitionByClause(pCxt, yymsp[-8].minor.yy504, yymsp[-3].minor.yy488); + yymsp[-8].minor.yy504 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy504, yymsp[-2].minor.yy504); + yymsp[-8].minor.yy504 = addGroupByClause(pCxt, yymsp[-8].minor.yy504, yymsp[-1].minor.yy488); + yymsp[-8].minor.yy504 = addHavingClause(pCxt, yymsp[-8].minor.yy504, yymsp[0].minor.yy504); } break; case 352: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy47 = false; } +{ yymsp[0].minor.yy121 = false; } break; case 353: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy334 = NULL; } +{ yymsp[0].minor.yy488 = NULL; } break; 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; +{ yylhsminor.yy504 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy504), &yymsp[0].minor.yy409); } + yymsp[-1].minor.yy504 = yylhsminor.yy504; break; 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; +{ yylhsminor.yy504 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), &yymsp[0].minor.yy409); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; 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; +{ yylhsminor.yy504 = createColumnNode(pCxt, &yymsp[-2].minor.yy409, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; 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; } +{ yymsp[-2].minor.yy488 = yymsp[0].minor.yy488; } break; 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)); } +{ yymsp[-5].minor.yy504 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy504), releaseRawExprNode(pCxt, yymsp[-1].minor.yy504)); } break; case 367: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ -{ yymsp[-3].minor.yy182 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy182)); } +{ yymsp[-3].minor.yy504 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy504)); } break; 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); } +{ yymsp[-5].minor.yy504 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy504), NULL, yymsp[-1].minor.yy504, yymsp[0].minor.yy504); } break; 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); } +{ yymsp[-7].minor.yy504 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy504), releaseRawExprNode(pCxt, yymsp[-3].minor.yy504), yymsp[-1].minor.yy504, yymsp[0].minor.yy504); } break; case 371: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ -{ yymsp[-3].minor.yy182 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy182); } +{ yymsp[-3].minor.yy504 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy504); } break; case 373: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy182 = createFillNode(pCxt, yymsp[-1].minor.yy144, NULL); } +{ yymsp[-3].minor.yy504 = createFillNode(pCxt, yymsp[-1].minor.yy22, NULL); } break; 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)); } +{ yymsp[-5].minor.yy504 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy488)); } break; case 375: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy144 = FILL_MODE_NONE; } +{ yymsp[0].minor.yy22 = FILL_MODE_NONE; } break; case 376: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy144 = FILL_MODE_PREV; } +{ yymsp[0].minor.yy22 = FILL_MODE_PREV; } break; case 377: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy144 = FILL_MODE_NULL; } +{ yymsp[0].minor.yy22 = FILL_MODE_NULL; } break; case 378: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy144 = FILL_MODE_LINEAR; } +{ yymsp[0].minor.yy22 = FILL_MODE_LINEAR; } break; case 379: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy144 = FILL_MODE_NEXT; } +{ yymsp[0].minor.yy22 = FILL_MODE_NEXT; } break; case 382: /* group_by_list ::= expression */ -{ yylhsminor.yy334 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy182))); } - yymsp[0].minor.yy334 = yylhsminor.yy334; +{ yylhsminor.yy488 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } + yymsp[0].minor.yy488 = yylhsminor.yy488; break; 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; +{ yylhsminor.yy488 = addNodeToList(pCxt, yymsp[-2].minor.yy488, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy504))); } + yymsp[-2].minor.yy488 = yylhsminor.yy488; break; case 386: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - 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); + yylhsminor.yy504 = addOrderByClause(pCxt, yymsp[-3].minor.yy504, yymsp[-2].minor.yy488); + yylhsminor.yy504 = addSlimitClause(pCxt, yylhsminor.yy504, yymsp[-1].minor.yy504); + yylhsminor.yy504 = addLimitClause(pCxt, yylhsminor.yy504, yymsp[0].minor.yy504); } - yymsp[-3].minor.yy182 = yylhsminor.yy182; + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; 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; +{ yylhsminor.yy504 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy504, yymsp[0].minor.yy504); } + yymsp[-3].minor.yy504 = yylhsminor.yy504; break; case 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); } +{ yymsp[-1].minor.yy504 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; 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); } +{ yymsp[-3].minor.yy504 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; 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); } +{ yymsp[-3].minor.yy504 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; 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; +{ yylhsminor.yy504 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy504); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; 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; +{ yylhsminor.yy504 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy504), yymsp[-1].minor.yy522, yymsp[0].minor.yy281); } + yymsp[-2].minor.yy504 = yylhsminor.yy504; break; case 405: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy218 = ORDER_ASC; } +{ yymsp[1].minor.yy522 = ORDER_ASC; } break; case 406: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy218 = ORDER_ASC; } +{ yymsp[0].minor.yy522 = ORDER_ASC; } break; case 407: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy218 = ORDER_DESC; } +{ yymsp[0].minor.yy522 = ORDER_DESC; } break; case 408: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy487 = NULL_ORDER_DEFAULT; } +{ yymsp[1].minor.yy281 = NULL_ORDER_DEFAULT; } break; case 409: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy487 = NULL_ORDER_FIRST; } +{ yymsp[-1].minor.yy281 = NULL_ORDER_FIRST; } break; case 410: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy487 = NULL_ORDER_LAST; } +{ yymsp[-1].minor.yy281 = NULL_ORDER_LAST; } break; default: break; /********** End reduce actions ************************************************/ }; - assert( yyrulenopOutputDataBlockDesc; + SDataBlockDescNode* pRightDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 1))->pOutputDataBlockDesc; int32_t code = TSDB_CODE_SUCCESS; pJoin->joinType = pJoinLogicNode->joinType; if (NULL != pJoinLogicNode->pOnConditions) { - SDataBlockDescNode* pLeftDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc; - SDataBlockDescNode* pRightDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 1))->pOutputDataBlockDesc; code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pOnConditions, &pJoin->pOnConditions); } if (TSDB_CODE_SUCCESS == code) { - pJoin->pTargets = nodesCloneList(pJoinLogicNode->node.pTargets); - if (NULL == pJoin->pTargets) { - code = TSDB_CODE_OUT_OF_MEMORY; - } + code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->node.pTargets, &pJoin->pTargets); } if (TSDB_CODE_SUCCESS == code) { code = addDataBlockSlots(pCxt, pJoin->pTargets, pJoin->node.pOutputDataBlockDesc); diff --git a/source/libs/planner/test/plannerTest.cpp b/source/libs/planner/test/plannerTest.cpp index 69c76fc3aef0433656d046abf9a226506d4970fd..48aa89eae6721f4fcd7ab3566c565330230b88cf 100644 --- a/source/libs/planner/test/plannerTest.cpp +++ b/source/libs/planner/test/plannerTest.cpp @@ -180,11 +180,11 @@ TEST_F(PlannerTest, selectStableBasic) { TEST_F(PlannerTest, selectJoin) { setDatabase("root", "test"); - // bind("SELECT t1.c1, t2.c2 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 t1.*, t2.* FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); - // ASSERT_TRUE(run()); + bind("SELECT t1.*, t2.* FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts"); + ASSERT_TRUE(run()); 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/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 4d57af822ea9cc938d36b208febce7b4a3cd1903..a3806893c775ccf7456f95aa84130d9c6c498ae4 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -331,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; @@ -363,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; } } @@ -444,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; } } diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 8dd76253253776ec8fd04ceba2b5bbc66f1a97c5..93bc16a7a2e2669d5e8c36c59408f3e1fb72d66b 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/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/util/src/tprocess.c b/source/util/src/tprocess.c index 2cafd3f7f6c9b6f9916f6314788a06e8346982ef..ae7b3d6f1f9552d91c8ea50faba183260fa7d578 100644 --- a/source/util/src/tprocess.c +++ b/source/util/src/tprocess.c @@ -154,7 +154,7 @@ static void taosProcCleanupQueue(SProcQueue *pQueue) { } static int32_t taosProcQueuePush(SProcObj *pProc, SProcQueue *pQueue, const char *pHead, int16_t rawHeadLen, - const char *pBody, int32_t rawBodyLen, int64_t handle, ProcFuncType ftype) { + const char *pBody, int32_t rawBodyLen, int64_t handle, EProcFuncType ftype) { if (rawHeadLen == 0 || pHead == NULL) { terrno = TSDB_CODE_INVALID_PARA; return -1; @@ -171,7 +171,7 @@ static int32_t taosProcQueuePush(SProcObj *pProc, SProcQueue *pQueue, const char return -1; } - if (handle != 0 && ftype == PROC_REQ) { + if (handle != 0 && ftype == PROC_FUNC_REQ) { if (taosHashPut(pProc->hash, &handle, sizeof(int64_t), &handle, sizeof(int64_t)) != 0) { taosThreadMutexUnlock(&pQueue->mutex); terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -232,7 +232,7 @@ static int32_t taosProcQueuePush(SProcObj *pProc, SProcQueue *pQueue, const char } static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHeadLen, void **ppBody, int32_t *pBodyLen, - ProcFuncType *pFuncType, ProcMallocFp mallocHeadFp, ProcFreeFp freeHeadFp, + EProcFuncType *pFuncType, ProcMallocFp mallocHeadFp, ProcFreeFp freeHeadFp, ProcMallocFp mallocBodyFp, ProcFreeFp freeBodyFp) { tsem_wait(&pQueue->sem); @@ -309,7 +309,7 @@ static int32_t taosProcQueuePop(SProcQueue *pQueue, void **ppHead, int16_t *pHea *ppBody = pBody; *pHeadLen = rawHeadLen; *pBodyLen = rawBodyLen; - *pFuncType = (ProcFuncType)ftype; + *pFuncType = (EProcFuncType)ftype; uTrace("proc:%s, pop msg at pos:%d ftype:%d remain:%d, head:%d %p body:%d %p", pQueue->name, pos, ftype, pQueue->items, rawHeadLen, pHead, rawBodyLen, pBody); @@ -364,7 +364,7 @@ SProcObj *taosProcInit(const SProcCfg *pCfg) { static void taosProcThreadLoop(SProcObj *pProc) { void *pHead, *pBody; int16_t headLen; - ProcFuncType ftype; + EProcFuncType ftype; int32_t bodyLen; SProcQueue *pQueue; ProcConsumeFp consumeFp; @@ -454,8 +454,8 @@ void taosProcCleanup(SProcObj *pProc) { } int32_t taosProcPutToChildQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, - void *handle, ProcFuncType ftype) { - if (ftype != PROC_REQ) { + void *handle, EProcFuncType ftype) { + if (ftype != PROC_FUNC_REQ) { terrno = TSDB_CODE_INVALID_PARA; return -1; } @@ -482,7 +482,7 @@ void taosProcCloseHandles(SProcObj *pProc, void (*HandleFp)(void *handle)) { } void taosProcPutToParentQ(SProcObj *pProc, const void *pHead, int16_t headLen, const void *pBody, int32_t bodyLen, - ProcFuncType ftype) { + EProcFuncType ftype) { int32_t retry = 0; while (taosProcQueuePush(pProc, pProc->pParentQueue, pHead, headLen, pBody, bodyLen, 0, ftype) != 0) { uWarn("proc:%s, failed to put to queue:%p since %s, retry:%d", pProc->name, pProc->pParentQueue, terrstr(), retry); diff --git a/source/util/test/procTest.cpp b/source/util/test/procTest.cpp index 54aaf496735c6657508ce2e995f97da3aa1fe612..e05008e8e14598a3c9f3534811d1707f889f999a 100644 --- a/source/util/test/procTest.cpp +++ b/source/util/test/procTest.cpp @@ -89,7 +89,7 @@ TEST_F(UtilTesProc, 00_Init_Cleanup) { taosDropShm(&shm); } -void ConsumeChild1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, ProcFuncType ftype) { +void ConsumeChild1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) { STestMsg msg; memcpy(&msg, pHead, headLen); char body[2000] = {0}; @@ -120,20 +120,20 @@ TEST_F(UtilTesProc, 01_Push_Pop_Child) { SProcObj *cproc = taosProcInit(&cfg); ASSERT_NE(cproc, nullptr); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_RSP), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_REGIST), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_RELEASE), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, NULL, 12, body, 0, 0, PROC_REQ), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_REQ), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, shm.size, body, 0, 0, PROC_REQ), 0); - ASSERT_NE(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, shm.size, 0, PROC_REQ), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_FUNC_RSP), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_FUNC_REGIST), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_FUNC_RELEASE), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, NULL, 12, body, 0, 0, PROC_FUNC_REQ), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, 0, body, 0, 0, PROC_FUNC_REQ), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, shm.size, body, 0, 0, PROC_FUNC_REQ), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, shm.size, 0, PROC_FUNC_REQ), 0); for (int32_t j = 0; j < 1000; j++) { int32_t i = 0; for (i = 0; i < 20; ++i) { - ASSERT_EQ(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, 0, PROC_REQ), 0); + ASSERT_EQ(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, 0, PROC_FUNC_REQ), 0); } - ASSERT_NE(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, 0, PROC_REQ), 0); + ASSERT_NE(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, 0, PROC_FUNC_REQ), 0); cfg.isChild = true; cfg.name = "1235_p"; @@ -147,7 +147,7 @@ TEST_F(UtilTesProc, 01_Push_Pop_Child) { taosDropShm(&shm); } -void ConsumeParent1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, ProcFuncType ftype) { +void ConsumeParent1(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) { STestMsg msg; memcpy(&msg, pHead, headLen); char body[2000] = {0}; @@ -186,7 +186,7 @@ TEST_F(UtilTesProc, 02_Push_Pop_Parent) { for (int32_t j = 0; j < 1000; j++) { int32_t i = 0; for (i = 0; i < 20; ++i) { - taosProcPutToParentQ(pproc, &head, sizeof(STestMsg), body, i, PROC_REQ); + taosProcPutToParentQ(pproc, &head, sizeof(STestMsg), body, i, PROC_FUNC_REQ); } taosProcRun(cproc); @@ -198,7 +198,7 @@ TEST_F(UtilTesProc, 02_Push_Pop_Parent) { taosDropShm(&shm); } -void ConsumeChild3(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, ProcFuncType ftype) { +void ConsumeChild3(void *parent, void *pHead, int16_t headLen, void *pBody, int32_t bodyLen, EProcFuncType ftype) { STestMsg msg; memcpy(&msg, pHead, headLen); char body[2000] = {0}; @@ -236,7 +236,7 @@ TEST_F(UtilTesProc, 03_Handle) { int32_t i = 0; for (i = 0; i < 20; ++i) { head.handle = (void *)((int64_t)i); - ASSERT_EQ(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, (void *)((int64_t)i), PROC_REQ), 0); + ASSERT_EQ(taosProcPutToChildQ(cproc, &head, sizeof(STestMsg), body, i, (void *)((int64_t)i), PROC_FUNC_REQ), 0); } cfg.isChild = true; diff --git a/tests/pytest/concurrent_inquiry.sh b/tests/pytest/concurrent_inquiry.sh index 6ac15fb46fd727ca56b1aef7e7137ef822e5244a..4cb1709bef4d6a7c363db83dcedde7eb725ec0c4 100755 --- a/tests/pytest/concurrent_inquiry.sh +++ b/tests/pytest/concurrent_inquiry.sh @@ -35,11 +35,11 @@ CURR_DIR=`pwd` IN_TDINTERNAL="community" if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then TAOS_DIR=$CURR_DIR/../../.. - TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1` + TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1` LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6,7|rev`/lib else TAOS_DIR=$CURR_DIR/../.. - TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1` + TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1` LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6|rev`/lib fi diff --git a/tests/pytest/crash_gen.sh b/tests/pytest/crash_gen.sh index 127e13c5be1ea562cbe536bbb05f6ecd5844b0ea..1c28abfdf4bd82e7ab559f19db6012c7ac72874f 100755 --- a/tests/pytest/crash_gen.sh +++ b/tests/pytest/crash_gen.sh @@ -35,11 +35,11 @@ CURR_DIR=`pwd` IN_TDINTERNAL="community" if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then TAOS_DIR=$CURR_DIR/../../.. - TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1` + TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1` LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6,7|rev`/lib else TAOS_DIR=$CURR_DIR/../.. - TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1` + TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1` LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6|rev`/lib fi diff --git a/tests/pytest/insert/bigint.py b/tests/pytest/insert/bigint.py index 7c7d2d0f9507e8688dd73bcefe88632361c80c70..5431cf8106fdbcd74bdd310de45039badb3bce7f 100644 --- a/tests/pytest/insert/bigint.py +++ b/tests/pytest/insert/bigint.py @@ -54,10 +54,6 @@ class TDTestCase: tdSql.checkData(0, 1, 9223372036854770000) tdLog.info('drop database db') tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) # convert end def stop(self): diff --git a/tests/pytest/insert/double.py b/tests/pytest/insert/double.py index 1b66ed1c44c7cec645be1f0f23866c7f06501ebc..2699f4b0e95897de47d461f885690e2b8a7863d7 100644 --- a/tests/pytest/insert/double.py +++ b/tests/pytest/insert/double.py @@ -75,10 +75,6 @@ class TDTestCase: tdSql.checkData(0, 1, 2.000000000) tdLog.info('drop database db') tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) # convert end def stop(self): diff --git a/tests/pytest/insert/smallint.py b/tests/pytest/insert/smallint.py index 16322e9aeb801ae92b75b920922991206a4b2e35..1a1eab6a98912639aa845e7aae552fdd49278a5b 100644 --- a/tests/pytest/insert/smallint.py +++ b/tests/pytest/insert/smallint.py @@ -91,10 +91,6 @@ class TDTestCase: tdSql.checkData(0, 1, 2) tdLog.info('drop database db') tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) # convert end def stop(self): diff --git a/tests/pytest/insert/timestamp.py b/tests/pytest/insert/timestamp.py new file mode 100644 index 0000000000000000000000000000000000000000..d5ddffcfafbade7b59fb32269a58b5ae0c9c0fdc --- /dev/null +++ b/tests/pytest/insert/timestamp.py @@ -0,0 +1,93 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys + +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + self.ts = 1607281690000 + + def run(self): + tdSql.prepare() + + # TS-806 + tdLog.info("test case for TS-806") + + # Case 1 + tdSql.execute("create table t1(ts timestamp, c1 int)") + tdSql.execute("insert into t1(c1, ts) values(1, %d)" % self.ts) + tdSql.query("select * from t1") + tdSql.checkRows(1) + + # Case 2 + tdSql.execute( + "insert into t1(c1, ts) values(2, %d)(3, %d)" % + (self.ts + 1000, self.ts + 2000)) + tdSql.query("select * from t1") + tdSql.checkRows(3) + + # Case 3 + tdSql.execute("create table t2(ts timestamp, c1 timestamp)") + tdSql.execute( + " insert into t2(c1, ts) values(%d, %d)" % + (self.ts, self.ts + 5000)) + tdSql.query("select * from t2") + tdSql.checkRows(1) + + tdSql.execute( + " insert into t2(c1, ts) values(%d, %d)(%d, %d)" % + (self.ts, self.ts + 6000, self.ts + 3000, self.ts + 8000)) + tdSql.query("select * from t2") + tdSql.checkRows(3) + + # Case 4 + tdSql.execute( + "create table stb(ts timestamp, c1 int, c2 binary(20)) tags(tstag timestamp, t1 int)") + tdSql.execute( + "insert into tb1(c2, ts, c1) using stb(t1, tstag) tags(1, now) values('test', %d, 1)" % + self.ts) + tdSql.query("select * from stb") + tdSql.checkRows(1) + + # Case 5 + tdSql.execute( + "insert into tb1(c2, ts, c1) using stb(t1, tstag) tags(1, now) values('test', now, 1) tb2(c1, ts) using stb tags(now + 2m, 1000) values(1, now - 1h)") + tdSql.query("select * from stb") + tdSql.checkRows(3) + + tdSql.execute(" insert into tb1(c2, ts, c1) using stb(t1, tstag) tags(1, now) values('test', now + 10s, 1) tb2(c1, ts) using stb(tstag) tags(now + 2m) values(1, now - 3h)(2, now - 2h)") + tdSql.query("select * from stb") + tdSql.checkRows(6) + + # Case 6 + tdSql.execute( + "create table stb2 (ts timestamp, c1 timestamp, c2 timestamp) tags(t1 timestamp, t2 timestamp)") + tdSql.execute(" insert into tb4(c1, c2, ts) using stb2(t2, t1) tags(now, now + 1h) values(now + 1s, now + 2s, now + 3s)(now -1s, now - 2s, now - 3s) tb5(c2, ts, c1) using stb2(t2) tags(now + 1h) values(now, now, now)") + tdSql.query("select * from stb2") + tdSql.checkRows(3) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/insert/tinyint.py b/tests/pytest/insert/tinyint.py index a10c999e8c2f0fe070347651f9246e3734104eca..a27b60aa724a93c7ccd40d521f0ee09c066c53d3 100644 --- a/tests/pytest/insert/tinyint.py +++ b/tests/pytest/insert/tinyint.py @@ -91,10 +91,6 @@ class TDTestCase: tdSql.checkData(0, 1, 2) tdLog.info('drop database db') tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) # convert end def stop(self): diff --git a/tests/pytest/insert/unsignedBigint.py b/tests/pytest/insert/unsignedBigint.py index b222f2cd0195e14fddf1f10662447cef97f0e841..0e99afa14207ed7e4426483c2276ec9b643f5873 100644 --- a/tests/pytest/insert/unsignedBigint.py +++ b/tests/pytest/insert/unsignedBigint.py @@ -93,10 +93,6 @@ class TDTestCase: tdSql.checkData(0, 1, 2) tdLog.info('drop database db') tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) # convert end def stop(self): diff --git a/tests/pytest/insert/unsignedInt.py b/tests/pytest/insert/unsignedInt.py index ed18999bc415022da34788a79e9045a5f67cf8ee..f38964677f99b945a136fe9e9ae58073edaba102 100644 --- a/tests/pytest/insert/unsignedInt.py +++ b/tests/pytest/insert/unsignedInt.py @@ -93,10 +93,6 @@ class TDTestCase: tdSql.checkData(0, 1, 2) tdLog.info('drop database db') tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) # convert end def stop(self): diff --git a/tests/pytest/insert/unsignedSmallint.py b/tests/pytest/insert/unsignedSmallint.py index 9893c470ce1a53a05138dd9d5c18e2b0a9f21374..815390868b530ed4321b23ee8776421941640176 100644 --- a/tests/pytest/insert/unsignedSmallint.py +++ b/tests/pytest/insert/unsignedSmallint.py @@ -93,10 +93,6 @@ class TDTestCase: tdSql.checkData(0, 1, 2) tdLog.info('drop database db') tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) # convert end def stop(self): diff --git a/tests/pytest/insert/unsignedTinyint.py b/tests/pytest/insert/unsignedTinyint.py index 5bdfe7580b198ccaffcab7005e88aa72e1c437af..200ac00eb00b673339cd35601e8ed0f7663f06b0 100644 --- a/tests/pytest/insert/unsignedTinyint.py +++ b/tests/pytest/insert/unsignedTinyint.py @@ -91,10 +91,6 @@ class TDTestCase: tdSql.checkData(0, 1, 2) tdLog.info('drop database db') tdSql.execute('drop database db') - tdLog.info('show databases') - tdSql.query('show databases') - tdLog.info('tdSql.checkRow(0)') - tdSql.checkRows(0) def stop(self): diff --git a/tests/pytest/perf_gen.sh b/tests/pytest/perf_gen.sh index d28b5422f8ba4d4683c78020e45d2085385c4b4f..13a667fd3801b1e0828d5704caec63c09a1c4518 100755 --- a/tests/pytest/perf_gen.sh +++ b/tests/pytest/perf_gen.sh @@ -35,11 +35,11 @@ CURR_DIR=`pwd` IN_TDINTERNAL="community" if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then TAOS_DIR=$CURR_DIR/../../.. - TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1` + TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1` LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6,7|rev`/lib else TAOS_DIR=$CURR_DIR/../.. - TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1` + TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1` LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6|rev`/lib fi diff --git a/tests/pytest/smoketest.sh b/tests/pytest/smoketest.sh index cbe80882fbb6dfb6cfa9695f66d0b22d09068ae5..7ac5d4f6d375d194077af80e2a89f0d34a8c32d1 100755 --- a/tests/pytest/smoketest.sh +++ b/tests/pytest/smoketest.sh @@ -4,10 +4,32 @@ ulimit -c unlimited # insert python3 ./test.py $1 -f insert/basic.py python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/bool.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/tinyint.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/smallint.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/int.py +python3 ./test.py $1 -s && sleep 1 python3 ./test.py $1 -f insert/bigint.py python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/float.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/double.py +python3 ./test.py $1 -s && sleep 1 python3 ./test.py $1 -f insert/nchar.py python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/timestamp.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/unsignedTinyint.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/unsignedSmallint.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/unsignedInt.py +python3 ./test.py $1 -s && sleep 1 +python3 ./test.py $1 -f insert/unsignedBigint.py +python3 ./test.py $1 -s && sleep 1 python3 ./test.py $1 -f insert/multi.py python3 ./test.py $1 -s && sleep 1 diff --git a/tests/pytest/test.sh b/tests/pytest/test.sh index 4e74341f7075b50329a49aa3eccd09f68b733f20..fd3010f4cbc7e518a7692dbdb78fa3da2103b543 100755 --- a/tests/pytest/test.sh +++ b/tests/pytest/test.sh @@ -11,7 +11,7 @@ if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then else TAOS_DIR=$CURR_DIR/../.. fi -TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1` LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6|rev`/lib export PYTHONPATH=$(pwd)/../../src/connector/python export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB_DIR diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 082f3adcec584653d9cca316081c0ff22ba95ccb..3df1d4287b663d37837029390a438d01fabf137b 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -31,7 +31,7 @@ ./test.sh -f tsim/query/interval.sim ./test.sh -f tsim/query/interval-offset.sim ./test.sh -f tsim/query/scalarFunction.sim -./test.sh -f tsim/query/charScalarFunction.sim +#./test.sh -f tsim/query/charScalarFunction.sim ./test.sh -f tsim/query/explain.sim ./test.sh -f tsim/query/session.sim @@ -81,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 diff --git a/tests/script/sh/cfg.sh b/tests/script/sh/cfg.sh index 7d4d747e54bab9ed98b42ab1902f8580e17fca6c..ac7e81e87b61042b748c9f52ac8c3b08a4ee1dc2 100755 --- a/tests/script/sh/cfg.sh +++ b/tests/script/sh/cfg.sh @@ -43,7 +43,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -52,9 +52,9 @@ else fi if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/clear.sh b/tests/script/sh/clear.sh index 4ee296cf058370552b14c31b67006830e84847dd..197020c92812f72a82698bd84427acaa7e5a3c1a 100755 --- a/tests/script/sh/clear.sh +++ b/tests/script/sh/clear.sh @@ -46,7 +46,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -55,9 +55,9 @@ else fi if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index 38b6d9aadbbfbc8ad3e0cd7c37f56961e4f3f25c..29a495113f8bc0c3b61271d0193408290924f330 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -41,7 +41,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" diff --git a/tests/script/sh/exec-default.sh b/tests/script/sh/exec-default.sh index f648315c6745f63cfba9eb06ecfd53a9ccef1fed..cca8dd0c3424b3e5d7482a8908af48bfd1aa2dc3 100755 --- a/tests/script/sh/exec-default.sh +++ b/tests/script/sh/exec-default.sh @@ -52,7 +52,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -61,9 +61,9 @@ else fi if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/exec-no-random-fail.sh b/tests/script/sh/exec-no-random-fail.sh index e01b18a8e6bb0d4631a28c64c6accd57bceb9076..72b2035af5105ed24b510cfa2bfb032654672f14 100755 --- a/tests/script/sh/exec-no-random-fail.sh +++ b/tests/script/sh/exec-no-random-fail.sh @@ -52,7 +52,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -61,9 +61,9 @@ else fi if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/exec-random-fail.sh b/tests/script/sh/exec-random-fail.sh index 1f31899e3ac26861fc1860d10cb0a4899ff7bf36..5ed71af05d1c428a7a59d2212f06339a951e8234 100755 --- a/tests/script/sh/exec-random-fail.sh +++ b/tests/script/sh/exec-random-fail.sh @@ -52,7 +52,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -61,9 +61,9 @@ else fi if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/exec.sh b/tests/script/sh/exec.sh index 1a9a6a2c5220184b99a6fe864372f585fd5c56bc..50ded73555690db1cf8d2a94014efdd51079c284 100755 --- a/tests/script/sh/exec.sh +++ b/tests/script/sh/exec.sh @@ -56,7 +56,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" diff --git a/tests/script/sh/exec_tarbitrator.sh b/tests/script/sh/exec_tarbitrator.sh index e985bd65856025b2db8dfef724fdc652b2a03392..1b91d999a7bb4e74ebb12a51ea365b70f59c5256 100755 --- a/tests/script/sh/exec_tarbitrator.sh +++ b/tests/script/sh/exec_tarbitrator.sh @@ -49,7 +49,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -58,9 +58,9 @@ else fi if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/move_dnode.sh b/tests/script/sh/move_dnode.sh index d3650c18ad0f49185ce1e1268273b8a44e3cdc14..4aa2daa3973fb52ff4680c7a146bcbf1905ae64f 100755 --- a/tests/script/sh/move_dnode.sh +++ b/tests/script/sh/move_dnode.sh @@ -18,7 +18,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -27,9 +27,9 @@ else fi if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/sh/mv_old_data.sh b/tests/script/sh/mv_old_data.sh index 3f4be6714fd757ee60d21ee97be5d411e3f95bdd..2c99bc11c4990603845a135775e0826eaafc5b7c 100755 --- a/tests/script/sh/mv_old_data.sh +++ b/tests/script/sh/mv_old_data.sh @@ -18,7 +18,7 @@ else fi TAOS_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -27,9 +27,9 @@ else fi if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2,3` else - BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` + BIN_DIR=`find . -name "taosd"|grep debug|head -n1|cut -d '/' ${cut_opt}2` fi BUILD_DIR=$TAOS_DIR/$BIN_DIR/build diff --git a/tests/script/test.sh b/tests/script/test.sh index 8b77575e1845d4bff7b62d6b5351263912a34a5d..f5a9e4187bb85ea4f0ddeadde92dec0bfc0a6fd0 100755 --- a/tests/script/test.sh +++ b/tests/script/test.sh @@ -51,7 +51,7 @@ else fi TOP_DIR=`pwd` -TAOSD_DIR=`find . -name "taosd"|grep bin|head -n1` +TAOSD_DIR=`find . -name "taosd"|grep debug|head -n1` if [[ "$OS_TYPE" != "Darwin" ]]; then cut_opt="--field=" @@ -125,8 +125,8 @@ ulimit -c unlimited if [ -n "$FILE_NAME" ]; then echo "------------------------------------------------------------------------" if [ $VALGRIND -eq 1 ]; then - echo valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=${CODE_DIR}/../script/valgrind.log $PROGRAM -c $CFG_DIR -f $FILE_NAME - valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=${CODE_DIR}/../script/valgrind.log $PROGRAM -c $CFG_DIR -f $FILE_NAME + echo valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=${CODE_DIR}/../script/valgrind.log $PROGRAM -c $CFG_DIR -f $FILE_NAME -v + valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=${CODE_DIR}/../script/valgrind.log $PROGRAM -c $CFG_DIR -f $FILE_NAME -v else if [[ $MULTIPROCESS -eq 1 ]];then echo "ExcuteCmd(multiprocess):" $PROGRAM -m -c $CFG_DIR -f $FILE_NAME diff --git a/tests/script/tsim/db/error1.sim b/tests/script/tsim/db/error1.sim index 2e00143eb9b3982d50401433c438ae6c1b45fe02..3460647bc9f3a9c1605624cdc65faf2eb4be7c69 100644 --- a/tests/script/tsim/db/error1.sim +++ b/tests/script/tsim/db/error1.sim @@ -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 diff --git a/tests/script/tsim/query/charScalarFunction.sim b/tests/script/tsim/query/charScalarFunction.sim index afdb9e0d74f5c53282bdd612c98984f71fecdfa0..046812599754b9832da716788342d96956cad5aa 100644 --- a/tests/script/tsim/query/charScalarFunction.sim +++ b/tests/script/tsim/query/charScalarFunction.sim @@ -266,20 +266,20 @@ 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 != 中文测试01中文测试01 then -# return -1 -# endi -# if $data12 != 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 diff --git a/tests/test/c/tmqDemo.c b/tests/test/c/tmqDemo.c index 16f6c42d872b9c038954135e3258ccb899c6accd..2b3e9963f08bf21f2a8b527c31a7bfde5d016d4b 100644 --- a/tests/test/c/tmqDemo.c +++ b/tests/test/c/tmqDemo.c @@ -13,8 +13,6 @@ * along with this program. If not, see . */ -#define ALLOW_FORBID_FUNC - #include #include #include @@ -36,7 +34,12 @@ #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 }; +enum _RUN_MODE { + TMQ_RUN_INSERT_AND_CONSUME, + TMQ_RUN_ONLY_INSERT, + TMQ_RUN_ONLY_CONSUME, + TMQ_RUN_MODE_BUTT, +}; typedef struct { char dbName[32]; @@ -338,6 +341,7 @@ tmq_t* build_consumer() { 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; } @@ -596,7 +600,7 @@ void printParaIntoFile() { g_fp = pFile; time_t tTime = taosGetTimestampSec(); - struct tm tm = *localtime(&tTime); + struct tm tm = *taosLocalTime(&tTime, NULL); taosFprintfFile(pFile, "###################################################################\n"); taosFprintfFile(pFile, "# configDir: %s\n", configDir); diff --git a/tests/tsim/inc/simInt.h b/tests/tsim/inc/simInt.h index a667139de1934fab479c8ed2c3d857b7ee111dea..c8b13736c7cb752c7fa52500f132ede02988089e 100644 --- a/tests/tsim/inc/simInt.h +++ b/tests/tsim/inc/simInt.h @@ -156,6 +156,7 @@ extern int32_t simDebugFlag; extern char simScriptDir[]; extern bool abortExecution; extern bool useMultiProcess; +extern bool useValgrind; SScript *simParseScript(char *fileName); SScript *simProcessCallOver(SScript *script); diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index d71323336292cccf3d4cdb951c3ce457bded0667..5a18084fff254de271c4c68a2472c283de331797 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -340,6 +340,10 @@ bool simExecuteSystemCmd(SScript *script, char *option) { simReplaceStr(buf, "deploy.sh", "deploy.sh -m"); } + if (useValgrind) { + simReplaceStr(buf, "exec.sh", "exec.sh -v"); + } + simLogSql(buf, true); int32_t code = system(buf); int32_t repeatTimes = 0; diff --git a/tests/tsim/src/simMain.c b/tests/tsim/src/simMain.c index 8898f1b201da5e41db81982a8261a2d792888912..713e46df58e8957be2593eb5d78698ed46e5a69b 100644 --- a/tests/tsim/src/simMain.c +++ b/tests/tsim/src/simMain.c @@ -19,6 +19,7 @@ bool simExecSuccess = false; bool abortExecution = false; bool useMultiProcess = false; +bool useValgrind = false; void simHandleSignal(int32_t signo, void *sigInfo, void *context) { simSystemCleanUp(); @@ -35,6 +36,8 @@ int32_t main(int32_t argc, char *argv[]) { strcpy(scriptFile, argv[++i]); } else if (strcmp(argv[i], "-m") == 0) { useMultiProcess = true; + } else if (strcmp(argv[i], "-v") == 0) { + useValgrind = true; } else { printf("usage: %s [options] \n", argv[0]); printf(" [-c config]: config directory, default is: %s\n", configDir); diff --git a/tools/taosTools-1.4.1-Linux-x64.tar.gz b/tools/taosTools-1.4.1-Linux-x64.tar.gz deleted file mode 100644 index caefa3d95768cc0551bdf2f9ba9b5631942b9e5a..0000000000000000000000000000000000000000 Binary files a/tools/taosTools-1.4.1-Linux-x64.tar.gz and /dev/null differ