handle merge conflict
This commit is contained in:
commit
df554c03fc
|
@ -6,28 +6,32 @@
|
|||
"dockerfile": "Dockerfile",
|
||||
// Update 'VARIANT' to pick an Debian / Ubuntu OS version: debian-11, debian-10, debian-9, ubuntu-21.04, ubuntu-20.04, ubuntu-18.04
|
||||
// Use Debian 11, Debian 9, Ubuntu 18.04 or Ubuntu 21.04 on local arm64/Apple Silicon
|
||||
"args": { "VARIANT": "ubuntu-21.04" }
|
||||
"args": {
|
||||
"VARIANT": "ubuntu-21.04"
|
||||
}
|
||||
},
|
||||
"runArgs": ["--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined"],
|
||||
|
||||
"runArgs": [
|
||||
"--cap-add=SYS_PTRACE",
|
||||
"--security-opt",
|
||||
"seccomp=unconfined"
|
||||
],
|
||||
// Set *default* container specific settings.json values on container create.
|
||||
"settings": {},
|
||||
|
||||
// Add the IDs of extensions you want installed when the container is created.
|
||||
"extensions": [
|
||||
"ms-vscode.cpptools",
|
||||
"ms-vscode.cmake-tools",
|
||||
"austin.code-gnu-global",
|
||||
"visualstudioexptteam.vscodeintel",
|
||||
"eamodio.gitlens"
|
||||
"eamodio.gitlens",
|
||||
"matepek.vscode-catch2-test-adapter",
|
||||
"spmeesseman.vscode-taskexplorer",
|
||||
"cschlosser.doxdocgen"
|
||||
],
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
// "postCreateCommand": "gcc -v",
|
||||
|
||||
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
|
||||
"remoteUser": "root"
|
||||
}
|
||||
}
|
|
@ -156,10 +156,6 @@ typedef struct {
|
|||
uint16_t port;
|
||||
} SEpAddr;
|
||||
|
||||
typedef struct {
|
||||
int32_t numOfVnodes;
|
||||
} SMsgDesc;
|
||||
|
||||
typedef struct SMsgHead {
|
||||
int32_t contLen;
|
||||
int32_t vgId;
|
||||
|
@ -341,7 +337,7 @@ typedef struct {
|
|||
int64_t clusterId;
|
||||
int32_t connId;
|
||||
int8_t superUser;
|
||||
int8_t reserved[5];
|
||||
int8_t align[3];
|
||||
SEpSet epSet;
|
||||
} SConnectRsp;
|
||||
|
||||
|
@ -354,21 +350,18 @@ typedef struct {
|
|||
int32_t maxStreams;
|
||||
int32_t accessState; // Configured only by command
|
||||
int64_t maxStorage; // In unit of GB
|
||||
int32_t reserve[8];
|
||||
} SCreateAcctMsg, SAlterAcctMsg;
|
||||
} SCreateAcctReq, SAlterAcctReq;
|
||||
|
||||
typedef struct {
|
||||
char user[TSDB_USER_LEN];
|
||||
int32_t reserve[8];
|
||||
} SDropUserMsg, SDropAcctMsg;
|
||||
char user[TSDB_USER_LEN];
|
||||
} SDropUserReq, SDropAcctReq;
|
||||
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_PASSWORD_LEN];
|
||||
int8_t superUser; // denote if it is a super user or not
|
||||
int32_t reserve[8];
|
||||
} SCreateUserMsg, SAlterUserMsg;
|
||||
int8_t type;
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_PASSWORD_LEN];
|
||||
int8_t superUser; // denote if it is a super user or not
|
||||
} SCreateUserReq, SAlterUserReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t contLen;
|
||||
|
@ -522,7 +515,7 @@ typedef struct {
|
|||
int64_t qId;
|
||||
}; // query handle
|
||||
int8_t free;
|
||||
} SRetrieveTableMsg;
|
||||
} SRetrieveTableReq;
|
||||
|
||||
typedef struct SRetrieveTableRsp {
|
||||
int64_t useconds;
|
||||
|
@ -556,7 +549,6 @@ typedef struct {
|
|||
int8_t update;
|
||||
int8_t cacheLastRow;
|
||||
int8_t ignoreExist;
|
||||
int32_t reserve[8];
|
||||
} SCreateDbMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -569,29 +561,24 @@ typedef struct {
|
|||
int8_t walLevel;
|
||||
int8_t quorum;
|
||||
int8_t cacheLastRow;
|
||||
int32_t reserve[8];
|
||||
} SAlterDbMsg;
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
int8_t ignoreNotExists;
|
||||
int32_t reserve[8];
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
int8_t ignoreNotExists;
|
||||
} SDropDbMsg;
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t vgVersion;
|
||||
int32_t reserve[8];
|
||||
} SUseDbMsg;
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t reserve[8];
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
} SSyncDbMsg;
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t reserve[8];
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
} SCompactDbMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -647,7 +634,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
int32_t vgId;
|
||||
int8_t role;
|
||||
int8_t reserved[3];
|
||||
int8_t align[3];
|
||||
int64_t totalStorage;
|
||||
int64_t compStorage;
|
||||
int64_t pointsWritten;
|
||||
|
@ -684,7 +671,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
int32_t id;
|
||||
int8_t isMnode;
|
||||
int8_t reserved;
|
||||
int8_t align;
|
||||
uint16_t port;
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
} SDnodeEp;
|
||||
|
@ -830,7 +817,7 @@ typedef struct {
|
|||
char db[TSDB_DB_FNAME_LEN];
|
||||
int16_t payloadLen;
|
||||
char payload[];
|
||||
} SShowMsg;
|
||||
} SShowReq;
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_DB_FNAME_LEN];
|
||||
|
@ -869,15 +856,15 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
} SMCreateQnodeMsg, SMDropQnodeMsg, SDCreateQnodeMsg, SDDropQnodeMsg;
|
||||
} SMCreateQnodeReq, SMDropQnodeReq, SDCreateQnodeReq, SDDropQnodeReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
} SMCreateSnodeMsg, SMDropSnodeMsg, SDCreateSnodeMsg, SDDropSnodeMsg;
|
||||
} SMCreateSnodeReq, SMDropSnodeReq, SDCreateSnodeReq, SDDropSnodeReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
} SMCreateBnodeMsg, SMDropBnodeMsg, SDCreateBnodeMsg, SDDropBnodeMsg;
|
||||
} SMCreateBnodeReq, SMDropBnodeReq, SDCreateBnodeReq, SDDropBnodeReq;
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
|
@ -920,7 +907,7 @@ typedef struct {
|
|||
int32_t totalDnodes;
|
||||
int32_t onlineDnodes;
|
||||
int8_t killConnection;
|
||||
int8_t reserved[3];
|
||||
int8_t align[3];
|
||||
SEpSet epSet;
|
||||
} SHeartBeatRsp;
|
||||
|
||||
|
@ -948,7 +935,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
int8_t finished;
|
||||
int8_t reserved1[7];
|
||||
int8_t align[7];
|
||||
char name[TSDB_STEP_NAME_LEN];
|
||||
char desc[TSDB_STEP_DESC_LEN];
|
||||
} SStartupMsg;
|
||||
|
@ -1059,6 +1046,7 @@ typedef struct SResFetchMsg {
|
|||
} SResFetchMsg;
|
||||
|
||||
typedef struct SSchTasksStatusMsg {
|
||||
SMsgHead header;
|
||||
uint64_t sId;
|
||||
} SSchTasksStatusMsg;
|
||||
|
||||
|
@ -1074,6 +1062,7 @@ typedef struct SSchedulerStatusRsp {
|
|||
} SSchedulerStatusRsp;
|
||||
|
||||
typedef struct STaskCancelMsg {
|
||||
SMsgHead header;
|
||||
uint64_t sId;
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
|
@ -1084,6 +1073,7 @@ typedef struct STaskCancelRsp {
|
|||
} STaskCancelRsp;
|
||||
|
||||
typedef struct STaskDropMsg {
|
||||
SMsgHead header;
|
||||
uint64_t sId;
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
|
|
|
@ -23,9 +23,9 @@ extern "C" {
|
|||
/* ------------------------ TYPES EXPOSED ------------------------ */
|
||||
typedef struct SDnode SDnode;
|
||||
typedef struct SBnode SBnode;
|
||||
typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
|
||||
typedef struct {
|
||||
int64_t numOfErrors;
|
||||
|
@ -40,9 +40,9 @@ typedef struct {
|
|||
int64_t clusterId;
|
||||
SBnodeCfg cfg;
|
||||
SDnode *pDnode;
|
||||
SendMsgToDnodeFp sendMsgToDnodeFp;
|
||||
SendMsgToMnodeFp sendMsgToMnodeFp;
|
||||
SendRedirectMsgFp sendRedirectMsgFp;
|
||||
SendReqToDnodeFp sendReqToDnodeFp;
|
||||
SendReqToMnodeFp sendReqToMnodeFp;
|
||||
SendRedirectRspFp sendRedirectRspFp;
|
||||
} SBnodeOpt;
|
||||
|
||||
/* ------------------------ SBnode ------------------------ */
|
||||
|
|
|
@ -24,9 +24,10 @@ extern "C" {
|
|||
typedef struct SDnode SDnode;
|
||||
typedef struct SMnode SMnode;
|
||||
typedef struct SMnodeMsg SMnodeMsg;
|
||||
typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*PutReqToMWriteQFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
|
||||
typedef struct SMnodeLoad {
|
||||
int64_t numOfDnode;
|
||||
|
@ -62,9 +63,10 @@ typedef struct {
|
|||
SReplica replicas[TSDB_MAX_REPLICA];
|
||||
SMnodeCfg cfg;
|
||||
SDnode *pDnode;
|
||||
SendMsgToDnodeFp sendMsgToDnodeFp;
|
||||
SendMsgToMnodeFp sendMsgToMnodeFp;
|
||||
SendRedirectMsgFp sendRedirectMsgFp;
|
||||
PutReqToMWriteQFp putReqToMWriteQFp;
|
||||
SendReqToDnodeFp sendReqToDnodeFp;
|
||||
SendReqToMnodeFp sendReqToMnodeFp;
|
||||
SendRedirectRspFp sendRedirectRspFp;
|
||||
} SMnodeOpt;
|
||||
|
||||
/* ------------------------ SMnode ------------------------ */
|
||||
|
|
|
@ -22,121 +22,70 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SDB_GET_INT64(pData, pRow, dataPos, val) \
|
||||
{ \
|
||||
if (sdbGetRawInt64(pRaw, dataPos, val) != 0) { \
|
||||
tfree(pRow); \
|
||||
return NULL; \
|
||||
} \
|
||||
dataPos += sizeof(int64_t); \
|
||||
#define SDB_GET_VAL(pData, dataPos, val, pos, func, type) \
|
||||
{ \
|
||||
if (func(pRaw, dataPos, val) != 0) { \
|
||||
goto pos; \
|
||||
} \
|
||||
dataPos += sizeof(type); \
|
||||
}
|
||||
|
||||
#define SDB_GET_INT32(pData, pRow, dataPos, val) \
|
||||
{ \
|
||||
if (sdbGetRawInt32(pRaw, dataPos, val) != 0) { \
|
||||
tfree(pRow); \
|
||||
return NULL; \
|
||||
} \
|
||||
dataPos += sizeof(int32_t); \
|
||||
}
|
||||
|
||||
#define SDB_GET_INT16(pData, pRow, dataPos, val) \
|
||||
{ \
|
||||
if (sdbGetRawInt16(pRaw, dataPos, val) != 0) { \
|
||||
tfree(pRow); \
|
||||
return NULL; \
|
||||
} \
|
||||
dataPos += sizeof(int16_t); \
|
||||
}
|
||||
|
||||
#define SDB_GET_INT8(pData, pRow, dataPos, val) \
|
||||
{ \
|
||||
if (sdbGetRawInt8(pRaw, dataPos, val) != 0) { \
|
||||
tfree(pRow); \
|
||||
return NULL; \
|
||||
} \
|
||||
dataPos += sizeof(int8_t); \
|
||||
}
|
||||
|
||||
#define SDB_GET_BINARY(pRaw, pRow, dataPos, val, valLen) \
|
||||
#define SDB_GET_BINARY(pRaw, dataPos, val, valLen, pos) \
|
||||
{ \
|
||||
if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
|
||||
tfree(pRow); \
|
||||
return NULL; \
|
||||
goto pos; \
|
||||
} \
|
||||
dataPos += valLen; \
|
||||
}
|
||||
|
||||
#define SDB_GET_RESERVE(pRaw, pRow, dataPos, valLen) \
|
||||
{ \
|
||||
char val[valLen] = {0}; \
|
||||
if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
|
||||
tfree(pRow); \
|
||||
return NULL; \
|
||||
} \
|
||||
dataPos += valLen; \
|
||||
#define SDB_GET_INT64(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt64, int64_t)
|
||||
|
||||
#define SDB_GET_INT32(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt32, int32_t)
|
||||
|
||||
#define SDB_GET_INT16(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt16, int16_t)
|
||||
|
||||
#define SDB_GET_INT8(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt8, int8_t)
|
||||
|
||||
#define SDB_GET_RESERVE(pRaw, dataPos, valLen, pos) \
|
||||
{ \
|
||||
char val[valLen] = {0}; \
|
||||
SDB_GET_BINARY(pRaw, dataPos, val, valLen, pos) \
|
||||
}
|
||||
|
||||
#define SDB_SET_INT64(pRaw, dataPos, val) \
|
||||
{ \
|
||||
if (sdbSetRawInt64(pRaw, dataPos, val) != 0) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
} \
|
||||
dataPos += sizeof(int64_t); \
|
||||
#define SDB_SET_VAL(pRaw, dataPos, val, pos, func, type) \
|
||||
{ \
|
||||
if (func(pRaw, dataPos, val) != 0) { \
|
||||
goto pos; \
|
||||
} \
|
||||
dataPos += sizeof(type); \
|
||||
}
|
||||
|
||||
#define SDB_SET_INT32(pRaw, dataPos, val) \
|
||||
{ \
|
||||
if (sdbSetRawInt32(pRaw, dataPos, val) != 0) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
} \
|
||||
dataPos += sizeof(int32_t); \
|
||||
}
|
||||
#define SDB_SET_INT64(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt64, int64_t)
|
||||
|
||||
#define SDB_SET_INT16(pRaw, dataPos, val) \
|
||||
{ \
|
||||
if (sdbSetRawInt16(pRaw, dataPos, val) != 0) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
} \
|
||||
dataPos += sizeof(int16_t); \
|
||||
}
|
||||
#define SDB_SET_INT32(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt32, int32_t)
|
||||
|
||||
#define SDB_SET_INT8(pRaw, dataPos, val) \
|
||||
{ \
|
||||
if (sdbSetRawInt8(pRaw, dataPos, val) != 0) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
} \
|
||||
dataPos += sizeof(int8_t); \
|
||||
}
|
||||
#define SDB_SET_INT16(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt16, int16_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) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
goto pos; \
|
||||
} \
|
||||
dataPos += valLen; \
|
||||
}
|
||||
|
||||
#define SDB_SET_RESERVE(pRaw, dataPos, valLen) \
|
||||
{ \
|
||||
char val[valLen] = {0}; \
|
||||
if (sdbSetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
} \
|
||||
dataPos += valLen; \
|
||||
#define SDB_SET_RESERVE(pRaw, dataPos, valLen, pos) \
|
||||
{ \
|
||||
char val[valLen] = {0}; \
|
||||
SDB_SET_BINARY(pRaw, dataPos, val, valLen, pos) \
|
||||
}
|
||||
|
||||
#define SDB_SET_DATALEN(pRaw, dataLen) \
|
||||
#define SDB_SET_DATALEN(pRaw, dataLen, pos) \
|
||||
{ \
|
||||
if (sdbSetRawDataLen(pRaw, dataLen) != 0) { \
|
||||
sdbFreeRaw(pRaw); \
|
||||
return NULL; \
|
||||
goto pos; \
|
||||
} \
|
||||
}
|
||||
|
||||
|
@ -145,6 +94,7 @@ typedef struct SSdbRaw SSdbRaw;
|
|||
typedef struct SSdbRow SSdbRow;
|
||||
typedef enum { SDB_KEY_BINARY = 1, SDB_KEY_INT32 = 2, SDB_KEY_INT64 = 3 } EKeyType;
|
||||
typedef enum {
|
||||
SDB_STATUS_INIT = 0,
|
||||
SDB_STATUS_CREATING = 1,
|
||||
SDB_STATUS_UPDATING = 2,
|
||||
SDB_STATUS_DROPPING = 3,
|
||||
|
@ -153,25 +103,24 @@ typedef enum {
|
|||
} ESdbStatus;
|
||||
|
||||
typedef enum {
|
||||
SDB_START = 0,
|
||||
SDB_TRANS = 1,
|
||||
SDB_CLUSTER = 2,
|
||||
SDB_MNODE = 3,
|
||||
SDB_QNODE = 4,
|
||||
SDB_SNODE = 5,
|
||||
SDB_BNODE = 6,
|
||||
SDB_DNODE = 7,
|
||||
SDB_USER = 8,
|
||||
SDB_AUTH = 9,
|
||||
SDB_ACCT = 10,
|
||||
SDB_CONSUMER = 11,
|
||||
SDB_CGROUP = 12,
|
||||
SDB_TOPIC = 13,
|
||||
SDB_VGROUP = 14,
|
||||
SDB_STB = 15,
|
||||
SDB_DB = 16,
|
||||
SDB_FUNC = 17,
|
||||
SDB_MAX = 18
|
||||
SDB_TRANS = 0,
|
||||
SDB_CLUSTER = 1,
|
||||
SDB_MNODE = 2,
|
||||
SDB_QNODE = 3,
|
||||
SDB_SNODE = 4,
|
||||
SDB_BNODE = 5,
|
||||
SDB_DNODE = 6,
|
||||
SDB_USER = 7,
|
||||
SDB_AUTH = 8,
|
||||
SDB_ACCT = 9,
|
||||
SDB_CONSUMER = 10,
|
||||
SDB_CGROUP = 11,
|
||||
SDB_TOPIC = 12,
|
||||
SDB_VGROUP = 13,
|
||||
SDB_STB = 14,
|
||||
SDB_DB = 15,
|
||||
SDB_FUNC = 16,
|
||||
SDB_MAX = 17
|
||||
} ESdbType;
|
||||
|
||||
typedef struct SSdb SSdb;
|
||||
|
@ -239,6 +188,14 @@ int32_t sdbDeploy(SSdb *pSdb);
|
|||
*/
|
||||
int32_t sdbReadFile(SSdb *pSdb);
|
||||
|
||||
/**
|
||||
* @brief Write sdb file.
|
||||
*
|
||||
* @param pSdb The sdb object.
|
||||
* @return int32_t 0 for success, -1 for failure.
|
||||
*/
|
||||
int32_t sdbWriteFile(SSdb *pSdb);
|
||||
|
||||
/**
|
||||
* @brief Parse and write raw data to sdb, then free the pRaw object
|
||||
*
|
||||
|
@ -311,7 +268,7 @@ void sdbTraverse(SSdb *pSdb, ESdbType type, sdbTraverseFp fp, void *p1, void *p2
|
|||
*
|
||||
* @param pSdb The sdb object.
|
||||
* @param pIter The type of the table.
|
||||
* @record int32_t The number of rows in the table
|
||||
* @return int32_t The number of rows in the table
|
||||
*/
|
||||
int32_t sdbGetSize(SSdb *pSdb, ESdbType type);
|
||||
|
||||
|
@ -320,10 +277,19 @@ int32_t sdbGetSize(SSdb *pSdb, ESdbType type);
|
|||
*
|
||||
* @param pSdb The sdb object.
|
||||
* @param pIter The type of the table.
|
||||
* @record int32_t The max id of the table
|
||||
* @return int32_t The max id of the table
|
||||
*/
|
||||
int32_t sdbGetMaxId(SSdb *pSdb, ESdbType type);
|
||||
|
||||
/**
|
||||
* @brief Update the version of sdb
|
||||
*
|
||||
* @param pSdb The sdb object.
|
||||
* @param val The update value of the version.
|
||||
* @return int32_t The current version of sdb
|
||||
*/
|
||||
int64_t sdbUpdateVer(SSdb *pSdb, int32_t val);
|
||||
|
||||
SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen);
|
||||
void sdbFreeRaw(SSdbRaw *pRaw);
|
||||
int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val);
|
||||
|
|
|
@ -23,9 +23,9 @@ extern "C" {
|
|||
/* ------------------------ TYPES EXPOSED ------------------------ */
|
||||
typedef struct SDnode SDnode;
|
||||
typedef struct SQnode SQnode;
|
||||
typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
|
||||
typedef struct {
|
||||
int64_t numOfStartTask;
|
||||
|
@ -47,9 +47,9 @@ typedef struct {
|
|||
int64_t clusterId;
|
||||
SQnodeCfg cfg;
|
||||
SDnode *pDnode;
|
||||
SendMsgToDnodeFp sendMsgToDnodeFp;
|
||||
SendMsgToMnodeFp sendMsgToMnodeFp;
|
||||
SendRedirectMsgFp sendRedirectMsgFp;
|
||||
SendReqToDnodeFp sendReqToDnodeFp;
|
||||
SendReqToMnodeFp sendReqToMnodeFp;
|
||||
SendRedirectRspFp sendRedirectRspFp;
|
||||
} SQnodeOpt;
|
||||
|
||||
/* ------------------------ SQnode ------------------------ */
|
||||
|
|
|
@ -23,9 +23,9 @@ extern "C" {
|
|||
/* ------------------------ TYPES EXPOSED ------------------------ */
|
||||
typedef struct SDnode SDnode;
|
||||
typedef struct SSnode SSnode;
|
||||
typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*SendReqToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg);
|
||||
typedef int32_t (*SendReqToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
typedef void (*SendRedirectRspFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg);
|
||||
|
||||
typedef struct {
|
||||
int64_t numOfErrors;
|
||||
|
@ -40,9 +40,9 @@ typedef struct {
|
|||
int64_t clusterId;
|
||||
SSnodeCfg cfg;
|
||||
SDnode *pDnode;
|
||||
SendMsgToDnodeFp sendMsgToDnodeFp;
|
||||
SendMsgToMnodeFp sendMsgToMnodeFp;
|
||||
SendRedirectMsgFp sendRedirectMsgFp;
|
||||
SendReqToDnodeFp sendReqToDnodeFp;
|
||||
SendReqToMnodeFp sendReqToMnodeFp;
|
||||
SendRedirectRspFp sendRedirectRspFp;
|
||||
} SSnodeOpt;
|
||||
|
||||
/* ------------------------ SSnode ------------------------ */
|
||||
|
|
|
@ -50,6 +50,7 @@ typedef struct SCatalogCfg {
|
|||
uint32_t maxDBCacheNum;
|
||||
} SCatalogCfg;
|
||||
|
||||
|
||||
int32_t catalogInit(SCatalogCfg *cfg);
|
||||
|
||||
/**
|
||||
|
@ -88,25 +89,39 @@ 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);
|
||||
|
||||
/**
|
||||
* Force renew a table's local cached meta data.
|
||||
* Get a super table's meta data.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pRpc (input, rpc object)
|
||||
* @param pTransporter (input, rpc object)
|
||||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pTableName (input, table name, NOT including db name)
|
||||
* @param pTableMeta(output, table meta data, NEED to free it by calller)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName);
|
||||
int32_t catalogGetSTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
|
||||
|
||||
|
||||
/**
|
||||
* Force renew a table's local cached meta data.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pTransporter (input, rpc object)
|
||||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pTableName (input, table name, NOT including db name)
|
||||
* @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, int32_t isSTable);
|
||||
|
||||
/**
|
||||
* Force renew a table's local cached meta data and get the new one.
|
||||
* @param pCatalog (input, got with catalogGetHandle)
|
||||
* @param pRpc (input, rpc object)
|
||||
* @param pTransporter (input, rpc object)
|
||||
* @param pMgmtEps (input, mnode EPs)
|
||||
* @param pTableName (input, table name, NOT including db name)
|
||||
* @param pTableMeta(output, table meta data, NEED to free it by calller)
|
||||
* @param isSTable (input, is super table or not, 1:supposed to be stable, 0: supposed not to be stable, -1:not sure)
|
||||
* @return error code
|
||||
*/
|
||||
int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta);
|
||||
int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable);
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -154,14 +154,14 @@ typedef struct SVgDataBlocks {
|
|||
char *pData; // SMsgDesc + SSubmitMsg + SSubmitBlk + ...
|
||||
} SVgDataBlocks;
|
||||
|
||||
typedef struct SInsertStmtInfo {
|
||||
typedef struct SVnodeModifOpStmtInfo {
|
||||
int16_t nodeType;
|
||||
SArray* pDataBlocks; // data block for each vgroup, SArray<SVgDataBlocks*>.
|
||||
int8_t schemaAttache; // denote if submit block is built with table schema or not
|
||||
uint8_t payloadType; // EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
|
||||
uint32_t insertType; // insert data from [file|sql statement| bound statement]
|
||||
const char* sql; // current sql statement position
|
||||
} SInsertStmtInfo;
|
||||
} SVnodeModifOpStmtInfo;
|
||||
|
||||
typedef struct SDclStmtInfo {
|
||||
int16_t nodeType;
|
||||
|
|
|
@ -43,7 +43,7 @@ int32_t qParseQuerySql(SParseContext* pContext, SQueryNode** pQuery);
|
|||
|
||||
bool qIsDdlQuery(const SQueryNode* pQuery);
|
||||
|
||||
void qDestroyQuery(SQueryNode* pQuery);
|
||||
void qDestroyQuery(SQueryNode* pQueryNode);
|
||||
|
||||
/**
|
||||
* Convert a normal sql statement to only query tags information to enable that the subscribe client can be aware quickly of the true vgroup ids that
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "query.h"
|
||||
#include "tmsg.h"
|
||||
#include "tarray.h"
|
||||
|
||||
|
@ -119,11 +120,12 @@ typedef struct SSubplanId {
|
|||
} SSubplanId;
|
||||
|
||||
typedef struct SSubplan {
|
||||
SSubplanId id; // unique id of the subplan
|
||||
SSubplanId id; // unique id of the subplan
|
||||
int32_t type; // QUERY_TYPE_MERGE|QUERY_TYPE_PARTIAL|QUERY_TYPE_SCAN|QUERY_TYPE_MODIFY
|
||||
int32_t level; // the execution level of current subplan, starting from 0.
|
||||
SEpSet execEpSet; // for the scan/modify subplan, the optional execution node
|
||||
SArray *pChildern; // the datasource subplan,from which to fetch the result
|
||||
int32_t msgType; // message type for subplan, used to denote the send message type to vnode.
|
||||
int32_t level; // the execution level of current subplan, starting from 0 in a top-down manner.
|
||||
SQueryNodeAddr execNode; // for the scan/modify subplan, the optional execution node
|
||||
SArray *pChildren; // the datasource subplan,from which to fetch the result
|
||||
SArray *pParents; // the data destination subplan, get data from current subplan
|
||||
SPhyNode *pNode; // physical plan of current subplan
|
||||
SDataSink *pDataSink; // data of the subplan flow into the datasink
|
||||
|
@ -140,13 +142,13 @@ struct SQueryNode;
|
|||
/**
|
||||
* Create the physical plan for the query, according to the AST.
|
||||
*/
|
||||
int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SQueryDag** pDag);
|
||||
int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SQueryDag** pDag, uint64_t requestId);
|
||||
|
||||
// Set datasource of this subplan, multiple calls may be made to a subplan.
|
||||
// @subplan subplan to be schedule
|
||||
// @templateId templateId of a group of datasource subplans of this @subplan
|
||||
// @ep one execution location of this group of datasource subplans
|
||||
int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep);
|
||||
int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SQueryNodeAddr* ep);
|
||||
|
||||
int32_t qExplainQuery(const struct SQueryNode* pQueryInfo, struct SEpSet* pQnode, char** str);
|
||||
|
||||
|
|
|
@ -111,6 +111,13 @@ typedef struct SMsgSendInfo {
|
|||
SDataBuf msgInfo;
|
||||
} SMsgSendInfo;
|
||||
|
||||
typedef struct SQueryNodeAddr{
|
||||
int32_t nodeId; //vgId or qnodeId
|
||||
int8_t inUse;
|
||||
int8_t numOfEps;
|
||||
SEpAddrMsg epAddr[TSDB_MAX_REPLICA];
|
||||
} SQueryNodeAddr;
|
||||
|
||||
bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags);
|
||||
|
||||
int32_t initTaskQueue();
|
||||
|
|
|
@ -50,13 +50,6 @@ typedef struct SQueryProfileSummary {
|
|||
uint64_t resultSize; // generated result size in Kb.
|
||||
} SQueryProfileSummary;
|
||||
|
||||
typedef struct SQueryNodeAddr{
|
||||
int32_t nodeId; //vgId or qnodeId
|
||||
int8_t inUse;
|
||||
int8_t numOfEps;
|
||||
SEpAddrMsg epAddr[TSDB_MAX_REPLICA];
|
||||
} SQueryNodeAddr;
|
||||
|
||||
typedef struct SQueryResult {
|
||||
int32_t code;
|
||||
uint64_t numOfRows;
|
||||
|
|
|
@ -22,11 +22,13 @@ extern "C" {
|
|||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <float.h>
|
||||
#include <inttypes.h>
|
||||
#include <locale.h>
|
||||
#include <math.h>
|
||||
#include <sched.h>
|
||||
#include <setjmp.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
|
@ -36,19 +38,14 @@ extern "C" {
|
|||
#include <stdio.h>
|
||||
#include <stdlib.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/types.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "osAtomic.h"
|
||||
#include "osDef.h"
|
||||
|
|
|
@ -54,7 +54,7 @@ bool taosGetSysMemory(float *memoryUsedMB);
|
|||
void taosPrintOsInfo();
|
||||
int taosSystem(const char *cmd);
|
||||
void taosKillSystem();
|
||||
int32_t taosGetSystemUid(char *uid, int32_t uidlen);
|
||||
int32_t taosGetSystemUUID(char *uid, int32_t uidlen);
|
||||
char * taosGetCmdlineByPID(int pid);
|
||||
void taosSetCoreDump(bool enable);
|
||||
|
||||
|
@ -68,8 +68,6 @@ typedef struct {
|
|||
|
||||
SysNameInfo taosGetSysNameInfo();
|
||||
|
||||
int64_t taosGetPid();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -160,6 +160,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_SDB_INVALID_DATA_VER TAOS_DEF_ERROR_CODE(0, 0x0339)
|
||||
#define TSDB_CODE_SDB_INVALID_DATA_LEN TAOS_DEF_ERROR_CODE(0, 0x033A)
|
||||
#define TSDB_CODE_SDB_INVALID_DATA_CONTENT TAOS_DEF_ERROR_CODE(0, 0x033B)
|
||||
#define TSDB_CODE_SDB_INVALID_WAl_VER TAOS_DEF_ERROR_CODE(0, 0x033C)
|
||||
|
||||
// mnode-dnode
|
||||
#define TSDB_CODE_MND_DNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0340)
|
||||
|
@ -252,7 +253,7 @@ int32_t* taosGetErrno();
|
|||
|
||||
// dnode
|
||||
#define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0400)
|
||||
#define TSDB_CODE_DND_EXITING TAOS_DEF_ERROR_CODE(0, 0x0401)
|
||||
#define TSDB_CODE_DND_OFFLINE TAOS_DEF_ERROR_CODE(0, 0x0401)
|
||||
#define TSDB_CODE_DND_INVALID_MSG_LEN TAOS_DEF_ERROR_CODE(0, 0x0402)
|
||||
#define TSDB_CODE_DND_DNODE_READ_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0410)
|
||||
#define TSDB_CODE_DND_DNODE_WRITE_FILE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0411)
|
||||
|
|
|
@ -43,7 +43,7 @@ int32_t tfFsync(int64_t tfd);
|
|||
bool tfValid(int64_t tfd);
|
||||
int64_t tfLseek(int64_t tfd, int64_t offset, int32_t whence);
|
||||
int32_t tfFtruncate(int64_t tfd, int64_t length);
|
||||
|
||||
void * tfMmapReadOnly(int64_t tfd, int64_t length);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -24,7 +24,7 @@ extern "C" {
|
|||
#include "tlockfree.h"
|
||||
|
||||
typedef uint32_t (*_hash_fn_t)(const char *, uint32_t);
|
||||
typedef int32_t (*_equal_fn_t)(const void*, const void*, uint32_t len);
|
||||
typedef int32_t (*_equal_fn_t)(const void*, const void*, size_t len);
|
||||
typedef void (*_hash_before_fn_t)(void *);
|
||||
typedef void (*_hash_free_fn_t)(void *);
|
||||
|
||||
|
|
|
@ -146,6 +146,8 @@ int taos_init();
|
|||
void* createTscObj(const char* user, const char* auth, const char *db, SAppInstInfo* pAppInfo);
|
||||
void destroyTscObj(void*pObj);
|
||||
|
||||
uint64_t generateRequestId();
|
||||
|
||||
void *createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type);
|
||||
void destroyRequest(SRequestObj* pRequest);
|
||||
|
||||
|
|
|
@ -53,8 +53,8 @@ static void registerRequest(SRequestObj* pRequest) {
|
|||
|
||||
int32_t total = atomic_add_fetch_32(&pSummary->totalRequests, 1);
|
||||
int32_t currentInst = atomic_add_fetch_32(&pSummary->currentRequests, 1);
|
||||
tscDebug("0x%" PRIx64 " new Request from connObj:0x%" PRIx64 ", current:%d, app current:%d, total:%d", pRequest->self,
|
||||
pRequest->pTscObj->id, num, currentInst, total);
|
||||
tscDebug("0x%" PRIx64 " new Request from connObj:0x%" PRIx64 ", current:%d, app current:%d, total:%d, reqId:0x%"PRIx64, pRequest->self,
|
||||
pRequest->pTscObj->id, num, currentInst, total, pRequest->requestId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,6 +87,7 @@ static void tscInitLogFile() {
|
|||
}
|
||||
}
|
||||
|
||||
// todo close the transporter properly
|
||||
void closeTransporter(STscObj* pTscObj) {
|
||||
if (pTscObj == NULL || pTscObj->pTransporter == NULL) {
|
||||
return;
|
||||
|
@ -166,8 +167,7 @@ void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t ty
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// TODO generated request uuid
|
||||
pRequest->requestId = 0;
|
||||
pRequest->requestId = generateRequestId();
|
||||
pRequest->metric.start = taosGetTimestampMs();
|
||||
|
||||
pRequest->type = type;
|
||||
|
@ -180,6 +180,14 @@ void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t ty
|
|||
return pRequest;
|
||||
}
|
||||
|
||||
static void doFreeReqResultInfo(SReqResultInfo* pResInfo) {
|
||||
tfree(pResInfo->pRspMsg);
|
||||
tfree(pResInfo->length);
|
||||
tfree(pResInfo->row);
|
||||
tfree(pResInfo->pCol);
|
||||
tfree(pResInfo->fields);
|
||||
}
|
||||
|
||||
static void doDestroyRequest(void* p) {
|
||||
assert(p != NULL);
|
||||
SRequestObj* pRequest = (SRequestObj*)p;
|
||||
|
@ -190,7 +198,7 @@ static void doDestroyRequest(void* p) {
|
|||
tfree(pRequest->sqlstr);
|
||||
tfree(pRequest->pInfo);
|
||||
|
||||
tfree(pRequest->body.resInfo.pRspMsg);
|
||||
doFreeReqResultInfo(&pRequest->body.resInfo);
|
||||
|
||||
deregisterRequest(pRequest);
|
||||
tfree(pRequest);
|
||||
|
@ -410,6 +418,39 @@ int taos_options_imp(TSDB_OPTION option, const char *str) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The request id is an unsigned integer format of 64bit.
|
||||
*+------------+-----+-----------+---------------+
|
||||
*| uid|localIp| PId | timestamp | serial number |
|
||||
*+------------+-----+-----------+---------------+
|
||||
*| 12bit |12bit|24bit |16bit |
|
||||
*+------------+-----+-----------+---------------+
|
||||
* @return
|
||||
*/
|
||||
uint64_t generateRequestId() {
|
||||
static uint64_t hashId = 0;
|
||||
static int32_t requestSerialId = 0;
|
||||
|
||||
if (hashId == 0) {
|
||||
char uid[64] = {0};
|
||||
int32_t code = taosGetSystemUUID(uid, tListLen(uid));
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tscError("Failed to get the system uid to generated request id, reason:%s. use ip address instead",
|
||||
tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
||||
|
||||
} else {
|
||||
hashId = MurmurHash3_32(uid, strlen(uid));
|
||||
}
|
||||
}
|
||||
|
||||
int64_t ts = taosGetTimestampMs();
|
||||
uint64_t pid = taosGetPId();
|
||||
int32_t val = atomic_add_fetch_32(&requestSerialId, 1);
|
||||
|
||||
uint64_t id = ((hashId & 0x0FFF) << 52) | ((pid & 0x0FFF) << 40) | ((ts & 0xFFFFFF) << 16) | (val & 0xFFFF);
|
||||
return id;
|
||||
}
|
||||
|
||||
#if 0
|
||||
#include "cJSON.h"
|
||||
static setConfRet taos_set_config_imp(const char *config){
|
||||
|
|
|
@ -140,7 +140,7 @@ int32_t buildRequest(STscObj *pTscObj, const char *sql, int sqlLen, SRequestObj*
|
|||
(*pRequest)->sqlstr[sqlLen] = 0;
|
||||
(*pRequest)->sqlLen = sqlLen;
|
||||
|
||||
tscDebugL("0x%"PRIx64" SQL: %s", (*pRequest)->requestId, (*pRequest)->sqlstr);
|
||||
tscDebugL("0x%"PRIx64" SQL: %s, reqId:0x"PRIx64, (*pRequest)->self, (*pRequest)->sqlstr, (*pRequest)->requestId);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -192,19 +192,22 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQueryNode* pQuery) {
|
|||
}
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
destroySendMsgInfo(pSendMsg);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQuery, SQueryDag** pDag) {
|
||||
pRequest->type = pQuery->type;
|
||||
return qCreateQueryDag(pQuery, pDag);
|
||||
int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQueryNode, SQueryDag** pDag) {
|
||||
pRequest->type = pQueryNode->type;
|
||||
return qCreateQueryDag(pQueryNode, pDag, pRequest->requestId);
|
||||
}
|
||||
|
||||
int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, void** pJob) {
|
||||
if (TSDB_SQL_INSERT == pRequest->type || TSDB_SQL_CREATE_TABLE == pRequest->type) {
|
||||
return scheduleExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob, &pRequest->affectedRows);
|
||||
SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf};
|
||||
int32_t code = scheduleExecJob(pRequest->pTscObj->pTransporter, NULL, pDag, pJob, &res);
|
||||
pRequest->affectedRows = res.numOfRows;
|
||||
return res.code;
|
||||
}
|
||||
|
||||
return scheduleAsyncExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob);
|
||||
}
|
||||
|
||||
|
@ -360,8 +363,6 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con
|
|||
asyncSendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body);
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
destroySendMsgInfo(body);
|
||||
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
const char *errorMsg = (pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(terrno);
|
||||
printf("failed to connect to server, reason: %s\n\n", errorMsg);
|
||||
|
@ -370,7 +371,7 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con
|
|||
taos_close(pTscObj);
|
||||
pTscObj = NULL;
|
||||
} else {
|
||||
tscDebug("0x%"PRIx64" connection is opening, connId:%d, dnodeConn:%p", pTscObj->id, pTscObj->connId, pTscObj->pTransporter);
|
||||
tscDebug("0x%"PRIx64" connection is opening, connId:%d, dnodeConn:%p, reqId:0x%"PRIx64, pTscObj->id, pTscObj->connId, pTscObj->pTransporter, pRequest->requestId);
|
||||
destroyRequest(pRequest);
|
||||
}
|
||||
|
||||
|
@ -440,30 +441,33 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
|||
* There is not response callback function for submit response.
|
||||
* The actual inserted number of points is the first number.
|
||||
*/
|
||||
int32_t elapsed = pRequest->metric.rsp - pRequest->metric.start;
|
||||
if (pMsg->code == TSDB_CODE_SUCCESS) {
|
||||
tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%" PRId64 " ms", pRequest->requestId,
|
||||
TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen,
|
||||
pRequest->metric.rsp - pRequest->metric.start);
|
||||
tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%d ms, reqId:0x%"PRIx64, pRequest->self,
|
||||
TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId);
|
||||
} else {
|
||||
tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%" PRId64 " ms", pRequest->requestId,
|
||||
TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen,
|
||||
pRequest->metric.rsp - pRequest->metric.start);
|
||||
tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%d ms, reqId:0x%"PRIx64, pRequest->self,
|
||||
TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId);
|
||||
}
|
||||
|
||||
taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId);
|
||||
}
|
||||
|
||||
SDataBuf buf = {.len = pMsg->contLen};
|
||||
buf.pData = calloc(1, pMsg->contLen);
|
||||
if (buf.pData == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pMsg->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
memcpy(buf.pData, pMsg->pCont, pMsg->contLen);
|
||||
SDataBuf buf = {.len = pMsg->contLen, .pData = NULL};
|
||||
|
||||
if (pMsg->contLen > 0) {
|
||||
buf.pData = calloc(1, pMsg->contLen);
|
||||
if (buf.pData == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
pMsg->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
memcpy(buf.pData, pMsg->pCont, pMsg->contLen);
|
||||
}
|
||||
}
|
||||
|
||||
pSendInfo->fp(pSendInfo->param, &buf, pMsg->code);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
destroySendMsgInfo(pSendInfo);
|
||||
}
|
||||
|
||||
TAOS *taos_connect_auth(const char *ip, const char *user, const char *auth, const char *db, uint16_t port) {
|
||||
|
@ -536,7 +540,6 @@ void* doFetchRow(SRequestObj* pRequest) {
|
|||
asyncSendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &transporterId, body);
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
destroySendMsgInfo(body);
|
||||
|
||||
pResultInfo->current = 0;
|
||||
if (pResultInfo->numOfRows <= pResultInfo->current) {
|
||||
|
|
|
@ -29,7 +29,7 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) {
|
|||
|
||||
// this function may be called by user or system, or by both simultaneously.
|
||||
void taos_cleanup(void) {
|
||||
tscDebug("start to cleanup client environment");
|
||||
tscInfo("start to cleanup client environment");
|
||||
|
||||
if (atomic_val_compare_exchange_32(&sentinel, TSC_VAR_NOT_RELEASE, TSC_VAR_RELEASED) != TSC_VAR_NOT_RELEASE) {
|
||||
return;
|
||||
|
@ -47,6 +47,8 @@ void taos_cleanup(void) {
|
|||
|
||||
rpcCleanup();
|
||||
taosCloseLog();
|
||||
|
||||
tscInfo("all local resources released");
|
||||
}
|
||||
|
||||
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) {
|
||||
|
@ -140,7 +142,9 @@ TAOS_ROW taos_fetch_row(TAOS_RES *pRes) {
|
|||
|
||||
SRequestObj *pRequest = (SRequestObj *) pRes;
|
||||
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT ||
|
||||
pRequest->type == TSDB_SQL_INSERT || pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
pRequest->type == TSDB_SQL_INSERT ||
|
||||
pRequest->code != TSDB_CODE_SUCCESS ||
|
||||
taos_num_fields(pRes) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -258,6 +262,8 @@ const char *taos_data_type(int type) {
|
|||
|
||||
const char *taos_get_client_info() { return version; }
|
||||
|
||||
int taos_affected_rows(TAOS_RES *res) { return 1; }
|
||||
int taos_affected_rows(TAOS_RES *res) {
|
||||
return ((SRequestObj*)res)->affectedRows;
|
||||
}
|
||||
|
||||
int taos_result_precision(TAOS_RES *res) { return TSDB_TIME_PRECISION_MILLI; }
|
||||
|
|
|
@ -30,6 +30,7 @@ int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
SRequestObj* pRequest = param;
|
||||
setErrno(pRequest, code);
|
||||
|
||||
free(pMsg->pData);
|
||||
sem_post(&pRequest->body.rspSem);
|
||||
return code;
|
||||
}
|
||||
|
@ -37,6 +38,7 @@ int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||
SRequestObj* pRequest = param;
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
free(pMsg->pData);
|
||||
setErrno(pRequest, code);
|
||||
sem_post(&pRequest->body.rspSem);
|
||||
return code;
|
||||
|
@ -73,6 +75,7 @@ int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, pConnect->clusterId,
|
||||
pTscObj->pAppInfo->numOfConns);
|
||||
|
||||
free(pMsg->pData);
|
||||
sem_post(&pRequest->body.rspSem);
|
||||
return 0;
|
||||
}
|
||||
|
@ -87,14 +90,14 @@ SMsgSendInfo* buildMsgInfoImpl(SRequestObj *pRequest) {
|
|||
|
||||
if (pRequest->type == TDMT_MND_SHOW_RETRIEVE || pRequest->type == TDMT_VND_SHOW_TABLES_FETCH) {
|
||||
if (pRequest->type == TDMT_MND_SHOW_RETRIEVE) {
|
||||
SRetrieveTableMsg* pRetrieveMsg = calloc(1, sizeof(SRetrieveTableMsg));
|
||||
SRetrieveTableReq* pRetrieveMsg = calloc(1, sizeof(SRetrieveTableReq));
|
||||
if (pRetrieveMsg == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pRetrieveMsg->showId = htobe64(pRequest->body.showInfo.execId);
|
||||
pMsgSendInfo->msgInfo.pData = pRetrieveMsg;
|
||||
pMsgSendInfo->msgInfo.len = sizeof(SRetrieveTableMsg);
|
||||
pMsgSendInfo->msgInfo.len = sizeof(SRetrieveTableReq);
|
||||
} else {
|
||||
SVShowTablesFetchReq* pFetchMsg = calloc(1, sizeof(SVShowTablesFetchReq));
|
||||
if (pFetchMsg == NULL) {
|
||||
|
@ -238,6 +241,7 @@ int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
int32_t processCreateDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||
// todo rsp with the vnode id list
|
||||
SRequestObj* pRequest = param;
|
||||
free(pMsg->pData);
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
}
|
||||
|
||||
|
@ -245,6 +249,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
SRequestObj* pRequest = param;
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
free(pMsg->pData);
|
||||
setErrno(pRequest, code);
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
return code;
|
||||
|
@ -258,6 +263,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
tNameGetDbName(&name, db);
|
||||
|
||||
setConnectionDB(pRequest->pTscObj, db);
|
||||
free(pMsg->pData);
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
return 0;
|
||||
}
|
||||
|
@ -266,6 +272,7 @@ int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
assert(pMsg != NULL && param != NULL);
|
||||
SRequestObj* pRequest = param;
|
||||
|
||||
free(pMsg->pData);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
setErrno(pRequest, code);
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
|
|
|
@ -57,175 +57,176 @@ TEST(testCase, connect_Test) {
|
|||
taos_close(pConn);
|
||||
}
|
||||
|
||||
//TEST(testCase, create_user_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'");
|
||||
// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
// printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
//
|
||||
// taos_free_result(pRes);
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
//
|
||||
//TEST(testCase, create_account_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'");
|
||||
// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
// printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
//
|
||||
// taos_free_result(pRes);
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
//
|
||||
//TEST(testCase, drop_account_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "drop account aabc");
|
||||
// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
// printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
//
|
||||
// taos_free_result(pRes);
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
TEST(testCase, create_user_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
//TEST(testCase, show_user_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "show users");
|
||||
// TAOS_ROW pRow = NULL;
|
||||
//
|
||||
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
// int32_t numOfFields = taos_num_fields(pRes);
|
||||
//
|
||||
// char str[512] = {0};
|
||||
// while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
// printf("%s\n", str);
|
||||
// }
|
||||
//
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'");
|
||||
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
//TEST(testCase, drop_user_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "drop user abc");
|
||||
// if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
// printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
//
|
||||
// taos_free_result(pRes);
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
//TEST(testCase, show_db_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
//// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "show databases");
|
||||
// TAOS_ROW pRow = NULL;
|
||||
//
|
||||
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
// int32_t numOfFields = taos_num_fields(pRes);
|
||||
//
|
||||
// char str[512] = {0};
|
||||
// while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
// printf("%s\n", str);
|
||||
// }
|
||||
//
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
TEST(testCase, create_account_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
//TEST(testCase, create_db_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "create database abc1");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
//
|
||||
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
// ASSERT_TRUE(pFields == NULL);
|
||||
//
|
||||
// int32_t numOfFields = taos_num_fields(pRes);
|
||||
// ASSERT_EQ(numOfFields, 0);
|
||||
//
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// pRes = taos_query(pConn, "create database abc1 vgroups 4");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
//
|
||||
//TEST(testCase, create_dnode_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "create dnode abc1 port 7000");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("error in create dnode, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// pRes = taos_query(pConn, "create dnode 1.1.1.1 port 9000");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("failed to create dnode, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
//
|
||||
//TEST(testCase, drop_dnode_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "drop dnode 2");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("error in drop dnode, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
//
|
||||
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
// ASSERT_TRUE(pFields == NULL);
|
||||
//
|
||||
// int32_t numOfFields = taos_num_fields(pRes);
|
||||
// ASSERT_EQ(numOfFields, 0);
|
||||
//
|
||||
// taos_free_result(pRes);
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
//
|
||||
//TEST(testCase, use_db_test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("error in use db, reason:%s\n", taos_errstr(pRes));
|
||||
// }
|
||||
//
|
||||
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
// ASSERT_TRUE(pFields == NULL);
|
||||
//
|
||||
// int32_t numOfFields = taos_num_fields(pRes);
|
||||
// ASSERT_EQ(numOfFields, 0);
|
||||
//
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
TAOS_RES* pRes = taos_query(pConn, "create account aabc pass 'abc'");
|
||||
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, drop_account_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "drop account aabc");
|
||||
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, show_user_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "show users");
|
||||
TAOS_ROW pRow = NULL;
|
||||
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
char str[512] = {0};
|
||||
while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, drop_user_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "drop user abc");
|
||||
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
printf("failed to create user, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, show_db_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "show databases");
|
||||
TAOS_ROW pRow = NULL;
|
||||
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
char str[512] = {0};
|
||||
while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
printf("%s\n", str);
|
||||
}
|
||||
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, create_db_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
ASSERT_TRUE(pFields == NULL);
|
||||
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
ASSERT_EQ(numOfFields, 0);
|
||||
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create database abc1 vgroups 4");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, create_dnode_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create dnode abc1 port 7000");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in create dnode, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create dnode 1.1.1.1 port 9000");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create dnode, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, drop_dnode_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "drop dnode 2");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in drop dnode, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
ASSERT_TRUE(pFields == NULL);
|
||||
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
ASSERT_EQ(numOfFields, 0);
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, use_db_test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in use db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
ASSERT_TRUE(pFields == NULL);
|
||||
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
ASSERT_EQ(numOfFields, 0);
|
||||
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
//TEST(testCase, drop_db_test) {
|
||||
//// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
|
@ -249,50 +250,50 @@ TEST(testCase, connect_Test) {
|
|||
//// taos_close(pConn);
|
||||
//}
|
||||
|
||||
// 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_stable_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "use abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in use db, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in create stable, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
ASSERT_TRUE(pFields == NULL);
|
||||
|
||||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
ASSERT_EQ(numOfFields, 0);
|
||||
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, create_table_Test) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table tm0(ts timestamp, k int)");
|
||||
taos_free_result(pRes);
|
||||
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
//TEST(testCase, create_ctable_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
|
@ -303,12 +304,12 @@ TEST(testCase, connect_Test) {
|
|||
// }
|
||||
// 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);
|
||||
// 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);
|
||||
//}
|
||||
//
|
||||
|
@ -342,7 +343,7 @@ TEST(testCase, connect_Test) {
|
|||
// taos_free_result(pRes);
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
//
|
||||
|
||||
//TEST(testCase, show_vgroup_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
|
@ -375,7 +376,7 @@ TEST(testCase, connect_Test) {
|
|||
//
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
//
|
||||
|
||||
//TEST(testCase, drop_stable_Test) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
|
@ -465,14 +466,29 @@ TEST(testCase, connect_Test) {
|
|||
|
||||
TEST(testCase, create_multiple_tables) {
|
||||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
ASSERT_NE(pConn, nullptr);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to use db, reason:%s", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
taos_close(pConn);
|
||||
return;
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create table t_2 using st1 tags(1) t_3 using st1 tags(2)");
|
||||
pRes = taos_query(pConn, "create table t_2 using st1 tags(1)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to show vgroups, reason:%s\n", taos_errstr(pRes));
|
||||
printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
ASSERT_TRUE(false);
|
||||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
pRes = taos_query(pConn, "create table t_3 using st1 tags(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);
|
||||
}
|
||||
|
@ -488,5 +504,61 @@ TEST(testCase, create_multiple_tables) {
|
|||
}
|
||||
|
||||
taos_free_result(pRes);
|
||||
|
||||
// for(int32_t i = 0; i < 10000; ++i) {
|
||||
// char sql[512] = {0};
|
||||
// snprintf(sql, tListLen(sql), "create table t_x_%d using st1 tags(2)", i);
|
||||
// TAOS_RES* pres = taos_query(pConn, sql);
|
||||
// if (taos_errno(pres) != 0) {
|
||||
// printf("failed to create table %d\n, reason:%s", i, taos_errstr(pres));
|
||||
// }
|
||||
// taos_free_result(pres);
|
||||
// }
|
||||
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, generated_request_id_test) {
|
||||
SHashObj *phash = taosHashInit(10000, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
|
||||
|
||||
for(int32_t i = 0; i < 50000000; ++i) {
|
||||
uint64_t v = generateRequestId();
|
||||
void* result = taosHashGet(phash, &v, sizeof(v));
|
||||
if (result != nullptr) {
|
||||
printf("0x%"PRIx64", index:%d\n", v, i);
|
||||
}
|
||||
assert(result == nullptr);
|
||||
taosHashPut(phash, &v, sizeof(v), NULL, 0);
|
||||
}
|
||||
|
||||
taosHashCleanup(phash);
|
||||
}
|
||||
|
||||
//TEST(testCase, projection_query_tables) {
|
||||
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
// ASSERT_EQ(pConn, nullptr);
|
||||
//
|
||||
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
// taos_free_result(pRes);
|
||||
//
|
||||
// pRes = taos_query(pConn, "select * from t_2");
|
||||
// if (taos_errno(pRes) != 0) {
|
||||
// printf("failed to create multiple tables, reason:%s\n", taos_errstr(pRes));
|
||||
// taos_free_result(pRes);
|
||||
// ASSERT_TRUE(false);
|
||||
// }
|
||||
//
|
||||
// TAOS_ROW pRow = NULL;
|
||||
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
// int32_t numOfFields = taos_num_fields(pRes);
|
||||
//
|
||||
// char str[512] = {0};
|
||||
// while((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
// printf("%s\n", str);
|
||||
// }
|
||||
//
|
||||
// taos_free_result(pRes);
|
||||
// taos_close(pConn);
|
||||
//}
|
||||
|
||||
|
|
|
@ -140,6 +140,7 @@ void *tSVCreateTbBatchReqDeserialize(void *buf, SVCreateTbBatchReq *pReq) {
|
|||
|
||||
buf = taosDecodeFixedU64(buf, &pReq->ver);
|
||||
buf = taosDecodeFixedU32(buf, &nsize);
|
||||
pReq->pArray = taosArrayInit(nsize, sizeof(SVCreateTbReq));
|
||||
for (size_t i = 0; i < nsize; i++) {
|
||||
SVCreateTbReq req;
|
||||
buf = tDeserializeSVCreateTbReq(buf, &req);
|
||||
|
|
|
@ -33,9 +33,9 @@ typedef struct SBnode {
|
|||
int32_t dnodeId;
|
||||
int64_t clusterId;
|
||||
SBnodeCfg cfg;
|
||||
SendMsgToDnodeFp sendMsgToDnodeFp;
|
||||
SendMsgToMnodeFp sendMsgToMnodeFp;
|
||||
SendRedirectMsgFp sendRedirectMsgFp;
|
||||
SendReqToDnodeFp sendReqToDnodeFp;
|
||||
SendReqToMnodeFp sendReqToMnodeFp;
|
||||
SendRedirectRspFp sendRedirectRspFp;
|
||||
} SBnode;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -29,8 +29,8 @@ int64_t dndGetClusterId(SDnode *pDnode);
|
|||
void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort);
|
||||
void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet);
|
||||
|
||||
void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
void dndSendStatusMsg(SDnode *pDnode);
|
||||
void dndSendRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
void dndSendStatusReq(SDnode *pDnode);
|
||||
void dndProcessMgmtMsg(SDnode *pDnode, SRpcMsg *pRpcMsg, SEpSet *pEpSet);
|
||||
void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
|
||||
|
|
|
@ -23,8 +23,8 @@ extern "C" {
|
|||
|
||||
int32_t dndInitTrans(SDnode *pDnode);
|
||||
void dndCleanupTrans(SDnode *pDnode);
|
||||
void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pRpcMsg);
|
||||
void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pRpcMsg);
|
||||
int32_t dndSendReqToMnode(SDnode *pDnode, SRpcMsg *pRpcMsg);
|
||||
int32_t dndSendReqToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pRpcMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ static SBnode *dndAcquireBnode(SDnode *pDnode) {
|
|||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pMgmt->deployed && !pMgmt->dropped) {
|
||||
if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pBnode != NULL) {
|
||||
refCount = atomic_add_fetch_32(&pMgmt->refCount, 1);
|
||||
pBnode = pMgmt->pBnode;
|
||||
} else {
|
||||
|
@ -60,7 +60,7 @@ static int32_t dndReadBnodeFile(SDnode *pDnode) {
|
|||
SBnodeMgmt *pMgmt = &pDnode->bmgmt;
|
||||
int32_t code = TSDB_CODE_DND_BNODE_READ_FILE_ERROR;
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 4096;
|
||||
int32_t maxLen = 1024;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
cJSON *root = NULL;
|
||||
|
||||
|
@ -127,7 +127,7 @@ static int32_t dndWriteBnodeFile(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 4096;
|
||||
int32_t maxLen = 1024;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
|
@ -170,7 +170,7 @@ static void dndStopBnodeWorker(SDnode *pDnode) {
|
|||
pMgmt->deployed = 0;
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
|
||||
while (pMgmt->refCount > 1) {
|
||||
while (pMgmt->refCount > 0) {
|
||||
taosMsleep(10);
|
||||
}
|
||||
|
||||
|
@ -179,9 +179,9 @@ static void dndStopBnodeWorker(SDnode *pDnode) {
|
|||
|
||||
static void dndBuildBnodeOption(SDnode *pDnode, SBnodeOpt *pOption) {
|
||||
pOption->pDnode = pDnode;
|
||||
pOption->sendMsgToDnodeFp = dndSendMsgToDnode;
|
||||
pOption->sendMsgToMnodeFp = dndSendMsgToMnode;
|
||||
pOption->sendRedirectMsgFp = dndSendRedirectMsg;
|
||||
pOption->sendReqToDnodeFp = dndSendReqToDnode;
|
||||
pOption->sendReqToMnodeFp = dndSendReqToMnode;
|
||||
pOption->sendRedirectRspFp = dndSendRedirectRsp;
|
||||
pOption->dnodeId = dndGetDnodeId(pDnode);
|
||||
pOption->clusterId = dndGetClusterId(pDnode);
|
||||
pOption->cfg.sver = pDnode->opt.sver;
|
||||
|
@ -189,10 +189,18 @@ static void dndBuildBnodeOption(SDnode *pDnode, SBnodeOpt *pOption) {
|
|||
|
||||
static int32_t dndOpenBnode(SDnode *pDnode) {
|
||||
SBnodeMgmt *pMgmt = &pDnode->bmgmt;
|
||||
SBnodeOpt option = {0};
|
||||
SBnode *pBnode = dndAcquireBnode(pDnode);
|
||||
if (pBnode != NULL) {
|
||||
dndReleaseBnode(pDnode, pBnode);
|
||||
terrno = TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED;
|
||||
dError("failed to create bnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SBnodeOpt option = {0};
|
||||
dndBuildBnodeOption(pDnode, &option);
|
||||
|
||||
SBnode *pBnode = bndOpen(pDnode->dir.bnode, &option);
|
||||
pBnode = bndOpen(pDnode->dir.bnode, &option);
|
||||
if (pBnode == NULL) {
|
||||
dError("failed to open bnode since %s", terrstr());
|
||||
return -1;
|
||||
|
@ -256,11 +264,12 @@ static int32_t dndDropBnode(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDCreateBnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
SDCreateBnodeReq *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_BNODE_ID_INVALID;
|
||||
dError("failed to create bnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndOpenBnode(pDnode);
|
||||
|
@ -268,11 +277,12 @@ int32_t dndProcessCreateBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
|||
}
|
||||
|
||||
int32_t dndProcessDropBnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDDropBnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
SDDropBnodeReq *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_BNODE_ID_INVALID;
|
||||
dError("failed to drop bnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndDropBnode(pDnode);
|
||||
|
|
|
@ -80,7 +80,7 @@ void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) {
|
|||
taosRUnLockLatch(&pMgmt->latch);
|
||||
}
|
||||
|
||||
void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
void dndSendRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
tmsg_t msgType = pMsg->msgType;
|
||||
|
||||
SEpSet epSet = {0};
|
||||
|
@ -354,7 +354,7 @@ static int32_t dndWriteDnodes(SDnode *pDnode) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
void dndSendStatusMsg(SDnode *pDnode) {
|
||||
void dndSendStatusReq(SDnode *pDnode) {
|
||||
int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad);
|
||||
|
||||
SStatusMsg *pStatus = rpcMallocCont(contLen);
|
||||
|
@ -391,7 +391,7 @@ void dndSendStatusMsg(SDnode *pDnode) {
|
|||
pMgmt->statusSent = 1;
|
||||
|
||||
dTrace("pDnode:%p, send status msg to mnode", pDnode);
|
||||
dndSendMsgToMnode(pDnode, &rpcMsg);
|
||||
dndSendReqToMnode(pDnode, &rpcMsg);
|
||||
}
|
||||
|
||||
static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) {
|
||||
|
@ -491,7 +491,7 @@ static void *dnodeThreadRoutine(void *param) {
|
|||
taosMsleep(ms);
|
||||
|
||||
if (dndGetStat(pDnode) == DND_STAT_RUNNING && !pMgmt->statusSent && !pMgmt->dropped) {
|
||||
dndSendStatusMsg(pDnode);
|
||||
dndSendStatusReq(pDnode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "dndTransport.h"
|
||||
#include "dndWorker.h"
|
||||
|
||||
static void dndWriteMnodeMsgToWorker(SDnode *pDnode, SDnodeWorker *pWorker, SRpcMsg *pRpcMsg);
|
||||
static void dndProcessMnodeQueue(SDnode *pDnode, SMnodeMsg *pMsg);
|
||||
|
||||
static SMnode *dndAcquireMnode(SDnode *pDnode) {
|
||||
|
@ -258,11 +259,16 @@ static bool dndNeedDeployMnode(SDnode *pDnode) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static int32_t dndPutMsgToMWriteQ(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
dndWriteMnodeMsgToWorker(pDnode, &pDnode->mmgmt.writeWorker, pRpcMsg);
|
||||
}
|
||||
|
||||
static void dndInitMnodeOption(SDnode *pDnode, SMnodeOpt *pOption) {
|
||||
pOption->pDnode = pDnode;
|
||||
pOption->sendMsgToDnodeFp = dndSendMsgToDnode;
|
||||
pOption->sendMsgToMnodeFp = dndSendMsgToMnode;
|
||||
pOption->sendRedirectMsgFp = dndSendRedirectMsg;
|
||||
pOption->sendReqToDnodeFp = dndSendReqToDnode;
|
||||
pOption->sendReqToMnodeFp = dndSendReqToMnode;
|
||||
pOption->sendRedirectRspFp = dndSendRedirectRsp;
|
||||
pOption->putReqToMWriteQFp = dndPutMsgToMWriteQ;
|
||||
pOption->dnodeId = dndGetDnodeId(pDnode);
|
||||
pOption->clusterId = dndGetClusterId(pDnode);
|
||||
pOption->cfg.sver = pDnode->opt.sver;
|
||||
|
|
|
@ -27,7 +27,7 @@ static SQnode *dndAcquireQnode(SDnode *pDnode) {
|
|||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pMgmt->deployed && !pMgmt->dropped) {
|
||||
if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pQnode != NULL) {
|
||||
refCount = atomic_add_fetch_32(&pMgmt->refCount, 1);
|
||||
pQnode = pMgmt->pQnode;
|
||||
} else {
|
||||
|
@ -60,7 +60,7 @@ static int32_t dndReadQnodeFile(SDnode *pDnode) {
|
|||
SQnodeMgmt *pMgmt = &pDnode->qmgmt;
|
||||
int32_t code = TSDB_CODE_DND_QNODE_READ_FILE_ERROR;
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 4096;
|
||||
int32_t maxLen = 1024;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
cJSON *root = NULL;
|
||||
|
||||
|
@ -127,7 +127,7 @@ static int32_t dndWriteQnodeFile(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 4096;
|
||||
int32_t maxLen = 1024;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
|
@ -175,7 +175,7 @@ static void dndStopQnodeWorker(SDnode *pDnode) {
|
|||
pMgmt->deployed = 0;
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
|
||||
while (pMgmt->refCount > 1) {
|
||||
while (pMgmt->refCount > 0) {
|
||||
taosMsleep(10);
|
||||
}
|
||||
|
||||
|
@ -185,9 +185,9 @@ static void dndStopQnodeWorker(SDnode *pDnode) {
|
|||
|
||||
static void dndBuildQnodeOption(SDnode *pDnode, SQnodeOpt *pOption) {
|
||||
pOption->pDnode = pDnode;
|
||||
pOption->sendMsgToDnodeFp = dndSendMsgToDnode;
|
||||
pOption->sendMsgToMnodeFp = dndSendMsgToMnode;
|
||||
pOption->sendRedirectMsgFp = dndSendRedirectMsg;
|
||||
pOption->sendReqToDnodeFp = dndSendReqToDnode;
|
||||
pOption->sendReqToMnodeFp = dndSendReqToMnode;
|
||||
pOption->sendRedirectRspFp = dndSendRedirectRsp;
|
||||
pOption->dnodeId = dndGetDnodeId(pDnode);
|
||||
pOption->clusterId = dndGetClusterId(pDnode);
|
||||
pOption->cfg.sver = pDnode->opt.sver;
|
||||
|
@ -195,10 +195,19 @@ static void dndBuildQnodeOption(SDnode *pDnode, SQnodeOpt *pOption) {
|
|||
|
||||
static int32_t dndOpenQnode(SDnode *pDnode) {
|
||||
SQnodeMgmt *pMgmt = &pDnode->qmgmt;
|
||||
SQnodeOpt option = {0};
|
||||
|
||||
SQnode *pQnode = dndAcquireQnode(pDnode);
|
||||
if (pQnode != NULL) {
|
||||
dndReleaseQnode(pDnode, pQnode);
|
||||
terrno = TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED;
|
||||
dError("failed to create qnode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SQnodeOpt option = {0};
|
||||
dndBuildQnodeOption(pDnode, &option);
|
||||
|
||||
SQnode *pQnode = qndOpen(&option);
|
||||
pQnode = qndOpen(&option);
|
||||
if (pQnode == NULL) {
|
||||
dError("failed to open qnode since %s", terrstr());
|
||||
return -1;
|
||||
|
@ -261,11 +270,12 @@ static int32_t dndDropQnode(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDCreateQnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
SDCreateQnodeReq *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_QNODE_ID_INVALID;
|
||||
dError("failed to create qnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndOpenQnode(pDnode);
|
||||
|
@ -273,11 +283,12 @@ int32_t dndProcessCreateQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
|||
}
|
||||
|
||||
int32_t dndProcessDropQnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDDropQnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
SDDropQnodeReq *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_QNODE_ID_INVALID;
|
||||
dError("failed to drop qnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndDropQnode(pDnode);
|
||||
|
@ -293,15 +304,18 @@ static void dndProcessQnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) {
|
|||
if (pQnode != NULL) {
|
||||
code = qndProcessMsg(pQnode, pMsg, &pRsp);
|
||||
}
|
||||
dndReleaseQnode(pDnode, pQnode);
|
||||
|
||||
if (pRsp != NULL) {
|
||||
pRsp->ahandle = pMsg->ahandle;
|
||||
rpcSendResponse(pRsp);
|
||||
free(pRsp);
|
||||
} else {
|
||||
if (code != 0) code = terrno;
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
if (pMsg->msgType & 1u) {
|
||||
if (pRsp != NULL) {
|
||||
pRsp->ahandle = pMsg->ahandle;
|
||||
rpcSendResponse(pRsp);
|
||||
free(pRsp);
|
||||
} else {
|
||||
if (code != 0) code = terrno;
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
}
|
||||
}
|
||||
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
|
|
@ -27,7 +27,7 @@ static SSnode *dndAcquireSnode(SDnode *pDnode) {
|
|||
int32_t refCount = 0;
|
||||
|
||||
taosRLockLatch(&pMgmt->latch);
|
||||
if (pMgmt->deployed && !pMgmt->dropped) {
|
||||
if (pMgmt->deployed && !pMgmt->dropped && pMgmt->pSnode != NULL) {
|
||||
refCount = atomic_add_fetch_32(&pMgmt->refCount, 1);
|
||||
pSnode = pMgmt->pSnode;
|
||||
} else {
|
||||
|
@ -60,7 +60,7 @@ static int32_t dndReadSnodeFile(SDnode *pDnode) {
|
|||
SSnodeMgmt *pMgmt = &pDnode->smgmt;
|
||||
int32_t code = TSDB_CODE_DND_SNODE_READ_FILE_ERROR;
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 4096;
|
||||
int32_t maxLen = 1024;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
cJSON *root = NULL;
|
||||
|
||||
|
@ -127,7 +127,7 @@ static int32_t dndWriteSnodeFile(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 4096;
|
||||
int32_t maxLen = 1024;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
|
@ -170,18 +170,18 @@ static void dndStopSnodeWorker(SDnode *pDnode) {
|
|||
pMgmt->deployed = 0;
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
|
||||
while (pMgmt->refCount > 1) {
|
||||
while (pMgmt->refCount > 0) {
|
||||
taosMsleep(10);
|
||||
}
|
||||
}
|
||||
|
||||
dndCleanupWorker(&pMgmt->writeWorker);
|
||||
}
|
||||
|
||||
static void dndBuildSnodeOption(SDnode *pDnode, SSnodeOpt *pOption) {
|
||||
pOption->pDnode = pDnode;
|
||||
pOption->sendMsgToDnodeFp = dndSendMsgToDnode;
|
||||
pOption->sendMsgToMnodeFp = dndSendMsgToMnode;
|
||||
pOption->sendRedirectMsgFp = dndSendRedirectMsg;
|
||||
pOption->sendReqToDnodeFp = dndSendReqToDnode;
|
||||
pOption->sendReqToMnodeFp = dndSendReqToMnode;
|
||||
pOption->sendRedirectRspFp = dndSendRedirectRsp;
|
||||
pOption->dnodeId = dndGetDnodeId(pDnode);
|
||||
pOption->clusterId = dndGetClusterId(pDnode);
|
||||
pOption->cfg.sver = pDnode->opt.sver;
|
||||
|
@ -189,10 +189,18 @@ static void dndBuildSnodeOption(SDnode *pDnode, SSnodeOpt *pOption) {
|
|||
|
||||
static int32_t dndOpenSnode(SDnode *pDnode) {
|
||||
SSnodeMgmt *pMgmt = &pDnode->smgmt;
|
||||
SSnodeOpt option = {0};
|
||||
SSnode *pSnode = dndAcquireSnode(pDnode);
|
||||
if (pSnode != NULL) {
|
||||
dndReleaseSnode(pDnode, pSnode);
|
||||
terrno = TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED;
|
||||
dError("failed to create snode since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SSnodeOpt option = {0};
|
||||
dndBuildSnodeOption(pDnode, &option);
|
||||
|
||||
SSnode *pSnode = sndOpen(pDnode->dir.snode, &option);
|
||||
pSnode = sndOpen(pDnode->dir.snode, &option);
|
||||
if (pSnode == NULL) {
|
||||
dError("failed to open snode since %s", terrstr());
|
||||
return -1;
|
||||
|
@ -256,11 +264,12 @@ static int32_t dndDropSnode(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDCreateSnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
SDCreateSnodeReq *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_SNODE_ID_INVALID;
|
||||
dError("failed to create snode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndOpenSnode(pDnode);
|
||||
|
@ -268,11 +277,12 @@ int32_t dndProcessCreateSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
|||
}
|
||||
|
||||
int32_t dndProcessDropSnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
|
||||
SDDropSnodeMsg *pMsg = pRpcMsg->pCont;
|
||||
SDDropSnodeReq *pMsg = pRpcMsg->pCont;
|
||||
pMsg->dnodeId = htonl(pMsg->dnodeId);
|
||||
|
||||
if (pMsg->dnodeId != dndGetDnodeId(pDnode)) {
|
||||
terrno = TSDB_CODE_DND_SNODE_ID_INVALID;
|
||||
dError("failed to drop snode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return dndDropSnode(pDnode);
|
||||
|
@ -288,15 +298,18 @@ static void dndProcessSnodeQueue(SDnode *pDnode, SRpcMsg *pMsg) {
|
|||
if (pSnode != NULL) {
|
||||
code = sndProcessMsg(pSnode, pMsg, &pRsp);
|
||||
}
|
||||
dndReleaseSnode(pDnode, pSnode);
|
||||
|
||||
if (pRsp != NULL) {
|
||||
pRsp->ahandle = pMsg->ahandle;
|
||||
rpcSendResponse(pRsp);
|
||||
free(pRsp);
|
||||
} else {
|
||||
if (code != 0) code = terrno;
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
if (pMsg->msgType & 1u) {
|
||||
if (pRsp != NULL) {
|
||||
pRsp->ahandle = pMsg->ahandle;
|
||||
rpcSendResponse(pRsp);
|
||||
free(pRsp);
|
||||
} else {
|
||||
if (code != 0) code = terrno;
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
}
|
||||
}
|
||||
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
|
|
@ -105,8 +105,6 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
|||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_SHOW_RETRIEVE)] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS)] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_STATUS_RSP)] = dndProcessMgmtMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_TRANS)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_TRANS_RSP)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GRANT)] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_GRANT_RSP)] = dndProcessMgmtMsg;
|
||||
pMgmt->msgFp[TMSG_INDEX(TDMT_MND_AUTH)] = dndProcessMnodeReadMsg;
|
||||
|
@ -160,8 +158,8 @@ static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
|||
|
||||
DndMsgFp fp = pMgmt->msgFp[TMSG_INDEX(msgType)];
|
||||
if (fp != NULL) {
|
||||
dTrace("RPC %p, rsp:%s will be processed, code:0x%x", pMsg->handle, TMSG_INFO(msgType), pMsg->code & 0XFFFF);
|
||||
(*fp)(pDnode, pMsg, pEpSet);
|
||||
dTrace("RPC %p, rsp:%s is processed, code:0x%x", pMsg->handle, TMSG_INFO(msgType), pMsg->code & 0XFFFF);
|
||||
} else {
|
||||
dError("RPC %p, rsp:%s not processed", pMsg->handle, TMSG_INFO(msgType));
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
@ -216,7 +214,7 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
|||
|
||||
if (dndGetStat(pDnode) == DND_STAT_STOPPED) {
|
||||
dError("RPC %p, req:%s app:%p is ignored since dnode exiting", pMsg->handle, TMSG_INFO(msgType), pMsg->ahandle);
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_EXITING};
|
||||
SRpcMsg rspMsg = {.handle = pMsg->handle, .code = TSDB_CODE_DND_OFFLINE};
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
return;
|
||||
|
@ -383,14 +381,19 @@ void dndCleanupTrans(SDnode *pDnode) {
|
|||
dInfo("dnode-transport is cleaned up");
|
||||
}
|
||||
|
||||
void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
int32_t dndSendReqToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
STransMgmt *pMgmt = &pDnode->tmgmt;
|
||||
if (pMgmt->clientRpc == NULL) return;
|
||||
if (pMgmt->clientRpc == NULL) {
|
||||
terrno = TSDB_CODE_DND_OFFLINE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rpcSendRequest(pMgmt->clientRpc, pEpSet, pMsg, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dndSendMsgToMnode(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
int32_t dndSendReqToMnode(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
SEpSet epSet = {0};
|
||||
dndGetMnodeEpSet(pDnode, &epSet);
|
||||
dndSendMsgToDnode(pDnode, &epSet, pMsg);
|
||||
return dndSendReqToDnode(pDnode, &epSet, pMsg);
|
||||
}
|
||||
|
|
|
@ -14,8 +14,11 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "dndBnode.h"
|
||||
#include "dndDnode.h"
|
||||
#include "dndMnode.h"
|
||||
#include "dndQnode.h"
|
||||
#include "dndSnode.h"
|
||||
#include "dndTransport.h"
|
||||
#include "dndVnodes.h"
|
||||
#include "sync.h"
|
||||
|
@ -200,6 +203,24 @@ SDnode *dndInit(SDnodeOpt *pOption) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (dndInitQnode(pDnode) != 0) {
|
||||
dError("failed to init qnode");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dndInitSnode(pDnode) != 0) {
|
||||
dError("failed to init snode");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dndInitBnode(pDnode) != 0) {
|
||||
dError("failed to init bnode");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dndInitMnode(pDnode) != 0) {
|
||||
dError("failed to init mnode");
|
||||
dndCleanup(pDnode);
|
||||
|
@ -213,7 +234,7 @@ SDnode *dndInit(SDnodeOpt *pOption) {
|
|||
}
|
||||
|
||||
dndSetStat(pDnode, DND_STAT_RUNNING);
|
||||
dndSendStatusMsg(pDnode);
|
||||
dndSendStatusReq(pDnode);
|
||||
dndReportStartup(pDnode, "TDengine", "initialized successfully");
|
||||
dInfo("TDengine is initialized successfully, pDnode:%p", pDnode);
|
||||
|
||||
|
@ -232,6 +253,9 @@ void dndCleanup(SDnode *pDnode) {
|
|||
dndSetStat(pDnode, DND_STAT_STOPPED);
|
||||
dndCleanupTrans(pDnode);
|
||||
dndCleanupMnode(pDnode);
|
||||
dndCleanupBnode(pDnode);
|
||||
dndCleanupSnode(pDnode);
|
||||
dndCleanupQnode(pDnode);
|
||||
dndCleanupVnodes(pDnode);
|
||||
dndCleanupDnode(pDnode);
|
||||
vnodeClear();
|
||||
|
|
|
@ -1,23 +1,20 @@
|
|||
enable_testing()
|
||||
|
||||
add_subdirectory(acct)
|
||||
add_subdirectory(qnode)
|
||||
add_subdirectory(bnode)
|
||||
add_subdirectory(snode)
|
||||
|
||||
# add_subdirectory(auth)
|
||||
# add_subdirectory(balance)
|
||||
add_subdirectory(cluster)
|
||||
add_subdirectory(db)
|
||||
add_subdirectory(dnode)
|
||||
# add_subdirectory(func)
|
||||
add_subdirectory(mnode)
|
||||
add_subdirectory(qnode)
|
||||
add_subdirectory(snode)
|
||||
add_subdirectory(bnode)
|
||||
add_subdirectory(profile)
|
||||
add_subdirectory(show)
|
||||
add_subdirectory(stb)
|
||||
# add_subdirectory(sync)
|
||||
# add_subdirectory(telem)
|
||||
# add_subdirectory(trans)
|
||||
add_subdirectory(user)
|
||||
add_subdirectory(vgroup)
|
||||
|
||||
add_subdirectory(sut)
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
aux_source_directory(. ACCT_SRC)
|
||||
add_executable(dnode_test_acct ${ACCT_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_acct
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_acct
|
||||
COMMAND dnode_test_acct
|
||||
)
|
|
@ -1,67 +0,0 @@
|
|||
/**
|
||||
* @file acct.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module acct-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
|
||||
class DndTestAcct : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_acct", 9012); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase DndTestAcct::test;
|
||||
|
||||
TEST_F(DndTestAcct, 01_CreateAcct) {
|
||||
int32_t contLen = sizeof(SCreateAcctMsg);
|
||||
|
||||
SCreateAcctMsg* pReq = (SCreateAcctMsg*)rpcMallocCont(contLen);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_ACCT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
||||
}
|
||||
|
||||
TEST_F(DndTestAcct, 02_AlterAcct) {
|
||||
int32_t contLen = sizeof(SCreateAcctMsg);
|
||||
|
||||
SAlterAcctMsg* pReq = (SAlterAcctMsg*)rpcMallocCont(contLen);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_ACCT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
||||
}
|
||||
|
||||
TEST_F(DndTestAcct, 03_DropAcct) {
|
||||
int32_t contLen = sizeof(SDropAcctMsg);
|
||||
|
||||
SDropAcctMsg* pReq = (SDropAcctMsg*)rpcMallocCont(contLen);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_ACCT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
||||
}
|
||||
|
||||
TEST_F(DndTestAcct, 04_ShowAcct) {
|
||||
int32_t contLen = sizeof(SShowMsg);
|
||||
|
||||
SShowMsg* pReq = (SShowMsg*)rpcMallocCont(contLen);
|
||||
pReq->type = TSDB_MGMT_TABLE_ACCT;
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_SHOW, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE);
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
aux_source_directory(. STEST_SRC)
|
||||
add_executable(dnode_test_bnode ${STEST_SRC})
|
||||
aux_source_directory(. BQTEST_SRC)
|
||||
add_executable(dnode_test_bnode ${BQTEST_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_bnode
|
||||
PUBLIC sut
|
||||
|
|
|
@ -1,154 +0,0 @@
|
|||
/**
|
||||
* @file dnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module dnode-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
|
||||
class DndTestBnode : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/dnode_test_bnode1", 9068);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9068";
|
||||
|
||||
server2.Start("/tmp/dnode_test_bnode2", fqdn, 9069, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
server2.Stop();
|
||||
test.Cleanup();
|
||||
}
|
||||
|
||||
static Testbase test;
|
||||
static TestServer server2;
|
||||
};
|
||||
|
||||
Testbase DndTestBnode::test;
|
||||
TestServer DndTestBnode::server2;
|
||||
|
||||
TEST_F(DndTestBnode, 01_ShowBnode) {
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, "");
|
||||
CHECK_META("show bnodes", 3);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestBnode, 02_Create_Bnode_Invalid_Id) {
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateBnodeMsg);
|
||||
|
||||
SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, "");
|
||||
CHECK_META("show bnodes", 3);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9068", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestBnode, 03_Create_Bnode_Invalid_Id) {
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateBnodeMsg);
|
||||
|
||||
SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestBnode, 04_Create_Bnode) {
|
||||
{
|
||||
// create dnode
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9069);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
taosMsleep(1300);
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
}
|
||||
|
||||
{
|
||||
// create bnode
|
||||
int32_t contLen = sizeof(SMCreateBnodeMsg);
|
||||
|
||||
SMCreateBnodeMsg* pReq = (SMCreateBnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, "");
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(2);
|
||||
CheckBinary("localhost:9068", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9069", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
{
|
||||
// drop bnode
|
||||
int32_t contLen = sizeof(SMDropBnodeMsg);
|
||||
|
||||
SMDropBnodeMsg* pReq = (SMDropBnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_BNODE, "");
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9068", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
/**
|
||||
* @file dbnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module bnode tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-05
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestBnode : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_snode", 9112); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase DndTestBnode::test;
|
||||
|
||||
TEST_F(DndTestBnode, 01_Create_Bnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateBnodeReq);
|
||||
|
||||
SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ID_INVALID);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateBnodeReq);
|
||||
|
||||
SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateBnodeReq);
|
||||
|
||||
SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED);
|
||||
}
|
||||
|
||||
test.Restart();
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateBnodeReq);
|
||||
|
||||
SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestBnode, 01_Drop_Bnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropBnodeReq);
|
||||
|
||||
SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_ID_INVALID);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropBnodeReq);
|
||||
|
||||
SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropBnodeReq);
|
||||
|
||||
SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_NOT_DEPLOYED);
|
||||
}
|
||||
|
||||
test.Restart();
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropBnodeReq);
|
||||
|
||||
SDDropBnodeReq* pReq = (SDDropBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_BNODE_NOT_DEPLOYED);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateBnodeReq);
|
||||
|
||||
SDCreateBnodeReq* pReq = (SDCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
aux_source_directory(. CLUSTER_SRC)
|
||||
add_executable(dnode_test_cluster ${CLUSTER_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_cluster
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_cluster
|
||||
COMMAND dnode_test_cluster
|
||||
)
|
|
@ -1,41 +0,0 @@
|
|||
/**
|
||||
* @file cluster.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module cluster-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
|
||||
class DndTestCluster : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_cluster", 9030); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase DndTestCluster::test;
|
||||
|
||||
TEST_F(DndTestCluster, 01_ShowCluster) {
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_CLUSTER, "");
|
||||
CHECK_META( "show cluster", 3);
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_BIGINT, 8, "id");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
IgnoreInt64();
|
||||
IgnoreBinary(TSDB_CLUSTER_ID_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
|
@ -9,7 +9,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestDb : public ::testing::Test {
|
||||
protected:
|
||||
|
@ -26,7 +26,7 @@ class DndTestDb : public ::testing::Test {
|
|||
Testbase DndTestDb::test;
|
||||
|
||||
TEST_F(DndTestDb, 01_ShowDb) {
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, "");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, "");
|
||||
CHECK_META("show databases", 18);
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN - 1 + VARSTR_HEADER_SIZE, "name");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
@ -47,7 +47,7 @@ TEST_F(DndTestDb, 01_ShowDb) {
|
|||
CHECK_SCHEMA(16, TSDB_DATA_TYPE_BINARY, 3 + VARSTR_HEADER_SIZE, "precision");
|
||||
CHECK_SCHEMA(17, TSDB_DATA_TYPE_TINYINT, 1, "update");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
||||
|
@ -77,15 +77,15 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
|
|||
pReq->cacheLastRow = 0;
|
||||
pReq->ignoreExist = 1;
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, "");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, "");
|
||||
CHECK_META("show databases", 18);
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
|
||||
CheckTimestamp();
|
||||
|
@ -106,17 +106,17 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
|
|||
CheckBinary("ms", 3); // precision
|
||||
CheckInt8(0); // update
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_VGROUP, "1.d1");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_VGROUP, "1.d1");
|
||||
CHECK_META("show vgroups", 4);
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "vgId");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_INT, 4, "tables");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "v1_dnode");
|
||||
CHECK_SCHEMA(3, TSDB_DATA_TYPE_BINARY, 9 + VARSTR_HEADER_SIZE, "v1_status");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
CheckInt32(1);
|
||||
CheckInt32(2);
|
||||
CheckInt32(3);
|
||||
CheckInt32(0);
|
||||
CheckInt32(0);
|
||||
CheckInt16(1);
|
||||
|
@ -138,13 +138,13 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
|
|||
pReq->quorum = 2;
|
||||
pReq->cacheLastRow = 1;
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_DB, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_DB, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, "");
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
|
||||
CheckTimestamp();
|
||||
|
@ -168,10 +168,10 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
|
|||
// restart
|
||||
test.Restart();
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, "");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, "");
|
||||
CHECK_META("show databases", 18);
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
|
||||
|
@ -199,15 +199,15 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
|
|||
SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->db, "1.d1");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DB, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DB, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, "");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, "");
|
||||
CHECK_META("show databases", 18);
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
||||
|
@ -237,15 +237,15 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) {
|
|||
pReq->cacheLastRow = 0;
|
||||
pReq->ignoreExist = 1;
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, "");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DB, "");
|
||||
CHECK_META("show databases", 18);
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
CheckBinary("d2", TSDB_DB_NAME_LEN - 1);
|
||||
|
||||
|
@ -256,7 +256,7 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) {
|
|||
strcpy(pReq->db, "1.d2");
|
||||
pReq->vgVersion = htonl(-1);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_USE_DB, pReq, contLen);
|
||||
SRpcMsg* pMsg = test.SendReq(TDMT_MND_USE_DB, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestDnode : public ::testing::Test {
|
||||
public:
|
||||
|
@ -51,7 +51,7 @@ TestServer DndTestDnode::server4;
|
|||
TestServer DndTestDnode::server5;
|
||||
|
||||
TEST_F(DndTestDnode, 01_ShowDnode) {
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
|
@ -62,7 +62,7 @@ TEST_F(DndTestDnode, 01_ShowDnode) {
|
|||
CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
|
@ -81,9 +81,9 @@ TEST_F(DndTestDnode, 02_ConfigDnode) {
|
|||
pReq->dnodeId = htonl(1);
|
||||
strcpy(pReq->config, "ddebugflag 131");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONFIG_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONFIG_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
||||
|
@ -94,16 +94,16 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
|||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9042);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
taosMsleep(1300);
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckInt16(1);
|
||||
|
@ -127,14 +127,14 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
|||
SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
|
@ -152,9 +152,9 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
|||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9043);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -164,9 +164,9 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
|||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9044);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -176,15 +176,15 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
|||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9045);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
taosMsleep(1300);
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
CheckInt16(1);
|
||||
|
@ -225,9 +225,9 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
|||
server5.Restart();
|
||||
|
||||
taosMsleep(1300);
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
CheckInt16(1);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestMnode : public ::testing::Test {
|
||||
public:
|
||||
|
@ -51,7 +51,7 @@ TestServer DndTestMnode::server4;
|
|||
TestServer DndTestMnode::server5;
|
||||
|
||||
TEST_F(DndTestMnode, 01_ShowDnode) {
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, "");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
|
||||
CHECK_META("show mnodes", 5);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
|
@ -60,7 +60,7 @@ TEST_F(DndTestMnode, 01_ShowDnode) {
|
|||
CHECK_SCHEMA(3, TSDB_DATA_TYPE_TIMESTAMP, 8, "role_time");
|
||||
CHECK_SCHEMA(4, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
|
@ -77,9 +77,9 @@ TEST_F(DndTestMnode, 02_Create_Mnode_Invalid_Id) {
|
|||
SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MNODE_ALREADY_EXIST);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MNODE_ALREADY_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,9 +90,9 @@ TEST_F(DndTestMnode, 03_Create_Mnode_Invalid_Id) {
|
|||
SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,13 +105,13 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
|
|||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9062);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
taosMsleep(1300);
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
}
|
||||
|
||||
|
@ -122,12 +122,12 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
|
|||
SMCreateMnodeMsg* pReq = (SMCreateMnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, "");
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckInt16(1);
|
||||
|
@ -149,12 +149,12 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
|
|||
SMDropMnodeMsg* pReq = (SMDropMnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_MNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_MNODE, "");
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_MNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
|
@ -170,14 +170,14 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
|
|||
// SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen);
|
||||
// pReq->dnodeId = htonl(2);
|
||||
|
||||
// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_DNODE, pReq, contLen);
|
||||
// ASSERT_NE(pMsg, nullptr);
|
||||
// ASSERT_EQ(pMsg->code, 0);
|
||||
// SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_DNODE, pReq, contLen);
|
||||
// ASSERT_NE(pRsp, nullptr);
|
||||
// ASSERT_EQ(pRsp->code, 0);
|
||||
// }
|
||||
|
||||
// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
// CHECK_META("show dnodes", 7);
|
||||
// test.SendShowRetrieveMsg();
|
||||
// test.SendShowRetrieveReq();
|
||||
// EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
// CheckInt16(1);
|
||||
|
@ -194,9 +194,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
|
|||
// SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
// strcpy(pReq->ep, "localhost:9063");
|
||||
|
||||
// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
// ASSERT_NE(pMsg, nullptr);
|
||||
// ASSERT_EQ(pMsg->code, 0);
|
||||
// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
// ASSERT_NE(pRsp, nullptr);
|
||||
// ASSERT_EQ(pRsp->code, 0);
|
||||
// }
|
||||
|
||||
// {
|
||||
|
@ -205,9 +205,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
|
|||
// SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
// strcpy(pReq->ep, "localhost:9064");
|
||||
|
||||
// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
// ASSERT_NE(pMsg, nullptr);
|
||||
// ASSERT_EQ(pMsg->code, 0);
|
||||
// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
// ASSERT_NE(pRsp, nullptr);
|
||||
// ASSERT_EQ(pRsp->code, 0);
|
||||
// }
|
||||
|
||||
// {
|
||||
|
@ -216,15 +216,15 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
|
|||
// SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
// strcpy(pReq->ep, "localhost:9065");
|
||||
|
||||
// SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
// ASSERT_NE(pMsg, nullptr);
|
||||
// ASSERT_EQ(pMsg->code, 0);
|
||||
// SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
// ASSERT_NE(pRsp, nullptr);
|
||||
// ASSERT_EQ(pRsp->code, 0);
|
||||
// }
|
||||
|
||||
// taosMsleep(1300);
|
||||
// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
// CHECK_META("show dnodes", 7);
|
||||
// test.SendShowRetrieveMsg();
|
||||
// test.SendShowRetrieveReq();
|
||||
// EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
// CheckInt16(1);
|
||||
|
@ -265,9 +265,9 @@ TEST_F(DndTestMnode, 04_Create_Mnode) {
|
|||
// server5.Restart();
|
||||
|
||||
// taosMsleep(1300);
|
||||
// test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
// test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
// CHECK_META("show dnodes", 7);
|
||||
// test.SendShowRetrieveMsg();
|
||||
// test.SendShowRetrieveReq();
|
||||
// EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
// CheckInt16(1);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestProfile : public ::testing::Test {
|
||||
protected:
|
||||
|
@ -17,15 +17,15 @@ class DndTestProfile : public ::testing::Test {
|
|||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
static int32_t connId;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
int32_t connId;
|
||||
};
|
||||
|
||||
Testbase DndTestProfile::test;
|
||||
int32_t DndTestProfile::connId;
|
||||
|
||||
TEST_F(DndTestProfile, 01_ConnectMsg) {
|
||||
int32_t contLen = sizeof(SConnectMsg);
|
||||
|
@ -35,7 +35,7 @@ TEST_F(DndTestProfile, 01_ConnectMsg) {
|
|||
strcpy(pReq->app, "dnode_test_profile");
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen);
|
||||
SRpcMsg* pMsg = test.SendReq(TDMT_MND_CONNECT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
|
@ -67,14 +67,14 @@ TEST_F(DndTestProfile, 02_ConnectMsg_InvalidDB) {
|
|||
strcpy(pReq->app, "dnode_test_profile");
|
||||
strcpy(pReq->db, "invalid_db");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_DB);
|
||||
ASSERT_EQ(pMsg->contLen, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONNECT, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_DB);
|
||||
ASSERT_EQ(pRsp->contLen, 0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, 03_ConnectMsg_Show) {
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_CONNS, "");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_CONNS, "");
|
||||
CHECK_META("show connections", 7);
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "connId");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "user");
|
||||
|
@ -84,7 +84,7 @@ TEST_F(DndTestProfile, 03_ConnectMsg_Show) {
|
|||
CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "login_time");
|
||||
CHECK_SCHEMA(6, TSDB_DATA_TYPE_TIMESTAMP, 8, "last_access");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
CheckInt32(1);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
|
@ -105,7 +105,7 @@ TEST_F(DndTestProfile, 04_HeartBeatMsg) {
|
|||
pReq->numOfStreams = htonl(0);
|
||||
strcpy(pReq->app, "dnode_test_profile");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_HEARTBEAT, pReq, contLen);
|
||||
SRpcMsg* pMsg = test.SendReq(TDMT_MND_HEARTBEAT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
|
@ -138,9 +138,9 @@ TEST_F(DndTestProfile, 05_KillConnMsg) {
|
|||
SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen);
|
||||
pReq->connId = htonl(connId);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_CONN, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_CONN, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -153,10 +153,10 @@ TEST_F(DndTestProfile, 05_KillConnMsg) {
|
|||
pReq->numOfStreams = htonl(0);
|
||||
strcpy(pReq->app, "dnode_test_profile");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_HEARTBEAT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONNECTION);
|
||||
ASSERT_EQ(pMsg->contLen, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_HEARTBEAT, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONNECTION);
|
||||
ASSERT_EQ(pRsp->contLen, 0);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -167,7 +167,7 @@ TEST_F(DndTestProfile, 05_KillConnMsg) {
|
|||
strcpy(pReq->app, "dnode_test_profile");
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen);
|
||||
SRpcMsg* pMsg = test.SendReq(TDMT_MND_CONNECT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
|
@ -198,9 +198,9 @@ TEST_F(DndTestProfile, 06_KillConnMsg_InvalidConn) {
|
|||
SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen);
|
||||
pReq->connId = htonl(2345);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_CONN, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_CONN, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONN_ID);
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, 07_KillQueryMsg) {
|
||||
|
@ -211,10 +211,10 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) {
|
|||
pReq->connId = htonl(connId);
|
||||
pReq->queryId = htonl(1234);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_QUERY, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
ASSERT_EQ(pMsg->contLen, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_QUERY, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
ASSERT_EQ(pRsp->contLen, 0);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -227,7 +227,7 @@ TEST_F(DndTestProfile, 07_KillQueryMsg) {
|
|||
pReq->numOfStreams = htonl(0);
|
||||
strcpy(pReq->app, "dnode_test_profile");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_HEARTBEAT, pReq, contLen);
|
||||
SRpcMsg* pMsg = test.SendReq(TDMT_MND_HEARTBEAT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
|
@ -261,13 +261,13 @@ TEST_F(DndTestProfile, 08_KillQueryMsg_InvalidConn) {
|
|||
pReq->connId = htonl(2345);
|
||||
pReq->queryId = htonl(1234);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_KILL_QUERY, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_KILL_QUERY, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_CONN_ID);
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, 09_KillQueryMsg) {
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_QUERIES, "");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_QUERIES, "");
|
||||
CHECK_META("show queries", 14);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "queryId");
|
||||
|
@ -285,6 +285,6 @@ TEST_F(DndTestProfile, 09_KillQueryMsg) {
|
|||
CHECK_SCHEMA(12, TSDB_DATA_TYPE_BINARY, TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE, "sub_query_info");
|
||||
CHECK_SCHEMA(13, TSDB_DATA_TYPE_BINARY, TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE, "sql");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
aux_source_directory(. QTEST_SRC)
|
||||
add_executable(dnode_test_qnode ${QTEST_SRC})
|
||||
aux_source_directory(. DQTEST_SRC)
|
||||
add_executable(dnode_test_qnode ${DQTEST_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_qnode
|
||||
PUBLIC sut
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
/**
|
||||
* @file dqnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module qnode tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-05
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestQnode : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_qnode", 9111); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase DndTestQnode::test;
|
||||
|
||||
TEST_F(DndTestQnode, 01_Create_Qnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateQnodeReq);
|
||||
|
||||
SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ID_INVALID);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateQnodeReq);
|
||||
|
||||
SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateQnodeReq);
|
||||
|
||||
SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED);
|
||||
}
|
||||
|
||||
test.Restart();
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateQnodeReq);
|
||||
|
||||
SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestQnode, 01_Drop_Qnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropQnodeReq);
|
||||
|
||||
SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_ID_INVALID);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropQnodeReq);
|
||||
|
||||
SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropQnodeReq);
|
||||
|
||||
SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_NOT_DEPLOYED);
|
||||
}
|
||||
|
||||
test.Restart();
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropQnodeReq);
|
||||
|
||||
SDDropQnodeReq* pReq = (SDDropQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_QNODE_NOT_DEPLOYED);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateQnodeReq);
|
||||
|
||||
SDCreateQnodeReq* pReq = (SDCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
}
|
|
@ -1,154 +0,0 @@
|
|||
/**
|
||||
* @file dnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module dnode-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
|
||||
class DndTestQnode : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/dnode_test_qnode1", 9064);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9064";
|
||||
|
||||
server2.Start("/tmp/dnode_test_qnode2", fqdn, 9065, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
server2.Stop();
|
||||
test.Cleanup();
|
||||
}
|
||||
|
||||
static Testbase test;
|
||||
static TestServer server2;
|
||||
};
|
||||
|
||||
Testbase DndTestQnode::test;
|
||||
TestServer DndTestQnode::server2;
|
||||
|
||||
TEST_F(DndTestQnode, 01_ShowQnode) {
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, "");
|
||||
CHECK_META("show qnodes", 3);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestQnode, 02_Create_Qnode_Invalid_Id) {
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateQnodeMsg);
|
||||
|
||||
SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, "");
|
||||
CHECK_META("show qnodes", 3);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9064", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestQnode, 03_Create_Qnode_Invalid_Id) {
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateQnodeMsg);
|
||||
|
||||
SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestQnode, 04_Create_Qnode) {
|
||||
{
|
||||
// create dnode
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9065);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
taosMsleep(1300);
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
}
|
||||
|
||||
{
|
||||
// create qnode
|
||||
int32_t contLen = sizeof(SMCreateQnodeMsg);
|
||||
|
||||
SMCreateQnodeMsg* pReq = (SMCreateQnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, "");
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(2);
|
||||
CheckBinary("localhost:9064", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9065", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
{
|
||||
// drop qnode
|
||||
int32_t contLen = sizeof(SMDropQnodeMsg);
|
||||
|
||||
SMDropQnodeMsg* pReq = (SMDropQnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_QNODE, "");
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9064", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
aux_source_directory(. SHOW_SRC)
|
||||
add_executable(dnode_test_show ${SHOW_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_show
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_show
|
||||
COMMAND dnode_test_show
|
||||
)
|
|
@ -1,87 +0,0 @@
|
|||
/**
|
||||
* @file show.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module show-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
|
||||
class DndTestShow : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_show", 9091); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase DndTestShow::test;
|
||||
|
||||
TEST_F(DndTestShow, 01_ShowMsg_InvalidMsgMax) {
|
||||
int32_t contLen = sizeof(SShowMsg);
|
||||
|
||||
SShowMsg* pReq = (SShowMsg*)rpcMallocCont(contLen);
|
||||
pReq->type = TSDB_MGMT_TABLE_MAX;
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_SHOW, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE);
|
||||
}
|
||||
|
||||
TEST_F(DndTestShow, 02_ShowMsg_InvalidMsgStart) {
|
||||
int32_t contLen = sizeof(SShowMsg);
|
||||
|
||||
SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pReq->type = TSDB_MGMT_TABLE_START;
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_SHOW, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE);
|
||||
}
|
||||
|
||||
TEST_F(DndTestShow, 02_ShowMsg_Conn) {
|
||||
int32_t contLen = sizeof(SConnectMsg);
|
||||
|
||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen);
|
||||
pReq->pid = htonl(1234);
|
||||
strcpy(pReq->app, "dnode_test_show");
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CONNECT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_CONNS, "");
|
||||
|
||||
STableMetaMsg* pMeta = test.GetShowMeta();
|
||||
EXPECT_STREQ(pMeta->tbFname, "show connections");
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, 7);
|
||||
EXPECT_EQ(pMeta->precision, 0);
|
||||
EXPECT_EQ(pMeta->tableType, 0);
|
||||
EXPECT_EQ(pMeta->update, 0);
|
||||
EXPECT_EQ(pMeta->sversion, 0);
|
||||
EXPECT_EQ(pMeta->tversion, 0);
|
||||
EXPECT_EQ(pMeta->tuid, 0);
|
||||
EXPECT_EQ(pMeta->suid, 0);
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
|
||||
SRetrieveTableRsp* pRetrieveRsp = test.GetRetrieveRsp();
|
||||
EXPECT_EQ(pRetrieveRsp->numOfRows, 1);
|
||||
EXPECT_EQ(pRetrieveRsp->useconds, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->completed, 1);
|
||||
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRetrieveRsp->compressed, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->compLen, 0);
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
aux_source_directory(. STEST_SRC)
|
||||
add_executable(dnode_test_snode ${STEST_SRC})
|
||||
aux_source_directory(. SQTEST_SRC)
|
||||
add_executable(dnode_test_snode ${SQTEST_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_snode
|
||||
PUBLIC sut
|
||||
|
|
|
@ -0,0 +1,133 @@
|
|||
/**
|
||||
* @file dsnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module snode tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-05
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestSnode : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_snode", 9112); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase DndTestSnode::test;
|
||||
|
||||
TEST_F(DndTestSnode, 01_Create_Snode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateSnodeReq);
|
||||
|
||||
SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_ID_INVALID);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateSnodeReq);
|
||||
|
||||
SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateSnodeReq);
|
||||
|
||||
SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED);
|
||||
}
|
||||
|
||||
test.Restart();
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateSnodeReq);
|
||||
|
||||
SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestSnode, 01_Drop_Snode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropSnodeReq);
|
||||
|
||||
SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_ID_INVALID);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropSnodeReq);
|
||||
|
||||
SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropSnodeReq);
|
||||
|
||||
SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_NOT_DEPLOYED);
|
||||
}
|
||||
|
||||
test.Restart();
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDDropSnodeReq);
|
||||
|
||||
SDDropSnodeReq* pReq = (SDDropSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_SNODE_NOT_DEPLOYED);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDCreateSnodeReq);
|
||||
|
||||
SDCreateSnodeReq* pReq = (SDCreateSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
}
|
|
@ -1,154 +0,0 @@
|
|||
/**
|
||||
* @file dnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module dnode-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
|
||||
class DndTestSnode : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/dnode_test_snode1", 9066);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9066";
|
||||
|
||||
server2.Start("/tmp/dnode_test_snode2", fqdn, 9067, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
server2.Stop();
|
||||
test.Cleanup();
|
||||
}
|
||||
|
||||
static Testbase test;
|
||||
static TestServer server2;
|
||||
};
|
||||
|
||||
Testbase DndTestSnode::test;
|
||||
TestServer DndTestSnode::server2;
|
||||
|
||||
TEST_F(DndTestSnode, 01_ShowSnode) {
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, "");
|
||||
CHECK_META("show snodes", 3);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestSnode, 02_Create_Snode_Invalid_Id) {
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateSnodeMsg);
|
||||
|
||||
SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, "");
|
||||
CHECK_META("show snodes", 3);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9066", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestSnode, 03_Create_Snode_Invalid_Id) {
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateSnodeMsg);
|
||||
|
||||
SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestSnode, 04_Create_Snode) {
|
||||
{
|
||||
// create dnode
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9067);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
taosMsleep(1300);
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
}
|
||||
|
||||
{
|
||||
// create snode
|
||||
int32_t contLen = sizeof(SMCreateSnodeMsg);
|
||||
|
||||
SMCreateSnodeMsg* pReq = (SMCreateSnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, "");
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(2);
|
||||
CheckBinary("localhost:9066", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9067", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
{
|
||||
// drop snode
|
||||
int32_t contLen = sizeof(SMDropSnodeMsg);
|
||||
|
||||
SMDropSnodeMsg* pReq = (SMDropSnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_SNODE, "");
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9066", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestStb : public ::testing::Test {
|
||||
protected:
|
||||
|
@ -51,9 +51,9 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
|||
pReq->cacheLastRow = 0;
|
||||
pReq->ignoreExist = 1;
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -101,12 +101,12 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
|||
strcpy(pSchema->name, "tag3");
|
||||
}
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_STB, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_STB, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, "1.d1");
|
||||
CHECK_META("show stables", 4);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, "name");
|
||||
|
@ -114,7 +114,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
|||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_INT, 4, "columns");
|
||||
CHECK_SCHEMA(3, TSDB_DATA_TYPE_INT, 4, "tags");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
CheckBinary("stb", TSDB_TABLE_NAME_LEN);
|
||||
CheckTimestamp();
|
||||
|
@ -128,7 +128,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
|||
STableInfoMsg* pReq = (STableInfoMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->tableFname, "1.d1.stb");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_STB_META, pReq, contLen);
|
||||
SRpcMsg* pMsg = test.SendReq(TDMT_MND_STB_META, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
|
@ -203,9 +203,9 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
|||
// restart
|
||||
test.Restart();
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, "1.d1");
|
||||
CHECK_META("show stables", 4);
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckBinary("stb", TSDB_TABLE_NAME_LEN);
|
||||
|
@ -219,13 +219,13 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
|||
SDropStbMsg* pReq = (SDropStbMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->name, "1.d1.stb");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_STB, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_STB, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1");
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_STB, "1.d1");
|
||||
CHECK_META("show stables", 4);
|
||||
test.SendShowRetrieveMsg();
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class TestClient {
|
|||
bool Init(const char* user, const char* pass, const char* fqdn, uint16_t port);
|
||||
void Cleanup();
|
||||
|
||||
SRpcMsg* SendMsg(SRpcMsg* pMsg);
|
||||
SRpcMsg* SendReq(SRpcMsg* pReq);
|
||||
void SetRpcRsp(SRpcMsg* pRsp);
|
||||
tsem_t* GetSem();
|
||||
|
||||
|
|
|
@ -21,10 +21,10 @@ class TestServer {
|
|||
bool Start(const char* path, const char* fqdn, uint16_t port, const char* firstEp);
|
||||
void Stop();
|
||||
void Restart();
|
||||
bool DoStart();
|
||||
|
||||
private:
|
||||
SDnodeOpt BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp);
|
||||
bool DoStart();
|
||||
|
||||
private:
|
||||
SDnode* pDnode;
|
||||
|
|
|
@ -37,7 +37,9 @@ class Testbase {
|
|||
void Init(const char* path, int16_t port);
|
||||
void Cleanup();
|
||||
void Restart();
|
||||
SRpcMsg* SendMsg(tmsg_t msgType, void* pCont, int32_t contLen);
|
||||
void ServerStop();
|
||||
void ServerStart();
|
||||
SRpcMsg* SendReq(tmsg_t msgType, void* pCont, int32_t contLen);
|
||||
|
||||
private:
|
||||
void InitLog(const char* path);
|
||||
|
@ -48,8 +50,8 @@ class Testbase {
|
|||
int32_t connId;
|
||||
|
||||
public:
|
||||
void SendShowMetaMsg(int8_t showType, const char* db);
|
||||
void SendShowRetrieveMsg();
|
||||
void SendShowMetaReq(int8_t showType, const char* db);
|
||||
void SendShowRetrieveReq();
|
||||
|
||||
STableMetaMsg* GetShowMeta();
|
||||
SRetrieveTableRsp* GetRetrieveRsp();
|
||||
|
@ -71,7 +73,7 @@ class Testbase {
|
|||
const char* GetShowBinary(int32_t len);
|
||||
|
||||
private:
|
||||
int32_t showId;
|
||||
int64_t showId;
|
||||
STableMetaMsg* pMeta;
|
||||
SRetrieveTableRsp* pRetrieveRsp;
|
||||
char* pData;
|
|
@ -13,12 +13,12 @@
|
|||
* 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;
|
||||
client->SetRpcRsp(pMsg);
|
||||
uInfo("response:%s from dnode, code:0x%x", TMSG_INFO(pMsg->msgType), pMsg->code);
|
||||
client->SetRpcRsp(pRsp);
|
||||
uInfo("response:%s from dnode, code:0x%x", TMSG_INFO(pRsp->msgType), pRsp->code);
|
||||
tsem_post(client->GetSem());
|
||||
}
|
||||
|
||||
|
@ -59,14 +59,14 @@ void TestClient::Cleanup() {
|
|||
rpcClose(clientRpc);
|
||||
}
|
||||
|
||||
SRpcMsg* TestClient::SendMsg(SRpcMsg* pMsg) {
|
||||
SRpcMsg* TestClient::SendReq(SRpcMsg* pReq) {
|
||||
SEpSet epSet = {0};
|
||||
epSet.inUse = 0;
|
||||
epSet.numOfEps = 1;
|
||||
epSet.port[0] = port;
|
||||
memcpy(epSet.fqdn[0], fqdn, TSDB_FQDN_LEN);
|
||||
|
||||
rpcSendRequest(clientRpc, &epSet, pMsg, NULL);
|
||||
rpcSendRequest(clientRpc, &epSet, pReq, NULL);
|
||||
tsem_wait(&sem);
|
||||
|
||||
return pRsp;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
#include "sut.h"
|
||||
|
||||
void* serverLoop(void* param) {
|
||||
while (1) {
|
||||
|
|
|
@ -13,16 +13,16 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
#include "sut.h"
|
||||
|
||||
void Testbase::InitLog(const char* path) {
|
||||
dDebugFlag = 207;
|
||||
dDebugFlag = 0;
|
||||
vDebugFlag = 0;
|
||||
mDebugFlag = 207;
|
||||
mDebugFlag = 143;
|
||||
cDebugFlag = 0;
|
||||
jniDebugFlag = 0;
|
||||
tmrDebugFlag = 0;
|
||||
uDebugFlag = 143;
|
||||
uDebugFlag = 0;
|
||||
rpcDebugFlag = 0;
|
||||
qDebugFlag = 0;
|
||||
wDebugFlag = 0;
|
||||
|
@ -60,26 +60,30 @@ void Testbase::Cleanup() {
|
|||
|
||||
void Testbase::Restart() { server.Restart(); }
|
||||
|
||||
SRpcMsg* Testbase::SendMsg(tmsg_t msgType, void* pCont, int32_t contLen) {
|
||||
void Testbase::ServerStop() { server.Stop(); }
|
||||
|
||||
void Testbase::ServerStart() { server.DoStart(); }
|
||||
|
||||
SRpcMsg* Testbase::SendReq(tmsg_t msgType, void* pCont, int32_t contLen) {
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pCont;
|
||||
rpcMsg.contLen = contLen;
|
||||
rpcMsg.msgType = msgType;
|
||||
|
||||
return client.SendMsg(&rpcMsg);
|
||||
return client.SendReq(&rpcMsg);
|
||||
}
|
||||
|
||||
void Testbase::SendShowMetaMsg(int8_t showType, const char* db) {
|
||||
int32_t contLen = sizeof(SShowMsg);
|
||||
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(contLen);
|
||||
void Testbase::SendShowMetaReq(int8_t showType, const char* db) {
|
||||
int32_t contLen = sizeof(SShowReq);
|
||||
SShowReq* pShow = (SShowReq*)rpcMallocCont(contLen);
|
||||
pShow->type = showType;
|
||||
strcpy(pShow->db, db);
|
||||
|
||||
SRpcMsg* pMsg = SendMsg(TDMT_MND_SHOW, pShow, contLen);
|
||||
SShowRsp* pShowRsp = (SShowRsp*)pMsg->pCont;
|
||||
SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW, pShow, contLen);
|
||||
SShowRsp* pShowRsp = (SShowRsp*)pRsp->pCont;
|
||||
|
||||
ASSERT(pShowRsp != nullptr);
|
||||
pShowRsp->showId = htonl(pShowRsp->showId);
|
||||
pShowRsp->showId = htobe64(pShowRsp->showId);
|
||||
pMeta = &pShowRsp->tableMeta;
|
||||
pMeta->numOfTags = htonl(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htonl(pMeta->numOfColumns);
|
||||
|
@ -117,15 +121,15 @@ int32_t Testbase::GetMetaNum() { return pMeta->numOfColumns; }
|
|||
|
||||
const char* Testbase::GetMetaTbName() { return pMeta->tbFname; }
|
||||
|
||||
void Testbase::SendShowRetrieveMsg() {
|
||||
int32_t contLen = sizeof(SRetrieveTableMsg);
|
||||
void Testbase::SendShowRetrieveReq() {
|
||||
int32_t contLen = sizeof(SRetrieveTableReq);
|
||||
|
||||
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(contLen);
|
||||
pRetrieve->showId = htonl(showId);
|
||||
SRetrieveTableReq* pRetrieve = (SRetrieveTableReq*)rpcMallocCont(contLen);
|
||||
pRetrieve->showId = htobe64(showId);
|
||||
pRetrieve->free = 0;
|
||||
|
||||
SRpcMsg* pMsg = SendMsg(TDMT_MND_SHOW_RETRIEVE, pRetrieve, contLen);
|
||||
pRetrieveRsp = (SRetrieveTableRsp*)pMsg->pCont;
|
||||
SRpcMsg* pRsp = SendReq(TDMT_MND_SHOW_RETRIEVE, pRetrieve, contLen);
|
||||
pRetrieveRsp = (SRetrieveTableRsp*)pRsp->pCont;
|
||||
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
||||
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
|
||||
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
|
|
@ -1,11 +0,0 @@
|
|||
aux_source_directory(. USER_SRC)
|
||||
add_executable(dnode_test_user ${USER_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_user
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dnode_test_user
|
||||
COMMAND dnode_test_user
|
||||
)
|
|
@ -1,164 +0,0 @@
|
|||
/**
|
||||
* @file user.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief DNODE module user-msg tests
|
||||
* @version 0.1
|
||||
* @date 2021-12-15
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
|
||||
class DndTestUser : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_user", 9140); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase DndTestUser::test;
|
||||
|
||||
TEST_F(DndTestUser, 01_ShowUser) {
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, "");
|
||||
CHECK_META("show users", 4);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "name");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "privilege");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
CHECK_SCHEMA(3, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "account");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("super", 10);
|
||||
CheckTimestamp();
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
}
|
||||
|
||||
TEST_F(DndTestUser, 02_Create_Drop_Alter_User) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateUserMsg);
|
||||
|
||||
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "u1");
|
||||
strcpy(pReq->pass, "p1");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateUserMsg);
|
||||
|
||||
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "u2");
|
||||
strcpy(pReq->pass, "p2");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, "");
|
||||
CHECK_META("show users", 4);
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 3);
|
||||
|
||||
CheckBinary("u1", TSDB_USER_LEN);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("u2", TSDB_USER_LEN);
|
||||
CheckBinary("normal", 10);
|
||||
CheckBinary("super", 10);
|
||||
CheckBinary("normal", 10);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SAlterUserMsg);
|
||||
|
||||
SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "u1");
|
||||
strcpy(pReq->pass, "p2");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, "");
|
||||
CHECK_META("show users", 4);
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 3);
|
||||
|
||||
CheckBinary("u1", TSDB_USER_LEN);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("u2", TSDB_USER_LEN);
|
||||
CheckBinary("normal", 10);
|
||||
CheckBinary("super", 10);
|
||||
CheckBinary("normal", 10);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDropUserMsg);
|
||||
|
||||
SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "u1");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, "");
|
||||
CHECK_META("show users", 4);
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("u2", TSDB_USER_LEN);
|
||||
CheckBinary("super", 10);
|
||||
CheckBinary("normal", 10);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
|
||||
// restart
|
||||
test.Restart();
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, "");
|
||||
CHECK_META("show users", 4);
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("u2", TSDB_USER_LEN);
|
||||
CheckBinary("super", 10);
|
||||
CheckBinary("normal", 10);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
}
|
|
@ -9,7 +9,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
#include "sut.h"
|
||||
|
||||
class DndTestVgroup : public ::testing::Test {
|
||||
protected:
|
||||
|
@ -60,9 +60,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
|
|||
pReplica->port = htons(9150);
|
||||
}
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_DND_CREATE_VNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_VNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -100,9 +100,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
|
|||
pReplica->port = htons(9150);
|
||||
}
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_DND_ALTER_VNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_ALTER_VNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,9 +121,9 @@ TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
|
|||
rpcMsg.contLen = sizeof(SDropVnodeMsg);
|
||||
rpcMsg.msgType = TDMT_DND_DROP_VNODE;
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_DND_DROP_VNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_VNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,12 @@ target_include_directories(
|
|||
target_link_libraries(
|
||||
mnode
|
||||
PRIVATE sdb
|
||||
PRIVATE wal
|
||||
PRIVATE transport
|
||||
PRIVATE cjson
|
||||
PRIVATE sync
|
||||
)
|
||||
)
|
||||
|
||||
if(${BUILD_TEST})
|
||||
add_subdirectory(test)
|
||||
endif(${BUILD_TEST})
|
|
@ -65,10 +65,10 @@ typedef enum {
|
|||
TRN_STAGE_PREPARE = 0,
|
||||
TRN_STAGE_REDO_LOG = 1,
|
||||
TRN_STAGE_REDO_ACTION = 2,
|
||||
TRN_STAGE_UNDO_LOG = 3,
|
||||
TRN_STAGE_UNDO_ACTION = 4,
|
||||
TRN_STAGE_COMMIT_LOG = 5,
|
||||
TRN_STAGE_COMMIT = 6,
|
||||
TRN_STAGE_COMMIT_LOG = 3,
|
||||
TRN_STAGE_COMMIT = 4,
|
||||
TRN_STAGE_UNDO_ACTION = 5,
|
||||
TRN_STAGE_UNDO_LOG = 6,
|
||||
TRN_STAGE_ROLLBACK = 7,
|
||||
TRN_STAGE_FINISHED = 8
|
||||
} ETrnStage;
|
||||
|
@ -161,8 +161,14 @@ typedef struct {
|
|||
typedef struct {
|
||||
int32_t maxUsers;
|
||||
int32_t maxDbs;
|
||||
int32_t maxStbs;
|
||||
int32_t maxTbs;
|
||||
int32_t maxTimeSeries;
|
||||
int32_t maxStreams;
|
||||
int32_t maxFuncs;
|
||||
int32_t maxConsumers;
|
||||
int32_t maxConns;
|
||||
int32_t maxTopics;
|
||||
int64_t maxStorage; // In unit of GB
|
||||
int32_t accessState; // Configured only by command
|
||||
} SAcctCfg;
|
||||
|
|
|
@ -17,11 +17,13 @@
|
|||
#define _TD_MND_INT_H_
|
||||
|
||||
#include "mndDef.h"
|
||||
|
||||
#include "sdb.h"
|
||||
#include "tcache.h"
|
||||
#include "tep.h"
|
||||
#include "tqueue.h"
|
||||
#include "ttime.h"
|
||||
#include "wal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -65,6 +67,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
int32_t errCode;
|
||||
sem_t syncSem;
|
||||
SWal *pWal;
|
||||
SSyncNode *pSyncNode;
|
||||
ESyncState state;
|
||||
} SSyncMgmt;
|
||||
|
@ -88,15 +91,16 @@ typedef struct SMnode {
|
|||
STelemMgmt telemMgmt;
|
||||
SSyncMgmt syncMgmt;
|
||||
MndMsgFp msgFp[TDMT_MAX];
|
||||
SendMsgToDnodeFp sendMsgToDnodeFp;
|
||||
SendMsgToMnodeFp sendMsgToMnodeFp;
|
||||
SendRedirectMsgFp sendRedirectMsgFp;
|
||||
SendReqToDnodeFp sendReqToDnodeFp;
|
||||
SendReqToMnodeFp sendReqToMnodeFp;
|
||||
SendRedirectRspFp sendRedirectRspFp;
|
||||
PutReqToMWriteQFp putReqToMWriteQFp;
|
||||
} SMnode;
|
||||
|
||||
void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg);
|
||||
void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg);
|
||||
void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg);
|
||||
void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp);
|
||||
int32_t mndSendReqToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *rpcMsg);
|
||||
int32_t mndSendReqToMnode(SMnode *pMnode, SRpcMsg *pMsg);
|
||||
void mndSendRedirectRsp(SMnode *pMnode, SRpcMsg *pMsg);
|
||||
void mndSetMsgHandle(SMnode *pMnode, tmsg_t msgType, MndMsgFp fp);
|
||||
|
||||
uint64_t mndGenerateUid(char *name, int32_t len) ;
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ typedef struct {
|
|||
int8_t msgSent;
|
||||
int8_t msgReceived;
|
||||
int32_t errCode;
|
||||
int32_t acceptableCode;
|
||||
int32_t contLen;
|
||||
void *pCont;
|
||||
} STransAction;
|
||||
|
@ -45,6 +46,7 @@ int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction);
|
|||
|
||||
int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans);
|
||||
void mndTransProcessRsp(SMnodeMsg *pMsg);
|
||||
void mndTransPullup(SMnode *pMnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -18,17 +18,17 @@
|
|||
#include "mndShow.h"
|
||||
|
||||
#define TSDB_ACCT_VER_NUMBER 1
|
||||
#define TSDB_ACCT_RESERVE_SIZE 64
|
||||
#define TSDB_ACCT_RESERVE_SIZE 128
|
||||
|
||||
static int32_t mndCreateDefaultAcct(SMnode *pMnode);
|
||||
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct);
|
||||
static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct);
|
||||
static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct);
|
||||
static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct);
|
||||
static int32_t mndProcessCreateAcctMsg(SMnodeMsg *pMnodeMsg);
|
||||
static int32_t mndProcessAlterAcctMsg(SMnodeMsg *pMnodeMsg);
|
||||
static int32_t mndProcessDropAcctMsg(SMnodeMsg *pMnodeMsg);
|
||||
static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew);
|
||||
static int32_t mndProcessCreateAcctReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessAlterAcctReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessDropAcctReq(SMnodeMsg *pReq);
|
||||
|
||||
int32_t mndInitAcct(SMnode *pMnode) {
|
||||
SSdbTable table = {.sdbType = SDB_ACCT,
|
||||
|
@ -40,9 +40,9 @@ int32_t mndInitAcct(SMnode *pMnode) {
|
|||
.updateFp = (SdbUpdateFp)mndAcctActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndAcctActionDelete};
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_DROP_ACCT, mndProcessDropAcctMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_DROP_ACCT, mndProcessDropAcctReq);
|
||||
|
||||
return sdbSetTable(pMnode->pSdb, table);
|
||||
}
|
||||
|
@ -55,10 +55,16 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
|||
acctObj.createdTime = taosGetTimestampMs();
|
||||
acctObj.updateTime = acctObj.createdTime;
|
||||
acctObj.acctId = 1;
|
||||
acctObj.cfg = (SAcctCfg){.maxUsers = 1024,
|
||||
.maxDbs = 1024,
|
||||
acctObj.cfg = (SAcctCfg){.maxUsers = INT32_MAX,
|
||||
.maxDbs = INT32_MAX,
|
||||
.maxStbs = INT32_MAX,
|
||||
.maxTbs = INT32_MAX,
|
||||
.maxTimeSeries = INT32_MAX,
|
||||
.maxStreams = 8092,
|
||||
.maxStreams = INT32_MAX,
|
||||
.maxFuncs = INT32_MAX,
|
||||
.maxConsumers = INT32_MAX,
|
||||
.maxConns = INT32_MAX,
|
||||
.maxTopics = INT32_MAX,
|
||||
.maxStorage = INT64_MAX,
|
||||
.accessState = TSDB_VN_ALL_ACCCESS};
|
||||
|
||||
|
@ -66,96 +72,133 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
|||
if (pRaw == NULL) return -1;
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
mDebug("acct:%s, will be created while deploy sdb", acctObj.acct);
|
||||
mDebug("acct:%s, will be created while deploy sdb, raw:%p", acctObj.acct, pRaw);
|
||||
return sdbWrite(pMnode->pSdb, pRaw);
|
||||
}
|
||||
|
||||
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, TSDB_ACCT_VER_NUMBER, sizeof(SAcctObj) + TSDB_ACCT_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
if (pRaw == NULL) goto ACCT_ENCODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN)
|
||||
SDB_SET_INT64(pRaw, dataPos, pAcct->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pAcct->updateTime)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->acctId)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->status)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxUsers)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxDbs)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTimeSeries)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStreams)
|
||||
SDB_SET_INT64(pRaw, dataPos, pAcct->cfg.maxStorage)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.accessState)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE)
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN, ACCT_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pAcct->createdTime, ACCT_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pAcct->updateTime, ACCT_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->acctId, ACCT_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->status, ACCT_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxUsers, ACCT_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxDbs, ACCT_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStbs, ACCT_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTbs, ACCT_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTimeSeries, ACCT_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxStreams, ACCT_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxFuncs, ACCT_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxConsumers, ACCT_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxConns, ACCT_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.maxTopics, ACCT_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pAcct->cfg.maxStorage, ACCT_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAcct->cfg.accessState, ACCT_ENCODE_OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, ACCT_ENCODE_OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, ACCT_ENCODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
ACCT_ENCODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("acct:%s, failed to encode to raw:%p since %s", pAcct->acct, pRaw, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("acct:%s, encode to raw:%p, row:%p", pAcct->acct, pRaw, pAcct);
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto ACCT_DECODE_OVER;
|
||||
|
||||
if (sver != TSDB_ACCT_VER_NUMBER) {
|
||||
mError("failed to decode acct since %s", terrstr());
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
goto ACCT_DECODE_OVER;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj));
|
||||
if (pRow == NULL) goto ACCT_DECODE_OVER;
|
||||
|
||||
SAcctObj *pAcct = sdbGetRowObj(pRow);
|
||||
if (pAcct == NULL) goto ACCT_DECODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_BINARY(pRaw, dataPos, pAcct->acct, TSDB_USER_LEN, ACCT_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pAcct->createdTime, ACCT_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pAcct->updateTime, ACCT_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pAcct->acctId, ACCT_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pAcct->status, ACCT_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxUsers, ACCT_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxDbs, ACCT_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStbs, ACCT_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTbs, ACCT_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTimeSeries, ACCT_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxStreams, ACCT_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxFuncs, ACCT_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxConsumers, ACCT_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxConns, ACCT_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.maxTopics, ACCT_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pAcct->cfg.maxStorage, ACCT_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pAcct->cfg.accessState, ACCT_DECODE_OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_ACCT_RESERVE_SIZE, ACCT_DECODE_OVER)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SAcctObj));
|
||||
SAcctObj *pAcct = sdbGetRowObj(pRow);
|
||||
if (pAcct == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pAcct->acct, TSDB_USER_LEN)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->updateTime)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->acctId)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->status)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxUsers)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxDbs)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxTimeSeries)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.maxStreams)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pAcct->cfg.maxStorage)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pAcct->cfg.accessState)
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_ACCT_RESERVE_SIZE)
|
||||
|
||||
mTrace("acct:%s, decode from raw:%p, row:%p", pAcct->acct, pRaw, pAcct);
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mndAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct) {
|
||||
mTrace("acct:%s, perform insert action", pAcct->acct);
|
||||
mTrace("acct:%s, perform insert action, row:%p", pAcct->acct, pAcct);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) {
|
||||
mTrace("acct:%s, perform delete action", pAcct->acct);
|
||||
mTrace("acct:%s, perform delete action, row:%p", pAcct->acct, pAcct);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct) {
|
||||
mTrace("acct:%s, perform update action", pOldAcct->acct);
|
||||
static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOld, SAcctObj *pNew) {
|
||||
mTrace("acct:%s, perform update action, old_row:%p new_row:%p", pOld->acct, pOld, pNew);
|
||||
|
||||
pOldAcct->updateTime = pNewAcct->updateTime;
|
||||
pOldAcct->status = pNewAcct->status;
|
||||
memcpy(&pOldAcct->cfg, &pNewAcct->cfg, sizeof(SAcctInfo));
|
||||
pOld->updateTime = pNew->updateTime;
|
||||
pOld->status = pNew->status;
|
||||
memcpy(&pOld->cfg, &pNew->cfg, sizeof(SAcctCfg));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateAcctMsg(SMnodeMsg *pMnodeMsg) {
|
||||
static int32_t mndProcessCreateAcctReq(SMnodeMsg *pReq) {
|
||||
terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
mError("failed to process create acct msg since %s", terrstr());
|
||||
mError("failed to process create acct request since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int32_t mndProcessAlterAcctMsg(SMnodeMsg *pMnodeMsg) {
|
||||
static int32_t mndProcessAlterAcctReq(SMnodeMsg *pReq) {
|
||||
terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
mError("failed to process create acct msg since %s", terrstr());
|
||||
mError("failed to process create acct request since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropAcctMsg(SMnodeMsg *pMnodeMsg) {
|
||||
static int32_t mndProcessDropAcctReq(SMnodeMsg *pReq) {
|
||||
terrno = TSDB_CODE_MND_MSG_NOT_PROCESSED;
|
||||
mError("failed to process create acct msg since %s", terrstr());
|
||||
mError("failed to process create acct request since %s", terrstr());
|
||||
return -1;
|
||||
}
|
|
@ -14,7 +14,6 @@
|
|||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "mndAuth.h"
|
||||
|
||||
int32_t mndInitAuth(SMnode *pMnode) { return 0; }
|
||||
|
|
|
@ -26,13 +26,13 @@ static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj);
|
|||
static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj);
|
||||
static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj);
|
||||
static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOldBnode, SBnodeObj *pNewBnode);
|
||||
static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pMsg);
|
||||
static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveBnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||
static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOld, SBnodeObj *pNew);
|
||||
static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessDropBnodeReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pRsp);
|
||||
static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pRsp);
|
||||
static int32_t mndGetBnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveBnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows);
|
||||
static void mndCancelGetNextBnode(SMnode *pMnode, void *pIter);
|
||||
|
||||
int32_t mndInitBnode(SMnode *pMnode) {
|
||||
|
@ -58,10 +58,9 @@ int32_t mndInitBnode(SMnode *pMnode) {
|
|||
|
||||
void mndCleanupBnode(SMnode *pMnode) {}
|
||||
|
||||
static SBnodeObj *mndAcquireBnode(SMnode *pMnode, int32_t snodeId) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SBnodeObj *pObj = sdbAcquire(pSdb, SDB_BNODE, &snodeId);
|
||||
if (pObj == NULL) {
|
||||
static SBnodeObj *mndAcquireBnode(SMnode *pMnode, int32_t bnodeId) {
|
||||
SBnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_BNODE, &bnodeId);
|
||||
if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
|
||||
terrno = TSDB_CODE_MND_BNODE_NOT_EXIST;
|
||||
}
|
||||
return pObj;
|
||||
|
@ -73,47 +72,72 @@ static void mndReleaseBnode(SMnode *pMnode, SBnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static SSdbRaw *mndBnodeActionEncode(SBnodeObj *pObj) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_BNODE, TSDB_BNODE_VER_NUMBER, sizeof(SBnodeObj) + TSDB_BNODE_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
if (pRaw == NULL) goto BNODE_ENCODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_INT32(pRaw, dataPos, pObj->id);
|
||||
SDB_SET_INT64(pRaw, dataPos, pObj->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pObj->updateTime)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_BNODE_RESERVE_SIZE)
|
||||
SDB_SET_INT32(pRaw, dataPos, pObj->id, BNODE_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pObj->createdTime, BNODE_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pObj->updateTime, BNODE_ENCODE_OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_BNODE_RESERVE_SIZE, BNODE_ENCODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
BNODE_ENCODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("bnode:%d, failed to encode to raw:%p since %s", pObj->id, pRaw, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("bnode:%d, encode to raw:%p, row:%p", pObj->id, pRaw, pObj);
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mndBnodeActionDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto BNODE_DECODE_OVER;
|
||||
|
||||
if (sver != TSDB_BNODE_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
mError("failed to decode snode since %s", terrstr());
|
||||
goto BNODE_DECODE_OVER;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SBnodeObj));
|
||||
if (pRow == NULL) goto BNODE_DECODE_OVER;
|
||||
|
||||
SBnodeObj *pObj = sdbGetRowObj(pRow);
|
||||
if (pObj == NULL) goto BNODE_DECODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &pObj->id, BNODE_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pObj->createdTime, BNODE_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pObj->updateTime, BNODE_DECODE_OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_BNODE_RESERVE_SIZE, BNODE_DECODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
BNODE_DECODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("bnode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr());
|
||||
tfree(pRow);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SBnodeObj));
|
||||
SBnodeObj *pObj = sdbGetRowObj(pRow);
|
||||
if (pObj == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime)
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_BNODE_RESERVE_SIZE)
|
||||
|
||||
mTrace("bnode:%d, decode from raw:%p, row:%p", pObj->id, pRaw, pObj);
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj) {
|
||||
mTrace("snode:%d, perform insert action", pObj->id);
|
||||
mTrace("bnode:%d, perform insert action, row:%p", pObj->id, pObj);
|
||||
pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id);
|
||||
if (pObj->pDnode == NULL) {
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
mError("snode:%d, failed to perform insert action since %s", pObj->id, terrstr());
|
||||
mError("bnode:%d, failed to perform insert action since %s", pObj->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -121,7 +145,7 @@ static int32_t mndBnodeActionInsert(SSdb *pSdb, SBnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj) {
|
||||
mTrace("snode:%d, perform delete action", pObj->id);
|
||||
mTrace("bnode:%d, perform delete action, row:%p", pObj->id, pObj);
|
||||
if (pObj->pDnode != NULL) {
|
||||
sdbRelease(pSdb, pObj->pDnode);
|
||||
pObj->pDnode = NULL;
|
||||
|
@ -130,9 +154,9 @@ static int32_t mndBnodeActionDelete(SSdb *pSdb, SBnodeObj *pObj) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOldBnode, SBnodeObj *pNewBnode) {
|
||||
mTrace("snode:%d, perform update action", pOldBnode->id);
|
||||
pOldBnode->updateTime = pNewBnode->updateTime;
|
||||
static int32_t mndBnodeActionUpdate(SSdb *pSdb, SBnodeObj *pOld, SBnodeObj *pNew) {
|
||||
mTrace("bnode:%d, perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew);
|
||||
pOld->updateTime = pNew->updateTime;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -144,6 +168,14 @@ static int32_t mndSetCreateBnodeRedoLogs(STrans *pTrans, SBnodeObj *pObj) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateBnodeUndoLogs(STrans *pTrans, SBnodeObj *pObj) {
|
||||
SSdbRaw *pUndoRaw = mndBnodeActionEncode(pObj);
|
||||
if (pUndoRaw == NULL) return -1;
|
||||
if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) {
|
||||
SSdbRaw *pCommitRaw = mndBnodeActionEncode(pObj);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
|
@ -153,60 +185,69 @@ static int32_t mndSetCreateBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static int32_t mndSetCreateBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) {
|
||||
SDCreateBnodeMsg *pMsg = malloc(sizeof(SDCreateBnodeMsg));
|
||||
if (pMsg == NULL) {
|
||||
SDCreateBnodeReq *pReq = malloc(sizeof(SDCreateBnodeReq));
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pMsg->dnodeId = htonl(pDnode->id);
|
||||
pReq->dnodeId = htonl(pDnode->id);
|
||||
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SDCreateBnodeMsg);
|
||||
action.pCont = pReq;
|
||||
action.contLen = sizeof(SDCreateBnodeReq);
|
||||
action.msgType = TDMT_DND_CREATE_BNODE;
|
||||
action.acceptableCode = TSDB_CODE_DND_BNODE_ALREADY_DEPLOYED;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
free(pReq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateBnodeMsg *pCreate) {
|
||||
SBnodeObj snodeObj = {0};
|
||||
snodeObj.id = pDnode->id;
|
||||
snodeObj.createdTime = taosGetTimestampMs();
|
||||
snodeObj.updateTime = snodeObj.createdTime;
|
||||
static int32_t mndSetCreateBnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) {
|
||||
SDDropBnodeReq *pReq = malloc(sizeof(SDDropBnodeReq));
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pReq->dnodeId = htonl(pDnode->id);
|
||||
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
action.pCont = pReq;
|
||||
action.contLen = sizeof(SDDropBnodeReq);
|
||||
action.msgType = TDMT_DND_DROP_BNODE;
|
||||
action.acceptableCode = TSDB_CODE_DND_BNODE_NOT_DEPLOYED;
|
||||
|
||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||
free(pReq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCreateBnode(SMnode *pMnode, SMnodeMsg *pReq, SDnodeObj *pDnode, SMCreateBnodeReq *pCreate) {
|
||||
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);
|
||||
|
||||
if (mndSetCreateBnodeRedoLogs(pTrans, &snodeObj) != 0) {
|
||||
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_BNODE_OVER;
|
||||
}
|
||||
SBnodeObj bnodeObj = {0};
|
||||
bnodeObj.id = pDnode->id;
|
||||
bnodeObj.createdTime = taosGetTimestampMs();
|
||||
bnodeObj.updateTime = bnodeObj.createdTime;
|
||||
|
||||
if (mndSetCreateBnodeCommitLogs(pTrans, &snodeObj) != 0) {
|
||||
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_BNODE_OVER;
|
||||
}
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) goto CREATE_BNODE_OVER;
|
||||
|
||||
if (mndSetCreateBnodeRedoActions(pTrans, pDnode, &snodeObj) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto CREATE_BNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
goto CREATE_BNODE_OVER;
|
||||
}
|
||||
mDebug("trans:%d, used to create bnode:%d", pTrans->id, pCreate->dnodeId);
|
||||
if (mndSetCreateBnodeRedoLogs(pTrans, &bnodeObj) != 0) goto CREATE_BNODE_OVER;
|
||||
if (mndSetCreateBnodeUndoLogs(pTrans, &bnodeObj) != 0) goto CREATE_BNODE_OVER;
|
||||
if (mndSetCreateBnodeCommitLogs(pTrans, &bnodeObj) != 0) goto CREATE_BNODE_OVER;
|
||||
if (mndSetCreateBnodeRedoActions(pTrans, pDnode, &bnodeObj) != 0) goto CREATE_BNODE_OVER;
|
||||
if (mndSetCreateBnodeUndoActions(pTrans, pDnode, &bnodeObj) != 0) goto CREATE_BNODE_OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto CREATE_BNODE_OVER;
|
||||
|
||||
code = 0;
|
||||
|
||||
|
@ -215,33 +256,37 @@ CREATE_BNODE_OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SMCreateBnodeMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndProcessCreateBnodeReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SMCreateBnodeReq *pCreate = pReq->rpcMsg.pCont;
|
||||
|
||||
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
||||
|
||||
mDebug("snode:%d, start to create", pCreate->dnodeId);
|
||||
mDebug("bnode:%d, start to create", pCreate->dnodeId);
|
||||
|
||||
SBnodeObj *pObj = mndAcquireBnode(pMnode, pCreate->dnodeId);
|
||||
if (pObj != NULL) {
|
||||
mError("snode:%d, snode already exist", pObj->id);
|
||||
mError("bnode:%d, bnode already exist", pObj->id);
|
||||
terrno = TSDB_CODE_MND_BNODE_ALREADY_EXIST;
|
||||
mndReleaseBnode(pMnode, pObj);
|
||||
return -1;
|
||||
} else if (terrno != TSDB_CODE_MND_BNODE_NOT_EXIST) {
|
||||
mError("bnode:%d, failed to create bnode since %s", pCreate->dnodeId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId);
|
||||
if (pDnode == NULL) {
|
||||
mError("snode:%d, dnode not exist", pCreate->dnodeId);
|
||||
mError("bnode:%d, dnode not exist", pCreate->dnodeId);
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mndCreateBnode(pMnode, pMsg, pDnode, pCreate);
|
||||
int32_t code = mndCreateBnode(pMnode, pReq, pDnode, pCreate);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
if (code != 0) {
|
||||
mError("snode:%d, failed to create since %s", pCreate->dnodeId, terrstr());
|
||||
mError("bnode:%d, failed to create since %s", pCreate->dnodeId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -265,56 +310,39 @@ static int32_t mndSetDropBnodeCommitLogs(STrans *pTrans, SBnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static int32_t mndSetDropBnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SBnodeObj *pObj) {
|
||||
SDDropBnodeMsg *pMsg = malloc(sizeof(SDDropBnodeMsg));
|
||||
if (pMsg == NULL) {
|
||||
SDDropBnodeReq *pReq = malloc(sizeof(SDDropBnodeReq));
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pMsg->dnodeId = htonl(pDnode->id);
|
||||
pReq->dnodeId = htonl(pDnode->id);
|
||||
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SDDropBnodeMsg);
|
||||
action.pCont = pReq;
|
||||
action.contLen = sizeof(SDDropBnodeReq);
|
||||
action.msgType = TDMT_DND_DROP_BNODE;
|
||||
action.acceptableCode = TSDB_CODE_DND_BNODE_NOT_DEPLOYED;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
free(pReq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndDropBnode(SMnode *pMnode, SMnodeMsg *pMsg, SBnodeObj *pObj) {
|
||||
static int32_t mndDropBnode(SMnode *pMnode, SMnodeMsg *pReq, SBnodeObj *pObj) {
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("snode:%d, failed to drop since %s", pObj->id, terrstr());
|
||||
goto DROP_BNODE_OVER;
|
||||
}
|
||||
|
||||
mDebug("trans:%d, used to drop snode:%d", pTrans->id, pObj->id);
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) goto DROP_BNODE_OVER;
|
||||
|
||||
if (mndSetDropBnodeRedoLogs(pTrans, pObj) != 0) {
|
||||
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||
goto DROP_BNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndSetDropBnodeCommitLogs(pTrans, pObj) != 0) {
|
||||
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||
goto DROP_BNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndSetDropBnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto DROP_BNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
goto DROP_BNODE_OVER;
|
||||
}
|
||||
mDebug("trans:%d, used to drop bnode:%d", pTrans->id, pObj->id);
|
||||
if (mndSetDropBnodeRedoLogs(pTrans, pObj) != 0) goto DROP_BNODE_OVER;
|
||||
if (mndSetDropBnodeCommitLogs(pTrans, pObj) != 0) goto DROP_BNODE_OVER;
|
||||
if (mndSetDropBnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) goto DROP_BNODE_OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto DROP_BNODE_OVER;
|
||||
|
||||
code = 0;
|
||||
|
||||
|
@ -323,48 +351,48 @@ DROP_BNODE_OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropBnodeReq(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SMDropBnodeMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndProcessDropBnodeReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SMDropBnodeReq *pDrop = pReq->rpcMsg.pCont;
|
||||
pDrop->dnodeId = htonl(pDrop->dnodeId);
|
||||
|
||||
mDebug("snode:%d, start to drop", pDrop->dnodeId);
|
||||
mDebug("bnode:%d, start to drop", pDrop->dnodeId);
|
||||
|
||||
if (pDrop->dnodeId <= 0) {
|
||||
terrno = TSDB_CODE_SDB_APP_ERROR;
|
||||
mError("snode:%d, failed to drop since %s", pDrop->dnodeId, terrstr());
|
||||
mError("bnode:%d, failed to drop since %s", pDrop->dnodeId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SBnodeObj *pObj = mndAcquireBnode(pMnode, pDrop->dnodeId);
|
||||
if (pObj == NULL) {
|
||||
mError("snode:%d, not exist", pDrop->dnodeId);
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
mError("bnode:%d, failed to drop since %s", pDrop->dnodeId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mndDropBnode(pMnode, pMsg, pObj);
|
||||
int32_t code = mndDropBnode(pMnode, pReq, pObj);
|
||||
if (code != 0) {
|
||||
mError("snode:%d, failed to drop since %s", pMnode->dnodeId, terrstr());
|
||||
sdbRelease(pMnode->pSdb, pObj);
|
||||
mError("bnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
sdbRelease(pMnode->pSdb, pMnode);
|
||||
sdbRelease(pMnode->pSdb, pObj);
|
||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pMsg) {
|
||||
mndTransProcessRsp(pMsg);
|
||||
static int32_t mndProcessCreateBnodeRsp(SMnodeMsg *pRsp) {
|
||||
mndTransProcessRsp(pRsp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pMsg) {
|
||||
mndTransProcessRsp(pMsg);
|
||||
static int32_t mndProcessDropBnodeRsp(SMnodeMsg *pRsp) {
|
||||
mndTransProcessRsp(pRsp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndGetBnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
int32_t cols = 0;
|
||||
|
@ -403,8 +431,8 @@ static int32_t mndGetBnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveBnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndRetrieveBnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfRows = 0;
|
||||
int32_t cols = 0;
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "mndCluster.h"
|
||||
#include "mndShow.h"
|
||||
#include "mndTrans.h"
|
||||
|
||||
#define TSDB_CLUSTER_VER_NUMBE 1
|
||||
#define TSDB_CLUSTER_RESERVE_SIZE 64
|
||||
|
@ -33,7 +32,7 @@ static void mndCancelGetNextCluster(SMnode *pMnode, void *pIter);
|
|||
|
||||
int32_t mndInitCluster(SMnode *pMnode) {
|
||||
SSdbTable table = {.sdbType = SDB_CLUSTER,
|
||||
.keyType = SDB_KEY_INT32,
|
||||
.keyType = SDB_KEY_INT64,
|
||||
.deployFp = (SdbDeployFp)mndCreateDefaultCluster,
|
||||
.encodeFp = (SdbEncodeFp)mndClusterActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mndClusterActionDecode,
|
||||
|
@ -63,55 +62,80 @@ int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len) {
|
|||
}
|
||||
|
||||
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_CLUSTER, TSDB_CLUSTER_VER_NUMBE, sizeof(SClusterObj) + TSDB_CLUSTER_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
if (pRaw == NULL) goto CLUSTER_ENCODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_INT64(pRaw, dataPos, pCluster->id);
|
||||
SDB_SET_INT64(pRaw, dataPos, pCluster->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pCluster->updateTime)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_CLUSTER_RESERVE_SIZE)
|
||||
SDB_SET_INT64(pRaw, dataPos, pCluster->id, CLUSTER_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pCluster->createdTime, CLUSTER_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pCluster->updateTime, CLUSTER_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, CLUSTER_ENCODE_OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_CLUSTER_RESERVE_SIZE, CLUSTER_ENCODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
CLUSTER_ENCODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("cluster:%" PRId64 ", failed to encode to raw:%p since %s", pCluster->id, pRaw, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("cluster:%" PRId64 ", encode to raw:%p, row:%p", pCluster->id, pRaw, pCluster);
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto CLUSTER_DECODE_OVER;
|
||||
|
||||
if (sver != TSDB_CLUSTER_VER_NUMBE) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
mError("failed to decode cluster since %s", terrstr());
|
||||
goto CLUSTER_DECODE_OVER;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SClusterObj));
|
||||
if (pRow == NULL) goto CLUSTER_DECODE_OVER;
|
||||
|
||||
SClusterObj *pCluster = sdbGetRowObj(pRow);
|
||||
if (pCluster == NULL) goto CLUSTER_DECODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT64(pRaw, dataPos, &pCluster->id, CLUSTER_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pCluster->createdTime, CLUSTER_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pCluster->updateTime, CLUSTER_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN, CLUSTER_DECODE_OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_CLUSTER_RESERVE_SIZE, CLUSTER_DECODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
CLUSTER_DECODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("cluster:%" PRId64 ", failed to decode from raw:%p since %s", pCluster->id, pRaw, terrstr());
|
||||
tfree(pRow);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SClusterObj));
|
||||
SClusterObj *pCluster = sdbGetRowObj(pRow);
|
||||
if (pCluster == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->id)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pCluster->updateTime)
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pCluster->name, TSDB_CLUSTER_ID_LEN)
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_CLUSTER_RESERVE_SIZE)
|
||||
|
||||
mTrace("cluster:%" PRId64 ", decode from raw:%p, row:%p", pCluster->id, pRaw, pCluster);
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mndClusterActionInsert(SSdb *pSdb, SClusterObj *pCluster) {
|
||||
mTrace("cluster:%" PRId64 ", perform insert action", pCluster->id);
|
||||
mTrace("cluster:%" PRId64 ", perform insert action, row:%p", pCluster->id, pCluster);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndClusterActionDelete(SSdb *pSdb, SClusterObj *pCluster) {
|
||||
mTrace("cluster:%" PRId64 ", perform delete action", pCluster->id);
|
||||
mTrace("cluster:%" PRId64 ", perform delete action, row:%p", pCluster->id, pCluster);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOldCluster, SClusterObj *pNewCluster) {
|
||||
mTrace("cluster:%" PRId64 ", perform update action", pOldCluster->id);
|
||||
static int32_t mndClusterActionUpdate(SSdb *pSdb, SClusterObj *pOld, SClusterObj *pNew) {
|
||||
mTrace("cluster:%" PRId64 ", perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -120,22 +144,22 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
|
|||
clusterObj.createdTime = taosGetTimestampMs();
|
||||
clusterObj.updateTime = clusterObj.createdTime;
|
||||
|
||||
int32_t code = taosGetSystemUid(clusterObj.name, TSDB_CLUSTER_ID_LEN);
|
||||
int32_t code = taosGetSystemUUID(clusterObj.name, TSDB_CLUSTER_ID_LEN);
|
||||
if (code != 0) {
|
||||
strcpy(clusterObj.name, "tdengine2.0");
|
||||
mError("failed to get name from system, set to default val %s", clusterObj.name);
|
||||
} else {
|
||||
mDebug("cluster:%" PRId64 ", name is %s", clusterObj.id, clusterObj.name);
|
||||
}
|
||||
clusterObj.id = MurmurHash3_32(clusterObj.name, TSDB_CLUSTER_ID_LEN);
|
||||
|
||||
clusterObj.id = mndGenerateUid(clusterObj.name, TSDB_CLUSTER_ID_LEN);
|
||||
clusterObj.id = (clusterObj.id >= 0 ? clusterObj.id : -clusterObj.id);
|
||||
pMnode->clusterId = clusterObj.id;
|
||||
mDebug("cluster:%" PRId64 ", name is %s", clusterObj.id, clusterObj.name);
|
||||
|
||||
SSdbRaw *pRaw = mndClusterActionEncode(&clusterObj);
|
||||
if (pRaw == NULL) return -1;
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
mDebug("cluster:%" PRId64 ", will be created while deploy sdb", clusterObj.id);
|
||||
mDebug("cluster:%" PRId64 ", will be created while deploy sdb, raw:%p", clusterObj.id, pRaw);
|
||||
return sdbWrite(pMnode->pSdb, pRaw);
|
||||
}
|
||||
|
||||
|
|
|
@ -74,14 +74,14 @@ static void *mndBuildMqVGroupSetReq(SMnode *pMnode, char *topicName, int32_t vgI
|
|||
static SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer) {
|
||||
int32_t size = sizeof(SMqConsumerObj) + MND_CONSUMER_RESERVE_SIZE;
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_CONSUMER, MND_CONSUMER_VER_NUMBER, size);
|
||||
if (pRaw == NULL) return NULL;
|
||||
if (pRaw == NULL) goto CM_ENCODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
int32_t topicNum = taosArrayGetSize(pConsumer->topics);
|
||||
SDB_SET_INT64(pRaw, dataPos, pConsumer->consumerId);
|
||||
int32_t len = strlen(pConsumer->cgroup);
|
||||
SDB_SET_INT32(pRaw, dataPos, len);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pConsumer->cgroup, len);
|
||||
SDB_SET_INT32(pRaw, dataPos, len, CM_ENCODE_OVER);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pConsumer->cgroup, len, CM_ENCODE_OVER);
|
||||
SDB_SET_INT32(pRaw, dataPos, topicNum);
|
||||
for (int i = 0; i < topicNum; i++) {
|
||||
int32_t len;
|
||||
|
@ -105,30 +105,41 @@ static SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer) {
|
|||
SDB_SET_RESERVE(pRaw, dataPos, MND_CONSUMER_RESERVE_SIZE);
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
|
||||
CM_ENCODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("consumer:%s, failed to encode to raw:%p since %s", pConsumer->name, pRaw, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("consumer:%s, encode to raw:%p, row:%p", pConsumer->name, pRaw, pConsumer);
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto CONSUME_DECODE_OVER;
|
||||
|
||||
if (sver != MND_CONSUMER_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
mError("failed to decode consumer since %s", terrstr());
|
||||
return NULL;
|
||||
goto CONSUME_DECODE_OVER;
|
||||
}
|
||||
|
||||
int32_t size = sizeof(SMqConsumerObj);
|
||||
SSdbRow *pRow = sdbAllocRow(size);
|
||||
if (pRow == NULL) goto CONSUMER_DECODE_OVER;
|
||||
|
||||
SMqConsumerObj *pConsumer = sdbGetRowObj(pRow);
|
||||
if (pConsumer == NULL) return NULL;
|
||||
if (pConsumer == NULL) goto CONSUMER_DECODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pConsumer->consumerId);
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pConsumer->consumerId, CONSUME_DECODE_OVER);
|
||||
int32_t len, topicNum;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &len);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pConsumer->cgroup, len);
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &topicNum);
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &len, CONSUME_DECODE_OVER);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pConsumer->cgroup, len, CONSUME_DECODE_OVER);
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &topicNum, CONSUME_DECODE_OVER);
|
||||
for (int i = 0; i < topicNum; i++) {
|
||||
int32_t topicLen;
|
||||
SMqConsumerTopic *pConsumerTopic = malloc(sizeof(SMqConsumerTopic));
|
||||
|
@ -138,12 +149,19 @@ static SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw) {
|
|||
return NULL;
|
||||
}
|
||||
/*pConsumerTopic->vgroups = taosArrayInit(topicNum, sizeof(SMqConsumerTopic));*/
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &topicLen);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pConsumerTopic->name, topicLen);
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &topicLen, CONSUME_DECODE_OVER);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pConsumerTopic->name, topicLen, CONSUME_DECODE_OVER);
|
||||
int32_t vgSize;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &vgSize);
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &vgSize, CONSUME_DECODE_OVER);
|
||||
}
|
||||
|
||||
|
||||
CONSUME_DECODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("consumer:%s, failed to decode from raw:%p since %s", pConsumer->name, pRaw, terrstr());
|
||||
tfree(pRow);
|
||||
return NULL;
|
||||
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, MND_CONSUMER_RESERVE_SIZE);
|
||||
|
||||
return pRow;
|
||||
|
|
|
@ -65,100 +65,125 @@ int32_t mndInitDb(SMnode *pMnode) {
|
|||
void mndCleanupDb(SMnode *pMnode) {}
|
||||
|
||||
static SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_DB, TSDB_DB_VER_NUMBER, sizeof(SDbObj) + TSDB_DB_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
if (pRaw == NULL) goto DB_ENCODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_BINARY(pRaw, dataPos, pDb->name, TSDB_DB_FNAME_LEN)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pDb->acct, TSDB_USER_LEN)
|
||||
SDB_SET_INT64(pRaw, dataPos, pDb->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pDb->updateTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pDb->uid)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfgVersion)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->vgVersion)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->hashMethod)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfVgroups)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.cacheBlockSize)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.totalBlocks)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysPerFile)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep0)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep1)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep2)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.minRows)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.maxRows)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.commitTime)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.fsyncPeriod)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.walLevel)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.precision)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.compression)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.replications)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.quorum)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.update)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.cacheLastRow)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_DB_RESERVE_SIZE)
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pDb->name, TSDB_DB_FNAME_LEN, DB_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pDb->acct, TSDB_USER_LEN, DB_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pDb->createdTime, DB_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pDb->updateTime, DB_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pDb->uid, DB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfgVersion, DB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->vgVersion, DB_ENCODE_OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->hashMethod, DB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfVgroups, DB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.cacheBlockSize, DB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.totalBlocks, DB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysPerFile, DB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep0, DB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep1, DB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysToKeep2, DB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.minRows, DB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.maxRows, DB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.commitTime, DB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.fsyncPeriod, DB_ENCODE_OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.walLevel, DB_ENCODE_OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.precision, DB_ENCODE_OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.compression, DB_ENCODE_OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.replications, DB_ENCODE_OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.quorum, DB_ENCODE_OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.update, DB_ENCODE_OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.cacheLastRow, DB_ENCODE_OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_DB_RESERVE_SIZE, DB_ENCODE_OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, DB_ENCODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
DB_ENCODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("db:%s, failed to encode to raw:%p since %s", pDb->name, pRaw, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("db:%s, encode to raw:%p, row:%p", pDb->name, pRaw, pDb);
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto DB_DECODE_OVER;
|
||||
|
||||
if (sver != TSDB_DB_VER_NUMBER) {
|
||||
mError("failed to decode db since %s", terrstr());
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
return NULL;
|
||||
goto DB_DECODE_OVER;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SDbObj));
|
||||
SDbObj *pDb = sdbGetRowObj(pRow);
|
||||
if (pDb == NULL) return NULL;
|
||||
if (pRow == NULL) goto DB_DECODE_OVER;
|
||||
|
||||
SDbObj *pDb = sdbGetRowObj(pRow);
|
||||
if (pDb == NULL) goto DB_DECODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pDb->name, TSDB_DB_FNAME_LEN)
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pDb->acct, TSDB_USER_LEN)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->updateTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->uid)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfgVersion)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->vgVersion)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->hashMethod)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.numOfVgroups)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.cacheBlockSize)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.totalBlocks)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysPerFile)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysToKeep0)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysToKeep1)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysToKeep2)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.minRows)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.maxRows)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.commitTime)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.fsyncPeriod)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.walLevel)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.precision)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.compression)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.replications)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.quorum)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.update)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->cfg.cacheLastRow)
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_DB_RESERVE_SIZE)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pDb->name, TSDB_DB_FNAME_LEN, DB_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pDb->acct, TSDB_USER_LEN, DB_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pDb->createdTime, DB_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pDb->updateTime, DB_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pDb->uid, DB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfgVersion, DB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pDb->vgVersion, DB_DECODE_OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pDb->hashMethod, DB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.numOfVgroups, DB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.cacheBlockSize, DB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.totalBlocks, DB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysPerFile, DB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep0, DB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep1, DB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.daysToKeep2, DB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.minRows, DB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.maxRows, DB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.commitTime, DB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.fsyncPeriod, DB_DECODE_OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.walLevel, DB_DECODE_OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.precision, DB_DECODE_OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.compression, DB_DECODE_OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.replications, DB_DECODE_OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.quorum, DB_DECODE_OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.update, DB_DECODE_OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.cacheLastRow, DB_DECODE_OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_DB_RESERVE_SIZE, DB_DECODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
DB_DECODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("db:%s, failed to decode from raw:%p since %s", pDb->name, pRaw, terrstr());
|
||||
tfree(pRow);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("db:%s, decode from raw:%p, row:%p", pDb->name, pRaw, pDb);
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mndDbActionInsert(SSdb *pSdb, SDbObj *pDb) {
|
||||
mTrace("db:%s, perform insert action", pDb->name);
|
||||
mTrace("db:%s, perform insert action, row:%p", pDb->name, pDb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndDbActionDelete(SSdb *pSdb, SDbObj *pDb) {
|
||||
mTrace("db:%s, perform delete action", pDb->name);
|
||||
mTrace("db:%s, perform delete action, row:%p", pDb->name, pDb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOldDb, SDbObj *pNewDb) {
|
||||
mTrace("db:%s, perform update action", pOldDb->name);
|
||||
mTrace("db:%s, perform update action, old_row:%p new_row:%p", pOldDb->name, pOldDb, pNewDb);
|
||||
pOldDb->updateTime = pNewDb->updateTime;
|
||||
pOldDb->cfgVersion = pNewDb->cfgVersion;
|
||||
pOldDb->vgVersion = pNewDb->vgVersion;
|
||||
|
|
|
@ -100,65 +100,90 @@ static int32_t mndCreateDefaultDnode(SMnode *pMnode) {
|
|||
if (pRaw == NULL) return -1;
|
||||
if (sdbSetRawStatus(pRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
|
||||
mDebug("dnode:%d, will be created while deploy sdb", dnodeObj.id);
|
||||
mDebug("dnode:%d, will be created while deploy sdb, raw:%p", dnodeObj.id, pRaw);
|
||||
return sdbWrite(pMnode->pSdb, pRaw);
|
||||
}
|
||||
|
||||
static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_DNODE, TSDB_DNODE_VER_NUMBER, sizeof(SDnodeObj) + TSDB_DNODE_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
if (pRaw == NULL) goto DNODE_ENCODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_INT32(pRaw, dataPos, pDnode->id);
|
||||
SDB_SET_INT64(pRaw, dataPos, pDnode->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pDnode->updateTime)
|
||||
SDB_SET_INT16(pRaw, dataPos, pDnode->port)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE)
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
SDB_SET_INT32(pRaw, dataPos, pDnode->id, DNODE_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pDnode->createdTime, DNODE_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pDnode->updateTime, DNODE_ENCODE_OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pDnode->port, DNODE_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, DNODE_ENCODE_OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, DNODE_ENCODE_OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, DNODE_ENCODE_OVER);
|
||||
|
||||
terrno = 0;
|
||||
|
||||
DNODE_ENCODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("dnode:%d, failed to encode to raw:%p since %s", pDnode->id, pRaw, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("dnode:%d, encode to raw:%p, row:%p", pDnode->id, pRaw, pDnode);
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto DNODE_DECODE_OVER;
|
||||
|
||||
if (sver != TSDB_DNODE_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
mError("failed to decode dnode since %s", terrstr());
|
||||
goto DNODE_DECODE_OVER;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SDnodeObj));
|
||||
if (pRow == NULL) goto DNODE_DECODE_OVER;
|
||||
|
||||
SDnodeObj *pDnode = sdbGetRowObj(pRow);
|
||||
if (pDnode == NULL) goto DNODE_DECODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &pDnode->id, DNODE_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pDnode->createdTime, DNODE_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pDnode->updateTime, DNODE_DECODE_OVER)
|
||||
SDB_GET_INT16(pRaw, dataPos, &pDnode->port, DNODE_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pDnode->fqdn, TSDB_FQDN_LEN, DNODE_DECODE_OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_DNODE_RESERVE_SIZE, DNODE_DECODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
DNODE_DECODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("dnode:%d, failed to decode from raw:%p since %s", pDnode->id, pRaw, terrstr());
|
||||
tfree(pRow);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SDnodeObj));
|
||||
SDnodeObj *pDnode = sdbGetRowObj(pRow);
|
||||
if (pDnode == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pDnode->id)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pDnode->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pDnode->updateTime)
|
||||
SDB_GET_INT16(pRaw, pRow, dataPos, &pDnode->port)
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pDnode->fqdn, TSDB_FQDN_LEN)
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_DNODE_RESERVE_SIZE)
|
||||
|
||||
mTrace("dnode:%d, decode from raw:%p, row:%p", pDnode->id, pRaw, pDnode);
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mndDnodeActionInsert(SSdb *pSdb, SDnodeObj *pDnode) {
|
||||
mTrace("dnode:%d, perform insert action", pDnode->id);
|
||||
mTrace("dnode:%d, perform insert action, row:%p", pDnode->id, pDnode);
|
||||
pDnode->offlineReason = DND_REASON_STATUS_NOT_RECEIVED;
|
||||
snprintf(pDnode->ep, TSDB_EP_LEN, "%s:%u", pDnode->fqdn, pDnode->port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndDnodeActionDelete(SSdb *pSdb, SDnodeObj *pDnode) {
|
||||
mTrace("dnode:%d, perform delete action", pDnode->id);
|
||||
mTrace("dnode:%d, perform delete action, row:%p", pDnode->id, pDnode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndDnodeActionUpdate(SSdb *pSdb, SDnodeObj *pOldDnode, SDnodeObj *pNewDnode) {
|
||||
mTrace("dnode:%d, perform update action", pOldDnode->id);
|
||||
mTrace("dnode:%d, perform update action, old_row:%p new_row:%p", pOldDnode->id, pOldDnode, pNewDnode);
|
||||
pOldDnode->updateTime = pNewDnode->updateTime;
|
||||
return 0;
|
||||
}
|
||||
|
@ -329,7 +354,7 @@ static int32_t mndProcessStatusMsg(SMnodeMsg *pMsg) {
|
|||
}
|
||||
|
||||
if (pStatus->dnodeId == 0) {
|
||||
mDebug("dnode:%d %s, first access, set clusterId %" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId);
|
||||
mDebug("dnode:%d, %s first access, set clusterId %" PRId64, pDnode->id, pDnode->ep, pMnode->clusterId);
|
||||
} else {
|
||||
if (pStatus->clusterId != pMnode->clusterId) {
|
||||
if (pDnode != NULL) {
|
||||
|
@ -532,7 +557,7 @@ static int32_t mndProcessConfigDnodeMsg(SMnodeMsg *pMsg) {
|
|||
.ahandle = pMsg->rpcMsg.ahandle};
|
||||
|
||||
mInfo("dnode:%d, app:%p config:%s req send to dnode", pCfg->dnodeId, rpcMsg.ahandle, pCfg->config);
|
||||
mndSendMsgToDnode(pMnode, &epSet, &rpcMsg);
|
||||
mndSendReqToDnode(pMnode, &epSet, &rpcMsg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -58,76 +58,101 @@ int32_t mndInitFunc(SMnode *pMnode) {
|
|||
void mndCleanupFunc(SMnode *pMnode) {}
|
||||
|
||||
static SSdbRaw *mndFuncActionEncode(SFuncObj *pFunc) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int32_t size = pFunc->commentSize + pFunc->codeSize + sizeof(SFuncObj);
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_FUNC, SDB_FUNC_VER, size);
|
||||
if (pRaw == NULL) return NULL;
|
||||
if (pRaw == NULL) goto FUNC_ENCODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_BINARY(pRaw, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN)
|
||||
SDB_SET_INT64(pRaw, dataPos, pFunc->createdTime)
|
||||
SDB_SET_INT8(pRaw, dataPos, pFunc->funcType)
|
||||
SDB_SET_INT8(pRaw, dataPos, pFunc->scriptType)
|
||||
SDB_SET_INT8(pRaw, dataPos, pFunc->align)
|
||||
SDB_SET_INT8(pRaw, dataPos, pFunc->outputType)
|
||||
SDB_SET_INT32(pRaw, dataPos, pFunc->outputLen)
|
||||
SDB_SET_INT32(pRaw, dataPos, pFunc->bufSize)
|
||||
SDB_SET_INT64(pRaw, dataPos, pFunc->sigature)
|
||||
SDB_SET_INT32(pRaw, dataPos, pFunc->commentSize)
|
||||
SDB_SET_INT32(pRaw, dataPos, pFunc->codeSize)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pFunc->pCode, pFunc->codeSize)
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN, FUNC_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pFunc->createdTime, FUNC_ENCODE_OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pFunc->funcType, FUNC_ENCODE_OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pFunc->scriptType, FUNC_ENCODE_OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pFunc->align, FUNC_ENCODE_OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pFunc->outputType, FUNC_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pFunc->outputLen, FUNC_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pFunc->bufSize, FUNC_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pFunc->sigature, FUNC_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pFunc->commentSize, FUNC_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pFunc->codeSize, FUNC_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize, FUNC_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pFunc->pCode, pFunc->codeSize, FUNC_ENCODE_OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, FUNC_ENCODE_OVER);
|
||||
|
||||
terrno = 0;
|
||||
|
||||
FUNC_ENCODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("func:%s, failed to encode to raw:%p since %s", pFunc->name, pRaw, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("func:%s, encode to raw:%p, row:%p", pFunc->name, pRaw, pFunc);
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mndFuncActionDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto FUNC_DECODE_OVER;
|
||||
|
||||
if (sver != SDB_FUNC_VER) {
|
||||
mError("failed to decode func since %s", terrstr());
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
return NULL;
|
||||
goto FUNC_DECODE_OVER;
|
||||
}
|
||||
|
||||
int32_t size = sizeof(SFuncObj) + TSDB_FUNC_COMMENT_LEN + TSDB_FUNC_CODE_LEN;
|
||||
SSdbRow *pRow = sdbAllocRow(size);
|
||||
int32_t size = sizeof(SFuncObj) + TSDB_FUNC_COMMENT_LEN + TSDB_FUNC_CODE_LEN;
|
||||
SSdbRow *pRow = sdbAllocRow(size);
|
||||
if (pRow == NULL) goto FUNC_DECODE_OVER;
|
||||
|
||||
SFuncObj *pFunc = sdbGetRowObj(pRow);
|
||||
if (pFunc == NULL) return NULL;
|
||||
if (pFunc == NULL) goto FUNC_DECODE_OVER;
|
||||
char *tmp = (char *)pFunc + sizeof(SFuncObj);
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pFunc->createdTime)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pFunc->funcType)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pFunc->scriptType)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pFunc->align)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pFunc->outputType)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pFunc->outputLen)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pFunc->bufSize)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pFunc->sigature)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pFunc->commentSize)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pFunc->codeSize)
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pFunc->pData, pFunc->commentSize + pFunc->codeSize)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pFunc->name, TSDB_FUNC_NAME_LEN, FUNC_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pFunc->createdTime, FUNC_DECODE_OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pFunc->funcType, FUNC_DECODE_OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pFunc->scriptType, FUNC_DECODE_OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pFunc->align, FUNC_DECODE_OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pFunc->outputType, FUNC_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pFunc->outputLen, FUNC_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pFunc->bufSize, FUNC_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pFunc->sigature, FUNC_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pFunc->commentSize, FUNC_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pFunc->codeSize, FUNC_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pFunc->pData, pFunc->commentSize + pFunc->codeSize, FUNC_DECODE_OVER)
|
||||
pFunc->pComment = pFunc->pData;
|
||||
pFunc->pCode = (pFunc->pData + pFunc->commentSize);
|
||||
|
||||
terrno = 0;
|
||||
|
||||
FUNC_DECODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("func:%s, failed to decode from raw:%p since %s", pFunc->name, pRaw, terrstr());
|
||||
tfree(pRow);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("func:%s, decode from raw:%p, row:%p", pFunc->name, pRaw, pFunc);
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mndFuncActionInsert(SSdb *pSdb, SFuncObj *pFunc) {
|
||||
mTrace("func:%s, perform insert action", pFunc->name);
|
||||
mTrace("func:%s, perform insert action, row:%p", pFunc->name, pFunc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndFuncActionDelete(SSdb *pSdb, SFuncObj *pFunc) {
|
||||
mTrace("func:%s, perform delete action", pFunc->name);
|
||||
mTrace("func:%s, perform delete action, row:%p", pFunc->name, pFunc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndFuncActionUpdate(SSdb *pSdb, SFuncObj *pOldFunc, SFuncObj *pNewFunc) {
|
||||
mTrace("func:%s, perform update action", pOldFunc->name);
|
||||
mTrace("func:%s, perform update action, old_row:%p new_row:%p", pOldFunc->name, pOldFunc, pNewFunc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -117,50 +117,75 @@ static int32_t mndCreateDefaultMnode(SMnode *pMnode) {
|
|||
if (pRaw == NULL) return -1;
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
mDebug("mnode:%d, will be created while deploy sdb", mnodeObj.id);
|
||||
mDebug("mnode:%d, will be created while deploy sdb, raw:%p", mnodeObj.id, pRaw);
|
||||
return sdbWrite(pMnode->pSdb, pRaw);
|
||||
}
|
||||
|
||||
static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pObj) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_MNODE, TSDB_MNODE_VER_NUMBER, sizeof(SMnodeObj) + TSDB_MNODE_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
if (pRaw == NULL) goto MNODE_ENCODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_INT32(pRaw, dataPos, pObj->id);
|
||||
SDB_SET_INT64(pRaw, dataPos, pObj->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pObj->updateTime)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_MNODE_RESERVE_SIZE)
|
||||
SDB_SET_INT32(pRaw, dataPos, pObj->id, MNODE_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pObj->createdTime, MNODE_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pObj->updateTime, MNODE_ENCODE_OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_MNODE_RESERVE_SIZE, MNODE_ENCODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
MNODE_ENCODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("mnode:%d, failed to encode to raw:%p since %s", pObj->id, pRaw, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("mnode:%d, encode to raw:%p, row:%p", pObj->id, pRaw, pObj);
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
if (sver != TSDB_MNODE_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
mError("failed to decode mnode since %s", terrstr());
|
||||
goto MNODE_DECODE_OVER;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SMnodeObj));
|
||||
if (pRow == NULL) goto MNODE_DECODE_OVER;
|
||||
|
||||
SMnodeObj *pObj = sdbGetRowObj(pRow);
|
||||
if (pObj == NULL) goto MNODE_DECODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &pObj->id, MNODE_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pObj->createdTime, MNODE_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pObj->updateTime, MNODE_DECODE_OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_MNODE_RESERVE_SIZE, MNODE_DECODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
MNODE_DECODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("mnode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr());
|
||||
tfree(pRow);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SMnodeObj));
|
||||
SMnodeObj *pObj = sdbGetRowObj(pRow);
|
||||
if (pObj == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime)
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_MNODE_RESERVE_SIZE)
|
||||
|
||||
mTrace("mnode:%d, decode from raw:%p, row:%p", pObj->id, pRaw, pObj);
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static void mnodeResetMnode(SMnodeObj *pObj) { pObj->role = TAOS_SYNC_STATE_FOLLOWER; }
|
||||
|
||||
static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj) {
|
||||
mTrace("mnode:%d, perform insert action", pObj->id);
|
||||
mTrace("mnode:%d, perform insert action, row:%p", pObj->id, pObj);
|
||||
pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id);
|
||||
if (pObj->pDnode == NULL) {
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
|
@ -173,7 +198,7 @@ static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj) {
|
||||
mTrace("mnode:%d, perform delete action", pObj->id);
|
||||
mTrace("mnode:%d, perform delete action, row:%p", pObj->id, pObj);
|
||||
if (pObj->pDnode != NULL) {
|
||||
sdbRelease(pSdb, pObj->pDnode);
|
||||
pObj->pDnode = NULL;
|
||||
|
@ -183,7 +208,7 @@ static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOldMnode, SMnodeObj *pNewMnode) {
|
||||
mTrace("mnode:%d, perform update action", pOldMnode->id);
|
||||
mTrace("mnode:%d, perform update action, old_row:%p new_row:%p", pOldMnode->id, pOldMnode, pNewMnode);
|
||||
pOldMnode->updateTime = pNewMnode->updateTime;
|
||||
return 0;
|
||||
}
|
||||
|
@ -370,7 +395,7 @@ CREATE_MNODE_OVER:
|
|||
}
|
||||
|
||||
static int32_t mndProcessCreateMnodeReq(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SMCreateMnodeMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||
|
||||
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
||||
|
@ -537,7 +562,7 @@ DROP_MNODE_OVER:
|
|||
}
|
||||
|
||||
static int32_t mndProcessDropMnodeReq(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SMDropMnodeMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||
pDrop->dnodeId = htonl(pDrop->dnodeId);
|
||||
|
||||
|
|
|
@ -26,13 +26,13 @@ static SSdbRaw *mndQnodeActionEncode(SQnodeObj *pObj);
|
|||
static SSdbRow *mndQnodeActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj);
|
||||
static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj);
|
||||
static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOldQnode, SQnodeObj *pNewQnode);
|
||||
static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pMsg);
|
||||
static int32_t mndGetQnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveQnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||
static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOld, SQnodeObj *pNew);
|
||||
static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessDropQnodeReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pRsp);
|
||||
static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pRsp);
|
||||
static int32_t mndGetQnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveQnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows);
|
||||
static void mndCancelGetNextQnode(SMnode *pMnode, void *pIter);
|
||||
|
||||
int32_t mndInitQnode(SMnode *pMnode) {
|
||||
|
@ -59,9 +59,8 @@ int32_t mndInitQnode(SMnode *pMnode) {
|
|||
void mndCleanupQnode(SMnode *pMnode) {}
|
||||
|
||||
static SQnodeObj *mndAcquireQnode(SMnode *pMnode, int32_t qnodeId) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SQnodeObj *pObj = sdbAcquire(pSdb, SDB_QNODE, &qnodeId);
|
||||
if (pObj == NULL) {
|
||||
SQnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_QNODE, &qnodeId);
|
||||
if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
|
||||
terrno = TSDB_CODE_MND_QNODE_NOT_EXIST;
|
||||
}
|
||||
return pObj;
|
||||
|
@ -73,43 +72,68 @@ static void mndReleaseQnode(SMnode *pMnode, SQnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static SSdbRaw *mndQnodeActionEncode(SQnodeObj *pObj) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_QNODE, TSDB_QNODE_VER_NUMBER, sizeof(SQnodeObj) + TSDB_QNODE_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
if (pRaw == NULL) goto QNODE_ENCODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_INT32(pRaw, dataPos, pObj->id);
|
||||
SDB_SET_INT64(pRaw, dataPos, pObj->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pObj->updateTime)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_QNODE_RESERVE_SIZE)
|
||||
SDB_SET_INT32(pRaw, dataPos, pObj->id, QNODE_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pObj->createdTime, QNODE_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pObj->updateTime, QNODE_ENCODE_OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_QNODE_RESERVE_SIZE, QNODE_ENCODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
QNODE_ENCODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("qnode:%d, failed to encode to raw:%p since %s", pObj->id, pRaw, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("qnode:%d, encode to raw:%p, row:%p", pObj->id, pRaw, pObj);
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mndQnodeActionDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto QNODE_DECODE_OVER;
|
||||
|
||||
if (sver != TSDB_QNODE_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
mError("failed to decode qnode since %s", terrstr());
|
||||
goto QNODE_DECODE_OVER;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SQnodeObj));
|
||||
if (pRow == NULL) goto QNODE_DECODE_OVER;
|
||||
|
||||
SQnodeObj *pObj = sdbGetRowObj(pRow);
|
||||
if (pObj == NULL) goto QNODE_DECODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &pObj->id, QNODE_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pObj->createdTime, QNODE_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pObj->updateTime, QNODE_DECODE_OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_QNODE_RESERVE_SIZE, QNODE_DECODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
QNODE_DECODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("qnode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr());
|
||||
tfree(pRow);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SQnodeObj));
|
||||
SQnodeObj *pObj = sdbGetRowObj(pRow);
|
||||
if (pObj == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime)
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_QNODE_RESERVE_SIZE)
|
||||
|
||||
mTrace("qnode:%d, decode from raw:%p, row:%p", pObj->id, pRaw, pObj);
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj) {
|
||||
mTrace("qnode:%d, perform insert action", pObj->id);
|
||||
mTrace("qnode:%d, perform insert action, row:%p", pObj->id, pObj);
|
||||
pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id);
|
||||
if (pObj->pDnode == NULL) {
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
|
@ -121,7 +145,7 @@ static int32_t mndQnodeActionInsert(SSdb *pSdb, SQnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj) {
|
||||
mTrace("qnode:%d, perform delete action", pObj->id);
|
||||
mTrace("qnode:%d, perform delete action, row:%p", pObj->id, pObj);
|
||||
if (pObj->pDnode != NULL) {
|
||||
sdbRelease(pSdb, pObj->pDnode);
|
||||
pObj->pDnode = NULL;
|
||||
|
@ -130,9 +154,9 @@ static int32_t mndQnodeActionDelete(SSdb *pSdb, SQnodeObj *pObj) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOldQnode, SQnodeObj *pNewQnode) {
|
||||
mTrace("qnode:%d, perform update action", pOldQnode->id);
|
||||
pOldQnode->updateTime = pNewQnode->updateTime;
|
||||
static int32_t mndQnodeActionUpdate(SSdb *pSdb, SQnodeObj *pOld, SQnodeObj *pNew) {
|
||||
mTrace("qnode:%d, perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew);
|
||||
pOld->updateTime = pNew->updateTime;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -144,6 +168,14 @@ static int32_t mndSetCreateQnodeRedoLogs(STrans *pTrans, SQnodeObj *pObj) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateQnodeUndoLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||
SSdbRaw *pUndoRaw = mndQnodeActionEncode(pObj);
|
||||
if (pUndoRaw == NULL) return -1;
|
||||
if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||
SSdbRaw *pCommitRaw = mndQnodeActionEncode(pObj);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
|
@ -153,60 +185,69 @@ static int32_t mndSetCreateQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
|
||||
SDCreateQnodeMsg *pMsg = malloc(sizeof(SDCreateQnodeMsg));
|
||||
if (pMsg == NULL) {
|
||||
SDCreateQnodeReq *pReq = malloc(sizeof(SDCreateQnodeReq));
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pMsg->dnodeId = htonl(pDnode->id);
|
||||
pReq->dnodeId = htonl(pDnode->id);
|
||||
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SDCreateQnodeMsg);
|
||||
action.pCont = pReq;
|
||||
action.contLen = sizeof(SDCreateQnodeReq);
|
||||
action.msgType = TDMT_DND_CREATE_QNODE;
|
||||
action.acceptableCode = TSDB_CODE_DND_QNODE_ALREADY_DEPLOYED;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
free(pReq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCreateQnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateQnodeMsg *pCreate) {
|
||||
static int32_t mndSetCreateQnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
|
||||
SDDropQnodeReq *pReq = malloc(sizeof(SDDropQnodeReq));
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pReq->dnodeId = htonl(pDnode->id);
|
||||
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
action.pCont = pReq;
|
||||
action.contLen = sizeof(SDDropQnodeReq);
|
||||
action.msgType = TDMT_DND_DROP_QNODE;
|
||||
action.acceptableCode = TSDB_CODE_DND_QNODE_NOT_DEPLOYED;
|
||||
|
||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||
free(pReq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCreateQnode(SMnode *pMnode, SMnodeMsg *pReq, SDnodeObj *pDnode, SMCreateQnodeReq *pCreate) {
|
||||
int32_t code = -1;
|
||||
|
||||
SQnodeObj qnodeObj = {0};
|
||||
qnodeObj.id = pDnode->id;
|
||||
qnodeObj.createdTime = taosGetTimestampMs();
|
||||
qnodeObj.updateTime = qnodeObj.createdTime;
|
||||
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("qnode:%d, failed to create since %s", pCreate->dnodeId, terrstr());
|
||||
goto CREATE_QNODE_OVER;
|
||||
}
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) goto CREATE_QNODE_OVER;
|
||||
|
||||
mDebug("trans:%d, used to create qnode:%d", pTrans->id, pCreate->dnodeId);
|
||||
|
||||
if (mndSetCreateQnodeRedoLogs(pTrans, &qnodeObj) != 0) {
|
||||
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_QNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndSetCreateQnodeCommitLogs(pTrans, &qnodeObj) != 0) {
|
||||
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_QNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndSetCreateQnodeRedoActions(pTrans, pDnode, &qnodeObj) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto CREATE_QNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
goto CREATE_QNODE_OVER;
|
||||
}
|
||||
if (mndSetCreateQnodeRedoLogs(pTrans, &qnodeObj) != 0) goto CREATE_QNODE_OVER;
|
||||
if (mndSetCreateQnodeUndoLogs(pTrans, &qnodeObj) != 0) goto CREATE_QNODE_OVER;
|
||||
if (mndSetCreateQnodeCommitLogs(pTrans, &qnodeObj) != 0) goto CREATE_QNODE_OVER;
|
||||
if (mndSetCreateQnodeRedoActions(pTrans, pDnode, &qnodeObj) != 0) goto CREATE_QNODE_OVER;
|
||||
if (mndSetCreateQnodeUndoActions(pTrans, pDnode, &qnodeObj) != 0) goto CREATE_QNODE_OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto CREATE_QNODE_OVER;
|
||||
|
||||
code = 0;
|
||||
|
||||
|
@ -215,9 +256,9 @@ CREATE_QNODE_OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SMCreateQnodeMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SMCreateQnodeReq *pCreate = pReq->rpcMsg.pCont;
|
||||
|
||||
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
||||
|
||||
|
@ -226,8 +267,12 @@ static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg) {
|
|||
SQnodeObj *pObj = mndAcquireQnode(pMnode, pCreate->dnodeId);
|
||||
if (pObj != NULL) {
|
||||
mError("qnode:%d, qnode already exist", pObj->id);
|
||||
terrno = TSDB_CODE_MND_QNODE_ALREADY_EXIST;
|
||||
mndReleaseQnode(pMnode, pObj);
|
||||
return -1;
|
||||
} else if (terrno != TSDB_CODE_MND_QNODE_NOT_EXIST) {
|
||||
mError("qnode:%d, failed to create qnode since %s", pCreate->dnodeId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId);
|
||||
|
@ -237,7 +282,7 @@ static int32_t mndProcessCreateQnodeReq(SMnodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mndCreateQnode(pMnode, pMsg, pDnode, pCreate);
|
||||
int32_t code = mndCreateQnode(pMnode, pReq, pDnode, pCreate);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
if (code != 0) {
|
||||
|
@ -265,56 +310,39 @@ static int32_t mndSetDropQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
|
||||
SDDropQnodeMsg *pMsg = malloc(sizeof(SDDropQnodeMsg));
|
||||
if (pMsg == NULL) {
|
||||
SDDropQnodeReq *pReq = malloc(sizeof(SDDropQnodeReq));
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pMsg->dnodeId = htonl(pDnode->id);
|
||||
pReq->dnodeId = htonl(pDnode->id);
|
||||
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SDDropQnodeMsg);
|
||||
action.pCont = pReq;
|
||||
action.contLen = sizeof(SDDropQnodeReq);
|
||||
action.msgType = TDMT_DND_DROP_QNODE;
|
||||
action.acceptableCode = TSDB_CODE_DND_QNODE_NOT_DEPLOYED;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
free(pReq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndDropQnode(SMnode *pMnode, SMnodeMsg *pMsg, SQnodeObj *pObj) {
|
||||
static int32_t mndDropQnode(SMnode *pMnode, SMnodeMsg *pReq, SQnodeObj *pObj) {
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("qnode:%d, failed to drop since %s", pObj->id, terrstr());
|
||||
goto DROP_QNODE_OVER;
|
||||
}
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) goto DROP_QNODE_OVER;
|
||||
|
||||
mDebug("trans:%d, used to drop qnode:%d", pTrans->id, pObj->id);
|
||||
|
||||
if (mndSetDropQnodeRedoLogs(pTrans, pObj) != 0) {
|
||||
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||
goto DROP_QNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndSetDropQnodeCommitLogs(pTrans, pObj) != 0) {
|
||||
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||
goto DROP_QNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto DROP_QNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
goto DROP_QNODE_OVER;
|
||||
}
|
||||
if (mndSetDropQnodeRedoLogs(pTrans, pObj) != 0) goto DROP_QNODE_OVER;
|
||||
if (mndSetDropQnodeCommitLogs(pTrans, pObj) != 0) goto DROP_QNODE_OVER;
|
||||
if (mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) goto DROP_QNODE_OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto DROP_QNODE_OVER;
|
||||
|
||||
code = 0;
|
||||
|
||||
|
@ -323,9 +351,9 @@ DROP_QNODE_OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SMDropQnodeMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndProcessDropQnodeReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SMDropQnodeReq *pDrop = pReq->rpcMsg.pCont;
|
||||
pDrop->dnodeId = htonl(pDrop->dnodeId);
|
||||
|
||||
mDebug("qnode:%d, start to drop", pDrop->dnodeId);
|
||||
|
@ -338,33 +366,33 @@ static int32_t mndProcessDropQnodeReq(SMnodeMsg *pMsg) {
|
|||
|
||||
SQnodeObj *pObj = mndAcquireQnode(pMnode, pDrop->dnodeId);
|
||||
if (pObj == NULL) {
|
||||
mError("qnode:%d, not exist", pDrop->dnodeId);
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
mError("qnode:%d, failed to drop since %s", pDrop->dnodeId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mndDropQnode(pMnode, pMsg, pObj);
|
||||
int32_t code = mndDropQnode(pMnode, pReq, pObj);
|
||||
if (code != 0) {
|
||||
sdbRelease(pMnode->pSdb, pObj);
|
||||
mError("qnode:%d, failed to drop since %s", pMnode->dnodeId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
sdbRelease(pMnode->pSdb, pMnode);
|
||||
sdbRelease(pMnode->pSdb, pObj);
|
||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pMsg) {
|
||||
mndTransProcessRsp(pMsg);
|
||||
static int32_t mndProcessCreateQnodeRsp(SMnodeMsg *pRsp) {
|
||||
mndTransProcessRsp(pRsp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pMsg) {
|
||||
mndTransProcessRsp(pMsg);
|
||||
static int32_t mndProcessDropQnodeRsp(SMnodeMsg *pRsp) {
|
||||
mndTransProcessRsp(pRsp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndGetQnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndGetQnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
int32_t cols = 0;
|
||||
|
@ -403,8 +431,8 @@ static int32_t mndGetQnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveQnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndRetrieveQnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfRows = 0;
|
||||
int32_t cols = 0;
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
|
||||
#define SHOW_STEP_SIZE 100
|
||||
|
||||
static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg);
|
||||
static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowReq *pReq);
|
||||
static void mndFreeShowObj(SShowObj *pShow);
|
||||
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId);
|
||||
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove);
|
||||
static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg);
|
||||
static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessShowReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq);
|
||||
static bool mndCheckRetrieveFinished(SShowObj *pShow);
|
||||
|
||||
int32_t mndInitShow(SMnode *pMnode) {
|
||||
|
@ -36,8 +36,8 @@ int32_t mndInitShow(SMnode *pMnode) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_SHOW, mndProcessShowMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_SHOW_RETRIEVE, mndProcessRetrieveMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_SHOW, mndProcessShowReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_SHOW_RETRIEVE, mndProcessRetrieveReq);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -49,30 +49,30 @@ void mndCleanupShow(SMnode *pMnode) {
|
|||
}
|
||||
}
|
||||
|
||||
static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowMsg *pMsg) {
|
||||
static SShowObj *mndCreateShowObj(SMnode *pMnode, SShowReq *pReq) {
|
||||
SShowMgmt *pMgmt = &pMnode->showMgmt;
|
||||
|
||||
int64_t showId = atomic_add_fetch_64(&pMgmt->showId, 1);
|
||||
if (showId == 0) atomic_add_fetch_64(&pMgmt->showId, 1);
|
||||
|
||||
int32_t size = sizeof(SShowObj) + pMsg->payloadLen;
|
||||
int32_t size = sizeof(SShowObj) + pReq->payloadLen;
|
||||
SShowObj showObj = {0};
|
||||
showObj.id = showId;
|
||||
showObj.pMnode = pMnode;
|
||||
showObj.type = pMsg->type;
|
||||
showObj.payloadLen = pMsg->payloadLen;
|
||||
memcpy(showObj.db, pMsg->db, TSDB_DB_FNAME_LEN);
|
||||
memcpy(showObj.payload, pMsg->payload, pMsg->payloadLen);
|
||||
showObj.type = pReq->type;
|
||||
showObj.payloadLen = pReq->payloadLen;
|
||||
memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN);
|
||||
memcpy(showObj.payload, pReq->payload, pReq->payloadLen);
|
||||
|
||||
int32_t keepTime = pMnode->cfg.shellActivityTimer * 6 * 1000;
|
||||
SShowObj *pShow = taosCachePut(pMgmt->cache, &showId, sizeof(int64_t), &showObj, size, keepTime);
|
||||
if (pShow == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("show:0x%"PRIx64", failed to put into cache since %s", showId, terrstr());
|
||||
mError("show:0x%" PRIx64 ", failed to put into cache since %s", showId, terrstr());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("show:0x%"PRIx64", is created, data:%p", showId, pShow);
|
||||
mTrace("show:0x%" PRIx64 ", is created, data:%p", showId, pShow);
|
||||
return pShow;
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ static void mndFreeShowObj(SShowObj *pShow) {
|
|||
}
|
||||
}
|
||||
|
||||
mTrace("show:0x%d, is destroyed, data:%p", pShow->id, pShow);
|
||||
mTrace("show:0x%" PRIx64 ", is destroyed, data:%p", pShow->id, pShow);
|
||||
}
|
||||
|
||||
static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
|
||||
|
@ -95,17 +95,17 @@ static SShowObj *mndAcquireShowObj(SMnode *pMnode, int64_t showId) {
|
|||
|
||||
SShowObj *pShow = taosCacheAcquireByKey(pMgmt->cache, &showId, sizeof(showId));
|
||||
if (pShow == NULL) {
|
||||
mError("show:0x%"PRIx64", already destroyed", showId);
|
||||
mError("show:0x%" PRIx64 ", already destroyed", showId);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("show:0x%"PRIx64", acquired from cache, data:%p", pShow->id, pShow);
|
||||
mTrace("show:0x%" PRIx64 ", acquired from cache, data:%p", pShow->id, pShow);
|
||||
return pShow;
|
||||
}
|
||||
|
||||
static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
|
||||
if (pShow == NULL) return;
|
||||
mTrace("show:0x%"PRIx64", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove);
|
||||
mTrace("show:0x%" PRIx64 ", released from cache, data:%p force:%d", pShow->id, pShow, forceRemove);
|
||||
|
||||
// A bug in tcache.c
|
||||
forceRemove = 0;
|
||||
|
@ -115,12 +115,12 @@ static void mndReleaseShowObj(SShowObj *pShow, bool forceRemove) {
|
|||
taosCacheRelease(pMgmt->cache, (void **)(&pShow), forceRemove);
|
||||
}
|
||||
|
||||
static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) {
|
||||
SMnode *pMnode = pMnodeMsg->pMnode;
|
||||
static int32_t mndProcessShowReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SShowMgmt *pMgmt = &pMnode->showMgmt;
|
||||
SShowMsg *pMsg = pMnodeMsg->rpcMsg.pCont;
|
||||
int8_t type = pMsg->type;
|
||||
int16_t payloadLen = htonl(pMsg->payloadLen);
|
||||
SShowReq *pShowReq = pReq->rpcMsg.pCont;
|
||||
int8_t type = pShowReq->type;
|
||||
int16_t payloadLen = htonl(pShowReq->payloadLen);
|
||||
|
||||
if (type <= TSDB_MGMT_TABLE_START || type >= TSDB_MGMT_TABLE_MAX) {
|
||||
terrno = TSDB_CODE_MND_INVALID_MSG_TYPE;
|
||||
|
@ -135,7 +135,7 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
SShowObj *pShow = mndCreateShowObj(pMnode, pMsg);
|
||||
SShowObj *pShow = mndCreateShowObj(pMnode, pShowReq);
|
||||
if (pShow == NULL) {
|
||||
mError("failed to process show-meta msg:%s since %s", mndShowStr(type), terrstr());
|
||||
return -1;
|
||||
|
@ -146,18 +146,19 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) {
|
|||
if (pRsp == NULL) {
|
||||
mndReleaseShowObj(pShow, true);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("show:0x%"PRIx64", failed to process show-meta msg:%s since malloc rsp error", pShow->id, mndShowStr(type));
|
||||
mError("show:0x%" PRIx64 ", failed to process show-meta msg:%s since malloc rsp error", pShow->id,
|
||||
mndShowStr(type));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = (*metaFp)(pMnodeMsg, pShow, &pRsp->tableMeta);
|
||||
mDebug("show:0x%"PRIx64", get meta finished, numOfRows:%d cols:%d type:%s result:%s", pShow->id, pShow->numOfRows,
|
||||
int32_t code = (*metaFp)(pReq, pShow, &pRsp->tableMeta);
|
||||
mDebug("show:0x%" PRIx64 ", get meta finished, numOfRows:%d cols:%d type:%s, result:%s", pShow->id, pShow->numOfRows,
|
||||
pShow->numOfColumns, mndShowStr(type), tstrerror(code));
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
pMnodeMsg->contLen = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns;
|
||||
pMnodeMsg->pCont = pRsp;
|
||||
pRsp->showId = htobe64(pShow->id);
|
||||
pReq->contLen = sizeof(SShowRsp) + sizeof(SSchema) * pShow->numOfColumns;
|
||||
pReq->pCont = pRsp;
|
||||
pRsp->showId = htobe64(pShow->id);
|
||||
mndReleaseShowObj(pShow, false);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else {
|
||||
|
@ -167,15 +168,15 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) {
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
|
||||
SMnode *pMnode = pMnodeMsg->pMnode;
|
||||
static int32_t mndProcessRetrieveReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SShowMgmt *pMgmt = &pMnode->showMgmt;
|
||||
int32_t rowsToRead = 0;
|
||||
int32_t size = 0;
|
||||
int32_t rowsRead = 0;
|
||||
|
||||
SRetrieveTableMsg *pRetrieve = pMnodeMsg->rpcMsg.pCont;
|
||||
int64_t showId = htobe64(pRetrieve->showId);
|
||||
SRetrieveTableReq *pRetrieve = pReq->rpcMsg.pCont;
|
||||
int64_t showId = htobe64(pRetrieve->showId);
|
||||
|
||||
SShowObj *pShow = mndAcquireShowObj(pMnode, showId);
|
||||
if (pShow == NULL) {
|
||||
|
@ -188,15 +189,16 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
|
|||
if (retrieveFp == NULL) {
|
||||
mndReleaseShowObj(pShow, false);
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
mError("show:0x%"PRIx64", failed to retrieve data since %s", pShow->id, terrstr());
|
||||
mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
mDebug("show:0x%"PRIx64", start retrieve data, numOfReads:%d numOfRows:%d type:%s", pShow->id, pShow->numOfReads,
|
||||
mDebug("show:0x%" PRIx64 ", start retrieve data, numOfReads:%d numOfRows:%d type:%s", pShow->id, pShow->numOfReads,
|
||||
pShow->numOfRows, mndShowStr(pShow->type));
|
||||
|
||||
if (mndCheckRetrieveFinished(pShow)) {
|
||||
mDebug("show:0x%"PRIx64", read finished, numOfReads:%d numOfRows:%d", pShow->id, pShow->numOfReads, pShow->numOfRows);
|
||||
mDebug("show:0x%" PRIx64 ", read finished, numOfReads:%d numOfRows:%d", pShow->id, pShow->numOfReads,
|
||||
pShow->numOfRows);
|
||||
pShow->numOfReads = pShow->numOfRows;
|
||||
}
|
||||
|
||||
|
@ -219,29 +221,29 @@ static int32_t mndProcessRetrieveMsg(SMnodeMsg *pMnodeMsg) {
|
|||
if (pRsp == NULL) {
|
||||
mndReleaseShowObj(pShow, false);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("show:0x%"PRIx64", failed to retrieve data since %s", pShow->id, terrstr());
|
||||
mError("show:0x%" PRIx64 ", failed to retrieve data since %s", pShow->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// if free flag is set, client wants to clean the resources
|
||||
if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) {
|
||||
rowsRead = (*retrieveFp)(pMnodeMsg, pShow, pRsp->data, rowsToRead);
|
||||
rowsRead = (*retrieveFp)(pReq, pShow, pRsp->data, rowsToRead);
|
||||
}
|
||||
|
||||
mDebug("show:0x%"PRIx64", stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead);
|
||||
mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead);
|
||||
|
||||
pRsp->numOfRows = htonl(rowsRead);
|
||||
pRsp->precision = TSDB_TIME_PRECISION_MILLI; // millisecond time precision
|
||||
|
||||
pMnodeMsg->pCont = pRsp;
|
||||
pMnodeMsg->contLen = size;
|
||||
pReq->pCont = pRsp;
|
||||
pReq->contLen = size;
|
||||
|
||||
if (rowsRead == 0 || rowsToRead == 0 || (rowsRead == rowsToRead && pShow->numOfRows == pShow->numOfReads)) {
|
||||
pRsp->completed = 1;
|
||||
mDebug("show:0x%"PRIx64", retrieve completed", pShow->id);
|
||||
mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
|
||||
mndReleaseShowObj(pShow, true);
|
||||
} else {
|
||||
mDebug("show:0x%"PRIx64", retrieve not completed yet", pShow->id);
|
||||
mDebug("show:0x%" PRIx64 ", retrieve not completed yet", pShow->id);
|
||||
mndReleaseShowObj(pShow, false);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,13 +26,13 @@ static SSdbRaw *mndSnodeActionEncode(SSnodeObj *pObj);
|
|||
static SSdbRow *mndSnodeActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndSnodeActionInsert(SSdb *pSdb, SSnodeObj *pObj);
|
||||
static int32_t mndSnodeActionDelete(SSdb *pSdb, SSnodeObj *pObj);
|
||||
static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOldSnode, SSnodeObj *pNewSnode);
|
||||
static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessDropSnodeRsp(SMnodeMsg *pMsg);
|
||||
static int32_t mndGetSnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveSnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||
static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOld, SSnodeObj *pNew);
|
||||
static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessDropSnodeReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pRsp);
|
||||
static int32_t mndProcessDropSnodeRsp(SMnodeMsg *pRsp);
|
||||
static int32_t mndGetSnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveSnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows);
|
||||
static void mndCancelGetNextSnode(SMnode *pMnode, void *pIter);
|
||||
|
||||
int32_t mndInitSnode(SMnode *pMnode) {
|
||||
|
@ -59,9 +59,8 @@ int32_t mndInitSnode(SMnode *pMnode) {
|
|||
void mndCleanupSnode(SMnode *pMnode) {}
|
||||
|
||||
static SSnodeObj *mndAcquireSnode(SMnode *pMnode, int32_t snodeId) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SSnodeObj *pObj = sdbAcquire(pSdb, SDB_SNODE, &snodeId);
|
||||
if (pObj == NULL) {
|
||||
SSnodeObj *pObj = sdbAcquire(pMnode->pSdb, SDB_SNODE, &snodeId);
|
||||
if (pObj == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
|
||||
terrno = TSDB_CODE_MND_SNODE_NOT_EXIST;
|
||||
}
|
||||
return pObj;
|
||||
|
@ -73,43 +72,68 @@ static void mndReleaseSnode(SMnode *pMnode, SSnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static SSdbRaw *mndSnodeActionEncode(SSnodeObj *pObj) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_SNODE, TSDB_SNODE_VER_NUMBER, sizeof(SSnodeObj) + TSDB_SNODE_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
if (pRaw == NULL) goto SNODE_ENCODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_INT32(pRaw, dataPos, pObj->id);
|
||||
SDB_SET_INT64(pRaw, dataPos, pObj->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pObj->updateTime)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_SNODE_RESERVE_SIZE)
|
||||
SDB_SET_INT32(pRaw, dataPos, pObj->id, SNODE_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pObj->createdTime, SNODE_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pObj->updateTime, SNODE_ENCODE_OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_SNODE_RESERVE_SIZE, SNODE_ENCODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
SNODE_ENCODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("snode:%d, failed to encode to raw:%p since %s", pObj->id, pRaw, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("snode:%d, encode to raw:%p, row:%p", pObj->id, pRaw, pObj);
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mndSnodeActionDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto SNODE_DECODE_OVER;
|
||||
|
||||
if (sver != TSDB_SNODE_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
mError("failed to decode snode since %s", terrstr());
|
||||
goto SNODE_DECODE_OVER;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SSnodeObj));
|
||||
if (pRow == NULL) goto SNODE_DECODE_OVER;
|
||||
|
||||
SSnodeObj *pObj = sdbGetRowObj(pRow);
|
||||
if (pObj == NULL) goto SNODE_DECODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT32(pRaw, dataPos, &pObj->id, SNODE_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pObj->createdTime, SNODE_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pObj->updateTime, SNODE_DECODE_OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_SNODE_RESERVE_SIZE, SNODE_DECODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
SNODE_DECODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("snode:%d, failed to decode from raw:%p since %s", pObj->id, pRaw, terrstr());
|
||||
tfree(pRow);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SSnodeObj));
|
||||
SSnodeObj *pObj = sdbGetRowObj(pRow);
|
||||
if (pObj == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pObj->id)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pObj->updateTime)
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_SNODE_RESERVE_SIZE)
|
||||
|
||||
mTrace("snode:%d, decode from raw:%p, row:%p", pObj->id, pRaw, pObj);
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mndSnodeActionInsert(SSdb *pSdb, SSnodeObj *pObj) {
|
||||
mTrace("snode:%d, perform insert action", pObj->id);
|
||||
mTrace("snode:%d, perform insert action, row:%p", pObj->id, pObj);
|
||||
pObj->pDnode = sdbAcquire(pSdb, SDB_DNODE, &pObj->id);
|
||||
if (pObj->pDnode == NULL) {
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
|
@ -121,7 +145,7 @@ static int32_t mndSnodeActionInsert(SSdb *pSdb, SSnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static int32_t mndSnodeActionDelete(SSdb *pSdb, SSnodeObj *pObj) {
|
||||
mTrace("snode:%d, perform delete action", pObj->id);
|
||||
mTrace("snode:%d, perform delete action, row:%p", pObj->id, pObj);
|
||||
if (pObj->pDnode != NULL) {
|
||||
sdbRelease(pSdb, pObj->pDnode);
|
||||
pObj->pDnode = NULL;
|
||||
|
@ -130,9 +154,9 @@ static int32_t mndSnodeActionDelete(SSdb *pSdb, SSnodeObj *pObj) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOldSnode, SSnodeObj *pNewSnode) {
|
||||
mTrace("snode:%d, perform update action", pOldSnode->id);
|
||||
pOldSnode->updateTime = pNewSnode->updateTime;
|
||||
static int32_t mndSnodeActionUpdate(SSdb *pSdb, SSnodeObj *pOld, SSnodeObj *pNew) {
|
||||
mTrace("snode:%d, perform update action, old_row:%p new_row:%p", pOld->id, pOld, pNew);
|
||||
pOld->updateTime = pNew->updateTime;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -144,6 +168,14 @@ static int32_t mndSetCreateSnodeRedoLogs(STrans *pTrans, SSnodeObj *pObj) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateSnodeUndoLogs(STrans *pTrans, SSnodeObj *pObj) {
|
||||
SSdbRaw *pUndoRaw = mndSnodeActionEncode(pObj);
|
||||
if (pUndoRaw == NULL) return -1;
|
||||
if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) {
|
||||
SSdbRaw *pCommitRaw = mndSnodeActionEncode(pObj);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
|
@ -153,60 +185,70 @@ static int32_t mndSetCreateSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) {
|
||||
SDCreateSnodeMsg *pMsg = malloc(sizeof(SDCreateSnodeMsg));
|
||||
if (pMsg == NULL) {
|
||||
SDCreateSnodeReq *pReq = malloc(sizeof(SDCreateSnodeReq));
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pMsg->dnodeId = htonl(pDnode->id);
|
||||
pReq->dnodeId = htonl(pDnode->id);
|
||||
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SDCreateSnodeMsg);
|
||||
action.pCont = pReq;
|
||||
action.contLen = sizeof(SDCreateSnodeReq);
|
||||
action.msgType = TDMT_DND_CREATE_SNODE;
|
||||
action.acceptableCode = TSDB_CODE_DND_SNODE_ALREADY_DEPLOYED;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
free(pReq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCreateSnode(SMnode *pMnode, SMnodeMsg *pMsg, SDnodeObj *pDnode, SMCreateSnodeMsg *pCreate) {
|
||||
static int32_t mndSetCreateSnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) {
|
||||
SDDropSnodeReq *pReq = malloc(sizeof(SDDropSnodeReq));
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pReq->dnodeId = htonl(pDnode->id);
|
||||
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
action.pCont = pReq;
|
||||
action.contLen = sizeof(SDDropSnodeReq);
|
||||
action.msgType = TDMT_DND_DROP_SNODE;
|
||||
action.acceptableCode = TSDB_CODE_DND_SNODE_NOT_DEPLOYED;
|
||||
|
||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||
free(pReq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCreateSnode(SMnode *pMnode, SMnodeMsg *pReq, SDnodeObj *pDnode, SMCreateSnodeReq *pCreate) {
|
||||
int32_t code = -1;
|
||||
|
||||
SSnodeObj snodeObj = {0};
|
||||
snodeObj.id = pDnode->id;
|
||||
snodeObj.createdTime = taosGetTimestampMs();
|
||||
snodeObj.updateTime = snodeObj.createdTime;
|
||||
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("snode:%d, failed to create since %s", pCreate->dnodeId, terrstr());
|
||||
goto CREATE_SNODE_OVER;
|
||||
}
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) goto CREATE_SNODE_OVER;
|
||||
|
||||
mDebug("trans:%d, used to create snode:%d", pTrans->id, pCreate->dnodeId);
|
||||
|
||||
if (mndSetCreateSnodeRedoLogs(pTrans, &snodeObj) != 0) {
|
||||
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_SNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndSetCreateSnodeCommitLogs(pTrans, &snodeObj) != 0) {
|
||||
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_SNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndSetCreateSnodeRedoActions(pTrans, pDnode, &snodeObj) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto CREATE_SNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
goto CREATE_SNODE_OVER;
|
||||
}
|
||||
if (mndSetCreateSnodeRedoLogs(pTrans, &snodeObj) != 0) goto CREATE_SNODE_OVER;
|
||||
if (mndSetCreateSnodeUndoLogs(pTrans, &snodeObj) != 0) goto CREATE_SNODE_OVER;
|
||||
if (mndSetCreateSnodeCommitLogs(pTrans, &snodeObj) != 0) goto CREATE_SNODE_OVER;
|
||||
if (mndSetCreateSnodeRedoActions(pTrans, pDnode, &snodeObj) != 0) goto CREATE_SNODE_OVER;
|
||||
if (mndSetCreateSnodeUndoActions(pTrans, pDnode, &snodeObj) != 0) goto CREATE_SNODE_OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto CREATE_SNODE_OVER;
|
||||
|
||||
code = 0;
|
||||
|
||||
|
@ -215,9 +257,9 @@ CREATE_SNODE_OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SMCreateSnodeMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SMCreateSnodeReq *pCreate = pReq->rpcMsg.pCont;
|
||||
|
||||
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
||||
|
||||
|
@ -226,8 +268,12 @@ static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg) {
|
|||
SSnodeObj *pObj = mndAcquireSnode(pMnode, pCreate->dnodeId);
|
||||
if (pObj != NULL) {
|
||||
mError("snode:%d, snode already exist", pObj->id);
|
||||
terrno = TSDB_CODE_MND_SNODE_ALREADY_EXIST;
|
||||
mndReleaseSnode(pMnode, pObj);
|
||||
return -1;
|
||||
} else if (terrno != TSDB_CODE_MND_SNODE_NOT_EXIST) {
|
||||
mError("snode:%d, failed to create snode since %s", pCreate->dnodeId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pCreate->dnodeId);
|
||||
|
@ -237,7 +283,7 @@ static int32_t mndProcessCreateSnodeReq(SMnodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mndCreateSnode(pMnode, pMsg, pDnode, pCreate);
|
||||
int32_t code = mndCreateSnode(pMnode, pReq, pDnode, pCreate);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
if (code != 0) {
|
||||
|
@ -265,56 +311,40 @@ static int32_t mndSetDropSnodeCommitLogs(STrans *pTrans, SSnodeObj *pObj) {
|
|||
}
|
||||
|
||||
static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSnodeObj *pObj) {
|
||||
SDDropSnodeMsg *pMsg = malloc(sizeof(SDDropSnodeMsg));
|
||||
if (pMsg == NULL) {
|
||||
SDDropSnodeReq *pReq = malloc(sizeof(SDDropSnodeReq));
|
||||
if (pReq == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pMsg->dnodeId = htonl(pDnode->id);
|
||||
pReq->dnodeId = htonl(pDnode->id);
|
||||
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SDDropSnodeMsg);
|
||||
action.pCont = pReq;
|
||||
action.contLen = sizeof(SDDropSnodeReq);
|
||||
action.msgType = TDMT_DND_DROP_SNODE;
|
||||
action.acceptableCode = TSDB_CODE_DND_SNODE_NOT_DEPLOYED;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
free(pReq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndDropSnode(SMnode *pMnode, SMnodeMsg *pMsg, SSnodeObj *pObj) {
|
||||
static int32_t mndDropSnode(SMnode *pMnode, SMnodeMsg *pReq, SSnodeObj *pObj) {
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pMsg->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("snode:%d, failed to drop since %s", pObj->id, terrstr());
|
||||
goto DROP_SNODE_OVER;
|
||||
}
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) goto DROP_SNODE_OVER;
|
||||
|
||||
mDebug("trans:%d, used to drop snode:%d", pTrans->id, pObj->id);
|
||||
|
||||
if (mndSetDropSnodeRedoLogs(pTrans, pObj) != 0) {
|
||||
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||
goto DROP_SNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndSetDropSnodeCommitLogs(pTrans, pObj) != 0) {
|
||||
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||
goto DROP_SNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto DROP_SNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
goto DROP_SNODE_OVER;
|
||||
}
|
||||
if (mndSetDropSnodeRedoLogs(pTrans, pObj) != 0) goto DROP_SNODE_OVER;
|
||||
if (mndSetDropSnodeCommitLogs(pTrans, pObj) != 0) goto DROP_SNODE_OVER;
|
||||
if (mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) goto DROP_SNODE_OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto DROP_SNODE_OVER;
|
||||
|
||||
code = 0;
|
||||
|
||||
|
@ -323,9 +353,9 @@ DROP_SNODE_OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SMDropSnodeMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndProcessDropSnodeReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SMDropSnodeReq *pDrop = pReq->rpcMsg.pCont;
|
||||
pDrop->dnodeId = htonl(pDrop->dnodeId);
|
||||
|
||||
mDebug("snode:%d, start to drop", pDrop->dnodeId);
|
||||
|
@ -338,33 +368,33 @@ static int32_t mndProcessDropSnodeReq(SMnodeMsg *pMsg) {
|
|||
|
||||
SSnodeObj *pObj = mndAcquireSnode(pMnode, pDrop->dnodeId);
|
||||
if (pObj == NULL) {
|
||||
mError("snode:%d, not exist", pDrop->dnodeId);
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
mError("snode:%d, failed to drop since %s", pDrop->dnodeId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mndDropSnode(pMnode, pMsg, pObj);
|
||||
int32_t code = mndDropSnode(pMnode, pReq, pObj);
|
||||
if (code != 0) {
|
||||
sdbRelease(pMnode->pSdb, pObj);
|
||||
mError("snode:%d, failed to drop since %s", pMnode->dnodeId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
sdbRelease(pMnode->pSdb, pMnode);
|
||||
sdbRelease(pMnode->pSdb, pObj);
|
||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pMsg) {
|
||||
mndTransProcessRsp(pMsg);
|
||||
static int32_t mndProcessCreateSnodeRsp(SMnodeMsg *pRsp) {
|
||||
mndTransProcessRsp(pRsp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropSnodeRsp(SMnodeMsg *pMsg) {
|
||||
mndTransProcessRsp(pMsg);
|
||||
static int32_t mndProcessDropSnodeRsp(SMnodeMsg *pRsp) {
|
||||
mndTransProcessRsp(pRsp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndGetSnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndGetSnodeMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
int32_t cols = 0;
|
||||
|
@ -403,8 +433,8 @@ static int32_t mndGetSnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveSnodes(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndRetrieveSnodes(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfRows = 0;
|
||||
int32_t cols = 0;
|
||||
|
|
|
@ -70,90 +70,115 @@ int32_t mndInitStb(SMnode *pMnode) {
|
|||
void mndCleanupStb(SMnode *pMnode) {}
|
||||
|
||||
static SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int32_t size = sizeof(SStbObj) + (pStb->numOfColumns + pStb->numOfTags) * sizeof(SSchema) + TSDB_STB_RESERVE_SIZE;
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_STB, TSDB_STB_VER_NUMBER, size);
|
||||
if (pRaw == NULL) return NULL;
|
||||
if (pRaw == NULL) goto STB_ENCODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_BINARY(pRaw, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pStb->db, TSDB_DB_FNAME_LEN)
|
||||
SDB_SET_INT64(pRaw, dataPos, pStb->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pStb->updateTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pStb->uid)
|
||||
SDB_SET_INT64(pRaw, dataPos, pStb->dbUid)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->version)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN, STB_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pStb->db, TSDB_DB_FNAME_LEN, STB_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pStb->createdTime, STB_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pStb->updateTime, STB_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pStb->uid, STB_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pStb->dbUid, STB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->version, STB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns, STB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags, STB_ENCODE_OVER)
|
||||
|
||||
int32_t totalCols = pStb->numOfColumns + pStb->numOfTags;
|
||||
for (int32_t i = 0; i < totalCols; ++i) {
|
||||
SSchema *pSchema = &pStb->pSchema[i];
|
||||
SDB_SET_INT8(pRaw, dataPos, pSchema->type);
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->colId);
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->bytes);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN);
|
||||
SDB_SET_INT8(pRaw, dataPos, pSchema->type, STB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->colId, STB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->bytes, STB_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_ENCODE_OVER)
|
||||
}
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE)
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE, STB_ENCODE_OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, STB_ENCODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
STB_ENCODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("stb:%s, failed to encode to raw:%p since %s", pStb->name, pRaw, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("stb:%s, encode to raw:%p, row:%p", pStb->name, pRaw, pStb);
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto STB_DECODE_OVER;
|
||||
|
||||
if (sver != TSDB_STB_VER_NUMBER) {
|
||||
mError("failed to decode stable since %s", terrstr());
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
return NULL;
|
||||
goto STB_DECODE_OVER;
|
||||
}
|
||||
|
||||
int32_t size = sizeof(SStbObj) + TSDB_MAX_COLUMNS * sizeof(SSchema);
|
||||
SSdbRow *pRow = sdbAllocRow(size);
|
||||
if (pRow == NULL) goto STB_DECODE_OVER;
|
||||
|
||||
SStbObj *pStb = sdbGetRowObj(pRow);
|
||||
if (pStb == NULL) return NULL;
|
||||
if (pStb == NULL) goto STB_DECODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN)
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pStb->db, TSDB_DB_FNAME_LEN)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->updateTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->uid)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pStb->dbUid)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pStb->version)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pStb->numOfColumns)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pStb->numOfTags)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pStb->name, TSDB_TABLE_FNAME_LEN, STB_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pStb->db, TSDB_DB_FNAME_LEN, STB_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pStb->createdTime, STB_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pStb->updateTime, STB_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pStb->uid, STB_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pStb->dbUid, STB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->version, STB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->numOfColumns, STB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pStb->numOfTags, STB_DECODE_OVER)
|
||||
|
||||
int32_t totalCols = pStb->numOfColumns + pStb->numOfTags;
|
||||
pStb->pSchema = calloc(totalCols, sizeof(SSchema));
|
||||
|
||||
for (int32_t i = 0; i < totalCols; ++i) {
|
||||
SSchema *pSchema = &pStb->pSchema[i];
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pSchema->type);
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pSchema->colId);
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pSchema->bytes);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pSchema->name, TSDB_COL_NAME_LEN);
|
||||
SDB_GET_INT8(pRaw, dataPos, &pSchema->type, STB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pSchema->colId, STB_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pSchema->bytes, STB_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN, STB_DECODE_OVER)
|
||||
}
|
||||
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_STB_RESERVE_SIZE)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE, STB_DECODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
STB_DECODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("stb:%s, failed to decode from raw:%p since %s", pStb->name, pRaw, terrstr());
|
||||
tfree(pRow);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("stb:%s, decode from raw:%p, row:%p", pStb->name, pRaw, pStb);
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mndStbActionInsert(SSdb *pSdb, SStbObj *pStb) {
|
||||
mTrace("stb:%s, perform insert action", pStb->name);
|
||||
mTrace("stb:%s, perform insert action, row:%p", pStb->name, pStb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndStbActionDelete(SSdb *pSdb, SStbObj *pStb) {
|
||||
mTrace("stb:%s, perform delete action", pStb->name);
|
||||
mTrace("stb:%s, perform delete action, row:%p", pStb->name, pStb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOldStb, SStbObj *pNewStb) {
|
||||
mTrace("stb:%s, perform update action", pOldStb->name);
|
||||
mTrace("stb:%s, perform update action, old_row:%p new_row:%p", pOldStb->name, pOldStb, pNewStb);
|
||||
atomic_exchange_32(&pOldStb->updateTime, pNewStb->updateTime);
|
||||
atomic_exchange_32(&pOldStb->version, pNewStb->version);
|
||||
|
||||
|
@ -177,7 +202,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOldStb, SStbObj *pNewStb
|
|||
}
|
||||
|
||||
SStbObj *mndAcquireStb(SMnode *pMnode, char *stbName) {
|
||||
SSdb * pSdb = pMnode->pSdb;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SStbObj *pStb = sdbAcquire(pSdb, SDB_STB, stbName);
|
||||
if (pStb == NULL) {
|
||||
terrno = TSDB_CODE_MND_STB_NOT_EXIST;
|
||||
|
@ -202,9 +227,9 @@ static SDbObj *mndAcquireDbByStb(SMnode *pMnode, char *stbName) {
|
|||
|
||||
static void *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int *pContLen) {
|
||||
SVCreateTbReq req;
|
||||
void * buf;
|
||||
void *buf;
|
||||
int bsize;
|
||||
SMsgHead * pMsgHead;
|
||||
SMsgHead *pMsgHead;
|
||||
|
||||
req.ver = 0;
|
||||
SName name = {0};
|
||||
|
@ -328,9 +353,9 @@ static int32_t mndSetCreateStbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj
|
|||
}
|
||||
|
||||
static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
|
||||
SSdb * pSdb = pMnode->pSdb;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SVgObj *pVgroup = NULL;
|
||||
void * pIter = NULL;
|
||||
void *pIter = NULL;
|
||||
int contLen;
|
||||
|
||||
while (1) {
|
||||
|
@ -364,9 +389,9 @@ static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj
|
|||
}
|
||||
|
||||
static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
|
||||
SSdb * pSdb = pMnode->pSdb;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SVgObj *pVgroup = NULL;
|
||||
void * pIter = NULL;
|
||||
void *pIter = NULL;
|
||||
|
||||
while (1) {
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
|
@ -470,7 +495,7 @@ CREATE_STB_OVER:
|
|||
}
|
||||
|
||||
static int32_t mndProcessCreateStbMsg(SMnodeMsg *pMsg) {
|
||||
SMnode * pMnode = pMsg->pMnode;
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SCreateStbMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||
|
||||
mDebug("stb:%s, start to create", pCreate->name);
|
||||
|
@ -554,7 +579,7 @@ static int32_t mndCheckAlterStbMsg(SAlterStbMsg *pAlter) {
|
|||
static int32_t mndUpdateStb(SMnode *pMnode, SMnodeMsg *pMsg, SStbObj *pOldStb, SStbObj *pNewStb) { return 0; }
|
||||
|
||||
static int32_t mndProcessAlterStbMsg(SMnodeMsg *pMsg) {
|
||||
SMnode * pMnode = pMsg->pMnode;
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SAlterStbMsg *pAlter = pMsg->rpcMsg.pCont;
|
||||
|
||||
mDebug("stb:%s, start to alter", pAlter->name);
|
||||
|
@ -668,7 +693,7 @@ DROP_STB_OVER:
|
|||
}
|
||||
|
||||
static int32_t mndProcessDropStbMsg(SMnodeMsg *pMsg) {
|
||||
SMnode * pMnode = pMsg->pMnode;
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SDropStbMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||
|
||||
mDebug("stb:%s, start to drop", pDrop->name);
|
||||
|
@ -703,7 +728,7 @@ static int32_t mndProcessDropStbInRsp(SMnodeMsg *pMsg) {
|
|||
}
|
||||
|
||||
static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) {
|
||||
SMnode * pMnode = pMsg->pMnode;
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
STableInfoMsg *pInfo = pMsg->rpcMsg.pCont;
|
||||
|
||||
mDebug("stb:%s, start to retrieve meta", pInfo->tableFname);
|
||||
|
@ -775,7 +800,7 @@ static int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs
|
|||
}
|
||||
|
||||
int32_t numOfStbs = 0;
|
||||
void * pIter = NULL;
|
||||
void *pIter = NULL;
|
||||
while (1) {
|
||||
SStbObj *pStb = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_STB, pIter, (void **)&pStb);
|
||||
|
@ -794,7 +819,7 @@ static int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs
|
|||
|
||||
static int32_t mndGetStbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SSdb * pSdb = pMnode->pSdb;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
if (mndGetNumOfStbs(pMnode, pShow->db, &pShow->numOfRows) != 0) {
|
||||
return -1;
|
||||
|
|
|
@ -15,11 +15,112 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "mndSync.h"
|
||||
#include "mndTrans.h"
|
||||
|
||||
static int32_t mndInitWal(SMnode *pMnode) {
|
||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||
|
||||
char path[PATH_MAX] = {0};
|
||||
snprintf(path, sizeof(path), "%s%swal", pMnode->path, TD_DIRSEP);
|
||||
SWalCfg cfg = {.vgId = 1,
|
||||
.fsyncPeriod = 0,
|
||||
.rollPeriod = -1,
|
||||
.segSize = -1,
|
||||
.retentionPeriod = -1,
|
||||
.retentionSize = -1,
|
||||
.level = TAOS_WAL_FSYNC};
|
||||
pMgmt->pWal = walOpen(path, &cfg);
|
||||
if (pMgmt->pWal == NULL) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mndCloseWal(SMnode *pMnode) {
|
||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||
if (pMgmt->pWal != NULL) {
|
||||
walClose(pMgmt->pWal);
|
||||
pMgmt->pWal = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mndRestoreWal(SMnode *pMnode) {
|
||||
SWal *pWal = pMnode->syncMgmt.pWal;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int64_t lastSdbVer = sdbUpdateVer(pSdb, 0);
|
||||
int32_t code = -1;
|
||||
|
||||
SWalReadHandle *pHandle = walOpenReadHandle(pWal);
|
||||
if (pHandle == NULL) return -1;
|
||||
|
||||
int64_t first = walGetFirstVer(pWal);
|
||||
int64_t last = walGetLastVer(pWal);
|
||||
mDebug("restore sdb wal start, sdb ver:%" PRId64 ", wal first:%" PRId64 " last:%" PRId64, lastSdbVer, first, last);
|
||||
|
||||
first = MAX(lastSdbVer + 1, first);
|
||||
for (int64_t ver = first; ver >= 0 && ver <= last; ++ver) {
|
||||
if (walReadWithHandle(pHandle, ver) < 0) {
|
||||
mError("failed to read by wal handle since %s, ver:%" PRId64, terrstr(), ver);
|
||||
goto WAL_RESTORE_OVER;
|
||||
}
|
||||
|
||||
SWalHead *pHead = pHandle->pHead;
|
||||
int64_t sdbVer = sdbUpdateVer(pSdb, 0);
|
||||
if (sdbVer + 1 != ver) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_WAl_VER;
|
||||
mError("failed to read wal from sdb, sdbVer:%" PRId64 " inconsistent with ver:%" PRId64, sdbVer, ver);
|
||||
goto WAL_RESTORE_OVER;
|
||||
}
|
||||
|
||||
if (sdbWriteNotFree(pSdb, (void *)pHead->head.body) < 0) {
|
||||
mError("failed to read wal from sdb since %s, ver:%" PRId64, terrstr(), ver);
|
||||
goto WAL_RESTORE_OVER;
|
||||
}
|
||||
|
||||
sdbUpdateVer(pSdb, 1);
|
||||
mDebug("wal:%" PRId64 ", is restored", ver);
|
||||
}
|
||||
|
||||
int64_t sdbVer = sdbUpdateVer(pSdb, 0);
|
||||
mDebug("restore sdb wal finished, sdb ver:%" PRId64, sdbVer);
|
||||
|
||||
mndTransPullup(pMnode);
|
||||
|
||||
if (walBeginSnapshot(pWal, sdbVer) < 0) {
|
||||
goto WAL_RESTORE_OVER;
|
||||
}
|
||||
|
||||
if (sdbVer != lastSdbVer) {
|
||||
mInfo("sdb restored from %" PRId64 " to %" PRId64 ", write file", lastSdbVer, sdbVer);
|
||||
if (sdbWriteFile(pSdb) != 0) {
|
||||
goto WAL_RESTORE_OVER;
|
||||
}
|
||||
}
|
||||
|
||||
if (walEndSnapshot(pWal) < 0) {
|
||||
goto WAL_RESTORE_OVER;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
||||
WAL_RESTORE_OVER:
|
||||
walCloseReadHandle(pHandle);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mndInitSync(SMnode *pMnode) {
|
||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||
tsem_init(&pMgmt->syncSem, 0, 0);
|
||||
|
||||
if (mndInitWal(pMnode) < 0) {
|
||||
mError("failed to open wal since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mndRestoreWal(pMnode) < 0) {
|
||||
mError("failed to restore wal since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
pMgmt->state = TAOS_SYNC_STATE_LEADER;
|
||||
pMgmt->pSyncNode = NULL;
|
||||
return 0;
|
||||
|
@ -28,6 +129,7 @@ int32_t mndInitSync(SMnode *pMnode) {
|
|||
void mndCleanupSync(SMnode *pMnode) {
|
||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||
tsem_destroy(&pMgmt->syncSem);
|
||||
mndCloseWal(pMnode);
|
||||
}
|
||||
|
||||
static int32_t mndSyncApplyCb(struct SSyncFSM *fsm, SyncIndex index, const SSyncBuffer *buf, void *pData) {
|
||||
|
@ -41,6 +143,20 @@ static int32_t mndSyncApplyCb(struct SSyncFSM *fsm, SyncIndex index, const SSync
|
|||
}
|
||||
|
||||
int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw) {
|
||||
SWal *pWal = pMnode->syncMgmt.pWal;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
int64_t ver = sdbUpdateVer(pSdb, 1);
|
||||
if (walWrite(pWal, ver, 1, pRaw, sdbGetRawTotalSize(pRaw)) < 0) {
|
||||
sdbUpdateVer(pSdb, -1);
|
||||
mError("failed to write raw:%p since %s, ver:%" PRId64, pRaw, terrstr(), ver);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mTrace("raw:%p, write to wal, ver:%" PRId64, pRaw, ver);
|
||||
walCommit(pWal, ver);
|
||||
walFsync(pWal, true);
|
||||
|
||||
#if 1
|
||||
return 0;
|
||||
#else
|
||||
|
|
|
@ -57,11 +57,10 @@ int32_t mndInitTopic(SMnode *pMnode) {
|
|||
|
||||
void mndCleanupTopic(SMnode *pMnode) {}
|
||||
|
||||
SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) {
|
||||
int32_t len;
|
||||
int32_t size = sizeof(SMqTopicObj) + MND_TOPIC_RESERVE_SIZE;
|
||||
static SSdbRaw *mndTopicActionEncode(STopicObj *pTopic) {
|
||||
int32_t size = sizeof(STopicObj) + MND_TOPIC_RESERVE_SIZE;
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_TOPIC, MND_TOPIC_VER_NUMBER, size);
|
||||
if (pRaw == NULL) return NULL;
|
||||
if (pRaw == NULL) goto TOPIC_ENCODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_BINARY(pRaw, dataPos, pTopic->name, TSDB_TABLE_FNAME_LEN);
|
||||
|
@ -71,15 +70,10 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) {
|
|||
SDB_SET_INT64(pRaw, dataPos, pTopic->uid);
|
||||
SDB_SET_INT64(pRaw, dataPos, pTopic->dbUid);
|
||||
SDB_SET_INT32(pRaw, dataPos, pTopic->version);
|
||||
SDB_SET_INT32(pRaw, dataPos, pTopic->execLen);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pTopic->executor, pTopic->execLen);
|
||||
SDB_SET_INT32(pRaw, dataPos, pTopic->sqlLen);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen);
|
||||
SDB_SET_INT32(pRaw, dataPos, pTopic->sqlLen);
|
||||
len = strlen(pTopic->logicalPlan);
|
||||
SDB_SET_INT32(pRaw, dataPos, len);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pTopic->logicalPlan, len);
|
||||
len = strlen(pTopic->physicalPlan);
|
||||
SDB_SET_INT32(pRaw, dataPos, len);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pTopic->physicalPlan, len);
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE);
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
|
@ -88,38 +82,50 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) {
|
|||
}
|
||||
|
||||
SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto TOPIC_DECODE_OVER;
|
||||
|
||||
if (sver != MND_TOPIC_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
mError("failed to decode topic since %s", terrstr());
|
||||
return NULL;
|
||||
goto TOPIC_DECODE_OVER;
|
||||
}
|
||||
|
||||
int32_t size = sizeof(SMqTopicObj) + TSDB_MAX_COLUMNS * sizeof(SSchema);
|
||||
int32_t size = sizeof(SMqTopicObj);
|
||||
SSdbRow *pRow = sdbAllocRow(size);
|
||||
if (pRow == NULL) goto TOPIC_DECODE_OVER;
|
||||
|
||||
SMqTopicObj *pTopic = sdbGetRowObj(pRow);
|
||||
if (pTopic == NULL) return NULL;
|
||||
if (pTopic == NULL) goto TOPIC_DECODE_OVER;
|
||||
|
||||
int32_t len;
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->name, TSDB_TABLE_FNAME_LEN);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->db, TSDB_DB_FNAME_LEN);
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pTopic->createTime);
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pTopic->updateTime);
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pTopic->uid);
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pTopic->dbUid);
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pTopic->version);
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pTopic->sqlLen);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->sql, pTopic->sqlLen);
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &len);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->logicalPlan, len);
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &len);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pTopic->physicalPlan, len);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTopic->name, TSDB_TABLE_FNAME_LEN, TOPIC_DECODE_OVER);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTopic->db, TSDB_DB_FNAME_LEN, TOPIC_DECODE_OVER);
|
||||
SDB_GET_INT64(pRaw, dataPos, &pTopic->createTime, TOPIC_DECODE_OVER);
|
||||
SDB_GET_INT64(pRaw, dataPos, &pTopic->updateTime, TOPIC_DECODE_OVER);
|
||||
SDB_GET_INT64(pRaw, dataPos, &pTopic->uid, TOPIC_DECODE_OVER);
|
||||
SDB_GET_INT64(pRaw, dataPos, &pTopic->dbUid, TOPIC_DECODE_OVER);
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTopic->version, TOPIC_DECODE_OVER);
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTopic->sqlLen, TOPIC_DECODE_OVER);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen, TOPIC_DECODE_OVER);
|
||||
SDB_GET_INT32(pRaw, dataPos, &len);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTopic->logicalPlan, len, TOPIC_DECODE_OVER);
|
||||
SDB_GET_INT32(pRaw, dataPos, &len);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTopic->physicalPlan, len, TOPIC_DECODE_OVER);
|
||||
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, MND_TOPIC_RESERVE_SIZE);
|
||||
SDB_GET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE, TOPIC_DECODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
TOPIC_DECODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("topic:%s, failed to decode from raw:%p since %s", pTopic->name, pRaw, terrstr());
|
||||
tfree(pRow);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("topic:%s, decode from raw:%p, row:%p", pTopic->name, pRaw, pTopic);
|
||||
return pRow;
|
||||
}
|
||||
|
||||
|
@ -368,7 +374,7 @@ static int32_t mndGetNumOfTopics(SMnode *pMnode, char *dbName, int32_t *pNumOfTo
|
|||
int32_t numOfTopics = 0;
|
||||
void *pIter = NULL;
|
||||
while (1) {
|
||||
SMqTopicObj *pTopic = NULL;
|
||||
STopicObj *pTopic = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_TOPIC, pIter, (void **)&pTopic);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ static int32_t mndTransAppendLog(SArray *pArray, SSdbRaw *pRaw);
|
|||
static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction);
|
||||
static void mndTransDropLogs(SArray *pArray);
|
||||
static void mndTransDropActions(SArray *pArray);
|
||||
static void mndTransDropData(STrans *pTrans);
|
||||
static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray);
|
||||
static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pArray);
|
||||
static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans);
|
||||
|
@ -51,7 +52,6 @@ static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans);
|
|||
static void mndTransExecute(SMnode *pMnode, STrans *pTrans);
|
||||
static void mndTransSendRpcRsp(STrans *pTrans);
|
||||
static int32_t mndProcessTransMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessTransRsp(SMnodeMsg *pMsg);
|
||||
|
||||
int32_t mndInitTrans(SMnode *pMnode) {
|
||||
SSdbTable table = {.sdbType = SDB_TRANS,
|
||||
|
@ -63,13 +63,14 @@ int32_t mndInitTrans(SMnode *pMnode) {
|
|||
.deleteFp = (SdbDeleteFp)mndTransActionDelete};
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_TRANS, mndProcessTransMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_TRANS_RSP, mndProcessTransRsp);
|
||||
return sdbSetTable(pMnode->pSdb, table);
|
||||
}
|
||||
|
||||
void mndCleanupTrans(SMnode *pMnode) {}
|
||||
|
||||
static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int32_t rawDataLen = sizeof(STrans) + MND_TRANS_RESERVE_SIZE;
|
||||
int32_t redoLogNum = taosArrayGetSize(pTrans->redoLogs);
|
||||
int32_t undoLogNum = taosArrayGetSize(pTrans->undoLogs);
|
||||
|
@ -109,75 +110,97 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
|||
}
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->id)
|
||||
SDB_SET_INT8(pRaw, dataPos, pTrans->policy)
|
||||
SDB_SET_INT32(pRaw, dataPos, redoLogNum)
|
||||
SDB_SET_INT32(pRaw, dataPos, undoLogNum)
|
||||
SDB_SET_INT32(pRaw, dataPos, commitLogNum)
|
||||
SDB_SET_INT32(pRaw, dataPos, redoActionNum)
|
||||
SDB_SET_INT32(pRaw, dataPos, undoActionNum)
|
||||
SDB_SET_INT32(pRaw, dataPos, pTrans->id, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pTrans->policy, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, redoLogNum, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, undoLogNum, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, commitLogNum, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, redoActionNum, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, undoActionNum, TRANS_ENCODE_OVER)
|
||||
|
||||
for (int32_t i = 0; i < redoLogNum; ++i) {
|
||||
SSdbRaw *pTmp = taosArrayGetP(pTrans->redoLogs, i);
|
||||
int32_t len = sdbGetRawTotalSize(pTmp);
|
||||
SDB_SET_INT32(pRaw, dataPos, len)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
|
||||
SDB_SET_INT32(pRaw, dataPos, len, TRANS_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len, TRANS_ENCODE_OVER)
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < undoLogNum; ++i) {
|
||||
SSdbRaw *pTmp = taosArrayGetP(pTrans->undoLogs, i);
|
||||
int32_t len = sdbGetRawTotalSize(pTmp);
|
||||
SDB_SET_INT32(pRaw, dataPos, len)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
|
||||
SDB_SET_INT32(pRaw, dataPos, len, TRANS_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len, TRANS_ENCODE_OVER)
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < commitLogNum; ++i) {
|
||||
SSdbRaw *pTmp = taosArrayGetP(pTrans->commitLogs, i);
|
||||
int32_t len = sdbGetRawTotalSize(pTmp);
|
||||
SDB_SET_INT32(pRaw, dataPos, len)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len)
|
||||
SDB_SET_INT32(pRaw, dataPos, len, TRANS_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pTmp, len, TRANS_ENCODE_OVER)
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < redoActionNum; ++i) {
|
||||
STransAction *pAction = taosArrayGet(pTrans->redoActions, i);
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet));
|
||||
SDB_SET_INT16(pRaw, dataPos, pAction->msgType)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->contLen)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen);
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pAction->msgType, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->acceptableCode, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->contLen, TRANS_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pAction->pCont, pAction->contLen, TRANS_ENCODE_OVER)
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < undoActionNum; ++i) {
|
||||
STransAction *pAction = taosArrayGet(pTrans->undoActions, i);
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet));
|
||||
SDB_SET_INT16(pRaw, dataPos, pAction->msgType)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->contLen)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pCont, pAction->contLen);
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)&pAction->epSet, sizeof(SEpSet), TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT16(pRaw, dataPos, pAction->msgType, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->acceptableCode, TRANS_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pAction->contLen, TRANS_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, (void *)pAction->pCont, pAction->contLen, TRANS_ENCODE_OVER)
|
||||
}
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, MND_TRANS_RESERVE_SIZE)
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
mTrace("trans:%d, encode to raw:%p, len:%d", pTrans->id, pRaw, dataPos);
|
||||
SDB_SET_RESERVE(pRaw, dataPos, MND_TRANS_RESERVE_SIZE, TRANS_ENCODE_OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, TRANS_ENCODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
TRANS_ENCODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("trans:%d, failed to encode to raw:%p len:%d since %s", pTrans->id, pRaw, dataPos, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("trans:%d, encode to raw:%p, row:%p len:%d", pTrans->id, pRaw, pTrans, dataPos);
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
||||
int32_t code = 0;
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
SSdbRow *pRow = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
char *pData = NULL;
|
||||
int32_t dataLen = 0;
|
||||
int8_t sver = 0;
|
||||
int32_t redoLogNum = 0;
|
||||
int32_t undoLogNum = 0;
|
||||
int32_t commitLogNum = 0;
|
||||
int32_t redoActionNum = 0;
|
||||
int32_t undoActionNum = 0;
|
||||
int32_t dataPos = 0;
|
||||
STransAction action = {0};
|
||||
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto TRANS_DECODE_OVER;
|
||||
|
||||
if (sver != MND_TRANS_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
mError("failed to get check soft ver from raw:%p since %s", pRaw, terrstr());
|
||||
return NULL;
|
||||
goto TRANS_DECODE_OVER;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(STrans));
|
||||
STrans *pTrans = sdbGetRowObj(pRow);
|
||||
if (pTrans == NULL) {
|
||||
mError("failed to alloc trans from raw:%p since %s", pRaw, terrstr());
|
||||
return NULL;
|
||||
}
|
||||
pRow = sdbAllocRow(sizeof(STrans));
|
||||
if (pRow == NULL) goto TRANS_DECODE_OVER;
|
||||
|
||||
pTrans = sdbGetRowObj(pRow);
|
||||
if (pTrans == NULL) goto TRANS_DECODE_OVER;
|
||||
|
||||
pTrans->redoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *));
|
||||
pTrans->undoLogs = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(void *));
|
||||
|
@ -185,139 +208,114 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
|||
pTrans->redoActions = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(STransAction));
|
||||
pTrans->undoActions = taosArrayInit(MND_TRANS_ARRAY_SIZE, sizeof(STransAction));
|
||||
|
||||
if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL ||
|
||||
pTrans->redoActions == NULL || pTrans->undoActions == NULL) {
|
||||
mDebug("trans:%d, failed to create array while parsed from raw:%p", pTrans->id, pRaw);
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TRANS_DECODE_OVER;
|
||||
}
|
||||
if (pTrans->redoLogs == NULL) goto TRANS_DECODE_OVER;
|
||||
if (pTrans->undoLogs == NULL) goto TRANS_DECODE_OVER;
|
||||
if (pTrans->commitLogs == NULL) goto TRANS_DECODE_OVER;
|
||||
if (pTrans->redoActions == NULL) goto TRANS_DECODE_OVER;
|
||||
if (pTrans->undoActions == NULL) goto TRANS_DECODE_OVER;
|
||||
|
||||
int32_t redoLogNum = 0;
|
||||
int32_t undoLogNum = 0;
|
||||
int32_t commitLogNum = 0;
|
||||
int32_t redoActionNum = 0;
|
||||
int32_t undoActionNum = 0;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pTrans->id)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, (int8_t *)&pTrans->policy)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &redoLogNum)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &undoLogNum)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &commitLogNum)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &redoActionNum)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &undoActionNum)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pTrans->id, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, (int8_t *)&pTrans->policy, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &redoLogNum, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &undoLogNum, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &commitLogNum, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &redoActionNum, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &undoActionNum, TRANS_DECODE_OVER)
|
||||
|
||||
for (int32_t i = 0; i < redoLogNum; ++i) {
|
||||
int32_t dataLen = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen)
|
||||
char *pData = malloc(dataLen);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pData, dataLen);
|
||||
|
||||
void *ret = taosArrayPush(pTrans->redoLogs, &pData);
|
||||
if (ret == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TRANS_DECODE_OVER;
|
||||
}
|
||||
SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER)
|
||||
pData = malloc(dataLen);
|
||||
if (pData == NULL) goto TRANS_DECODE_OVER;
|
||||
mTrace("raw:%p, is created", pData);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER);
|
||||
if (taosArrayPush(pTrans->redoLogs, &pData) == NULL) goto TRANS_DECODE_OVER;
|
||||
pData = NULL;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < undoLogNum; ++i) {
|
||||
int32_t dataLen = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen)
|
||||
char *pData = malloc(dataLen);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pData, dataLen);
|
||||
|
||||
void *ret = taosArrayPush(pTrans->undoLogs, &pData);
|
||||
if (ret == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TRANS_DECODE_OVER;
|
||||
}
|
||||
SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER)
|
||||
pData = malloc(dataLen);
|
||||
if (pData == NULL) goto TRANS_DECODE_OVER;
|
||||
mTrace("raw:%p, is created", pData);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER);
|
||||
if (taosArrayPush(pTrans->undoLogs, &pData) == NULL) goto TRANS_DECODE_OVER;
|
||||
pData = NULL;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < commitLogNum; ++i) {
|
||||
int32_t dataLen = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &dataLen)
|
||||
char *pData = malloc(dataLen);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pData, dataLen);
|
||||
|
||||
void *ret = taosArrayPush(pTrans->commitLogs, &pData);
|
||||
if (ret == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TRANS_DECODE_OVER;
|
||||
}
|
||||
SDB_GET_INT32(pRaw, dataPos, &dataLen, TRANS_DECODE_OVER)
|
||||
pData = malloc(dataLen);
|
||||
if (pData == NULL) goto TRANS_DECODE_OVER;
|
||||
mTrace("raw:%p, is created", pData);
|
||||
SDB_GET_BINARY(pRaw, dataPos, pData, dataLen, TRANS_DECODE_OVER);
|
||||
if (taosArrayPush(pTrans->commitLogs, &pData) == NULL) goto TRANS_DECODE_OVER;
|
||||
pData = NULL;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < redoActionNum; ++i) {
|
||||
STransAction action = {0};
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, (void *)&action.epSet, sizeof(SEpSet));
|
||||
SDB_GET_INT16(pRaw, pRow, dataPos, &action.msgType)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &action.contLen)
|
||||
SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), TRANS_DECODE_OVER);
|
||||
SDB_GET_INT16(pRaw, dataPos, &action.msgType, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.contLen, TRANS_DECODE_OVER)
|
||||
action.pCont = malloc(action.contLen);
|
||||
if (action.pCont == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TRANS_DECODE_OVER;
|
||||
}
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, action.pCont, action.contLen);
|
||||
|
||||
void *ret = taosArrayPush(pTrans->redoActions, &action);
|
||||
if (ret == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TRANS_DECODE_OVER;
|
||||
}
|
||||
if (action.pCont == NULL) goto TRANS_DECODE_OVER;
|
||||
SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, TRANS_DECODE_OVER);
|
||||
if (taosArrayPush(pTrans->redoActions, &action) == NULL) goto TRANS_DECODE_OVER;
|
||||
action.pCont = NULL;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < undoActionNum; ++i) {
|
||||
STransAction action = {0};
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, (void *)&action.epSet, sizeof(SEpSet));
|
||||
SDB_GET_INT16(pRaw, pRow, dataPos, &action.msgType)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &action.contLen)
|
||||
SDB_GET_BINARY(pRaw, dataPos, (void *)&action.epSet, sizeof(SEpSet), TRANS_DECODE_OVER);
|
||||
SDB_GET_INT16(pRaw, dataPos, &action.msgType, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.acceptableCode, TRANS_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &action.contLen, TRANS_DECODE_OVER)
|
||||
action.pCont = malloc(action.contLen);
|
||||
if (action.pCont == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TRANS_DECODE_OVER;
|
||||
}
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, action.pCont, action.contLen);
|
||||
|
||||
void *ret = taosArrayPush(pTrans->undoActions, &action);
|
||||
if (ret == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TRANS_DECODE_OVER;
|
||||
}
|
||||
if (action.pCont == NULL) goto TRANS_DECODE_OVER;
|
||||
SDB_GET_BINARY(pRaw, dataPos, action.pCont, action.contLen, TRANS_DECODE_OVER);
|
||||
if (taosArrayPush(pTrans->undoActions, &action) == NULL) goto TRANS_DECODE_OVER;
|
||||
action.pCont = NULL;
|
||||
}
|
||||
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, MND_TRANS_RESERVE_SIZE)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, MND_TRANS_RESERVE_SIZE, TRANS_DECODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
TRANS_DECODE_OVER:
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to parse from raw:%p since %s", pTrans->id, pRaw, tstrerror(errno));
|
||||
mndTransDrop(pTrans);
|
||||
terrno = code;
|
||||
if (terrno != 0) {
|
||||
mError("trans:%d, failed to parse from raw:%p since %s", pTrans->id, pRaw, terrstr());
|
||||
mndTransDropData(pTrans);
|
||||
tfree(pRow);
|
||||
tfree(pData);
|
||||
tfree(action.pCont);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("trans:%d, decode from raw:%p, data:%p", pTrans->id, pRaw, pTrans);
|
||||
mTrace("trans:%d, decode from raw:%p, row:%p", pTrans->id, pRaw, pTrans);
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) {
|
||||
pTrans->stage = TRN_STAGE_PREPARE;
|
||||
mTrace("trans:%d, perform insert action, data:%p", pTrans->id, pTrans);
|
||||
mTrace("trans:%d, perform insert action, row:%p", pTrans->id, pTrans);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) {
|
||||
mTrace("trans:%d, perform delete action, data:%p", pTrans->id, pTrans);
|
||||
|
||||
static void mndTransDropData(STrans *pTrans) {
|
||||
mndTransDropLogs(pTrans->redoLogs);
|
||||
mndTransDropLogs(pTrans->undoLogs);
|
||||
mndTransDropLogs(pTrans->commitLogs);
|
||||
mndTransDropActions(pTrans->redoActions);
|
||||
mndTransDropActions(pTrans->undoActions);
|
||||
}
|
||||
|
||||
static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans) {
|
||||
mTrace("trans:%d, perform delete action, row:%p", pTrans->id, pTrans);
|
||||
mndTransDropData(pTrans);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOldTrans, STrans *pNewTrans) {
|
||||
mTrace("trans:%d, perform update action, data:%p", pOldTrans->id, pOldTrans);
|
||||
mTrace("trans:%d, perform update action, old_row:%p new_row:%p", pOldTrans->id, pOldTrans, pNewTrans);
|
||||
pOldTrans->stage = pNewTrans->stage;
|
||||
return 0;
|
||||
}
|
||||
|
@ -367,6 +365,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
static void mndTransDropLogs(SArray *pArray) {
|
||||
if (pArray == NULL) return;
|
||||
for (int32_t i = 0; i < pArray->size; ++i) {
|
||||
SSdbRaw *pRaw = taosArrayGetP(pArray, i);
|
||||
sdbFreeRaw(pRaw);
|
||||
|
@ -376,6 +375,7 @@ static void mndTransDropLogs(SArray *pArray) {
|
|||
}
|
||||
|
||||
static void mndTransDropActions(SArray *pArray) {
|
||||
if (pArray == NULL) return;
|
||||
for (int32_t i = 0; i < pArray->size; ++i) {
|
||||
STransAction *pAction = taosArrayGet(pArray, i);
|
||||
free(pAction->pCont);
|
||||
|
@ -385,12 +385,7 @@ static void mndTransDropActions(SArray *pArray) {
|
|||
}
|
||||
|
||||
void mndTransDrop(STrans *pTrans) {
|
||||
mndTransDropLogs(pTrans->redoLogs);
|
||||
mndTransDropLogs(pTrans->undoLogs);
|
||||
mndTransDropLogs(pTrans->commitLogs);
|
||||
mndTransDropActions(pTrans->redoActions);
|
||||
mndTransDropActions(pTrans->undoActions);
|
||||
|
||||
mndTransDropData(pTrans);
|
||||
mDebug("trans:%d, is dropped, data:%p", pTrans->id, pTrans);
|
||||
tfree(pTrans);
|
||||
}
|
||||
|
@ -505,10 +500,31 @@ static int32_t mndTransRollback(SMnode *pMnode, STrans *pTrans) {
|
|||
}
|
||||
|
||||
static void mndTransSendRpcRsp(STrans *pTrans) {
|
||||
if (pTrans->rpcHandle != NULL) {
|
||||
mDebug("trans:%d, send rsp, ahandle:%p code:0x%x", pTrans->id, pTrans->rpcAHandle, pTrans->code & 0xFFFF);
|
||||
bool sendRsp = false;
|
||||
|
||||
if (pTrans->stage == TRN_STAGE_FINISHED) {
|
||||
sendRsp = true;
|
||||
}
|
||||
|
||||
if (pTrans->policy == TRN_POLICY_ROLLBACK) {
|
||||
if (pTrans->stage == TRN_STAGE_UNDO_LOG || pTrans->stage == TRN_STAGE_UNDO_ACTION ||
|
||||
pTrans->stage == TRN_STAGE_ROLLBACK) {
|
||||
sendRsp = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (pTrans->policy == TRN_POLICY_RETRY) {
|
||||
if (pTrans->stage == TRN_STAGE_REDO_ACTION && pTrans->failedTimes > 0) {
|
||||
sendRsp = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (sendRsp && pTrans->rpcHandle != NULL) {
|
||||
mDebug("trans:%d, send rsp, code:0x%x stage:%d app:%p", pTrans->id, pTrans->code & 0xFFFF, pTrans->stage,
|
||||
pTrans->rpcAHandle);
|
||||
SRpcMsg rspMsg = {.handle = pTrans->rpcHandle, .code = pTrans->code, .ahandle = pTrans->rpcAHandle};
|
||||
rpcSendResponse(&rspMsg);
|
||||
pTrans->rpcHandle = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -551,7 +567,8 @@ void mndTransProcessRsp(SMnodeMsg *pMsg) {
|
|||
pAction->errCode = pMsg->rpcMsg.code;
|
||||
}
|
||||
|
||||
mDebug("trans:%d, action:%d response is received, code:0x%x", transId, action, pMsg->rpcMsg.code);
|
||||
mDebug("trans:%d, action:%d response is received, code:0x%x, accept:0x%x", transId, action, pMsg->rpcMsg.code,
|
||||
pAction->acceptableCode);
|
||||
mndTransExecute(pMnode, pTrans);
|
||||
|
||||
HANDLE_ACTION_RSP_OVER:
|
||||
|
@ -622,12 +639,15 @@ static int32_t mndTransSendActionMsg(SMnode *pMnode, STrans *pTrans, SArray *pAr
|
|||
}
|
||||
memcpy(rpcMsg.pCont, pAction->pCont, pAction->contLen);
|
||||
|
||||
pAction->msgSent = 1;
|
||||
pAction->msgReceived = 0;
|
||||
pAction->errCode = 0;
|
||||
|
||||
mDebug("trans:%d, action:%d is sent", pTrans->id, action);
|
||||
mndSendMsgToDnode(pMnode, &pAction->epSet, &rpcMsg);
|
||||
if (mndSendReqToDnode(pMnode, &pAction->epSet, &rpcMsg) == 0) {
|
||||
mDebug("trans:%d, action:%d is sent", pTrans->id, action);
|
||||
pAction->msgSent = 1;
|
||||
pAction->msgReceived = 0;
|
||||
pAction->errCode = 0;
|
||||
} else {
|
||||
mDebug("trans:%d, action:%d not sent since %s", pTrans->id, action, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -648,7 +668,7 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA
|
|||
if (pAction == NULL) continue;
|
||||
if (pAction->msgSent && pAction->msgReceived) {
|
||||
numOfReceived++;
|
||||
if (pAction->errCode != 0) {
|
||||
if (pAction->errCode != 0 && pAction->errCode != pAction->acceptableCode) {
|
||||
errCode = pAction->errCode;
|
||||
}
|
||||
}
|
||||
|
@ -696,7 +716,7 @@ static bool mndTransPerformRedoLogStage(SMnode *pMnode, STrans *pTrans) {
|
|||
} else {
|
||||
pTrans->code = terrno;
|
||||
pTrans->stage = TRN_STAGE_UNDO_LOG;
|
||||
mError("trans:%d, stage from redoLog to undoLog", pTrans->id);
|
||||
mError("trans:%d, stage from redoLog to undoLog since %s", pTrans->id, terrstr());
|
||||
}
|
||||
|
||||
return continueExec;
|
||||
|
@ -770,7 +790,6 @@ static bool mndTransPerformCommitLogStage(SMnode *pMnode, STrans *pTrans) {
|
|||
pTrans->failedTimes++;
|
||||
mError("trans:%d, stage keep on commitLog since %s", pTrans->id, terrstr());
|
||||
continueExec = false;
|
||||
;
|
||||
}
|
||||
|
||||
return continueExec;
|
||||
|
@ -797,7 +816,7 @@ static bool mndTransPerformUndoActionStage(SMnode *pMnode, STrans *pTrans) {
|
|||
int32_t code = mndTransExecuteUndoActions(pMnode, pTrans);
|
||||
|
||||
if (code == 0) {
|
||||
pTrans->stage = TRN_STAGE_REDO_LOG;
|
||||
pTrans->stage = TRN_STAGE_UNDO_LOG;
|
||||
mDebug("trans:%d, stage from undoAction to undoLog", pTrans->id);
|
||||
continueExec = true;
|
||||
} else if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
|
@ -820,7 +839,6 @@ static bool mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans) {
|
|||
pTrans->stage = TRN_STAGE_FINISHED;
|
||||
mDebug("trans:%d, stage from rollback to finished", pTrans->id);
|
||||
continueExec = true;
|
||||
;
|
||||
} else {
|
||||
pTrans->failedTimes++;
|
||||
mError("trans:%d, stage keep on rollback since %s", pTrans->id, terrstr());
|
||||
|
@ -886,13 +904,15 @@ static void mndTransExecute(SMnode *pMnode, STrans *pTrans) {
|
|||
}
|
||||
}
|
||||
|
||||
if (pTrans->stage == TRN_STAGE_FINISHED) {
|
||||
mndTransSendRpcRsp(pTrans);
|
||||
}
|
||||
mndTransSendRpcRsp(pTrans);
|
||||
}
|
||||
|
||||
static int32_t mndProcessTransMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
mndTransPullup(pMsg->pMnode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mndTransPullup(SMnode *pMnode) {
|
||||
STrans *pTrans = NULL;
|
||||
void *pIter = NULL;
|
||||
|
||||
|
@ -904,5 +924,3 @@ static int32_t mndProcessTransMsg(SMnodeMsg *pMsg) {
|
|||
sdbRelease(pMnode->pSdb, pTrans);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mndProcessTransRsp(SMnodeMsg *pMsg) { return 0; }
|
|
@ -16,7 +16,6 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "mndUser.h"
|
||||
#include "mndShow.h"
|
||||
#include "mndSync.h"
|
||||
#include "mndTrans.h"
|
||||
#include "tkey.h"
|
||||
|
||||
|
@ -28,13 +27,13 @@ static SSdbRaw *mndUserActionEncode(SUserObj *pUser);
|
|||
static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser);
|
||||
static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser);
|
||||
static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOldUser, SUserObj *pNewUser);
|
||||
static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndGetUserMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveUsers(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||
static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew);
|
||||
static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pReq);
|
||||
static int32_t mndProcessCreateUserReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessAlterUserReq(SMnodeMsg *pReq);
|
||||
static int32_t mndProcessDropUserReq(SMnodeMsg *pReq);
|
||||
static int32_t mndGetUserMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveUsers(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows);
|
||||
static void mndCancelGetNextUser(SMnode *pMnode, void *pIter);
|
||||
|
||||
int32_t mndInitUser(SMnode *pMnode) {
|
||||
|
@ -47,9 +46,9 @@ int32_t mndInitUser(SMnode *pMnode) {
|
|||
.updateFp = (SdbUpdateFp)mndUserActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndUserActionDelete};
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_USER, mndProcessCreateUserMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_ALTER_USER, mndProcessAlterUserMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_DROP_USER, mndProcessDropUserMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_USER, mndProcessCreateUserReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_ALTER_USER, mndProcessAlterUserReq);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_DROP_USER, mndProcessDropUserReq);
|
||||
|
||||
mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_USER, mndGetUserMeta);
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_USER, mndRetrieveUsers);
|
||||
|
@ -75,7 +74,7 @@ static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char
|
|||
if (pRaw == NULL) return -1;
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
mDebug("user:%s, will be created while deploy sdb", userObj.user);
|
||||
mDebug("user:%s, will be created while deploy sdb, raw:%p", userObj.user, pRaw);
|
||||
return sdbWrite(pMnode->pSdb, pRaw);
|
||||
}
|
||||
|
||||
|
@ -94,50 +93,75 @@ static int32_t mndCreateDefaultUsers(SMnode *pMnode) {
|
|||
}
|
||||
|
||||
static SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, TSDB_USER_VER_NUMBER, sizeof(SUserObj) + TSDB_USER_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
if (pRaw == NULL) goto USER_ENCODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->pass, TSDB_PASSWORD_LEN)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN)
|
||||
SDB_SET_INT64(pRaw, dataPos, pUser->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pUser->updateTime)
|
||||
SDB_SET_INT8(pRaw, dataPos, pUser->superUser)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_USER_RESERVE_SIZE)
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN, USER_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->pass, TSDB_PASSWORD_LEN, USER_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN, USER_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pUser->createdTime, USER_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pUser->updateTime, USER_ENCODE_OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pUser->superUser, USER_ENCODE_OVER)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_USER_RESERVE_SIZE, USER_ENCODE_OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, USER_ENCODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
USER_ENCODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("user:%s, failed to encode to raw:%p since %s", pUser->user, pRaw, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("user:%s, encode to raw:%p, row:%p", pUser->user, pRaw, pUser);
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto USER_DECODE_OVER;
|
||||
|
||||
if (sver != TSDB_USER_VER_NUMBER) {
|
||||
mError("failed to decode user since %s", terrstr());
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
goto USER_DECODE_OVER;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SUserObj));
|
||||
if (pRow == NULL) goto USER_DECODE_OVER;
|
||||
|
||||
SUserObj *pUser = sdbGetRowObj(pRow);
|
||||
if (pUser == NULL) goto USER_DECODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_BINARY(pRaw, dataPos, pUser->user, TSDB_USER_LEN, USER_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pUser->pass, TSDB_PASSWORD_LEN, USER_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pUser->acct, TSDB_USER_LEN, USER_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pUser->createdTime, USER_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pUser->updateTime, USER_DECODE_OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pUser->superUser, USER_DECODE_OVER)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_USER_RESERVE_SIZE, USER_DECODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
USER_DECODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("user:%s, failed to decode from raw:%p since %s", pUser->user, pRaw, terrstr());
|
||||
tfree(pRow);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SUserObj));
|
||||
SUserObj *pUser = sdbGetRowObj(pRow);
|
||||
if (pUser == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->user, TSDB_USER_LEN)
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->pass, TSDB_PASSWORD_LEN)
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pUser->acct, TSDB_USER_LEN)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pUser->updateTime)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pUser->superUser)
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_USER_RESERVE_SIZE)
|
||||
|
||||
mTrace("user:%s, decode from raw:%p, row:%p", pUser->user, pRaw, pUser);
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) {
|
||||
mTrace("user:%s, perform insert action", pUser->user);
|
||||
mTrace("user:%s, perform insert action, row:%p", pUser->user, pUser);
|
||||
pUser->prohibitDbHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (pUser->prohibitDbHash == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -158,7 +182,7 @@ static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) {
|
|||
}
|
||||
|
||||
static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
|
||||
mTrace("user:%s, perform delete action", pUser->user);
|
||||
mTrace("user:%s, perform delete action, row:%p", pUser->user, pUser);
|
||||
if (pUser->prohibitDbHash) {
|
||||
taosHashCleanup(pUser->prohibitDbHash);
|
||||
pUser->prohibitDbHash = NULL;
|
||||
|
@ -167,10 +191,10 @@ static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOldUser, SUserObj *pNewUser) {
|
||||
mTrace("user:%s, perform update action", pOldUser->user);
|
||||
memcpy(pOldUser->pass, pNewUser->pass, TSDB_PASSWORD_LEN);
|
||||
pOldUser->updateTime = pNewUser->updateTime;
|
||||
static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOld, SUserObj *pNew) {
|
||||
mTrace("user:%s, perform update action, old_row:%p new_row:%p", pOld->user, pOld, pNew);
|
||||
memcpy(pOld->pass, pNew->pass, TSDB_PASSWORD_LEN);
|
||||
pOld->updateTime = pNew->updateTime;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -188,7 +212,7 @@ void mndReleaseUser(SMnode *pMnode, SUserObj *pUser) {
|
|||
sdbRelease(pSdb, pUser);
|
||||
}
|
||||
|
||||
static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pMsg) {
|
||||
static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass, SMnodeMsg *pReq) {
|
||||
SUserObj userObj = {0};
|
||||
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
||||
tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
|
||||
|
@ -197,7 +221,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass,
|
|||
userObj.updateTime = userObj.createdTime;
|
||||
userObj.superUser = 0;
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg);
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("user:%s, failed to create since %s", user, terrstr());
|
||||
return -1;
|
||||
|
@ -222,9 +246,9 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, char *user, char *pass,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SCreateUserMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndProcessCreateUserReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SCreateUserReq *pCreate = pReq->rpcMsg.pCont;
|
||||
|
||||
mDebug("user:%s, start to create", pCreate->user);
|
||||
|
||||
|
@ -240,23 +264,23 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pCreate->user);
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pCreate->user);
|
||||
if (pUser != NULL) {
|
||||
sdbRelease(pMnode->pSdb, pUser);
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
terrno = TSDB_CODE_MND_USER_ALREADY_EXIST;
|
||||
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user);
|
||||
SUserObj *pOperUser = mndAcquireUser(pMnode, pReq->user);
|
||||
if (pOperUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mndCreateUser(pMnode, pOperUser->acct, pCreate->user, pCreate->pass, pMsg);
|
||||
sdbRelease(pMnode->pSdb, pOperUser);
|
||||
int32_t code = mndCreateUser(pMnode, pOperUser->acct, pCreate->user, pCreate->pass, pReq);
|
||||
mndReleaseUser(pMnode, pOperUser);
|
||||
|
||||
if (code != 0) {
|
||||
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
|
||||
|
@ -266,15 +290,15 @@ static int32_t mndProcessCreateUserMsg(SMnodeMsg *pMsg) {
|
|||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOldUser, SUserObj *pNewUser, SMnodeMsg *pMsg) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg);
|
||||
static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SMnodeMsg *pReq) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("user:%s, failed to update since %s", pOldUser->user, terrstr());
|
||||
mError("user:%s, failed to update since %s", pOld->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
mDebug("trans:%d, used to update user:%s", pTrans->id, pOldUser->user);
|
||||
mDebug("trans:%d, used to update user:%s", pTrans->id, pOld->user);
|
||||
|
||||
SSdbRaw *pRedoRaw = mndUserActionEncode(pNewUser);
|
||||
SSdbRaw *pRedoRaw = mndUserActionEncode(pNew);
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
|
@ -292,9 +316,9 @@ static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOldUser, SUserObj *pNewU
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SAlterUserMsg *pAlter = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndProcessAlterUserReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SAlterUserReq *pAlter = pReq->rpcMsg.pCont;
|
||||
|
||||
mDebug("user:%s, start to alter", pAlter->user);
|
||||
|
||||
|
@ -310,15 +334,16 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pAlter->user);
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pAlter->user);
|
||||
if (pUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_USER_NOT_EXIST;
|
||||
mError("user:%s, failed to alter since %s", pAlter->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user);
|
||||
SUserObj *pOperUser = mndAcquireUser(pMnode, pReq->user);
|
||||
if (pOperUser == NULL) {
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
mError("user:%s, failed to alter since %s", pAlter->user, terrstr());
|
||||
return -1;
|
||||
|
@ -330,8 +355,9 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) {
|
|||
taosEncryptPass((uint8_t *)pAlter->pass, strlen(pAlter->pass), pUser->pass);
|
||||
newUser.updateTime = taosGetTimestampMs();
|
||||
|
||||
int32_t code = mndUpdateUser(pMnode, pUser, &newUser, pMsg);
|
||||
sdbRelease(pMnode->pSdb, pOperUser);
|
||||
int32_t code = mndUpdateUser(pMnode, pUser, &newUser, pReq);
|
||||
mndReleaseUser(pMnode, pOperUser);
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
|
||||
if (code != 0) {
|
||||
mError("user:%s, failed to alter since %s", pAlter->user, terrstr());
|
||||
|
@ -341,8 +367,8 @@ static int32_t mndProcessAlterUserMsg(SMnodeMsg *pMsg) {
|
|||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pMsg, SUserObj *pUser) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pMsg->rpcMsg);
|
||||
static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pReq, SUserObj *pUser) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("user:%s, failed to drop since %s", pUser->user, terrstr());
|
||||
return -1;
|
||||
|
@ -367,9 +393,9 @@ static int32_t mndDropUser(SMnode *pMnode, SMnodeMsg *pMsg, SUserObj *pUser) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SDropUserMsg *pDrop = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndProcessDropUserReq(SMnodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SDropUserReq *pDrop = pReq->rpcMsg.pCont;
|
||||
|
||||
mDebug("user:%s, start to drop", pDrop->user);
|
||||
|
||||
|
@ -379,22 +405,24 @@ static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
SUserObj *pUser = sdbAcquire(pMnode->pSdb, SDB_USER, pDrop->user);
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pDrop->user);
|
||||
if (pUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_USER_NOT_EXIST;
|
||||
mError("user:%s, failed to drop since %s", pDrop->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SUserObj *pOperUser = sdbAcquire(pMnode->pSdb, SDB_USER, pMsg->user);
|
||||
SUserObj *pOperUser = mndAcquireUser(pMnode, pReq->user);
|
||||
if (pOperUser == NULL) {
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
mError("user:%s, failed to drop since %s", pDrop->user, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mndDropUser(pMnode, pMsg, pUser);
|
||||
sdbRelease(pMnode->pSdb, pOperUser);
|
||||
int32_t code = mndDropUser(pMnode, pReq, pUser);
|
||||
mndReleaseUser(pMnode, pOperUser);
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
|
||||
if (code != 0) {
|
||||
mError("user:%s, failed to drop since %s", pDrop->user, terrstr());
|
||||
|
@ -404,8 +432,8 @@ static int32_t mndProcessDropUserMsg(SMnodeMsg *pMsg) {
|
|||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndGetUserMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndGetUserMeta(SMnodeMsg *pReq, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
int32_t cols = 0;
|
||||
|
@ -450,8 +478,8 @@ static int32_t mndGetUserMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *p
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveUsers(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
static int32_t mndRetrieveUsers(SMnodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pReq->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfRows = 0;
|
||||
SUserObj *pUser = NULL;
|
||||
|
|
|
@ -70,77 +70,102 @@ int32_t mndInitVgroup(SMnode *pMnode) {
|
|||
void mndCleanupVgroup(SMnode *pMnode) {}
|
||||
|
||||
SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_VGROUP, TSDB_VGROUP_VER_NUMBER, sizeof(SVgObj) + TSDB_VGROUP_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
if (pRaw == NULL) goto VG_ENCODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_INT32(pRaw, dataPos, pVgroup->vgId)
|
||||
SDB_SET_INT64(pRaw, dataPos, pVgroup->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pVgroup->updateTime)
|
||||
SDB_SET_INT32(pRaw, dataPos, pVgroup->version)
|
||||
SDB_SET_INT32(pRaw, dataPos, pVgroup->hashBegin)
|
||||
SDB_SET_INT32(pRaw, dataPos, pVgroup->hashEnd)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pVgroup->dbName, TSDB_DB_FNAME_LEN)
|
||||
SDB_SET_INT64(pRaw, dataPos, pVgroup->dbUid)
|
||||
SDB_SET_INT8(pRaw, dataPos, pVgroup->replica)
|
||||
SDB_SET_INT32(pRaw, dataPos, pVgroup->vgId, VG_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pVgroup->createdTime, VG_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pVgroup->updateTime, VG_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pVgroup->version, VG_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pVgroup->hashBegin, VG_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pVgroup->hashEnd, VG_ENCODE_OVER)
|
||||
SDB_SET_BINARY(pRaw, dataPos, pVgroup->dbName, TSDB_DB_FNAME_LEN, VG_ENCODE_OVER)
|
||||
SDB_SET_INT64(pRaw, dataPos, pVgroup->dbUid, VG_ENCODE_OVER)
|
||||
SDB_SET_INT8(pRaw, dataPos, pVgroup->replica, VG_ENCODE_OVER)
|
||||
for (int8_t i = 0; i < pVgroup->replica; ++i) {
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[i];
|
||||
SDB_SET_INT32(pRaw, dataPos, pVgid->dnodeId)
|
||||
SDB_SET_INT32(pRaw, dataPos, pVgid->dnodeId, VG_ENCODE_OVER)
|
||||
}
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_VGROUP_RESERVE_SIZE)
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_VGROUP_RESERVE_SIZE, VG_ENCODE_OVER)
|
||||
SDB_SET_DATALEN(pRaw, dataPos, VG_ENCODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
VG_ENCODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("vgId:%d, failed to encode to raw:%p since %s", pVgroup->vgId, pRaw, terrstr());
|
||||
sdbFreeRaw(pRaw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("vgId:%d, encode to raw:%p, row:%p", pVgroup->vgId, pRaw, pVgroup);
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto VG_DECODE_OVER;
|
||||
|
||||
if (sver != TSDB_VGROUP_VER_NUMBER) {
|
||||
mError("failed to decode vgroup since %s", terrstr());
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
return NULL;
|
||||
goto VG_DECODE_OVER;
|
||||
}
|
||||
|
||||
SSdbRow *pRow = sdbAllocRow(sizeof(SVgObj));
|
||||
SVgObj *pVgroup = sdbGetRowObj(pRow);
|
||||
if (pVgroup == NULL) return NULL;
|
||||
if (pRow == NULL) goto VG_DECODE_OVER;
|
||||
|
||||
SVgObj *pVgroup = sdbGetRowObj(pRow);
|
||||
if (pVgroup == NULL) goto VG_DECODE_OVER;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->vgId)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pVgroup->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pVgroup->updateTime)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->version)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->hashBegin)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pVgroup->hashEnd)
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pVgroup->dbName, TSDB_DB_FNAME_LEN)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pVgroup->dbUid)
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pVgroup->replica)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pVgroup->vgId, VG_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pVgroup->createdTime, VG_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pVgroup->updateTime, VG_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pVgroup->version, VG_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pVgroup->hashBegin, VG_DECODE_OVER)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pVgroup->hashEnd, VG_DECODE_OVER)
|
||||
SDB_GET_BINARY(pRaw, dataPos, pVgroup->dbName, TSDB_DB_FNAME_LEN, VG_DECODE_OVER)
|
||||
SDB_GET_INT64(pRaw, dataPos, &pVgroup->dbUid, VG_DECODE_OVER)
|
||||
SDB_GET_INT8(pRaw, dataPos, &pVgroup->replica, VG_DECODE_OVER)
|
||||
for (int8_t i = 0; i < pVgroup->replica; ++i) {
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[i];
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pVgid->dnodeId)
|
||||
SDB_GET_INT32(pRaw, dataPos, &pVgid->dnodeId, VG_DECODE_OVER)
|
||||
if (pVgroup->replica == 1) {
|
||||
pVgid->role = TAOS_SYNC_STATE_LEADER;
|
||||
}
|
||||
}
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_VGROUP_RESERVE_SIZE)
|
||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_VGROUP_RESERVE_SIZE, VG_DECODE_OVER)
|
||||
|
||||
terrno = 0;
|
||||
|
||||
VG_DECODE_OVER:
|
||||
if (terrno != 0) {
|
||||
mError("vgId:%d, failed to decode from raw:%p since %s", pVgroup->vgId, pRaw, terrstr());
|
||||
tfree(pRow);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mTrace("vgId:%d, decode from raw:%p, row:%p", pVgroup->vgId, pRaw, pVgroup);
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mndVgroupActionInsert(SSdb *pSdb, SVgObj *pVgroup) {
|
||||
mTrace("vgId:%d, perform insert action", pVgroup->vgId);
|
||||
mTrace("vgId:%d, perform insert action, row:%p", pVgroup->vgId, pVgroup);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndVgroupActionDelete(SSdb *pSdb, SVgObj *pVgroup) {
|
||||
mTrace("vgId:%d, perform delete action", pVgroup->vgId);
|
||||
mTrace("vgId:%d, perform delete action, row:%p", pVgroup->vgId, pVgroup);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndVgroupActionUpdate(SSdb *pSdb, SVgObj *pOldVgroup, SVgObj *pNewVgroup) {
|
||||
mTrace("vgId:%d, perform update action", pOldVgroup->vgId);
|
||||
mTrace("vgId:%d, perform update action, old_row:%p new_row:%p", pOldVgroup->vgId, pOldVgroup, pNewVgroup);
|
||||
pOldVgroup->updateTime = pNewVgroup->updateTime;
|
||||
pOldVgroup->version = pNewVgroup->version;
|
||||
pOldVgroup->hashBegin = pNewVgroup->hashBegin;
|
||||
|
|
|
@ -34,21 +34,27 @@
|
|||
#include "mndUser.h"
|
||||
#include "mndVgroup.h"
|
||||
|
||||
void mndSendMsgToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
if (pMnode != NULL && pMnode->sendMsgToDnodeFp != NULL) {
|
||||
(*pMnode->sendMsgToDnodeFp)(pMnode->pDnode, pEpSet, pMsg);
|
||||
int32_t mndSendReqToDnode(SMnode *pMnode, SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||
if (pMnode == NULL || pMnode->sendReqToDnodeFp == NULL) {
|
||||
terrno = TSDB_CODE_MND_NOT_READY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (*pMnode->sendReqToDnodeFp)(pMnode->pDnode, pEpSet, pMsg);
|
||||
}
|
||||
|
||||
void mndSendMsgToMnode(SMnode *pMnode, SRpcMsg *pMsg) {
|
||||
if (pMnode != NULL && pMnode->sendMsgToMnodeFp != NULL) {
|
||||
(*pMnode->sendMsgToMnodeFp)(pMnode->pDnode, pMsg);
|
||||
int32_t mndSendReqToMnode(SMnode *pMnode, SRpcMsg *pMsg) {
|
||||
if (pMnode == NULL || pMnode->sendReqToDnodeFp == NULL) {
|
||||
terrno = TSDB_CODE_MND_NOT_READY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (*pMnode->sendReqToMnodeFp)(pMnode->pDnode, pMsg);
|
||||
}
|
||||
|
||||
void mndSendRedirectMsg(SMnode *pMnode, SRpcMsg *pMsg) {
|
||||
if (pMnode != NULL && pMnode->sendRedirectMsgFp != NULL) {
|
||||
(*pMnode->sendRedirectMsgFp)(pMnode->pDnode, pMsg);
|
||||
void mndSendRedirectRsp(SMnode *pMnode, SRpcMsg *pMsg) {
|
||||
if (pMnode != NULL && pMnode->sendRedirectRspFp != NULL) {
|
||||
(*pMnode->sendRedirectRspFp)(pMnode->pDnode, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,11 +62,8 @@ static void mndTransReExecute(void *param, void *tmrId) {
|
|||
SMnode *pMnode = param;
|
||||
if (mndIsMaster(pMnode)) {
|
||||
STransMsg *pMsg = rpcMallocCont(sizeof(STransMsg));
|
||||
SEpSet epSet = {.inUse = 0, .numOfEps = 1};
|
||||
epSet.port[0] = pMnode->replicas[pMnode->selfIndex].port;
|
||||
memcpy(epSet.fqdn[0], pMnode->replicas[pMnode->selfIndex].fqdn, TSDB_FQDN_LEN);
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS, .pCont = pMsg, .contLen = sizeof(STransMsg)};
|
||||
mndSendMsgToDnode(pMnode, &epSet, &rpcMsg);
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS, .pCont = pMsg, .contLen = sizeof(STransMsg)};
|
||||
pMnode->putReqToMWriteQFp(pMnode->pDnode, &rpcMsg);
|
||||
}
|
||||
|
||||
taosTmrReset(mndTransReExecute, 3000, pMnode, pMnode->timer, &pMnode->transTimer);
|
||||
|
@ -76,7 +79,7 @@ static int32_t mndInitTimer(SMnode *pMnode) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (taosTmrReset(mndTransReExecute, 1000, pMnode, pMnode->timer, &pMnode->transTimer)) {
|
||||
if (taosTmrReset(mndTransReExecute, 6000, pMnode, pMnode->timer, &pMnode->transTimer)) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
@ -185,7 +188,7 @@ static void mndCleanupSteps(SMnode *pMnode, int32_t pos) {
|
|||
|
||||
for (int32_t s = pos; s >= 0; s--) {
|
||||
SMnodeStep *pStep = taosArrayGet(pMnode->pSteps, s);
|
||||
mDebug("step:%s will cleanup", pStep->name);
|
||||
mDebug("%s will cleanup", pStep->name);
|
||||
if (pStep->cleanupFp != NULL) {
|
||||
(*pStep->cleanupFp)(pMnode);
|
||||
}
|
||||
|
@ -202,19 +205,15 @@ static int32_t mndExecSteps(SMnode *pMnode) {
|
|||
SMnodeStep *pStep = taosArrayGet(pMnode->pSteps, pos);
|
||||
if (pStep->initFp == NULL) continue;
|
||||
|
||||
// (*pMnode->reportProgress)(pStep->name, "start initialize");
|
||||
|
||||
if ((*pStep->initFp)(pMnode) != 0) {
|
||||
int32_t code = terrno;
|
||||
mError("step:%s exec failed since %s, start to cleanup", pStep->name, terrstr());
|
||||
mError("%s exec failed since %s, start to cleanup", pStep->name, terrstr());
|
||||
mndCleanupSteps(pMnode, pos);
|
||||
terrno = code;
|
||||
return -1;
|
||||
} else {
|
||||
mDebug("step:%s is initialized", pStep->name);
|
||||
mDebug("%s is initialized", pStep->name);
|
||||
}
|
||||
|
||||
// (*pMnode->reportProgress)(pStep->name, "initialize completed");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -227,9 +226,10 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) {
|
|||
pMnode->selfIndex = pOption->selfIndex;
|
||||
memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA);
|
||||
pMnode->pDnode = pOption->pDnode;
|
||||
pMnode->sendMsgToDnodeFp = pOption->sendMsgToDnodeFp;
|
||||
pMnode->sendMsgToMnodeFp = pOption->sendMsgToMnodeFp;
|
||||
pMnode->sendRedirectMsgFp = pOption->sendRedirectMsgFp;
|
||||
pMnode->putReqToMWriteQFp = pOption->putReqToMWriteQFp;
|
||||
pMnode->sendReqToDnodeFp = pOption->sendReqToDnodeFp;
|
||||
pMnode->sendReqToMnodeFp = pOption->sendReqToMnodeFp;
|
||||
pMnode->sendRedirectRspFp = pOption->sendRedirectRspFp;
|
||||
pMnode->cfg.sver = pOption->cfg.sver;
|
||||
pMnode->cfg.enableTelem = pOption->cfg.enableTelem;
|
||||
pMnode->cfg.statusInterval = pOption->cfg.statusInterval;
|
||||
|
@ -240,8 +240,9 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) {
|
|||
pMnode->cfg.gitinfo = strdup(pOption->cfg.gitinfo);
|
||||
pMnode->cfg.buildinfo = strdup(pOption->cfg.buildinfo);
|
||||
|
||||
if (pMnode->sendMsgToDnodeFp == NULL || pMnode->sendMsgToMnodeFp == NULL || pMnode->sendRedirectMsgFp == NULL ||
|
||||
pMnode->dnodeId < 0 || pMnode->clusterId < 0 || pMnode->cfg.statusInterval < 1) {
|
||||
if (pMnode->sendReqToDnodeFp == NULL || pMnode->sendReqToMnodeFp == NULL || pMnode->sendRedirectRspFp == NULL ||
|
||||
pMnode->putReqToMWriteQFp == NULL || pMnode->dnodeId < 0 || pMnode->clusterId < 0 ||
|
||||
pMnode->cfg.statusInterval < 1) {
|
||||
terrno = TSDB_CODE_MND_INVALID_OPTIONS;
|
||||
return -1;
|
||||
}
|
||||
|
@ -361,29 +362,31 @@ SMnodeMsg *mndInitMsg(SMnode *pMnode, SRpcMsg *pRpcMsg) {
|
|||
SMnodeMsg *pMsg = taosAllocateQitem(sizeof(SMnodeMsg));
|
||||
if (pMsg == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("RPC:%p, app:%p failed to create msg since %s", pRpcMsg->handle, pRpcMsg->ahandle, terrstr());
|
||||
mError("failed to create msg since %s, app:%p RPC:%p", terrstr(), pRpcMsg->ahandle, pRpcMsg->handle);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SRpcConnInfo connInfo = {0};
|
||||
if ((pRpcMsg->msgType & 1U) && rpcGetConnInfo(pRpcMsg->handle, &connInfo) != 0) {
|
||||
taosFreeQitem(pMsg);
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
mError("RPC:%p, app:%p failed to create msg since %s", pRpcMsg->handle, pRpcMsg->ahandle, terrstr());
|
||||
return NULL;
|
||||
if (pRpcMsg->msgType != TDMT_MND_TRANS) {
|
||||
SRpcConnInfo connInfo = {0};
|
||||
if ((pRpcMsg->msgType & 1U) && rpcGetConnInfo(pRpcMsg->handle, &connInfo) != 0) {
|
||||
taosFreeQitem(pMsg);
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
mError("failed to create msg since %s, app:%p RPC:%p", terrstr(), pRpcMsg->ahandle, pRpcMsg->handle);
|
||||
return NULL;
|
||||
}
|
||||
memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN);
|
||||
}
|
||||
memcpy(pMsg->user, connInfo.user, TSDB_USER_LEN);
|
||||
|
||||
pMsg->pMnode = pMnode;
|
||||
pMsg->rpcMsg = *pRpcMsg;
|
||||
pMsg->createdTime = taosGetTimestampSec();
|
||||
|
||||
mTrace("msg:%p, app:%p is created, RPC:%p", pMsg, pRpcMsg->ahandle, pRpcMsg->handle);
|
||||
mTrace("msg:%p, is created, app:%p RPC:%p user:%s", pMsg, pRpcMsg->ahandle, pRpcMsg->handle, pMsg->user);
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
void mndCleanupMsg(SMnodeMsg *pMsg) {
|
||||
mTrace("msg:%p, app:%p is destroyed, RPC:%p", pMsg, pMsg->rpcMsg.ahandle, pMsg->rpcMsg.handle);
|
||||
mTrace("msg:%p, is destroyed, app:%p RPC:%p", pMsg, pMsg->rpcMsg.ahandle, pMsg->rpcMsg.handle);
|
||||
rpcFreeCont(pMsg->rpcMsg.pCont);
|
||||
pMsg->rpcMsg.pCont = NULL;
|
||||
taosFreeQitem(pMsg);
|
||||
|
@ -401,43 +404,43 @@ void mndProcessMsg(SMnodeMsg *pMsg) {
|
|||
void *ahandle = pMsg->rpcMsg.ahandle;
|
||||
bool isReq = (msgType & 1U);
|
||||
|
||||
mTrace("msg:%p, app:%p type:%s will be processed", pMsg, ahandle, TMSG_INFO(msgType));
|
||||
mTrace("msg:%p, type:%s will be processed, app:%p", pMsg, TMSG_INFO(msgType), ahandle);
|
||||
|
||||
if (isReq && !mndIsMaster(pMnode)) {
|
||||
code = TSDB_CODE_APP_NOT_READY;
|
||||
mDebug("msg:%p, app:%p failed to process since %s", pMsg, ahandle, terrstr());
|
||||
mDebug("msg:%p, failed to process since %s, app:%p", pMsg, terrstr(), ahandle);
|
||||
goto PROCESS_RPC_END;
|
||||
}
|
||||
|
||||
if (isReq && pMsg->rpcMsg.pCont == NULL) {
|
||||
code = TSDB_CODE_MND_INVALID_MSG_LEN;
|
||||
mError("msg:%p, app:%p failed to process since %s", pMsg, ahandle, terrstr());
|
||||
mError("msg:%p, failed to process since %s, app:%p", pMsg, terrstr(), ahandle);
|
||||
goto PROCESS_RPC_END;
|
||||
}
|
||||
|
||||
MndMsgFp fp = pMnode->msgFp[TMSG_INDEX(msgType)];
|
||||
if (fp == NULL) {
|
||||
code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
mError("msg:%p, app:%p failed to process since no handle", pMsg, ahandle);
|
||||
mError("msg:%p, failed to process since no msg handle, app:%p", pMsg, ahandle);
|
||||
goto PROCESS_RPC_END;
|
||||
}
|
||||
|
||||
code = (*fp)(pMsg);
|
||||
if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
mTrace("msg:%p, app:%p in progressing", pMsg, ahandle);
|
||||
mTrace("msg:%p, in progress, app:%p", pMsg, ahandle);
|
||||
return;
|
||||
} else if (code != 0) {
|
||||
code = terrno;
|
||||
mError("msg:%p, app:%p failed to process since %s", pMsg, ahandle, terrstr());
|
||||
mError("msg:%p, failed to process since %s, app:%p", pMsg, terrstr(), ahandle);
|
||||
goto PROCESS_RPC_END;
|
||||
} else {
|
||||
mTrace("msg:%p, app:%p is processed", pMsg, ahandle);
|
||||
mTrace("msg:%p, is processed, app:%p", pMsg, ahandle);
|
||||
}
|
||||
|
||||
PROCESS_RPC_END:
|
||||
if (isReq) {
|
||||
if (code == TSDB_CODE_APP_NOT_READY) {
|
||||
mndSendRedirectMsg(pMnode, &pMsg->rpcMsg);
|
||||
mndSendRedirectRsp(pMnode, &pMsg->rpcMsg);
|
||||
} else if (code != 0) {
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->rpcMsg.handle, .code = code};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
enable_testing()
|
||||
|
||||
add_subdirectory(user)
|
||||
add_subdirectory(acct)
|
||||
add_subdirectory(trans)
|
||||
add_subdirectory(qnode)
|
||||
add_subdirectory(snode)
|
||||
add_subdirectory(bnode)
|
||||
add_subdirectory(show)
|
|
@ -0,0 +1,11 @@
|
|||
aux_source_directory(. ACCT_SRC)
|
||||
add_executable(mnode_test_acct ${ACCT_SRC})
|
||||
target_link_libraries(
|
||||
mnode_test_acct
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME mnode_test_acct
|
||||
COMMAND mnode_test_acct
|
||||
)
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* @file acct.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief MNODE module acct tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-04
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class MndTestAcct : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_acct", 9012); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase MndTestAcct::test;
|
||||
|
||||
TEST_F(MndTestAcct, 01_Create_Acct) {
|
||||
int32_t contLen = sizeof(SCreateAcctReq);
|
||||
|
||||
SCreateAcctReq* pReq = (SCreateAcctReq*)rpcMallocCont(contLen);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_ACCT, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
||||
}
|
||||
|
||||
TEST_F(MndTestAcct, 02_Alter_Acct) {
|
||||
int32_t contLen = sizeof(SCreateAcctReq);
|
||||
|
||||
SAlterAcctReq* pReq = (SAlterAcctReq*)rpcMallocCont(contLen);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_ACCT, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
||||
}
|
||||
|
||||
TEST_F(MndTestAcct, 03_Drop_Acct) {
|
||||
int32_t contLen = sizeof(SDropAcctReq);
|
||||
|
||||
SDropAcctReq* pReq = (SDropAcctReq*)rpcMallocCont(contLen);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_ACCT, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
||||
}
|
||||
|
||||
TEST_F(MndTestAcct, 04_Show_Acct) {
|
||||
int32_t contLen = sizeof(SShowReq);
|
||||
|
||||
SShowReq* pReq = (SShowReq*)rpcMallocCont(contLen);
|
||||
pReq->type = TSDB_MGMT_TABLE_ACCT;
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_MSG_TYPE);
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
aux_source_directory(. STEST_SRC)
|
||||
add_executable(mnode_test_bnode ${STEST_SRC})
|
||||
target_link_libraries(
|
||||
mnode_test_bnode
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME mnode_test_bnode
|
||||
COMMAND mnode_test_bnode
|
||||
)
|
|
@ -0,0 +1,294 @@
|
|||
/**
|
||||
* @file bnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief MNODE module bnode tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-05
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class MndTestBnode : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/mnode_test_bnode1", 9018);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9018";
|
||||
|
||||
server2.Start("/tmp/mnode_test_bnode2", fqdn, 9019, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
server2.Stop();
|
||||
test.Cleanup();
|
||||
}
|
||||
|
||||
static Testbase test;
|
||||
static TestServer server2;
|
||||
};
|
||||
|
||||
Testbase MndTestBnode::test;
|
||||
TestServer MndTestBnode::server2;
|
||||
|
||||
TEST_F(MndTestBnode, 01_Show_Bnode) {
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, "");
|
||||
CHECK_META("show bnodes", 3);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
||||
TEST_F(MndTestBnode, 02_Create_Bnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateBnodeReq);
|
||||
|
||||
SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateBnodeReq);
|
||||
|
||||
SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, "");
|
||||
CHECK_META("show bnodes", 3);
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9018", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateBnodeReq);
|
||||
|
||||
SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_BNODE_ALREADY_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestBnode, 03_Drop_Bnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9019);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
taosMsleep(1300);
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateBnodeReq);
|
||||
|
||||
SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(2);
|
||||
CheckBinary("localhost:9018", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9019", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SMDropBnodeReq);
|
||||
|
||||
SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_BNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9018", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SMDropBnodeReq);
|
||||
|
||||
SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_BNODE_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestBnode, 03_Create_Bnode_Rollback) {
|
||||
{
|
||||
// send message first, then dnode2 crash, result is returned, and rollback is started
|
||||
int32_t contLen = sizeof(SMCreateBnodeReq);
|
||||
|
||||
SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL);
|
||||
}
|
||||
|
||||
{
|
||||
// continue send message, bnode is creating
|
||||
int32_t contLen = sizeof(SMCreateBnodeReq);
|
||||
|
||||
SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING);
|
||||
}
|
||||
|
||||
{
|
||||
// continue send message, bnode is creating
|
||||
int32_t contLen = sizeof(SMDropBnodeReq);
|
||||
|
||||
SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING);
|
||||
}
|
||||
|
||||
{
|
||||
// server start, wait until the rollback finished
|
||||
server2.DoStart();
|
||||
taosMsleep(1000);
|
||||
|
||||
int32_t retry = 0;
|
||||
int32_t retryMax = 10;
|
||||
|
||||
for (retry = 0; retry < retryMax; retry++) {
|
||||
int32_t contLen = sizeof(SMCreateBnodeReq);
|
||||
|
||||
SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
if (pRsp->code == 0) break;
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
||||
ASSERT_NE(retry, retryMax);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestBnode, 04_Drop_Bnode_Rollback) {
|
||||
{
|
||||
// send message first, then dnode2 crash, result is returned, and rollback is started
|
||||
int32_t contLen = sizeof(SMDropBnodeReq);
|
||||
|
||||
SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL);
|
||||
}
|
||||
|
||||
{
|
||||
// continue send message, bnode is dropping
|
||||
int32_t contLen = sizeof(SMCreateBnodeReq);
|
||||
|
||||
SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING);
|
||||
}
|
||||
|
||||
{
|
||||
// continue send message, bnode is dropping
|
||||
int32_t contLen = sizeof(SMDropBnodeReq);
|
||||
|
||||
SMDropBnodeReq* pReq = (SMDropBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING);
|
||||
}
|
||||
|
||||
{
|
||||
// server start, wait until the rollback finished
|
||||
server2.DoStart();
|
||||
taosMsleep(1000);
|
||||
|
||||
int32_t retry = 0;
|
||||
int32_t retryMax = 10;
|
||||
|
||||
for (retry = 0; retry < retryMax; retry++) {
|
||||
int32_t contLen = sizeof(SMCreateBnodeReq);
|
||||
|
||||
SMCreateBnodeReq* pReq = (SMCreateBnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_BNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
if (pRsp->code == 0) break;
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
||||
ASSERT_NE(retry, retryMax);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
aux_source_directory(. QTEST_SRC)
|
||||
add_executable(mnode_test_qnode ${QTEST_SRC})
|
||||
target_link_libraries(
|
||||
mnode_test_qnode
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME mnode_test_qnode
|
||||
COMMAND mnode_test_qnode
|
||||
)
|
|
@ -0,0 +1,294 @@
|
|||
/**
|
||||
* @file qnode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief MNODE module qnode tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-05
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class MndTestQnode : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/mnode_test_qnode1", 9014);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9014";
|
||||
|
||||
server2.Start("/tmp/mnode_test_qnode2", fqdn, 9015, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
server2.Stop();
|
||||
test.Cleanup();
|
||||
}
|
||||
|
||||
static Testbase test;
|
||||
static TestServer server2;
|
||||
};
|
||||
|
||||
Testbase MndTestQnode::test;
|
||||
TestServer MndTestQnode::server2;
|
||||
|
||||
TEST_F(MndTestQnode, 01_Show_Qnode) {
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_QNODE, "");
|
||||
CHECK_META("show qnodes", 3);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
||||
TEST_F(MndTestQnode, 02_Create_Qnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateQnodeReq);
|
||||
|
||||
SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateQnodeReq);
|
||||
|
||||
SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_QNODE, "");
|
||||
CHECK_META("show qnodes", 3);
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9014", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateQnodeReq);
|
||||
|
||||
SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_QNODE_ALREADY_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestQnode, 03_Drop_Qnode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9015);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
taosMsleep(1300);
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateQnodeReq);
|
||||
|
||||
SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_QNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(2);
|
||||
CheckBinary("localhost:9014", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9015", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SMDropQnodeReq);
|
||||
|
||||
SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_QNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9014", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SMDropQnodeReq);
|
||||
|
||||
SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_QNODE_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestQnode, 03_Create_Qnode_Rollback) {
|
||||
{
|
||||
// send message first, then dnode2 crash, result is returned, and rollback is started
|
||||
int32_t contLen = sizeof(SMCreateQnodeReq);
|
||||
|
||||
SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL);
|
||||
}
|
||||
|
||||
{
|
||||
// continue send message, qnode is creating
|
||||
int32_t contLen = sizeof(SMCreateQnodeReq);
|
||||
|
||||
SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING);
|
||||
}
|
||||
|
||||
{
|
||||
// continue send message, qnode is creating
|
||||
int32_t contLen = sizeof(SMDropQnodeReq);
|
||||
|
||||
SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING);
|
||||
}
|
||||
|
||||
{
|
||||
// server start, wait until the rollback finished
|
||||
server2.DoStart();
|
||||
taosMsleep(1000);
|
||||
|
||||
int32_t retry = 0;
|
||||
int32_t retryMax = 10;
|
||||
|
||||
for (retry = 0; retry < retryMax; retry++) {
|
||||
int32_t contLen = sizeof(SMCreateQnodeReq);
|
||||
|
||||
SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
if (pRsp->code == 0) break;
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
||||
ASSERT_NE(retry, retryMax);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestQnode, 04_Drop_Qnode_Rollback) {
|
||||
{
|
||||
// send message first, then dnode2 crash, result is returned, and rollback is started
|
||||
int32_t contLen = sizeof(SMDropQnodeReq);
|
||||
|
||||
SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL);
|
||||
}
|
||||
|
||||
{
|
||||
// continue send message, qnode is dropping
|
||||
int32_t contLen = sizeof(SMCreateQnodeReq);
|
||||
|
||||
SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING);
|
||||
}
|
||||
|
||||
{
|
||||
// continue send message, qnode is dropping
|
||||
int32_t contLen = sizeof(SMDropQnodeReq);
|
||||
|
||||
SMDropQnodeReq* pReq = (SMDropQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING);
|
||||
}
|
||||
|
||||
{
|
||||
// server start, wait until the rollback finished
|
||||
server2.DoStart();
|
||||
taosMsleep(1000);
|
||||
|
||||
int32_t retry = 0;
|
||||
int32_t retryMax = 10;
|
||||
|
||||
for (retry = 0; retry < retryMax; retry++) {
|
||||
int32_t contLen = sizeof(SMCreateQnodeReq);
|
||||
|
||||
SMCreateQnodeReq* pReq = (SMCreateQnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_QNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
if (pRsp->code == 0) break;
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
||||
ASSERT_NE(retry, retryMax);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
aux_source_directory(. SHOW_SRC)
|
||||
add_executable(mnode_test_show ${SHOW_SRC})
|
||||
target_link_libraries(
|
||||
mnode_test_show
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME mnode_test_show
|
||||
COMMAND mnode_test_show
|
||||
)
|
|
@ -0,0 +1,102 @@
|
|||
/**
|
||||
* @file show.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief MNODE module show tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-06
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class MndTestShow : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_show", 9020); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
Testbase MndTestShow::test;
|
||||
|
||||
TEST_F(MndTestShow, 01_ShowMsg_InvalidMsgMax) {
|
||||
int32_t contLen = sizeof(SShowReq);
|
||||
|
||||
SShowReq* pReq = (SShowReq*)rpcMallocCont(contLen);
|
||||
pReq->type = TSDB_MGMT_TABLE_MAX;
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_MSG_TYPE);
|
||||
}
|
||||
|
||||
TEST_F(MndTestShow, 02_ShowMsg_InvalidMsgStart) {
|
||||
int32_t contLen = sizeof(SShowReq);
|
||||
|
||||
SShowReq* pReq = (SShowReq*)rpcMallocCont(sizeof(SShowReq));
|
||||
pReq->type = TSDB_MGMT_TABLE_START;
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_SHOW, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_MSG_TYPE);
|
||||
}
|
||||
|
||||
TEST_F(MndTestShow, 03_ShowMsg_Conn) {
|
||||
int32_t contLen = sizeof(SConnectMsg);
|
||||
|
||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen);
|
||||
pReq->pid = htonl(1234);
|
||||
strcpy(pReq->app, "mnode_test_show");
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CONNECT, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_CONNS, "");
|
||||
|
||||
STableMetaMsg* pMeta = test.GetShowMeta();
|
||||
EXPECT_STREQ(pMeta->tbFname, "show connections");
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, 7);
|
||||
EXPECT_EQ(pMeta->precision, 0);
|
||||
EXPECT_EQ(pMeta->tableType, 0);
|
||||
EXPECT_EQ(pMeta->update, 0);
|
||||
EXPECT_EQ(pMeta->sversion, 0);
|
||||
EXPECT_EQ(pMeta->tversion, 0);
|
||||
EXPECT_EQ(pMeta->tuid, 0);
|
||||
EXPECT_EQ(pMeta->suid, 0);
|
||||
|
||||
test.SendShowRetrieveReq();
|
||||
|
||||
SRetrieveTableRsp* pRetrieveRsp = test.GetRetrieveRsp();
|
||||
EXPECT_EQ(pRetrieveRsp->numOfRows, 1);
|
||||
EXPECT_EQ(pRetrieveRsp->useconds, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->completed, 1);
|
||||
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRetrieveRsp->compressed, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->compLen, 0);
|
||||
}
|
||||
|
||||
TEST_F(MndTestShow, 04_ShowMsg_Cluster) {
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_CLUSTER, "");
|
||||
CHECK_META( "show cluster", 3);
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_BIGINT, 8, "id");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
IgnoreInt64();
|
||||
IgnoreBinary(TSDB_CLUSTER_ID_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
aux_source_directory(. STEST_SRC)
|
||||
add_executable(mnode_test_snode ${STEST_SRC})
|
||||
target_link_libraries(
|
||||
mnode_test_snode
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME mnode_test_snode
|
||||
COMMAND mnode_test_snode
|
||||
)
|
|
@ -0,0 +1,294 @@
|
|||
/**
|
||||
* @file snode.cpp
|
||||
* @author slguan (slguan@taosdata.com)
|
||||
* @brief MNODE module snode tests
|
||||
* @version 1.0
|
||||
* @date 2022-01-05
|
||||
*
|
||||
* @copyright Copyright (c) 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sut.h"
|
||||
|
||||
class MndTestSnode : public ::testing::Test {
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/mnode_test_snode1", 9016);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9016";
|
||||
|
||||
server2.Start("/tmp/mnode_test_snode2", fqdn, 9017, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
server2.Stop();
|
||||
test.Cleanup();
|
||||
}
|
||||
|
||||
static Testbase test;
|
||||
static TestServer server2;
|
||||
};
|
||||
|
||||
Testbase MndTestSnode::test;
|
||||
TestServer MndTestSnode::server2;
|
||||
|
||||
TEST_F(MndTestSnode, 01_Show_Snode) {
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_SNODE, "");
|
||||
CHECK_META("show snodes", 3);
|
||||
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
||||
TEST_F(MndTestSnode, 02_Create_Snode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateSnodeReq);
|
||||
|
||||
SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DNODE_NOT_EXIST);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateSnodeReq);
|
||||
|
||||
SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_SNODE, "");
|
||||
CHECK_META("show snodes", 3);
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9016", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateSnodeReq);
|
||||
|
||||
SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_SNODE_ALREADY_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestSnode, 03_Drop_Snode) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->fqdn, "localhost");
|
||||
pReq->port = htonl(9017);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
taosMsleep(1300);
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_DNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SMCreateSnodeReq);
|
||||
|
||||
SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_SNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(2);
|
||||
CheckBinary("localhost:9016", TSDB_EP_LEN);
|
||||
CheckBinary("localhost:9017", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SMDropSnodeReq);
|
||||
|
||||
SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
test.SendShowMetaReq(TSDB_MGMT_TABLE_SNODE, "");
|
||||
test.SendShowRetrieveReq();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9016", TSDB_EP_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SMDropSnodeReq);
|
||||
|
||||
SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_SNODE_NOT_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestSnode, 03_Create_Snode_Rollback) {
|
||||
{
|
||||
// send message first, then dnode2 crash, result is returned, and rollback is started
|
||||
int32_t contLen = sizeof(SMCreateSnodeReq);
|
||||
|
||||
SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL);
|
||||
}
|
||||
|
||||
{
|
||||
// continue send message, snode is creating
|
||||
int32_t contLen = sizeof(SMCreateSnodeReq);
|
||||
|
||||
SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING);
|
||||
}
|
||||
|
||||
{
|
||||
// continue send message, snode is creating
|
||||
int32_t contLen = sizeof(SMDropSnodeReq);
|
||||
|
||||
SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_CREATING);
|
||||
}
|
||||
|
||||
{
|
||||
// server start, wait until the rollback finished
|
||||
server2.DoStart();
|
||||
taosMsleep(1000);
|
||||
|
||||
int32_t retry = 0;
|
||||
int32_t retryMax = 10;
|
||||
|
||||
for (retry = 0; retry < retryMax; retry++) {
|
||||
int32_t contLen = sizeof(SMCreateSnodeReq);
|
||||
|
||||
SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
if (pRsp->code == 0) break;
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
||||
ASSERT_NE(retry, retryMax);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestSnode, 04_Drop_Snode_Rollback) {
|
||||
{
|
||||
// send message first, then dnode2 crash, result is returned, and rollback is started
|
||||
int32_t contLen = sizeof(SMDropSnodeReq);
|
||||
|
||||
SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_RPC_NETWORK_UNAVAIL);
|
||||
}
|
||||
|
||||
{
|
||||
// continue send message, snode is dropping
|
||||
int32_t contLen = sizeof(SMCreateSnodeReq);
|
||||
|
||||
SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING);
|
||||
}
|
||||
|
||||
{
|
||||
// continue send message, snode is dropping
|
||||
int32_t contLen = sizeof(SMDropSnodeReq);
|
||||
|
||||
SMDropSnodeReq* pReq = (SMDropSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
server2.Stop();
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, TSDB_CODE_SDB_OBJ_DROPPING);
|
||||
}
|
||||
|
||||
{
|
||||
// server start, wait until the rollback finished
|
||||
server2.DoStart();
|
||||
taosMsleep(1000);
|
||||
|
||||
int32_t retry = 0;
|
||||
int32_t retryMax = 10;
|
||||
|
||||
for (retry = 0; retry < retryMax; retry++) {
|
||||
int32_t contLen = sizeof(SMCreateSnodeReq);
|
||||
|
||||
SMCreateSnodeReq* pReq = (SMCreateSnodeReq*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_SNODE, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
if (pRsp->code == 0) break;
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
||||
ASSERT_NE(retry, retryMax);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue