提交 df554c03 编写于 作者: L Liu Jicong

handle merge conflict

...@@ -6,28 +6,32 @@ ...@@ -6,28 +6,32 @@
"dockerfile": "Dockerfile", "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 // 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 // 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. // Set *default* container specific settings.json values on container create.
"settings": {}, "settings": {},
// Add the IDs of extensions you want installed when the container is created. // Add the IDs of extensions you want installed when the container is created.
"extensions": [ "extensions": [
"ms-vscode.cpptools", "ms-vscode.cpptools",
"ms-vscode.cmake-tools", "ms-vscode.cmake-tools",
"austin.code-gnu-global", "austin.code-gnu-global",
"visualstudioexptteam.vscodeintel", "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. // Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [], // "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created. // Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "gcc -v", // "postCreateCommand": "gcc -v",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "root" "remoteUser": "root"
} }
\ No newline at end of file
...@@ -156,10 +156,6 @@ typedef struct { ...@@ -156,10 +156,6 @@ typedef struct {
uint16_t port; uint16_t port;
} SEpAddr; } SEpAddr;
typedef struct {
int32_t numOfVnodes;
} SMsgDesc;
typedef struct SMsgHead { typedef struct SMsgHead {
int32_t contLen; int32_t contLen;
int32_t vgId; int32_t vgId;
...@@ -341,7 +337,7 @@ typedef struct { ...@@ -341,7 +337,7 @@ typedef struct {
int64_t clusterId; int64_t clusterId;
int32_t connId; int32_t connId;
int8_t superUser; int8_t superUser;
int8_t reserved[5]; int8_t align[3];
SEpSet epSet; SEpSet epSet;
} SConnectRsp; } SConnectRsp;
...@@ -354,21 +350,18 @@ typedef struct { ...@@ -354,21 +350,18 @@ typedef struct {
int32_t maxStreams; int32_t maxStreams;
int32_t accessState; // Configured only by command int32_t accessState; // Configured only by command
int64_t maxStorage; // In unit of GB int64_t maxStorage; // In unit of GB
int32_t reserve[8]; } SCreateAcctReq, SAlterAcctReq;
} SCreateAcctMsg, SAlterAcctMsg;
typedef struct { typedef struct {
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
int32_t reserve[8]; } SDropUserReq, SDropAcctReq;
} SDropUserMsg, SDropAcctMsg;
typedef struct { typedef struct {
int8_t type; int8_t type;
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
char pass[TSDB_PASSWORD_LEN]; char pass[TSDB_PASSWORD_LEN];
int8_t superUser; // denote if it is a super user or not int8_t superUser; // denote if it is a super user or not
int32_t reserve[8]; } SCreateUserReq, SAlterUserReq;
} SCreateUserMsg, SAlterUserMsg;
typedef struct { typedef struct {
int32_t contLen; int32_t contLen;
...@@ -522,7 +515,7 @@ typedef struct { ...@@ -522,7 +515,7 @@ typedef struct {
int64_t qId; int64_t qId;
}; // query handle }; // query handle
int8_t free; int8_t free;
} SRetrieveTableMsg; } SRetrieveTableReq;
typedef struct SRetrieveTableRsp { typedef struct SRetrieveTableRsp {
int64_t useconds; int64_t useconds;
...@@ -556,7 +549,6 @@ typedef struct { ...@@ -556,7 +549,6 @@ typedef struct {
int8_t update; int8_t update;
int8_t cacheLastRow; int8_t cacheLastRow;
int8_t ignoreExist; int8_t ignoreExist;
int32_t reserve[8];
} SCreateDbMsg; } SCreateDbMsg;
typedef struct { typedef struct {
...@@ -569,29 +561,24 @@ typedef struct { ...@@ -569,29 +561,24 @@ typedef struct {
int8_t walLevel; int8_t walLevel;
int8_t quorum; int8_t quorum;
int8_t cacheLastRow; int8_t cacheLastRow;
int32_t reserve[8];
} SAlterDbMsg; } SAlterDbMsg;
typedef struct { typedef struct {
char db[TSDB_TABLE_FNAME_LEN]; char db[TSDB_TABLE_FNAME_LEN];
int8_t ignoreNotExists; int8_t ignoreNotExists;
int32_t reserve[8];
} SDropDbMsg; } SDropDbMsg;
typedef struct { typedef struct {
char db[TSDB_TABLE_FNAME_LEN]; char db[TSDB_TABLE_FNAME_LEN];
int32_t vgVersion; int32_t vgVersion;
int32_t reserve[8];
} SUseDbMsg; } SUseDbMsg;
typedef struct { typedef struct {
char db[TSDB_TABLE_FNAME_LEN]; char db[TSDB_TABLE_FNAME_LEN];
int32_t reserve[8];
} SSyncDbMsg; } SSyncDbMsg;
typedef struct { typedef struct {
char db[TSDB_TABLE_FNAME_LEN]; char db[TSDB_TABLE_FNAME_LEN];
int32_t reserve[8];
} SCompactDbMsg; } SCompactDbMsg;
typedef struct { typedef struct {
...@@ -647,7 +634,7 @@ typedef struct { ...@@ -647,7 +634,7 @@ typedef struct {
typedef struct { typedef struct {
int32_t vgId; int32_t vgId;
int8_t role; int8_t role;
int8_t reserved[3]; int8_t align[3];
int64_t totalStorage; int64_t totalStorage;
int64_t compStorage; int64_t compStorage;
int64_t pointsWritten; int64_t pointsWritten;
...@@ -684,7 +671,7 @@ typedef struct { ...@@ -684,7 +671,7 @@ typedef struct {
typedef struct { typedef struct {
int32_t id; int32_t id;
int8_t isMnode; int8_t isMnode;
int8_t reserved; int8_t align;
uint16_t port; uint16_t port;
char fqdn[TSDB_FQDN_LEN]; char fqdn[TSDB_FQDN_LEN];
} SDnodeEp; } SDnodeEp;
...@@ -830,7 +817,7 @@ typedef struct { ...@@ -830,7 +817,7 @@ typedef struct {
char db[TSDB_DB_FNAME_LEN]; char db[TSDB_DB_FNAME_LEN];
int16_t payloadLen; int16_t payloadLen;
char payload[]; char payload[];
} SShowMsg; } SShowReq;
typedef struct { typedef struct {
char db[TSDB_DB_FNAME_LEN]; char db[TSDB_DB_FNAME_LEN];
...@@ -869,15 +856,15 @@ typedef struct { ...@@ -869,15 +856,15 @@ typedef struct {
typedef struct { typedef struct {
int32_t dnodeId; int32_t dnodeId;
} SMCreateQnodeMsg, SMDropQnodeMsg, SDCreateQnodeMsg, SDDropQnodeMsg; } SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq;
typedef struct { typedef struct {
int32_t dnodeId; int32_t dnodeId;
} SMCreateSnodeMsg, SMDropSnodeMsg, SDCreateSnodeMsg, SDDropSnodeMsg; } SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
typedef struct { typedef struct {
int32_t dnodeId; int32_t dnodeId;
} SMCreateBnodeMsg, SMDropBnodeMsg, SDCreateBnodeMsg, SDDropBnodeMsg; } SMCreateBnodeReq, SMDropBnodeReq, SDCreateBnodeReq, SDDropBnodeReq;
typedef struct { typedef struct {
int32_t dnodeId; int32_t dnodeId;
...@@ -920,7 +907,7 @@ typedef struct { ...@@ -920,7 +907,7 @@ typedef struct {
int32_t totalDnodes; int32_t totalDnodes;
int32_t onlineDnodes; int32_t onlineDnodes;
int8_t killConnection; int8_t killConnection;
int8_t reserved[3]; int8_t align[3];
SEpSet epSet; SEpSet epSet;
} SHeartBeatRsp; } SHeartBeatRsp;
...@@ -948,7 +935,7 @@ typedef struct { ...@@ -948,7 +935,7 @@ typedef struct {
typedef struct { typedef struct {
int8_t finished; int8_t finished;
int8_t reserved1[7]; int8_t align[7];
char name[TSDB_STEP_NAME_LEN]; char name[TSDB_STEP_NAME_LEN];
char desc[TSDB_STEP_DESC_LEN]; char desc[TSDB_STEP_DESC_LEN];
} SStartupMsg; } SStartupMsg;
...@@ -1059,6 +1046,7 @@ typedef struct SResFetchMsg { ...@@ -1059,6 +1046,7 @@ typedef struct SResFetchMsg {
} SResFetchMsg; } SResFetchMsg;
typedef struct SSchTasksStatusMsg { typedef struct SSchTasksStatusMsg {
SMsgHead header;
uint64_t sId; uint64_t sId;
} SSchTasksStatusMsg; } SSchTasksStatusMsg;
...@@ -1074,6 +1062,7 @@ typedef struct SSchedulerStatusRsp { ...@@ -1074,6 +1062,7 @@ typedef struct SSchedulerStatusRsp {
} SSchedulerStatusRsp; } SSchedulerStatusRsp;
typedef struct STaskCancelMsg { typedef struct STaskCancelMsg {
SMsgHead header;
uint64_t sId; uint64_t sId;
uint64_t queryId; uint64_t queryId;
uint64_t taskId; uint64_t taskId;
...@@ -1084,6 +1073,7 @@ typedef struct STaskCancelRsp { ...@@ -1084,6 +1073,7 @@ typedef struct STaskCancelRsp {
} STaskCancelRsp; } STaskCancelRsp;
typedef struct STaskDropMsg { typedef struct STaskDropMsg {
SMsgHead header;
uint64_t sId; uint64_t sId;
uint64_t queryId; uint64_t queryId;
uint64_t taskId; uint64_t taskId;
......
...@@ -23,9 +23,9 @@ extern "C" { ...@@ -23,9 +23,9 @@ extern "C" {
/* ------------------------ TYPES EXPOSED ------------------------ */ /* ------------------------ TYPES EXPOSED ------------------------ */
typedef struct SDnode SDnode; typedef struct SDnode SDnode;
typedef struct SBnode SBnode; typedef struct SBnode SBnode;
typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
typedef struct { typedef struct {
int64_t numOfErrors; int64_t numOfErrors;
...@@ -40,9 +40,9 @@ typedef struct { ...@@ -40,9 +40,9 @@ typedef struct {
int64_t clusterId; int64_t clusterId;
SBnodeCfg cfg; SBnodeCfg cfg;
SDnode *pDnode; SDnode *pDnode;
SendMsgToDnodeFp sendMsgToDnodeFp; SendReqToDnodeFp sendReqToDnodeFp;
SendMsgToMnodeFp sendMsgToMnodeFp; SendReqToMnodeFp sendReqToMnodeFp;
SendRedirectMsgFp sendRedirectMsgFp; SendRedirectRspFp sendRedirectRspFp;
} SBnodeOpt; } SBnodeOpt;
/* ------------------------ SBnode ------------------------ */ /* ------------------------ SBnode ------------------------ */
......
...@@ -24,9 +24,10 @@ extern "C" { ...@@ -24,9 +24,10 @@ extern "C" {
typedef struct SDnode SDnode; typedef struct SDnode SDnode;
typedef struct SMnode SMnode; typedef struct SMnode SMnode;
typedef struct SMnodeMsg SMnodeMsg; typedef struct SMnodeMsg SMnodeMsg;
typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
typedef void (*SendRedirectMsgFp)(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 { typedef struct SMnodeLoad {
int64_t numOfDnode; int64_t numOfDnode;
...@@ -62,9 +63,10 @@ typedef struct { ...@@ -62,9 +63,10 @@ typedef struct {
SReplica replicas[TSDB_MAX_REPLICA]; SReplica replicas[TSDB_MAX_REPLICA];
SMnodeCfg cfg; SMnodeCfg cfg;
SDnode *pDnode; SDnode *pDnode;
SendMsgToDnodeFp sendMsgToDnodeFp; PutReqToMWriteQFp putReqToMWriteQFp;
SendMsgToMnodeFp sendMsgToMnodeFp; SendReqToDnodeFp sendReqToDnodeFp;
SendRedirectMsgFp sendRedirectMsgFp; SendReqToMnodeFp sendReqToMnodeFp;
SendRedirectRspFp sendRedirectRspFp;
} SMnodeOpt; } SMnodeOpt;
/* ------------------------ SMnode ------------------------ */ /* ------------------------ SMnode ------------------------ */
......
...@@ -22,121 +22,70 @@ ...@@ -22,121 +22,70 @@
extern "C" { extern "C" {
#endif #endif
#define SDB_GET_INT64(pData, pRow, dataPos, val) \ #define SDB_GET_VAL(pData, dataPos, val, pos, func, type) \
{ \ { \
if (sdbGetRawInt64(pRaw, dataPos, val) != 0) { \ if (func(pRaw, dataPos, val) != 0) { \
tfree(pRow); \ goto pos; \
return NULL; \
} \ } \
dataPos += sizeof(int64_t); \ dataPos += sizeof(type); \
} }
#define SDB_GET_INT32(pData, pRow, dataPos, val) \ #define SDB_GET_BINARY(pRaw, dataPos, val, valLen, pos) \
{ \ { \
if (sdbGetRawInt32(pRaw, dataPos, val) != 0) { \ if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
tfree(pRow); \ goto pos; \
return NULL; \
} \ } \
dataPos += sizeof(int32_t); \ dataPos += valLen; \
} }
#define SDB_GET_INT16(pData, pRow, dataPos, val) \ #define SDB_GET_INT64(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt64, int64_t)
{ \
if (sdbGetRawInt16(pRaw, dataPos, val) != 0) { \
tfree(pRow); \
return NULL; \
} \
dataPos += sizeof(int16_t); \
}
#define SDB_GET_INT8(pData, pRow, dataPos, val) \ #define SDB_GET_INT32(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt32, int32_t)
{ \
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_INT16(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt16, int16_t)
{ \
if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \ #define SDB_GET_INT8(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt8, int8_t)
tfree(pRow); \
return NULL; \
} \
dataPos += valLen; \
}
#define SDB_GET_RESERVE(pRaw, pRow, dataPos, valLen) \ #define SDB_GET_RESERVE(pRaw, dataPos, valLen, pos) \
{ \ { \
char val[valLen] = {0}; \ char val[valLen] = {0}; \
if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \ SDB_GET_BINARY(pRaw, dataPos, val, valLen, pos) \
tfree(pRow); \
return NULL; \
} \
dataPos += valLen; \
} }
#define SDB_SET_INT64(pRaw, dataPos, val) \ #define SDB_SET_VAL(pRaw, dataPos, val, pos, func, type) \
{ \ { \
if (sdbSetRawInt64(pRaw, dataPos, val) != 0) { \ if (func(pRaw, dataPos, val) != 0) { \
sdbFreeRaw(pRaw); \ goto pos; \
return NULL; \
} \ } \
dataPos += sizeof(int64_t); \ dataPos += sizeof(type); \
} }
#define SDB_SET_INT32(pRaw, dataPos, val) \ #define SDB_SET_INT64(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt64, int64_t)
{ \
if (sdbSetRawInt32(pRaw, dataPos, val) != 0) { \
sdbFreeRaw(pRaw); \
return NULL; \
} \
dataPos += sizeof(int32_t); \
}
#define SDB_SET_INT16(pRaw, dataPos, val) \ #define SDB_SET_INT32(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt32, int32_t)
{ \
if (sdbSetRawInt16(pRaw, dataPos, val) != 0) { \
sdbFreeRaw(pRaw); \
return NULL; \
} \
dataPos += sizeof(int16_t); \
}
#define SDB_SET_INT8(pRaw, dataPos, val) \ #define SDB_SET_INT16(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt16, int16_t)
{ \
if (sdbSetRawInt8(pRaw, dataPos, val) != 0) { \
sdbFreeRaw(pRaw); \
return NULL; \
} \
dataPos += sizeof(int8_t); \
}
#define SDB_SET_BINARY(pRaw, dataPos, val, valLen) \ #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) { \ if (sdbSetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
sdbFreeRaw(pRaw); \ goto pos; \
return NULL; \
} \ } \
dataPos += valLen; \ dataPos += valLen; \
} }
#define SDB_SET_RESERVE(pRaw, dataPos, valLen) \ #define SDB_SET_RESERVE(pRaw, dataPos, valLen, pos) \
{ \ { \
char val[valLen] = {0}; \ char val[valLen] = {0}; \
if (sdbSetRawBinary(pRaw, dataPos, val, valLen) != 0) { \ SDB_SET_BINARY(pRaw, dataPos, val, valLen, pos) \
sdbFreeRaw(pRaw); \
return NULL; \
} \
dataPos += valLen; \
} }
#define SDB_SET_DATALEN(pRaw, dataLen) \ #define SDB_SET_DATALEN(pRaw, dataLen, pos) \
{ \ { \
if (sdbSetRawDataLen(pRaw, dataLen) != 0) { \ if (sdbSetRawDataLen(pRaw, dataLen) != 0) { \
sdbFreeRaw(pRaw); \ goto pos; \
return NULL; \
} \ } \
} }
...@@ -145,6 +94,7 @@ typedef struct SSdbRaw SSdbRaw; ...@@ -145,6 +94,7 @@ typedef struct SSdbRaw SSdbRaw;
typedef struct SSdbRow SSdbRow; typedef struct SSdbRow SSdbRow;
typedef enum { SDB_KEY_BINARY = 1, SDB_KEY_INT32 = 2, SDB_KEY_INT64 = 3 } EKeyType; typedef enum { SDB_KEY_BINARY = 1, SDB_KEY_INT32 = 2, SDB_KEY_INT64 = 3 } EKeyType;
typedef enum { typedef enum {
SDB_STATUS_INIT = 0,
SDB_STATUS_CREATING = 1, SDB_STATUS_CREATING = 1,
SDB_STATUS_UPDATING = 2, SDB_STATUS_UPDATING = 2,
SDB_STATUS_DROPPING = 3, SDB_STATUS_DROPPING = 3,
...@@ -153,25 +103,24 @@ typedef enum { ...@@ -153,25 +103,24 @@ typedef enum {
} ESdbStatus; } ESdbStatus;
typedef enum { typedef enum {
SDB_START = 0, SDB_TRANS = 0,
SDB_TRANS = 1, SDB_CLUSTER = 1,
SDB_CLUSTER = 2, SDB_MNODE = 2,
SDB_MNODE = 3, SDB_QNODE = 3,
SDB_QNODE = 4, SDB_SNODE = 4,
SDB_SNODE = 5, SDB_BNODE = 5,
SDB_BNODE = 6, SDB_DNODE = 6,
SDB_DNODE = 7, SDB_USER = 7,
SDB_USER = 8, SDB_AUTH = 8,
SDB_AUTH = 9, SDB_ACCT = 9,
SDB_ACCT = 10, SDB_CONSUMER = 10,
SDB_CONSUMER = 11, SDB_CGROUP = 11,
SDB_CGROUP = 12, SDB_TOPIC = 12,
SDB_TOPIC = 13, SDB_VGROUP = 13,
SDB_VGROUP = 14, SDB_STB = 14,
SDB_STB = 15, SDB_DB = 15,
SDB_DB = 16, SDB_FUNC = 16,
SDB_FUNC = 17, SDB_MAX = 17
SDB_MAX = 18
} ESdbType; } ESdbType;
typedef struct SSdb SSdb; typedef struct SSdb SSdb;
...@@ -239,6 +188,14 @@ int32_t sdbDeploy(SSdb *pSdb); ...@@ -239,6 +188,14 @@ int32_t sdbDeploy(SSdb *pSdb);
*/ */
int32_t sdbReadFile(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 * @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 ...@@ -311,7 +268,7 @@ void sdbTraverse(SSdb *pSdb, ESdbType type, sdbTraverseFp fp, void *p1, void *p2
* *
* @param pSdb The sdb object. * @param pSdb The sdb object.
* @param pIter The type of the table. * @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); int32_t sdbGetSize(SSdb *pSdb, ESdbType type);
...@@ -320,10 +277,19 @@ int32_t sdbGetSize(SSdb *pSdb, ESdbType type); ...@@ -320,10 +277,19 @@ int32_t sdbGetSize(SSdb *pSdb, ESdbType type);
* *
* @param pSdb The sdb object. * @param pSdb The sdb object.
* @param pIter The type of the table. * @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); 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); SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen);
void sdbFreeRaw(SSdbRaw *pRaw); void sdbFreeRaw(SSdbRaw *pRaw);
int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val); int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val);
......
...@@ -23,9 +23,9 @@ extern "C" { ...@@ -23,9 +23,9 @@ extern "C" {
/* ------------------------ TYPES EXPOSED ------------------------ */ /* ------------------------ TYPES EXPOSED ------------------------ */
typedef struct SDnode SDnode; typedef struct SDnode SDnode;
typedef struct SQnode SQnode; typedef struct SQnode SQnode;
typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
typedef struct { typedef struct {
int64_t numOfStartTask; int64_t numOfStartTask;
...@@ -47,9 +47,9 @@ typedef struct { ...@@ -47,9 +47,9 @@ typedef struct {
int64_t clusterId; int64_t clusterId;
SQnodeCfg cfg; SQnodeCfg cfg;
SDnode *pDnode; SDnode *pDnode;
SendMsgToDnodeFp sendMsgToDnodeFp; SendReqToDnodeFp sendReqToDnodeFp;
SendMsgToMnodeFp sendMsgToMnodeFp; SendReqToMnodeFp sendReqToMnodeFp;
SendRedirectMsgFp sendRedirectMsgFp; SendRedirectRspFp sendRedirectRspFp;
} SQnodeOpt; } SQnodeOpt;
/* ------------------------ SQnode ------------------------ */ /* ------------------------ SQnode ------------------------ */
......
...@@ -23,9 +23,9 @@ extern "C" { ...@@ -23,9 +23,9 @@ extern "C" {
/* ------------------------ TYPES EXPOSED ------------------------ */ /* ------------------------ TYPES EXPOSED ------------------------ */
typedef struct SDnode SDnode; typedef struct SDnode SDnode;
typedef struct SSnode SSnode; typedef struct SSnode SSnode;
typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
typedef struct { typedef struct {
int64_t numOfErrors; int64_t numOfErrors;
...@@ -40,9 +40,9 @@ typedef struct { ...@@ -40,9 +40,9 @@ typedef struct {
int64_t clusterId; int64_t clusterId;
SSnodeCfg cfg; SSnodeCfg cfg;
SDnode *pDnode; SDnode *pDnode;
SendMsgToDnodeFp sendMsgToDnodeFp; SendReqToDnodeFp sendReqToDnodeFp;
SendMsgToMnodeFp sendMsgToMnodeFp; SendReqToMnodeFp sendReqToMnodeFp;
SendRedirectMsgFp sendRedirectMsgFp; SendRedirectRspFp sendRedirectRspFp;
} SSnodeOpt; } SSnodeOpt;
/* ------------------------ SSnode ------------------------ */ /* ------------------------ SSnode ------------------------ */
......
...@@ -50,6 +50,7 @@ typedef struct SCatalogCfg { ...@@ -50,6 +50,7 @@ typedef struct SCatalogCfg {
uint32_t maxDBCacheNum; uint32_t maxDBCacheNum;
} SCatalogCfg; } SCatalogCfg;
int32_t catalogInit(SCatalogCfg *cfg); int32_t catalogInit(SCatalogCfg *cfg);
/** /**
...@@ -87,26 +88,40 @@ int32_t catalogUpdateDBVgroup(struct SCatalog* pCatalog, const char* dbName, SDB ...@@ -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); 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. * Force renew a table's local cached meta data.
* @param pCatalog (input, got with catalogGetHandle) * @param pCatalog (input, got with catalogGetHandle)
* @param pRpc (input, rpc object) * @param pTransporter (input, rpc object)
* @param pMgmtEps (input, mnode EPs) * @param pMgmtEps (input, mnode EPs)
* @param pTableName (input, table name, NOT including db name) * @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 * @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. * Force renew a table's local cached meta data and get the new one.
* @param pCatalog (input, got with catalogGetHandle) * @param pCatalog (input, got with catalogGetHandle)
* @param pRpc (input, rpc object) * @param pTransporter (input, rpc object)
* @param pMgmtEps (input, mnode EPs) * @param pMgmtEps (input, mnode EPs)
* @param pTableName (input, table name, NOT including db name) * @param pTableName (input, table name, NOT including db name)
* @param pTableMeta(output, table meta data, NEED to free it by calller) * @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 * @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);
/** /**
......
...@@ -154,14 +154,14 @@ typedef struct SVgDataBlocks { ...@@ -154,14 +154,14 @@ typedef struct SVgDataBlocks {
char *pData; // SMsgDesc + SSubmitMsg + SSubmitBlk + ... char *pData; // SMsgDesc + SSubmitMsg + SSubmitBlk + ...
} SVgDataBlocks; } SVgDataBlocks;
typedef struct SInsertStmtInfo { typedef struct SVnodeModifOpStmtInfo {
int16_t nodeType; int16_t nodeType;
SArray* pDataBlocks; // data block for each vgroup, SArray<SVgDataBlocks*>. SArray* pDataBlocks; // data block for each vgroup, SArray<SVgDataBlocks*>.
int8_t schemaAttache; // denote if submit block is built with table schema or not 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 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] uint32_t insertType; // insert data from [file|sql statement| bound statement]
const char* sql; // current sql statement position const char* sql; // current sql statement position
} SInsertStmtInfo; } SVnodeModifOpStmtInfo;
typedef struct SDclStmtInfo { typedef struct SDclStmtInfo {
int16_t nodeType; int16_t nodeType;
......
...@@ -43,7 +43,7 @@ int32_t qParseQuerySql(SParseContext* pContext, SQueryNode** pQuery); ...@@ -43,7 +43,7 @@ int32_t qParseQuerySql(SParseContext* pContext, SQueryNode** pQuery);
bool qIsDdlQuery(const 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 * 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
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#include "query.h"
#include "tmsg.h" #include "tmsg.h"
#include "tarray.h" #include "tarray.h"
...@@ -121,9 +122,10 @@ typedef struct SSubplanId { ...@@ -121,9 +122,10 @@ typedef struct SSubplanId {
typedef struct SSubplan { 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 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. int32_t msgType; // message type for subplan, used to denote the send message type to vnode.
SEpSet execEpSet; // for the scan/modify subplan, the optional execution node int32_t level; // the execution level of current subplan, starting from 0 in a top-down manner.
SArray *pChildern; // the datasource subplan,from which to fetch the result 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 SArray *pParents; // the data destination subplan, get data from current subplan
SPhyNode *pNode; // physical plan of current subplan SPhyNode *pNode; // physical plan of current subplan
SDataSink *pDataSink; // data of the subplan flow into the datasink SDataSink *pDataSink; // data of the subplan flow into the datasink
...@@ -140,13 +142,13 @@ struct SQueryNode; ...@@ -140,13 +142,13 @@ struct SQueryNode;
/** /**
* Create the physical plan for the query, according to the AST. * 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. // Set datasource of this subplan, multiple calls may be made to a subplan.
// @subplan subplan to be schedule // @subplan subplan to be schedule
// @templateId templateId of a group of datasource subplans of this @subplan // @templateId templateId of a group of datasource subplans of this @subplan
// @ep one execution location of this group of datasource subplans // @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); int32_t qExplainQuery(const struct SQueryNode* pQueryInfo, struct SEpSet* pQnode, char** str);
......
...@@ -111,6 +111,13 @@ typedef struct SMsgSendInfo { ...@@ -111,6 +111,13 @@ typedef struct SMsgSendInfo {
SDataBuf msgInfo; SDataBuf msgInfo;
} SMsgSendInfo; } 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); bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags);
int32_t initTaskQueue(); int32_t initTaskQueue();
......
...@@ -50,13 +50,6 @@ typedef struct SQueryProfileSummary { ...@@ -50,13 +50,6 @@ typedef struct SQueryProfileSummary {
uint64_t resultSize; // generated result size in Kb. uint64_t resultSize; // generated result size in Kb.
} SQueryProfileSummary; } 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 { typedef struct SQueryResult {
int32_t code; int32_t code;
uint64_t numOfRows; uint64_t numOfRows;
......
...@@ -22,11 +22,13 @@ extern "C" { ...@@ -22,11 +22,13 @@ extern "C" {
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <dirent.h>
#include <errno.h> #include <errno.h>
#include <float.h> #include <float.h>
#include <inttypes.h> #include <inttypes.h>
#include <locale.h> #include <locale.h>
#include <math.h> #include <math.h>
#include <sched.h>
#include <setjmp.h> #include <setjmp.h>
#include <signal.h> #include <signal.h>
#include <stdarg.h> #include <stdarg.h>
...@@ -36,19 +38,14 @@ extern "C" { ...@@ -36,19 +38,14 @@ extern "C" {
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h>
#include <wctype.h>
#include <wchar.h>
#include <sched.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <math.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <dirent.h>
#include <unistd.h> #include <unistd.h>
#include <wchar.h>
#include <wctype.h>
#include <sys/mman.h>
#include "osAtomic.h" #include "osAtomic.h"
#include "osDef.h" #include "osDef.h"
......
...@@ -54,7 +54,7 @@ bool taosGetSysMemory(float *memoryUsedMB); ...@@ -54,7 +54,7 @@ bool taosGetSysMemory(float *memoryUsedMB);
void taosPrintOsInfo(); void taosPrintOsInfo();
int taosSystem(const char *cmd); int taosSystem(const char *cmd);
void taosKillSystem(); void taosKillSystem();
int32_t taosGetSystemUid(char *uid, int32_t uidlen); int32_t taosGetSystemUUID(char *uid, int32_t uidlen);
char * taosGetCmdlineByPID(int pid); char * taosGetCmdlineByPID(int pid);
void taosSetCoreDump(bool enable); void taosSetCoreDump(bool enable);
...@@ -68,8 +68,6 @@ typedef struct { ...@@ -68,8 +68,6 @@ typedef struct {
SysNameInfo taosGetSysNameInfo(); SysNameInfo taosGetSysNameInfo();
int64_t taosGetPid();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -160,6 +160,7 @@ int32_t* taosGetErrno(); ...@@ -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_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_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_DATA_CONTENT TAOS_DEF_ERROR_CODE(0, 0x033B)
#define TSDB_CODE_SDB_INVALID_WAl_VER TAOS_DEF_ERROR_CODE(0, 0x033C)
// mnode-dnode // mnode-dnode
#define TSDB_CODE_MND_DNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0340) #define TSDB_CODE_MND_DNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0340)
...@@ -252,7 +253,7 @@ int32_t* taosGetErrno(); ...@@ -252,7 +253,7 @@ int32_t* taosGetErrno();
// dnode // dnode
#define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0400) #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_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_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0410)
#define TSDB_CODE_DND_DNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0411) #define TSDB_CODE_DND_DNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0411)
......
...@@ -43,7 +43,7 @@ int32_t tfFsync(int64_t tfd); ...@@ -43,7 +43,7 @@ int32_t tfFsync(int64_t tfd);
bool tfValid(int64_t tfd); bool tfValid(int64_t tfd);
int64_t tfLseek(int64_t tfd, int64_t offset, int32_t whence); int64_t tfLseek(int64_t tfd, int64_t offset, int32_t whence);
int32_t tfFtruncate(int64_t tfd, int64_t length); int32_t tfFtruncate(int64_t tfd, int64_t length);
void * tfMmapReadOnly(int64_t tfd, int64_t length);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -24,7 +24,7 @@ extern "C" { ...@@ -24,7 +24,7 @@ extern "C" {
#include "tlockfree.h" #include "tlockfree.h"
typedef uint32_t (*_hash_fn_t)(const char *, uint32_t); 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_before_fn_t)(void *);
typedef void (*_hash_free_fn_t)(void *); typedef void (*_hash_free_fn_t)(void *);
......
...@@ -146,6 +146,8 @@ int taos_init(); ...@@ -146,6 +146,8 @@ int taos_init();
void* createTscObj(const char* user, const char* auth, const char *db, SAppInstInfo* pAppInfo); void* createTscObj(const char* user, const char* auth, const char *db, SAppInstInfo* pAppInfo);
void destroyTscObj(void*pObj); void destroyTscObj(void*pObj);
uint64_t generateRequestId();
void *createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type); void *createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type);
void destroyRequest(SRequestObj* pRequest); void destroyRequest(SRequestObj* pRequest);
......
...@@ -53,8 +53,8 @@ static void registerRequest(SRequestObj* pRequest) { ...@@ -53,8 +53,8 @@ static void registerRequest(SRequestObj* pRequest) {
int32_t total = atomic_add_fetch_32(&pSummary->totalRequests, 1); int32_t total = atomic_add_fetch_32(&pSummary->totalRequests, 1);
int32_t currentInst = atomic_add_fetch_32(&pSummary->currentRequests, 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, 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->pTscObj->id, num, currentInst, total, pRequest->requestId);
} }
} }
...@@ -87,6 +87,7 @@ static void tscInitLogFile() { ...@@ -87,6 +87,7 @@ static void tscInitLogFile() {
} }
} }
// todo close the transporter properly
void closeTransporter(STscObj* pTscObj) { void closeTransporter(STscObj* pTscObj) {
if (pTscObj == NULL || pTscObj->pTransporter == NULL) { if (pTscObj == NULL || pTscObj->pTransporter == NULL) {
return; return;
...@@ -166,8 +167,7 @@ void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t ty ...@@ -166,8 +167,7 @@ void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t ty
return NULL; return NULL;
} }
// TODO generated request uuid pRequest->requestId = generateRequestId();
pRequest->requestId = 0;
pRequest->metric.start = taosGetTimestampMs(); pRequest->metric.start = taosGetTimestampMs();
pRequest->type = type; pRequest->type = type;
...@@ -180,6 +180,14 @@ void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t ty ...@@ -180,6 +180,14 @@ void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t ty
return pRequest; 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) { static void doDestroyRequest(void* p) {
assert(p != NULL); assert(p != NULL);
SRequestObj* pRequest = (SRequestObj*)p; SRequestObj* pRequest = (SRequestObj*)p;
...@@ -190,7 +198,7 @@ static void doDestroyRequest(void* p) { ...@@ -190,7 +198,7 @@ static void doDestroyRequest(void* p) {
tfree(pRequest->sqlstr); tfree(pRequest->sqlstr);
tfree(pRequest->pInfo); tfree(pRequest->pInfo);
tfree(pRequest->body.resInfo.pRspMsg); doFreeReqResultInfo(&pRequest->body.resInfo);
deregisterRequest(pRequest); deregisterRequest(pRequest);
tfree(pRequest); tfree(pRequest);
...@@ -410,6 +418,39 @@ int taos_options_imp(TSDB_OPTION option, const char *str) { ...@@ -410,6 +418,39 @@ int taos_options_imp(TSDB_OPTION option, const char *str) {
return 0; 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 #if 0
#include "cJSON.h" #include "cJSON.h"
static setConfRet taos_set_config_imp(const char *config){ static setConfRet taos_set_config_imp(const char *config){
......
...@@ -140,7 +140,7 @@ int32_t buildRequest(STscObj *pTscObj, const char *sql, int sqlLen, SRequestObj* ...@@ -140,7 +140,7 @@ int32_t buildRequest(STscObj *pTscObj, const char *sql, int sqlLen, SRequestObj*
(*pRequest)->sqlstr[sqlLen] = 0; (*pRequest)->sqlstr[sqlLen] = 0;
(*pRequest)->sqlLen = sqlLen; (*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; return TSDB_CODE_SUCCESS;
} }
...@@ -192,19 +192,22 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) { ...@@ -192,19 +192,22 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) {
} }
tsem_wait(&pRequest->body.rspSem); tsem_wait(&pRequest->body.rspSem);
destroySendMsgInfo(pSendMsg);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQuery, SQueryDag** pDag) { int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQueryNode, SQueryDag** pDag) {
pRequest->type = pQuery->type; pRequest->type = pQueryNode->type;
return qCreateQueryDag(pQuery, pDag); return qCreateQueryDag(pQueryNode, pDag, pRequest->requestId);
} }
int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, void** pJob) { int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, void** pJob) {
if (TSDB_SQL_INSERT == pRequest->type || TSDB_SQL_CREATE_TABLE == pRequest->type) { 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); 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 ...@@ -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); asyncSendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body);
tsem_wait(&pRequest->body.rspSem); tsem_wait(&pRequest->body.rspSem);
destroySendMsgInfo(body);
if (pRequest->code != TSDB_CODE_SUCCESS) { if (pRequest->code != TSDB_CODE_SUCCESS) {
const char *errorMsg = (pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(terrno); 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); 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 ...@@ -370,7 +371,7 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con
taos_close(pTscObj); taos_close(pTscObj);
pTscObj = NULL; pTscObj = NULL;
} else { } 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); destroyRequest(pRequest);
} }
...@@ -440,20 +441,21 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { ...@@ -440,20 +441,21 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
* There is not response callback function for submit response. * There is not response callback function for submit response.
* The actual inserted number of points is the first number. * 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) { if (pMsg->code == TSDB_CODE_SUCCESS) {
tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%" PRId64 " ms", pRequest->requestId, 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, TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId);
pRequest->metric.rsp - pRequest->metric.start);
} else { } else {
tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%" PRId64 " ms", pRequest->requestId, 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, TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId);
pRequest->metric.rsp - pRequest->metric.start);
} }
taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId); taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId);
} }
SDataBuf buf = {.len = pMsg->contLen}; SDataBuf buf = {.len = pMsg->contLen, .pData = NULL};
if (pMsg->contLen > 0) {
buf.pData = calloc(1, pMsg->contLen); buf.pData = calloc(1, pMsg->contLen);
if (buf.pData == NULL) { if (buf.pData == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
...@@ -461,9 +463,11 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { ...@@ -461,9 +463,11 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
} else { } else {
memcpy(buf.pData, pMsg->pCont, pMsg->contLen); memcpy(buf.pData, pMsg->pCont, pMsg->contLen);
} }
}
pSendInfo->fp(pSendInfo->param, &buf, pMsg->code); pSendInfo->fp(pSendInfo->param, &buf, pMsg->code);
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
destroySendMsgInfo(pSendInfo);
} }
TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port) { 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) { ...@@ -536,7 +540,6 @@ void* doFetchRow(SRequestObj* pRequest) {
asyncSendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body); asyncSendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body);
tsem_wait(&pRequest->body.rspSem); tsem_wait(&pRequest->body.rspSem);
destroySendMsgInfo(body);
pResultInfo->current = 0; pResultInfo->current = 0;
if (pResultInfo->numOfRows <= pResultInfo->current) { if (pResultInfo->numOfRows <= pResultInfo->current) {
......
...@@ -29,7 +29,7 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) { ...@@ -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. // this function may be called by user or system, or by both simultaneously.
void taos_cleanup(void) { 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) { if (atomic_val_compare_exchange_32(&sentinel, TSC_VAR_NOT_RELEASE, TSC_VAR_RELEASED) != TSC_VAR_NOT_RELEASE) {
return; return;
...@@ -47,6 +47,8 @@ void taos_cleanup(void) { ...@@ -47,6 +47,8 @@ void taos_cleanup(void) {
rpcCleanup(); rpcCleanup();
taosCloseLog(); taosCloseLog();
tscInfo("all local resources released");
} }
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) { 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) { ...@@ -140,7 +142,9 @@ TAOS_ROW taos_fetch_row(TAOS_RES *pRes) {
SRequestObj *pRequest = (SRequestObj *) pRes; SRequestObj *pRequest = (SRequestObj *) pRes;
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || 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; return NULL;
} }
...@@ -258,6 +262,8 @@ const char *taos_data_type(int type) { ...@@ -258,6 +262,8 @@ const char *taos_data_type(int type) {
const char *taos_get_client_info() { return version; } 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; } int taos_result_precision(TAOS_RES *res) { return TSDB_TIME_PRECISION_MILLI; }
...@@ -30,6 +30,7 @@ int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) { ...@@ -30,6 +30,7 @@ int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) {
SRequestObj* pRequest = param; SRequestObj* pRequest = param;
setErrno(pRequest, code); setErrno(pRequest, code);
free(pMsg->pData);
sem_post(&pRequest->body.rspSem); sem_post(&pRequest->body.rspSem);
return code; return code;
} }
...@@ -37,6 +38,7 @@ int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t 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) { int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
SRequestObj* pRequest = param; SRequestObj* pRequest = param;
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
free(pMsg->pData);
setErrno(pRequest, code); setErrno(pRequest, code);
sem_post(&pRequest->body.rspSem); sem_post(&pRequest->body.rspSem);
return code; return code;
...@@ -73,6 +75,7 @@ int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t 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, tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, pConnect->clusterId,
pTscObj->pAppInfo->numOfConns); pTscObj->pAppInfo->numOfConns);
free(pMsg->pData);
sem_post(&pRequest->body.rspSem); sem_post(&pRequest->body.rspSem);
return 0; return 0;
} }
...@@ -87,14 +90,14 @@ SMsgSendInfo* buildMsgInfoImpl(SRequestObj *pRequest) { ...@@ -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 || pRequest->type == TDMT_VND_SHOW_TABLES_FETCH) {
if (pRequest->type == TDMT_MND_SHOW_RETRIEVE) { if (pRequest->type == TDMT_MND_SHOW_RETRIEVE) {
SRetrieveTableMsg* pRetrieveMsg = calloc(1, sizeof(SRetrieveTableMsg)); SRetrieveTableReq* pRetrieveMsg = calloc(1, sizeof(SRetrieveTableReq));
if (pRetrieveMsg == NULL) { if (pRetrieveMsg == NULL) {
return NULL; return NULL;
} }
pRetrieveMsg->showId = htobe64(pRequest->body.showInfo.execId); pRetrieveMsg->showId = htobe64(pRequest->body.showInfo.execId);
pMsgSendInfo->msgInfo.pData = pRetrieveMsg; pMsgSendInfo->msgInfo.pData = pRetrieveMsg;
pMsgSendInfo->msgInfo.len = sizeof(SRetrieveTableMsg); pMsgSendInfo->msgInfo.len = sizeof(SRetrieveTableReq);
} else { } else {
SVShowTablesFetchReq* pFetchMsg = calloc(1, sizeof(SVShowTablesFetchReq)); SVShowTablesFetchReq* pFetchMsg = calloc(1, sizeof(SVShowTablesFetchReq));
if (pFetchMsg == NULL) { if (pFetchMsg == NULL) {
...@@ -238,6 +241,7 @@ int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) { ...@@ -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) { int32_t processCreateDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
// todo rsp with the vnode id list // todo rsp with the vnode id list
SRequestObj* pRequest = param; SRequestObj* pRequest = param;
free(pMsg->pData);
tsem_post(&pRequest->body.rspSem); tsem_post(&pRequest->body.rspSem);
} }
...@@ -245,6 +249,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { ...@@ -245,6 +249,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
SRequestObj* pRequest = param; SRequestObj* pRequest = param;
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
free(pMsg->pData);
setErrno(pRequest, code); setErrno(pRequest, code);
tsem_post(&pRequest->body.rspSem); tsem_post(&pRequest->body.rspSem);
return code; return code;
...@@ -258,6 +263,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { ...@@ -258,6 +263,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
tNameGetDbName(&name, db); tNameGetDbName(&name, db);
setConnectionDB(pRequest->pTscObj, db); setConnectionDB(pRequest->pTscObj, db);
free(pMsg->pData);
tsem_post(&pRequest->body.rspSem); tsem_post(&pRequest->body.rspSem);
return 0; return 0;
} }
...@@ -266,6 +272,7 @@ int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) { ...@@ -266,6 +272,7 @@ int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) {
assert(pMsg != NULL && param != NULL); assert(pMsg != NULL && param != NULL);
SRequestObj* pRequest = param; SRequestObj* pRequest = param;
free(pMsg->pData);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
setErrno(pRequest, code); setErrno(pRequest, code);
tsem_post(&pRequest->body.rspSem); tsem_post(&pRequest->body.rspSem);
......
...@@ -57,175 +57,176 @@ TEST(testCase, connect_Test) { ...@@ -57,175 +57,176 @@ TEST(testCase, connect_Test) {
taos_close(pConn); taos_close(pConn);
} }
//TEST(testCase, create_user_Test) { TEST(testCase, create_user_Test) {
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
// assert(pConn != NULL); 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, show_user_Test) { TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'");
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
// assert(pConn != NULL); printf("failed to create user, reason:%s\n", taos_errstr(pRes));
// }
// 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);
//}
//TEST(testCase, drop_user_Test) { taos_free_result(pRes);
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); taos_close(pConn);
// 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) { TEST(testCase, create_account_Test) {
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
//// assert(pConn != NULL); 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_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'");
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
// assert(pConn != NULL); printf("failed to create user, reason:%s\n", taos_errstr(pRes));
// }
// TAOS_RES* pRes = taos_query(pConn, "create database abc1");
// if (taos_errno(pRes) != 0) { taos_free_result(pRes);
// printf("error in create db, reason:%s\n", taos_errstr(pRes)); taos_close(pConn);
// } }
//
// TAOS_FIELD* pFields = taos_fetch_fields(pRes); TEST(testCase, drop_account_Test) {
// ASSERT_TRUE(pFields == NULL); TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
// assert(pConn != NULL);
// int32_t numOfFields = taos_num_fields(pRes);
// ASSERT_EQ(numOfFields, 0); TAOS_RES* pRes = taos_query(pConn, "drop account aabc");
// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
// taos_free_result(pRes); printf("failed to create user, reason:%s\n", taos_errstr(pRes));
// }
// pRes = taos_query(pConn, "create database abc1 vgroups 4");
// if (taos_errno(pRes) != 0) { taos_free_result(pRes);
// printf("error in create db, reason:%s\n", taos_errstr(pRes)); taos_close(pConn);
// } }
// taos_close(pConn);
//} TEST(testCase, show_user_Test) {
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
//TEST(testCase, create_dnode_Test) { assert(pConn != NULL);
// 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_RES* pRes = taos_query(pConn, "create dnode abc1 port 7000");
// if (taos_errno(pRes) != 0) { TAOS_FIELD* pFields = taos_fetch_fields(pRes);
// printf("error in create dnode, reason:%s\n", taos_errstr(pRes)); int32_t numOfFields = taos_num_fields(pRes);
// }
// taos_free_result(pRes); char str[512] = {0};
// while((pRow = taos_fetch_row(pRes)) != NULL) {
// pRes = taos_query(pConn, "create dnode 1.1.1.1 port 9000"); int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
// if (taos_errno(pRes) != 0) { printf("%s\n", str);
// printf("failed to create dnode, reason:%s\n", taos_errstr(pRes)); }
// }
// taos_free_result(pRes); taos_free_result(pRes);
// taos_close(pConn);
// taos_close(pConn); }
//}
// TEST(testCase, drop_user_Test) {
//TEST(testCase, drop_dnode_Test) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); assert(pConn != NULL);
// assert(pConn != NULL);
// TAOS_RES* pRes = taos_query(pConn, "drop user abc");
// TAOS_RES* pRes = taos_query(pConn, "drop dnode 2"); if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
// if (taos_errno(pRes) != 0) { printf("failed to create user, reason:%s\n", taos_errstr(pRes));
// printf("error in drop dnode, reason:%s\n", taos_errstr(pRes)); }
// }
// taos_free_result(pRes);
// TAOS_FIELD* pFields = taos_fetch_fields(pRes); taos_close(pConn);
// ASSERT_TRUE(pFields == NULL); }
//
// int32_t numOfFields = taos_num_fields(pRes); TEST(testCase, show_db_Test) {
// ASSERT_EQ(numOfFields, 0); TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
// assert(pConn != NULL);
// taos_free_result(pRes);
// taos_close(pConn); TAOS_RES* pRes = taos_query(pConn, "show databases");
//} TAOS_ROW pRow = NULL;
//
//TEST(testCase, use_db_test) { TAOS_FIELD* pFields = taos_fetch_fields(pRes);
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); int32_t numOfFields = taos_num_fields(pRes);
// assert(pConn != NULL);
// char str[512] = {0};
// TAOS_RES* pRes = taos_query(pConn, "use abc1"); while((pRow = taos_fetch_row(pRes)) != NULL) {
// if (taos_errno(pRes) != 0) { int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
// printf("error in use db, reason:%s\n", taos_errstr(pRes)); printf("%s\n", str);
// } }
//
// TAOS_FIELD* pFields = taos_fetch_fields(pRes); taos_close(pConn);
// ASSERT_TRUE(pFields == NULL); }
//
// int32_t numOfFields = taos_num_fields(pRes); TEST(testCase, create_db_Test) {
// ASSERT_EQ(numOfFields, 0); TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
// assert(pConn != NULL);
// taos_close(pConn);
//} 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) { //TEST(testCase, drop_db_test) {
//// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); //// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
...@@ -249,66 +250,66 @@ TEST(testCase, connect_Test) { ...@@ -249,66 +250,66 @@ TEST(testCase, connect_Test) {
//// taos_close(pConn); //// 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); // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
// assert(pConn != NULL); // assert(pConn != NULL);
// //
// TAOS_RES* pRes = taos_query(pConn, "create database abc1"); // TAOS_RES* pRes = taos_query(pConn, "use 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) { // 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); // 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) { // 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); // 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); // taos_close(pConn);
//} //}
// //
...@@ -342,7 +343,7 @@ TEST(testCase, connect_Test) { ...@@ -342,7 +343,7 @@ TEST(testCase, connect_Test) {
// taos_free_result(pRes); // taos_free_result(pRes);
// taos_close(pConn); // taos_close(pConn);
//} //}
//
//TEST(testCase, show_vgroup_Test) { //TEST(testCase, show_vgroup_Test) {
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
// assert(pConn != NULL); // assert(pConn != NULL);
...@@ -375,7 +376,7 @@ TEST(testCase, connect_Test) { ...@@ -375,7 +376,7 @@ TEST(testCase, connect_Test) {
// //
// taos_close(pConn); // taos_close(pConn);
//} //}
//
//TEST(testCase, drop_stable_Test) { //TEST(testCase, drop_stable_Test) {
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); // TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
// assert(pConn != NULL); // assert(pConn != NULL);
...@@ -465,14 +466,29 @@ TEST(testCase, connect_Test) { ...@@ -465,14 +466,29 @@ TEST(testCase, connect_Test) {
TEST(testCase, create_multiple_tables) { TEST(testCase, create_multiple_tables) {
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
assert(pConn != NULL); ASSERT_NE(pConn, nullptr);
TAOS_RES* pRes = taos_query(pConn, "use abc1"); 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); 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) { 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); taos_free_result(pRes);
ASSERT_TRUE(false); ASSERT_TRUE(false);
} }
...@@ -488,5 +504,61 @@ TEST(testCase, create_multiple_tables) { ...@@ -488,5 +504,61 @@ TEST(testCase, create_multiple_tables) {
} }
taos_free_result(pRes); 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); 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);
//}
...@@ -140,6 +140,7 @@ void *tSVCreateTbBatchReqDeserialize(void *buf, SVCreateTbBatchReq *pReq) { ...@@ -140,6 +140,7 @@ void *tSVCreateTbBatchReqDeserialize(void *buf, SVCreateTbBatchReq *pReq) {
buf = taosDecodeFixedU64(buf, &pReq->ver); buf = taosDecodeFixedU64(buf, &pReq->ver);
buf = taosDecodeFixedU32(buf, &nsize); buf = taosDecodeFixedU32(buf, &nsize);
pReq->pArray = taosArrayInit(nsize, sizeof(SVCreateTbReq));
for (size_t i = 0; i < nsize; i++) { for (size_t i = 0; i < nsize; i++) {
SVCreateTbReq req; SVCreateTbReq req;
buf = tDeserializeSVCreateTbReq(buf, &req); buf = tDeserializeSVCreateTbReq(buf, &req);
......
...@@ -33,9 +33,9 @@ typedef struct SBnode { ...@@ -33,9 +33,9 @@ typedef struct SBnode {
int32_t dnodeId; int32_t dnodeId;
int64_t clusterId; int64_t clusterId;
SBnodeCfg cfg; SBnodeCfg cfg;
SendMsgToDnodeFp sendMsgToDnodeFp; SendReqToDnodeFp sendReqToDnodeFp;
SendMsgToMnodeFp sendMsgToMnodeFp; SendReqToMnodeFp sendReqToMnodeFp;
SendRedirectMsgFp sendRedirectMsgFp; SendRedirectRspFp sendRedirectRspFp;
} SBnode; } SBnode;
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -29,8 +29,8 @@ int64_t dndGetClusterId(SDnode *pDnode); ...@@ -29,8 +29,8 @@ int64_t dndGetClusterId(SDnode *pDnode);
void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort); void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort);
void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet); void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet);
void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg); void dndSendRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg);
void dndSendStatusMsg(SDnode *pDnode); void dndSendStatusReq(SDnode *pDnode);
void dndProcessMgmtMsg(SDnode *pDnode, SRpcMsg *pRpcMsg, SEpSet *pEpSet); void dndProcessMgmtMsg(SDnode *pDnode, SRpcMsg *pRpcMsg, SEpSet *pEpSet);
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg); void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg);
......
...@@ -23,8 +23,8 @@ extern "C" { ...@@ -23,8 +23,8 @@ extern "C" {
int32_t dndInitTrans(SDnode *pDnode); int32_t dndInitTrans(SDnode *pDnode);
void dndCleanupTrans(SDnode *pDnode); void dndCleanupTrans(SDnode *pDnode);
void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pRpcMsg); int32_t dndSendReqToMnode(SDnode *pDnode, SRpcMsg *pRpcMsg);
void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pRpcMsg); int32_t dndSendReqToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pRpcMsg);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -27,7 +27,7 @@ static SBnode *dndAcquireBnode(SDnode *pDnode) { ...@@ -27,7 +27,7 @@ static SBnode *dndAcquireBnode(SDnode *pDnode) {
int32_t refCount = 0; int32_t refCount = 0;
taosRLockLatch(&pMgmt->latch); taosRLockLatch(&pMgmt->latch);
if (pMgmt->deployed && !pMgmt->dropped) { if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pBnode != NULL) {
refCount = atomic_add_fetch_32(&pMgmt->refCount, 1); refCount = atomic_add_fetch_32(&pMgmt->refCount, 1);
pBnode = pMgmt->pBnode; pBnode = pMgmt->pBnode;
} else { } else {
...@@ -60,7 +60,7 @@ static int32_t dndReadBnodeFile(SDnode *pDnode) { ...@@ -60,7 +60,7 @@ static int32_t dndReadBnodeFile(SDnode *pDnode) {
SBnodeMgmt *pMgmt = &pDnode->bmgmt; SBnodeMgmt *pMgmt = &pDnode->bmgmt;
int32_t code = TSDB_CODE_DND_BNODE_READ_FILE_ERROR; int32_t code = TSDB_CODE_DND_BNODE_READ_FILE_ERROR;
int32_t len = 0; int32_t len = 0;
int32_t maxLen = 4096; int32_t maxLen = 1024;
char *content = calloc(1, maxLen + 1); char *content = calloc(1, maxLen + 1);
cJSON *root = NULL; cJSON *root = NULL;
...@@ -127,7 +127,7 @@ static int32_t dndWriteBnodeFile(SDnode *pDnode) { ...@@ -127,7 +127,7 @@ static int32_t dndWriteBnodeFile(SDnode *pDnode) {
} }
int32_t len = 0; int32_t len = 0;
int32_t maxLen = 4096; int32_t maxLen = 1024;
char *content = calloc(1, maxLen + 1); char *content = calloc(1, maxLen + 1);
len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, "{\n");
...@@ -170,7 +170,7 @@ static void dndStopBnodeWorker(SDnode *pDnode) { ...@@ -170,7 +170,7 @@ static void dndStopBnodeWorker(SDnode *pDnode) {
pMgmt->deployed = 0; pMgmt->deployed = 0;
taosWUnLockLatch(&pMgmt->latch); taosWUnLockLatch(&pMgmt->latch);
while (pMgmt->refCount > 1) { while (pMgmt->refCount > 0) {
taosMsleep(10); taosMsleep(10);
} }
...@@ -179,9 +179,9 @@ static void dndStopBnodeWorker(SDnode *pDnode) { ...@@ -179,9 +179,9 @@ static void dndStopBnodeWorker(SDnode *pDnode) {
static void dndBuildBnodeOption(SDnode *pDnode, SBnodeOpt *pOption) { static void dndBuildBnodeOption(SDnode *pDnode, SBnodeOpt *pOption) {
pOption->pDnode = pDnode; pOption->pDnode = pDnode;
pOption->sendMsgToDnodeFp = dndSendMsgToDnode; pOption->sendReqToDnodeFp = dndSendReqToDnode;
pOption->sendMsgToMnodeFp = dndSendMsgToMnode; pOption->sendReqToMnodeFp = dndSendReqToMnode;
pOption->sendRedirectMsgFp = dndSendRedirectMsg; pOption->sendRedirectRspFp = dndSendRedirectRsp;
pOption->dnodeId = dndGetDnodeId(pDnode); pOption->dnodeId = dndGetDnodeId(pDnode);
pOption->clusterId = dndGetClusterId(pDnode); pOption->clusterId = dndGetClusterId(pDnode);
pOption->cfg.sver = pDnode->opt.sver; pOption->cfg.sver = pDnode->opt.sver;
...@@ -189,10 +189,18 @@ static void dndBuildBnodeOption(SDnode *pDnode, SBnodeOpt *pOption) { ...@@ -189,10 +189,18 @@ static void dndBuildBnodeOption(SDnode *pDnode, SBnodeOpt *pOption) {
static int32_t dndOpenBnode(SDnode *pDnode) { static int32_t dndOpenBnode(SDnode *pDnode) {
SBnodeMgmt *pMgmt = &pDnode->bmgmt; SBnodeMgmt *pMgmt = &pDnode->bmgmt;
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}; SBnodeOpt option = {0};
dndBuildBnodeOption(pDnode, &option); dndBuildBnodeOption(pDnode, &option);
SBnode *pBnode = bndOpen(pDnode->dir.bnode, &option); pBnode = bndOpen(pDnode->dir.bnode, &option);
if (pBnode == NULL) { if (pBnode == NULL) {
dError("failed to open bnode since %s", terrstr()); dError("failed to open bnode since %s", terrstr());
return -1; return -1;
...@@ -256,11 +264,12 @@ static int32_t dndDropBnode(SDnode *pDnode) { ...@@ -256,11 +264,12 @@ static int32_t dndDropBnode(SDnode *pDnode) {
} }
int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
SDCreateBnodeMsg *pMsg = pRpcMsg->pCont; SDCreateBnodeReq *pMsg = pRpcMsg->pCont;
pMsg->dnodeId = htonl(pMsg->dnodeId); pMsg->dnodeId = htonl(pMsg->dnodeId);
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
terrno = TSDB_CODE_DND_BNODE_ID_INVALID; terrno = TSDB_CODE_DND_BNODE_ID_INVALID;
dError("failed to create bnode since %s", terrstr());
return -1; return -1;
} else { } else {
return dndOpenBnode(pDnode); return dndOpenBnode(pDnode);
...@@ -268,11 +277,12 @@ int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { ...@@ -268,11 +277,12 @@ int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
} }
int32_t dndProcessDropBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { int32_t dndProcessDropBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
SDDropBnodeMsg *pMsg = pRpcMsg->pCont; SDDropBnodeReq *pMsg = pRpcMsg->pCont;
pMsg->dnodeId = htonl(pMsg->dnodeId); pMsg->dnodeId = htonl(pMsg->dnodeId);
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
terrno = TSDB_CODE_DND_BNODE_ID_INVALID; terrno = TSDB_CODE_DND_BNODE_ID_INVALID;
dError("failed to drop bnode since %s", terrstr());
return -1; return -1;
} else { } else {
return dndDropBnode(pDnode); return dndDropBnode(pDnode);
......
...@@ -80,7 +80,7 @@ void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { ...@@ -80,7 +80,7 @@ void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
taosRUnLockLatch(&pMgmt->latch); taosRUnLockLatch(&pMgmt->latch);
} }
void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) { void dndSendRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg) {
tmsg_t msgType = pMsg->msgType; tmsg_t msgType = pMsg->msgType;
SEpSet epSet = {0}; SEpSet epSet = {0};
...@@ -354,7 +354,7 @@ static int32_t dndWriteDnodes(SDnode *pDnode) { ...@@ -354,7 +354,7 @@ static int32_t dndWriteDnodes(SDnode *pDnode) {
return 0; return 0;
} }
void dndSendStatusMsg(SDnode *pDnode) { void dndSendStatusReq(SDnode *pDnode) {
int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad); int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad);
SStatusMsg *pStatus = rpcMallocCont(contLen); SStatusMsg *pStatus = rpcMallocCont(contLen);
...@@ -391,7 +391,7 @@ void dndSendStatusMsg(SDnode *pDnode) { ...@@ -391,7 +391,7 @@ void dndSendStatusMsg(SDnode *pDnode) {
pMgmt->statusSent = 1; pMgmt->statusSent = 1;
dTrace("pDnode:%p, send status msg to mnode", pDnode); dTrace("pDnode:%p, send status msg to mnode", pDnode);
dndSendMsgToMnode(pDnode, &rpcMsg); dndSendReqToMnode(pDnode, &rpcMsg);
} }
static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) { static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) {
...@@ -491,7 +491,7 @@ static void *dnodeThreadRoutine(void *param) { ...@@ -491,7 +491,7 @@ static void *dnodeThreadRoutine(void *param) {
taosMsleep(ms); taosMsleep(ms);
if (dndGetStat(pDnode) == DND_STAT_RUNNING && !pMgmt->statusSent && !pMgmt->dropped) { if (dndGetStat(pDnode) == DND_STAT_RUNNING && !pMgmt->statusSent && !pMgmt->dropped) {
dndSendStatusMsg(pDnode); dndSendStatusReq(pDnode);
} }
} }
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "dndTransport.h" #include "dndTransport.h"
#include "dndWorker.h" #include "dndWorker.h"
static void dndWriteMnodeMsgToWorker(SDnode *pDnode, SDnodeWorker *pWorker, SRpcMsg *pRpcMsg);
static void dndProcessMnodeQueue(SDnode *pDnode, SMnodeMsg *pMsg); static void dndProcessMnodeQueue(SDnode *pDnode, SMnodeMsg *pMsg);
static SMnode *dndAcquireMnode(SDnode *pDnode) { static SMnode *dndAcquireMnode(SDnode *pDnode) {
...@@ -258,11 +259,16 @@ static bool dndNeedDeployMnode(SDnode *pDnode) { ...@@ -258,11 +259,16 @@ static bool dndNeedDeployMnode(SDnode *pDnode) {
return true; return true;
} }
static int32_t dndPutMsgToMWriteQ(SDnode *pDnode, SRpcMsg *pRpcMsg) {
dndWriteMnodeMsgToWorker(pDnode, &pDnode->mmgmt.writeWorker, pRpcMsg);
}
static void dndInitMnodeOption(SDnode *pDnode, SMnodeOpt *pOption) { static void dndInitMnodeOption(SDnode *pDnode, SMnodeOpt *pOption) {
pOption->pDnode = pDnode; pOption->pDnode = pDnode;
pOption->sendMsgToDnodeFp = dndSendMsgToDnode; pOption->sendReqToDnodeFp = dndSendReqToDnode;
pOption->sendMsgToMnodeFp = dndSendMsgToMnode; pOption->sendReqToMnodeFp = dndSendReqToMnode;
pOption->sendRedirectMsgFp = dndSendRedirectMsg; pOption->sendRedirectRspFp = dndSendRedirectRsp;
pOption->putReqToMWriteQFp = dndPutMsgToMWriteQ;
pOption->dnodeId = dndGetDnodeId(pDnode); pOption->dnodeId = dndGetDnodeId(pDnode);
pOption->clusterId = dndGetClusterId(pDnode); pOption->clusterId = dndGetClusterId(pDnode);
pOption->cfg.sver = pDnode->opt.sver; pOption->cfg.sver = pDnode->opt.sver;
......
...@@ -27,7 +27,7 @@ static SQnode *dndAcquireQnode(SDnode *pDnode) { ...@@ -27,7 +27,7 @@ static SQnode *dndAcquireQnode(SDnode *pDnode) {
int32_t refCount = 0; int32_t refCount = 0;
taosRLockLatch(&pMgmt->latch); taosRLockLatch(&pMgmt->latch);
if (pMgmt->deployed && !pMgmt->dropped) { if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pQnode != NULL) {
refCount = atomic_add_fetch_32(&pMgmt->refCount, 1); refCount = atomic_add_fetch_32(&pMgmt->refCount, 1);
pQnode = pMgmt->pQnode; pQnode = pMgmt->pQnode;
} else { } else {
...@@ -60,7 +60,7 @@ static int32_t dndReadQnodeFile(SDnode *pDnode) { ...@@ -60,7 +60,7 @@ static int32_t dndReadQnodeFile(SDnode *pDnode) {
SQnodeMgmt *pMgmt = &pDnode->qmgmt; SQnodeMgmt *pMgmt = &pDnode->qmgmt;
int32_t code = TSDB_CODE_DND_QNODE_READ_FILE_ERROR; int32_t code = TSDB_CODE_DND_QNODE_READ_FILE_ERROR;
int32_t len = 0; int32_t len = 0;
int32_t maxLen = 4096; int32_t maxLen = 1024;
char *content = calloc(1, maxLen + 1); char *content = calloc(1, maxLen + 1);
cJSON *root = NULL; cJSON *root = NULL;
...@@ -127,7 +127,7 @@ static int32_t dndWriteQnodeFile(SDnode *pDnode) { ...@@ -127,7 +127,7 @@ static int32_t dndWriteQnodeFile(SDnode *pDnode) {
} }
int32_t len = 0; int32_t len = 0;
int32_t maxLen = 4096; int32_t maxLen = 1024;
char *content = calloc(1, maxLen + 1); char *content = calloc(1, maxLen + 1);
len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, "{\n");
...@@ -175,7 +175,7 @@ static void dndStopQnodeWorker(SDnode *pDnode) { ...@@ -175,7 +175,7 @@ static void dndStopQnodeWorker(SDnode *pDnode) {
pMgmt->deployed = 0; pMgmt->deployed = 0;
taosWUnLockLatch(&pMgmt->latch); taosWUnLockLatch(&pMgmt->latch);
while (pMgmt->refCount > 1) { while (pMgmt->refCount > 0) {
taosMsleep(10); taosMsleep(10);
} }
...@@ -185,9 +185,9 @@ static void dndStopQnodeWorker(SDnode *pDnode) { ...@@ -185,9 +185,9 @@ static void dndStopQnodeWorker(SDnode *pDnode) {
static void dndBuildQnodeOption(SDnode *pDnode, SQnodeOpt *pOption) { static void dndBuildQnodeOption(SDnode *pDnode, SQnodeOpt *pOption) {
pOption->pDnode = pDnode; pOption->pDnode = pDnode;
pOption->sendMsgToDnodeFp = dndSendMsgToDnode; pOption->sendReqToDnodeFp = dndSendReqToDnode;
pOption->sendMsgToMnodeFp = dndSendMsgToMnode; pOption->sendReqToMnodeFp = dndSendReqToMnode;
pOption->sendRedirectMsgFp = dndSendRedirectMsg; pOption->sendRedirectRspFp = dndSendRedirectRsp;
pOption->dnodeId = dndGetDnodeId(pDnode); pOption->dnodeId = dndGetDnodeId(pDnode);
pOption->clusterId = dndGetClusterId(pDnode); pOption->clusterId = dndGetClusterId(pDnode);
pOption->cfg.sver = pDnode->opt.sver; pOption->cfg.sver = pDnode->opt.sver;
...@@ -195,10 +195,19 @@ static void dndBuildQnodeOption(SDnode *pDnode, SQnodeOpt *pOption) { ...@@ -195,10 +195,19 @@ static void dndBuildQnodeOption(SDnode *pDnode, SQnodeOpt *pOption) {
static int32_t dndOpenQnode(SDnode *pDnode) { static int32_t dndOpenQnode(SDnode *pDnode) {
SQnodeMgmt *pMgmt = &pDnode->qmgmt; SQnodeMgmt *pMgmt = &pDnode->qmgmt;
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}; SQnodeOpt option = {0};
dndBuildQnodeOption(pDnode, &option); dndBuildQnodeOption(pDnode, &option);
SQnode *pQnode = qndOpen(&option); pQnode = qndOpen(&option);
if (pQnode == NULL) { if (pQnode == NULL) {
dError("failed to open qnode since %s", terrstr()); dError("failed to open qnode since %s", terrstr());
return -1; return -1;
...@@ -261,11 +270,12 @@ static int32_t dndDropQnode(SDnode *pDnode) { ...@@ -261,11 +270,12 @@ static int32_t dndDropQnode(SDnode *pDnode) {
} }
int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
SDCreateQnodeMsg *pMsg = pRpcMsg->pCont; SDCreateQnodeReq *pMsg = pRpcMsg->pCont;
pMsg->dnodeId = htonl(pMsg->dnodeId); pMsg->dnodeId = htonl(pMsg->dnodeId);
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
terrno = TSDB_CODE_DND_QNODE_ID_INVALID; terrno = TSDB_CODE_DND_QNODE_ID_INVALID;
dError("failed to create qnode since %s", terrstr());
return -1; return -1;
} else { } else {
return dndOpenQnode(pDnode); return dndOpenQnode(pDnode);
...@@ -273,11 +283,12 @@ int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { ...@@ -273,11 +283,12 @@ int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
} }
int32_t dndProcessDropQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { int32_t dndProcessDropQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
SDDropQnodeMsg *pMsg = pRpcMsg->pCont; SDDropQnodeReq *pMsg = pRpcMsg->pCont;
pMsg->dnodeId = htonl(pMsg->dnodeId); pMsg->dnodeId = htonl(pMsg->dnodeId);
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
terrno = TSDB_CODE_DND_QNODE_ID_INVALID; terrno = TSDB_CODE_DND_QNODE_ID_INVALID;
dError("failed to drop qnode since %s", terrstr());
return -1; return -1;
} else { } else {
return dndDropQnode(pDnode); return dndDropQnode(pDnode);
...@@ -293,7 +304,9 @@ static void dndProcessQnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) { ...@@ -293,7 +304,9 @@ static void dndProcessQnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) {
if (pQnode != NULL) { if (pQnode != NULL) {
code = qndProcessMsg(pQnode, pMsg, &pRsp); code = qndProcessMsg(pQnode, pMsg, &pRsp);
} }
dndReleaseQnode(pDnode, pQnode);
if (pMsg->msgType & 1u) {
if (pRsp != NULL) { if (pRsp != NULL) {
pRsp->ahandle = pMsg->ahandle; pRsp->ahandle = pMsg->ahandle;
rpcSendResponse(pRsp); rpcSendResponse(pRsp);
...@@ -303,6 +316,7 @@ static void dndProcessQnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) { ...@@ -303,6 +316,7 @@ static void dndProcessQnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code};
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
} }
}
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
taosFreeQitem(pMsg); taosFreeQitem(pMsg);
......
...@@ -27,7 +27,7 @@ static SSnode *dndAcquireSnode(SDnode *pDnode) { ...@@ -27,7 +27,7 @@ static SSnode *dndAcquireSnode(SDnode *pDnode) {
int32_t refCount = 0; int32_t refCount = 0;
taosRLockLatch(&pMgmt->latch); taosRLockLatch(&pMgmt->latch);
if (pMgmt->deployed && !pMgmt->dropped) { if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pSnode != NULL) {
refCount = atomic_add_fetch_32(&pMgmt->refCount, 1); refCount = atomic_add_fetch_32(&pMgmt->refCount, 1);
pSnode = pMgmt->pSnode; pSnode = pMgmt->pSnode;
} else { } else {
...@@ -60,7 +60,7 @@ static int32_t dndReadSnodeFile(SDnode *pDnode) { ...@@ -60,7 +60,7 @@ static int32_t dndReadSnodeFile(SDnode *pDnode) {
SSnodeMgmt *pMgmt = &pDnode->smgmt; SSnodeMgmt *pMgmt = &pDnode->smgmt;
int32_t code = TSDB_CODE_DND_SNODE_READ_FILE_ERROR; int32_t code = TSDB_CODE_DND_SNODE_READ_FILE_ERROR;
int32_t len = 0; int32_t len = 0;
int32_t maxLen = 4096; int32_t maxLen = 1024;
char *content = calloc(1, maxLen + 1); char *content = calloc(1, maxLen + 1);
cJSON *root = NULL; cJSON *root = NULL;
...@@ -127,7 +127,7 @@ static int32_t dndWriteSnodeFile(SDnode *pDnode) { ...@@ -127,7 +127,7 @@ static int32_t dndWriteSnodeFile(SDnode *pDnode) {
} }
int32_t len = 0; int32_t len = 0;
int32_t maxLen = 4096; int32_t maxLen = 1024;
char *content = calloc(1, maxLen + 1); char *content = calloc(1, maxLen + 1);
len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, "{\n");
...@@ -170,7 +170,7 @@ static void dndStopSnodeWorker(SDnode *pDnode) { ...@@ -170,7 +170,7 @@ static void dndStopSnodeWorker(SDnode *pDnode) {
pMgmt->deployed = 0; pMgmt->deployed = 0;
taosWUnLockLatch(&pMgmt->latch); taosWUnLockLatch(&pMgmt->latch);
while (pMgmt->refCount > 1) { while (pMgmt->refCount > 0) {
taosMsleep(10); taosMsleep(10);
} }
...@@ -179,9 +179,9 @@ static void dndStopSnodeWorker(SDnode *pDnode) { ...@@ -179,9 +179,9 @@ static void dndStopSnodeWorker(SDnode *pDnode) {
static void dndBuildSnodeOption(SDnode *pDnode, SSnodeOpt *pOption) { static void dndBuildSnodeOption(SDnode *pDnode, SSnodeOpt *pOption) {
pOption->pDnode = pDnode; pOption->pDnode = pDnode;
pOption->sendMsgToDnodeFp = dndSendMsgToDnode; pOption->sendReqToDnodeFp = dndSendReqToDnode;
pOption->sendMsgToMnodeFp = dndSendMsgToMnode; pOption->sendReqToMnodeFp = dndSendReqToMnode;
pOption->sendRedirectMsgFp = dndSendRedirectMsg; pOption->sendRedirectRspFp = dndSendRedirectRsp;
pOption->dnodeId = dndGetDnodeId(pDnode); pOption->dnodeId = dndGetDnodeId(pDnode);
pOption->clusterId = dndGetClusterId(pDnode); pOption->clusterId = dndGetClusterId(pDnode);
pOption->cfg.sver = pDnode->opt.sver; pOption->cfg.sver = pDnode->opt.sver;
...@@ -189,10 +189,18 @@ static void dndBuildSnodeOption(SDnode *pDnode, SSnodeOpt *pOption) { ...@@ -189,10 +189,18 @@ static void dndBuildSnodeOption(SDnode *pDnode, SSnodeOpt *pOption) {
static int32_t dndOpenSnode(SDnode *pDnode) { static int32_t dndOpenSnode(SDnode *pDnode) {
SSnodeMgmt *pMgmt = &pDnode->smgmt; SSnodeMgmt *pMgmt = &pDnode->smgmt;
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}; SSnodeOpt option = {0};
dndBuildSnodeOption(pDnode, &option); dndBuildSnodeOption(pDnode, &option);
SSnode *pSnode = sndOpen(pDnode->dir.snode, &option); pSnode = sndOpen(pDnode->dir.snode, &option);
if (pSnode == NULL) { if (pSnode == NULL) {
dError("failed to open snode since %s", terrstr()); dError("failed to open snode since %s", terrstr());
return -1; return -1;
...@@ -256,11 +264,12 @@ static int32_t dndDropSnode(SDnode *pDnode) { ...@@ -256,11 +264,12 @@ static int32_t dndDropSnode(SDnode *pDnode) {
} }
int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
SDCreateSnodeMsg *pMsg = pRpcMsg->pCont; SDCreateSnodeReq *pMsg = pRpcMsg->pCont;
pMsg->dnodeId = htonl(pMsg->dnodeId); pMsg->dnodeId = htonl(pMsg->dnodeId);
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
terrno = TSDB_CODE_DND_SNODE_ID_INVALID; terrno = TSDB_CODE_DND_SNODE_ID_INVALID;
dError("failed to create snode since %s", terrstr());
return -1; return -1;
} else { } else {
return dndOpenSnode(pDnode); return dndOpenSnode(pDnode);
...@@ -268,11 +277,12 @@ int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { ...@@ -268,11 +277,12 @@ int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
} }
int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
SDDropSnodeMsg *pMsg = pRpcMsg->pCont; SDDropSnodeReq *pMsg = pRpcMsg->pCont;
pMsg->dnodeId = htonl(pMsg->dnodeId); pMsg->dnodeId = htonl(pMsg->dnodeId);
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) { if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
terrno = TSDB_CODE_DND_SNODE_ID_INVALID; terrno = TSDB_CODE_DND_SNODE_ID_INVALID;
dError("failed to drop snode since %s", terrstr());
return -1; return -1;
} else { } else {
return dndDropSnode(pDnode); return dndDropSnode(pDnode);
...@@ -288,7 +298,9 @@ static void dndProcessSnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) { ...@@ -288,7 +298,9 @@ static void dndProcessSnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) {
if (pSnode != NULL) { if (pSnode != NULL) {
code = sndProcessMsg(pSnode, pMsg, &pRsp); code = sndProcessMsg(pSnode, pMsg, &pRsp);
} }
dndReleaseSnode(pDnode, pSnode);
if (pMsg->msgType & 1u) {
if (pRsp != NULL) { if (pRsp != NULL) {
pRsp->ahandle = pMsg->ahandle; pRsp->ahandle = pMsg->ahandle;
rpcSendResponse(pRsp); rpcSendResponse(pRsp);
...@@ -298,6 +310,7 @@ static void dndProcessSnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) { ...@@ -298,6 +310,7 @@ static void dndProcessSnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code}; SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code};
rpcSendResponse(&rpcRsp); rpcSendResponse(&rpcRsp);
} }
}
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
taosFreeQitem(pMsg); taosFreeQitem(pMsg);
......
...@@ -105,8 +105,6 @@ static void dndInitMsgFp(STransMgmt *pMgmt) { ...@@ -105,8 +105,6 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SHOW_RETRIEVE)] = dndProcessMnodeReadMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SHOW_RETRIEVE)] = dndProcessMnodeReadMsg;
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS)] = dndProcessMnodeReadMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS)] = dndProcessMnodeReadMsg;
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS_RSP)] = dndProcessMgmtMsg; 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)] = dndProcessMnodeWriteMsg;
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GRANT_RSP)] = dndProcessMgmtMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GRANT_RSP)] = dndProcessMgmtMsg;
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_AUTH)] = dndProcessMnodeReadMsg; pMgmt->msgFp[TMSG_INDEX(TDMT_MND_AUTH)] = dndProcessMnodeReadMsg;
...@@ -160,8 +158,8 @@ static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { ...@@ -160,8 +158,8 @@ static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
DndMsgFp fp = pMgmt->msgFp[TMSG_INDEX(msgType)]; DndMsgFp fp = pMgmt->msgFp[TMSG_INDEX(msgType)];
if (fp != NULL) { 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); (*fp)(pDnode, pMsg, pEpSet);
dTrace("RPC %p, rsp:%s is processed, code:0x%x", pMsg->handle, TMSG_INFO(msgType), pMsg->code & 0XFFFF);
} else { } else {
dError("RPC %p, rsp:%s not processed", pMsg->handle, TMSG_INFO(msgType)); dError("RPC %p, rsp:%s not processed", pMsg->handle, TMSG_INFO(msgType));
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
...@@ -216,7 +214,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { ...@@ -216,7 +214,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) {
if (dndGetStat(pDnode) == DND_STAT_STOPPED) { 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); 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); rpcSendResponse(&rspMsg);
rpcFreeCont(pMsg->pCont); rpcFreeCont(pMsg->pCont);
return; return;
...@@ -383,14 +381,19 @@ void dndCleanupTrans(SDnode *pDnode) { ...@@ -383,14 +381,19 @@ void dndCleanupTrans(SDnode *pDnode) {
dInfo("dnode-transport is cleaned up"); 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; 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); rpcSendRequest(pMgmt->clientRpc, pEpSet, pMsg, NULL);
return 0;
} }
void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pMsg) { int32_t dndSendReqToMnode(SDnode *pDnode, SRpcMsg *pMsg) {
SEpSet epSet = {0}; SEpSet epSet = {0};
dndGetMnodeEpSet(pDnode, &epSet); dndGetMnodeEpSet(pDnode, &epSet);
dndSendMsgToDnode(pDnode, &epSet, pMsg); return dndSendReqToDnode(pDnode, &epSet, pMsg);
} }
...@@ -14,8 +14,11 @@ ...@@ -14,8 +14,11 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "dndBnode.h"
#include "dndDnode.h" #include "dndDnode.h"
#include "dndMnode.h" #include "dndMnode.h"
#include "dndQnode.h"
#include "dndSnode.h"
#include "dndTransport.h" #include "dndTransport.h"
#include "dndVnodes.h" #include "dndVnodes.h"
#include "sync.h" #include "sync.h"
...@@ -200,6 +203,24 @@ SDnode *dndInit(SDnodeOpt *pOption) { ...@@ -200,6 +203,24 @@ SDnode *dndInit(SDnodeOpt *pOption) {
return NULL; 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) { if (dndInitMnode(pDnode) != 0) {
dError("failed to init mnode"); dError("failed to init mnode");
dndCleanup(pDnode); dndCleanup(pDnode);
...@@ -213,7 +234,7 @@ SDnode *dndInit(SDnodeOpt *pOption) { ...@@ -213,7 +234,7 @@ SDnode *dndInit(SDnodeOpt *pOption) {
} }
dndSetStat(pDnode, DND_STAT_RUNNING); dndSetStat(pDnode, DND_STAT_RUNNING);
dndSendStatusMsg(pDnode); dndSendStatusReq(pDnode);
dndReportStartup(pDnode, "TDengine", "initialized successfully"); dndReportStartup(pDnode, "TDengine", "initialized successfully");
dInfo("TDengine is initialized successfully, pDnode:%p", pDnode); dInfo("TDengine is initialized successfully, pDnode:%p", pDnode);
...@@ -232,6 +253,9 @@ void dndCleanup(SDnode *pDnode) { ...@@ -232,6 +253,9 @@ void dndCleanup(SDnode *pDnode) {
dndSetStat(pDnode, DND_STAT_STOPPED); dndSetStat(pDnode, DND_STAT_STOPPED);
dndCleanupTrans(pDnode); dndCleanupTrans(pDnode);
dndCleanupMnode(pDnode); dndCleanupMnode(pDnode);
dndCleanupBnode(pDnode);
dndCleanupSnode(pDnode);
dndCleanupQnode(pDnode);
dndCleanupVnodes(pDnode); dndCleanupVnodes(pDnode);
dndCleanupDnode(pDnode); dndCleanupDnode(pDnode);
vnodeClear(); vnodeClear();
......
enable_testing() enable_testing()
add_subdirectory(acct) add_subdirectory(qnode)
add_subdirectory(bnode)
add_subdirectory(snode)
# add_subdirectory(auth) # add_subdirectory(auth)
# add_subdirectory(balance) # add_subdirectory(balance)
add_subdirectory(cluster)
add_subdirectory(db) add_subdirectory(db)
add_subdirectory(dnode) add_subdirectory(dnode)
# add_subdirectory(func) # add_subdirectory(func)
add_subdirectory(mnode) add_subdirectory(mnode)
add_subdirectory(qnode)
add_subdirectory(snode)
add_subdirectory(bnode)
add_subdirectory(profile) add_subdirectory(profile)
add_subdirectory(show)
add_subdirectory(stb) add_subdirectory(stb)
# add_subdirectory(sync) # add_subdirectory(sync)
# add_subdirectory(telem) # add_subdirectory(telem)
# add_subdirectory(trans) # add_subdirectory(trans)
add_subdirectory(user)
add_subdirectory(vgroup) add_subdirectory(vgroup)
add_subdirectory(sut) add_subdirectory(sut)
/**
* @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
aux_source_directory(. STEST_SRC) aux_source_directory(. BQTEST_SRC)
add_executable(dnode_test_bnode ${STEST_SRC}) add_executable(dnode_test_bnode ${BQTEST_SRC})
target_link_libraries( target_link_libraries(
dnode_test_bnode dnode_test_bnode
PUBLIC sut PUBLIC sut
......
/**
* @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
/**
* @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
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
)
/**
* @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
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
*/ */
#include "base.h" #include "sut.h"
class DndTestDb : public ::testing::Test { class DndTestDb : public ::testing::Test {
protected: protected:
...@@ -26,7 +26,7 @@ class DndTestDb : public ::testing::Test { ...@@ -26,7 +26,7 @@ class DndTestDb : public ::testing::Test {
Testbase DndTestDb::test; Testbase DndTestDb::test;
TEST_F(DndTestDb, 01_ShowDb) { TEST_F(DndTestDb, 01_ShowDb) {
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, "");
CHECK_META("show databases", 18); CHECK_META("show databases", 18);
CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN - 1 + VARSTR_HEADER_SIZE, "name"); 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"); CHECK_SCHEMA(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
...@@ -47,7 +47,7 @@ TEST_F(DndTestDb, 01_ShowDb) { ...@@ -47,7 +47,7 @@ TEST_F(DndTestDb, 01_ShowDb) {
CHECK_SCHEMA(16, TSDB_DATA_TYPE_BINARY, 3 + VARSTR_HEADER_SIZE, "precision"); CHECK_SCHEMA(16, TSDB_DATA_TYPE_BINARY, 3 + VARSTR_HEADER_SIZE, "precision");
CHECK_SCHEMA(17, TSDB_DATA_TYPE_TINYINT, 1, "update"); CHECK_SCHEMA(17, TSDB_DATA_TYPE_TINYINT, 1, "update");
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 0); EXPECT_EQ(test.GetShowRows(), 0);
} }
...@@ -77,15 +77,15 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { ...@@ -77,15 +77,15 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
pReq->cacheLastRow = 0; pReq->cacheLastRow = 0;
pReq->ignoreExist = 1; pReq->ignoreExist = 1;
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, "");
CHECK_META("show databases", 18); CHECK_META("show databases", 18);
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 1); EXPECT_EQ(test.GetShowRows(), 1);
CheckBinary("d1", TSDB_DB_NAME_LEN - 1); CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
CheckTimestamp(); CheckTimestamp();
...@@ -106,17 +106,17 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { ...@@ -106,17 +106,17 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
CheckBinary("ms", 3); // precision CheckBinary("ms", 3); // precision
CheckInt8(0); // update 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_META("show vgroups", 4);
CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "vgId"); CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "vgId");
CHECK_SCHEMA(1, TSDB_DATA_TYPE_INT, 4, "tables"); CHECK_SCHEMA(1, TSDB_DATA_TYPE_INT, 4, "tables");
CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "v1_dnode"); CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "v1_dnode");
CHECK_SCHEMA(3, TSDB_DATA_TYPE_BINARY, 9 + VARSTR_HEADER_SIZE, "v1_status"); CHECK_SCHEMA(3, TSDB_DATA_TYPE_BINARY, 9 + VARSTR_HEADER_SIZE, "v1_status");
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 2); EXPECT_EQ(test.GetShowRows(), 2);
CheckInt32(1);
CheckInt32(2); CheckInt32(2);
CheckInt32(3);
CheckInt32(0); CheckInt32(0);
CheckInt32(0); CheckInt32(0);
CheckInt16(1); CheckInt16(1);
...@@ -138,13 +138,13 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { ...@@ -138,13 +138,13 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
pReq->quorum = 2; pReq->quorum = 2;
pReq->cacheLastRow = 1; pReq->cacheLastRow = 1;
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_DB, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_DB, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, "");
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 1); EXPECT_EQ(test.GetShowRows(), 1);
CheckBinary("d1", TSDB_DB_NAME_LEN - 1); CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
CheckTimestamp(); CheckTimestamp();
...@@ -168,10 +168,10 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { ...@@ -168,10 +168,10 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
// restart // restart
test.Restart(); test.Restart();
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, "");
CHECK_META("show databases", 18); CHECK_META("show databases", 18);
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 1); EXPECT_EQ(test.GetShowRows(), 1);
CheckBinary("d1", TSDB_DB_NAME_LEN - 1); CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
...@@ -199,15 +199,15 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) { ...@@ -199,15 +199,15 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(contLen); SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(contLen);
strcpy(pReq->db, "1.d1"); strcpy(pReq->db, "1.d1");
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DB, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, "");
CHECK_META("show databases", 18); CHECK_META("show databases", 18);
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 0); EXPECT_EQ(test.GetShowRows(), 0);
} }
...@@ -237,15 +237,15 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) { ...@@ -237,15 +237,15 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) {
pReq->cacheLastRow = 0; pReq->cacheLastRow = 0;
pReq->ignoreExist = 1; pReq->ignoreExist = 1;
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, "");
CHECK_META("show databases", 18); CHECK_META("show databases", 18);
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 1); EXPECT_EQ(test.GetShowRows(), 1);
CheckBinary("d2", TSDB_DB_NAME_LEN - 1); CheckBinary("d2", TSDB_DB_NAME_LEN - 1);
...@@ -256,7 +256,7 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) { ...@@ -256,7 +256,7 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) {
strcpy(pReq->db, "1.d2"); strcpy(pReq->db, "1.d2");
pReq->vgVersion = htonl(-1); 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_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pMsg->code, 0);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
*/ */
#include "base.h" #include "sut.h"
class DndTestDnode : public ::testing::Test { class DndTestDnode : public ::testing::Test {
public: public:
...@@ -51,7 +51,7 @@ TestServer DndTestDnode::server4; ...@@ -51,7 +51,7 @@ TestServer DndTestDnode::server4;
TestServer DndTestDnode::server5; TestServer DndTestDnode::server5;
TEST_F(DndTestDnode, 01_ShowDnode) { TEST_F(DndTestDnode, 01_ShowDnode) {
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
CHECK_META("show dnodes", 7); CHECK_META("show dnodes", 7);
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
...@@ -62,7 +62,7 @@ TEST_F(DndTestDnode, 01_ShowDnode) { ...@@ -62,7 +62,7 @@ TEST_F(DndTestDnode, 01_ShowDnode) {
CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason"); CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason");
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 1); EXPECT_EQ(test.GetShowRows(), 1);
CheckInt16(1); CheckInt16(1);
...@@ -81,9 +81,9 @@ TEST_F(DndTestDnode, 02_ConfigDnode) { ...@@ -81,9 +81,9 @@ TEST_F(DndTestDnode, 02_ConfigDnode) {
pReq->dnodeId = htonl(1); pReq->dnodeId = htonl(1);
strcpy(pReq->config, "ddebugflag 131"); strcpy(pReq->config, "ddebugflag 131");
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONFIG_DNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONFIG_DNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
...@@ -94,16 +94,16 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { ...@@ -94,16 +94,16 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
strcpy(pReq->fqdn, "localhost"); strcpy(pReq->fqdn, "localhost");
pReq->port = htonl(9042); pReq->port = htonl(9042);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
taosMsleep(1300); taosMsleep(1300);
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
CHECK_META("show dnodes", 7); CHECK_META("show dnodes", 7);
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 2); EXPECT_EQ(test.GetShowRows(), 2);
CheckInt16(1); CheckInt16(1);
...@@ -127,14 +127,14 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { ...@@ -127,14 +127,14 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen); SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(2); pReq->dnodeId = htonl(2);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
CHECK_META("show dnodes", 7); CHECK_META("show dnodes", 7);
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 1); EXPECT_EQ(test.GetShowRows(), 1);
CheckInt16(1); CheckInt16(1);
...@@ -152,9 +152,9 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { ...@@ -152,9 +152,9 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
strcpy(pReq->fqdn, "localhost"); strcpy(pReq->fqdn, "localhost");
pReq->port = htonl(9043); pReq->port = htonl(9043);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
{ {
...@@ -164,9 +164,9 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { ...@@ -164,9 +164,9 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
strcpy(pReq->fqdn, "localhost"); strcpy(pReq->fqdn, "localhost");
pReq->port = htonl(9044); pReq->port = htonl(9044);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
{ {
...@@ -176,15 +176,15 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { ...@@ -176,15 +176,15 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
strcpy(pReq->fqdn, "localhost"); strcpy(pReq->fqdn, "localhost");
pReq->port = htonl(9045); pReq->port = htonl(9045);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
taosMsleep(1300); taosMsleep(1300);
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
CHECK_META("show dnodes", 7); CHECK_META("show dnodes", 7);
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 4); EXPECT_EQ(test.GetShowRows(), 4);
CheckInt16(1); CheckInt16(1);
...@@ -225,9 +225,9 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) { ...@@ -225,9 +225,9 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
server5.Restart(); server5.Restart();
taosMsleep(1300); taosMsleep(1300);
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
CHECK_META("show dnodes", 7); CHECK_META("show dnodes", 7);
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 4); EXPECT_EQ(test.GetShowRows(), 4);
CheckInt16(1); CheckInt16(1);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
*/ */
#include "base.h" #include "sut.h"
class DndTestMnode : public ::testing::Test { class DndTestMnode : public ::testing::Test {
public: public:
...@@ -51,7 +51,7 @@ TestServer DndTestMnode::server4; ...@@ -51,7 +51,7 @@ TestServer DndTestMnode::server4;
TestServer DndTestMnode::server5; TestServer DndTestMnode::server5;
TEST_F(DndTestMnode, 01_ShowDnode) { TEST_F(DndTestMnode, 01_ShowDnode) {
test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
CHECK_META("show mnodes", 5); CHECK_META("show mnodes", 5);
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
...@@ -60,7 +60,7 @@ TEST_F(DndTestMnode, 01_ShowDnode) { ...@@ -60,7 +60,7 @@ TEST_F(DndTestMnode, 01_ShowDnode) {
CHECK_SCHEMA(3, TSDB_DATA_TYPE_TIMESTAMP, 8, "role_time"); CHECK_SCHEMA(3, TSDB_DATA_TYPE_TIMESTAMP, 8, "role_time");
CHECK_SCHEMA(4, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time"); CHECK_SCHEMA(4, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 1); EXPECT_EQ(test.GetShowRows(), 1);
CheckInt16(1); CheckInt16(1);
...@@ -77,9 +77,9 @@ TEST_F(DndTestMnode, 02_Create_Mnode_Invalid_Id) { ...@@ -77,9 +77,9 @@ TEST_F(DndTestMnode, 02_Create_Mnode_Invalid_Id) {
SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen); SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(1); pReq->dnodeId = htonl(1);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MNODE_ALREADY_EXIST); ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MNODE_ALREADY_EXIST);
} }
} }
...@@ -90,9 +90,9 @@ TEST_F(DndTestMnode, 03_Create_Mnode_Invalid_Id) { ...@@ -90,9 +90,9 @@ TEST_F(DndTestMnode, 03_Create_Mnode_Invalid_Id) {
SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen); SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(2); pReq->dnodeId = htonl(2);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST); ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
} }
} }
...@@ -105,13 +105,13 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { ...@@ -105,13 +105,13 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
strcpy(pReq->fqdn, "localhost"); strcpy(pReq->fqdn, "localhost");
pReq->port = htonl(9062); pReq->port = htonl(9062);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
taosMsleep(1300); taosMsleep(1300);
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 2); EXPECT_EQ(test.GetShowRows(), 2);
} }
...@@ -122,12 +122,12 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { ...@@ -122,12 +122,12 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen); SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(2); pReq->dnodeId = htonl(2);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 2); EXPECT_EQ(test.GetShowRows(), 2);
CheckInt16(1); CheckInt16(1);
...@@ -149,12 +149,12 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { ...@@ -149,12 +149,12 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
SMDropMnodeMsg* pReq = (SMDropMnodeMsg*)rpcMallocCont(contLen); SMDropMnodeMsg* pReq = (SMDropMnodeMsg*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(2); pReq->dnodeId = htonl(2);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_MNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 1); EXPECT_EQ(test.GetShowRows(), 1);
CheckInt16(1); CheckInt16(1);
...@@ -170,14 +170,14 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { ...@@ -170,14 +170,14 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
// SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen); // SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen);
// pReq->dnodeId = htonl(2); // pReq->dnodeId = htonl(2);
// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DNODE, pReq, contLen); // SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
// ASSERT_NE(pMsg, nullptr); // ASSERT_NE(pRsp, nullptr);
// ASSERT_EQ(pMsg->code, 0); // ASSERT_EQ(pRsp->code, 0);
// } // }
// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); // test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
// CHECK_META("show dnodes", 7); // CHECK_META("show dnodes", 7);
// test.SendShowRetrieveMsg(); // test.SendShowRetrieveReq();
// EXPECT_EQ(test.GetShowRows(), 1); // EXPECT_EQ(test.GetShowRows(), 1);
// CheckInt16(1); // CheckInt16(1);
...@@ -194,9 +194,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { ...@@ -194,9 +194,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
// SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); // SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
// strcpy(pReq->ep, "localhost:9063"); // strcpy(pReq->ep, "localhost:9063");
// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); // SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
// ASSERT_NE(pMsg, nullptr); // ASSERT_NE(pRsp, nullptr);
// ASSERT_EQ(pMsg->code, 0); // ASSERT_EQ(pRsp->code, 0);
// } // }
// { // {
...@@ -205,9 +205,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { ...@@ -205,9 +205,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
// SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); // SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
// strcpy(pReq->ep, "localhost:9064"); // strcpy(pReq->ep, "localhost:9064");
// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); // SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
// ASSERT_NE(pMsg, nullptr); // ASSERT_NE(pRsp, nullptr);
// ASSERT_EQ(pMsg->code, 0); // ASSERT_EQ(pRsp->code, 0);
// } // }
// { // {
...@@ -216,15 +216,15 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { ...@@ -216,15 +216,15 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
// SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen); // SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
// strcpy(pReq->ep, "localhost:9065"); // strcpy(pReq->ep, "localhost:9065");
// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen); // SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
// ASSERT_NE(pMsg, nullptr); // ASSERT_NE(pRsp, nullptr);
// ASSERT_EQ(pMsg->code, 0); // ASSERT_EQ(pRsp->code, 0);
// } // }
// taosMsleep(1300); // taosMsleep(1300);
// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); // test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
// CHECK_META("show dnodes", 7); // CHECK_META("show dnodes", 7);
// test.SendShowRetrieveMsg(); // test.SendShowRetrieveReq();
// EXPECT_EQ(test.GetShowRows(), 4); // EXPECT_EQ(test.GetShowRows(), 4);
// CheckInt16(1); // CheckInt16(1);
...@@ -265,9 +265,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) { ...@@ -265,9 +265,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
// server5.Restart(); // server5.Restart();
// taosMsleep(1300); // taosMsleep(1300);
// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, ""); // test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
// CHECK_META("show dnodes", 7); // CHECK_META("show dnodes", 7);
// test.SendShowRetrieveMsg(); // test.SendShowRetrieveReq();
// EXPECT_EQ(test.GetShowRows(), 4); // EXPECT_EQ(test.GetShowRows(), 4);
// CheckInt16(1); // CheckInt16(1);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
*/ */
#include "base.h" #include "sut.h"
class DndTestProfile : public ::testing::Test { class DndTestProfile : public ::testing::Test {
protected: protected:
...@@ -17,15 +17,15 @@ class DndTestProfile : public ::testing::Test { ...@@ -17,15 +17,15 @@ class DndTestProfile : public ::testing::Test {
static void TearDownTestSuite() { test.Cleanup(); } static void TearDownTestSuite() { test.Cleanup(); }
static Testbase test; static Testbase test;
static int32_t connId;
public: public:
void SetUp() override {} void SetUp() override {}
void TearDown() override {} void TearDown() override {}
int32_t connId;
}; };
Testbase DndTestProfile::test; Testbase DndTestProfile::test;
int32_t DndTestProfile::connId;
TEST_F(DndTestProfile, 01_ConnectMsg) { TEST_F(DndTestProfile, 01_ConnectMsg) {
int32_t contLen = sizeof(SConnectMsg); int32_t contLen = sizeof(SConnectMsg);
...@@ -35,7 +35,7 @@ TEST_F(DndTestProfile, 01_ConnectMsg) { ...@@ -35,7 +35,7 @@ TEST_F(DndTestProfile, 01_ConnectMsg) {
strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->app, "dnode_test_profile");
strcpy(pReq->db, ""); 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_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pMsg->code, 0);
...@@ -67,14 +67,14 @@ TEST_F(DndTestProfile, 02_ConnectMsg_InvalidDB) { ...@@ -67,14 +67,14 @@ TEST_F(DndTestProfile, 02_ConnectMsg_InvalidDB) {
strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->app, "dnode_test_profile");
strcpy(pReq->db, "invalid_db"); strcpy(pReq->db, "invalid_db");
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONNECT, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_DB); ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DB);
ASSERT_EQ(pMsg->contLen, 0); ASSERT_EQ(pRsp->contLen, 0);
} }
TEST_F(DndTestProfile, 03_ConnectMsg_Show) { TEST_F(DndTestProfile, 03_ConnectMsg_Show) {
test.SendShowMetaMsg(TSDB_MGMT_TABLE_CONNS, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_CONNS, "");
CHECK_META("show connections", 7); CHECK_META("show connections", 7);
CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "connId"); CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "connId");
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "user"); CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "user");
...@@ -84,7 +84,7 @@ TEST_F(DndTestProfile, 03_ConnectMsg_Show) { ...@@ -84,7 +84,7 @@ TEST_F(DndTestProfile, 03_ConnectMsg_Show) {
CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "login_time"); CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "login_time");
CHECK_SCHEMA(6, TSDB_DATA_TYPE_TIMESTAMP, 8, "last_access"); CHECK_SCHEMA(6, TSDB_DATA_TYPE_TIMESTAMP, 8, "last_access");
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 1); EXPECT_EQ(test.GetShowRows(), 1);
CheckInt32(1); CheckInt32(1);
CheckBinary("root", TSDB_USER_LEN); CheckBinary("root", TSDB_USER_LEN);
...@@ -105,7 +105,7 @@ TEST_F(DndTestProfile, 04_HeartBeatMsg) { ...@@ -105,7 +105,7 @@ TEST_F(DndTestProfile, 04_HeartBeatMsg) {
pReq->numOfStreams = htonl(0); pReq->numOfStreams = htonl(0);
strcpy(pReq->app, "dnode_test_profile"); 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_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pMsg->code, 0);
...@@ -138,9 +138,9 @@ TEST_F(DndTestProfile, 05_KillConnMsg) { ...@@ -138,9 +138,9 @@ TEST_F(DndTestProfile, 05_KillConnMsg) {
SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen); SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen);
pReq->connId = htonl(connId); pReq->connId = htonl(connId);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_CONN, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_CONN, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
{ {
...@@ -153,10 +153,10 @@ TEST_F(DndTestProfile, 05_KillConnMsg) { ...@@ -153,10 +153,10 @@ TEST_F(DndTestProfile, 05_KillConnMsg) {
pReq->numOfStreams = htonl(0); pReq->numOfStreams = htonl(0);
strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->app, "dnode_test_profile");
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_HEARTBEAT, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_HEARTBEAT, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONNECTION); ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONNECTION);
ASSERT_EQ(pMsg->contLen, 0); ASSERT_EQ(pRsp->contLen, 0);
} }
{ {
...@@ -167,7 +167,7 @@ TEST_F(DndTestProfile, 05_KillConnMsg) { ...@@ -167,7 +167,7 @@ TEST_F(DndTestProfile, 05_KillConnMsg) {
strcpy(pReq->app, "dnode_test_profile"); strcpy(pReq->app, "dnode_test_profile");
strcpy(pReq->db, ""); 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_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pMsg->code, 0);
...@@ -198,9 +198,9 @@ TEST_F(DndTestProfile, 06_KillConnMsg_InvalidConn) { ...@@ -198,9 +198,9 @@ TEST_F(DndTestProfile, 06_KillConnMsg_InvalidConn) {
SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen); SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen);
pReq->connId = htonl(2345); pReq->connId = htonl(2345);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_CONN, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_CONN, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID); ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONN_ID);
} }
TEST_F(DndTestProfile, 07_KillQueryMsg) { TEST_F(DndTestProfile, 07_KillQueryMsg) {
...@@ -211,10 +211,10 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) { ...@@ -211,10 +211,10 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) {
pReq->connId = htonl(connId); pReq->connId = htonl(connId);
pReq->queryId = htonl(1234); pReq->queryId = htonl(1234);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_QUERY, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_QUERY, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
ASSERT_EQ(pMsg->contLen, 0); ASSERT_EQ(pRsp->contLen, 0);
} }
{ {
...@@ -227,7 +227,7 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) { ...@@ -227,7 +227,7 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) {
pReq->numOfStreams = htonl(0); pReq->numOfStreams = htonl(0);
strcpy(pReq->app, "dnode_test_profile"); 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_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pMsg->code, 0);
...@@ -261,13 +261,13 @@ TEST_F(DndTestProfile, 08_KillQueryMsg_InvalidConn) { ...@@ -261,13 +261,13 @@ TEST_F(DndTestProfile, 08_KillQueryMsg_InvalidConn) {
pReq->connId = htonl(2345); pReq->connId = htonl(2345);
pReq->queryId = htonl(1234); pReq->queryId = htonl(1234);
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_QUERY, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_QUERY, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID); ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONN_ID);
} }
TEST_F(DndTestProfile, 09_KillQueryMsg) { TEST_F(DndTestProfile, 09_KillQueryMsg) {
test.SendShowMetaMsg(TSDB_MGMT_TABLE_QUERIES, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_QUERIES, "");
CHECK_META("show queries", 14); CHECK_META("show queries", 14);
CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "queryId"); CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "queryId");
...@@ -285,6 +285,6 @@ TEST_F(DndTestProfile, 09_KillQueryMsg) { ...@@ -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(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"); CHECK_SCHEMA(13, TSDB_DATA_TYPE_BINARY, TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, "sql");
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 0); EXPECT_EQ(test.GetShowRows(), 0);
} }
aux_source_directory(. QTEST_SRC) aux_source_directory(. DQTEST_SRC)
add_executable(dnode_test_qnode ${QTEST_SRC}) add_executable(dnode_test_qnode ${DQTEST_SRC})
target_link_libraries( target_link_libraries(
dnode_test_qnode dnode_test_qnode
PUBLIC sut PUBLIC sut
......
/**
* @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
/**
* @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
aux_source_directory(. STEST_SRC) aux_source_directory(. SQTEST_SRC)
add_executable(dnode_test_snode ${STEST_SRC}) add_executable(dnode_test_snode ${SQTEST_SRC})
target_link_libraries( target_link_libraries(
dnode_test_snode dnode_test_snode
PUBLIC sut PUBLIC sut
......
/**
* @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
/**
* @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
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
*/ */
#include "base.h" #include "sut.h"
class DndTestStb : public ::testing::Test { class DndTestStb : public ::testing::Test {
protected: protected:
...@@ -51,9 +51,9 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { ...@@ -51,9 +51,9 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
pReq->cacheLastRow = 0; pReq->cacheLastRow = 0;
pReq->ignoreExist = 1; pReq->ignoreExist = 1;
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
{ {
...@@ -101,12 +101,12 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { ...@@ -101,12 +101,12 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
strcpy(pSchema->name, "tag3"); strcpy(pSchema->name, "tag3");
} }
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_STB, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); 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_META("show stables", 4);
CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, "name"); 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) { ...@@ -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(2, TSDB_DATA_TYPE_INT, 4, "columns");
CHECK_SCHEMA(3, TSDB_DATA_TYPE_INT, 4, "tags"); CHECK_SCHEMA(3, TSDB_DATA_TYPE_INT, 4, "tags");
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 1); EXPECT_EQ(test.GetShowRows(), 1);
CheckBinary("stb", TSDB_TABLE_NAME_LEN); CheckBinary("stb", TSDB_TABLE_NAME_LEN);
CheckTimestamp(); CheckTimestamp();
...@@ -128,7 +128,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { ...@@ -128,7 +128,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
STableInfoMsg* pReq = (STableInfoMsg*)rpcMallocCont(contLen); STableInfoMsg* pReq = (STableInfoMsg*)rpcMallocCont(contLen);
strcpy(pReq->tableFname, "1.d1.stb"); 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_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pMsg->code, 0);
...@@ -203,9 +203,9 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { ...@@ -203,9 +203,9 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
// restart // restart
test.Restart(); test.Restart();
test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1"); test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, "1.d1");
CHECK_META("show stables", 4); CHECK_META("show stables", 4);
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 1); EXPECT_EQ(test.GetShowRows(), 1);
CheckBinary("stb", TSDB_TABLE_NAME_LEN); CheckBinary("stb", TSDB_TABLE_NAME_LEN);
...@@ -219,13 +219,13 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) { ...@@ -219,13 +219,13 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
SDropStbMsg* pReq = (SDropStbMsg*)rpcMallocCont(contLen); SDropStbMsg* pReq = (SDropStbMsg*)rpcMallocCont(contLen);
strcpy(pReq->name, "1.d1.stb"); strcpy(pReq->name, "1.d1.stb");
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_STB, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_STB, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); 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_META("show stables", 4);
test.SendShowRetrieveMsg(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 0); EXPECT_EQ(test.GetShowRows(), 0);
} }
...@@ -21,7 +21,7 @@ class TestClient { ...@@ -21,7 +21,7 @@ class TestClient {
bool Init(const char* user, const char* pass, const char* fqdn, uint16_t port); bool Init(const char* user, const char* pass, const char* fqdn, uint16_t port);
void Cleanup(); void Cleanup();
SRpcMsg* SendMsg(SRpcMsg* pMsg); SRpcMsg* SendReq(SRpcMsg* pReq);
void SetRpcRsp(SRpcMsg* pRsp); void SetRpcRsp(SRpcMsg* pRsp);
tsem_t* GetSem(); tsem_t* GetSem();
......
...@@ -21,10 +21,10 @@ class TestServer { ...@@ -21,10 +21,10 @@ class TestServer {
bool Start(const char* path, const char* fqdn, uint16_t port, const char* firstEp); bool Start(const char* path, const char* fqdn, uint16_t port, const char* firstEp);
void Stop(); void Stop();
void Restart(); void Restart();
bool DoStart();
private: private:
SDnodeOpt BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp); SDnodeOpt BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp);
bool DoStart();
private: private:
SDnode* pDnode; SDnode* pDnode;
......
...@@ -37,7 +37,9 @@ class Testbase { ...@@ -37,7 +37,9 @@ class Testbase {
void Init(const char* path, int16_t port); void Init(const char* path, int16_t port);
void Cleanup(); void Cleanup();
void Restart(); 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: private:
void InitLog(const char* path); void InitLog(const char* path);
...@@ -48,8 +50,8 @@ class Testbase { ...@@ -48,8 +50,8 @@ class Testbase {
int32_t connId; int32_t connId;
public: public:
void SendShowMetaMsg(int8_t showType, const char* db); void SendShowMetaReq(int8_t showType, const char* db);
void SendShowRetrieveMsg(); void SendShowRetrieveReq();
STableMetaMsg* GetShowMeta(); STableMetaMsg* GetShowMeta();
SRetrieveTableRsp* GetRetrieveRsp(); SRetrieveTableRsp* GetRetrieveRsp();
...@@ -71,7 +73,7 @@ class Testbase { ...@@ -71,7 +73,7 @@ class Testbase {
const char* GetShowBinary(int32_t len); const char* GetShowBinary(int32_t len);
private: private:
int32_t showId; int64_t showId;
STableMetaMsg* pMeta; STableMetaMsg* pMeta;
SRetrieveTableRsp* pRetrieveRsp; SRetrieveTableRsp* pRetrieveRsp;
char* pData; char* pData;
......
...@@ -13,12 +13,12 @@ ...@@ -13,12 +13,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#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; TestClient* client = (TestClient*)parent;
client->SetRpcRsp(pMsg); client->SetRpcRsp(pRsp);
uInfo("response:%s from dnode, code:0x%x", TMSG_INFO(pMsg->msgType), pMsg->code); uInfo("response:%s from dnode, code:0x%x", TMSG_INFO(pRsp->msgType), pRsp->code);
tsem_post(client->GetSem()); tsem_post(client->GetSem());
} }
...@@ -59,14 +59,14 @@ void TestClient::Cleanup() { ...@@ -59,14 +59,14 @@ void TestClient::Cleanup() {
rpcClose(clientRpc); rpcClose(clientRpc);
} }
SRpcMsg* TestClient::SendMsg(SRpcMsg* pMsg) { SRpcMsg* TestClient::SendReq(SRpcMsg* pReq) {
SEpSet epSet = {0}; SEpSet epSet = {0};
epSet.inUse = 0; epSet.inUse = 0;
epSet.numOfEps = 1; epSet.numOfEps = 1;
epSet.port[0] = port; epSet.port[0] = port;
memcpy(epSet.fqdn[0], fqdn, TSDB_FQDN_LEN); memcpy(epSet.fqdn[0], fqdn, TSDB_FQDN_LEN);
rpcSendRequest(clientRpc, &epSet, pMsg, NULL); rpcSendRequest(clientRpc, &epSet, pReq, NULL);
tsem_wait(&sem); tsem_wait(&sem);
return pRsp; return pRsp;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "base.h" #include "sut.h"
void* serverLoop(void* param) { void* serverLoop(void* param) {
while (1) { while (1) {
......
...@@ -13,16 +13,16 @@ ...@@ -13,16 +13,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "base.h" #include "sut.h"
void Testbase::InitLog(const char* path) { void Testbase::InitLog(const char* path) {
dDebugFlag = 207; dDebugFlag = 0;
vDebugFlag = 0; vDebugFlag = 0;
mDebugFlag = 207; mDebugFlag = 143;
cDebugFlag = 0; cDebugFlag = 0;
jniDebugFlag = 0; jniDebugFlag = 0;
tmrDebugFlag = 0; tmrDebugFlag = 0;
uDebugFlag = 143; uDebugFlag = 0;
rpcDebugFlag = 0; rpcDebugFlag = 0;
qDebugFlag = 0; qDebugFlag = 0;
wDebugFlag = 0; wDebugFlag = 0;
...@@ -60,26 +60,30 @@ void Testbase::Cleanup() { ...@@ -60,26 +60,30 @@ void Testbase::Cleanup() {
void Testbase::Restart() { server.Restart(); } 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}; SRpcMsg rpcMsg = {0};
rpcMsg.pCont = pCont; rpcMsg.pCont = pCont;
rpcMsg.contLen = contLen; rpcMsg.contLen = contLen;
rpcMsg.msgType = msgType; rpcMsg.msgType = msgType;
return client.SendMsg(&rpcMsg); return client.SendReq(&rpcMsg);
} }
void Testbase::SendShowMetaMsg(int8_t showType, const char* db) { void Testbase::SendShowMetaReq(int8_t showType, const char* db) {
int32_t contLen = sizeof(SShowMsg); int32_t contLen = sizeof(SShowReq);
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(contLen); SShowReq* pShow = (SShowReq*)rpcMallocCont(contLen);
pShow->type = showType; pShow->type = showType;
strcpy(pShow->db, db); strcpy(pShow->db, db);
SRpcMsg* pMsg = SendMsg(TDMT_MND_SHOW, pShow, contLen); SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW, pShow, contLen);
SShowRsp* pShowRsp = (SShowRsp*)pMsg->pCont; SShowRsp* pShowRsp = (SShowRsp*)pRsp->pCont;
ASSERT(pShowRsp != nullptr); ASSERT(pShowRsp != nullptr);
pShowRsp->showId = htonl(pShowRsp->showId); pShowRsp->showId = htobe64(pShowRsp->showId);
pMeta = &pShowRsp->tableMeta; pMeta = &pShowRsp->tableMeta;
pMeta->numOfTags = htonl(pMeta->numOfTags); pMeta->numOfTags = htonl(pMeta->numOfTags);
pMeta->numOfColumns = htonl(pMeta->numOfColumns); pMeta->numOfColumns = htonl(pMeta->numOfColumns);
...@@ -117,15 +121,15 @@ int32_t Testbase::GetMetaNum() { return pMeta->numOfColumns; } ...@@ -117,15 +121,15 @@ int32_t Testbase::GetMetaNum() { return pMeta->numOfColumns; }
const char* Testbase::GetMetaTbName() { return pMeta->tbFname; } const char* Testbase::GetMetaTbName() { return pMeta->tbFname; }
void Testbase::SendShowRetrieveMsg() { void Testbase::SendShowRetrieveReq() {
int32_t contLen = sizeof(SRetrieveTableMsg); int32_t contLen = sizeof(SRetrieveTableReq);
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(contLen); SRetrieveTableReq* pRetrieve = (SRetrieveTableReq*)rpcMallocCont(contLen);
pRetrieve->showId = htonl(showId); pRetrieve->showId = htobe64(showId);
pRetrieve->free = 0; pRetrieve->free = 0;
SRpcMsg* pMsg = SendMsg(TDMT_MND_SHOW_RETRIEVE, pRetrieve, contLen); SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW_RETRIEVE, pRetrieve, contLen);
pRetrieveRsp = (SRetrieveTableRsp*)pMsg->pCont; pRetrieveRsp = (SRetrieveTableRsp*)pRsp->pCont;
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen); pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
*/ */
#include "base.h" #include "sut.h"
class DndTestVgroup : public ::testing::Test { class DndTestVgroup : public ::testing::Test {
protected: protected:
...@@ -60,9 +60,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { ...@@ -60,9 +60,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
pReplica->port = htons(9150); pReplica->port = htons(9150);
} }
SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_VNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_VNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
} }
...@@ -100,9 +100,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { ...@@ -100,9 +100,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
pReplica->port = htons(9150); pReplica->port = htons(9150);
} }
SRpcMsg* pMsg = test.SendMsg(TDMT_DND_ALTER_VNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_VNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
} }
...@@ -121,9 +121,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) { ...@@ -121,9 +121,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
rpcMsg.contLen = sizeof(SDropVnodeMsg); rpcMsg.contLen = sizeof(SDropVnodeMsg);
rpcMsg.msgType = TDMT_DND_DROP_VNODE; rpcMsg.msgType = TDMT_DND_DROP_VNODE;
SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_VNODE, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_VNODE, pReq, contLen);
ASSERT_NE(pMsg, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pMsg->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
} }
} }
...@@ -8,7 +8,12 @@ target_include_directories( ...@@ -8,7 +8,12 @@ target_include_directories(
target_link_libraries( target_link_libraries(
mnode mnode
PRIVATE sdb PRIVATE sdb
PRIVATE wal
PRIVATE transport PRIVATE transport
PRIVATE cjson PRIVATE cjson
PRIVATE sync PRIVATE sync
) )
if(${BUILD_TEST})
add_subdirectory(test)
endif(${BUILD_TEST})
\ No newline at end of file
...@@ -65,10 +65,10 @@ typedef enum { ...@@ -65,10 +65,10 @@ typedef enum {
TRN_STAGE_PREPARE = 0, TRN_STAGE_PREPARE = 0,
TRN_STAGE_REDO_LOG = 1, TRN_STAGE_REDO_LOG = 1,
TRN_STAGE_REDO_ACTION = 2, TRN_STAGE_REDO_ACTION = 2,
TRN_STAGE_UNDO_LOG = 3, TRN_STAGE_COMMIT_LOG = 3,
TRN_STAGE_UNDO_ACTION = 4, TRN_STAGE_COMMIT = 4,
TRN_STAGE_COMMIT_LOG = 5, TRN_STAGE_UNDO_ACTION = 5,
TRN_STAGE_COMMIT = 6, TRN_STAGE_UNDO_LOG = 6,
TRN_STAGE_ROLLBACK = 7, TRN_STAGE_ROLLBACK = 7,
TRN_STAGE_FINISHED = 8 TRN_STAGE_FINISHED = 8
} ETrnStage; } ETrnStage;
...@@ -161,8 +161,14 @@ typedef struct { ...@@ -161,8 +161,14 @@ typedef struct {
typedef struct { typedef struct {
int32_t maxUsers; int32_t maxUsers;
int32_t maxDbs; int32_t maxDbs;
int32_t maxStbs;
int32_t maxTbs;
int32_t maxTimeSeries; int32_t maxTimeSeries;
int32_t maxStreams; int32_t maxStreams;
int32_t maxFuncs;
int32_t maxConsumers;
int32_t maxConns;
int32_t maxTopics;
int64_t maxStorage; // In unit of GB int64_t maxStorage; // In unit of GB
int32_t accessState; // Configured only by command int32_t accessState; // Configured only by command
} SAcctCfg; } SAcctCfg;
......
...@@ -17,11 +17,13 @@ ...@@ -17,11 +17,13 @@
#define _TD_MND_INT_H_ #define _TD_MND_INT_H_
#include "mndDef.h" #include "mndDef.h"
#include "sdb.h" #include "sdb.h"
#include "tcache.h" #include "tcache.h"
#include "tep.h" #include "tep.h"
#include "tqueue.h" #include "tqueue.h"
#include "ttime.h" #include "ttime.h"
#include "wal.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -65,6 +67,7 @@ typedef struct { ...@@ -65,6 +67,7 @@ typedef struct {
typedef struct { typedef struct {
int32_t errCode; int32_t errCode;
sem_t syncSem; sem_t syncSem;
SWal *pWal;
SSyncNode *pSyncNode; SSyncNode *pSyncNode;
ESyncState state; ESyncState state;
} SSyncMgmt; } SSyncMgmt;
...@@ -88,14 +91,15 @@ typedef struct SMnode { ...@@ -88,14 +91,15 @@ typedef struct SMnode {
STelemMgmt telemMgmt; STelemMgmt telemMgmt;
SSyncMgmt syncMgmt; SSyncMgmt syncMgmt;
MndMsgFp msgFp[TDMT_MAX]; MndMsgFp msgFp[TDMT_MAX];
SendMsgToDnodeFp sendMsgToDnodeFp; SendReqToDnodeFp sendReqToDnodeFp;
SendMsgToMnodeFp sendMsgToMnodeFp; SendReqToMnodeFp sendReqToMnodeFp;
SendRedirectMsgFp sendRedirectMsgFp; SendRedirectRspFp sendRedirectRspFp;
PutReqToMWriteQFp putReqToMWriteQFp;
} SMnode; } SMnode;
void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg); int32_t mndSendReqToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg);
void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg); int32_t mndSendReqToMnode(SMnode *pMnode, SRpcMsg *pMsg);
void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg); void mndSendRedirectRsp(SMnode *pMnode, SRpcMsg *pMsg);
void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp); void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp);
uint64_t mndGenerateUid(char *name, int32_t len) ; uint64_t mndGenerateUid(char *name, int32_t len) ;
......
...@@ -28,6 +28,7 @@ typedef struct { ...@@ -28,6 +28,7 @@ typedef struct {
int8_t msgSent; int8_t msgSent;
int8_t msgReceived; int8_t msgReceived;
int32_t errCode; int32_t errCode;
int32_t acceptableCode;
int32_t contLen; int32_t contLen;
void *pCont; void *pCont;
} STransAction; } STransAction;
...@@ -45,6 +46,7 @@ int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction); ...@@ -45,6 +46,7 @@ int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction);
int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans); int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans);
void mndTransProcessRsp(SMnodeMsg *pMsg); void mndTransProcessRsp(SMnodeMsg *pMsg);
void mndTransPullup(SMnode *pMnode);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -18,17 +18,17 @@ ...@@ -18,17 +18,17 @@
#include "mndShow.h" #include "mndShow.h"
#define TSDB_ACCT_VER_NUMBER 1 #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 int32_t mndCreateDefaultAcct(SMnode *pMnode);
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct); static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct);
static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw); static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw);
static int32_t mndAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct); static int32_t mndAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct);
static int32_t mndAcctActionDelete(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 mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew);
static int32_t mndProcessCreateAcctMsg(SMnodeMsg *pMnodeMsg); static int32_t mndProcessCreateAcctReq(SMnodeMsg *pReq);
static int32_t mndProcessAlterAcctMsg(SMnodeMsg *pMnodeMsg); static int32_t mndProcessAlterAcctReq(SMnodeMsg *pReq);
static int32_t mndProcessDropAcctMsg(SMnodeMsg *pMnodeMsg); static int32_t mndProcessDropAcctReq(SMnodeMsg *pReq);
int32_t mndInitAcct(SMnode *pMnode) { int32_t mndInitAcct(SMnode *pMnode) {
SSdbTable table = {.sdbType = SDB_ACCT, SSdbTable table = {.sdbType = SDB_ACCT,
...@@ -40,9 +40,9 @@ int32_t mndInitAcct(SMnode *pMnode) { ...@@ -40,9 +40,9 @@ int32_t mndInitAcct(SMnode *pMnode) {
.updateFp = (SdbUpdateFp)mndAcctActionUpdate, .updateFp = (SdbUpdateFp)mndAcctActionUpdate,
.deleteFp = (SdbDeleteFp)mndAcctActionDelete}; .deleteFp = (SdbDeleteFp)mndAcctActionDelete};
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctMsg); mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctReq);
mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctMsg); mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctReq);
mndSetMsgHandle(pMnode, TDMT_MND_DROP_ACCT, mndProcessDropAcctMsg); mndSetMsgHandle(pMnode, TDMT_MND_DROP_ACCT, mndProcessDropAcctReq);
return sdbSetTable(pMnode->pSdb, table); return sdbSetTable(pMnode->pSdb, table);
} }
...@@ -55,10 +55,16 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) { ...@@ -55,10 +55,16 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
acctObj.createdTime = taosGetTimestampMs(); acctObj.createdTime = taosGetTimestampMs();
acctObj.updateTime = acctObj.createdTime; acctObj.updateTime = acctObj.createdTime;
acctObj.acctId = 1; acctObj.acctId = 1;
acctObj.cfg = (SAcctCfg){.maxUsers = 1024, acctObj.cfg = (SAcctCfg){.maxUsers = INT32_MAX,
.maxDbs = 1024, .maxDbs = INT32_MAX,
.maxStbs = INT32_MAX,
.maxTbs = INT32_MAX,
.maxTimeSeries = 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, .maxStorage = INT64_MAX,
.accessState = TSDB_VN_ALL_ACCCESS}; .accessState = TSDB_VN_ALL_ACCCESS};
...@@ -66,96 +72,133 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) { ...@@ -66,96 +72,133 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
if (pRaw == NULL) return -1; if (pRaw == NULL) return -1;
sdbSetRawStatus(pRaw, SDB_STATUS_READY); 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); return sdbWrite(pMnode->pSdb, pRaw);
} }
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) { 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); 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; int32_t dataPos = 0;
SDB_SET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN) SDB_SET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN, ACCT_ENCODE_OVER)
SDB_SET_INT64(pRaw, dataPos, pAcct->createdTime) SDB_SET_INT64(pRaw, dataPos, pAcct->createdTime, ACCT_ENCODE_OVER)
SDB_SET_INT64(pRaw, dataPos, pAcct->updateTime) SDB_SET_INT64(pRaw, dataPos, pAcct->updateTime, ACCT_ENCODE_OVER)
SDB_SET_INT32(pRaw, dataPos, pAcct->acctId) SDB_SET_INT32(pRaw, dataPos, pAcct->acctId, ACCT_ENCODE_OVER)
SDB_SET_INT32(pRaw, dataPos, pAcct->status) SDB_SET_INT32(pRaw, dataPos, pAcct->status, ACCT_ENCODE_OVER)
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxUsers) SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxUsers, ACCT_ENCODE_OVER)
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxDbs) SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxDbs, ACCT_ENCODE_OVER)
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTimeSeries) SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStbs, ACCT_ENCODE_OVER)
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStreams) SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTbs, ACCT_ENCODE_OVER)
SDB_SET_INT64(pRaw, dataPos, pAcct->cfg.maxStorage) SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTimeSeries, ACCT_ENCODE_OVER)
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.accessState) SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStreams, ACCT_ENCODE_OVER)
SDB_SET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE) SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxFuncs, ACCT_ENCODE_OVER)
SDB_SET_DATALEN(pRaw, dataPos); 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; return pRaw;
} }
static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) { static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
int8_t sver = 0; 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) { if (sver != TSDB_ACCT_VER_NUMBER) {
mError("failed to decode acct since %s", terrstr());
terrno = TSDB_CODE_SDB_INVALID_DATA_VER; 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); SAcctObj *pAcct = sdbGetRowObj(pRow);
if (pAcct == NULL) return NULL; if (pAcct == NULL) goto ACCT_DECODE_OVER;
int32_t dataPos = 0; int32_t dataPos = 0;
SDB_GET_BINARY(pRaw, pRow, dataPos, pAcct->acct, TSDB_USER_LEN) SDB_GET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN, ACCT_DECODE_OVER)
SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->createdTime) SDB_GET_INT64(pRaw, dataPos, &pAcct->createdTime, ACCT_DECODE_OVER)
SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->updateTime) SDB_GET_INT64(pRaw, dataPos, &pAcct->updateTime, ACCT_DECODE_OVER)
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->acctId) SDB_GET_INT32(pRaw, dataPos, &pAcct->acctId, ACCT_DECODE_OVER)
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->status) SDB_GET_INT32(pRaw, dataPos, &pAcct->status, ACCT_DECODE_OVER)
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxUsers) SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxUsers, ACCT_DECODE_OVER)
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxDbs) SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxDbs, ACCT_DECODE_OVER)
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxTimeSeries) SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStbs, ACCT_DECODE_OVER)
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxStreams) SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTbs, ACCT_DECODE_OVER)
SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->cfg.maxStorage) SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTimeSeries, ACCT_DECODE_OVER)
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.accessState) SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStreams, ACCT_DECODE_OVER)
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_ACCT_RESERVE_SIZE) 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; return pRow;
} }
static int32_t mndAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct) { 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; return 0;
} }
static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) { 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; return 0;
} }
static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct) { static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew) {
mTrace("acct:%s, perform update action", pOldAcct->acct); mTrace("acct:%s, perform update action, old_row:%p new_row:%p", pOld->acct, pOld, pNew);
pOldAcct->updateTime = pNewAcct->updateTime; pOld->updateTime = pNew->updateTime;
pOldAcct->status = pNewAcct->status; pOld->status = pNew->status;
memcpy(&pOldAcct->cfg, &pNewAcct->cfg, sizeof(SAcctInfo)); memcpy(&pOld->cfg, &pNew->cfg, sizeof(SAcctCfg));
return 0; return 0;
} }
static int32_t mndProcessCreateAcctMsg(SMnodeMsg *pMnodeMsg) { static int32_t mndProcessCreateAcctReq(SMnodeMsg *pReq) {
terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; 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; return -1;
} }
static int32_t mndProcessAlterAcctMsg(SMnodeMsg *pMnodeMsg) { static int32_t mndProcessAlterAcctReq(SMnodeMsg *pReq) {
terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; 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; return -1;
} }
static int32_t mndProcessDropAcctMsg(SMnodeMsg *pMnodeMsg) { static int32_t mndProcessDropAcctReq(SMnodeMsg *pReq) {
terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED; 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; return -1;
} }
\ No newline at end of file
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h"
#include "mndAuth.h" #include "mndAuth.h"
int32_t mndInitAuth(SMnode *pMnode) { return 0; } int32_t mndInitAuth(SMnode *pMnode) { return 0; }
......
...@@ -26,13 +26,13 @@ static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj); ...@@ -26,13 +26,13 @@ static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj);
static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw); static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw);
static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj); static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj);
static int32_t mndBnodeActionDelete(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 mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOld, SBnodeObj *pNew);
static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg); static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pReq);
static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg); static int32_t mndProcessDropBnodeReq(SMnodeMsg *pReq);
static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pMsg); static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pRsp);
static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pMsg); static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pRsp);
static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta); static int32_t mndGetBnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta);
static int32_t mndRetrieveBnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows); static int32_t mndRetrieveBnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows);
static void mndCancelGetNextBnode(SMnode *pMnode, void *pIter); static void mndCancelGetNextBnode(SMnode *pMnode, void *pIter);
int32_t mndInitBnode(SMnode *pMnode) { int32_t mndInitBnode(SMnode *pMnode) {
...@@ -58,10 +58,9 @@ int32_t mndInitBnode(SMnode *pMnode) { ...@@ -58,10 +58,9 @@ int32_t mndInitBnode(SMnode *pMnode) {
void mndCleanupBnode(SMnode *pMnode) {} void mndCleanupBnode(SMnode *pMnode) {}
static SBnodeObj *mndAcquireBnode(SMnode *pMnode, int32_t snodeId) { static SBnodeObj *mndAcquireBnode(SMnode *pMnode, int32_t bnodeId) {
SSdb *pSdb = pMnode->pSdb; SBnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_BNODE, &bnodeId);
SBnodeObj *pObj = sdbAcquire(pSdb, SDB_BNODE, &snodeId); if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
if (pObj == NULL) {
terrno = TSDB_CODE_MND_BNODE_NOT_EXIST; terrno = TSDB_CODE_MND_BNODE_NOT_EXIST;
} }
return pObj; return pObj;
...@@ -73,47 +72,72 @@ static void mndReleaseBnode(SMnode *pMnode, SBnodeObj *pObj) { ...@@ -73,47 +72,72 @@ static void mndReleaseBnode(SMnode *pMnode, SBnodeObj *pObj) {
} }
static SSdbRaw *mndBnodeActionEncode(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); 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; int32_t dataPos = 0;
SDB_SET_INT32(pRaw, dataPos, pObj->id); SDB_SET_INT32(pRaw, dataPos, pObj->id, BNODE_ENCODE_OVER)
SDB_SET_INT64(pRaw, dataPos, pObj->createdTime) SDB_SET_INT64(pRaw, dataPos, pObj->createdTime, BNODE_ENCODE_OVER)
SDB_SET_INT64(pRaw, dataPos, pObj->updateTime) SDB_SET_INT64(pRaw, dataPos, pObj->updateTime, BNODE_ENCODE_OVER)
SDB_SET_RESERVE(pRaw, dataPos, TSDB_BNODE_RESERVE_SIZE) 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; return pRaw;
} }
static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw) { static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
int8_t sver = 0; 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) { if (sver != TSDB_BNODE_VER_NUMBER) {
terrno = TSDB_CODE_SDB_INVALID_DATA_VER; terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
mError("failed to decode snode since %s", terrstr()); goto BNODE_DECODE_OVER;
return NULL;
} }
SSdbRow *pRow = sdbAllocRow(sizeof(SBnodeObj)); SSdbRow *pRow = sdbAllocRow(sizeof(SBnodeObj));
if (pRow == NULL) goto BNODE_DECODE_OVER;
SBnodeObj *pObj = sdbGetRowObj(pRow); SBnodeObj *pObj = sdbGetRowObj(pRow);
if (pObj == NULL) return NULL; if (pObj == NULL) goto BNODE_DECODE_OVER;
int32_t dataPos = 0; int32_t dataPos = 0;
SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id) SDB_GET_INT32(pRaw, dataPos, &pObj->id, BNODE_DECODE_OVER)
SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime) SDB_GET_INT64(pRaw, dataPos, &pObj->createdTime, BNODE_DECODE_OVER)
SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime) SDB_GET_INT64(pRaw, dataPos, &pObj->updateTime, BNODE_DECODE_OVER)
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_BNODE_RESERVE_SIZE) 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; return pRow;
} }
static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj) { 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); pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id);
if (pObj->pDnode == NULL) { if (pObj->pDnode == NULL) {
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST; 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; return -1;
} }
...@@ -121,7 +145,7 @@ static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj) { ...@@ -121,7 +145,7 @@ static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj) {
} }
static int32_t mndBnodeActionDelete(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) { if (pObj->pDnode != NULL) {
sdbRelease(pSdb, pObj->pDnode); sdbRelease(pSdb, pObj->pDnode);
pObj->pDnode = NULL; pObj->pDnode = NULL;
...@@ -130,9 +154,9 @@ static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj) { ...@@ -130,9 +154,9 @@ static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj) {
return 0; return 0;
} }
static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOldBnode, SBnodeObj *pNewBnode) { static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOld, SBnodeObj *pNew) {
mTrace("snode:%d, perform update action", pOldBnode->id); mTrace("bnode:%d, perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew);
pOldBnode->updateTime = pNewBnode->updateTime; pOld->updateTime = pNew->updateTime;
return 0; return 0;
} }
...@@ -144,6 +168,14 @@ static int32_t mndSetCreateBnodeRedoLogs(STrans *pTrans, SBnodeObj *pObj) { ...@@ -144,6 +168,14 @@ static int32_t mndSetCreateBnodeRedoLogs(STrans *pTrans, SBnodeObj *pObj) {
return 0; 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) { static int32_t mndSetCreateBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) {
SSdbRaw *pCommitRaw = mndBnodeActionEncode(pObj); SSdbRaw *pCommitRaw = mndBnodeActionEncode(pObj);
if (pCommitRaw == NULL) return -1; if (pCommitRaw == NULL) return -1;
...@@ -153,60 +185,69 @@ static int32_t mndSetCreateBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) { ...@@ -153,60 +185,69 @@ static int32_t mndSetCreateBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) {
} }
static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) { static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) {
SDCreateBnodeMsg *pMsg = malloc(sizeof(SDCreateBnodeMsg)); SDCreateBnodeReq *pReq = malloc(sizeof(SDCreateBnodeReq));
if (pMsg == NULL) { if (pReq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1; return -1;
} }
pMsg->dnodeId = htonl(pDnode->id); pReq->dnodeId = htonl(pDnode->id);
STransAction action = {0}; STransAction action = {0};
action.epSet = mndGetDnodeEpset(pDnode); action.epSet = mndGetDnodeEpset(pDnode);
action.pCont = pMsg; action.pCont = pReq;
action.contLen = sizeof(SDCreateBnodeMsg); action.contLen = sizeof(SDCreateBnodeReq);
action.msgType = TDMT_DND_CREATE_BNODE; action.msgType = TDMT_DND_CREATE_BNODE;
action.acceptableCode = TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED;
if (mndTransAppendRedoAction(pTrans, &action) != 0) { if (mndTransAppendRedoAction(pTrans, &action) != 0) {
free(pMsg); free(pReq);
return -1; return -1;
} }
return 0; return 0;
} }
static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateBnodeMsg *pCreate) { static int32_t mndSetCreateBnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) {
SBnodeObj snodeObj = {0}; SDDropBnodeReq *pReq = malloc(sizeof(SDDropBnodeReq));
snodeObj.id = pDnode->id; if (pReq == NULL) {
snodeObj.createdTime = taosGetTimestampMs(); terrno = TSDB_CODE_OUT_OF_MEMORY;
snodeObj.updateTime = snodeObj.createdTime; return -1;
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;
} }
mDebug("trans:%d, used to create snode:%d", pTrans->id, pCreate->dnodeId); pReq->dnodeId = htonl(pDnode->id);
if (mndSetCreateBnodeRedoLogs(pTrans, &snodeObj) != 0) { STransAction action = {0};
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); action.epSet = mndGetDnodeEpset(pDnode);
goto CREATE_BNODE_OVER; 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) { if (mndTransAppendUndoAction(pTrans, &action) != 0) {
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr()); free(pReq);
goto CREATE_BNODE_OVER; return -1;
} }
if (mndSetCreateBnodeRedoActions(pTrans, pDnode, &snodeObj) != 0) { return 0;
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr()); }
goto CREATE_BNODE_OVER;
}
if (mndTransPrepare(pMnode, pTrans) != 0) { static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pReq, SDnodeObj *pDnode, SMCreateBnodeReq *pCreate) {
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); int32_t code = -1;
goto CREATE_BNODE_OVER;
} 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; code = 0;
...@@ -215,33 +256,37 @@ CREATE_BNODE_OVER: ...@@ -215,33 +256,37 @@ CREATE_BNODE_OVER:
return code; return code;
} }
static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg) { static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pReq) {
SMnode *pMnode = pMsg->pMnode; SMnode *pMnode = pReq->pMnode;
SMCreateBnodeMsg *pCreate = pMsg->rpcMsg.pCont; SMCreateBnodeReq *pCreate = pReq->rpcMsg.pCont;
pCreate->dnodeId = htonl(pCreate->dnodeId); 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); SBnodeObj *pObj = mndAcquireBnode(pMnode, pCreate->dnodeId);
if (pObj != NULL) { 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); mndReleaseBnode(pMnode, pObj);
return -1; 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); SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId);
if (pDnode == NULL) { 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; terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
return -1; return -1;
} }
int32_t code = mndCreateBnode(pMnode, pMsg, pDnode, pCreate); int32_t code = mndCreateBnode(pMnode, pReq, pDnode, pCreate);
mndReleaseDnode(pMnode, pDnode); mndReleaseDnode(pMnode, pDnode);
if (code != 0) { 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; return -1;
} }
...@@ -265,56 +310,39 @@ static int32_t mndSetDropBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) { ...@@ -265,56 +310,39 @@ static int32_t mndSetDropBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) {
} }
static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) { static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) {
SDDropBnodeMsg *pMsg = malloc(sizeof(SDDropBnodeMsg)); SDDropBnodeReq *pReq = malloc(sizeof(SDDropBnodeReq));
if (pMsg == NULL) { if (pReq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1; return -1;
} }
pMsg->dnodeId = htonl(pDnode->id); pReq->dnodeId = htonl(pDnode->id);
STransAction action = {0}; STransAction action = {0};
action.epSet = mndGetDnodeEpset(pDnode); action.epSet = mndGetDnodeEpset(pDnode);
action.pCont = pMsg; action.pCont = pReq;
action.contLen = sizeof(SDDropBnodeMsg); action.contLen = sizeof(SDDropBnodeReq);
action.msgType = TDMT_DND_DROP_BNODE; action.msgType = TDMT_DND_DROP_BNODE;
action.acceptableCode = TSDB_CODE_DND_BNODE_NOT_DEPLOYED;
if (mndTransAppendRedoAction(pTrans, &action) != 0) { if (mndTransAppendRedoAction(pTrans, &action) != 0) {
free(pMsg); free(pReq);
return -1; return -1;
} }
return 0; 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; 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) { mDebug("trans:%d, used to drop bnode:%d", pTrans->id, pObj->id);
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr()); if (mndSetDropBnodeRedoLogs(pTrans, pObj) != 0) goto DROP_BNODE_OVER;
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;
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;
}
code = 0; code = 0;
...@@ -323,48 +351,48 @@ DROP_BNODE_OVER: ...@@ -323,48 +351,48 @@ DROP_BNODE_OVER:
return code; return code;
} }
static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg) { static int32_t mndProcessDropBnodeReq(SMnodeMsg *pReq) {
SMnode *pMnode = pMsg->pMnode; SMnode *pMnode = pReq->pMnode;
SMDropBnodeMsg *pDrop = pMsg->rpcMsg.pCont; SMDropBnodeReq *pDrop = pReq->rpcMsg.pCont;
pDrop->dnodeId = htonl(pDrop->dnodeId); 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) { if (pDrop->dnodeId <= 0) {
terrno = TSDB_CODE_SDB_APP_ERROR; 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; return -1;
} }
SBnodeObj *pObj = mndAcquireBnode(pMnode, pDrop->dnodeId); SBnodeObj *pObj = mndAcquireBnode(pMnode, pDrop->dnodeId);
if (pObj == NULL) { if (pObj == NULL) {
mError("snode:%d, not exist", pDrop->dnodeId); mError("bnode:%d, failed to drop since %s", pDrop->dnodeId, terrstr());
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
return -1; return -1;
} }
int32_t code = mndDropBnode(pMnode, pMsg, pObj); int32_t code = mndDropBnode(pMnode, pReq, pObj);
if (code != 0) { 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; return -1;
} }
sdbRelease(pMnode->pSdb, pMnode); sdbRelease(pMnode->pSdb, pObj);
return TSDB_CODE_MND_ACTION_IN_PROGRESS; return TSDB_CODE_MND_ACTION_IN_PROGRESS;
} }
static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pMsg) { static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pRsp) {
mndTransProcessRsp(pMsg); mndTransProcessRsp(pRsp);
return 0; return 0;
} }
static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pMsg) { static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pRsp) {
mndTransProcessRsp(pMsg); mndTransProcessRsp(pRsp);
return 0; return 0;
} }
static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) { static int32_t mndGetBnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) {
SMnode *pMnode = pMsg->pMnode; SMnode *pMnode = pReq->pMnode;
SSdb *pSdb = pMnode->pSdb; SSdb *pSdb = pMnode->pSdb;
int32_t cols = 0; int32_t cols = 0;
...@@ -403,8 +431,8 @@ static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * ...@@ -403,8 +431,8 @@ static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
return 0; return 0;
} }
static int32_t mndRetrieveBnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) { static int32_t mndRetrieveBnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) {
SMnode *pMnode = pMsg->pMnode; SMnode *pMnode = pReq->pMnode;
SSdb *pSdb = pMnode->pSdb; SSdb *pSdb = pMnode->pSdb;
int32_t numOfRows = 0; int32_t numOfRows = 0;
int32_t cols = 0; int32_t cols = 0;
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "mndCluster.h" #include "mndCluster.h"
#include "mndShow.h" #include "mndShow.h"
#include "mndTrans.h"
#define TSDB_CLUSTER_VER_NUMBE 1 #define TSDB_CLUSTER_VER_NUMBE 1
#define TSDB_CLUSTER_RESERVE_SIZE 64 #define TSDB_CLUSTER_RESERVE_SIZE 64
...@@ -33,7 +32,7 @@ static void mndCancelGetNextCluster(SMnode *pMnode, void *pIter); ...@@ -33,7 +32,7 @@ static void mndCancelGetNextCluster(SMnode *pMnode, void *pIter);
int32_t mndInitCluster(SMnode *pMnode) { int32_t mndInitCluster(SMnode *pMnode) {
SSdbTable table = {.sdbType = SDB_CLUSTER, SSdbTable table = {.sdbType = SDB_CLUSTER,
.keyType = SDB_KEY_INT32, .keyType = SDB_KEY_INT64,
.deployFp = (SdbDeployFp)mndCreateDefaultCluster, .deployFp = (SdbDeployFp)mndCreateDefaultCluster,
.encodeFp = (SdbEncodeFp)mndClusterActionEncode, .encodeFp = (SdbEncodeFp)mndClusterActionEncode,
.decodeFp = (SdbDecodeFp)mndClusterActionDecode, .decodeFp = (SdbDecodeFp)mndClusterActionDecode,
...@@ -63,55 +62,80 @@ int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len) { ...@@ -63,55 +62,80 @@ int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len) {
} }
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) { 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); 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; int32_t dataPos = 0;
SDB_SET_INT64(pRaw, dataPos, pCluster->id); SDB_SET_INT64(pRaw, dataPos, pCluster->id, CLUSTER_ENCODE_OVER)
SDB_SET_INT64(pRaw, dataPos, pCluster->createdTime) SDB_SET_INT64(pRaw, dataPos, pCluster->createdTime, CLUSTER_ENCODE_OVER)
SDB_SET_INT64(pRaw, dataPos, pCluster->updateTime) SDB_SET_INT64(pRaw, dataPos, pCluster->updateTime, CLUSTER_ENCODE_OVER)
SDB_SET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN) SDB_SET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, CLUSTER_ENCODE_OVER)
SDB_SET_RESERVE(pRaw, dataPos, TSDB_CLUSTER_RESERVE_SIZE) 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; return pRaw;
} }
static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) { static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
int8_t sver = 0; 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) { if (sver != TSDB_CLUSTER_VER_NUMBE) {
terrno = TSDB_CODE_SDB_INVALID_DATA_VER; terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
mError("failed to decode cluster since %s", terrstr()); goto CLUSTER_DECODE_OVER;
return NULL;
} }
SSdbRow *pRow = sdbAllocRow(sizeof(SClusterObj)); SSdbRow *pRow = sdbAllocRow(sizeof(SClusterObj));
if (pRow == NULL) goto CLUSTER_DECODE_OVER;
SClusterObj *pCluster = sdbGetRowObj(pRow); SClusterObj *pCluster = sdbGetRowObj(pRow);
if (pCluster == NULL) return NULL; if (pCluster == NULL) goto CLUSTER_DECODE_OVER;
int32_t dataPos = 0; int32_t dataPos = 0;
SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->id) SDB_GET_INT64(pRaw, dataPos, &pCluster->id, CLUSTER_DECODE_OVER)
SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->createdTime) SDB_GET_INT64(pRaw, dataPos, &pCluster->createdTime, CLUSTER_DECODE_OVER)
SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->updateTime) SDB_GET_INT64(pRaw, dataPos, &pCluster->updateTime, CLUSTER_DECODE_OVER)
SDB_GET_BINARY(pRaw, pRow, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN) SDB_GET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, CLUSTER_DECODE_OVER)
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_CLUSTER_RESERVE_SIZE) 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; return pRow;
} }
static int32_t mndClusterActionInsert(SSdb *pSdb, SClusterObj *pCluster) { 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; return 0;
} }
static int32_t mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster) { 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; return 0;
} }
static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOldCluster, SClusterObj *pNewCluster) { static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOld, SClusterObj *pNew) {
mTrace("cluster:%" PRId64 ", perform update action", pOldCluster->id); mTrace("cluster:%" PRId64 ", perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew);
return 0; return 0;
} }
...@@ -120,22 +144,22 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) { ...@@ -120,22 +144,22 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
clusterObj.createdTime = taosGetTimestampMs(); clusterObj.createdTime = taosGetTimestampMs();
clusterObj.updateTime = clusterObj.createdTime; 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) { if (code != 0) {
strcpy(clusterObj.name, "tdengine2.0"); strcpy(clusterObj.name, "tdengine2.0");
mError("failed to get name from system, set to default val %s", clusterObj.name); 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); clusterObj.id = (clusterObj.id >= 0 ? clusterObj.id : -clusterObj.id);
pMnode->clusterId = clusterObj.id; pMnode->clusterId = clusterObj.id;
mDebug("cluster:%" PRId64 ", name is %s", clusterObj.id, clusterObj.name);
SSdbRaw *pRaw = mndClusterActionEncode(&clusterObj); SSdbRaw *pRaw = mndClusterActionEncode(&clusterObj);
if (pRaw == NULL) return -1; if (pRaw == NULL) return -1;
sdbSetRawStatus(pRaw, SDB_STATUS_READY); 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); return sdbWrite(pMnode->pSdb, pRaw);
} }
......
此差异已折叠。
此差异已折叠。
enable_testing()
add_subdirectory(user)
add_subdirectory(acct)
add_subdirectory(trans)
add_subdirectory(qnode)
add_subdirectory(snode)
add_subdirectory(bnode)
add_subdirectory(show)
aux_source_directory(. ACCT_SRC) aux_source_directory(. ACCT_SRC)
add_executable(dnode_test_acct ${ACCT_SRC}) add_executable(mnode_test_acct ${ACCT_SRC})
target_link_libraries( target_link_libraries(
dnode_test_acct mnode_test_acct
PUBLIC sut PUBLIC sut
) )
add_test( add_test(
NAME dnode_test_acct NAME mnode_test_acct
COMMAND dnode_test_acct COMMAND mnode_test_acct
) )
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册