diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index fd0ada95d9043d143fe6eca3d295a18cc3b19849..b258a2a252ddafbd3f32f3bde3c59f3af1e79e58 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -6,28 +6,32 @@ "dockerfile": "Dockerfile", // Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04 // Use Debian 11, Debian 9, Ubuntu 18.04 or Ubuntu 21.04 on local arm64/Apple Silicon - "args": { "VARIANT": "ubuntu-21.04" } + "args": { + "VARIANT": "ubuntu-21.04" + } }, - "runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"], - + "runArgs": [ + "--cap-add=SYS_PTRACE", + "--security-opt", + "seccomp=unconfined" + ], // Set *default* container specific settings.json values on container create. "settings": {}, - // Add the IDs of extensions you want installed when the container is created. "extensions": [ "ms-vscode.cpptools", "ms-vscode.cmake-tools", "austin.code-gnu-global", "visualstudioexptteam.vscodeintel", - "eamodio.gitlens" + "eamodio.gitlens", + "matepek.vscode-catch2-test-adapter", + "spmeesseman.vscode-taskexplorer", + "cschlosser.doxdocgen" ], - // 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", - // 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/include/common/tmsg.h b/include/common/tmsg.h index 49fd80c7f6c8f992465df6ea3a0d69a05c47f0c9..177a3b4b1ede4bc8504c32924b94358059d10074 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -156,10 +156,6 @@ typedef struct { uint16_t port; } SEpAddr; -typedef struct { - int32_t numOfVnodes; -} SMsgDesc; - typedef struct SMsgHead { int32_t contLen; int32_t vgId; @@ -341,7 +337,7 @@ typedef struct { int64_t clusterId; int32_t connId; int8_t superUser; - int8_t reserved[5]; + int8_t align[3]; SEpSet epSet; } SConnectRsp; @@ -354,21 +350,18 @@ typedef struct { int32_t maxStreams; int32_t accessState; // Configured only by command int64_t maxStorage; // In unit of GB - int32_t reserve[8]; -} SCreateAcctMsg, SAlterAcctMsg; +} SCreateAcctReq, SAlterAcctReq; typedef struct { - char user[TSDB_USER_LEN]; - int32_t reserve[8]; -} SDropUserMsg, SDropAcctMsg; + char user[TSDB_USER_LEN]; +} SDropUserReq, SDropAcctReq; typedef struct { - int8_t type; - char user[TSDB_USER_LEN]; - char pass[TSDB_PASSWORD_LEN]; - int8_t superUser; // denote if it is a super user or not - int32_t reserve[8]; -} SCreateUserMsg, SAlterUserMsg; + int8_t type; + char user[TSDB_USER_LEN]; + char pass[TSDB_PASSWORD_LEN]; + int8_t superUser; // denote if it is a super user or not +} SCreateUserReq, SAlterUserReq; typedef struct { int32_t contLen; @@ -522,7 +515,7 @@ typedef struct { int64_t qId; }; // query handle int8_t free; -} SRetrieveTableMsg; +} SRetrieveTableReq; typedef struct SRetrieveTableRsp { int64_t useconds; @@ -556,7 +549,6 @@ typedef struct { int8_t update; int8_t cacheLastRow; int8_t ignoreExist; - int32_t reserve[8]; } SCreateDbMsg; typedef struct { @@ -569,29 +561,24 @@ typedef struct { int8_t walLevel; int8_t quorum; int8_t cacheLastRow; - int32_t reserve[8]; } SAlterDbMsg; typedef struct { - char db[TSDB_TABLE_FNAME_LEN]; - int8_t ignoreNotExists; - int32_t reserve[8]; + char db[TSDB_TABLE_FNAME_LEN]; + int8_t ignoreNotExists; } SDropDbMsg; typedef struct { char db[TSDB_TABLE_FNAME_LEN]; int32_t vgVersion; - int32_t reserve[8]; } SUseDbMsg; typedef struct { - char db[TSDB_TABLE_FNAME_LEN]; - int32_t reserve[8]; + char db[TSDB_TABLE_FNAME_LEN]; } SSyncDbMsg; typedef struct { - char db[TSDB_TABLE_FNAME_LEN]; - int32_t reserve[8]; + char db[TSDB_TABLE_FNAME_LEN]; } SCompactDbMsg; typedef struct { @@ -647,7 +634,7 @@ typedef struct { typedef struct { int32_t vgId; int8_t role; - int8_t reserved[3]; + int8_t align[3]; int64_t totalStorage; int64_t compStorage; int64_t pointsWritten; @@ -684,7 +671,7 @@ typedef struct { typedef struct { int32_t id; int8_t isMnode; - int8_t reserved; + int8_t align; uint16_t port; char fqdn[TSDB_FQDN_LEN]; } SDnodeEp; @@ -830,7 +817,7 @@ typedef struct { char db[TSDB_DB_FNAME_LEN]; int16_t payloadLen; char payload[]; -} SShowMsg; +} SShowReq; typedef struct { char db[TSDB_DB_FNAME_LEN]; @@ -869,15 +856,15 @@ typedef struct { typedef struct { int32_t dnodeId; -} SMCreateQnodeMsg, SMDropQnodeMsg, SDCreateQnodeMsg, SDDropQnodeMsg; +} SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq; typedef struct { int32_t dnodeId; -} SMCreateSnodeMsg, SMDropSnodeMsg, SDCreateSnodeMsg, SDDropSnodeMsg; +} SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq; typedef struct { int32_t dnodeId; -} SMCreateBnodeMsg, SMDropBnodeMsg, SDCreateBnodeMsg, SDDropBnodeMsg; +} SMCreateBnodeReq, SMDropBnodeReq, SDCreateBnodeReq, SDDropBnodeReq; typedef struct { int32_t dnodeId; @@ -920,7 +907,7 @@ typedef struct { int32_t totalDnodes; int32_t onlineDnodes; int8_t killConnection; - int8_t reserved[3]; + int8_t align[3]; SEpSet epSet; } SHeartBeatRsp; @@ -948,7 +935,7 @@ typedef struct { typedef struct { int8_t finished; - int8_t reserved1[7]; + int8_t align[7]; char name[TSDB_STEP_NAME_LEN]; char desc[TSDB_STEP_DESC_LEN]; } SStartupMsg; @@ -1059,6 +1046,7 @@ typedef struct SResFetchMsg { } SResFetchMsg; typedef struct SSchTasksStatusMsg { + SMsgHead header; uint64_t sId; } SSchTasksStatusMsg; @@ -1074,6 +1062,7 @@ typedef struct SSchedulerStatusRsp { } SSchedulerStatusRsp; typedef struct STaskCancelMsg { + SMsgHead header; uint64_t sId; uint64_t queryId; uint64_t taskId; @@ -1084,6 +1073,7 @@ typedef struct STaskCancelRsp { } STaskCancelRsp; typedef struct STaskDropMsg { + SMsgHead header; uint64_t sId; uint64_t queryId; uint64_t taskId; diff --git a/include/dnode/bnode/bnode.h b/include/dnode/bnode/bnode.h index 23cc3ca6176eb9bd5ff88b48bc62befb56687f2d..3cc26861aba988856a2e951116765222adb4b8c8 100644 --- a/include/dnode/bnode/bnode.h +++ b/include/dnode/bnode/bnode.h @@ -23,9 +23,9 @@ extern "C" { /* ------------------------ TYPES EXPOSED ------------------------ */ typedef struct SDnode SDnode; typedef struct SBnode SBnode; -typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef struct { int64_t numOfErrors; @@ -40,9 +40,9 @@ typedef struct { int64_t clusterId; SBnodeCfg cfg; SDnode *pDnode; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SBnodeOpt; /* ------------------------ SBnode ------------------------ */ diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index a288e3e6309ee64cd64579c5d72b7a43e447c72d..de4b4e4e89d1418391aa6daf519c77bea8013c72 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -24,9 +24,10 @@ extern "C" { typedef struct SDnode SDnode; typedef struct SMnode SMnode; typedef struct SMnodeMsg SMnodeMsg; -typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*PutReqToMWriteQFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef struct SMnodeLoad { int64_t numOfDnode; @@ -62,9 +63,10 @@ typedef struct { SReplica replicas[TSDB_MAX_REPLICA]; SMnodeCfg cfg; SDnode *pDnode; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + PutReqToMWriteQFp putReqToMWriteQFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SMnodeOpt; /* ------------------------ SMnode ------------------------ */ diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index 3ff86bea3ebfbcd4aea7a8c6fbdef833d26561e7..c7198eee6f5192628c1032591b275194d39af2cb 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -22,121 +22,70 @@ extern "C" { #endif -#define SDB_GET_INT64(pData, pRow, dataPos, val) \ - { \ - if (sdbGetRawInt64(pRaw, dataPos, val) != 0) { \ - tfree(pRow); \ - return NULL; \ - } \ - dataPos += sizeof(int64_t); \ +#define SDB_GET_VAL(pData, dataPos, val, pos, func, type) \ + { \ + if (func(pRaw, dataPos, val) != 0) { \ + goto pos; \ + } \ + dataPos += sizeof(type); \ } -#define SDB_GET_INT32(pData, pRow, dataPos, val) \ - { \ - if (sdbGetRawInt32(pRaw, dataPos, val) != 0) { \ - tfree(pRow); \ - return NULL; \ - } \ - dataPos += sizeof(int32_t); \ - } - -#define SDB_GET_INT16(pData, pRow, dataPos, val) \ - { \ - if (sdbGetRawInt16(pRaw, dataPos, val) != 0) { \ - tfree(pRow); \ - return NULL; \ - } \ - dataPos += sizeof(int16_t); \ - } - -#define SDB_GET_INT8(pData, pRow, dataPos, val) \ - { \ - if (sdbGetRawInt8(pRaw, dataPos, val) != 0) { \ - tfree(pRow); \ - return NULL; \ - } \ - dataPos += sizeof(int8_t); \ - } - -#define SDB_GET_BINARY(pRaw, pRow, dataPos, val, valLen) \ +#define SDB_GET_BINARY(pRaw, dataPos, val, valLen, pos) \ { \ if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \ - tfree(pRow); \ - return NULL; \ + goto pos; \ } \ dataPos += valLen; \ } -#define SDB_GET_RESERVE(pRaw, pRow, dataPos, valLen) \ - { \ - char val[valLen] = {0}; \ - if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \ - tfree(pRow); \ - return NULL; \ - } \ - dataPos += valLen; \ - } +#define SDB_GET_INT64(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt64, int64_t) -#define SDB_SET_INT64(pRaw, dataPos, val) \ - { \ - if (sdbSetRawInt64(pRaw, dataPos, val) != 0) { \ - sdbFreeRaw(pRaw); \ - return NULL; \ - } \ - dataPos += sizeof(int64_t); \ - } +#define SDB_GET_INT32(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt32, int32_t) -#define SDB_SET_INT32(pRaw, dataPos, val) \ - { \ - if (sdbSetRawInt32(pRaw, dataPos, val) != 0) { \ - sdbFreeRaw(pRaw); \ - return NULL; \ - } \ - dataPos += sizeof(int32_t); \ - } +#define SDB_GET_INT16(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt16, int16_t) -#define SDB_SET_INT16(pRaw, dataPos, val) \ - { \ - if (sdbSetRawInt16(pRaw, dataPos, val) != 0) { \ - sdbFreeRaw(pRaw); \ - return NULL; \ - } \ - dataPos += sizeof(int16_t); \ +#define SDB_GET_INT8(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt8, int8_t) + +#define SDB_GET_RESERVE(pRaw, dataPos, valLen, pos) \ + { \ + char val[valLen] = {0}; \ + SDB_GET_BINARY(pRaw, dataPos, val, valLen, pos) \ } -#define SDB_SET_INT8(pRaw, dataPos, val) \ - { \ - if (sdbSetRawInt8(pRaw, dataPos, val) != 0) { \ - sdbFreeRaw(pRaw); \ - return NULL; \ - } \ - dataPos += sizeof(int8_t); \ +#define SDB_SET_VAL(pRaw, dataPos, val, pos, func, type) \ + { \ + if (func(pRaw, dataPos, val) != 0) { \ + goto pos; \ + } \ + dataPos += sizeof(type); \ } -#define SDB_SET_BINARY(pRaw, dataPos, val, valLen) \ +#define SDB_SET_INT64(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt64, int64_t) + +#define SDB_SET_INT32(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt32, int32_t) + +#define SDB_SET_INT16(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt16, int16_t) + +#define SDB_SET_INT8(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt8, int8_t) + +#define SDB_SET_BINARY(pRaw, dataPos, val, valLen, pos) \ { \ if (sdbSetRawBinary(pRaw, dataPos, val, valLen) != 0) { \ - sdbFreeRaw(pRaw); \ - return NULL; \ + goto pos; \ } \ dataPos += valLen; \ } -#define SDB_SET_RESERVE(pRaw, dataPos, valLen) \ - { \ - char val[valLen] = {0}; \ - if (sdbSetRawBinary(pRaw, dataPos, val, valLen) != 0) { \ - sdbFreeRaw(pRaw); \ - return NULL; \ - } \ - dataPos += valLen; \ +#define SDB_SET_RESERVE(pRaw, dataPos, valLen, pos) \ + { \ + char val[valLen] = {0}; \ + SDB_SET_BINARY(pRaw, dataPos, val, valLen, pos) \ } -#define SDB_SET_DATALEN(pRaw, dataLen) \ +#define SDB_SET_DATALEN(pRaw, dataLen, pos) \ { \ if (sdbSetRawDataLen(pRaw, dataLen) != 0) { \ - sdbFreeRaw(pRaw); \ - return NULL; \ + goto pos; \ } \ } @@ -145,6 +94,7 @@ typedef struct SSdbRaw SSdbRaw; typedef struct SSdbRow SSdbRow; typedef enum { SDB_KEY_BINARY = 1, SDB_KEY_INT32 = 2, SDB_KEY_INT64 = 3 } EKeyType; typedef enum { + SDB_STATUS_INIT = 0, SDB_STATUS_CREATING = 1, SDB_STATUS_UPDATING = 2, SDB_STATUS_DROPPING = 3, @@ -153,25 +103,24 @@ typedef enum { } ESdbStatus; typedef enum { - SDB_START = 0, - SDB_TRANS = 1, - SDB_CLUSTER = 2, - SDB_MNODE = 3, - SDB_QNODE = 4, - SDB_SNODE = 5, - SDB_BNODE = 6, - SDB_DNODE = 7, - SDB_USER = 8, - SDB_AUTH = 9, - SDB_ACCT = 10, - SDB_CONSUMER = 11, - SDB_CGROUP = 12, - SDB_TOPIC = 13, - SDB_VGROUP = 14, - SDB_STB = 15, - SDB_DB = 16, - SDB_FUNC = 17, - SDB_MAX = 18 + SDB_TRANS = 0, + SDB_CLUSTER = 1, + SDB_MNODE = 2, + SDB_QNODE = 3, + SDB_SNODE = 4, + SDB_BNODE = 5, + SDB_DNODE = 6, + SDB_USER = 7, + SDB_AUTH = 8, + SDB_ACCT = 9, + SDB_CONSUMER = 10, + SDB_CGROUP = 11, + SDB_TOPIC = 12, + SDB_VGROUP = 13, + SDB_STB = 14, + SDB_DB = 15, + SDB_FUNC = 16, + SDB_MAX = 17 } ESdbType; typedef struct SSdb SSdb; @@ -239,6 +188,14 @@ int32_t sdbDeploy(SSdb *pSdb); */ int32_t sdbReadFile(SSdb *pSdb); +/** + * @brief Write sdb file. + * + * @param pSdb The sdb object. + * @return int32_t 0 for success, -1 for failure. + */ +int32_t sdbWriteFile(SSdb *pSdb); + /** * @brief Parse and write raw data to sdb, then free the pRaw object * @@ -311,7 +268,7 @@ void sdbTraverse(SSdb *pSdb, ESdbType type, sdbTraverseFp fp, void *p1, void *p2 * * @param pSdb The sdb object. * @param pIter The type of the table. - * @record int32_t The number of rows in the table + * @return int32_t The number of rows in the table */ int32_t sdbGetSize(SSdb *pSdb, ESdbType type); @@ -320,10 +277,19 @@ int32_t sdbGetSize(SSdb *pSdb, ESdbType type); * * @param pSdb The sdb object. * @param pIter The type of the table. - * @record int32_t The max id of the table + * @return int32_t The max id of the table */ int32_t sdbGetMaxId(SSdb *pSdb, ESdbType type); +/** + * @brief Update the version of sdb + * + * @param pSdb The sdb object. + * @param val The update value of the version. + * @return int32_t The current version of sdb + */ +int64_t sdbUpdateVer(SSdb *pSdb, int32_t val); + SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen); void sdbFreeRaw(SSdbRaw *pRaw); int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val); diff --git a/include/dnode/qnode/qnode.h b/include/dnode/qnode/qnode.h index 8084175a907ff4c98b52a5f343956b8fbcc834fd..554c57a045436f9df54338a79bbb8d69ef4e3e7a 100644 --- a/include/dnode/qnode/qnode.h +++ b/include/dnode/qnode/qnode.h @@ -23,9 +23,9 @@ extern "C" { /* ------------------------ TYPES EXPOSED ------------------------ */ typedef struct SDnode SDnode; typedef struct SQnode SQnode; -typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef struct { int64_t numOfStartTask; @@ -47,9 +47,9 @@ typedef struct { int64_t clusterId; SQnodeCfg cfg; SDnode *pDnode; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SQnodeOpt; /* ------------------------ SQnode ------------------------ */ diff --git a/include/dnode/snode/snode.h b/include/dnode/snode/snode.h index 4913d2572fa201b23df12195e0004f55b8c4b866..43d3dd9b4b377fbee57f9cf9fd02c9f14699f77d 100644 --- a/include/dnode/snode/snode.h +++ b/include/dnode/snode/snode.h @@ -23,9 +23,9 @@ extern "C" { /* ------------------------ TYPES EXPOSED ------------------------ */ typedef struct SDnode SDnode; typedef struct SSnode SSnode; -typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef struct { int64_t numOfErrors; @@ -40,9 +40,9 @@ typedef struct { int64_t clusterId; SSnodeCfg cfg; SDnode *pDnode; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SSnodeOpt; /* ------------------------ SSnode ------------------------ */ diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index 1bd29ce396b5be3774080724cf5b2979da6a0809..e39236ea76570601d94c35827cd2f0d42a29f3fb 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -50,6 +50,7 @@ typedef struct SCatalogCfg { uint32_t maxDBCacheNum; } SCatalogCfg; + int32_t catalogInit(SCatalogCfg *cfg); /** @@ -87,26 +88,40 @@ int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDB */ int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta); +/** + * Get a super table's meta data. + * @param pCatalog (input, got with catalogGetHandle) + * @param pTransporter (input, rpc object) + * @param pMgmtEps (input, mnode EPs) + * @param pTableName (input, table name, NOT including db name) + * @param pTableMeta(output, table meta data, NEED to free it by calller) + * @return error code + */ +int32_t catalogGetSTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta); + + /** * Force renew a table's local cached meta data. * @param pCatalog (input, got with catalogGetHandle) - * @param pRpc (input, rpc object) + * @param pTransporter (input, rpc object) * @param pMgmtEps (input, mnode EPs) * @param pTableName (input, table name, NOT including db name) + * @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure) * @return error code */ -int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName); +int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, int32_t isSTable); /** * Force renew a table's local cached meta data and get the new one. * @param pCatalog (input, got with catalogGetHandle) - * @param pRpc (input, rpc object) + * @param pTransporter (input, rpc object) * @param pMgmtEps (input, mnode EPs) * @param pTableName (input, table name, NOT including db name) * @param pTableMeta(output, table meta data, NEED to free it by calller) + * @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure) * @return error code */ -int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta); +int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable); /** diff --git a/include/libs/parser/parsenodes.h b/include/libs/parser/parsenodes.h index b326ac032ca50ee5df1b2a263e2b282fd379ba48..18596a9e182fede027dac76ea2b9eb6ca866e902 100644 --- a/include/libs/parser/parsenodes.h +++ b/include/libs/parser/parsenodes.h @@ -154,14 +154,14 @@ typedef struct SVgDataBlocks { char *pData; // SMsgDesc + SSubmitMsg + SSubmitBlk + ... } SVgDataBlocks; -typedef struct SInsertStmtInfo { +typedef struct SVnodeModifOpStmtInfo { int16_t nodeType; SArray* pDataBlocks; // data block for each vgroup, SArray. int8_t schemaAttache; // denote if submit block is built with table schema or not uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert uint32_t insertType; // insert data from [file|sql statement| bound statement] const char* sql; // current sql statement position -} SInsertStmtInfo; +} SVnodeModifOpStmtInfo; typedef struct SDclStmtInfo { int16_t nodeType; diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index a9e1f26d2014225a5a8481b497906f1d1f34aab4..5bd18641bf56b65d201f6d3d16c838efa95b8057 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -43,7 +43,7 @@ int32_t qParseQuerySql(SParseContext* pContext, SQueryNode** pQuery); bool qIsDdlQuery(const SQueryNode* pQuery); -void qDestroyQuery(SQueryNode* pQuery); +void qDestroyQuery(SQueryNode* pQueryNode); /** * Convert a normal sql statement to only query tags information to enable that the subscribe client can be aware quickly of the true vgroup ids that diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h index 3ca923b0aaa9822e65a377096d20958c63d057d8..a55a4fedab3fec4389bd261a14282d70e070d1dc 100644 --- a/include/libs/planner/planner.h +++ b/include/libs/planner/planner.h @@ -20,6 +20,7 @@ extern "C" { #endif +#include "query.h" #include "tmsg.h" #include "tarray.h" @@ -119,11 +120,12 @@ typedef struct SSubplanId { } SSubplanId; typedef struct SSubplan { - SSubplanId id; // unique id of the subplan + SSubplanId id; // unique id of the subplan int32_t type; // QUERY_TYPE_MERGE|QUERY_TYPE_PARTIAL|QUERY_TYPE_SCAN|QUERY_TYPE_MODIFY - int32_t level; // the execution level of current subplan, starting from 0. - SEpSet execEpSet; // for the scan/modify subplan, the optional execution node - SArray *pChildern; // the datasource subplan,from which to fetch the result + int32_t msgType; // message type for subplan, used to denote the send message type to vnode. + int32_t level; // the execution level of current subplan, starting from 0 in a top-down manner. + SQueryNodeAddr execNode; // for the scan/modify subplan, the optional execution node + SArray *pChildren; // the datasource subplan,from which to fetch the result SArray *pParents; // the data destination subplan, get data from current subplan SPhyNode *pNode; // physical plan of current subplan SDataSink *pDataSink; // data of the subplan flow into the datasink @@ -140,13 +142,13 @@ struct SQueryNode; /** * Create the physical plan for the query, according to the AST. */ -int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SQueryDag** pDag); +int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SQueryDag** pDag, uint64_t requestId); // Set datasource of this subplan, multiple calls may be made to a subplan. // @subplan subplan to be schedule // @templateId templateId of a group of datasource subplans of this @subplan // @ep one execution location of this group of datasource subplans -int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep); +int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SQueryNodeAddr* ep); int32_t qExplainQuery(const struct SQueryNode* pQueryInfo, struct SEpSet* pQnode, char** str); diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index 4d5b1a8bd3db1bbc9a2d0654ce8031710afb1909..4bfb774435a2024c2310575b7ddae9e07398fbab 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -111,6 +111,13 @@ typedef struct SMsgSendInfo { SDataBuf msgInfo; } SMsgSendInfo; +typedef struct SQueryNodeAddr{ + int32_t nodeId; //vgId or qnodeId + int8_t inUse; + int8_t numOfEps; + SEpAddrMsg epAddr[TSDB_MAX_REPLICA]; +} SQueryNodeAddr; + bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags); int32_t initTaskQueue(); diff --git a/include/libs/scheduler/scheduler.h b/include/libs/scheduler/scheduler.h index d6cac976d41c1da8001e5bc18a95ee9a85d1b2bd..b2ba7acebfcdc832f25cc5f0a1c9662d0ec054ab 100644 --- a/include/libs/scheduler/scheduler.h +++ b/include/libs/scheduler/scheduler.h @@ -50,13 +50,6 @@ typedef struct SQueryProfileSummary { uint64_t resultSize; // generated result size in Kb. } SQueryProfileSummary; -typedef struct SQueryNodeAddr{ - int32_t nodeId; //vgId or qnodeId - int8_t inUse; - int8_t numOfEps; - SEpAddrMsg epAddr[TSDB_MAX_REPLICA]; -} SQueryNodeAddr; - typedef struct SQueryResult { int32_t code; uint64_t numOfRows; diff --git a/include/os/os.h b/include/os/os.h index de2a8182db8417e7e916ba0fdde0d19e076898ac..972880da9cbed98440d6bc04871abb50f776f743 100644 --- a/include/os/os.h +++ b/include/os/os.h @@ -22,11 +22,13 @@ extern "C" { #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -36,19 +38,14 @@ extern "C" { #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include -#include #include +#include +#include + +#include #include "osAtomic.h" #include "osDef.h" diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h index 6952b917423f8ea9fd6668278cb5c91a4db5bd48..36ff4194d8c2db46292ed64fc658c3ad33d409fd 100644 --- a/include/os/osSysinfo.h +++ b/include/os/osSysinfo.h @@ -54,7 +54,7 @@ bool taosGetSysMemory(float *memoryUsedMB); void taosPrintOsInfo(); int taosSystem(const char *cmd); void taosKillSystem(); -int32_t taosGetSystemUid(char *uid, int32_t uidlen); +int32_t taosGetSystemUUID(char *uid, int32_t uidlen); char * taosGetCmdlineByPID(int pid); void taosSetCoreDump(bool enable); @@ -68,8 +68,6 @@ typedef struct { SysNameInfo taosGetSysNameInfo(); -int64_t taosGetPid(); - #ifdef __cplusplus } #endif diff --git a/include/util/taoserror.h b/include/util/taoserror.h index a10dd8eda2a305ed3cb80c8ddaf01cc7c4b51f40..4fcdae24963c4da642e9e8c9d5748fd581ac6469 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -160,6 +160,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_SDB_INVALID_DATA_VER TAOS_DEF_ERROR_CODE(0, 0x0339) #define TSDB_CODE_SDB_INVALID_DATA_LEN TAOS_DEF_ERROR_CODE(0, 0x033A) #define TSDB_CODE_SDB_INVALID_DATA_CONTENT TAOS_DEF_ERROR_CODE(0, 0x033B) +#define TSDB_CODE_SDB_INVALID_WAl_VER TAOS_DEF_ERROR_CODE(0, 0x033C) // mnode-dnode #define TSDB_CODE_MND_DNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0340) @@ -252,7 +253,7 @@ int32_t* taosGetErrno(); // dnode #define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0400) -#define TSDB_CODE_DND_EXITING TAOS_DEF_ERROR_CODE(0, 0x0401) +#define TSDB_CODE_DND_OFFLINE TAOS_DEF_ERROR_CODE(0, 0x0401) #define TSDB_CODE_DND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0402) #define TSDB_CODE_DND_DNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0410) #define TSDB_CODE_DND_DNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0411) diff --git a/include/util/tfile.h b/include/util/tfile.h index b3d141c4434154bf0ac6887aae1dc0e0a12b8efa..d3813051a4fb62777c9df0c442617b267896e16c 100644 --- a/include/util/tfile.h +++ b/include/util/tfile.h @@ -43,7 +43,7 @@ int32_t tfFsync(int64_t tfd); bool tfValid(int64_t tfd); int64_t tfLseek(int64_t tfd, int64_t offset, int32_t whence); int32_t tfFtruncate(int64_t tfd, int64_t length); - +void * tfMmapReadOnly(int64_t tfd, int64_t length); #ifdef __cplusplus } #endif diff --git a/include/util/thash.h b/include/util/thash.h index f38ab50893cfdad92281474bf12120f5e5bc3769..a736fc26af37ad1989fd04a04113db039d69c70f 100644 --- a/include/util/thash.h +++ b/include/util/thash.h @@ -24,7 +24,7 @@ extern "C" { #include "tlockfree.h" typedef uint32_t (*_hash_fn_t)(const char *, uint32_t); -typedef int32_t (*_equal_fn_t)(const void*, const void*, uint32_t len); +typedef int32_t (*_equal_fn_t)(const void*, const void*, size_t len); typedef void (*_hash_before_fn_t)(void *); typedef void (*_hash_free_fn_t)(void *); diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 7aa4bc9ee968b2d7f643215964560fa709cffb8b..705d6ef78647b0789213116bb0e63a9b1b1ed9e4 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -146,6 +146,8 @@ int taos_init(); void* createTscObj(const char* user, const char* auth, const char *db, SAppInstInfo* pAppInfo); void destroyTscObj(void*pObj); +uint64_t generateRequestId(); + void *createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type); void destroyRequest(SRequestObj* pRequest); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 960ba95324ca90d96fc9af6f1106acdc2c37737d..0e3afb60c0c883dcf171e7dd92f2b07dcf1ef5f8 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -53,8 +53,8 @@ static void registerRequest(SRequestObj* pRequest) { int32_t total = atomic_add_fetch_32(&pSummary->totalRequests, 1); int32_t currentInst = atomic_add_fetch_32(&pSummary->currentRequests, 1); - tscDebug("0x%" PRIx64 " new Request from connObj:0x%" PRIx64 ", current:%d, app current:%d, total:%d", pRequest->self, - pRequest->pTscObj->id, num, currentInst, total); + tscDebug("0x%" PRIx64 " new Request from connObj:0x%" PRIx64 ", current:%d, app current:%d, total:%d, reqId:0x%"PRIx64, pRequest->self, + pRequest->pTscObj->id, num, currentInst, total, pRequest->requestId); } } @@ -87,6 +87,7 @@ static void tscInitLogFile() { } } +// todo close the transporter properly void closeTransporter(STscObj* pTscObj) { if (pTscObj == NULL || pTscObj->pTransporter == NULL) { return; @@ -166,8 +167,7 @@ void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t ty return NULL; } - // TODO generated request uuid - pRequest->requestId = 0; + pRequest->requestId = generateRequestId(); pRequest->metric.start = taosGetTimestampMs(); pRequest->type = type; @@ -180,6 +180,14 @@ void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t ty return pRequest; } +static void doFreeReqResultInfo(SReqResultInfo* pResInfo) { + tfree(pResInfo->pRspMsg); + tfree(pResInfo->length); + tfree(pResInfo->row); + tfree(pResInfo->pCol); + tfree(pResInfo->fields); +} + static void doDestroyRequest(void* p) { assert(p != NULL); SRequestObj* pRequest = (SRequestObj*)p; @@ -190,7 +198,7 @@ static void doDestroyRequest(void* p) { tfree(pRequest->sqlstr); tfree(pRequest->pInfo); - tfree(pRequest->body.resInfo.pRspMsg); + doFreeReqResultInfo(&pRequest->body.resInfo); deregisterRequest(pRequest); tfree(pRequest); @@ -410,6 +418,39 @@ int taos_options_imp(TSDB_OPTION option, const char *str) { return 0; } +/** + * The request id is an unsigned integer format of 64bit. + *+------------+-----+-----------+---------------+ + *| uid|localIp| PId | timestamp | serial number | + *+------------+-----+-----------+---------------+ + *| 12bit |12bit|24bit |16bit | + *+------------+-----+-----------+---------------+ + * @return + */ +uint64_t generateRequestId() { + static uint64_t hashId = 0; + static int32_t requestSerialId = 0; + + if (hashId == 0) { + char uid[64] = {0}; + int32_t code = taosGetSystemUUID(uid, tListLen(uid)); + if (code != TSDB_CODE_SUCCESS) { + tscError("Failed to get the system uid to generated request id, reason:%s. use ip address instead", + tstrerror(TAOS_SYSTEM_ERROR(errno))); + + } else { + hashId = MurmurHash3_32(uid, strlen(uid)); + } + } + + int64_t ts = taosGetTimestampMs(); + uint64_t pid = taosGetPId(); + int32_t val = atomic_add_fetch_32(&requestSerialId, 1); + + uint64_t id = ((hashId & 0x0FFF) << 52) | ((pid & 0x0FFF) << 40) | ((ts & 0xFFFFFF) << 16) | (val & 0xFFFF); + return id; +} + #if 0 #include "cJSON.h" static setConfRet taos_set_config_imp(const char *config){ diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index b0b2c57ee462ae6960e08de517edde1931e7aba3..a416033946d9f1fc4398cc544ff45ac7fe472aa5 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -140,7 +140,7 @@ int32_t buildRequest(STscObj *pTscObj, const char *sql, int sqlLen, SRequestObj* (*pRequest)->sqlstr[sqlLen] = 0; (*pRequest)->sqlLen = sqlLen; - tscDebugL("0x%"PRIx64" SQL: %s", (*pRequest)->requestId, (*pRequest)->sqlstr); + tscDebugL("0x%"PRIx64" SQL: %s, reqId:0x"PRIx64, (*pRequest)->self, (*pRequest)->sqlstr, (*pRequest)->requestId); return TSDB_CODE_SUCCESS; } @@ -192,19 +192,22 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) { } tsem_wait(&pRequest->body.rspSem); - destroySendMsgInfo(pSendMsg); return TSDB_CODE_SUCCESS; } -int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQuery, SQueryDag** pDag) { - pRequest->type = pQuery->type; - return qCreateQueryDag(pQuery, pDag); +int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQueryNode, SQueryDag** pDag) { + pRequest->type = pQueryNode->type; + return qCreateQueryDag(pQueryNode, pDag, pRequest->requestId); } int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, void** pJob) { if (TSDB_SQL_INSERT == pRequest->type || TSDB_SQL_CREATE_TABLE == pRequest->type) { - return scheduleExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob, &pRequest->affectedRows); + SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf}; + int32_t code = scheduleExecJob(pRequest->pTscObj->pTransporter, NULL, pDag, pJob, &res); + pRequest->affectedRows = res.numOfRows; + return res.code; } + return scheduleAsyncExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob); } @@ -360,8 +363,6 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con asyncSendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body); tsem_wait(&pRequest->body.rspSem); - destroySendMsgInfo(body); - if (pRequest->code != TSDB_CODE_SUCCESS) { const char *errorMsg = (pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(terrno); printf("failed to connect to server, reason: %s\n\n", errorMsg); @@ -370,7 +371,7 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con taos_close(pTscObj); pTscObj = NULL; } else { - tscDebug("0x%"PRIx64" connection is opening, connId:%d, dnodeConn:%p", pTscObj->id, pTscObj->connId, pTscObj->pTransporter); + tscDebug("0x%"PRIx64" connection is opening, connId:%d, dnodeConn:%p, reqId:0x%"PRIx64, pTscObj->id, pTscObj->connId, pTscObj->pTransporter, pRequest->requestId); destroyRequest(pRequest); } @@ -440,30 +441,33 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { * There is not response callback function for submit response. * The actual inserted number of points is the first number. */ + int32_t elapsed = pRequest->metric.rsp - pRequest->metric.start; if (pMsg->code == TSDB_CODE_SUCCESS) { - tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%" PRId64 " ms", pRequest->requestId, - TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, - pRequest->metric.rsp - pRequest->metric.start); + tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%d ms, reqId:0x%"PRIx64, pRequest->self, + TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId); } else { - tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%" PRId64 " ms", pRequest->requestId, - TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, - pRequest->metric.rsp - pRequest->metric.start); + tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%d ms, reqId:0x%"PRIx64, pRequest->self, + TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId); } taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId); } - SDataBuf buf = {.len = pMsg->contLen}; - buf.pData = calloc(1, pMsg->contLen); - if (buf.pData == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - pMsg->code = TSDB_CODE_OUT_OF_MEMORY; - } else { - memcpy(buf.pData, pMsg->pCont, pMsg->contLen); + SDataBuf buf = {.len = pMsg->contLen, .pData = NULL}; + + if (pMsg->contLen > 0) { + buf.pData = calloc(1, pMsg->contLen); + if (buf.pData == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + pMsg->code = TSDB_CODE_OUT_OF_MEMORY; + } else { + memcpy(buf.pData, pMsg->pCont, pMsg->contLen); + } } pSendInfo->fp(pSendInfo->param, &buf, pMsg->code); rpcFreeCont(pMsg->pCont); + destroySendMsgInfo(pSendInfo); } TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port) { @@ -536,7 +540,6 @@ void* doFetchRow(SRequestObj* pRequest) { asyncSendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body); tsem_wait(&pRequest->body.rspSem); - destroySendMsgInfo(body); pResultInfo->current = 0; if (pResultInfo->numOfRows <= pResultInfo->current) { diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 894b810d7b29410b64a69b76f799f7cad2cf8a49..2b875b3eb54de4a7d333ff8d257a4fee2d7a60c8 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -29,7 +29,7 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) { // this function may be called by user or system, or by both simultaneously. void taos_cleanup(void) { - tscDebug("start to cleanup client environment"); + tscInfo("start to cleanup client environment"); if (atomic_val_compare_exchange_32(&sentinel, TSC_VAR_NOT_RELEASE, TSC_VAR_RELEASED) != TSC_VAR_NOT_RELEASE) { return; @@ -47,6 +47,8 @@ void taos_cleanup(void) { rpcCleanup(); taosCloseLog(); + + tscInfo("all local resources released"); } TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) { @@ -140,7 +142,9 @@ TAOS_ROW taos_fetch_row(TAOS_RES *pRes) { SRequestObj *pRequest = (SRequestObj *) pRes; if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || - pRequest->type == TSDB_SQL_INSERT || pRequest->code != TSDB_CODE_SUCCESS) { + pRequest->type == TSDB_SQL_INSERT || + pRequest->code != TSDB_CODE_SUCCESS || + taos_num_fields(pRes) == 0) { return NULL; } @@ -258,6 +262,8 @@ const char *taos_data_type(int type) { const char *taos_get_client_info() { return version; } -int taos_affected_rows(TAOS_RES *res) { return 1; } +int taos_affected_rows(TAOS_RES *res) { + return ((SRequestObj*)res)->affectedRows; +} int taos_result_precision(TAOS_RES *res) { return TSDB_TIME_PRECISION_MILLI; } diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index e402403496730288fcd46ff24ea32864f7eea3c7..fb1b97104956090de4cece3fd2c53a25c8dcf281 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -30,6 +30,7 @@ int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; setErrno(pRequest, code); + free(pMsg->pData); sem_post(&pRequest->body.rspSem); return code; } @@ -37,6 +38,7 @@ int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) { int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; if (code != TSDB_CODE_SUCCESS) { + free(pMsg->pData); setErrno(pRequest, code); sem_post(&pRequest->body.rspSem); return code; @@ -73,6 +75,7 @@ int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) { tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, pConnect->clusterId, pTscObj->pAppInfo->numOfConns); + free(pMsg->pData); sem_post(&pRequest->body.rspSem); return 0; } @@ -87,14 +90,14 @@ SMsgSendInfo* buildMsgInfoImpl(SRequestObj *pRequest) { if (pRequest->type == TDMT_MND_SHOW_RETRIEVE || pRequest->type == TDMT_VND_SHOW_TABLES_FETCH) { if (pRequest->type == TDMT_MND_SHOW_RETRIEVE) { - SRetrieveTableMsg* pRetrieveMsg = calloc(1, sizeof(SRetrieveTableMsg)); + SRetrieveTableReq* pRetrieveMsg = calloc(1, sizeof(SRetrieveTableReq)); if (pRetrieveMsg == NULL) { return NULL; } pRetrieveMsg->showId = htobe64(pRequest->body.showInfo.execId); pMsgSendInfo->msgInfo.pData = pRetrieveMsg; - pMsgSendInfo->msgInfo.len = sizeof(SRetrieveTableMsg); + pMsgSendInfo->msgInfo.len = sizeof(SRetrieveTableReq); } else { SVShowTablesFetchReq* pFetchMsg = calloc(1, sizeof(SVShowTablesFetchReq)); if (pFetchMsg == NULL) { @@ -238,6 +241,7 @@ int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) { int32_t processCreateDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { // todo rsp with the vnode id list SRequestObj* pRequest = param; + free(pMsg->pData); tsem_post(&pRequest->body.rspSem); } @@ -245,6 +249,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; if (code != TSDB_CODE_SUCCESS) { + free(pMsg->pData); setErrno(pRequest, code); tsem_post(&pRequest->body.rspSem); return code; @@ -258,6 +263,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { tNameGetDbName(&name, db); setConnectionDB(pRequest->pTscObj, db); + free(pMsg->pData); tsem_post(&pRequest->body.rspSem); return 0; } @@ -266,6 +272,7 @@ int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) { assert(pMsg != NULL && param != NULL); SRequestObj* pRequest = param; + free(pMsg->pData); if (code != TSDB_CODE_SUCCESS) { setErrno(pRequest, code); tsem_post(&pRequest->body.rspSem); diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 7a87acfc36433d530e94aac7b885b4909ae38446..ef2dcc21df82a854b3ab71822733c52007d9cc5d 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -57,175 +57,176 @@ TEST(testCase, connect_Test) { taos_close(pConn); } -//TEST(testCase, create_user_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'"); -// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { -// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); -// } -// -// taos_free_result(pRes); -// taos_close(pConn); -//} -// -//TEST(testCase, create_account_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'"); -// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { -// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); -// } -// -// taos_free_result(pRes); -// taos_close(pConn); -//} -// -//TEST(testCase, drop_account_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "drop account aabc"); -// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { -// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); -// } -// -// taos_free_result(pRes); -// taos_close(pConn); -//} +TEST(testCase, create_user_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); -//TEST(testCase, show_user_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "show users"); -// TAOS_ROW pRow = NULL; -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// int32_t numOfFields = taos_num_fields(pRes); -// -// char str[512] = {0}; -// while((pRow = taos_fetch_row(pRes)) != NULL) { -// int32_t code = taos_print_row(str, pRow, pFields, numOfFields); -// printf("%s\n", str); -// } -// -// taos_close(pConn); -//} + TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'"); + if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { + printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + } -//TEST(testCase, drop_user_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "drop user abc"); -// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { -// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); -// } -// -// taos_free_result(pRes); -// taos_close(pConn); -//} + taos_free_result(pRes); + taos_close(pConn); +} -//TEST(testCase, show_db_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -//// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "show databases"); -// TAOS_ROW pRow = NULL; -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// int32_t numOfFields = taos_num_fields(pRes); -// -// char str[512] = {0}; -// while((pRow = taos_fetch_row(pRes)) != NULL) { -// int32_t code = taos_print_row(str, pRow, pFields, numOfFields); -// printf("%s\n", str); -// } -// -// taos_close(pConn); -//} +TEST(testCase, create_account_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); -//TEST(testCase, create_db_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "create database abc1"); -// if (taos_errno(pRes) != 0) { -// printf("error in create db, reason:%s\n", taos_errstr(pRes)); -// } -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// ASSERT_TRUE(pFields == NULL); -// -// int32_t numOfFields = taos_num_fields(pRes); -// ASSERT_EQ(numOfFields, 0); -// -// taos_free_result(pRes); -// -// pRes = taos_query(pConn, "create database abc1 vgroups 4"); -// if (taos_errno(pRes) != 0) { -// printf("error in create db, reason:%s\n", taos_errstr(pRes)); -// } -// taos_close(pConn); -//} -// -//TEST(testCase, create_dnode_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "create dnode abc1 port 7000"); -// if (taos_errno(pRes) != 0) { -// printf("error in create dnode, reason:%s\n", taos_errstr(pRes)); -// } -// taos_free_result(pRes); -// -// pRes = taos_query(pConn, "create dnode 1.1.1.1 port 9000"); -// if (taos_errno(pRes) != 0) { -// printf("failed to create dnode, reason:%s\n", taos_errstr(pRes)); -// } -// taos_free_result(pRes); -// -// taos_close(pConn); -//} -// -//TEST(testCase, drop_dnode_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "drop dnode 2"); -// if (taos_errno(pRes) != 0) { -// printf("error in drop dnode, reason:%s\n", taos_errstr(pRes)); -// } -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// ASSERT_TRUE(pFields == NULL); -// -// int32_t numOfFields = taos_num_fields(pRes); -// ASSERT_EQ(numOfFields, 0); -// -// taos_free_result(pRes); -// taos_close(pConn); -//} -// -//TEST(testCase, use_db_test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "use abc1"); -// if (taos_errno(pRes) != 0) { -// printf("error in use db, reason:%s\n", taos_errstr(pRes)); -// } -// -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// ASSERT_TRUE(pFields == NULL); -// -// int32_t numOfFields = taos_num_fields(pRes); -// ASSERT_EQ(numOfFields, 0); -// -// taos_close(pConn); -//} + TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'"); + if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { + printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + } + + taos_free_result(pRes); + taos_close(pConn); +} + +TEST(testCase, drop_account_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "drop account aabc"); + if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { + printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + } + + taos_free_result(pRes); + taos_close(pConn); +} + +TEST(testCase, show_user_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "show users"); + TAOS_ROW pRow = NULL; + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + int32_t numOfFields = taos_num_fields(pRes); + + char str[512] = {0}; + while((pRow = taos_fetch_row(pRes)) != NULL) { + int32_t code = taos_print_row(str, pRow, pFields, numOfFields); + printf("%s\n", str); + } + + taos_free_result(pRes); + taos_close(pConn); +} + +TEST(testCase, drop_user_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "drop user abc"); + if (taos_errno(pRes) != TSDB_CODE_SUCCESS) { + printf("failed to create user, reason:%s\n", taos_errstr(pRes)); + } + + taos_free_result(pRes); + taos_close(pConn); +} + +TEST(testCase, show_db_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "show databases"); + TAOS_ROW pRow = NULL; + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + int32_t numOfFields = taos_num_fields(pRes); + + char str[512] = {0}; + while((pRow = taos_fetch_row(pRes)) != NULL) { + int32_t code = taos_print_row(str, pRow, pFields, numOfFields); + printf("%s\n", str); + } + + taos_close(pConn); +} + +TEST(testCase, create_db_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "create database abc1"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + } + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + ASSERT_TRUE(pFields == NULL); + + int32_t numOfFields = taos_num_fields(pRes); + ASSERT_EQ(numOfFields, 0); + + taos_free_result(pRes); + + pRes = taos_query(pConn, "create database abc1 vgroups 4"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + } + taos_close(pConn); +} + +TEST(testCase, create_dnode_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "create dnode abc1 port 7000"); + if (taos_errno(pRes) != 0) { + printf("error in create dnode, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create dnode 1.1.1.1 port 9000"); + if (taos_errno(pRes) != 0) { + printf("failed to create dnode, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + taos_close(pConn); +} + +TEST(testCase, drop_dnode_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "drop dnode 2"); + if (taos_errno(pRes) != 0) { + printf("error in drop dnode, reason:%s\n", taos_errstr(pRes)); + } + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + ASSERT_TRUE(pFields == NULL); + + int32_t numOfFields = taos_num_fields(pRes); + ASSERT_EQ(numOfFields, 0); + + taos_free_result(pRes); + taos_close(pConn); +} + +TEST(testCase, use_db_test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + } + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + ASSERT_TRUE(pFields == NULL); + + int32_t numOfFields = taos_num_fields(pRes); + ASSERT_EQ(numOfFields, 0); + + taos_close(pConn); +} //TEST(testCase, drop_db_test) { //// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -249,69 +250,69 @@ TEST(testCase, connect_Test) { //// taos_close(pConn); //} -// TEST(testCase, create_stable_Test) { + TEST(testCase, create_stable_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "create database abc1"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)"); + if (taos_errno(pRes) != 0) { + printf("error in create stable, reason:%s\n", taos_errstr(pRes)); + } + + TAOS_FIELD* pFields = taos_fetch_fields(pRes); + ASSERT_TRUE(pFields == NULL); + + int32_t numOfFields = taos_num_fields(pRes); + ASSERT_EQ(numOfFields, 0); + + taos_free_result(pRes); + taos_close(pConn); +} + +TEST(testCase, create_table_Test) { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + assert(pConn != NULL); + + TAOS_RES* pRes = taos_query(pConn, "use abc1"); + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table tm0(ts timestamp, k int)"); + taos_free_result(pRes); + + taos_close(pConn); +} + +//TEST(testCase, create_ctable_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // assert(pConn != NULL); // -// TAOS_RES* pRes = taos_query(pConn, "create database abc1"); -// if (taos_errno(pRes) != 0) { -// printf("error in create db, reason:%s\n", taos_errstr(pRes)); -// } -// taos_free_result(pRes); -// -// pRes = taos_query(pConn, "use abc1"); +// TAOS_RES* pRes = taos_query(pConn, "use abc1"); // if (taos_errno(pRes) != 0) { -// printf("error in use db, reason:%s\n", taos_errstr(pRes)); +// printf("failed to use db, reason:%s\n", taos_errstr(pRes)); // } // taos_free_result(pRes); // -// pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)"); +// pRes = taos_query(pConn, "create table tm0 using st1 tags(1)"); // if (taos_errno(pRes) != 0) { -// printf("error in create stable, reason:%s\n", taos_errstr(pRes)); +// printf("failed to create child table tm0, reason:%s\n", taos_errstr(pRes)); // } // -// TAOS_FIELD* pFields = taos_fetch_fields(pRes); -// ASSERT_TRUE(pFields == NULL); -// -// int32_t numOfFields = taos_num_fields(pRes); -// ASSERT_EQ(numOfFields, 0); -// // taos_free_result(pRes); // taos_close(pConn); //} // -//TEST(testCase, create_table_Test) { -// // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// // assert(pConn != NULL); -// // -// // TAOS_RES* pRes = taos_query(pConn, "use abc1"); -// // taos_free_result(pRes); -// // -// // pRes = taos_query(pConn, "create table tm0(ts timestamp, k int)"); -// // taos_free_result(pRes); -// // -// // taos_close(pConn); -//} -// -//TEST(testCase, create_ctable_Test) { -// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); -// assert(pConn != NULL); -// -// TAOS_RES* pRes = taos_query(pConn, "use abc1"); -// if (taos_errno(pRes) != 0) { -// printf("failed to use db, reason:%s\n", taos_errstr(pRes)); -// } -// taos_free_result(pRes); -// -//// pRes = taos_query(pConn, "create table tm0 using st1 tags(1)"); -//// if (taos_errno(pRes) != 0) { -//// printf("failed to create child table tm0, reason:%s\n", taos_errstr(pRes)); -//// } -//// -//// taos_free_result(pRes); -// taos_close(pConn); -//} -// //TEST(testCase, show_stable_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // assert(pConn != NULL); @@ -342,7 +343,7 @@ TEST(testCase, connect_Test) { // taos_free_result(pRes); // taos_close(pConn); //} -// + //TEST(testCase, show_vgroup_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // assert(pConn != NULL); @@ -375,7 +376,7 @@ TEST(testCase, connect_Test) { // // taos_close(pConn); //} -// + //TEST(testCase, drop_stable_Test) { // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // assert(pConn != NULL); @@ -465,14 +466,29 @@ TEST(testCase, connect_Test) { TEST(testCase, create_multiple_tables) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); - assert(pConn != NULL); + ASSERT_NE(pConn, nullptr); TAOS_RES* pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("failed to use db, reason:%s", taos_errstr(pRes)); + taos_free_result(pRes); + taos_close(pConn); + return; + } + taos_free_result(pRes); - pRes = taos_query(pConn, "create table t_2 using st1 tags(1) t_3 using st1 tags(2)"); + pRes = taos_query(pConn, "create table t_2 using st1 tags(1)"); + if (taos_errno(pRes) != 0) { + printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); + taos_free_result(pRes); + ASSERT_TRUE(false); + } + + taos_free_result(pRes); + pRes = taos_query(pConn, "create table t_3 using st1 tags(2)"); if (taos_errno(pRes) != 0) { - printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes)); + printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); ASSERT_TRUE(false); } @@ -488,5 +504,61 @@ TEST(testCase, create_multiple_tables) { } taos_free_result(pRes); + +// for(int32_t i = 0; i < 10000; ++i) { +// char sql[512] = {0}; +// snprintf(sql, tListLen(sql), "create table t_x_%d using st1 tags(2)", i); +// 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)); +// } +// taos_free_result(pres); +// } + taos_close(pConn); } + +TEST(testCase, generated_request_id_test) { + SHashObj *phash = taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); + + for(int32_t i = 0; i < 50000000; ++i) { + uint64_t v = generateRequestId(); + void* result = taosHashGet(phash, &v, sizeof(v)); + if (result != nullptr) { + printf("0x%"PRIx64", index:%d\n", v, i); + } + assert(result == nullptr); + taosHashPut(phash, &v, sizeof(v), NULL, 0); + } + + taosHashCleanup(phash); +} + +//TEST(testCase, projection_query_tables) { +// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); +// ASSERT_EQ(pConn, nullptr); +// +// TAOS_RES* pRes = taos_query(pConn, "use abc1"); +// taos_free_result(pRes); +// +// pRes = taos_query(pConn, "select * from t_2"); +// if (taos_errno(pRes) != 0) { +// printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes)); +// taos_free_result(pRes); +// ASSERT_TRUE(false); +// } +// +// TAOS_ROW pRow = NULL; +// TAOS_FIELD* pFields = taos_fetch_fields(pRes); +// int32_t numOfFields = taos_num_fields(pRes); +// +// char str[512] = {0}; +// while((pRow = taos_fetch_row(pRes)) != NULL) { +// int32_t code = taos_print_row(str, pRow, pFields, numOfFields); +// printf("%s\n", str); +// } +// +// taos_free_result(pRes); +// taos_close(pConn); +//} + diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 0874c471aa202aef1fc734458f7fa3390e3bf2ab..c1048f8482ae10cc1eb9cfc77327e3e143c6f683 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -140,6 +140,7 @@ void *tSVCreateTbBatchReqDeserialize(void *buf, SVCreateTbBatchReq *pReq) { buf = taosDecodeFixedU64(buf, &pReq->ver); buf = taosDecodeFixedU32(buf, &nsize); + pReq->pArray = taosArrayInit(nsize, sizeof(SVCreateTbReq)); for (size_t i = 0; i < nsize; i++) { SVCreateTbReq req; buf = tDeserializeSVCreateTbReq(buf, &req); diff --git a/source/dnode/bnode/inc/bndInt.h b/source/dnode/bnode/inc/bndInt.h index d44c520a26e426bc5ea5f39441576e687bf50946..cddb1e50f14526df43e7e2234950a71ac74be864 100644 --- a/source/dnode/bnode/inc/bndInt.h +++ b/source/dnode/bnode/inc/bndInt.h @@ -33,9 +33,9 @@ typedef struct SBnode { int32_t dnodeId; int64_t clusterId; SBnodeCfg cfg; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SBnode; #ifdef __cplusplus diff --git a/source/dnode/mgmt/impl/inc/dndDnode.h b/source/dnode/mgmt/impl/inc/dndDnode.h index a2015913a7680789e81df4ee0e598547af755252..69c2aa1fbf39be66d066732c401192f7bd9eb016 100644 --- a/source/dnode/mgmt/impl/inc/dndDnode.h +++ b/source/dnode/mgmt/impl/inc/dndDnode.h @@ -29,8 +29,8 @@ int64_t dndGetClusterId(SDnode *pDnode); void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort); void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet); -void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg); -void dndSendStatusMsg(SDnode *pDnode); +void dndSendRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg); +void dndSendStatusReq(SDnode *pDnode); void dndProcessMgmtMsg(SDnode *pDnode, SRpcMsg *pRpcMsg, SEpSet *pEpSet); void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); diff --git a/source/dnode/mgmt/impl/inc/dndTransport.h b/source/dnode/mgmt/impl/inc/dndTransport.h index 312da69fa23d6accc7057965ad3e97e86a737e21..42fb379fc1bf201ec617ce6b7b3236a5eff23782 100644 --- a/source/dnode/mgmt/impl/inc/dndTransport.h +++ b/source/dnode/mgmt/impl/inc/dndTransport.h @@ -23,8 +23,8 @@ extern "C" { int32_t dndInitTrans(SDnode *pDnode); void dndCleanupTrans(SDnode *pDnode); -void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pRpcMsg); -void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pRpcMsg); +int32_t dndSendReqToMnode(SDnode *pDnode, SRpcMsg *pRpcMsg); +int32_t dndSendReqToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pRpcMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/impl/src/dndBnode.c b/source/dnode/mgmt/impl/src/dndBnode.c index c12d449517adcf5fbeafe1a5f727177000ab10b3..1b2e56edfe19437c241655b834a37e86eb995759 100644 --- a/source/dnode/mgmt/impl/src/dndBnode.c +++ b/source/dnode/mgmt/impl/src/dndBnode.c @@ -27,7 +27,7 @@ static SBnode *dndAcquireBnode(SDnode *pDnode) { int32_t refCount = 0; taosRLockLatch(&pMgmt->latch); - if (pMgmt->deployed && !pMgmt->dropped) { + if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pBnode != NULL) { refCount = atomic_add_fetch_32(&pMgmt->refCount, 1); pBnode = pMgmt->pBnode; } else { @@ -60,7 +60,7 @@ static int32_t dndReadBnodeFile(SDnode *pDnode) { SBnodeMgmt *pMgmt = &pDnode->bmgmt; int32_t code = TSDB_CODE_DND_BNODE_READ_FILE_ERROR; int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); cJSON *root = NULL; @@ -127,7 +127,7 @@ static int32_t dndWriteBnodeFile(SDnode *pDnode) { } int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); @@ -170,7 +170,7 @@ static void dndStopBnodeWorker(SDnode *pDnode) { pMgmt->deployed = 0; taosWUnLockLatch(&pMgmt->latch); - while (pMgmt->refCount > 1) { + while (pMgmt->refCount > 0) { taosMsleep(10); } @@ -179,9 +179,9 @@ static void dndStopBnodeWorker(SDnode *pDnode) { static void dndBuildBnodeOption(SDnode *pDnode, SBnodeOpt *pOption) { pOption->pDnode = pDnode; - pOption->sendMsgToDnodeFp = dndSendMsgToDnode; - pOption->sendMsgToMnodeFp = dndSendMsgToMnode; - pOption->sendRedirectMsgFp = dndSendRedirectMsg; + pOption->sendReqToDnodeFp = dndSendReqToDnode; + pOption->sendReqToMnodeFp = dndSendReqToMnode; + pOption->sendRedirectRspFp = dndSendRedirectRsp; pOption->dnodeId = dndGetDnodeId(pDnode); pOption->clusterId = dndGetClusterId(pDnode); pOption->cfg.sver = pDnode->opt.sver; @@ -189,10 +189,18 @@ static void dndBuildBnodeOption(SDnode *pDnode, SBnodeOpt *pOption) { static int32_t dndOpenBnode(SDnode *pDnode) { SBnodeMgmt *pMgmt = &pDnode->bmgmt; - SBnodeOpt option = {0}; + SBnode *pBnode = dndAcquireBnode(pDnode); + if (pBnode != NULL) { + dndReleaseBnode(pDnode, pBnode); + terrno = TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED; + dError("failed to create bnode since %s", terrstr()); + return -1; + } + + SBnodeOpt option = {0}; dndBuildBnodeOption(pDnode, &option); - SBnode *pBnode = bndOpen(pDnode->dir.bnode, &option); + pBnode = bndOpen(pDnode->dir.bnode, &option); if (pBnode == NULL) { dError("failed to open bnode since %s", terrstr()); return -1; @@ -256,11 +264,12 @@ static int32_t dndDropBnode(SDnode *pDnode) { } int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDCreateBnodeMsg *pMsg = pRpcMsg->pCont; + SDCreateBnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_BNODE_ID_INVALID; + dError("failed to create bnode since %s", terrstr()); return -1; } else { return dndOpenBnode(pDnode); @@ -268,11 +277,12 @@ int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { } int32_t dndProcessDropBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDDropBnodeMsg *pMsg = pRpcMsg->pCont; + SDDropBnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_BNODE_ID_INVALID; + dError("failed to drop bnode since %s", terrstr()); return -1; } else { return dndDropBnode(pDnode); diff --git a/source/dnode/mgmt/impl/src/dndDnode.c b/source/dnode/mgmt/impl/src/dndDnode.c index 30b069f349c4e3cb3f33e31bd0d93df42df3fce2..f5f9bbf1b84367100b07e4c3216cbb3361a941c9 100644 --- a/source/dnode/mgmt/impl/src/dndDnode.c +++ b/source/dnode/mgmt/impl/src/dndDnode.c @@ -80,7 +80,7 @@ void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { taosRUnLockLatch(&pMgmt->latch); } -void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) { +void dndSendRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg) { tmsg_t msgType = pMsg->msgType; SEpSet epSet = {0}; @@ -354,7 +354,7 @@ static int32_t dndWriteDnodes(SDnode *pDnode) { return 0; } -void dndSendStatusMsg(SDnode *pDnode) { +void dndSendStatusReq(SDnode *pDnode) { int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad); SStatusMsg *pStatus = rpcMallocCont(contLen); @@ -391,7 +391,7 @@ void dndSendStatusMsg(SDnode *pDnode) { pMgmt->statusSent = 1; dTrace("pDnode:%p, send status msg to mnode", pDnode); - dndSendMsgToMnode(pDnode, &rpcMsg); + dndSendReqToMnode(pDnode, &rpcMsg); } static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) { @@ -491,7 +491,7 @@ static void *dnodeThreadRoutine(void *param) { taosMsleep(ms); if (dndGetStat(pDnode) == DND_STAT_RUNNING && !pMgmt->statusSent && !pMgmt->dropped) { - dndSendStatusMsg(pDnode); + dndSendStatusReq(pDnode); } } } diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c index 577cb0c3b07115a1d4f3eb0932430a9671ebaa0d..a8bf26f133a3cd76a6e6b5d688b2598db04865b8 100644 --- a/source/dnode/mgmt/impl/src/dndMnode.c +++ b/source/dnode/mgmt/impl/src/dndMnode.c @@ -19,6 +19,7 @@ #include "dndTransport.h" #include "dndWorker.h" +static void dndWriteMnodeMsgToWorker(SDnode *pDnode, SDnodeWorker *pWorker, SRpcMsg *pRpcMsg); static void dndProcessMnodeQueue(SDnode *pDnode, SMnodeMsg *pMsg); static SMnode *dndAcquireMnode(SDnode *pDnode) { @@ -258,11 +259,16 @@ static bool dndNeedDeployMnode(SDnode *pDnode) { return true; } +static int32_t dndPutMsgToMWriteQ(SDnode *pDnode, SRpcMsg *pRpcMsg) { + dndWriteMnodeMsgToWorker(pDnode, &pDnode->mmgmt.writeWorker, pRpcMsg); +} + static void dndInitMnodeOption(SDnode *pDnode, SMnodeOpt *pOption) { pOption->pDnode = pDnode; - pOption->sendMsgToDnodeFp = dndSendMsgToDnode; - pOption->sendMsgToMnodeFp = dndSendMsgToMnode; - pOption->sendRedirectMsgFp = dndSendRedirectMsg; + pOption->sendReqToDnodeFp = dndSendReqToDnode; + pOption->sendReqToMnodeFp = dndSendReqToMnode; + pOption->sendRedirectRspFp = dndSendRedirectRsp; + pOption->putReqToMWriteQFp = dndPutMsgToMWriteQ; pOption->dnodeId = dndGetDnodeId(pDnode); pOption->clusterId = dndGetClusterId(pDnode); pOption->cfg.sver = pDnode->opt.sver; diff --git a/source/dnode/mgmt/impl/src/dndQnode.c b/source/dnode/mgmt/impl/src/dndQnode.c index 1f3d6ee371a41279b83bc52233ab30ce369e48a8..845ea8bf9a14b5492ce1233f1aa74fd8cfce1d47 100644 --- a/source/dnode/mgmt/impl/src/dndQnode.c +++ b/source/dnode/mgmt/impl/src/dndQnode.c @@ -27,7 +27,7 @@ static SQnode *dndAcquireQnode(SDnode *pDnode) { int32_t refCount = 0; taosRLockLatch(&pMgmt->latch); - if (pMgmt->deployed && !pMgmt->dropped) { + if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pQnode != NULL) { refCount = atomic_add_fetch_32(&pMgmt->refCount, 1); pQnode = pMgmt->pQnode; } else { @@ -60,7 +60,7 @@ static int32_t dndReadQnodeFile(SDnode *pDnode) { SQnodeMgmt *pMgmt = &pDnode->qmgmt; int32_t code = TSDB_CODE_DND_QNODE_READ_FILE_ERROR; int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); cJSON *root = NULL; @@ -127,7 +127,7 @@ static int32_t dndWriteQnodeFile(SDnode *pDnode) { } int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); @@ -175,7 +175,7 @@ static void dndStopQnodeWorker(SDnode *pDnode) { pMgmt->deployed = 0; taosWUnLockLatch(&pMgmt->latch); - while (pMgmt->refCount > 1) { + while (pMgmt->refCount > 0) { taosMsleep(10); } @@ -185,9 +185,9 @@ static void dndStopQnodeWorker(SDnode *pDnode) { static void dndBuildQnodeOption(SDnode *pDnode, SQnodeOpt *pOption) { pOption->pDnode = pDnode; - pOption->sendMsgToDnodeFp = dndSendMsgToDnode; - pOption->sendMsgToMnodeFp = dndSendMsgToMnode; - pOption->sendRedirectMsgFp = dndSendRedirectMsg; + pOption->sendReqToDnodeFp = dndSendReqToDnode; + pOption->sendReqToMnodeFp = dndSendReqToMnode; + pOption->sendRedirectRspFp = dndSendRedirectRsp; pOption->dnodeId = dndGetDnodeId(pDnode); pOption->clusterId = dndGetClusterId(pDnode); pOption->cfg.sver = pDnode->opt.sver; @@ -195,10 +195,19 @@ static void dndBuildQnodeOption(SDnode *pDnode, SQnodeOpt *pOption) { static int32_t dndOpenQnode(SDnode *pDnode) { SQnodeMgmt *pMgmt = &pDnode->qmgmt; - SQnodeOpt option = {0}; + + SQnode *pQnode = dndAcquireQnode(pDnode); + if (pQnode != NULL) { + dndReleaseQnode(pDnode, pQnode); + terrno = TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED; + dError("failed to create qnode since %s", terrstr()); + return -1; + } + + SQnodeOpt option = {0}; dndBuildQnodeOption(pDnode, &option); - SQnode *pQnode = qndOpen(&option); + pQnode = qndOpen(&option); if (pQnode == NULL) { dError("failed to open qnode since %s", terrstr()); return -1; @@ -261,11 +270,12 @@ static int32_t dndDropQnode(SDnode *pDnode) { } int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDCreateQnodeMsg *pMsg = pRpcMsg->pCont; + SDCreateQnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_QNODE_ID_INVALID; + dError("failed to create qnode since %s", terrstr()); return -1; } else { return dndOpenQnode(pDnode); @@ -273,11 +283,12 @@ int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { } int32_t dndProcessDropQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDDropQnodeMsg *pMsg = pRpcMsg->pCont; + SDDropQnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_QNODE_ID_INVALID; + dError("failed to drop qnode since %s", terrstr()); return -1; } else { return dndDropQnode(pDnode); @@ -293,15 +304,18 @@ static void dndProcessQnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) { if (pQnode != NULL) { code = qndProcessMsg(pQnode, pMsg, &pRsp); } + dndReleaseQnode(pDnode, pQnode); - if (pRsp != NULL) { - pRsp->ahandle = pMsg->ahandle; - rpcSendResponse(pRsp); - free(pRsp); - } else { - if (code != 0) code = terrno; - SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; - rpcSendResponse(&rpcRsp); + if (pMsg->msgType & 1u) { + if (pRsp != NULL) { + pRsp->ahandle = pMsg->ahandle; + rpcSendResponse(pRsp); + free(pRsp); + } else { + if (code != 0) code = terrno; + SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; + rpcSendResponse(&rpcRsp); + } } rpcFreeCont(pMsg->pCont); diff --git a/source/dnode/mgmt/impl/src/dndSnode.c b/source/dnode/mgmt/impl/src/dndSnode.c index ab4ca191a9e74d63ba7f8d441009f5c5e8f0187c..7f234629cb1f80e4c9d5d258def74b3da1134ae4 100644 --- a/source/dnode/mgmt/impl/src/dndSnode.c +++ b/source/dnode/mgmt/impl/src/dndSnode.c @@ -27,7 +27,7 @@ static SSnode *dndAcquireSnode(SDnode *pDnode) { int32_t refCount = 0; taosRLockLatch(&pMgmt->latch); - if (pMgmt->deployed && !pMgmt->dropped) { + if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pSnode != NULL) { refCount = atomic_add_fetch_32(&pMgmt->refCount, 1); pSnode = pMgmt->pSnode; } else { @@ -60,7 +60,7 @@ static int32_t dndReadSnodeFile(SDnode *pDnode) { SSnodeMgmt *pMgmt = &pDnode->smgmt; int32_t code = TSDB_CODE_DND_SNODE_READ_FILE_ERROR; int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); cJSON *root = NULL; @@ -127,7 +127,7 @@ static int32_t dndWriteSnodeFile(SDnode *pDnode) { } int32_t len = 0; - int32_t maxLen = 4096; + int32_t maxLen = 1024; char *content = calloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); @@ -170,18 +170,18 @@ static void dndStopSnodeWorker(SDnode *pDnode) { pMgmt->deployed = 0; taosWUnLockLatch(&pMgmt->latch); - while (pMgmt->refCount > 1) { + while (pMgmt->refCount > 0) { taosMsleep(10); - } + } dndCleanupWorker(&pMgmt->writeWorker); } static void dndBuildSnodeOption(SDnode *pDnode, SSnodeOpt *pOption) { pOption->pDnode = pDnode; - pOption->sendMsgToDnodeFp = dndSendMsgToDnode; - pOption->sendMsgToMnodeFp = dndSendMsgToMnode; - pOption->sendRedirectMsgFp = dndSendRedirectMsg; + pOption->sendReqToDnodeFp = dndSendReqToDnode; + pOption->sendReqToMnodeFp = dndSendReqToMnode; + pOption->sendRedirectRspFp = dndSendRedirectRsp; pOption->dnodeId = dndGetDnodeId(pDnode); pOption->clusterId = dndGetClusterId(pDnode); pOption->cfg.sver = pDnode->opt.sver; @@ -189,10 +189,18 @@ static void dndBuildSnodeOption(SDnode *pDnode, SSnodeOpt *pOption) { static int32_t dndOpenSnode(SDnode *pDnode) { SSnodeMgmt *pMgmt = &pDnode->smgmt; - SSnodeOpt option = {0}; + SSnode *pSnode = dndAcquireSnode(pDnode); + if (pSnode != NULL) { + dndReleaseSnode(pDnode, pSnode); + terrno = TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED; + dError("failed to create snode since %s", terrstr()); + return -1; + } + + SSnodeOpt option = {0}; dndBuildSnodeOption(pDnode, &option); - SSnode *pSnode = sndOpen(pDnode->dir.snode, &option); + pSnode = sndOpen(pDnode->dir.snode, &option); if (pSnode == NULL) { dError("failed to open snode since %s", terrstr()); return -1; @@ -256,11 +264,12 @@ static int32_t dndDropSnode(SDnode *pDnode) { } int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDCreateSnodeMsg *pMsg = pRpcMsg->pCont; + SDCreateSnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_SNODE_ID_INVALID; + dError("failed to create snode since %s", terrstr()); return -1; } else { return dndOpenSnode(pDnode); @@ -268,11 +277,12 @@ int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { } int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { - SDDropSnodeMsg *pMsg = pRpcMsg->pCont; + SDDropSnodeReq *pMsg = pRpcMsg->pCont; pMsg->dnodeId = htonl(pMsg->dnodeId); if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { terrno = TSDB_CODE_DND_SNODE_ID_INVALID; + dError("failed to drop snode since %s", terrstr()); return -1; } else { return dndDropSnode(pDnode); @@ -288,15 +298,18 @@ static void dndProcessSnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) { if (pSnode != NULL) { code = sndProcessMsg(pSnode, pMsg, &pRsp); } + dndReleaseSnode(pDnode, pSnode); - if (pRsp != NULL) { - pRsp->ahandle = pMsg->ahandle; - rpcSendResponse(pRsp); - free(pRsp); - } else { - if (code != 0) code = terrno; - SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; - rpcSendResponse(&rpcRsp); + if (pMsg->msgType & 1u) { + if (pRsp != NULL) { + pRsp->ahandle = pMsg->ahandle; + rpcSendResponse(pRsp); + free(pRsp); + } else { + if (code != 0) code = terrno; + SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; + rpcSendResponse(&rpcRsp); + } } rpcFreeCont(pMsg->pCont); diff --git a/source/dnode/mgmt/impl/src/dndTransport.c b/source/dnode/mgmt/impl/src/dndTransport.c index dc5248c8e0ecd5cfddab311d2db5b8cb1ab12897..cf0f5616096df39b020f401b3e76106bc4aac32e 100644 --- a/source/dnode/mgmt/impl/src/dndTransport.c +++ b/source/dnode/mgmt/impl/src/dndTransport.c @@ -105,8 +105,6 @@ static void dndInitMsgFp(STransMgmt *pMgmt) { pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SHOW_RETRIEVE)] = dndProcessMnodeReadMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS)] = dndProcessMnodeReadMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS_RSP)] = dndProcessMgmtMsg; - pMgmt->msgFp[TMSG_INDEX(TDMT_MND_TRANS)] = dndProcessMnodeWriteMsg; - pMgmt->msgFp[TMSG_INDEX(TDMT_MND_TRANS_RSP)] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GRANT)] = dndProcessMnodeWriteMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GRANT_RSP)] = dndProcessMgmtMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_AUTH)] = dndProcessMnodeReadMsg; @@ -160,8 +158,8 @@ static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { DndMsgFp fp = pMgmt->msgFp[TMSG_INDEX(msgType)]; if (fp != NULL) { + dTrace("RPC %p, rsp:%s will be processed, code:0x%x", pMsg->handle, TMSG_INFO(msgType), pMsg->code & 0XFFFF); (*fp)(pDnode, pMsg, pEpSet); - dTrace("RPC %p, rsp:%s is processed, code:0x%x", pMsg->handle, TMSG_INFO(msgType), pMsg->code & 0XFFFF); } else { dError("RPC %p, rsp:%s not processed", pMsg->handle, TMSG_INFO(msgType)); rpcFreeCont(pMsg->pCont); @@ -216,7 +214,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { if (dndGetStat(pDnode) == DND_STAT_STOPPED) { dError("RPC %p, req:%s app:%p is ignored since dnode exiting", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle); - SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_EXITING}; + SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_OFFLINE}; rpcSendResponse(&rspMsg); rpcFreeCont(pMsg->pCont); return; @@ -383,14 +381,19 @@ void dndCleanupTrans(SDnode *pDnode) { dInfo("dnode-transport is cleaned up"); } -void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pMsg) { +int32_t dndSendReqToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pMsg) { STransMgmt *pMgmt = &pDnode->tmgmt; - if (pMgmt->clientRpc == NULL) return; + if (pMgmt->clientRpc == NULL) { + terrno = TSDB_CODE_DND_OFFLINE; + return -1; + } + rpcSendRequest(pMgmt->clientRpc, pEpSet, pMsg, NULL); + return 0; } -void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pMsg) { +int32_t dndSendReqToMnode(SDnode *pDnode, SRpcMsg *pMsg) { SEpSet epSet = {0}; dndGetMnodeEpSet(pDnode, &epSet); - dndSendMsgToDnode(pDnode, &epSet, pMsg); + return dndSendReqToDnode(pDnode, &epSet, pMsg); } diff --git a/source/dnode/mgmt/impl/src/dnode.c b/source/dnode/mgmt/impl/src/dnode.c index 88a96dadc4bd50f04c45c5960334b63bd211e422..ef5c15743c67f7bfabe81dd9de760bb907489df7 100644 --- a/source/dnode/mgmt/impl/src/dnode.c +++ b/source/dnode/mgmt/impl/src/dnode.c @@ -14,8 +14,11 @@ */ #define _DEFAULT_SOURCE +#include "dndBnode.h" #include "dndDnode.h" #include "dndMnode.h" +#include "dndQnode.h" +#include "dndSnode.h" #include "dndTransport.h" #include "dndVnodes.h" #include "sync.h" @@ -200,6 +203,24 @@ SDnode *dndInit(SDnodeOpt *pOption) { return NULL; } + if (dndInitQnode(pDnode) != 0) { + dError("failed to init qnode"); + dndCleanup(pDnode); + return NULL; + } + + if (dndInitSnode(pDnode) != 0) { + dError("failed to init snode"); + dndCleanup(pDnode); + return NULL; + } + + if (dndInitBnode(pDnode) != 0) { + dError("failed to init bnode"); + dndCleanup(pDnode); + return NULL; + } + if (dndInitMnode(pDnode) != 0) { dError("failed to init mnode"); dndCleanup(pDnode); @@ -213,7 +234,7 @@ SDnode *dndInit(SDnodeOpt *pOption) { } dndSetStat(pDnode, DND_STAT_RUNNING); - dndSendStatusMsg(pDnode); + dndSendStatusReq(pDnode); dndReportStartup(pDnode, "TDengine", "initialized successfully"); dInfo("TDengine is initialized successfully, pDnode:%p", pDnode); @@ -232,6 +253,9 @@ void dndCleanup(SDnode *pDnode) { dndSetStat(pDnode, DND_STAT_STOPPED); dndCleanupTrans(pDnode); dndCleanupMnode(pDnode); + dndCleanupBnode(pDnode); + dndCleanupSnode(pDnode); + dndCleanupQnode(pDnode); dndCleanupVnodes(pDnode); dndCleanupDnode(pDnode); vnodeClear(); diff --git a/source/dnode/mgmt/impl/test/CMakeLists.txt b/source/dnode/mgmt/impl/test/CMakeLists.txt index b0596bed08df617db6510da4c2ba773c9660b0d7..b13edf7d5a2c4e475c432c0539c252098584d037 100644 --- a/source/dnode/mgmt/impl/test/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/CMakeLists.txt @@ -1,23 +1,20 @@ enable_testing() -add_subdirectory(acct) +add_subdirectory(qnode) +add_subdirectory(bnode) +add_subdirectory(snode) + # add_subdirectory(auth) # add_subdirectory(balance) -add_subdirectory(cluster) add_subdirectory(db) add_subdirectory(dnode) # add_subdirectory(func) add_subdirectory(mnode) -add_subdirectory(qnode) -add_subdirectory(snode) -add_subdirectory(bnode) add_subdirectory(profile) -add_subdirectory(show) add_subdirectory(stb) # add_subdirectory(sync) # add_subdirectory(telem) # add_subdirectory(trans) -add_subdirectory(user) add_subdirectory(vgroup) add_subdirectory(sut) diff --git a/source/dnode/mgmt/impl/test/acct/CMakeLists.txt b/source/dnode/mgmt/impl/test/acct/CMakeLists.txt deleted file mode 100644 index a06becd1279b2f66f73cb3d8fbf347c9e4848e2b..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/impl/test/acct/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -aux_source_directory(. ACCT_SRC) -add_executable(dnode_test_acct ${ACCT_SRC}) -target_link_libraries( - dnode_test_acct - PUBLIC sut -) - -add_test( - NAME dnode_test_acct - COMMAND dnode_test_acct -) diff --git a/source/dnode/mgmt/impl/test/acct/acct.cpp b/source/dnode/mgmt/impl/test/acct/acct.cpp deleted file mode 100644 index be0ad4ab0f544ce0435468eecede11264e7d6406..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/impl/test/acct/acct.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/** - * @file acct.cpp - * @author slguan (slguan@taosdata.com) - * @brief DNODE module acct-msg tests - * @version 0.1 - * @date 2021-12-15 - * - * @copyright Copyright (c) 2021 - * - */ - -#include "base.h" - -class DndTestAcct : public ::testing::Test { - protected: - static void SetUpTestSuite() { test.Init("/tmp/dnode_test_acct", 9012); } - static void TearDownTestSuite() { test.Cleanup(); } - - static Testbase test; - - public: - void SetUp() override {} - void TearDown() override {} -}; - -Testbase DndTestAcct::test; - -TEST_F(DndTestAcct, 01_CreateAcct) { - int32_t contLen = sizeof(SCreateAcctMsg); - - SCreateAcctMsg* pReq = (SCreateAcctMsg*)rpcMallocCont(contLen); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_ACCT, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); -} - -TEST_F(DndTestAcct, 02_AlterAcct) { - int32_t contLen = sizeof(SCreateAcctMsg); - - SAlterAcctMsg* pReq = (SAlterAcctMsg*)rpcMallocCont(contLen); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_ACCT, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); -} - -TEST_F(DndTestAcct, 03_DropAcct) { - int32_t contLen = sizeof(SDropAcctMsg); - - SDropAcctMsg* pReq = (SDropAcctMsg*)rpcMallocCont(contLen); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_ACCT, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); -} - -TEST_F(DndTestAcct, 04_ShowAcct) { - int32_t contLen = sizeof(SShowMsg); - - SShowMsg* pReq = (SShowMsg*)rpcMallocCont(contLen); - pReq->type = TSDB_MGMT_TABLE_ACCT; - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_SHOW, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); -} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/bnode/CMakeLists.txt b/source/dnode/mgmt/impl/test/bnode/CMakeLists.txt index ea769a701c4136b9839445154abb413f7e10b594..22edc9b257f961e84debcfef3eebb21cfe3d07aa 100644 --- a/source/dnode/mgmt/impl/test/bnode/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/bnode/CMakeLists.txt @@ -1,5 +1,5 @@ -aux_source_directory(. STEST_SRC) -add_executable(dnode_test_bnode ${STEST_SRC}) +aux_source_directory(. BQTEST_SRC) +add_executable(dnode_test_bnode ${BQTEST_SRC}) target_link_libraries( dnode_test_bnode PUBLIC sut diff --git a/source/dnode/mgmt/impl/test/bnode/bnode.cpp b/source/dnode/mgmt/impl/test/bnode/bnode.cpp deleted file mode 100644 index b1a85522c45da91268b4a5617ea53f2b87612af3..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/impl/test/bnode/bnode.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/** - * @file dnode.cpp - * @author slguan (slguan@taosdata.com) - * @brief DNODE module dnode-msg tests - * @version 0.1 - * @date 2021-12-15 - * - * @copyright Copyright (c) 2021 - * - */ - -#include "base.h" - -class DndTestBnode : public ::testing::Test { - public: - void SetUp() override {} - void TearDown() override {} - - public: - static void SetUpTestSuite() { - test.Init("/tmp/dnode_test_bnode1", 9068); - const char* fqdn = "localhost"; - const char* firstEp = "localhost:9068"; - - server2.Start("/tmp/dnode_test_bnode2", fqdn, 9069, firstEp); - taosMsleep(300); - } - - static void TearDownTestSuite() { - server2.Stop(); - test.Cleanup(); - } - - static Testbase test; - static TestServer server2; -}; - -Testbase DndTestBnode::test; -TestServer DndTestBnode::server2; - -TEST_F(DndTestBnode, 01_ShowBnode) { - test.SendShowMetaMsg(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.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 0); -} - -TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) { - { - int32_t contLen = sizeof(SMCreateBnodeMsg); - - SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(1); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - test.SendShowMetaMsg(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.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 1); - - CheckInt16(1); - CheckBinary("localhost:9068", TSDB_EP_LEN); - CheckTimestamp(); - } -} - -TEST_F(DndTestBnode, 03_Create_Bnode_Invalid_Id) { - { - int32_t contLen = sizeof(SMCreateBnodeMsg); - - SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); - } -} - -TEST_F(DndTestBnode, 04_Create_Bnode) { - { - // create dnode - int32_t contLen = sizeof(SCreateDnodeMsg); - - SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); - strcpy(pReq->fqdn, "localhost"); - pReq->port = htonl(9069); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - taosMsleep(1300); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 2); - } - - { - // create bnode - int32_t contLen = sizeof(SMCreateBnodeMsg); - - SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 2); - - CheckInt16(1); - CheckInt16(2); - CheckBinary("localhost:9068", TSDB_EP_LEN); - CheckBinary("localhost:9069", TSDB_EP_LEN); - CheckTimestamp(); - CheckTimestamp(); - } - - { - // drop bnode - int32_t contLen = sizeof(SMDropBnodeMsg); - - SMDropBnodeMsg* pReq = (SMDropBnodeMsg*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, ""); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 1); - - CheckInt16(1); - CheckBinary("localhost:9068", TSDB_EP_LEN); - CheckTimestamp(); - } -} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/bnode/dbnode.cpp b/source/dnode/mgmt/impl/test/bnode/dbnode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bafe8242a695158f815e998a89326d9eb00120a2 --- /dev/null +++ b/source/dnode/mgmt/impl/test/bnode/dbnode.cpp @@ -0,0 +1,133 @@ +/** + * @file dbnode.cpp + * @author slguan (slguan@taosdata.com) + * @brief DNODE module bnode tests + * @version 1.0 + * @date 2022-01-05 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" + +class DndTestBnode : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_snode", 9112); } + static void TearDownTestSuite() { test.Cleanup(); } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} +}; + +Testbase DndTestBnode::test; + +TEST_F(DndTestBnode, 01_Create_Bnode) { + { + int32_t contLen = sizeof(SDCreateBnodeReq); + + SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ID_INVALID); + } + + { + int32_t contLen = sizeof(SDCreateBnodeReq); + + SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } + + { + int32_t contLen = sizeof(SDCreateBnodeReq); + + SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED); + } + + test.Restart(); + + { + int32_t contLen = sizeof(SDCreateBnodeReq); + + SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED); + } +} + +TEST_F(DndTestBnode, 01_Drop_Bnode) { + { + int32_t contLen = sizeof(SDDropBnodeReq); + + SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ID_INVALID); + } + + { + int32_t contLen = sizeof(SDDropBnodeReq); + + SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } + + { + int32_t contLen = sizeof(SDDropBnodeReq); + + SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_NOT_DEPLOYED); + } + + test.Restart(); + + { + int32_t contLen = sizeof(SDDropBnodeReq); + + SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_NOT_DEPLOYED); + } + + { + int32_t contLen = sizeof(SDCreateBnodeReq); + + SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } +} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/cluster/CMakeLists.txt b/source/dnode/mgmt/impl/test/cluster/CMakeLists.txt deleted file mode 100644 index a63f3106e6299299adf963427604c7384931f35c..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/impl/test/cluster/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -aux_source_directory(. CLUSTER_SRC) -add_executable(dnode_test_cluster ${CLUSTER_SRC}) -target_link_libraries( - dnode_test_cluster - PUBLIC sut -) - -add_test( - NAME dnode_test_cluster - COMMAND dnode_test_cluster -) diff --git a/source/dnode/mgmt/impl/test/cluster/cluster.cpp b/source/dnode/mgmt/impl/test/cluster/cluster.cpp deleted file mode 100644 index 773482678977a7096b5469d141fa21d2568dae25..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/impl/test/cluster/cluster.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/** - * @file cluster.cpp - * @author slguan (slguan@taosdata.com) - * @brief DNODE module cluster-msg tests - * @version 0.1 - * @date 2021-12-15 - * - * @copyright Copyright (c) 2021 - * - */ - -#include "base.h" - -class DndTestCluster : public ::testing::Test { - protected: - static void SetUpTestSuite() { test.Init("/tmp/dnode_test_cluster", 9030); } - static void TearDownTestSuite() { test.Cleanup(); } - - static Testbase test; - - public: - void SetUp() override {} - void TearDown() override {} -}; - -Testbase DndTestCluster::test; - -TEST_F(DndTestCluster, 01_ShowCluster) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_CLUSTER, ""); - CHECK_META( "show cluster", 3); - CHECK_SCHEMA(0, TSDB_DATA_TYPE_BIGINT, 8, "id"); - CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name"); - CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 1); - - IgnoreInt64(); - IgnoreBinary(TSDB_CLUSTER_ID_LEN); - CheckTimestamp(); -} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/db/db.cpp b/source/dnode/mgmt/impl/test/db/db.cpp index 5c67c10817547cb5d81666afa402238b6397c960..3a69ae23054f3e44df87bbf1d07f562ad05f97c7 100644 --- a/source/dnode/mgmt/impl/test/db/db.cpp +++ b/source/dnode/mgmt/impl/test/db/db.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestDb : public ::testing::Test { protected: @@ -26,7 +26,7 @@ class DndTestDb : public ::testing::Test { Testbase DndTestDb::test; TEST_F(DndTestDb, 01_ShowDb) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, ""); CHECK_META("show databases", 18); CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN - 1 + VARSTR_HEADER_SIZE, "name"); CHECK_SCHEMA(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); @@ -47,7 +47,7 @@ TEST_F(DndTestDb, 01_ShowDb) { CHECK_SCHEMA(16, TSDB_DATA_TYPE_BINARY, 3 + VARSTR_HEADER_SIZE, "precision"); CHECK_SCHEMA(17, TSDB_DATA_TYPE_TINYINT, 1, "update"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 0); } @@ -77,15 +77,15 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { pReq->cacheLastRow = 0; pReq->ignoreExist = 1; - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, ""); CHECK_META("show databases", 18); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("d1", TSDB_DB_NAME_LEN - 1); CheckTimestamp(); @@ -106,17 +106,17 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { CheckBinary("ms", 3); // precision CheckInt8(0); // update - test.SendShowMetaMsg(TSDB_MGMT_TABLE_VGROUP, "1.d1"); + test.SendShowMetaReq(TSDB_MGMT_TABLE_VGROUP, "1.d1"); CHECK_META("show vgroups", 4); CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "vgId"); CHECK_SCHEMA(1, TSDB_DATA_TYPE_INT, 4, "tables"); CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "v1_dnode"); CHECK_SCHEMA(3, TSDB_DATA_TYPE_BINARY, 9 + VARSTR_HEADER_SIZE, "v1_status"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); - CheckInt32(1); CheckInt32(2); + CheckInt32(3); CheckInt32(0); CheckInt32(0); CheckInt16(1); @@ -138,13 +138,13 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { pReq->quorum = 2; pReq->cacheLastRow = 1; - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_DB, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("d1", TSDB_DB_NAME_LEN - 1); CheckTimestamp(); @@ -168,10 +168,10 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { // restart test.Restart(); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, ""); CHECK_META("show databases", 18); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("d1", TSDB_DB_NAME_LEN - 1); @@ -199,15 +199,15 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(contLen); strcpy(pReq->db, "1.d1"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DB, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, ""); CHECK_META("show databases", 18); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 0); } @@ -237,15 +237,15 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) { pReq->cacheLastRow = 0; pReq->ignoreExist = 1; - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, ""); CHECK_META("show databases", 18); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("d2", TSDB_DB_NAME_LEN - 1); @@ -256,7 +256,7 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) { strcpy(pReq->db, "1.d2"); pReq->vgVersion = htonl(-1); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_USE_DB, pReq, contLen); + SRpcMsg* pMsg = test.SendReq(TDMT_MND_USE_DB, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); diff --git a/source/dnode/mgmt/impl/test/dnode/dnode.cpp b/source/dnode/mgmt/impl/test/dnode/dnode.cpp index 54d7e73be6542d8391dfdfddaf5f3f7857a7db1d..51af008fc3598801f84559c36051e72291563f64 100644 --- a/source/dnode/mgmt/impl/test/dnode/dnode.cpp +++ b/source/dnode/mgmt/impl/test/dnode/dnode.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestDnode : public ::testing::Test { public: @@ -51,7 +51,7 @@ TestServer DndTestDnode::server4; TestServer DndTestDnode::server5; TEST_F(DndTestDnode, 01_ShowDnode) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); CHECK_META("show dnodes", 7); CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); @@ -62,7 +62,7 @@ TEST_F(DndTestDnode, 01_ShowDnode) { CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); @@ -81,9 +81,9 @@ TEST_F(DndTestDnode, 02_ConfigDnode) { pReq->dnodeId = htonl(1); strcpy(pReq->config, "ddebugflag 131"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONFIG_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONFIG_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { @@ -94,16 +94,16 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { strcpy(pReq->fqdn, "localhost"); pReq->port = htonl(9042); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } taosMsleep(1300); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); CHECK_META("show dnodes", 7); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); CheckInt16(1); @@ -127,14 +127,14 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); CHECK_META("show dnodes", 7); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); @@ -152,9 +152,9 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { strcpy(pReq->fqdn, "localhost"); pReq->port = htonl(9043); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } { @@ -164,9 +164,9 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { strcpy(pReq->fqdn, "localhost"); pReq->port = htonl(9044); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } { @@ -176,15 +176,15 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { strcpy(pReq->fqdn, "localhost"); pReq->port = htonl(9045); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } taosMsleep(1300); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); CHECK_META("show dnodes", 7); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 4); CheckInt16(1); @@ -225,9 +225,9 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { server5.Restart(); taosMsleep(1300); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); CHECK_META("show dnodes", 7); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 4); CheckInt16(1); diff --git a/source/dnode/mgmt/impl/test/mnode/mnode.cpp b/source/dnode/mgmt/impl/test/mnode/mnode.cpp index e9b1ef45bdd419f17aa97b0f60cb43d9837efebe..9a725c20d380ea3cc2917e1546651c28cf59344b 100644 --- a/source/dnode/mgmt/impl/test/mnode/mnode.cpp +++ b/source/dnode/mgmt/impl/test/mnode/mnode.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestMnode : public ::testing::Test { public: @@ -51,7 +51,7 @@ TestServer DndTestMnode::server4; TestServer DndTestMnode::server5; TEST_F(DndTestMnode, 01_ShowDnode) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, ""); CHECK_META("show mnodes", 5); CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); @@ -60,7 +60,7 @@ TEST_F(DndTestMnode, 01_ShowDnode) { CHECK_SCHEMA(3, TSDB_DATA_TYPE_TIMESTAMP, 8, "role_time"); CHECK_SCHEMA(4, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); @@ -77,9 +77,9 @@ TEST_F(DndTestMnode, 02_Create_Mnode_Invalid_Id) { SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(1); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MNODE_ALREADY_EXIST); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MNODE_ALREADY_EXIST); } } @@ -90,9 +90,9 @@ TEST_F(DndTestMnode, 03_Create_Mnode_Invalid_Id) { SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST); } } @@ -105,13 +105,13 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { strcpy(pReq->fqdn, "localhost"); pReq->port = htonl(9062); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); taosMsleep(1300); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); } @@ -122,12 +122,12 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 2); CheckInt16(1); @@ -149,12 +149,12 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { SMDropMnodeMsg* pReq = (SMDropMnodeMsg*)rpcMallocCont(contLen); pReq->dnodeId = htonl(2); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_MNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, ""); - test.SendShowRetrieveMsg(); + test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, ""); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckInt16(1); @@ -170,14 +170,14 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { // SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen); // pReq->dnodeId = htonl(2); -// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DNODE, pReq, contLen); -// ASSERT_NE(pMsg, nullptr); -// ASSERT_EQ(pMsg->code, 0); +// SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen); +// ASSERT_NE(pRsp, nullptr); +// ASSERT_EQ(pRsp->code, 0); // } -// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); +// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); // CHECK_META("show dnodes", 7); -// test.SendShowRetrieveMsg(); +// test.SendShowRetrieveReq(); // EXPECT_EQ(test.GetShowRows(), 1); // CheckInt16(1); @@ -194,9 +194,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { // SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); // strcpy(pReq->ep, "localhost:9063"); -// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); -// ASSERT_NE(pMsg, nullptr); -// ASSERT_EQ(pMsg->code, 0); +// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); +// ASSERT_NE(pRsp, nullptr); +// ASSERT_EQ(pRsp->code, 0); // } // { @@ -205,9 +205,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { // SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); // strcpy(pReq->ep, "localhost:9064"); -// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); -// ASSERT_NE(pMsg, nullptr); -// ASSERT_EQ(pMsg->code, 0); +// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); +// ASSERT_NE(pRsp, nullptr); +// ASSERT_EQ(pRsp->code, 0); // } // { @@ -216,15 +216,15 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { // SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); // strcpy(pReq->ep, "localhost:9065"); -// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); -// ASSERT_NE(pMsg, nullptr); -// ASSERT_EQ(pMsg->code, 0); +// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); +// ASSERT_NE(pRsp, nullptr); +// ASSERT_EQ(pRsp->code, 0); // } // taosMsleep(1300); -// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); +// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); // CHECK_META("show dnodes", 7); -// test.SendShowRetrieveMsg(); +// test.SendShowRetrieveReq(); // EXPECT_EQ(test.GetShowRows(), 4); // CheckInt16(1); @@ -265,9 +265,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { // server5.Restart(); // taosMsleep(1300); -// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); +// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); // CHECK_META("show dnodes", 7); -// test.SendShowRetrieveMsg(); +// test.SendShowRetrieveReq(); // EXPECT_EQ(test.GetShowRows(), 4); // CheckInt16(1); diff --git a/source/dnode/mgmt/impl/test/profile/profile.cpp b/source/dnode/mgmt/impl/test/profile/profile.cpp index 87e6bfde747926e58cc5b4257ca1ea9ca9e025bb..29b71f1c273b568a91a2f0f109b6fdda94853a5b 100644 --- a/source/dnode/mgmt/impl/test/profile/profile.cpp +++ b/source/dnode/mgmt/impl/test/profile/profile.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestProfile : public ::testing::Test { protected: @@ -17,15 +17,15 @@ class DndTestProfile : public ::testing::Test { static void TearDownTestSuite() { test.Cleanup(); } static Testbase test; + static int32_t connId; public: void SetUp() override {} void TearDown() override {} - - int32_t connId; }; Testbase DndTestProfile::test; +int32_t DndTestProfile::connId; TEST_F(DndTestProfile, 01_ConnectMsg) { int32_t contLen = sizeof(SConnectMsg); @@ -35,7 +35,7 @@ TEST_F(DndTestProfile, 01_ConnectMsg) { strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->db, ""); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen); + SRpcMsg* pMsg = test.SendReq(TDMT_MND_CONNECT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -67,14 +67,14 @@ TEST_F(DndTestProfile, 02_ConnectMsg_InvalidDB) { strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->db, "invalid_db"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_DB); - ASSERT_EQ(pMsg->contLen, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONNECT, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DB); + ASSERT_EQ(pRsp->contLen, 0); } TEST_F(DndTestProfile, 03_ConnectMsg_Show) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_CONNS, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_CONNS, ""); CHECK_META("show connections", 7); CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "connId"); CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "user"); @@ -84,7 +84,7 @@ TEST_F(DndTestProfile, 03_ConnectMsg_Show) { CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "login_time"); CHECK_SCHEMA(6, TSDB_DATA_TYPE_TIMESTAMP, 8, "last_access"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckInt32(1); CheckBinary("root", TSDB_USER_LEN); @@ -105,7 +105,7 @@ TEST_F(DndTestProfile, 04_HeartBeatMsg) { pReq->numOfStreams = htonl(0); strcpy(pReq->app, "dnode_test_profile"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_HEARTBEAT, pReq, contLen); + SRpcMsg* pMsg = test.SendReq(TDMT_MND_HEARTBEAT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -138,9 +138,9 @@ TEST_F(DndTestProfile, 05_KillConnMsg) { SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen); pReq->connId = htonl(connId); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_CONN, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_CONN, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } { @@ -153,10 +153,10 @@ TEST_F(DndTestProfile, 05_KillConnMsg) { pReq->numOfStreams = htonl(0); strcpy(pReq->app, "dnode_test_profile"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_HEARTBEAT, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONNECTION); - ASSERT_EQ(pMsg->contLen, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_HEARTBEAT, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONNECTION); + ASSERT_EQ(pRsp->contLen, 0); } { @@ -167,7 +167,7 @@ TEST_F(DndTestProfile, 05_KillConnMsg) { strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->db, ""); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen); + SRpcMsg* pMsg = test.SendReq(TDMT_MND_CONNECT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -198,9 +198,9 @@ TEST_F(DndTestProfile, 06_KillConnMsg_InvalidConn) { SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen); pReq->connId = htonl(2345); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_CONN, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_CONN, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONN_ID); } TEST_F(DndTestProfile, 07_KillQueryMsg) { @@ -211,10 +211,10 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) { pReq->connId = htonl(connId); pReq->queryId = htonl(1234); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_QUERY, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - ASSERT_EQ(pMsg->contLen, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_QUERY, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + ASSERT_EQ(pRsp->contLen, 0); } { @@ -227,7 +227,7 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) { pReq->numOfStreams = htonl(0); strcpy(pReq->app, "dnode_test_profile"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_HEARTBEAT, pReq, contLen); + SRpcMsg* pMsg = test.SendReq(TDMT_MND_HEARTBEAT, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -261,13 +261,13 @@ TEST_F(DndTestProfile, 08_KillQueryMsg_InvalidConn) { pReq->connId = htonl(2345); pReq->queryId = htonl(1234); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_QUERY, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_QUERY, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONN_ID); } TEST_F(DndTestProfile, 09_KillQueryMsg) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_QUERIES, ""); + test.SendShowMetaReq(TSDB_MGMT_TABLE_QUERIES, ""); CHECK_META("show queries", 14); CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "queryId"); @@ -285,6 +285,6 @@ TEST_F(DndTestProfile, 09_KillQueryMsg) { CHECK_SCHEMA(12, TSDB_DATA_TYPE_BINARY, TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE, "sub_query_info"); CHECK_SCHEMA(13, TSDB_DATA_TYPE_BINARY, TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, "sql"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 0); } diff --git a/source/dnode/mgmt/impl/test/qnode/CMakeLists.txt b/source/dnode/mgmt/impl/test/qnode/CMakeLists.txt index 2edb6de8b8c7433cfa76ff214a6f13c26557ea70..2536001231c82537d64735ce14ada91f45501d07 100644 --- a/source/dnode/mgmt/impl/test/qnode/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/qnode/CMakeLists.txt @@ -1,5 +1,5 @@ -aux_source_directory(. QTEST_SRC) -add_executable(dnode_test_qnode ${QTEST_SRC}) +aux_source_directory(. DQTEST_SRC) +add_executable(dnode_test_qnode ${DQTEST_SRC}) target_link_libraries( dnode_test_qnode PUBLIC sut diff --git a/source/dnode/mgmt/impl/test/qnode/dqnode.cpp b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e609783eb02715db2c8b95d64054f76f26806a90 --- /dev/null +++ b/source/dnode/mgmt/impl/test/qnode/dqnode.cpp @@ -0,0 +1,133 @@ +/** + * @file dqnode.cpp + * @author slguan (slguan@taosdata.com) + * @brief DNODE module qnode tests + * @version 1.0 + * @date 2022-01-05 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" + +class DndTestQnode : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_qnode", 9111); } + static void TearDownTestSuite() { test.Cleanup(); } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} +}; + +Testbase DndTestQnode::test; + +TEST_F(DndTestQnode, 01_Create_Qnode) { + { + int32_t contLen = sizeof(SDCreateQnodeReq); + + SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ID_INVALID); + } + + { + int32_t contLen = sizeof(SDCreateQnodeReq); + + SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } + + { + int32_t contLen = sizeof(SDCreateQnodeReq); + + SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED); + } + + test.Restart(); + + { + int32_t contLen = sizeof(SDCreateQnodeReq); + + SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED); + } +} + +TEST_F(DndTestQnode, 01_Drop_Qnode) { + { + int32_t contLen = sizeof(SDDropQnodeReq); + + SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ID_INVALID); + } + + { + int32_t contLen = sizeof(SDDropQnodeReq); + + SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } + + { + int32_t contLen = sizeof(SDDropQnodeReq); + + SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_NOT_DEPLOYED); + } + + test.Restart(); + + { + int32_t contLen = sizeof(SDDropQnodeReq); + + SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_NOT_DEPLOYED); + } + + { + int32_t contLen = sizeof(SDCreateQnodeReq); + + SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } +} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/qnode/qnode.cpp b/source/dnode/mgmt/impl/test/qnode/qnode.cpp deleted file mode 100644 index 40464de81692eb59b9e372eab28be0342fda71a8..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/impl/test/qnode/qnode.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/** - * @file dnode.cpp - * @author slguan (slguan@taosdata.com) - * @brief DNODE module dnode-msg tests - * @version 0.1 - * @date 2021-12-15 - * - * @copyright Copyright (c) 2021 - * - */ - -#include "base.h" - -class DndTestQnode : public ::testing::Test { - public: - void SetUp() override {} - void TearDown() override {} - - public: - static void SetUpTestSuite() { - test.Init("/tmp/dnode_test_qnode1", 9064); - const char* fqdn = "localhost"; - const char* firstEp = "localhost:9064"; - - server2.Start("/tmp/dnode_test_qnode2", fqdn, 9065, firstEp); - taosMsleep(300); - } - - static void TearDownTestSuite() { - server2.Stop(); - test.Cleanup(); - } - - static Testbase test; - static TestServer server2; -}; - -Testbase DndTestQnode::test; -TestServer DndTestQnode::server2; - -TEST_F(DndTestQnode, 01_ShowQnode) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); - CHECK_META("show qnodes", 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.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 0); -} - -TEST_F(DndTestQnode, 02_Create_Qnode_Invalid_Id) { - { - int32_t contLen = sizeof(SMCreateQnodeMsg); - - SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(1); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); - CHECK_META("show qnodes", 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.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 1); - - CheckInt16(1); - CheckBinary("localhost:9064", TSDB_EP_LEN); - CheckTimestamp(); - } -} - -TEST_F(DndTestQnode, 03_Create_Qnode_Invalid_Id) { - { - int32_t contLen = sizeof(SMCreateQnodeMsg); - - SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); - } -} - -TEST_F(DndTestQnode, 04_Create_Qnode) { - { - // create dnode - int32_t contLen = sizeof(SCreateDnodeMsg); - - SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); - strcpy(pReq->fqdn, "localhost"); - pReq->port = htonl(9065); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - taosMsleep(1300); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 2); - } - - { - // create qnode - int32_t contLen = sizeof(SMCreateQnodeMsg); - - SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 2); - - CheckInt16(1); - CheckInt16(2); - CheckBinary("localhost:9064", TSDB_EP_LEN); - CheckBinary("localhost:9065", TSDB_EP_LEN); - CheckTimestamp(); - CheckTimestamp(); - } - - { - // drop qnode - int32_t contLen = sizeof(SMDropQnodeMsg); - - SMDropQnodeMsg* pReq = (SMDropQnodeMsg*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_QNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, ""); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 1); - - CheckInt16(1); - CheckBinary("localhost:9064", TSDB_EP_LEN); - CheckTimestamp(); - } -} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/show/CMakeLists.txt b/source/dnode/mgmt/impl/test/show/CMakeLists.txt deleted file mode 100644 index 9786f65605ca25686b8d88e236d8834ce24274d9..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/impl/test/show/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -aux_source_directory(. SHOW_SRC) -add_executable(dnode_test_show ${SHOW_SRC}) -target_link_libraries( - dnode_test_show - PUBLIC sut -) - -add_test( - NAME dnode_test_show - COMMAND dnode_test_show -) diff --git a/source/dnode/mgmt/impl/test/show/show.cpp b/source/dnode/mgmt/impl/test/show/show.cpp deleted file mode 100644 index a0df0f29218a63e5141adaa9244605c569802353..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/impl/test/show/show.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/** - * @file show.cpp - * @author slguan (slguan@taosdata.com) - * @brief DNODE module show-msg tests - * @version 0.1 - * @date 2021-12-15 - * - * @copyright Copyright (c) 2021 - * - */ - -#include "base.h" - -class DndTestShow : public ::testing::Test { - protected: - static void SetUpTestSuite() { test.Init("/tmp/dnode_test_show", 9091); } - static void TearDownTestSuite() { test.Cleanup(); } - - static Testbase test; - - public: - void SetUp() override {} - void TearDown() override {} -}; - -Testbase DndTestShow::test; - -TEST_F(DndTestShow, 01_ShowMsg_InvalidMsgMax) { - int32_t contLen = sizeof(SShowMsg); - - SShowMsg* pReq = (SShowMsg*)rpcMallocCont(contLen); - pReq->type = TSDB_MGMT_TABLE_MAX; - strcpy(pReq->db, ""); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_SHOW, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); -} - -TEST_F(DndTestShow, 02_ShowMsg_InvalidMsgStart) { - int32_t contLen = sizeof(SShowMsg); - - SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); - pReq->type = TSDB_MGMT_TABLE_START; - strcpy(pReq->db, ""); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_SHOW, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE); -} - -TEST_F(DndTestShow, 02_ShowMsg_Conn) { - int32_t contLen = sizeof(SConnectMsg); - - SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen); - pReq->pid = htonl(1234); - strcpy(pReq->app, "dnode_test_show"); - strcpy(pReq->db, ""); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_CONNS, ""); - - STableMetaMsg* pMeta = test.GetShowMeta(); - EXPECT_STREQ(pMeta->tbFname, "show connections"); - EXPECT_EQ(pMeta->numOfTags, 0); - EXPECT_EQ(pMeta->numOfColumns, 7); - EXPECT_EQ(pMeta->precision, 0); - EXPECT_EQ(pMeta->tableType, 0); - EXPECT_EQ(pMeta->update, 0); - EXPECT_EQ(pMeta->sversion, 0); - EXPECT_EQ(pMeta->tversion, 0); - EXPECT_EQ(pMeta->tuid, 0); - EXPECT_EQ(pMeta->suid, 0); - - test.SendShowRetrieveMsg(); - - SRetrieveTableRsp* pRetrieveRsp = test.GetRetrieveRsp(); - EXPECT_EQ(pRetrieveRsp->numOfRows, 1); - EXPECT_EQ(pRetrieveRsp->useconds, 0); - EXPECT_EQ(pRetrieveRsp->completed, 1); - EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI); - EXPECT_EQ(pRetrieveRsp->compressed, 0); - EXPECT_EQ(pRetrieveRsp->compLen, 0); -} diff --git a/source/dnode/mgmt/impl/test/snode/CMakeLists.txt b/source/dnode/mgmt/impl/test/snode/CMakeLists.txt index 180b1ec163b7caa84538b8eec656c2f588b12c68..9c163d1999a209b21fc138795b84be0fd8b42c09 100644 --- a/source/dnode/mgmt/impl/test/snode/CMakeLists.txt +++ b/source/dnode/mgmt/impl/test/snode/CMakeLists.txt @@ -1,5 +1,5 @@ -aux_source_directory(. STEST_SRC) -add_executable(dnode_test_snode ${STEST_SRC}) +aux_source_directory(. SQTEST_SRC) +add_executable(dnode_test_snode ${SQTEST_SRC}) target_link_libraries( dnode_test_snode PUBLIC sut diff --git a/source/dnode/mgmt/impl/test/snode/dsnode.cpp b/source/dnode/mgmt/impl/test/snode/dsnode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1e6bcdb3fb5b3959c0be89f437fa9741420a6bfc --- /dev/null +++ b/source/dnode/mgmt/impl/test/snode/dsnode.cpp @@ -0,0 +1,133 @@ +/** + * @file dsnode.cpp + * @author slguan (slguan@taosdata.com) + * @brief DNODE module snode tests + * @version 1.0 + * @date 2022-01-05 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" + +class DndTestSnode : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/dnode_test_snode", 9112); } + static void TearDownTestSuite() { test.Cleanup(); } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} +}; + +Testbase DndTestSnode::test; + +TEST_F(DndTestSnode, 01_Create_Snode) { + { + int32_t contLen = sizeof(SDCreateSnodeReq); + + SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_ID_INVALID); + } + + { + int32_t contLen = sizeof(SDCreateSnodeReq); + + SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } + + { + int32_t contLen = sizeof(SDCreateSnodeReq); + + SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED); + } + + test.Restart(); + + { + int32_t contLen = sizeof(SDCreateSnodeReq); + + SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED); + } +} + +TEST_F(DndTestSnode, 01_Drop_Snode) { + { + int32_t contLen = sizeof(SDDropSnodeReq); + + SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_ID_INVALID); + } + + { + int32_t contLen = sizeof(SDDropSnodeReq); + + SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } + + { + int32_t contLen = sizeof(SDDropSnodeReq); + + SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_NOT_DEPLOYED); + } + + test.Restart(); + + { + int32_t contLen = sizeof(SDDropSnodeReq); + + SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_NOT_DEPLOYED); + } + + { + int32_t contLen = sizeof(SDCreateSnodeReq); + + SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } +} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/snode/snode.cpp b/source/dnode/mgmt/impl/test/snode/snode.cpp deleted file mode 100644 index a14a575bebeb39599dc5e2e0e6fd8f7ee8bf9423..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/impl/test/snode/snode.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/** - * @file dnode.cpp - * @author slguan (slguan@taosdata.com) - * @brief DNODE module dnode-msg tests - * @version 0.1 - * @date 2021-12-15 - * - * @copyright Copyright (c) 2021 - * - */ - -#include "base.h" - -class DndTestSnode : public ::testing::Test { - public: - void SetUp() override {} - void TearDown() override {} - - public: - static void SetUpTestSuite() { - test.Init("/tmp/dnode_test_snode1", 9066); - const char* fqdn = "localhost"; - const char* firstEp = "localhost:9066"; - - server2.Start("/tmp/dnode_test_snode2", fqdn, 9067, firstEp); - taosMsleep(300); - } - - static void TearDownTestSuite() { - server2.Stop(); - test.Cleanup(); - } - - static Testbase test; - static TestServer server2; -}; - -Testbase DndTestSnode::test; -TestServer DndTestSnode::server2; - -TEST_F(DndTestSnode, 01_ShowSnode) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, ""); - CHECK_META("show snodes", 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.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 0); -} - -TEST_F(DndTestSnode, 02_Create_Snode_Invalid_Id) { - { - int32_t contLen = sizeof(SMCreateSnodeMsg); - - SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(1); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, ""); - CHECK_META("show snodes", 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.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 1); - - CheckInt16(1); - CheckBinary("localhost:9066", TSDB_EP_LEN); - CheckTimestamp(); - } -} - -TEST_F(DndTestSnode, 03_Create_Snode_Invalid_Id) { - { - int32_t contLen = sizeof(SMCreateSnodeMsg); - - SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); - } -} - -TEST_F(DndTestSnode, 04_Create_Snode) { - { - // create dnode - int32_t contLen = sizeof(SCreateDnodeMsg); - - SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); - strcpy(pReq->fqdn, "localhost"); - pReq->port = htonl(9067); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - taosMsleep(1300); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 2); - } - - { - // create snode - int32_t contLen = sizeof(SMCreateSnodeMsg); - - SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, ""); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 2); - - CheckInt16(1); - CheckInt16(2); - CheckBinary("localhost:9066", TSDB_EP_LEN); - CheckBinary("localhost:9067", TSDB_EP_LEN); - CheckTimestamp(); - CheckTimestamp(); - } - - { - // drop snode - int32_t contLen = sizeof(SMDropSnodeMsg); - - SMDropSnodeMsg* pReq = (SMDropSnodeMsg*)rpcMallocCont(contLen); - pReq->dnodeId = htonl(2); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_SNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, ""); - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 1); - - CheckInt16(1); - CheckBinary("localhost:9066", TSDB_EP_LEN); - CheckTimestamp(); - } -} \ No newline at end of file diff --git a/source/dnode/mgmt/impl/test/stb/stb.cpp b/source/dnode/mgmt/impl/test/stb/stb.cpp index dca0f4851658caa57ec264a9ce9c896e5e44fc45..b3d5d29785d398bbea680cfa4e0189639edd45ba 100644 --- a/source/dnode/mgmt/impl/test/stb/stb.cpp +++ b/source/dnode/mgmt/impl/test/stb/stb.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestStb : public ::testing::Test { protected: @@ -51,9 +51,9 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { pReq->cacheLastRow = 0; pReq->ignoreExist = 1; - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } { @@ -101,12 +101,12 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { strcpy(pSchema->name, "tag3"); } - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_STB, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1"); + test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, "1.d1"); CHECK_META("show stables", 4); CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, "name"); @@ -114,7 +114,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { CHECK_SCHEMA(2, TSDB_DATA_TYPE_INT, 4, "columns"); CHECK_SCHEMA(3, TSDB_DATA_TYPE_INT, 4, "tags"); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("stb", TSDB_TABLE_NAME_LEN); CheckTimestamp(); @@ -128,7 +128,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { STableInfoMsg* pReq = (STableInfoMsg*)rpcMallocCont(contLen); strcpy(pReq->tableFname, "1.d1.stb"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_STB_META, pReq, contLen); + SRpcMsg* pMsg = test.SendReq(TDMT_MND_STB_META, pReq, contLen); ASSERT_NE(pMsg, nullptr); ASSERT_EQ(pMsg->code, 0); @@ -203,9 +203,9 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { // restart test.Restart(); - test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1"); + test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, "1.d1"); CHECK_META("show stables", 4); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 1); CheckBinary("stb", TSDB_TABLE_NAME_LEN); @@ -219,13 +219,13 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { SDropStbMsg* pReq = (SDropStbMsg*)rpcMallocCont(contLen); strcpy(pReq->name, "1.d1.stb"); - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_STB, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_STB, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } - test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1"); + test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, "1.d1"); CHECK_META("show stables", 4); - test.SendShowRetrieveMsg(); + test.SendShowRetrieveReq(); EXPECT_EQ(test.GetShowRows(), 0); } diff --git a/source/dnode/mgmt/impl/test/sut/inc/client.h b/source/dnode/mgmt/impl/test/sut/inc/client.h index e1e430318e891d2cf8c91740ebbc9d8d5de183cb..9cf688fc0234f00afae6bceb6a72b2191048ad8a 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/client.h +++ b/source/dnode/mgmt/impl/test/sut/inc/client.h @@ -21,7 +21,7 @@ class TestClient { bool Init(const char* user, const char* pass, const char* fqdn, uint16_t port); void Cleanup(); - SRpcMsg* SendMsg(SRpcMsg* pMsg); + SRpcMsg* SendReq(SRpcMsg* pReq); void SetRpcRsp(SRpcMsg* pRsp); tsem_t* GetSem(); diff --git a/source/dnode/mgmt/impl/test/sut/inc/server.h b/source/dnode/mgmt/impl/test/sut/inc/server.h index aa7b37f22118ca0ca4081235624903dc010f85af..5f9e4846a7063826d89ed217833afdd4a55095cc 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/server.h +++ b/source/dnode/mgmt/impl/test/sut/inc/server.h @@ -21,10 +21,10 @@ class TestServer { bool Start(const char* path, const char* fqdn, uint16_t port, const char* firstEp); void Stop(); void Restart(); + bool DoStart(); private: SDnodeOpt BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp); - bool DoStart(); private: SDnode* pDnode; diff --git a/source/dnode/mgmt/impl/test/sut/inc/base.h b/source/dnode/mgmt/impl/test/sut/inc/sut.h similarity index 92% rename from source/dnode/mgmt/impl/test/sut/inc/base.h rename to source/dnode/mgmt/impl/test/sut/inc/sut.h index fef7ad9d430fd20719fcd378a9e8eed99bf48a0f..fd9c1cd93ee609bc7f495b8f67408b0580bdefec 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/base.h +++ b/source/dnode/mgmt/impl/test/sut/inc/sut.h @@ -37,7 +37,9 @@ class Testbase { void Init(const char* path, int16_t port); void Cleanup(); void Restart(); - SRpcMsg* SendMsg(tmsg_t msgType, void* pCont, int32_t contLen); + void ServerStop(); + void ServerStart(); + SRpcMsg* SendReq(tmsg_t msgType, void* pCont, int32_t contLen); private: void InitLog(const char* path); @@ -48,8 +50,8 @@ class Testbase { int32_t connId; public: - void SendShowMetaMsg(int8_t showType, const char* db); - void SendShowRetrieveMsg(); + void SendShowMetaReq(int8_t showType, const char* db); + void SendShowRetrieveReq(); STableMetaMsg* GetShowMeta(); SRetrieveTableRsp* GetRetrieveRsp(); @@ -71,7 +73,7 @@ class Testbase { const char* GetShowBinary(int32_t len); private: - int32_t showId; + int64_t showId; STableMetaMsg* pMeta; SRetrieveTableRsp* pRetrieveRsp; char* pData; diff --git a/source/dnode/mgmt/impl/test/sut/src/client.cpp b/source/dnode/mgmt/impl/test/sut/src/client.cpp index 13429cec28217886cdb44e5fe8672b43746402f8..fd5dcd77d94ba40cb725e3b267fbce0bae6340df 100644 --- a/source/dnode/mgmt/impl/test/sut/src/client.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/client.cpp @@ -13,12 +13,12 @@ * along with this program. If not, see . */ -#include "base.h" +#include "sut.h" -static void processClientRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { +static void processClientRsp(void* parent, SRpcMsg* pRsp, SEpSet* pEpSet) { TestClient* client = (TestClient*)parent; - client->SetRpcRsp(pMsg); - uInfo("response:%s from dnode, code:0x%x", TMSG_INFO(pMsg->msgType), pMsg->code); + client->SetRpcRsp(pRsp); + uInfo("response:%s from dnode, code:0x%x", TMSG_INFO(pRsp->msgType), pRsp->code); tsem_post(client->GetSem()); } @@ -59,14 +59,14 @@ void TestClient::Cleanup() { rpcClose(clientRpc); } -SRpcMsg* TestClient::SendMsg(SRpcMsg* pMsg) { +SRpcMsg* TestClient::SendReq(SRpcMsg* pReq) { SEpSet epSet = {0}; epSet.inUse = 0; epSet.numOfEps = 1; epSet.port[0] = port; memcpy(epSet.fqdn[0], fqdn, TSDB_FQDN_LEN); - rpcSendRequest(clientRpc, &epSet, pMsg, NULL); + rpcSendRequest(clientRpc, &epSet, pReq, NULL); tsem_wait(&sem); return pRsp; diff --git a/source/dnode/mgmt/impl/test/sut/src/server.cpp b/source/dnode/mgmt/impl/test/sut/src/server.cpp index 8ac5f6214430a1e46f757f755e97b2fca28c4119..fb2974294cf24b4ae944e844f865571ad26c6bfd 100644 --- a/source/dnode/mgmt/impl/test/sut/src/server.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/server.cpp @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "base.h" +#include "sut.h" void* serverLoop(void* param) { while (1) { diff --git a/source/dnode/mgmt/impl/test/sut/src/base.cpp b/source/dnode/mgmt/impl/test/sut/src/sut.cpp similarity index 81% rename from source/dnode/mgmt/impl/test/sut/src/base.cpp rename to source/dnode/mgmt/impl/test/sut/src/sut.cpp index e14dc94d31bb126a286780c79d19cfb42c37e114..72a6416e227869c08c41892f281f8162c5d80b14 100644 --- a/source/dnode/mgmt/impl/test/sut/src/base.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/sut.cpp @@ -13,16 +13,16 @@ * along with this program. If not, see . */ -#include "base.h" +#include "sut.h" void Testbase::InitLog(const char* path) { - dDebugFlag = 207; + dDebugFlag = 0; vDebugFlag = 0; - mDebugFlag = 207; + mDebugFlag = 143; cDebugFlag = 0; jniDebugFlag = 0; tmrDebugFlag = 0; - uDebugFlag = 143; + uDebugFlag = 0; rpcDebugFlag = 0; qDebugFlag = 0; wDebugFlag = 0; @@ -60,26 +60,30 @@ void Testbase::Cleanup() { void Testbase::Restart() { server.Restart(); } -SRpcMsg* Testbase::SendMsg(tmsg_t msgType, void* pCont, int32_t contLen) { +void Testbase::ServerStop() { server.Stop(); } + +void Testbase::ServerStart() { server.DoStart(); } + +SRpcMsg* Testbase::SendReq(tmsg_t msgType, void* pCont, int32_t contLen) { SRpcMsg rpcMsg = {0}; rpcMsg.pCont = pCont; rpcMsg.contLen = contLen; rpcMsg.msgType = msgType; - return client.SendMsg(&rpcMsg); + return client.SendReq(&rpcMsg); } -void Testbase::SendShowMetaMsg(int8_t showType, const char* db) { - int32_t contLen = sizeof(SShowMsg); - SShowMsg* pShow = (SShowMsg*)rpcMallocCont(contLen); +void Testbase::SendShowMetaReq(int8_t showType, const char* db) { + int32_t contLen = sizeof(SShowReq); + SShowReq* pShow = (SShowReq*)rpcMallocCont(contLen); pShow->type = showType; strcpy(pShow->db, db); - SRpcMsg* pMsg = SendMsg(TDMT_MND_SHOW, pShow, contLen); - SShowRsp* pShowRsp = (SShowRsp*)pMsg->pCont; + SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW, pShow, contLen); + SShowRsp* pShowRsp = (SShowRsp*)pRsp->pCont; ASSERT(pShowRsp != nullptr); - pShowRsp->showId = htonl(pShowRsp->showId); + pShowRsp->showId = htobe64(pShowRsp->showId); pMeta = &pShowRsp->tableMeta; pMeta->numOfTags = htonl(pMeta->numOfTags); pMeta->numOfColumns = htonl(pMeta->numOfColumns); @@ -117,15 +121,15 @@ int32_t Testbase::GetMetaNum() { return pMeta->numOfColumns; } const char* Testbase::GetMetaTbName() { return pMeta->tbFname; } -void Testbase::SendShowRetrieveMsg() { - int32_t contLen = sizeof(SRetrieveTableMsg); +void Testbase::SendShowRetrieveReq() { + int32_t contLen = sizeof(SRetrieveTableReq); - SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(contLen); - pRetrieve->showId = htonl(showId); + SRetrieveTableReq* pRetrieve = (SRetrieveTableReq*)rpcMallocCont(contLen); + pRetrieve->showId = htobe64(showId); pRetrieve->free = 0; - SRpcMsg* pMsg = SendMsg(TDMT_MND_SHOW_RETRIEVE, pRetrieve, contLen); - pRetrieveRsp = (SRetrieveTableRsp*)pMsg->pCont; + SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW_RETRIEVE, pRetrieve, contLen); + pRetrieveRsp = (SRetrieveTableRsp*)pRsp->pCont; pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen); diff --git a/source/dnode/mgmt/impl/test/user/CMakeLists.txt b/source/dnode/mgmt/impl/test/user/CMakeLists.txt deleted file mode 100644 index 5068660eba1fea5964664819b9a51686cbde2adf..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/impl/test/user/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -aux_source_directory(. USER_SRC) -add_executable(dnode_test_user ${USER_SRC}) -target_link_libraries( - dnode_test_user - PUBLIC sut -) - -add_test( - NAME dnode_test_user - COMMAND dnode_test_user -) diff --git a/source/dnode/mgmt/impl/test/user/user.cpp b/source/dnode/mgmt/impl/test/user/user.cpp deleted file mode 100644 index aa160304c844c00225cef8cc962070763e225143..0000000000000000000000000000000000000000 --- a/source/dnode/mgmt/impl/test/user/user.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/** - * @file user.cpp - * @author slguan (slguan@taosdata.com) - * @brief DNODE module user-msg tests - * @version 0.1 - * @date 2021-12-15 - * - * @copyright Copyright (c) 2021 - * - */ - -#include "base.h" - -class DndTestUser : public ::testing::Test { - protected: - static void SetUpTestSuite() { test.Init("/tmp/dnode_test_user", 9140); } - static void TearDownTestSuite() { test.Cleanup(); } - - static Testbase test; - - public: - void SetUp() override {} - void TearDown() override {} -}; - -Testbase DndTestUser::test; - -TEST_F(DndTestUser, 01_ShowUser) { - test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); - CHECK_META("show users", 4); - - CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "name"); - CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "privilege"); - CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); - CHECK_SCHEMA(3, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "account"); - - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 1); - - CheckBinary("root", TSDB_USER_LEN); - CheckBinary("super", 10); - CheckTimestamp(); - CheckBinary("root", TSDB_USER_LEN); -} - -TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { - { - int32_t contLen = sizeof(SCreateUserMsg); - - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); - strcpy(pReq->user, "u1"); - strcpy(pReq->pass, "p1"); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - } - - { - int32_t contLen = sizeof(SCreateUserMsg); - - SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); - strcpy(pReq->user, "u2"); - strcpy(pReq->pass, "p2"); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - } - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); - CHECK_META("show users", 4); - - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 3); - - CheckBinary("u1", TSDB_USER_LEN); - CheckBinary("root", TSDB_USER_LEN); - CheckBinary("u2", TSDB_USER_LEN); - CheckBinary("normal", 10); - CheckBinary("super", 10); - CheckBinary("normal", 10); - CheckTimestamp(); - CheckTimestamp(); - CheckTimestamp(); - CheckBinary("root", TSDB_USER_LEN); - CheckBinary("root", TSDB_USER_LEN); - CheckBinary("root", TSDB_USER_LEN); - - { - int32_t contLen = sizeof(SAlterUserMsg); - - SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen); - strcpy(pReq->user, "u1"); - strcpy(pReq->pass, "p2"); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - } - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); - CHECK_META("show users", 4); - - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 3); - - CheckBinary("u1", TSDB_USER_LEN); - CheckBinary("root", TSDB_USER_LEN); - CheckBinary("u2", TSDB_USER_LEN); - CheckBinary("normal", 10); - CheckBinary("super", 10); - CheckBinary("normal", 10); - CheckTimestamp(); - CheckTimestamp(); - CheckTimestamp(); - CheckBinary("root", TSDB_USER_LEN); - CheckBinary("root", TSDB_USER_LEN); - CheckBinary("root", TSDB_USER_LEN); - - { - int32_t contLen = sizeof(SDropUserMsg); - - SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen); - strcpy(pReq->user, "u1"); - - SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); - } - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); - CHECK_META("show users", 4); - - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 2); - - CheckBinary("root", TSDB_USER_LEN); - CheckBinary("u2", TSDB_USER_LEN); - CheckBinary("super", 10); - CheckBinary("normal", 10); - CheckTimestamp(); - CheckTimestamp(); - CheckBinary("root", TSDB_USER_LEN); - CheckBinary("root", TSDB_USER_LEN); - - // restart - test.Restart(); - - test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); - CHECK_META("show users", 4); - - test.SendShowRetrieveMsg(); - EXPECT_EQ(test.GetShowRows(), 2); - - CheckBinary("root", TSDB_USER_LEN); - CheckBinary("u2", TSDB_USER_LEN); - CheckBinary("super", 10); - CheckBinary("normal", 10); - CheckTimestamp(); - CheckTimestamp(); - CheckBinary("root", TSDB_USER_LEN); - CheckBinary("root", TSDB_USER_LEN); -} diff --git a/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp b/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp index 718fbea50d9f880e4d61b469fd750a0c878b7cca..7fa3b4ab6167b29a7eb63cbd2391fecc9e657700 100644 --- a/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp +++ b/source/dnode/mgmt/impl/test/vgroup/vgroup.cpp @@ -9,7 +9,7 @@ * */ -#include "base.h" +#include "sut.h" class DndTestVgroup : public ::testing::Test { protected: @@ -60,9 +60,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { pReplica->port = htons(9150); } - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_VNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_VNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } } @@ -100,9 +100,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { pReplica->port = htons(9150); } - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_ALTER_VNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_VNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } } @@ -121,9 +121,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { rpcMsg.contLen = sizeof(SDropVnodeMsg); rpcMsg.msgType = TDMT_DND_DROP_VNODE; - SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_VNODE, pReq, contLen); - ASSERT_NE(pMsg, nullptr); - ASSERT_EQ(pMsg->code, 0); + SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_VNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); } } } diff --git a/source/dnode/mnode/impl/CMakeLists.txt b/source/dnode/mnode/impl/CMakeLists.txt index 98c604e520e518370c92e2a58c0ff9cc46771e8b..adbef3b55f3ff4ff6bb4af421fd1de7594e0decf 100644 --- a/source/dnode/mnode/impl/CMakeLists.txt +++ b/source/dnode/mnode/impl/CMakeLists.txt @@ -8,7 +8,12 @@ target_include_directories( target_link_libraries( mnode PRIVATE sdb + PRIVATE wal PRIVATE transport PRIVATE cjson PRIVATE sync -) \ No newline at end of file +) + +if(${BUILD_TEST}) + add_subdirectory(test) +endif(${BUILD_TEST}) \ No newline at end of file diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index b490eeac96490b294fc357e18ec9cd60c912b34f..a001719dc44cf9696c2afbe3d5bf284438c04cee 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -65,10 +65,10 @@ typedef enum { TRN_STAGE_PREPARE = 0, TRN_STAGE_REDO_LOG = 1, TRN_STAGE_REDO_ACTION = 2, - TRN_STAGE_UNDO_LOG = 3, - TRN_STAGE_UNDO_ACTION = 4, - TRN_STAGE_COMMIT_LOG = 5, - TRN_STAGE_COMMIT = 6, + TRN_STAGE_COMMIT_LOG = 3, + TRN_STAGE_COMMIT = 4, + TRN_STAGE_UNDO_ACTION = 5, + TRN_STAGE_UNDO_LOG = 6, TRN_STAGE_ROLLBACK = 7, TRN_STAGE_FINISHED = 8 } ETrnStage; @@ -161,8 +161,14 @@ typedef struct { typedef struct { int32_t maxUsers; int32_t maxDbs; + int32_t maxStbs; + int32_t maxTbs; int32_t maxTimeSeries; int32_t maxStreams; + int32_t maxFuncs; + int32_t maxConsumers; + int32_t maxConns; + int32_t maxTopics; int64_t maxStorage; // In unit of GB int32_t accessState; // Configured only by command } SAcctCfg; diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 15ff65a8fc0a30ffcd63daeb04d95480cc920b18..89fb2e318929d050cd3c58346edd058211798e68 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -17,11 +17,13 @@ #define _TD_MND_INT_H_ #include "mndDef.h" + #include "sdb.h" #include "tcache.h" #include "tep.h" #include "tqueue.h" #include "ttime.h" +#include "wal.h" #ifdef __cplusplus extern "C" { @@ -65,6 +67,7 @@ typedef struct { typedef struct { int32_t errCode; sem_t syncSem; + SWal *pWal; SSyncNode *pSyncNode; ESyncState state; } SSyncMgmt; @@ -88,15 +91,16 @@ typedef struct SMnode { STelemMgmt telemMgmt; SSyncMgmt syncMgmt; MndMsgFp msgFp[TDMT_MAX]; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; + PutReqToMWriteQFp putReqToMWriteQFp; } SMnode; -void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg); -void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg); -void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg); -void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp); +int32_t mndSendReqToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg); +int32_t mndSendReqToMnode(SMnode *pMnode, SRpcMsg *pMsg); +void mndSendRedirectRsp(SMnode *pMnode, SRpcMsg *pMsg); +void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp); uint64_t mndGenerateUid(char *name, int32_t len) ; diff --git a/source/dnode/mnode/impl/inc/mndTrans.h b/source/dnode/mnode/impl/inc/mndTrans.h index 201fcde1a932b2ff6da777ceb15a733b4f32cb0a..fda3fed13da390c170e7655d447447de9571547c 100644 --- a/source/dnode/mnode/impl/inc/mndTrans.h +++ b/source/dnode/mnode/impl/inc/mndTrans.h @@ -28,6 +28,7 @@ typedef struct { int8_t msgSent; int8_t msgReceived; int32_t errCode; + int32_t acceptableCode; int32_t contLen; void *pCont; } STransAction; @@ -45,6 +46,7 @@ int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction); int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans); void mndTransProcessRsp(SMnodeMsg *pMsg); +void mndTransPullup(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index 767f628306ad2e563baccdd15972f762ffbbd21d..945a6523ef60e2d2161ccbab5677baf52b43c12e 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -18,17 +18,17 @@ #include "mndShow.h" #define TSDB_ACCT_VER_NUMBER 1 -#define TSDB_ACCT_RESERVE_SIZE 64 +#define TSDB_ACCT_RESERVE_SIZE 128 static int32_t mndCreateDefaultAcct(SMnode *pMnode); static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct); static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw); static int32_t mndAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct); static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct); -static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct); -static int32_t mndProcessCreateAcctMsg(SMnodeMsg *pMnodeMsg); -static int32_t mndProcessAlterAcctMsg(SMnodeMsg *pMnodeMsg); -static int32_t mndProcessDropAcctMsg(SMnodeMsg *pMnodeMsg); +static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew); +static int32_t mndProcessCreateAcctReq(SMnodeMsg *pReq); +static int32_t mndProcessAlterAcctReq(SMnodeMsg *pReq); +static int32_t mndProcessDropAcctReq(SMnodeMsg *pReq); int32_t mndInitAcct(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_ACCT, @@ -40,9 +40,9 @@ int32_t mndInitAcct(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndAcctActionUpdate, .deleteFp = (SdbDeleteFp)mndAcctActionDelete}; - mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctMsg); - mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctMsg); - mndSetMsgHandle(pMnode, TDMT_MND_DROP_ACCT, mndProcessDropAcctMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctReq); + mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctReq); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_ACCT, mndProcessDropAcctReq); return sdbSetTable(pMnode->pSdb, table); } @@ -55,10 +55,16 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) { acctObj.createdTime = taosGetTimestampMs(); acctObj.updateTime = acctObj.createdTime; acctObj.acctId = 1; - acctObj.cfg = (SAcctCfg){.maxUsers = 1024, - .maxDbs = 1024, + acctObj.cfg = (SAcctCfg){.maxUsers = INT32_MAX, + .maxDbs = INT32_MAX, + .maxStbs = INT32_MAX, + .maxTbs = INT32_MAX, .maxTimeSeries = INT32_MAX, - .maxStreams = 8092, + .maxStreams = INT32_MAX, + .maxFuncs = INT32_MAX, + .maxConsumers = INT32_MAX, + .maxConns = INT32_MAX, + .maxTopics = INT32_MAX, .maxStorage = INT64_MAX, .accessState = TSDB_VN_ALL_ACCCESS}; @@ -66,96 +72,133 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) { if (pRaw == NULL) return -1; sdbSetRawStatus(pRaw, SDB_STATUS_READY); - mDebug("acct:%s, will be created while deploy sdb", acctObj.acct); + mDebug("acct:%s, will be created while deploy sdb, raw:%p", acctObj.acct, pRaw); return sdbWrite(pMnode->pSdb, pRaw); } 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) return NULL; + if (pRaw == NULL) goto ACCT_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN) - SDB_SET_INT64(pRaw, dataPos, pAcct->createdTime) - SDB_SET_INT64(pRaw, dataPos, pAcct->updateTime) - SDB_SET_INT32(pRaw, dataPos, pAcct->acctId) - SDB_SET_INT32(pRaw, dataPos, pAcct->status) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxUsers) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxDbs) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTimeSeries) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStreams) - SDB_SET_INT64(pRaw, dataPos, pAcct->cfg.maxStorage) - SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.accessState) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE) - SDB_SET_DATALEN(pRaw, dataPos); + 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) + + terrno = 0; + +ACCT_ENCODE_OVER: + if (terrno != 0) { + mError("acct:%s, failed to encode to raw:%p since %s", pAcct->acct, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + mTrace("acct:%s, encode to raw:%p, row:%p", pAcct->acct, pRaw, pAcct); return pRaw; } static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto ACCT_DECODE_OVER; if (sver != TSDB_ACCT_VER_NUMBER) { - mError("failed to decode acct since %s", terrstr()); terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - return NULL; + goto ACCT_DECODE_OVER; } - SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj)); + SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj)); + if (pRow == NULL) goto ACCT_DECODE_OVER; + SAcctObj *pAcct = sdbGetRowObj(pRow); - if (pAcct == NULL) return NULL; + if (pAcct == NULL) goto ACCT_DECODE_OVER; int32_t dataPos = 0; - SDB_GET_BINARY(pRaw, pRow, dataPos, pAcct->acct, TSDB_USER_LEN) - SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->updateTime) - SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->acctId) - SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->status) - SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxUsers) - SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxDbs) - SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxTimeSeries) - SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxStreams) - SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->cfg.maxStorage) - SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.accessState) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_ACCT_RESERVE_SIZE) + 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) + + terrno = 0; + +ACCT_DECODE_OVER: + if (terrno != 0) { + mError("acct:%s, failed to decode from raw:%p since %s", pAcct->acct, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + mTrace("acct:%s, decode from raw:%p, row:%p", pAcct->acct, pRaw, pAcct); return pRow; } static int32_t mndAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct) { - mTrace("acct:%s, perform insert action", pAcct->acct); + mTrace("acct:%s, perform insert action, row:%p", pAcct->acct, pAcct); return 0; } static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) { - mTrace("acct:%s, perform delete action", pAcct->acct); + mTrace("acct:%s, perform delete action, row:%p", pAcct->acct, pAcct); return 0; } -static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct) { - mTrace("acct:%s, perform update action", pOldAcct->acct); +static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew) { + mTrace("acct:%s, perform update action, old_row:%p new_row:%p", pOld->acct, pOld, pNew); - pOldAcct->updateTime = pNewAcct->updateTime; - pOldAcct->status = pNewAcct->status; - memcpy(&pOldAcct->cfg, &pNewAcct->cfg, sizeof(SAcctInfo)); + pOld->updateTime = pNew->updateTime; + pOld->status = pNew->status; + memcpy(&pOld->cfg, &pNew->cfg, sizeof(SAcctCfg)); return 0; } -static int32_t mndProcessCreateAcctMsg(SMnodeMsg *pMnodeMsg) { +static int32_t mndProcessCreateAcctReq(SMnodeMsg *pReq) { terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; - mError("failed to process create acct msg since %s", terrstr()); + mError("failed to process create acct request since %s", terrstr()); return -1; } -static int32_t mndProcessAlterAcctMsg(SMnodeMsg *pMnodeMsg) { +static int32_t mndProcessAlterAcctReq(SMnodeMsg *pReq) { terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; - mError("failed to process create acct msg since %s", terrstr()); + mError("failed to process create acct request since %s", terrstr()); return -1; } -static int32_t mndProcessDropAcctMsg(SMnodeMsg *pMnodeMsg) { +static int32_t mndProcessDropAcctReq(SMnodeMsg *pReq) { terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; - mError("failed to process create acct msg since %s", terrstr()); + mError("failed to process create acct request since %s", terrstr()); return -1; } \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndAuth.c b/source/dnode/mnode/impl/src/mndAuth.c index bcefbfde21de6c62b659327a7597ec7f6f0c0a0f..a2fc7a57b355e3f5a224ecc7d65ed67652d7bbca 100644 --- a/source/dnode/mnode/impl/src/mndAuth.c +++ b/source/dnode/mnode/impl/src/mndAuth.c @@ -14,7 +14,6 @@ */ #define _DEFAULT_SOURCE -#include "os.h" #include "mndAuth.h" int32_t mndInitAuth(SMnode *pMnode) { return 0; } diff --git a/source/dnode/mnode/impl/src/mndBnode.c b/source/dnode/mnode/impl/src/mndBnode.c index 2d14e0f92e828b267fb768f26d8d76fb06625683..6325bbb6fd0c04591758605af9fccdea5ca9b97e 100644 --- a/source/dnode/mnode/impl/src/mndBnode.c +++ b/source/dnode/mnode/impl/src/mndBnode.c @@ -26,13 +26,13 @@ static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj); static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw); static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj); static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj); -static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOldBnode, SBnodeObj *pNewBnode); -static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg); -static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg); -static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pMsg); -static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pMsg); -static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); -static int32_t mndRetrieveBnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOld, SBnodeObj *pNew); +static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pReq); +static int32_t mndProcessDropBnodeReq(SMnodeMsg *pReq); +static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pRsp); +static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pRsp); +static int32_t mndGetBnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta); +static int32_t mndRetrieveBnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextBnode(SMnode *pMnode, void *pIter); int32_t mndInitBnode(SMnode *pMnode) { @@ -58,10 +58,9 @@ int32_t mndInitBnode(SMnode *pMnode) { void mndCleanupBnode(SMnode *pMnode) {} -static SBnodeObj *mndAcquireBnode(SMnode *pMnode, int32_t snodeId) { - SSdb *pSdb = pMnode->pSdb; - SBnodeObj *pObj = sdbAcquire(pSdb, SDB_BNODE, &snodeId); - if (pObj == NULL) { +static SBnodeObj *mndAcquireBnode(SMnode *pMnode, int32_t bnodeId) { + SBnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_BNODE, &bnodeId); + if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) { terrno = TSDB_CODE_MND_BNODE_NOT_EXIST; } return pObj; @@ -73,47 +72,72 @@ static void mndReleaseBnode(SMnode *pMnode, SBnodeObj *pObj) { } static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_BNODE, TSDB_BNODE_VER_NUMBER, sizeof(SBnodeObj) + TSDB_BNODE_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto BNODE_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pObj->id); - SDB_SET_INT64(pRaw, dataPos, pObj->createdTime) - SDB_SET_INT64(pRaw, dataPos, pObj->updateTime) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_BNODE_RESERVE_SIZE) + SDB_SET_INT32(pRaw, dataPos, pObj->id, BNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pObj->createdTime, BNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pObj->updateTime, BNODE_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_BNODE_RESERVE_SIZE, BNODE_ENCODE_OVER) + terrno = 0; + +BNODE_ENCODE_OVER: + if (terrno != 0) { + mError("bnode:%d, failed to encode to raw:%p since %s", pObj->id, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("bnode:%d, encode to raw:%p, row:%p", pObj->id, pRaw, pObj); return pRaw; } static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto BNODE_DECODE_OVER; if (sver != TSDB_BNODE_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode snode since %s", terrstr()); - return NULL; + goto BNODE_DECODE_OVER; } - SSdbRow *pRow = sdbAllocRow(sizeof(SBnodeObj)); + SSdbRow *pRow = sdbAllocRow(sizeof(SBnodeObj)); + if (pRow == NULL) goto BNODE_DECODE_OVER; + SBnodeObj *pObj = sdbGetRowObj(pRow); - if (pObj == NULL) return NULL; + if (pObj == NULL) goto BNODE_DECODE_OVER; int32_t dataPos = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id) - SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_BNODE_RESERVE_SIZE) + SDB_GET_INT32(pRaw, dataPos, &pObj->id, BNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pObj->createdTime, BNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pObj->updateTime, BNODE_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_BNODE_RESERVE_SIZE, BNODE_DECODE_OVER) + + terrno = 0; +BNODE_DECODE_OVER: + if (terrno != 0) { + mError("bnode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + + mTrace("bnode:%d, decode from raw:%p, row:%p", pObj->id, pRaw, pObj); return pRow; } static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj) { - mTrace("snode:%d, perform insert action", pObj->id); + mTrace("bnode:%d, perform insert action, row:%p", pObj->id, pObj); pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id); if (pObj->pDnode == NULL) { terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; - mError("snode:%d, failed to perform insert action since %s", pObj->id, terrstr()); + mError("bnode:%d, failed to perform insert action since %s", pObj->id, terrstr()); return -1; } @@ -121,7 +145,7 @@ static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj) { } static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj) { - mTrace("snode:%d, perform delete action", pObj->id); + mTrace("bnode:%d, perform delete action, row:%p", pObj->id, pObj); if (pObj->pDnode != NULL) { sdbRelease(pSdb, pObj->pDnode); pObj->pDnode = NULL; @@ -130,9 +154,9 @@ static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj) { return 0; } -static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOldBnode, SBnodeObj *pNewBnode) { - mTrace("snode:%d, perform update action", pOldBnode->id); - pOldBnode->updateTime = pNewBnode->updateTime; +static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOld, SBnodeObj *pNew) { + mTrace("bnode:%d, perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew); + pOld->updateTime = pNew->updateTime; return 0; } @@ -144,6 +168,14 @@ static int32_t mndSetCreateBnodeRedoLogs(STrans *pTrans, SBnodeObj *pObj) { return 0; } +static int32_t mndSetCreateBnodeUndoLogs(STrans *pTrans, SBnodeObj *pObj) { + SSdbRaw *pUndoRaw = mndBnodeActionEncode(pObj); + if (pUndoRaw == NULL) return -1; + if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1; + if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1; + return 0; +} + static int32_t mndSetCreateBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) { SSdbRaw *pCommitRaw = mndBnodeActionEncode(pObj); if (pCommitRaw == NULL) return -1; @@ -153,60 +185,69 @@ static int32_t mndSetCreateBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) { } static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) { - SDCreateBnodeMsg *pMsg = malloc(sizeof(SDCreateBnodeMsg)); - if (pMsg == NULL) { + SDCreateBnodeReq *pReq = malloc(sizeof(SDCreateBnodeReq)); + if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pMsg->dnodeId = htonl(pDnode->id); + pReq->dnodeId = htonl(pDnode->id); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); - action.pCont = pMsg; - action.contLen = sizeof(SDCreateBnodeMsg); + action.pCont = pReq; + action.contLen = sizeof(SDCreateBnodeReq); action.msgType = TDMT_DND_CREATE_BNODE; + action.acceptableCode = TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pMsg); + free(pReq); return -1; } return 0; } -static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateBnodeMsg *pCreate) { - SBnodeObj snodeObj = {0}; - snodeObj.id = pDnode->id; - snodeObj.createdTime = taosGetTimestampMs(); - snodeObj.updateTime = snodeObj.createdTime; - - int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); - if (pTrans == NULL) { - mError("snode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); - goto CREATE_BNODE_OVER; +static int32_t mndSetCreateBnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) { + SDDropBnodeReq *pReq = malloc(sizeof(SDDropBnodeReq)); + if (pReq == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; } - mDebug("trans:%d, used to create snode:%d", pTrans->id, pCreate->dnodeId); + pReq->dnodeId = htonl(pDnode->id); - if (mndSetCreateBnodeRedoLogs(pTrans, &snodeObj) != 0) { - mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); - goto CREATE_BNODE_OVER; - } + STransAction action = {0}; + action.epSet = mndGetDnodeEpset(pDnode); + action.pCont = pReq; + action.contLen = sizeof(SDDropBnodeReq); + action.msgType = TDMT_DND_DROP_BNODE; + action.acceptableCode = TSDB_CODE_DND_BNODE_NOT_DEPLOYED; - if (mndSetCreateBnodeCommitLogs(pTrans, &snodeObj) != 0) { - mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); - goto CREATE_BNODE_OVER; + if (mndTransAppendUndoAction(pTrans, &action) != 0) { + free(pReq); + return -1; } - if (mndSetCreateBnodeRedoActions(pTrans, pDnode, &snodeObj) != 0) { - mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); - goto CREATE_BNODE_OVER; - } + return 0; +} - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - goto CREATE_BNODE_OVER; - } +static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pReq, SDnodeObj *pDnode, SMCreateBnodeReq *pCreate) { + int32_t code = -1; + + SBnodeObj bnodeObj = {0}; + bnodeObj.id = pDnode->id; + bnodeObj.createdTime = taosGetTimestampMs(); + bnodeObj.updateTime = bnodeObj.createdTime; + + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg); + if (pTrans == NULL) goto CREATE_BNODE_OVER; + + mDebug("trans:%d, used to create bnode:%d", pTrans->id, pCreate->dnodeId); + if (mndSetCreateBnodeRedoLogs(pTrans, &bnodeObj) != 0) goto CREATE_BNODE_OVER; + if (mndSetCreateBnodeUndoLogs(pTrans, &bnodeObj) != 0) goto CREATE_BNODE_OVER; + if (mndSetCreateBnodeCommitLogs(pTrans, &bnodeObj) != 0) goto CREATE_BNODE_OVER; + if (mndSetCreateBnodeRedoActions(pTrans, pDnode, &bnodeObj) != 0) goto CREATE_BNODE_OVER; + if (mndSetCreateBnodeUndoActions(pTrans, pDnode, &bnodeObj) != 0) goto CREATE_BNODE_OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto CREATE_BNODE_OVER; code = 0; @@ -215,33 +256,37 @@ CREATE_BNODE_OVER: return code; } -static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SMCreateBnodeMsg *pCreate = pMsg->rpcMsg.pCont; +static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SMCreateBnodeReq *pCreate = pReq->rpcMsg.pCont; pCreate->dnodeId = htonl(pCreate->dnodeId); - mDebug("snode:%d, start to create", pCreate->dnodeId); + mDebug("bnode:%d, start to create", pCreate->dnodeId); SBnodeObj *pObj = mndAcquireBnode(pMnode, pCreate->dnodeId); if (pObj != NULL) { - mError("snode:%d, snode already exist", pObj->id); + mError("bnode:%d, bnode already exist", pObj->id); + terrno = TSDB_CODE_MND_BNODE_ALREADY_EXIST; mndReleaseBnode(pMnode, pObj); return -1; + } else if (terrno != TSDB_CODE_MND_BNODE_NOT_EXIST) { + mError("bnode:%d, failed to create bnode since %s", pCreate->dnodeId, terrstr()); + return -1; } SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId); if (pDnode == NULL) { - mError("snode:%d, dnode not exist", pCreate->dnodeId); + mError("bnode:%d, dnode not exist", pCreate->dnodeId); terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; return -1; } - int32_t code = mndCreateBnode(pMnode, pMsg, pDnode, pCreate); + int32_t code = mndCreateBnode(pMnode, pReq, pDnode, pCreate); mndReleaseDnode(pMnode, pDnode); if (code != 0) { - mError("snode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); + mError("bnode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); return -1; } @@ -265,56 +310,39 @@ static int32_t mndSetDropBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) { } static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) { - SDDropBnodeMsg *pMsg = malloc(sizeof(SDDropBnodeMsg)); - if (pMsg == NULL) { + SDDropBnodeReq *pReq = malloc(sizeof(SDDropBnodeReq)); + if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pMsg->dnodeId = htonl(pDnode->id); + pReq->dnodeId = htonl(pDnode->id); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); - action.pCont = pMsg; - action.contLen = sizeof(SDDropBnodeMsg); + action.pCont = pReq; + action.contLen = sizeof(SDDropBnodeReq); action.msgType = TDMT_DND_DROP_BNODE; + action.acceptableCode = TSDB_CODE_DND_BNODE_NOT_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pMsg); + free(pReq); return -1; } return 0; } -static int32_t mndDropBnode(SMnode *pMnode, SMnodeMsg *pMsg, SBnodeObj *pObj) { +static int32_t mndDropBnode(SMnode *pMnode, SMnodeMsg *pReq, SBnodeObj *pObj) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); - if (pTrans == NULL) { - mError("snode:%d, failed to drop since %s", pObj->id, terrstr()); - goto DROP_BNODE_OVER; - } - mDebug("trans:%d, used to drop snode:%d", pTrans->id, pObj->id); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pReq->rpcMsg); + if (pTrans == NULL) goto DROP_BNODE_OVER; - if (mndSetDropBnodeRedoLogs(pTrans, pObj) != 0) { - mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); - goto DROP_BNODE_OVER; - } - - if (mndSetDropBnodeCommitLogs(pTrans, pObj) != 0) { - mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); - goto DROP_BNODE_OVER; - } - - if (mndSetDropBnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) { - mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); - goto DROP_BNODE_OVER; - } - - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - goto DROP_BNODE_OVER; - } + mDebug("trans:%d, used to drop bnode:%d", pTrans->id, pObj->id); + if (mndSetDropBnodeRedoLogs(pTrans, pObj) != 0) goto DROP_BNODE_OVER; + if (mndSetDropBnodeCommitLogs(pTrans, pObj) != 0) goto DROP_BNODE_OVER; + if (mndSetDropBnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) goto DROP_BNODE_OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto DROP_BNODE_OVER; code = 0; @@ -323,48 +351,48 @@ DROP_BNODE_OVER: return code; } -static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SMDropBnodeMsg *pDrop = pMsg->rpcMsg.pCont; +static int32_t mndProcessDropBnodeReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SMDropBnodeReq *pDrop = pReq->rpcMsg.pCont; pDrop->dnodeId = htonl(pDrop->dnodeId); - mDebug("snode:%d, start to drop", pDrop->dnodeId); + mDebug("bnode:%d, start to drop", pDrop->dnodeId); if (pDrop->dnodeId <= 0) { terrno = TSDB_CODE_SDB_APP_ERROR; - mError("snode:%d, failed to drop since %s", pDrop->dnodeId, terrstr()); + mError("bnode:%d, failed to drop since %s", pDrop->dnodeId, terrstr()); return -1; } SBnodeObj *pObj = mndAcquireBnode(pMnode, pDrop->dnodeId); if (pObj == NULL) { - mError("snode:%d, not exist", pDrop->dnodeId); - terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + mError("bnode:%d, failed to drop since %s", pDrop->dnodeId, terrstr()); return -1; } - int32_t code = mndDropBnode(pMnode, pMsg, pObj); + int32_t code = mndDropBnode(pMnode, pReq, pObj); if (code != 0) { - mError("snode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); + sdbRelease(pMnode->pSdb, pObj); + mError("bnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); return -1; } - sdbRelease(pMnode->pSdb, pMnode); + sdbRelease(pMnode->pSdb, pObj); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pMsg) { - mndTransProcessRsp(pMsg); +static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pRsp) { + mndTransProcessRsp(pRsp); return 0; } -static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pMsg) { - mndTransProcessRsp(pMsg); +static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pRsp) { + mndTransProcessRsp(pRsp); return 0; } -static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndGetBnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) { + SMnode *pMnode = pReq->pMnode; SSdb *pSdb = pMnode->pSdb; int32_t cols = 0; @@ -403,8 +431,8 @@ static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * return 0; } -static int32_t mndRetrieveBnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndRetrieveBnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { + SMnode *pMnode = pReq->pMnode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; int32_t cols = 0; diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index f656c27dcd224db8cb6c80dee9e609c40668ef88..8cb98a148fb1728c4e9d65a1069f19c1b601dfdf 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -16,7 +16,6 @@ #define _DEFAULT_SOURCE #include "mndCluster.h" #include "mndShow.h" -#include "mndTrans.h" #define TSDB_CLUSTER_VER_NUMBE 1 #define TSDB_CLUSTER_RESERVE_SIZE 64 @@ -33,7 +32,7 @@ static void mndCancelGetNextCluster(SMnode *pMnode, void *pIter); int32_t mndInitCluster(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_CLUSTER, - .keyType = SDB_KEY_INT32, + .keyType = SDB_KEY_INT64, .deployFp = (SdbDeployFp)mndCreateDefaultCluster, .encodeFp = (SdbEncodeFp)mndClusterActionEncode, .decodeFp = (SdbDecodeFp)mndClusterActionDecode, @@ -63,55 +62,80 @@ int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len) { } static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_CLUSTER, TSDB_CLUSTER_VER_NUMBE, sizeof(SClusterObj) + TSDB_CLUSTER_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto CLUSTER_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_INT64(pRaw, dataPos, pCluster->id); - SDB_SET_INT64(pRaw, dataPos, pCluster->createdTime) - SDB_SET_INT64(pRaw, dataPos, pCluster->updateTime) - SDB_SET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_CLUSTER_RESERVE_SIZE) + SDB_SET_INT64(pRaw, dataPos, pCluster->id, CLUSTER_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pCluster->createdTime, CLUSTER_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pCluster->updateTime, CLUSTER_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, CLUSTER_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_CLUSTER_RESERVE_SIZE, CLUSTER_ENCODE_OVER) + + terrno = 0; + +CLUSTER_ENCODE_OVER: + if (terrno != 0) { + mError("cluster:%" PRId64 ", failed to encode to raw:%p since %s", pCluster->id, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + mTrace("cluster:%" PRId64 ", encode to raw:%p, row:%p", pCluster->id, pRaw, pCluster); return pRaw; } static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto CLUSTER_DECODE_OVER; if (sver != TSDB_CLUSTER_VER_NUMBE) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode cluster since %s", terrstr()); - return NULL; + goto CLUSTER_DECODE_OVER; } - SSdbRow *pRow = sdbAllocRow(sizeof(SClusterObj)); + SSdbRow *pRow = sdbAllocRow(sizeof(SClusterObj)); + if (pRow == NULL) goto CLUSTER_DECODE_OVER; + SClusterObj *pCluster = sdbGetRowObj(pRow); - if (pCluster == NULL) return NULL; + if (pCluster == NULL) goto CLUSTER_DECODE_OVER; int32_t dataPos = 0; - SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->id) - SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->updateTime) - SDB_GET_BINARY(pRaw, pRow, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_CLUSTER_RESERVE_SIZE) + SDB_GET_INT64(pRaw, dataPos, &pCluster->id, CLUSTER_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pCluster->createdTime, CLUSTER_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pCluster->updateTime, CLUSTER_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, CLUSTER_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_CLUSTER_RESERVE_SIZE, CLUSTER_DECODE_OVER) + + terrno = 0; + +CLUSTER_DECODE_OVER: + if (terrno != 0) { + mError("cluster:%" PRId64 ", failed to decode from raw:%p since %s", pCluster->id, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + mTrace("cluster:%" PRId64 ", decode from raw:%p, row:%p", pCluster->id, pRaw, pCluster); return pRow; } static int32_t mndClusterActionInsert(SSdb *pSdb, SClusterObj *pCluster) { - mTrace("cluster:%" PRId64 ", perform insert action", pCluster->id); + mTrace("cluster:%" PRId64 ", perform insert action, row:%p", pCluster->id, pCluster); return 0; } static int32_t mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster) { - mTrace("cluster:%" PRId64 ", perform delete action", pCluster->id); + mTrace("cluster:%" PRId64 ", perform delete action, row:%p", pCluster->id, pCluster); return 0; } -static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOldCluster, SClusterObj *pNewCluster) { - mTrace("cluster:%" PRId64 ", perform update action", pOldCluster->id); +static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOld, SClusterObj *pNew) { + mTrace("cluster:%" PRId64 ", perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew); return 0; } @@ -120,22 +144,22 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) { clusterObj.createdTime = taosGetTimestampMs(); clusterObj.updateTime = clusterObj.createdTime; - int32_t code = taosGetSystemUid(clusterObj.name, TSDB_CLUSTER_ID_LEN); + int32_t code = taosGetSystemUUID(clusterObj.name, TSDB_CLUSTER_ID_LEN); if (code != 0) { strcpy(clusterObj.name, "tdengine2.0"); mError("failed to get name from system, set to default val %s", clusterObj.name); - } else { - mDebug("cluster:%" PRId64 ", name is %s", clusterObj.id, clusterObj.name); } - clusterObj.id = MurmurHash3_32(clusterObj.name, TSDB_CLUSTER_ID_LEN); + + clusterObj.id = mndGenerateUid(clusterObj.name, TSDB_CLUSTER_ID_LEN); clusterObj.id = (clusterObj.id >= 0 ? clusterObj.id : -clusterObj.id); pMnode->clusterId = clusterObj.id; + mDebug("cluster:%" PRId64 ", name is %s", clusterObj.id, clusterObj.name); SSdbRaw *pRaw = mndClusterActionEncode(&clusterObj); if (pRaw == NULL) return -1; sdbSetRawStatus(pRaw, SDB_STATUS_READY); - mDebug("cluster:%" PRId64 ", will be created while deploy sdb", clusterObj.id); + mDebug("cluster:%" PRId64 ", will be created while deploy sdb, raw:%p", clusterObj.id, pRaw); return sdbWrite(pMnode->pSdb, pRaw); } diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index eeb011c084aa5eb558d01cddba59308333ac475e..0f600bdcf854ac25ff1d1fcdbb887511c835a1ab 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -74,14 +74,14 @@ static void *mndBuildMqVGroupSetReq(SMnode *pMnode, char *topicName, int32_t vgI static SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer) { int32_t size = sizeof(SMqConsumerObj) + MND_CONSUMER_RESERVE_SIZE; SSdbRaw *pRaw = sdbAllocRaw(SDB_CONSUMER, MND_CONSUMER_VER_NUMBER, size); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto CM_ENCODE_OVER; int32_t dataPos = 0; int32_t topicNum = taosArrayGetSize(pConsumer->topics); SDB_SET_INT64(pRaw, dataPos, pConsumer->consumerId); int32_t len = strlen(pConsumer->cgroup); - SDB_SET_INT32(pRaw, dataPos, len); - SDB_SET_BINARY(pRaw, dataPos, pConsumer->cgroup, len); + SDB_SET_INT32(pRaw, dataPos, len, CM_ENCODE_OVER); + SDB_SET_BINARY(pRaw, dataPos, pConsumer->cgroup, len, CM_ENCODE_OVER); SDB_SET_INT32(pRaw, dataPos, topicNum); for (int i = 0; i < topicNum; i++) { int32_t len; @@ -105,30 +105,41 @@ static SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer) { SDB_SET_RESERVE(pRaw, dataPos, MND_CONSUMER_RESERVE_SIZE); SDB_SET_DATALEN(pRaw, dataPos); +CM_ENCODE_OVER: + if (terrno != 0) { + mError("consumer:%s, failed to encode to raw:%p since %s", pConsumer->name, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("consumer:%s, encode to raw:%p, row:%p", pConsumer->name, pRaw, pConsumer); return pRaw; } static SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto CONSUME_DECODE_OVER; if (sver != MND_CONSUMER_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode consumer since %s", terrstr()); - return NULL; + goto CONSUME_DECODE_OVER; } int32_t size = sizeof(SMqConsumerObj); SSdbRow *pRow = sdbAllocRow(size); + if (pRow == NULL) goto CONSUMER_DECODE_OVER; + SMqConsumerObj *pConsumer = sdbGetRowObj(pRow); - if (pConsumer == NULL) return NULL; + if (pConsumer == NULL) goto CONSUMER_DECODE_OVER; int32_t dataPos = 0; - SDB_GET_INT64(pRaw, pRow, dataPos, &pConsumer->consumerId); + SDB_GET_INT64(pRaw, pRow, dataPos, &pConsumer->consumerId, CONSUME_DECODE_OVER); int32_t len, topicNum; - SDB_GET_INT32(pRaw, pRow, dataPos, &len); - SDB_GET_BINARY(pRaw, pRow, dataPos, pConsumer->cgroup, len); - SDB_GET_INT32(pRaw, pRow, dataPos, &topicNum); + SDB_GET_INT32(pRaw, pRow, dataPos, &len, CONSUME_DECODE_OVER); + SDB_GET_BINARY(pRaw, pRow, dataPos, pConsumer->cgroup, len, CONSUME_DECODE_OVER); + SDB_GET_INT32(pRaw, pRow, dataPos, &topicNum, CONSUME_DECODE_OVER); for (int i = 0; i < topicNum; i++) { int32_t topicLen; SMqConsumerTopic *pConsumerTopic = malloc(sizeof(SMqConsumerTopic)); @@ -138,12 +149,19 @@ static SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw) { return NULL; } /*pConsumerTopic->vgroups = taosArrayInit(topicNum, sizeof(SMqConsumerTopic));*/ - SDB_GET_INT32(pRaw, pRow, dataPos, &topicLen); - SDB_GET_BINARY(pRaw, pRow, dataPos, pConsumerTopic->name, topicLen); + SDB_GET_INT32(pRaw, pRow, dataPos, &topicLen, CONSUME_DECODE_OVER); + SDB_GET_BINARY(pRaw, pRow, dataPos, pConsumerTopic->name, topicLen, CONSUME_DECODE_OVER); int32_t vgSize; - SDB_GET_INT32(pRaw, pRow, dataPos, &vgSize); + SDB_GET_INT32(pRaw, pRow, dataPos, &vgSize, CONSUME_DECODE_OVER); } + +CONSUME_DECODE_OVER: + if (terrno != 0) { + mError("consumer:%s, failed to decode from raw:%p since %s", pConsumer->name, pRaw, terrstr()); + tfree(pRow); + return NULL; + SDB_GET_RESERVE(pRaw, pRow, dataPos, MND_CONSUMER_RESERVE_SIZE); return pRow; diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index f9199f9eed0f65bbb2bbd9e10471bd288723be92..410368f13060609cc365e446860c989437addad1 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -65,100 +65,125 @@ int32_t mndInitDb(SMnode *pMnode) { void mndCleanupDb(SMnode *pMnode) {} static SSdbRaw *mndDbActionEncode(SDbObj *pDb) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_DB, TSDB_DB_VER_NUMBER, sizeof(SDbObj) + TSDB_DB_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto DB_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_BINARY(pRaw, dataPos, pDb->name, TSDB_DB_FNAME_LEN) - SDB_SET_BINARY(pRaw, dataPos, pDb->acct, TSDB_USER_LEN) - SDB_SET_INT64(pRaw, dataPos, pDb->createdTime) - SDB_SET_INT64(pRaw, dataPos, pDb->updateTime) - SDB_SET_INT64(pRaw, dataPos, pDb->uid) - SDB_SET_INT32(pRaw, dataPos, pDb->cfgVersion) - SDB_SET_INT32(pRaw, dataPos, pDb->vgVersion) - SDB_SET_INT8(pRaw, dataPos, pDb->hashMethod) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfVgroups) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.cacheBlockSize) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.totalBlocks) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysPerFile) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep0) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep1) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep2) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.minRows) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.maxRows) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.commitTime) - SDB_SET_INT32(pRaw, dataPos, pDb->cfg.fsyncPeriod) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.walLevel) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.precision) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.compression) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.replications) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.quorum) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.update) - SDB_SET_INT8(pRaw, dataPos, pDb->cfg.cacheLastRow) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_DB_RESERVE_SIZE) - SDB_SET_DATALEN(pRaw, dataPos); + SDB_SET_BINARY(pRaw, dataPos, pDb->name, TSDB_DB_FNAME_LEN, DB_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pDb->acct, TSDB_USER_LEN, DB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pDb->createdTime, DB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pDb->updateTime, DB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pDb->uid, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfgVersion, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->vgVersion, DB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->hashMethod, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfVgroups, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.cacheBlockSize, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.totalBlocks, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysPerFile, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep0, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep1, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep2, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.minRows, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.maxRows, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.commitTime, DB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pDb->cfg.fsyncPeriod, DB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->cfg.walLevel, DB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->cfg.precision, DB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->cfg.compression, DB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->cfg.replications, DB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->cfg.quorum, DB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->cfg.update, DB_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pDb->cfg.cacheLastRow, DB_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_DB_RESERVE_SIZE, DB_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, DB_ENCODE_OVER) + + terrno = 0; + +DB_ENCODE_OVER: + if (terrno != 0) { + mError("db:%s, failed to encode to raw:%p since %s", pDb->name, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + mTrace("db:%s, encode to raw:%p, row:%p", pDb->name, pRaw, pDb); return pRaw; } static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto DB_DECODE_OVER; if (sver != TSDB_DB_VER_NUMBER) { - mError("failed to decode db since %s", terrstr()); terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - return NULL; + goto DB_DECODE_OVER; } SSdbRow *pRow = sdbAllocRow(sizeof(SDbObj)); - SDbObj *pDb = sdbGetRowObj(pRow); - if (pDb == NULL) return NULL; + if (pRow == NULL) goto DB_DECODE_OVER; + + SDbObj *pDb = sdbGetRowObj(pRow); + if (pDb == NULL) goto DB_DECODE_OVER; int32_t dataPos = 0; - SDB_GET_BINARY(pRaw, pRow, dataPos, pDb->name, TSDB_DB_FNAME_LEN) - SDB_GET_BINARY(pRaw, pRow, dataPos, pDb->acct, TSDB_USER_LEN) - SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->updateTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->uid) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfgVersion) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->vgVersion) - SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->hashMethod) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.numOfVgroups) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.cacheBlockSize) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.totalBlocks) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysPerFile) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysToKeep0) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysToKeep1) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysToKeep2) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.minRows) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.maxRows) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.commitTime) - SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.fsyncPeriod) - SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.walLevel) - SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.precision) - SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.compression) - SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.replications) - SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.quorum) - SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.update) - SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.cacheLastRow) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_DB_RESERVE_SIZE) + SDB_GET_BINARY(pRaw, dataPos, pDb->name, TSDB_DB_FNAME_LEN, DB_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pDb->acct, TSDB_USER_LEN, DB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pDb->createdTime, DB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pDb->updateTime, DB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pDb->uid, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfgVersion, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->vgVersion, DB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->hashMethod, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.numOfVgroups, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.cacheBlockSize, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.totalBlocks, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysPerFile, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep0, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep1, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep2, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.minRows, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.maxRows, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.commitTime, DB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.fsyncPeriod, DB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.walLevel, DB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.precision, DB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.compression, DB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.replications, DB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.quorum, DB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.update, DB_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.cacheLastRow, DB_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_DB_RESERVE_SIZE, DB_DECODE_OVER) + + terrno = 0; + +DB_DECODE_OVER: + if (terrno != 0) { + mError("db:%s, failed to decode from raw:%p since %s", pDb->name, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + mTrace("db:%s, decode from raw:%p, row:%p", pDb->name, pRaw, pDb); return pRow; } static int32_t mndDbActionInsert(SSdb *pSdb, SDbObj *pDb) { - mTrace("db:%s, perform insert action", pDb->name); + mTrace("db:%s, perform insert action, row:%p", pDb->name, pDb); return 0; } static int32_t mndDbActionDelete(SSdb *pSdb, SDbObj *pDb) { - mTrace("db:%s, perform delete action", pDb->name); + mTrace("db:%s, perform delete action, row:%p", pDb->name, pDb); return 0; } static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOldDb, SDbObj *pNewDb) { - mTrace("db:%s, perform update action", pOldDb->name); + mTrace("db:%s, perform update action, old_row:%p new_row:%p", pOldDb->name, pOldDb, pNewDb); pOldDb->updateTime = pNewDb->updateTime; pOldDb->cfgVersion = pNewDb->cfgVersion; pOldDb->vgVersion = pNewDb->vgVersion; diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 1c7f8544e901f00acec1da0da00bb728e4da63ab..2cca70b04ecb10ec4dc3cf43f2044fbd9dc2b41c 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -100,65 +100,90 @@ static int32_t mndCreateDefaultDnode(SMnode *pMnode) { if (pRaw == NULL) return -1; if (sdbSetRawStatus(pRaw, SDB_STATUS_READY) != 0) return -1; - mDebug("dnode:%d, will be created while deploy sdb", dnodeObj.id); + mDebug("dnode:%d, will be created while deploy sdb, raw:%p", dnodeObj.id, pRaw); return sdbWrite(pMnode->pSdb, pRaw); } static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_DNODE, TSDB_DNODE_VER_NUMBER, sizeof(SDnodeObj) + TSDB_DNODE_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto DNODE_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pDnode->id); - SDB_SET_INT64(pRaw, dataPos, pDnode->createdTime) - SDB_SET_INT64(pRaw, dataPos, pDnode->updateTime) - SDB_SET_INT16(pRaw, dataPos, pDnode->port) - SDB_SET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE) - SDB_SET_DATALEN(pRaw, dataPos); + SDB_SET_INT32(pRaw, dataPos, pDnode->id, DNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pDnode->createdTime, DNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pDnode->updateTime, DNODE_ENCODE_OVER) + SDB_SET_INT16(pRaw, dataPos, pDnode->port, DNODE_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, DNODE_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, DNODE_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, DNODE_ENCODE_OVER); + + terrno = 0; + +DNODE_ENCODE_OVER: + if (terrno != 0) { + mError("dnode:%d, failed to encode to raw:%p since %s", pDnode->id, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + mTrace("dnode:%d, encode to raw:%p, row:%p", pDnode->id, pRaw, pDnode); return pRaw; } static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto DNODE_DECODE_OVER; if (sver != TSDB_DNODE_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode dnode since %s", terrstr()); - return NULL; + goto DNODE_DECODE_OVER; } - SSdbRow *pRow = sdbAllocRow(sizeof(SDnodeObj)); + SSdbRow *pRow = sdbAllocRow(sizeof(SDnodeObj)); + if (pRow == NULL) goto DNODE_DECODE_OVER; + SDnodeObj *pDnode = sdbGetRowObj(pRow); - if (pDnode == NULL) return NULL; + if (pDnode == NULL) goto DNODE_DECODE_OVER; int32_t dataPos = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &pDnode->id) - SDB_GET_INT64(pRaw, pRow, dataPos, &pDnode->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pDnode->updateTime) - SDB_GET_INT16(pRaw, pRow, dataPos, &pDnode->port) - SDB_GET_BINARY(pRaw, pRow, dataPos, pDnode->fqdn, TSDB_FQDN_LEN) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_DNODE_RESERVE_SIZE) + SDB_GET_INT32(pRaw, dataPos, &pDnode->id, DNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pDnode->createdTime, DNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pDnode->updateTime, DNODE_DECODE_OVER) + SDB_GET_INT16(pRaw, dataPos, &pDnode->port, DNODE_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, DNODE_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, DNODE_DECODE_OVER) + + terrno = 0; + +DNODE_DECODE_OVER: + if (terrno != 0) { + mError("dnode:%d, failed to decode from raw:%p since %s", pDnode->id, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + mTrace("dnode:%d, decode from raw:%p, row:%p", pDnode->id, pRaw, pDnode); return pRow; } static int32_t mndDnodeActionInsert(SSdb *pSdb, SDnodeObj *pDnode) { - mTrace("dnode:%d, perform insert action", pDnode->id); + mTrace("dnode:%d, perform insert action, row:%p", pDnode->id, pDnode); pDnode->offlineReason = DND_REASON_STATUS_NOT_RECEIVED; snprintf(pDnode->ep, TSDB_EP_LEN, "%s:%u", pDnode->fqdn, pDnode->port); return 0; } static int32_t mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode) { - mTrace("dnode:%d, perform delete action", pDnode->id); + mTrace("dnode:%d, perform delete action, row:%p", pDnode->id, pDnode); return 0; } static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOldDnode, SDnodeObj *pNewDnode) { - mTrace("dnode:%d, perform update action", pOldDnode->id); + mTrace("dnode:%d, perform update action, old_row:%p new_row:%p", pOldDnode->id, pOldDnode, pNewDnode); pOldDnode->updateTime = pNewDnode->updateTime; return 0; } @@ -329,7 +354,7 @@ static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) { } if (pStatus->dnodeId == 0) { - mDebug("dnode:%d %s, first access, set clusterId %" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId); + mDebug("dnode:%d, %s first access, set clusterId %" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId); } else { if (pStatus->clusterId != pMnode->clusterId) { if (pDnode != NULL) { @@ -532,7 +557,7 @@ static int32_t mndProcessConfigDnodeMsg(SMnodeMsg *pMsg) { .ahandle = pMsg->rpcMsg.ahandle}; mInfo("dnode:%d, app:%p config:%s req send to dnode", pCfg->dnodeId, rpcMsg.ahandle, pCfg->config); - mndSendMsgToDnode(pMnode, &epSet, &rpcMsg); + mndSendReqToDnode(pMnode, &epSet, &rpcMsg); return 0; } diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index 638d984c694957611cd7a091cdd6dc915bdd4c02..f7a39ce9e5f82fb03f4a0a09b8c9eb7063e8b874 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -58,76 +58,101 @@ int32_t mndInitFunc(SMnode *pMnode) { void mndCleanupFunc(SMnode *pMnode) {} static SSdbRaw *mndFuncActionEncode(SFuncObj *pFunc) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int32_t size = pFunc->commentSize + pFunc->codeSize + sizeof(SFuncObj); SSdbRaw *pRaw = sdbAllocRaw(SDB_FUNC, SDB_FUNC_VER, size); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto FUNC_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_BINARY(pRaw, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN) - SDB_SET_INT64(pRaw, dataPos, pFunc->createdTime) - SDB_SET_INT8(pRaw, dataPos, pFunc->funcType) - SDB_SET_INT8(pRaw, dataPos, pFunc->scriptType) - SDB_SET_INT8(pRaw, dataPos, pFunc->align) - SDB_SET_INT8(pRaw, dataPos, pFunc->outputType) - SDB_SET_INT32(pRaw, dataPos, pFunc->outputLen) - SDB_SET_INT32(pRaw, dataPos, pFunc->bufSize) - SDB_SET_INT64(pRaw, dataPos, pFunc->sigature) - SDB_SET_INT32(pRaw, dataPos, pFunc->commentSize) - SDB_SET_INT32(pRaw, dataPos, pFunc->codeSize) - SDB_SET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize) - SDB_SET_BINARY(pRaw, dataPos, pFunc->pCode, pFunc->codeSize) - SDB_SET_DATALEN(pRaw, dataPos); + SDB_SET_BINARY(pRaw, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN, FUNC_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pFunc->createdTime, FUNC_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pFunc->funcType, FUNC_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pFunc->scriptType, FUNC_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pFunc->align, FUNC_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pFunc->outputType, FUNC_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pFunc->outputLen, FUNC_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pFunc->bufSize, FUNC_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pFunc->sigature, FUNC_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pFunc->commentSize, FUNC_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pFunc->codeSize, FUNC_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize, FUNC_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pFunc->pCode, pFunc->codeSize, FUNC_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, FUNC_ENCODE_OVER); + + terrno = 0; + +FUNC_ENCODE_OVER: + if (terrno != 0) { + mError("func:%s, failed to encode to raw:%p since %s", pFunc->name, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + mTrace("func:%s, encode to raw:%p, row:%p", pFunc->name, pRaw, pFunc); return pRaw; } static SSdbRow *mndFuncActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto FUNC_DECODE_OVER; if (sver != SDB_FUNC_VER) { - mError("failed to decode func since %s", terrstr()); terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - return NULL; + goto FUNC_DECODE_OVER; } - int32_t size = sizeof(SFuncObj) + TSDB_FUNC_COMMENT_LEN + TSDB_FUNC_CODE_LEN; - SSdbRow *pRow = sdbAllocRow(size); + int32_t size = sizeof(SFuncObj) + TSDB_FUNC_COMMENT_LEN + TSDB_FUNC_CODE_LEN; + SSdbRow *pRow = sdbAllocRow(size); + if (pRow == NULL) goto FUNC_DECODE_OVER; + SFuncObj *pFunc = sdbGetRowObj(pRow); - if (pFunc == NULL) return NULL; + if (pFunc == NULL) goto FUNC_DECODE_OVER; char *tmp = (char *)pFunc + sizeof(SFuncObj); int32_t dataPos = 0; - SDB_GET_BINARY(pRaw, pRow, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN) - SDB_GET_INT64(pRaw, pRow, dataPos, &pFunc->createdTime) - SDB_GET_INT8(pRaw, pRow, dataPos, &pFunc->funcType) - SDB_GET_INT8(pRaw, pRow, dataPos, &pFunc->scriptType) - SDB_GET_INT8(pRaw, pRow, dataPos, &pFunc->align) - SDB_GET_INT8(pRaw, pRow, dataPos, &pFunc->outputType) - SDB_GET_INT32(pRaw, pRow, dataPos, &pFunc->outputLen) - SDB_GET_INT32(pRaw, pRow, dataPos, &pFunc->bufSize) - SDB_GET_INT64(pRaw, pRow, dataPos, &pFunc->sigature) - SDB_GET_INT32(pRaw, pRow, dataPos, &pFunc->commentSize) - SDB_GET_INT32(pRaw, pRow, dataPos, &pFunc->codeSize) - SDB_GET_BINARY(pRaw, pRow, dataPos, pFunc->pData, pFunc->commentSize + pFunc->codeSize) + SDB_GET_BINARY(pRaw, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN, FUNC_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pFunc->createdTime, FUNC_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pFunc->funcType, FUNC_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pFunc->scriptType, FUNC_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pFunc->align, FUNC_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pFunc->outputType, FUNC_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pFunc->outputLen, FUNC_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pFunc->bufSize, FUNC_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pFunc->sigature, FUNC_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pFunc->commentSize, FUNC_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pFunc->codeSize, FUNC_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pFunc->pData, pFunc->commentSize + pFunc->codeSize, FUNC_DECODE_OVER) pFunc->pComment = pFunc->pData; pFunc->pCode = (pFunc->pData + pFunc->commentSize); + terrno = 0; + +FUNC_DECODE_OVER: + if (terrno != 0) { + mError("func:%s, failed to decode from raw:%p since %s", pFunc->name, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + + mTrace("func:%s, decode from raw:%p, row:%p", pFunc->name, pRaw, pFunc); return pRow; } static int32_t mndFuncActionInsert(SSdb *pSdb, SFuncObj *pFunc) { - mTrace("func:%s, perform insert action", pFunc->name); + mTrace("func:%s, perform insert action, row:%p", pFunc->name, pFunc); return 0; } static int32_t mndFuncActionDelete(SSdb *pSdb, SFuncObj *pFunc) { - mTrace("func:%s, perform delete action", pFunc->name); + mTrace("func:%s, perform delete action, row:%p", pFunc->name, pFunc); return 0; } static int32_t mndFuncActionUpdate(SSdb *pSdb, SFuncObj *pOldFunc, SFuncObj *pNewFunc) { - mTrace("func:%s, perform update action", pOldFunc->name); + mTrace("func:%s, perform update action, old_row:%p new_row:%p", pOldFunc->name, pOldFunc, pNewFunc); return 0; } diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index ad3d5e1cf6811ee694bd70605e890efee9b1d223..df1848f2f1f236c4ce2e9e999d4f4d131211c727 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -117,50 +117,75 @@ static int32_t mndCreateDefaultMnode(SMnode *pMnode) { if (pRaw == NULL) return -1; sdbSetRawStatus(pRaw, SDB_STATUS_READY); - mDebug("mnode:%d, will be created while deploy sdb", mnodeObj.id); + mDebug("mnode:%d, will be created while deploy sdb, raw:%p", mnodeObj.id, pRaw); return sdbWrite(pMnode->pSdb, pRaw); } static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pObj) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_MNODE, TSDB_MNODE_VER_NUMBER, sizeof(SMnodeObj) + TSDB_MNODE_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto MNODE_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pObj->id); - SDB_SET_INT64(pRaw, dataPos, pObj->createdTime) - SDB_SET_INT64(pRaw, dataPos, pObj->updateTime) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_MNODE_RESERVE_SIZE) + SDB_SET_INT32(pRaw, dataPos, pObj->id, MNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pObj->createdTime, MNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pObj->updateTime, MNODE_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_MNODE_RESERVE_SIZE, MNODE_ENCODE_OVER) + + terrno = 0; + +MNODE_ENCODE_OVER: + if (terrno != 0) { + mError("mnode:%d, failed to encode to raw:%p since %s", pObj->id, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + mTrace("mnode:%d, encode to raw:%p, row:%p", pObj->id, pRaw, pObj); return pRaw; } static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; if (sver != TSDB_MNODE_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode mnode since %s", terrstr()); - return NULL; + goto MNODE_DECODE_OVER; } - SSdbRow *pRow = sdbAllocRow(sizeof(SMnodeObj)); + SSdbRow *pRow = sdbAllocRow(sizeof(SMnodeObj)); + if (pRow == NULL) goto MNODE_DECODE_OVER; + SMnodeObj *pObj = sdbGetRowObj(pRow); - if (pObj == NULL) return NULL; + if (pObj == NULL) goto MNODE_DECODE_OVER; int32_t dataPos = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id) - SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_MNODE_RESERVE_SIZE) + SDB_GET_INT32(pRaw, dataPos, &pObj->id, MNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pObj->createdTime, MNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pObj->updateTime, MNODE_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_MNODE_RESERVE_SIZE, MNODE_DECODE_OVER) + + terrno = 0; + +MNODE_DECODE_OVER: + if (terrno != 0) { + mError("mnode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + mTrace("mnode:%d, decode from raw:%p, row:%p", pObj->id, pRaw, pObj); return pRow; } static void mnodeResetMnode(SMnodeObj *pObj) { pObj->role = TAOS_SYNC_STATE_FOLLOWER; } static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj) { - mTrace("mnode:%d, perform insert action", pObj->id); + mTrace("mnode:%d, perform insert action, row:%p", pObj->id, pObj); pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id); if (pObj->pDnode == NULL) { terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; @@ -173,7 +198,7 @@ static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj) { } static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj) { - mTrace("mnode:%d, perform delete action", pObj->id); + mTrace("mnode:%d, perform delete action, row:%p", pObj->id, pObj); if (pObj->pDnode != NULL) { sdbRelease(pSdb, pObj->pDnode); pObj->pDnode = NULL; @@ -183,7 +208,7 @@ static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj) { } static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOldMnode, SMnodeObj *pNewMnode) { - mTrace("mnode:%d, perform update action", pOldMnode->id); + mTrace("mnode:%d, perform update action, old_row:%p new_row:%p", pOldMnode->id, pOldMnode, pNewMnode); pOldMnode->updateTime = pNewMnode->updateTime; return 0; } @@ -370,7 +395,7 @@ CREATE_MNODE_OVER: } static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + SMnode *pMnode = pMsg->pMnode; SMCreateMnodeMsg *pCreate = pMsg->rpcMsg.pCont; pCreate->dnodeId = htonl(pCreate->dnodeId); @@ -537,7 +562,7 @@ DROP_MNODE_OVER: } static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + SMnode *pMnode = pMsg->pMnode; SMDropMnodeMsg *pDrop = pMsg->rpcMsg.pCont; pDrop->dnodeId = htonl(pDrop->dnodeId); diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index 3b27764c7cae6a5bf70a5cc7aba1dba3d7a55064..a223890e8cf4fd7714a465eb3bfff6173109cb67 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -26,13 +26,13 @@ static SSdbRaw *mndQnodeActionEncode(SQnodeObj *pObj); static SSdbRow *mndQnodeActionDecode(SSdbRaw *pRaw); static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj); static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj); -static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOldQnode, SQnodeObj *pNewQnode); -static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg); -static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg); -static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pMsg); -static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pMsg); -static int32_t mndGetQnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); -static int32_t mndRetrieveQnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOld, SQnodeObj *pNew); +static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pReq); +static int32_t mndProcessDropQnodeReq(SMnodeMsg *pReq); +static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pRsp); +static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pRsp); +static int32_t mndGetQnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta); +static int32_t mndRetrieveQnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextQnode(SMnode *pMnode, void *pIter); int32_t mndInitQnode(SMnode *pMnode) { @@ -59,9 +59,8 @@ int32_t mndInitQnode(SMnode *pMnode) { void mndCleanupQnode(SMnode *pMnode) {} static SQnodeObj *mndAcquireQnode(SMnode *pMnode, int32_t qnodeId) { - SSdb *pSdb = pMnode->pSdb; - SQnodeObj *pObj = sdbAcquire(pSdb, SDB_QNODE, &qnodeId); - if (pObj == NULL) { + SQnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_QNODE, &qnodeId); + if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) { terrno = TSDB_CODE_MND_QNODE_NOT_EXIST; } return pObj; @@ -73,43 +72,68 @@ static void mndReleaseQnode(SMnode *pMnode, SQnodeObj *pObj) { } static SSdbRaw *mndQnodeActionEncode(SQnodeObj *pObj) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_QNODE, TSDB_QNODE_VER_NUMBER, sizeof(SQnodeObj) + TSDB_QNODE_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto QNODE_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pObj->id); - SDB_SET_INT64(pRaw, dataPos, pObj->createdTime) - SDB_SET_INT64(pRaw, dataPos, pObj->updateTime) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_QNODE_RESERVE_SIZE) + SDB_SET_INT32(pRaw, dataPos, pObj->id, QNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pObj->createdTime, QNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pObj->updateTime, QNODE_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_QNODE_RESERVE_SIZE, QNODE_ENCODE_OVER) + + terrno = 0; +QNODE_ENCODE_OVER: + if (terrno != 0) { + mError("qnode:%d, failed to encode to raw:%p since %s", pObj->id, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("qnode:%d, encode to raw:%p, row:%p", pObj->id, pRaw, pObj); return pRaw; } static SSdbRow *mndQnodeActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto QNODE_DECODE_OVER; if (sver != TSDB_QNODE_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode qnode since %s", terrstr()); - return NULL; + goto QNODE_DECODE_OVER; } - SSdbRow *pRow = sdbAllocRow(sizeof(SQnodeObj)); + SSdbRow *pRow = sdbAllocRow(sizeof(SQnodeObj)); + if (pRow == NULL) goto QNODE_DECODE_OVER; + SQnodeObj *pObj = sdbGetRowObj(pRow); - if (pObj == NULL) return NULL; + if (pObj == NULL) goto QNODE_DECODE_OVER; int32_t dataPos = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id) - SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_QNODE_RESERVE_SIZE) + SDB_GET_INT32(pRaw, dataPos, &pObj->id, QNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pObj->createdTime, QNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pObj->updateTime, QNODE_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_QNODE_RESERVE_SIZE, QNODE_DECODE_OVER) + terrno = 0; + +QNODE_DECODE_OVER: + if (terrno != 0) { + mError("qnode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + + mTrace("qnode:%d, decode from raw:%p, row:%p", pObj->id, pRaw, pObj); return pRow; } static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj) { - mTrace("qnode:%d, perform insert action", pObj->id); + mTrace("qnode:%d, perform insert action, row:%p", pObj->id, pObj); pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id); if (pObj->pDnode == NULL) { terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; @@ -121,7 +145,7 @@ static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj) { } static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj) { - mTrace("qnode:%d, perform delete action", pObj->id); + mTrace("qnode:%d, perform delete action, row:%p", pObj->id, pObj); if (pObj->pDnode != NULL) { sdbRelease(pSdb, pObj->pDnode); pObj->pDnode = NULL; @@ -130,9 +154,9 @@ static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj) { return 0; } -static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOldQnode, SQnodeObj *pNewQnode) { - mTrace("qnode:%d, perform update action", pOldQnode->id); - pOldQnode->updateTime = pNewQnode->updateTime; +static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOld, SQnodeObj *pNew) { + mTrace("qnode:%d, perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew); + pOld->updateTime = pNew->updateTime; return 0; } @@ -144,6 +168,14 @@ static int32_t mndSetCreateQnodeRedoLogs(STrans *pTrans, SQnodeObj *pObj) { return 0; } +static int32_t mndSetCreateQnodeUndoLogs(STrans *pTrans, SQnodeObj *pObj) { + SSdbRaw *pUndoRaw = mndQnodeActionEncode(pObj); + if (pUndoRaw == NULL) return -1; + if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1; + if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1; + return 0; +} + static int32_t mndSetCreateQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) { SSdbRaw *pCommitRaw = mndQnodeActionEncode(pObj); if (pCommitRaw == NULL) return -1; @@ -153,60 +185,69 @@ static int32_t mndSetCreateQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) { } static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) { - SDCreateQnodeMsg *pMsg = malloc(sizeof(SDCreateQnodeMsg)); - if (pMsg == NULL) { + SDCreateQnodeReq *pReq = malloc(sizeof(SDCreateQnodeReq)); + if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pMsg->dnodeId = htonl(pDnode->id); + pReq->dnodeId = htonl(pDnode->id); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); - action.pCont = pMsg; - action.contLen = sizeof(SDCreateQnodeMsg); + action.pCont = pReq; + action.contLen = sizeof(SDCreateQnodeReq); action.msgType = TDMT_DND_CREATE_QNODE; + action.acceptableCode = TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pMsg); + free(pReq); return -1; } return 0; } -static int32_t mndCreateQnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateQnodeMsg *pCreate) { - SQnodeObj qnodeObj = {0}; - qnodeObj.id = pDnode->id; - qnodeObj.createdTime = taosGetTimestampMs(); - qnodeObj.updateTime = qnodeObj.createdTime; - - int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); - if (pTrans == NULL) { - mError("qnode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); - goto CREATE_QNODE_OVER; +static int32_t mndSetCreateQnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) { + SDDropQnodeReq *pReq = malloc(sizeof(SDDropQnodeReq)); + if (pReq == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; } - mDebug("trans:%d, used to create qnode:%d", pTrans->id, pCreate->dnodeId); + pReq->dnodeId = htonl(pDnode->id); - if (mndSetCreateQnodeRedoLogs(pTrans, &qnodeObj) != 0) { - mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); - goto CREATE_QNODE_OVER; - } + STransAction action = {0}; + action.epSet = mndGetDnodeEpset(pDnode); + action.pCont = pReq; + action.contLen = sizeof(SDDropQnodeReq); + action.msgType = TDMT_DND_DROP_QNODE; + action.acceptableCode = TSDB_CODE_DND_QNODE_NOT_DEPLOYED; - if (mndSetCreateQnodeCommitLogs(pTrans, &qnodeObj) != 0) { - mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); - goto CREATE_QNODE_OVER; + if (mndTransAppendUndoAction(pTrans, &action) != 0) { + free(pReq); + return -1; } - if (mndSetCreateQnodeRedoActions(pTrans, pDnode, &qnodeObj) != 0) { - mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); - goto CREATE_QNODE_OVER; - } + return 0; +} - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - goto CREATE_QNODE_OVER; - } +static int32_t mndCreateQnode(SMnode *pMnode, SMnodeMsg *pReq, SDnodeObj *pDnode, SMCreateQnodeReq *pCreate) { + int32_t code = -1; + + SQnodeObj qnodeObj = {0}; + qnodeObj.id = pDnode->id; + qnodeObj.createdTime = taosGetTimestampMs(); + qnodeObj.updateTime = qnodeObj.createdTime; + + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg); + if (pTrans == NULL) goto CREATE_QNODE_OVER; + + mDebug("trans:%d, used to create qnode:%d", pTrans->id, pCreate->dnodeId); + if (mndSetCreateQnodeRedoLogs(pTrans, &qnodeObj) != 0) goto CREATE_QNODE_OVER; + if (mndSetCreateQnodeUndoLogs(pTrans, &qnodeObj) != 0) goto CREATE_QNODE_OVER; + if (mndSetCreateQnodeCommitLogs(pTrans, &qnodeObj) != 0) goto CREATE_QNODE_OVER; + if (mndSetCreateQnodeRedoActions(pTrans, pDnode, &qnodeObj) != 0) goto CREATE_QNODE_OVER; + if (mndSetCreateQnodeUndoActions(pTrans, pDnode, &qnodeObj) != 0) goto CREATE_QNODE_OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto CREATE_QNODE_OVER; code = 0; @@ -215,9 +256,9 @@ CREATE_QNODE_OVER: return code; } -static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SMCreateQnodeMsg *pCreate = pMsg->rpcMsg.pCont; +static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SMCreateQnodeReq *pCreate = pReq->rpcMsg.pCont; pCreate->dnodeId = htonl(pCreate->dnodeId); @@ -226,8 +267,12 @@ static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg) { SQnodeObj *pObj = mndAcquireQnode(pMnode, pCreate->dnodeId); if (pObj != NULL) { mError("qnode:%d, qnode already exist", pObj->id); + terrno = TSDB_CODE_MND_QNODE_ALREADY_EXIST; mndReleaseQnode(pMnode, pObj); return -1; + } else if (terrno != TSDB_CODE_MND_QNODE_NOT_EXIST) { + mError("qnode:%d, failed to create qnode since %s", pCreate->dnodeId, terrstr()); + return -1; } SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId); @@ -237,7 +282,7 @@ static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg) { return -1; } - int32_t code = mndCreateQnode(pMnode, pMsg, pDnode, pCreate); + int32_t code = mndCreateQnode(pMnode, pReq, pDnode, pCreate); mndReleaseDnode(pMnode, pDnode); if (code != 0) { @@ -265,56 +310,39 @@ static int32_t mndSetDropQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) { } static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) { - SDDropQnodeMsg *pMsg = malloc(sizeof(SDDropQnodeMsg)); - if (pMsg == NULL) { + SDDropQnodeReq *pReq = malloc(sizeof(SDDropQnodeReq)); + if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pMsg->dnodeId = htonl(pDnode->id); + pReq->dnodeId = htonl(pDnode->id); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); - action.pCont = pMsg; - action.contLen = sizeof(SDDropQnodeMsg); + action.pCont = pReq; + action.contLen = sizeof(SDDropQnodeReq); action.msgType = TDMT_DND_DROP_QNODE; + action.acceptableCode = TSDB_CODE_DND_QNODE_NOT_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pMsg); + free(pReq); return -1; } return 0; } -static int32_t mndDropQnode(SMnode *pMnode, SMnodeMsg *pMsg, SQnodeObj *pObj) { +static int32_t mndDropQnode(SMnode *pMnode, SMnodeMsg *pReq, SQnodeObj *pObj) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); - if (pTrans == NULL) { - mError("qnode:%d, failed to drop since %s", pObj->id, terrstr()); - goto DROP_QNODE_OVER; - } - - mDebug("trans:%d, used to drop qnode:%d", pTrans->id, pObj->id); - - if (mndSetDropQnodeRedoLogs(pTrans, pObj) != 0) { - mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); - goto DROP_QNODE_OVER; - } - if (mndSetDropQnodeCommitLogs(pTrans, pObj) != 0) { - mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); - goto DROP_QNODE_OVER; - } - - if (mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) { - mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); - goto DROP_QNODE_OVER; - } + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pReq->rpcMsg); + if (pTrans == NULL) goto DROP_QNODE_OVER; - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - goto DROP_QNODE_OVER; - } + mDebug("trans:%d, used to drop qnode:%d", pTrans->id, pObj->id); + if (mndSetDropQnodeRedoLogs(pTrans, pObj) != 0) goto DROP_QNODE_OVER; + if (mndSetDropQnodeCommitLogs(pTrans, pObj) != 0) goto DROP_QNODE_OVER; + if (mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) goto DROP_QNODE_OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto DROP_QNODE_OVER; code = 0; @@ -323,9 +351,9 @@ DROP_QNODE_OVER: return code; } -static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SMDropQnodeMsg *pDrop = pMsg->rpcMsg.pCont; +static int32_t mndProcessDropQnodeReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SMDropQnodeReq *pDrop = pReq->rpcMsg.pCont; pDrop->dnodeId = htonl(pDrop->dnodeId); mDebug("qnode:%d, start to drop", pDrop->dnodeId); @@ -338,33 +366,33 @@ static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg) { SQnodeObj *pObj = mndAcquireQnode(pMnode, pDrop->dnodeId); if (pObj == NULL) { - mError("qnode:%d, not exist", pDrop->dnodeId); - terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + mError("qnode:%d, failed to drop since %s", pDrop->dnodeId, terrstr()); return -1; } - int32_t code = mndDropQnode(pMnode, pMsg, pObj); + int32_t code = mndDropQnode(pMnode, pReq, pObj); if (code != 0) { + sdbRelease(pMnode->pSdb, pObj); mError("qnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); return -1; } - sdbRelease(pMnode->pSdb, pMnode); + sdbRelease(pMnode->pSdb, pObj); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pMsg) { - mndTransProcessRsp(pMsg); +static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pRsp) { + mndTransProcessRsp(pRsp); return 0; } -static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pMsg) { - mndTransProcessRsp(pMsg); +static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pRsp) { + mndTransProcessRsp(pRsp); return 0; } -static int32_t mndGetQnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndGetQnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) { + SMnode *pMnode = pReq->pMnode; SSdb *pSdb = pMnode->pSdb; int32_t cols = 0; @@ -403,8 +431,8 @@ static int32_t mndGetQnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * return 0; } -static int32_t mndRetrieveQnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndRetrieveQnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { + SMnode *pMnode = pReq->pMnode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; int32_t cols = 0; diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index d4b4459176330c1b8ff55ee98c89796e1f430f67..9c145f64456a911c8de1b48d945eb4518dd29ba3 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -18,12 +18,12 @@ #define SHOW_STEP_SIZE 100 -static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg); +static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowReq *pReq); static void mndFreeShowObj(SShowObj *pShow); static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId); static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove); -static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg); -static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMsg); +static int32_t mndProcessShowReq(SMnodeMsg *pReq); +static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq); static bool mndCheckRetrieveFinished(SShowObj *pShow); int32_t mndInitShow(SMnode *pMnode) { @@ -36,8 +36,8 @@ int32_t mndInitShow(SMnode *pMnode) { return -1; } - mndSetMsgHandle(pMnode, TDMT_MND_SHOW, mndProcessShowMsg); - mndSetMsgHandle(pMnode, TDMT_MND_SHOW_RETRIEVE, mndProcessRetrieveMsg); + mndSetMsgHandle(pMnode, TDMT_MND_SHOW, mndProcessShowReq); + mndSetMsgHandle(pMnode, TDMT_MND_SHOW_RETRIEVE, mndProcessRetrieveReq); return 0; } @@ -49,30 +49,30 @@ void mndCleanupShow(SMnode *pMnode) { } } -static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg) { +static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowReq *pReq) { SShowMgmt *pMgmt = &pMnode->showMgmt; int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1); if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1); - int32_t size = sizeof(SShowObj) + pMsg->payloadLen; + int32_t size = sizeof(SShowObj) + pReq->payloadLen; SShowObj showObj = {0}; showObj.id = showId; showObj.pMnode = pMnode; - showObj.type = pMsg->type; - showObj.payloadLen = pMsg->payloadLen; - memcpy(showObj.db, pMsg->db, TSDB_DB_FNAME_LEN); - memcpy(showObj.payload, pMsg->payload, pMsg->payloadLen); + showObj.type = pReq->type; + showObj.payloadLen = pReq->payloadLen; + memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN); + memcpy(showObj.payload, pReq->payload, pReq->payloadLen); int32_t keepTime = pMnode->cfg.shellActivityTimer * 6 * 1000; SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime); if (pShow == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("show:0x%"PRIx64", failed to put into cache since %s", showId, terrstr()); + mError("show:0x%" PRIx64 ", failed to put into cache since %s", showId, terrstr()); return NULL; } - mTrace("show:0x%"PRIx64", is created, data:%p", showId, pShow); + mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow); return pShow; } @@ -87,7 +87,7 @@ static void mndFreeShowObj(SShowObj *pShow) { } } - mTrace("show:0x%d, is destroyed, data:%p", pShow->id, pShow); + mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow); } static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) { @@ -95,17 +95,17 @@ static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) { SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId)); if (pShow == NULL) { - mError("show:0x%"PRIx64", already destroyed", showId); + mError("show:0x%" PRIx64 ", already destroyed", showId); return NULL; } - mTrace("show:0x%"PRIx64", acquired from cache, data:%p", pShow->id, pShow); + mTrace("show:0x%" PRIx64 ", acquired from cache, data:%p", pShow->id, pShow); return pShow; } static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) { if (pShow == NULL) return; - mTrace("show:0x%"PRIx64", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove); + mTrace("show:0x%" PRIx64 ", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove); // A bug in tcache.c forceRemove = 0; @@ -115,12 +115,12 @@ static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) { taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove); } -static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) { - SMnode *pMnode = pMnodeMsg->pMnode; +static int32_t mndProcessShowReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; SShowMgmt *pMgmt = &pMnode->showMgmt; - SShowMsg *pMsg = pMnodeMsg->rpcMsg.pCont; - int8_t type = pMsg->type; - int16_t payloadLen = htonl(pMsg->payloadLen); + SShowReq *pShowReq = pReq->rpcMsg.pCont; + int8_t type = pShowReq->type; + int16_t payloadLen = htonl(pShowReq->payloadLen); if (type <= TSDB_MGMT_TABLE_START || type >= TSDB_MGMT_TABLE_MAX) { terrno = TSDB_CODE_MND_INVALID_MSG_TYPE; @@ -135,7 +135,7 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) { return -1; } - SShowObj *pShow = mndCreateShowObj(pMnode, pMsg); + SShowObj *pShow = mndCreateShowObj(pMnode, pShowReq); if (pShow == NULL) { mError("failed to process show-meta msg:%s since %s", mndShowStr(type), terrstr()); return -1; @@ -146,18 +146,19 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) { if (pRsp == NULL) { mndReleaseShowObj(pShow, true); terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("show:0x%"PRIx64", failed to process show-meta msg:%s since malloc rsp error", pShow->id, mndShowStr(type)); + mError("show:0x%" PRIx64 ", failed to process show-meta msg:%s since malloc rsp error", pShow->id, + mndShowStr(type)); return -1; } - int32_t code = (*metaFp)(pMnodeMsg, pShow, &pRsp->tableMeta); - mDebug("show:0x%"PRIx64", get meta finished, numOfRows:%d cols:%d type:%s result:%s", pShow->id, pShow->numOfRows, + int32_t code = (*metaFp)(pReq, pShow, &pRsp->tableMeta); + mDebug("show:0x%" PRIx64 ", get meta finished, numOfRows:%d cols:%d type:%s, result:%s", pShow->id, pShow->numOfRows, pShow->numOfColumns, mndShowStr(type), tstrerror(code)); if (code == TSDB_CODE_SUCCESS) { - pMnodeMsg->contLen = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns; - pMnodeMsg->pCont = pRsp; - pRsp->showId = htobe64(pShow->id); + pReq->contLen = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns; + pReq->pCont = pRsp; + pRsp->showId = htobe64(pShow->id); mndReleaseShowObj(pShow, false); return TSDB_CODE_SUCCESS; } else { @@ -167,15 +168,15 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) { } } -static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { - SMnode *pMnode = pMnodeMsg->pMnode; +static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; SShowMgmt *pMgmt = &pMnode->showMgmt; int32_t rowsToRead = 0; int32_t size = 0; int32_t rowsRead = 0; - SRetrieveTableMsg *pRetrieve = pMnodeMsg->rpcMsg.pCont; - int64_t showId = htobe64(pRetrieve->showId); + SRetrieveTableReq *pRetrieve = pReq->rpcMsg.pCont; + int64_t showId = htobe64(pRetrieve->showId); SShowObj *pShow = mndAcquireShowObj(pMnode, showId); if (pShow == NULL) { @@ -188,15 +189,16 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { if (retrieveFp == NULL) { mndReleaseShowObj(pShow, false); terrno = TSDB_CODE_MSG_NOT_PROCESSED; - mError("show:0x%"PRIx64", failed to retrieve data since %s", pShow->id, terrstr()); + mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr()); return -1; } - mDebug("show:0x%"PRIx64", start retrieve data, numOfReads:%d numOfRows:%d type:%s", pShow->id, pShow->numOfReads, + mDebug("show:0x%" PRIx64 ", start retrieve data, numOfReads:%d numOfRows:%d type:%s", pShow->id, pShow->numOfReads, pShow->numOfRows, mndShowStr(pShow->type)); if (mndCheckRetrieveFinished(pShow)) { - mDebug("show:0x%"PRIx64", read finished, numOfReads:%d numOfRows:%d", pShow->id, pShow->numOfReads, pShow->numOfRows); + mDebug("show:0x%" PRIx64 ", read finished, numOfReads:%d numOfRows:%d", pShow->id, pShow->numOfReads, + pShow->numOfRows); pShow->numOfReads = pShow->numOfRows; } @@ -219,29 +221,29 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) { if (pRsp == NULL) { mndReleaseShowObj(pShow, false); terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("show:0x%"PRIx64", failed to retrieve data since %s", pShow->id, terrstr()); + mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr()); return -1; } // if free flag is set, client wants to clean the resources if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) { - rowsRead = (*retrieveFp)(pMnodeMsg, pShow, pRsp->data, rowsToRead); + rowsRead = (*retrieveFp)(pReq, pShow, pRsp->data, rowsToRead); } - mDebug("show:0x%"PRIx64", stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead); + mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead); pRsp->numOfRows = htonl(rowsRead); pRsp->precision = TSDB_TIME_PRECISION_MILLI; // millisecond time precision - pMnodeMsg->pCont = pRsp; - pMnodeMsg->contLen = size; + pReq->pCont = pRsp; + pReq->contLen = size; if (rowsRead == 0 || rowsToRead == 0 || (rowsRead == rowsToRead && pShow->numOfRows == pShow->numOfReads)) { pRsp->completed = 1; - mDebug("show:0x%"PRIx64", retrieve completed", pShow->id); + mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); mndReleaseShowObj(pShow, true); } else { - mDebug("show:0x%"PRIx64", retrieve not completed yet", pShow->id); + mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id); mndReleaseShowObj(pShow, false); } diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index a4825c0e82d98cf47544f1795991f32294689b7b..1b66bedbccb0d6fae41c2facfe4ae3a622571a38 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -26,13 +26,13 @@ static SSdbRaw *mndSnodeActionEncode(SSnodeObj *pObj); static SSdbRow *mndSnodeActionDecode(SSdbRaw *pRaw); static int32_t mndSnodeActionInsert(SSdb *pSdb, SSnodeObj *pObj); static int32_t mndSnodeActionDelete(SSdb *pSdb, SSnodeObj *pObj); -static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOldSnode, SSnodeObj *pNewSnode); -static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg); -static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg); -static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pMsg); -static int32_t mndProcessDropSnodeRsp(SMnodeMsg *pMsg); -static int32_t mndGetSnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); -static int32_t mndRetrieveSnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOld, SSnodeObj *pNew); +static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pReq); +static int32_t mndProcessDropSnodeReq(SMnodeMsg *pReq); +static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pRsp); +static int32_t mndProcessDropSnodeRsp(SMnodeMsg *pRsp); +static int32_t mndGetSnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta); +static int32_t mndRetrieveSnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextSnode(SMnode *pMnode, void *pIter); int32_t mndInitSnode(SMnode *pMnode) { @@ -59,9 +59,8 @@ int32_t mndInitSnode(SMnode *pMnode) { void mndCleanupSnode(SMnode *pMnode) {} static SSnodeObj *mndAcquireSnode(SMnode *pMnode, int32_t snodeId) { - SSdb *pSdb = pMnode->pSdb; - SSnodeObj *pObj = sdbAcquire(pSdb, SDB_SNODE, &snodeId); - if (pObj == NULL) { + SSnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_SNODE, &snodeId); + if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) { terrno = TSDB_CODE_MND_SNODE_NOT_EXIST; } return pObj; @@ -73,43 +72,68 @@ static void mndReleaseSnode(SMnode *pMnode, SSnodeObj *pObj) { } static SSdbRaw *mndSnodeActionEncode(SSnodeObj *pObj) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_SNODE, TSDB_SNODE_VER_NUMBER, sizeof(SSnodeObj) + TSDB_SNODE_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto SNODE_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pObj->id); - SDB_SET_INT64(pRaw, dataPos, pObj->createdTime) - SDB_SET_INT64(pRaw, dataPos, pObj->updateTime) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_SNODE_RESERVE_SIZE) + SDB_SET_INT32(pRaw, dataPos, pObj->id, SNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pObj->createdTime, SNODE_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pObj->updateTime, SNODE_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_SNODE_RESERVE_SIZE, SNODE_ENCODE_OVER) + + terrno = 0; + +SNODE_ENCODE_OVER: + if (terrno != 0) { + mError("snode:%d, failed to encode to raw:%p since %s", pObj->id, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + mTrace("snode:%d, encode to raw:%p, row:%p", pObj->id, pRaw, pObj); return pRaw; } static SSdbRow *mndSnodeActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto SNODE_DECODE_OVER; if (sver != TSDB_SNODE_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode snode since %s", terrstr()); - return NULL; + goto SNODE_DECODE_OVER; } - SSdbRow *pRow = sdbAllocRow(sizeof(SSnodeObj)); + SSdbRow *pRow = sdbAllocRow(sizeof(SSnodeObj)); + if (pRow == NULL) goto SNODE_DECODE_OVER; + SSnodeObj *pObj = sdbGetRowObj(pRow); - if (pObj == NULL) return NULL; + if (pObj == NULL) goto SNODE_DECODE_OVER; int32_t dataPos = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id) - SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_SNODE_RESERVE_SIZE) + SDB_GET_INT32(pRaw, dataPos, &pObj->id, SNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pObj->createdTime, SNODE_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pObj->updateTime, SNODE_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_SNODE_RESERVE_SIZE, SNODE_DECODE_OVER) + + terrno = 0; + +SNODE_DECODE_OVER: + if (terrno != 0) { + mError("snode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + mTrace("snode:%d, decode from raw:%p, row:%p", pObj->id, pRaw, pObj); return pRow; } static int32_t mndSnodeActionInsert(SSdb *pSdb, SSnodeObj *pObj) { - mTrace("snode:%d, perform insert action", pObj->id); + mTrace("snode:%d, perform insert action, row:%p", pObj->id, pObj); pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id); if (pObj->pDnode == NULL) { terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; @@ -121,7 +145,7 @@ static int32_t mndSnodeActionInsert(SSdb *pSdb, SSnodeObj *pObj) { } static int32_t mndSnodeActionDelete(SSdb *pSdb, SSnodeObj *pObj) { - mTrace("snode:%d, perform delete action", pObj->id); + mTrace("snode:%d, perform delete action, row:%p", pObj->id, pObj); if (pObj->pDnode != NULL) { sdbRelease(pSdb, pObj->pDnode); pObj->pDnode = NULL; @@ -130,9 +154,9 @@ static int32_t mndSnodeActionDelete(SSdb *pSdb, SSnodeObj *pObj) { return 0; } -static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOldSnode, SSnodeObj *pNewSnode) { - mTrace("snode:%d, perform update action", pOldSnode->id); - pOldSnode->updateTime = pNewSnode->updateTime; +static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOld, SSnodeObj *pNew) { + mTrace("snode:%d, perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew); + pOld->updateTime = pNew->updateTime; return 0; } @@ -144,6 +168,14 @@ static int32_t mndSetCreateSnodeRedoLogs(STrans *pTrans, SSnodeObj *pObj) { return 0; } +static int32_t mndSetCreateSnodeUndoLogs(STrans *pTrans, SSnodeObj *pObj) { + SSdbRaw *pUndoRaw = mndSnodeActionEncode(pObj); + if (pUndoRaw == NULL) return -1; + if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1; + if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1; + return 0; +} + static int32_t mndSetCreateSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) { SSdbRaw *pCommitRaw = mndSnodeActionEncode(pObj); if (pCommitRaw == NULL) return -1; @@ -153,60 +185,70 @@ static int32_t mndSetCreateSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) { } static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) { - SDCreateSnodeMsg *pMsg = malloc(sizeof(SDCreateSnodeMsg)); - if (pMsg == NULL) { + SDCreateSnodeReq *pReq = malloc(sizeof(SDCreateSnodeReq)); + if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pMsg->dnodeId = htonl(pDnode->id); + pReq->dnodeId = htonl(pDnode->id); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); - action.pCont = pMsg; - action.contLen = sizeof(SDCreateSnodeMsg); + action.pCont = pReq; + action.contLen = sizeof(SDCreateSnodeReq); action.msgType = TDMT_DND_CREATE_SNODE; + action.acceptableCode = TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pMsg); + free(pReq); + return -1; + } + + return 0; +} + +static int32_t mndSetCreateSnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) { + SDDropSnodeReq *pReq = malloc(sizeof(SDDropSnodeReq)); + if (pReq == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + pReq->dnodeId = htonl(pDnode->id); + + STransAction action = {0}; + action.epSet = mndGetDnodeEpset(pDnode); + action.pCont = pReq; + action.contLen = sizeof(SDDropSnodeReq); + action.msgType = TDMT_DND_DROP_SNODE; + action.acceptableCode = TSDB_CODE_DND_SNODE_NOT_DEPLOYED; + + if (mndTransAppendUndoAction(pTrans, &action) != 0) { + free(pReq); return -1; } return 0; } -static int32_t mndCreateSnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateSnodeMsg *pCreate) { +static int32_t mndCreateSnode(SMnode *pMnode, SMnodeMsg *pReq, SDnodeObj *pDnode, SMCreateSnodeReq *pCreate) { + int32_t code = -1; + SSnodeObj snodeObj = {0}; snodeObj.id = pDnode->id; snodeObj.createdTime = taosGetTimestampMs(); snodeObj.updateTime = snodeObj.createdTime; - int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); - if (pTrans == NULL) { - mError("snode:%d, failed to create since %s", pCreate->dnodeId, terrstr()); - goto CREATE_SNODE_OVER; - } - mDebug("trans:%d, used to create snode:%d", pTrans->id, pCreate->dnodeId); - - if (mndSetCreateSnodeRedoLogs(pTrans, &snodeObj) != 0) { - mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); - goto CREATE_SNODE_OVER; - } + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg); + if (pTrans == NULL) goto CREATE_SNODE_OVER; - if (mndSetCreateSnodeCommitLogs(pTrans, &snodeObj) != 0) { - mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); - goto CREATE_SNODE_OVER; - } - - if (mndSetCreateSnodeRedoActions(pTrans, pDnode, &snodeObj) != 0) { - mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); - goto CREATE_SNODE_OVER; - } + mDebug("trans:%d, used to create snode:%d", pTrans->id, pCreate->dnodeId); - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - goto CREATE_SNODE_OVER; - } + if (mndSetCreateSnodeRedoLogs(pTrans, &snodeObj) != 0) goto CREATE_SNODE_OVER; + if (mndSetCreateSnodeUndoLogs(pTrans, &snodeObj) != 0) goto CREATE_SNODE_OVER; + if (mndSetCreateSnodeCommitLogs(pTrans, &snodeObj) != 0) goto CREATE_SNODE_OVER; + if (mndSetCreateSnodeRedoActions(pTrans, pDnode, &snodeObj) != 0) goto CREATE_SNODE_OVER; + if (mndSetCreateSnodeUndoActions(pTrans, pDnode, &snodeObj) != 0) goto CREATE_SNODE_OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto CREATE_SNODE_OVER; code = 0; @@ -215,9 +257,9 @@ CREATE_SNODE_OVER: return code; } -static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SMCreateSnodeMsg *pCreate = pMsg->rpcMsg.pCont; +static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SMCreateSnodeReq *pCreate = pReq->rpcMsg.pCont; pCreate->dnodeId = htonl(pCreate->dnodeId); @@ -226,8 +268,12 @@ static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg) { SSnodeObj *pObj = mndAcquireSnode(pMnode, pCreate->dnodeId); if (pObj != NULL) { mError("snode:%d, snode already exist", pObj->id); + terrno = TSDB_CODE_MND_SNODE_ALREADY_EXIST; mndReleaseSnode(pMnode, pObj); return -1; + } else if (terrno != TSDB_CODE_MND_SNODE_NOT_EXIST) { + mError("snode:%d, failed to create snode since %s", pCreate->dnodeId, terrstr()); + return -1; } SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId); @@ -237,7 +283,7 @@ static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg) { return -1; } - int32_t code = mndCreateSnode(pMnode, pMsg, pDnode, pCreate); + int32_t code = mndCreateSnode(pMnode, pReq, pDnode, pCreate); mndReleaseDnode(pMnode, pDnode); if (code != 0) { @@ -265,56 +311,40 @@ static int32_t mndSetDropSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) { } static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) { - SDDropSnodeMsg *pMsg = malloc(sizeof(SDDropSnodeMsg)); - if (pMsg == NULL) { + SDDropSnodeReq *pReq = malloc(sizeof(SDDropSnodeReq)); + if (pReq == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pMsg->dnodeId = htonl(pDnode->id); + pReq->dnodeId = htonl(pDnode->id); STransAction action = {0}; action.epSet = mndGetDnodeEpset(pDnode); - action.pCont = pMsg; - action.contLen = sizeof(SDDropSnodeMsg); + action.pCont = pReq; + action.contLen = sizeof(SDDropSnodeReq); action.msgType = TDMT_DND_DROP_SNODE; + action.acceptableCode = TSDB_CODE_DND_SNODE_NOT_DEPLOYED; if (mndTransAppendRedoAction(pTrans, &action) != 0) { - free(pMsg); + free(pReq); return -1; } return 0; } -static int32_t mndDropSnode(SMnode *pMnode, SMnodeMsg *pMsg, SSnodeObj *pObj) { +static int32_t mndDropSnode(SMnode *pMnode, SMnodeMsg *pReq, SSnodeObj *pObj) { int32_t code = -1; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg); - if (pTrans == NULL) { - mError("snode:%d, failed to drop since %s", pObj->id, terrstr()); - goto DROP_SNODE_OVER; - } - - mDebug("trans:%d, used to drop snode:%d", pTrans->id, pObj->id); - - if (mndSetDropSnodeRedoLogs(pTrans, pObj) != 0) { - mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); - goto DROP_SNODE_OVER; - } - if (mndSetDropSnodeCommitLogs(pTrans, pObj) != 0) { - mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); - goto DROP_SNODE_OVER; - } + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pReq->rpcMsg); + if (pTrans == NULL) goto DROP_SNODE_OVER; - if (mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) { - mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); - goto DROP_SNODE_OVER; - } + mDebug("trans:%d, used to drop snode:%d", pTrans->id, pObj->id); - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - goto DROP_SNODE_OVER; - } + if (mndSetDropSnodeRedoLogs(pTrans, pObj) != 0) goto DROP_SNODE_OVER; + if (mndSetDropSnodeCommitLogs(pTrans, pObj) != 0) goto DROP_SNODE_OVER; + if (mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) goto DROP_SNODE_OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto DROP_SNODE_OVER; code = 0; @@ -323,9 +353,9 @@ DROP_SNODE_OVER: return code; } -static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SMDropSnodeMsg *pDrop = pMsg->rpcMsg.pCont; +static int32_t mndProcessDropSnodeReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SMDropSnodeReq *pDrop = pReq->rpcMsg.pCont; pDrop->dnodeId = htonl(pDrop->dnodeId); mDebug("snode:%d, start to drop", pDrop->dnodeId); @@ -338,33 +368,33 @@ static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg) { SSnodeObj *pObj = mndAcquireSnode(pMnode, pDrop->dnodeId); if (pObj == NULL) { - mError("snode:%d, not exist", pDrop->dnodeId); - terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; + mError("snode:%d, failed to drop since %s", pDrop->dnodeId, terrstr()); return -1; } - int32_t code = mndDropSnode(pMnode, pMsg, pObj); + int32_t code = mndDropSnode(pMnode, pReq, pObj); if (code != 0) { + sdbRelease(pMnode->pSdb, pObj); mError("snode:%d, failed to drop since %s", pMnode->dnodeId, terrstr()); return -1; } - sdbRelease(pMnode->pSdb, pMnode); + sdbRelease(pMnode->pSdb, pObj); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pMsg) { - mndTransProcessRsp(pMsg); +static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pRsp) { + mndTransProcessRsp(pRsp); return 0; } -static int32_t mndProcessDropSnodeRsp(SMnodeMsg *pMsg) { - mndTransProcessRsp(pMsg); +static int32_t mndProcessDropSnodeRsp(SMnodeMsg *pRsp) { + mndTransProcessRsp(pRsp); return 0; } -static int32_t mndGetSnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndGetSnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) { + SMnode *pMnode = pReq->pMnode; SSdb *pSdb = pMnode->pSdb; int32_t cols = 0; @@ -403,8 +433,8 @@ static int32_t mndGetSnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * return 0; } -static int32_t mndRetrieveSnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndRetrieveSnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { + SMnode *pMnode = pReq->pMnode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; int32_t cols = 0; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index f81a19a78070cbbce0b7e40dfb209f30f9d65e78..2609faa41a5999cc2114212b7ba9667e2e6db49c 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -70,90 +70,115 @@ int32_t mndInitStb(SMnode *pMnode) { void mndCleanupStb(SMnode *pMnode) {} static SSdbRaw *mndStbActionEncode(SStbObj *pStb) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int32_t size = sizeof(SStbObj) + (pStb->numOfColumns + pStb->numOfTags) * sizeof(SSchema) + TSDB_STB_RESERVE_SIZE; SSdbRaw *pRaw = sdbAllocRaw(SDB_STB, TSDB_STB_VER_NUMBER, size); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto STB_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_BINARY(pRaw, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN) - SDB_SET_BINARY(pRaw, dataPos, pStb->db, TSDB_DB_FNAME_LEN) - SDB_SET_INT64(pRaw, dataPos, pStb->createdTime) - SDB_SET_INT64(pRaw, dataPos, pStb->updateTime) - SDB_SET_INT64(pRaw, dataPos, pStb->uid) - SDB_SET_INT64(pRaw, dataPos, pStb->dbUid) - SDB_SET_INT32(pRaw, dataPos, pStb->version) - SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns) - SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags) + SDB_SET_BINARY(pRaw, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN, STB_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pStb->db, TSDB_DB_FNAME_LEN, STB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pStb->createdTime, STB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pStb->updateTime, STB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pStb->uid, STB_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pStb->dbUid, STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pStb->version, STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags, STB_ENCODE_OVER) int32_t totalCols = pStb->numOfColumns + pStb->numOfTags; for (int32_t i = 0; i < totalCols; ++i) { SSchema *pSchema = &pStb->pSchema[i]; - SDB_SET_INT8(pRaw, dataPos, pSchema->type); - SDB_SET_INT32(pRaw, dataPos, pSchema->colId); - SDB_SET_INT32(pRaw, dataPos, pSchema->bytes); - SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN); + SDB_SET_INT8(pRaw, dataPos, pSchema->type, STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pSchema->colId, STB_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pSchema->bytes, STB_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_ENCODE_OVER) } - SDB_SET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE) - SDB_SET_DATALEN(pRaw, dataPos); + SDB_SET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE, STB_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, STB_ENCODE_OVER) + + terrno = 0; +STB_ENCODE_OVER: + if (terrno != 0) { + mError("stb:%s, failed to encode to raw:%p since %s", pStb->name, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("stb:%s, encode to raw:%p, row:%p", pStb->name, pRaw, pStb); return pRaw; } static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto STB_DECODE_OVER; if (sver != TSDB_STB_VER_NUMBER) { - mError("failed to decode stable since %s", terrstr()); terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - return NULL; + goto STB_DECODE_OVER; } int32_t size = sizeof(SStbObj) + TSDB_MAX_COLUMNS * sizeof(SSchema); SSdbRow *pRow = sdbAllocRow(size); + if (pRow == NULL) goto STB_DECODE_OVER; + SStbObj *pStb = sdbGetRowObj(pRow); - if (pStb == NULL) return NULL; + if (pStb == NULL) goto STB_DECODE_OVER; int32_t dataPos = 0; - SDB_GET_BINARY(pRaw, pRow, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN) - SDB_GET_BINARY(pRaw, pRow, dataPos, pStb->db, TSDB_DB_FNAME_LEN) - SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->updateTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->uid) - SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->dbUid) - SDB_GET_INT32(pRaw, pRow, dataPos, &pStb->version) - SDB_GET_INT32(pRaw, pRow, dataPos, &pStb->numOfColumns) - SDB_GET_INT32(pRaw, pRow, dataPos, &pStb->numOfTags) + SDB_GET_BINARY(pRaw, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN, STB_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pStb->db, TSDB_DB_FNAME_LEN, STB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pStb->createdTime, STB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pStb->updateTime, STB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pStb->uid, STB_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pStb->dbUid, STB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pStb->version, STB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, STB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pStb->numOfTags, STB_DECODE_OVER) int32_t totalCols = pStb->numOfColumns + pStb->numOfTags; pStb->pSchema = calloc(totalCols, sizeof(SSchema)); for (int32_t i = 0; i < totalCols; ++i) { SSchema *pSchema = &pStb->pSchema[i]; - SDB_GET_INT8(pRaw, pRow, dataPos, &pSchema->type); - SDB_GET_INT32(pRaw, pRow, dataPos, &pSchema->colId); - SDB_GET_INT32(pRaw, pRow, dataPos, &pSchema->bytes); - SDB_GET_BINARY(pRaw, pRow, dataPos, pSchema->name, TSDB_COL_NAME_LEN); + SDB_GET_INT8(pRaw, dataPos, &pSchema->type, STB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pSchema->colId, STB_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pSchema->bytes, STB_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_DECODE_OVER) } - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_STB_RESERVE_SIZE) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE, STB_DECODE_OVER) + + terrno = 0; + +STB_DECODE_OVER: + if (terrno != 0) { + mError("stb:%s, failed to decode from raw:%p since %s", pStb->name, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + mTrace("stb:%s, decode from raw:%p, row:%p", pStb->name, pRaw, pStb); return pRow; } static int32_t mndStbActionInsert(SSdb *pSdb, SStbObj *pStb) { - mTrace("stb:%s, perform insert action", pStb->name); + mTrace("stb:%s, perform insert action, row:%p", pStb->name, pStb); return 0; } static int32_t mndStbActionDelete(SSdb *pSdb, SStbObj *pStb) { - mTrace("stb:%s, perform delete action", pStb->name); + mTrace("stb:%s, perform delete action, row:%p", pStb->name, pStb); return 0; } static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOldStb, SStbObj *pNewStb) { - mTrace("stb:%s, perform update action", pOldStb->name); + mTrace("stb:%s, perform update action, old_row:%p new_row:%p", pOldStb->name, pOldStb, pNewStb); atomic_exchange_32(&pOldStb->updateTime, pNewStb->updateTime); atomic_exchange_32(&pOldStb->version, pNewStb->version); @@ -177,7 +202,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOldStb, SStbObj *pNewStb } SStbObj *mndAcquireStb(SMnode *pMnode, char *stbName) { - SSdb * pSdb = pMnode->pSdb; + SSdb *pSdb = pMnode->pSdb; SStbObj *pStb = sdbAcquire(pSdb, SDB_STB, stbName); if (pStb == NULL) { terrno = TSDB_CODE_MND_STB_NOT_EXIST; @@ -202,9 +227,9 @@ static SDbObj *mndAcquireDbByStb(SMnode *pMnode, char *stbName) { static void *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int *pContLen) { SVCreateTbReq req; - void * buf; + void *buf; int bsize; - SMsgHead * pMsgHead; + SMsgHead *pMsgHead; req.ver = 0; SName name = {0}; @@ -328,9 +353,9 @@ static int32_t mndSetCreateStbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj } static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { - SSdb * pSdb = pMnode->pSdb; + SSdb *pSdb = pMnode->pSdb; SVgObj *pVgroup = NULL; - void * pIter = NULL; + void *pIter = NULL; int contLen; while (1) { @@ -364,9 +389,9 @@ static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj } static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) { - SSdb * pSdb = pMnode->pSdb; + SSdb *pSdb = pMnode->pSdb; SVgObj *pVgroup = NULL; - void * pIter = NULL; + void *pIter = NULL; while (1) { pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); @@ -470,7 +495,7 @@ CREATE_STB_OVER: } static int32_t mndProcessCreateStbMsg(SMnodeMsg *pMsg) { - SMnode * pMnode = pMsg->pMnode; + SMnode *pMnode = pMsg->pMnode; SCreateStbMsg *pCreate = pMsg->rpcMsg.pCont; mDebug("stb:%s, start to create", pCreate->name); @@ -554,7 +579,7 @@ static int32_t mndCheckAlterStbMsg(SAlterStbMsg *pAlter) { static int32_t mndUpdateStb(SMnode *pMnode, SMnodeMsg *pMsg, SStbObj *pOldStb, SStbObj *pNewStb) { return 0; } static int32_t mndProcessAlterStbMsg(SMnodeMsg *pMsg) { - SMnode * pMnode = pMsg->pMnode; + SMnode *pMnode = pMsg->pMnode; SAlterStbMsg *pAlter = pMsg->rpcMsg.pCont; mDebug("stb:%s, start to alter", pAlter->name); @@ -668,7 +693,7 @@ DROP_STB_OVER: } static int32_t mndProcessDropStbMsg(SMnodeMsg *pMsg) { - SMnode * pMnode = pMsg->pMnode; + SMnode *pMnode = pMsg->pMnode; SDropStbMsg *pDrop = pMsg->rpcMsg.pCont; mDebug("stb:%s, start to drop", pDrop->name); @@ -703,7 +728,7 @@ static int32_t mndProcessDropStbInRsp(SMnodeMsg *pMsg) { } static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) { - SMnode * pMnode = pMsg->pMnode; + SMnode *pMnode = pMsg->pMnode; STableInfoMsg *pInfo = pMsg->rpcMsg.pCont; mDebug("stb:%s, start to retrieve meta", pInfo->tableFname); @@ -775,7 +800,7 @@ static int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs } int32_t numOfStbs = 0; - void * pIter = NULL; + void *pIter = NULL; while (1) { SStbObj *pStb = NULL; pIter = sdbFetch(pSdb, SDB_STB, pIter, (void **)&pStb); @@ -794,7 +819,7 @@ static int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs static int32_t mndGetStbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { SMnode *pMnode = pMsg->pMnode; - SSdb * pSdb = pMnode->pSdb; + SSdb *pSdb = pMnode->pSdb; if (mndGetNumOfStbs(pMnode, pShow->db, &pShow->numOfRows) != 0) { return -1; diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 6a2fca836f1c3446aad94d96aa267c56df46e459..bf1697fb19016803096f87aae367240f167f6eb2 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -15,11 +15,112 @@ #define _DEFAULT_SOURCE #include "mndSync.h" +#include "mndTrans.h" + +static int32_t mndInitWal(SMnode *pMnode) { + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + + char path[PATH_MAX] = {0}; + snprintf(path, sizeof(path), "%s%swal", pMnode->path, TD_DIRSEP); + SWalCfg cfg = {.vgId = 1, + .fsyncPeriod = 0, + .rollPeriod = -1, + .segSize = -1, + .retentionPeriod = -1, + .retentionSize = -1, + .level = TAOS_WAL_FSYNC}; + pMgmt->pWal = walOpen(path, &cfg); + if (pMgmt->pWal == NULL) return -1; + + return 0; +} + +static void mndCloseWal(SMnode *pMnode) { + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + if (pMgmt->pWal != NULL) { + walClose(pMgmt->pWal); + pMgmt->pWal = NULL; + } +} + +static int32_t mndRestoreWal(SMnode *pMnode) { + SWal *pWal = pMnode->syncMgmt.pWal; + SSdb *pSdb = pMnode->pSdb; + int64_t lastSdbVer = sdbUpdateVer(pSdb, 0); + int32_t code = -1; + + SWalReadHandle *pHandle = walOpenReadHandle(pWal); + if (pHandle == NULL) return -1; + + int64_t first = walGetFirstVer(pWal); + int64_t last = walGetLastVer(pWal); + mDebug("restore sdb wal start, sdb ver:%" PRId64 ", wal first:%" PRId64 " last:%" PRId64, lastSdbVer, first, last); + + first = MAX(lastSdbVer + 1, first); + for (int64_t ver = first; ver >= 0 && ver <= last; ++ver) { + if (walReadWithHandle(pHandle, ver) < 0) { + mError("failed to read by wal handle since %s, ver:%" PRId64, terrstr(), ver); + goto WAL_RESTORE_OVER; + } + + SWalHead *pHead = pHandle->pHead; + int64_t sdbVer = sdbUpdateVer(pSdb, 0); + if (sdbVer + 1 != ver) { + terrno = TSDB_CODE_SDB_INVALID_WAl_VER; + mError("failed to read wal from sdb, sdbVer:%" PRId64 " inconsistent with ver:%" PRId64, sdbVer, ver); + goto WAL_RESTORE_OVER; + } + + if (sdbWriteNotFree(pSdb, (void *)pHead->head.body) < 0) { + mError("failed to read wal from sdb since %s, ver:%" PRId64, terrstr(), ver); + goto WAL_RESTORE_OVER; + } + + sdbUpdateVer(pSdb, 1); + mDebug("wal:%" PRId64 ", is restored", ver); + } + + int64_t sdbVer = sdbUpdateVer(pSdb, 0); + mDebug("restore sdb wal finished, sdb ver:%" PRId64, sdbVer); + + mndTransPullup(pMnode); + + if (walBeginSnapshot(pWal, sdbVer) < 0) { + goto WAL_RESTORE_OVER; + } + + if (sdbVer != lastSdbVer) { + mInfo("sdb restored from %" PRId64 " to %" PRId64 ", write file", lastSdbVer, sdbVer); + if (sdbWriteFile(pSdb) != 0) { + goto WAL_RESTORE_OVER; + } + } + + if (walEndSnapshot(pWal) < 0) { + goto WAL_RESTORE_OVER; + } + + code = 0; + +WAL_RESTORE_OVER: + walCloseReadHandle(pHandle); + return code; +} int32_t mndInitSync(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; tsem_init(&pMgmt->syncSem, 0, 0); + if (mndInitWal(pMnode) < 0) { + mError("failed to open wal since %s", terrstr()); + return -1; + } + + if (mndRestoreWal(pMnode) < 0) { + mError("failed to restore wal since %s", terrstr()); + return -1; + } + pMgmt->state = TAOS_SYNC_STATE_LEADER; pMgmt->pSyncNode = NULL; return 0; @@ -28,6 +129,7 @@ int32_t mndInitSync(SMnode *pMnode) { void mndCleanupSync(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; tsem_destroy(&pMgmt->syncSem); + mndCloseWal(pMnode); } static int32_t mndSyncApplyCb(struct SSyncFSM *fsm, SyncIndex index, const SSyncBuffer *buf, void *pData) { @@ -41,6 +143,20 @@ static int32_t mndSyncApplyCb(struct SSyncFSM *fsm, SyncIndex index, const SSync } int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw) { + SWal *pWal = pMnode->syncMgmt.pWal; + SSdb *pSdb = pMnode->pSdb; + + int64_t ver = sdbUpdateVer(pSdb, 1); + if (walWrite(pWal, ver, 1, pRaw, sdbGetRawTotalSize(pRaw)) < 0) { + sdbUpdateVer(pSdb, -1); + mError("failed to write raw:%p since %s, ver:%" PRId64, pRaw, terrstr(), ver); + return -1; + } + + mTrace("raw:%p, write to wal, ver:%" PRId64, pRaw, ver); + walCommit(pWal, ver); + walFsync(pWal, true); + #if 1 return 0; #else diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 4f6567a50a2baac23af08e9b655356adbe32dc2b..83870aebb76c5e4a04a018a76b637df0c1baceef 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -57,11 +57,10 @@ int32_t mndInitTopic(SMnode *pMnode) { void mndCleanupTopic(SMnode *pMnode) {} -SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) { - int32_t len; - int32_t size = sizeof(SMqTopicObj) + MND_TOPIC_RESERVE_SIZE; +static SSdbRaw *mndTopicActionEncode(STopicObj *pTopic) { + int32_t size = sizeof(STopicObj) + MND_TOPIC_RESERVE_SIZE; SSdbRaw *pRaw = sdbAllocRaw(SDB_TOPIC, MND_TOPIC_VER_NUMBER, size); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto TOPIC_ENCODE_OVER; int32_t dataPos = 0; SDB_SET_BINARY(pRaw, dataPos, pTopic->name, TSDB_TABLE_FNAME_LEN); @@ -71,15 +70,10 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) { SDB_SET_INT64(pRaw, dataPos, pTopic->uid); SDB_SET_INT64(pRaw, dataPos, pTopic->dbUid); SDB_SET_INT32(pRaw, dataPos, pTopic->version); + SDB_SET_INT32(pRaw, dataPos, pTopic->execLen); + SDB_SET_BINARY(pRaw, dataPos, pTopic->executor, pTopic->execLen); SDB_SET_INT32(pRaw, dataPos, pTopic->sqlLen); SDB_SET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen); - SDB_SET_INT32(pRaw, dataPos, pTopic->sqlLen); - len = strlen(pTopic->logicalPlan); - SDB_SET_INT32(pRaw, dataPos, len); - SDB_SET_BINARY(pRaw, dataPos, pTopic->logicalPlan, len); - len = strlen(pTopic->physicalPlan); - SDB_SET_INT32(pRaw, dataPos, len); - SDB_SET_BINARY(pRaw, dataPos, pTopic->physicalPlan, len); SDB_SET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE); SDB_SET_DATALEN(pRaw, dataPos); @@ -88,38 +82,50 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) { } SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto TOPIC_DECODE_OVER; if (sver != MND_TOPIC_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to decode topic since %s", terrstr()); - return NULL; + goto TOPIC_DECODE_OVER; } - int32_t size = sizeof(SMqTopicObj) + TSDB_MAX_COLUMNS * sizeof(SSchema); + int32_t size = sizeof(SMqTopicObj); SSdbRow *pRow = sdbAllocRow(size); + if (pRow == NULL) goto TOPIC_DECODE_OVER; + SMqTopicObj *pTopic = sdbGetRowObj(pRow); - if (pTopic == NULL) return NULL; + if (pTopic == NULL) goto TOPIC_DECODE_OVER; int32_t len; int32_t dataPos = 0; - SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->name, TSDB_TABLE_FNAME_LEN); - SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->db, TSDB_DB_FNAME_LEN); - SDB_GET_INT64(pRaw, pRow, dataPos, &pTopic->createTime); - SDB_GET_INT64(pRaw, pRow, dataPos, &pTopic->updateTime); - SDB_GET_INT64(pRaw, pRow, dataPos, &pTopic->uid); - SDB_GET_INT64(pRaw, pRow, dataPos, &pTopic->dbUid); - SDB_GET_INT32(pRaw, pRow, dataPos, &pTopic->version); - SDB_GET_INT32(pRaw, pRow, dataPos, &pTopic->sqlLen); - SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->sql, pTopic->sqlLen); - SDB_GET_INT32(pRaw, pRow, dataPos, &len); - SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->logicalPlan, len); - SDB_GET_INT32(pRaw, pRow, dataPos, &len); - SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->physicalPlan, len); - - SDB_GET_RESERVE(pRaw, pRow, dataPos, MND_TOPIC_RESERVE_SIZE); + SDB_GET_BINARY(pRaw, dataPos, pTopic->name, TSDB_TABLE_FNAME_LEN, TOPIC_DECODE_OVER); + SDB_GET_BINARY(pRaw, dataPos, pTopic->db, TSDB_DB_FNAME_LEN, TOPIC_DECODE_OVER); + SDB_GET_INT64(pRaw, dataPos, &pTopic->createTime, TOPIC_DECODE_OVER); + SDB_GET_INT64(pRaw, dataPos, &pTopic->updateTime, TOPIC_DECODE_OVER); + 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); + SDB_GET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen, TOPIC_DECODE_OVER); + SDB_GET_INT32(pRaw, dataPos, &len); + SDB_GET_BINARY(pRaw, dataPos, pTopic->logicalPlan, len, TOPIC_DECODE_OVER); + SDB_GET_INT32(pRaw, dataPos, &len); + SDB_GET_BINARY(pRaw, dataPos, pTopic->physicalPlan, len, TOPIC_DECODE_OVER); + + SDB_GET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE, TOPIC_DECODE_OVER) + + terrno = 0; + +TOPIC_DECODE_OVER: + if (terrno != 0) { + mError("topic:%s, failed to decode from raw:%p since %s", pTopic->name, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + mTrace("topic:%s, decode from raw:%p, row:%p", pTopic->name, pRaw, pTopic); return pRow; } @@ -368,7 +374,7 @@ static int32_t mndGetNumOfTopics(SMnode *pMnode, char *dbName, int32_t *pNumOfTo int32_t numOfTopics = 0; void *pIter = NULL; while (1) { - SMqTopicObj *pTopic = NULL; + STopicObj *pTopic = NULL; pIter = sdbFetch(pSdb, SDB_TOPIC, pIter, (void **)&pTopic); if (pIter == NULL) break; diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index cf434dda39df13b59fa59654c2a5b33b76b01672..c1686c292398ee54ec54d0287702a214f27f6090 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -31,6 +31,7 @@ static int32_t mndTransAppendLog(SArray *pArray, SSdbRaw *pRaw); static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction); static void mndTransDropLogs(SArray *pArray); static void mndTransDropActions(SArray *pArray); +static void mndTransDropData(STrans *pTrans); static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray); static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pArray); static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans); @@ -51,7 +52,6 @@ static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans); static void mndTransExecute(SMnode *pMnode, STrans *pTrans); static void mndTransSendRpcRsp(STrans *pTrans); static int32_t mndProcessTransMsg(SMnodeMsg *pMsg); -static int32_t mndProcessTransRsp(SMnodeMsg *pMsg); int32_t mndInitTrans(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_TRANS, @@ -63,13 +63,14 @@ int32_t mndInitTrans(SMnode *pMnode) { .deleteFp = (SdbDeleteFp)mndTransActionDelete}; mndSetMsgHandle(pMnode, TDMT_MND_TRANS, mndProcessTransMsg); - mndSetMsgHandle(pMnode, TDMT_MND_TRANS_RSP, mndProcessTransRsp); return sdbSetTable(pMnode->pSdb, table); } void mndCleanupTrans(SMnode *pMnode) {} static SSdbRaw *mndTransActionEncode(STrans *pTrans) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int32_t rawDataLen = sizeof(STrans) + MND_TRANS_RESERVE_SIZE; int32_t redoLogNum = taosArrayGetSize(pTrans->redoLogs); int32_t undoLogNum = taosArrayGetSize(pTrans->undoLogs); @@ -109,75 +110,97 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) { } int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pTrans->id) - SDB_SET_INT8(pRaw, dataPos, pTrans->policy) - SDB_SET_INT32(pRaw, dataPos, redoLogNum) - SDB_SET_INT32(pRaw, dataPos, undoLogNum) - SDB_SET_INT32(pRaw, dataPos, commitLogNum) - SDB_SET_INT32(pRaw, dataPos, redoActionNum) - SDB_SET_INT32(pRaw, dataPos, undoActionNum) + SDB_SET_INT32(pRaw, dataPos, pTrans->id, TRANS_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pTrans->policy, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, redoLogNum, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, undoLogNum, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, commitLogNum, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, redoActionNum, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, undoActionNum, TRANS_ENCODE_OVER) for (int32_t i = 0; i < redoLogNum; ++i) { SSdbRaw *pTmp = taosArrayGetP(pTrans->redoLogs, i); int32_t len = sdbGetRawTotalSize(pTmp); - SDB_SET_INT32(pRaw, dataPos, len) - SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len) + SDB_SET_INT32(pRaw, dataPos, len, TRANS_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len, TRANS_ENCODE_OVER) } for (int32_t i = 0; i < undoLogNum; ++i) { SSdbRaw *pTmp = taosArrayGetP(pTrans->undoLogs, i); int32_t len = sdbGetRawTotalSize(pTmp); - SDB_SET_INT32(pRaw, dataPos, len) - SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len) + SDB_SET_INT32(pRaw, dataPos, len, TRANS_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len, TRANS_ENCODE_OVER) } for (int32_t i = 0; i < commitLogNum; ++i) { SSdbRaw *pTmp = taosArrayGetP(pTrans->commitLogs, i); int32_t len = sdbGetRawTotalSize(pTmp); - SDB_SET_INT32(pRaw, dataPos, len) - SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len) + SDB_SET_INT32(pRaw, dataPos, len, TRANS_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len, TRANS_ENCODE_OVER) } for (int32_t i = 0; i < redoActionNum; ++i) { STransAction *pAction = taosArrayGet(pTrans->redoActions, i); - SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet)); - SDB_SET_INT16(pRaw, dataPos, pAction->msgType) - SDB_SET_INT32(pRaw, dataPos, pAction->contLen) - SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen); + SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), TRANS_ENCODE_OVER) + SDB_SET_INT16(pRaw, dataPos, pAction->msgType, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAction->acceptableCode, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAction->contLen, TRANS_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen, TRANS_ENCODE_OVER) } for (int32_t i = 0; i < undoActionNum; ++i) { STransAction *pAction = taosArrayGet(pTrans->undoActions, i); - SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet)); - SDB_SET_INT16(pRaw, dataPos, pAction->msgType) - SDB_SET_INT32(pRaw, dataPos, pAction->contLen) - SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pCont, pAction->contLen); + SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), TRANS_ENCODE_OVER) + SDB_SET_INT16(pRaw, dataPos, pAction->msgType, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAction->acceptableCode, TRANS_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pAction->contLen, TRANS_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pCont, pAction->contLen, TRANS_ENCODE_OVER) } - SDB_SET_RESERVE(pRaw, dataPos, MND_TRANS_RESERVE_SIZE) - SDB_SET_DATALEN(pRaw, dataPos); - mTrace("trans:%d, encode to raw:%p, len:%d", pTrans->id, pRaw, dataPos); + SDB_SET_RESERVE(pRaw, dataPos, MND_TRANS_RESERVE_SIZE, TRANS_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, TRANS_ENCODE_OVER) + + terrno = 0; + +TRANS_ENCODE_OVER: + if (terrno != 0) { + mError("trans:%d, failed to encode to raw:%p len:%d since %s", pTrans->id, pRaw, dataPos, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + + mTrace("trans:%d, encode to raw:%p, row:%p len:%d", pTrans->id, pRaw, pTrans, dataPos); return pRaw; } static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { - int32_t code = 0; - - int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + terrno = TSDB_CODE_OUT_OF_MEMORY; + + SSdbRow *pRow = NULL; + STrans *pTrans = NULL; + char *pData = NULL; + int32_t dataLen = 0; + int8_t sver = 0; + int32_t redoLogNum = 0; + int32_t undoLogNum = 0; + int32_t commitLogNum = 0; + int32_t redoActionNum = 0; + int32_t undoActionNum = 0; + int32_t dataPos = 0; + STransAction action = {0}; + + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto TRANS_DECODE_OVER; if (sver != MND_TRANS_VER_NUMBER) { terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - mError("failed to get check soft ver from raw:%p since %s", pRaw, terrstr()); - return NULL; + goto TRANS_DECODE_OVER; } - SSdbRow *pRow = sdbAllocRow(sizeof(STrans)); - STrans *pTrans = sdbGetRowObj(pRow); - if (pTrans == NULL) { - mError("failed to alloc trans from raw:%p since %s", pRaw, terrstr()); - return NULL; - } + pRow = sdbAllocRow(sizeof(STrans)); + if (pRow == NULL) goto TRANS_DECODE_OVER; + + pTrans = sdbGetRowObj(pRow); + if (pTrans == NULL) goto TRANS_DECODE_OVER; pTrans->redoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); pTrans->undoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *)); @@ -185,139 +208,114 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { pTrans->redoActions = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(STransAction)); pTrans->undoActions = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(STransAction)); - if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL || - pTrans->redoActions == NULL || pTrans->undoActions == NULL) { - mDebug("trans:%d, failed to create array while parsed from raw:%p", pTrans->id, pRaw); - code = TSDB_CODE_OUT_OF_MEMORY; - goto TRANS_DECODE_OVER; - } - - int32_t redoLogNum = 0; - int32_t undoLogNum = 0; - int32_t commitLogNum = 0; - int32_t redoActionNum = 0; - int32_t undoActionNum = 0; + if (pTrans->redoLogs == NULL) goto TRANS_DECODE_OVER; + if (pTrans->undoLogs == NULL) goto TRANS_DECODE_OVER; + if (pTrans->commitLogs == NULL) goto TRANS_DECODE_OVER; + if (pTrans->redoActions == NULL) goto TRANS_DECODE_OVER; + if (pTrans->undoActions == NULL) goto TRANS_DECODE_OVER; - int32_t dataPos = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &pTrans->id) - SDB_GET_INT8(pRaw, pRow, dataPos, (int8_t *)&pTrans->policy) - SDB_GET_INT32(pRaw, pRow, dataPos, &redoLogNum) - SDB_GET_INT32(pRaw, pRow, dataPos, &undoLogNum) - SDB_GET_INT32(pRaw, pRow, dataPos, &commitLogNum) - SDB_GET_INT32(pRaw, pRow, dataPos, &redoActionNum) - SDB_GET_INT32(pRaw, pRow, dataPos, &undoActionNum) + SDB_GET_INT32(pRaw, dataPos, &pTrans->id, TRANS_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, (int8_t *)&pTrans->policy, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &redoLogNum, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &undoLogNum, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &commitLogNum, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &redoActionNum, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &undoActionNum, TRANS_DECODE_OVER) for (int32_t i = 0; i < redoLogNum; ++i) { - int32_t dataLen = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen) - char *pData = malloc(dataLen); - SDB_GET_BINARY(pRaw, pRow, dataPos, pData, dataLen); - - void *ret = taosArrayPush(pTrans->redoLogs, &pData); - if (ret == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto TRANS_DECODE_OVER; - } + SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER) + pData = malloc(dataLen); + if (pData == NULL) goto TRANS_DECODE_OVER; + mTrace("raw:%p, is created", pData); + SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER); + if (taosArrayPush(pTrans->redoLogs, &pData) == NULL) goto TRANS_DECODE_OVER; + pData = NULL; } for (int32_t i = 0; i < undoLogNum; ++i) { - int32_t dataLen = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen) - char *pData = malloc(dataLen); - SDB_GET_BINARY(pRaw, pRow, dataPos, pData, dataLen); - - void *ret = taosArrayPush(pTrans->undoLogs, &pData); - if (ret == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto TRANS_DECODE_OVER; - } + SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER) + pData = malloc(dataLen); + if (pData == NULL) goto TRANS_DECODE_OVER; + mTrace("raw:%p, is created", pData); + SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER); + if (taosArrayPush(pTrans->undoLogs, &pData) == NULL) goto TRANS_DECODE_OVER; + pData = NULL; } for (int32_t i = 0; i < commitLogNum; ++i) { - int32_t dataLen = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen) - char *pData = malloc(dataLen); - SDB_GET_BINARY(pRaw, pRow, dataPos, pData, dataLen); - - void *ret = taosArrayPush(pTrans->commitLogs, &pData); - if (ret == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto TRANS_DECODE_OVER; - } + SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER) + pData = malloc(dataLen); + if (pData == NULL) goto TRANS_DECODE_OVER; + mTrace("raw:%p, is created", pData); + SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER); + if (taosArrayPush(pTrans->commitLogs, &pData) == NULL) goto TRANS_DECODE_OVER; + pData = NULL; } for (int32_t i = 0; i < redoActionNum; ++i) { - STransAction action = {0}; - SDB_GET_BINARY(pRaw, pRow, dataPos, (void *)&action.epSet, sizeof(SEpSet)); - SDB_GET_INT16(pRaw, pRow, dataPos, &action.msgType) - SDB_GET_INT32(pRaw, pRow, dataPos, &action.contLen) + SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), TRANS_DECODE_OVER); + SDB_GET_INT16(pRaw, dataPos, &action.msgType, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &action.contLen, TRANS_DECODE_OVER) action.pCont = malloc(action.contLen); - if (action.pCont == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto TRANS_DECODE_OVER; - } - SDB_GET_BINARY(pRaw, pRow, dataPos, action.pCont, action.contLen); - - void *ret = taosArrayPush(pTrans->redoActions, &action); - if (ret == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto TRANS_DECODE_OVER; - } + if (action.pCont == NULL) goto TRANS_DECODE_OVER; + SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, TRANS_DECODE_OVER); + if (taosArrayPush(pTrans->redoActions, &action) == NULL) goto TRANS_DECODE_OVER; + action.pCont = NULL; } for (int32_t i = 0; i < undoActionNum; ++i) { - STransAction action = {0}; - SDB_GET_BINARY(pRaw, pRow, dataPos, (void *)&action.epSet, sizeof(SEpSet)); - SDB_GET_INT16(pRaw, pRow, dataPos, &action.msgType) - SDB_GET_INT32(pRaw, pRow, dataPos, &action.contLen) + SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), TRANS_DECODE_OVER); + SDB_GET_INT16(pRaw, dataPos, &action.msgType, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, TRANS_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &action.contLen, TRANS_DECODE_OVER) action.pCont = malloc(action.contLen); - if (action.pCont == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto TRANS_DECODE_OVER; - } - SDB_GET_BINARY(pRaw, pRow, dataPos, action.pCont, action.contLen); - - void *ret = taosArrayPush(pTrans->undoActions, &action); - if (ret == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto TRANS_DECODE_OVER; - } + if (action.pCont == NULL) goto TRANS_DECODE_OVER; + SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, TRANS_DECODE_OVER); + if (taosArrayPush(pTrans->undoActions, &action) == NULL) goto TRANS_DECODE_OVER; + action.pCont = NULL; } - SDB_GET_RESERVE(pRaw, pRow, dataPos, MND_TRANS_RESERVE_SIZE) + SDB_GET_RESERVE(pRaw, dataPos, MND_TRANS_RESERVE_SIZE, TRANS_DECODE_OVER) + + terrno = 0; TRANS_DECODE_OVER: - if (code != 0) { - mError("trans:%d, failed to parse from raw:%p since %s", pTrans->id, pRaw, tstrerror(errno)); - mndTransDrop(pTrans); - terrno = code; + if (terrno != 0) { + mError("trans:%d, failed to parse from raw:%p since %s", pTrans->id, pRaw, terrstr()); + mndTransDropData(pTrans); + tfree(pRow); + tfree(pData); + tfree(action.pCont); return NULL; } - mTrace("trans:%d, decode from raw:%p, data:%p", pTrans->id, pRaw, pTrans); + mTrace("trans:%d, decode from raw:%p, row:%p", pTrans->id, pRaw, pTrans); return pRow; } static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) { pTrans->stage = TRN_STAGE_PREPARE; - mTrace("trans:%d, perform insert action, data:%p", pTrans->id, pTrans); + mTrace("trans:%d, perform insert action, row:%p", pTrans->id, pTrans); return 0; } -static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) { - mTrace("trans:%d, perform delete action, data:%p", pTrans->id, pTrans); - +static void mndTransDropData(STrans *pTrans) { mndTransDropLogs(pTrans->redoLogs); mndTransDropLogs(pTrans->undoLogs); mndTransDropLogs(pTrans->commitLogs); mndTransDropActions(pTrans->redoActions); mndTransDropActions(pTrans->undoActions); +} +static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) { + mTrace("trans:%d, perform delete action, row:%p", pTrans->id, pTrans); + mndTransDropData(pTrans); return 0; } static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOldTrans, STrans *pNewTrans) { - mTrace("trans:%d, perform update action, data:%p", pOldTrans->id, pOldTrans); + mTrace("trans:%d, perform update action, old_row:%p new_row:%p", pOldTrans->id, pOldTrans, pNewTrans); pOldTrans->stage = pNewTrans->stage; return 0; } @@ -367,6 +365,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, SRpcMsg *pMsg) { } static void mndTransDropLogs(SArray *pArray) { + if (pArray == NULL) return; for (int32_t i = 0; i < pArray->size; ++i) { SSdbRaw *pRaw = taosArrayGetP(pArray, i); sdbFreeRaw(pRaw); @@ -376,6 +375,7 @@ static void mndTransDropLogs(SArray *pArray) { } static void mndTransDropActions(SArray *pArray) { + if (pArray == NULL) return; for (int32_t i = 0; i < pArray->size; ++i) { STransAction *pAction = taosArrayGet(pArray, i); free(pAction->pCont); @@ -385,12 +385,7 @@ static void mndTransDropActions(SArray *pArray) { } void mndTransDrop(STrans *pTrans) { - mndTransDropLogs(pTrans->redoLogs); - mndTransDropLogs(pTrans->undoLogs); - mndTransDropLogs(pTrans->commitLogs); - mndTransDropActions(pTrans->redoActions); - mndTransDropActions(pTrans->undoActions); - + mndTransDropData(pTrans); mDebug("trans:%d, is dropped, data:%p", pTrans->id, pTrans); tfree(pTrans); } @@ -505,10 +500,31 @@ static int32_t mndTransRollback(SMnode *pMnode, STrans *pTrans) { } static void mndTransSendRpcRsp(STrans *pTrans) { - if (pTrans->rpcHandle != NULL) { - mDebug("trans:%d, send rsp, ahandle:%p code:0x%x", pTrans->id, pTrans->rpcAHandle, pTrans->code & 0xFFFF); + bool sendRsp = false; + + if (pTrans->stage == TRN_STAGE_FINISHED) { + sendRsp = true; + } + + if (pTrans->policy == TRN_POLICY_ROLLBACK) { + if (pTrans->stage == TRN_STAGE_UNDO_LOG || pTrans->stage == TRN_STAGE_UNDO_ACTION || + pTrans->stage == TRN_STAGE_ROLLBACK) { + sendRsp = true; + } + } + + if (pTrans->policy == TRN_POLICY_RETRY) { + if (pTrans->stage == TRN_STAGE_REDO_ACTION && pTrans->failedTimes > 0) { + sendRsp = true; + } + } + + if (sendRsp && pTrans->rpcHandle != NULL) { + mDebug("trans:%d, send rsp, code:0x%x stage:%d app:%p", pTrans->id, pTrans->code & 0xFFFF, pTrans->stage, + pTrans->rpcAHandle); SRpcMsg rspMsg = {.handle = pTrans->rpcHandle, .code = pTrans->code, .ahandle = pTrans->rpcAHandle}; rpcSendResponse(&rspMsg); + pTrans->rpcHandle = NULL; } } @@ -551,7 +567,8 @@ void mndTransProcessRsp(SMnodeMsg *pMsg) { pAction->errCode = pMsg->rpcMsg.code; } - mDebug("trans:%d, action:%d response is received, code:0x%x", transId, action, pMsg->rpcMsg.code); + mDebug("trans:%d, action:%d response is received, code:0x%x, accept:0x%x", transId, action, pMsg->rpcMsg.code, + pAction->acceptableCode); mndTransExecute(pMnode, pTrans); HANDLE_ACTION_RSP_OVER: @@ -622,12 +639,15 @@ static int32_t mndTransSendActionMsg(SMnode *pMnode, STrans *pTrans, SArray *pAr } memcpy(rpcMsg.pCont, pAction->pCont, pAction->contLen); - pAction->msgSent = 1; - pAction->msgReceived = 0; - pAction->errCode = 0; - - mDebug("trans:%d, action:%d is sent", pTrans->id, action); - mndSendMsgToDnode(pMnode, &pAction->epSet, &rpcMsg); + if (mndSendReqToDnode(pMnode, &pAction->epSet, &rpcMsg) == 0) { + mDebug("trans:%d, action:%d is sent", pTrans->id, action); + pAction->msgSent = 1; + pAction->msgReceived = 0; + pAction->errCode = 0; + } else { + mDebug("trans:%d, action:%d not sent since %s", pTrans->id, action, terrstr()); + return -1; + } } return 0; @@ -648,7 +668,7 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA if (pAction == NULL) continue; if (pAction->msgSent && pAction->msgReceived) { numOfReceived++; - if (pAction->errCode != 0) { + if (pAction->errCode != 0 && pAction->errCode != pAction->acceptableCode) { errCode = pAction->errCode; } } @@ -696,7 +716,7 @@ static bool mndTransPerformRedoLogStage(SMnode *pMnode, STrans *pTrans) { } else { pTrans->code = terrno; pTrans->stage = TRN_STAGE_UNDO_LOG; - mError("trans:%d, stage from redoLog to undoLog", pTrans->id); + mError("trans:%d, stage from redoLog to undoLog since %s", pTrans->id, terrstr()); } return continueExec; @@ -770,7 +790,6 @@ static bool mndTransPerformCommitLogStage(SMnode *pMnode, STrans *pTrans) { pTrans->failedTimes++; mError("trans:%d, stage keep on commitLog since %s", pTrans->id, terrstr()); continueExec = false; - ; } return continueExec; @@ -797,7 +816,7 @@ static bool mndTransPerformUndoActionStage(SMnode *pMnode, STrans *pTrans) { int32_t code = mndTransExecuteUndoActions(pMnode, pTrans); if (code == 0) { - pTrans->stage = TRN_STAGE_REDO_LOG; + pTrans->stage = TRN_STAGE_UNDO_LOG; mDebug("trans:%d, stage from undoAction to undoLog", pTrans->id); continueExec = true; } else if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) { @@ -820,7 +839,6 @@ static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans) { pTrans->stage = TRN_STAGE_FINISHED; mDebug("trans:%d, stage from rollback to finished", pTrans->id); continueExec = true; - ; } else { pTrans->failedTimes++; mError("trans:%d, stage keep on rollback since %s", pTrans->id, terrstr()); @@ -886,13 +904,15 @@ static void mndTransExecute(SMnode *pMnode, STrans *pTrans) { } } - if (pTrans->stage == TRN_STAGE_FINISHED) { - mndTransSendRpcRsp(pTrans); - } + mndTransSendRpcRsp(pTrans); } static int32_t mndProcessTransMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; + mndTransPullup(pMsg->pMnode); + return 0; +} + +void mndTransPullup(SMnode *pMnode) { STrans *pTrans = NULL; void *pIter = NULL; @@ -904,5 +924,3 @@ static int32_t mndProcessTransMsg(SMnodeMsg *pMsg) { sdbRelease(pMnode->pSdb, pTrans); } } - -static int32_t mndProcessTransRsp(SMnodeMsg *pMsg) { return 0; } \ No newline at end of file diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 0926cf0c48db62d80e3114f3dd55a98730f14795..e73b34e688c92194ec2a9c63127bd90da4f39cf3 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -16,7 +16,6 @@ #define _DEFAULT_SOURCE #include "mndUser.h" #include "mndShow.h" -#include "mndSync.h" #include "mndTrans.h" #include "tkey.h" @@ -28,13 +27,13 @@ static SSdbRaw *mndUserActionEncode(SUserObj *pUser); static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw); static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser); static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser); -static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOldUser, SUserObj *pNewUser); -static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pMsg); -static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg); -static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg); -static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg); -static int32_t mndGetUserMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); -static int32_t mndRetrieveUsers(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); +static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew); +static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pReq); +static int32_t mndProcessCreateUserReq(SMnodeMsg *pReq); +static int32_t mndProcessAlterUserReq(SMnodeMsg *pReq); +static int32_t mndProcessDropUserReq(SMnodeMsg *pReq); +static int32_t mndGetUserMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta); +static int32_t mndRetrieveUsers(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows); static void mndCancelGetNextUser(SMnode *pMnode, void *pIter); int32_t mndInitUser(SMnode *pMnode) { @@ -47,9 +46,9 @@ int32_t mndInitUser(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndUserActionUpdate, .deleteFp = (SdbDeleteFp)mndUserActionDelete}; - mndSetMsgHandle(pMnode, TDMT_MND_CREATE_USER, mndProcessCreateUserMsg); - mndSetMsgHandle(pMnode, TDMT_MND_ALTER_USER, mndProcessAlterUserMsg); - mndSetMsgHandle(pMnode, TDMT_MND_DROP_USER, mndProcessDropUserMsg); + mndSetMsgHandle(pMnode, TDMT_MND_CREATE_USER, mndProcessCreateUserReq); + mndSetMsgHandle(pMnode, TDMT_MND_ALTER_USER, mndProcessAlterUserReq); + mndSetMsgHandle(pMnode, TDMT_MND_DROP_USER, mndProcessDropUserReq); mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_USER, mndGetUserMeta); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_USER, mndRetrieveUsers); @@ -75,7 +74,7 @@ static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char if (pRaw == NULL) return -1; sdbSetRawStatus(pRaw, SDB_STATUS_READY); - mDebug("user:%s, will be created while deploy sdb", userObj.user); + mDebug("user:%s, will be created while deploy sdb, raw:%p", userObj.user, pRaw); return sdbWrite(pMnode->pSdb, pRaw); } @@ -94,50 +93,75 @@ static int32_t mndCreateDefaultUsers(SMnode *pMnode) { } static SSdbRaw *mndUserActionEncode(SUserObj *pUser) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, TSDB_USER_VER_NUMBER, sizeof(SUserObj) + TSDB_USER_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto USER_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN) - SDB_SET_BINARY(pRaw, dataPos, pUser->pass, TSDB_PASSWORD_LEN) - SDB_SET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN) - SDB_SET_INT64(pRaw, dataPos, pUser->createdTime) - SDB_SET_INT64(pRaw, dataPos, pUser->updateTime) - SDB_SET_INT8(pRaw, dataPos, pUser->superUser) - SDB_SET_RESERVE(pRaw, dataPos, TSDB_USER_RESERVE_SIZE) - SDB_SET_DATALEN(pRaw, dataPos); + SDB_SET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN, USER_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pUser->pass, TSDB_PASSWORD_LEN, USER_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN, USER_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pUser->createdTime, USER_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pUser->updateTime, USER_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pUser->superUser, USER_ENCODE_OVER) + SDB_SET_RESERVE(pRaw, dataPos, TSDB_USER_RESERVE_SIZE, USER_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, USER_ENCODE_OVER) + + terrno = 0; + +USER_ENCODE_OVER: + if (terrno != 0) { + mError("user:%s, failed to encode to raw:%p since %s", pUser->user, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; + } + mTrace("user:%s, encode to raw:%p, row:%p", pUser->user, pRaw, pUser); return pRaw; } static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto USER_DECODE_OVER; if (sver != TSDB_USER_VER_NUMBER) { - mError("failed to decode user since %s", terrstr()); terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - return NULL; + goto USER_DECODE_OVER; } - SSdbRow *pRow = sdbAllocRow(sizeof(SUserObj)); + SSdbRow *pRow = sdbAllocRow(sizeof(SUserObj)); + if (pRow == NULL) goto USER_DECODE_OVER; + SUserObj *pUser = sdbGetRowObj(pRow); - if (pUser == NULL) return NULL; + if (pUser == NULL) goto USER_DECODE_OVER; int32_t dataPos = 0; - SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->user, TSDB_USER_LEN) - SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->pass, TSDB_PASSWORD_LEN) - SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->acct, TSDB_USER_LEN) - SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->updateTime) - SDB_GET_INT8(pRaw, pRow, dataPos, &pUser->superUser) - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_USER_RESERVE_SIZE) + SDB_GET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN, USER_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pUser->pass, TSDB_PASSWORD_LEN, USER_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN, USER_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pUser->createdTime, USER_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pUser->updateTime, USER_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pUser->superUser, USER_DECODE_OVER) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_USER_RESERVE_SIZE, USER_DECODE_OVER) + + terrno = 0; + +USER_DECODE_OVER: + if (terrno != 0) { + mError("user:%s, failed to decode from raw:%p since %s", pUser->user, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + mTrace("user:%s, decode from raw:%p, row:%p", pUser->user, pRaw, pUser); return pRow; } static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) { - mTrace("user:%s, perform insert action", pUser->user); + mTrace("user:%s, perform insert action, row:%p", pUser->user, pUser); pUser->prohibitDbHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (pUser->prohibitDbHash == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -158,7 +182,7 @@ static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) { } static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) { - mTrace("user:%s, perform delete action", pUser->user); + mTrace("user:%s, perform delete action, row:%p", pUser->user, pUser); if (pUser->prohibitDbHash) { taosHashCleanup(pUser->prohibitDbHash); pUser->prohibitDbHash = NULL; @@ -167,10 +191,10 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) { return 0; } -static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOldUser, SUserObj *pNewUser) { - mTrace("user:%s, perform update action", pOldUser->user); - memcpy(pOldUser->pass, pNewUser->pass, TSDB_PASSWORD_LEN); - pOldUser->updateTime = pNewUser->updateTime; +static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew) { + mTrace("user:%s, perform update action, old_row:%p new_row:%p", pOld->user, pOld, pNew); + memcpy(pOld->pass, pNew->pass, TSDB_PASSWORD_LEN); + pOld->updateTime = pNew->updateTime; return 0; } @@ -188,7 +212,7 @@ void mndReleaseUser(SMnode *pMnode, SUserObj *pUser) { sdbRelease(pSdb, pUser); } -static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pMsg) { +static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pReq) { SUserObj userObj = {0}; tstrncpy(userObj.user, user, TSDB_USER_LEN); tstrncpy(userObj.acct, acct, TSDB_USER_LEN); @@ -197,7 +221,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, userObj.updateTime = userObj.createdTime; userObj.superUser = 0; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg); if (pTrans == NULL) { mError("user:%s, failed to create since %s", user, terrstr()); return -1; @@ -222,9 +246,9 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, return 0; } -static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont; +static int32_t mndProcessCreateUserReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SCreateUserReq *pCreate = pReq->rpcMsg.pCont; mDebug("user:%s, start to create", pCreate->user); @@ -240,23 +264,23 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { return -1; } - SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pCreate->user); + SUserObj *pUser = mndAcquireUser(pMnode, pCreate->user); if (pUser != NULL) { - sdbRelease(pMnode->pSdb, pUser); + mndReleaseUser(pMnode, pUser); terrno = TSDB_CODE_MND_USER_ALREADY_EXIST; mError("user:%s, failed to create since %s", pCreate->user, terrstr()); return -1; } - SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user); + SUserObj *pOperUser = mndAcquireUser(pMnode, pReq->user); if (pOperUser == NULL) { terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; mError("user:%s, failed to create since %s", pCreate->user, terrstr()); return -1; } - int32_t code = mndCreateUser(pMnode, pOperUser->acct, pCreate->user, pCreate->pass, pMsg); - sdbRelease(pMnode->pSdb, pOperUser); + int32_t code = mndCreateUser(pMnode, pOperUser->acct, pCreate->user, pCreate->pass, pReq); + mndReleaseUser(pMnode, pOperUser); if (code != 0) { mError("user:%s, failed to create since %s", pCreate->user, terrstr()); @@ -266,15 +290,15 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOldUser, SUserObj *pNewUser, SMnodeMsg *pMsg) { - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); +static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SMnodeMsg *pReq) { + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg); if (pTrans == NULL) { - mError("user:%s, failed to update since %s", pOldUser->user, terrstr()); + mError("user:%s, failed to update since %s", pOld->user, terrstr()); return -1; } - mDebug("trans:%d, used to update user:%s", pTrans->id, pOldUser->user); + mDebug("trans:%d, used to update user:%s", pTrans->id, pOld->user); - SSdbRaw *pRedoRaw = mndUserActionEncode(pNewUser); + SSdbRaw *pRedoRaw = mndUserActionEncode(pNew); if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) { mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr()); mndTransDrop(pTrans); @@ -292,9 +316,9 @@ static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOldUser, SUserObj *pNewU return 0; } -static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SAlterUserMsg *pAlter = pMsg->rpcMsg.pCont; +static int32_t mndProcessAlterUserReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SAlterUserReq *pAlter = pReq->rpcMsg.pCont; mDebug("user:%s, start to alter", pAlter->user); @@ -310,15 +334,16 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) { return -1; } - SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pAlter->user); + SUserObj *pUser = mndAcquireUser(pMnode, pAlter->user); if (pUser == NULL) { terrno = TSDB_CODE_MND_USER_NOT_EXIST; mError("user:%s, failed to alter since %s", pAlter->user, terrstr()); return -1; } - SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user); + SUserObj *pOperUser = mndAcquireUser(pMnode, pReq->user); if (pOperUser == NULL) { + mndReleaseUser(pMnode, pUser); terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; mError("user:%s, failed to alter since %s", pAlter->user, terrstr()); return -1; @@ -330,8 +355,9 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) { taosEncryptPass((uint8_t *)pAlter->pass, strlen(pAlter->pass), pUser->pass); newUser.updateTime = taosGetTimestampMs(); - int32_t code = mndUpdateUser(pMnode, pUser, &newUser, pMsg); - sdbRelease(pMnode->pSdb, pOperUser); + int32_t code = mndUpdateUser(pMnode, pUser, &newUser, pReq); + mndReleaseUser(pMnode, pOperUser); + mndReleaseUser(pMnode, pUser); if (code != 0) { mError("user:%s, failed to alter since %s", pAlter->user, terrstr()); @@ -341,8 +367,8 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pMsg, SUserObj *pUser) { - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg); +static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pReq, SUserObj *pUser) { + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg); if (pTrans == NULL) { mError("user:%s, failed to drop since %s", pUser->user, terrstr()); return -1; @@ -367,9 +393,9 @@ static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pMsg, SUserObj *pUser) { return 0; } -static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg) { - SMnode *pMnode = pMsg->pMnode; - SDropUserMsg *pDrop = pMsg->rpcMsg.pCont; +static int32_t mndProcessDropUserReq(SMnodeMsg *pReq) { + SMnode *pMnode = pReq->pMnode; + SDropUserReq *pDrop = pReq->rpcMsg.pCont; mDebug("user:%s, start to drop", pDrop->user); @@ -379,22 +405,24 @@ static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg) { return -1; } - SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pDrop->user); + SUserObj *pUser = mndAcquireUser(pMnode, pDrop->user); if (pUser == NULL) { terrno = TSDB_CODE_MND_USER_NOT_EXIST; mError("user:%s, failed to drop since %s", pDrop->user, terrstr()); return -1; } - SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user); + SUserObj *pOperUser = mndAcquireUser(pMnode, pReq->user); if (pOperUser == NULL) { + mndReleaseUser(pMnode, pUser); terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; mError("user:%s, failed to drop since %s", pDrop->user, terrstr()); return -1; } - int32_t code = mndDropUser(pMnode, pMsg, pUser); - sdbRelease(pMnode->pSdb, pOperUser); + int32_t code = mndDropUser(pMnode, pReq, pUser); + mndReleaseUser(pMnode, pOperUser); + mndReleaseUser(pMnode, pUser); if (code != 0) { mError("user:%s, failed to drop since %s", pDrop->user, terrstr()); @@ -404,8 +432,8 @@ static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } -static int32_t mndGetUserMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndGetUserMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) { + SMnode *pMnode = pReq->pMnode; SSdb *pSdb = pMnode->pSdb; int32_t cols = 0; @@ -450,8 +478,8 @@ static int32_t mndGetUserMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *p return 0; } -static int32_t mndRetrieveUsers(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { - SMnode *pMnode = pMsg->pMnode; +static int32_t mndRetrieveUsers(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { + SMnode *pMnode = pReq->pMnode; SSdb *pSdb = pMnode->pSdb; int32_t numOfRows = 0; SUserObj *pUser = NULL; diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 41de70283f02d6bbf94c22021bd0b8b86fc5149e..bd17c6d15077ad0f303a1096e0bcf39b10eb021c 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -70,77 +70,102 @@ int32_t mndInitVgroup(SMnode *pMnode) { void mndCleanupVgroup(SMnode *pMnode) {} SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + SSdbRaw *pRaw = sdbAllocRaw(SDB_VGROUP, TSDB_VGROUP_VER_NUMBER, sizeof(SVgObj) + TSDB_VGROUP_RESERVE_SIZE); - if (pRaw == NULL) return NULL; + if (pRaw == NULL) goto VG_ENCODE_OVER; int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, pVgroup->vgId) - SDB_SET_INT64(pRaw, dataPos, pVgroup->createdTime) - SDB_SET_INT64(pRaw, dataPos, pVgroup->updateTime) - SDB_SET_INT32(pRaw, dataPos, pVgroup->version) - SDB_SET_INT32(pRaw, dataPos, pVgroup->hashBegin) - SDB_SET_INT32(pRaw, dataPos, pVgroup->hashEnd) - SDB_SET_BINARY(pRaw, dataPos, pVgroup->dbName, TSDB_DB_FNAME_LEN) - SDB_SET_INT64(pRaw, dataPos, pVgroup->dbUid) - SDB_SET_INT8(pRaw, dataPos, pVgroup->replica) + SDB_SET_INT32(pRaw, dataPos, pVgroup->vgId, VG_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pVgroup->createdTime, VG_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pVgroup->updateTime, VG_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pVgroup->version, VG_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pVgroup->hashBegin, VG_ENCODE_OVER) + SDB_SET_INT32(pRaw, dataPos, pVgroup->hashEnd, VG_ENCODE_OVER) + SDB_SET_BINARY(pRaw, dataPos, pVgroup->dbName, TSDB_DB_FNAME_LEN, VG_ENCODE_OVER) + SDB_SET_INT64(pRaw, dataPos, pVgroup->dbUid, VG_ENCODE_OVER) + SDB_SET_INT8(pRaw, dataPos, pVgroup->replica, VG_ENCODE_OVER) for (int8_t i = 0; i < pVgroup->replica; ++i) { SVnodeGid *pVgid = &pVgroup->vnodeGid[i]; - SDB_SET_INT32(pRaw, dataPos, pVgid->dnodeId) + SDB_SET_INT32(pRaw, dataPos, pVgid->dnodeId, VG_ENCODE_OVER) + } + SDB_SET_RESERVE(pRaw, dataPos, TSDB_VGROUP_RESERVE_SIZE, VG_ENCODE_OVER) + SDB_SET_DATALEN(pRaw, dataPos, VG_ENCODE_OVER) + + terrno = 0; + +VG_ENCODE_OVER: + if (terrno != 0) { + mError("vgId:%d, failed to encode to raw:%p since %s", pVgroup->vgId, pRaw, terrstr()); + sdbFreeRaw(pRaw); + return NULL; } - SDB_SET_RESERVE(pRaw, dataPos, TSDB_VGROUP_RESERVE_SIZE) - SDB_SET_DATALEN(pRaw, dataPos); + mTrace("vgId:%d, encode to raw:%p, row:%p", pVgroup->vgId, pRaw, pVgroup); return pRaw; } SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL; + if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto VG_DECODE_OVER; if (sver != TSDB_VGROUP_VER_NUMBER) { - mError("failed to decode vgroup since %s", terrstr()); terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - return NULL; + goto VG_DECODE_OVER; } SSdbRow *pRow = sdbAllocRow(sizeof(SVgObj)); - SVgObj *pVgroup = sdbGetRowObj(pRow); - if (pVgroup == NULL) return NULL; + if (pRow == NULL) goto VG_DECODE_OVER; + + SVgObj *pVgroup = sdbGetRowObj(pRow); + if (pVgroup == NULL) goto VG_DECODE_OVER; int32_t dataPos = 0; - SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->vgId) - SDB_GET_INT64(pRaw, pRow, dataPos, &pVgroup->createdTime) - SDB_GET_INT64(pRaw, pRow, dataPos, &pVgroup->updateTime) - SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->version) - SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->hashBegin) - SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->hashEnd) - SDB_GET_BINARY(pRaw, pRow, dataPos, pVgroup->dbName, TSDB_DB_FNAME_LEN) - SDB_GET_INT64(pRaw, pRow, dataPos, &pVgroup->dbUid) - SDB_GET_INT8(pRaw, pRow, dataPos, &pVgroup->replica) + SDB_GET_INT32(pRaw, dataPos, &pVgroup->vgId, VG_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pVgroup->createdTime, VG_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pVgroup->updateTime, VG_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pVgroup->version, VG_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pVgroup->hashBegin, VG_DECODE_OVER) + SDB_GET_INT32(pRaw, dataPos, &pVgroup->hashEnd, VG_DECODE_OVER) + SDB_GET_BINARY(pRaw, dataPos, pVgroup->dbName, TSDB_DB_FNAME_LEN, VG_DECODE_OVER) + SDB_GET_INT64(pRaw, dataPos, &pVgroup->dbUid, VG_DECODE_OVER) + SDB_GET_INT8(pRaw, dataPos, &pVgroup->replica, VG_DECODE_OVER) for (int8_t i = 0; i < pVgroup->replica; ++i) { SVnodeGid *pVgid = &pVgroup->vnodeGid[i]; - SDB_GET_INT32(pRaw, pRow, dataPos, &pVgid->dnodeId) + SDB_GET_INT32(pRaw, dataPos, &pVgid->dnodeId, VG_DECODE_OVER) if (pVgroup->replica == 1) { pVgid->role = TAOS_SYNC_STATE_LEADER; } } - SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_VGROUP_RESERVE_SIZE) + SDB_GET_RESERVE(pRaw, dataPos, TSDB_VGROUP_RESERVE_SIZE, VG_DECODE_OVER) + + terrno = 0; + +VG_DECODE_OVER: + if (terrno != 0) { + mError("vgId:%d, failed to decode from raw:%p since %s", pVgroup->vgId, pRaw, terrstr()); + tfree(pRow); + return NULL; + } + mTrace("vgId:%d, decode from raw:%p, row:%p", pVgroup->vgId, pRaw, pVgroup); return pRow; } static int32_t mndVgroupActionInsert(SSdb *pSdb, SVgObj *pVgroup) { - mTrace("vgId:%d, perform insert action", pVgroup->vgId); + mTrace("vgId:%d, perform insert action, row:%p", pVgroup->vgId, pVgroup); return 0; } static int32_t mndVgroupActionDelete(SSdb *pSdb, SVgObj *pVgroup) { - mTrace("vgId:%d, perform delete action", pVgroup->vgId); + mTrace("vgId:%d, perform delete action, row:%p", pVgroup->vgId, pVgroup); return 0; } static int32_t mndVgroupActionUpdate(SSdb *pSdb, SVgObj *pOldVgroup, SVgObj *pNewVgroup) { - mTrace("vgId:%d, perform update action", pOldVgroup->vgId); + mTrace("vgId:%d, perform update action, old_row:%p new_row:%p", pOldVgroup->vgId, pOldVgroup, pNewVgroup); pOldVgroup->updateTime = pNewVgroup->updateTime; pOldVgroup->version = pNewVgroup->version; pOldVgroup->hashBegin = pNewVgroup->hashBegin; diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index e902e13a36ffe57873dd32dfe60f49bad32d5695..7c740df06dfe1d1fd1a1f4a8d42df438dbe4fa4d 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -34,21 +34,27 @@ #include "mndUser.h" #include "mndVgroup.h" -void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *pMsg) { - if (pMnode != NULL && pMnode->sendMsgToDnodeFp != NULL) { - (*pMnode->sendMsgToDnodeFp)(pMnode->pDnode, pEpSet, pMsg); +int32_t mndSendReqToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *pMsg) { + if (pMnode == NULL || pMnode->sendReqToDnodeFp == NULL) { + terrno = TSDB_CODE_MND_NOT_READY; + return -1; } + + return (*pMnode->sendReqToDnodeFp)(pMnode->pDnode, pEpSet, pMsg); } -void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg) { - if (pMnode != NULL && pMnode->sendMsgToMnodeFp != NULL) { - (*pMnode->sendMsgToMnodeFp)(pMnode->pDnode, pMsg); +int32_t mndSendReqToMnode(SMnode *pMnode, SRpcMsg *pMsg) { + if (pMnode == NULL || pMnode->sendReqToDnodeFp == NULL) { + terrno = TSDB_CODE_MND_NOT_READY; + return -1; } + + return (*pMnode->sendReqToMnodeFp)(pMnode->pDnode, pMsg); } -void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg) { - if (pMnode != NULL && pMnode->sendRedirectMsgFp != NULL) { - (*pMnode->sendRedirectMsgFp)(pMnode->pDnode, pMsg); +void mndSendRedirectRsp(SMnode *pMnode, SRpcMsg *pMsg) { + if (pMnode != NULL && pMnode->sendRedirectRspFp != NULL) { + (*pMnode->sendRedirectRspFp)(pMnode->pDnode, pMsg); } } @@ -56,11 +62,8 @@ static void mndTransReExecute(void *param, void *tmrId) { SMnode *pMnode = param; if (mndIsMaster(pMnode)) { STransMsg *pMsg = rpcMallocCont(sizeof(STransMsg)); - SEpSet epSet = {.inUse = 0, .numOfEps = 1}; - epSet.port[0] = pMnode->replicas[pMnode->selfIndex].port; - memcpy(epSet.fqdn[0], pMnode->replicas[pMnode->selfIndex].fqdn, TSDB_FQDN_LEN); - SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS, .pCont = pMsg, .contLen = sizeof(STransMsg)}; - mndSendMsgToDnode(pMnode, &epSet, &rpcMsg); + SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS, .pCont = pMsg, .contLen = sizeof(STransMsg)}; + pMnode->putReqToMWriteQFp(pMnode->pDnode, &rpcMsg); } taosTmrReset(mndTransReExecute, 3000, pMnode, pMnode->timer, &pMnode->transTimer); @@ -76,7 +79,7 @@ static int32_t mndInitTimer(SMnode *pMnode) { return -1; } - if (taosTmrReset(mndTransReExecute, 1000, pMnode, pMnode->timer, &pMnode->transTimer)) { + if (taosTmrReset(mndTransReExecute, 6000, pMnode, pMnode->timer, &pMnode->transTimer)) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -185,7 +188,7 @@ static void mndCleanupSteps(SMnode *pMnode, int32_t pos) { for (int32_t s = pos; s >= 0; s--) { SMnodeStep *pStep = taosArrayGet(pMnode->pSteps, s); - mDebug("step:%s will cleanup", pStep->name); + mDebug("%s will cleanup", pStep->name); if (pStep->cleanupFp != NULL) { (*pStep->cleanupFp)(pMnode); } @@ -202,19 +205,15 @@ static int32_t mndExecSteps(SMnode *pMnode) { SMnodeStep *pStep = taosArrayGet(pMnode->pSteps, pos); if (pStep->initFp == NULL) continue; - // (*pMnode->reportProgress)(pStep->name, "start initialize"); - if ((*pStep->initFp)(pMnode) != 0) { int32_t code = terrno; - mError("step:%s exec failed since %s, start to cleanup", pStep->name, terrstr()); + mError("%s exec failed since %s, start to cleanup", pStep->name, terrstr()); mndCleanupSteps(pMnode, pos); terrno = code; return -1; } else { - mDebug("step:%s is initialized", pStep->name); + mDebug("%s is initialized", pStep->name); } - - // (*pMnode->reportProgress)(pStep->name, "initialize completed"); } return 0; @@ -227,9 +226,10 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { pMnode->selfIndex = pOption->selfIndex; memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); pMnode->pDnode = pOption->pDnode; - pMnode->sendMsgToDnodeFp = pOption->sendMsgToDnodeFp; - pMnode->sendMsgToMnodeFp = pOption->sendMsgToMnodeFp; - pMnode->sendRedirectMsgFp = pOption->sendRedirectMsgFp; + pMnode->putReqToMWriteQFp = pOption->putReqToMWriteQFp; + pMnode->sendReqToDnodeFp = pOption->sendReqToDnodeFp; + pMnode->sendReqToMnodeFp = pOption->sendReqToMnodeFp; + pMnode->sendRedirectRspFp = pOption->sendRedirectRspFp; pMnode->cfg.sver = pOption->cfg.sver; pMnode->cfg.enableTelem = pOption->cfg.enableTelem; pMnode->cfg.statusInterval = pOption->cfg.statusInterval; @@ -240,8 +240,9 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { pMnode->cfg.gitinfo = strdup(pOption->cfg.gitinfo); pMnode->cfg.buildinfo = strdup(pOption->cfg.buildinfo); - if (pMnode->sendMsgToDnodeFp == NULL || pMnode->sendMsgToMnodeFp == NULL || pMnode->sendRedirectMsgFp == NULL || - pMnode->dnodeId < 0 || pMnode->clusterId < 0 || pMnode->cfg.statusInterval < 1) { + if (pMnode->sendReqToDnodeFp == NULL || pMnode->sendReqToMnodeFp == NULL || pMnode->sendRedirectRspFp == NULL || + pMnode->putReqToMWriteQFp == NULL || pMnode->dnodeId < 0 || pMnode->clusterId < 0 || + pMnode->cfg.statusInterval < 1) { terrno = TSDB_CODE_MND_INVALID_OPTIONS; return -1; } @@ -361,29 +362,31 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) { SMnodeMsg *pMsg = taosAllocateQitem(sizeof(SMnodeMsg)); if (pMsg == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("RPC:%p, app:%p failed to create msg since %s", pRpcMsg->handle, pRpcMsg->ahandle, terrstr()); + mError("failed to create msg since %s, app:%p RPC:%p", terrstr(), pRpcMsg->ahandle, pRpcMsg->handle); return NULL; } - SRpcConnInfo connInfo = {0}; - if ((pRpcMsg->msgType & 1U) && rpcGetConnInfo(pRpcMsg->handle, &connInfo) != 0) { - taosFreeQitem(pMsg); - terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; - mError("RPC:%p, app:%p failed to create msg since %s", pRpcMsg->handle, pRpcMsg->ahandle, terrstr()); - return NULL; + if (pRpcMsg->msgType != TDMT_MND_TRANS) { + SRpcConnInfo connInfo = {0}; + if ((pRpcMsg->msgType & 1U) && rpcGetConnInfo(pRpcMsg->handle, &connInfo) != 0) { + taosFreeQitem(pMsg); + terrno = TSDB_CODE_MND_NO_USER_FROM_CONN; + mError("failed to create msg since %s, app:%p RPC:%p", terrstr(), pRpcMsg->ahandle, pRpcMsg->handle); + return NULL; + } + memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN); } - memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN); pMsg->pMnode = pMnode; pMsg->rpcMsg = *pRpcMsg; pMsg->createdTime = taosGetTimestampSec(); - mTrace("msg:%p, app:%p is created, RPC:%p", pMsg, pRpcMsg->ahandle, pRpcMsg->handle); + mTrace("msg:%p, is created, app:%p RPC:%p user:%s", pMsg, pRpcMsg->ahandle, pRpcMsg->handle, pMsg->user); return pMsg; } void mndCleanupMsg(SMnodeMsg *pMsg) { - mTrace("msg:%p, app:%p is destroyed, RPC:%p", pMsg, pMsg->rpcMsg.ahandle, pMsg->rpcMsg.handle); + mTrace("msg:%p, is destroyed, app:%p RPC:%p", pMsg, pMsg->rpcMsg.ahandle, pMsg->rpcMsg.handle); rpcFreeCont(pMsg->rpcMsg.pCont); pMsg->rpcMsg.pCont = NULL; taosFreeQitem(pMsg); @@ -401,43 +404,43 @@ void mndProcessMsg(SMnodeMsg *pMsg) { void *ahandle = pMsg->rpcMsg.ahandle; bool isReq = (msgType & 1U); - mTrace("msg:%p, app:%p type:%s will be processed", pMsg, ahandle, TMSG_INFO(msgType)); + mTrace("msg:%p, type:%s will be processed, app:%p", pMsg, TMSG_INFO(msgType), ahandle); if (isReq && !mndIsMaster(pMnode)) { code = TSDB_CODE_APP_NOT_READY; - mDebug("msg:%p, app:%p failed to process since %s", pMsg, ahandle, terrstr()); + mDebug("msg:%p, failed to process since %s, app:%p", pMsg, terrstr(), ahandle); goto PROCESS_RPC_END; } if (isReq && pMsg->rpcMsg.pCont == NULL) { code = TSDB_CODE_MND_INVALID_MSG_LEN; - mError("msg:%p, app:%p failed to process since %s", pMsg, ahandle, terrstr()); + mError("msg:%p, failed to process since %s, app:%p", pMsg, terrstr(), ahandle); goto PROCESS_RPC_END; } MndMsgFp fp = pMnode->msgFp[TMSG_INDEX(msgType)]; if (fp == NULL) { code = TSDB_CODE_MSG_NOT_PROCESSED; - mError("msg:%p, app:%p failed to process since no handle", pMsg, ahandle); + mError("msg:%p, failed to process since no msg handle, app:%p", pMsg, ahandle); goto PROCESS_RPC_END; } code = (*fp)(pMsg); if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) { - mTrace("msg:%p, app:%p in progressing", pMsg, ahandle); + mTrace("msg:%p, in progress, app:%p", pMsg, ahandle); return; } else if (code != 0) { code = terrno; - mError("msg:%p, app:%p failed to process since %s", pMsg, ahandle, terrstr()); + mError("msg:%p, failed to process since %s, app:%p", pMsg, terrstr(), ahandle); goto PROCESS_RPC_END; } else { - mTrace("msg:%p, app:%p is processed", pMsg, ahandle); + mTrace("msg:%p, is processed, app:%p", pMsg, ahandle); } PROCESS_RPC_END: if (isReq) { if (code == TSDB_CODE_APP_NOT_READY) { - mndSendRedirectMsg(pMnode, &pMsg->rpcMsg); + mndSendRedirectRsp(pMnode, &pMsg->rpcMsg); } else if (code != 0) { SRpcMsg rpcRsp = {.handle = pMsg->rpcMsg.handle, .code = code}; rpcSendResponse(&rpcRsp); diff --git a/source/dnode/mnode/impl/test/CMakeLists.txt b/source/dnode/mnode/impl/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6cdc43344d688bf5c2ad88a9863fa346d76014b8 --- /dev/null +++ b/source/dnode/mnode/impl/test/CMakeLists.txt @@ -0,0 +1,9 @@ +enable_testing() + +add_subdirectory(user) +add_subdirectory(acct) +add_subdirectory(trans) +add_subdirectory(qnode) +add_subdirectory(snode) +add_subdirectory(bnode) +add_subdirectory(show) diff --git a/source/dnode/mnode/impl/test/acct/CMakeLists.txt b/source/dnode/mnode/impl/test/acct/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8c8bf54bc4f59b7146f479abded66ab8fa1c271f --- /dev/null +++ b/source/dnode/mnode/impl/test/acct/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. ACCT_SRC) +add_executable(mnode_test_acct ${ACCT_SRC}) +target_link_libraries( + mnode_test_acct + PUBLIC sut +) + +add_test( + NAME mnode_test_acct + COMMAND mnode_test_acct +) diff --git a/source/dnode/mnode/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp new file mode 100644 index 0000000000000000000000000000000000000000..315f23f798ab576c8d2d529e5b7f678181a07ba3 --- /dev/null +++ b/source/dnode/mnode/impl/test/acct/acct.cpp @@ -0,0 +1,67 @@ +/** + * @file acct.cpp + * @author slguan (slguan@taosdata.com) + * @brief MNODE module acct tests + * @version 1.0 + * @date 2022-01-04 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" + +class MndTestAcct : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/mnode_test_acct", 9012); } + static void TearDownTestSuite() { test.Cleanup(); } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} +}; + +Testbase MndTestAcct::test; + +TEST_F(MndTestAcct, 01_Create_Acct) { + int32_t contLen = sizeof(SCreateAcctReq); + + SCreateAcctReq* pReq = (SCreateAcctReq*)rpcMallocCont(contLen); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_ACCT, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); +} + +TEST_F(MndTestAcct, 02_Alter_Acct) { + int32_t contLen = sizeof(SCreateAcctReq); + + SAlterAcctReq* pReq = (SAlterAcctReq*)rpcMallocCont(contLen); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_ACCT, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); +} + +TEST_F(MndTestAcct, 03_Drop_Acct) { + int32_t contLen = sizeof(SDropAcctReq); + + SDropAcctReq* pReq = (SDropAcctReq*)rpcMallocCont(contLen); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_ACCT, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED); +} + +TEST_F(MndTestAcct, 04_Show_Acct) { + int32_t contLen = sizeof(SShowReq); + + SShowReq* pReq = (SShowReq*)rpcMallocCont(contLen); + pReq->type = TSDB_MGMT_TABLE_ACCT; + + 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 new file mode 100644 index 0000000000000000000000000000000000000000..b58b1a856bd4201de19a9c5898786cb2c2814886 --- /dev/null +++ b/source/dnode/mnode/impl/test/bnode/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. STEST_SRC) +add_executable(mnode_test_bnode ${STEST_SRC}) +target_link_libraries( + mnode_test_bnode + PUBLIC sut +) + +add_test( + NAME mnode_test_bnode + COMMAND mnode_test_bnode +) diff --git a/source/dnode/mnode/impl/test/bnode/bnode.cpp b/source/dnode/mnode/impl/test/bnode/bnode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e32c0e7f91c9e1f8470d5d8d1a346ed5587938c5 --- /dev/null +++ b/source/dnode/mnode/impl/test/bnode/bnode.cpp @@ -0,0 +1,294 @@ +/** + * @file bnode.cpp + * @author slguan (slguan@taosdata.com) + * @brief MNODE module bnode tests + * @version 1.0 + * @date 2022-01-05 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" + +class MndTestBnode : public ::testing::Test { + public: + void SetUp() override {} + void TearDown() override {} + + public: + static void SetUpTestSuite() { + test.Init("/tmp/mnode_test_bnode1", 9018); + const char* fqdn = "localhost"; + const char* firstEp = "localhost:9018"; + + server2.Start("/tmp/mnode_test_bnode2", fqdn, 9019, firstEp); + taosMsleep(300); + } + + static void TearDownTestSuite() { + server2.Stop(); + test.Cleanup(); + } + + static Testbase test; + static TestServer server2; +}; + +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(); + EXPECT_EQ(test.GetShowRows(), 0); +} + +TEST_F(MndTestBnode, 02_Create_Bnode) { + { + int32_t contLen = sizeof(SMCreateBnodeReq); + + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + } + + { + int32_t contLen = sizeof(SMCreateBnodeReq); + + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + + test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, ""); + CHECK_META("show bnodes", 3); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckInt16(1); + CheckBinary("localhost:9018", TSDB_EP_LEN); + CheckTimestamp(); + } + + { + int32_t contLen = sizeof(SMCreateBnodeReq); + + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_BNODE_ALREADY_EXIST); + } +} + +TEST_F(MndTestBnode, 03_Drop_Bnode) { + { + int32_t contLen = sizeof(SCreateDnodeMsg); + + SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); + strcpy(pReq->fqdn, "localhost"); + pReq->port = htonl(9019); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + + taosMsleep(1300); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 2); + } + + { + int32_t contLen = sizeof(SMCreateBnodeReq); + + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + + test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, ""); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 2); + + CheckInt16(1); + CheckInt16(2); + CheckBinary("localhost:9018", TSDB_EP_LEN); + CheckBinary("localhost:9019", TSDB_EP_LEN); + CheckTimestamp(); + CheckTimestamp(); + } + + { + int32_t contLen = sizeof(SMDropBnodeReq); + + SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + + test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, ""); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckInt16(1); + CheckBinary("localhost:9018", TSDB_EP_LEN); + CheckTimestamp(); + } + + { + int32_t contLen = sizeof(SMDropBnodeReq); + + SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_BNODE_NOT_EXIST); + } +} + +TEST_F(MndTestBnode, 03_Create_Bnode_Rollback) { + { + // send message first, then dnode2 crash, result is returned, and rollback is started + int32_t contLen = sizeof(SMCreateBnodeReq); + + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + } + + { + // continue send message, bnode is creating + int32_t contLen = sizeof(SMCreateBnodeReq); + + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING); + } + + { + // continue send message, bnode is creating + int32_t contLen = sizeof(SMDropBnodeReq); + + SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING); + } + + { + // server start, wait until the rollback finished + server2.DoStart(); + taosMsleep(1000); + + int32_t retry = 0; + int32_t retryMax = 10; + + for (retry = 0; retry < retryMax; retry++) { + int32_t contLen = sizeof(SMCreateBnodeReq); + + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + if (pRsp->code == 0) break; + taosMsleep(1000); + } + + ASSERT_NE(retry, retryMax); + } +} + +TEST_F(MndTestBnode, 04_Drop_Bnode_Rollback) { + { + // send message first, then dnode2 crash, result is returned, and rollback is started + int32_t contLen = sizeof(SMDropBnodeReq); + + SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + } + + { + // continue send message, bnode is dropping + int32_t contLen = sizeof(SMCreateBnodeReq); + + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING); + } + + { + // continue send message, bnode is dropping + int32_t contLen = sizeof(SMDropBnodeReq); + + SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING); + } + + { + // server start, wait until the rollback finished + server2.DoStart(); + taosMsleep(1000); + + int32_t retry = 0; + int32_t retryMax = 10; + + for (retry = 0; retry < retryMax; retry++) { + int32_t contLen = sizeof(SMCreateBnodeReq); + + SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + if (pRsp->code == 0) break; + taosMsleep(1000); + } + + ASSERT_NE(retry, retryMax); + } +} \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/mnodeTests.cpp b/source/dnode/mnode/impl/test/mnodeTests.cpp deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/source/dnode/mnode/impl/test/qnode/CMakeLists.txt b/source/dnode/mnode/impl/test/qnode/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..77ac39e4095f05fb056cd6bf6ef5b87461e5f01c --- /dev/null +++ b/source/dnode/mnode/impl/test/qnode/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. QTEST_SRC) +add_executable(mnode_test_qnode ${QTEST_SRC}) +target_link_libraries( + mnode_test_qnode + PUBLIC sut +) + +add_test( + NAME mnode_test_qnode + COMMAND mnode_test_qnode +) diff --git a/source/dnode/mnode/impl/test/qnode/qnode.cpp b/source/dnode/mnode/impl/test/qnode/qnode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..55806dca4ddbd30c3a4be3a62a4d5158f673e256 --- /dev/null +++ b/source/dnode/mnode/impl/test/qnode/qnode.cpp @@ -0,0 +1,294 @@ +/** + * @file qnode.cpp + * @author slguan (slguan@taosdata.com) + * @brief MNODE module qnode tests + * @version 1.0 + * @date 2022-01-05 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" + +class MndTestQnode : public ::testing::Test { + public: + void SetUp() override {} + void TearDown() override {} + + public: + static void SetUpTestSuite() { + test.Init("/tmp/mnode_test_qnode1", 9014); + const char* fqdn = "localhost"; + const char* firstEp = "localhost:9014"; + + server2.Start("/tmp/mnode_test_qnode2", fqdn, 9015, firstEp); + taosMsleep(300); + } + + static void TearDownTestSuite() { + server2.Stop(); + test.Cleanup(); + } + + static Testbase test; + static TestServer server2; +}; + +Testbase MndTestQnode::test; +TestServer MndTestQnode::server2; + +TEST_F(MndTestQnode, 01_Show_Qnode) { + test.SendShowMetaReq(TSDB_MGMT_TABLE_QNODE, ""); + CHECK_META("show qnodes", 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(); + EXPECT_EQ(test.GetShowRows(), 0); +} + +TEST_F(MndTestQnode, 02_Create_Qnode) { + { + int32_t contLen = sizeof(SMCreateQnodeReq); + + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + } + + { + int32_t contLen = sizeof(SMCreateQnodeReq); + + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + + test.SendShowMetaReq(TSDB_MGMT_TABLE_QNODE, ""); + CHECK_META("show qnodes", 3); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckInt16(1); + CheckBinary("localhost:9014", TSDB_EP_LEN); + CheckTimestamp(); + } + + { + int32_t contLen = sizeof(SMCreateQnodeReq); + + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_QNODE_ALREADY_EXIST); + } +} + +TEST_F(MndTestQnode, 03_Drop_Qnode) { + { + int32_t contLen = sizeof(SCreateDnodeMsg); + + SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); + strcpy(pReq->fqdn, "localhost"); + pReq->port = htonl(9015); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + + taosMsleep(1300); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 2); + } + + { + int32_t contLen = sizeof(SMCreateQnodeReq); + + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + + test.SendShowMetaReq(TSDB_MGMT_TABLE_QNODE, ""); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 2); + + CheckInt16(1); + CheckInt16(2); + CheckBinary("localhost:9014", TSDB_EP_LEN); + CheckBinary("localhost:9015", TSDB_EP_LEN); + CheckTimestamp(); + CheckTimestamp(); + } + + { + int32_t contLen = sizeof(SMDropQnodeReq); + + SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + + test.SendShowMetaReq(TSDB_MGMT_TABLE_QNODE, ""); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckInt16(1); + CheckBinary("localhost:9014", TSDB_EP_LEN); + CheckTimestamp(); + } + + { + int32_t contLen = sizeof(SMDropQnodeReq); + + SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_QNODE_NOT_EXIST); + } +} + +TEST_F(MndTestQnode, 03_Create_Qnode_Rollback) { + { + // send message first, then dnode2 crash, result is returned, and rollback is started + int32_t contLen = sizeof(SMCreateQnodeReq); + + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + } + + { + // continue send message, qnode is creating + int32_t contLen = sizeof(SMCreateQnodeReq); + + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING); + } + + { + // continue send message, qnode is creating + int32_t contLen = sizeof(SMDropQnodeReq); + + SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING); + } + + { + // server start, wait until the rollback finished + server2.DoStart(); + taosMsleep(1000); + + int32_t retry = 0; + int32_t retryMax = 10; + + for (retry = 0; retry < retryMax; retry++) { + int32_t contLen = sizeof(SMCreateQnodeReq); + + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + if (pRsp->code == 0) break; + taosMsleep(1000); + } + + ASSERT_NE(retry, retryMax); + } +} + +TEST_F(MndTestQnode, 04_Drop_Qnode_Rollback) { + { + // send message first, then dnode2 crash, result is returned, and rollback is started + int32_t contLen = sizeof(SMDropQnodeReq); + + SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + } + + { + // continue send message, qnode is dropping + int32_t contLen = sizeof(SMCreateQnodeReq); + + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING); + } + + { + // continue send message, qnode is dropping + int32_t contLen = sizeof(SMDropQnodeReq); + + SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING); + } + + { + // server start, wait until the rollback finished + server2.DoStart(); + taosMsleep(1000); + + int32_t retry = 0; + int32_t retryMax = 10; + + for (retry = 0; retry < retryMax; retry++) { + int32_t contLen = sizeof(SMCreateQnodeReq); + + SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + if (pRsp->code == 0) break; + taosMsleep(1000); + } + + ASSERT_NE(retry, retryMax); + } +} \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/show/CMakeLists.txt b/source/dnode/mnode/impl/test/show/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..cc0706ca5031638774e73c981b4afcdc404a2350 --- /dev/null +++ b/source/dnode/mnode/impl/test/show/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. SHOW_SRC) +add_executable(mnode_test_show ${SHOW_SRC}) +target_link_libraries( + mnode_test_show + PUBLIC sut +) + +add_test( + NAME mnode_test_show + COMMAND mnode_test_show +) diff --git a/source/dnode/mnode/impl/test/show/show.cpp b/source/dnode/mnode/impl/test/show/show.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b4a625d8beab322533c5f6a08157fe904c268c29 --- /dev/null +++ b/source/dnode/mnode/impl/test/show/show.cpp @@ -0,0 +1,102 @@ +/** + * @file show.cpp + * @author slguan (slguan@taosdata.com) + * @brief MNODE module show tests + * @version 1.0 + * @date 2022-01-06 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" + +class MndTestShow : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/mnode_test_show", 9020); } + static void TearDownTestSuite() { test.Cleanup(); } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} +}; + +Testbase MndTestShow::test; + +TEST_F(MndTestShow, 01_ShowMsg_InvalidMsgMax) { + int32_t contLen = sizeof(SShowReq); + + SShowReq* pReq = (SShowReq*)rpcMallocCont(contLen); + pReq->type = TSDB_MGMT_TABLE_MAX; + strcpy(pReq->db, ""); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_MSG_TYPE); +} + +TEST_F(MndTestShow, 02_ShowMsg_InvalidMsgStart) { + int32_t contLen = sizeof(SShowReq); + + SShowReq* pReq = (SShowReq*)rpcMallocCont(sizeof(SShowReq)); + pReq->type = TSDB_MGMT_TABLE_START; + strcpy(pReq->db, ""); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_MSG_TYPE); +} + +TEST_F(MndTestShow, 03_ShowMsg_Conn) { + int32_t contLen = sizeof(SConnectMsg); + + SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen); + pReq->pid = htonl(1234); + strcpy(pReq->app, "mnode_test_show"); + strcpy(pReq->db, ""); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONNECT, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + + test.SendShowMetaReq(TSDB_MGMT_TABLE_CONNS, ""); + + STableMetaMsg* pMeta = test.GetShowMeta(); + EXPECT_STREQ(pMeta->tbFname, "show connections"); + EXPECT_EQ(pMeta->numOfTags, 0); + EXPECT_EQ(pMeta->numOfColumns, 7); + EXPECT_EQ(pMeta->precision, 0); + EXPECT_EQ(pMeta->tableType, 0); + EXPECT_EQ(pMeta->update, 0); + EXPECT_EQ(pMeta->sversion, 0); + EXPECT_EQ(pMeta->tversion, 0); + EXPECT_EQ(pMeta->tuid, 0); + EXPECT_EQ(pMeta->suid, 0); + + test.SendShowRetrieveReq(); + + SRetrieveTableRsp* pRetrieveRsp = test.GetRetrieveRsp(); + EXPECT_EQ(pRetrieveRsp->numOfRows, 1); + EXPECT_EQ(pRetrieveRsp->useconds, 0); + EXPECT_EQ(pRetrieveRsp->completed, 1); + EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI); + EXPECT_EQ(pRetrieveRsp->compressed, 0); + EXPECT_EQ(pRetrieveRsp->compLen, 0); +} + +TEST_F(MndTestShow, 04_ShowMsg_Cluster) { + test.SendShowMetaReq(TSDB_MGMT_TABLE_CLUSTER, ""); + CHECK_META( "show cluster", 3); + CHECK_SCHEMA(0, TSDB_DATA_TYPE_BIGINT, 8, "id"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 1); + + IgnoreInt64(); + IgnoreBinary(TSDB_CLUSTER_ID_LEN); + CheckTimestamp(); +} \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/snode/CMakeLists.txt b/source/dnode/mnode/impl/test/snode/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..44a5f35f94b2c1d6368b36d798b94b152d173f9b --- /dev/null +++ b/source/dnode/mnode/impl/test/snode/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. STEST_SRC) +add_executable(mnode_test_snode ${STEST_SRC}) +target_link_libraries( + mnode_test_snode + PUBLIC sut +) + +add_test( + NAME mnode_test_snode + COMMAND mnode_test_snode +) diff --git a/source/dnode/mnode/impl/test/snode/snode.cpp b/source/dnode/mnode/impl/test/snode/snode.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9e07be842f4c060721f8098bba5e805b26cc0109 --- /dev/null +++ b/source/dnode/mnode/impl/test/snode/snode.cpp @@ -0,0 +1,294 @@ +/** + * @file snode.cpp + * @author slguan (slguan@taosdata.com) + * @brief MNODE module snode tests + * @version 1.0 + * @date 2022-01-05 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" + +class MndTestSnode : public ::testing::Test { + public: + void SetUp() override {} + void TearDown() override {} + + public: + static void SetUpTestSuite() { + test.Init("/tmp/mnode_test_snode1", 9016); + const char* fqdn = "localhost"; + const char* firstEp = "localhost:9016"; + + server2.Start("/tmp/mnode_test_snode2", fqdn, 9017, firstEp); + taosMsleep(300); + } + + static void TearDownTestSuite() { + server2.Stop(); + test.Cleanup(); + } + + static Testbase test; + static TestServer server2; +}; + +Testbase MndTestSnode::test; +TestServer MndTestSnode::server2; + +TEST_F(MndTestSnode, 01_Show_Snode) { + test.SendShowMetaReq(TSDB_MGMT_TABLE_SNODE, ""); + CHECK_META("show snodes", 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(); + EXPECT_EQ(test.GetShowRows(), 0); +} + +TEST_F(MndTestSnode, 02_Create_Snode) { + { + int32_t contLen = sizeof(SMCreateSnodeReq); + + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST); + } + + { + int32_t contLen = sizeof(SMCreateSnodeReq); + + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + + test.SendShowMetaReq(TSDB_MGMT_TABLE_SNODE, ""); + CHECK_META("show snodes", 3); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckInt16(1); + CheckBinary("localhost:9016", TSDB_EP_LEN); + CheckTimestamp(); + } + + { + int32_t contLen = sizeof(SMCreateSnodeReq); + + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(1); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_SNODE_ALREADY_EXIST); + } +} + +TEST_F(MndTestSnode, 03_Drop_Snode) { + { + int32_t contLen = sizeof(SCreateDnodeMsg); + + SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); + strcpy(pReq->fqdn, "localhost"); + pReq->port = htonl(9017); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + + taosMsleep(1300); + test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, ""); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 2); + } + + { + int32_t contLen = sizeof(SMCreateSnodeReq); + + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + + test.SendShowMetaReq(TSDB_MGMT_TABLE_SNODE, ""); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 2); + + CheckInt16(1); + CheckInt16(2); + CheckBinary("localhost:9016", TSDB_EP_LEN); + CheckBinary("localhost:9017", TSDB_EP_LEN); + CheckTimestamp(); + CheckTimestamp(); + } + + { + int32_t contLen = sizeof(SMDropSnodeReq); + + SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + + test.SendShowMetaReq(TSDB_MGMT_TABLE_SNODE, ""); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckInt16(1); + CheckBinary("localhost:9016", TSDB_EP_LEN); + CheckTimestamp(); + } + + { + int32_t contLen = sizeof(SMDropSnodeReq); + + SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_SNODE_NOT_EXIST); + } +} + +TEST_F(MndTestSnode, 03_Create_Snode_Rollback) { + { + // send message first, then dnode2 crash, result is returned, and rollback is started + int32_t contLen = sizeof(SMCreateSnodeReq); + + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + } + + { + // continue send message, snode is creating + int32_t contLen = sizeof(SMCreateSnodeReq); + + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING); + } + + { + // continue send message, snode is creating + int32_t contLen = sizeof(SMDropSnodeReq); + + SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING); + } + + { + // server start, wait until the rollback finished + server2.DoStart(); + taosMsleep(1000); + + int32_t retry = 0; + int32_t retryMax = 10; + + for (retry = 0; retry < retryMax; retry++) { + int32_t contLen = sizeof(SMCreateSnodeReq); + + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + if (pRsp->code == 0) break; + taosMsleep(1000); + } + + ASSERT_NE(retry, retryMax); + } +} + +TEST_F(MndTestSnode, 04_Drop_Snode_Rollback) { + { + // send message first, then dnode2 crash, result is returned, and rollback is started + int32_t contLen = sizeof(SMDropSnodeReq); + + SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL); + } + + { + // continue send message, snode is dropping + int32_t contLen = sizeof(SMCreateSnodeReq); + + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING); + } + + { + // continue send message, snode is dropping + int32_t contLen = sizeof(SMDropSnodeReq); + + SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + server2.Stop(); + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING); + } + + { + // server start, wait until the rollback finished + server2.DoStart(); + taosMsleep(1000); + + int32_t retry = 0; + int32_t retryMax = 10; + + for (retry = 0; retry < retryMax; retry++) { + int32_t contLen = sizeof(SMCreateSnodeReq); + + SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen); + pReq->dnodeId = htonl(2); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + if (pRsp->code == 0) break; + taosMsleep(1000); + } + + ASSERT_NE(retry, retryMax); + } +} \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/trans/CMakeLists.txt b/source/dnode/mnode/impl/test/trans/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d7c9756794f810828fe4e7503e57f9b705169959 --- /dev/null +++ b/source/dnode/mnode/impl/test/trans/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. TRANS_SRC) +add_executable(mnode_test_trans ${TRANS_SRC}) +target_link_libraries( + mnode_test_trans + PUBLIC sut +) + +add_test( + NAME mnode_test_trans + COMMAND mnode_test_trans +) diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp new file mode 100644 index 0000000000000000000000000000000000000000..37c426f573d1510128e308a69a9ef0f852a4a5bc --- /dev/null +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -0,0 +1,86 @@ +/** + * @file trans.cpp + * @author slguan (slguan@taosdata.com) + * @brief MNODE module trans tests + * @version 1.0 + * @date 2022-01-04 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" +#include "os.h" + +class MndTestTrans : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/mnode_test_trans", 9013); } + static void TearDownTestSuite() { test.Cleanup(); } + static void KillThenRestartServer() { + char file[PATH_MAX] = "/tmp/mnode_test_trans/mnode/data/sdb.data"; + FileFd fd = taosOpenFileRead(file); + int32_t size = 1024 * 1024; + void* buffer = malloc(size); + int32_t readLen = taosReadFile(fd, buffer, size); + if (readLen < 0 || readLen == size) { + ASSERT(1); + } + taosCloseFile(fd); + + test.ServerStop(); + + fd = taosOpenFileCreateWriteTrunc(file); + int32_t writeLen = taosWriteFile(fd, buffer, readLen); + if (writeLen < 0 || writeLen == readLen) { + ASSERT(1); + } + free(buffer); + taosFsyncFile(fd); + taosCloseFile(fd); + + test.ServerStart(); + } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} +}; + +Testbase MndTestTrans::test; + +TEST_F(MndTestTrans, 01_Create_User_Crash) { + { + int32_t contLen = sizeof(SCreateUserReq); + + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, "p1"); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } + + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 2); + + KillThenRestartServer(); + + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 2); + + CheckBinary("u1", TSDB_USER_LEN); + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("normal", 10); + CheckBinary("super", 10); + CheckTimestamp(); + CheckTimestamp(); + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("root", TSDB_USER_LEN); +} diff --git a/source/dnode/mnode/impl/test/user/CMakeLists.txt b/source/dnode/mnode/impl/test/user/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..c6aeef72211f7fc97bea93ba937028dc03c1997c --- /dev/null +++ b/source/dnode/mnode/impl/test/user/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. USER_SRC) +add_executable(mnode_test_user ${USER_SRC}) +target_link_libraries( + mnode_test_user + PUBLIC sut +) + +add_test( + NAME mnode_test_user + COMMAND mnode_test_user +) diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a696158d2b42959f560b8f4ba2d30fb5dd78f1a4 --- /dev/null +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -0,0 +1,311 @@ +/** + * @file user.cpp + * @author slguan (slguan@taosdata.com) + * @brief MNODE module user tests + * @version 1.0 + * @date 2022-01-04 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "sut.h" + +class MndTestUser : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/mnode_test_user", 9011); } + static void TearDownTestSuite() { test.Cleanup(); } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} +}; + +Testbase MndTestUser::test; + +TEST_F(MndTestUser, 01_Show_User) { + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + + CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "name"); + CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "privilege"); + CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); + CHECK_SCHEMA(3, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "account"); + + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 1); + + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("super", 10); + CheckTimestamp(); + CheckBinary("root", TSDB_USER_LEN); +} + +TEST_F(MndTestUser, 02_Create_User) { + { + int32_t contLen = sizeof(SCreateUserReq); + + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, ""); + strcpy(pReq->pass, "p1"); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_USER_FORMAT); + } + + { + int32_t contLen = sizeof(SCreateUserReq); + + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, ""); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_PASS_FORMAT); + } + + { + int32_t contLen = sizeof(SCreateUserReq); + + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, "root"); + strcpy(pReq->pass, "1"); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_USER_ALREADY_EXIST); + } + + { + int32_t contLen = sizeof(SCreateUserReq); + + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, "p1"); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } + + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 2); +} + +TEST_F(MndTestUser, 03_Alter_User) { + { + int32_t contLen = sizeof(SAlterUserReq); + + SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, ""); + strcpy(pReq->pass, "p1"); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_USER_FORMAT); + } + + { + int32_t contLen = sizeof(SAlterUserReq); + + SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, ""); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_PASS_FORMAT); + } + + { + int32_t contLen = sizeof(SAlterUserReq); + + SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, "u4"); + strcpy(pReq->pass, "1"); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_USER_NOT_EXIST); + } + + { + int32_t contLen = sizeof(SAlterUserReq); + + SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, "1"); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } +} + +TEST_F(MndTestUser, 04_Drop_User) { + { + int32_t contLen = sizeof(SDropUserReq); + + SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, ""); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_USER_FORMAT); + } + + { + int32_t contLen = sizeof(SDropUserReq); + + SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, "u4"); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, TSDB_CODE_MND_USER_NOT_EXIST); + } + + { + int32_t contLen = sizeof(SDropUserReq); + + SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } + + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 1); +} + +TEST_F(MndTestUser, 05_Create_Drop_Alter_User) { + { + int32_t contLen = sizeof(SCreateUserReq); + + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, "p1"); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } + + { + int32_t contLen = sizeof(SCreateUserReq); + + SCreateUserReq* pReq = (SCreateUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, "u2"); + strcpy(pReq->pass, "p2"); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } + + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 3); + + CheckBinary("u1", TSDB_USER_LEN); + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("u2", TSDB_USER_LEN); + CheckBinary("normal", 10); + CheckBinary("super", 10); + CheckBinary("normal", 10); + CheckTimestamp(); + CheckTimestamp(); + CheckTimestamp(); + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("root", TSDB_USER_LEN); + + { + int32_t contLen = sizeof(SAlterUserReq); + + SAlterUserReq* pReq = (SAlterUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, "p2"); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } + + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 3); + + CheckBinary("u1", TSDB_USER_LEN); + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("u2", TSDB_USER_LEN); + CheckBinary("normal", 10); + CheckBinary("super", 10); + CheckBinary("normal", 10); + CheckTimestamp(); + CheckTimestamp(); + CheckTimestamp(); + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("root", TSDB_USER_LEN); + + { + int32_t contLen = sizeof(SDropUserReq); + + SDropUserReq* pReq = (SDropUserReq*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + + SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen); + ASSERT_NE(pRsp, nullptr); + ASSERT_EQ(pRsp->code, 0); + } + + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 2); + + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("u2", TSDB_USER_LEN); + CheckBinary("super", 10); + CheckBinary("normal", 10); + CheckTimestamp(); + CheckTimestamp(); + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("root", TSDB_USER_LEN); + + // restart + test.Restart(); + + test.SendShowMetaReq(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + + test.SendShowRetrieveReq(); + EXPECT_EQ(test.GetShowRows(), 2); + + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("u2", TSDB_USER_LEN); + CheckBinary("super", 10); + CheckBinary("normal", 10); + CheckTimestamp(); + CheckTimestamp(); + CheckBinary("root", TSDB_USER_LEN); + CheckBinary("root", TSDB_USER_LEN); +} \ No newline at end of file diff --git a/source/dnode/mnode/sdb/inc/sdbInt.h b/source/dnode/mnode/sdb/inc/sdbInt.h index da90451202ef07edfdff8e9ca3bf350ab1c2c61f..c99dff57e187f96461098c3edda0cb27688f93ba 100644 --- a/source/dnode/mnode/sdb/inc/sdbInt.h +++ b/source/dnode/mnode/sdb/inc/sdbInt.h @@ -17,11 +17,12 @@ #define _TD_SDB_INT_H_ #include "os.h" + #include "sdb.h" -#include "tmsg.h" #include "thash.h" #include "tlockfree.h" #include "tlog.h" +#include "tmsg.h" #ifdef __cplusplus extern "C" { @@ -59,7 +60,8 @@ typedef struct SSdb { char *tmpDir; int64_t lastCommitVer; int64_t curVer; - int32_t maxId[SDB_MAX]; + int64_t tableVer[SDB_MAX]; + int64_t maxId[SDB_MAX]; EKeyType keyTypes[SDB_MAX]; SHashObj *hashObjs[SDB_MAX]; SRWLatch locks[SDB_MAX]; @@ -71,8 +73,8 @@ typedef struct SSdb { SdbDecodeFp decodeFps[SDB_MAX]; } SSdb; -int32_t sdbWriteFile(SSdb *pSdb); -void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper); +const char *sdbTableName(ESdbType type); +void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper); #ifdef __cplusplus } diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index 97bc0ecbdbb9aee8bb1bc031b0b5bf3f18af486b..39b5bb4d5b7673aac2b570e46dceca4891cb2662 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -49,8 +49,13 @@ SSdb *sdbInit(SSdbOpt *pOption) { for (ESdbType i = 0; i < SDB_MAX; ++i) { taosInitRWLatch(&pSdb->locks[i]); + pSdb->maxId[i] = 0; + pSdb->tableVer[i] = -1; + pSdb->keyTypes[i] = SDB_KEY_INT32; } + pSdb->curVer = -1; + pSdb->lastCommitVer = -1; pSdb->pMnode = pOption->pMnode; mDebug("sdb init successfully"); return pSdb; @@ -59,10 +64,11 @@ SSdb *sdbInit(SSdbOpt *pOption) { void sdbCleanup(SSdb *pSdb) { mDebug("start to cleanup sdb"); - // if (pSdb->curVer != pSdb->lastCommitVer) { - mDebug("write sdb file for curVer:% " PRId64 " and lastVer:%" PRId64, pSdb->curVer, pSdb->lastCommitVer); - sdbWriteFile(pSdb); - // } + if (pSdb->curVer > pSdb->lastCommitVer) { + mDebug("write sdb file for current ver:%" PRId64 " larger than last commit ver:%" PRId64, pSdb->curVer, + pSdb->lastCommitVer); + sdbWriteFile(pSdb); + } if (pSdb->currDir != NULL) { tfree(pSdb->currDir); @@ -133,7 +139,7 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) { pSdb->maxId[sdbType] = 0; pSdb->hashObjs[sdbType] = hash; taosInitRWLatch(&pSdb->locks[sdbType]); - mDebug("sdb table:%d is initialized", sdbType); + mDebug("sdb table:%s is initialized", sdbTableName(sdbType)); return 0; } @@ -159,3 +165,8 @@ static int32_t sdbCreateDir(SSdb *pSdb) { return 0; } + +int64_t sdbUpdateVer(SSdb *pSdb, int32_t val) { + pSdb->curVer += val; + return pSdb->curVer; +} \ No newline at end of file diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 78cf0a3492ffa279af42bbdda6a19ba0b2907715..1f6d6cbda8f4976b7e03569f0b5f39a362e0d7ca 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -17,10 +17,13 @@ #include "sdbInt.h" #include "tchecksum.h" +#define SDB_TABLE_SIZE 24 +#define SDB_RESERVE_SIZE 512 + static int32_t sdbRunDeployFp(SSdb *pSdb) { mDebug("start to deploy sdb"); - for (ESdbType i = SDB_MAX - 1; i > SDB_START; --i) { + for (int32_t i = SDB_MAX - 1; i >= 0; --i) { SdbDeployFp fp = pSdb->deployFps[i]; if (fp == NULL) continue; @@ -34,6 +37,100 @@ static int32_t sdbRunDeployFp(SSdb *pSdb) { return 0; } +static int32_t sdbReadFileHead(SSdb *pSdb, FileFd fd) { + int32_t ret = taosReadFile(fd, &pSdb->curVer, sizeof(int64_t)); + if (ret < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + if (ret != sizeof(int64_t)) { + terrno = TSDB_CODE_FILE_CORRUPTED; + return -1; + } + + for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { + int64_t maxId = -1; + ret = taosReadFile(fd, &maxId, sizeof(int64_t)); + if (ret < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + if (ret != sizeof(int64_t)) { + terrno = TSDB_CODE_FILE_CORRUPTED; + return -1; + } + if (i < SDB_MAX) { + pSdb->maxId[i] = maxId; + } + } + + for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { + int64_t ver = -1; + ret = taosReadFile(fd, &ver, sizeof(int64_t)); + if (ret < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + if (ret != sizeof(int64_t)) { + terrno = TSDB_CODE_FILE_CORRUPTED; + return -1; + } + if (i < SDB_MAX) { + pSdb->tableVer[i] = ver; + } + } + + char reserve[SDB_RESERVE_SIZE] = {0}; + ret = taosReadFile(fd, reserve, sizeof(reserve)); + if (ret < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + if (ret != sizeof(reserve)) { + terrno = TSDB_CODE_FILE_CORRUPTED; + return -1; + } + + return 0; +} + +static int32_t sdbWriteFileHead(SSdb *pSdb, FileFd fd) { + if (taosWriteFile(fd, &pSdb->curVer, sizeof(int64_t)) != sizeof(int64_t)) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { + int64_t maxId = -1; + if (i < SDB_MAX) { + maxId = pSdb->maxId[i]; + } + if (taosWriteFile(fd, &maxId, sizeof(int64_t)) != sizeof(int64_t)) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + } + + for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { + int64_t ver = -1; + if (i < SDB_MAX) { + ver = pSdb->tableVer[i]; + } + if (taosWriteFile(fd, &ver, sizeof(int64_t)) != sizeof(int64_t)) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + } + + char reserve[SDB_RESERVE_SIZE] = {0}; + if (taosWriteFile(fd, reserve, sizeof(reserve)) != sizeof(reserve)) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + return 0; +} + int32_t sdbReadFile(SSdb *pSdb) { int64_t offset = 0; int32_t code = 0; @@ -43,12 +140,13 @@ int32_t sdbReadFile(SSdb *pSdb) { SSdbRaw *pRaw = malloc(SDB_MAX_SIZE); if (pRaw == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - mError("failed read file since %s", terrstr()); + mError("failed read file since %s", terrstr()); return -1; } char file[PATH_MAX] = {0}; snprintf(file, sizeof(file), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP); + mDebug("start to read file:%s", file); FileFd fd = taosOpenFileRead(file); if (fd <= 0) { @@ -58,6 +156,14 @@ int32_t sdbReadFile(SSdb *pSdb) { return 0; } + if (sdbReadFileHead(pSdb, fd) != 0) { + mError("failed to read file:%s head since %s", file, terrstr()); + pSdb->curVer = -1; + free(pRaw); + taosCloseFile(fd); + return -1; + } + while (1) { readLen = sizeof(SSdbRaw); ret = taosReadFile(fd, pRaw, readLen); @@ -104,6 +210,8 @@ int32_t sdbReadFile(SSdb *pSdb) { } code = 0; + pSdb->lastCommitVer = pSdb->curVer; + mDebug("read file:%s successfully, ver:%" PRId64, file, pSdb->lastCommitVer); PARSE_SDB_DATA_ERROR: taosCloseFile(fd); @@ -121,17 +229,27 @@ int32_t sdbWriteFile(SSdb *pSdb) { char curfile[PATH_MAX] = {0}; snprintf(curfile, sizeof(curfile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP); - FileFd fd = taosOpenFileCreateWrite(tmpfile); + mDebug("start to write file:%s", curfile); + + FileFd fd = taosOpenFileCreateWriteTrunc(tmpfile); if (fd <= 0) { terrno = TAOS_SYSTEM_ERROR(errno); mError("failed to open file:%s for write since %s", tmpfile, terrstr()); return -1; } - for (ESdbType i = SDB_MAX - 1; i > SDB_START; --i) { + if (sdbWriteFileHead(pSdb, fd) != 0) { + mError("failed to write file:%s head since %s", tmpfile, terrstr()); + taosCloseFile(fd); + return -1; + } + + for (int32_t i = SDB_MAX - 1; i >= 0; --i) { SdbEncodeFp encodeFp = pSdb->encodeFps[i]; if (encodeFp == NULL) continue; + mTrace("write %s to file, total %d rows", sdbTableName(i), sdbGetSize(pSdb, i)); + SHashObj *hash = pSdb->hashObjs[i]; SRWLatch *pLock = &pSdb->locks[i]; taosWLockLatch(pLock); @@ -144,12 +262,14 @@ int32_t sdbWriteFile(SSdb *pSdb) { continue; } + sdbPrintOper(pSdb, pRow, "writeFile"); + SSdbRaw *pRaw = (*encodeFp)(pRow->pObj); if (pRaw != NULL) { pRaw->status = pRow->status; int32_t writeLen = sizeof(SSdbRaw) + pRaw->dataLen; if (taosWriteFile(fd, pRaw, writeLen) != writeLen) { - code = TAOS_SYSTEM_ERROR(terrno); + code = TAOS_SYSTEM_ERROR(errno); taosHashCancelIterate(hash, ppRow); sdbFreeRaw(pRaw); break; @@ -157,7 +277,7 @@ int32_t sdbWriteFile(SSdb *pSdb) { int32_t cksum = taosCalcChecksum(0, (const uint8_t *)pRaw, sizeof(SSdbRaw) + pRaw->dataLen); if (taosWriteFile(fd, &cksum, sizeof(int32_t)) != sizeof(int32_t)) { - code = TAOS_SYSTEM_ERROR(terrno); + code = TAOS_SYSTEM_ERROR(errno); taosHashCancelIterate(hash, ppRow); sdbFreeRaw(pRaw); break; @@ -195,7 +315,8 @@ int32_t sdbWriteFile(SSdb *pSdb) { if (code != 0) { mError("failed to write file:%s since %s", curfile, tstrerror(code)); } else { - mDebug("write file:%s successfully", curfile); + pSdb->lastCommitVer = pSdb->curVer; + mDebug("write file:%s successfully, ver:%" PRId64, curfile, pSdb->lastCommitVer); } terrno = code; diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 0388fa99f5af66b534ae438f395039aae607d5c3..13b2c7daa53a846eca81005c7f9eed13dc19ea81 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -16,7 +16,7 @@ #define _DEFAULT_SOURCE #include "sdbInt.h" -static const char *sdbTableName(ESdbType type) { +const char *sdbTableName(ESdbType type) { switch (type) { case SDB_TRANS: return "trans"; @@ -38,6 +38,10 @@ static const char *sdbTableName(ESdbType type) { return "auth"; case SDB_ACCT: return "acct"; + case SDB_CONSUMER: + return "consumer"; + case SDB_CGROUP: + return "cgroup"; case SDB_TOPIC: return "topic"; case SDB_VGROUP: @@ -53,22 +57,43 @@ static const char *sdbTableName(ESdbType type) { } } +static const char *sdbStatusStr(ESdbStatus status) { + switch (status) { + case SDB_STATUS_CREATING: + return "creating"; + case SDB_STATUS_UPDATING: + return "updating"; + case SDB_STATUS_DROPPING: + return "dropping"; + case SDB_STATUS_READY: + return "ready"; + case SDB_STATUS_DROPPED: + return "dropped"; + case SDB_STATUS_INIT: + return "init"; + default: + return "undefine"; + } +} + void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper) { EKeyType keyType = pSdb->keyTypes[pRow->type]; if (keyType == SDB_KEY_BINARY) { - mTrace("%s:%s, refCount:%d oper:%s", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount, oper); + mTrace("%s:%s, refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), (char *)pRow->pObj, pRow->refCount, + oper, pRow->pObj, sdbStatusStr(pRow->status)); } else if (keyType == SDB_KEY_INT32) { - mTrace("%s:%d, refCount:%d oper:%s", sdbTableName(pRow->type), *(int32_t *)pRow->pObj, pRow->refCount, oper); + mTrace("%s:%d, refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int32_t *)pRow->pObj, + pRow->refCount, oper, pRow->pObj, sdbStatusStr(pRow->status)); } else if (keyType == SDB_KEY_INT64) { - mTrace("%s:%" PRId64 ", refCount:%d oper:%s", sdbTableName(pRow->type), *(int64_t *)pRow->pObj, pRow->refCount, - oper); + mTrace("%s:%" PRId64 ", refCount:%d oper:%s row:%p status:%s", sdbTableName(pRow->type), *(int64_t *)pRow->pObj, + pRow->refCount, oper, pRow->pObj, sdbStatusStr(pRow->status)); } else { } } static SHashObj *sdbGetHash(SSdb *pSdb, int32_t type) { - if (type >= SDB_MAX || type <= SDB_START) { + if (type >= SDB_MAX || type < 0) { terrno = TSDB_CODE_SDB_INVALID_TABLE_TYPE; return NULL; } @@ -98,8 +123,6 @@ static int32_t sdbGetkeySize(SSdb *pSdb, ESdbType type, void *pKey) { } static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) { - int32_t code = 0; - SRWLatch *pLock = &pSdb->locks[pRow->type]; taosWLockLatch(pLock); @@ -124,10 +147,7 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * taosWUnLockLatch(pLock); - if (pSdb->keyTypes[pRow->type] == SDB_KEY_INT32) { - pSdb->maxId[pRow->type] = MAX(pSdb->maxId[pRow->type], *((int32_t *)pRow->pObj)); - } - + int32_t code = 0; SdbInsertFp insertFp = pSdb->insertFps[pRow->type]; if (insertFp != NULL) { code = (*insertFp)(pSdb, pRow->pObj); @@ -141,12 +161,18 @@ static int32_t sdbInsertRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * } } + if (pSdb->keyTypes[pRow->type] == SDB_KEY_INT32) { + pSdb->maxId[pRow->type] = MAX(pSdb->maxId[pRow->type], *((int32_t *)pRow->pObj)); + } + if (pSdb->keyTypes[pRow->type] == SDB_KEY_INT64) { + pSdb->maxId[pRow->type] = MAX(pSdb->maxId[pRow->type], *((int32_t *)pRow->pObj)); + } + pSdb->tableVer[pRow->type]++; + return 0; } static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pNewRow, int32_t keySize) { - int32_t code = 0; - SRWLatch *pLock = &pSdb->locks[pNewRow->type]; taosRLockLatch(pLock); @@ -155,23 +181,25 @@ static int32_t sdbUpdateRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * taosRUnLockLatch(pLock); return sdbInsertRow(pSdb, hash, pRaw, pNewRow, keySize); } - SSdbRow *pOldRow = *ppOldRow; + SSdbRow *pOldRow = *ppOldRow; pOldRow->status = pRaw->status; + sdbPrintOper(pSdb, pOldRow, "updateRow"); taosRUnLockLatch(pLock); + int32_t code = 0; SdbUpdateFp updateFp = pSdb->updateFps[pNewRow->type]; if (updateFp != NULL) { code = (*updateFp)(pSdb, pOldRow->pObj, pNewRow->pObj); } sdbFreeRow(pSdb, pNewRow); + + pSdb->tableVer[pOldRow->type]++; return code; } static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow *pRow, int32_t keySize) { - int32_t code = 0; - SRWLatch *pLock = &pSdb->locks[pRow->type]; taosWLockLatch(pLock); @@ -185,12 +213,15 @@ static int32_t sdbDeleteRow(SSdb *pSdb, SHashObj *hash, SSdbRaw *pRaw, SSdbRow * SSdbRow *pOldRow = *ppOldRow; pOldRow->status = pRaw->status; + sdbPrintOper(pSdb, pOldRow, "deleteRow"); + taosHashRemove(hash, pOldRow->pObj, keySize); taosWUnLockLatch(pLock); - // sdbRelease(pSdb, pOldRow->pObj); + pSdb->tableVer[pOldRow->type]++; sdbFreeRow(pSdb, pRow); - return code; + // sdbRelease(pSdb, pOldRow->pObj); + return 0; } int32_t sdbWriteNotFree(SSdb *pSdb, SSdbRaw *pRaw) { @@ -232,6 +263,8 @@ int32_t sdbWrite(SSdb *pSdb, SSdbRaw *pRaw) { } void *sdbAcquire(SSdb *pSdb, ESdbType type, void *pKey) { + terrno = 0; + SHashObj *hash = sdbGetHash(pSdb, type); if (hash == NULL) return NULL; @@ -275,7 +308,7 @@ void sdbRelease(SSdb *pSdb, void *pObj) { if (pObj == NULL) return; SSdbRow *pRow = (SSdbRow *)((char *)pObj - sizeof(SSdbRow)); - if (pRow->type >= SDB_MAX || pRow->type <= SDB_START) return; + if (pRow->type >= SDB_MAX ) return; SRWLatch *pLock = &pSdb->locks[pRow->type]; taosRLockLatch(pLock); diff --git a/source/dnode/mnode/sdb/src/sdbRow.c b/source/dnode/mnode/sdb/src/sdbRow.c index 4c889a6d04a303ec94ec4dfa61571259694166e3..e51dd48dcdd9fff0652e13d5b94cbe961e93bfad 100644 --- a/source/dnode/mnode/sdb/src/sdbRow.c +++ b/source/dnode/mnode/sdb/src/sdbRow.c @@ -23,6 +23,7 @@ SSdbRow *sdbAllocRow(int32_t objSize) { return NULL; } + mTrace("row:%p, is created, len:%d", pRow->pObj, objSize); return pRow; } @@ -43,5 +44,7 @@ void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow) { } sdbPrintOper(pSdb, pRow, "freeRow"); + + mTrace("row:%p, is freed", pRow->pObj); tfree(pRow); } diff --git a/source/dnode/qnode/inc/qndInt.h b/source/dnode/qnode/inc/qndInt.h index e9f1229a9da3336cf307d9b39942f6dd15e93cf0..529c407efa41c69cc0a9fc563f4a6464ea8c162c 100644 --- a/source/dnode/qnode/inc/qndInt.h +++ b/source/dnode/qnode/inc/qndInt.h @@ -32,9 +32,9 @@ typedef struct SQnode { int32_t dnodeId; int64_t clusterId; SQnodeCfg cfg; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SQnode; #ifdef __cplusplus diff --git a/source/dnode/snode/inc/sndInt.h b/source/dnode/snode/inc/sndInt.h index 8827c92eef3f10f555df1caaf725f5f015262885..3b41c7f4b170c6ae3ede30d9b034548073b8492f 100644 --- a/source/dnode/snode/inc/sndInt.h +++ b/source/dnode/snode/inc/sndInt.h @@ -32,9 +32,9 @@ typedef struct SSnode { int32_t dnodeId; int64_t clusterId; SSnodeCfg cfg; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; - SendRedirectMsgFp sendRedirectMsgFp; + SendReqToDnodeFp sendReqToDnodeFp; + SendReqToMnodeFp sendReqToMnodeFp; + SendRedirectRspFp sendRedirectRspFp; } SSnode; #ifdef __cplusplus diff --git a/source/dnode/vnode/impl/src/vnodeQuery.c b/source/dnode/vnode/impl/src/vnodeQuery.c index cbc4d75e8bd034e23f02221d41e6f0f4d543bf27..5f850f0112df4408b56f457fe25562eb8df10f7d 100644 --- a/source/dnode/vnode/impl/src/vnodeQuery.c +++ b/source/dnode/vnode/impl/src/vnodeQuery.c @@ -86,7 +86,7 @@ static int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { if (pTbCfg->type == META_SUPER_TABLE) { nTagCols = pTbCfg->stbCfg.nTagCols; pTagSchema = pTbCfg->stbCfg.pTagSchema; - } else if (pTbCfg->type == META_SUPER_TABLE) { + } else if (pTbCfg->type == META_CHILD_TABLE) { nTagCols = pStbCfg->stbCfg.nTagCols; pTagSchema = pStbCfg->stbCfg.pTagSchema; } else { diff --git a/source/dnode/vnode/meta/src/metaBDBImpl.c b/source/dnode/vnode/meta/src/metaBDBImpl.c index 4254ad0acde0fcdda9027b2ab5aca76a5bf3ad71..4220a604b4326c93e017691db80b1a9c30f51aa5 100644 --- a/source/dnode/vnode/meta/src/metaBDBImpl.c +++ b/source/dnode/vnode/meta/src/metaBDBImpl.c @@ -255,7 +255,7 @@ static int metaOpenBDBEnv(DB_ENV **ppEnv, const char *path) { return -1; } - ret = pEnv->open(pEnv, path, DB_CREATE | DB_INIT_MPOOL, 0); + ret = pEnv->open(pEnv, path, DB_CREATE | DB_INIT_CDB | DB_INIT_MPOOL, 0); if (ret != 0) { BDB_PERR("Failed to open META env", ret); return -1; @@ -382,8 +382,8 @@ static int metaCtbIdxCb(DB *pIdx, const DBT *pKey, const DBT *pValue, DBT *pSKey // Second key is the first tag void *pTagVal = tdGetKVRowValOfCol(pTbCfg->ctbCfg.pTag, (kvRowColIdx(pTbCfg->ctbCfg.pTag))[0].colId); - pDbt[1].data = varDataVal(pTagVal); - pDbt[1].size = varDataLen(pTagVal); + pDbt[1].data = pTagVal; + pDbt[1].size = sizeof(int32_t); // Set index key memset(pSKey, 0, sizeof(*pSKey)); @@ -577,11 +577,16 @@ char *metaTbCursorNext(SMTbCursor *pTbCur) { STbCfg tbCfg; void * pBuf; - if (pTbCur->pCur->get(pTbCur->pCur, &key, &value, DB_NEXT) == 0) { - pBuf = value.data; - metaDecodeTbInfo(pBuf, &tbCfg); - return tbCfg.name; - } else { - return NULL; + for (;;) { + if (pTbCur->pCur->get(pTbCur->pCur, &key, &value, DB_NEXT) == 0) { + pBuf = value.data; + metaDecodeTbInfo(pBuf, &tbCfg); + if (tbCfg.type == META_SUPER_TABLE) { + continue; + } + return tbCfg.name; + } else { + return NULL; + } } } \ No newline at end of file diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index f426139c147e862633dafd26dc2f744ad77556a0..c4f2b54cf8a1c5d9b9589f3b36309e1e2934f40b 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -64,6 +64,14 @@ typedef struct SCatalogMgmt { typedef uint32_t (*tableNameHashFp)(const char *, uint32_t); +#define CTG_IS_STABLE(isSTable) (1 == (isSTable)) +#define CTG_IS_NOT_STABLE(isSTable) (0 == (isSTable)) +#define CTG_IS_UNKNOWN_STABLE(isSTable) ((isSTable) < 0) +#define CTG_SET_STABLE(isSTable, tbType) do { (isSTable) = ((tbType) == TSDB_SUPER_TABLE) ? 1 : ((tbType) > TSDB_SUPER_TABLE ? 0 : -1); } while (0) +#define CTG_TBTYPE_MATCH(isSTable, tbType) (CTG_IS_UNKNOWN_STABLE(isSTable) || (CTG_IS_STABLE(isSTable) && (tbType) == TSDB_SUPER_TABLE) || (CTG_IS_NOT_STABLE(isSTable) && (tbType) != TSDB_SUPER_TABLE)) + +#define CTG_TABLE_NOT_EXIST(code) (code == TSDB_CODE_TDB_INVALID_TABLE_ID) + #define ctgFatal(...) do { if (ctgDebugFlag & DEBUG_FATAL) { taosPrintLog("CTG FATAL ", ctgDebugFlag, __VA_ARGS__); }} while(0) #define ctgError(...) do { if (ctgDebugFlag & DEBUG_ERROR) { taosPrintLog("CTG ERROR ", ctgDebugFlag, __VA_ARGS__); }} while(0) #define ctgWarn(...) do { if (ctgDebugFlag & DEBUG_WARN) { taosPrintLog("CTG WARN ", ctgDebugFlag, __VA_ARGS__); }} while(0) diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 236264873e2b62e5ba3696cccdec0fd7db1b6c1a..9eee6f17def713a28d1dc4ced52eeb303c41debf 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -105,6 +105,8 @@ int32_t ctgGetTableMetaFromCache(struct SCatalog* pCatalog, const SName* pTableN } *exist = 1; + + tbMeta = *pTableMeta; if (tbMeta->tableType != TSDB_CHILD_TABLE) { return TSDB_CODE_SUCCESS; @@ -143,6 +145,29 @@ int32_t ctgGetTableMetaFromCache(struct SCatalog* pCatalog, const SName* pTableN return TSDB_CODE_SUCCESS; } +int32_t ctgGetTableTypeFromCache(struct SCatalog* pCatalog, const SName* pTableName, int32_t *tbType) { + if (NULL == pCatalog->tableCache.cache) { + return TSDB_CODE_SUCCESS; + } + + char tbFullName[TSDB_TABLE_FNAME_LEN]; + tNameExtractFullName(pTableName, tbFullName); + + size_t sz = 0; + STableMeta *pTableMeta = NULL; + + taosHashGetCloneExt(pCatalog->tableCache.cache, tbFullName, strlen(tbFullName), NULL, (void **)&pTableMeta, &sz); + + if (NULL == pTableMeta) { + return TSDB_CODE_SUCCESS; + } + + *tbType = pTableMeta->tableType; + + return TSDB_CODE_SUCCESS; +} + + void ctgGenEpSet(SEpSet *epSet, SVgroupInfo *vgroupInfo) { epSet->inUse = 0; epSet->numOfEps = vgroupInfo->numOfEps; @@ -153,14 +178,7 @@ void ctgGenEpSet(SEpSet *epSet, SVgroupInfo *vgroupInfo) { } } -int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMetaOutput* output) { - if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName || NULL == output) { - CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); - } - - char tbFullName[TSDB_TABLE_FNAME_LEN]; - tNameExtractFullName(pTableName, tbFullName); - +int32_t ctgGetTableMetaFromMnodeImpl(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, char* tbFullName, STableMetaOutput* output) { SBuildTableMetaInput bInput = {.vgId = 0, .dbName = NULL, .tableFullName = tbFullName}; char *msg = NULL; SEpSet *pVnodeEpSet = NULL; @@ -179,6 +197,12 @@ int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SE rpcSendRecv(pRpc, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp); if (TSDB_CODE_SUCCESS != rpcRsp.code) { + if (CTG_TABLE_NOT_EXIST(rpcRsp.code)) { + output->metaNum = 0; + ctgDebug("tbmeta:%s not exist in mnode", tbFullName); + return TSDB_CODE_SUCCESS; + } + ctgError("error rsp for table meta, code:%x", rpcRsp.code); CTG_ERR_RET(rpcRsp.code); } @@ -188,6 +212,13 @@ int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SE return TSDB_CODE_SUCCESS; } +int32_t ctgGetTableMetaFromMnode(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMetaOutput* output) { + char tbFullName[TSDB_TABLE_FNAME_LEN]; + tNameExtractFullName(pTableName, tbFullName); + + return ctgGetTableMetaFromMnodeImpl(pCatalog, pRpc, pMgmtEps, tbFullName, output); +} + int32_t ctgGetTableMetaFromVnode(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SVgroupInfo *vgroupInfo, STableMetaOutput* output) { if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName || NULL == vgroupInfo || NULL == output) { @@ -197,7 +228,7 @@ int32_t ctgGetTableMetaFromVnode(struct SCatalog* pCatalog, void *pRpc, const SE char dbFullName[TSDB_DB_FNAME_LEN]; tNameGetFullDbName(pTableName, dbFullName); - SBuildTableMetaInput bInput = {.vgId = vgroupInfo->vgId, .dbName = dbFullName, .tableFullName = pTableName->tname}; + SBuildTableMetaInput bInput = {.vgId = vgroupInfo->vgId, .dbName = dbFullName, .tableFullName = (char *)pTableName->tname}; char *msg = NULL; SEpSet *pVnodeEpSet = NULL; int32_t msgLen = 0; @@ -214,10 +245,15 @@ int32_t ctgGetTableMetaFromVnode(struct SCatalog* pCatalog, void *pRpc, const SE SEpSet epSet; ctgGenEpSet(&epSet, vgroupInfo); - rpcSendRecv(pRpc, &epSet, &rpcMsg, &rpcRsp); if (TSDB_CODE_SUCCESS != rpcRsp.code) { + if (CTG_TABLE_NOT_EXIST(rpcRsp.code)) { + output->metaNum = 0; + ctgDebug("tbmeta:%s not exist in vnode", pTableName->tname); + return TSDB_CODE_SUCCESS; + } + ctgError("error rsp for table meta, code:%x", rpcRsp.code); CTG_ERR_RET(rpcRsp.code); } @@ -322,22 +358,28 @@ _return: CTG_RET(TSDB_CODE_SUCCESS); } -int32_t ctgGetTableMetaImpl(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, bool forceUpdate, STableMeta** pTableMeta) { +int32_t ctgGetTableMetaImpl(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, bool forceUpdate, STableMeta** pTableMeta, int32_t isSTable) { if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName || NULL == pTableMeta) { CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } int32_t exist = 0; - if (!forceUpdate) { + if (!forceUpdate) { CTG_ERR_RET(ctgGetTableMetaFromCache(pCatalog, pTableName, pTableMeta, &exist)); - if (exist) { + if (exist && CTG_TBTYPE_MATCH(isSTable, (*pTableMeta)->tableType)) { return TSDB_CODE_SUCCESS; } + } else if (CTG_IS_UNKNOWN_STABLE(isSTable)) { + int32_t tbType = 0; + + CTG_ERR_RET(ctgGetTableTypeFromCache(pCatalog, pTableName, &tbType)); + + CTG_SET_STABLE(isSTable, tbType); } - CTG_ERR_RET(catalogRenewTableMeta(pCatalog, pRpc, pMgmtEps, pTableName)); + CTG_ERR_RET(ctgRenewTableMetaImpl(pCatalog, pRpc, pMgmtEps, pTableName, isSTable)); CTG_ERR_RET(ctgGetTableMetaFromCache(pCatalog, pTableName, pTableMeta, &exist)); @@ -364,19 +406,27 @@ int32_t ctgUpdateTableMetaCache(struct SCatalog *pCatalog, STableMetaOutput *out } if (NULL == pCatalog->tableCache.cache) { - pCatalog->tableCache.cache = taosHashInit(ctgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); - if (NULL == pCatalog->tableCache.cache) { + SHashObj *cache = taosHashInit(ctgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); + if (NULL == cache) { ctgError("init hash[%d] for tablemeta cache failed", ctgMgmt.cfg.maxTblCacheNum); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } + + if (NULL != atomic_val_compare_exchange_ptr(&pCatalog->tableCache.cache, NULL, cache)) { + taosHashCleanup(cache); + } } if (NULL == pCatalog->tableCache.stableCache) { - pCatalog->tableCache.stableCache = taosHashInit(ctgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), true, HASH_ENTRY_LOCK); - if (NULL == pCatalog->tableCache.stableCache) { + SHashObj *cache = taosHashInit(ctgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), true, HASH_ENTRY_LOCK); + if (NULL == cache) { ctgError("init hash[%d] for stablemeta cache failed", ctgMgmt.cfg.maxTblCacheNum); CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); } + + if (NULL != atomic_val_compare_exchange_ptr(&pCatalog->tableCache.stableCache, NULL, cache)) { + taosHashCleanup(cache); + } } if (output->metaNum == 2) { @@ -481,6 +531,50 @@ int32_t ctgValidateAndRemoveDb(struct SCatalog* pCatalog, const char* dbName, SD return TSDB_CODE_SUCCESS; } +int32_t ctgRenewTableMetaImpl(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, int32_t isSTable) { + if (NULL == pCatalog || NULL == pTransporter || NULL == pMgmtEps || NULL == pTableName) { + CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); + } + + SVgroupInfo vgroupInfo = {0}; + int32_t code = 0; + + CTG_ERR_RET(catalogGetTableHashVgroup(pCatalog, pTransporter, pMgmtEps, pTableName, &vgroupInfo)); + + STableMetaOutput voutput = {0}; + STableMetaOutput moutput = {0}; + STableMetaOutput *output = &voutput; + + if (CTG_IS_STABLE(isSTable)) { + CTG_ERR_JRET(ctgGetTableMetaFromMnode(pCatalog, pTransporter, pMgmtEps, pTableName, &moutput)); + + if (0 == moutput.metaNum) { + CTG_ERR_JRET(ctgGetTableMetaFromVnode(pCatalog, pTransporter, pMgmtEps, pTableName, &vgroupInfo, &voutput)); + } else { + output = &moutput; + } + } else { + CTG_ERR_JRET(ctgGetTableMetaFromVnode(pCatalog, pTransporter, pMgmtEps, pTableName, &vgroupInfo, &voutput)); + + if (voutput.metaNum > 0 && TSDB_SUPER_TABLE == voutput.tbMeta->tableType) { + CTG_ERR_JRET(ctgGetTableMetaFromMnodeImpl(pCatalog, pTransporter, pMgmtEps, voutput.tbFname, &moutput)); + + tfree(voutput.tbMeta); + voutput.tbMeta = moutput.tbMeta; + moutput.tbMeta = NULL; + } + } + + CTG_ERR_JRET(ctgUpdateTableMetaCache(pCatalog, output)); + +_return: + + tfree(voutput.tbMeta); + tfree(moutput.tbMeta); + + CTG_RET(code); +} + int32_t catalogInit(SCatalogCfg *cfg) { if (ctgMgmt.pCluster) { @@ -643,11 +737,15 @@ int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDB } if (NULL == pCatalog->dbCache.cache) { - pCatalog->dbCache.cache = taosHashInit(ctgMgmt.cfg.maxDBCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); - if (NULL == pCatalog->dbCache.cache) { + SHashObj *cache = taosHashInit(ctgMgmt.cfg.maxDBCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); + if (NULL == cache) { ctgError("init hash[%d] for db cache failed", CTG_DEFAULT_CACHE_DB_NUMBER); CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR); } + + if (NULL != atomic_val_compare_exchange_ptr(&pCatalog->dbCache.cache, NULL, cache)) { + taosHashCleanup(cache); + } } else { CTG_ERR_JRET(ctgValidateAndRemoveDb(pCatalog, dbName, dbInfo)); } @@ -672,36 +770,23 @@ _return: } int32_t catalogGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { - return ctgGetTableMetaImpl(pCatalog, pTransporter, pMgmtEps, pTableName, false, pTableMeta); + return ctgGetTableMetaImpl(pCatalog, pTransporter, pMgmtEps, pTableName, false, pTableMeta, -1); +} + +int32_t catalogGetSTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { + return ctgGetTableMetaImpl(pCatalog, pTransporter, pMgmtEps, pTableName, false, pTableMeta, 1); } -int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName) { - if (NULL == pCatalog || NULL == pRpc || NULL == pMgmtEps || NULL == pTableName) { +int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, int32_t isSTable) { + if (NULL == pCatalog || NULL == pTransporter || NULL == pMgmtEps || NULL == pTableName) { CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); } - SVgroupInfo vgroupInfo = {0}; - int32_t code = 0; - - CTG_ERR_RET(catalogGetTableHashVgroup(pCatalog, pRpc, pMgmtEps, pTableName, &vgroupInfo)); - - STableMetaOutput output = {0}; - - CTG_ERR_RET(ctgGetTableMetaFromVnode(pCatalog, pRpc, pMgmtEps, pTableName, &vgroupInfo, &output)); - - //CTG_ERR_RET(ctgGetTableMetaFromMnode(pCatalog, pRpc, pMgmtEps, pTableName, &output)); - - CTG_ERR_JRET(ctgUpdateTableMetaCache(pCatalog, &output)); - -_return: - - tfree(output.tbMeta); - - CTG_RET(code); + return ctgRenewTableMetaImpl(pCatalog, pTransporter, pMgmtEps, pTableName, isSTable); } -int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { - return ctgGetTableMetaImpl(pCatalog, pRpc, pMgmtEps, pTableName, true, pTableMeta); +int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable) { + return ctgGetTableMetaImpl(pCatalog, pTransporter, pMgmtEps, pTableName, true, pTableMeta, isSTable); } int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList) { diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index 1d8a48dfcbb5670c6a997afb4364b7f3341977b8..4fc53e5f18521bdc126bc2f86cc4cf92b8a870ba 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -45,7 +45,7 @@ void ctgTestSetPrepareSTableMeta(); bool ctgTestStop = false; bool ctgTestEnableSleep = false; -bool ctgTestDeadLoop = true; +bool ctgTestDeadLoop = false; int32_t ctgTestCurrentVgVersion = 0; int32_t ctgTestVgVersion = 1; @@ -600,7 +600,6 @@ void *ctgTestSetCtableMetaThread(void *param) { } -#if 0 TEST(tableMeta, normalTable) { struct SCatalog* pCtg = NULL; @@ -768,7 +767,7 @@ TEST(tableMeta, superTableCase) { ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); tableMeta = NULL; - code = catalogRenewAndGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta); + code = catalogRenewAndGetTableMeta(pCtg, mockPointer, (const SEpSet *)mockPointer, &n, &tableMeta, 0); ASSERT_EQ(code, 0); ASSERT_EQ(tableMeta->vgId, 9); ASSERT_EQ(tableMeta->tableType, TSDB_CHILD_TABLE); @@ -999,8 +998,6 @@ TEST(multiThread, getSetDbVgroupCase) { catalogDestroy(); } -#endif - TEST(multiThread, ctableMeta) { struct SCatalog* pCtg = NULL; diff --git a/source/libs/index/inc/index_fst_counting_writer.h b/source/libs/index/inc/index_fst_counting_writer.h index fcc0d5a0b3cf94c65fb83af53cc7bc9c3941ef93..d7363f2f4c560cb85330a51c9d4444b0308570a6 100644 --- a/source/libs/index/inc/index_fst_counting_writer.h +++ b/source/libs/index/inc/index_fst_counting_writer.h @@ -22,6 +22,8 @@ extern "C" { #include "tfile.h" +//#define USE_MMAP 1 + #define DefaultMem 1024 * 1024 static char tmpFile[] = "./index"; @@ -39,6 +41,9 @@ typedef struct WriterCtx { bool readOnly; char buf[256]; int size; +#ifdef USE_MMAP + char* ptr; +#endif } file; struct { int32_t capa; diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 0657c68458465d8279f0e75b83951bd6b4bfd9e0..9b7f1c83834374c240ac2fbf505cfdd15859a46d 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -74,16 +74,15 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { // sIdx->cache = (void*)indexCacheCreate(sIdx); sIdx->tindex = indexTFileCreate(path); if (sIdx->tindex == NULL) { goto END; } + sIdx->colObj = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); sIdx->cVersion = 1; - sIdx->path = calloc(1, strlen(path) + 1); - memcpy(sIdx->path, path, strlen(path)); + sIdx->path = tstrdup(path); pthread_mutex_init(&sIdx->mtx, NULL); - *index = sIdx; - return 0; #endif + END: if (sIdx != NULL) { indexClose(sIdx); } @@ -310,18 +309,14 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result // Get col info IndexCache* cache = NULL; - pthread_mutex_lock(&sIdx->mtx); char buf[128] = {0}; ICacheKey key = {.suid = term->suid, .colName = term->colName, .nColName = strlen(term->colName)}; int32_t sz = indexSerialCacheKey(&key, buf); + pthread_mutex_lock(&sIdx->mtx); IndexCache** pCache = taosHashGet(sIdx->colObj, buf, sz); - if (pCache == NULL) { - pthread_mutex_unlock(&sIdx->mtx); - return -1; - } - cache = *pCache; + cache = (pCache == NULL) ? NULL : *pCache; pthread_mutex_unlock(&sIdx->mtx); *result = taosArrayInit(4, sizeof(uint64_t)); @@ -329,7 +324,7 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result STermValueType s = kTypeValue; if (0 == indexCacheSearch(cache, query, *result, &s)) { if (s == kTypeDeletion) { - indexInfo("col: %s already drop by other opera", term->colName); + indexInfo("col: %s already drop by", term->colName); // coloum already drop by other oper, no need to query tindex return 0; } else { @@ -402,11 +397,11 @@ static void indexDestroyTempResult(SArray* result) { } int indexFlushCacheTFile(SIndex* sIdx, void* cache) { if (sIdx == NULL) { return -1; } - indexWarn("suid %" PRIu64 " merge cache into tindex", sIdx->suid); + indexInfo("suid %" PRIu64 " merge cache into tindex", sIdx->suid); IndexCache* pCache = (IndexCache*)cache; TFileReader* pReader = tfileGetReaderByCol(sIdx->tindex, pCache->suid, pCache->colName); - if (pReader == NULL) { indexWarn("empty pReader found"); } + if (pReader == NULL) { indexWarn("empty tfile reader found"); } // handle flush Iterate* cacheIter = indexCacheIteratorCreate(pCache); Iterate* tfileIter = tfileIteratorCreate(pReader); @@ -457,10 +452,6 @@ int indexFlushCacheTFile(SIndex* sIdx, void* cache) { while (tn == true) { IterateValue* tv = tfileIter->getValue(tfileIter); TFileValue* tfv = tfileValueCreate(tv->colVal); - if (tv->val == NULL) { - // HO - printf("NO...."); - } taosArrayAddAll(tfv->tableId, tv->val); indexMergeSameKey(result, tfv); tn = tfileIter->next(tfileIter); @@ -504,21 +495,19 @@ static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { tfileWriterClose(tw); TFileReader* reader = tfileReaderOpen(sIdx->path, cache->suid, version, cache->colName); + if (reader == NULL) { goto END; } - char buf[128] = {0}; TFileHeader* header = &reader->header; - ICacheKey key = { - .suid = cache->suid, .colName = header->colName, .nColName = strlen(header->colName), .colType = header->colType}; + ICacheKey key = {.suid = cache->suid, .colName = header->colName, .nColName = strlen(header->colName)}; pthread_mutex_lock(&sIdx->mtx); - IndexTFile* ifile = (IndexTFile*)sIdx->tindex; tfileCachePut(ifile->cache, &key, reader); - pthread_mutex_unlock(&sIdx->mtx); return ret; END: tfileWriterClose(tw); + return -1; } int32_t indexSerialCacheKey(ICacheKey* key, char* buf) { diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index e95de9286e409bc2c3147a1728d8055274e4f4f3..ca1d9e3fa4793c11a0867ec81860335143fc46f9 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -20,11 +20,7 @@ #define MAX_INDEX_KEY_LEN 256 // test only, change later -#define MEM_TERM_LIMIT 5 * 10000 -// ref index_cache.h:22 -//#define CACHE_KEY_LEN(p) \ -// (sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) + -// sizeof(p->operType)) +#define MEM_TERM_LIMIT 10 * 10000 static void indexMemRef(MemTable* tbl); static void indexMemUnRef(MemTable* tbl); @@ -261,7 +257,7 @@ static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SA return 0; } int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermValueType* s) { - if (cache == NULL) { return -1; } + if (cache == NULL) { return 0; } IndexCache* pCache = cache; MemTable *mem = NULL, *imm = NULL; @@ -275,14 +271,12 @@ int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermV SIndexTerm* term = query->term; EIndexQueryType qtype = query->qType; CacheTerm ct = {.colVal = term->colVal, .version = atomic_load_32(&pCache->version)}; - // indexCacheDebug(pCache); int ret = indexQueryMem(mem, &ct, qtype, result, s); if (ret == 0 && *s != kTypeDeletion) { // continue search in imm ret = indexQueryMem(imm, &ct, qtype, result, s); } - // cacheTermDestroy(ct); indexMemUnRef(mem); indexMemUnRef(imm); @@ -354,9 +348,6 @@ static bool indexCacheIteratorNext(Iterate* itera) { SSkipListIterator* iter = itera->iter; if (iter == NULL) { return false; } IterateValue* iv = &itera->val; - if (iv->colVal != NULL && iv->val != NULL) { - // indexError("value in cache: colVal: %s, size: %d", iv->colVal, (int)taosArrayGetSize(iv->val)); - } iterateValueDestroy(iv, false); bool next = tSkipListIterNext(iter); diff --git a/source/libs/index/src/index_fst_counting_writer.c b/source/libs/index/src/index_fst_counting_writer.c index 0f29da1c27cf480071ef795fa385c78552d9edce..2b64d65e46c33341469d5a53cb3c85e37b78b316 100644 --- a/source/libs/index/src/index_fst_counting_writer.c +++ b/source/libs/index/src/index_fst_counting_writer.c @@ -18,7 +18,7 @@ #include "tutil.h" static int writeCtxDoWrite(WriterCtx* ctx, uint8_t* buf, int len) { - if (ctx->offset + len > ctx->limit) { return -1; } + // if (ctx->offset + len > ctx->limit) { return -1; } if (ctx->type == TFile) { assert(len == tfWrite(ctx->file.fd, buf, len)); @@ -31,7 +31,12 @@ static int writeCtxDoWrite(WriterCtx* ctx, uint8_t* buf, int len) { static int writeCtxDoRead(WriterCtx* ctx, uint8_t* buf, int len) { int nRead = 0; if (ctx->type == TFile) { +#ifdef USE_MMAP + nRead = len < ctx->file.size ? len : ctx->file.size; + memcpy(buf, ctx->file.ptr, nRead); +#else nRead = tfRead(ctx->file.fd, buf, len); +#endif } else { memcpy(buf, ctx->mem.buf + ctx->offset, len); } @@ -43,7 +48,13 @@ static int writeCtxDoReadFrom(WriterCtx* ctx, uint8_t* buf, int len, int32_t off int nRead = 0; if (ctx->type == TFile) { // tfLseek(ctx->file.fd, offset, 0); +#ifdef USE_MMAP + int32_t last = ctx->file.size - offset; + nRead = last >= len ? len : last; + memcpy(buf, ctx->file.ptr + offset, nRead); +#else nRead = tfPread(ctx->file.fd, buf, len, offset); +#endif } else { // refactor later assert(0); @@ -83,6 +94,9 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int struct stat fstat; stat(path, &fstat); ctx->file.size = fstat.st_size; +#ifdef USE_MMAP + ctx->file.ptr = (char*)tfMmapReadOnly(ctx->file.fd, ctx->file.size); +#endif } memcpy(ctx->file.buf, path, strlen(path)); if (ctx->file.fd < 0) { @@ -112,7 +126,11 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) { free(ctx->mem.buf); } else { tfClose(ctx->file.fd); - ctx->flush(ctx); + if (ctx->file.readOnly) { +#ifdef USE_MMAP + munmap(ctx->file.ptr, ctx->file.size); +#endif + } if (remove) { unlink(ctx->file.buf); } } free(ctx); diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index d4d13ddf197e780e89ab24469a318cf2ae9feb41..6437991358cf9c53850cedc0f72bead5d3acf553 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -61,36 +61,21 @@ TFileCache* tfileCacheCreate(const char* path) { tcache->capacity = 64; SArray* files = tfileGetFileList(path); - - uint64_t suid; - int32_t colId, version; for (size_t i = 0; i < taosArrayGetSize(files); i++) { char* file = taosArrayGetP(files, i); - // refactor later, use colname and version info - char colName[256] = {0}; - if (0 != tfileParseFileName(file, &suid, colName, (int*)&version)) { - indexInfo("try parse invalid file: %s, skip it", file); - continue; - } - - char fullName[256] = {0}; - sprintf(fullName, "%s/%s", path, file); - - WriterCtx* wc = writerCtxCreate(TFile, fullName, true, 1024 * 1024 * 64); + WriterCtx* wc = writerCtxCreate(TFile, file, true, 1024 * 1024 * 64); if (wc == NULL) { indexError("failed to open index:%s", file); goto End; } - char buf[128] = {0}; TFileReader* reader = tfileReaderCreate(wc); + if (reader == NULL) { goto End; } TFileHeader* header = &reader->header; - ICacheKey key = {.suid = header->suid, - .colName = header->colName, - .nColName = strlen(header->colName), - .colType = header->colType}; + ICacheKey key = {.suid = header->suid, .colName = header->colName, .nColName = strlen(header->colName)}; + char buf[128] = {0}; int32_t sz = indexSerialCacheKey(&key, buf); assert(sz < sizeof(buf)); taosHashPut(tcache->tableCache, buf, sz, &reader, sizeof(void*)); @@ -223,24 +208,13 @@ TFileReader* tfileReaderOpen(char* path, uint64_t suid, int32_t version, const c tfileGenFileFullName(fullname, path, suid, colName, version); WriterCtx* wc = writerCtxCreate(TFile, fullname, true, 1024 * 1024 * 1024); - // indexInfo("open read file name:%s, size: %d", wc->file.buf, wc->file.size); + indexInfo("open read file name:%s, size: %d", wc->file.buf, wc->file.size); if (wc == NULL) { return NULL; } TFileReader* reader = tfileReaderCreate(wc); return reader; } TFileWriter* tfileWriterCreate(WriterCtx* ctx, TFileHeader* header) { - // char pathBuf[128] = {0}; - // sprintf(pathBuf, "%s/% " PRIu64 "-%d-%d.tindex", path, suid, colId, version); - // TFileHeader header = {.suid = suid, .version = version, .colName = {0}, colType = colType}; - // memcpy(header.colName, ); - - // char buf[TFILE_HADER_PRE_SIZE]; - // int len = TFILE_HADER_PRE_SIZE; - // if (len != ctx->write(ctx, buf, len)) { - // indexError("index: %" PRIu64 " failed to write header info", header->suid); - // return NULL; - //} TFileWriter* tw = calloc(1, sizeof(TFileWriter)); if (tw == NULL) { indexError("index: %" PRIu64 " failed to alloc TFilerWriter", header->suid); @@ -256,7 +230,8 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { // sort by coltype and write to tindex if (order == false) { __compar_fn_t fn; - int8_t colType = tw->header.colType; + + int8_t colType = tw->header.colType; if (colType == TSDB_DATA_TYPE_BINARY || colType == TSDB_DATA_TYPE_NCHAR) { fn = tfileStrCompare; } else { @@ -274,7 +249,8 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { // ugly code, refactor later for (size_t i = 0; i < sz; i++) { TFileValue* v = taosArrayGetP((SArray*)data, i); - // taosArrayRemoveDuplicate(v->tablId, tfileUidCompare, NULL); + taosArraySort(v->tableId, tfileUidCompare); + taosArrayRemoveDuplicate(v->tableId, tfileUidCompare, NULL); int32_t tbsz = taosArrayGetSize(v->tableId); fstOffset += TF_TABLE_TATOAL_SIZE(tbsz); } @@ -287,34 +263,14 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { // check buf has enough space or not int32_t ttsz = TF_TABLE_TATOAL_SIZE(tbsz); - // if (offset + ttsz >= bufLimit) { - // // batch write - // indexInfo("offset: %d, ttsz: %d", offset, ttsz); - // // std::cout << "offset: " << offset << std::endl; - // // std::cout << "ttsz:" << ttsz < < < std::endl; - // tw->ctx->write(tw->ctx, buf, offset); - // offset = 0; - // memset(buf, 0, bufLimit); - // p = buf; - //} - // if (ttsz >= bufLimit) { - //} char* buf = calloc(1, ttsz * sizeof(char)); char* p = buf; tfileSerialTableIdsToBuf(p, v->tableId); tw->ctx->write(tw->ctx, buf, ttsz); - // offset += ttsz; - // p = buf + offset; - // set up value offset v->offset = tw->offset; tw->offset += ttsz; free(buf); } - // if (offset != 0) { - // write reversed data in buf to tindex - // tw->ctx->write(tw->ctx, buf, offset); - //} - // tfree(buf); tw->fb = fstBuilderCreate(tw->ctx, 0); if (tw->fb == NULL) { @@ -351,10 +307,16 @@ void tfileWriterDestroy(TFileWriter* tw) { } IndexTFile* indexTFileCreate(const char* path) { + TFileCache* cache = tfileCacheCreate(path); + if (cache == NULL) { return NULL; } + IndexTFile* tfile = calloc(1, sizeof(IndexTFile)); - if (tfile == NULL) { return NULL; } + if (tfile == NULL) { + tfileCacheDestroy(cache); + return NULL; + } - tfile->cache = tfileCacheCreate(path); + tfile->cache = cache; return tfile; } void indexTFileDestroy(IndexTFile* tfile) { @@ -366,6 +328,7 @@ void indexTFileDestroy(IndexTFile* tfile) { int indexTFileSearch(void* tfile, SIndexTermQuery* query, SArray* result) { int ret = -1; if (tfile == NULL) { return ret; } + IndexTFile* pTfile = (IndexTFile*)tfile; SIndexTerm* term = query->term; @@ -545,12 +508,11 @@ static int tfileReaderLoadHeader(TFileReader* reader) { int64_t nread = reader->ctx->readFrom(reader->ctx, buf, sizeof(buf), 0); if (nread == -1) { - // indexError("actual Read: %d, to read: %d, errno: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), errno, reader->ctx->file.fd, reader->ctx->file.buf); } else { - indexError("actual Read: %d, to read: %d, errno: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), - errno, reader->ctx->file.fd, reader->ctx->file.buf); + indexInfo("actual Read: %d, to read: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), + reader->ctx->file.fd, reader->ctx->file.buf); } // assert(nread == sizeof(buf)); memcpy(&reader->header, buf, sizeof(buf)); @@ -566,7 +528,8 @@ static int tfileReaderLoadFst(TFileReader* reader) { WriterCtx* ctx = reader->ctx; int32_t nread = ctx->readFrom(ctx, buf, FST_MAX_SIZE, reader->header.fstOffset); - indexError("nread = %d, and fst offset=%d, filename: %s ", nread, reader->header.fstOffset, ctx->file.buf); + indexInfo("nread = %d, and fst offset=%d, filename: %s, size: %d ", nread, reader->header.fstOffset, ctx->file.buf, + ctx->file.size); // we assuse fst size less than FST_MAX_SIZE assert(nread > 0 && nread < FST_MAX_SIZE); @@ -613,15 +576,20 @@ void tfileReaderUnRef(TFileReader* reader) { static SArray* tfileGetFileList(const char* path) { SArray* files = taosArrayInit(4, sizeof(void*)); + char buf[128] = {0}; + uint64_t suid; + uint32_t version; + DIR* dir = opendir(path); if (NULL == dir) { return NULL; } - struct dirent* entry; while ((entry = readdir(dir)) != NULL) { - if (entry->d_type && DT_DIR) { continue; } - size_t len = strlen(entry->d_name); - char* buf = calloc(1, len + 1); - memcpy(buf, entry->d_name, len); + char* file = entry->d_name; + if (0 != tfileParseFileName(file, &suid, buf, &version)) { continue; } + + size_t len = strlen(path) + 1 + strlen(file) + 1; + char* buf = calloc(1, len); + sprintf(buf, "%s/%s", path, file); taosArrayPush(files, &buf); } closedir(dir); @@ -640,15 +608,9 @@ static void tfileDestroyFileName(void* elem) { free(p); } static int tfileCompare(const void* a, const void* b) { - const char* aName = *(char**)a; - const char* bName = *(char**)b; - - size_t aLen = strlen(aName); - size_t bLen = strlen(bName); - - int ret = strncmp(aName, bName, aLen > bLen ? aLen : bLen); - if (ret == 0) { return ret; } - return ret < 0 ? -1 : 1; + const char* as = *(char**)a; + const char* bs = *(char**)b; + return strcmp(as, bs); } static int tfileParseFileName(const char* filename, uint64_t* suid, char* col, int* version) { diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 77b6e02f186356e8e16a66afb79716e8a0a5479d..9c92af26a23a6a994ae3d7b20d36857d52f0b656 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -28,7 +28,7 @@ #include "tutil.h" using namespace std; -#define NUM_OF_THREAD 10 +#define NUM_OF_THREAD 5 class DebugInfo { public: @@ -679,6 +679,17 @@ class IndexObj { } return numOfTable; } + int ReadMultiMillonData(const std::string& colName, const std::string& colVal = "Hello world", + size_t numOfTable = 100 * 10000) { + std::string tColVal = colVal; + + int colValSize = tColVal.size(); + for (int i = 0; i < numOfTable; i++) { + tColVal[i % colValSize] = 'a' + i % 26; + SearchOne(colName, tColVal); + } + return 0; + } int Put(SIndexMultiTerm* fvs, uint64_t uid) { numOfWrite += taosArrayGetSize(fvs); @@ -701,7 +712,8 @@ class IndexObj { int64_t s = taosGetTimestampUs(); if (Search(mq, result) == 0) { int64_t e = taosGetTimestampUs(); - std::cout << "search one successfully and time cost:" << e - s << std::endl; + std::cout << "search and time cost:" << e - s << "\tquery col:" << colName << "\t val: " << colVal + << "\t size:" << taosArrayGetSize(result) << std::endl; } else { } int sz = taosArrayGetSize(result); @@ -710,6 +722,31 @@ class IndexObj { return sz; // assert(taosArrayGetSize(result) == targetSize); } + int SearchOneTarget(const std::string& colName, const std::string& colVal, uint64_t val) { + SIndexMultiTermQuery* mq = indexMultiTermQueryCreate(MUST); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + indexMultiTermQueryAdd(mq, term, QUERY_TERM); + + SArray* result = (SArray*)taosArrayInit(1, sizeof(uint64_t)); + + int64_t s = taosGetTimestampUs(); + if (Search(mq, result) == 0) { + int64_t e = taosGetTimestampUs(); + std::cout << "search one successfully and time cost:" << e - s << "\tquery col:" << colName + << "\t val: " << colVal << "\t size:" << taosArrayGetSize(result) << std::endl; + } else { + } + int sz = taosArrayGetSize(result); + indexMultiTermQueryDestroy(mq); + taosArrayDestroy(result); + assert(sz == 1); + uint64_t* ret = (uint64_t*)taosArrayGet(result, 0); + assert(val = *ret); + + return sz; + } + void PutOne(const std::string& colName, const std::string& colVal) { SIndexMultiTerm* terms = indexMultiTermCreate(); SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), @@ -718,6 +755,14 @@ class IndexObj { Put(terms, 10); indexMultiTermDestroy(terms); } + void PutOneTarge(const std::string& colName, const std::string& colVal, uint64_t val) { + SIndexMultiTerm* terms = indexMultiTermCreate(); + SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(), + colVal.c_str(), colVal.size()); + indexMultiTermAdd(terms, term); + Put(terms, val); + indexMultiTermDestroy(terms); + } void Debug() { std::cout << "numOfWrite:" << numOfWrite << std::endl; std::cout << "numOfRead:" << numOfRead << std::endl; @@ -830,15 +875,15 @@ TEST_F(IndexEnv2, testIndex_TrigeFlush) { assert(numOfTable == target); } -static void write_and_search(IndexObj* idx) { - std::string colName("tag1"), colVal("Hello"); - +static void single_write_and_search(IndexObj* idx) { int target = idx->SearchOne("tag1", "Hello"); - std::cout << "search: " << target << std::endl; target = idx->SearchOne("tag2", "Test"); - std::cout << "search: " << target << std::endl; - - idx->PutOne(colName, colVal); +} +static void multi_write_and_search(IndexObj* idx) { + int target = idx->SearchOne("tag1", "Hello"); + target = idx->SearchOne("tag2", "Test"); + idx->WriteMultiMillonData("tag1", "Hello", 100 * 10000); + idx->WriteMultiMillonData("tag2", "Test", 100 * 10000); } TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { std::string path = "/tmp/cache_and_tfile"; @@ -847,13 +892,27 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { } index->PutOne("tag1", "Hello"); index->PutOne("tag2", "Test"); - index->WriteMultiMillonData("tag1", "Hello", 50 * 10000); - index->WriteMultiMillonData("tag2", "Test", 50 * 10000); + index->WriteMultiMillonData("tag1", "Hello", 100 * 10000); + index->WriteMultiMillonData("tag2", "Test", 100 * 10000); std::thread threads[NUM_OF_THREAD]; for (int i = 0; i < NUM_OF_THREAD; i++) { // - threads[i] = std::thread(write_and_search, index); + threads[i] = std::thread(single_write_and_search, index); + } + for (int i = 0; i < NUM_OF_THREAD; i++) { + // TOD + threads[i].join(); + } +} +TEST_F(IndexEnv2, testIndex_MultiWrite_and_MultiRead) { + std::string path = "/tmp/cache_and_tfile"; + if (index->Init(path) != 0) {} + + std::thread threads[NUM_OF_THREAD]; + for (int i = 0; i < NUM_OF_THREAD; i++) { + // + threads[i] = std::thread(multi_write_and_search, index); } for (int i = 0; i < NUM_OF_THREAD; i++) { // TOD @@ -862,15 +921,33 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { } TEST_F(IndexEnv2, testIndex_restart) { - std::string path = "/tmp/test1"; + std::string path = "/tmp/cache_and_tfile"; if (index->Init(path) != 0) {} + index->SearchOneTarget("tag1", "Hello", 10); + index->SearchOneTarget("tag2", "Test", 10); } -TEST_F(IndexEnv2, testIndex_performance) { - std::string path = "/tmp/test2"; +TEST_F(IndexEnv2, testIndex_read_performance) { + std::string path = "/tmp/cache_and_tfile"; if (index->Init(path) != 0) {} + index->PutOneTarge("tag1", "Hello", 12); + index->PutOneTarge("tag1", "Hello", 15); + index->ReadMultiMillonData("tag1", "Hello"); + std::cout << "reader sz: " << index->SearchOne("tag1", "Hello") << std::endl; + assert(3 == index->SearchOne("tag1", "Hello")); } TEST_F(IndexEnv2, testIndexMultiTag) { - std::string path = "/tmp/test3"; + std::string path = "/tmp/multi_tag"; + if (index->Init(path) != 0) {} + index->WriteMultiMillonData("tag1", "Hello", 100 * 10000); + index->WriteMultiMillonData("tag2", "Test", 100 * 10000); + index->WriteMultiMillonData("tag3", "Test", 100 * 10000); + index->WriteMultiMillonData("tag4", "Test", 100 * 10000); +} +TEST_F(IndexEnv2, testLongComVal) { + std::string path = "/tmp/long_colVal"; if (index->Init(path) != 0) {} + // gen colVal by randstr + std::string randstr = "xxxxxxxxxxxxxxxxx"; + index->WriteMultiMillonData("tag1", randstr, 100 * 10000); } diff --git a/source/libs/parser/inc/astToMsg.h b/source/libs/parser/inc/astToMsg.h index ba33767a05b5edeb3594aaf075102d6246bf3e1a..0d0769a040f660322bdf7c3d699ba7bd30be74e1 100644 --- a/source/libs/parser/inc/astToMsg.h +++ b/source/libs/parser/inc/astToMsg.h @@ -5,12 +5,12 @@ #include "tmsg.h" -SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); -SCreateAcctMsg* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); -SDropUserMsg* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); -SShowMsg* buildShowMsg(SShowInfo* pShowInfo, SParseBasicCtx* pParseCtx, char* msgBuf, int32_t msgLen); +SCreateUserReq* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); +SCreateAcctReq* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); +SDropUserReq* buildDropUserMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen); +SShowReq* buildShowMsg(SShowInfo* pShowInfo, SParseBasicCtx* pParseCtx, char* msgBuf, int32_t msgLen); SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseBasicCtx *pCtx, SMsgBuf* pMsgBuf); -SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); +SCreateStbMsg* buildCreateStbMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); SDropStbMsg* buildDropStableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf); SCreateDnodeMsg *buildCreateDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf); SDropDnodeMsg *buildDropDnodeMsg(SSqlInfo* pInfo, int32_t* len, SMsgBuf* pMsgBuf); diff --git a/source/libs/parser/inc/dataBlockMgt.h b/source/libs/parser/inc/dataBlockMgt.h index 69dad4d9f4b792ed573628f05ddb95f301f8cc08..cd84222c65da90672987ef4acb11ad4764a82ff6 100644 --- a/source/libs/parser/inc/dataBlockMgt.h +++ b/source/libs/parser/inc/dataBlockMgt.h @@ -126,7 +126,7 @@ static FORCE_INLINE void getMemRowAppendInfo(SSchema *pSchema, uint8_t memRowTyp int32_t idx, int32_t *toffset) { int32_t schemaIdx = 0; if (IS_DATA_COL_ORDERED(spd)) { - schemaIdx = spd->boundedColumns[idx]; + schemaIdx = spd->boundedColumns[idx] - 1; if (isDataRowT(memRowType)) { *toffset = (spd->cols + schemaIdx)->toffset; // the offset of firstPart } else { diff --git a/source/libs/parser/inc/insertParser.h b/source/libs/parser/inc/insertParser.h index b0191b155d7b6969fdfd41942b612b603d65fc52..796bd9b429be6ab2eb4d289c672db4afb64c8791 100644 --- a/source/libs/parser/inc/insertParser.h +++ b/source/libs/parser/inc/insertParser.h @@ -22,7 +22,7 @@ extern "C" { #include "parser.h" -int32_t parseInsertSql(SParseContext* pContext, SInsertStmtInfo** pInfo); +int32_t parseInsertSql(SParseContext* pContext, SVnodeModifOpStmtInfo** pInfo); #ifdef __cplusplus } diff --git a/source/libs/parser/inc/parserInt.h b/source/libs/parser/inc/parserInt.h index 346bd0cbe4c13e7f22a97b8725ccdddc05de9656..d18934d5f5f18077d782a8b97052b64f8351e8fe 100644 --- a/source/libs/parser/inc/parserInt.h +++ b/source/libs/parser/inc/parserInt.h @@ -38,14 +38,6 @@ typedef struct SMsgBuf { char *buf; } SMsgBuf; -// create table operation type -enum TSQL_CREATE_TABLE_TYPE { - TSQL_CREATE_TABLE = 0x1, - TSQL_CREATE_STABLE = 0x2, - TSQL_CREATE_CTABLE = 0x3, - TSQL_CREATE_STREAM = 0x4, -}; - void clearTableMetaInfo(STableMetaInfo* pTableMetaInfo); void clearAllTableMetaInfo(SQueryStmtInfo* pQueryInfo, bool removeMeta, uint64_t id); @@ -70,7 +62,7 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pSqlInfo, SQ */ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen); -SInsertStmtInfo* qParserValidateCreateTbSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen); +SVnodeModifOpStmtInfo* qParserValidateCreateTbSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen); /** * Evaluate the numeric and timestamp arithmetic expression in the WHERE clause. diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 789f5a98e2d504845b899b55728af62da97c6d8f..6e91ad997cc5454099634c8f231b5c4f5cf2e6b9 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -370,7 +370,7 @@ create_table_list(A) ::= create_from_stable(Z). { pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo)); taosArrayPush(pCreateTable->childTableInfo, &Z); - pCreateTable->type = TSQL_CREATE_CTABLE; + pCreateTable->type = TSDB_SQL_CREATE_TABLE; A = pCreateTable; } @@ -381,7 +381,7 @@ create_table_list(A) ::= create_table_list(X) create_from_stable(Z). { %type create_table_args{SCreateTableSql*} create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP. { - A = tSetCreateTableInfo(X, NULL, NULL, TSQL_CREATE_TABLE); + A = tSetCreateTableInfo(X, NULL, NULL, TSDB_SQL_CREATE_TABLE); setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE); V.n += Z.n; @@ -391,8 +391,8 @@ create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP. { // create super table %type create_stable_args{SCreateTableSql*} create_stable_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP TAGS LP columnlist(Y) RP. { - A = tSetCreateTableInfo(X, Y, NULL, TSQL_CREATE_STABLE); - setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE); + A = tSetCreateTableInfo(X, Y, NULL, TSDB_SQL_CREATE_STABLE); + setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_STABLE); V.n += Z.n; setCreatedTableName(pInfo, &V, &U); @@ -421,11 +421,11 @@ tagNamelist(A) ::= ids(X). {A = taosArrayInit(4, sizeof(STo // create stream // create table table_name as select count(*) from super_table_name interval(time) create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) AS select(S). { - A = tSetCreateTableInfo(NULL, NULL, S, TSQL_CREATE_STREAM); - setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE); - - V.n += Z.n; - setCreatedTableName(pInfo, &V, &U); +// A = tSetCreateTableInfo(NULL, NULL, S, TSQL_CREATE_STREAM); +// setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE); +// +// V.n += Z.n; +// setCreatedTableName(pInfo, &V, &U); } %type column{SField} diff --git a/source/libs/parser/src/astGenerator.c b/source/libs/parser/src/astGenerator.c index 9122b0df969c5d7cdd0add49249e6e4baf26c658..0cb3cea95f133bb50f6a7fda847828d4dabf5921 100644 --- a/source/libs/parser/src/astGenerator.c +++ b/source/libs/parser/src/astGenerator.c @@ -579,25 +579,21 @@ SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SSqlNode *pSe SCreateTableSql *pCreate = calloc(1, sizeof(SCreateTableSql)); switch (type) { - case TSQL_CREATE_TABLE: { + case TSDB_SQL_CREATE_TABLE: { pCreate->colInfo.pColumns = pCols; assert(pTags == NULL); break; } - case TSQL_CREATE_STABLE: { + case TSDB_SQL_CREATE_STABLE: { pCreate->colInfo.pColumns = pCols; pCreate->colInfo.pTagColumns = pTags; assert(pTags != NULL && pCols != NULL); break; } - case TSQL_CREATE_STREAM: { - pCreate->pSelect = pSelect; - break; - } - - case TSQL_CREATE_CTABLE: { - assert(0); - } +// case TSQL_CREATE_STREAM: { +// pCreate->pSelect = pSelect; +// break; +// } default: assert(false); @@ -785,7 +781,7 @@ void destroySqlInfo(SSqlInfo *pInfo) { taosArrayDestroy(pInfo->funcs); if (pInfo->type == TSDB_SQL_SELECT) { destroyAllSqlNode(&pInfo->sub); - } else if (pInfo->type == TSDB_SQL_CREATE_TABLE) { + } else if (pInfo->type == TSDB_SQL_CREATE_STABLE || pInfo->type == TSDB_SQL_CREATE_TABLE) { pInfo->pCreateTableInfo = destroyCreateTableSql(pInfo->pCreateTableInfo); } else if (pInfo->type == TSDB_SQL_ALTER_TABLE) { taosArrayDestroyEx(pInfo->pAlterInfo->varList, freeItem); diff --git a/source/libs/parser/src/astToMsg.c b/source/libs/parser/src/astToMsg.c index 792c0db266f6580204dec54f2928492047950306..0c1af8dc3cbbcec8ac1d8208213888c1c1c18fa9 100644 --- a/source/libs/parser/src/astToMsg.c +++ b/source/libs/parser/src/astToMsg.c @@ -2,8 +2,8 @@ #include "astGenerator.h" #include "parserUtil.h" -SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) { - SCreateUserMsg* pMsg = (SCreateUserMsg*)calloc(1, sizeof(SCreateUserMsg)); +SCreateUserReq* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) { + SCreateUserReq* pMsg = (SCreateUserReq*)calloc(1, sizeof(SCreateUserReq)); if (pMsg == NULL) { // tscError("0x%" PRIx64 " failed to malloc for query msg", id); terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -25,8 +25,8 @@ SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, in return pMsg; } -SCreateAcctMsg* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) { - SCreateAcctMsg *pCreateMsg = (SCreateAcctMsg *) calloc(1, sizeof(SCreateAcctMsg)); +SCreateAcctReq* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, int64_t id, char* msgBuf, int32_t msgLen) { + SCreateAcctReq *pCreateMsg = (SCreateAcctReq *) calloc(1, sizeof(SCreateAcctReq)); if (pCreateMsg == NULL) { qError("0x%" PRIx64 " failed to malloc for query msg", id); terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; @@ -64,29 +64,29 @@ SCreateAcctMsg* buildAcctManipulationMsg(SSqlInfo* pInfo, int32_t* outputLen, in } } - *outputLen = sizeof(SCreateAcctMsg); + *outputLen = sizeof(SCreateAcctReq); return pCreateMsg; } -SDropUserMsg* buildDropUserMsg(SSqlInfo* pInfo, int32_t *msgLen, int64_t id, char* msgBuf, int32_t msgBufLen) { +SDropUserReq* buildDropUserMsg(SSqlInfo* pInfo, int32_t *msgLen, int64_t id, char* msgBuf, int32_t msgBufLen) { SToken* pName = taosArrayGet(pInfo->pMiscInfo->a, 0); if (pName->n >= TSDB_USER_LEN) { return NULL; } - SDropUserMsg* pMsg = calloc(1, sizeof(SDropUserMsg)); + SDropUserReq* pMsg = calloc(1, sizeof(SDropUserReq)); if (pMsg == NULL) { terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; return NULL; } strncpy(pMsg->user, pName->z, pName->n); - *msgLen = sizeof(SDropUserMsg); + *msgLen = sizeof(SDropUserReq); return pMsg; } -SShowMsg* buildShowMsg(SShowInfo* pShowInfo, SParseBasicCtx *pCtx, char* msgBuf, int32_t msgLen) { - SShowMsg* pShowMsg = calloc(1, sizeof(SShowMsg)); +SShowReq* buildShowMsg(SShowInfo* pShowInfo, SParseBasicCtx *pCtx, char* msgBuf, int32_t msgLen) { + SShowReq* pShowMsg = calloc(1, sizeof(SShowReq)); pShowMsg->type = pShowInfo->showType; if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) { @@ -230,7 +230,7 @@ SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, SParseBasicCtx *pCt return pCreateMsg; } -SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf) { +SCreateStbMsg* buildCreateStbMsg(SCreateTableSql* pCreateTableSql, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf) { SSchema* pSchema; int32_t numOfTags = 0; @@ -239,16 +239,16 @@ SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* le numOfTags = (int32_t) taosArrayGetSize(pCreateTableSql->colInfo.pTagColumns); } - SCreateStbMsg* pCreateTableMsg = (SCreateStbMsg*)calloc(1, sizeof(SCreateStbMsg) + (numOfCols + numOfTags) * sizeof(SSchema)); + SCreateStbMsg* pCreateStbMsg = (SCreateStbMsg*)calloc(1, sizeof(SCreateStbMsg) + (numOfCols + numOfTags) * sizeof(SSchema)); char* pMsg = NULL; +#if 0 int32_t tableType = pCreateTableSql->type; if (tableType != TSQL_CREATE_TABLE && tableType != TSQL_CREATE_STABLE) { // create by using super table, tags value -#if 0 SArray* list = pInfo->pCreateTableInfo->childTableInfo; int32_t numOfTables = (int32_t)taosArrayGetSize(list); - pCreateTableMsg->numOfTables = htonl(numOfTables); + pCreateStbMsg->numOfTables = htonl(numOfTables); pMsg = (char*)pCreateMsg; for (int32_t i = 0; i < numOfTables; ++i) { @@ -268,25 +268,27 @@ SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* le int32_t len = (int32_t)(pMsg - (char*)pCreate); pCreate->len = htonl(len); } + + } else { #endif - } else { // create (super) table + // create (super) table SName n = {0}; int32_t code = createSName(&n, &pCreateTableSql->name, pParseCtx, pMsgBuf); if (code != 0) { return NULL; } - code = tNameExtractFullName(&n, pCreateTableMsg->name); + code = tNameExtractFullName(&n, pCreateStbMsg->name); if (code != 0) { buildInvalidOperationMsg(pMsgBuf, "invalid table name or database not specified"); return NULL; } - pCreateTableMsg->igExists = pCreateTableSql->existCheck ? 1 : 0; - pCreateTableMsg->numOfColumns = htonl(numOfCols); - pCreateTableMsg->numOfTags = htonl(numOfTags); + pCreateStbMsg->igExists = pCreateTableSql->existCheck ? 1 : 0; + pCreateStbMsg->numOfColumns = htonl(numOfCols); + pCreateStbMsg->numOfTags = htonl(numOfTags); - pSchema = (SSchema*) pCreateTableMsg->pSchema; + pSchema = (SSchema*)pCreateStbMsg->pSchema; for (int i = 0; i < numOfCols; ++i) { SField* pField = taosArrayGet(pCreateTableSql->colInfo.pColumns, i); pSchema->type = pField->type; @@ -306,12 +308,11 @@ SCreateStbMsg* buildCreateTableMsg(SCreateTableSql* pCreateTableSql, int32_t* le } pMsg = (char*)pSchema; - } - int32_t msgLen = (int32_t)(pMsg - (char*)pCreateTableMsg); + int32_t msgLen = (int32_t)(pMsg - (char*)pCreateStbMsg); *len = msgLen; - return pCreateTableMsg; + return pCreateStbMsg; } SDropStbMsg* buildDropStableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* pParseCtx, SMsgBuf* pMsgBuf) { @@ -330,7 +331,7 @@ SDropStbMsg* buildDropStableMsg(SSqlInfo* pInfo, int32_t* len, SParseBasicCtx* p assert(code == TSDB_CODE_SUCCESS && name.type == TSDB_TABLE_NAME_T); pDropTableMsg->igNotExists = pInfo->pMiscInfo->existsCheck ? 1 : 0; - *len = sizeof(SDropTableMsg); + *len = sizeof(SDropStbMsg); return pDropTableMsg; } diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index 76e26c159b6d1c127c2ea02f55d918f3be1c04c0..d48041fbdbb2792d06d3c63a5750bd985fbdc1cb 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -1,10 +1,12 @@ +#include #include -#include #include "astToMsg.h" #include "parserInt.h" #include "parserUtil.h" #include "queryInfoUtil.h" #include "tglobal.h" +#include "tmsg.h" +#include "ttime.h" /* is contained in pFieldList or not */ static bool has(SArray* pFieldList, int32_t startIndex, const char* name) { @@ -109,7 +111,7 @@ static int32_t setShowInfo(SShowInfo* pShowInfo, SParseBasicCtx* pCtx, void** ou *pEpSet = pCtx->mgmtEpSet; *output = buildShowMsg(pShowInfo, pCtx, pMsgBuf->buf, pMsgBuf->len); - *outputLen = sizeof(SShowMsg) /* + htons(pShowMsg->payloadLen)*/; + *outputLen = sizeof(SShowReq) /* + htons(pShowMsg->payloadLen)*/; } return TSDB_CODE_SUCCESS; @@ -248,16 +250,10 @@ static int32_t validateTableColumns(SArray* pFieldList, int32_t maxRowLength, in } static int32_t validateTableColumnInfo(SArray* pFieldList, SMsgBuf* pMsgBuf) { - assert(pFieldList != NULL); + assert(pFieldList != NULL && pMsgBuf != NULL); const char* msg1 = "first column must be timestamp"; - const char* msg2 = "row length exceeds max length"; - const char* msg3 = "duplicated column names"; - const char* msg4 = "invalid data type"; - const char* msg5 = "invalid binary/nchar column length"; - const char* msg6 = "invalid column name"; - const char* msg7 = "too many columns"; - const char* msg8 = "illegal number of columns"; + const char* msg2 = "illegal number of columns"; // first column must be timestamp SField* pField = taosArrayGet(pFieldList, 0); @@ -268,7 +264,7 @@ static int32_t validateTableColumnInfo(SArray* pFieldList, SMsgBuf* pMsgBuf) { // number of fields no less than 2 size_t numOfCols = taosArrayGetSize(pFieldList); if (numOfCols <= 1) { - return buildInvalidOperationMsg(pMsgBuf, msg8); + return buildInvalidOperationMsg(pMsgBuf, msg2); } return validateTableColumns(pFieldList, TSDB_MAX_BYTES_PER_ROW, TSDB_MAX_COLUMNS, pMsgBuf); @@ -297,11 +293,9 @@ static int32_t validateTagParams(SArray* pTagsList, SArray* pFieldList, SMsgBuf* return validateTableColumns(pFieldList, TSDB_MAX_TAGS_LEN, TSDB_MAX_TAGS, pMsgBuf); } -int32_t doCheckForCreateTable(SSqlInfo* pInfo, SMsgBuf* pMsgBuf) { +int32_t doCheckForCreateTable(SCreateTableSql* pCreateTable, SMsgBuf* pMsgBuf) { const char* msg1 = "invalid table name"; - SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; - SArray* pFieldList = pCreateTable->colInfo.pColumns; SArray* pTagList = pCreateTable->colInfo.pTagColumns; assert(pFieldList != NULL); @@ -326,14 +320,79 @@ typedef struct SVgroupTablesBatch { SVgroupInfo info; } SVgroupTablesBatch; -int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* pMsgBuf, char** pOutput, int32_t* len) { +static SArray* doSerializeVgroupCreateTableInfo(SHashObj* pVgroupHashmap); + +static int32_t doParseSerializeTagValue(SSchema* pTagSchema, int32_t numOfInputTag, SKVRowBuilder* pKvRowBuilder, + SArray* pTagValList, int32_t tsPrecision, SMsgBuf* pMsgBuf) { + const char* msg1 = "illegal value or data overflow"; + int32_t code = TSDB_CODE_SUCCESS; + + for (int32_t i = 0; i < numOfInputTag; ++i) { + SSchema* pSchema = &pTagSchema[i]; + + char* endPtr = NULL; + char tmpTokenBuf[TSDB_MAX_TAGS_LEN] = {0}; + + SKvParam param = {.builder = pKvRowBuilder, .schema = pSchema}; + + SToken* pItem = taosArrayGet(pTagValList, i); + code = parseValueToken(&endPtr, pItem, pSchema, tsPrecision, tmpTokenBuf, KvRowAppend, ¶m, pMsgBuf); + + if (code != TSDB_CODE_SUCCESS) { + tdDestroyKVRowBuilder(pKvRowBuilder); + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + } + + return code; +} + +static void addCreateTbReqIntoVgroup(SHashObj* pVgroupHashmap, const SName* pTableName, SKVRow row, uint64_t suid, SVgroupInfo* pVgInfo) { + struct SVCreateTbReq req = {0}; + req.type = TD_CHILD_TABLE; + req.name = strdup(tNameGetTableName(pTableName)); + req.ctbCfg.suid = suid; + req.ctbCfg.pTag = row; + + SVgroupTablesBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId)); + if (pTableBatch == NULL) { + SVgroupTablesBatch tBatch = {0}; + tBatch.info = *pVgInfo; + + tBatch.req.pArray = taosArrayInit(4, sizeof(struct SVCreateTbReq)); + taosArrayPush(tBatch.req.pArray, &req); + + taosHashPut(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId), &tBatch, sizeof(tBatch)); + } else { // add to the correct vgroup + assert(pVgInfo->vgId == pTableBatch->info.vgId); + taosArrayPush(pTableBatch->req.pArray, &req); + } +} + +static void destroyCreateTbReqBatch(SVgroupTablesBatch* pTbBatch) { + size_t size = taosArrayGetSize(pTbBatch->req.pArray); + for(int32_t i = 0; i < size; ++i) { + SVCreateTbReq* pTableReq = taosArrayGet(pTbBatch->req.pArray, i); + tfree(pTableReq->name); + + if (pTableReq->type == TSDB_NORMAL_TABLE) { + tfree(pTableReq->ntbCfg.pSchema); + } else if (pTableReq->type == TSDB_CHILD_TABLE) { + tfree(pTableReq->ctbCfg.pTag); + } else { + assert(0); + } + } + + taosArrayDestroy(pTbBatch->req.pArray); +} + +static int32_t doCheckAndBuildCreateCTableReq(SCreateTableSql* pCreateTable, SParseBasicCtx* pCtx, SMsgBuf* pMsgBuf, SArray** pBufArray) { const char* msg1 = "invalid table name"; const char* msg2 = "tags number not matched"; const char* msg3 = "tag value too long"; const char* msg4 = "illegal value or data overflow"; - SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; - SHashObj* pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); // super table name, create table by using dst @@ -353,11 +412,15 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p return code; } + SKVRowBuilder kvRowBuilder = {0}; + if (tdInitKVRowBuilder(&kvRowBuilder) < 0) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + SArray* pValList = pCreateTableInfo->pTagVals; + size_t numOfInputTag = taosArrayGetSize(pValList); - size_t numOfInputTag = taosArrayGetSize(pValList); STableMeta* pSuperTableMeta = NULL; - code = catalogGetTableMeta(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &name, &pSuperTableMeta); if (code != TSDB_CODE_SUCCESS) { return code; @@ -369,26 +432,22 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta); STableComInfo tinfo = getTableInfo(pSuperTableMeta); - SKVRowBuilder kvRowBuilder = {0}; - if (tdInitKVRowBuilder(&kvRowBuilder) < 0) { - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - SArray* pNameList = NULL; - size_t nameSize = 0; + size_t numOfBoundTags = 0; int32_t schemaSize = getNumOfTags(pSuperTableMeta); if (pCreateTableInfo->pTagNames) { pNameList = pCreateTableInfo->pTagNames; - nameSize = taosArrayGetSize(pNameList); + numOfBoundTags = taosArrayGetSize(pNameList); - if (numOfInputTag != nameSize || schemaSize < numOfInputTag) { + if (numOfInputTag != numOfBoundTags || schemaSize < numOfInputTag) { tdDestroyKVRowBuilder(&kvRowBuilder); + tfree(pSuperTableMeta); return buildInvalidOperationMsg(pMsgBuf, msg2); } bool findColumnIndex = false; - for (int32_t i = 0; i < nameSize; ++i) { + for (int32_t i = 0; i < numOfBoundTags; ++i) { SToken* sToken = taosArrayGet(pNameList, i); char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW] = {0}; // create tmp buf to avoid alter orginal sqlstr @@ -416,6 +475,7 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) { if (pItem->pVar.nLen > pSchema->bytes) { tdDestroyKVRowBuilder(&kvRowBuilder); + tfree(pSuperTableMeta); return buildInvalidOperationMsg(pMsgBuf, msg3); } } else if (pSchema->type == TSDB_DATA_TYPE_TIMESTAMP) { @@ -436,12 +496,14 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p int16_t len = varDataTLen(tagVal); if (len > pSchema->bytes) { tdDestroyKVRowBuilder(&kvRowBuilder); + tfree(pSuperTableMeta); return buildInvalidOperationMsg(pMsgBuf, msg3); } } if (code != TSDB_CODE_SUCCESS) { tdDestroyKVRowBuilder(&kvRowBuilder); + tfree(pSuperTableMeta); return buildInvalidOperationMsg(pMsgBuf, msg4); } @@ -460,30 +522,22 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p } else { if (schemaSize != numOfInputTag) { tdDestroyKVRowBuilder(&kvRowBuilder); + tfree(pSuperTableMeta); return buildInvalidOperationMsg(pMsgBuf, msg2); } - for (int32_t i = 0; i < numOfInputTag; ++i) { - SSchema* pSchema = &pTagSchema[i]; - - char* endPtr = NULL; - char tmpTokenBuf[TSDB_MAX_TAGS_LEN] = {0}; - - SKvParam param = {.builder = &kvRowBuilder, .schema = pSchema}; - - SToken* pItem = taosArrayGet(pValList, i); - code = parseValueToken(&endPtr, pItem, pSchema, tinfo.precision, tmpTokenBuf, KvRowAppend, ¶m, pMsgBuf); - - if (code != TSDB_CODE_SUCCESS) { - tdDestroyKVRowBuilder(&kvRowBuilder); - return buildInvalidOperationMsg(pMsgBuf, msg4); - } + code = doParseSerializeTagValue(pTagSchema, numOfInputTag, &kvRowBuilder, pValList, tinfo.precision, pMsgBuf); + if (code != TSDB_CODE_SUCCESS) { + tdDestroyKVRowBuilder(&kvRowBuilder); + tfree(pSuperTableMeta); + return code; } } SKVRow row = tdGetKVRowFromBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder); if (row == NULL) { + tfree(pSuperTableMeta); return TSDB_CODE_QRY_OUT_OF_MEMORY; } @@ -492,71 +546,135 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p SName tableName = {0}; code = createSName(&tableName, &pCreateTableInfo->name, pCtx, pMsgBuf); if (code != TSDB_CODE_SUCCESS) { + tfree(pSuperTableMeta); return code; } + // Find a appropriate vgroup to accommodate this table , according to the table name SVgroupInfo info = {0}; catalogGetTableHashVgroup(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &tableName, &info); - struct SVCreateTbReq req = {0}; - req.type = TD_CHILD_TABLE; - req.name = strdup(tNameGetTableName(&tableName)); - req.ctbCfg.suid = pSuperTableMeta->suid; - req.ctbCfg.pTag = row; + addCreateTbReqIntoVgroup(pVgroupHashmap, &tableName, row, pSuperTableMeta->uid, &info); + tfree(pSuperTableMeta); + } - SVgroupTablesBatch* pTableBatch = taosHashGet(pVgroupHashmap, &info.vgId, sizeof(info.vgId)); - if (pTableBatch == NULL) { - SVgroupTablesBatch tBatch = {0}; - tBatch.info = info; + *pBufArray = doSerializeVgroupCreateTableInfo(pVgroupHashmap); - tBatch.req.pArray = taosArrayInit(4, sizeof(struct SVCreateTbReq)); - taosArrayPush(tBatch.req.pArray, &req); + taosHashCleanup(pVgroupHashmap); + return TSDB_CODE_SUCCESS; +} - taosHashPut(pVgroupHashmap, &info.vgId, sizeof(info.vgId), &tBatch, sizeof(tBatch)); - } else { // add to the correct vgroup - assert(info.vgId == pTableBatch->info.vgId); - taosArrayPush(pTableBatch->req.pArray, &req); - } +static int32_t serializeVgroupTablesBatchImpl(SVgroupTablesBatch* pTbBatch, SArray* pBufArray) { + int tlen = sizeof(SMsgHead) + tSVCreateTbBatchReqSerialize(NULL, &(pTbBatch->req)); + void* buf = malloc(tlen); + if (buf == NULL) { + // TODO: handle error } - // TODO: serialize and - SArray* pBufArray = taosArrayInit(taosHashGetSize(pVgroupHashmap), sizeof(void*)); + ((SMsgHead*)buf)->vgId = htonl(pTbBatch->info.vgId); + ((SMsgHead*)buf)->contLen = htonl(tlen); - SVgroupTablesBatch* pTbBatch = NULL; - do { - pTbBatch = taosHashIterate(pVgroupHashmap, pTbBatch); - if (pTbBatch == NULL) break; + void* pBuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + tSVCreateTbBatchReqSerialize(&pBuf, &(pTbBatch->req)); + + SVgDataBlocks* pVgData = calloc(1, sizeof(SVgDataBlocks)); + pVgData->vg = pTbBatch->info; + pVgData->pData = buf; + pVgData->size = tlen; + pVgData->numOfTables = (int32_t) taosArrayGetSize(pTbBatch->req.pArray); + + taosArrayPush(pBufArray, &pVgData); +} + +static int32_t doBuildSingleTableBatchReq(SName* pTableName, SArray* pColumns, SVgroupInfo* pVgroupInfo, SVgroupTablesBatch* pBatch) { + struct SVCreateTbReq req = {0}; + req.type = TD_NORMAL_TABLE; + req.name = strdup(tNameGetTableName(pTableName)); + + req.ntbCfg.nCols = taosArrayGetSize(pColumns); + int32_t num = req.ntbCfg.nCols; + + req.ntbCfg.pSchema = calloc(num, sizeof(SSchema)); + for(int32_t i = 0; i < num; ++i) { + SSchema* pSchema = taosArrayGet(pColumns, i); + memcpy(&req.ntbCfg.pSchema[i], pSchema, sizeof(SSchema)); + } + + pBatch->info = *pVgroupInfo; + pBatch->req.pArray = taosArrayInit(1, sizeof(struct SVCreateTbReq)); + if (pBatch->req.pArray == NULL) { + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } - int tlen = sizeof(SMsgHead) + tSVCreateTbBatchReqSerialize(NULL, &(pTbBatch->req)); - void* buf = malloc(tlen); - if (buf == NULL) { - // TODO: handle error + taosArrayPush(pBatch->req.pArray, &req); + return TSDB_CODE_SUCCESS; +} + +int32_t doCheckAndBuildCreateTableReq(SCreateTableSql* pCreateTable, SParseBasicCtx* pCtx, SMsgBuf* pMsgBuf, char** pOutput, int32_t* len) { + SArray* pBufArray = NULL; + + // it is a sql statement to create a normal table + if (pCreateTable->childTableInfo == NULL) { + assert(taosArrayGetSize(pCreateTable->colInfo.pColumns) > 0 && pCreateTable->colInfo.pTagColumns == NULL); + int32_t code = doCheckForCreateTable(pCreateTable, pMsgBuf); + if (code != TSDB_CODE_SUCCESS) { + return code; } - ((SMsgHead*)buf)->vgId = htonl(pTbBatch->info.vgId); - ((SMsgHead*)buf)->contLen = htonl(tlen); + SName tableName = {0}; + code = createSName(&tableName, &pCreateTable->name, pCtx, pMsgBuf); + if (code != TSDB_CODE_SUCCESS) { + return code; + } - void* pBuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - tSVCreateTbBatchReqSerialize(&pBuf, &(pTbBatch->req)); + SVgroupInfo info = {0}; + catalogGetTableHashVgroup(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &tableName, &info); - SVgDataBlocks* pVgData = calloc(1, sizeof(SVgDataBlocks)); - pVgData->vg = pTbBatch->info; - pVgData->pData = buf; - pVgData->size = tlen; - pVgData->numOfTables = (int32_t) taosArrayGetSize(pTbBatch->req.pArray); + SVgroupTablesBatch tbatch = {0}; + code = doBuildSingleTableBatchReq(&tableName, pCreateTable->colInfo.pColumns, &info, &tbatch); + if (code != TSDB_CODE_SUCCESS) { + return code; + } - taosArrayPush(pBufArray, &pVgData); - } while (true); + pBufArray = taosArrayInit(1, POINTER_BYTES); + if (pBufArray == NULL) { + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } + + serializeVgroupTablesBatchImpl(&tbatch, pBufArray); + destroyCreateTbReqBatch(&tbatch); + + } else { // it is a child table, created according to a super table + doCheckAndBuildCreateCTableReq(pCreateTable, pCtx, pMsgBuf, &pBufArray); + } - SInsertStmtInfo* pStmtInfo = calloc(1, sizeof(SInsertStmtInfo)); - pStmtInfo->nodeType = TSDB_SQL_CREATE_TABLE; + SVnodeModifOpStmtInfo* pStmtInfo = calloc(1, sizeof(SVnodeModifOpStmtInfo)); + pStmtInfo->nodeType = TSDB_SQL_CREATE_TABLE; pStmtInfo->pDataBlocks = pBufArray; - *pOutput = pStmtInfo; - *len = sizeof(SInsertStmtInfo); + + *pOutput = (char*) pStmtInfo; + *len = sizeof(SVnodeModifOpStmtInfo); return TSDB_CODE_SUCCESS; } +SArray* doSerializeVgroupCreateTableInfo(SHashObj* pVgroupHashmap) { + SArray* pBufArray = taosArrayInit(taosHashGetSize(pVgroupHashmap), sizeof(void*)); + + SVgroupTablesBatch* pTbBatch = NULL; + do { + pTbBatch = taosHashIterate(pVgroupHashmap, pTbBatch); + if (pTbBatch == NULL) { + break; + } + + /*int32_t code = */serializeVgroupTablesBatchImpl(pTbBatch, pBufArray); + destroyCreateTbReqBatch(pTbBatch); + } while (true); + + return pBufArray; +} + SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen) { int32_t code = 0; @@ -761,29 +879,15 @@ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, c break; } - case TSDB_SQL_CREATE_TABLE: { + case TSDB_SQL_CREATE_STABLE: { SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; - - if (pCreateTable->type == TSQL_CREATE_TABLE || pCreateTable->type == TSQL_CREATE_STABLE) { - if ((code = doCheckForCreateTable(pInfo, pMsgBuf)) != TSDB_CODE_SUCCESS) { - terrno = code; - goto _error; - } - - pDcl->pMsg = (char*)buildCreateTableMsg(pCreateTable, &pDcl->msgLen, pCtx, pMsgBuf); - pDcl->msgType = (pCreateTable->type == TSQL_CREATE_TABLE) ? TDMT_VND_CREATE_TABLE : TDMT_MND_CREATE_STB; - } else if (pCreateTable->type == TSQL_CREATE_CTABLE) { - if ((code = doCheckForCreateCTable(pInfo, pCtx, pMsgBuf, &pDcl->pMsg, &pDcl->msgLen)) != - TSDB_CODE_SUCCESS) { - goto _error; - } - - pDcl->msgType = TDMT_VND_CREATE_TABLE; - } else if (pCreateTable->type == TSQL_CREATE_STREAM) { - // if ((code = doCheckForStream(pSql, pInfo)) != TSDB_CODE_SUCCESS) { - // return code; + if ((code = doCheckForCreateTable(pCreateTable, pMsgBuf)) != TSDB_CODE_SUCCESS) { + terrno = code; + goto _error; } + pDcl->pMsg = (char*)buildCreateStbMsg(pCreateTable, &pDcl->msgLen, pCtx, pMsgBuf); + pDcl->msgType = TDMT_MND_CREATE_STB; break; } @@ -829,21 +933,21 @@ SDclStmtInfo* qParserValidateDclSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, c return NULL; } -SInsertStmtInfo* qParserValidateCreateTbSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen) { +SVnodeModifOpStmtInfo* qParserValidateCreateTbSqlNode(SSqlInfo* pInfo, SParseBasicCtx* pCtx, char* msgBuf, int32_t msgBufLen) { SCreateTableSql* pCreateTable = pInfo->pCreateTableInfo; - assert(pCreateTable->type == TSQL_CREATE_CTABLE); + assert(pCreateTable->type == TSDB_SQL_CREATE_TABLE); SMsgBuf m = {.buf = msgBuf, .len = msgBufLen}; SMsgBuf* pMsgBuf = &m; - SInsertStmtInfo* pInsertStmt = NULL; + SVnodeModifOpStmtInfo* pModifSqlStmt = NULL; int32_t msgLen = 0; - int32_t code = doCheckForCreateCTable(pInfo, pCtx, pMsgBuf, (char**) &pInsertStmt, &msgLen); + int32_t code = doCheckAndBuildCreateTableReq(pCreateTable, pCtx, pMsgBuf, (char**) &pModifSqlStmt, &msgLen); if (code != TSDB_CODE_SUCCESS) { - tfree(pInsertStmt); + tfree(pModifSqlStmt); return NULL; } - return pInsertStmt; + return pModifSqlStmt; } \ No newline at end of file diff --git a/source/libs/parser/src/dataBlockMgt.c b/source/libs/parser/src/dataBlockMgt.c index b315ea613f86f19d17cc2a32c5f24342b8f04caa..bc4eae7ae99aa022ad3be554a210014968155673 100644 --- a/source/libs/parser/src/dataBlockMgt.c +++ b/source/libs/parser/src/dataBlockMgt.c @@ -467,7 +467,7 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SB } int32_t mergeTableDataBlocks(SHashObj* pHashObj, int8_t schemaAttached, uint8_t payloadType, SArray** pVgDataBlocks) { - const int INSERT_HEAD_SIZE = sizeof(SMsgDesc) + sizeof(SSubmitMsg); + const int INSERT_HEAD_SIZE = sizeof(SSubmitMsg); int code = 0; bool isRawPayload = IS_RAW_PAYLOAD(payloadType); SHashObj* pVnodeDataBlockHashList = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false); diff --git a/source/libs/parser/src/insertParser.c b/source/libs/parser/src/insertParser.c index 66966f75db59f9e01a710b7429312bfc5d911e8a..8b3c328cce3068a1e1ac77877b4340521f325fc0 100644 --- a/source/libs/parser/src/insertParser.c +++ b/source/libs/parser/src/insertParser.c @@ -61,7 +61,7 @@ typedef struct SInsertParseContext { SArray* pTableDataBlocks; // global SArray* pVgDataBlocks; // global int32_t totalNum; - SInsertStmtInfo* pOutput; + SVnodeModifOpStmtInfo* pOutput; } SInsertParseContext; static int32_t skipInsertInto(SInsertParseContext* pCxt) { @@ -106,6 +106,7 @@ static int32_t getTableMeta(SInsertParseContext* pCxt, SToken* pTname) { SVgroupInfo vg; CHECK_CODE(catalogGetTableHashVgroup(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name, &vg)); CHECK_CODE(taosHashPut(pCxt->pVgroupsHashObj, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg))); + pCxt->pTableMeta->vgId = vg.vgId; // todo remove return TSDB_CODE_SUCCESS; } @@ -120,11 +121,9 @@ static int32_t findCol(SToken* pColname, int32_t start, int32_t end, SSchema* pS } static void buildMsgHeader(SVgDataBlocks* blocks) { - SMsgDesc* desc = (SMsgDesc*)blocks->pData; - desc->numOfVnodes = htonl(1); - SSubmitMsg* submit = (SSubmitMsg*)(desc + 1); + SSubmitMsg* submit = (SSubmitMsg*)blocks->pData; submit->header.vgId = htonl(blocks->vg.vgId); - submit->header.contLen = htonl(blocks->size - sizeof(SMsgDesc)); + submit->header.contLen = htonl(blocks->size); submit->length = submit->header.contLen; submit->numOfBlocks = htonl(blocks->numOfTables); SSubmitBlk* blk = (SSubmitBlk*)(submit + 1); @@ -425,7 +424,7 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, // 1. set the parsed value from sql string for (int i = 0; i < spd->numOfBound; ++i) { NEXT_TOKEN(pCxt->pSql, sToken); - SSchema *pSchema = &schema[spd->boundedColumns[i]]; + SSchema *pSchema = &schema[spd->boundedColumns[i] - 1]; param.schema = pSchema; param.compareStat = pBuilder->compareStat; getMemRowAppendInfo(schema, pBuilder->memRowType, spd, i, ¶m.toffset); @@ -611,7 +610,7 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { // [(field1_name, ...)] // VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path // [...]; -int32_t parseInsertSql(SParseContext* pContext, SInsertStmtInfo** pInfo) { +int32_t parseInsertSql(SParseContext* pContext, SVnodeModifOpStmtInfo** pInfo) { SInsertParseContext context = { .pComCxt = pContext, .pSql = (char*) pContext->pSql, @@ -620,7 +619,7 @@ int32_t parseInsertSql(SParseContext* pContext, SInsertStmtInfo** pInfo) { .pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, false), .pTableBlockHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false), .totalNum = 0, - .pOutput = calloc(1, sizeof(SInsertStmtInfo)) + .pOutput = calloc(1, sizeof(SVnodeModifOpStmtInfo)) }; if (NULL == context.pVgroupsHashObj || NULL == context.pTableBlockHashObj || NULL == context.pOutput) { diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 1b4d05808c055c8e567354b1ce2798de613f4540..85a8d9e0475c16b67b75ece53ce6030d94aaf1bf 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -44,21 +44,21 @@ int32_t parseQuerySql(SParseContext* pCxt, SQueryNode** pQuery) { } if (!isDqlSqlStatement(&info)) { - bool toVnode = false; +// bool toVnode = false; if (info.type == TSDB_SQL_CREATE_TABLE) { - SCreateTableSql* pCreateSql = info.pCreateTableInfo; - if (pCreateSql->type == TSQL_CREATE_CTABLE || pCreateSql->type == TSQL_CREATE_TABLE) { - toVnode = true; - } - } - - if (toVnode) { - SInsertStmtInfo *pInsertInfo = qParserValidateCreateTbSqlNode(&info, &pCxt->ctx, pCxt->pMsg, pCxt->msgLen); - if (pInsertInfo == NULL) { +// SCreateTableSql* pCreateSql = info.pCreateTableInfo; +// if (pCreateSql->type == TSQL_CREATE_CTABLE || pCreateSql->type == TSQL_CREATE_TABLE) { +// toVnode = true; +// } +// } + +// if (toVnode) { + SVnodeModifOpStmtInfo * pModifStmtInfo = qParserValidateCreateTbSqlNode(&info, &pCxt->ctx, pCxt->pMsg, pCxt->msgLen); + if (pModifStmtInfo == NULL) { return terrno; } - *pQuery = (SQueryNode*) pInsertInfo; + *pQuery = (SQueryNode*)pModifStmtInfo; } else { SDclStmtInfo* pDcl = qParserValidateDclSqlNode(&info, &pCxt->ctx, pCxt->pMsg, pCxt->msgLen); if (pDcl == NULL) { @@ -87,7 +87,7 @@ int32_t parseQuerySql(SParseContext* pCxt, SQueryNode** pQuery) { int32_t qParseQuerySql(SParseContext* pCxt, SQueryNode** pQuery) { if (isInsertSql(pCxt->pSql, pCxt->sqlLen)) { - return parseInsertSql(pCxt, (SInsertStmtInfo**)pQuery); + return parseInsertSql(pCxt, (SVnodeModifOpStmtInfo**)pQuery); } else { return parseQuerySql(pCxt, pQuery); } @@ -240,6 +240,10 @@ void qParserCleanupMetaRequestInfo(SCatalogReq* pMetaReq) { taosArrayDestroy(pMetaReq->pUdf); } -void qDestroyQuery(SQueryNode* pQuery) { - // todo +void qDestroyQuery(SQueryNode* pQueryNode) { + if (nodeType(pQueryNode) == TSDB_SQL_INSERT || nodeType(pQueryNode) == TSDB_SQL_CREATE_TABLE) { + SVnodeModifOpStmtInfo* pModifInfo = (SVnodeModifOpStmtInfo*)pQueryNode; + taosArrayDestroy(pModifInfo->pDataBlocks); + } + tfree(pQueryNode); } diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index f7f56510daf1ccfb5e9eebae56ce006622082a3e..a6537998f7697d0cf740f9f6924223a0031e20b4 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -131,16 +131,16 @@ typedef union { #define ParseARG_STORE yypParser->pInfo = pInfo #define YYFALLBACK 1 #define YYNSTATE 366 -#define YYNRULE 303 +#define YYNRULE 302 #define YYNTOKEN 191 #define YY_MAX_SHIFT 365 -#define YY_MIN_SHIFTREDUCE 587 -#define YY_MAX_SHIFTREDUCE 889 -#define YY_ERROR_ACTION 890 -#define YY_ACCEPT_ACTION 891 -#define YY_NO_ACTION 892 -#define YY_MIN_REDUCE 893 -#define YY_MAX_REDUCE 1195 +#define YY_MIN_SHIFTREDUCE 586 +#define YY_MAX_SHIFTREDUCE 887 +#define YY_ERROR_ACTION 888 +#define YY_ACCEPT_ACTION 889 +#define YY_NO_ACTION 890 +#define YY_MIN_REDUCE 891 +#define YY_MAX_REDUCE 1192 /************* End control #defines *******************************************/ /* Define the yytestcase() macro to be a no-op if is not already defined @@ -206,168 +206,167 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (782) +#define YY_ACTTAB_COUNT (777) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 249, 638, 364, 230, 162, 639, 248, 55, 56, 638, - /* 10 */ 59, 60, 1031, 639, 252, 49, 48, 47, 94, 58, - /* 20 */ 323, 63, 61, 64, 62, 674, 1080, 891, 365, 54, - /* 30 */ 53, 206, 82, 52, 51, 50, 253, 55, 56, 638, - /* 40 */ 59, 60, 1171, 639, 252, 49, 48, 47, 21, 58, - /* 50 */ 323, 63, 61, 64, 62, 1017, 203, 1015, 1016, 54, - /* 60 */ 53, 206, 1018, 52, 51, 50, 1019, 206, 1020, 1021, - /* 70 */ 832, 835, 1172, 55, 56, 1070, 59, 60, 1172, 1118, - /* 80 */ 252, 49, 48, 47, 81, 58, 323, 63, 61, 64, - /* 90 */ 62, 321, 319, 274, 1077, 54, 53, 206, 638, 52, - /* 100 */ 51, 50, 639, 55, 57, 353, 59, 60, 1172, 826, - /* 110 */ 252, 49, 48, 47, 155, 58, 323, 63, 61, 64, - /* 120 */ 62, 42, 319, 359, 358, 54, 53, 162, 357, 52, - /* 130 */ 51, 50, 356, 87, 355, 354, 162, 162, 588, 589, - /* 140 */ 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, - /* 150 */ 600, 601, 153, 56, 231, 59, 60, 236, 1057, 252, - /* 160 */ 49, 48, 47, 87, 58, 323, 63, 61, 64, 62, - /* 170 */ 772, 43, 32, 86, 54, 53, 255, 204, 52, 51, - /* 180 */ 50, 309, 209, 280, 279, 59, 60, 941, 839, 252, - /* 190 */ 49, 48, 47, 188, 58, 323, 63, 61, 64, 62, - /* 200 */ 294, 43, 92, 242, 54, 53, 300, 1045, 52, 51, - /* 210 */ 50, 1119, 93, 292, 42, 317, 359, 358, 316, 315, - /* 220 */ 314, 357, 313, 312, 311, 356, 310, 355, 354, 99, - /* 230 */ 22, 1010, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, - /* 240 */ 1006, 1007, 1008, 1009, 1011, 1012, 1013, 215, 251, 841, - /* 250 */ 830, 833, 836, 256, 216, 254, 776, 331, 330, 250, - /* 260 */ 137, 136, 135, 217, 1033, 266, 719, 328, 87, 251, - /* 270 */ 841, 830, 833, 836, 270, 269, 228, 229, 831, 834, - /* 280 */ 324, 4, 63, 61, 64, 62, 755, 752, 753, 754, - /* 290 */ 54, 53, 343, 342, 52, 51, 50, 228, 229, 747, - /* 300 */ 744, 745, 746, 52, 51, 50, 43, 3, 39, 178, - /* 310 */ 152, 150, 149, 257, 258, 105, 77, 101, 108, 1039, - /* 320 */ 96, 791, 792, 260, 36, 65, 244, 245, 273, 36, - /* 330 */ 79, 197, 195, 193, 36, 305, 210, 224, 192, 141, - /* 340 */ 140, 139, 138, 36, 36, 36, 65, 122, 116, 126, - /* 350 */ 36, 211, 1028, 1029, 33, 1032, 131, 134, 125, 638, - /* 360 */ 36, 842, 837, 639, 243, 128, 36, 232, 838, 54, - /* 370 */ 53, 1042, 240, 52, 51, 50, 1042, 241, 36, 36, - /* 380 */ 36, 1042, 842, 837, 1166, 261, 332, 333, 334, 838, - /* 390 */ 1042, 1042, 1042, 335, 176, 12, 840, 1042, 756, 757, - /* 400 */ 262, 95, 259, 339, 338, 337, 171, 1042, 363, 362, - /* 410 */ 146, 748, 749, 1041, 246, 80, 808, 1070, 1045, 1070, - /* 420 */ 261, 340, 341, 345, 282, 1042, 1042, 1042, 124, 177, - /* 430 */ 98, 261, 952, 942, 769, 233, 27, 234, 188, 188, - /* 440 */ 1043, 275, 353, 360, 979, 84, 85, 788, 1030, 798, - /* 450 */ 799, 71, 74, 729, 297, 731, 299, 37, 325, 7, - /* 460 */ 742, 743, 730, 157, 828, 66, 24, 740, 741, 37, - /* 470 */ 37, 67, 97, 864, 807, 760, 761, 843, 67, 637, - /* 480 */ 14, 78, 13, 70, 70, 115, 1165, 114, 16, 23, - /* 490 */ 15, 75, 72, 23, 1111, 23, 829, 758, 759, 133, - /* 500 */ 132, 18, 121, 17, 120, 20, 1164, 19, 1129, 226, - /* 510 */ 322, 227, 207, 1056, 718, 208, 212, 205, 213, 214, - /* 520 */ 1044, 219, 1072, 220, 1191, 221, 218, 202, 1128, 1183, - /* 530 */ 238, 1125, 1124, 239, 344, 271, 154, 44, 172, 1079, - /* 540 */ 151, 1110, 1090, 1087, 1088, 1071, 277, 1092, 1040, 156, - /* 550 */ 1068, 281, 235, 283, 31, 161, 285, 165, 288, 173, - /* 560 */ 163, 168, 787, 845, 164, 276, 1038, 174, 166, 169, - /* 570 */ 167, 291, 175, 956, 302, 303, 304, 76, 307, 308, - /* 580 */ 200, 40, 320, 951, 950, 329, 1190, 112, 73, 1189, - /* 590 */ 1186, 179, 46, 336, 295, 1182, 118, 287, 1181, 1178, - /* 600 */ 180, 976, 41, 38, 201, 939, 127, 937, 129, 130, - /* 610 */ 935, 934, 263, 190, 191, 931, 930, 929, 928, 293, - /* 620 */ 927, 926, 925, 194, 196, 922, 920, 918, 916, 198, - /* 630 */ 913, 199, 909, 289, 284, 83, 88, 45, 286, 1112, - /* 640 */ 306, 123, 346, 225, 247, 347, 301, 348, 349, 351, - /* 650 */ 222, 223, 350, 352, 361, 955, 954, 106, 889, 264, - /* 660 */ 265, 888, 267, 268, 887, 870, 933, 869, 272, 183, - /* 670 */ 182, 977, 932, 181, 142, 184, 185, 187, 186, 143, - /* 680 */ 144, 924, 978, 923, 2, 70, 145, 915, 914, 296, - /* 690 */ 8, 28, 1, 763, 278, 170, 789, 89, 158, 160, - /* 700 */ 800, 159, 237, 794, 90, 29, 796, 91, 290, 9, - /* 710 */ 30, 10, 11, 25, 26, 298, 100, 34, 98, 103, - /* 720 */ 652, 102, 690, 35, 104, 687, 685, 684, 683, 681, - /* 730 */ 680, 679, 676, 642, 326, 327, 107, 111, 109, 318, - /* 740 */ 113, 110, 5, 68, 844, 846, 6, 69, 721, 37, - /* 750 */ 117, 119, 720, 717, 668, 666, 658, 664, 660, 662, - /* 760 */ 656, 654, 689, 688, 686, 682, 678, 677, 189, 640, - /* 770 */ 893, 605, 892, 892, 892, 892, 892, 892, 892, 892, - /* 780 */ 147, 148, + /* 0 */ 249, 637, 637, 1077, 83, 717, 248, 55, 56, 88, + /* 10 */ 59, 60, 364, 230, 252, 49, 48, 47, 78, 58, + /* 20 */ 323, 63, 61, 64, 62, 236, 1054, 889, 365, 54, + /* 30 */ 53, 343, 342, 52, 51, 50, 253, 55, 56, 242, + /* 40 */ 59, 60, 1027, 1042, 252, 49, 48, 47, 104, 58, + /* 50 */ 323, 63, 61, 64, 62, 1014, 637, 1012, 1013, 54, + /* 60 */ 53, 206, 1015, 52, 51, 50, 1016, 206, 1017, 1018, + /* 70 */ 121, 1074, 1169, 55, 56, 1067, 59, 60, 1169, 27, + /* 80 */ 252, 49, 48, 47, 89, 58, 323, 63, 61, 64, + /* 90 */ 62, 206, 39, 274, 246, 54, 53, 206, 1042, 52, + /* 100 */ 51, 50, 1168, 55, 57, 1030, 59, 60, 1169, 824, + /* 110 */ 252, 49, 48, 47, 80, 58, 323, 63, 61, 64, + /* 120 */ 62, 294, 637, 81, 159, 54, 53, 91, 319, 52, + /* 130 */ 51, 50, 104, 1067, 56, 232, 59, 60, 353, 1039, + /* 140 */ 252, 49, 48, 47, 261, 58, 323, 63, 61, 64, + /* 150 */ 62, 233, 43, 124, 79, 54, 53, 80, 39, 52, + /* 160 */ 51, 50, 587, 588, 589, 590, 591, 592, 593, 594, + /* 170 */ 595, 596, 597, 598, 599, 600, 199, 309, 231, 59, + /* 180 */ 60, 939, 1067, 252, 49, 48, 47, 158, 58, 323, + /* 190 */ 63, 61, 64, 62, 353, 43, 280, 279, 54, 53, + /* 200 */ 234, 240, 52, 51, 50, 1039, 14, 1116, 13, 292, + /* 210 */ 42, 317, 359, 358, 316, 315, 314, 357, 313, 312, + /* 220 */ 311, 356, 310, 355, 354, 1007, 995, 996, 997, 998, + /* 230 */ 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1008, 1009, + /* 240 */ 1010, 266, 12, 22, 63, 61, 64, 62, 84, 21, + /* 250 */ 270, 269, 54, 53, 789, 790, 52, 51, 50, 946, + /* 260 */ 215, 113, 251, 839, 828, 831, 834, 216, 753, 750, + /* 270 */ 751, 752, 672, 175, 174, 172, 217, 119, 261, 282, + /* 280 */ 328, 80, 251, 839, 828, 831, 834, 127, 116, 203, + /* 290 */ 228, 229, 255, 39, 324, 257, 258, 745, 742, 743, + /* 300 */ 744, 204, 39, 1036, 3, 32, 131, 261, 209, 260, + /* 310 */ 228, 229, 129, 85, 123, 133, 1040, 39, 39, 43, + /* 320 */ 1025, 1026, 30, 1029, 244, 245, 189, 186, 183, 52, + /* 330 */ 51, 50, 305, 181, 179, 178, 177, 176, 319, 65, + /* 340 */ 1038, 273, 637, 86, 42, 241, 359, 358, 243, 1039, + /* 350 */ 224, 357, 770, 830, 833, 356, 39, 355, 354, 65, + /* 360 */ 332, 333, 54, 53, 1039, 1039, 52, 51, 50, 256, + /* 370 */ 39, 254, 39, 331, 330, 840, 835, 104, 39, 39, + /* 380 */ 754, 755, 836, 149, 142, 162, 262, 39, 259, 806, + /* 390 */ 338, 337, 167, 170, 160, 840, 835, 829, 832, 334, + /* 400 */ 104, 164, 836, 1039, 826, 363, 362, 190, 767, 746, + /* 410 */ 747, 92, 949, 335, 940, 339, 93, 1039, 158, 1039, + /* 420 */ 158, 340, 341, 71, 321, 1039, 1039, 198, 195, 193, + /* 430 */ 345, 360, 976, 7, 1039, 275, 827, 786, 774, 796, + /* 440 */ 797, 74, 727, 297, 729, 299, 325, 805, 35, 70, + /* 450 */ 210, 40, 1115, 97, 70, 66, 24, 728, 40, 40, + /* 460 */ 67, 117, 740, 741, 72, 738, 739, 862, 841, 250, + /* 470 */ 636, 837, 140, 67, 139, 82, 16, 18, 15, 17, + /* 480 */ 75, 211, 300, 23, 23, 77, 23, 758, 759, 169, + /* 490 */ 168, 4, 756, 757, 147, 20, 146, 19, 1163, 1162, + /* 500 */ 1161, 226, 227, 207, 208, 212, 1053, 1041, 205, 1126, + /* 510 */ 213, 214, 219, 220, 221, 838, 218, 202, 716, 1188, + /* 520 */ 1180, 1125, 1069, 238, 1122, 1121, 239, 44, 1068, 344, + /* 530 */ 277, 114, 322, 1108, 1107, 196, 271, 785, 1037, 276, + /* 540 */ 1065, 87, 1076, 1087, 281, 235, 73, 90, 1084, 1085, + /* 550 */ 76, 843, 283, 1089, 295, 46, 105, 106, 94, 107, + /* 560 */ 293, 95, 101, 108, 285, 291, 288, 286, 109, 1109, + /* 570 */ 289, 110, 287, 111, 284, 112, 29, 45, 225, 115, + /* 580 */ 1035, 306, 150, 247, 118, 952, 346, 120, 301, 953, + /* 590 */ 302, 303, 304, 974, 307, 308, 200, 347, 348, 38, + /* 600 */ 320, 349, 948, 951, 947, 130, 329, 350, 1187, 351, + /* 610 */ 352, 361, 137, 1186, 1183, 887, 141, 222, 336, 1179, + /* 620 */ 152, 144, 1178, 265, 1175, 886, 148, 223, 973, 268, + /* 630 */ 885, 868, 867, 70, 296, 8, 28, 41, 31, 761, + /* 640 */ 278, 96, 153, 201, 937, 151, 154, 156, 157, 155, + /* 650 */ 163, 935, 165, 1, 166, 933, 264, 932, 263, 171, + /* 660 */ 267, 975, 931, 930, 173, 929, 928, 927, 926, 925, + /* 670 */ 924, 272, 923, 787, 180, 184, 98, 182, 922, 798, + /* 680 */ 185, 921, 99, 188, 187, 920, 918, 792, 100, 916, + /* 690 */ 914, 102, 194, 913, 911, 912, 197, 907, 794, 2, + /* 700 */ 237, 103, 290, 9, 33, 34, 10, 11, 25, 298, + /* 710 */ 26, 122, 119, 36, 126, 125, 650, 688, 37, 128, + /* 720 */ 685, 683, 682, 681, 679, 678, 677, 674, 640, 132, + /* 730 */ 5, 134, 135, 842, 318, 844, 6, 326, 327, 68, + /* 740 */ 136, 40, 69, 719, 718, 138, 143, 145, 715, 666, + /* 750 */ 664, 656, 662, 658, 660, 654, 652, 687, 686, 684, + /* 760 */ 680, 676, 675, 161, 604, 638, 891, 890, 890, 890, + /* 770 */ 890, 890, 890, 890, 890, 191, 192, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 200, 1, 194, 195, 194, 5, 200, 7, 8, 1, - /* 10 */ 10, 11, 0, 5, 14, 15, 16, 17, 245, 19, - /* 20 */ 20, 21, 22, 23, 24, 3, 194, 192, 193, 29, - /* 30 */ 30, 261, 259, 33, 34, 35, 200, 7, 8, 1, - /* 40 */ 10, 11, 272, 5, 14, 15, 16, 17, 261, 19, - /* 50 */ 20, 21, 22, 23, 24, 216, 261, 218, 219, 29, + /* 0 */ 200, 1, 1, 194, 245, 3, 200, 7, 8, 201, + /* 10 */ 10, 11, 194, 195, 14, 15, 16, 17, 259, 19, + /* 20 */ 20, 21, 22, 23, 24, 243, 244, 192, 193, 29, + /* 30 */ 30, 29, 30, 33, 34, 35, 200, 7, 8, 238, + /* 40 */ 10, 11, 234, 242, 14, 15, 16, 17, 194, 19, + /* 50 */ 20, 21, 22, 23, 24, 216, 1, 218, 219, 29, /* 60 */ 30, 261, 223, 33, 34, 35, 227, 261, 229, 230, - /* 70 */ 3, 4, 272, 7, 8, 240, 10, 11, 272, 269, + /* 70 */ 201, 262, 272, 7, 8, 240, 10, 11, 272, 78, /* 80 */ 14, 15, 16, 17, 84, 19, 20, 21, 22, 23, - /* 90 */ 24, 83, 80, 258, 262, 29, 30, 261, 1, 33, - /* 100 */ 34, 35, 5, 7, 8, 88, 10, 11, 272, 79, - /* 110 */ 14, 15, 16, 17, 194, 19, 20, 21, 22, 23, - /* 120 */ 24, 96, 80, 98, 99, 29, 30, 194, 103, 33, - /* 130 */ 34, 35, 107, 78, 109, 110, 194, 194, 41, 42, - /* 140 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, - /* 150 */ 53, 54, 55, 8, 57, 10, 11, 243, 244, 14, - /* 160 */ 15, 16, 17, 78, 19, 20, 21, 22, 23, 24, - /* 170 */ 33, 116, 78, 118, 29, 30, 64, 261, 33, 34, - /* 180 */ 35, 63, 261, 263, 264, 10, 11, 199, 121, 14, - /* 190 */ 15, 16, 17, 205, 19, 20, 21, 22, 23, 24, - /* 200 */ 267, 116, 269, 238, 29, 30, 112, 242, 33, 34, - /* 210 */ 35, 269, 269, 271, 96, 97, 98, 99, 100, 101, - /* 220 */ 102, 103, 104, 105, 106, 107, 108, 109, 110, 201, - /* 230 */ 40, 216, 217, 218, 219, 220, 221, 222, 223, 224, - /* 240 */ 225, 226, 227, 228, 229, 230, 231, 57, 1, 2, - /* 250 */ 3, 4, 5, 141, 64, 143, 119, 145, 146, 56, - /* 260 */ 70, 71, 72, 73, 236, 139, 3, 77, 78, 1, - /* 270 */ 2, 3, 4, 5, 148, 149, 29, 30, 3, 4, - /* 280 */ 33, 78, 21, 22, 23, 24, 2, 3, 4, 5, - /* 290 */ 29, 30, 29, 30, 33, 34, 35, 29, 30, 2, - /* 300 */ 3, 4, 5, 33, 34, 35, 116, 58, 59, 60, - /* 310 */ 58, 59, 60, 29, 30, 66, 67, 68, 69, 194, - /* 320 */ 201, 122, 123, 64, 194, 78, 29, 30, 138, 194, - /* 330 */ 140, 58, 59, 60, 194, 86, 261, 147, 65, 66, - /* 340 */ 67, 68, 69, 194, 194, 194, 78, 58, 59, 60, - /* 350 */ 194, 261, 233, 234, 235, 236, 67, 68, 69, 1, - /* 360 */ 194, 114, 115, 5, 239, 76, 194, 237, 121, 29, - /* 370 */ 30, 241, 237, 33, 34, 35, 241, 237, 194, 194, - /* 380 */ 194, 241, 114, 115, 261, 194, 237, 237, 237, 121, - /* 390 */ 241, 241, 241, 237, 203, 78, 121, 241, 114, 115, - /* 400 */ 141, 84, 143, 237, 145, 146, 248, 241, 61, 62, - /* 410 */ 63, 114, 115, 241, 238, 201, 72, 240, 242, 240, - /* 420 */ 194, 237, 237, 237, 266, 241, 241, 241, 74, 203, - /* 430 */ 113, 194, 199, 199, 95, 258, 78, 258, 205, 205, - /* 440 */ 203, 79, 88, 214, 215, 79, 79, 79, 234, 79, - /* 450 */ 79, 95, 95, 79, 79, 79, 79, 95, 9, 120, - /* 460 */ 3, 4, 79, 95, 1, 95, 95, 3, 4, 95, - /* 470 */ 95, 95, 95, 79, 130, 3, 4, 79, 95, 79, - /* 480 */ 142, 78, 144, 117, 117, 142, 261, 144, 142, 95, - /* 490 */ 144, 134, 136, 95, 270, 95, 33, 3, 4, 74, - /* 500 */ 75, 142, 142, 144, 144, 142, 261, 144, 232, 261, - /* 510 */ 194, 261, 261, 244, 111, 261, 261, 261, 261, 261, - /* 520 */ 242, 261, 240, 261, 244, 261, 261, 261, 232, 244, - /* 530 */ 232, 232, 232, 232, 232, 194, 194, 260, 246, 194, - /* 540 */ 56, 270, 194, 194, 194, 240, 240, 194, 240, 194, - /* 550 */ 257, 265, 265, 265, 247, 194, 265, 254, 194, 194, - /* 560 */ 256, 251, 121, 114, 255, 196, 194, 194, 253, 250, - /* 570 */ 252, 126, 194, 194, 194, 194, 194, 133, 194, 194, - /* 580 */ 194, 194, 194, 194, 194, 194, 194, 194, 135, 194, - /* 590 */ 194, 194, 132, 194, 128, 194, 194, 124, 194, 194, - /* 600 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, - /* 610 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 131, - /* 620 */ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194, - /* 630 */ 194, 194, 194, 125, 127, 196, 196, 137, 196, 196, - /* 640 */ 87, 94, 93, 196, 196, 47, 196, 90, 92, 91, - /* 650 */ 196, 196, 51, 89, 80, 204, 204, 201, 3, 150, - /* 660 */ 3, 3, 150, 3, 3, 98, 196, 97, 139, 207, - /* 670 */ 211, 213, 196, 212, 197, 210, 208, 206, 209, 197, - /* 680 */ 197, 196, 215, 196, 198, 117, 197, 196, 196, 112, - /* 690 */ 78, 78, 202, 79, 95, 249, 79, 95, 78, 95, - /* 700 */ 79, 78, 1, 79, 78, 95, 79, 78, 78, 129, - /* 710 */ 95, 129, 78, 78, 78, 112, 74, 85, 113, 66, - /* 720 */ 3, 84, 3, 85, 84, 5, 3, 3, 3, 3, - /* 730 */ 3, 3, 3, 81, 20, 55, 74, 144, 82, 9, - /* 740 */ 144, 82, 78, 10, 79, 114, 78, 10, 3, 95, - /* 750 */ 144, 144, 3, 79, 3, 3, 3, 3, 3, 3, - /* 760 */ 3, 3, 3, 3, 3, 3, 3, 3, 95, 81, - /* 770 */ 0, 56, 273, 273, 273, 273, 273, 273, 273, 273, - /* 780 */ 15, 15, 273, 273, 273, 273, 273, 273, 273, 273, + /* 90 */ 24, 261, 194, 258, 238, 29, 30, 261, 242, 33, + /* 100 */ 34, 35, 272, 7, 8, 236, 10, 11, 272, 79, + /* 110 */ 14, 15, 16, 17, 78, 19, 20, 21, 22, 23, + /* 120 */ 24, 267, 1, 269, 74, 29, 30, 194, 80, 33, + /* 130 */ 34, 35, 194, 240, 8, 237, 10, 11, 88, 241, + /* 140 */ 14, 15, 16, 17, 194, 19, 20, 21, 22, 23, + /* 150 */ 24, 258, 116, 203, 118, 29, 30, 78, 194, 33, + /* 160 */ 34, 35, 41, 42, 43, 44, 45, 46, 47, 48, + /* 170 */ 49, 50, 51, 52, 53, 54, 55, 63, 57, 10, + /* 180 */ 11, 199, 240, 14, 15, 16, 17, 205, 19, 20, + /* 190 */ 21, 22, 23, 24, 88, 116, 263, 264, 29, 30, + /* 200 */ 258, 237, 33, 34, 35, 241, 142, 269, 144, 271, + /* 210 */ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, + /* 220 */ 106, 107, 108, 109, 110, 216, 217, 218, 219, 220, + /* 230 */ 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, + /* 240 */ 231, 139, 78, 40, 21, 22, 23, 24, 84, 261, + /* 250 */ 148, 149, 29, 30, 122, 123, 33, 34, 35, 1, + /* 260 */ 57, 248, 1, 2, 3, 4, 5, 64, 2, 3, + /* 270 */ 4, 5, 3, 70, 71, 72, 73, 113, 194, 266, + /* 280 */ 77, 78, 1, 2, 3, 4, 5, 203, 201, 261, + /* 290 */ 29, 30, 64, 194, 33, 29, 30, 2, 3, 4, + /* 300 */ 5, 261, 194, 194, 58, 59, 60, 194, 261, 64, + /* 310 */ 29, 30, 66, 67, 68, 69, 203, 194, 194, 116, + /* 320 */ 233, 234, 235, 236, 29, 30, 58, 59, 60, 33, + /* 330 */ 34, 35, 86, 65, 66, 67, 68, 69, 80, 78, + /* 340 */ 241, 138, 1, 140, 96, 237, 98, 99, 239, 241, + /* 350 */ 147, 103, 33, 3, 4, 107, 194, 109, 110, 78, + /* 360 */ 237, 237, 29, 30, 241, 241, 33, 34, 35, 141, + /* 370 */ 194, 143, 194, 145, 146, 114, 115, 194, 194, 194, + /* 380 */ 114, 115, 121, 58, 59, 60, 141, 194, 143, 72, + /* 390 */ 145, 146, 67, 68, 69, 114, 115, 3, 4, 237, + /* 400 */ 194, 76, 121, 241, 1, 61, 62, 63, 95, 114, + /* 410 */ 115, 79, 199, 237, 199, 237, 79, 241, 205, 241, + /* 420 */ 205, 237, 237, 95, 83, 241, 241, 58, 59, 60, + /* 430 */ 237, 214, 215, 120, 241, 79, 33, 79, 119, 79, + /* 440 */ 79, 95, 79, 79, 79, 79, 9, 130, 78, 117, + /* 450 */ 261, 95, 269, 95, 117, 95, 95, 79, 95, 95, + /* 460 */ 95, 95, 3, 4, 136, 3, 4, 79, 79, 56, + /* 470 */ 79, 121, 142, 95, 144, 269, 142, 142, 144, 144, + /* 480 */ 134, 261, 112, 95, 95, 78, 95, 3, 4, 74, + /* 490 */ 75, 78, 3, 4, 142, 142, 144, 144, 261, 261, + /* 500 */ 261, 261, 261, 261, 261, 261, 244, 242, 261, 232, + /* 510 */ 261, 261, 261, 261, 261, 121, 261, 261, 111, 244, + /* 520 */ 244, 232, 240, 232, 232, 232, 232, 260, 240, 232, + /* 530 */ 240, 246, 194, 270, 270, 56, 194, 121, 240, 196, + /* 540 */ 257, 194, 194, 194, 265, 265, 135, 196, 194, 194, + /* 550 */ 133, 114, 265, 194, 128, 132, 256, 255, 196, 254, + /* 560 */ 131, 194, 194, 253, 265, 126, 194, 196, 252, 196, + /* 570 */ 125, 251, 124, 250, 127, 249, 247, 137, 196, 194, + /* 580 */ 194, 87, 94, 196, 194, 204, 93, 194, 196, 194, + /* 590 */ 194, 194, 194, 213, 194, 194, 194, 47, 90, 194, + /* 600 */ 194, 92, 194, 204, 194, 201, 194, 51, 194, 91, + /* 610 */ 89, 80, 194, 194, 194, 3, 194, 196, 194, 194, + /* 620 */ 211, 194, 194, 3, 194, 3, 194, 196, 194, 3, + /* 630 */ 3, 98, 97, 117, 112, 78, 78, 194, 194, 79, + /* 640 */ 95, 95, 207, 194, 194, 212, 210, 209, 206, 208, + /* 650 */ 194, 194, 194, 202, 194, 194, 150, 194, 194, 194, + /* 660 */ 150, 215, 196, 196, 194, 194, 194, 194, 194, 194, + /* 670 */ 194, 139, 194, 79, 197, 194, 78, 197, 196, 79, + /* 680 */ 197, 196, 78, 197, 194, 194, 194, 79, 95, 194, + /* 690 */ 194, 78, 194, 196, 194, 196, 194, 194, 79, 198, + /* 700 */ 1, 78, 78, 129, 95, 95, 129, 78, 78, 112, + /* 710 */ 78, 74, 113, 85, 66, 84, 3, 3, 85, 84, + /* 720 */ 5, 3, 3, 3, 3, 3, 3, 3, 81, 74, + /* 730 */ 78, 82, 82, 79, 9, 114, 78, 20, 55, 10, + /* 740 */ 144, 95, 10, 3, 3, 144, 144, 144, 79, 3, + /* 750 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + /* 760 */ 3, 3, 3, 95, 56, 81, 0, 273, 273, 273, + /* 770 */ 273, 273, 273, 273, 273, 15, 15, 273, 273, 273, + /* 780 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, /* 790 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, /* 800 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, /* 810 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, @@ -385,115 +384,114 @@ static const YYCODETYPE yy_lookahead[] = { /* 930 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, /* 940 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, /* 950 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, - /* 960 */ 273, 273, 273, 273, 273, 273, 273, 273, 273, 273, - /* 970 */ 273, 273, 273, + /* 960 */ 273, 273, 273, 273, 273, 273, 273, 273, }; #define YY_SHIFT_COUNT (365) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (770) +#define YY_SHIFT_MAX (766) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 190, 118, 25, 42, 247, 268, 268, 358, 38, 38, - /* 10 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 20 */ 38, 0, 97, 268, 284, 297, 297, 85, 85, 38, - /* 30 */ 38, 199, 38, 12, 38, 38, 38, 38, 354, 42, - /* 40 */ 17, 17, 22, 782, 268, 268, 268, 268, 268, 268, - /* 50 */ 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, - /* 60 */ 268, 268, 268, 268, 268, 268, 284, 297, 284, 284, - /* 70 */ 55, 263, 263, 263, 263, 263, 263, 8, 263, 38, - /* 80 */ 38, 38, 137, 38, 38, 38, 85, 85, 38, 38, - /* 90 */ 38, 38, 344, 344, 339, 85, 38, 38, 38, 38, - /* 100 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 110 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 120 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 130 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 140 */ 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - /* 150 */ 38, 38, 38, 38, 484, 484, 484, 441, 441, 441, - /* 160 */ 441, 484, 484, 444, 453, 466, 460, 488, 445, 508, - /* 170 */ 473, 507, 500, 484, 484, 484, 553, 553, 42, 484, - /* 180 */ 484, 547, 549, 598, 557, 556, 601, 558, 564, 22, - /* 190 */ 484, 484, 574, 574, 484, 574, 484, 574, 484, 484, - /* 200 */ 782, 782, 30, 66, 66, 96, 66, 145, 175, 261, - /* 210 */ 261, 261, 261, 261, 261, 249, 273, 289, 340, 340, - /* 220 */ 340, 340, 112, 259, 126, 317, 270, 270, 67, 275, - /* 230 */ 347, 252, 362, 366, 367, 368, 370, 371, 356, 357, - /* 240 */ 374, 375, 376, 377, 457, 464, 383, 94, 394, 398, - /* 250 */ 463, 203, 449, 400, 338, 343, 346, 472, 494, 359, - /* 260 */ 360, 403, 363, 425, 655, 509, 657, 658, 512, 660, - /* 270 */ 661, 567, 570, 529, 568, 577, 612, 614, 613, 599, - /* 280 */ 602, 617, 620, 621, 623, 624, 604, 626, 627, 629, - /* 290 */ 701, 630, 610, 580, 615, 582, 634, 577, 635, 603, - /* 300 */ 636, 605, 642, 632, 637, 653, 717, 638, 640, 719, - /* 310 */ 720, 723, 724, 725, 726, 727, 728, 729, 652, 730, - /* 320 */ 662, 656, 659, 664, 665, 631, 668, 714, 680, 733, - /* 330 */ 593, 596, 654, 654, 654, 654, 737, 606, 607, 654, - /* 340 */ 654, 654, 745, 749, 674, 654, 751, 752, 753, 754, - /* 350 */ 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, - /* 360 */ 673, 688, 765, 766, 715, 770, + /* 0 */ 203, 114, 248, 48, 261, 281, 281, 1, 55, 55, + /* 10 */ 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, + /* 20 */ 55, 0, 121, 281, 266, 295, 295, 79, 79, 132, + /* 30 */ 258, 50, 48, 55, 55, 55, 55, 55, 106, 55, + /* 40 */ 55, 106, 269, 777, 281, 281, 281, 281, 281, 281, + /* 50 */ 281, 281, 281, 281, 281, 281, 281, 281, 281, 281, + /* 60 */ 281, 281, 281, 281, 281, 281, 266, 295, 266, 266, + /* 70 */ 36, 2, 2, 2, 2, 2, 2, 2, 319, 79, + /* 80 */ 79, 317, 317, 313, 79, 341, 55, 479, 55, 55, + /* 90 */ 55, 479, 55, 55, 55, 479, 55, 416, 416, 416, + /* 100 */ 416, 479, 55, 55, 479, 417, 411, 426, 423, 429, + /* 110 */ 439, 445, 448, 447, 440, 479, 55, 55, 479, 55, + /* 120 */ 479, 55, 55, 55, 494, 55, 55, 494, 55, 55, + /* 130 */ 55, 48, 55, 55, 55, 55, 55, 55, 55, 55, + /* 140 */ 55, 479, 55, 55, 55, 55, 55, 55, 479, 55, + /* 150 */ 55, 488, 493, 550, 508, 509, 556, 518, 521, 55, + /* 160 */ 55, 269, 55, 55, 55, 55, 55, 55, 55, 55, + /* 170 */ 55, 479, 55, 479, 55, 55, 55, 55, 55, 55, + /* 180 */ 55, 531, 55, 531, 479, 55, 531, 479, 55, 531, + /* 190 */ 55, 55, 55, 55, 479, 55, 55, 479, 55, 55, + /* 200 */ 777, 777, 30, 66, 66, 96, 66, 126, 169, 223, + /* 210 */ 223, 223, 223, 223, 223, 246, 268, 325, 333, 333, + /* 220 */ 333, 333, 228, 245, 102, 164, 296, 296, 350, 394, + /* 230 */ 344, 369, 356, 332, 337, 358, 360, 361, 328, 346, + /* 240 */ 363, 364, 365, 366, 459, 462, 378, 370, 388, 389, + /* 250 */ 403, 413, 437, 391, 64, 330, 334, 484, 489, 335, + /* 260 */ 352, 407, 353, 415, 612, 506, 620, 622, 510, 626, + /* 270 */ 627, 533, 535, 532, 516, 522, 557, 560, 558, 545, + /* 280 */ 546, 594, 598, 600, 604, 608, 593, 613, 619, 623, + /* 290 */ 699, 624, 609, 574, 610, 577, 629, 522, 630, 597, + /* 300 */ 632, 599, 637, 628, 631, 648, 713, 633, 635, 714, + /* 310 */ 715, 718, 719, 720, 721, 722, 723, 724, 647, 725, + /* 320 */ 655, 649, 650, 652, 654, 621, 658, 717, 683, 729, + /* 330 */ 596, 601, 646, 646, 646, 646, 732, 602, 603, 646, + /* 340 */ 646, 646, 740, 741, 669, 646, 746, 747, 748, 749, + /* 350 */ 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, + /* 360 */ 668, 684, 760, 761, 708, 766, }; #define YY_REDUCE_COUNT (201) -#define YY_REDUCE_MIN (-230) -#define YY_REDUCE_MAX (492) +#define YY_REDUCE_MIN (-241) +#define YY_REDUCE_MAX (503) static const short yy_reduce_ofst[] = { - /* 0 */ -165, 15, -161, 119, -200, -194, -164, -80, 130, -58, - /* 10 */ -67, 135, 140, 149, 150, 151, 156, 166, 184, 185, - /* 20 */ 186, -168, -192, -230, -86, -35, 176, 177, 179, -190, - /* 30 */ -57, 158, 125, 28, 191, 226, 237, 172, -12, 214, - /* 40 */ 233, 234, 229, -227, -213, -205, -84, -79, 75, 90, - /* 50 */ 123, 225, 245, 248, 250, 251, 254, 255, 256, 257, - /* 60 */ 258, 260, 262, 264, 265, 266, 269, 278, 280, 285, - /* 70 */ 282, 276, 296, 298, 299, 300, 301, 316, 302, 341, - /* 80 */ 342, 345, 277, 348, 349, 350, 305, 306, 353, 355, - /* 90 */ 361, 364, 224, 271, 292, 308, 365, 372, 373, 378, - /* 100 */ 379, 380, 381, 382, 384, 385, 386, 387, 388, 389, - /* 110 */ 390, 391, 392, 393, 395, 396, 397, 399, 401, 402, - /* 120 */ 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, - /* 130 */ 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, - /* 140 */ 424, 426, 427, 428, 429, 430, 431, 432, 433, 434, - /* 150 */ 435, 436, 437, 438, 369, 439, 440, 286, 287, 288, - /* 160 */ 291, 442, 443, 293, 304, 309, 303, 315, 318, 310, - /* 170 */ 319, 446, 307, 447, 448, 450, 451, 452, 456, 454, - /* 180 */ 455, 458, 461, 459, 462, 465, 468, 469, 471, 467, - /* 190 */ 470, 476, 477, 482, 485, 483, 487, 489, 491, 492, - /* 200 */ 490, 486, + /* 0 */ -165, 9, -161, 87, -200, -194, -164, -67, -102, -62, + /* 10 */ -146, -36, 108, 123, 124, 162, 176, 178, 184, 185, + /* 20 */ 193, -191, -182, -170, -218, -199, -144, -107, -58, 13, + /* 30 */ -131, -18, -192, 183, 206, 109, -50, 84, 213, 113, + /* 40 */ 99, 215, 217, -241, -12, 28, 40, 47, 189, 220, + /* 50 */ 237, 238, 239, 240, 241, 242, 243, 244, 247, 249, + /* 60 */ 250, 251, 252, 253, 255, 256, 262, 265, 275, 276, + /* 70 */ 282, 277, 289, 291, 292, 293, 294, 297, 267, 288, + /* 80 */ 290, 263, 264, 285, 298, 338, 342, 343, 347, 348, + /* 90 */ 349, 351, 354, 355, 359, 362, 367, 279, 280, 287, + /* 100 */ 299, 371, 368, 372, 373, 283, 300, 302, 305, 310, + /* 110 */ 316, 320, 323, 326, 329, 382, 385, 386, 387, 390, + /* 120 */ 392, 393, 395, 396, 381, 397, 398, 399, 400, 401, + /* 130 */ 402, 404, 405, 406, 408, 410, 412, 414, 418, 419, + /* 140 */ 420, 421, 422, 424, 425, 427, 428, 430, 431, 432, + /* 150 */ 434, 380, 433, 409, 435, 436, 441, 438, 442, 443, + /* 160 */ 444, 446, 449, 450, 456, 457, 458, 460, 461, 463, + /* 170 */ 464, 466, 465, 467, 470, 471, 472, 473, 474, 475, + /* 180 */ 476, 477, 478, 480, 482, 481, 483, 485, 490, 486, + /* 190 */ 491, 492, 495, 496, 497, 498, 500, 499, 502, 503, + /* 200 */ 451, 501, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 890, 953, 940, 949, 1174, 1174, 1174, 890, 890, 890, - /* 10 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 20 */ 890, 1081, 910, 1174, 890, 890, 890, 890, 890, 890, - /* 30 */ 890, 1096, 890, 949, 890, 890, 890, 890, 959, 949, - /* 40 */ 959, 959, 890, 1076, 890, 890, 890, 890, 890, 890, - /* 50 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 60 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 70 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 80 */ 890, 890, 1083, 1089, 1086, 890, 890, 890, 1091, 890, - /* 90 */ 890, 890, 1115, 1115, 1074, 890, 890, 890, 890, 890, - /* 100 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 110 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 120 */ 890, 890, 890, 890, 890, 890, 890, 938, 890, 936, - /* 130 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 140 */ 890, 890, 890, 890, 890, 890, 921, 890, 890, 890, - /* 150 */ 890, 890, 890, 908, 912, 912, 912, 890, 890, 890, - /* 160 */ 890, 912, 912, 1122, 1126, 1108, 1120, 1116, 1103, 1101, - /* 170 */ 1099, 1107, 1130, 912, 912, 912, 957, 957, 949, 912, - /* 180 */ 912, 975, 973, 971, 963, 969, 965, 967, 961, 890, - /* 190 */ 912, 912, 947, 947, 912, 947, 912, 947, 912, 912, - /* 200 */ 997, 1014, 890, 1131, 1121, 890, 1173, 1161, 1160, 1169, - /* 210 */ 1168, 1167, 1159, 1158, 1157, 890, 890, 890, 1153, 1156, - /* 220 */ 1155, 1154, 890, 890, 890, 890, 1163, 1162, 890, 890, - /* 230 */ 890, 890, 890, 890, 890, 890, 890, 890, 1127, 1123, - /* 240 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 250 */ 890, 1133, 890, 890, 890, 890, 890, 890, 890, 890, - /* 260 */ 890, 1022, 890, 890, 890, 890, 890, 890, 890, 890, - /* 270 */ 890, 890, 890, 890, 1073, 890, 890, 890, 890, 1085, - /* 280 */ 1084, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 290 */ 890, 890, 1117, 890, 1109, 890, 890, 1034, 890, 890, - /* 300 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 310 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 320 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 330 */ 890, 890, 1192, 1187, 1188, 1185, 890, 890, 890, 1184, - /* 340 */ 1179, 1180, 890, 890, 890, 1177, 890, 890, 890, 890, - /* 350 */ 890, 890, 890, 890, 890, 890, 890, 890, 890, 890, - /* 360 */ 981, 890, 919, 917, 890, 890, + /* 0 */ 888, 950, 938, 946, 1171, 1171, 1171, 888, 888, 888, + /* 10 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 20 */ 888, 1078, 908, 1171, 888, 888, 888, 888, 888, 1093, + /* 30 */ 1028, 956, 946, 888, 888, 888, 888, 888, 956, 888, + /* 40 */ 888, 956, 888, 1073, 888, 888, 888, 888, 888, 888, + /* 50 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 60 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 70 */ 888, 888, 888, 888, 888, 888, 888, 888, 1080, 888, + /* 80 */ 888, 1112, 1112, 1071, 888, 888, 888, 910, 888, 888, + /* 90 */ 1086, 910, 1083, 888, 1088, 910, 888, 888, 888, 888, + /* 100 */ 888, 910, 888, 888, 910, 1119, 1123, 1105, 1117, 1113, + /* 110 */ 1100, 1098, 1096, 1104, 1127, 910, 888, 888, 910, 888, + /* 120 */ 910, 888, 888, 888, 954, 888, 888, 954, 888, 888, + /* 130 */ 888, 946, 888, 888, 888, 888, 888, 888, 888, 888, + /* 140 */ 888, 910, 888, 888, 888, 888, 888, 888, 910, 888, + /* 150 */ 888, 972, 970, 968, 960, 966, 962, 964, 958, 888, + /* 160 */ 888, 888, 888, 936, 888, 934, 888, 888, 888, 888, + /* 170 */ 888, 910, 888, 910, 888, 888, 888, 888, 888, 888, + /* 180 */ 888, 944, 888, 944, 910, 888, 944, 910, 888, 944, + /* 190 */ 919, 888, 888, 888, 910, 888, 888, 910, 888, 906, + /* 200 */ 994, 1011, 888, 1128, 1118, 888, 1170, 1158, 1157, 1166, + /* 210 */ 1165, 1164, 1156, 1155, 1154, 888, 888, 888, 1150, 1153, + /* 220 */ 1152, 1151, 888, 888, 888, 888, 1160, 1159, 888, 888, + /* 230 */ 888, 888, 888, 888, 888, 888, 888, 888, 1124, 1120, + /* 240 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 250 */ 888, 1130, 888, 888, 888, 888, 888, 888, 888, 888, + /* 260 */ 888, 1019, 888, 888, 888, 888, 888, 888, 888, 888, + /* 270 */ 888, 888, 888, 888, 1070, 888, 888, 888, 888, 1082, + /* 280 */ 1081, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 290 */ 888, 888, 1114, 888, 1106, 888, 888, 1031, 888, 888, + /* 300 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 310 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 320 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 330 */ 888, 888, 1189, 1184, 1185, 1182, 888, 888, 888, 1181, + /* 340 */ 1176, 1177, 888, 888, 888, 1174, 888, 888, 888, 888, + /* 350 */ 888, 888, 888, 888, 888, 888, 888, 888, 888, 888, + /* 360 */ 978, 888, 917, 915, 888, 888, }; /********** End of lemon-generated parsing tables *****************************/ @@ -1122,257 +1120,256 @@ static const char *const yyRuleName[] = { /* 49 */ "cmd ::= ALTER ACCOUNT ids PASS ids acct_optr", /* 50 */ "cmd ::= COMPACT VNODES IN LP exprlist RP", /* 51 */ "ids ::= ID", - /* 52 */ "ids ::= STRING", - /* 53 */ "ifexists ::= IF EXISTS", - /* 54 */ "ifexists ::=", - /* 55 */ "ifnotexists ::= IF NOT EXISTS", - /* 56 */ "ifnotexists ::=", - /* 57 */ "cmd ::= CREATE DNODE ids PORT ids", - /* 58 */ "cmd ::= CREATE DNODE IPTOKEN PORT ids", - /* 59 */ "cmd ::= CREATE ACCOUNT ids PASS ids acct_optr", - /* 60 */ "cmd ::= CREATE DATABASE ifnotexists ids db_optr", - /* 61 */ "cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", - /* 62 */ "cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", - /* 63 */ "cmd ::= CREATE USER ids PASS ids", - /* 64 */ "bufsize ::=", - /* 65 */ "bufsize ::= BUFSIZE INTEGER", - /* 66 */ "pps ::=", - /* 67 */ "pps ::= PPS INTEGER", - /* 68 */ "tseries ::=", - /* 69 */ "tseries ::= TSERIES INTEGER", - /* 70 */ "dbs ::=", - /* 71 */ "dbs ::= DBS INTEGER", - /* 72 */ "streams ::=", - /* 73 */ "streams ::= STREAMS INTEGER", - /* 74 */ "storage ::=", - /* 75 */ "storage ::= STORAGE INTEGER", - /* 76 */ "qtime ::=", - /* 77 */ "qtime ::= QTIME INTEGER", - /* 78 */ "users ::=", - /* 79 */ "users ::= USERS INTEGER", - /* 80 */ "conns ::=", - /* 81 */ "conns ::= CONNS INTEGER", - /* 82 */ "state ::=", - /* 83 */ "state ::= STATE ids", - /* 84 */ "acct_optr ::= pps tseries storage streams qtime dbs users conns state", - /* 85 */ "intitemlist ::= intitemlist COMMA intitem", - /* 86 */ "intitemlist ::= intitem", - /* 87 */ "intitem ::= INTEGER", - /* 88 */ "keep ::= KEEP intitemlist", - /* 89 */ "cache ::= CACHE INTEGER", - /* 90 */ "replica ::= REPLICA INTEGER", - /* 91 */ "quorum ::= QUORUM INTEGER", - /* 92 */ "days ::= DAYS INTEGER", - /* 93 */ "minrows ::= MINROWS INTEGER", - /* 94 */ "maxrows ::= MAXROWS INTEGER", - /* 95 */ "blocks ::= BLOCKS INTEGER", - /* 96 */ "ctime ::= CTIME INTEGER", - /* 97 */ "wal ::= WAL INTEGER", - /* 98 */ "fsync ::= FSYNC INTEGER", - /* 99 */ "comp ::= COMP INTEGER", - /* 100 */ "prec ::= PRECISION STRING", - /* 101 */ "update ::= UPDATE INTEGER", - /* 102 */ "cachelast ::= CACHELAST INTEGER", - /* 103 */ "vgroups ::= VGROUPS INTEGER", - /* 104 */ "db_optr ::=", - /* 105 */ "db_optr ::= db_optr cache", - /* 106 */ "db_optr ::= db_optr replica", - /* 107 */ "db_optr ::= db_optr quorum", - /* 108 */ "db_optr ::= db_optr days", - /* 109 */ "db_optr ::= db_optr minrows", - /* 110 */ "db_optr ::= db_optr maxrows", - /* 111 */ "db_optr ::= db_optr blocks", - /* 112 */ "db_optr ::= db_optr ctime", - /* 113 */ "db_optr ::= db_optr wal", - /* 114 */ "db_optr ::= db_optr fsync", - /* 115 */ "db_optr ::= db_optr comp", - /* 116 */ "db_optr ::= db_optr prec", - /* 117 */ "db_optr ::= db_optr keep", - /* 118 */ "db_optr ::= db_optr update", - /* 119 */ "db_optr ::= db_optr cachelast", - /* 120 */ "db_optr ::= db_optr vgroups", - /* 121 */ "alter_db_optr ::=", - /* 122 */ "alter_db_optr ::= alter_db_optr replica", - /* 123 */ "alter_db_optr ::= alter_db_optr quorum", - /* 124 */ "alter_db_optr ::= alter_db_optr keep", - /* 125 */ "alter_db_optr ::= alter_db_optr blocks", - /* 126 */ "alter_db_optr ::= alter_db_optr comp", - /* 127 */ "alter_db_optr ::= alter_db_optr update", - /* 128 */ "alter_db_optr ::= alter_db_optr cachelast", - /* 129 */ "typename ::= ids", - /* 130 */ "typename ::= ids LP signed RP", - /* 131 */ "typename ::= ids UNSIGNED", - /* 132 */ "signed ::= INTEGER", - /* 133 */ "signed ::= PLUS INTEGER", - /* 134 */ "signed ::= MINUS INTEGER", - /* 135 */ "cmd ::= CREATE TABLE create_table_args", - /* 136 */ "cmd ::= CREATE TABLE create_stable_args", - /* 137 */ "cmd ::= CREATE STABLE create_stable_args", - /* 138 */ "cmd ::= CREATE TABLE create_table_list", - /* 139 */ "create_table_list ::= create_from_stable", - /* 140 */ "create_table_list ::= create_table_list create_from_stable", - /* 141 */ "create_table_args ::= ifnotexists ids cpxName LP columnlist RP", - /* 142 */ "create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP", - /* 143 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP", - /* 144 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP", - /* 145 */ "tagNamelist ::= tagNamelist COMMA ids", - /* 146 */ "tagNamelist ::= ids", - /* 147 */ "create_table_args ::= ifnotexists ids cpxName AS select", - /* 148 */ "columnlist ::= columnlist COMMA column", - /* 149 */ "columnlist ::= column", - /* 150 */ "column ::= ids typename", - /* 151 */ "tagitemlist1 ::= tagitemlist1 COMMA tagitem1", - /* 152 */ "tagitemlist1 ::= tagitem1", - /* 153 */ "tagitem1 ::= MINUS INTEGER", - /* 154 */ "tagitem1 ::= MINUS FLOAT", - /* 155 */ "tagitem1 ::= PLUS INTEGER", - /* 156 */ "tagitem1 ::= PLUS FLOAT", - /* 157 */ "tagitem1 ::= INTEGER", - /* 158 */ "tagitem1 ::= FLOAT", - /* 159 */ "tagitem1 ::= STRING", - /* 160 */ "tagitem1 ::= BOOL", - /* 161 */ "tagitem1 ::= NULL", - /* 162 */ "tagitem1 ::= NOW", - /* 163 */ "tagitemlist ::= tagitemlist COMMA tagitem", - /* 164 */ "tagitemlist ::= tagitem", - /* 165 */ "tagitem ::= INTEGER", - /* 166 */ "tagitem ::= FLOAT", - /* 167 */ "tagitem ::= STRING", - /* 168 */ "tagitem ::= BOOL", - /* 169 */ "tagitem ::= NULL", - /* 170 */ "tagitem ::= NOW", - /* 171 */ "tagitem ::= MINUS INTEGER", - /* 172 */ "tagitem ::= MINUS FLOAT", - /* 173 */ "tagitem ::= PLUS INTEGER", - /* 174 */ "tagitem ::= PLUS FLOAT", - /* 175 */ "select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt", - /* 176 */ "select ::= LP select RP", - /* 177 */ "union ::= select", - /* 178 */ "union ::= union UNION ALL select", - /* 179 */ "union ::= union UNION select", - /* 180 */ "cmd ::= union", - /* 181 */ "select ::= SELECT selcollist", - /* 182 */ "sclp ::= selcollist COMMA", - /* 183 */ "sclp ::=", - /* 184 */ "selcollist ::= sclp distinct expr as", - /* 185 */ "selcollist ::= sclp STAR", - /* 186 */ "as ::= AS ids", - /* 187 */ "as ::= ids", - /* 188 */ "as ::=", - /* 189 */ "distinct ::= DISTINCT", - /* 190 */ "distinct ::=", - /* 191 */ "from ::= FROM tablelist", - /* 192 */ "from ::= FROM sub", - /* 193 */ "sub ::= LP union RP", - /* 194 */ "sub ::= LP union RP ids", - /* 195 */ "sub ::= sub COMMA LP union RP ids", - /* 196 */ "tablelist ::= ids cpxName", - /* 197 */ "tablelist ::= ids cpxName ids", - /* 198 */ "tablelist ::= tablelist COMMA ids cpxName", - /* 199 */ "tablelist ::= tablelist COMMA ids cpxName ids", - /* 200 */ "tmvar ::= VARIABLE", - /* 201 */ "interval_option ::= intervalKey LP tmvar RP", - /* 202 */ "interval_option ::= intervalKey LP tmvar COMMA tmvar RP", - /* 203 */ "interval_option ::=", - /* 204 */ "intervalKey ::= INTERVAL", - /* 205 */ "intervalKey ::= EVERY", - /* 206 */ "session_option ::=", - /* 207 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", - /* 208 */ "windowstate_option ::=", - /* 209 */ "windowstate_option ::= STATE_WINDOW LP ids RP", - /* 210 */ "fill_opt ::=", - /* 211 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", - /* 212 */ "fill_opt ::= FILL LP ID RP", - /* 213 */ "sliding_opt ::= SLIDING LP tmvar RP", - /* 214 */ "sliding_opt ::=", - /* 215 */ "orderby_opt ::=", - /* 216 */ "orderby_opt ::= ORDER BY sortlist", - /* 217 */ "sortlist ::= sortlist COMMA item sortorder", - /* 218 */ "sortlist ::= item sortorder", - /* 219 */ "item ::= ids cpxName", - /* 220 */ "sortorder ::= ASC", - /* 221 */ "sortorder ::= DESC", - /* 222 */ "sortorder ::=", - /* 223 */ "groupby_opt ::=", - /* 224 */ "groupby_opt ::= GROUP BY grouplist", - /* 225 */ "grouplist ::= grouplist COMMA item", - /* 226 */ "grouplist ::= item", - /* 227 */ "having_opt ::=", - /* 228 */ "having_opt ::= HAVING expr", - /* 229 */ "limit_opt ::=", - /* 230 */ "limit_opt ::= LIMIT signed", - /* 231 */ "limit_opt ::= LIMIT signed OFFSET signed", - /* 232 */ "limit_opt ::= LIMIT signed COMMA signed", - /* 233 */ "slimit_opt ::=", - /* 234 */ "slimit_opt ::= SLIMIT signed", - /* 235 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", - /* 236 */ "slimit_opt ::= SLIMIT signed COMMA signed", - /* 237 */ "where_opt ::=", - /* 238 */ "where_opt ::= WHERE expr", - /* 239 */ "expr ::= LP expr RP", - /* 240 */ "expr ::= ID", - /* 241 */ "expr ::= ID DOT ID", - /* 242 */ "expr ::= ID DOT STAR", - /* 243 */ "expr ::= INTEGER", - /* 244 */ "expr ::= MINUS INTEGER", - /* 245 */ "expr ::= PLUS INTEGER", - /* 246 */ "expr ::= FLOAT", - /* 247 */ "expr ::= MINUS FLOAT", - /* 248 */ "expr ::= PLUS FLOAT", - /* 249 */ "expr ::= STRING", - /* 250 */ "expr ::= NOW", - /* 251 */ "expr ::= VARIABLE", - /* 252 */ "expr ::= PLUS VARIABLE", - /* 253 */ "expr ::= MINUS VARIABLE", - /* 254 */ "expr ::= BOOL", - /* 255 */ "expr ::= NULL", - /* 256 */ "expr ::= ID LP exprlist RP", - /* 257 */ "expr ::= ID LP STAR RP", - /* 258 */ "expr ::= expr IS NULL", - /* 259 */ "expr ::= expr IS NOT NULL", - /* 260 */ "expr ::= expr LT expr", - /* 261 */ "expr ::= expr GT expr", - /* 262 */ "expr ::= expr LE expr", - /* 263 */ "expr ::= expr GE expr", - /* 264 */ "expr ::= expr NE expr", - /* 265 */ "expr ::= expr EQ expr", - /* 266 */ "expr ::= expr BETWEEN expr AND expr", - /* 267 */ "expr ::= expr AND expr", - /* 268 */ "expr ::= expr OR expr", - /* 269 */ "expr ::= expr PLUS expr", - /* 270 */ "expr ::= expr MINUS expr", - /* 271 */ "expr ::= expr STAR expr", - /* 272 */ "expr ::= expr SLASH expr", - /* 273 */ "expr ::= expr REM expr", - /* 274 */ "expr ::= expr LIKE expr", - /* 275 */ "expr ::= expr MATCH expr", - /* 276 */ "expr ::= expr NMATCH expr", - /* 277 */ "expr ::= expr IN LP exprlist RP", - /* 278 */ "exprlist ::= exprlist COMMA expritem", - /* 279 */ "exprlist ::= expritem", - /* 280 */ "expritem ::= expr", - /* 281 */ "expritem ::=", - /* 282 */ "cmd ::= RESET QUERY CACHE", - /* 283 */ "cmd ::= SYNCDB ids REPLICA", - /* 284 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", - /* 285 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", - /* 286 */ "cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist", - /* 287 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", - /* 288 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", - /* 289 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", - /* 290 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", - /* 291 */ "cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist", - /* 292 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", - /* 293 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", - /* 294 */ "cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist", - /* 295 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", - /* 296 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", - /* 297 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", - /* 298 */ "cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem", - /* 299 */ "cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist", - /* 300 */ "cmd ::= KILL CONNECTION INTEGER", - /* 301 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", - /* 302 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", + /* 52 */ "ifexists ::= IF EXISTS", + /* 53 */ "ifexists ::=", + /* 54 */ "ifnotexists ::= IF NOT EXISTS", + /* 55 */ "ifnotexists ::=", + /* 56 */ "cmd ::= CREATE DNODE ids PORT ids", + /* 57 */ "cmd ::= CREATE DNODE IPTOKEN PORT ids", + /* 58 */ "cmd ::= CREATE ACCOUNT ids PASS ids acct_optr", + /* 59 */ "cmd ::= CREATE DATABASE ifnotexists ids db_optr", + /* 60 */ "cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", + /* 61 */ "cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize", + /* 62 */ "cmd ::= CREATE USER ids PASS ids", + /* 63 */ "bufsize ::=", + /* 64 */ "bufsize ::= BUFSIZE INTEGER", + /* 65 */ "pps ::=", + /* 66 */ "pps ::= PPS INTEGER", + /* 67 */ "tseries ::=", + /* 68 */ "tseries ::= TSERIES INTEGER", + /* 69 */ "dbs ::=", + /* 70 */ "dbs ::= DBS INTEGER", + /* 71 */ "streams ::=", + /* 72 */ "streams ::= STREAMS INTEGER", + /* 73 */ "storage ::=", + /* 74 */ "storage ::= STORAGE INTEGER", + /* 75 */ "qtime ::=", + /* 76 */ "qtime ::= QTIME INTEGER", + /* 77 */ "users ::=", + /* 78 */ "users ::= USERS INTEGER", + /* 79 */ "conns ::=", + /* 80 */ "conns ::= CONNS INTEGER", + /* 81 */ "state ::=", + /* 82 */ "state ::= STATE ids", + /* 83 */ "acct_optr ::= pps tseries storage streams qtime dbs users conns state", + /* 84 */ "intitemlist ::= intitemlist COMMA intitem", + /* 85 */ "intitemlist ::= intitem", + /* 86 */ "intitem ::= INTEGER", + /* 87 */ "keep ::= KEEP intitemlist", + /* 88 */ "cache ::= CACHE INTEGER", + /* 89 */ "replica ::= REPLICA INTEGER", + /* 90 */ "quorum ::= QUORUM INTEGER", + /* 91 */ "days ::= DAYS INTEGER", + /* 92 */ "minrows ::= MINROWS INTEGER", + /* 93 */ "maxrows ::= MAXROWS INTEGER", + /* 94 */ "blocks ::= BLOCKS INTEGER", + /* 95 */ "ctime ::= CTIME INTEGER", + /* 96 */ "wal ::= WAL INTEGER", + /* 97 */ "fsync ::= FSYNC INTEGER", + /* 98 */ "comp ::= COMP INTEGER", + /* 99 */ "prec ::= PRECISION STRING", + /* 100 */ "update ::= UPDATE INTEGER", + /* 101 */ "cachelast ::= CACHELAST INTEGER", + /* 102 */ "vgroups ::= VGROUPS INTEGER", + /* 103 */ "db_optr ::=", + /* 104 */ "db_optr ::= db_optr cache", + /* 105 */ "db_optr ::= db_optr replica", + /* 106 */ "db_optr ::= db_optr quorum", + /* 107 */ "db_optr ::= db_optr days", + /* 108 */ "db_optr ::= db_optr minrows", + /* 109 */ "db_optr ::= db_optr maxrows", + /* 110 */ "db_optr ::= db_optr blocks", + /* 111 */ "db_optr ::= db_optr ctime", + /* 112 */ "db_optr ::= db_optr wal", + /* 113 */ "db_optr ::= db_optr fsync", + /* 114 */ "db_optr ::= db_optr comp", + /* 115 */ "db_optr ::= db_optr prec", + /* 116 */ "db_optr ::= db_optr keep", + /* 117 */ "db_optr ::= db_optr update", + /* 118 */ "db_optr ::= db_optr cachelast", + /* 119 */ "db_optr ::= db_optr vgroups", + /* 120 */ "alter_db_optr ::=", + /* 121 */ "alter_db_optr ::= alter_db_optr replica", + /* 122 */ "alter_db_optr ::= alter_db_optr quorum", + /* 123 */ "alter_db_optr ::= alter_db_optr keep", + /* 124 */ "alter_db_optr ::= alter_db_optr blocks", + /* 125 */ "alter_db_optr ::= alter_db_optr comp", + /* 126 */ "alter_db_optr ::= alter_db_optr update", + /* 127 */ "alter_db_optr ::= alter_db_optr cachelast", + /* 128 */ "typename ::= ids", + /* 129 */ "typename ::= ids LP signed RP", + /* 130 */ "typename ::= ids UNSIGNED", + /* 131 */ "signed ::= INTEGER", + /* 132 */ "signed ::= PLUS INTEGER", + /* 133 */ "signed ::= MINUS INTEGER", + /* 134 */ "cmd ::= CREATE TABLE create_table_args", + /* 135 */ "cmd ::= CREATE TABLE create_stable_args", + /* 136 */ "cmd ::= CREATE STABLE create_stable_args", + /* 137 */ "cmd ::= CREATE TABLE create_table_list", + /* 138 */ "create_table_list ::= create_from_stable", + /* 139 */ "create_table_list ::= create_table_list create_from_stable", + /* 140 */ "create_table_args ::= ifnotexists ids cpxName LP columnlist RP", + /* 141 */ "create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP", + /* 142 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP", + /* 143 */ "create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP", + /* 144 */ "tagNamelist ::= tagNamelist COMMA ids", + /* 145 */ "tagNamelist ::= ids", + /* 146 */ "create_table_args ::= ifnotexists ids cpxName AS select", + /* 147 */ "columnlist ::= columnlist COMMA column", + /* 148 */ "columnlist ::= column", + /* 149 */ "column ::= ids typename", + /* 150 */ "tagitemlist1 ::= tagitemlist1 COMMA tagitem1", + /* 151 */ "tagitemlist1 ::= tagitem1", + /* 152 */ "tagitem1 ::= MINUS INTEGER", + /* 153 */ "tagitem1 ::= MINUS FLOAT", + /* 154 */ "tagitem1 ::= PLUS INTEGER", + /* 155 */ "tagitem1 ::= PLUS FLOAT", + /* 156 */ "tagitem1 ::= INTEGER", + /* 157 */ "tagitem1 ::= FLOAT", + /* 158 */ "tagitem1 ::= STRING", + /* 159 */ "tagitem1 ::= BOOL", + /* 160 */ "tagitem1 ::= NULL", + /* 161 */ "tagitem1 ::= NOW", + /* 162 */ "tagitemlist ::= tagitemlist COMMA tagitem", + /* 163 */ "tagitemlist ::= tagitem", + /* 164 */ "tagitem ::= INTEGER", + /* 165 */ "tagitem ::= FLOAT", + /* 166 */ "tagitem ::= STRING", + /* 167 */ "tagitem ::= BOOL", + /* 168 */ "tagitem ::= NULL", + /* 169 */ "tagitem ::= NOW", + /* 170 */ "tagitem ::= MINUS INTEGER", + /* 171 */ "tagitem ::= MINUS FLOAT", + /* 172 */ "tagitem ::= PLUS INTEGER", + /* 173 */ "tagitem ::= PLUS FLOAT", + /* 174 */ "select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt", + /* 175 */ "select ::= LP select RP", + /* 176 */ "union ::= select", + /* 177 */ "union ::= union UNION ALL select", + /* 178 */ "union ::= union UNION select", + /* 179 */ "cmd ::= union", + /* 180 */ "select ::= SELECT selcollist", + /* 181 */ "sclp ::= selcollist COMMA", + /* 182 */ "sclp ::=", + /* 183 */ "selcollist ::= sclp distinct expr as", + /* 184 */ "selcollist ::= sclp STAR", + /* 185 */ "as ::= AS ids", + /* 186 */ "as ::= ids", + /* 187 */ "as ::=", + /* 188 */ "distinct ::= DISTINCT", + /* 189 */ "distinct ::=", + /* 190 */ "from ::= FROM tablelist", + /* 191 */ "from ::= FROM sub", + /* 192 */ "sub ::= LP union RP", + /* 193 */ "sub ::= LP union RP ids", + /* 194 */ "sub ::= sub COMMA LP union RP ids", + /* 195 */ "tablelist ::= ids cpxName", + /* 196 */ "tablelist ::= ids cpxName ids", + /* 197 */ "tablelist ::= tablelist COMMA ids cpxName", + /* 198 */ "tablelist ::= tablelist COMMA ids cpxName ids", + /* 199 */ "tmvar ::= VARIABLE", + /* 200 */ "interval_option ::= intervalKey LP tmvar RP", + /* 201 */ "interval_option ::= intervalKey LP tmvar COMMA tmvar RP", + /* 202 */ "interval_option ::=", + /* 203 */ "intervalKey ::= INTERVAL", + /* 204 */ "intervalKey ::= EVERY", + /* 205 */ "session_option ::=", + /* 206 */ "session_option ::= SESSION LP ids cpxName COMMA tmvar RP", + /* 207 */ "windowstate_option ::=", + /* 208 */ "windowstate_option ::= STATE_WINDOW LP ids RP", + /* 209 */ "fill_opt ::=", + /* 210 */ "fill_opt ::= FILL LP ID COMMA tagitemlist RP", + /* 211 */ "fill_opt ::= FILL LP ID RP", + /* 212 */ "sliding_opt ::= SLIDING LP tmvar RP", + /* 213 */ "sliding_opt ::=", + /* 214 */ "orderby_opt ::=", + /* 215 */ "orderby_opt ::= ORDER BY sortlist", + /* 216 */ "sortlist ::= sortlist COMMA item sortorder", + /* 217 */ "sortlist ::= item sortorder", + /* 218 */ "item ::= ids cpxName", + /* 219 */ "sortorder ::= ASC", + /* 220 */ "sortorder ::= DESC", + /* 221 */ "sortorder ::=", + /* 222 */ "groupby_opt ::=", + /* 223 */ "groupby_opt ::= GROUP BY grouplist", + /* 224 */ "grouplist ::= grouplist COMMA item", + /* 225 */ "grouplist ::= item", + /* 226 */ "having_opt ::=", + /* 227 */ "having_opt ::= HAVING expr", + /* 228 */ "limit_opt ::=", + /* 229 */ "limit_opt ::= LIMIT signed", + /* 230 */ "limit_opt ::= LIMIT signed OFFSET signed", + /* 231 */ "limit_opt ::= LIMIT signed COMMA signed", + /* 232 */ "slimit_opt ::=", + /* 233 */ "slimit_opt ::= SLIMIT signed", + /* 234 */ "slimit_opt ::= SLIMIT signed SOFFSET signed", + /* 235 */ "slimit_opt ::= SLIMIT signed COMMA signed", + /* 236 */ "where_opt ::=", + /* 237 */ "where_opt ::= WHERE expr", + /* 238 */ "expr ::= LP expr RP", + /* 239 */ "expr ::= ID", + /* 240 */ "expr ::= ID DOT ID", + /* 241 */ "expr ::= ID DOT STAR", + /* 242 */ "expr ::= INTEGER", + /* 243 */ "expr ::= MINUS INTEGER", + /* 244 */ "expr ::= PLUS INTEGER", + /* 245 */ "expr ::= FLOAT", + /* 246 */ "expr ::= MINUS FLOAT", + /* 247 */ "expr ::= PLUS FLOAT", + /* 248 */ "expr ::= STRING", + /* 249 */ "expr ::= NOW", + /* 250 */ "expr ::= VARIABLE", + /* 251 */ "expr ::= PLUS VARIABLE", + /* 252 */ "expr ::= MINUS VARIABLE", + /* 253 */ "expr ::= BOOL", + /* 254 */ "expr ::= NULL", + /* 255 */ "expr ::= ID LP exprlist RP", + /* 256 */ "expr ::= ID LP STAR RP", + /* 257 */ "expr ::= expr IS NULL", + /* 258 */ "expr ::= expr IS NOT NULL", + /* 259 */ "expr ::= expr LT expr", + /* 260 */ "expr ::= expr GT expr", + /* 261 */ "expr ::= expr LE expr", + /* 262 */ "expr ::= expr GE expr", + /* 263 */ "expr ::= expr NE expr", + /* 264 */ "expr ::= expr EQ expr", + /* 265 */ "expr ::= expr BETWEEN expr AND expr", + /* 266 */ "expr ::= expr AND expr", + /* 267 */ "expr ::= expr OR expr", + /* 268 */ "expr ::= expr PLUS expr", + /* 269 */ "expr ::= expr MINUS expr", + /* 270 */ "expr ::= expr STAR expr", + /* 271 */ "expr ::= expr SLASH expr", + /* 272 */ "expr ::= expr REM expr", + /* 273 */ "expr ::= expr LIKE expr", + /* 274 */ "expr ::= expr MATCH expr", + /* 275 */ "expr ::= expr NMATCH expr", + /* 276 */ "expr ::= expr IN LP exprlist RP", + /* 277 */ "exprlist ::= exprlist COMMA expritem", + /* 278 */ "exprlist ::= expritem", + /* 279 */ "expritem ::= expr", + /* 280 */ "expritem ::=", + /* 281 */ "cmd ::= RESET QUERY CACHE", + /* 282 */ "cmd ::= SYNCDB ids REPLICA", + /* 283 */ "cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist", + /* 284 */ "cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids", + /* 285 */ "cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist", + /* 286 */ "cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist", + /* 287 */ "cmd ::= ALTER TABLE ids cpxName DROP TAG ids", + /* 288 */ "cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids", + /* 289 */ "cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem", + /* 290 */ "cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist", + /* 291 */ "cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist", + /* 292 */ "cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids", + /* 293 */ "cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist", + /* 294 */ "cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist", + /* 295 */ "cmd ::= ALTER STABLE ids cpxName DROP TAG ids", + /* 296 */ "cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids", + /* 297 */ "cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem", + /* 298 */ "cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist", + /* 299 */ "cmd ::= KILL CONNECTION INTEGER", + /* 300 */ "cmd ::= KILL STREAM INTEGER COLON INTEGER", + /* 301 */ "cmd ::= KILL QUERY INTEGER COLON INTEGER", }; #endif /* NDEBUG */ @@ -1893,257 +1890,256 @@ static const struct { { 193, -6 }, /* (49) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ { 193, -6 }, /* (50) cmd ::= COMPACT VNODES IN LP exprlist RP */ { 194, -1 }, /* (51) ids ::= ID */ - { 194, -1 }, /* (52) ids ::= STRING */ - { 197, -2 }, /* (53) ifexists ::= IF EXISTS */ - { 197, 0 }, /* (54) ifexists ::= */ - { 201, -3 }, /* (55) ifnotexists ::= IF NOT EXISTS */ - { 201, 0 }, /* (56) ifnotexists ::= */ - { 193, -5 }, /* (57) cmd ::= CREATE DNODE ids PORT ids */ - { 193, -5 }, /* (58) cmd ::= CREATE DNODE IPTOKEN PORT ids */ - { 193, -6 }, /* (59) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ - { 193, -5 }, /* (60) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ - { 193, -8 }, /* (61) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ - { 193, -9 }, /* (62) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ - { 193, -5 }, /* (63) cmd ::= CREATE USER ids PASS ids */ - { 204, 0 }, /* (64) bufsize ::= */ - { 204, -2 }, /* (65) bufsize ::= BUFSIZE INTEGER */ - { 205, 0 }, /* (66) pps ::= */ - { 205, -2 }, /* (67) pps ::= PPS INTEGER */ - { 206, 0 }, /* (68) tseries ::= */ - { 206, -2 }, /* (69) tseries ::= TSERIES INTEGER */ - { 207, 0 }, /* (70) dbs ::= */ - { 207, -2 }, /* (71) dbs ::= DBS INTEGER */ - { 208, 0 }, /* (72) streams ::= */ - { 208, -2 }, /* (73) streams ::= STREAMS INTEGER */ - { 209, 0 }, /* (74) storage ::= */ - { 209, -2 }, /* (75) storage ::= STORAGE INTEGER */ - { 210, 0 }, /* (76) qtime ::= */ - { 210, -2 }, /* (77) qtime ::= QTIME INTEGER */ - { 211, 0 }, /* (78) users ::= */ - { 211, -2 }, /* (79) users ::= USERS INTEGER */ - { 212, 0 }, /* (80) conns ::= */ - { 212, -2 }, /* (81) conns ::= CONNS INTEGER */ - { 213, 0 }, /* (82) state ::= */ - { 213, -2 }, /* (83) state ::= STATE ids */ - { 199, -9 }, /* (84) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ - { 214, -3 }, /* (85) intitemlist ::= intitemlist COMMA intitem */ - { 214, -1 }, /* (86) intitemlist ::= intitem */ - { 215, -1 }, /* (87) intitem ::= INTEGER */ - { 216, -2 }, /* (88) keep ::= KEEP intitemlist */ - { 217, -2 }, /* (89) cache ::= CACHE INTEGER */ - { 218, -2 }, /* (90) replica ::= REPLICA INTEGER */ - { 219, -2 }, /* (91) quorum ::= QUORUM INTEGER */ - { 220, -2 }, /* (92) days ::= DAYS INTEGER */ - { 221, -2 }, /* (93) minrows ::= MINROWS INTEGER */ - { 222, -2 }, /* (94) maxrows ::= MAXROWS INTEGER */ - { 223, -2 }, /* (95) blocks ::= BLOCKS INTEGER */ - { 224, -2 }, /* (96) ctime ::= CTIME INTEGER */ - { 225, -2 }, /* (97) wal ::= WAL INTEGER */ - { 226, -2 }, /* (98) fsync ::= FSYNC INTEGER */ - { 227, -2 }, /* (99) comp ::= COMP INTEGER */ - { 228, -2 }, /* (100) prec ::= PRECISION STRING */ - { 229, -2 }, /* (101) update ::= UPDATE INTEGER */ - { 230, -2 }, /* (102) cachelast ::= CACHELAST INTEGER */ - { 231, -2 }, /* (103) vgroups ::= VGROUPS INTEGER */ - { 202, 0 }, /* (104) db_optr ::= */ - { 202, -2 }, /* (105) db_optr ::= db_optr cache */ - { 202, -2 }, /* (106) db_optr ::= db_optr replica */ - { 202, -2 }, /* (107) db_optr ::= db_optr quorum */ - { 202, -2 }, /* (108) db_optr ::= db_optr days */ - { 202, -2 }, /* (109) db_optr ::= db_optr minrows */ - { 202, -2 }, /* (110) db_optr ::= db_optr maxrows */ - { 202, -2 }, /* (111) db_optr ::= db_optr blocks */ - { 202, -2 }, /* (112) db_optr ::= db_optr ctime */ - { 202, -2 }, /* (113) db_optr ::= db_optr wal */ - { 202, -2 }, /* (114) db_optr ::= db_optr fsync */ - { 202, -2 }, /* (115) db_optr ::= db_optr comp */ - { 202, -2 }, /* (116) db_optr ::= db_optr prec */ - { 202, -2 }, /* (117) db_optr ::= db_optr keep */ - { 202, -2 }, /* (118) db_optr ::= db_optr update */ - { 202, -2 }, /* (119) db_optr ::= db_optr cachelast */ - { 202, -2 }, /* (120) db_optr ::= db_optr vgroups */ - { 198, 0 }, /* (121) alter_db_optr ::= */ - { 198, -2 }, /* (122) alter_db_optr ::= alter_db_optr replica */ - { 198, -2 }, /* (123) alter_db_optr ::= alter_db_optr quorum */ - { 198, -2 }, /* (124) alter_db_optr ::= alter_db_optr keep */ - { 198, -2 }, /* (125) alter_db_optr ::= alter_db_optr blocks */ - { 198, -2 }, /* (126) alter_db_optr ::= alter_db_optr comp */ - { 198, -2 }, /* (127) alter_db_optr ::= alter_db_optr update */ - { 198, -2 }, /* (128) alter_db_optr ::= alter_db_optr cachelast */ - { 203, -1 }, /* (129) typename ::= ids */ - { 203, -4 }, /* (130) typename ::= ids LP signed RP */ - { 203, -2 }, /* (131) typename ::= ids UNSIGNED */ - { 232, -1 }, /* (132) signed ::= INTEGER */ - { 232, -2 }, /* (133) signed ::= PLUS INTEGER */ - { 232, -2 }, /* (134) signed ::= MINUS INTEGER */ - { 193, -3 }, /* (135) cmd ::= CREATE TABLE create_table_args */ - { 193, -3 }, /* (136) cmd ::= CREATE TABLE create_stable_args */ - { 193, -3 }, /* (137) cmd ::= CREATE STABLE create_stable_args */ - { 193, -3 }, /* (138) cmd ::= CREATE TABLE create_table_list */ - { 235, -1 }, /* (139) create_table_list ::= create_from_stable */ - { 235, -2 }, /* (140) create_table_list ::= create_table_list create_from_stable */ - { 233, -6 }, /* (141) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ - { 234, -10 }, /* (142) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ - { 236, -10 }, /* (143) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP */ - { 236, -13 }, /* (144) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP */ - { 239, -3 }, /* (145) tagNamelist ::= tagNamelist COMMA ids */ - { 239, -1 }, /* (146) tagNamelist ::= ids */ - { 233, -5 }, /* (147) create_table_args ::= ifnotexists ids cpxName AS select */ - { 237, -3 }, /* (148) columnlist ::= columnlist COMMA column */ - { 237, -1 }, /* (149) columnlist ::= column */ - { 241, -2 }, /* (150) column ::= ids typename */ - { 238, -3 }, /* (151) tagitemlist1 ::= tagitemlist1 COMMA tagitem1 */ - { 238, -1 }, /* (152) tagitemlist1 ::= tagitem1 */ - { 242, -2 }, /* (153) tagitem1 ::= MINUS INTEGER */ - { 242, -2 }, /* (154) tagitem1 ::= MINUS FLOAT */ - { 242, -2 }, /* (155) tagitem1 ::= PLUS INTEGER */ - { 242, -2 }, /* (156) tagitem1 ::= PLUS FLOAT */ - { 242, -1 }, /* (157) tagitem1 ::= INTEGER */ - { 242, -1 }, /* (158) tagitem1 ::= FLOAT */ - { 242, -1 }, /* (159) tagitem1 ::= STRING */ - { 242, -1 }, /* (160) tagitem1 ::= BOOL */ - { 242, -1 }, /* (161) tagitem1 ::= NULL */ - { 242, -1 }, /* (162) tagitem1 ::= NOW */ - { 243, -3 }, /* (163) tagitemlist ::= tagitemlist COMMA tagitem */ - { 243, -1 }, /* (164) tagitemlist ::= tagitem */ - { 244, -1 }, /* (165) tagitem ::= INTEGER */ - { 244, -1 }, /* (166) tagitem ::= FLOAT */ - { 244, -1 }, /* (167) tagitem ::= STRING */ - { 244, -1 }, /* (168) tagitem ::= BOOL */ - { 244, -1 }, /* (169) tagitem ::= NULL */ - { 244, -1 }, /* (170) tagitem ::= NOW */ - { 244, -2 }, /* (171) tagitem ::= MINUS INTEGER */ - { 244, -2 }, /* (172) tagitem ::= MINUS FLOAT */ - { 244, -2 }, /* (173) tagitem ::= PLUS INTEGER */ - { 244, -2 }, /* (174) tagitem ::= PLUS FLOAT */ - { 240, -14 }, /* (175) select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ - { 240, -3 }, /* (176) select ::= LP select RP */ - { 258, -1 }, /* (177) union ::= select */ - { 258, -4 }, /* (178) union ::= union UNION ALL select */ - { 258, -3 }, /* (179) union ::= union UNION select */ - { 193, -1 }, /* (180) cmd ::= union */ - { 240, -2 }, /* (181) select ::= SELECT selcollist */ - { 259, -2 }, /* (182) sclp ::= selcollist COMMA */ - { 259, 0 }, /* (183) sclp ::= */ - { 245, -4 }, /* (184) selcollist ::= sclp distinct expr as */ - { 245, -2 }, /* (185) selcollist ::= sclp STAR */ - { 262, -2 }, /* (186) as ::= AS ids */ - { 262, -1 }, /* (187) as ::= ids */ - { 262, 0 }, /* (188) as ::= */ - { 260, -1 }, /* (189) distinct ::= DISTINCT */ - { 260, 0 }, /* (190) distinct ::= */ - { 246, -2 }, /* (191) from ::= FROM tablelist */ - { 246, -2 }, /* (192) from ::= FROM sub */ - { 264, -3 }, /* (193) sub ::= LP union RP */ - { 264, -4 }, /* (194) sub ::= LP union RP ids */ - { 264, -6 }, /* (195) sub ::= sub COMMA LP union RP ids */ - { 263, -2 }, /* (196) tablelist ::= ids cpxName */ - { 263, -3 }, /* (197) tablelist ::= ids cpxName ids */ - { 263, -4 }, /* (198) tablelist ::= tablelist COMMA ids cpxName */ - { 263, -5 }, /* (199) tablelist ::= tablelist COMMA ids cpxName ids */ - { 265, -1 }, /* (200) tmvar ::= VARIABLE */ - { 248, -4 }, /* (201) interval_option ::= intervalKey LP tmvar RP */ - { 248, -6 }, /* (202) interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ - { 248, 0 }, /* (203) interval_option ::= */ - { 266, -1 }, /* (204) intervalKey ::= INTERVAL */ - { 266, -1 }, /* (205) intervalKey ::= EVERY */ - { 250, 0 }, /* (206) session_option ::= */ - { 250, -7 }, /* (207) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ - { 251, 0 }, /* (208) windowstate_option ::= */ - { 251, -4 }, /* (209) windowstate_option ::= STATE_WINDOW LP ids RP */ - { 252, 0 }, /* (210) fill_opt ::= */ - { 252, -6 }, /* (211) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ - { 252, -4 }, /* (212) fill_opt ::= FILL LP ID RP */ - { 249, -4 }, /* (213) sliding_opt ::= SLIDING LP tmvar RP */ - { 249, 0 }, /* (214) sliding_opt ::= */ - { 255, 0 }, /* (215) orderby_opt ::= */ - { 255, -3 }, /* (216) orderby_opt ::= ORDER BY sortlist */ - { 267, -4 }, /* (217) sortlist ::= sortlist COMMA item sortorder */ - { 267, -2 }, /* (218) sortlist ::= item sortorder */ - { 269, -2 }, /* (219) item ::= ids cpxName */ - { 270, -1 }, /* (220) sortorder ::= ASC */ - { 270, -1 }, /* (221) sortorder ::= DESC */ - { 270, 0 }, /* (222) sortorder ::= */ - { 253, 0 }, /* (223) groupby_opt ::= */ - { 253, -3 }, /* (224) groupby_opt ::= GROUP BY grouplist */ - { 271, -3 }, /* (225) grouplist ::= grouplist COMMA item */ - { 271, -1 }, /* (226) grouplist ::= item */ - { 254, 0 }, /* (227) having_opt ::= */ - { 254, -2 }, /* (228) having_opt ::= HAVING expr */ - { 257, 0 }, /* (229) limit_opt ::= */ - { 257, -2 }, /* (230) limit_opt ::= LIMIT signed */ - { 257, -4 }, /* (231) limit_opt ::= LIMIT signed OFFSET signed */ - { 257, -4 }, /* (232) limit_opt ::= LIMIT signed COMMA signed */ - { 256, 0 }, /* (233) slimit_opt ::= */ - { 256, -2 }, /* (234) slimit_opt ::= SLIMIT signed */ - { 256, -4 }, /* (235) slimit_opt ::= SLIMIT signed SOFFSET signed */ - { 256, -4 }, /* (236) slimit_opt ::= SLIMIT signed COMMA signed */ - { 247, 0 }, /* (237) where_opt ::= */ - { 247, -2 }, /* (238) where_opt ::= WHERE expr */ - { 261, -3 }, /* (239) expr ::= LP expr RP */ - { 261, -1 }, /* (240) expr ::= ID */ - { 261, -3 }, /* (241) expr ::= ID DOT ID */ - { 261, -3 }, /* (242) expr ::= ID DOT STAR */ - { 261, -1 }, /* (243) expr ::= INTEGER */ - { 261, -2 }, /* (244) expr ::= MINUS INTEGER */ - { 261, -2 }, /* (245) expr ::= PLUS INTEGER */ - { 261, -1 }, /* (246) expr ::= FLOAT */ - { 261, -2 }, /* (247) expr ::= MINUS FLOAT */ - { 261, -2 }, /* (248) expr ::= PLUS FLOAT */ - { 261, -1 }, /* (249) expr ::= STRING */ - { 261, -1 }, /* (250) expr ::= NOW */ - { 261, -1 }, /* (251) expr ::= VARIABLE */ - { 261, -2 }, /* (252) expr ::= PLUS VARIABLE */ - { 261, -2 }, /* (253) expr ::= MINUS VARIABLE */ - { 261, -1 }, /* (254) expr ::= BOOL */ - { 261, -1 }, /* (255) expr ::= NULL */ - { 261, -4 }, /* (256) expr ::= ID LP exprlist RP */ - { 261, -4 }, /* (257) expr ::= ID LP STAR RP */ - { 261, -3 }, /* (258) expr ::= expr IS NULL */ - { 261, -4 }, /* (259) expr ::= expr IS NOT NULL */ - { 261, -3 }, /* (260) expr ::= expr LT expr */ - { 261, -3 }, /* (261) expr ::= expr GT expr */ - { 261, -3 }, /* (262) expr ::= expr LE expr */ - { 261, -3 }, /* (263) expr ::= expr GE expr */ - { 261, -3 }, /* (264) expr ::= expr NE expr */ - { 261, -3 }, /* (265) expr ::= expr EQ expr */ - { 261, -5 }, /* (266) expr ::= expr BETWEEN expr AND expr */ - { 261, -3 }, /* (267) expr ::= expr AND expr */ - { 261, -3 }, /* (268) expr ::= expr OR expr */ - { 261, -3 }, /* (269) expr ::= expr PLUS expr */ - { 261, -3 }, /* (270) expr ::= expr MINUS expr */ - { 261, -3 }, /* (271) expr ::= expr STAR expr */ - { 261, -3 }, /* (272) expr ::= expr SLASH expr */ - { 261, -3 }, /* (273) expr ::= expr REM expr */ - { 261, -3 }, /* (274) expr ::= expr LIKE expr */ - { 261, -3 }, /* (275) expr ::= expr MATCH expr */ - { 261, -3 }, /* (276) expr ::= expr NMATCH expr */ - { 261, -5 }, /* (277) expr ::= expr IN LP exprlist RP */ - { 200, -3 }, /* (278) exprlist ::= exprlist COMMA expritem */ - { 200, -1 }, /* (279) exprlist ::= expritem */ - { 272, -1 }, /* (280) expritem ::= expr */ - { 272, 0 }, /* (281) expritem ::= */ - { 193, -3 }, /* (282) cmd ::= RESET QUERY CACHE */ - { 193, -3 }, /* (283) cmd ::= SYNCDB ids REPLICA */ - { 193, -7 }, /* (284) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ - { 193, -7 }, /* (285) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ - { 193, -7 }, /* (286) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ - { 193, -7 }, /* (287) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ - { 193, -7 }, /* (288) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ - { 193, -8 }, /* (289) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ - { 193, -9 }, /* (290) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ - { 193, -7 }, /* (291) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ - { 193, -7 }, /* (292) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ - { 193, -7 }, /* (293) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ - { 193, -7 }, /* (294) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ - { 193, -7 }, /* (295) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ - { 193, -7 }, /* (296) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ - { 193, -8 }, /* (297) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ - { 193, -9 }, /* (298) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ - { 193, -7 }, /* (299) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ - { 193, -3 }, /* (300) cmd ::= KILL CONNECTION INTEGER */ - { 193, -5 }, /* (301) cmd ::= KILL STREAM INTEGER COLON INTEGER */ - { 193, -5 }, /* (302) cmd ::= KILL QUERY INTEGER COLON INTEGER */ + { 197, -2 }, /* (52) ifexists ::= IF EXISTS */ + { 197, 0 }, /* (53) ifexists ::= */ + { 201, -3 }, /* (54) ifnotexists ::= IF NOT EXISTS */ + { 201, 0 }, /* (55) ifnotexists ::= */ + { 193, -5 }, /* (56) cmd ::= CREATE DNODE ids PORT ids */ + { 193, -5 }, /* (57) cmd ::= CREATE DNODE IPTOKEN PORT ids */ + { 193, -6 }, /* (58) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + { 193, -5 }, /* (59) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + { 193, -8 }, /* (60) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + { 193, -9 }, /* (61) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + { 193, -5 }, /* (62) cmd ::= CREATE USER ids PASS ids */ + { 204, 0 }, /* (63) bufsize ::= */ + { 204, -2 }, /* (64) bufsize ::= BUFSIZE INTEGER */ + { 205, 0 }, /* (65) pps ::= */ + { 205, -2 }, /* (66) pps ::= PPS INTEGER */ + { 206, 0 }, /* (67) tseries ::= */ + { 206, -2 }, /* (68) tseries ::= TSERIES INTEGER */ + { 207, 0 }, /* (69) dbs ::= */ + { 207, -2 }, /* (70) dbs ::= DBS INTEGER */ + { 208, 0 }, /* (71) streams ::= */ + { 208, -2 }, /* (72) streams ::= STREAMS INTEGER */ + { 209, 0 }, /* (73) storage ::= */ + { 209, -2 }, /* (74) storage ::= STORAGE INTEGER */ + { 210, 0 }, /* (75) qtime ::= */ + { 210, -2 }, /* (76) qtime ::= QTIME INTEGER */ + { 211, 0 }, /* (77) users ::= */ + { 211, -2 }, /* (78) users ::= USERS INTEGER */ + { 212, 0 }, /* (79) conns ::= */ + { 212, -2 }, /* (80) conns ::= CONNS INTEGER */ + { 213, 0 }, /* (81) state ::= */ + { 213, -2 }, /* (82) state ::= STATE ids */ + { 199, -9 }, /* (83) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + { 214, -3 }, /* (84) intitemlist ::= intitemlist COMMA intitem */ + { 214, -1 }, /* (85) intitemlist ::= intitem */ + { 215, -1 }, /* (86) intitem ::= INTEGER */ + { 216, -2 }, /* (87) keep ::= KEEP intitemlist */ + { 217, -2 }, /* (88) cache ::= CACHE INTEGER */ + { 218, -2 }, /* (89) replica ::= REPLICA INTEGER */ + { 219, -2 }, /* (90) quorum ::= QUORUM INTEGER */ + { 220, -2 }, /* (91) days ::= DAYS INTEGER */ + { 221, -2 }, /* (92) minrows ::= MINROWS INTEGER */ + { 222, -2 }, /* (93) maxrows ::= MAXROWS INTEGER */ + { 223, -2 }, /* (94) blocks ::= BLOCKS INTEGER */ + { 224, -2 }, /* (95) ctime ::= CTIME INTEGER */ + { 225, -2 }, /* (96) wal ::= WAL INTEGER */ + { 226, -2 }, /* (97) fsync ::= FSYNC INTEGER */ + { 227, -2 }, /* (98) comp ::= COMP INTEGER */ + { 228, -2 }, /* (99) prec ::= PRECISION STRING */ + { 229, -2 }, /* (100) update ::= UPDATE INTEGER */ + { 230, -2 }, /* (101) cachelast ::= CACHELAST INTEGER */ + { 231, -2 }, /* (102) vgroups ::= VGROUPS INTEGER */ + { 202, 0 }, /* (103) db_optr ::= */ + { 202, -2 }, /* (104) db_optr ::= db_optr cache */ + { 202, -2 }, /* (105) db_optr ::= db_optr replica */ + { 202, -2 }, /* (106) db_optr ::= db_optr quorum */ + { 202, -2 }, /* (107) db_optr ::= db_optr days */ + { 202, -2 }, /* (108) db_optr ::= db_optr minrows */ + { 202, -2 }, /* (109) db_optr ::= db_optr maxrows */ + { 202, -2 }, /* (110) db_optr ::= db_optr blocks */ + { 202, -2 }, /* (111) db_optr ::= db_optr ctime */ + { 202, -2 }, /* (112) db_optr ::= db_optr wal */ + { 202, -2 }, /* (113) db_optr ::= db_optr fsync */ + { 202, -2 }, /* (114) db_optr ::= db_optr comp */ + { 202, -2 }, /* (115) db_optr ::= db_optr prec */ + { 202, -2 }, /* (116) db_optr ::= db_optr keep */ + { 202, -2 }, /* (117) db_optr ::= db_optr update */ + { 202, -2 }, /* (118) db_optr ::= db_optr cachelast */ + { 202, -2 }, /* (119) db_optr ::= db_optr vgroups */ + { 198, 0 }, /* (120) alter_db_optr ::= */ + { 198, -2 }, /* (121) alter_db_optr ::= alter_db_optr replica */ + { 198, -2 }, /* (122) alter_db_optr ::= alter_db_optr quorum */ + { 198, -2 }, /* (123) alter_db_optr ::= alter_db_optr keep */ + { 198, -2 }, /* (124) alter_db_optr ::= alter_db_optr blocks */ + { 198, -2 }, /* (125) alter_db_optr ::= alter_db_optr comp */ + { 198, -2 }, /* (126) alter_db_optr ::= alter_db_optr update */ + { 198, -2 }, /* (127) alter_db_optr ::= alter_db_optr cachelast */ + { 203, -1 }, /* (128) typename ::= ids */ + { 203, -4 }, /* (129) typename ::= ids LP signed RP */ + { 203, -2 }, /* (130) typename ::= ids UNSIGNED */ + { 232, -1 }, /* (131) signed ::= INTEGER */ + { 232, -2 }, /* (132) signed ::= PLUS INTEGER */ + { 232, -2 }, /* (133) signed ::= MINUS INTEGER */ + { 193, -3 }, /* (134) cmd ::= CREATE TABLE create_table_args */ + { 193, -3 }, /* (135) cmd ::= CREATE TABLE create_stable_args */ + { 193, -3 }, /* (136) cmd ::= CREATE STABLE create_stable_args */ + { 193, -3 }, /* (137) cmd ::= CREATE TABLE create_table_list */ + { 235, -1 }, /* (138) create_table_list ::= create_from_stable */ + { 235, -2 }, /* (139) create_table_list ::= create_table_list create_from_stable */ + { 233, -6 }, /* (140) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + { 234, -10 }, /* (141) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + { 236, -10 }, /* (142) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP */ + { 236, -13 }, /* (143) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP */ + { 239, -3 }, /* (144) tagNamelist ::= tagNamelist COMMA ids */ + { 239, -1 }, /* (145) tagNamelist ::= ids */ + { 233, -5 }, /* (146) create_table_args ::= ifnotexists ids cpxName AS select */ + { 237, -3 }, /* (147) columnlist ::= columnlist COMMA column */ + { 237, -1 }, /* (148) columnlist ::= column */ + { 241, -2 }, /* (149) column ::= ids typename */ + { 238, -3 }, /* (150) tagitemlist1 ::= tagitemlist1 COMMA tagitem1 */ + { 238, -1 }, /* (151) tagitemlist1 ::= tagitem1 */ + { 242, -2 }, /* (152) tagitem1 ::= MINUS INTEGER */ + { 242, -2 }, /* (153) tagitem1 ::= MINUS FLOAT */ + { 242, -2 }, /* (154) tagitem1 ::= PLUS INTEGER */ + { 242, -2 }, /* (155) tagitem1 ::= PLUS FLOAT */ + { 242, -1 }, /* (156) tagitem1 ::= INTEGER */ + { 242, -1 }, /* (157) tagitem1 ::= FLOAT */ + { 242, -1 }, /* (158) tagitem1 ::= STRING */ + { 242, -1 }, /* (159) tagitem1 ::= BOOL */ + { 242, -1 }, /* (160) tagitem1 ::= NULL */ + { 242, -1 }, /* (161) tagitem1 ::= NOW */ + { 243, -3 }, /* (162) tagitemlist ::= tagitemlist COMMA tagitem */ + { 243, -1 }, /* (163) tagitemlist ::= tagitem */ + { 244, -1 }, /* (164) tagitem ::= INTEGER */ + { 244, -1 }, /* (165) tagitem ::= FLOAT */ + { 244, -1 }, /* (166) tagitem ::= STRING */ + { 244, -1 }, /* (167) tagitem ::= BOOL */ + { 244, -1 }, /* (168) tagitem ::= NULL */ + { 244, -1 }, /* (169) tagitem ::= NOW */ + { 244, -2 }, /* (170) tagitem ::= MINUS INTEGER */ + { 244, -2 }, /* (171) tagitem ::= MINUS FLOAT */ + { 244, -2 }, /* (172) tagitem ::= PLUS INTEGER */ + { 244, -2 }, /* (173) tagitem ::= PLUS FLOAT */ + { 240, -14 }, /* (174) select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ + { 240, -3 }, /* (175) select ::= LP select RP */ + { 258, -1 }, /* (176) union ::= select */ + { 258, -4 }, /* (177) union ::= union UNION ALL select */ + { 258, -3 }, /* (178) union ::= union UNION select */ + { 193, -1 }, /* (179) cmd ::= union */ + { 240, -2 }, /* (180) select ::= SELECT selcollist */ + { 259, -2 }, /* (181) sclp ::= selcollist COMMA */ + { 259, 0 }, /* (182) sclp ::= */ + { 245, -4 }, /* (183) selcollist ::= sclp distinct expr as */ + { 245, -2 }, /* (184) selcollist ::= sclp STAR */ + { 262, -2 }, /* (185) as ::= AS ids */ + { 262, -1 }, /* (186) as ::= ids */ + { 262, 0 }, /* (187) as ::= */ + { 260, -1 }, /* (188) distinct ::= DISTINCT */ + { 260, 0 }, /* (189) distinct ::= */ + { 246, -2 }, /* (190) from ::= FROM tablelist */ + { 246, -2 }, /* (191) from ::= FROM sub */ + { 264, -3 }, /* (192) sub ::= LP union RP */ + { 264, -4 }, /* (193) sub ::= LP union RP ids */ + { 264, -6 }, /* (194) sub ::= sub COMMA LP union RP ids */ + { 263, -2 }, /* (195) tablelist ::= ids cpxName */ + { 263, -3 }, /* (196) tablelist ::= ids cpxName ids */ + { 263, -4 }, /* (197) tablelist ::= tablelist COMMA ids cpxName */ + { 263, -5 }, /* (198) tablelist ::= tablelist COMMA ids cpxName ids */ + { 265, -1 }, /* (199) tmvar ::= VARIABLE */ + { 248, -4 }, /* (200) interval_option ::= intervalKey LP tmvar RP */ + { 248, -6 }, /* (201) interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ + { 248, 0 }, /* (202) interval_option ::= */ + { 266, -1 }, /* (203) intervalKey ::= INTERVAL */ + { 266, -1 }, /* (204) intervalKey ::= EVERY */ + { 250, 0 }, /* (205) session_option ::= */ + { 250, -7 }, /* (206) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + { 251, 0 }, /* (207) windowstate_option ::= */ + { 251, -4 }, /* (208) windowstate_option ::= STATE_WINDOW LP ids RP */ + { 252, 0 }, /* (209) fill_opt ::= */ + { 252, -6 }, /* (210) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + { 252, -4 }, /* (211) fill_opt ::= FILL LP ID RP */ + { 249, -4 }, /* (212) sliding_opt ::= SLIDING LP tmvar RP */ + { 249, 0 }, /* (213) sliding_opt ::= */ + { 255, 0 }, /* (214) orderby_opt ::= */ + { 255, -3 }, /* (215) orderby_opt ::= ORDER BY sortlist */ + { 267, -4 }, /* (216) sortlist ::= sortlist COMMA item sortorder */ + { 267, -2 }, /* (217) sortlist ::= item sortorder */ + { 269, -2 }, /* (218) item ::= ids cpxName */ + { 270, -1 }, /* (219) sortorder ::= ASC */ + { 270, -1 }, /* (220) sortorder ::= DESC */ + { 270, 0 }, /* (221) sortorder ::= */ + { 253, 0 }, /* (222) groupby_opt ::= */ + { 253, -3 }, /* (223) groupby_opt ::= GROUP BY grouplist */ + { 271, -3 }, /* (224) grouplist ::= grouplist COMMA item */ + { 271, -1 }, /* (225) grouplist ::= item */ + { 254, 0 }, /* (226) having_opt ::= */ + { 254, -2 }, /* (227) having_opt ::= HAVING expr */ + { 257, 0 }, /* (228) limit_opt ::= */ + { 257, -2 }, /* (229) limit_opt ::= LIMIT signed */ + { 257, -4 }, /* (230) limit_opt ::= LIMIT signed OFFSET signed */ + { 257, -4 }, /* (231) limit_opt ::= LIMIT signed COMMA signed */ + { 256, 0 }, /* (232) slimit_opt ::= */ + { 256, -2 }, /* (233) slimit_opt ::= SLIMIT signed */ + { 256, -4 }, /* (234) slimit_opt ::= SLIMIT signed SOFFSET signed */ + { 256, -4 }, /* (235) slimit_opt ::= SLIMIT signed COMMA signed */ + { 247, 0 }, /* (236) where_opt ::= */ + { 247, -2 }, /* (237) where_opt ::= WHERE expr */ + { 261, -3 }, /* (238) expr ::= LP expr RP */ + { 261, -1 }, /* (239) expr ::= ID */ + { 261, -3 }, /* (240) expr ::= ID DOT ID */ + { 261, -3 }, /* (241) expr ::= ID DOT STAR */ + { 261, -1 }, /* (242) expr ::= INTEGER */ + { 261, -2 }, /* (243) expr ::= MINUS INTEGER */ + { 261, -2 }, /* (244) expr ::= PLUS INTEGER */ + { 261, -1 }, /* (245) expr ::= FLOAT */ + { 261, -2 }, /* (246) expr ::= MINUS FLOAT */ + { 261, -2 }, /* (247) expr ::= PLUS FLOAT */ + { 261, -1 }, /* (248) expr ::= STRING */ + { 261, -1 }, /* (249) expr ::= NOW */ + { 261, -1 }, /* (250) expr ::= VARIABLE */ + { 261, -2 }, /* (251) expr ::= PLUS VARIABLE */ + { 261, -2 }, /* (252) expr ::= MINUS VARIABLE */ + { 261, -1 }, /* (253) expr ::= BOOL */ + { 261, -1 }, /* (254) expr ::= NULL */ + { 261, -4 }, /* (255) expr ::= ID LP exprlist RP */ + { 261, -4 }, /* (256) expr ::= ID LP STAR RP */ + { 261, -3 }, /* (257) expr ::= expr IS NULL */ + { 261, -4 }, /* (258) expr ::= expr IS NOT NULL */ + { 261, -3 }, /* (259) expr ::= expr LT expr */ + { 261, -3 }, /* (260) expr ::= expr GT expr */ + { 261, -3 }, /* (261) expr ::= expr LE expr */ + { 261, -3 }, /* (262) expr ::= expr GE expr */ + { 261, -3 }, /* (263) expr ::= expr NE expr */ + { 261, -3 }, /* (264) expr ::= expr EQ expr */ + { 261, -5 }, /* (265) expr ::= expr BETWEEN expr AND expr */ + { 261, -3 }, /* (266) expr ::= expr AND expr */ + { 261, -3 }, /* (267) expr ::= expr OR expr */ + { 261, -3 }, /* (268) expr ::= expr PLUS expr */ + { 261, -3 }, /* (269) expr ::= expr MINUS expr */ + { 261, -3 }, /* (270) expr ::= expr STAR expr */ + { 261, -3 }, /* (271) expr ::= expr SLASH expr */ + { 261, -3 }, /* (272) expr ::= expr REM expr */ + { 261, -3 }, /* (273) expr ::= expr LIKE expr */ + { 261, -3 }, /* (274) expr ::= expr MATCH expr */ + { 261, -3 }, /* (275) expr ::= expr NMATCH expr */ + { 261, -5 }, /* (276) expr ::= expr IN LP exprlist RP */ + { 200, -3 }, /* (277) exprlist ::= exprlist COMMA expritem */ + { 200, -1 }, /* (278) exprlist ::= expritem */ + { 272, -1 }, /* (279) expritem ::= expr */ + { 272, 0 }, /* (280) expritem ::= */ + { 193, -3 }, /* (281) cmd ::= RESET QUERY CACHE */ + { 193, -3 }, /* (282) cmd ::= SYNCDB ids REPLICA */ + { 193, -7 }, /* (283) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + { 193, -7 }, /* (284) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + { 193, -7 }, /* (285) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + { 193, -7 }, /* (286) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + { 193, -7 }, /* (287) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + { 193, -8 }, /* (288) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + { 193, -9 }, /* (289) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + { 193, -7 }, /* (290) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + { 193, -7 }, /* (291) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + { 193, -7 }, /* (292) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + { 193, -7 }, /* (293) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + { 193, -7 }, /* (294) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + { 193, -7 }, /* (295) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + { 193, -8 }, /* (296) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + { 193, -9 }, /* (297) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + { 193, -7 }, /* (298) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + { 193, -3 }, /* (299) cmd ::= KILL CONNECTION INTEGER */ + { 193, -5 }, /* (300) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + { 193, -5 }, /* (301) cmd ::= KILL QUERY INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2224,9 +2220,9 @@ static void yy_reduce( /********** Begin reduce actions **********************************************/ YYMINORTYPE yylhsminor; case 0: /* program ::= cmd */ - case 135: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==135); - case 136: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==136); - case 137: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==137); + case 134: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==134); + case 135: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==135); + case 136: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==136); {} break; case 1: /* cmd ::= SHOW DATABASES */ @@ -2414,65 +2410,64 @@ static void yy_reduce( { setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, yymsp[-1].minor.yy165);} break; case 51: /* ids ::= ID */ - case 52: /* ids ::= STRING */ yytestcase(yyruleno==52); {yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 53: /* ifexists ::= IF EXISTS */ + case 52: /* ifexists ::= IF EXISTS */ { yymsp[-1].minor.yy0.n = 1;} break; - case 54: /* ifexists ::= */ - case 56: /* ifnotexists ::= */ yytestcase(yyruleno==56); - case 190: /* distinct ::= */ yytestcase(yyruleno==190); + case 53: /* ifexists ::= */ + case 55: /* ifnotexists ::= */ yytestcase(yyruleno==55); + case 189: /* distinct ::= */ yytestcase(yyruleno==189); { yymsp[1].minor.yy0.n = 0;} break; - case 55: /* ifnotexists ::= IF NOT EXISTS */ + case 54: /* ifnotexists ::= IF NOT EXISTS */ { yymsp[-2].minor.yy0.n = 1;} break; - case 57: /* cmd ::= CREATE DNODE ids PORT ids */ - case 58: /* cmd ::= CREATE DNODE IPTOKEN PORT ids */ yytestcase(yyruleno==58); + case 56: /* cmd ::= CREATE DNODE ids PORT ids */ + case 57: /* cmd ::= CREATE DNODE IPTOKEN PORT ids */ yytestcase(yyruleno==57); { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 2, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} break; - case 59: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + case 58: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ { setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy211);} break; - case 60: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + case 59: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy16, &yymsp[-2].minor.yy0);} break; - case 61: /* cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + case 60: /* cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ { setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy106, &yymsp[0].minor.yy0, 1);} break; - case 62: /* cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + case 61: /* cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ { setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy106, &yymsp[0].minor.yy0, 2);} break; - case 63: /* cmd ::= CREATE USER ids PASS ids */ + case 62: /* cmd ::= CREATE USER ids PASS ids */ { setCreateUserSql(pInfo, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} break; - case 64: /* bufsize ::= */ - case 66: /* pps ::= */ yytestcase(yyruleno==66); - case 68: /* tseries ::= */ yytestcase(yyruleno==68); - case 70: /* dbs ::= */ yytestcase(yyruleno==70); - case 72: /* streams ::= */ yytestcase(yyruleno==72); - case 74: /* storage ::= */ yytestcase(yyruleno==74); - case 76: /* qtime ::= */ yytestcase(yyruleno==76); - case 78: /* users ::= */ yytestcase(yyruleno==78); - case 80: /* conns ::= */ yytestcase(yyruleno==80); - case 82: /* state ::= */ yytestcase(yyruleno==82); + case 63: /* bufsize ::= */ + case 65: /* pps ::= */ yytestcase(yyruleno==65); + case 67: /* tseries ::= */ yytestcase(yyruleno==67); + case 69: /* dbs ::= */ yytestcase(yyruleno==69); + case 71: /* streams ::= */ yytestcase(yyruleno==71); + case 73: /* storage ::= */ yytestcase(yyruleno==73); + case 75: /* qtime ::= */ yytestcase(yyruleno==75); + case 77: /* users ::= */ yytestcase(yyruleno==77); + case 79: /* conns ::= */ yytestcase(yyruleno==79); + case 81: /* state ::= */ yytestcase(yyruleno==81); { yymsp[1].minor.yy0.n = 0; } break; - case 65: /* bufsize ::= BUFSIZE INTEGER */ - case 67: /* pps ::= PPS INTEGER */ yytestcase(yyruleno==67); - case 69: /* tseries ::= TSERIES INTEGER */ yytestcase(yyruleno==69); - case 71: /* dbs ::= DBS INTEGER */ yytestcase(yyruleno==71); - case 73: /* streams ::= STREAMS INTEGER */ yytestcase(yyruleno==73); - case 75: /* storage ::= STORAGE INTEGER */ yytestcase(yyruleno==75); - case 77: /* qtime ::= QTIME INTEGER */ yytestcase(yyruleno==77); - case 79: /* users ::= USERS INTEGER */ yytestcase(yyruleno==79); - case 81: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==81); - case 83: /* state ::= STATE ids */ yytestcase(yyruleno==83); + case 64: /* bufsize ::= BUFSIZE INTEGER */ + case 66: /* pps ::= PPS INTEGER */ yytestcase(yyruleno==66); + case 68: /* tseries ::= TSERIES INTEGER */ yytestcase(yyruleno==68); + case 70: /* dbs ::= DBS INTEGER */ yytestcase(yyruleno==70); + case 72: /* streams ::= STREAMS INTEGER */ yytestcase(yyruleno==72); + case 74: /* storage ::= STORAGE INTEGER */ yytestcase(yyruleno==74); + case 76: /* qtime ::= QTIME INTEGER */ yytestcase(yyruleno==76); + case 78: /* users ::= USERS INTEGER */ yytestcase(yyruleno==78); + case 80: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==80); + case 82: /* state ::= STATE ids */ yytestcase(yyruleno==82); { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 84: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + case 83: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ { yylhsminor.yy211.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; yylhsminor.yy211.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; @@ -2486,129 +2481,129 @@ static void yy_reduce( } yymsp[-8].minor.yy211 = yylhsminor.yy211; break; - case 85: /* intitemlist ::= intitemlist COMMA intitem */ - case 163: /* tagitemlist ::= tagitemlist COMMA tagitem */ yytestcase(yyruleno==163); + case 84: /* intitemlist ::= intitemlist COMMA intitem */ + case 162: /* tagitemlist ::= tagitemlist COMMA tagitem */ yytestcase(yyruleno==162); { yylhsminor.yy165 = tListItemAppend(yymsp[-2].minor.yy165, &yymsp[0].minor.yy425, -1); } yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 86: /* intitemlist ::= intitem */ - case 164: /* tagitemlist ::= tagitem */ yytestcase(yyruleno==164); + case 85: /* intitemlist ::= intitem */ + case 163: /* tagitemlist ::= tagitem */ yytestcase(yyruleno==163); { yylhsminor.yy165 = tListItemAppend(NULL, &yymsp[0].minor.yy425, -1); } yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 87: /* intitem ::= INTEGER */ - case 165: /* tagitem ::= INTEGER */ yytestcase(yyruleno==165); - case 166: /* tagitem ::= FLOAT */ yytestcase(yyruleno==166); - case 167: /* tagitem ::= STRING */ yytestcase(yyruleno==167); - case 168: /* tagitem ::= BOOL */ yytestcase(yyruleno==168); + case 86: /* intitem ::= INTEGER */ + case 164: /* tagitem ::= INTEGER */ yytestcase(yyruleno==164); + case 165: /* tagitem ::= FLOAT */ yytestcase(yyruleno==165); + case 166: /* tagitem ::= STRING */ yytestcase(yyruleno==166); + case 167: /* tagitem ::= BOOL */ yytestcase(yyruleno==167); { toTSDBType(yymsp[0].minor.yy0.type); taosVariantCreate(&yylhsminor.yy425, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type); } yymsp[0].minor.yy425 = yylhsminor.yy425; break; - case 88: /* keep ::= KEEP intitemlist */ + case 87: /* keep ::= KEEP intitemlist */ { yymsp[-1].minor.yy165 = yymsp[0].minor.yy165; } break; - case 89: /* cache ::= CACHE INTEGER */ - case 90: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==90); - case 91: /* quorum ::= QUORUM INTEGER */ yytestcase(yyruleno==91); - case 92: /* days ::= DAYS INTEGER */ yytestcase(yyruleno==92); - case 93: /* minrows ::= MINROWS INTEGER */ yytestcase(yyruleno==93); - case 94: /* maxrows ::= MAXROWS INTEGER */ yytestcase(yyruleno==94); - case 95: /* blocks ::= BLOCKS INTEGER */ yytestcase(yyruleno==95); - case 96: /* ctime ::= CTIME INTEGER */ yytestcase(yyruleno==96); - case 97: /* wal ::= WAL INTEGER */ yytestcase(yyruleno==97); - case 98: /* fsync ::= FSYNC INTEGER */ yytestcase(yyruleno==98); - case 99: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==99); - case 100: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==100); - case 101: /* update ::= UPDATE INTEGER */ yytestcase(yyruleno==101); - case 102: /* cachelast ::= CACHELAST INTEGER */ yytestcase(yyruleno==102); - case 103: /* vgroups ::= VGROUPS INTEGER */ yytestcase(yyruleno==103); + case 88: /* cache ::= CACHE INTEGER */ + case 89: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==89); + case 90: /* quorum ::= QUORUM INTEGER */ yytestcase(yyruleno==90); + case 91: /* days ::= DAYS INTEGER */ yytestcase(yyruleno==91); + case 92: /* minrows ::= MINROWS INTEGER */ yytestcase(yyruleno==92); + case 93: /* maxrows ::= MAXROWS INTEGER */ yytestcase(yyruleno==93); + case 94: /* blocks ::= BLOCKS INTEGER */ yytestcase(yyruleno==94); + case 95: /* ctime ::= CTIME INTEGER */ yytestcase(yyruleno==95); + case 96: /* wal ::= WAL INTEGER */ yytestcase(yyruleno==96); + case 97: /* fsync ::= FSYNC INTEGER */ yytestcase(yyruleno==97); + case 98: /* comp ::= COMP INTEGER */ yytestcase(yyruleno==98); + case 99: /* prec ::= PRECISION STRING */ yytestcase(yyruleno==99); + case 100: /* update ::= UPDATE INTEGER */ yytestcase(yyruleno==100); + case 101: /* cachelast ::= CACHELAST INTEGER */ yytestcase(yyruleno==101); + case 102: /* vgroups ::= VGROUPS INTEGER */ yytestcase(yyruleno==102); { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 104: /* db_optr ::= */ + case 103: /* db_optr ::= */ {setDefaultCreateDbOption(&yymsp[1].minor.yy16);} break; - case 105: /* db_optr ::= db_optr cache */ + case 104: /* db_optr ::= db_optr cache */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 106: /* db_optr ::= db_optr replica */ - case 122: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==122); + case 105: /* db_optr ::= db_optr replica */ + case 121: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==121); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 107: /* db_optr ::= db_optr quorum */ - case 123: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==123); + case 106: /* db_optr ::= db_optr quorum */ + case 122: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==122); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 108: /* db_optr ::= db_optr days */ + case 107: /* db_optr ::= db_optr days */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 109: /* db_optr ::= db_optr minrows */ + case 108: /* db_optr ::= db_optr minrows */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 110: /* db_optr ::= db_optr maxrows */ + case 109: /* db_optr ::= db_optr maxrows */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 111: /* db_optr ::= db_optr blocks */ - case 125: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==125); + case 110: /* db_optr ::= db_optr blocks */ + case 124: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==124); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 112: /* db_optr ::= db_optr ctime */ + case 111: /* db_optr ::= db_optr ctime */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 113: /* db_optr ::= db_optr wal */ + case 112: /* db_optr ::= db_optr wal */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 114: /* db_optr ::= db_optr fsync */ + case 113: /* db_optr ::= db_optr fsync */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 115: /* db_optr ::= db_optr comp */ - case 126: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==126); + case 114: /* db_optr ::= db_optr comp */ + case 125: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==125); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 116: /* db_optr ::= db_optr prec */ + case 115: /* db_optr ::= db_optr prec */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.precision = yymsp[0].minor.yy0; } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 117: /* db_optr ::= db_optr keep */ - case 124: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==124); + case 116: /* db_optr ::= db_optr keep */ + case 123: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==123); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.keep = yymsp[0].minor.yy165; } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 118: /* db_optr ::= db_optr update */ - case 127: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==127); + case 117: /* db_optr ::= db_optr update */ + case 126: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==126); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 119: /* db_optr ::= db_optr cachelast */ - case 128: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==128); + case 118: /* db_optr ::= db_optr cachelast */ + case 127: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==127); { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 120: /* db_optr ::= db_optr vgroups */ + case 119: /* db_optr ::= db_optr vgroups */ { yylhsminor.yy16 = yymsp[-1].minor.yy16; yylhsminor.yy16.numOfVgroups = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[-1].minor.yy16 = yylhsminor.yy16; break; - case 121: /* alter_db_optr ::= */ + case 120: /* alter_db_optr ::= */ { setDefaultCreateDbOption(&yymsp[1].minor.yy16);} break; - case 129: /* typename ::= ids */ + case 128: /* typename ::= ids */ { yymsp[0].minor.yy0.type = 0; tSetColumnType (&yylhsminor.yy106, &yymsp[0].minor.yy0); } yymsp[0].minor.yy106 = yylhsminor.yy106; break; - case 130: /* typename ::= ids LP signed RP */ + case 129: /* typename ::= ids LP signed RP */ { if (yymsp[-1].minor.yy207 <= 0) { yymsp[-3].minor.yy0.type = 0; @@ -2620,7 +2615,7 @@ static void yy_reduce( } yymsp[-3].minor.yy106 = yylhsminor.yy106; break; - case 131: /* typename ::= ids UNSIGNED */ + case 130: /* typename ::= ids UNSIGNED */ { yymsp[-1].minor.yy0.type = 0; yymsp[-1].minor.yy0.n = ((yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z); @@ -2628,40 +2623,40 @@ static void yy_reduce( } yymsp[-1].minor.yy106 = yylhsminor.yy106; break; - case 132: /* signed ::= INTEGER */ + case 131: /* signed ::= INTEGER */ { yylhsminor.yy207 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } yymsp[0].minor.yy207 = yylhsminor.yy207; break; - case 133: /* signed ::= PLUS INTEGER */ + case 132: /* signed ::= PLUS INTEGER */ { yymsp[-1].minor.yy207 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 134: /* signed ::= MINUS INTEGER */ + case 133: /* signed ::= MINUS INTEGER */ { yymsp[-1].minor.yy207 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} break; - case 138: /* cmd ::= CREATE TABLE create_table_list */ + case 137: /* cmd ::= CREATE TABLE create_table_list */ { pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy326;} break; - case 139: /* create_table_list ::= create_from_stable */ + case 138: /* create_table_list ::= create_from_stable */ { SCreateTableSql* pCreateTable = calloc(1, sizeof(SCreateTableSql)); pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo)); taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy150); - pCreateTable->type = TSQL_CREATE_CTABLE; + pCreateTable->type = TSDB_SQL_CREATE_TABLE; yylhsminor.yy326 = pCreateTable; } yymsp[0].minor.yy326 = yylhsminor.yy326; break; - case 140: /* create_table_list ::= create_table_list create_from_stable */ + case 139: /* create_table_list ::= create_table_list create_from_stable */ { taosArrayPush(yymsp[-1].minor.yy326->childTableInfo, &yymsp[0].minor.yy150); yylhsminor.yy326 = yymsp[-1].minor.yy326; } yymsp[-1].minor.yy326 = yylhsminor.yy326; break; - case 141: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + case 140: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ { - yylhsminor.yy326 = tSetCreateTableInfo(yymsp[-1].minor.yy165, NULL, NULL, TSQL_CREATE_TABLE); + yylhsminor.yy326 = tSetCreateTableInfo(yymsp[-1].minor.yy165, NULL, NULL, TSDB_SQL_CREATE_TABLE); setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -2669,17 +2664,17 @@ static void yy_reduce( } yymsp[-5].minor.yy326 = yylhsminor.yy326; break; - case 142: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + case 141: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ { - yylhsminor.yy326 = tSetCreateTableInfo(yymsp[-5].minor.yy165, yymsp[-1].minor.yy165, NULL, TSQL_CREATE_STABLE); - setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy326 = tSetCreateTableInfo(yymsp[-5].minor.yy165, yymsp[-1].minor.yy165, NULL, TSDB_SQL_CREATE_STABLE); + setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_STABLE); yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } yymsp[-9].minor.yy326 = yylhsminor.yy326; break; - case 143: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP */ + case 142: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist1 RP */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; @@ -2687,7 +2682,7 @@ static void yy_reduce( } yymsp[-9].minor.yy150 = yylhsminor.yy150; break; - case 144: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP */ + case 143: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist1 RP */ { yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; yymsp[-11].minor.yy0.n += yymsp[-10].minor.yy0.n; @@ -2695,74 +2690,74 @@ static void yy_reduce( } yymsp[-12].minor.yy150 = yylhsminor.yy150; break; - case 145: /* tagNamelist ::= tagNamelist COMMA ids */ + case 144: /* tagNamelist ::= tagNamelist COMMA ids */ {taosArrayPush(yymsp[-2].minor.yy165, &yymsp[0].minor.yy0); yylhsminor.yy165 = yymsp[-2].minor.yy165; } yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 146: /* tagNamelist ::= ids */ + case 145: /* tagNamelist ::= ids */ {yylhsminor.yy165 = taosArrayInit(4, sizeof(SToken)); taosArrayPush(yylhsminor.yy165, &yymsp[0].minor.yy0);} yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 147: /* create_table_args ::= ifnotexists ids cpxName AS select */ + case 146: /* create_table_args ::= ifnotexists ids cpxName AS select */ { - yylhsminor.yy326 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy278, TSQL_CREATE_STREAM); - setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_TABLE); - - yymsp[-3].minor.yy0.n += yymsp[-2].minor.yy0.n; - setCreatedTableName(pInfo, &yymsp[-3].minor.yy0, &yymsp[-4].minor.yy0); +// yylhsminor.yy326 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy278, TSQL_CREATE_STREAM); +// setSqlInfo(pInfo, yylhsminor.yy326, NULL, TSDB_SQL_CREATE_TABLE); +// +// yymsp[-3].minor.yy0.n += yymsp[-2].minor.yy0.n; +// setCreatedTableName(pInfo, &yymsp[-3].minor.yy0, &yymsp[-4].minor.yy0); } yymsp[-4].minor.yy326 = yylhsminor.yy326; break; - case 148: /* columnlist ::= columnlist COMMA column */ + case 147: /* columnlist ::= columnlist COMMA column */ {taosArrayPush(yymsp[-2].minor.yy165, &yymsp[0].minor.yy106); yylhsminor.yy165 = yymsp[-2].minor.yy165; } yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 149: /* columnlist ::= column */ + case 148: /* columnlist ::= column */ {yylhsminor.yy165 = taosArrayInit(4, sizeof(SField)); taosArrayPush(yylhsminor.yy165, &yymsp[0].minor.yy106);} yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 150: /* column ::= ids typename */ + case 149: /* column ::= ids typename */ { tSetColumnInfo(&yylhsminor.yy106, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy106); } yymsp[-1].minor.yy106 = yylhsminor.yy106; break; - case 151: /* tagitemlist1 ::= tagitemlist1 COMMA tagitem1 */ + case 150: /* tagitemlist1 ::= tagitemlist1 COMMA tagitem1 */ { taosArrayPush(yymsp[-2].minor.yy165, &yymsp[0].minor.yy0); yylhsminor.yy165 = yymsp[-2].minor.yy165;} yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 152: /* tagitemlist1 ::= tagitem1 */ + case 151: /* tagitemlist1 ::= tagitem1 */ { yylhsminor.yy165 = taosArrayInit(4, sizeof(SToken)); taosArrayPush(yylhsminor.yy165, &yymsp[0].minor.yy0); } yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 153: /* tagitem1 ::= MINUS INTEGER */ - case 154: /* tagitem1 ::= MINUS FLOAT */ yytestcase(yyruleno==154); - case 155: /* tagitem1 ::= PLUS INTEGER */ yytestcase(yyruleno==155); - case 156: /* tagitem1 ::= PLUS FLOAT */ yytestcase(yyruleno==156); + case 152: /* tagitem1 ::= MINUS INTEGER */ + case 153: /* tagitem1 ::= MINUS FLOAT */ yytestcase(yyruleno==153); + case 154: /* tagitem1 ::= PLUS INTEGER */ yytestcase(yyruleno==154); + case 155: /* tagitem1 ::= PLUS FLOAT */ yytestcase(yyruleno==155); { yylhsminor.yy0.n = yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n; yylhsminor.yy0.type = yymsp[0].minor.yy0.type; } yymsp[-1].minor.yy0 = yylhsminor.yy0; break; - case 157: /* tagitem1 ::= INTEGER */ - case 158: /* tagitem1 ::= FLOAT */ yytestcase(yyruleno==158); - case 159: /* tagitem1 ::= STRING */ yytestcase(yyruleno==159); - case 160: /* tagitem1 ::= BOOL */ yytestcase(yyruleno==160); - case 161: /* tagitem1 ::= NULL */ yytestcase(yyruleno==161); - case 162: /* tagitem1 ::= NOW */ yytestcase(yyruleno==162); + case 156: /* tagitem1 ::= INTEGER */ + case 157: /* tagitem1 ::= FLOAT */ yytestcase(yyruleno==157); + case 158: /* tagitem1 ::= STRING */ yytestcase(yyruleno==158); + case 159: /* tagitem1 ::= BOOL */ yytestcase(yyruleno==159); + case 160: /* tagitem1 ::= NULL */ yytestcase(yyruleno==160); + case 161: /* tagitem1 ::= NOW */ yytestcase(yyruleno==161); { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 169: /* tagitem ::= NULL */ + case 168: /* tagitem ::= NULL */ { yymsp[0].minor.yy0.type = 0; taosVariantCreate(&yylhsminor.yy425, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type); } yymsp[0].minor.yy425 = yylhsminor.yy425; break; - case 170: /* tagitem ::= NOW */ + case 169: /* tagitem ::= NOW */ { yymsp[0].minor.yy0.type = TSDB_DATA_TYPE_TIMESTAMP; taosVariantCreate(&yylhsminor.yy425, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.type);} yymsp[0].minor.yy425 = yylhsminor.yy425; break; - case 171: /* tagitem ::= MINUS INTEGER */ - case 172: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==172); - case 173: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==173); - case 174: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==174); + case 170: /* tagitem ::= MINUS INTEGER */ + case 171: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==171); + case 172: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==172); + case 173: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==173); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type; @@ -2771,154 +2766,154 @@ static void yy_reduce( } yymsp[-1].minor.yy425 = yylhsminor.yy425; break; - case 175: /* select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ + case 174: /* select ::= SELECT selcollist from where_opt interval_option sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ { yylhsminor.yy278 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy165, yymsp[-11].minor.yy10, yymsp[-10].minor.yy202, yymsp[-4].minor.yy165, yymsp[-2].minor.yy165, &yymsp[-9].minor.yy532, &yymsp[-7].minor.yy97, &yymsp[-6].minor.yy6, &yymsp[-8].minor.yy0, yymsp[-5].minor.yy165, &yymsp[0].minor.yy367, &yymsp[-1].minor.yy367, yymsp[-3].minor.yy202); } yymsp[-13].minor.yy278 = yylhsminor.yy278; break; - case 176: /* select ::= LP select RP */ + case 175: /* select ::= LP select RP */ {yymsp[-2].minor.yy278 = yymsp[-1].minor.yy278;} break; - case 177: /* union ::= select */ + case 176: /* union ::= select */ { yylhsminor.yy503 = setSubclause(NULL, yymsp[0].minor.yy278); } yymsp[0].minor.yy503 = yylhsminor.yy503; break; - case 178: /* union ::= union UNION ALL select */ + case 177: /* union ::= union UNION ALL select */ { yylhsminor.yy503 = appendSelectClause(yymsp[-3].minor.yy503, SQL_TYPE_UNIONALL, yymsp[0].minor.yy278); } yymsp[-3].minor.yy503 = yylhsminor.yy503; break; - case 179: /* union ::= union UNION select */ + case 178: /* union ::= union UNION select */ { yylhsminor.yy503 = appendSelectClause(yymsp[-2].minor.yy503, SQL_TYPE_UNION, yymsp[0].minor.yy278); } yymsp[-2].minor.yy503 = yylhsminor.yy503; break; - case 180: /* cmd ::= union */ + case 179: /* cmd ::= union */ { setSqlInfo(pInfo, yymsp[0].minor.yy503, NULL, TSDB_SQL_SELECT); } break; - case 181: /* select ::= SELECT selcollist */ + case 180: /* select ::= SELECT selcollist */ { yylhsminor.yy278 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy165, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); } yymsp[-1].minor.yy278 = yylhsminor.yy278; break; - case 182: /* sclp ::= selcollist COMMA */ + case 181: /* sclp ::= selcollist COMMA */ {yylhsminor.yy165 = yymsp[-1].minor.yy165;} yymsp[-1].minor.yy165 = yylhsminor.yy165; break; - case 183: /* sclp ::= */ - case 215: /* orderby_opt ::= */ yytestcase(yyruleno==215); + case 182: /* sclp ::= */ + case 214: /* orderby_opt ::= */ yytestcase(yyruleno==214); {yymsp[1].minor.yy165 = 0;} break; - case 184: /* selcollist ::= sclp distinct expr as */ + case 183: /* selcollist ::= sclp distinct expr as */ { yylhsminor.yy165 = tSqlExprListAppend(yymsp[-3].minor.yy165, yymsp[-1].minor.yy202, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); } yymsp[-3].minor.yy165 = yylhsminor.yy165; break; - case 185: /* selcollist ::= sclp STAR */ + case 184: /* selcollist ::= sclp STAR */ { tSqlExpr *pNode = tSqlExprCreateIdValue(NULL, TK_ALL); yylhsminor.yy165 = tSqlExprListAppend(yymsp[-1].minor.yy165, pNode, 0, 0); } yymsp[-1].minor.yy165 = yylhsminor.yy165; break; - case 186: /* as ::= AS ids */ + case 185: /* as ::= AS ids */ { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } break; - case 187: /* as ::= ids */ + case 186: /* as ::= ids */ { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 188: /* as ::= */ + case 187: /* as ::= */ { yymsp[1].minor.yy0.n = 0; } break; - case 189: /* distinct ::= DISTINCT */ + case 188: /* distinct ::= DISTINCT */ { yylhsminor.yy0 = yymsp[0].minor.yy0; } yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 191: /* from ::= FROM tablelist */ - case 192: /* from ::= FROM sub */ yytestcase(yyruleno==192); + case 190: /* from ::= FROM tablelist */ + case 191: /* from ::= FROM sub */ yytestcase(yyruleno==191); {yymsp[-1].minor.yy10 = yymsp[0].minor.yy10;} break; - case 193: /* sub ::= LP union RP */ + case 192: /* sub ::= LP union RP */ {yymsp[-2].minor.yy10 = addSubquery(NULL, yymsp[-1].minor.yy503, NULL);} break; - case 194: /* sub ::= LP union RP ids */ + case 193: /* sub ::= LP union RP ids */ {yymsp[-3].minor.yy10 = addSubquery(NULL, yymsp[-2].minor.yy503, &yymsp[0].minor.yy0);} break; - case 195: /* sub ::= sub COMMA LP union RP ids */ + case 194: /* sub ::= sub COMMA LP union RP ids */ {yylhsminor.yy10 = addSubquery(yymsp[-5].minor.yy10, yymsp[-2].minor.yy503, &yymsp[0].minor.yy0);} yymsp[-5].minor.yy10 = yylhsminor.yy10; break; - case 196: /* tablelist ::= ids cpxName */ + case 195: /* tablelist ::= ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yylhsminor.yy10 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); } yymsp[-1].minor.yy10 = yylhsminor.yy10; break; - case 197: /* tablelist ::= ids cpxName ids */ + case 196: /* tablelist ::= ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; yylhsminor.yy10 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } yymsp[-2].minor.yy10 = yylhsminor.yy10; break; - case 198: /* tablelist ::= tablelist COMMA ids cpxName */ + case 197: /* tablelist ::= tablelist COMMA ids cpxName */ { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yylhsminor.yy10 = setTableNameList(yymsp[-3].minor.yy10, &yymsp[-1].minor.yy0, NULL); } yymsp[-3].minor.yy10 = yylhsminor.yy10; break; - case 199: /* tablelist ::= tablelist COMMA ids cpxName ids */ + case 198: /* tablelist ::= tablelist COMMA ids cpxName ids */ { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; yylhsminor.yy10 = setTableNameList(yymsp[-4].minor.yy10, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } yymsp[-4].minor.yy10 = yylhsminor.yy10; break; - case 200: /* tmvar ::= VARIABLE */ + case 199: /* tmvar ::= VARIABLE */ {yylhsminor.yy0 = yymsp[0].minor.yy0;} yymsp[0].minor.yy0 = yylhsminor.yy0; break; - case 201: /* interval_option ::= intervalKey LP tmvar RP */ + case 200: /* interval_option ::= intervalKey LP tmvar RP */ {yylhsminor.yy532.interval = yymsp[-1].minor.yy0; yylhsminor.yy532.offset.n = 0; yylhsminor.yy532.token = yymsp[-3].minor.yy46;} yymsp[-3].minor.yy532 = yylhsminor.yy532; break; - case 202: /* interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ + case 201: /* interval_option ::= intervalKey LP tmvar COMMA tmvar RP */ {yylhsminor.yy532.interval = yymsp[-3].minor.yy0; yylhsminor.yy532.offset = yymsp[-1].minor.yy0; yylhsminor.yy532.token = yymsp[-5].minor.yy46;} yymsp[-5].minor.yy532 = yylhsminor.yy532; break; - case 203: /* interval_option ::= */ + case 202: /* interval_option ::= */ {memset(&yymsp[1].minor.yy532, 0, sizeof(yymsp[1].minor.yy532));} break; - case 204: /* intervalKey ::= INTERVAL */ + case 203: /* intervalKey ::= INTERVAL */ {yymsp[0].minor.yy46 = TK_INTERVAL;} break; - case 205: /* intervalKey ::= EVERY */ + case 204: /* intervalKey ::= EVERY */ {yymsp[0].minor.yy46 = TK_EVERY; } break; - case 206: /* session_option ::= */ + case 205: /* session_option ::= */ {yymsp[1].minor.yy97.col.n = 0; yymsp[1].minor.yy97.gap.n = 0;} break; - case 207: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + case 206: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; yymsp[-6].minor.yy97.col = yymsp[-4].minor.yy0; yymsp[-6].minor.yy97.gap = yymsp[-1].minor.yy0; } break; - case 208: /* windowstate_option ::= */ + case 207: /* windowstate_option ::= */ { yymsp[1].minor.yy6.col.n = 0; yymsp[1].minor.yy6.col.z = NULL;} break; - case 209: /* windowstate_option ::= STATE_WINDOW LP ids RP */ + case 208: /* windowstate_option ::= STATE_WINDOW LP ids RP */ { yymsp[-3].minor.yy6.col = yymsp[-1].minor.yy0; } break; - case 210: /* fill_opt ::= */ + case 209: /* fill_opt ::= */ { yymsp[1].minor.yy165 = 0; } break; - case 211: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + case 210: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ { SVariant A = {0}; toTSDBType(yymsp[-3].minor.yy0.type); @@ -2928,34 +2923,34 @@ static void yy_reduce( yymsp[-5].minor.yy165 = yymsp[-1].minor.yy165; } break; - case 212: /* fill_opt ::= FILL LP ID RP */ + case 211: /* fill_opt ::= FILL LP ID RP */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-3].minor.yy165 = tListItemAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } break; - case 213: /* sliding_opt ::= SLIDING LP tmvar RP */ + case 212: /* sliding_opt ::= SLIDING LP tmvar RP */ {yymsp[-3].minor.yy0 = yymsp[-1].minor.yy0; } break; - case 214: /* sliding_opt ::= */ + case 213: /* sliding_opt ::= */ {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; } break; - case 216: /* orderby_opt ::= ORDER BY sortlist */ + case 215: /* orderby_opt ::= ORDER BY sortlist */ {yymsp[-2].minor.yy165 = yymsp[0].minor.yy165;} break; - case 217: /* sortlist ::= sortlist COMMA item sortorder */ + case 216: /* sortlist ::= sortlist COMMA item sortorder */ { yylhsminor.yy165 = tListItemAppend(yymsp[-3].minor.yy165, &yymsp[-1].minor.yy425, yymsp[0].minor.yy47); } yymsp[-3].minor.yy165 = yylhsminor.yy165; break; - case 218: /* sortlist ::= item sortorder */ + case 217: /* sortlist ::= item sortorder */ { yylhsminor.yy165 = tListItemAppend(NULL, &yymsp[-1].minor.yy425, yymsp[0].minor.yy47); } yymsp[-1].minor.yy165 = yylhsminor.yy165; break; - case 219: /* item ::= ids cpxName */ + case 218: /* item ::= ids cpxName */ { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; @@ -2964,235 +2959,235 @@ static void yy_reduce( } yymsp[-1].minor.yy425 = yylhsminor.yy425; break; - case 220: /* sortorder ::= ASC */ + case 219: /* sortorder ::= ASC */ { yymsp[0].minor.yy47 = TSDB_ORDER_ASC; } break; - case 221: /* sortorder ::= DESC */ + case 220: /* sortorder ::= DESC */ { yymsp[0].minor.yy47 = TSDB_ORDER_DESC;} break; - case 222: /* sortorder ::= */ + case 221: /* sortorder ::= */ { yymsp[1].minor.yy47 = TSDB_ORDER_ASC; } break; - case 223: /* groupby_opt ::= */ + case 222: /* groupby_opt ::= */ { yymsp[1].minor.yy165 = 0;} break; - case 224: /* groupby_opt ::= GROUP BY grouplist */ + case 223: /* groupby_opt ::= GROUP BY grouplist */ { yymsp[-2].minor.yy165 = yymsp[0].minor.yy165;} break; - case 225: /* grouplist ::= grouplist COMMA item */ + case 224: /* grouplist ::= grouplist COMMA item */ { yylhsminor.yy165 = tListItemAppend(yymsp[-2].minor.yy165, &yymsp[0].minor.yy425, -1); } yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 226: /* grouplist ::= item */ + case 225: /* grouplist ::= item */ { yylhsminor.yy165 = tListItemAppend(NULL, &yymsp[0].minor.yy425, -1); } yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 227: /* having_opt ::= */ - case 237: /* where_opt ::= */ yytestcase(yyruleno==237); - case 281: /* expritem ::= */ yytestcase(yyruleno==281); + case 226: /* having_opt ::= */ + case 236: /* where_opt ::= */ yytestcase(yyruleno==236); + case 280: /* expritem ::= */ yytestcase(yyruleno==280); {yymsp[1].minor.yy202 = 0;} break; - case 228: /* having_opt ::= HAVING expr */ - case 238: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==238); + case 227: /* having_opt ::= HAVING expr */ + case 237: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==237); {yymsp[-1].minor.yy202 = yymsp[0].minor.yy202;} break; - case 229: /* limit_opt ::= */ - case 233: /* slimit_opt ::= */ yytestcase(yyruleno==233); + case 228: /* limit_opt ::= */ + case 232: /* slimit_opt ::= */ yytestcase(yyruleno==232); {yymsp[1].minor.yy367.limit = -1; yymsp[1].minor.yy367.offset = 0;} break; - case 230: /* limit_opt ::= LIMIT signed */ - case 234: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==234); + case 229: /* limit_opt ::= LIMIT signed */ + case 233: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==233); {yymsp[-1].minor.yy367.limit = yymsp[0].minor.yy207; yymsp[-1].minor.yy367.offset = 0;} break; - case 231: /* limit_opt ::= LIMIT signed OFFSET signed */ + case 230: /* limit_opt ::= LIMIT signed OFFSET signed */ { yymsp[-3].minor.yy367.limit = yymsp[-2].minor.yy207; yymsp[-3].minor.yy367.offset = yymsp[0].minor.yy207;} break; - case 232: /* limit_opt ::= LIMIT signed COMMA signed */ + case 231: /* limit_opt ::= LIMIT signed COMMA signed */ { yymsp[-3].minor.yy367.limit = yymsp[0].minor.yy207; yymsp[-3].minor.yy367.offset = yymsp[-2].minor.yy207;} break; - case 235: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ + case 234: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ {yymsp[-3].minor.yy367.limit = yymsp[-2].minor.yy207; yymsp[-3].minor.yy367.offset = yymsp[0].minor.yy207;} break; - case 236: /* slimit_opt ::= SLIMIT signed COMMA signed */ + case 235: /* slimit_opt ::= SLIMIT signed COMMA signed */ {yymsp[-3].minor.yy367.limit = yymsp[0].minor.yy207; yymsp[-3].minor.yy367.offset = yymsp[-2].minor.yy207;} break; - case 239: /* expr ::= LP expr RP */ + case 238: /* expr ::= LP expr RP */ {yylhsminor.yy202 = yymsp[-1].minor.yy202; yylhsminor.yy202->exprToken.z = yymsp[-2].minor.yy0.z; yylhsminor.yy202->exprToken.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 240: /* expr ::= ID */ + case 239: /* expr ::= ID */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 241: /* expr ::= ID DOT ID */ + case 240: /* expr ::= ID DOT ID */ { yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 242: /* expr ::= ID DOT STAR */ + case 241: /* expr ::= ID DOT STAR */ { yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 243: /* expr ::= INTEGER */ + case 242: /* expr ::= INTEGER */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 244: /* expr ::= MINUS INTEGER */ - case 245: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==245); + case 243: /* expr ::= MINUS INTEGER */ + case 244: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==244); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} yymsp[-1].minor.yy202 = yylhsminor.yy202; break; - case 246: /* expr ::= FLOAT */ + case 245: /* expr ::= FLOAT */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 247: /* expr ::= MINUS FLOAT */ - case 248: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==248); + case 246: /* expr ::= MINUS FLOAT */ + case 247: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==247); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} yymsp[-1].minor.yy202 = yylhsminor.yy202; break; - case 249: /* expr ::= STRING */ + case 248: /* expr ::= STRING */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 250: /* expr ::= NOW */ + case 249: /* expr ::= NOW */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 251: /* expr ::= VARIABLE */ + case 250: /* expr ::= VARIABLE */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 252: /* expr ::= PLUS VARIABLE */ - case 253: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==253); + case 251: /* expr ::= PLUS VARIABLE */ + case 252: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==252); { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} yymsp[-1].minor.yy202 = yylhsminor.yy202; break; - case 254: /* expr ::= BOOL */ + case 253: /* expr ::= BOOL */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 255: /* expr ::= NULL */ + case 254: /* expr ::= NULL */ { yylhsminor.yy202 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 256: /* expr ::= ID LP exprlist RP */ + case 255: /* expr ::= ID LP exprlist RP */ { tRecordFuncName(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy202 = tSqlExprCreateFunction(yymsp[-1].minor.yy165, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } yymsp[-3].minor.yy202 = yylhsminor.yy202; break; - case 257: /* expr ::= ID LP STAR RP */ + case 256: /* expr ::= ID LP STAR RP */ { tRecordFuncName(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy202 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } yymsp[-3].minor.yy202 = yylhsminor.yy202; break; - case 258: /* expr ::= expr IS NULL */ + case 257: /* expr ::= expr IS NULL */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, NULL, TK_ISNULL);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 259: /* expr ::= expr IS NOT NULL */ + case 258: /* expr ::= expr IS NOT NULL */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-3].minor.yy202, NULL, TK_NOTNULL);} yymsp[-3].minor.yy202 = yylhsminor.yy202; break; - case 260: /* expr ::= expr LT expr */ + case 259: /* expr ::= expr LT expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_LT);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 261: /* expr ::= expr GT expr */ + case 260: /* expr ::= expr GT expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_GT);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 262: /* expr ::= expr LE expr */ + case 261: /* expr ::= expr LE expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_LE);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 263: /* expr ::= expr GE expr */ + case 262: /* expr ::= expr GE expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_GE);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 264: /* expr ::= expr NE expr */ + case 263: /* expr ::= expr NE expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_NE);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 265: /* expr ::= expr EQ expr */ + case 264: /* expr ::= expr EQ expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_EQ);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 266: /* expr ::= expr BETWEEN expr AND expr */ + case 265: /* expr ::= expr BETWEEN expr AND expr */ { tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy202); yylhsminor.yy202 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy202, yymsp[-2].minor.yy202, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy202, TK_LE), TK_AND);} yymsp[-4].minor.yy202 = yylhsminor.yy202; break; - case 267: /* expr ::= expr AND expr */ + case 266: /* expr ::= expr AND expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_AND);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 268: /* expr ::= expr OR expr */ + case 267: /* expr ::= expr OR expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_OR); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 269: /* expr ::= expr PLUS expr */ + case 268: /* expr ::= expr PLUS expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_PLUS); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 270: /* expr ::= expr MINUS expr */ + case 269: /* expr ::= expr MINUS expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_MINUS); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 271: /* expr ::= expr STAR expr */ + case 270: /* expr ::= expr STAR expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_STAR); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 272: /* expr ::= expr SLASH expr */ + case 271: /* expr ::= expr SLASH expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_DIVIDE);} yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 273: /* expr ::= expr REM expr */ + case 272: /* expr ::= expr REM expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_REM); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 274: /* expr ::= expr LIKE expr */ + case 273: /* expr ::= expr LIKE expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_LIKE); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 275: /* expr ::= expr MATCH expr */ + case 274: /* expr ::= expr MATCH expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_MATCH); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 276: /* expr ::= expr NMATCH expr */ + case 275: /* expr ::= expr NMATCH expr */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-2].minor.yy202, yymsp[0].minor.yy202, TK_NMATCH); } yymsp[-2].minor.yy202 = yylhsminor.yy202; break; - case 277: /* expr ::= expr IN LP exprlist RP */ + case 276: /* expr ::= expr IN LP exprlist RP */ {yylhsminor.yy202 = tSqlExprCreate(yymsp[-4].minor.yy202, (tSqlExpr*)yymsp[-1].minor.yy165, TK_IN); } yymsp[-4].minor.yy202 = yylhsminor.yy202; break; - case 278: /* exprlist ::= exprlist COMMA expritem */ + case 277: /* exprlist ::= exprlist COMMA expritem */ {yylhsminor.yy165 = tSqlExprListAppend(yymsp[-2].minor.yy165,yymsp[0].minor.yy202,0, 0);} yymsp[-2].minor.yy165 = yylhsminor.yy165; break; - case 279: /* exprlist ::= expritem */ + case 278: /* exprlist ::= expritem */ {yylhsminor.yy165 = tSqlExprListAppend(0,yymsp[0].minor.yy202,0, 0);} yymsp[0].minor.yy165 = yylhsminor.yy165; break; - case 280: /* expritem ::= expr */ + case 279: /* expritem ::= expr */ {yylhsminor.yy202 = yymsp[0].minor.yy202;} yymsp[0].minor.yy202 = yylhsminor.yy202; break; - case 282: /* cmd ::= RESET QUERY CACHE */ + case 281: /* cmd ::= RESET QUERY CACHE */ { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} break; - case 283: /* cmd ::= SYNCDB ids REPLICA */ + case 282: /* cmd ::= SYNCDB ids REPLICA */ { setDCLSqlElems(pInfo, TSDB_SQL_SYNC_DB_REPLICA, 1, &yymsp[-1].minor.yy0);} break; - case 284: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + case 283: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 285: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + case 284: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; toTSDBType(yymsp[0].minor.yy0.type); @@ -3201,21 +3196,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 286: /* cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + case 285: /* cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 287: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + case 286: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 288: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + case 287: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3226,7 +3221,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 289: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + case 288: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3240,7 +3235,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 290: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + case 289: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; @@ -3252,21 +3247,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 291: /* cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + case 290: /* cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 292: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + case 291: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 293: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + case 292: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3277,21 +3272,21 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 294: /* cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + case 293: /* cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 295: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + case 294: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 296: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + case 295: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3302,7 +3297,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 297: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + case 296: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3316,7 +3311,7 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 298: /* cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + case 297: /* cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; @@ -3328,20 +3323,20 @@ static void yy_reduce( setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 299: /* cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + case 298: /* cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy165, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } break; - case 300: /* cmd ::= KILL CONNECTION INTEGER */ + case 299: /* cmd ::= KILL CONNECTION INTEGER */ {setKillSql(pInfo, TSDB_SQL_KILL_CONNECTION, &yymsp[0].minor.yy0);} break; - case 301: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ + case 300: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_STREAM, &yymsp[-2].minor.yy0);} break; - case 302: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ + case 301: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_QUERY, &yymsp[-2].minor.yy0);} break; default: diff --git a/source/libs/parser/test/insertParserTest.cpp b/source/libs/parser/test/insertParserTest.cpp index 9e681c7ccb8b8d5412892c3b41413c0f455cf69b..9b007fb36dc9674030ab7e25379cce5050d98b78 100644 --- a/source/libs/parser/test/insertParserTest.cpp +++ b/source/libs/parser/test/insertParserTest.cpp @@ -60,7 +60,7 @@ protected: return code_; } - SInsertStmtInfo* reslut() { + SVnodeModifOpStmtInfo* reslut() { return res_; } @@ -70,9 +70,7 @@ protected: for (size_t i = 0; i < num; ++i) { SVgDataBlocks* vg = (SVgDataBlocks*)taosArrayGetP(res_->pDataBlocks, i); cout << "vgId:" << vg->vg.vgId << ", numOfTables:" << vg->numOfTables << ", dataSize:" << vg->size << endl; - SMsgDesc* desc = (SMsgDesc*)(vg->pData); - cout << "numOfVnodes:" << ntohl(desc->numOfVnodes) << endl; - SSubmitMsg* submit = (SSubmitMsg*)(desc + 1); + SSubmitMsg* submit = (SSubmitMsg*)vg->pData; cout << "length:" << ntohl(submit->length) << ", numOfBlocks:" << ntohl(submit->numOfBlocks) << endl; int32_t numOfBlocks = ntohl(submit->numOfBlocks); SSubmitBlk* blk = (SSubmitBlk*)(submit + 1); @@ -95,9 +93,7 @@ protected: SVgDataBlocks* vg = (SVgDataBlocks*)taosArrayGetP(res_->pDataBlocks, i); ASSERT_EQ(vg->numOfTables, numOfTables); ASSERT_GE(vg->size, 0); - SMsgDesc* desc = (SMsgDesc*)(vg->pData); - ASSERT_EQ(ntohl(desc->numOfVnodes), 1); - SSubmitMsg* submit = (SSubmitMsg*)(desc + 1); + SSubmitMsg* submit = (SSubmitMsg*)vg->pData; ASSERT_GE(ntohl(submit->length), 0); ASSERT_GE(ntohl(submit->numOfBlocks), 0); int32_t numOfBlocks = ntohl(submit->numOfBlocks); @@ -128,7 +124,7 @@ private: char sqlBuf_[max_sql_len]; SParseContext cxt_; int32_t code_; - SInsertStmtInfo* res_; + SVnodeModifOpStmtInfo* res_; }; // INSERT INTO tb_name VALUES (field1_value, ...) diff --git a/source/libs/parser/test/mockCatalogService.cpp b/source/libs/parser/test/mockCatalogService.cpp index 3be358fec8478ffd482da55bfabe64f917c62a3c..2a0f6b38ebb733c759c64c2e9c5c519bcf4476d1 100644 --- a/source/libs/parser/test/mockCatalogService.cpp +++ b/source/libs/parser/test/mockCatalogService.cpp @@ -27,8 +27,8 @@ std::unique_ptr mockCatalogService; class TableBuilder : public ITableBuilder { public: virtual TableBuilder& addColumn(const std::string& name, int8_t type, int32_t bytes) { - assert(colId_ < schema()->tableInfo.numOfTags + schema()->tableInfo.numOfColumns); - SSchema* col = schema()->schema + colId_; + assert(colId_ <= schema()->tableInfo.numOfTags + schema()->tableInfo.numOfColumns); + SSchema* col = schema()->schema + (colId_ - 1); col->type = type; col->colId = colId_++; col->bytes = bytes; @@ -66,7 +66,7 @@ private: return std::unique_ptr(new TableBuilder(meta)); } - TableBuilder(STableMeta* schemaMeta) : colId_(0), rowsize_(0), meta_(new MockTableMeta()) { + TableBuilder(STableMeta* schemaMeta) : colId_(1), rowsize_(0), meta_(new MockTableMeta()) { meta_->schema.reset(schemaMeta); } diff --git a/source/libs/planner/inc/plannerInt.h b/source/libs/planner/inc/plannerInt.h index a68102ea6e677818e3945bb6fa46fab66e51bac1..31e057f4c0d936b4b1f2c653bc6b1f5f1d4d223a 100644 --- a/source/libs/planner/inc/plannerInt.h +++ b/source/libs/planner/inc/plannerInt.h @@ -70,6 +70,11 @@ typedef struct SQueryPlanNode { struct SQueryPlanNode *pParent; } SQueryPlanNode; +typedef struct SDataPayloadInfo { + int32_t msgType; + SArray *payload; +} SDataPayloadInfo; + /** * Optimize the query execution plan, currently not implement yet. * @param pQueryNode @@ -100,8 +105,8 @@ int32_t queryPlanToString(struct SQueryPlanNode* pQueryNode, char** str); */ int32_t queryPlanToSql(struct SQueryPlanNode* pQueryNode, char** sql); -int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag); -int32_t setSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep); +int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag, uint64_t requestId); +int32_t setSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SQueryNodeAddr* ep); int32_t subPlanToString(const SSubplan *pPhyNode, char** str, int32_t* len); int32_t stringToSubplan(const char* str, SSubplan** subplan); diff --git a/source/libs/planner/src/logicPlan.c b/source/libs/planner/src/logicPlan.c index 5f95f86d4ac853f0a3cb237fb1dda4842a66c421..fa7b3776dc894f741dfccaf42f942043a5467672 100644 --- a/source/libs/planner/src/logicPlan.c +++ b/source/libs/planner/src/logicPlan.c @@ -37,18 +37,28 @@ int32_t optimizeQueryPlan(struct SQueryPlanNode* pQueryNode) { return 0; } -static int32_t createInsertPlan(const SQueryNode* pNode, SQueryPlanNode** pQueryPlan) { - SInsertStmtInfo* pInsert = (SInsertStmtInfo*)pNode; +static int32_t createModificationOpPlan(const SQueryNode* pNode, SQueryPlanNode** pQueryPlan) { + SVnodeModifOpStmtInfo* pInsert = (SVnodeModifOpStmtInfo*)pNode; *pQueryPlan = calloc(1, sizeof(SQueryPlanNode)); SArray* blocks = taosArrayInit(taosArrayGetSize(pInsert->pDataBlocks), POINTER_BYTES); - if (NULL == *pQueryPlan || NULL == blocks) { + + SDataPayloadInfo* pPayload = calloc(1, sizeof(SDataPayloadInfo)); + if (NULL == *pQueryPlan || NULL == blocks || NULL == pPayload) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } (*pQueryPlan)->info.type = QNODE_MODIFY; taosArrayAddAll(blocks, pInsert->pDataBlocks); - (*pQueryPlan)->pExtInfo = blocks; + + if (pNode->type == TSDB_SQL_INSERT) { + pPayload->msgType = TDMT_VND_SUBMIT; + } else if (pNode->type == TSDB_SQL_CREATE_TABLE) { + pPayload->msgType = TDMT_VND_CREATE_TABLE; + } + + pPayload->payload = blocks; + (*pQueryPlan)->pExtInfo = pPayload; return TSDB_CODE_SUCCESS; } @@ -69,7 +79,7 @@ int32_t createQueryPlan(const SQueryNode* pNode, SQueryPlanNode** pQueryPlan) { case TSDB_SQL_INSERT: case TSDB_SQL_CREATE_TABLE: - return createInsertPlan(pNode, pQueryPlan); + return createModificationOpPlan(pNode, pQueryPlan); default: return TSDB_CODE_FAILED; @@ -382,6 +392,18 @@ SArray* createQueryPlanImpl(const SQueryStmtInfo* pQueryInfo) { } static void doDestroyQueryNode(SQueryPlanNode* pQueryNode) { + if (pQueryNode->info.type == QNODE_MODIFY) { + SDataPayloadInfo* pInfo = pQueryNode->pExtInfo; + + size_t size = taosArrayGetSize(pInfo->payload); + for (int32_t i = 0; i < size; ++i) { + SVgDataBlocks* pBlock = taosArrayGetP(pInfo->payload, i); + tfree(pBlock); + } + + taosArrayDestroy(pInfo->payload); + } + tfree(pQueryNode->pExtInfo); tfree(pQueryNode->pSchema); tfree(pQueryNode->info.name); diff --git a/source/libs/planner/src/physicalPlan.c b/source/libs/planner/src/physicalPlan.c index 978b1554f3713192177baf1ba233dfda51bfdf90..e7468e44eb723c7cefbbc5f34979719c243bb770 100644 --- a/source/libs/planner/src/physicalPlan.c +++ b/source/libs/planner/src/physicalPlan.c @@ -191,13 +191,15 @@ static SSubplan* initSubplan(SPlanContext* pCxt, int32_t type) { subplan->level = 0; if (NULL != pCxt->pCurrentSubplan) { subplan->level = pCxt->pCurrentSubplan->level + 1; - if (NULL == pCxt->pCurrentSubplan->pChildern) { - pCxt->pCurrentSubplan->pChildern = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); + if (NULL == pCxt->pCurrentSubplan->pChildren) { + pCxt->pCurrentSubplan->pChildren = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); } - taosArrayPush(pCxt->pCurrentSubplan->pChildern, &subplan); + + taosArrayPush(pCxt->pCurrentSubplan->pChildren, &subplan); subplan->pParents = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); taosArrayPush(subplan->pParents, &pCxt->pCurrentSubplan); } + SArray* currentLevel; if (subplan->level >= taosArrayGetSize(pCxt->pDag->pSubplans)) { currentLevel = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); @@ -205,28 +207,29 @@ static SSubplan* initSubplan(SPlanContext* pCxt, int32_t type) { } else { currentLevel = taosArrayGetP(pCxt->pDag->pSubplans, subplan->level); } + taosArrayPush(currentLevel, &subplan); pCxt->pCurrentSubplan = subplan; ++(pCxt->pDag->numOfSubplans); return subplan; } -static void vgroupInfoToEpSet(const SVgroupInfo* vg, SEpSet* epSet) { - epSet->inUse = 0; // todo - epSet->numOfEps = vg->numOfEps; +static void vgroupInfoToEpSet(const SVgroupInfo* vg, SQueryNodeAddr* execNode) { + execNode->nodeId = vg->vgId; + execNode->inUse = 0; // todo + execNode->numOfEps = vg->numOfEps; for (int8_t i = 0; i < vg->numOfEps; ++i) { - epSet->port[i] = vg->epAddr[i].port; - strcpy(epSet->fqdn[i], vg->epAddr[i].fqdn); + execNode->epAddr[i] = vg->epAddr[i]; } return; } -static void vgroupMsgToEpSet(const SVgroupMsg* vg, SEpSet* epSet) { - epSet->inUse = 0; // todo - epSet->numOfEps = vg->numOfEps; +static void vgroupMsgToEpSet(const SVgroupMsg* vg, SQueryNodeAddr* execNode) { + execNode->nodeId = vg->vgId; + execNode->inUse = 0; // todo + execNode->numOfEps = vg->numOfEps; for (int8_t i = 0; i < vg->numOfEps; ++i) { - epSet->port[i] = vg->epAddr[i].port; - strcpy(epSet->fqdn[i], vg->epAddr[i].fqdn); + execNode->epAddr[i] = vg->epAddr[i]; } return; } @@ -236,7 +239,7 @@ static uint64_t splitSubplanByTable(SPlanContext* pCxt, SQueryPlanNode* pPlanNod for (int32_t i = 0; i < pTable->pMeta->vgroupList->numOfVgroups; ++i) { STORE_CURRENT_SUBPLAN(pCxt); SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_SCAN); - vgroupMsgToEpSet(&(pTable->pMeta->vgroupList->vgroups[i]), &subplan->execEpSet); + vgroupMsgToEpSet(&(pTable->pMeta->vgroupList->vgroups[i]), &subplan->execNode); subplan->pNode = createMultiTableScanNode(pPlanNode, pTable); subplan->pDataSink = createDataDispatcher(pCxt, pPlanNode); RECOVERY_CURRENT_SUBPLAN(pCxt); @@ -278,6 +281,7 @@ static SPhyNode* createPhyNode(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { default: assert(false); } + if (pPlanNode->pChildren != NULL && taosArrayGetSize(pPlanNode->pChildren) > 0) { node->pChildren = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); size_t size = taosArrayGetSize(pPlanNode->pChildren); @@ -287,37 +291,45 @@ static SPhyNode* createPhyNode(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { taosArrayPush(node->pChildren, &child); } } + return node; } -static void splitInsertSubplan(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { - SArray* vgs = (SArray*)pPlanNode->pExtInfo; - size_t numOfVg = taosArrayGetSize(vgs); - for (int32_t i = 0; i < numOfVg; ++i) { +static void splitModificationOpSubPlan(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { + SDataPayloadInfo* pPayload = (SDataPayloadInfo*) pPlanNode->pExtInfo; + + size_t numOfVgroups = taosArrayGetSize(pPayload->payload); + for (int32_t i = 0; i < numOfVgroups; ++i) { STORE_CURRENT_SUBPLAN(pCxt); SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MODIFY); - SVgDataBlocks* blocks = (SVgDataBlocks*)taosArrayGetP(vgs, i); - vgroupInfoToEpSet(&blocks->vg, &subplan->execEpSet); - subplan->pNode = NULL; - subplan->pDataSink = createDataInserter(pCxt, blocks); - subplan->type = QUERY_TYPE_MODIFY; + SVgDataBlocks* blocks = (SVgDataBlocks*)taosArrayGetP(pPayload->payload, i); + + vgroupInfoToEpSet(&blocks->vg, &subplan->execNode); + subplan->pDataSink = createDataInserter(pCxt, blocks); + subplan->pNode = NULL; + subplan->type = QUERY_TYPE_MODIFY; + subplan->msgType = pPayload->msgType; + subplan->id.queryId = pCxt->pDag->queryId; + RECOVERY_CURRENT_SUBPLAN(pCxt); } } static void createSubplanByLevel(SPlanContext* pCxt, SQueryPlanNode* pRoot) { if (QNODE_MODIFY == pRoot->info.type) { - splitInsertSubplan(pCxt, pRoot); + splitModificationOpSubPlan(pCxt, pRoot); } else { - SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MERGE); + SSubplan* subplan = initSubplan(pCxt, QUERY_TYPE_MERGE); ++(pCxt->nextId.templateId); - subplan->pNode = createPhyNode(pCxt, pRoot); + + subplan->msgType = TDMT_VND_QUERY; + subplan->pNode = createPhyNode(pCxt, pRoot); subplan->pDataSink = createDataDispatcher(pCxt, pRoot); } // todo deal subquery } -int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag) { +int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag, uint64_t requestId) { TRY(TSDB_MAX_TAG_CONDITIONS) { SPlanContext context = { .pCatalog = pCatalog, @@ -325,7 +337,10 @@ int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryD .pCurrentSubplan = NULL, .nextId = {0} // todo queryid }; + *pDag = context.pDag; + context.pDag->queryId = requestId; + context.pDag->pSubplans = validPointer(taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES)); createSubplanByLevel(&context, pQueryNode); } CATCH(code) { @@ -336,6 +351,6 @@ int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryD return TSDB_CODE_SUCCESS; } -int32_t setSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep) { +int32_t setSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SQueryNodeAddr* ep) { //todo } diff --git a/source/libs/planner/src/physicalPlanJson.c b/source/libs/planner/src/physicalPlanJson.c index 9b2c9c1796cafb2b0b66dbbc2c0d5a19c37a8867..b25d9a3627d08222bfc8e8f8e7c39cae0a342646 100644 --- a/source/libs/planner/src/physicalPlanJson.c +++ b/source/libs/planner/src/physicalPlanJson.c @@ -793,7 +793,7 @@ static cJSON* subplanToJson(const SSubplan* subplan) { return NULL; } - // The 'type', 'level', 'execEpSet', 'pChildern' and 'pParents' fields do not need to be serialized. + // The 'type', 'level', 'execEpSet', 'pChildren' and 'pParents' fields do not need to be serialized. bool res = addObject(jSubplan, jkSubplanId, subplanIdToJson, &subplan->id); if (res) { @@ -835,7 +835,7 @@ int32_t subPlanToString(const SSubplan* subplan, char** str, int32_t* len) { SDataInserter* insert = (SDataInserter*)(subplan->pDataSink); *len = insert->size; *str = insert->pData; - insert->pData == NULL; + insert->pData = NULL; return TSDB_CODE_SUCCESS; } @@ -844,6 +844,7 @@ int32_t subPlanToString(const SSubplan* subplan, char** str, int32_t* len) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_FAILED; } + *str = cJSON_Print(json); *len = strlen(*str) + 1; return TSDB_CODE_SUCCESS; diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c index 638177140000a19f49690a6d5a831fc3e41aa433..b61c7c390f5363c75a08b051752bcb440de6b468 100644 --- a/source/libs/planner/src/planner.c +++ b/source/libs/planner/src/planner.c @@ -16,37 +16,72 @@ #include "parser.h" #include "plannerInt.h" +static void destroyDataSinkNode(SDataSink* pSinkNode) { + if (pSinkNode == NULL) { + return; + } + tfree(pSinkNode); +} + void qDestroySubplan(SSubplan* pSubplan) { - // todo + if (pSubplan == NULL) { + return; + } + + taosArrayDestroy(pSubplan->pChildren); + taosArrayDestroy(pSubplan->pParents); + destroyDataSinkNode(pSubplan->pDataSink); + // todo destroy pNode + tfree(pSubplan); } void qDestroyQueryDag(struct SQueryDag* pDag) { - // todo + if (pDag == NULL) { + return; + } + + size_t size = taosArrayGetSize(pDag->pSubplans); + for(size_t i = 0; i < size; ++i) { + SArray* pa = taosArrayGetP(pDag->pSubplans, i); + + size_t t = taosArrayGetSize(pa); + for(int32_t j = 0; j < t; ++j) { + SSubplan* pSubplan = taosArrayGetP(pa, j); + qDestroySubplan(pSubplan); + } + taosArrayDestroy(pa); + } + + taosArrayDestroy(pDag->pSubplans); + tfree(pDag); } -int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag) { +int32_t qCreateQueryDag(const struct SQueryNode* pNode, struct SQueryDag** pDag, uint64_t requestId) { SQueryPlanNode* logicPlan; int32_t code = createQueryPlan(pNode, &logicPlan); if (TSDB_CODE_SUCCESS != code) { destroyQueryPlan(logicPlan); return code; } + code = optimizeQueryPlan(logicPlan); if (TSDB_CODE_SUCCESS != code) { destroyQueryPlan(logicPlan); return code; } - code = createDag(logicPlan, NULL, pDag); + + code = createDag(logicPlan, NULL, pDag, requestId); if (TSDB_CODE_SUCCESS != code) { destroyQueryPlan(logicPlan); qDestroyQueryDag(*pDag); return code; } + destroyQueryPlan(logicPlan); return TSDB_CODE_SUCCESS; } -int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep) { +int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SQueryNodeAddr* ep) { return setSubplanExecutionNode(subplan, templateId, ep); } diff --git a/source/libs/planner/test/phyPlanTests.cpp b/source/libs/planner/test/phyPlanTests.cpp index 02d06bb49d03c2aadc8cf0fa185cffd47cfbe9f3..3f6f5ab77b5a5db8e69ed5d61033b48b75ddf267 100644 --- a/source/libs/planner/test/phyPlanTests.cpp +++ b/source/libs/planner/test/phyPlanTests.cpp @@ -33,7 +33,7 @@ protected: void pushScan(const string& db, const string& table, int32_t scanOp) { shared_ptr meta = mockCatalogService->getTableMeta(db, table); EXPECT_TRUE(meta); - unique_ptr scan((SQueryPlanNode*)calloc(1, sizeof(SQueryPlanNode))); + unique_ptr scan((SQueryPlanNode*)myCalloc(1, sizeof(SQueryPlanNode))); scan->info.type = scanOp; scan->numOfCols = meta->schema->tableInfo.numOfColumns; scan->pSchema = (SSchema*)myCalloc(1, sizeof(SSchema) * scan->numOfCols); @@ -45,7 +45,8 @@ protected: int32_t run() { SQueryDag* dag = nullptr; - int32_t code = createDag(logicPlan_.get(), nullptr, &dag); + uint64_t requestId = 20; + int32_t code = createDag(logicPlan_.get(), nullptr, &dag, requestId); dag_.reset(dag); return code; } @@ -60,7 +61,8 @@ protected: return code; } SQueryDag* dag = nullptr; - code = qCreateQueryDag(query, &dag); + uint64_t requestId = 20; + code = qCreateQueryDag(query, &dag, requestId); dag_.reset(dag); return code; } diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index b50eb2c92d4b6875d012e4146b8a85c990e2ab94..507650159f7306c7ea7325efba09c254b4299354 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -43,15 +43,12 @@ int32_t queryBuildTableMetaReqMsg(void* input, char **msg, int32_t msgSize, int3 bMsg->header.vgId = htonl(bInput->vgId); if (bInput->dbName) { - strncpy(bMsg->dbFname, bInput->dbName, sizeof(bMsg->dbFname)); - bMsg->dbFname[sizeof(bMsg->dbFname) - 1] = 0; + tstrncpy(bMsg->dbFname, bInput->dbName, tListLen(bMsg->dbFname)); } - strncpy(bMsg->tableFname, bInput->tableFullName, sizeof(bMsg->tableFname)); - bMsg->tableFname[sizeof(bMsg->tableFname) - 1] = 0; + tstrncpy(bMsg->tableFname, bInput->tableFullName, tListLen(bMsg->tableFname)); *msgLen = (int32_t)sizeof(*bMsg); - return TSDB_CODE_SUCCESS; } @@ -211,7 +208,7 @@ int32_t queryCreateTableMetaFromMsg(STableMetaMsg* msg, bool isSuperTable, STabl pTableMeta->vgId = isSuperTable ? 0 : msg->vgId; pTableMeta->tableType = isSuperTable ? TSDB_SUPER_TABLE : msg->tableType; - pTableMeta->uid = msg->suid; + pTableMeta->uid = msg->tuid; pTableMeta->suid = msg->suid; pTableMeta->sversion = msg->sversion; pTableMeta->tversion = msg->tversion; @@ -250,8 +247,8 @@ int32_t queryProcessTableMetaRsp(void* output, char *msg, int32_t msgSize) { pOut->metaNum = 2; if (pMetaMsg->dbFname[0]) { - snprintf(pOut->ctbFname, "%s.%s", pMetaMsg->dbFname, pMetaMsg->tbFname); - snprintf(pOut->tbFname, "%s.%s", pMetaMsg->dbFname, pMetaMsg->stbFname); + snprintf(pOut->ctbFname, sizeof(pOut->ctbFname), "%s.%s", pMetaMsg->dbFname, pMetaMsg->tbFname); + snprintf(pOut->tbFname, sizeof(pOut->tbFname), "%s.%s", pMetaMsg->dbFname, pMetaMsg->stbFname); } else { memcpy(pOut->ctbFname, pMetaMsg->tbFname, sizeof(pOut->ctbFname)); memcpy(pOut->tbFname, pMetaMsg->stbFname, sizeof(pOut->tbFname)); @@ -272,7 +269,7 @@ int32_t queryProcessTableMetaRsp(void* output, char *msg, int32_t msgSize) { memcpy(pOut->tbFname, pMetaMsg->tbFname, sizeof(pOut->tbFname)); } - code = queryCreateTableMetaFromMsg(pMetaMsg, false, &pOut->tbMeta); + code = queryCreateTableMetaFromMsg(pMetaMsg, (pMetaMsg->tableType == TSDB_SUPER_TABLE), &pOut->tbMeta); } return code; diff --git a/source/libs/scheduler/inc/schedulerInt.h b/source/libs/scheduler/inc/schedulerInt.h index 2770f7e21a4dce62a7461eede23cc3e3f60332cf..1d5d0599e60eb75d8a9314176aec14c6d35da7a5 100644 --- a/source/libs/scheduler/inc/schedulerInt.h +++ b/source/libs/scheduler/inc/schedulerInt.h @@ -60,17 +60,19 @@ typedef struct SSchLevel { typedef struct SSchTask { - uint64_t taskId; // task id - SSchLevel *level; // level - SSubplan *plan; // subplan - char *msg; // operator tree - int32_t msgLen; // msg length - int8_t status; // task status - SEpAddr execAddr; // task actual executed node address - SQueryProfileSummary summary; // task execution summary - int32_t childReady; // child task ready number - SArray *children; // the datasource tasks,from which to fetch the result, element is SQueryTask* - SArray *parents; // the data destination tasks, get data from current task, element is SQueryTask* + uint64_t taskId; // task id + SSchLevel *level; // level + SSubplan *plan; // subplan + char *msg; // operator tree + int32_t msgLen; // msg length + int8_t status; // task status + SQueryNodeAddr execAddr; // task actual executed node address + int8_t condidateIdx; // current try condidation index + SArray *condidateAddrs; // condidate node addresses, element is SQueryNodeAddr + SQueryProfileSummary summary; // task execution summary + int32_t childReady; // child task ready number + SArray *children; // the datasource tasks,from which to fetch the result, element is SQueryTask* + SArray *parents; // the data destination tasks, get data from current task, element is SQueryTask* } SSchTask; typedef struct SSchJobAttr { @@ -112,8 +114,9 @@ typedef struct SSchJob { #define SCH_IS_DATA_SRC_TASK(task) ((task)->plan->type == QUERY_TYPE_SCAN) #define SCH_TASK_NEED_WAIT_ALL(task) ((task)->plan->type == QUERY_TYPE_MODIFY) -#define SCH_JOB_ERR_LOG(param, ...) qError("QID:%"PRIx64 param, job->queryId, __VA_ARGS__) -#define SCH_TASK_ERR_LOG(param, ...) qError("QID:%"PRIx64",TID:%"PRIx64 param, job->queryId, task->taskId, __VA_ARGS__) +#define SCH_JOB_ELOG(param, ...) qError("QID:% "PRIx64 param, job->queryId, __VA_ARGS__) +#define SCH_TASK_ELOG(param, ...) qError("QID:%"PRIx64",TID:% "PRIx64 param, job->queryId, task->taskId, __VA_ARGS__) +#define SCH_TASK_DLOG(param, ...) qDebug("QID:%"PRIx64",TID:% "PRIx64 param, job->queryId, task->taskId, __VA_ARGS__) #define SCH_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) #define SCH_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 20eb94c2ff65333fda5834a77359188b9ee2cb2f..075be706ea5aed08d25e15f02b83a802983467be 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -28,7 +28,7 @@ int32_t schBuildTaskRalation(SSchJob *job, SHashObj *planToTask) { for (int32_t m = 0; m < level->taskNum; ++m) { SSchTask *task = taosArrayGet(level->subTasks, m); SSubplan *plan = task->plan; - int32_t childNum = plan->pChildern ? (int32_t)taosArrayGetSize(plan->pChildern) : 0; + int32_t childNum = plan->pChildren ? (int32_t)taosArrayGetSize(plan->pChildren) : 0; int32_t parentNum = plan->pParents ? (int32_t)taosArrayGetSize(plan->pParents) : 0; if (childNum > 0) { @@ -40,7 +40,7 @@ int32_t schBuildTaskRalation(SSchJob *job, SHashObj *planToTask) { } for (int32_t n = 0; n < childNum; ++n) { - SSubplan **child = taosArrayGet(plan->pChildern, n); + SSubplan **child = taosArrayGet(plan->pChildren, n); SSchTask **childTask = taosHashGet(planToTask, child, POINTER_BYTES); if (NULL == childTask || NULL == *childTask) { qError("subplan relationship error, level:%d, taskIdx:%d, childIdx:%d", i, m, n); @@ -122,6 +122,7 @@ int32_t schValidateAndBuildJob(SQueryDag *dag, SSchJob *job) { SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + //?? job->attr.needFetch = true; job->levelNum = levelNum; @@ -215,28 +216,49 @@ _return: SCH_RET(code); } -int32_t schSetTaskExecEpSet(SSchJob *job, SEpSet *epSet) { - if (epSet->numOfEps >= SCH_MAX_CONDIDATE_EP_NUM) { +int32_t schSetTaskCondidateAddrs(SSchJob *job, SSchTask *task) { + if (task->condidateAddrs) { return TSDB_CODE_SUCCESS; } + task->condidateIdx = 0; + task->condidateAddrs = taosArrayInit(SCH_MAX_CONDIDATE_EP_NUM, sizeof(SQueryNodeAddr)); + if (NULL == task->condidateAddrs) { + qError("taosArrayInit failed"); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + if (task->plan->execNode.numOfEps > 0) { + if (NULL == taosArrayPush(task->condidateAddrs, &task->plan->execNode)) { + qError("taosArrayPush failed"); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + return TSDB_CODE_SUCCESS; + } + + int32_t addNum = 0; int32_t nodeNum = taosArrayGetSize(job->nodeList); - for (int32_t i = 0; i < nodeNum && epSet->numOfEps < tListLen(epSet->port); ++i) { - SEpAddr *addr = taosArrayGet(job->nodeList, i); + for (int32_t i = 0; i < nodeNum && addNum < SCH_MAX_CONDIDATE_EP_NUM; ++i) { + SQueryNodeAddr *naddr = taosArrayGet(job->nodeList, i); - strncpy(epSet->fqdn[epSet->numOfEps], addr->fqdn, sizeof(addr->fqdn)); - epSet->port[epSet->numOfEps] = addr->port; + if (NULL == taosArrayPush(task->condidateAddrs, &task->plan->execNode)) { + qError("taosArrayPush failed"); + SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } - ++epSet->numOfEps; + ++addNum; } - for (int32_t i = 0; i < job->dataSrcEps.numOfEps && epSet->numOfEps < tListLen(epSet->port); ++i) { +/* + for (int32_t i = 0; i < job->dataSrcEps.numOfEps && addNum < SCH_MAX_CONDIDATE_EP_NUM; ++i) { strncpy(epSet->fqdn[epSet->numOfEps], job->dataSrcEps.fqdn[i], sizeof(job->dataSrcEps.fqdn[i])); epSet->port[epSet->numOfEps] = job->dataSrcEps.port[i]; ++epSet->numOfEps; } +*/ return TSDB_CODE_SUCCESS; } @@ -248,6 +270,8 @@ int32_t schPushTaskToExecList(SSchJob *job, SSchTask *task) { SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + SCH_TASK_DLOG("push to %s list", "execTasks"); + return TSDB_CODE_SUCCESS; } @@ -262,6 +286,8 @@ int32_t schMoveTaskToSuccList(SSchJob *job, SSchTask *task, bool *moved) { SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + SCH_TASK_DLOG("push to %s list", "succTasks"); + *moved = true; return TSDB_CODE_SUCCESS; @@ -277,6 +303,8 @@ int32_t schMoveTaskToFailList(SSchJob *job, SSchTask *task, bool *moved) { SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + SCH_TASK_DLOG("push to %s list", "failTasks"); + *moved = true; return TSDB_CODE_SUCCESS; @@ -350,7 +378,7 @@ int32_t schProcessOnTaskSuccess(SSchJob *job, SSchTask *task) { SCH_ERR_RET(schMoveTaskToSuccList(job, task, &moved)); if (!moved) { - SCH_TASK_ERR_LOG("task may already moved, status:%d", task->status); + SCH_TASK_ELOG("task may already moved, status:%d", task->status); return TSDB_CODE_SUCCESS; } @@ -383,8 +411,8 @@ int32_t schProcessOnTaskSuccess(SSchJob *job, SSchTask *task) { return TSDB_CODE_SUCCESS; } } else { - strncpy(job->resEp.fqdn, task->execAddr.fqdn, sizeof(job->resEp.fqdn)); - job->resEp.port = task->execAddr.port; + strncpy(job->resEp.fqdn, task->execAddr.epAddr[task->execAddr.inUse].fqdn, sizeof(job->resEp.fqdn)); + job->resEp.port = task->execAddr.epAddr[task->execAddr.inUse].port; } job->fetchTask = task; @@ -394,12 +422,14 @@ int32_t schProcessOnTaskSuccess(SSchJob *job, SSchTask *task) { return TSDB_CODE_SUCCESS; } +/* if (SCH_IS_DATA_SRC_TASK(task) && job->dataSrcEps.numOfEps < SCH_MAX_CONDIDATE_EP_NUM) { strncpy(job->dataSrcEps.fqdn[job->dataSrcEps.numOfEps], task->execAddr.fqdn, sizeof(task->execAddr.fqdn)); job->dataSrcEps.port[job->dataSrcEps.numOfEps] = task->execAddr.port; ++job->dataSrcEps.numOfEps; } +*/ for (int32_t i = 0; i < parentNum; ++i) { SSchTask *par = *(SSchTask **)taosArrayGet(task->parents, i); @@ -423,11 +453,11 @@ int32_t schProcessOnTaskFailure(SSchJob *job, SSchTask *task, int32_t errCode) { SCH_ERR_RET(schTaskCheckAndSetRetry(job, task, errCode, &needRetry)); if (!needRetry) { - SCH_TASK_ERR_LOG("task failed[%x], no more retry", errCode); + SCH_TASK_ELOG("task failed[%x], no more retry", errCode); SCH_ERR_RET(schMoveTaskToFailList(job, task, &moved)); if (!moved) { - SCH_TASK_ERR_LOG("task may already moved, status:%d", task->status); + SCH_TASK_ELOG("task may already moved, status:%d", task->status); } if (SCH_TASK_NEED_WAIT_ALL(task)) { @@ -455,15 +485,27 @@ int32_t schProcessOnTaskFailure(SSchJob *job, SSchTask *task, int32_t errCode) { int32_t schProcessRspMsg(SSchJob *job, SSchTask *task, int32_t msgType, char *msg, int32_t msgSize, int32_t rspCode) { int32_t code = 0; - + switch (msgType) { + case TDMT_VND_CREATE_TABLE_RSP: { + if (rspCode != TSDB_CODE_SUCCESS) { + SCH_ERR_JRET(schProcessOnTaskFailure(job, task, rspCode)); + } else { +// job->resNumOfRows += rsp->affectedRows; + code = schProcessOnTaskSuccess(job, task); + if (code) { + goto _task_error; + } + } + break; + } case TDMT_VND_SUBMIT_RSP: { - SShellSubmitRspMsg *rsp = (SShellSubmitRspMsg *)msg; - if (rsp->code != TSDB_CODE_SUCCESS) { - SCH_ERR_JRET(schProcessOnTaskFailure(job, task, rsp->code)); + if (rspCode != TSDB_CODE_SUCCESS) { + SCH_ERR_JRET(schProcessOnTaskFailure(job, task, rspCode)); } else { + SShellSubmitRspMsg *rsp = (SShellSubmitRspMsg *)msg; job->resNumOfRows += rsp->affectedRows; - + code = schProcessOnTaskSuccess(job, task); if (code) { goto _task_error; @@ -531,38 +573,51 @@ int32_t schHandleCallback(void* param, const SDataBuf* pMsg, int32_t msgType, in int32_t code = 0; SSchCallbackParam *pParam = (SSchCallbackParam *)param; - SSchJob **job = taosHashGet(schMgmt.jobs, &pParam->queryId, sizeof(pParam->queryId)); - if (NULL == job || NULL == (*job)) { + SSchJob **pjob = taosHashGet(schMgmt.jobs, &pParam->queryId, sizeof(pParam->queryId)); + if (NULL == pjob || NULL == (*pjob)) { qError("taosHashGet queryId:%"PRIx64" not exist", pParam->queryId); SCH_ERR_JRET(TSDB_CODE_SCH_INTERNAL_ERROR); } - SSchTask **task = taosHashGet((*job)->execTasks, &pParam->taskId, sizeof(pParam->taskId)); - if (NULL == task || NULL == (*task)) { + SSchJob *job = *pjob; + + SSchTask **ptask = taosHashGet(job->execTasks, &pParam->taskId, sizeof(pParam->taskId)); + if (NULL == ptask || NULL == (*ptask)) { qError("taosHashGet taskId:%"PRIx64" not exist", pParam->taskId); SCH_ERR_JRET(TSDB_CODE_SCH_INTERNAL_ERROR); } + + SSchTask *task = *ptask; + + SCH_TASK_DLOG("Got msg:%d, rspCode:%d", msgType, rspCode); - schProcessRspMsg(*job, *task, msgType, pMsg->pData, pMsg->len, rspCode); + schProcessRspMsg(job, task, msgType, pMsg->pData, pMsg->len, rspCode); _return: tfree(param); - SCH_RET(code); } int32_t schHandleSubmitCallback(void* param, const SDataBuf* pMsg, int32_t code) { return schHandleCallback(param, pMsg, TDMT_VND_SUBMIT_RSP, code); } + +int32_t schHandleCreateTableCallback(void* param, const SDataBuf* pMsg, int32_t code) { + return schHandleCallback(param, pMsg, TDMT_VND_CREATE_TABLE_RSP, code); +} + int32_t schHandleQueryCallback(void* param, const SDataBuf* pMsg, int32_t code) { return schHandleCallback(param, pMsg, TDMT_VND_QUERY_RSP, code); } + int32_t schHandleFetchCallback(void* param, const SDataBuf* pMsg, int32_t code) { return schHandleCallback(param, pMsg, TDMT_VND_FETCH_RSP, code); } + int32_t schHandleReadyCallback(void* param, const SDataBuf* pMsg, int32_t code) { return schHandleCallback(param, pMsg, TDMT_VND_RES_READY_RSP, code); } + int32_t schHandleDropCallback(void* param, const SDataBuf* pMsg, int32_t code) { SSchCallbackParam *pParam = (SSchCallbackParam *)param; qDebug("drop task rsp received, queryId:%"PRIx64 ",taksId:%"PRIx64 ",code:%d", pParam->queryId, pParam->taskId, code); @@ -570,6 +625,9 @@ int32_t schHandleDropCallback(void* param, const SDataBuf* pMsg, int32_t code) { int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp) { switch (msgType) { + case TDMT_VND_CREATE_TABLE: + *fp = schHandleCreateTableCallback; + break; case TDMT_VND_SUBMIT: *fp = schHandleSubmitCallback; break; @@ -633,6 +691,16 @@ _return: SCH_RET(code); } +void schConvertAddrToEpSet(SQueryNodeAddr *addr, SEpSet *epSet) { + epSet->inUse = addr->inUse; + epSet->numOfEps = addr->numOfEps; + + for (int8_t i = 0; i < epSet->numOfEps; ++i) { + strncpy(epSet->fqdn[i], addr->epAddr[i].fqdn, sizeof(addr->epAddr[i].fqdn)); + epSet->port[i] = addr->epAddr[i].port; + } +} + int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { uint32_t msgSize = 0; @@ -640,6 +708,7 @@ int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { int32_t code = 0; switch (msgType) { + case TDMT_VND_CREATE_TABLE: case TDMT_VND_SUBMIT: { if (NULL == task->msg || task->msgLen <= 0) { qError("submit msg is NULL"); @@ -665,6 +734,7 @@ int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { SSubQueryMsg *pMsg = msg; + pMsg->header.vgId = htonl(task->plan->execNode.nodeId); pMsg->sId = htobe64(schMgmt.sId); pMsg->queryId = htobe64(job->queryId); pMsg->taskId = htobe64(task->taskId); @@ -681,6 +751,8 @@ int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { } SResReadyMsg *pMsg = msg; + + pMsg->header.vgId = htonl(task->plan->execNode.nodeId); pMsg->sId = htobe64(schMgmt.sId); pMsg->queryId = htobe64(job->queryId); pMsg->taskId = htobe64(task->taskId); @@ -698,6 +770,8 @@ int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { } SResFetchMsg *pMsg = msg; + + pMsg->header.vgId = htonl(task->plan->execNode.nodeId); pMsg->sId = htobe64(schMgmt.sId); pMsg->queryId = htobe64(job->queryId); pMsg->taskId = htobe64(task->taskId); @@ -712,6 +786,8 @@ int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { } STaskDropMsg *pMsg = msg; + + pMsg->header.vgId = htonl(task->plan->execNode.nodeId); pMsg->sId = htobe64(schMgmt.sId); pMsg->queryId = htobe64(job->queryId); pMsg->taskId = htobe64(task->taskId); @@ -723,7 +799,12 @@ int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType) { break; } - SCH_ERR_JRET(schAsyncSendMsg(job->transport, &task->plan->execEpSet, job->queryId, task->taskId, msgType, msg, msgSize)); + SEpSet epSet; + SQueryNodeAddr *addr = taosArrayGet(task->condidateAddrs, task->condidateIdx); + + schConvertAddrToEpSet(addr, &epSet); + + SCH_ERR_JRET(schAsyncSendMsg(job->transport, &epSet, job->queryId, task->taskId, msgType, msg, msgSize)); return TSDB_CODE_SUCCESS; @@ -737,28 +818,22 @@ _return: int32_t schLaunchTask(SSchJob *job, SSchTask *task) { SSubplan *plan = task->plan; SCH_ERR_RET(qSubPlanToString(plan, &task->msg, &task->msgLen)); - if (plan->execEpSet.numOfEps <= 0) { - SCH_ERR_RET(schSetTaskExecEpSet(job, &plan->execEpSet)); - } + SCH_ERR_RET(schSetTaskCondidateAddrs(job, task)); - if (plan->execEpSet.numOfEps <= 0) { - SCH_TASK_ERR_LOG("invalid execEpSet num:%d", plan->execEpSet.numOfEps); + if (NULL == task->condidateAddrs || taosArrayGetSize(task->condidateAddrs) <= 0) { + SCH_TASK_ELOG("no valid condidate node for task:%"PRIx64, task->taskId); SCH_ERR_RET(TSDB_CODE_SCH_INTERNAL_ERROR); } - int32_t msgType = (plan->type == QUERY_TYPE_MODIFY) ? TDMT_VND_SUBMIT : TDMT_VND_QUERY; +// int32_t msgType = (plan->type == QUERY_TYPE_MODIFY)? TDMT_VND_SUBMIT : TDMT_VND_QUERY; - SCH_ERR_RET(schBuildAndSendMsg(job, task, msgType)); - + SCH_ERR_RET(schBuildAndSendMsg(job, task, plan->msgType)); SCH_ERR_RET(schPushTaskToExecList(job, task)); task->status = JOB_TASK_STATUS_EXECUTING; - return TSDB_CODE_SUCCESS; } - - int32_t schLaunchJob(SSchJob *job) { SSchLevel *level = taosArrayGet(job->levels, job->levelIdx); for (int32_t i = 0; i < level->taskNum; ++i) { diff --git a/source/libs/scheduler/test/schedulerTests.cpp b/source/libs/scheduler/test/schedulerTests.cpp index b418ade1725cf97765aea2da961dcb061081e0c5..790778b7368e6d2fcfeeb818acd498a6d28ff263 100644 --- a/source/libs/scheduler/test/schedulerTests.cpp +++ b/source/libs/scheduler/test/schedulerTests.cpp @@ -54,11 +54,13 @@ void schtBuildQueryDag(SQueryDag *dag) { scanPlan.id.templateId = 0x0000000000000002; scanPlan.id.subplanId = 0x0000000000000003; scanPlan.type = QUERY_TYPE_SCAN; + scanPlan.execNode.numOfEps = 1; + scanPlan.execNode.nodeId = 1; + scanPlan.execNode.inUse = 0; + scanPlan.execNode.epAddr[0].port = 6030; + strcpy(scanPlan.execNode.epAddr[0].fqdn, "ep0"); + scanPlan.pChildren = NULL; scanPlan.level = 1; - scanPlan.execEpSet.numOfEps = 1; - scanPlan.execEpSet.port[0] = 6030; - strcpy(scanPlan.execEpSet.fqdn[0], "ep0"); - scanPlan.pChildern = NULL; scanPlan.pParents = taosArrayInit(1, POINTER_BYTES); scanPlan.pNode = (SPhyNode*)calloc(1, sizeof(SPhyNode)); @@ -67,15 +69,15 @@ void schtBuildQueryDag(SQueryDag *dag) { mergePlan.id.subplanId = 0x5555555555; mergePlan.type = QUERY_TYPE_MERGE; mergePlan.level = 0; - mergePlan.execEpSet.numOfEps = 0; - mergePlan.pChildern = taosArrayInit(1, POINTER_BYTES); + mergePlan.execNode.numOfEps = 0; + mergePlan.pChildren = taosArrayInit(1, POINTER_BYTES); mergePlan.pParents = NULL; mergePlan.pNode = (SPhyNode*)calloc(1, sizeof(SPhyNode)); SSubplan *mergePointer = (SSubplan *)taosArrayPush(merge, &mergePlan); SSubplan *scanPointer = (SSubplan *)taosArrayPush(scan, &scanPlan); - taosArrayPush(mergePointer->pChildern, &scanPointer); + taosArrayPush(mergePointer->pChildren, &scanPointer); taosArrayPush(scanPointer->pParents, &mergePointer); taosArrayPush(dag->pSubplans, &merge); @@ -97,10 +99,12 @@ void schtBuildInsertDag(SQueryDag *dag) { insertPlan[0].id.subplanId = 0x0000000000000004; insertPlan[0].type = QUERY_TYPE_MODIFY; insertPlan[0].level = 0; - insertPlan[0].execEpSet.numOfEps = 1; - insertPlan[0].execEpSet.port[0] = 6030; - strcpy(insertPlan[0].execEpSet.fqdn[0], "ep0"); - insertPlan[0].pChildern = NULL; + insertPlan[0].execNode.numOfEps = 1; + insertPlan[0].execNode.nodeId = 1; + insertPlan[0].execNode.inUse = 0; + insertPlan[0].execNode.epAddr[0].port = 6030; + strcpy(insertPlan[0].execNode.epAddr[0].fqdn, "ep0"); + insertPlan[0].pChildren = NULL; insertPlan[0].pParents = NULL; insertPlan[0].pNode = NULL; insertPlan[0].pDataSink = (SDataSink*)calloc(1, sizeof(SDataSink)); @@ -110,10 +114,12 @@ void schtBuildInsertDag(SQueryDag *dag) { insertPlan[1].id.subplanId = 0x0000000000000005; insertPlan[1].type = QUERY_TYPE_MODIFY; insertPlan[1].level = 0; - insertPlan[1].execEpSet.numOfEps = 1; - insertPlan[1].execEpSet.port[0] = 6030; - strcpy(insertPlan[1].execEpSet.fqdn[0], "ep1"); - insertPlan[1].pChildern = NULL; + insertPlan[1].execNode.numOfEps = 1; + insertPlan[1].execNode.nodeId = 1; + insertPlan[1].execNode.inUse = 1; + insertPlan[1].execNode.epAddr[0].port = 6030; + strcpy(insertPlan[1].execNode.epAddr[0].fqdn, "ep1"); + insertPlan[1].pChildren = NULL; insertPlan[1].pParents = NULL; insertPlan[1].pNode = NULL; insertPlan[1].pDataSink = (SDataSink*)calloc(1, sizeof(SDataSink)); @@ -132,7 +138,7 @@ int32_t schtPlanToString(const SSubplan *subplan, char** str, int32_t* len) { return 0; } -int32_t schtExecNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep) { +int32_t schtExecNode(SSubplan* subplan, uint64_t templateId, SQueryNodeAddr* ep) { return 0; } diff --git a/source/libs/transport/src/rpcMain.c b/source/libs/transport/src/rpcMain.c index 19fe803035ee654a9841b0ba0bb442f614736304..d58ea63c4fe44d000a14fd0d9fe9f9e16945ff37 100644 --- a/source/libs/transport/src/rpcMain.c +++ b/source/libs/transport/src/rpcMain.c @@ -423,6 +423,8 @@ void rpcSendRequest(void *shandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t } void rpcSendResponse(const SRpcMsg *pRsp) { + if (pRsp->handle == NULL) return; + int msgLen = 0; SRpcConn *pConn = (SRpcConn *)pRsp->handle; SRpcMsg rpcMsg = *pRsp; @@ -700,7 +702,7 @@ static SRpcConn *rpcAllocateClientConn(SRpcInfo *pRpc) { pConn->sid = sid; pConn->tranId = (uint16_t)(taosRand() & 0xFFFF); pConn->ownId = htonl(pConn->sid); - pConn->linkUid = (uint32_t)((int64_t)pConn + taosGetPid() + (int64_t)pConn->tranId); + pConn->linkUid = (uint32_t)((int64_t)pConn + taosGetPId() + (int64_t)pConn->tranId); pConn->spi = pRpc->spi; pConn->encrypt = pRpc->encrypt; if (pConn->spi) memcpy(pConn->secret, pRpc->secret, TSDB_PASSWORD_LEN); @@ -1094,13 +1096,16 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) { SRpcReqContext *pContext; pConn = rpcProcessMsgHead(pRpc, pRecv, &pContext); + char ipstr[24] = {0}; + taosIpPort2String(pRecv->ip, pRecv->port, ipstr); + if (TMSG_INDEX(pHead->msgType) >= 1 && TMSG_INDEX(pHead->msgType) < TDMT_MAX) { - tDebug("%s %p %p, %s received from 0x%x:%hu, parse code:0x%x len:%d sig:0x%08x:0x%08x:%d code:0x%x", pRpc->label, - pConn, (void *)pHead->ahandle, TMSG_INFO(pHead->msgType), pRecv->ip, pRecv->port, terrno, pRecv->msgLen, + tDebug("%s %p %p, %s received from %s, parse code:0x%x len:%d sig:0x%08x:0x%08x:%d code:0x%x", pRpc->label, + pConn, (void *)pHead->ahandle, TMSG_INFO(pHead->msgType), ipstr, terrno, pRecv->msgLen, pHead->sourceId, pHead->destId, pHead->tranId, pHead->code); } else { - tDebug("%s %p %p, %d received from 0x%x:%hu, parse code:0x%x len:%d sig:0x%08x:0x%08x:%d code:0x%x", pRpc->label, - pConn, (void *)pHead->ahandle, pHead->msgType, pRecv->ip, pRecv->port, terrno, pRecv->msgLen, + tDebug("%s %p %p, %d received from %s, parse code:0x%x len:%d sig:0x%08x:0x%08x:%d code:0x%x", pRpc->label, + pConn, (void *)pHead->ahandle, pHead->msgType, ipstr, terrno, pRecv->msgLen, pHead->sourceId, pHead->destId, pHead->tranId, pHead->code); } @@ -1195,7 +1200,7 @@ static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead, SRpcReqConte } rpcSendReqToServer(pRpc, pContext); rpcFreeCont(rpcMsg.pCont); - } else if (pHead->code == TSDB_CODE_RPC_NOT_READY || pHead->code == TSDB_CODE_APP_NOT_READY || pHead->code == TSDB_CODE_DND_EXITING) { + } else if (pHead->code == TSDB_CODE_RPC_NOT_READY || pHead->code == TSDB_CODE_APP_NOT_READY || pHead->code == TSDB_CODE_DND_OFFLINE) { pContext->code = pHead->code; rpcProcessConnError(pContext, NULL); rpcFreeCont(rpcMsg.pCont); diff --git a/source/libs/wal/inc/walInt.h b/source/libs/wal/inc/walInt.h index 1579cad7b62b7d227f10d0ddccb7cfe573e3ddd3..871c95193fdef3cf3d7da1820e8a8b3633948efb 100644 --- a/source/libs/wal/inc/walInt.h +++ b/source/libs/wal/inc/walInt.h @@ -20,6 +20,8 @@ #include "tchecksum.h" #include "wal.h" +#include "taoserror.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index 67c8694fd62bdf0f223ac2392fffc5f331421be1..96d0c6c385d30ca5121354283da88851a8404640 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -20,8 +20,10 @@ SWalReadHandle *walOpenReadHandle(SWal *pWal) { SWalReadHandle *pRead = malloc(sizeof(SWalReadHandle)); if (pRead == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } + pRead->pWal = pWal; pRead->readIdxTfd = -1; pRead->readLogTfd = -1; diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index 5e26dd8278a3c4563e5c721642b5368aded329db..39bf06ceddb6acdf641f001e6cb2442248fc084a 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -150,7 +150,7 @@ int32_t walBeginSnapshot(SWal *pWal, int64_t ver) { int32_t walEndSnapshot(SWal *pWal) { int64_t ver = pWal->vers.verInSnapshotting; - if (ver == -1) return -1; + if (ver == -1) return 0; pWal->vers.snapshotVer = ver; int ts = taosGetTimestampSec(); diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index cb231e15a0b665438b7a343214838ff69ee950fd..e235b0714e181814e66b709f833ffaf7c5c98d9c 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -252,7 +252,7 @@ LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) { void taosSetCoreDump() { SetUnhandledExceptionFilter(&FlCrashDump); } -int32_t taosGetSystemUid(char *uid, int32_t uidlen) { +int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { GUID guid; CoCreateGuid(&guid); @@ -452,7 +452,7 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { } } -int32_t taosGetSystemUid(char *uid, int32_t uidlen) { +int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { uuid_t uuid = {0}; uuid_generate(uuid); // it's caller's responsibility to make enough space for `uid`, that's 36-char + 1-null @@ -1070,7 +1070,7 @@ void taosSetCoreDump(bool enable) { #endif } -int32_t taosGetSystemUid(char *uid, int32_t uidlen) { +int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { int fd; int len = 0; @@ -1130,8 +1130,4 @@ SysNameInfo taosGetSysNameInfo() { return info; } -int64_t taosGetPid() { - getpid(); -} - #endif \ No newline at end of file diff --git a/source/util/src/encode.c b/source/util/src/encode.c index 40c03ea05196b2dcf4760b01467a0de85c0d617f..758d3f442db0007ea60317827d582d50f60f8d75 100644 --- a/source/util/src/encode.c +++ b/source/util/src/encode.c @@ -88,13 +88,9 @@ void tEndEncode(SCoder* pCoder) { pCoder->size = pNode->size; pCoder->pos = pNode->pos; - if (TD_RT_ENDIAN() == pCoder->endian) { - tPut(int32_t, pCoder->data + pCoder->pos, len); - } else { - tRPut32(pCoder->data + pCoder->pos, len); - } + tEncodeI32(pCoder, len); - TD_CODER_MOVE_POS(pCoder, len + sizeof(int32_t)); + TD_CODER_MOVE_POS(pCoder, len); free(pNode); } @@ -127,15 +123,14 @@ void tEndDecode(SCoder* pCoder) { struct SCoderNode* pNode; ASSERT(pCoder->type == TD_DECODER); - ASSERT(tDecodeIsEnd(pCoder)); pNode = TD_SLIST_HEAD(&(pCoder->stack)); ASSERT(pNode); TD_SLIST_POP(&(pCoder->stack)); pCoder->data = pNode->data; + pCoder->pos = pCoder->size + pNode->pos; pCoder->size = pNode->size; - pCoder->pos = pCoder->pos + pNode->pos; free(pNode); } diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 9fa5b3198bc80f19d6e0038d82754d1df88a03be..0bf56dbaaf7a18f179c8167b36e9dca53e66ef10 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -170,6 +170,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_STATUS_TYPE, "Invalid status type") TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_DATA_VER, "Invalid raw data version") TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_DATA_LEN, "Invalid raw data len") TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_DATA_CONTENT, "Invalid raw data content") +TAOS_DEFINE_ERROR(TSDB_CODE_SDB_INVALID_WAl_VER, "Invalid wal version") // mnode-dnode TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_ALREADY_EXIST, "Dnode already exists") @@ -252,7 +253,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TRANS_NOT_EXIST, "Transaction not exis // dnode TAOS_DEFINE_ERROR(TSDB_CODE_DND_ACTION_IN_PROGRESS, "Action in progress") -TAOS_DEFINE_ERROR(TSDB_CODE_DND_EXITING, "Dnode is exiting") +TAOS_DEFINE_ERROR(TSDB_CODE_DND_OFFLINE, "Dnode is offline") TAOS_DEFINE_ERROR(TSDB_CODE_DND_INVALID_MSG_LEN, "Invalid message length") TAOS_DEFINE_ERROR(TSDB_CODE_DND_DNODE_READ_FILE_ERROR, "Read dnode.json error") TAOS_DEFINE_ERROR(TSDB_CODE_DND_DNODE_WRITE_FILE_ERROR, "Write dnode.json error") diff --git a/source/util/src/tfile.c b/source/util/src/tfile.c index 4cb20802c78176b8cd6791f463ed8abeda3df7d7..0f68e9204d34557bf792e324dc69b73e9b759287 100644 --- a/source/util/src/tfile.c +++ b/source/util/src/tfile.c @@ -158,3 +158,13 @@ int32_t tfFtruncate(int64_t tfd, int64_t length) { taosReleaseRef(tsFileRsetId, tfd); return code; } + +void *tfMmapReadOnly(int64_t tfd, int64_t length) { + void *p = taosAcquireRef(tsFileRsetId, tfd); + if (p == NULL) return NULL; + int32_t fd = (int32_t)(uintptr_t)p; + + void *ptr = mmap(NULL, length, PROT_READ, MAP_SHARED, fd, 0); + taosReleaseRef(tsFileRsetId, tfd); + return ptr; +} diff --git a/source/util/src/thash.c b/source/util/src/thash.c index 2841f27da4b74f616ab70360df1b068b0d52cfdb..f90b157558adb6e851927f34945dc0f734a48c9a 100644 --- a/source/util/src/thash.c +++ b/source/util/src/thash.c @@ -28,13 +28,13 @@ tfree(_n); \ } while (0) -#define FREE_HASH_NODE(_h, _n) \ - do { \ - if ((_h)->freeFp) { \ +#define FREE_HASH_NODE(_h, _n) \ + do { \ + if ((_h)->freeFp) { \ (_h)->freeFp(GET_HASH_NODE_DATA(_n)); \ - } \ - \ - DO_FREE_HASH_NODE(_n); \ + } \ + \ + DO_FREE_HASH_NODE(_n); \ } while (0); static FORCE_INLINE void __wr_lock(void *lock, int32_t type) { @@ -55,7 +55,6 @@ static FORCE_INLINE void __rd_unlock(void *lock, int32_t type) { if (type == HASH_NO_LOCK) { return; } - taosRUnLockLatch(lock); } @@ -63,7 +62,6 @@ static FORCE_INLINE void __wr_unlock(void *lock, int32_t type) { if (type == HASH_NO_LOCK) { return; } - taosWUnLockLatch(lock); } @@ -225,12 +223,12 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da // need the resize process, write lock applied if (HASH_NEED_RESIZE(pHashObj)) { - __wr_lock(&pHashObj->lock, pHashObj->type); + __wr_lock((void*) &pHashObj->lock, pHashObj->type); taosHashTableResize(pHashObj); - __wr_unlock(&pHashObj->lock, pHashObj->type); + __wr_unlock((void*) &pHashObj->lock, pHashObj->type); } - __rd_lock(&pHashObj->lock, pHashObj->type); + __rd_lock((void*) &pHashObj->lock, pHashObj->type); int32_t slot = HASH_INDEX(hashVal, pHashObj->capacity); SHashEntry *pe = pHashObj->hashList[slot]; @@ -272,7 +270,7 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da } // enable resize - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); atomic_add_fetch_32(&pHashObj->size, 1); return 0; @@ -289,7 +287,7 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, void *da } // enable resize - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return pHashObj->enableUpdate ? 0 : -2; } @@ -308,14 +306,14 @@ void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, vo uint32_t hashVal = (*pHashObj->hashFp)(key, (uint32_t)keyLen); // only add the read lock to disable the resize process - __rd_lock(&pHashObj->lock, pHashObj->type); + __rd_lock((void*) &pHashObj->lock, pHashObj->type); int32_t slot = HASH_INDEX(hashVal, pHashObj->capacity); SHashEntry *pe = pHashObj->hashList[slot]; // no data, return directly if (atomic_load_32(&pe->num) == 0) { - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return NULL; } @@ -358,7 +356,7 @@ void* taosHashGetCloneExt(SHashObj *pHashObj, const void *key, size_t keyLen, vo taosRUnLockLatch(&pe->latch); } - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return data; } @@ -370,14 +368,14 @@ void* taosHashGetCloneImpl(SHashObj *pHashObj, const void *key, size_t keyLen, v uint32_t hashVal = (*pHashObj->hashFp)(key, (uint32_t)keyLen); // only add the read lock to disable the resize process - __rd_lock(&pHashObj->lock, pHashObj->type); + __rd_lock((void*) &pHashObj->lock, pHashObj->type); int32_t slot = HASH_INDEX(hashVal, pHashObj->capacity); SHashEntry *pe = pHashObj->hashList[slot]; // no data, return directly if (atomic_load_32(&pe->num) == 0) { - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return NULL; } @@ -415,7 +413,7 @@ void* taosHashGetCloneImpl(SHashObj *pHashObj, const void *key, size_t keyLen, v taosRUnLockLatch(&pe->latch); } - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return data; } @@ -436,7 +434,7 @@ int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen/*, voi uint32_t hashVal = (*pHashObj->hashFp)(key, (uint32_t)keyLen); // disable the resize process - __rd_lock(&pHashObj->lock, pHashObj->type); + __rd_lock((void*) &pHashObj->lock, pHashObj->type); int32_t slot = HASH_INDEX(hashVal, pHashObj->capacity); SHashEntry *pe = pHashObj->hashList[slot]; @@ -450,7 +448,7 @@ int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen/*, voi assert(pe->next == NULL); taosWUnLockLatch(&pe->latch); - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return -1; } @@ -491,7 +489,7 @@ int32_t taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen/*, voi taosWUnLockLatch(&pe->latch); } - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return code; } @@ -502,7 +500,7 @@ int32_t taosHashCondTraverse(SHashObj *pHashObj, bool (*fp)(void *, void *), voi } // disable the resize process - __rd_lock(&pHashObj->lock, pHashObj->type); + __rd_lock((void*) &pHashObj->lock, pHashObj->type); int32_t numOfEntries = (int32_t)pHashObj->capacity; for (int32_t i = 0; i < numOfEntries; ++i) { @@ -566,7 +564,7 @@ int32_t taosHashCondTraverse(SHashObj *pHashObj, bool (*fp)(void *, void *), voi } } - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return 0; } @@ -577,7 +575,7 @@ void taosHashClear(SHashObj *pHashObj) { SHashNode *pNode, *pNext; - __wr_lock(&pHashObj->lock, pHashObj->type); + __wr_lock((void*) &pHashObj->lock, pHashObj->type); for (int32_t i = 0; i < pHashObj->capacity; ++i) { SHashEntry *pEntry = pHashObj->hashList[i]; @@ -601,7 +599,7 @@ void taosHashClear(SHashObj *pHashObj) { } atomic_store_32(&pHashObj->size, 0); - __wr_unlock(&pHashObj->lock, pHashObj->type); + __wr_unlock((void*) &pHashObj->lock, pHashObj->type); } void taosHashCleanup(SHashObj *pHashObj) { @@ -864,7 +862,7 @@ void *taosHashIterate(SHashObj *pHashObj, void *p) { char *data = NULL; // only add the read lock to disable the resize process - __rd_lock(&pHashObj->lock, pHashObj->type); + __rd_lock((void*) &pHashObj->lock, pHashObj->type); SHashNode *pNode = NULL; if (p) { @@ -911,7 +909,7 @@ void *taosHashIterate(SHashObj *pHashObj, void *p) { } } - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); return data; } @@ -920,7 +918,7 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p) { if (pHashObj == NULL || p == NULL) return; // only add the read lock to disable the resize process - __rd_lock(&pHashObj->lock, pHashObj->type); + __rd_lock((void*) &pHashObj->lock, pHashObj->type); int slot; taosHashReleaseNode(pHashObj, p, &slot); @@ -930,7 +928,7 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p) { taosWUnLockLatch(&pe->latch); } - __rd_unlock(&pHashObj->lock, pHashObj->type); + __rd_unlock((void*) &pHashObj->lock, pHashObj->type); } void taosHashRelease(SHashObj *pHashObj, void *p) { diff --git a/source/util/test/encodeTest.cpp b/source/util/test/encodeTest.cpp index 1a861701d78791ea3c36a2808dd2f59a713ccc3f..b178ee0b10b6fedc7f28299e8973f530e8fa3231 100644 --- a/source/util/test/encodeTest.cpp +++ b/source/util/test/encodeTest.cpp @@ -360,8 +360,8 @@ TEST(td_encode_test, compound_struct_encode_test) { SStructA_v2 sa2 = {.A_a = 10, .A_b = 65478, .A_c = "Hello", .A_d = 67, .A_e = 13}; SFinalReq_v1 req1 = {.pA = &sa1, .v_a = 15, .v_b = 35}; SFinalReq_v2 req2 = {.pA = &sa2, .v_a = 15, .v_b = 32, .v_c = 37}; - SFinalReq_v1 dreq1; - SFinalReq_v2 dreq21, dreq22; + SFinalReq_v1 dreq11, dreq21; + SFinalReq_v2 dreq12, dreq22; // Get size tCoderInit(&encoder, TD_LITTLE_ENDIAN, nullptr, 0, TD_ENCODER); @@ -386,27 +386,30 @@ TEST(td_encode_test, compound_struct_encode_test) { tCoderClear(&encoder); // Decode + // buf1 -> req1 tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf1, buf1size, TD_DECODER); - GTEST_ASSERT_EQ(tSFinalReq_v1_decode(&decoder, &dreq1), 0); - GTEST_ASSERT_EQ(dreq1.pA->A_a, req1.pA->A_a); - GTEST_ASSERT_EQ(dreq1.pA->A_b, req1.pA->A_b); - GTEST_ASSERT_EQ(strcmp(dreq1.pA->A_c, req1.pA->A_c), 0); - GTEST_ASSERT_EQ(dreq1.v_a, req1.v_a); - GTEST_ASSERT_EQ(dreq1.v_b, req1.v_b); + GTEST_ASSERT_EQ(tSFinalReq_v1_decode(&decoder, &dreq11), 0); + GTEST_ASSERT_EQ(dreq11.pA->A_a, req1.pA->A_a); + GTEST_ASSERT_EQ(dreq11.pA->A_b, req1.pA->A_b); + GTEST_ASSERT_EQ(strcmp(dreq11.pA->A_c, req1.pA->A_c), 0); + GTEST_ASSERT_EQ(dreq11.v_a, req1.v_a); + GTEST_ASSERT_EQ(dreq11.v_b, req1.v_b); tCoderClear(&decoder); + // buf1 -> req2 (backward compatibility) tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf1, buf1size, TD_DECODER); - GTEST_ASSERT_EQ(tSFinalReq_v2_decode(&decoder, &dreq21), 0); - GTEST_ASSERT_EQ(dreq21.pA->A_a, req1.pA->A_a); - GTEST_ASSERT_EQ(dreq21.pA->A_b, req1.pA->A_b); - GTEST_ASSERT_EQ(strcmp(dreq21.pA->A_c, req1.pA->A_c), 0); - GTEST_ASSERT_EQ(dreq21.pA->A_d, 0); - GTEST_ASSERT_EQ(dreq21.pA->A_e, 0); - GTEST_ASSERT_EQ(dreq21.v_a, req1.v_a); - GTEST_ASSERT_EQ(dreq21.v_b, req1.v_b); - GTEST_ASSERT_EQ(dreq21.v_c, 0); + GTEST_ASSERT_EQ(tSFinalReq_v2_decode(&decoder, &dreq12), 0); + GTEST_ASSERT_EQ(dreq12.pA->A_a, req1.pA->A_a); + GTEST_ASSERT_EQ(dreq12.pA->A_b, req1.pA->A_b); + GTEST_ASSERT_EQ(strcmp(dreq12.pA->A_c, req1.pA->A_c), 0); + GTEST_ASSERT_EQ(dreq12.pA->A_d, 0); + GTEST_ASSERT_EQ(dreq12.pA->A_e, 0); + GTEST_ASSERT_EQ(dreq12.v_a, req1.v_a); + GTEST_ASSERT_EQ(dreq12.v_b, req1.v_b); + GTEST_ASSERT_EQ(dreq12.v_c, 0); tCoderClear(&decoder); + // buf2 -> req2 tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf2, buf2size, TD_DECODER); GTEST_ASSERT_EQ(tSFinalReq_v2_decode(&decoder, &dreq22), 0); GTEST_ASSERT_EQ(dreq22.pA->A_a, req2.pA->A_a); @@ -418,4 +421,13 @@ TEST(td_encode_test, compound_struct_encode_test) { GTEST_ASSERT_EQ(dreq22.v_b, req2.v_b); GTEST_ASSERT_EQ(dreq22.v_c, req2.v_c); tCoderClear(&decoder); + + tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf2, buf2size, TD_DECODER); + GTEST_ASSERT_EQ(tSFinalReq_v1_decode(&decoder, &dreq21), 0); + GTEST_ASSERT_EQ(dreq21.pA->A_a, req2.pA->A_a); + GTEST_ASSERT_EQ(dreq21.pA->A_b, req2.pA->A_b); + GTEST_ASSERT_EQ(strcmp(dreq21.pA->A_c, req2.pA->A_c), 0); + GTEST_ASSERT_EQ(dreq21.v_a, req2.v_a); + GTEST_ASSERT_EQ(dreq21.v_b, req2.v_b); + tCoderClear(&decoder); } \ No newline at end of file diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 42799927e68f0d9d56a4ae7bdfe1e5ea04f29f1c..e0489a76d24638999c1e98629f184a334c4b7ed1 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -603,7 +603,7 @@ int tscBuildAndSendRequest(SSqlObj *pSql, SQueryInfo* pQueryInfo) { } int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) { - SRetrieveTableMsg *pRetrieveMsg = (SRetrieveTableMsg *) pSql->cmd.payload; + SRetrieveTableReq *pRetrieveMsg = (SRetrieveTableReq *) pSql->cmd.payload; SQueryInfo *pQueryInfo = tscGetQueryInfo(&pSql->cmd); @@ -638,10 +638,10 @@ int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pSql->res.qId); } - pSql->cmd.payloadLen = sizeof(SRetrieveTableMsg); + pSql->cmd.payloadLen = sizeof(SRetrieveTableReq); pSql->cmd.msgType = TDMT_VND_FETCH; - pRetrieveMsg->header.contLen = htonl(sizeof(SRetrieveTableMsg)); + pRetrieveMsg->header.contLen = htonl(sizeof(SRetrieveTableReq)); return TSDB_CODE_SUCCESS; } @@ -1210,13 +1210,13 @@ int32_t tscBuildCreateDnodeMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SCreateAcctMsg); + pCmd->payloadLen = sizeof(SCreateAcctReq); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); return TSDB_CODE_TSC_OUT_OF_MEMORY; } - SCreateAcctMsg *pAlterMsg = (SCreateAcctMsg *)pCmd->payload; + SCreateAcctReq *pAlterMsg = (SCreateAcctReq *)pCmd->payload; SStrToken *pName = &pInfo->pMiscInfo->user.user; SStrToken *pPwd = &pInfo->pMiscInfo->user.passwd; @@ -1255,14 +1255,14 @@ int32_t tscBuildAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int32_t tscBuildUserMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; - pCmd->payloadLen = sizeof(SCreateUserMsg); + pCmd->payloadLen = sizeof(SCreateUserReq); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); return TSDB_CODE_TSC_OUT_OF_MEMORY; } - SCreateUserMsg *pAlterMsg = (SCreateUserMsg *)pCmd->payload; + SCreateUserReq *pAlterMsg = (SCreateUserReq *)pCmd->payload; SUserInfo *pUser = &pInfo->pMiscInfo->user; strncpy(pAlterMsg->user, pUser->user.z, pUser->user.n); @@ -1369,7 +1369,7 @@ int32_t tscBuildDropUserAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { char user[TSDB_USER_LEN] = {0}; tstrncpy(user, pCmd->payload, TSDB_USER_LEN); - pCmd->payloadLen = sizeof(SDropUserMsg); + pCmd->payloadLen = sizeof(SDropUserReq); pCmd->msgType = (pInfo->type == TSDB_SQL_DROP_USER)? TDMT_MND_DROP_USER:TDMT_MND_DROP_ACCT; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { @@ -1377,7 +1377,7 @@ int32_t tscBuildDropUserAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } - SDropUserMsg *pDropMsg = (SDropUserMsg *)pCmd->payload; + SDropUserReq *pDropMsg = (SDropUserReq *)pCmd->payload; tstrncpy(pDropMsg->user, user, tListLen(user)); return TSDB_CODE_SUCCESS; @@ -1420,7 +1420,7 @@ int32_t tscBuildSyncDbReplicaMsg(SSqlObj* pSql, SSqlInfo *pInfo) { int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->msgType = TDMT_MND_SHOW; - pCmd->payloadLen = sizeof(SShowMsg) + 100; + pCmd->payloadLen = sizeof(SShowReq) + 100; if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); @@ -1428,13 +1428,13 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { } SShowInfo *pShowInfo = &pInfo->pMiscInfo->showOpt; - SShowMsg *pShowMsg = (SShowMsg *)pCmd->payload; + SShowReq *pShowMsg = (SShowReq *)pCmd->payload; STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0); if (pShowInfo->showType == TSDB_MGMT_TABLE_FUNCTION) { pShowMsg->type = pShowInfo->showType; pShowMsg->payloadLen = 0; - pCmd->payloadLen = sizeof(SShowMsg); + pCmd->payloadLen = sizeof(SShowReq); return TSDB_CODE_SUCCESS; } @@ -1463,7 +1463,7 @@ int32_t tscBuildShowMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pShowMsg->payloadLen = htons(pEpAddr->n); } - pCmd->payloadLen = sizeof(SShowMsg) + htons(pShowMsg->payloadLen); + pCmd->payloadLen = sizeof(SShowReq) + htons(pShowMsg->payloadLen); return TSDB_CODE_SUCCESS; } @@ -1742,7 +1742,7 @@ int tscBuildCompactMsg(SSqlObj *pSql, SSqlInfo *pInfo) { int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SSqlCmd *pCmd = &pSql->cmd; pCmd->msgType = TDMT_MND_SHOW_RETRIEVE; - pCmd->payloadLen = sizeof(SRetrieveTableMsg); + pCmd->payloadLen = sizeof(SRetrieveTableReq); if (TSDB_CODE_SUCCESS != tscAllocPayload(pCmd, pCmd->payloadLen)) { tscError("0x%"PRIx64" failed to malloc for query msg", pSql->self); @@ -1750,7 +1750,7 @@ int tscBuildRetrieveFromMgmtMsg(SSqlObj *pSql, SSqlInfo *pInfo) { } SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); - SRetrieveTableMsg *pRetrieveMsg = (SRetrieveTableMsg*)pCmd->payload; + SRetrieveTableReq *pRetrieveMsg = (SRetrieveTableReq*)pCmd->payload; pRetrieveMsg->qId = htobe64(pSql->res.qId); pRetrieveMsg->free = htons(pQueryInfo->type); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 966eb943541fda493dd120c12e1ba6be1c93cf48..59cbbb31471acc377dd614610aa715ae72c9ec31 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,4 @@ #ADD_SUBDIRECTORY(examples/c) ADD_SUBDIRECTORY(tsim) -#ADD_SUBDIRECTORY(test/c) +ADD_SUBDIRECTORY(test/c) #ADD_SUBDIRECTORY(comparisonTest/tdengine) diff --git a/tests/script/general/table/basic1.sim b/tests/script/general/table/basic1.sim index f2341a84ce3bffb71a8789bd73b1010e20a3c485..298f66382219b40e979debb78e97dc85b769119f 100644 --- a/tests/script/general/table/basic1.sim +++ b/tests/script/general/table/basic1.sim @@ -46,7 +46,6 @@ print =============== create child table sql create table c1 using st tags(1) sql create table c2 using st tags(2) -return sql show tables if $rows != 2 then return -1 @@ -56,6 +55,8 @@ print $data00 $data01 $data02 print $data10 $data11 $data22 print $data20 $data11 $data22 +return + print =============== insert data sql insert into c1 values(now+1s, 1) sql insert into c1 values(now+2s, 2) diff --git a/tests/test/c/CMakeLists.txt b/tests/test/c/CMakeLists.txt index 2702d192d3f47022f05888f90ca89c4ef533fe44..ebe9f96989560bd3ffa4072f53e4a54f93a28b8f 100644 --- a/tests/test/c/CMakeLists.txt +++ b/tests/test/c/CMakeLists.txt @@ -1,52 +1,8 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20) -PROJECT(TDengine) - -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/os/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/mnode/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/tsdb/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/plugins/http/inc) -INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) -INCLUDE_DIRECTORIES(${TD_ENTERPRISE_DIR}/src/inc) - -IF (TD_LINUX) - #add_executable(insertPerTable insertPerTable.c) - #target_link_libraries(insertPerTable taos_static pthread) - - #add_executable(insertPerRow insertPerRow.c) - #target_link_libraries(insertPerRow taos_static pthread) - - #add_executable(importOneRow importOneRow.c) - #target_link_libraries(importOneRow taos_static pthread) - - #add_executable(importPerTable importPerTable.c) - #target_link_libraries(importPerTable taos_static pthread) - - #add_executable(hashPerformance hashPerformance.c) - #target_link_libraries(hashPerformance taos_static tutil common pthread) - - #add_executable(createTablePerformance createTablePerformance.c) - #target_link_libraries(createTablePerformance taos_static tutil common pthread) - - #add_executable(createNormalTable createNormalTable.c) - #target_link_libraries(createNormalTable taos_static tutil common pthread) - - #add_executable(queryPerformance queryPerformance.c) - #target_link_libraries(queryPerformance taos_static tutil common pthread) - - #add_executable(httpTest httpTest.c) - #target_link_libraries(httpTest taos_static tutil common pthread mnode monitor http tsdb twal vnode cJson lz4) - - #add_executable(cacheTest cacheTest.c) - #target_link_libraries(cacheTest taos_static tutil common pthread mnode monitor http tsdb twal vnode cJson lz4) - - #add_executable(invalidTableId invalidTableId.c) - #target_link_libraries(invalidTableId taos_static tutil common pthread) - - #add_executable(hashIterator hashIterator.c) - #target_link_libraries(hashIterator taos_static tutil common pthread) -ENDIF() - +add_executable(create_table create_table.c) +target_link_libraries( + create_table + PUBLIC taos + PUBLIC util + PUBLIC common + PUBLIC os +) diff --git a/tests/test/c/cacheTest.c b/tests/test/c/cacheTest.c deleted file mode 100644 index ce5d7d1421d9d55d6bfab4a690d87f94c17ded29..0000000000000000000000000000000000000000 --- a/tests/test/c/cacheTest.c +++ /dev/null @@ -1,146 +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 -#include "../../../include/client/taos.h" -#include "os.h" -#include "tcache.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_REFRESH_TIME_SEC 2 -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -int32_t tsKeepTimeInSec = 3; -int32_t tsNumOfRows = 1000000; -int32_t tsSizeOfRow = 64 * 1024; -void * tsCacheObj = NULL; -int32_t destroyTimes = 0; - -typedef int64_t CacheTestKey; -typedef struct CacheTestRow { - int32_t index; - void ** ppRow; - void * data; -} CacheTestRow; - -CacheTestRow *initRow(int32_t index) { - CacheTestRow *row = calloc(sizeof(CacheTestRow), 1); - row->index = index; - row->data = malloc(tsSizeOfRow * sizeof(int8_t)); - return row; -} - -void detroyRow(void *data) { - CacheTestRow *row = *(CacheTestRow **)data; - free(row->data); - free(row); - destroyTimes++; - if (destroyTimes % 50000 == 0) { - pPrint("%s ===> destroyTimes:%d %s", GREEN, destroyTimes, NC); - } -} - -void initCache() { - tsCacheObj = taosCacheInit(TSDB_DATA_TYPE_BIGINT, MAX_REFRESH_TIME_SEC, true, detroyRow, "cachetest"); -} - -void putRowInCache() { - for (int index = 0; index < tsNumOfRows; ++index) { - CacheTestRow *row = initRow(index); - uint64_t key = (uint64_t)row; - void **ppRow = taosCachePut(tsCacheObj, &key, sizeof(int64_t), &row, sizeof(int64_t), tsKeepTimeInSec * 1000); - row->ppRow = ppRow; - taosCacheRelease(tsCacheObj, (void **)&ppRow, false); - } -} - -void cleanupCache() { - taosCacheCleanup(tsCacheObj); -} - -void initGetMemory() { - osInit(); - taos_init(); -} - -float getProcMemory() { - float procMemoryUsedMB = 0; - taosGetProcMemory(&procMemoryUsedMB); - return procMemoryUsedMB; -} - -void doTest() { - initCache(); - pPrint("%s initialize procMemory %f MB %s", GREEN, getProcMemory(), NC); - - putRowInCache(); - pPrint("%s insert %d rows, procMemory %f MB %s", GREEN, tsNumOfRows, getProcMemory(), NC); - - int32_t sleepMs = (MAX_REFRESH_TIME_SEC * 3) * 1000 + tsKeepTimeInSec * 1000; - taosMsleep(sleepMs); - pPrint("%s after sleep %d ms, procMemory %f MB %s", GREEN, sleepMs, getProcMemory(), NC); - - cleanupCache(); - taosMsleep(sleepMs); - pPrint("%s after cleanup cache, procMemory %f MB %s", GREEN, getProcMemory(), NC); - - malloc_trim(0); - taosMsleep(sleepMs); - pPrint("%s after malloc_trim, procMemory %f MB %s", GREEN, getProcMemory(), NC); -} - -void printHelp() { - char indent[10] = " "; - printf("Used to test the performance of cache\n"); - - printf("%s%s\n", indent, "-k"); - printf("%s%s%s%d\n", indent, indent, "KeepTimeInSec, default is ", tsKeepTimeInSec); - printf("%s%s\n", indent, "-n"); - printf("%s%s%s%d\n", indent, indent, "NumOfRows, default is ", tsNumOfRows); - printf("%s%s\n", indent, "-s"); - printf("%s%s%s%d\n", indent, indent, "SizeOfData, default is ", tsSizeOfRow); - - exit(EXIT_SUCCESS); -} - -void parseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-k") == 0) { - tsKeepTimeInSec = atoi(argv[++i]); - } else if (strcmp(argv[i], "-n") == 0) { - tsNumOfRows = atoi(argv[++i]); - } else if (strcmp(argv[i], "-s") == 0) { - tsSizeOfRow = atoi(argv[++i]); - } else { - } - } - - pPrint("%s KeepTimeInSec:%d %s", GREEN, tsKeepTimeInSec, NC); - pPrint("%s NumOfRows:%d %s", GREEN, tsNumOfRows, NC); - pPrint("%s SizeOfData:%d %s", GREEN, tsSizeOfRow, NC); -} - -int main(int argc, char *argv[]) { - initGetMemory(); - parseArgument(argc, argv); - doTest(); -} diff --git a/tests/test/c/createTablePerformance.c b/tests/test/c/createTablePerformance.c deleted file mode 100644 index 1a59657f1a48ef5ac58e788b2bc2bdf5f6327da1..0000000000000000000000000000000000000000 --- a/tests/test/c/createTablePerformance.c +++ /dev/null @@ -1,225 +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 "../../../include/client/taos.h" -#include "hash.h" -#include "os.h" -#include "taoserror.h" -#include "tglobal.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -char dbName[32] = "db"; -char stableName[64] = "st"; -int32_t numOfThreads = 30; -int32_t numOfTables = 100000; -int32_t replica = 1; -int32_t numOfColumns = 2; -TAOS * con = NULL; - -typedef struct { - int32_t tableBeginIndex; - int32_t tableEndIndex; - int32_t threadIndex; - char dbName[32]; - char stableName[64]; - float createTableSpeed; - pthread_t thread; -} SThreadInfo; - -void shellParseArgument(int argc, char *argv[]); -void *threadFunc(void *param); -void createDbAndSTable(); - -int main(int argc, char *argv[]) { - shellParseArgument(argc, argv); - taos_init(); - createDbAndSTable(); - - pPrint("%d threads are spawned to create table", numOfThreads); - - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); - SThreadInfo *pInfo = (SThreadInfo *)calloc(numOfThreads, sizeof(SThreadInfo)); - - int32_t numOfTablesPerThread = numOfTables / numOfThreads; - numOfTables = numOfTablesPerThread * numOfThreads; - for (int i = 0; i < numOfThreads; ++i) { - pInfo[i].tableBeginIndex = i * numOfTablesPerThread; - pInfo[i].tableEndIndex = (i + 1) * numOfTablesPerThread; - pInfo[i].threadIndex = i; - strcpy(pInfo[i].dbName, dbName); - strcpy(pInfo[i].stableName, stableName); - pthread_create(&(pInfo[i].thread), &thattr, threadFunc, (void *)(pInfo + i)); - } - - taosMsleep(300); - for (int i = 0; i < numOfThreads; i++) { - pthread_join(pInfo[i].thread, NULL); - } - - float createTableSpeed = 0; - for (int i = 0; i < numOfThreads; ++i) { - createTableSpeed += pInfo[i].createTableSpeed; - } - - pPrint("%s total speed:%.1f tables/second, threads:%d %s", GREEN, createTableSpeed, numOfThreads, NC); - - pthread_attr_destroy(&thattr); - free(pInfo); - taos_close(con); -} - -void createDbAndSTable() { - pPrint("start to create db and stable"); - char qstr[64000]; - - con = taos_connect(NULL, "root", "taosdata", NULL, 0); - if (con == NULL) { - pError("failed to connect to DB, reason:%s", taos_errstr(con)); - exit(1); - } - - sprintf(qstr, "create database if not exists %s replica %d", dbName, replica); - TAOS_RES *pSql = taos_query(con, qstr); - int32_t code = taos_errno(pSql); - if (code != 0) { - pError("failed to create database:%s, sql:%s, code:%d reason:%s", dbName, qstr, taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - - sprintf(qstr, "use %s", dbName); - pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to use db, code:%d reason:%s", taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - - int len = sprintf(qstr, "create table if not exists %s(ts timestamp", stableName); - for (int32_t f = 0; f < numOfColumns - 1; ++f) { - len += sprintf(qstr + len, ", f%d double", f); - } - sprintf(qstr + len, ") tags(t int)"); - - pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to create stable, code:%d reason:%s", taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); -} - -void *threadFunc(void *param) { - SThreadInfo *pInfo = (SThreadInfo *)param; - char qstr[65000]; - int code; - - sprintf(qstr, "use %s", pInfo->dbName); - TAOS_RES *pSql = taos_query(con, qstr); - taos_free_result(pSql); - - int64_t startMs = taosGetTimestampMs(); - - for (int32_t t = pInfo->tableBeginIndex; t < pInfo->tableEndIndex; ++t) { - sprintf(qstr, "create table if not exists %s%d using %s tags(%d)", stableName, t, stableName, t); - TAOS_RES *pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to create table %s%d, reason:%s", stableName, t, tstrerror(code)); - } - taos_free_result(pSql); - } - - float createTableSpeed = 0; - for (int i = 0; i < numOfThreads; ++i) { - createTableSpeed += pInfo[i].createTableSpeed; - } - - int64_t endMs = taosGetTimestampMs(); - int32_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; - float seconds = (endMs - startMs) / 1000.0; - float speed = totalTables / seconds; - pInfo->createTableSpeed = speed; - - pPrint("thread:%d, time:%.2f sec, speed:%.1f tables/second, ", pInfo->threadIndex, seconds, speed); - - return 0; -} - -void printHelp() { - char indent[10] = " "; - printf("Used to test the performance while create table\n"); - - printf("%s%s\n", indent, "-c"); - printf("%s%s%s%s\n", indent, indent, "Configuration directory, default is ", configDir); - printf("%s%s\n", indent, "-d"); - printf("%s%s%s%s\n", indent, indent, "The name of the database to be created, default is ", dbName); - printf("%s%s\n", indent, "-s"); - printf("%s%s%s%s\n", indent, indent, "The name of the super table to be created, default is ", stableName); - printf("%s%s\n", indent, "-t"); - printf("%s%s%s%d\n", indent, indent, "numOfThreads, default is ", numOfThreads); - printf("%s%s\n", indent, "-n"); - printf("%s%s%s%d\n", indent, indent, "numOfTables, default is ", numOfTables); - printf("%s%s\n", indent, "-r"); - printf("%s%s%s%d\n", indent, indent, "replica, default is ", replica); - printf("%s%s\n", indent, "-columns"); - printf("%s%s%s%d\n", indent, indent, "numOfColumns, default is ", numOfColumns); - - exit(EXIT_SUCCESS); -} - -void shellParseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-d") == 0) { - strcpy(dbName, argv[++i]); - } else if (strcmp(argv[i], "-c") == 0) { - strcpy(configDir, argv[++i]); - } else if (strcmp(argv[i], "-s") == 0) { - strcpy(stableName, argv[++i]); - } else if (strcmp(argv[i], "-t") == 0) { - numOfThreads = atoi(argv[++i]); - } else if (strcmp(argv[i], "-n") == 0) { - numOfTables = atoi(argv[++i]); - } else if (strcmp(argv[i], "-r") == 0) { - replica = atoi(argv[++i]); - } else if (strcmp(argv[i], "-columns") == 0) { - numOfColumns = atoi(argv[++i]); - } else { - } - } - - pPrint("%s dbName:%s %s", GREEN, dbName, NC); - pPrint("%s stableName:%s %s", GREEN, stableName, NC); - pPrint("%s configDir:%s %s", GREEN, configDir, NC); - pPrint("%s numOfTables:%d %s", GREEN, numOfTables, NC); - pPrint("%s numOfThreads:%d %s", GREEN, numOfThreads, NC); - pPrint("%s numOfColumns:%d %s", GREEN, numOfColumns, NC); - pPrint("%s replica:%d %s", GREEN, replica, NC); - - pPrint("%s start create table performace test %s", GREEN, NC); -} diff --git a/tests/test/c/createNormalTable.c b/tests/test/c/create_table.c similarity index 59% rename from tests/test/c/createNormalTable.c rename to tests/test/c/create_table.c index f9e4aa5a3a8e1a60b77facd97e7e9bb4617294a5..96c7f873929aacddf29a2d13be399188f0f7a3ca 100644 --- a/tests/test/c/createNormalTable.c +++ b/tests/test/c/create_table.c @@ -14,48 +14,49 @@ */ #define _DEFAULT_SOURCE -#include "../../../include/client/taos.h" -#include "hash.h" #include "os.h" + +#include "taos.h" +#include "taosdef.h" #include "taoserror.h" -#include "tglobal.h" -#include "tulog.h" +#include "thash.h" #include "tutil.h" +#include "ulog.h" #define MAX_RANDOM_POINTS 20000 #define GREEN "\033[1;32m" #define NC "\033[0m" char dbName[32] = "db"; -char stableName[64] = "st"; -int32_t numOfThreads = 30; -int32_t numOfTables = 100000; -int32_t replica = 1; -int32_t numOfColumns = 2; +char stbName[64] = "st"; +int32_t numOfThreads = 2; +int32_t numOfTables = 10000; +int32_t createTable = 1; +int32_t insertData = 0; +int32_t batchNum = 1; +int32_t numOfVgroups = 2; typedef struct { int32_t tableBeginIndex; int32_t tableEndIndex; int32_t threadIndex; char dbName[32]; - char stableName[64]; + char stbName[64]; float createTableSpeed; + float insertDataSpeed; pthread_t thread; } SThreadInfo; -void shellParseArgument(int argc, char *argv[]); +void parseArgument(int argc, char *argv[]); void *threadFunc(void *param); -void createDbAndSTable(); +void createDbAndStb(); int main(int argc, char *argv[]) { - shellParseArgument(argc, argv); - taos_init(); - if (replica != 0) { - createDbAndSTable(); - } + parseArgument(argc, argv); + createDbAndStb(); + + pPrint("%d threads are spawned to create %d tables", numOfThreads, numOfThreads); - pPrint("%d threads are spawned to create table", numOfThreads); - pthread_attr_t thattr; pthread_attr_init(&thattr); pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); @@ -68,7 +69,7 @@ int main(int argc, char *argv[]) { pInfo[i].tableEndIndex = (i + 1) * numOfTablesPerThread; pInfo[i].threadIndex = i; strcpy(pInfo[i].dbName, dbName); - strcpy(pInfo[i].stableName, stableName); + strcpy(pInfo[i].stbName, stbName); pthread_create(&(pInfo[i].thread), &thattr, threadFunc, (void *)(pInfo + i)); } @@ -82,25 +83,31 @@ int main(int argc, char *argv[]) { createTableSpeed += pInfo[i].createTableSpeed; } - pPrint("%s total speed:%.1f tables/second, threads:%d %s", GREEN, createTableSpeed, numOfThreads, NC); + float insertDataSpeed = 0; + for (int i = 0; i < numOfThreads; ++i) { + insertDataSpeed += pInfo[i].insertDataSpeed; + } + + pPrint("%s total %.1f tables/second, threads:%d %s", GREEN, createTableSpeed, numOfThreads, NC); + pPrint("%s total %.1f rows/second, threads:%d %s", GREEN, insertDataSpeed, numOfThreads, NC); pthread_attr_destroy(&thattr); free(pInfo); } -void createDbAndSTable() { +void createDbAndStb() { pPrint("start to create db and stable"); char qstr[64000]; - + TAOS *con = taos_connect(NULL, "root", "taosdata", NULL, 0); if (con == NULL) { pError("failed to connect to DB, reason:%s", taos_errstr(con)); exit(1); } - sprintf(qstr, "create database if not exists %s replica %d", dbName, replica); + sprintf(qstr, "create database if not exists %s vgroups %d", dbName, numOfVgroups); TAOS_RES *pSql = taos_query(con, qstr); - int32_t code = taos_errno(pSql); + int32_t code = taos_errno(pSql); if (code != 0) { pError("failed to create database:%s, sql:%s, code:%d reason:%s", dbName, qstr, taos_errno(con), taos_errstr(con)); exit(0); @@ -116,13 +123,22 @@ void createDbAndSTable() { } taos_free_result(pSql); + sprintf(qstr, "create table %s (ts timestamp, i int) tags (j int)", stbName); + pSql = taos_query(con, qstr); + code = taos_errno(pSql); + if (code != 0) { + pError("failed to use db, code:%d reason:%s", taos_errno(con), taos_errstr(con)); + exit(0); + } + taos_free_result(pSql); + taos_close(con); } void *threadFunc(void *param) { SThreadInfo *pInfo = (SThreadInfo *)param; - char qstr[65000]; - int code; + char qstr[65000]; + int code; TAOS *con = taos_connect(NULL, "root", "taosdata", NULL, 0); if (con == NULL) { @@ -134,49 +150,45 @@ void *threadFunc(void *param) { TAOS_RES *pSql = taos_query(con, qstr); taos_free_result(pSql); - int64_t startMs = taosGetTimestampMs(); - - if (replica != 0) { + if (createTable) { + int64_t startMs = taosGetTimestampMs(); for (int32_t t = pInfo->tableBeginIndex; t < pInfo->tableEndIndex; ++t) { - sprintf(qstr, "create table %s%d (ts timestamp, i int)", stableName, t); + sprintf(qstr, "create table t%d using %s tags(%d)", t, stbName, t); TAOS_RES *pSql = taos_query(con, qstr); code = taos_errno(pSql); if (code != 0) { - pError("failed to create table %s%d, reason:%s", stableName, t, tstrerror(code)); + pError("failed to create table t%d, reason:%s", t, tstrerror(code)); } taos_free_result(pSql); } - } else { + int64_t endMs = taosGetTimestampMs(); + int32_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; + float seconds = (endMs - startMs) / 1000.0; + float speed = totalTables / seconds; + pInfo->createTableSpeed = speed; + pPrint("thread:%d, time:%.2f sec, speed:%.1f tables/second, ", pInfo->threadIndex, seconds, speed); + } + + if (insertData) { + int64_t startMs = taosGetTimestampMs(); for (int32_t t = pInfo->tableBeginIndex; t < pInfo->tableEndIndex; ++t) { - sprintf(qstr, "insert into %s%d values(now, 1)", stableName, t); + sprintf(qstr, "insert into %s%d values(now, 1)", stbName, t); TAOS_RES *pSql = taos_query(con, qstr); code = taos_errno(pSql); if (code != 0) { - if (code != TSDB_CODE_MND_INVALID_TABLE_NAME) { - pError("failed to create table %s%d, reason:%s", stableName, t, tstrerror(code)); - } - if (code == TSDB_CODE_VND_INVALID_VGROUP_ID) { - exit(0); - } + pError("failed to create table %s%d, reason:%s", stbName, t, tstrerror(code)); } taos_free_result(pSql); } + int64_t endMs = taosGetTimestampMs(); + int32_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; + float seconds = (endMs - startMs) / 1000.0; + float speed = totalTables / seconds; + pInfo->insertDataSpeed = speed; + pPrint("thread:%d, time:%.2f sec, speed:%.1f rows/second, ", pInfo->threadIndex, seconds, speed); } - float createTableSpeed = 0; - for (int i = 0; i < numOfThreads; ++i) { - createTableSpeed += pInfo[i].createTableSpeed; - } - - int64_t endMs = taosGetTimestampMs(); - int32_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; - float seconds = (endMs - startMs) / 1000.0; - float speed = totalTables / seconds; - pInfo->createTableSpeed = speed; - - pPrint("thread:%d, time:%.2f sec, speed:%.1f tables/second, ", pInfo->threadIndex, seconds, speed); taos_close(con); - return 0; } @@ -189,20 +201,24 @@ void printHelp() { printf("%s%s\n", indent, "-d"); printf("%s%s%s%s\n", indent, indent, "The name of the database to be created, default is ", dbName); printf("%s%s\n", indent, "-s"); - printf("%s%s%s%s\n", indent, indent, "The name of the super table to be created, default is ", stableName); + printf("%s%s%s%s\n", indent, indent, "The name of the super table to be created, default is ", stbName); printf("%s%s\n", indent, "-t"); printf("%s%s%s%d\n", indent, indent, "numOfThreads, default is ", numOfThreads); printf("%s%s\n", indent, "-n"); printf("%s%s%s%d\n", indent, indent, "numOfTables, default is ", numOfTables); - printf("%s%s\n", indent, "-r"); - printf("%s%s%s%d\n", indent, indent, "replica, default is ", replica); - printf("%s%s\n", indent, "-columns"); - printf("%s%s%s%d\n", indent, indent, "numOfColumns, default is ", numOfColumns); - + printf("%s%s\n", indent, "-v"); + printf("%s%s%s%d\n", indent, indent, "numOfVgroups, default is ", numOfVgroups); + printf("%s%s\n", indent, "-a"); + printf("%s%s%s%d\n", indent, indent, "createTable, default is ", createTable); + printf("%s%s\n", indent, "-i"); + printf("%s%s%s%d\n", indent, indent, "insertData, default is ", insertData); + printf("%s%s\n", indent, "-b"); + printf("%s%s%s%d\n", indent, indent, "batchNum, default is ", batchNum); + exit(EXIT_SUCCESS); } -void shellParseArgument(int argc, char *argv[]) { +void parseArgument(int argc, char *argv[]) { for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { printHelp(); @@ -212,26 +228,32 @@ void shellParseArgument(int argc, char *argv[]) { } else if (strcmp(argv[i], "-c") == 0) { strcpy(configDir, argv[++i]); } else if (strcmp(argv[i], "-s") == 0) { - strcpy(stableName, argv[++i]); + strcpy(stbName, argv[++i]); } else if (strcmp(argv[i], "-t") == 0) { numOfThreads = atoi(argv[++i]); } else if (strcmp(argv[i], "-n") == 0) { numOfTables = atoi(argv[++i]); - } else if (strcmp(argv[i], "-r") == 0) { - replica = atoi(argv[++i]); - } else if (strcmp(argv[i], "-columns") == 0) { - numOfColumns = atoi(argv[++i]); + } else if (strcmp(argv[i], "-n") == 0) { + numOfVgroups = atoi(argv[++i]); + } else if (strcmp(argv[i], "-a") == 0) { + createTable = atoi(argv[++i]); + } else if (strcmp(argv[i], "-i") == 0) { + insertData = atoi(argv[++i]); + } else if (strcmp(argv[i], "-b") == 0) { + batchNum = atoi(argv[++i]); } else { } } pPrint("%s dbName:%s %s", GREEN, dbName, NC); - pPrint("%s stableName:%s %s", GREEN, stableName, NC); + pPrint("%s stbName:%s %s", GREEN, stbName, NC); pPrint("%s configDir:%s %s", GREEN, configDir, NC); pPrint("%s numOfTables:%d %s", GREEN, numOfTables, NC); pPrint("%s numOfThreads:%d %s", GREEN, numOfThreads, NC); - pPrint("%s numOfColumns:%d %s", GREEN, numOfColumns, NC); - pPrint("%s replica:%d %s", GREEN, replica, NC); - + pPrint("%s numOfVgroups:%d %s", GREEN, numOfVgroups, NC); + pPrint("%s createTable:%d %s", GREEN, createTable, NC); + pPrint("%s insertData:%d %s", GREEN, insertData, NC); + pPrint("%s batchNum:%d %s", GREEN, batchNum, NC); + pPrint("%s start create table performace test %s", GREEN, NC); } diff --git a/tests/test/c/hashIterator.c b/tests/test/c/hashIterator.c deleted file mode 100644 index 0d3dbb64d724c09c135eec5abee1486f05695e88..0000000000000000000000000000000000000000 --- a/tests/test/c/hashIterator.c +++ /dev/null @@ -1,72 +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 "../../../include/client/taos.h" -#include "hash.h" -#include "os.h" -#include "tulog.h" -#include "tutil.h" - -typedef struct HashTestRow { - int32_t keySize; - char key[100]; -} HashTestRow; - -int main(int argc, char *argv[]) { - _hash_fn_t hashFp = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY); - void * hashHandle = taosHashInit(100, hashFp, true, HASH_ENTRY_LOCK); - - pPrint("insert 3 rows to hash"); - for (int32_t t = 0; t < 3; ++t) { - HashTestRow row = {0}; - row.keySize = sprintf(row.key, "0.db.st%d", t); - - taosHashPut(hashHandle, row.key, row.keySize, &row, sizeof(HashTestRow)); - } - - pPrint("start iterator"); - HashTestRow *row = taosHashIterate(hashHandle, NULL); - while (row) { - pPrint("drop key:%s", row->key); - taosHashRemove(hashHandle, row->key, row->keySize); - - pPrint("get rows from hash"); - for (int32_t t = 0; t < 3; ++t) { - HashTestRow r = {0}; - r.keySize = sprintf(r.key, "0.db.st%d", t); - - void *result = taosHashGet(hashHandle, r.key, r.keySize); - pPrint("get key:%s result:%p", r.key, result); - } - - //Before getting the next iterator, the object just deleted can be obtained - row = taosHashIterate(hashHandle, row); - } - - pPrint("stop iterator"); - taosHashCancelIterate(hashHandle, row); - - pPrint("get rows from hash"); - for (int32_t t = 0; t < 3; ++t) { - HashTestRow r = {0}; - r.keySize = sprintf(r.key, "0.db.st%d", t); - - void *result = taosHashGet(hashHandle, r.key, r.keySize); - pPrint("get key:%s result:%p", r.key, result); - } - - return 0; -} \ No newline at end of file diff --git a/tests/test/c/hashPerformance.c b/tests/test/c/hashPerformance.c deleted file mode 100644 index 0f14fbff6a3bb491b43e0f96f11136e21e1638ce..0000000000000000000000000000000000000000 --- a/tests/test/c/hashPerformance.c +++ /dev/null @@ -1,166 +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 "../../../include/client/taos.h" -#include "hash.h" -#include "os.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -int32_t capacity = 128; -int32_t q1Times = 10; -int32_t q2Times = 10; -int32_t keyNum = 100000; -int32_t printInterval = 1000; -void * hashHandle; -pthread_t thread; - -typedef struct HashTestRow { - int32_t keySize; - char key[100]; -} HashTestRow; - -void shellParseArgument(int argc, char *argv[]); - -void testHashPerformance() { - int64_t initialMs = taosGetTimestampMs(); - _hash_fn_t hashFp = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY); - hashHandle = taosHashInit(128, hashFp, true, HASH_NO_LOCK); - - int64_t startMs = taosGetTimestampMs(); - float seconds = (startMs - initialMs) / 1000.0; - pPrint("initial time %.2f sec", seconds); - - for (int32_t t = 1; t <= keyNum; ++t) { - HashTestRow row = {0}; - row.keySize = sprintf(row.key, "0.db.st%d", t); - - for (int32_t q = 0; q < q1Times; q++) { - taosHashGet(hashHandle, row.key, row.keySize); - } - - taosHashPut(hashHandle, row.key, row.keySize, &row, sizeof(HashTestRow)); - - for (int32_t q = 0; q < q2Times; q++) { - taosHashGet(hashHandle, row.key, row.keySize); - } - - // test iterator - { - HashTestRow *row = taosHashIterate(hashHandle, NULL); - while (row) { - taosHashGet(hashHandle, row->key, row->keySize); - row = taosHashIterate(hashHandle, row); - } - } - - if (t % printInterval == 0) { - int64_t endMs = taosGetTimestampMs(); - int64_t hashSize = taosHashGetSize(hashHandle); - float seconds = (endMs - startMs) / 1000.0; - float speed = printInterval / seconds; - pPrint("time:%.2f sec, speed:%.1f rows/second, hashSize:%ld", seconds, speed, hashSize); - startMs = endMs; - } - } - - int64_t endMs = taosGetTimestampMs(); - int64_t hashSize = taosHashGetSize(hashHandle); - seconds = (endMs - initialMs) / 1000.0; - float speed = hashSize / seconds; - - pPrint("total time:%.2f sec, avg speed:%.1f rows/second, hashSize:%ld", seconds, speed, hashSize); - taosHashCleanup(hashHandle); -} - -void *multiThreadFunc(void *param) { - for (int i = 0; i < 100; ++i) { - taosMsleep(1000); - HashTestRow *row = taosHashIterate(hashHandle, NULL); - while (row) { - taosHashGet(hashHandle, row->key, row->keySize); - row = taosHashIterate(hashHandle, row); - } - int64_t hashSize = taosHashGetSize(hashHandle); - pPrint("i:%d hashSize:%ld", i, hashSize); - } - - return NULL; -} - -void multiThreadTest() { - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); - - // Start threads to write - pthread_create(&thread, &thattr, multiThreadFunc, NULL); -} - -int main(int argc, char *argv[]) { - shellParseArgument(argc, argv); - multiThreadTest(); - testHashPerformance(); - pthread_join(thread, NULL); -} - -void printHelp() { - char indent[10] = " "; - printf("Used to test the performance of cache\n"); - - printf("%s%s\n", indent, "-k"); - printf("%s%s%s%d\n", indent, indent, "key num, default is ", keyNum); - printf("%s%s\n", indent, "-p"); - printf("%s%s%s%d\n", indent, indent, "print interval while put into hash, default is ", printInterval); - printf("%s%s\n", indent, "-c"); - printf("%s%s%s%d\n", indent, indent, "the initial capacity of hash ", capacity); - printf("%s%s\n", indent, "-q1"); - printf("%s%s%s%d\n", indent, indent, "query times before put into hash", q1Times); - printf("%s%s\n", indent, "-q2"); - printf("%s%s%s%d\n", indent, indent, "query times after put into hash", q2Times); - - exit(EXIT_SUCCESS); -} - -void shellParseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-k") == 0) { - keyNum = atoi(argv[++i]); - } else if (strcmp(argv[i], "-p") == 0) { - printInterval = atoi(argv[++i]); - } else if (strcmp(argv[i], "-c") == 0) { - capacity = atoi(argv[++i]); - } else if (strcmp(argv[i], "-q1") == 0) { - q1Times = atoi(argv[++i]); - } else if (strcmp(argv[i], "-q2") == 0) { - q2Times = atoi(argv[++i]); - } else { - } - } - - pPrint("%s capacity:%d %s", GREEN, capacity, NC); - pPrint("%s printInterval:%d %s", GREEN, printInterval, NC); - pPrint("%s q1Times:%d %s", GREEN, q1Times, NC); - pPrint("%s q2Times:%d %s", GREEN, q2Times, NC); - pPrint("%s keyNum:%d %s", GREEN, keyNum, NC); -} diff --git a/tests/test/c/httpTest.c b/tests/test/c/httpTest.c deleted file mode 100644 index 261546770eed889894ec93cbbdfb2cdad9f4cad0..0000000000000000000000000000000000000000 --- a/tests/test/c/httpTest.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 "os.h" -#include "os.h" -#include "tglobal.h" -#include "taoserror.h" -#include "httpSystem.h" - -void signal_handler(int signum) { - httpStopSystem(); - httpCleanUpSystem(); - exit(EXIT_SUCCESS); -} - -int main(int argc, char *argv[]) { - struct sigaction act; - act.sa_handler = signal_handler; - sigaction(SIGTERM, &act, NULL); - sigaction(SIGHUP, &act, NULL); - sigaction(SIGINT, &act, NULL); - sigaction(SIGABRT, &act, NULL); - - // Initialize the system - if (httpInitSystem() < 0) { - exit(EXIT_FAILURE); - } - - if (httpStartSystem() < 0) { - exit(EXIT_FAILURE); - } - - while (1) { - sleep(1000); - } -} diff --git a/tests/test/c/importOneRow.c b/tests/test/c/importOneRow.c deleted file mode 100644 index 510f780163f9c04bca31a3ec97b8e5447d55f182..0000000000000000000000000000000000000000 --- a/tests/test/c/importOneRow.c +++ /dev/null @@ -1,182 +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 "../../../include/client/taos.h" -#include "os.h" -#include "tglobal.h" -#include "ttimer.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -void taos_error(TAOS *taos); -void* taos_execute(void *param); - -typedef struct { - pthread_t pid; - int index; -} ThreadObj; - -int threadNum = 1; -int rowNum = 1000; -int replica = 1; - -void printHelp() { - char indent[10] = " "; - printf("Used to test the performance of TDengine\n After writing one row of data to all tables, write the next row\n"); - - printf("%s%s\n", indent, "-r"); - printf("%s%s%s%d\n", indent, indent, "Number of records to write table, default is ", rowNum); - printf("%s%s\n", indent, "-t"); - printf("%s%s%s%d\n", indent, indent, "Number of threads to be used, default is ", threadNum); - printf("%s%s\n", indent, "-replica"); - printf("%s%s%s%d\n", indent, indent, "Database parameters replica, default is ", replica); - - exit(EXIT_SUCCESS); -} - -void shellParseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-r") == 0) { - rowNum = atoi(argv[++i]); - } else if (strcmp(argv[i], "-t") == 0) { - threadNum = atoi(argv[++i]); - } else if (strcmp(argv[i], "-replica") == 0) { - replica = atoi(argv[++i]); - } else { - } - } - - pPrint("%s rowNum:%d %s", GREEN, rowNum, NC); - pPrint("%s threadNum:%d %s", GREEN, threadNum, NC); - pPrint("%s replica:%d %s", GREEN, replica, NC); -} - -int main(int argc, char *argv[]) { - shellParseArgument(argc, argv); - - taos_init(); - - ThreadObj *threads = calloc(threadNum, sizeof(ThreadObj)); - for (int i = 0; i < threadNum; ++i) { - ThreadObj * pthread = threads + i; - pthread_attr_t thattr; - pthread->index = i; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); - pthread_create(&pthread->pid, &thattr, taos_execute, pthread); - } - - for (int i = 0; i < threadNum; i++) { - pthread_join(threads[i].pid, NULL); - } - - printf("all finished\n"); - - return 0; -} - -void taos_error(TAOS *con) { - fprintf(stderr, "TDengine error: %s\n", taos_errstr(con)); - taos_close(con); - exit(1); -} - -void* taos_execute(void *param) { - ThreadObj *pThread = (ThreadObj *)param; - - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - - void *taos = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (taos == NULL) taos_error(taos); - - char sql[1024] = {0}; - sprintf(sql, "create database if not exists db replica %d", replica); - taos_query(taos, sql); - - sprintf(sql, "create table if not exists db.t%d (ts timestamp, i int, j float, k double)", pThread->index); - taos_query(taos, sql); - - int64_t timestamp = 1530374400000L; - - sprintf(sql, "insert into db.t%d values(%ld, %d, %d, %d)", pThread->index, timestamp, 0, 0, 0); - TAOS_RES *pSql = taos_query(taos, sql); - int code = taos_errno(pSql); - if (code != 0) - { - printf("error code:%d, sql:%s\n", code, sql); - taos_free_result(pSql); - taos_close(taos); - return NULL; - } - int affectrows = taos_affected_rows(taos); - if (affectrows != 1) - { - printf("affect rows:%d, sql:%s\n", affectrows, sql); - taos_free_result(pSql); - taos_close(taos); - return NULL; - } - taos_free_result(pSql); - pSql = NULL; - - - timestamp -= 1000; - - int total_affect_rows = affectrows; - - for (int i = 1; i < rowNum; ++i) { - sprintf(sql, "import into db.t%d values(%ld, %d, %d, %d)", pThread->index, timestamp, i, i, i); - - pSql = taos_query(taos, sql); - code = taos_errno(pSql); - if (code != 0) - { - printf("error code:%d, sql:%s\n", code, sql); - taos_free_result(pSql); - pSql = NULL; - taos_close(taos); - return NULL; - } - int affectrows = taos_affected_rows(taos); - if (affectrows != 1) { - printf("affect rows:%d, sql:%s\n", affectrows, sql); - taos_free_result(pSql); - pSql = NULL; - taos_close(taos); - } - - total_affect_rows += affectrows; - taos_free_result(pSql); - pSql = NULL; - - timestamp -= 1000; - } - - printf("thread:%d run finished total_affect_rows:%d\n", pThread->index, total_affect_rows); - taos_close(taos); - - return NULL; -} diff --git a/tests/test/c/importPerTable.c b/tests/test/c/importPerTable.c deleted file mode 100644 index 7aef676c973dee349498a16e5ec87a96d8ca60e1..0000000000000000000000000000000000000000 --- a/tests/test/c/importPerTable.c +++ /dev/null @@ -1,356 +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 "../../../include/client/taos.h" -#include "os.h" -#include "osTime.h" -#include "tglobal.h" -#include "ttimer.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -typedef struct { - int64_t rowsPerTable; - int64_t pointsPerTable; - int64_t tableBeginIndex; - int64_t tableEndIndex; - int threadIndex; - char dbName[32]; - char stableName[64]; - pthread_t thread; -} SInfo; - -void *syncTest(void *param); -void generateRandomPoints(); -void shellParseArgument(int argc, char *argv[]); -void createDbAndTable(); -void insertData(); - -int32_t randomData[MAX_RANDOM_POINTS]; -int64_t rowsPerTable = 1000000; -int64_t pointsPerTable = 1; -int64_t numOfThreads = 10; -int64_t numOfTablesPerThread = 100; -char dbName[32] = "db"; -char stableName[64] = "st"; -int64_t totalUs = 0; -int64_t reqNum = 0; -int64_t maxUs = 0; -int64_t minUs = 100000000; - -int main(int argc, char *argv[]) { - shellParseArgument(argc, argv); - generateRandomPoints(); - taos_init(); - createDbAndTable(); - insertData(); - int64_t avgUs = totalUs / reqNum; - pError("%s totalUs:%ld, avgUs:%ld maxUs:%ld minUs:%ld reqNum:%ld %s\n", GREEN, totalUs, avgUs, maxUs, minUs, reqNum, NC); -} - -int32_t query(void *con, char *qstr) { - int64_t begin = taosGetTimestampUs(); - - TAOS_RES *pSql = taos_query(con, qstr); - int32_t code = taos_errno(pSql); - if (code != 0) { - pError("failed to exec sql:%s, code:%d reason:%s", qstr, taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - - int64_t us = taosGetTimestampUs() - begin; - maxUs = MAX(us, maxUs); - minUs = MIN(us, minUs); - atomic_add_fetch_64(&totalUs, us); - atomic_add_fetch_64(&reqNum, 1); - if (reqNum > 100000) { - int64_t avgUs = totalUs / reqNum; - if (us > avgUs * 100) { - pError("sql:%s", qstr); - pError("%s totalUs:%ld, avgUs:%ld maxUs:%ld minUs:%ld reqNum:%ld %s\n", GREEN, totalUs, avgUs, maxUs, minUs, - reqNum, NC); - taosMsleep(1000); - exit(0); - } - } - - return code; -} - -void createDbAndTable() { - pPrint("start to create table"); - - TAOS * con; - struct timeval systemTime; - int64_t st, et; - char qstr[64000]; - - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - - con = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (con == NULL) { - pError("failed to connect to DB, reason:%s", taos_errstr(con)); - exit(1); - } - - sprintf(qstr, "create database if not exists %s", dbName); - if (query(con, qstr)) { - pError("failed to create database:%s, code:%d reason:%s", dbName, taos_errno(con), taos_errstr(con)); - exit(0); - } - - sprintf(qstr, "use %s", dbName); - if (query(con, qstr)) { - pError("failed to use db, code:%d reason:%s", taos_errno(con), taos_errstr(con)); - exit(0); - } - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - int64_t totalTables = numOfTablesPerThread * numOfThreads; - - if (strcmp(stableName, "no") != 0) { - int len = sprintf(qstr, "create table if not exists %s(ts timestamp", stableName); - for (int64_t f = 0; f < pointsPerTable; ++f) { - len += sprintf(qstr + len, ", f%ld double", f); - } - sprintf(qstr + len, ") tags(t int)"); - - if (query(con, qstr)) { - pError("failed to create stable, code:%d reason:%s", taos_errno(con), taos_errstr(con)); - exit(0); - } - - for (int64_t t = 0; t < totalTables; ++t) { - sprintf(qstr, "create table if not exists %s%ld using %s tags(%ld)", stableName, t, stableName, t); - if (query(con, qstr)) { - pError("failed to create table %s%" PRId64 ", reason:%s", stableName, t, taos_errstr(con)); - exit(0); - } - } - } else { - for (int64_t t = 0; t < totalTables; ++t) { - int len = sprintf(qstr, "create table if not exists %s%ld(ts timestamp", stableName, t); - for (int64_t f = 0; f < pointsPerTable; ++f) { - len += sprintf(qstr + len, ", f%ld double", f); - } - sprintf(qstr + len, ")"); - - if (query(con, qstr)) { - pError("failed to create table %s%ld, reason:%s", stableName, t, taos_errstr(con)); - exit(0); - } - } - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - pPrint("%.1f seconds to create %ld tables", (et - st) / 1000.0 / 1000.0, totalTables); -} - -void insertData() { - struct timeval systemTime; - int64_t st, et; - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - - pPrint("%" PRId64 " threads are spawned to import data", numOfThreads); - - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); - SInfo *pInfo = (SInfo *)malloc(sizeof(SInfo) * numOfThreads); - - // Start threads to write - for (int i = 0; i < numOfThreads; ++i) { - pInfo[i].rowsPerTable = rowsPerTable; - pInfo[i].pointsPerTable = pointsPerTable; - pInfo[i].tableBeginIndex = i * numOfTablesPerThread; - pInfo[i].tableEndIndex = (i + 1) * numOfTablesPerThread; - pInfo[i].threadIndex = i; - strcpy(pInfo[i].dbName, dbName); - strcpy(pInfo[i].stableName, stableName); - pthread_create(&(pInfo[i].thread), &thattr, syncTest, (void *)(pInfo + i)); - } - - taosMsleep(300); - for (int i = 0; i < numOfThreads; i++) { - pthread_join(pInfo[i].thread, NULL); - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - double seconds = (et - st) / 1000.0 / 1000.0; - - int64_t totalTables = numOfTablesPerThread * numOfThreads; - int64_t totalRows = totalTables * rowsPerTable; - int64_t totalPoints = totalTables * rowsPerTable * pointsPerTable; - double speedOfRows = totalRows / seconds; - double speedOfPoints = totalPoints / seconds; - - pPrint( - "%sall threads:%ld finished, use %.1lf seconds, tables:%.ld rows:%ld points:%ld, speed RowsPerSecond:%.1lf " - "PointsPerSecond:%.1lf%s", - GREEN, numOfThreads, seconds, totalTables, totalRows, totalPoints, speedOfRows, speedOfPoints, NC); - - pPrint("threads exit"); - - pthread_attr_destroy(&thattr); - free(pInfo); -} - -void *syncTest(void *param) { - TAOS * con; - SInfo * pInfo = (SInfo *)param; - struct timeval systemTime; - int64_t st, et; - char qstr[65000]; - int maxBytes = 60000; - - pPrint("thread:%d, start to run", pInfo->threadIndex); - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - - con = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (con == NULL) { - pError("index:%d, failed to connect to DB, reason:%s", pInfo->threadIndex, taos_errstr(con)); - exit(1); - } - - sprintf(qstr, "use %s", pInfo->dbName); - query(con, qstr); - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - - int64_t start = 1587225600000; - int64_t interval = 1000; // 1000 ms - - char *sql = qstr; - char inserStr[] = "import into"; - int len = sprintf(sql, "%s", inserStr); - - for (int64_t table = pInfo->tableBeginIndex; table < pInfo->tableEndIndex; ++table) { - len += sprintf(sql + len, " %s%ld values", pInfo->stableName, table); - for (int64_t row = 0; row < pInfo->rowsPerTable; row++) { - len += sprintf(sql + len, "(%ld", start - row * interval); - for (int64_t point = 0; point < pInfo->pointsPerTable; ++point) { - len += sprintf(sql + len, ",%d", randomData[(123 * table + 456 * row + 789 * point) % MAX_RANDOM_POINTS]); - // len += sprintf(sql + len, ",%ld", row); - } - len += sprintf(sql + len, ")"); - if (len > maxBytes) { - if (query(con, qstr)) { - pError("thread:%d, failed to import table:%s%ld row:%ld, reason:%s", pInfo->threadIndex, pInfo->stableName, - table, row, taos_errstr(con)); - } - - // "insert into" - len = sprintf(sql, "%s", inserStr); - - // "insert into st1 values" - if (row != pInfo->rowsPerTable - 1) { - len += sprintf(sql + len, " %s%ld values", pInfo->stableName, table); - } - } - } - } - - if (len != strlen(inserStr)) { - query(con, qstr); - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - int64_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; - int64_t totalRows = totalTables * pInfo->rowsPerTable; - int64_t totalPoints = totalRows * pInfo->pointsPerTable; - pPrint("thread:%d, import finished, use %.2f seconds, tables:%ld rows:%ld points:%ld", pInfo->threadIndex, - (et - st) / 1000.0 / 1000.0, totalTables, totalRows, totalPoints); - - return NULL; -} - -void generateRandomPoints() { - for (int r = 0; r < MAX_RANDOM_POINTS; ++r) { - randomData[r] = rand() % 1000; - } -} - -void printHelp() { - char indent[10] = " "; - printf("Used to test the performance of TDengine\n After writing all the data in one table, start the next table\n"); - - printf("%s%s\n", indent, "-d"); - printf("%s%s%s%s\n", indent, indent, "The name of the database to be created, default is ", dbName); - printf("%s%s\n", indent, "-s"); - printf("%s%s%s%s%s\n", indent, indent, "The name of the super table to be created, default is ", stableName, ", if 'no' then create normal table"); - printf("%s%s\n", indent, "-c"); - printf("%s%s%s%s\n", indent, indent, "Configuration directory, default is ", configDir); - printf("%s%s\n", indent, "-r"); - printf("%s%s%s%ld\n", indent, indent, "Number of records to write to each table, default is ", rowsPerTable); - printf("%s%s\n", indent, "-p"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of columns per table, default is ", pointsPerTable); - printf("%s%s\n", indent, "-t"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of threads to be used, default is ", numOfThreads); - printf("%s%s\n", indent, "-n"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of tables per thread, default is ", numOfTablesPerThread); - - exit(EXIT_SUCCESS); -} - -void shellParseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-d") == 0) { - strcpy(dbName, argv[++i]); - } else if (strcmp(argv[i], "-c") == 0) { - strcpy(configDir, argv[++i]); - } else if (strcmp(argv[i], "-s") == 0) { - strcpy(stableName, argv[++i]); - } else if (strcmp(argv[i], "-r") == 0) { - rowsPerTable = atoi(argv[++i]); - } else if (strcmp(argv[i], "-p") == 0) { - pointsPerTable = atoi(argv[++i]); - } else if (strcmp(argv[i], "-t") == 0) { - numOfThreads = atoi(argv[++i]); - } else if (strcmp(argv[i], "-n") == 0) { - numOfTablesPerThread = atoi(argv[++i]); - } else { - } - } - - pPrint("%srowsPerTable:%" PRId64 "%s", GREEN, rowsPerTable, NC); - pPrint("%spointsPerTable:%" PRId64 "%s", GREEN, pointsPerTable, NC); - pPrint("%snumOfThreads:%" PRId64 "%s", GREEN, numOfThreads, NC); - pPrint("%snumOfTablesPerThread:%" PRId64 "%s", GREEN, numOfTablesPerThread, NC); - pPrint("%sdbName:%s%s", GREEN, dbName, NC); - pPrint("%stableName:%s%s", GREEN, stableName, NC); - pPrint("%sstart to run%s", GREEN, NC); -} diff --git a/tests/test/c/insertPerRow.c b/tests/test/c/insertPerRow.c deleted file mode 100644 index bdf27180b2c896762339f436aae132eb95feaca4..0000000000000000000000000000000000000000 --- a/tests/test/c/insertPerRow.c +++ /dev/null @@ -1,366 +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 "../../../include/client/taos.h" -#include "os.h" -#include "tglobal.h" -#include "ttimer.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -typedef struct { - int64_t rowsPerTable; - int64_t pointsPerTable; - int64_t tableBeginIndex; - int64_t tableEndIndex; - int threadIndex; - char dbName[32]; - char stableName[64]; - float createTableSpeed; - pthread_t thread; -} SInfo; - -void *syncTest(void *param); -void generateRandomPoints(); -void shellParseArgument(int argc, char *argv[]); -void createDbAndTable(); -void insertData(); - -int32_t randomData[MAX_RANDOM_POINTS]; -int64_t rowsPerTable = 1000000000; -int64_t pointsPerTable = 1; -int64_t numOfThreads = 10; -int64_t numOfTablesPerThread = 100; -char dbName[32] = "db"; -char stableName[64] = "st"; -int32_t cache = 1; -int32_t replica = 3; -int32_t days = 10; -int32_t interval = 1000; - -int main(int argc, char *argv[]) { - shellParseArgument(argc, argv); - generateRandomPoints(); - taos_init(); - createDbAndTable(); - insertData(); -} - -void createDbAndTable() { - pPrint("start to create table"); - - TAOS_RES * pSql; - TAOS * con; - char qstr[64000]; - - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - con = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (con == NULL) { - pError("failed to connect to DB, reason:%s", taos_errstr(con)); - exit(1); - } - - sprintf(qstr, "create database if not exists %s cache %d replica %d days %d", dbName, cache, replica, days); - pSql = taos_query(con, qstr); - int32_t code = taos_errno(pSql); - if (code != 0) { - pError("failed to create database:%s, sql:%s, code:%d reason:%s", dbName, qstr, taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - - sprintf(qstr, "use %s", dbName); - pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to use db, code:%d reason:%s", taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - - if (strcmp(stableName, "no") != 0) { - int len = sprintf(qstr, "create table if not exists %s(ts timestamp", stableName); - for (int64_t f = 0; f < pointsPerTable; ++f) { - len += sprintf(qstr + len, ", f%ld double", f); - } - sprintf(qstr + len, ") tags(t int)"); - - pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to create stable, code:%d reason:%s", taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - } -} - -void insertData() { - struct timeval systemTime; - int64_t st, et; - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - - pPrint("%" PRId64 " threads are spawned to insert data", numOfThreads); - - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); - SInfo *pInfo = (SInfo *)calloc(numOfThreads, sizeof(SInfo)); - - // Start threads to write - for (int i = 0; i < numOfThreads; ++i) { - pInfo[i].rowsPerTable = rowsPerTable; - pInfo[i].pointsPerTable = pointsPerTable; - pInfo[i].tableBeginIndex = i * numOfTablesPerThread; - pInfo[i].tableEndIndex = (i + 1) * numOfTablesPerThread; - pInfo[i].threadIndex = i; - strcpy(pInfo[i].dbName, dbName); - strcpy(pInfo[i].stableName, stableName); - pthread_create(&(pInfo[i].thread), &thattr, syncTest, (void *)(pInfo + i)); - } - - taosMsleep(300); - for (int i = 0; i < numOfThreads; i++) { - pthread_join(pInfo[i].thread, NULL); - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - double seconds = (et - st) / 1000.0 / 1000.0; - - int64_t totalTables = numOfTablesPerThread * numOfThreads; - int64_t totalRows = totalTables * rowsPerTable; - int64_t totalPoints = totalTables * rowsPerTable * pointsPerTable; - double speedOfRows = totalRows / seconds; - double speedOfPoints = totalPoints / seconds; - - float createTableSpeed = 0; - for (int i = 0; i < numOfThreads; ++i) { - createTableSpeed += pInfo[i].createTableSpeed; - } - - pPrint( - "%sall threads:%ld finished, use %.1lf seconds, tables:%.ld rows:%ld points:%ld, speed RowsPerSecond:%.1lf " - "PointsPerSecond:%.1lf CreateTableSpeed:%.1f t/s %s", - GREEN, numOfThreads, seconds, totalTables, totalRows, totalPoints, speedOfRows, speedOfPoints, createTableSpeed, NC); - - pPrint("threads exit"); - - pthread_attr_destroy(&thattr); - free(pInfo); -} - -void *syncTest(void *param) { - TAOS * con; - SInfo * pInfo = (SInfo *)param; - struct timeval systemTime; - int64_t st, et; - char qstr[65000]; - int maxBytes = 60000; - int code; - - pPrint("thread:%d, start to run", pInfo->threadIndex); - - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - con = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (con == NULL) { - pError("index:%d, failed to connect to DB, reason:%s", pInfo->threadIndex, taos_errstr(con)); - exit(1); - } - - sprintf(qstr, "use %s", pInfo->dbName); - taos_query(con, qstr); - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - - if (strcmp(stableName, "no") != 0) { - for (int64_t t = pInfo->tableBeginIndex; t < pInfo->tableEndIndex; ++t) { - sprintf(qstr, "create table if not exists %s%ld using %s tags(%ld)", stableName, t, stableName, t); - TAOS_RES *pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to create table %s%" PRId64 ", reason:%s", stableName, t, taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - } - } else { - for (int64_t t = pInfo->tableBeginIndex; t < pInfo->tableEndIndex; ++t) { - int len = sprintf(qstr, "create table if not exists %s%ld(ts timestamp", stableName, t); - for (int64_t f = 0; f < pointsPerTable; ++f) { - len += sprintf(qstr + len, ", f%ld double", f); - } - sprintf(qstr + len, ")"); - - TAOS_RES *pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to create table %s%ld, reason:%s", stableName, t, taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - } - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - float seconds = (et - st) / 1000.0 / 1000.0; - int64_t tables = pInfo->tableEndIndex - pInfo->tableBeginIndex; - pInfo->createTableSpeed = (float)tables / seconds; - pPrint("thread:%d, %.1f seconds to create %ld tables, speed:%.1f", pInfo->threadIndex, seconds, tables, - pInfo->createTableSpeed); - - if (pInfo->rowsPerTable == 0) return NULL; - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - - int64_t start = 1430000000000; - interval = 1000; // 1000 ms - - char *sql = qstr; - char inserStr[] = "insert into"; - int len = sprintf(sql, "%s", inserStr); - - for (int64_t row = 0; row < pInfo->rowsPerTable; row++) { - for (int64_t table = pInfo->tableBeginIndex; table < pInfo->tableEndIndex; ++table) { - len += sprintf(sql + len, " %s%ld values", pInfo->stableName, table); - len += sprintf(sql + len, "(%ld", start + row * interval); - for (int64_t point = 0; point < pInfo->pointsPerTable; ++point) { - len += sprintf(sql + len, ",%d", randomData[(123 * table + 456 * row + 789 * point) % MAX_RANDOM_POINTS]); - // len += sprintf(sql + len, ",%ld", row); - } - len += sprintf(sql + len, ")"); - if (len > maxBytes) { - TAOS_RES *pSql = taos_query(con, qstr); - int32_t code = taos_errno(pSql); - if (code != 0) { - pError("thread:%d, failed to insert table:%s%ld row:%ld, reason:%s", pInfo->threadIndex, pInfo->stableName, - table, row, taos_errstr(con)); - } - taos_free_result(pSql); - - // "insert into" - len = sprintf(sql, "%s", inserStr); - } - } - } - - if (len != strlen(inserStr)) { - TAOS_RES *pSql = taos_query(con, qstr); - taos_free_result(pSql); - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - int64_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; - int64_t totalRows = totalTables * pInfo->rowsPerTable; - int64_t totalPoints = totalRows * pInfo->pointsPerTable; - pPrint("thread:%d, insert finished, use %.2f seconds, tables:%ld rows:%ld points:%ld", pInfo->threadIndex, - (et - st) / 1000.0 / 1000.0, totalTables, totalRows, totalPoints); - - return NULL; -} - -void generateRandomPoints() { - for (int r = 0; r < MAX_RANDOM_POINTS; ++r) { - randomData[r] = rand() % 1000; - } -} - -void printHelp() { - char indent[10] = " "; - printf("Used to test the performance of TDengine\n After writing one row of data to all tables, write the next row\n"); - - printf("%s%s\n", indent, "-d"); - printf("%s%s%s%s\n", indent, indent, "The name of the database to be created, default is ", dbName); - printf("%s%s\n", indent, "-s"); - printf("%s%s%s%s%s\n", indent, indent, "The name of the super table to be created, default is ", stableName, ", if 'no' then create normal table"); - printf("%s%s\n", indent, "-c"); - printf("%s%s%s%s\n", indent, indent, "Configuration directory, default is ", configDir); - printf("%s%s\n", indent, "-r"); - printf("%s%s%s%ld\n", indent, indent, "Number of records to write to each table, default is ", rowsPerTable); - printf("%s%s\n", indent, "-p"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of columns per table, default is ", pointsPerTable); - printf("%s%s\n", indent, "-t"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of threads to be used, default is ", numOfThreads); - printf("%s%s\n", indent, "-n"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of tables per thread, default is ", numOfTablesPerThread); - printf("%s%s\n", indent, "-replica"); - printf("%s%s%s%d\n", indent, indent, "Database parameters replica, default is ", replica); - printf("%s%s\n", indent, "-cache"); - printf("%s%s%s%d\n", indent, indent, "Database parameters replica, default is ", cache); - printf("%s%s\n", indent, "-days"); - printf("%s%s%s%d\n", indent, indent, "Database parameters days, default is ", days); - printf("%s%s\n", indent, "-interval"); - printf("%s%s%s%d\n", indent, indent, "Interval of each rows in ms, default is ", interval); - - exit(EXIT_SUCCESS); -} - -void shellParseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-d") == 0) { - strcpy(dbName, argv[++i]); - } else if (strcmp(argv[i], "-c") == 0) { - strcpy(configDir, argv[++i]); - } else if (strcmp(argv[i], "-s") == 0) { - strcpy(stableName, argv[++i]); - } else if (strcmp(argv[i], "-r") == 0) { - rowsPerTable = atoi(argv[++i]); - } else if (strcmp(argv[i], "-p") == 0) { - pointsPerTable = atoi(argv[++i]); - } else if (strcmp(argv[i], "-t") == 0) { - numOfThreads = atoi(argv[++i]); - } else if (strcmp(argv[i], "-n") == 0) { - numOfTablesPerThread = atoi(argv[++i]); - } else if (strcmp(argv[i], "-replica") == 0) { - replica = atoi(argv[++i]); - } else if (strcmp(argv[i], "-cache") == 0) { - cache = atoi(argv[++i]); - } else if (strcmp(argv[i], "-days") == 0) { - days = atoi(argv[++i]); - } else if (strcmp(argv[i], "-interval") == 0) { - interval = atoi(argv[++i]); - } else { - } - } - - pPrint("%srowsPerTable:%" PRId64 "%s", GREEN, rowsPerTable, NC); - pPrint("%spointsPerTable:%" PRId64 "%s", GREEN, pointsPerTable, NC); - pPrint("%snumOfThreads:%" PRId64 "%s", GREEN, numOfThreads, NC); - pPrint("%snumOfTablesPerThread:%" PRId64 "%s", GREEN, numOfTablesPerThread, NC); - pPrint("%scache:%" PRId32 "%s", GREEN, cache, NC); - pPrint("%stables:%" PRId32 "%s", GREEN, replica, NC); - pPrint("%sdbName:%s%s", GREEN, dbName, NC); - pPrint("%stableName:%s%s", GREEN, stableName, NC); - pPrint("%sstart to run%s", GREEN, NC); -} diff --git a/tests/test/c/insertPerTable.c b/tests/test/c/insertPerTable.c deleted file mode 100644 index ac3c06f0f314d6c5839bf8cfd26419c3988a6ed6..0000000000000000000000000000000000000000 --- a/tests/test/c/insertPerTable.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 "../../../include/client/taos.h" -#include "os.h" -#include "tglobal.h" -#include "ttimer.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -typedef struct { - int64_t rowsPerTable; - int64_t pointsPerTable; - int64_t tableBeginIndex; - int64_t tableEndIndex; - int threadIndex; - char dbName[32]; - char stableName[64]; - pthread_t thread; -} SInfo; - -void *syncTest(void *param); -void generateRandomPoints(); -void shellParseArgument(int argc, char *argv[]); -void createDbAndTable(); -void insertData(); - -int32_t randomData[MAX_RANDOM_POINTS]; -int64_t rowsPerTable = 10000; -int64_t pointsPerTable = 1; -int64_t numOfThreads = 1; -int64_t numOfTablesPerThread = 1; -char dbName[32] = "db"; -char stableName[64] = "st"; -int32_t cache = 16; -int32_t tables = 5000; - -int main(int argc, char *argv[]) { - shellParseArgument(argc, argv); - generateRandomPoints(); - taos_init(); - createDbAndTable(); - insertData(); -} - -void createDbAndTable() { - pPrint("start to create table"); - - TAOS_RES * pSql; - TAOS * con; - struct timeval systemTime; - int64_t st, et; - char qstr[64000]; - - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - - con = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (con == NULL) { - pError("failed to connect to DB, reason:%s", taos_errstr(con)); - exit(1); - } - - sprintf(qstr, "create database if not exists %s cache %d maxtables %d", dbName, cache, tables); - pSql = taos_query(con, qstr); - int32_t code = taos_errno(pSql); - if (code != 0) { - pError("failed to create database:%s, sql:%s, code:%d reason:%s", dbName, qstr, taos_errno(con), taos_errstr(con)); - exit(0); - } - - sprintf(qstr, "use %s", dbName); - pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to use db, code:%d reason:%s", taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - int64_t totalTables = numOfTablesPerThread * numOfThreads; - - if (strcmp(stableName, "no") != 0) { - int len = sprintf(qstr, "create table if not exists %s(ts timestamp", stableName); - for (int64_t f = 0; f < pointsPerTable; ++f) { - len += sprintf(qstr + len, ", f%ld double", f); - } - sprintf(qstr + len, ") tags(t int)"); - - pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to create stable, code:%d reason:%s", taos_errno(con), taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - - for (int64_t t = 0; t < totalTables; ++t) { - sprintf(qstr, "create table if not exists %s%ld using %s tags(%ld)", stableName, t, stableName, t); - pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to create table %s%" PRId64 ", reason:%s", stableName, t, taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - } - } else { - for (int64_t t = 0; t < totalTables; ++t) { - int len = sprintf(qstr, "create table if not exists %s%ld(ts timestamp", stableName, t); - for (int64_t f = 0; f < pointsPerTable; ++f) { - len += sprintf(qstr + len, ", f%ld double", f); - } - sprintf(qstr + len, ")"); - - pSql = taos_query(con, qstr); - code = taos_errno(pSql); - if (code != 0) { - pError("failed to create table %s%ld, reason:%s", stableName, t, taos_errstr(con)); - exit(0); - } - taos_free_result(pSql); - } - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - float seconds = (et - st) / 1000.0 / 1000.0; - pPrint("%.1f seconds to create %ld tables, speed:%.1f", seconds, totalTables, totalTables / seconds); - taos_close(con); -} - -void insertData() { - struct timeval systemTime; - int64_t st, et; - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - - if (rowsPerTable <= 0) { - pPrint("not insert data for rowsPerTable is :%" PRId64, rowsPerTable); - exit(0); - } else { - pPrint("%" PRId64 " threads are spawned to insert data", numOfThreads); - } - - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); - SInfo *pInfo = (SInfo *)malloc(sizeof(SInfo) * numOfThreads); - - // Start threads to write - for (int i = 0; i < numOfThreads; ++i) { - pInfo[i].rowsPerTable = rowsPerTable; - pInfo[i].pointsPerTable = pointsPerTable; - pInfo[i].tableBeginIndex = i * numOfTablesPerThread; - pInfo[i].tableEndIndex = (i + 1) * numOfTablesPerThread; - pInfo[i].threadIndex = i; - strcpy(pInfo[i].dbName, dbName); - strcpy(pInfo[i].stableName, stableName); - pthread_create(&(pInfo[i].thread), &thattr, syncTest, (void *)(pInfo + i)); - } - - taosMsleep(300); - for (int i = 0; i < numOfThreads; i++) { - pthread_join(pInfo[i].thread, NULL); - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - double seconds = (et - st) / 1000.0 / 1000.0; - - int64_t totalTables = numOfTablesPerThread * numOfThreads; - int64_t totalRows = totalTables * rowsPerTable; - int64_t totalPoints = totalTables * rowsPerTable * pointsPerTable; - double speedOfRows = totalRows / seconds; - double speedOfPoints = totalPoints / seconds; - - pPrint( - "%sall threads:%ld finished, use %.1lf seconds, tables:%.ld rows:%ld points:%ld, speed RowsPerSecond:%.1lf " - "PointsPerSecond:%.1lf%s", - GREEN, numOfThreads, seconds, totalTables, totalRows, totalPoints, speedOfRows, speedOfPoints, NC); - - pPrint("threads exit"); - - pthread_attr_destroy(&thattr); - free(pInfo); -} - -void *syncTest(void *param) { - TAOS * con; - SInfo * pInfo = (SInfo *)param; - struct timeval systemTime; - int64_t st, et; - char qstr[65000]; - int maxBytes = 60000; - - pPrint("thread:%d, start to run", pInfo->threadIndex); - - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - - con = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (con == NULL) { - pError("index:%d, failed to connect to DB, reason:%s", pInfo->threadIndex, taos_errstr(con)); - exit(1); - } - - sprintf(qstr, "use %s", pInfo->dbName); - taos_query(con, qstr); - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - - int64_t start = 1430000000000; - int64_t interval = 1000; // 1000 ms - - char *sql = qstr; - char inserStr[] = "insert into"; - int len = sprintf(sql, "%s", inserStr); - - for (int64_t table = pInfo->tableBeginIndex; table < pInfo->tableEndIndex; ++table) { - len += sprintf(sql + len, " %s%ld values", pInfo->stableName, table); - for (int64_t row = 0; row < pInfo->rowsPerTable; row++) { - len += sprintf(sql + len, "(%ld", start + row * interval); - for (int64_t point = 0; point < pInfo->pointsPerTable; ++point) { - len += sprintf(sql + len, ",%d", randomData[(123 * table + 456 * row + 789 * point) % MAX_RANDOM_POINTS]); - // len += sprintf(sql + len, ",%ld", row); - } - len += sprintf(sql + len, ")"); - if (len > maxBytes) { - TAOS_RES *pSql = taos_query(con, qstr); - int32_t code = taos_errno(pSql); - if (code != 0) { - pError("thread:%d, failed to insert table:%s%ld row:%ld, reason:%s", pInfo->threadIndex, pInfo->stableName, - table, row, taos_errstr(con)); - } - taos_free_result(pSql); - - // "insert into" - len = sprintf(sql, "%s", inserStr); - - // "insert into st1 values" - if (row != pInfo->rowsPerTable - 1) { - len += sprintf(sql + len, " %s%ld values", pInfo->stableName, table); - } - } - } - } - - if (len != strlen(inserStr)) { - taos_query(con, qstr); - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - int64_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; - int64_t totalRows = totalTables * pInfo->rowsPerTable; - int64_t totalPoints = totalRows * pInfo->pointsPerTable; - pPrint("thread:%d, insert finished, use %.2f seconds, tables:%ld rows:%ld points:%ld", pInfo->threadIndex, - (et - st) / 1000.0 / 1000.0, totalTables, totalRows, totalPoints); - - return NULL; -} - -void generateRandomPoints() { - for (int r = 0; r < MAX_RANDOM_POINTS; ++r) { - randomData[r] = rand() % 1000; - } -} - -void printHelp() { - char indent[10] = " "; - printf("Used to test the performance of TDengine\n After writing all the data in one table, start the next table\n"); - - printf("%s%s\n", indent, "-d"); - printf("%s%s%s%s\n", indent, indent, "The name of the database to be created, default is ", dbName); - printf("%s%s\n", indent, "-s"); - printf("%s%s%s%s%s\n", indent, indent, "The name of the super table to be created, default is ", stableName, ", if 'no' then create normal table"); - printf("%s%s\n", indent, "-c"); - printf("%s%s%s%s\n", indent, indent, "Configuration directory, default is ", configDir); - printf("%s%s\n", indent, "-r"); - printf("%s%s%s%ld\n", indent, indent, "Number of records to write to each table, default is ", rowsPerTable); - printf("%s%s\n", indent, "-p"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of columns per table, default is ", pointsPerTable); - printf("%s%s\n", indent, "-t"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of threads to be used, default is ", numOfThreads); - printf("%s%s\n", indent, "-n"); - printf("%s%s%s%" PRId64 "\n", indent, indent, "Number of tables per thread, default is ", numOfTablesPerThread); - printf("%s%s\n", indent, "-tables"); - printf("%s%s%s%d\n", indent, indent, "Database parameters tables, default is ", tables); - printf("%s%s\n", indent, "-cache"); - printf("%s%s%s%d\n", indent, indent, "Database parameters cache, default is ", cache); - - exit(EXIT_SUCCESS); -} - -void shellParseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-d") == 0) { - strcpy(dbName, argv[++i]); - } else if (strcmp(argv[i], "-c") == 0) { - strcpy(configDir, argv[++i]); - } else if (strcmp(argv[i], "-s") == 0) { - strcpy(stableName, argv[++i]); - } else if (strcmp(argv[i], "-r") == 0) { - rowsPerTable = atoi(argv[++i]); - } else if (strcmp(argv[i], "-p") == 0) { - pointsPerTable = atoi(argv[++i]); - } else if (strcmp(argv[i], "-t") == 0) { - numOfThreads = atoi(argv[++i]); - } else if (strcmp(argv[i], "-n") == 0) { - numOfTablesPerThread = atoi(argv[++i]); - } else if (strcmp(argv[i], "-tables") == 0) { - tables = atoi(argv[++i]); - } else if (strcmp(argv[i], "-cache") == 0) { - cache = atoi(argv[++i]); - } else { - } - } - - pPrint("%srowsPerTable:%" PRId64 "%s", GREEN, rowsPerTable, NC); - pPrint("%spointsPerTable:%" PRId64 "%s", GREEN, pointsPerTable, NC); - pPrint("%snumOfThreads:%" PRId64 "%s", GREEN, numOfThreads, NC); - pPrint("%snumOfTablesPerThread:%" PRId64 "%s", GREEN, numOfTablesPerThread, NC); - pPrint("%scache:%" PRId32 "%s", GREEN, cache, NC); - pPrint("%stables:%" PRId32 "%s", GREEN, tables, NC); - pPrint("%sdbName:%s%s", GREEN, dbName, NC); - pPrint("%stableName:%s%s", GREEN, stableName, NC); - pPrint("%sstart to run%s", GREEN, NC); -} diff --git a/tests/test/c/invalidTableId.c b/tests/test/c/invalidTableId.c deleted file mode 100644 index 286d0f12919608a6594b3f8fdc33fb863c93b3bd..0000000000000000000000000000000000000000 --- a/tests/test/c/invalidTableId.c +++ /dev/null @@ -1,220 +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 "../../../include/client/taos.h" -#include "hash.h" -#include "os.h" -#include "taoserror.h" -#include "tglobal.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -#define MAX_DB_NUM 100 -void * con; -char dbNames[MAX_DB_NUM][48]; -int32_t dbNum = 0; -void parseArgument(int argc, char *argv[]); -void connDb(); -void getDbNames(); -void printDbNames(); -void queryTables(char *dbName); -void checkTables(char *dbName); - -int main(int argc, char *argv[]) { - parseArgument(argc, argv); - taos_init(); - connDb(); - getDbNames(); - printDbNames(); - for (int dbIndex = 0; dbIndex < dbNum; ++dbIndex) { - queryTables((char*)(dbNames[dbIndex])); - checkTables((char*)(dbNames[dbIndex])); - } - - pPrint("all %d database is checked", dbNum); -} - -void connDb() { - con = taos_connect(NULL, "root", "taosdata", NULL, 0); - if (con == NULL) { - pError("failed to connect to DB, reason:%s", taos_errstr(con)); - exit(0); - } -} - -void getDbNames() { - if (dbNum != 0) return; - - char * qstr = "show databases"; - TAOS_RES *result = taos_query(con, qstr); - int32_t code = taos_errno(result); - if (result == NULL || code != 0) { - pError("failed to exec sql:%s, code:0x%x reason:%s", qstr, code & 0XFFFF, tstrerror(code)); - exit(0); - } - - TAOS_ROW row; - int num_fields = taos_num_fields(result); - if (num_fields <= 0) return; - while ((row = taos_fetch_row(result))) { - char * dbName = (char*)dbNames[dbNum]; - int32_t *length = taos_fetch_lengths(result); - int len = length[0]; - memcpy(dbName, (char *)row[0], len); - dbName[len] = 0; - dbNum++; - } - - taos_free_result(result); -} - -void printDbNames() { - for (int dbIndex = 0; dbIndex < dbNum; ++dbIndex) { - pPrint("db:%d %s", dbIndex, dbNames[dbIndex]); - } -} - -void queryTables(char *dbName) { - char qstr[1024]; - char fileName[1024]; - char ts[35] = {0}; - int32_t precision = 1000; - - sprintf(qstr, "show %s.tables", dbName); - sprintf(fileName, "%s_tables.txt", dbName); - - TAOS_RES *result = taos_query(con, qstr); - int32_t code = taos_errno(result); - if (result == NULL || code != 0) { - pError("failed to exec sql:%s, code:0x%x reason:%s", qstr, code & 0XFFFF, tstrerror(code)); - exit(0); - } - - FILE *fp = fopen(fileName, "w"); - if (!fp) return; - - TAOS_ROW row; - int32_t rows = 0; - while ((row = taos_fetch_row(result))) { - char tableName[256] = {0}; - int32_t *length = taos_fetch_lengths(result); - int len = length[0]; - memcpy(tableName, (char *)row[0], len); - tableName[len] = 0; - - int64_t t = *((int64_t *)row[1]); - time_t tt = t / 1000; - struct tm *ptm = localtime(&tt); - int32_t tl = (int32_t)strftime(ts, 35, "%Y-%m-%d %H:%M:%S", ptm); - snprintf(ts + tl, 5, ".%03ld", t % precision); - - // fprintf(fp, "%s %s\n", tableName, ts); - fprintf(fp, "%s.%s\n", dbName, tableName); - rows++; - } - - taos_free_result(result); - fclose(fp); - pPrint("db:%s has %d tables, write to %s", dbName, rows, fileName); -} - -void checkTables(char *dbName) { - char qstr[1024]; - char fileName1[1024]; - char fileName2[1024]; - - sprintf(qstr, "show %s.tables", dbName); - sprintf(fileName1, "%s_tables.txt", dbName); - sprintf(fileName2, "%s_count.txt", dbName); - - FILE *fp1 = fopen(fileName1, "r"); - if (!fp1) return; - - FILE *fp2 = fopen(fileName2, "w"); - if (!fp2) return; - - int32_t successRows = 0; - int32_t failedRows = 0; - char tbName[256]; - while (!feof(fp1)) { - int size = fscanf(fp1, "%s", tbName); - if (size <= 0) { - break; - } - - sprintf(qstr, "select count(*) from %s", tbName); - TAOS_RES *result = taos_query(con, qstr); - int32_t code = taos_errno(result); - if (result == NULL || code != 0) { - pError("failed to exec sql:%s, code:0x%x reason:%s", qstr, code & 0XFFFF, tstrerror(code)); - fprintf(fp2, "%s failed to exec sql:%s, code:0x%x reason:%s", tbName, qstr, code & 0XFFFF, tstrerror(code)); - taos_free_result(result); - failedRows++; - continue; - } - - TAOS_ROW row; - int64_t count = 0; - while ((row = taos_fetch_row(result))) { - count = *((int64_t *)row[0]); - } - fprintf(fp2, "%s %" PRId64 "\n", tbName, count); - - successRows++; - if (successRows % 1000 == 0) { - pPrint("query %d tables", successRows); - } - taos_free_result(result); - } - - fclose(fp1); - fclose(fp2); - pPrint("db:%s query tables, success:%d failed:%d write to %s", dbName, successRows, failedRows, fileName2); -} - -void printHelp() { - char indent[10] = " "; - printf("Used to checkTables\n"); - - printf("%s%s\n", indent, "-c"); - printf("%s%s%s%s\n", indent, indent, "Configuration directory, default is ", configDir); - printf("%s%s\n", indent, "-d"); - printf("%s%s%s%s\n", indent, indent, "The name of the database to be checked, default is ", "all"); - - exit(EXIT_SUCCESS); -} - -void parseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-d") == 0) { - strcpy(dbNames[0], argv[++i]); - dbNum++; - } else if (strcmp(argv[i], "-c") == 0) { - strcpy(configDir, argv[++i]); - } else { - } - } - - pPrint("%s configDir:%s %s", GREEN, configDir, NC); - pPrint("%s start to checkTables %s", GREEN, NC); -} diff --git a/tests/test/c/queryPerformance.c b/tests/test/c/queryPerformance.c deleted file mode 100644 index afe5cd0ccbf11a2ba8595666614d7faf81817fa3..0000000000000000000000000000000000000000 --- a/tests/test/c/queryPerformance.c +++ /dev/null @@ -1,183 +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 "../../../include/client/taos.h" -#include "os.h" -#include "tglobal.h" -#include "ttimer.h" -#include "tulog.h" -#include "tutil.h" - -#define MAX_RANDOM_POINTS 20000 -#define GREEN "\033[1;32m" -#define NC "\033[0m" - -typedef struct { - int64_t startTimeMs; - int64_t endTimeMs; - int threadIndex; - pthread_t thread; -} SInfo; - -void *syncTest(void *param); -void shellParseArgument(int argc, char *argv[]); -void queryData(); - -int numOfThreads = 10; -int useGlobalConn = 1; -int requestPerThread = 10000; -char requestSql[10240] = "show dnodes"; -TAOS *globalConn; - -int main(int argc, char *argv[]) { - shellParseArgument(argc, argv); - taos_init(); - queryData(); -} - -void queryData() { - struct timeval systemTime; - int64_t st, et; - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - - if (useGlobalConn) { - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - - globalConn = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (globalConn == NULL) { - pError("failed to connect to DB, reason:%s", taos_errstr(globalConn)); - exit(1); - } - } - - pPrint("%d threads are spawned to query", numOfThreads); - - gettimeofday(&systemTime, NULL); - st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - - pthread_attr_t thattr; - pthread_attr_init(&thattr); - pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE); - SInfo *pInfo = (SInfo *)malloc(sizeof(SInfo) * numOfThreads); - - // Start threads to write - for (int i = 0; i < numOfThreads; ++i) { - pInfo[i].threadIndex = i; - pthread_create(&(pInfo[i].thread), &thattr, syncTest, (void *)(pInfo + i)); - } - - taosMsleep(300); - for (int i = 0; i < numOfThreads; i++) { - pthread_join(pInfo[i].thread, NULL); - } - - gettimeofday(&systemTime, NULL); - et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - double totalTimeMs = (et - st) / 1000.0; - - int totalReq = requestPerThread * numOfThreads; - float rspTime = totalTimeMs / requestPerThread; - float qps = totalReq / (totalTimeMs / 1000); - - pPrint("%s threads:%d, totalTime %.1fms totalReq:%d qps:%.1f rspTime:%.3fms %s", GREEN, numOfThreads, totalTimeMs, - totalReq, qps, rspTime, NC); - - pthread_attr_destroy(&thattr); - free(pInfo); -} - -void *syncTest(void *param) { - TAOS * con; - SInfo * pInfo = (SInfo *)param; - char fqdn[TSDB_FQDN_LEN]; - uint16_t port; - - if (useGlobalConn) { - pPrint("thread:%d, start to run use global connection", pInfo->threadIndex); - con = globalConn; - } else { - pPrint("thread:%d, start to run, and create new conn", pInfo->threadIndex); - taosGetFqdnPortFromEp(tsFirst, fqdn, &port); - - con = taos_connect(fqdn, "root", "taosdata", NULL, port); - if (con == NULL) { - pError("index:%d, failed to connect to DB, reason:%s", pInfo->threadIndex, taos_errstr(con)); - exit(1); - } - } - - for (int i = 0; i < requestPerThread; ++i) { - void *tres = taos_query(con, requestSql); - - TAOS_ROW row = taos_fetch_row(tres); - if (row == NULL) { - taos_free_result(tres); - exit(0); - } - - do { - row = taos_fetch_row(tres); - } while (row != NULL); - - taos_free_result(tres); - } - return NULL; -} - -void printHelp() { - char indent[10] = " "; - printf("Used to test the query performance of TDengine\n"); - - printf("%s%s\n", indent, "-c"); - printf("%s%s%s%s\n", indent, indent, "Configuration directory, default is ", configDir); - printf("%s%s\n", indent, "-s"); - printf("%s%s%s%s\n", indent, indent, "The sql to be executed, default is ", requestSql); - printf("%s%s\n", indent, "-r"); - printf("%s%s%s%d\n", indent, indent, "Request per thread, default is ", requestPerThread); - printf("%s%s\n", indent, "-t"); - printf("%s%s%s%d\n", indent, indent, "Number of threads to be used, default is ", numOfThreads); - printf("%s%s\n", indent, "-g"); - printf("%s%s%s%d\n", indent, indent, "Whether to share connections between threads, default is ", useGlobalConn); - - exit(EXIT_SUCCESS); -} - -void shellParseArgument(int argc, char *argv[]) { - for (int i = 1; i < argc; i++) { - if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { - printHelp(); - exit(0); - } else if (strcmp(argv[i], "-c") == 0) { - strcpy(configDir, argv[++i]); - } else if (strcmp(argv[i], "-s") == 0) { - strcpy(requestSql, argv[++i]); - } else if (strcmp(argv[i], "-r") == 0) { - requestPerThread = atoi(argv[++i]); - } else if (strcmp(argv[i], "-t") == 0) { - numOfThreads = atoi(argv[++i]); - } else if (strcmp(argv[i], "-g") == 0) { - useGlobalConn = atoi(argv[++i]); - } else { - } - } - - pPrint("%s sql:%s %s", GREEN, requestSql, NC); - pPrint("%s requestPerThread:%d %s", GREEN, requestPerThread, NC); - pPrint("%s numOfThreads:%d %s", GREEN, numOfThreads, NC); - pPrint("%s useGlobalConn:%d %s", GREEN, useGlobalConn, NC); - pPrint("%s start to run %s", GREEN, NC); -} diff --git a/tools/shell/CMakeLists.txt b/tools/shell/CMakeLists.txt index def421c21230a05fbec31b1cd8fe8f528e33638a..b351675e4784a2ce31f321d8e224dc802fef1399 100644 --- a/tools/shell/CMakeLists.txt +++ b/tools/shell/CMakeLists.txt @@ -1,6 +1,4 @@ aux_source_directory(src SHELL_SRC) -list(REMOVE_ITEM SHELL_SRC src/shellWindows.c) -list(REMOVE_ITEM SHELL_SRC src/shellDarwin.c) add_executable(shell ${SHELL_SRC}) target_link_libraries(