tq consume refactor
This commit is contained in:
commit
75e2ee1019
|
@ -106,6 +106,10 @@ pipeline {
|
|||
abortPreviousBuilds()
|
||||
}
|
||||
pre_test()
|
||||
sh'''
|
||||
cd ${WKC}/tests
|
||||
./test-all.sh b1fq
|
||||
'''
|
||||
}
|
||||
}
|
||||
// stage('Parallel test stage') {
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
# stub
|
||||
ExternalProject_Add(stub
|
||||
GIT_REPOSITORY https://github.com/coolxv/cpp-stub.git
|
||||
GIT_SUBMODULES "src"
|
||||
SOURCE_DIR "${CMAKE_CONTRIB_DIR}/cpp-stub"
|
||||
BINARY_DIR "${CMAKE_CONTRIB_DIR}/cpp-stub/src"
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
)
|
|
@ -12,6 +12,7 @@ configure_file("${CMAKE_SUPPORT_DIR}/deps_CMakeLists.txt.in" ${CONTRIB_TMP_FILE}
|
|||
# googletest
|
||||
if(${BUILD_TEST})
|
||||
cat("${CMAKE_SUPPORT_DIR}/gtest_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
cat("${CMAKE_SUPPORT_DIR}/stub_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
endif(${BUILD_TEST})
|
||||
|
||||
# lz4
|
||||
|
@ -79,6 +80,11 @@ execute_process(COMMAND "${CMAKE_COMMAND}" --build .
|
|||
# googletest
|
||||
if(${BUILD_TEST})
|
||||
add_subdirectory(googletest)
|
||||
target_include_directories(
|
||||
gtest
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src>
|
||||
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cpp-stub/src_linux>
|
||||
)
|
||||
endif(${BUILD_TEST})
|
||||
|
||||
# cJson
|
||||
|
|
|
@ -51,7 +51,7 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_QUERY, "mq-query" )
|
|||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_CONNECT, "mq-connect" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_DISCONNECT, "mq-disconnect" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_SET_CUR, "mq-set-cur" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_RSP_READY, "rsp-ready" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_RES_READY, "res-ready" )
|
||||
// message from client to mnode
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONNECT, "connect" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_ACCT, "create-acct" )
|
||||
|
@ -78,8 +78,7 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STB, "create-stb" )
|
|||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STB, "alter-stb" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STB, "drop-stb" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_VGROUP_LIST, "vgroup-list" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_QUERY, "kill-query" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_STREAM, "kill-stream" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_QUERY, "kill-query" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_CONN, "kill-conn" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_HEARTBEAT, "heartbeat" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SHOW, "show" )
|
||||
|
@ -94,22 +93,22 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_NETWORK_TEST, "nettest" )
|
|||
// message from vnode to dnode
|
||||
|
||||
// message from mnode to vnode
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STB_IN, "create-stb-in" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STB_IN, "alter-stb-in" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STB_IN, "drop-stb-in" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STB_IN, "create-stb-internal" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STB_IN, "alter-stb-internal" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STB_IN, "drop-stb-internal" )
|
||||
// message from mnode to mnode
|
||||
// message from mnode to qnode
|
||||
// message from mnode to dnode
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_VNODE_IN, "create-vnode" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_VNODE_IN, "alter-vnode" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_VNODE_IN, "drop-vnode" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_AUTH_VNODE_IN, "auth-vnode" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SYNC_VNODE_IN, "sync-vnode" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_COMPACT_VNODE_IN, "compact-vnode" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_MNODE_IN, "create-mnode" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_MNODE_IN, "alter-mnode" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_MNODE_IN, "drop-mnode" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONFIG_DNODE_IN, "config-dnode" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_VNODE_IN, "create-vnode-internal" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_VNODE_IN, "alter-vnode-internal" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_VNODE_IN, "drop-vnode-internal" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_AUTH_VNODE_IN, "auth-vnode-internal" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_SYNC_VNODE_IN, "sync-vnode-internal" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_COMPACT_VNODE_IN, "compact-vnode-internal" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_MNODE_IN, "create-mnode-internal" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_MNODE_IN, "alter-mnode-internal" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_MNODE_IN, "drop-mnode-internal" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONFIG_DNODE_IN, "config-dnode-internal" )
|
||||
|
||||
// message from qnode to vnode
|
||||
// message from qnode to mnode
|
||||
|
@ -312,11 +311,11 @@ typedef struct {
|
|||
typedef struct {
|
||||
int32_t len; // one create table message
|
||||
char tableName[TSDB_TABLE_FNAME_LEN];
|
||||
int8_t igExists;
|
||||
int8_t getMeta;
|
||||
int16_t numOfTags;
|
||||
int16_t numOfColumns;
|
||||
int16_t sqlLen; // the length of SQL, it starts after schema , sql is a null-terminated string
|
||||
int8_t igExists;
|
||||
int8_t rspMeta;
|
||||
int8_t reserved[16];
|
||||
char schema[];
|
||||
} SCreateTableMsg;
|
||||
|
@ -341,16 +340,37 @@ typedef struct {
|
|||
} SAlterStbMsg;
|
||||
|
||||
typedef struct {
|
||||
char tableFname[TSDB_TABLE_FNAME_LEN];
|
||||
char db[TSDB_FULL_DB_NAME_LEN];
|
||||
int16_t type; /* operation type */
|
||||
int16_t numOfCols; /* number of schema */
|
||||
int32_t tagValLen;
|
||||
SSchema schema[];
|
||||
// tagVal is padded after schema
|
||||
// char tagVal[];
|
||||
SMsgHead head;
|
||||
char name[TSDB_TABLE_FNAME_LEN];
|
||||
uint64_t suid;
|
||||
int32_t sverson;
|
||||
uint32_t ttl;
|
||||
uint32_t keep;
|
||||
int32_t numOfTags;
|
||||
int32_t numOfColumns;
|
||||
SSchema pSchema[];
|
||||
} SCreateStbInternalMsg;
|
||||
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
char name[TSDB_TABLE_FNAME_LEN];
|
||||
uint64_t suid;
|
||||
} SDropStbInternalMsg;
|
||||
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
char name[TSDB_TABLE_FNAME_LEN];
|
||||
int8_t type; /* operation type */
|
||||
int32_t numOfCols; /* number of schema */
|
||||
int32_t numOfTags;
|
||||
char data[];
|
||||
} SAlterTableMsg;
|
||||
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
char name[TSDB_TABLE_FNAME_LEN];
|
||||
} SDropTableMsg;
|
||||
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
int64_t uid;
|
||||
|
@ -591,8 +611,8 @@ typedef struct {
|
|||
int32_t daysToKeep0;
|
||||
int32_t daysToKeep1;
|
||||
int32_t daysToKeep2;
|
||||
int32_t minRowsPerFileBlock;
|
||||
int32_t maxRowsPerFileBlock;
|
||||
int32_t minRows;
|
||||
int32_t maxRows;
|
||||
int32_t commitTime;
|
||||
int32_t fsyncPeriod;
|
||||
int8_t walLevel;
|
||||
|
@ -706,7 +726,7 @@ typedef struct {
|
|||
SVnodeLoad data[];
|
||||
} SVnodeLoads;
|
||||
|
||||
typedef struct SStatusMsg {
|
||||
typedef struct {
|
||||
int32_t sver;
|
||||
int32_t dnodeId;
|
||||
int32_t clusterId;
|
||||
|
@ -756,6 +776,7 @@ typedef struct {
|
|||
int32_t dnodeId;
|
||||
char db[TSDB_FULL_DB_NAME_LEN];
|
||||
uint64_t dbUid;
|
||||
int32_t vgVersion;
|
||||
int32_t cacheBlockSize;
|
||||
int32_t totalBlocks;
|
||||
int32_t daysPerFile;
|
||||
|
@ -942,18 +963,6 @@ typedef struct {
|
|||
char subSqlInfo[TSDB_SHOW_SUBQUERY_LEN]; // include subqueries' index, Obj IDs and states(C-complete/I-imcomplete)
|
||||
} SQueryDesc;
|
||||
|
||||
typedef struct {
|
||||
char sql[TSDB_SHOW_SQL_LEN];
|
||||
char dstTable[TSDB_TABLE_NAME_LEN];
|
||||
int32_t streamId;
|
||||
int64_t num; // number of computing/cycles
|
||||
int64_t useconds;
|
||||
int64_t ctime;
|
||||
int64_t stime;
|
||||
int64_t slidingTime;
|
||||
int64_t interval;
|
||||
} SStreamDesc;
|
||||
|
||||
typedef struct {
|
||||
int32_t connId;
|
||||
int32_t pid;
|
||||
|
@ -1090,6 +1099,7 @@ typedef struct {
|
|||
} SUpdateTagValRsp;
|
||||
|
||||
typedef struct SSchedulerQueryMsg {
|
||||
uint64_t schedulerId;
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
uint32_t contentLen;
|
||||
|
@ -1097,15 +1107,39 @@ typedef struct SSchedulerQueryMsg {
|
|||
} SSchedulerQueryMsg;
|
||||
|
||||
typedef struct SSchedulerReadyMsg {
|
||||
uint64_t schedulerId;
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
} SSchedulerReadyMsg;
|
||||
|
||||
typedef struct SSchedulerFetchMsg {
|
||||
uint64_t schedulerId;
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
} SSchedulerFetchMsg;
|
||||
|
||||
typedef struct SSchedulerStatusMsg {
|
||||
uint64_t schedulerId;
|
||||
} SSchedulerStatusMsg;
|
||||
|
||||
typedef struct STaskStatus {
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
int8_t status;
|
||||
} STaskStatus;
|
||||
|
||||
typedef struct SSchedulerStatusRsp {
|
||||
uint32_t num;
|
||||
STaskStatus status[];
|
||||
} SSchedulerStatusRsp;
|
||||
|
||||
|
||||
typedef struct SSchedulerCancelMsg {
|
||||
uint64_t schedulerId;
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
} SSchedulerCancelMsg;
|
||||
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ enum {
|
|||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_SELECT, "select" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_FETCH, "fetch" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_INSERT, "insert" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_UPDATE_TAGS_VAL, "update-tag-val" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_UPDATE_TAG_VAL, "update-tag-val" )
|
||||
|
||||
// the SQL below is for mgmt node
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_MGMT, "mgmt" )
|
||||
|
@ -54,7 +54,7 @@ enum {
|
|||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_ALTER_TABLE, "alter-table" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_ALTER_DB, "alter-db" )
|
||||
|
||||
TSDB_DEFINE_SQL_TYPE(TSDB_SQL_SYNC_DB_REPLICA, "sync db-replica")
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_SYNC_DB_REPLICA, "sync db-replica")
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_MNODE, "create-mnode" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_DROP_MNODE, "drop-mnode" )
|
||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CREATE_DNODE, "create-dnode" )
|
||||
|
@ -102,14 +102,6 @@ enum {
|
|||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_MAX, "max" )
|
||||
};
|
||||
|
||||
// create table operation type
|
||||
enum TSQL_CREATE_TABLE_TYPE {
|
||||
TSQL_CREATE_TABLE = 0x1,
|
||||
TSQL_CREATE_STABLE = 0x2,
|
||||
TSQL_CREATE_CTABLE = 0x3,
|
||||
TSQL_CREATE_STREAM = 0x4,
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
#ifndef TDENGINE_TNAME_H
|
||||
#define TDENGINE_TNAME_H
|
||||
|
||||
//#include "taosmsg.h"
|
||||
|
||||
#define TSDB_DB_NAME_T 1
|
||||
#define TSDB_TABLE_NAME_T 2
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "trpc.h"
|
||||
|
||||
typedef struct {
|
||||
uint64_t numOfStartTask;
|
||||
|
@ -32,48 +32,6 @@ typedef struct {
|
|||
uint64_t numOfErrors;
|
||||
} SQnodeStat;
|
||||
|
||||
/* start Task msg */
|
||||
typedef struct {
|
||||
uint32_t schedulerIp;
|
||||
uint16_t schedulerPort;
|
||||
int64_t taskId;
|
||||
int64_t queryId;
|
||||
uint32_t srcIp;
|
||||
uint16_t srcPort;
|
||||
} SQnodeStartTaskMsg;
|
||||
|
||||
/* stop Task msg */
|
||||
typedef struct {
|
||||
int64_t taskId;
|
||||
} SQnodeStopTaskMsg;
|
||||
|
||||
/* start/stop Task msg response */
|
||||
typedef struct {
|
||||
int64_t taskId;
|
||||
int32_t code;
|
||||
} SQnodeTaskRespMsg;
|
||||
|
||||
/* Task status msg */
|
||||
typedef struct {
|
||||
int64_t taskId;
|
||||
int32_t status;
|
||||
int64_t queryId;
|
||||
} SQnodeTaskStatusMsg;
|
||||
|
||||
/* Qnode/Scheduler heartbeat msg */
|
||||
typedef struct {
|
||||
int32_t status;
|
||||
int32_t load;
|
||||
|
||||
} SQnodeHeartbeatMsg;
|
||||
|
||||
/* Qnode sent/received msg */
|
||||
typedef struct {
|
||||
int8_t msgType;
|
||||
int32_t msgLen;
|
||||
char msg[];
|
||||
} SQnodeMsg;
|
||||
|
||||
|
||||
/**
|
||||
* Start one Qnode in Dnode.
|
||||
|
|
|
@ -142,6 +142,36 @@ int vnodeProcessCMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
|||
*/
|
||||
int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
||||
|
||||
/**
|
||||
* @brief Process a query message.
|
||||
*
|
||||
* @param pVnode The vnode object.
|
||||
* @param pMsg The request message
|
||||
* @param pRsp The response message
|
||||
* @return int 0 for success, -1 for failure
|
||||
*/
|
||||
int vnodeProcessQueryReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
||||
|
||||
/**
|
||||
* @brief Process a fetch message.
|
||||
*
|
||||
* @param pVnode The vnode object.
|
||||
* @param pMsg The request message
|
||||
* @param pRsp The response message
|
||||
* @return int 0 for success, -1 for failure
|
||||
*/
|
||||
int vnodeProcessFetchReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
||||
|
||||
/**
|
||||
* @brief Process a consume message.
|
||||
*
|
||||
* @param pVnode The vnode object.
|
||||
* @param pMsg The request message
|
||||
* @param pRsp The response message
|
||||
* @return int 0 for success, -1 for failure
|
||||
*/
|
||||
int vnodeProcessConsumeReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
||||
|
||||
/* ------------------------ SVnodeCfg ------------------------ */
|
||||
/**
|
||||
* @brief Initialize VNODE options.
|
||||
|
@ -180,73 +210,52 @@ typedef struct {
|
|||
char info[];
|
||||
} SVnodeRsp;
|
||||
|
||||
#define VNODE_INIT_CREATE_STB_REQ(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) \
|
||||
{ .ver = 0, .ctReq = META_INIT_STB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) }
|
||||
static FORCE_INLINE void vnodeSetCreateStbReq(SVnodeReq *pReq, char *name, uint32_t ttl, uint32_t keep, tb_uid_t suid,
|
||||
STSchema *pSchema, STSchema *pTagSchema) {
|
||||
pReq->ver = 0;
|
||||
|
||||
#define VNODE_INIT_CREATE_CTB_REQ(NAME, TTL, KEEP, SUID, PTAG) \
|
||||
{ .ver = 0, .ctReq = META_INIT_CTB_CFG(NAME, TTL, KEEP, SUID, PTAG) }
|
||||
pReq->ctReq.name = name;
|
||||
pReq->ctReq.ttl = ttl;
|
||||
pReq->ctReq.keep = keep;
|
||||
pReq->ctReq.type = META_SUPER_TABLE;
|
||||
pReq->ctReq.stbCfg.suid = suid;
|
||||
pReq->ctReq.stbCfg.pSchema = pSchema;
|
||||
pReq->ctReq.stbCfg.pTagSchema = pTagSchema;
|
||||
}
|
||||
|
||||
#define VNODE_INIT_CREATE_NTB_REQ(NAME, TTL, KEEP, SUID, PSCHEMA) \
|
||||
{ .ver = 0, .ctReq = META_INIT_NTB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA) }
|
||||
static FORCE_INLINE void vnodeSetCreateCtbReq(SVnodeReq *pReq, char *name, uint32_t ttl, uint32_t keep, tb_uid_t suid,
|
||||
SKVRow pTag) {
|
||||
pReq->ver = 0;
|
||||
|
||||
pReq->ctReq.name = name;
|
||||
pReq->ctReq.ttl = ttl;
|
||||
pReq->ctReq.keep = keep;
|
||||
pReq->ctReq.type = META_CHILD_TABLE;
|
||||
pReq->ctReq.ctbCfg.suid = suid;
|
||||
pReq->ctReq.ctbCfg.pTag = pTag;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void vnodeSetCreateNtbReq(SVnodeReq *pReq, char *name, uint32_t ttl, uint32_t keep,
|
||||
STSchema *pSchema) {
|
||||
pReq->ver = 0;
|
||||
|
||||
pReq->ctReq.name = name;
|
||||
pReq->ctReq.ttl = ttl;
|
||||
pReq->ctReq.keep = keep;
|
||||
pReq->ctReq.type = META_NORMAL_TABLE;
|
||||
pReq->ctReq.ntbCfg.pSchema = pSchema;
|
||||
}
|
||||
|
||||
int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type);
|
||||
void *vnodeParseReq(void *buf, SVnodeReq *pReq, uint8_t type);
|
||||
|
||||
/* ------------------------ FOR COMPILE ------------------------ */
|
||||
|
||||
#if 1
|
||||
|
||||
#include "taosmsg.h"
|
||||
#include "trpc.h"
|
||||
|
||||
// typedef struct {
|
||||
// char db[TSDB_FULL_DB_NAME_LEN];
|
||||
// int32_t cacheBlockSize; // MB
|
||||
// int32_t totalBlocks;
|
||||
// int32_t daysPerFile;
|
||||
// int32_t daysToKeep0;
|
||||
// int32_t daysToKeep1;
|
||||
// int32_t daysToKeep2;
|
||||
// int32_t minRowsPerFileBlock;
|
||||
// int32_t maxRowsPerFileBlock;
|
||||
// int8_t precision; // time resolution
|
||||
// int8_t compression;
|
||||
// int8_t cacheLastRow;
|
||||
// int8_t update;
|
||||
// int8_t quorum;
|
||||
// int8_t replica;
|
||||
// int8_t selfIndex;
|
||||
// int8_t walLevel;
|
||||
// int32_t fsyncPeriod; // millisecond
|
||||
// SReplica replicas[TSDB_MAX_REPLICA];
|
||||
// } SVnodeCfg;
|
||||
|
||||
typedef enum {
|
||||
VN_MSG_TYPE_WRITE = 1,
|
||||
VN_MSG_TYPE_APPLY,
|
||||
VN_MSG_TYPE_SYNC,
|
||||
VN_MSG_TYPE_QUERY,
|
||||
VN_MSG_TYPE_FETCH
|
||||
} EVnMsgType;
|
||||
|
||||
typedef struct {
|
||||
int32_t curNum;
|
||||
int32_t allocNum;
|
||||
SRpcMsg rpcMsg[];
|
||||
} SVnodeMsg;
|
||||
|
||||
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg);
|
||||
int32_t vnodeCompact(SVnode *pVnode);
|
||||
int32_t vnodeSync(SVnode *pVnode);
|
||||
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad);
|
||||
|
||||
SVnodeMsg *vnodeInitMsg(int32_t msgNum);
|
||||
int32_t vnodeAppendMsg(SVnodeMsg *pMsg, SRpcMsg *pRpcMsg);
|
||||
void vnodeCleanupMsg(SVnodeMsg *pMsg);
|
||||
void vnodeProcessMsg(SVnode *pVnode, SVnodeMsg *pMsg, EVnMsgType msgType);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -23,63 +23,67 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SIndex SIndex;
|
||||
typedef struct SIndexTerm SIndexTerm;
|
||||
typedef struct SIndexOpts SIndexOpts;
|
||||
typedef struct SIndex SIndex;
|
||||
typedef struct SIndexTerm SIndexTerm;
|
||||
typedef struct SIndexOpts SIndexOpts;
|
||||
typedef struct SIndexMultiTermQuery SIndexMultiTermQuery;
|
||||
typedef struct SArray SIndexMultiTerm;
|
||||
|
||||
typedef enum {
|
||||
ADD_VALUE, // add index colume value
|
||||
DEL_VALUE, // delete index column value
|
||||
UPDATE_VALUE, // update index column value
|
||||
ADD_INDEX, // add index on specify column
|
||||
DROP_INDEX, // drop existed index
|
||||
DROP_SATBLE // drop stable
|
||||
typedef enum {
|
||||
ADD_VALUE, // add index colume value
|
||||
DEL_VALUE, // delete index column value
|
||||
UPDATE_VALUE, // update index column value
|
||||
ADD_INDEX, // add index on specify column
|
||||
DROP_INDEX, // drop existed index
|
||||
DROP_SATBLE // drop stable
|
||||
} SIndexOperOnColumn;
|
||||
|
||||
typedef enum { MUST = 0, SHOULD = 1, NOT = 2 } EIndexOperatorType;
|
||||
typedef enum { QUERY_TERM = 0, QUERY_PREFIX = 1, QUERY_SUFFIX = 2,QUERY_REGEX = 3} EIndexQueryType;
|
||||
typedef enum { MUST = 0, SHOULD = 1, NOT = 2 } EIndexOperatorType;
|
||||
typedef enum { QUERY_TERM = 0, QUERY_PREFIX = 1, QUERY_SUFFIX = 2, QUERY_REGEX = 3 } EIndexQueryType;
|
||||
/*
|
||||
* @param: oper
|
||||
* @param: oper
|
||||
*
|
||||
*/
|
||||
SIndexMultiTermQuery *indexMultiTermQueryCreate(EIndexOperatorType oper);
|
||||
void indexMultiTermQueryDestroy(SIndexMultiTermQuery *pQuery);
|
||||
int indexMultiTermQueryAdd(SIndexMultiTermQuery *pQuery, SIndexTerm *term, EIndexQueryType type);
|
||||
/*
|
||||
* @param:
|
||||
*/
|
||||
SIndexMultiTermQuery* indexMultiTermQueryCreate(EIndexOperatorType oper);
|
||||
void indexMultiTermQueryDestroy(SIndexMultiTermQuery* pQuery);
|
||||
int indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EIndexQueryType type);
|
||||
/*
|
||||
* @param:
|
||||
* @param:
|
||||
*/
|
||||
int indexOpen(SIndexOpts *opt, const char *path, SIndex **index);
|
||||
void indexClose(SIndex *index);
|
||||
int indexPut(SIndex *index, SIndexMultiTerm *terms, uint64_t uid);
|
||||
int indexDelete(SIndex *index, SIndexMultiTermQuery *query);
|
||||
int indexSearch(SIndex *index, SIndexMultiTermQuery *query, SArray *result);
|
||||
int indexRebuild(SIndex *index, SIndexOpts *opt);
|
||||
int indexOpen(SIndexOpts* opt, const char* path, SIndex** index);
|
||||
void indexClose(SIndex* index);
|
||||
int indexPut(SIndex* index, SIndexMultiTerm* terms, uint64_t uid);
|
||||
int indexDelete(SIndex* index, SIndexMultiTermQuery* query);
|
||||
int indexSearch(SIndex* index, SIndexMultiTermQuery* query, SArray* result);
|
||||
int indexRebuild(SIndex* index, SIndexOpts* opt);
|
||||
/*
|
||||
* @param
|
||||
* @param
|
||||
*/
|
||||
SIndexMultiTerm *indexMultiTermCreate();
|
||||
int indexMultiTermAdd(SIndexMultiTerm *terms, SIndexTerm *term);
|
||||
void indexMultiTermDestroy(SIndexMultiTerm *terms);
|
||||
SIndexMultiTerm* indexMultiTermCreate();
|
||||
int indexMultiTermAdd(SIndexMultiTerm* terms, SIndexTerm* term);
|
||||
void indexMultiTermDestroy(SIndexMultiTerm* terms);
|
||||
/*
|
||||
* @param:
|
||||
* @param:
|
||||
* @param:
|
||||
*/
|
||||
SIndexOpts *indexOptsCreate();
|
||||
void indexOptsDestroy(SIndexOpts *opts);
|
||||
SIndexOpts* indexOptsCreate();
|
||||
void indexOptsDestroy(SIndexOpts* opts);
|
||||
|
||||
/*
|
||||
* @param:
|
||||
* @param:
|
||||
*/
|
||||
|
||||
SIndexTerm *indexTermCreate(int64_t suid, SIndexOperOnColumn operType, uint8_t colType,
|
||||
const char *colName, int32_t nColName, const char *colVal, int32_t nColVal);
|
||||
void indexTermDestroy(SIndexTerm *p);
|
||||
|
||||
SIndexTerm* indexTermCreate(int64_t suid,
|
||||
SIndexOperOnColumn operType,
|
||||
uint8_t colType,
|
||||
const char* colName,
|
||||
int32_t nColName,
|
||||
const char* colVal,
|
||||
int32_t nColVal);
|
||||
void indexTermDestroy(SIndexTerm* p);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_PARSENODES_H_
|
||||
#define _TD_PARSENODES_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "catalog.h"
|
||||
#include "common.h"
|
||||
#include "function.h"
|
||||
#include "tmsgtype.h"
|
||||
#include "tname.h"
|
||||
#include "tvariant.h"
|
||||
|
||||
/*
|
||||
* The first field of a node of any type is guaranteed to be the int16_t.
|
||||
* Hence the type of any node can be gotten by casting it to SQueryNode.
|
||||
*/
|
||||
typedef struct SQueryNode {
|
||||
int16_t type;
|
||||
} SQueryNode;
|
||||
|
||||
#define nodeType(nodeptr) (((const SQueryNode*)(nodeptr))->type)
|
||||
|
||||
typedef struct SField {
|
||||
char name[TSDB_COL_NAME_LEN];
|
||||
uint8_t type;
|
||||
int16_t bytes;
|
||||
} SField;
|
||||
|
||||
typedef struct SParseBasicCtx {
|
||||
const char *db;
|
||||
int32_t acctId;
|
||||
uint64_t requestId;
|
||||
} SParseBasicCtx;
|
||||
|
||||
typedef struct SFieldInfo {
|
||||
int16_t numOfOutput; // number of column in result
|
||||
SField *final;
|
||||
SArray *internalField; // SArray<SInternalField>
|
||||
} SFieldInfo;
|
||||
|
||||
typedef struct SCond {
|
||||
uint64_t uid;
|
||||
int32_t len; // length of tag query condition data
|
||||
char * cond;
|
||||
} SCond;
|
||||
|
||||
typedef struct SJoinNode {
|
||||
uint64_t uid;
|
||||
int16_t tagColId;
|
||||
SArray* tsJoin;
|
||||
SArray* tagJoin;
|
||||
} SJoinNode;
|
||||
|
||||
typedef struct SJoinInfo {
|
||||
bool hasJoin;
|
||||
SJoinNode *joinTables[TSDB_MAX_JOIN_TABLE_NUM];
|
||||
} SJoinInfo;
|
||||
|
||||
typedef struct STagCond {
|
||||
int16_t relType; // relation between tbname list and query condition, including : TK_AND or TK_OR
|
||||
SCond tbnameCond; // tbname query condition, only support tbname query condition on one table
|
||||
SJoinInfo joinInfo; // join condition, only support two tables join currently
|
||||
SArray *pCond; // for different table, the query condition must be seperated
|
||||
} STagCond;
|
||||
|
||||
typedef struct STableMetaInfo {
|
||||
STableMeta *pTableMeta; // table meta, cached in client side and acquired by name
|
||||
SVgroupsInfo *vgroupList;
|
||||
SName name;
|
||||
char aliasName[TSDB_TABLE_NAME_LEN]; // alias name of table specified in query sql
|
||||
SArray *tagColList; // SArray<SColumn*>, involved tag columns
|
||||
} STableMetaInfo;
|
||||
|
||||
typedef struct SColumnIndex {
|
||||
int16_t tableIndex;
|
||||
int16_t columnIndex;
|
||||
int16_t type; // normal column/tag/ user input constant column
|
||||
} SColumnIndex;
|
||||
|
||||
// select statement
|
||||
typedef struct SQueryStmtInfo {
|
||||
int16_t command; // the command may be different for each subclause, so keep it seperately.
|
||||
uint32_t type; // query/insert type
|
||||
STimeWindow window; // the whole query time window
|
||||
SInterval interval; // tumble time window
|
||||
SSessionWindow sessionWindow; // session time window
|
||||
SStateWindow stateWindow; // state window query
|
||||
SGroupbyExpr groupbyExpr; // groupby tags info
|
||||
SArray * colList; // SArray<SColumn*>
|
||||
SFieldInfo fieldsInfo;
|
||||
SArray** exprList; // SArray<SExprInfo*>
|
||||
SLimit limit;
|
||||
SLimit slimit;
|
||||
STagCond tagCond;
|
||||
SArray * colCond;
|
||||
SArray * order;
|
||||
int16_t numOfTables;
|
||||
int16_t curTableIdx;
|
||||
STableMetaInfo **pTableMetaInfo;
|
||||
struct STSBuf *tsBuf;
|
||||
|
||||
int16_t fillType; // final result fill type
|
||||
int64_t * fillVal; // default value for fill
|
||||
int32_t numOfFillVal; // fill value size
|
||||
|
||||
char * msg; // pointer to the pCmd->payload to keep error message temporarily
|
||||
int64_t clauseLimit; // limit for current sub clause
|
||||
|
||||
int64_t prjOffset; // offset value in the original sql expression, only applied at client side
|
||||
int64_t vgroupLimit; // table limit in case of super table projection query + global order + limit
|
||||
|
||||
int32_t udColumnId; // current user-defined constant output field column id, monotonically decreases from TSDB_UD_COLUMN_INDEX
|
||||
int32_t bufLen;
|
||||
char* buf;
|
||||
SArray *pUdfInfo;
|
||||
|
||||
struct SQueryStmtInfo *sibling; // sibling
|
||||
struct SQueryStmtInfo *pDownstream;
|
||||
SMultiFunctionsDesc info;
|
||||
SArray *pUpstream; // SArray<struct SQueryStmtInfo>
|
||||
int32_t havingFieldNum;
|
||||
int32_t exprListLevelIndex;
|
||||
} SQueryStmtInfo;
|
||||
|
||||
typedef enum {
|
||||
PAYLOAD_TYPE_KV = 0,
|
||||
PAYLOAD_TYPE_RAW = 1,
|
||||
} EPayloadType;
|
||||
|
||||
typedef struct SVgDataBlocks {
|
||||
SVgroupInfo vg;
|
||||
int32_t numOfTables; // number of tables in current submit block
|
||||
uint32_t size;
|
||||
char *pData; // SMsgDesc + SSubmitMsg + SSubmitBlk + ...
|
||||
} SVgDataBlocks;
|
||||
|
||||
typedef struct SInsertStmtInfo {
|
||||
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;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_PARSENODES_H_*/
|
|
@ -20,108 +20,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "catalog.h"
|
||||
#include "common.h"
|
||||
#include "tname.h"
|
||||
#include "tvariant.h"
|
||||
#include "function.h"
|
||||
|
||||
typedef struct SField {
|
||||
char name[TSDB_COL_NAME_LEN];
|
||||
uint8_t type;
|
||||
int16_t bytes;
|
||||
} SField;
|
||||
|
||||
typedef struct SFieldInfo {
|
||||
int16_t numOfOutput; // number of column in result
|
||||
SField *final;
|
||||
SArray *internalField; // SArray<SInternalField>
|
||||
} SFieldInfo;
|
||||
|
||||
typedef struct SCond {
|
||||
uint64_t uid;
|
||||
int32_t len; // length of tag query condition data
|
||||
char * cond;
|
||||
} SCond;
|
||||
|
||||
typedef struct SJoinNode {
|
||||
uint64_t uid;
|
||||
int16_t tagColId;
|
||||
SArray* tsJoin;
|
||||
SArray* tagJoin;
|
||||
} SJoinNode;
|
||||
|
||||
typedef struct SJoinInfo {
|
||||
bool hasJoin;
|
||||
SJoinNode *joinTables[TSDB_MAX_JOIN_TABLE_NUM];
|
||||
} SJoinInfo;
|
||||
|
||||
typedef struct STagCond {
|
||||
int16_t relType; // relation between tbname list and query condition, including : TK_AND or TK_OR
|
||||
SCond tbnameCond; // tbname query condition, only support tbname query condition on one table
|
||||
SJoinInfo joinInfo; // join condition, only support two tables join currently
|
||||
SArray *pCond; // for different table, the query condition must be seperated
|
||||
} STagCond;
|
||||
|
||||
typedef struct STableMetaInfo {
|
||||
STableMeta *pTableMeta; // table meta, cached in client side and acquired by name
|
||||
SVgroupsInfo *vgroupList;
|
||||
SName name;
|
||||
char aliasName[TSDB_TABLE_NAME_LEN]; // alias name of table specified in query sql
|
||||
SArray *tagColList; // SArray<SColumn*>, involved tag columns
|
||||
} STableMetaInfo;
|
||||
|
||||
typedef struct SQueryStmtInfo {
|
||||
int16_t command; // the command may be different for each subclause, so keep it seperately.
|
||||
uint32_t type; // query/insert type
|
||||
STimeWindow window; // the whole query time window
|
||||
SInterval interval; // tumble time window
|
||||
SSessionWindow sessionWindow; // session time window
|
||||
SStateWindow stateWindow; // state window query
|
||||
SGroupbyExpr groupbyExpr; // groupby tags info
|
||||
SArray * colList; // SArray<SColumn*>
|
||||
SFieldInfo fieldsInfo;
|
||||
SArray** exprList; // SArray<SExprInfo*>
|
||||
SLimit limit;
|
||||
SLimit slimit;
|
||||
STagCond tagCond;
|
||||
SArray * colCond;
|
||||
SArray * order;
|
||||
int16_t numOfTables;
|
||||
int16_t curTableIdx;
|
||||
STableMetaInfo **pTableMetaInfo;
|
||||
struct STSBuf *tsBuf;
|
||||
|
||||
int16_t fillType; // final result fill type
|
||||
int64_t * fillVal; // default value for fill
|
||||
int32_t numOfFillVal; // fill value size
|
||||
|
||||
char * msg; // pointer to the pCmd->payload to keep error message temporarily
|
||||
int64_t clauseLimit; // limit for current sub clause
|
||||
|
||||
int64_t prjOffset; // offset value in the original sql expression, only applied at client side
|
||||
int64_t vgroupLimit; // table limit in case of super table projection query + global order + limit
|
||||
|
||||
int32_t udColumnId; // current user-defined constant output field column id, monotonically decreases from TSDB_UD_COLUMN_INDEX
|
||||
int32_t bufLen;
|
||||
char* buf;
|
||||
SArray *pUdfInfo;
|
||||
|
||||
struct SQueryStmtInfo *sibling; // sibling
|
||||
struct SQueryStmtInfo *pDownstream;
|
||||
SMultiFunctionsDesc info;
|
||||
SArray *pUpstream; // SArray<struct SQueryStmtInfo>
|
||||
int32_t havingFieldNum;
|
||||
int32_t exprListLevelIndex;
|
||||
} SQueryStmtInfo;
|
||||
|
||||
typedef struct SColumnIndex {
|
||||
int16_t tableIndex;
|
||||
int16_t columnIndex;
|
||||
int16_t type; // normal column/tag/ user input constant column
|
||||
} SColumnIndex;
|
||||
|
||||
struct SInsertStmtInfo;
|
||||
#include "parsenodes.h"
|
||||
|
||||
/**
|
||||
* True will be returned if the input sql string is insert, false otherwise.
|
||||
|
@ -132,17 +31,16 @@ struct SInsertStmtInfo;
|
|||
bool qIsInsertSql(const char* pStr, size_t length);
|
||||
|
||||
typedef struct SParseContext {
|
||||
const char* pAcctId;
|
||||
const char* pDbname;
|
||||
void *pRpc;
|
||||
const char* pClusterId;
|
||||
const SEpSet* pEpSet;
|
||||
int64_t id; // query id, generated by uuid generator
|
||||
int8_t schemaAttached; // denote if submit block is built with table schema or not
|
||||
const char* pSql; // sql string
|
||||
size_t sqlLen; // length of the sql string
|
||||
char* pMsg; // extended error message if exists to help avoid the problem in sql statement.
|
||||
int32_t msgLen; // max length of the msg
|
||||
SParseBasicCtx ctx;
|
||||
void *pRpc;
|
||||
struct SCatalog *pCatalog;
|
||||
const SEpSet *pEpSet;
|
||||
int64_t id; // query id, generated by uuid generator
|
||||
int8_t schemaAttached; // denote if submit block is built with table schema or not
|
||||
const char *pSql; // sql string
|
||||
size_t sqlLen; // length of the sql string
|
||||
char *pMsg; // extended error message if exists to help avoid the problem in sql statement.
|
||||
int32_t msgLen; // max length of the msg
|
||||
} SParseContext;
|
||||
|
||||
/**
|
||||
|
@ -153,27 +51,7 @@ typedef struct SParseContext {
|
|||
* @param msg extended error message if exists.
|
||||
* @return error code
|
||||
*/
|
||||
int32_t qParseQuerySql(const char* pStr, size_t length, int64_t id, int32_t* type, void** pOutput, int32_t* outputLen, char* msg, int32_t msgLen);
|
||||
|
||||
typedef enum {
|
||||
PAYLOAD_TYPE_KV = 0,
|
||||
PAYLOAD_TYPE_RAW = 1,
|
||||
} EPayloadType;
|
||||
|
||||
typedef struct SVgDataBlocks {
|
||||
int64_t vgId; // virtual group id
|
||||
int32_t numOfTables; // number of tables in current submit block
|
||||
uint32_t size;
|
||||
char *pData; // SMsgDesc + SSubmitMsg + SSubmitBlk + ...
|
||||
} SVgDataBlocks;
|
||||
|
||||
typedef struct SInsertStmtInfo {
|
||||
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;
|
||||
int32_t qParseQuerySql(const char* pStr, size_t length, SParseBasicCtx* pParseCtx, int32_t* type, void** pOutput, int32_t* outputLen, char* msg, int32_t msgLen);
|
||||
|
||||
/**
|
||||
* Parse the insert sql statement.
|
||||
|
@ -210,9 +88,9 @@ typedef struct SSourceParam {
|
|||
SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, const char* funcName, SSourceParam* pSource, SSchema* pResSchema, int16_t interSize);
|
||||
int32_t copyExprInfoList(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy);
|
||||
int32_t copyAllExprInfo(SArray* dst, const SArray* src, bool deepcopy);
|
||||
int32_t getExprFunctionLevel(SQueryStmtInfo* pQueryInfo);
|
||||
int32_t getExprFunctionLevel(const SQueryStmtInfo* pQueryInfo);
|
||||
|
||||
STableMetaInfo* getMetaInfo(SQueryStmtInfo* pQueryInfo, int32_t tableIndex);
|
||||
STableMetaInfo* getMetaInfo(const SQueryStmtInfo* pQueryInfo, int32_t tableIndex);
|
||||
SSchema *getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex);
|
||||
SSchema createSchema(uint8_t type, int16_t bytes, int16_t colId, const char* name);
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ extern "C" {
|
|||
#define QUERY_TYPE_MERGE 1
|
||||
#define QUERY_TYPE_PARTIAL 2
|
||||
#define QUERY_TYPE_SCAN 3
|
||||
#define QUERY_TYPE_MODIFY 4
|
||||
|
||||
enum OPERATOR_TYPE_E {
|
||||
OP_Unknown,
|
||||
|
@ -58,18 +59,17 @@ typedef struct SQueryNodeBasicInfo {
|
|||
|
||||
typedef struct SDataSink {
|
||||
SQueryNodeBasicInfo info;
|
||||
SDataBlockSchema schema;
|
||||
} SDataSink;
|
||||
|
||||
typedef struct SDataDispatcher {
|
||||
SDataSink sink;
|
||||
// todo
|
||||
} SDataDispatcher;
|
||||
|
||||
typedef struct SDataInserter {
|
||||
SDataSink sink;
|
||||
uint64_t uid; // unique id of the table
|
||||
// todo data field
|
||||
int32_t numOfTables;
|
||||
uint32_t size;
|
||||
char *pData;
|
||||
} SDataInserter;
|
||||
|
||||
typedef struct SPhyNode {
|
||||
|
@ -119,12 +119,13 @@ typedef struct SSubplanId {
|
|||
|
||||
typedef struct SSubplan {
|
||||
SSubplanId id; // unique id of the subplan
|
||||
int32_t type; // QUERY_TYPE_MERGE|QUERY_TYPE_PARTIAL|QUERY_TYPE_SCAN
|
||||
int32_t level; // the execution level of current subplan, starting from 0.
|
||||
SEpSet execEpSet; // for the scan sub plan, the optional execution node
|
||||
SArray *pChildern; // 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
|
||||
int32_t type; // QUERY_TYPE_MERGE|QUERY_TYPE_PARTIAL|QUERY_TYPE_SCAN
|
||||
int32_t level; // the execution level of current subplan, starting from 0.
|
||||
SEpSet execEpSet; // for the scan sub plan, the optional execution node
|
||||
SArray *pChildern; // 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
|
||||
} SSubplan;
|
||||
|
||||
typedef struct SQueryDag {
|
||||
|
@ -133,10 +134,12 @@ typedef struct SQueryDag {
|
|||
SArray *pSubplans; // Element is SArray*, and nested element is SSubplan. The execution level of subplan, starting from 0.
|
||||
} SQueryDag;
|
||||
|
||||
struct SQueryNode;
|
||||
|
||||
/**
|
||||
* Create the physical plan for the query, according to the AST.
|
||||
*/
|
||||
int32_t qCreateQueryDag(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet* pQnode, struct SQueryDag** pDag);
|
||||
int32_t qCreateQueryDag(const struct SQueryNode* pQueryInfo, struct SEpSet* pQnode, struct SQueryDag** pDag);
|
||||
|
||||
// Set datasource of this subplan, multiple calls may be made to a subplan.
|
||||
// @subplan subplan to be schedule
|
||||
|
@ -144,7 +147,7 @@ int32_t qCreateQueryDag(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet*
|
|||
// @ep one execution location of this group of datasource subplans
|
||||
int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SEpAddr* ep);
|
||||
|
||||
int32_t qExplainQuery(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet* pQnode, char** str);
|
||||
int32_t qExplainQuery(const struct SQueryNode* pQueryInfo, struct SEpSet* pQnode, char** str);
|
||||
|
||||
/**
|
||||
* Convert to subplan to string for the scheduler to send to the executor
|
||||
|
|
|
@ -24,6 +24,15 @@ extern "C" {
|
|||
#include "thash.h"
|
||||
#include "tlog.h"
|
||||
|
||||
enum {
|
||||
JOB_TASK_STATUS_NOT_START = 1,
|
||||
JOB_TASK_STATUS_EXECUTING,
|
||||
JOB_TASK_STATUS_SUCCEED,
|
||||
JOB_TASK_STATUS_FAILED,
|
||||
JOB_TASK_STATUS_CANCELLING,
|
||||
JOB_TASK_STATUS_CANCELLED
|
||||
};
|
||||
|
||||
typedef struct STableComInfo {
|
||||
uint8_t numOfTags; // the number of tags in schema
|
||||
uint8_t precision; // the number of precision
|
||||
|
@ -81,16 +90,28 @@ typedef struct STableMetaOutput {
|
|||
STableMeta *tbMeta;
|
||||
} STableMetaOutput;
|
||||
|
||||
typedef int32_t __async_exec_fn_t(void* param);
|
||||
|
||||
bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags);
|
||||
|
||||
int32_t initTaskQueue();
|
||||
int32_t cleanupTaskQueue();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param execFn The asynchronously execution function
|
||||
* @param execParam The parameters of the execFn
|
||||
* @param code The response code during execution the execFn
|
||||
* @return
|
||||
*/
|
||||
int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code);
|
||||
|
||||
SSchema* tGetTbnameColumnSchema();
|
||||
void msgInit();
|
||||
|
||||
extern int32_t (*queryBuildMsg[TSDB_MSG_TYPE_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen);
|
||||
extern int32_t (*queryProcessMsgRsp[TSDB_MSG_TYPE_MAX])(void* output, char *msg, int32_t msgSize);
|
||||
|
||||
SSchema* tGetTbnameColumnSchema();
|
||||
extern void msgInit();
|
||||
|
||||
extern int32_t qDebugFlag;
|
||||
|
||||
#define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", qDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define qError(...) do { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", qDebugFlag, __VA_ARGS__); }} while(0)
|
||||
#define qWarn(...) do { if (qDebugFlag & DEBUG_WARN) { taosPrintLog("QRY WARN ", qDebugFlag, __VA_ARGS__); }} while(0)
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_QWORKER_H_
|
||||
#define _TD_QWORKER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "trpc.h"
|
||||
|
||||
typedef struct SQWorkerCfg {
|
||||
uint32_t maxSchedulerNum;
|
||||
uint32_t maxResCacheNum;
|
||||
uint32_t maxSchTaskNum;
|
||||
} SQWorkerCfg;
|
||||
|
||||
typedef struct {
|
||||
uint64_t numOfStartTask;
|
||||
uint64_t numOfStopTask;
|
||||
uint64_t numOfRecvedFetch;
|
||||
uint64_t numOfSentHb;
|
||||
uint64_t numOfSentFetch;
|
||||
uint64_t numOfTaskInQueue;
|
||||
uint64_t numOfFetchInQueue;
|
||||
uint64_t numOfErrors;
|
||||
} SQWorkerStat;
|
||||
|
||||
|
||||
int32_t qWorkerInit(SQWorkerCfg *cfg, void **qWorkerMgmt);
|
||||
|
||||
int32_t qWorkerProcessQueryMsg(void *qWorkerMgmt, SSchedulerQueryMsg *msg, SRpcMsg *rsp);
|
||||
|
||||
int32_t qWorkerProcessReadyMsg(void *qWorkerMgmt, SSchedulerReadyMsg *msg, SRpcMsg *rsp);
|
||||
|
||||
int32_t qWorkerProcessStatusMsg(void *qWorkerMgmt, SSchedulerStatusMsg *msg, SRpcMsg *rsp);
|
||||
|
||||
int32_t qWorkerProcessFetchMsg(void *qWorkerMgmt, SSchedulerFetchMsg *msg, SRpcMsg *rsp);
|
||||
|
||||
int32_t qWorkerProcessCancelMsg(void *qWorkerMgmt, SSchedulerCancelMsg *msg, SRpcMsg *rsp);
|
||||
|
||||
void qWorkerDestroy(void **qWorkerMgmt);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_QWORKER_H_*/
|
|
@ -25,6 +25,7 @@ extern "C" {
|
|||
|
||||
typedef struct SSchedulerCfg {
|
||||
int32_t clusterType;
|
||||
int32_t maxJobNum;
|
||||
} SSchedulerCfg;
|
||||
|
||||
typedef struct SQueryProfileSummary {
|
||||
|
|
|
@ -230,6 +230,10 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_INVALID_FUNC_CODE TAOS_DEF_ERROR_CODE(0, 0x03C5)
|
||||
#define TSDB_CODE_MND_INVALID_FUNC_BUFSIZE TAOS_DEF_ERROR_CODE(0, 0x03C6)
|
||||
|
||||
// mnode-trans
|
||||
#define TSDB_CODE_MND_TRANS_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03D0)
|
||||
#define TSDB_CODE_MND_TRANS_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03D1)
|
||||
|
||||
// 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)
|
||||
|
|
|
@ -193,11 +193,10 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p);
|
|||
|
||||
/**
|
||||
* Get the corresponding key information for a given data in hash table
|
||||
* @param pHashObj
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
int32_t taosHashGetKey(SHashObj *pHashObj, void *data, void** key, size_t* keyLen);
|
||||
int32_t taosHashGetKey(void *data, void** key, size_t* keyLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ extern "C" {
|
|||
#include "tdef.h"
|
||||
|
||||
// create new thread
|
||||
pthread_t* taosCreateThread( void *(*__start_routine) (void *), void* param);
|
||||
// destory thread
|
||||
pthread_t* taosCreateThread(void* (*__start_routine)(void*), void* param);
|
||||
// destory thread
|
||||
bool taosDestoryThread(pthread_t* pthread);
|
||||
// thread running return true
|
||||
bool taosThreadRunning(pthread_t* pthread);
|
||||
|
|
|
@ -86,26 +86,32 @@ typedef struct STscObj {
|
|||
SAppInstInfo *pAppInfo;
|
||||
} STscObj;
|
||||
|
||||
typedef struct SClientResultInfo {
|
||||
const char *pMsg;
|
||||
typedef struct SReqResultInfo {
|
||||
const char *pRspMsg;
|
||||
const char *pData;
|
||||
TAOS_FIELD *fields;
|
||||
int32_t numOfCols;
|
||||
int32_t numOfRows;
|
||||
int32_t current;
|
||||
uint32_t numOfCols;
|
||||
|
||||
int32_t *length;
|
||||
TAOS_ROW row;
|
||||
char **pCol;
|
||||
} SClientResultInfo;
|
||||
|
||||
typedef struct SReqBody {
|
||||
tsem_t rspSem; // not used now
|
||||
void* fp;
|
||||
void* param;
|
||||
int32_t paramLen;
|
||||
int64_t execId; // showId/queryId
|
||||
SClientResultInfo* pResInfo;
|
||||
} SRequestBody;
|
||||
uint32_t numOfRows;
|
||||
uint32_t current;
|
||||
} SReqResultInfo;
|
||||
|
||||
typedef struct SReqMsg {
|
||||
void *pMsg;
|
||||
uint32_t len;
|
||||
} SReqMsgInfo;
|
||||
|
||||
typedef struct SRequestSendRecvBody {
|
||||
tsem_t rspSem; // not used now
|
||||
void* fp;
|
||||
int64_t execId; // showId/queryId
|
||||
SReqMsgInfo requestMsg;
|
||||
SReqResultInfo resInfo;
|
||||
} SRequestSendRecvBody;
|
||||
|
||||
#define ERROR_MSG_BUF_DEFAULT_SIZE 512
|
||||
|
||||
|
@ -115,7 +121,7 @@ typedef struct SRequestObj {
|
|||
STscObj *pTscObj;
|
||||
SQueryExecMetric metric;
|
||||
char *sqlstr; // sql string
|
||||
SRequestBody body;
|
||||
SRequestSendRecvBody body;
|
||||
int64_t self;
|
||||
char *msgBuf;
|
||||
int32_t code;
|
||||
|
@ -123,11 +129,10 @@ typedef struct SRequestObj {
|
|||
} SRequestObj;
|
||||
|
||||
typedef struct SRequestMsgBody {
|
||||
int32_t msgType;
|
||||
void *pData;
|
||||
int32_t msgLen;
|
||||
uint64_t requestId;
|
||||
uint64_t requestObjRefId;
|
||||
int32_t msgType;
|
||||
SReqMsgInfo msgInfo;
|
||||
uint64_t requestId;
|
||||
uint64_t requestObjRefId;
|
||||
} SRequestMsgBody;
|
||||
|
||||
extern SAppInfo appInfo;
|
||||
|
@ -143,13 +148,16 @@ int taos_init();
|
|||
void* createTscObj(const char* user, const char* auth, const char *ip, uint32_t port, SAppInstInfo* pAppInfo);
|
||||
void destroyTscObj(void*pObj);
|
||||
|
||||
void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type);
|
||||
void destroyRequest(SRequestObj* pRequest);
|
||||
void *createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type);
|
||||
void destroyRequest(SRequestObj* pRequest);
|
||||
|
||||
char *getConnectionDB(STscObj* pObj);
|
||||
void setConnectionDB(STscObj* pTscObj, const char* db);
|
||||
|
||||
void taos_init_imp(void);
|
||||
int taos_options_imp(TSDB_OPTION option, const char *str);
|
||||
|
||||
void* openTransporter(const char *user, const char *auth);
|
||||
void* openTransporter(const char *user, const char *auth, int32_t numOfThreads);
|
||||
|
||||
void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet);
|
||||
void initMsgHandleFp();
|
||||
|
@ -158,7 +166,7 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass,
|
|||
TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen);
|
||||
|
||||
void* doFetchRow(SRequestObj* pRequest);
|
||||
void setResultDataPtr(SClientResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows);
|
||||
void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -13,17 +13,17 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
#include "os.h"
|
||||
#include "taosmsg.h"
|
||||
#include "query.h"
|
||||
#include "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
#include "tcache.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tnote.h"
|
||||
#include "tref.h"
|
||||
#include "trpc.h"
|
||||
#include "tsched.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimezone.h"
|
||||
|
||||
|
@ -33,10 +33,8 @@
|
|||
SAppInfo appInfo;
|
||||
int32_t tscReqRef = -1;
|
||||
int32_t tscConnRef = -1;
|
||||
void *tscQhandle = NULL;
|
||||
|
||||
static pthread_once_t tscinit = PTHREAD_ONCE_INIT;
|
||||
int32_t tsNumOfThreads = 1;
|
||||
volatile int32_t tscInitRes = 0;
|
||||
|
||||
static void registerRequest(SRequestObj* pRequest) {
|
||||
|
@ -98,12 +96,12 @@ void closeTransporter(STscObj* pTscObj) {
|
|||
}
|
||||
|
||||
// TODO refactor
|
||||
void* openTransporter(const char *user, const char *auth) {
|
||||
void* openTransporter(const char *user, const char *auth, int32_t numOfThread) {
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localPort = 0;
|
||||
rpcInit.label = "TSC";
|
||||
rpcInit.numOfThreads = tsNumOfThreads;
|
||||
rpcInit.numOfThreads = numOfThread;
|
||||
rpcInit.cfp = processMsgFromServer;
|
||||
rpcInit.sessions = tsMaxConnections;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
|
@ -170,7 +168,7 @@ void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t ty
|
|||
pRequest->type = type;
|
||||
pRequest->pTscObj = pObj;
|
||||
pRequest->body.fp = fp;
|
||||
pRequest->body.param = param;
|
||||
// pRequest->body.requestMsg. = param;
|
||||
pRequest->msgBuf = calloc(1, ERROR_MSG_BUF_DEFAULT_SIZE);
|
||||
tsem_init(&pRequest->body.rspSem, 0, 0);
|
||||
|
||||
|
@ -188,11 +186,7 @@ static void doDestroyRequest(void* p) {
|
|||
tfree(pRequest->sqlstr);
|
||||
tfree(pRequest->pInfo);
|
||||
|
||||
if (pRequest->body.pResInfo != NULL) {
|
||||
tfree(pRequest->body.pResInfo->pData);
|
||||
tfree(pRequest->body.pResInfo->pMsg);
|
||||
tfree(pRequest->body.pResInfo);
|
||||
}
|
||||
tfree(pRequest->body.resInfo.pRspMsg);
|
||||
|
||||
deregisterRequest(pRequest);
|
||||
tfree(pRequest);
|
||||
|
@ -233,18 +227,8 @@ void taos_init_imp(void) {
|
|||
|
||||
taosSetCoreDump(true);
|
||||
|
||||
double factor = 4.0;
|
||||
int32_t numOfThreads = MAX((int)(tsNumOfCores * tsNumOfThreadsPerCore / factor), 2);
|
||||
initTaskQueue();
|
||||
|
||||
int32_t queueSize = tsMaxConnections * 2;
|
||||
tscQhandle = taosInitScheduler(queueSize, numOfThreads, "tsc");
|
||||
if (NULL == tscQhandle) {
|
||||
tscError("failed to init task queue");
|
||||
tscInitRes = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
tscDebug("client task queue is initialized, numOfThreads: %d", numOfThreads);
|
||||
tscConnRef = taosOpenRef(200, destroyTscObj);
|
||||
tscReqRef = taosOpenRef(40960, doDestroyRequest);
|
||||
|
|
@ -102,9 +102,8 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass,
|
|||
SAppInstInfo** pInst = taosHashGet(appInfo.pInstMap, key, strlen(key));
|
||||
if (pInst == NULL) {
|
||||
SAppInstInfo* p = calloc(1, sizeof(struct SAppInstInfo));
|
||||
|
||||
p->mgmtEp = epSet;
|
||||
p->pTransporter = openTransporter(user, secretEncrypt);
|
||||
p->pTransporter = openTransporter(user, secretEncrypt, tsNumOfCores);
|
||||
taosHashPut(appInfo.pInstMap, key, strlen(key), &p, POINTER_BYTES);
|
||||
|
||||
pInst = &p;
|
||||
|
@ -152,11 +151,14 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
|
|||
int32_t type = 0;
|
||||
void* output = NULL;
|
||||
int32_t outputLen = 0;
|
||||
code = qParseQuerySql(pRequest->sqlstr, sqlLen, pRequest->requestId, &type, &output, &outputLen, pRequest->msgBuf, ERROR_MSG_BUF_DEFAULT_SIZE);
|
||||
if (type == TSDB_SQL_CREATE_USER || type == TSDB_SQL_SHOW || type == TSDB_SQL_DROP_USER || type == TSDB_SQL_CREATE_DB) {
|
||||
|
||||
SParseBasicCtx c = {.requestId = pRequest->requestId, .acctId = pTscObj->acctId, .db = getConnectionDB(pTscObj)};
|
||||
code = qParseQuerySql(pRequest->sqlstr, sqlLen, &c, &type, &output, &outputLen, pRequest->msgBuf, ERROR_MSG_BUF_DEFAULT_SIZE);
|
||||
if (type == TSDB_SQL_CREATE_USER || type == TSDB_SQL_SHOW || type == TSDB_SQL_DROP_USER ||
|
||||
type == TSDB_SQL_DROP_ACCT || type == TSDB_SQL_CREATE_DB || type == TSDB_SQL_CREATE_ACCT ||
|
||||
type == TSDB_SQL_CREATE_TABLE || type == TSDB_SQL_USE_DB) {
|
||||
pRequest->type = type;
|
||||
pRequest->body.param = output;
|
||||
pRequest->body.paramLen = outputLen;
|
||||
pRequest->body.requestMsg = (SReqMsgInfo){.pMsg = output, .len = outputLen};
|
||||
|
||||
SRequestMsgBody body = {0};
|
||||
buildRequestMsgFp[type](pRequest, &body);
|
||||
|
@ -169,6 +171,8 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
|
|||
} else {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
tfree(c.db);
|
||||
}
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -255,7 +259,7 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con
|
|||
|
||||
static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) {
|
||||
pMsgBody->msgType = TSDB_MSG_TYPE_CONNECT;
|
||||
pMsgBody->msgLen = sizeof(SConnectMsg);
|
||||
pMsgBody->msgInfo.len = sizeof(SConnectMsg);
|
||||
pMsgBody->requestObjRefId = pRequest->self;
|
||||
|
||||
SConnectMsg *pConnect = calloc(1, sizeof(SConnectMsg));
|
||||
|
@ -279,28 +283,28 @@ static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody)
|
|||
pConnect->startTime = htobe64(appInfo.startTime);
|
||||
tstrncpy(pConnect->app, appInfo.appName, tListLen(pConnect->app));
|
||||
|
||||
pMsgBody->pData = pConnect;
|
||||
pMsgBody->msgInfo.pMsg = pConnect;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void destroyRequestMsgBody(SRequestMsgBody* pMsgBody) {
|
||||
assert(pMsgBody != NULL);
|
||||
tfree(pMsgBody->pData);
|
||||
tfree(pMsgBody->msgInfo.pMsg);
|
||||
}
|
||||
|
||||
int32_t sendMsgToServer(void *pTransporter, SEpSet* epSet, const SRequestMsgBody *pBody, int64_t* pTransporterId) {
|
||||
char *pMsg = rpcMallocCont(pBody->msgLen);
|
||||
char *pMsg = rpcMallocCont(pBody->msgInfo.len);
|
||||
if (NULL == pMsg) {
|
||||
tscError("0x%"PRIx64" msg:%s malloc failed", pBody->requestId, taosMsg[pBody->msgType]);
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(pMsg, pBody->pData, pBody->msgLen);
|
||||
memcpy(pMsg, pBody->msgInfo.pMsg, pBody->msgInfo.len);
|
||||
SRpcMsg rpcMsg = {
|
||||
.msgType = pBody->msgType,
|
||||
.pCont = pMsg,
|
||||
.contLen = pBody->msgLen,
|
||||
.contLen = pBody->msgInfo.len,
|
||||
.ahandle = (void*) pBody->requestObjRefId,
|
||||
.handle = NULL,
|
||||
.code = 0
|
||||
|
@ -388,7 +392,7 @@ TAOS *taos_connect_l(const char *ip, int ipLen, const char *user, int userLen, c
|
|||
|
||||
void* doFetchRow(SRequestObj* pRequest) {
|
||||
assert(pRequest != NULL);
|
||||
SClientResultInfo* pResultInfo = pRequest->body.pResInfo;
|
||||
SReqResultInfo* pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
if (pResultInfo->pData == NULL || pResultInfo->current >= pResultInfo->numOfRows) {
|
||||
pRequest->type = TSDB_SQL_RETRIEVE_MNODE;
|
||||
|
@ -421,7 +425,7 @@ void* doFetchRow(SRequestObj* pRequest) {
|
|||
return pResultInfo->row;
|
||||
}
|
||||
|
||||
void setResultDataPtr(SClientResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows) {
|
||||
void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows) {
|
||||
assert(numOfCols > 0 && pFields != NULL && pResultInfo != NULL);
|
||||
if (numOfRows == 0) {
|
||||
return;
|
||||
|
@ -436,8 +440,19 @@ void setResultDataPtr(SClientResultInfo* pResultInfo, TAOS_FIELD* pFields, int32
|
|||
}
|
||||
}
|
||||
|
||||
const char *taos_get_client_info() { return version; }
|
||||
char* getConnectionDB(STscObj* pObj) {
|
||||
char *p = NULL;
|
||||
pthread_mutex_lock(&pObj->mutex);
|
||||
p = strndup(pObj->db, tListLen(pObj->db));
|
||||
pthread_mutex_unlock(&pObj->mutex);
|
||||
|
||||
int taos_affected_rows(TAOS_RES *res) { return 1; }
|
||||
return p;
|
||||
}
|
||||
|
||||
void setConnectionDB(STscObj* pTscObj, const char* db) {
|
||||
assert(db != NULL && pTscObj != NULL);
|
||||
pthread_mutex_lock(&pTscObj->mutex);
|
||||
tstrncpy(pTscObj->db, db, tListLen(pTscObj->db));
|
||||
pthread_mutex_unlock(&pTscObj->mutex);
|
||||
}
|
||||
|
||||
int taos_result_precision(TAOS_RES *res) { return TSDB_TIME_PRECISION_MILLI; }
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
#include "os.h"
|
||||
#include "clientInt.h"
|
||||
#include "clientLog.h"
|
||||
#include "os.h"
|
||||
#include "query.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tcache.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tnote.h"
|
||||
#include "tref.h"
|
||||
#include "trpc.h"
|
||||
#include "tsched.h"
|
||||
#include "ttime.h"
|
||||
#include "ttimezone.h"
|
||||
|
||||
#define TSC_VAR_NOT_RELEASE 1
|
||||
#define TSC_VAR_RELEASED 0
|
||||
|
@ -44,9 +39,7 @@ void taos_cleanup(void) {
|
|||
tscReqRef = -1;
|
||||
taosCloseRef(id);
|
||||
|
||||
void* p = tscQhandle;
|
||||
tscQhandle = NULL;
|
||||
taosCleanUpScheduler(p);
|
||||
cleanupTaskQueue();
|
||||
|
||||
id = tscConnRef;
|
||||
tscConnRef = -1;
|
||||
|
@ -115,12 +108,7 @@ int taos_field_count(TAOS_RES *res) {
|
|||
}
|
||||
|
||||
SRequestObj* pRequest = (SRequestObj*) res;
|
||||
|
||||
SClientResultInfo* pResInfo = pRequest->body.pResInfo;
|
||||
if (pResInfo == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SReqResultInfo* pResInfo = &pRequest->body.resInfo;
|
||||
return pResInfo->numOfCols;
|
||||
}
|
||||
|
||||
|
@ -133,7 +121,7 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SClientResultInfo* pResInfo = ((SRequestObj*) res)->body.pResInfo;
|
||||
SReqResultInfo* pResInfo = &(((SRequestObj*) res)->body.resInfo);
|
||||
return pResInfo->fields;
|
||||
}
|
||||
|
||||
|
@ -248,7 +236,7 @@ int* taos_fetch_lengths(TAOS_RES *res) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
return ((SRequestObj*) res)->body.pResInfo->length;
|
||||
return ((SRequestObj*) res)->body.resInfo.length;
|
||||
}
|
||||
|
||||
const char *taos_data_type(int type) {
|
||||
|
@ -267,3 +255,9 @@ const char *taos_data_type(int type) {
|
|||
default: return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
const char *taos_get_client_info() { return version; }
|
||||
|
||||
int taos_affected_rows(TAOS_RES *res) { return 1; }
|
||||
|
||||
int taos_result_precision(TAOS_RES *res) { return TSDB_TIME_PRECISION_MILLI; }
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -16,15 +16,15 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <taoserror.h>
|
||||
#include <iostream>
|
||||
#include "tglobal.h"
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
|
||||
#include "../inc/clientInt.h"
|
||||
#include "taos.h"
|
||||
#include "tglobal.h"
|
||||
#include "../inc/clientInt.h"
|
||||
|
||||
namespace {
|
||||
} // namespace
|
||||
|
@ -40,13 +40,13 @@ TEST(testCase, driverInit_Test) {
|
|||
|
||||
TEST(testCase, connect_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
// assert(pConn != NULL);
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, create_user_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
// assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'");
|
||||
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
|
||||
|
@ -57,22 +57,35 @@ TEST(testCase, create_user_Test) {
|
|||
taos_close(pConn);
|
||||
}
|
||||
|
||||
//TEST(testCase, drop_user_Test) {
|
||||
// TAOS* pConn = taos_connect("ubuntu", "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, create_account_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "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("ubuntu", "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("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
// assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "show users");
|
||||
TAOS_ROW pRow = NULL;
|
||||
|
@ -89,10 +102,23 @@ TEST(testCase, show_user_Test) {
|
|||
taos_close(pConn);
|
||||
}
|
||||
|
||||
TEST(testCase, show_db_Test) {
|
||||
TEST(testCase, drop_user_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "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("ubuntu", "root", "taosdata", NULL, 0);
|
||||
// assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "show databases");
|
||||
TAOS_ROW pRow = NULL;
|
||||
|
||||
|
@ -112,7 +138,40 @@ TEST(testCase, create_db_Test) {
|
|||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database abc");
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database abc1");
|
||||
|
||||
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, use_db_test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
|
||||
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, create_stable_Test) {
|
||||
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
|
||||
assert(pConn != NULL);
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "create stable st1(ts timestamp, k int) tags(a int)");
|
||||
|
||||
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
ASSERT_TRUE(pFields == NULL);
|
||||
|
|
|
@ -6,21 +6,6 @@
|
|||
|
||||
#define VALID_NAME_TYPE(x) ((x) == TSDB_DB_NAME_T || (x) == TSDB_TABLE_NAME_T)
|
||||
|
||||
char* extractDBName(const char* tableId, char* name) {
|
||||
size_t offset1 = strcspn(tableId, &TS_PATH_DELIMITER[0]);
|
||||
size_t len = strcspn(&tableId[offset1 + 1], &TS_PATH_DELIMITER[0]);
|
||||
|
||||
return strncpy(name, &tableId[offset1 + 1], len);
|
||||
}
|
||||
|
||||
// todo remove it
|
||||
size_t tableIdPrefix(const char* name, char* prefix, int32_t len) {
|
||||
tstrncpy(prefix, name, len);
|
||||
strcat(prefix, TS_PATH_DELIMITER);
|
||||
|
||||
return strlen(prefix);
|
||||
}
|
||||
|
||||
bool tscValidateTableNameLength(size_t len) {
|
||||
return len < TSDB_TABLE_NAME_LEN;
|
||||
}
|
||||
|
@ -125,7 +110,7 @@ int32_t tNameExtractFullName(const SName* name, char* dst) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t len = snprintf(dst, TSDB_FULL_DB_NAME_LEN, "%s.%s", name->acctId, name->dbname);
|
||||
int32_t len = snprintf(dst, TSDB_FULL_DB_NAME_LEN, "%d.%s", name->acctId, name->dbname);
|
||||
|
||||
size_t tnameLen = strlen(name->tname);
|
||||
if (tnameLen > 0) {
|
||||
|
@ -141,7 +126,9 @@ int32_t tNameExtractFullName(const SName* name, char* dst) {
|
|||
|
||||
int32_t tNameLen(const SName* name) {
|
||||
assert(name != NULL);
|
||||
int32_t len = (int32_t) strlen(name->acctId);
|
||||
|
||||
char tmp[12] = {0};
|
||||
int32_t len = sprintf(tmp, "%d", name->acctId);
|
||||
int32_t len1 = (int32_t) strlen(name->dbname);
|
||||
int32_t len2 = (int32_t) strlen(name->tname);
|
||||
|
||||
|
@ -161,10 +148,6 @@ bool tNameIsValid(const SName* name) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (strlen(name->acctId) <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (name->type == TSDB_DB_NAME_T) {
|
||||
return strlen(name->dbname) > 0;
|
||||
} else {
|
||||
|
@ -237,13 +220,6 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t len = (int32_t)(p - str);
|
||||
|
||||
// too long account id or too long db name
|
||||
// if ((len >= tListLen(dst->acctId)) || (len <= 0)) {
|
||||
// return -1;
|
||||
// }
|
||||
// memcpy (dst->acctId, str, len);
|
||||
dst->acctId = strtoll(str, NULL, 10);
|
||||
}
|
||||
|
||||
|
@ -272,9 +248,8 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) {
|
|||
dst->type = TSDB_TABLE_NAME_T;
|
||||
char* start = (char*) ((p == NULL)? str: (p+1));
|
||||
|
||||
int32_t len = (int32_t) strlen(start);
|
||||
|
||||
// too long account id or too long db name
|
||||
int32_t len = (int32_t) strlen(start);
|
||||
if ((len >= tListLen(dst->tname)) || (len <= 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ static struct {
|
|||
} global = {0};
|
||||
|
||||
void dmnSigintHandle(int signum, void *info, void *ctx) {
|
||||
uError("singal:%d is received", signum);
|
||||
uInfo("singal:%d is received", signum);
|
||||
global.stop = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,6 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
|||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STB] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_VGROUP_LIST] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_KILL_QUERY] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_KILL_STREAM] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_KILL_CONN] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_HEARTBEAT] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_SHOW] = dndProcessMnodeReadMsg;
|
||||
|
|
|
@ -17,11 +17,23 @@
|
|||
#include "dndVnodes.h"
|
||||
#include "dndTransport.h"
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int32_t vgVersion;
|
||||
int8_t dropped;
|
||||
uint64_t dbUid;
|
||||
char db[TSDB_FULL_DB_NAME_LEN];
|
||||
char path[PATH_MAX + 20];
|
||||
} SWrapperCfg;
|
||||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
int32_t refCount;
|
||||
int32_t vgVersion;
|
||||
int8_t dropped;
|
||||
int8_t accessState;
|
||||
uint64_t dbUid;
|
||||
char *db;
|
||||
char *path;
|
||||
SVnode *pImpl;
|
||||
taos_queue pWriteQ;
|
||||
|
@ -32,13 +44,13 @@ typedef struct {
|
|||
} SVnodeObj;
|
||||
|
||||
typedef struct {
|
||||
int32_t vnodeNum;
|
||||
int32_t opened;
|
||||
int32_t failed;
|
||||
int32_t threadIndex;
|
||||
pthread_t *pThreadId;
|
||||
SVnodeObj *pVnodes;
|
||||
SDnode * pDnode;
|
||||
int32_t vnodeNum;
|
||||
int32_t opened;
|
||||
int32_t failed;
|
||||
int32_t threadIndex;
|
||||
pthread_t thread;
|
||||
SDnode *pDnode;
|
||||
SWrapperCfg *pCfgs;
|
||||
} SVnodeThread;
|
||||
|
||||
static int32_t dndInitVnodeReadWorker(SDnode *pDnode);
|
||||
|
@ -60,8 +72,8 @@ static void dndFreeVnodeWriteQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
|||
static void dndFreeVnodeApplyQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static void dndFreeVnodeSyncQueue(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
|
||||
static void dndProcessVnodeQueryQueue(SVnodeObj *pVnode, SVnodeMsg *pMsg);
|
||||
static void dndProcessVnodeFetchQueue(SVnodeObj *pVnode, SVnodeMsg *pMsg);
|
||||
static void dndProcessVnodeQueryQueue(SVnodeObj *pVnode, SRpcMsg *pMsg);
|
||||
static void dndProcessVnodeFetchQueue(SVnodeObj *pVnode, SRpcMsg *pMsg);
|
||||
static void dndProcessVnodeWriteQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs);
|
||||
static void dndProcessVnodeApplyQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs);
|
||||
static void dndProcessVnodeSyncQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs);
|
||||
|
@ -71,18 +83,16 @@ void dndProcessVnodeFetchMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pE
|
|||
void dndProcessVnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dndProcessVnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
void dndProcessVnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
static int32_t dndPutMsgIntoVnodeApplyQueue(SDnode *pDnode, int32_t vgId, SVnodeMsg *pMsg);
|
||||
static int32_t dndPutMsgIntoVnodeApplyQueue(SDnode *pDnode, int32_t vgId, SRpcMsg *pMsg);
|
||||
|
||||
static SVnodeObj * dndAcquireVnode(SDnode *pDnode, int32_t vgId);
|
||||
static SVnodeObj *dndAcquireVnode(SDnode *pDnode, int32_t vgId);
|
||||
static void dndReleaseVnode(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static int32_t dndCreateVnodeWrapper(SDnode *pDnode, int32_t vgId, char *path, SVnode *pImpl);
|
||||
static void dndDropVnodeWrapper(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static int32_t dndOpenVnode(SDnode *pDnode, SWrapperCfg *pCfg, SVnode *pImpl);
|
||||
static void dndCloseVnode(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static SVnodeObj **dndGetVnodesFromHash(SDnode *pDnode, int32_t *numOfVnodes);
|
||||
static int32_t dndGetVnodesFromFile(SDnode *pDnode, SVnodeObj **ppVnodes, int32_t *numOfVnodes);
|
||||
static int32_t dndGetVnodesFromFile(SDnode *pDnode, SWrapperCfg **ppCfgs, int32_t *numOfVnodes);
|
||||
static int32_t dndWriteVnodesToFile(SDnode *pDnode);
|
||||
|
||||
static int32_t dndCreateVnode(SDnode *pDnode, int32_t vgId, SVnodeCfg *pCfg);
|
||||
static int32_t dndDropVnode(SDnode *pDnode, SVnodeObj *pVnode);
|
||||
static int32_t dndOpenVnodes(SDnode *pDnode);
|
||||
static void dndCloseVnodes(SDnode *pDnode);
|
||||
|
||||
|
@ -126,22 +136,25 @@ static void dndReleaseVnode(SDnode *pDnode, SVnodeObj *pVnode) {
|
|||
dTrace("vgId:%d, release vnode, refCount:%d", pVnode->vgId, refCount);
|
||||
}
|
||||
|
||||
static int32_t dndCreateVnodeWrapper(SDnode *pDnode, int32_t vgId, char *path, SVnode *pImpl) {
|
||||
static int32_t dndOpenVnode(SDnode *pDnode, SWrapperCfg *pCfg, SVnode *pImpl) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
SVnodeObj * pVnode = calloc(1, sizeof(SVnodeObj));
|
||||
SVnodeObj *pVnode = calloc(1, sizeof(SVnodeObj));
|
||||
if (pVnode == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pVnode->vgId = vgId;
|
||||
pVnode->refCount = 0;
|
||||
pVnode->vgId = pCfg->vgId;
|
||||
pVnode->refCount = 1;
|
||||
pVnode->dropped = 0;
|
||||
pVnode->accessState = TSDB_VN_ALL_ACCCESS;
|
||||
pVnode->pImpl = pImpl;
|
||||
pVnode->vgVersion = pCfg->vgVersion;
|
||||
pVnode->dbUid = pCfg->dbUid;
|
||||
pVnode->db = tstrdup(pCfg->db);
|
||||
pVnode->path = tstrdup(pCfg->path);
|
||||
|
||||
pVnode->path = tstrdup(path);
|
||||
if (pVnode->path == NULL) {
|
||||
if (pVnode->path == NULL || pVnode->db == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
@ -167,7 +180,7 @@ static int32_t dndCreateVnodeWrapper(SDnode *pDnode, int32_t vgId, char *path, S
|
|||
}
|
||||
|
||||
taosWLockLatch(&pMgmt->latch);
|
||||
int32_t code = taosHashPut(pMgmt->hash, &vgId, sizeof(int32_t), &pVnode, sizeof(SVnodeObj *));
|
||||
int32_t code = taosHashPut(pMgmt->hash, &pVnode->vgId, sizeof(int32_t), &pVnode, sizeof(SVnodeObj *));
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
|
||||
if (code != 0) {
|
||||
|
@ -176,7 +189,7 @@ static int32_t dndCreateVnodeWrapper(SDnode *pDnode, int32_t vgId, char *path, S
|
|||
return code;
|
||||
}
|
||||
|
||||
static void dndDropVnodeWrapper(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
static void dndCloseVnode(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
taosWLockLatch(&pMgmt->latch);
|
||||
taosHashRemove(pMgmt->hash, &pVnode->vgId, sizeof(int32_t));
|
||||
|
@ -195,6 +208,9 @@ static void dndDropVnodeWrapper(SDnode *pDnode, SVnodeObj *pVnode) {
|
|||
dndFreeVnodeWriteQueue(pDnode, pVnode);
|
||||
dndFreeVnodeApplyQueue(pDnode, pVnode);
|
||||
dndFreeVnodeSyncQueue(pDnode, pVnode);
|
||||
free(pVnode->path);
|
||||
free(pVnode->db);
|
||||
free(pVnode);
|
||||
}
|
||||
|
||||
static SVnodeObj **dndGetVnodesFromHash(SDnode *pDnode, int32_t *numOfVnodes) {
|
||||
|
@ -208,16 +224,16 @@ static SVnodeObj **dndGetVnodesFromHash(SDnode *pDnode, int32_t *numOfVnodes) {
|
|||
void *pIter = taosHashIterate(pMgmt->hash, NULL);
|
||||
while (pIter) {
|
||||
SVnodeObj **ppVnode = pIter;
|
||||
SVnodeObj * pVnode = *ppVnode;
|
||||
if (pVnode) {
|
||||
SVnodeObj *pVnode = *ppVnode;
|
||||
if (pVnode && num < size) {
|
||||
int32_t refCount = atomic_add_fetch_32(&pVnode->refCount, 1);
|
||||
dTrace("vgId:%d, acquire vnode, refCount:%d", pVnode->vgId, refCount);
|
||||
pVnodes[num] = (*ppVnode);
|
||||
num++;
|
||||
if (num < size) {
|
||||
int32_t refCount = atomic_add_fetch_32(&pVnode->refCount, 1);
|
||||
dTrace("vgId:%d, acquire vnode, refCount:%d", pVnode->vgId, refCount);
|
||||
pVnodes[num] = (*ppVnode);
|
||||
}
|
||||
pIter = taosHashIterate(pMgmt->hash, pIter);
|
||||
} else {
|
||||
taosHashCancelIterate(pMgmt->hash, pIter);
|
||||
}
|
||||
pIter = taosHashIterate(pMgmt->hash, pIter);
|
||||
}
|
||||
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
@ -226,15 +242,15 @@ static SVnodeObj **dndGetVnodesFromHash(SDnode *pDnode, int32_t *numOfVnodes) {
|
|||
return pVnodes;
|
||||
}
|
||||
|
||||
static int32_t dndGetVnodesFromFile(SDnode *pDnode, SVnodeObj **ppVnodes, int32_t *numOfVnodes) {
|
||||
int32_t code = TSDB_CODE_DND_VNODE_READ_FILE_ERROR;
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 30000;
|
||||
char * content = calloc(1, maxLen + 1);
|
||||
cJSON * root = NULL;
|
||||
FILE * fp = NULL;
|
||||
char file[PATH_MAX + 20] = {0};
|
||||
SVnodeObj *pVnodes = NULL;
|
||||
static int32_t dndGetVnodesFromFile(SDnode *pDnode, SWrapperCfg **ppCfgs, int32_t *numOfVnodes) {
|
||||
int32_t code = TSDB_CODE_DND_VNODE_READ_FILE_ERROR;
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 30000;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
cJSON *root = NULL;
|
||||
FILE *fp = NULL;
|
||||
char file[PATH_MAX + 20] = {0};
|
||||
SWrapperCfg *pCfgs = NULL;
|
||||
|
||||
snprintf(file, PATH_MAX + 20, "%s/vnodes.json", pDnode->dir.vnodes);
|
||||
|
||||
|
@ -270,31 +286,55 @@ static int32_t dndGetVnodesFromFile(SDnode *pDnode, SVnodeObj **ppVnodes, int32_
|
|||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
|
||||
pVnodes = calloc(vnodesNum, sizeof(SVnodeObj));
|
||||
if (pVnodes == NULL) {
|
||||
pCfgs = calloc(vnodesNum, sizeof(SWrapperCfg));
|
||||
if (pCfgs == NULL) {
|
||||
dError("failed to read %s since out of memory", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < vnodesNum; ++i) {
|
||||
cJSON * vnode = cJSON_GetArrayItem(vnodes, i);
|
||||
SVnodeObj *pVnode = &pVnodes[i];
|
||||
cJSON *vnode = cJSON_GetArrayItem(vnodes, i);
|
||||
SWrapperCfg *pCfg = &pCfgs[i];
|
||||
|
||||
cJSON *vgId = cJSON_GetObjectItem(vnode, "vgId");
|
||||
if (!vgId || vgId->type != cJSON_String) {
|
||||
if (!vgId || vgId->type != cJSON_Number) {
|
||||
dError("failed to read %s since vgId not found", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
pVnode->vgId = atoi(vgId->valuestring);
|
||||
pCfg->vgId = vgId->valueint;
|
||||
snprintf(pCfg->path, sizeof(pCfg->path), "%s/vnode%d", pDnode->dir.vnodes, pCfg->vgId);
|
||||
|
||||
cJSON *dropped = cJSON_GetObjectItem(vnode, "dropped");
|
||||
if (!dropped || dropped->type != cJSON_String) {
|
||||
if (!dropped || dropped->type != cJSON_Number) {
|
||||
dError("failed to read %s since dropped not found", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
pVnode->dropped = atoi(vnode->valuestring);
|
||||
pCfg->dropped = dropped->valueint;
|
||||
|
||||
cJSON *vgVersion = cJSON_GetObjectItem(vnode, "vgVersion");
|
||||
if (!vgVersion || vgVersion->type != cJSON_Number) {
|
||||
dError("failed to read %s since vgVersion not found", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
pCfg->vgVersion = vgVersion->valueint;
|
||||
|
||||
cJSON *dbUid = cJSON_GetObjectItem(vnode, "dbUid");
|
||||
if (!dbUid || dbUid->type != cJSON_String) {
|
||||
dError("failed to read %s since dbUid not found", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
pCfg->dbUid = atoll(dbUid->valuestring);
|
||||
|
||||
cJSON *db = cJSON_GetObjectItem(vnode, "db");
|
||||
if (!db || db->type != cJSON_String) {
|
||||
dError("failed to read %s since db not found", file);
|
||||
goto PRASE_VNODE_OVER;
|
||||
}
|
||||
tstrncpy(pCfg->db, db->valuestring, TSDB_FULL_DB_NAME_LEN);
|
||||
}
|
||||
|
||||
*ppCfgs = pCfgs;
|
||||
*numOfVnodes = vnodesNum;
|
||||
code = 0;
|
||||
dInfo("succcessed to read file %s", file);
|
||||
|
||||
|
@ -313,30 +353,35 @@ static int32_t dndWriteVnodesToFile(SDnode *pDnode) {
|
|||
snprintf(realfile, PATH_MAX + 20, "%s/vnodes.json", pDnode->dir.vnodes);
|
||||
|
||||
FILE *fp = fopen(file, "w");
|
||||
if (fp != NULL) {
|
||||
if (fp == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to write %s since %s", file, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 30000;
|
||||
char * content = calloc(1, maxLen + 1);
|
||||
int32_t numOfVnodes = 0;
|
||||
SVnodeObj **pVnodes = dndGetVnodesFromHash(pDnode, &numOfVnodes);
|
||||
|
||||
int32_t len = 0;
|
||||
int32_t maxLen = 65536;
|
||||
char *content = calloc(1, maxLen + 1);
|
||||
|
||||
len += snprintf(content + len, maxLen - len, "{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"vnodes\": [{\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"vnodes\": [\n");
|
||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||
SVnodeObj *pVnode = pVnodes[i];
|
||||
len += snprintf(content + len, maxLen - len, " \"vgId\": \"%d\",\n", pVnode->vgId);
|
||||
len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\"\n", pVnode->dropped);
|
||||
len += snprintf(content + len, maxLen - len, " {\n");
|
||||
len += snprintf(content + len, maxLen - len, " \"vgId\": %d,\n", pVnode->vgId);
|
||||
len += snprintf(content + len, maxLen - len, " \"dropped\": %d,\n", pVnode->dropped);
|
||||
len += snprintf(content + len, maxLen - len, " \"vgVersion\": %d,\n", pVnode->vgVersion);
|
||||
len += snprintf(content + len, maxLen - len, " \"dbUid\": \"%" PRIu64 "\",\n", pVnode->dbUid);
|
||||
len += snprintf(content + len, maxLen - len, " \"db\": \"%s\"\n", pVnode->db);
|
||||
if (i < numOfVnodes - 1) {
|
||||
len += snprintf(content + len, maxLen - len, " },{\n");
|
||||
len += snprintf(content + len, maxLen - len, " },\n");
|
||||
} else {
|
||||
len += snprintf(content + len, maxLen - len, " }]\n");
|
||||
len += snprintf(content + len, maxLen - len, " }\n");
|
||||
}
|
||||
}
|
||||
len += snprintf(content + len, maxLen - len, " ]\n");
|
||||
len += snprintf(content + len, maxLen - len, "}\n");
|
||||
|
||||
fwrite(content, 1, len, fp);
|
||||
|
@ -358,74 +403,29 @@ static int32_t dndWriteVnodesToFile(SDnode *pDnode) {
|
|||
return taosRenameFile(file, realfile);
|
||||
}
|
||||
|
||||
static int32_t dndCreateVnode(SDnode *pDnode, int32_t vgId, SVnodeCfg *pCfg) {
|
||||
char path[PATH_MAX + 20] = {0};
|
||||
snprintf(path, sizeof(path), "%s/vnode%d", pDnode->dir.vnodes, vgId);
|
||||
// SVnode *pImpl = vnodeCreate(vgId, path, pCfg);
|
||||
|
||||
SVnode *pImpl = vnodeOpen(path, NULL);
|
||||
if (pImpl == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = dndCreateVnodeWrapper(pDnode, vgId, path, pImpl);
|
||||
if (code != 0) {
|
||||
vnodeClose(pImpl);
|
||||
vnodeDestroy(path);
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
code = dndWriteVnodesToFile(pDnode);
|
||||
if (code != 0) {
|
||||
vnodeClose(pImpl);
|
||||
vnodeDestroy(path);
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndDropVnode(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
pVnode->dropped = 1;
|
||||
if (dndWriteVnodesToFile(pDnode) != 0) {
|
||||
pVnode->dropped = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
dndDropVnodeWrapper(pDnode, pVnode);
|
||||
vnodeClose(pVnode->pImpl);
|
||||
vnodeDestroy(pVnode->path);
|
||||
dndWriteVnodesToFile(pDnode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *dnodeOpenVnodeFunc(void *param) {
|
||||
SVnodeThread *pThread = param;
|
||||
SDnode * pDnode = pThread->pDnode;
|
||||
SVnodesMgmt * pMgmt = &pDnode->vmgmt;
|
||||
SDnode *pDnode = pThread->pDnode;
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
|
||||
dDebug("thread:%d, start to open %d vnodes", pThread->threadIndex, pThread->vnodeNum);
|
||||
setThreadName("open-vnodes");
|
||||
|
||||
for (int32_t v = 0; v < pThread->vnodeNum; ++v) {
|
||||
SVnodeObj *pVnode = &pThread->pVnodes[v];
|
||||
SWrapperCfg *pCfg = &pThread->pCfgs[v];
|
||||
|
||||
char stepDesc[TSDB_STEP_DESC_LEN] = {0};
|
||||
snprintf(stepDesc, TSDB_STEP_DESC_LEN, "vgId:%d, start to restore, %d of %d have been opened", pVnode->vgId,
|
||||
snprintf(stepDesc, TSDB_STEP_DESC_LEN, "vgId:%d, start to restore, %d of %d have been opened", pCfg->vgId,
|
||||
pMgmt->openVnodes, pMgmt->totalVnodes);
|
||||
dndReportStartup(pDnode, "open-vnodes", stepDesc);
|
||||
|
||||
char path[PATH_MAX + 20] = {0};
|
||||
snprintf(path, sizeof(path), "%s/vnode%d", pDnode->dir.vnodes, pVnode->vgId);
|
||||
SVnode *pImpl = vnodeOpen(path, NULL);
|
||||
SVnode *pImpl = vnodeOpen(pCfg->path, NULL);
|
||||
if (pImpl == NULL) {
|
||||
dError("vgId:%d, failed to open vnode by thread:%d", pVnode->vgId, pThread->threadIndex);
|
||||
dError("vgId:%d, failed to open vnode by thread:%d", pCfg->vgId, pThread->threadIndex);
|
||||
pThread->failed++;
|
||||
} else {
|
||||
dndCreateVnodeWrapper(pDnode, pVnode->vgId, path, pImpl);
|
||||
dDebug("vgId:%d, is opened by thread:%d", pVnode->vgId, pThread->threadIndex);
|
||||
dndOpenVnode(pDnode, pCfg, pImpl);
|
||||
dDebug("vgId:%d, is opened by thread:%d", pCfg->vgId, pThread->threadIndex);
|
||||
pThread->opened++;
|
||||
}
|
||||
|
||||
|
@ -448,9 +448,9 @@ static int32_t dndOpenVnodes(SDnode *pDnode) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
SVnodeObj *pVnodes = NULL;
|
||||
int32_t numOfVnodes = 0;
|
||||
if (dndGetVnodesFromFile(pDnode, &pVnodes, &numOfVnodes) != 0) {
|
||||
SWrapperCfg *pCfgs = NULL;
|
||||
int32_t numOfVnodes = 0;
|
||||
if (dndGetVnodesFromFile(pDnode, &pCfgs, &numOfVnodes) != 0) {
|
||||
dInfo("failed to get vnode list from disk since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -463,13 +463,14 @@ static int32_t dndOpenVnodes(SDnode *pDnode) {
|
|||
SVnodeThread *threads = calloc(threadNum, sizeof(SVnodeThread));
|
||||
for (int32_t t = 0; t < threadNum; ++t) {
|
||||
threads[t].threadIndex = t;
|
||||
threads[t].pVnodes = calloc(vnodesPerThread, sizeof(SVnodeObj));
|
||||
threads[t].pDnode = pDnode;
|
||||
threads[t].pCfgs = calloc(vnodesPerThread, sizeof(SWrapperCfg));
|
||||
}
|
||||
|
||||
for (int32_t v = 0; v < numOfVnodes; ++v) {
|
||||
int32_t t = v % threadNum;
|
||||
SVnodeThread *pThread = &threads[t];
|
||||
pThread->pVnodes[pThread->vnodeNum++] = pVnodes[v];
|
||||
pThread->pCfgs[pThread->vnodeNum++] = pCfgs[v];
|
||||
}
|
||||
|
||||
dInfo("start %d threads to open %d vnodes", threadNum, numOfVnodes);
|
||||
|
@ -478,19 +479,25 @@ static int32_t dndOpenVnodes(SDnode *pDnode) {
|
|||
SVnodeThread *pThread = &threads[t];
|
||||
if (pThread->vnodeNum == 0) continue;
|
||||
|
||||
pThread->pThreadId = taosCreateThread(dnodeOpenVnodeFunc, pThread);
|
||||
if (pThread->pThreadId == NULL) {
|
||||
pthread_attr_t thAttr;
|
||||
pthread_attr_init(&thAttr);
|
||||
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||
if (pthread_create(&pThread->thread, &thAttr, dnodeOpenVnodeFunc, pThread) != 0) {
|
||||
dError("thread:%d, failed to create thread to open vnode, reason:%s", pThread->threadIndex, strerror(errno));
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&thAttr);
|
||||
}
|
||||
|
||||
for (int32_t t = 0; t < threadNum; ++t) {
|
||||
SVnodeThread *pThread = &threads[t];
|
||||
taosDestoryThread(pThread->pThreadId);
|
||||
pThread->pThreadId = NULL;
|
||||
free(pThread->pVnodes);
|
||||
if (pThread->vnodeNum > 0 && taosCheckPthreadValid(pThread->thread)) {
|
||||
pthread_join(pThread->thread, NULL);
|
||||
}
|
||||
free(pThread->pCfgs);
|
||||
}
|
||||
free(threads);
|
||||
free(pCfgs);
|
||||
|
||||
if (pMgmt->openVnodes != pMgmt->totalVnodes) {
|
||||
dError("there are total vnodes:%d, opened:%d", pMgmt->totalVnodes, pMgmt->openVnodes);
|
||||
|
@ -508,7 +515,8 @@ static void dndCloseVnodes(SDnode *pDnode) {
|
|||
SVnodeObj **pVnodes = dndGetVnodesFromHash(pDnode, &numOfVnodes);
|
||||
|
||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||
dndDropVnodeWrapper(pDnode, pVnodes[i]);
|
||||
dndReleaseVnode(pDnode, pVnodes[i]);
|
||||
dndCloseVnode(pDnode, pVnodes[i]);
|
||||
}
|
||||
|
||||
if (pVnodes != NULL) {
|
||||
|
@ -523,11 +531,12 @@ static void dndCloseVnodes(SDnode *pDnode) {
|
|||
dInfo("total vnodes:%d are all closed", numOfVnodes);
|
||||
}
|
||||
|
||||
static int32_t dndParseCreateVnodeReq(SRpcMsg *rpcMsg, int32_t *vgId, SVnodeCfg *pCfg) {
|
||||
static SCreateVnodeMsg *dndParseCreateVnodeReq(SRpcMsg *rpcMsg) {
|
||||
SCreateVnodeMsg *pCreate = rpcMsg->pCont;
|
||||
pCreate->vgId = htonl(pCreate->vgId);
|
||||
pCreate->dnodeId = htonl(pCreate->dnodeId);
|
||||
pCreate->dbUid = htobe64(pCreate->dbUid);
|
||||
pCreate->vgVersion = htonl(pCreate->vgVersion);
|
||||
pCreate->cacheBlockSize = htonl(pCreate->cacheBlockSize);
|
||||
pCreate->totalBlocks = htonl(pCreate->totalBlocks);
|
||||
pCreate->daysPerFile = htonl(pCreate->daysPerFile);
|
||||
|
@ -544,9 +553,10 @@ static int32_t dndParseCreateVnodeReq(SRpcMsg *rpcMsg, int32_t *vgId, SVnodeCfg
|
|||
pReplica->port = htons(pReplica->port);
|
||||
}
|
||||
|
||||
*vgId = pCreate->vgId;
|
||||
return pCreate;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void dndGenerateVnodeCfg(SCreateVnodeMsg *pCreate, SVnodeCfg *pCfg) {
|
||||
pCfg->wsize = pCreate->cacheBlockSize;
|
||||
pCfg->ssize = pCreate->cacheBlockSize;
|
||||
pCfg->wsize = pCreate->cacheBlockSize;
|
||||
|
@ -567,8 +577,15 @@ static int32_t dndParseCreateVnodeReq(SRpcMsg *rpcMsg, int32_t *vgId, SVnodeCfg
|
|||
pCfg->walCfg.rollPeriod = 128;
|
||||
pCfg->walCfg.segSize = 128;
|
||||
pCfg->walCfg.vgId = pCreate->vgId;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndGenerateWrapperCfg(SDnode *pDnode, SCreateVnodeMsg *pCreate, SWrapperCfg *pCfg) {
|
||||
memcpy(pCfg->db, pCreate->db, TSDB_FULL_DB_NAME_LEN);
|
||||
pCfg->dbUid = pCreate->dbUid;
|
||||
pCfg->dropped = 0;
|
||||
snprintf(pCfg->path, sizeof(pCfg->path), "%s/vnode%d", pDnode->dir.vnodes, pCreate->vgId);
|
||||
pCfg->vgId = pCreate->vgId;
|
||||
pCfg->vgVersion = pCreate->vgVersion;
|
||||
}
|
||||
|
||||
static SDropVnodeMsg *vnodeParseDropVnodeReq(SRpcMsg *rpcMsg) {
|
||||
|
@ -584,48 +601,83 @@ static SAuthVnodeMsg *vnodeParseAuthVnodeReq(SRpcMsg *rpcMsg) {
|
|||
}
|
||||
|
||||
static int32_t dndProcessCreateVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
||||
SCreateVnodeMsg *pCreate = dndParseCreateVnodeReq(rpcMsg);
|
||||
dDebug("vgId:%d, create vnode req is received", pCreate->vgId);
|
||||
|
||||
SVnodeCfg vnodeCfg = {0};
|
||||
int32_t vgId = 0;
|
||||
dndGenerateVnodeCfg(pCreate, &vnodeCfg);
|
||||
|
||||
dndParseCreateVnodeReq(rpcMsg, &vgId, &vnodeCfg);
|
||||
dDebug("vgId:%d, create vnode req is received", vgId);
|
||||
SWrapperCfg wrapperCfg = {0};
|
||||
dndGenerateWrapperCfg(pDnode, pCreate, &wrapperCfg);
|
||||
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, vgId);
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, pCreate->vgId);
|
||||
if (pVnode != NULL) {
|
||||
dDebug("vgId:%d, already exist, return success", vgId);
|
||||
dDebug("vgId:%d, already exist, return success", pCreate->vgId);
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dndCreateVnode(pDnode, vgId, &vnodeCfg) != 0) {
|
||||
dError("vgId:%d, failed to create vnode since %s", vgId, terrstr());
|
||||
return terrno;
|
||||
SVnode *pImpl = vnodeOpen(wrapperCfg.path, NULL /*pCfg*/);
|
||||
if (pImpl == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = dndOpenVnode(pDnode, &wrapperCfg, pImpl);
|
||||
if (code != 0) {
|
||||
vnodeClose(pImpl);
|
||||
vnodeDestroy(wrapperCfg.path);
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
code = dndWriteVnodesToFile(pDnode);
|
||||
if (code != 0) {
|
||||
vnodeClose(pImpl);
|
||||
vnodeDestroy(wrapperCfg.path);
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndProcessAlterVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
||||
SAlterVnodeMsg *pAlter = (SAlterVnodeMsg *)dndParseCreateVnodeReq(rpcMsg);
|
||||
dDebug("vgId:%d, alter vnode req is received", pAlter->vgId);
|
||||
|
||||
SVnodeCfg vnodeCfg = {0};
|
||||
int32_t vgId = 0;
|
||||
dndGenerateVnodeCfg(pAlter, &vnodeCfg);
|
||||
|
||||
dndParseCreateVnodeReq(rpcMsg, &vgId, &vnodeCfg);
|
||||
dDebug("vgId:%d, alter vnode req is received", vgId);
|
||||
SWrapperCfg wrapperCfg = {0};
|
||||
dndGenerateWrapperCfg(pDnode, pAlter, &wrapperCfg);
|
||||
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, vgId);
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, pAlter->vgId);
|
||||
if (pVnode == NULL) {
|
||||
dDebug("vgId:%d, failed to alter vnode since %s", vgId, terrstr());
|
||||
dDebug("vgId:%d, failed to alter vnode since %s", pAlter->vgId, terrstr());
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (wrapperCfg.vgVersion == pVnode->vgVersion) {
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
dDebug("vgId:%d, no need to alter vnode cfg for version unchanged ", pAlter->vgId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (vnodeAlter(pVnode->pImpl, &vnodeCfg) != 0) {
|
||||
dError("vgId:%d, failed to alter vnode since %s", vgId, terrstr());
|
||||
dError("vgId:%d, failed to alter vnode since %s", pAlter->vgId, terrstr());
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return terrno;
|
||||
}
|
||||
|
||||
int32_t oldVersion = pVnode->vgVersion;
|
||||
pVnode->vgVersion = wrapperCfg.vgVersion;
|
||||
int32_t code = dndWriteVnodesToFile(pDnode);
|
||||
if (code != 0) {
|
||||
pVnode->vgVersion = oldVersion;
|
||||
}
|
||||
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
||||
|
@ -637,14 +689,20 @@ static int32_t dndProcessDropVnodeReq(SDnode *pDnode, SRpcMsg *rpcMsg) {
|
|||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, vgId);
|
||||
if (pVnode == NULL) {
|
||||
dDebug("vgId:%d, failed to drop since %s", vgId, terrstr());
|
||||
return 0;
|
||||
}
|
||||
|
||||
pVnode->dropped = 1;
|
||||
if (dndWriteVnodesToFile(pDnode) != 0) {
|
||||
pVnode->dropped = 0;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (dndDropVnode(pDnode, pVnode) != 0) {
|
||||
dError("vgId:%d, failed to drop vnode since %s", vgId, terrstr());
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
return terrno;
|
||||
}
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
dndCloseVnode(pDnode, pVnode);
|
||||
vnodeClose(pVnode->pImpl);
|
||||
vnodeDestroy(pVnode->path);
|
||||
dndWriteVnodesToFile(pDnode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -738,48 +796,76 @@ static void dndProcessVnodeMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg) {
|
|||
break;
|
||||
}
|
||||
|
||||
if (code != 0) {
|
||||
SRpcMsg rsp = {.code = code, .handle = pMsg->handle};
|
||||
rpcSendResponse(&rsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
SRpcMsg rsp = {.code = code, .handle = pMsg->handle, .ahandle = pMsg->ahandle};
|
||||
rpcSendResponse(&rsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
static void dndProcessVnodeQueryQueue(SVnodeObj *pVnode, SVnodeMsg *pMsg) {
|
||||
vnodeProcessMsg(pVnode->pImpl, pMsg, VN_MSG_TYPE_QUERY);
|
||||
static void dndProcessVnodeQueryQueue(SVnodeObj *pVnode, SRpcMsg *pMsg) {
|
||||
SRpcMsg *pRsp = NULL;
|
||||
vnodeProcessQueryReq(pVnode->pImpl, pMsg, &pRsp);
|
||||
}
|
||||
|
||||
static void dndProcessVnodeFetchQueue(SVnodeObj *pVnode, SVnodeMsg *pMsg) {
|
||||
vnodeProcessMsg(pVnode->pImpl, pMsg, VN_MSG_TYPE_FETCH);
|
||||
static void dndProcessVnodeFetchQueue(SVnodeObj *pVnode, SRpcMsg *pMsg) {
|
||||
SRpcMsg *pRsp = NULL;
|
||||
vnodeProcessFetchReq(pVnode->pImpl, pMsg, &pRsp);
|
||||
}
|
||||
|
||||
static void dndProcessVnodeWriteQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs) {
|
||||
SVnodeMsg *pMsg = vnodeInitMsg(numOfMsgs);
|
||||
SRpcMsg * pRpcMsg = NULL;
|
||||
SArray *pArray = taosArrayInit(numOfMsgs, sizeof(SRpcMsg *));
|
||||
|
||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
taosGetQitem(qall, (void **)&pRpcMsg);
|
||||
vnodeAppendMsg(pMsg, pRpcMsg);
|
||||
taosFreeQitem(pRpcMsg);
|
||||
SRpcMsg *pMsg = NULL;
|
||||
taosGetQitem(qall, (void **)&pMsg);
|
||||
void *ptr = taosArrayPush(pArray, &pMsg);
|
||||
assert(ptr != NULL);
|
||||
}
|
||||
|
||||
vnodeProcessMsg(pVnode->pImpl, pMsg, VN_MSG_TYPE_WRITE);
|
||||
vnodeProcessWMsgs(pVnode->pImpl, pArray);
|
||||
|
||||
for (size_t i = 0; i < numOfMsgs; i++) {
|
||||
SRpcMsg *pRsp = NULL;
|
||||
SRpcMsg *pMsg = *(SRpcMsg **)taosArrayGet(pArray, i);
|
||||
int32_t code = vnodeApplyWMsg(pVnode->pImpl, pMsg, &pRsp);
|
||||
if (pRsp != NULL) {
|
||||
rpcSendResponse(pRsp);
|
||||
free(pRsp);
|
||||
} else {
|
||||
if (code != 0) code = terrno;
|
||||
SRpcMsg rpcRsp = {.handle = pMsg->handle, .ahandle = pMsg->ahandle, .code = code};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < numOfMsgs; i++) {
|
||||
SRpcMsg *pMsg = *(SRpcMsg **)taosArrayGet(pArray, i);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pArray);
|
||||
}
|
||||
|
||||
static void dndProcessVnodeApplyQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs) {
|
||||
SVnodeMsg *pMsg = NULL;
|
||||
SRpcMsg *pMsg = NULL;
|
||||
|
||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
taosGetQitem(qall, (void **)&pMsg);
|
||||
vnodeProcessMsg(pVnode->pImpl, pMsg, VN_MSG_TYPE_APPLY);
|
||||
|
||||
SRpcMsg *pRsp = NULL;
|
||||
(void)vnodeApplyWMsg(pVnode->pImpl, pMsg, &pRsp);
|
||||
}
|
||||
}
|
||||
|
||||
static void dndProcessVnodeSyncQueue(SVnodeObj *pVnode, taos_qall qall, int32_t numOfMsgs) {
|
||||
SVnodeMsg *pMsg = NULL;
|
||||
SRpcMsg *pMsg = NULL;
|
||||
|
||||
for (int32_t i = 0; i < numOfMsgs; ++i) {
|
||||
taosGetQitem(qall, (void **)&pMsg);
|
||||
vnodeProcessMsg(pVnode->pImpl, pMsg, VN_MSG_TYPE_SYNC);
|
||||
|
||||
SRpcMsg *pRsp = NULL;
|
||||
(void)vnodeProcessSyncReq(pVnode->pImpl, pMsg, &pRsp);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -807,40 +893,14 @@ static int32_t dndWriteRpcMsgToVnodeQueue(taos_queue pQueue, SRpcMsg *pRpcMsg) {
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t dndWriteVnodeMsgToVnodeQueue(taos_queue pQueue, SRpcMsg *pRpcMsg) {
|
||||
int32_t code = 0;
|
||||
|
||||
if (pQueue == NULL) {
|
||||
code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
} else {
|
||||
SVnodeMsg *pMsg = vnodeInitMsg(1);
|
||||
if (pMsg == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
if (vnodeAppendMsg(pMsg, pRpcMsg) != 0) {
|
||||
code = terrno;
|
||||
} else {
|
||||
if (taosWriteQitem(pQueue, pMsg) != 0) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
SRpcMsg rsp = {.handle = pRpcMsg->handle, .code = code};
|
||||
rpcSendResponse(&rsp);
|
||||
rpcFreeCont(pRpcMsg->pCont);
|
||||
}
|
||||
}
|
||||
|
||||
static SVnodeObj *dndAcquireVnodeFromMsg(SDnode *pDnode, SRpcMsg *pMsg) {
|
||||
SMsgHead *pHead = (SMsgHead *)pMsg->pCont;
|
||||
pHead->contLen = htonl(pHead->contLen);
|
||||
pHead->vgId = htonl(pHead->vgId);
|
||||
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, pHead->vgId);
|
||||
if (pVnode == NULL) {
|
||||
SRpcMsg rsp = {.handle = pMsg->handle, .code = terrno};
|
||||
SRpcMsg rsp = {.handle = pMsg->handle, .code = TSDB_CODE_VND_INVALID_VGROUP_ID};
|
||||
rpcSendResponse(&rsp);
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
}
|
||||
|
@ -864,7 +924,7 @@ void dndProcessVnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
|||
void dndProcessVnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SVnodeObj *pVnode = dndAcquireVnodeFromMsg(pDnode, pMsg);
|
||||
if (pVnode != NULL) {
|
||||
dndWriteVnodeMsgToVnodeQueue(pVnode->pSyncQ, pMsg);
|
||||
dndWriteRpcMsgToVnodeQueue(pVnode->pSyncQ, pMsg);
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
}
|
||||
}
|
||||
|
@ -872,7 +932,7 @@ void dndProcessVnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
|||
void dndProcessVnodeQueryMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SVnodeObj *pVnode = dndAcquireVnodeFromMsg(pDnode, pMsg);
|
||||
if (pVnode != NULL) {
|
||||
dndWriteVnodeMsgToVnodeQueue(pVnode->pQueryQ, pMsg);
|
||||
dndWriteRpcMsgToVnodeQueue(pVnode->pQueryQ, pMsg);
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
}
|
||||
}
|
||||
|
@ -880,12 +940,12 @@ void dndProcessVnodeQueryMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
|||
void dndProcessVnodeFetchMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SVnodeObj *pVnode = dndAcquireVnodeFromMsg(pDnode, pMsg);
|
||||
if (pVnode != NULL) {
|
||||
dndWriteVnodeMsgToVnodeQueue(pVnode->pFetchQ, pMsg);
|
||||
dndWriteRpcMsgToVnodeQueue(pVnode->pFetchQ, pMsg);
|
||||
dndReleaseVnode(pDnode, pVnode);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dndPutMsgIntoVnodeApplyQueue(SDnode *pDnode, int32_t vgId, SVnodeMsg *pMsg) {
|
||||
static int32_t dndPutMsgIntoVnodeApplyQueue(SDnode *pDnode, int32_t vgId, SRpcMsg *pMsg) {
|
||||
SVnodeObj *pVnode = dndAcquireVnode(pDnode, vgId);
|
||||
if (pVnode == NULL) {
|
||||
return -1;
|
||||
|
@ -1029,7 +1089,7 @@ static void dndFreeVnodeApplyQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
|||
}
|
||||
|
||||
static int32_t dndInitVnodeWriteWorker(SDnode *pDnode) {
|
||||
SVnodesMgmt * pMgmt = &pDnode->vmgmt;
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
SMWorkerPool *pPool = &pMgmt->writePool;
|
||||
pPool->name = "vnode-write";
|
||||
pPool->max = pDnode->opt.numOfCores;
|
||||
|
@ -1050,7 +1110,7 @@ static void dndCleanupVnodeWriteWorker(SDnode *pDnode) {
|
|||
|
||||
static int32_t dndAllocVnodeSyncQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
pVnode->pSyncQ = tMWorkerAllocQueue(&pMgmt->writePool, pVnode, (FProcessItems)dndProcessVnodeSyncQueue);
|
||||
pVnode->pSyncQ = tMWorkerAllocQueue(&pMgmt->syncPool, pVnode, (FProcessItems)dndProcessVnodeSyncQueue);
|
||||
if (pVnode->pSyncQ == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
|
@ -1061,7 +1121,7 @@ static int32_t dndAllocVnodeSyncQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
|||
|
||||
static void dndFreeVnodeSyncQueue(SDnode *pDnode, SVnodeObj *pVnode) {
|
||||
SVnodesMgmt *pMgmt = &pDnode->vmgmt;
|
||||
tMWorkerFreeQueue(&pMgmt->writePool, pVnode->pSyncQ);
|
||||
tMWorkerFreeQueue(&pMgmt->syncPool, pVnode->pSyncQ);
|
||||
pVnode->pSyncQ = NULL;
|
||||
}
|
||||
|
||||
|
@ -1137,12 +1197,12 @@ void dndGetVnodeLoads(SDnode *pDnode, SVnodeLoads *pLoads) {
|
|||
pLoads->num = taosHashGetSize(pMgmt->hash);
|
||||
|
||||
int32_t v = 0;
|
||||
void * pIter = taosHashIterate(pMgmt->hash, NULL);
|
||||
void *pIter = taosHashIterate(pMgmt->hash, NULL);
|
||||
while (pIter) {
|
||||
SVnodeObj **ppVnode = pIter;
|
||||
if (ppVnode == NULL || *ppVnode == NULL) continue;
|
||||
|
||||
SVnodeObj * pVnode = *ppVnode;
|
||||
SVnodeObj *pVnode = *ppVnode;
|
||||
SVnodeLoad *pLoad = &pLoads->data[v++];
|
||||
|
||||
vnodeGetLoad(pVnode->pImpl, pLoad);
|
||||
|
|
|
@ -176,6 +176,12 @@ SDnode *dndInit(SDnodeOpt *pOption) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (vnodeInit(1) != 0) {
|
||||
dError("failed to init vnode env");
|
||||
dndCleanup(pDnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dndInitDnode(pDnode) != 0) {
|
||||
dError("failed to init dnode");
|
||||
dndCleanup(pDnode);
|
||||
|
@ -222,8 +228,10 @@ void dndCleanup(SDnode *pDnode) {
|
|||
dndCleanupMnode(pDnode);
|
||||
dndCleanupVnodes(pDnode);
|
||||
dndCleanupDnode(pDnode);
|
||||
vnodeClear();
|
||||
walCleanUp();
|
||||
rpcCleanup();
|
||||
|
||||
dndCleanupEnv(pDnode);
|
||||
free(pDnode);
|
||||
dInfo("TDengine is cleaned up successfully");
|
||||
|
|
|
@ -8,8 +8,8 @@ add_subdirectory(db)
|
|||
add_subdirectory(dnode)
|
||||
# add_subdirectory(func)
|
||||
# add_subdirectory(mnode)
|
||||
# add_subdirectory(profile)
|
||||
# add_subdirectory(show)
|
||||
add_subdirectory(profile)
|
||||
add_subdirectory(show)
|
||||
add_subdirectory(stb)
|
||||
# add_subdirectory(sync)
|
||||
# add_subdirectory(telem)
|
||||
|
@ -17,4 +17,4 @@ add_subdirectory(stb)
|
|||
add_subdirectory(user)
|
||||
add_subdirectory(vgroup)
|
||||
|
||||
# add_subdirectory(common)
|
||||
add_subdirectory(sut)
|
||||
|
|
|
@ -1,24 +1,8 @@
|
|||
add_executable(dnode_test_acct "")
|
||||
|
||||
target_sources(dnode_test_acct
|
||||
PRIVATE
|
||||
"acct.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
aux_source_directory(. ACCT_SRC)
|
||||
add_executable(dnode_test_acct ${ACCT_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_acct
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dnode_test_acct
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
|
|
|
@ -9,103 +9,59 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "deploy.h"
|
||||
#include "base.h"
|
||||
|
||||
class DndTestAcct : public ::testing::Test {
|
||||
protected:
|
||||
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
||||
ASSERT(pServer);
|
||||
return pServer;
|
||||
}
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_acct", 9012); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
initLog("/tmp/tdlog");
|
||||
static Testbase test;
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9012";
|
||||
pServer = CreateServer("/tmp/dnode_test_user", fqdn, 9012, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9012);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
stopServer(pServer);
|
||||
dropClient(pClient);
|
||||
pServer = NULL;
|
||||
pClient = NULL;
|
||||
}
|
||||
|
||||
static SServer* pServer;
|
||||
static SClient* pClient;
|
||||
static int32_t connId;
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
};
|
||||
|
||||
SServer* DndTestAcct::pServer;
|
||||
SClient* DndTestAcct::pClient;
|
||||
int32_t DndTestAcct::connId;
|
||||
Testbase DndTestAcct::test;
|
||||
|
||||
TEST_F(DndTestAcct, 01_CreateAcct) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
int32_t contLen = sizeof(SCreateAcctMsg);
|
||||
|
||||
SCreateAcctMsg* pReq = (SCreateAcctMsg*)rpcMallocCont(sizeof(SCreateAcctMsg));
|
||||
SCreateAcctMsg* pReq = (SCreateAcctMsg*)rpcMallocCont(contLen);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateAcctMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_ACCT;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_ACCT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
||||
}
|
||||
|
||||
TEST_F(DndTestAcct, 02_AlterAcct) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
int32_t contLen = sizeof(SCreateAcctMsg);
|
||||
|
||||
SAlterAcctMsg* pReq = (SAlterAcctMsg*)rpcMallocCont(sizeof(SAlterAcctMsg));
|
||||
SAlterAcctMsg* pReq = (SAlterAcctMsg*)rpcMallocCont(contLen);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SAlterAcctMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_ACCT;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_ACCT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
||||
}
|
||||
|
||||
TEST_F(DndTestAcct, 03_DropAcct) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
int32_t contLen = sizeof(SDropAcctMsg);
|
||||
|
||||
SDropAcctMsg* pReq = (SDropAcctMsg*)rpcMallocCont(sizeof(SDropAcctMsg));
|
||||
SDropAcctMsg* pReq = (SDropAcctMsg*)rpcMallocCont(contLen);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SDropAcctMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_ACCT;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_ACCT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_MSG_NOT_PROCESSED);
|
||||
}
|
||||
|
||||
TEST_F(DndTestAcct, 04_ShowAcct) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
int32_t contLen = sizeof(SShowMsg);
|
||||
|
||||
SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
SShowMsg* pReq = (SShowMsg*)rpcMallocCont(contLen);
|
||||
pReq->type = TSDB_MGMT_TABLE_ACCT;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SShowMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_SHOW, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE);
|
||||
}
|
|
@ -1,24 +1,8 @@
|
|||
add_executable(dnode_test_cluster "")
|
||||
|
||||
target_sources(dnode_test_cluster
|
||||
PRIVATE
|
||||
"cluster.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
aux_source_directory(. CLUSTER_SRC)
|
||||
add_executable(dnode_test_cluster ${CLUSTER_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_cluster
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dnode_test_cluster
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
|
|
|
@ -9,162 +9,33 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "deploy.h"
|
||||
#include "base.h"
|
||||
|
||||
class DndTestCluster : public ::testing::Test {
|
||||
protected:
|
||||
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
||||
ASSERT(pServer);
|
||||
return pServer;
|
||||
}
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_cluster", 9030); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
initLog("/tmp/tdlog");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9030";
|
||||
pServer = CreateServer("/tmp/dnode_test_cluster", fqdn, 9030, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9030);
|
||||
taosMsleep(1100);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
stopServer(pServer);
|
||||
dropClient(pClient);
|
||||
pServer = NULL;
|
||||
pClient = NULL;
|
||||
}
|
||||
|
||||
static SServer* pServer;
|
||||
static SClient* pClient;
|
||||
static int32_t connId;
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns, const char* db) {
|
||||
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pShow->type = showType;
|
||||
if (db != NULL) {
|
||||
strcpy(pShow->db, db);
|
||||
}
|
||||
SRpcMsg showRpcMsg = {0};
|
||||
showRpcMsg.pCont = pShow;
|
||||
showRpcMsg.contLen = sizeof(SShowMsg);
|
||||
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &showRpcMsg);
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pShowRsp, nullptr);
|
||||
pShowRsp->showId = htonl(pShowRsp->showId);
|
||||
pMeta = &pShowRsp->tableMeta;
|
||||
pMeta->numOfTags = htonl(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htonl(pMeta->numOfColumns);
|
||||
pMeta->sversion = htonl(pMeta->sversion);
|
||||
pMeta->tversion = htonl(pMeta->tversion);
|
||||
pMeta->tuid = htobe64(pMeta->tuid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
showId = pShowRsp->showId;
|
||||
|
||||
EXPECT_NE(pShowRsp->showId, 0);
|
||||
EXPECT_STREQ(pMeta->tbFname, showName);
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, columns);
|
||||
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);
|
||||
}
|
||||
|
||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, type);
|
||||
EXPECT_EQ(pSchema->bytes, bytes);
|
||||
EXPECT_STREQ(pSchema->name, name);
|
||||
}
|
||||
|
||||
void SendThenCheckShowRetrieveMsg(int32_t rows) {
|
||||
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
||||
pRetrieve->showId = htonl(showId);
|
||||
pRetrieve->free = 0;
|
||||
|
||||
SRpcMsg retrieveRpcMsg = {0};
|
||||
retrieveRpcMsg.pCont = pRetrieve;
|
||||
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
||||
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
||||
|
||||
sendMsg(pClient, &retrieveRpcMsg);
|
||||
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pRetrieveRsp, nullptr);
|
||||
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
||||
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
|
||||
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
|
||||
EXPECT_EQ(pRetrieveRsp->useconds, 0);
|
||||
// EXPECT_EQ(pRetrieveRsp->completed, completed);
|
||||
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRetrieveRsp->compressed, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->compLen, 0);
|
||||
|
||||
pData = pRetrieveRsp->data;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
void CheckInt32() {
|
||||
int32_t data = *((int32_t*)(pData + pos));
|
||||
pos += sizeof(int32_t);
|
||||
EXPECT_GT(data, 0);
|
||||
}
|
||||
|
||||
void CheckTimestamp() {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_GT(data, 0);
|
||||
}
|
||||
|
||||
void CheckBinary(int32_t len) {
|
||||
pos += sizeof(VarDataLenT);
|
||||
char* data = (char*)(pData + pos);
|
||||
pos += len;
|
||||
}
|
||||
|
||||
int32_t showId;
|
||||
STableMetaMsg* pMeta;
|
||||
SRetrieveTableRsp* pRetrieveRsp;
|
||||
char* pData;
|
||||
int32_t pos;
|
||||
};
|
||||
|
||||
SServer* DndTestCluster::pServer;
|
||||
SClient* DndTestCluster::pClient;
|
||||
int32_t DndTestCluster::connId;
|
||||
Testbase DndTestCluster::test;
|
||||
|
||||
TEST_F(DndTestCluster, 01_ShowCluster) {
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_CLUSTER, "show cluster", 3, NULL);
|
||||
CheckSchema(0, TSDB_DATA_TYPE_INT, 4, "id");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name");
|
||||
CheckSchema(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_CLUSTER, "");
|
||||
CHECK_META( "show cluster", 3);
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "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");
|
||||
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckInt32();
|
||||
CheckBinary(TSDB_CLUSTER_ID_LEN);
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
IgnoreInt32();
|
||||
IgnoreBinary(TSDB_CLUSTER_ID_LEN);
|
||||
CheckTimestamp();
|
||||
}
|
|
@ -1,24 +1,8 @@
|
|||
add_executable(dnode_test_db "")
|
||||
|
||||
target_sources(dnode_test_db
|
||||
PRIVATE
|
||||
"db.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
aux_source_directory(. DB_SRC)
|
||||
add_executable(dnode_test_db ${DB_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_db
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dnode_test_db
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
|
|
|
@ -9,199 +9,52 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "deploy.h"
|
||||
#include "base.h"
|
||||
|
||||
class DndTestDb : public ::testing::Test {
|
||||
protected:
|
||||
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
||||
ASSERT(pServer);
|
||||
return pServer;
|
||||
}
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_db", 9040); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
initLog("/tmp/tdlog");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9040";
|
||||
pServer = CreateServer("/tmp/dnode_test_db", fqdn, 9040, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9040);
|
||||
taosMsleep(1100);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
stopServer(pServer);
|
||||
dropClient(pClient);
|
||||
pServer = NULL;
|
||||
pClient = NULL;
|
||||
}
|
||||
|
||||
static SServer* pServer;
|
||||
static SClient* pClient;
|
||||
static int32_t connId;
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns, const char* db) {
|
||||
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pShow->type = showType;
|
||||
if (db != NULL) {
|
||||
strcpy(pShow->db, db);
|
||||
}
|
||||
SRpcMsg showRpcMsg = {0};
|
||||
showRpcMsg.pCont = pShow;
|
||||
showRpcMsg.contLen = sizeof(SShowMsg);
|
||||
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &showRpcMsg);
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pShowRsp, nullptr);
|
||||
pShowRsp->showId = htonl(pShowRsp->showId);
|
||||
pMeta = &pShowRsp->tableMeta;
|
||||
pMeta->numOfTags = htonl(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htonl(pMeta->numOfColumns);
|
||||
pMeta->sversion = htonl(pMeta->sversion);
|
||||
pMeta->tversion = htonl(pMeta->tversion);
|
||||
pMeta->tuid = htobe64(pMeta->tuid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
showId = pShowRsp->showId;
|
||||
|
||||
EXPECT_NE(pShowRsp->showId, 0);
|
||||
EXPECT_STREQ(pMeta->tbFname, showName);
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, columns);
|
||||
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);
|
||||
}
|
||||
|
||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, type);
|
||||
EXPECT_EQ(pSchema->bytes, bytes);
|
||||
EXPECT_STREQ(pSchema->name, name);
|
||||
}
|
||||
|
||||
void SendThenCheckShowRetrieveMsg(int32_t rows) {
|
||||
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
||||
pRetrieve->showId = htonl(showId);
|
||||
pRetrieve->free = 0;
|
||||
|
||||
SRpcMsg retrieveRpcMsg = {0};
|
||||
retrieveRpcMsg.pCont = pRetrieve;
|
||||
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
||||
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
||||
|
||||
sendMsg(pClient, &retrieveRpcMsg);
|
||||
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pRetrieveRsp, nullptr);
|
||||
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
||||
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
|
||||
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
|
||||
EXPECT_EQ(pRetrieveRsp->useconds, 0);
|
||||
// EXPECT_EQ(pRetrieveRsp->completed, completed);
|
||||
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRetrieveRsp->compressed, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->compLen, 0);
|
||||
|
||||
pData = pRetrieveRsp->data;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
void CheckInt8(int8_t val) {
|
||||
int8_t data = *((int8_t*)(pData + pos));
|
||||
pos += sizeof(int8_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt16(int16_t val) {
|
||||
int16_t data = *((int16_t*)(pData + pos));
|
||||
pos += sizeof(int16_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt32(int32_t val) {
|
||||
int32_t data = *((int32_t*)(pData + pos));
|
||||
pos += sizeof(int32_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt64(int64_t val) {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckTimestamp() {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_GT(data, 0);
|
||||
}
|
||||
|
||||
void CheckBinary(const char* val, int32_t len) {
|
||||
pos += sizeof(VarDataLenT);
|
||||
char* data = (char*)(pData + pos);
|
||||
pos += len;
|
||||
EXPECT_STREQ(data, val);
|
||||
}
|
||||
|
||||
int32_t showId;
|
||||
STableMetaMsg* pMeta;
|
||||
SRetrieveTableRsp* pRetrieveRsp;
|
||||
char* pData;
|
||||
int32_t pos;
|
||||
};
|
||||
|
||||
SServer* DndTestDb::pServer;
|
||||
SClient* DndTestDb::pClient;
|
||||
int32_t DndTestDb::connId;
|
||||
Testbase DndTestDb::test;
|
||||
|
||||
TEST_F(DndTestDb, 01_ShowDb) {
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL);
|
||||
CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN - 1 + VARSTR_HEADER_SIZE, "name");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
CheckSchema(2, TSDB_DATA_TYPE_SMALLINT, 2, "vgroups");
|
||||
CheckSchema(3, TSDB_DATA_TYPE_SMALLINT, 2, "replica");
|
||||
CheckSchema(4, TSDB_DATA_TYPE_SMALLINT, 2, "quorum");
|
||||
CheckSchema(5, TSDB_DATA_TYPE_SMALLINT, 2, "days");
|
||||
CheckSchema(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "keep0,keep1,keep2");
|
||||
CheckSchema(7, TSDB_DATA_TYPE_INT, 4, "cache");
|
||||
CheckSchema(8, TSDB_DATA_TYPE_INT, 4, "blocks");
|
||||
CheckSchema(9, TSDB_DATA_TYPE_INT, 4, "minrows");
|
||||
CheckSchema(10, TSDB_DATA_TYPE_INT, 4, "maxrows");
|
||||
CheckSchema(11, TSDB_DATA_TYPE_TINYINT, 1, "wallevel");
|
||||
CheckSchema(12, TSDB_DATA_TYPE_INT, 4, "fsync");
|
||||
CheckSchema(13, TSDB_DATA_TYPE_TINYINT, 1, "comp");
|
||||
CheckSchema(14, TSDB_DATA_TYPE_TINYINT, 1, "cachelast");
|
||||
CheckSchema(15, TSDB_DATA_TYPE_BINARY, 3 + VARSTR_HEADER_SIZE, "precision");
|
||||
CheckSchema(16, TSDB_DATA_TYPE_TINYINT, 1, "update");
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, "");
|
||||
CHECK_META("show databases", 17);
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN - 1 + VARSTR_HEADER_SIZE, "name");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_SMALLINT, 2, "vgroups");
|
||||
CHECK_SCHEMA(3, TSDB_DATA_TYPE_SMALLINT, 2, "replica");
|
||||
CHECK_SCHEMA(4, TSDB_DATA_TYPE_SMALLINT, 2, "quorum");
|
||||
CHECK_SCHEMA(5, TSDB_DATA_TYPE_SMALLINT, 2, "days");
|
||||
CHECK_SCHEMA(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "keep0,keep1,keep2");
|
||||
CHECK_SCHEMA(7, TSDB_DATA_TYPE_INT, 4, "cache");
|
||||
CHECK_SCHEMA(8, TSDB_DATA_TYPE_INT, 4, "blocks");
|
||||
CHECK_SCHEMA(9, TSDB_DATA_TYPE_INT, 4, "minrows");
|
||||
CHECK_SCHEMA(10, TSDB_DATA_TYPE_INT, 4, "maxrows");
|
||||
CHECK_SCHEMA(11, TSDB_DATA_TYPE_TINYINT, 1, "wallevel");
|
||||
CHECK_SCHEMA(12, TSDB_DATA_TYPE_INT, 4, "fsync");
|
||||
CHECK_SCHEMA(13, TSDB_DATA_TYPE_TINYINT, 1, "comp");
|
||||
CHECK_SCHEMA(14, TSDB_DATA_TYPE_TINYINT, 1, "cachelast");
|
||||
CHECK_SCHEMA(15, TSDB_DATA_TYPE_BINARY, 3 + VARSTR_HEADER_SIZE, "precision");
|
||||
CHECK_SCHEMA(16, TSDB_DATA_TYPE_TINYINT, 1, "update");
|
||||
|
||||
SendThenCheckShowRetrieveMsg(0);
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
|
||||
{
|
||||
SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(sizeof(SCreateDbMsg));
|
||||
int32_t contLen = sizeof(SCreateDbMsg);
|
||||
|
||||
SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->db, "1.d1");
|
||||
pReq->numOfVgroups = htonl(2);
|
||||
pReq->cacheBlockSize = htonl(16);
|
||||
|
@ -210,8 +63,8 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
|
|||
pReq->daysToKeep0 = htonl(3650);
|
||||
pReq->daysToKeep1 = htonl(3650);
|
||||
pReq->daysToKeep2 = htonl(3650);
|
||||
pReq->minRowsPerFileBlock = htonl(100);
|
||||
pReq->maxRowsPerFileBlock = htonl(4096);
|
||||
pReq->minRows = htonl(100);
|
||||
pReq->maxRows = htonl(4096);
|
||||
pReq->commitTime = htonl(3600);
|
||||
pReq->fsyncPeriod = htonl(3000);
|
||||
pReq->walLevel = 1;
|
||||
|
@ -223,20 +76,16 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
|
|||
pReq->cacheLastRow = 0;
|
||||
pReq->ignoreExist = 1;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateDbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DB, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
// taosMsleep(1000000);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL);
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, "");
|
||||
CHECK_META("show databases", 17);
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
|
||||
CheckTimestamp();
|
||||
CheckInt16(2); // vgroups
|
||||
|
@ -255,12 +104,15 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
|
|||
CheckBinary("ms", 3); // precision
|
||||
CheckInt8(0); // update
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_VGROUP, "show vgroups", 4, "1.d1");
|
||||
CheckSchema(0, TSDB_DATA_TYPE_INT, 4, "vgId");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_INT, 4, "tables");
|
||||
CheckSchema(2, TSDB_DATA_TYPE_SMALLINT, 2, "v1_dnode");
|
||||
CheckSchema(3, TSDB_DATA_TYPE_BINARY, 9 + VARSTR_HEADER_SIZE, "v1_status");
|
||||
SendThenCheckShowRetrieveMsg(2);
|
||||
test.SendShowMetaMsg(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();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
CheckInt32(1);
|
||||
CheckInt32(2);
|
||||
CheckInt32(0);
|
||||
|
@ -271,7 +123,9 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
|
|||
CheckBinary("master", 9);
|
||||
|
||||
{
|
||||
SAlterDbMsg* pReq = (SAlterDbMsg*)rpcMallocCont(sizeof(SAlterDbMsg));
|
||||
int32_t contLen = sizeof(SAlterDbMsg);
|
||||
|
||||
SAlterDbMsg* pReq = (SAlterDbMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->db, "1.d1");
|
||||
pReq->totalBlocks = htonl(12);
|
||||
pReq->daysToKeep0 = htonl(300);
|
||||
|
@ -282,19 +136,14 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
|
|||
pReq->quorum = 2;
|
||||
pReq->cacheLastRow = 1;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SAlterDbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_DB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_DB, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL);
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, "");
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
|
||||
CheckTimestamp();
|
||||
CheckInt16(2); // vgroups
|
||||
|
@ -314,19 +163,14 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
|
|||
CheckInt8(0); // update
|
||||
|
||||
// restart
|
||||
stopServer(pServer);
|
||||
pServer = NULL;
|
||||
test.Restart();
|
||||
|
||||
uInfo("start all server");
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, "");
|
||||
CHECK_META("show databases", 17);
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9040";
|
||||
pServer = startServer("/tmp/dnode_test_db", fqdn, 9040, firstEp);
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
uInfo("all server is running");
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL);
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckBinary("d1", TSDB_DB_NAME_LEN - 1);
|
||||
CheckTimestamp();
|
||||
CheckInt16(2); // vgroups
|
||||
|
@ -346,27 +190,28 @@ TEST_F(DndTestDb, 02_Create_Alter_Drop_Db) {
|
|||
CheckInt8(0); // update
|
||||
|
||||
{
|
||||
SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(sizeof(SDropDbMsg));
|
||||
int32_t contLen = sizeof(SDropDbMsg);
|
||||
|
||||
SDropDbMsg* pReq = (SDropDbMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->db, "1.d1");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SDropDbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_DB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_DB, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL);
|
||||
SendThenCheckShowRetrieveMsg(0);
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, "");
|
||||
CHECK_META("show databases", 17);
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) {
|
||||
{
|
||||
SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(sizeof(SCreateDbMsg));
|
||||
int32_t contLen = sizeof(SCreateDbMsg);
|
||||
|
||||
SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->db, "1.d2");
|
||||
pReq->numOfVgroups = htonl(2);
|
||||
pReq->cacheBlockSize = htonl(16);
|
||||
|
@ -375,8 +220,8 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) {
|
|||
pReq->daysToKeep0 = htonl(3650);
|
||||
pReq->daysToKeep1 = htonl(3650);
|
||||
pReq->daysToKeep2 = htonl(3650);
|
||||
pReq->minRowsPerFileBlock = htonl(100);
|
||||
pReq->maxRowsPerFileBlock = htonl(4096);
|
||||
pReq->minRows = htonl(100);
|
||||
pReq->maxRows = htonl(4096);
|
||||
pReq->commitTime = htonl(3600);
|
||||
pReq->fsyncPeriod = htonl(3000);
|
||||
pReq->walLevel = 1;
|
||||
|
@ -388,33 +233,26 @@ TEST_F(DndTestDb, 03_Create_Use_Restart_Use_Db) {
|
|||
pReq->cacheLastRow = 0;
|
||||
pReq->ignoreExist = 1;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateDbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DB, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL);
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DB, "");
|
||||
CHECK_META("show databases", 17);
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
CheckBinary("d2", TSDB_DB_NAME_LEN - 1);
|
||||
|
||||
{
|
||||
SUseDbMsg* pReq = (SUseDbMsg*)rpcMallocCont(sizeof(SUseDbMsg));
|
||||
int32_t contLen = sizeof(SUseDbMsg);
|
||||
|
||||
SUseDbMsg* pReq = (SUseDbMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->db, "1.d2");
|
||||
pReq->vgVersion = htonl(-1);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SUseDbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_USE_DB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_USE_DB, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
|
|
|
@ -1,24 +1,8 @@
|
|||
add_executable(dnode_test_dnode "")
|
||||
|
||||
target_sources(dnode_test_dnode
|
||||
PRIVATE
|
||||
"dnode.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
aux_source_directory(. DTEST_SRC)
|
||||
add_executable(dnode_test_dnode ${DTEST_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_dnode
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dnode_test_dnode
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
|
|
|
@ -9,189 +9,62 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "deploy.h"
|
||||
#include "base.h"
|
||||
|
||||
class DndTestDnode : public ::testing::Test {
|
||||
public:
|
||||
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
||||
ASSERT(pServer);
|
||||
return pServer;
|
||||
}
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
initLog("/tmp/tdlog");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9041";
|
||||
pServer1 = CreateServer("/tmp/dnode_test_dnode1", fqdn, 9041, firstEp);
|
||||
pServer2 = CreateServer("/tmp/dnode_test_dnode2", fqdn, 9042, firstEp);
|
||||
pServer3 = CreateServer("/tmp/dnode_test_dnode3", fqdn, 9043, firstEp);
|
||||
pServer4 = CreateServer("/tmp/dnode_test_dnode4", fqdn, 9044, firstEp);
|
||||
pServer5 = CreateServer("/tmp/dnode_test_dnode5", fqdn, 9045, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9041);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
stopServer(pServer1);
|
||||
stopServer(pServer2);
|
||||
stopServer(pServer3);
|
||||
stopServer(pServer4);
|
||||
stopServer(pServer5);
|
||||
dropClient(pClient);
|
||||
pServer1 = NULL;
|
||||
pServer2 = NULL;
|
||||
pServer3 = NULL;
|
||||
pServer4 = NULL;
|
||||
pServer5 = NULL;
|
||||
pClient = NULL;
|
||||
}
|
||||
|
||||
static SServer* pServer1;
|
||||
static SServer* pServer2;
|
||||
static SServer* pServer3;
|
||||
static SServer* pServer4;
|
||||
static SServer* pServer5;
|
||||
static SClient* pClient;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns) {
|
||||
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pShow->type = showType;
|
||||
strcpy(pShow->db, "");
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/dnode_test_dnode1", 9041);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9041";
|
||||
|
||||
SRpcMsg showRpcMsg = {0};
|
||||
showRpcMsg.pCont = pShow;
|
||||
showRpcMsg.contLen = sizeof(SShowMsg);
|
||||
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &showRpcMsg);
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pShowRsp, nullptr);
|
||||
pShowRsp->showId = htonl(pShowRsp->showId);
|
||||
pMeta = &pShowRsp->tableMeta;
|
||||
pMeta->numOfTags = htonl(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htonl(pMeta->numOfColumns);
|
||||
pMeta->sversion = htonl(pMeta->sversion);
|
||||
pMeta->tversion = htonl(pMeta->tversion);
|
||||
pMeta->tuid = htobe64(pMeta->tuid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
showId = pShowRsp->showId;
|
||||
|
||||
EXPECT_NE(pShowRsp->showId, 0);
|
||||
EXPECT_STREQ(pMeta->tbFname, showName);
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, columns);
|
||||
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);
|
||||
server2.Start("/tmp/dnode_test_dnode2", fqdn, 9042, firstEp);
|
||||
server3.Start("/tmp/dnode_test_dnode3", fqdn, 9043, firstEp);
|
||||
server4.Start("/tmp/dnode_test_dnode4", fqdn, 9044, firstEp);
|
||||
server5.Start("/tmp/dnode_test_dnode5", fqdn, 9045, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, type);
|
||||
EXPECT_EQ(pSchema->bytes, bytes);
|
||||
EXPECT_STREQ(pSchema->name, name);
|
||||
static void TearDownTestSuite() {
|
||||
server2.Stop();
|
||||
server3.Stop();
|
||||
server4.Stop();
|
||||
server5.Stop();
|
||||
test.Cleanup();
|
||||
}
|
||||
|
||||
void SendThenCheckShowRetrieveMsg(int32_t rows) {
|
||||
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
||||
pRetrieve->showId = htonl(showId);
|
||||
pRetrieve->free = 0;
|
||||
|
||||
SRpcMsg retrieveRpcMsg = {0};
|
||||
retrieveRpcMsg.pCont = pRetrieve;
|
||||
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
||||
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
||||
|
||||
sendMsg(pClient, &retrieveRpcMsg);
|
||||
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pRetrieveRsp, nullptr);
|
||||
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
||||
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
|
||||
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
|
||||
EXPECT_EQ(pRetrieveRsp->useconds, 0);
|
||||
// EXPECT_EQ(pRetrieveRsp->completed, completed);
|
||||
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRetrieveRsp->compressed, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->compLen, 0);
|
||||
|
||||
pData = pRetrieveRsp->data;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
void CheckInt16(int16_t val) {
|
||||
int16_t data = *((int16_t*)(pData + pos));
|
||||
pos += sizeof(int16_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt64(int64_t val) {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckTimestamp() {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_GT(data, 0);
|
||||
}
|
||||
|
||||
void CheckBinary(const char* val, int32_t len) {
|
||||
pos += sizeof(VarDataLenT);
|
||||
char* data = (char*)(pData + pos);
|
||||
pos += len;
|
||||
EXPECT_STREQ(data, val);
|
||||
}
|
||||
|
||||
int32_t showId;
|
||||
STableMetaMsg* pMeta;
|
||||
SRetrieveTableRsp* pRetrieveRsp;
|
||||
char* pData;
|
||||
int32_t pos;
|
||||
static Testbase test;
|
||||
static TestServer server2;
|
||||
static TestServer server3;
|
||||
static TestServer server4;
|
||||
static TestServer server5;
|
||||
};
|
||||
|
||||
SServer* DndTestDnode::pServer1;
|
||||
SServer* DndTestDnode::pServer2;
|
||||
SServer* DndTestDnode::pServer3;
|
||||
SServer* DndTestDnode::pServer4;
|
||||
SServer* DndTestDnode::pServer5;
|
||||
SClient* DndTestDnode::pClient;
|
||||
Testbase DndTestDnode::test;
|
||||
TestServer DndTestDnode::server2;
|
||||
TestServer DndTestDnode::server3;
|
||||
TestServer DndTestDnode::server4;
|
||||
TestServer DndTestDnode::server5;
|
||||
|
||||
TEST_F(DndTestDnode, 01_ShowDnode) {
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
||||
CheckSchema(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
|
||||
CheckSchema(2, TSDB_DATA_TYPE_SMALLINT, 2, "vnodes");
|
||||
CheckSchema(3, TSDB_DATA_TYPE_SMALLINT, 2, "max_vnodes");
|
||||
CheckSchema(4, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "status");
|
||||
CheckSchema(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
CheckSchema(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason");
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
|
||||
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_SMALLINT, 2, "vnodes");
|
||||
CHECK_SCHEMA(3, TSDB_DATA_TYPE_SMALLINT, 2, "max_vnodes");
|
||||
CHECK_SCHEMA(4, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "status");
|
||||
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();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
|
@ -202,40 +75,36 @@ TEST_F(DndTestDnode, 01_ShowDnode) {
|
|||
}
|
||||
|
||||
TEST_F(DndTestDnode, 02_ConfigDnode) {
|
||||
SCfgDnodeMsg* pReq = (SCfgDnodeMsg*)rpcMallocCont(sizeof(SCfgDnodeMsg));
|
||||
int32_t contLen = sizeof(SCfgDnodeMsg);
|
||||
|
||||
SCfgDnodeMsg* pReq = (SCfgDnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(1);
|
||||
strcpy(pReq->config, "ddebugflag 131");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCfgDnodeMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CONFIG_DNODE;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONFIG_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
||||
{
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->ep, "localhost:9042");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateDnodeMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DNODE;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
taosMsleep(1300);
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
||||
SendThenCheckShowRetrieveMsg(2);
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(2);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
|
@ -252,22 +121,21 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
|||
CheckBinary("", 24);
|
||||
|
||||
{
|
||||
SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(sizeof(SDropDnodeMsg));
|
||||
int32_t contLen = sizeof(SDropDnodeMsg);
|
||||
|
||||
SDropDnodeMsg* pReq = (SDropDnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->dnodeId = htonl(2);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SDropDnodeMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_DNODE;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckBinary("localhost:9041", TSDB_EP_LEN);
|
||||
CheckInt16(0);
|
||||
|
@ -277,53 +145,44 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
|||
CheckBinary("", 24);
|
||||
|
||||
{
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->ep, "localhost:9043");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateDnodeMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DNODE;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->ep, "localhost:9044");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateDnodeMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DNODE;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(sizeof(SCreateDnodeMsg));
|
||||
int32_t contLen = sizeof(SCreateDnodeMsg);
|
||||
|
||||
SCreateDnodeMsg* pReq = (SCreateDnodeMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->ep, "localhost:9045");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateDnodeMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DNODE;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DNODE, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
taosMsleep(1300);
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
||||
SendThenCheckShowRetrieveMsg(4);
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(3);
|
||||
CheckInt16(4);
|
||||
|
@ -355,31 +214,18 @@ TEST_F(DndTestDnode, 03_Create_Drop_Restart_Dnode) {
|
|||
|
||||
// restart
|
||||
uInfo("stop all server");
|
||||
stopServer(pServer1);
|
||||
stopServer(pServer2);
|
||||
stopServer(pServer3);
|
||||
stopServer(pServer4);
|
||||
stopServer(pServer5);
|
||||
pServer1 = NULL;
|
||||
pServer2 = NULL;
|
||||
pServer3 = NULL;
|
||||
pServer4 = NULL;
|
||||
pServer5 = NULL;
|
||||
|
||||
uInfo("start all server");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9041";
|
||||
pServer1 = startServer("/tmp/dnode_test_dnode1", fqdn, 9041, firstEp);
|
||||
pServer3 = startServer("/tmp/dnode_test_dnode3", fqdn, 9043, firstEp);
|
||||
pServer4 = startServer("/tmp/dnode_test_dnode4", fqdn, 9044, firstEp);
|
||||
pServer5 = startServer("/tmp/dnode_test_dnode5", fqdn, 9045, firstEp);
|
||||
|
||||
uInfo("all server is running");
|
||||
test.Restart();
|
||||
server2.Restart();
|
||||
server3.Restart();
|
||||
server4.Restart();
|
||||
server5.Restart();
|
||||
|
||||
taosMsleep(1300);
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
|
||||
SendThenCheckShowRetrieveMsg(4);
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "");
|
||||
CHECK_META("show dnodes", 7);
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 4);
|
||||
|
||||
CheckInt16(1);
|
||||
CheckInt16(3);
|
||||
CheckInt16(4);
|
||||
|
|
|
@ -1,27 +1,11 @@
|
|||
add_executable(dndTestProfile "")
|
||||
|
||||
target_sources(dndTestProfile
|
||||
PRIVATE
|
||||
"profile.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
aux_source_directory(. PROFILE_SRC)
|
||||
add_executable(dnode_test_profile ${PROFILE_SRC})
|
||||
target_link_libraries(
|
||||
dndTestProfile
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dndTestProfile
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
dnode_test_profile
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
NAME dndTestProfile
|
||||
COMMAND dndTestProfile
|
||||
NAME dnode_test_profile
|
||||
COMMAND dnode_test_profile
|
||||
)
|
||||
|
|
|
@ -9,55 +9,35 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "deploy.h"
|
||||
#include "base.h"
|
||||
|
||||
class DndTestProfile : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_profile", 9080); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
const char* user = "root";
|
||||
const char* pass = "taosdata";
|
||||
const char* path = "/tmp/dndTestProfile";
|
||||
const char* fqdn = "localhost";
|
||||
uint16_t port = 9522;
|
||||
|
||||
pServer = createServer(path, fqdn, port);
|
||||
ASSERT(pServer);
|
||||
pClient = createClient(user, pass, fqdn, port);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
stopServer(pServer);
|
||||
dropClient(pClient);
|
||||
}
|
||||
|
||||
static SServer* pServer;
|
||||
static SClient* pClient;
|
||||
static int32_t connId;
|
||||
int32_t connId;
|
||||
};
|
||||
|
||||
SServer* DndTestProfile::pServer;
|
||||
SClient* DndTestProfile::pClient;
|
||||
int32_t DndTestProfile::connId;
|
||||
Testbase DndTestProfile::test;
|
||||
|
||||
TEST_F(DndTestProfile, SConnectMsg_01) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
TEST_F(DndTestProfile, 01_ConnectMsg) {
|
||||
int32_t contLen = sizeof(SConnectMsg);
|
||||
|
||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(sizeof(SConnectMsg));
|
||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen);
|
||||
pReq->pid = htonl(1234);
|
||||
strcpy(pReq->app, "dndTestProfile");
|
||||
strcpy(pReq->app, "dnode_test_profile");
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SConnectMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CONNECT;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
SConnectRsp* pRsp = (SConnectRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
|
@ -69,183 +49,65 @@ TEST_F(DndTestProfile, SConnectMsg_01) {
|
|||
EXPECT_EQ(pRsp->acctId, 1);
|
||||
EXPECT_GT(pRsp->clusterId, 0);
|
||||
EXPECT_EQ(pRsp->connId, 1);
|
||||
EXPECT_EQ(pRsp->superAuth, 1);
|
||||
EXPECT_EQ(pRsp->readAuth, 1);
|
||||
EXPECT_EQ(pRsp->writeAuth, 1);
|
||||
EXPECT_EQ(pRsp->superUser, 1);
|
||||
|
||||
EXPECT_EQ(pRsp->epSet.inUse, 0);
|
||||
EXPECT_EQ(pRsp->epSet.numOfEps, 1);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9522);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9080);
|
||||
EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");
|
||||
|
||||
connId = pRsp->connId;
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, SConnectMsg_02) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
TEST_F(DndTestProfile, 02_ConnectMsg_InvalidDB) {
|
||||
int32_t contLen = sizeof(SConnectMsg);
|
||||
|
||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(sizeof(SConnectMsg));
|
||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen);
|
||||
pReq->pid = htonl(1234);
|
||||
strcpy(pReq->app, "dndTestProfile");
|
||||
strcpy(pReq->app, "dnode_test_profile");
|
||||
strcpy(pReq->db, "invalid_db");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SConnectMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CONNECT;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_DB);
|
||||
ASSERT_EQ(pMsg->contLen, 0);
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, SConnectMsg_03) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
int32_t showId = 0;
|
||||
TEST_F(DndTestProfile, 03_ConnectMsg_Show) {
|
||||
test.SendShowMetaMsg(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");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_BINARY, TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE, "program");
|
||||
CHECK_SCHEMA(3, TSDB_DATA_TYPE_INT, 4, "pid");
|
||||
CHECK_SCHEMA(4, TSDB_DATA_TYPE_BINARY, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, "ip:port");
|
||||
CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "login_time");
|
||||
CHECK_SCHEMA(6, TSDB_DATA_TYPE_TIMESTAMP, 8, "last_access");
|
||||
|
||||
{
|
||||
SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pReq->type = TSDB_MGMT_TABLE_CONNS;
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SShowMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
|
||||
SShowRsp* pRsp = (SShowRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
pRsp->showId = htonl(pRsp->showId);
|
||||
STableMetaMsg* pMeta = &pRsp->tableMeta;
|
||||
pMeta->contLen = htonl(pMeta->contLen);
|
||||
pMeta->numOfColumns = htons(pMeta->numOfColumns);
|
||||
pMeta->sversion = htons(pMeta->sversion);
|
||||
pMeta->tversion = htons(pMeta->tversion);
|
||||
pMeta->tid = htonl(pMeta->tid);
|
||||
pMeta->uid = htobe64(pMeta->uid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
showId = pRsp->showId;
|
||||
|
||||
EXPECT_NE(pRsp->showId, 0);
|
||||
EXPECT_EQ(pMeta->contLen, 0);
|
||||
EXPECT_STREQ(pMeta->tbFname, "");
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->precision, 0);
|
||||
EXPECT_EQ(pMeta->tableType, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, 7);
|
||||
EXPECT_EQ(pMeta->sversion, 0);
|
||||
EXPECT_EQ(pMeta->tversion, 0);
|
||||
EXPECT_EQ(pMeta->tid, 0);
|
||||
EXPECT_EQ(pMeta->uid, 0);
|
||||
EXPECT_STREQ(pMeta->sTableName, "");
|
||||
EXPECT_EQ(pMeta->suid, 0);
|
||||
|
||||
SSchema* pSchema = NULL;
|
||||
pSchema = &pMeta->pSchema[0];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT);
|
||||
EXPECT_EQ(pSchema->bytes, 4);
|
||||
EXPECT_STREQ(pSchema->name, "connId");
|
||||
|
||||
pSchema = &pMeta->pSchema[1];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
|
||||
EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE);
|
||||
EXPECT_STREQ(pSchema->name, "user");
|
||||
|
||||
pSchema = &pMeta->pSchema[2];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
|
||||
EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE);
|
||||
EXPECT_STREQ(pSchema->name, "program");
|
||||
|
||||
pSchema = &pMeta->pSchema[3];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT);
|
||||
EXPECT_EQ(pSchema->bytes, 4);
|
||||
EXPECT_STREQ(pSchema->name, "pid");
|
||||
|
||||
pSchema = &pMeta->pSchema[4];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
|
||||
EXPECT_EQ(pSchema->bytes, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE);
|
||||
EXPECT_STREQ(pSchema->name, "ip:port");
|
||||
|
||||
pSchema = &pMeta->pSchema[5];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP);
|
||||
EXPECT_EQ(pSchema->bytes, 8);
|
||||
EXPECT_STREQ(pSchema->name, "login_time");
|
||||
|
||||
pSchema = &pMeta->pSchema[6];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP);
|
||||
EXPECT_EQ(pSchema->bytes, 8);
|
||||
EXPECT_STREQ(pSchema->name, "last_access");
|
||||
}
|
||||
|
||||
{
|
||||
SRetrieveTableMsg* pReq = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
||||
pReq->showId = htonl(showId);
|
||||
pReq->free = 0;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
SRetrieveTableRsp* pRsp = (SRetrieveTableRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
pRsp->numOfRows = htonl(pRsp->numOfRows);
|
||||
pRsp->useconds = htobe64(pRsp->useconds);
|
||||
pRsp->compLen = htonl(pRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRsp->numOfRows, 1);
|
||||
EXPECT_EQ(pRsp->useconds, 0);
|
||||
EXPECT_EQ(pRsp->completed, 1);
|
||||
EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRsp->compressed, 0);
|
||||
EXPECT_EQ(pRsp->compLen, 0);
|
||||
}
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
CheckInt32(1);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("dnode_test_profile", TSDB_APP_NAME_LEN);
|
||||
CheckInt32(1234);
|
||||
IgnoreBinary(TSDB_IPv4ADDR_LEN + 6);
|
||||
CheckTimestamp();
|
||||
CheckTimestamp();
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, SHeartBeatMsg_01) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
TEST_F(DndTestProfile, 04_HeartBeatMsg) {
|
||||
int32_t contLen = sizeof(SHeartBeatMsg);
|
||||
|
||||
SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(sizeof(SHeartBeatMsg));
|
||||
SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(contLen);
|
||||
pReq->connId = htonl(connId);
|
||||
pReq->pid = htonl(1234);
|
||||
pReq->numOfQueries = htonl(0);
|
||||
pReq->numOfStreams = htonl(0);
|
||||
strcpy(pReq->app, "dndTestProfile");
|
||||
strcpy(pReq->app, "dnode_test_profile");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SHeartBeatMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_HEARTBEAT;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_HEARTBEAT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
SHeartBeatRsp* pRsp = (SHeartBeatRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
|
@ -265,62 +127,49 @@ TEST_F(DndTestProfile, SHeartBeatMsg_01) {
|
|||
|
||||
EXPECT_EQ(pRsp->epSet.inUse, 0);
|
||||
EXPECT_EQ(pRsp->epSet.numOfEps, 1);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9522);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9080);
|
||||
EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, SKillConnMsg_01) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
|
||||
TEST_F(DndTestProfile, 05_KillConnMsg) {
|
||||
{
|
||||
SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(sizeof(SKillConnMsg));
|
||||
int32_t contLen = sizeof(SKillConnMsg);
|
||||
|
||||
SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen);
|
||||
pReq->connId = htonl(connId);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SKillConnMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_KILL_CONN;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_CONN, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(sizeof(SHeartBeatMsg));
|
||||
int32_t contLen = sizeof(SHeartBeatMsg);
|
||||
|
||||
SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(contLen);
|
||||
pReq->connId = htonl(connId);
|
||||
pReq->pid = htonl(1234);
|
||||
pReq->numOfQueries = htonl(0);
|
||||
pReq->numOfStreams = htonl(0);
|
||||
strcpy(pReq->app, "dndTestProfile");
|
||||
strcpy(pReq->app, "dnode_test_profile");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SHeartBeatMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_HEARTBEAT;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_HEARTBEAT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONNECTION);
|
||||
ASSERT_EQ(pMsg->contLen, 0);
|
||||
}
|
||||
|
||||
{
|
||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(sizeof(SConnectMsg));
|
||||
int32_t contLen = sizeof(SConnectMsg);
|
||||
|
||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen);
|
||||
pReq->pid = htonl(1234);
|
||||
strcpy(pReq->app, "dndTestProfile");
|
||||
strcpy(pReq->app, "dnode_test_profile");
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SConnectMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CONNECT;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
SConnectRsp* pRsp = (SConnectRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
|
@ -332,71 +181,55 @@ TEST_F(DndTestProfile, SKillConnMsg_01) {
|
|||
EXPECT_EQ(pRsp->acctId, 1);
|
||||
EXPECT_GT(pRsp->clusterId, 0);
|
||||
EXPECT_GT(pRsp->connId, connId);
|
||||
EXPECT_EQ(pRsp->readAuth, 1);
|
||||
EXPECT_EQ(pRsp->writeAuth, 1);
|
||||
EXPECT_EQ(pRsp->superUser, 1);
|
||||
|
||||
EXPECT_EQ(pRsp->epSet.inUse, 0);
|
||||
EXPECT_EQ(pRsp->epSet.numOfEps, 1);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9522);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9080);
|
||||
EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");
|
||||
|
||||
connId = pRsp->connId;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, SKillConnMsg_02) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
TEST_F(DndTestProfile, 06_KillConnMsg_InvalidConn) {
|
||||
int32_t contLen = sizeof(SKillConnMsg);
|
||||
|
||||
SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(sizeof(SKillConnMsg));
|
||||
SKillConnMsg* pReq = (SKillConnMsg*)rpcMallocCont(contLen);
|
||||
pReq->connId = htonl(2345);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SKillConnMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_KILL_CONN;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_CONN, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID);
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, SKillQueryMsg_01) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
|
||||
TEST_F(DndTestProfile, 07_KillQueryMsg) {
|
||||
{
|
||||
SKillQueryMsg* pReq = (SKillQueryMsg*)rpcMallocCont(sizeof(SKillQueryMsg));
|
||||
int32_t contLen = sizeof(SKillQueryMsg);
|
||||
|
||||
SKillQueryMsg* pReq = (SKillQueryMsg*)rpcMallocCont(contLen);
|
||||
pReq->connId = htonl(connId);
|
||||
pReq->queryId = htonl(1234);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SKillQueryMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_KILL_QUERY;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_QUERY, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
ASSERT_EQ(pMsg->contLen, 0);
|
||||
}
|
||||
|
||||
{
|
||||
SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(sizeof(SHeartBeatMsg));
|
||||
int32_t contLen = sizeof(SHeartBeatMsg);
|
||||
|
||||
SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(contLen);
|
||||
pReq->connId = htonl(connId);
|
||||
pReq->pid = htonl(1234);
|
||||
pReq->numOfQueries = htonl(0);
|
||||
pReq->numOfStreams = htonl(0);
|
||||
strcpy(pReq->app, "dndTestProfile");
|
||||
strcpy(pReq->app, "dnode_test_profile");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SHeartBeatMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_HEARTBEAT;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_HEARTBEAT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
SHeartBeatRsp* pRsp = (SHeartBeatRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
|
@ -416,314 +249,42 @@ TEST_F(DndTestProfile, SKillQueryMsg_01) {
|
|||
|
||||
EXPECT_EQ(pRsp->epSet.inUse, 0);
|
||||
EXPECT_EQ(pRsp->epSet.numOfEps, 1);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9522);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9080);
|
||||
EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, SKillQueryMsg_02) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
TEST_F(DndTestProfile, 08_KillQueryMsg_InvalidConn) {
|
||||
int32_t contLen = sizeof(SKillQueryMsg);
|
||||
|
||||
SKillQueryMsg* pReq = (SKillQueryMsg*)rpcMallocCont(sizeof(SKillQueryMsg));
|
||||
SKillQueryMsg* pReq = (SKillQueryMsg*)rpcMallocCont(contLen);
|
||||
pReq->connId = htonl(2345);
|
||||
pReq->queryId = htonl(1234);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SKillQueryMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_KILL_QUERY;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_KILL_QUERY, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID);
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, SKillQueryMsg_03) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
int32_t showId = 0;
|
||||
TEST_F(DndTestProfile, 09_KillQueryMsg) {
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_QUERIES, "");
|
||||
CHECK_META("show queries", 14);
|
||||
|
||||
{
|
||||
SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pReq->type = TSDB_MGMT_TABLE_QUERIES;
|
||||
strcpy(pReq->db, "");
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_INT, 4, "queryId");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_INT, 4, "connId");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "user");
|
||||
CHECK_SCHEMA(3, TSDB_DATA_TYPE_BINARY, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE, "ip:port");
|
||||
CHECK_SCHEMA(4, TSDB_DATA_TYPE_BINARY, 22 + VARSTR_HEADER_SIZE, "qid");
|
||||
CHECK_SCHEMA(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "created_time");
|
||||
CHECK_SCHEMA(6, TSDB_DATA_TYPE_BIGINT, 8, "time");
|
||||
CHECK_SCHEMA(7, TSDB_DATA_TYPE_BINARY, 18 + VARSTR_HEADER_SIZE, "sql_obj_id");
|
||||
CHECK_SCHEMA(8, TSDB_DATA_TYPE_INT, 4, "pid");
|
||||
CHECK_SCHEMA(9, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "ep");
|
||||
CHECK_SCHEMA(10, TSDB_DATA_TYPE_BOOL, 1, "stable_query");
|
||||
CHECK_SCHEMA(11, TSDB_DATA_TYPE_INT, 4, "sub_queries");
|
||||
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");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SShowMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
|
||||
SShowRsp* pRsp = (SShowRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
pRsp->showId = htonl(pRsp->showId);
|
||||
STableMetaMsg* pMeta = &pRsp->tableMeta;
|
||||
pMeta->contLen = htonl(pMeta->contLen);
|
||||
pMeta->numOfColumns = htons(pMeta->numOfColumns);
|
||||
pMeta->sversion = htons(pMeta->sversion);
|
||||
pMeta->tversion = htons(pMeta->tversion);
|
||||
pMeta->tid = htonl(pMeta->tid);
|
||||
pMeta->uid = htobe64(pMeta->uid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
showId = pRsp->showId;
|
||||
|
||||
EXPECT_NE(pRsp->showId, 0);
|
||||
EXPECT_EQ(pMeta->contLen, 0);
|
||||
EXPECT_STREQ(pMeta->tbFname, "");
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->precision, 0);
|
||||
EXPECT_EQ(pMeta->tableType, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, 14);
|
||||
EXPECT_EQ(pMeta->sversion, 0);
|
||||
EXPECT_EQ(pMeta->tversion, 0);
|
||||
EXPECT_EQ(pMeta->tid, 0);
|
||||
EXPECT_EQ(pMeta->uid, 0);
|
||||
EXPECT_STREQ(pMeta->sTableName, "");
|
||||
EXPECT_EQ(pMeta->suid, 0);
|
||||
|
||||
SSchema* pSchema = NULL;
|
||||
pSchema = &pMeta->pSchema[0];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT);
|
||||
EXPECT_EQ(pSchema->bytes, 4);
|
||||
EXPECT_STREQ(pSchema->name, "queryId");
|
||||
|
||||
pSchema = &pMeta->pSchema[1];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT);
|
||||
EXPECT_EQ(pSchema->bytes, 4);
|
||||
EXPECT_STREQ(pSchema->name, "connId");
|
||||
|
||||
pSchema = &pMeta->pSchema[2];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
|
||||
EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE);
|
||||
EXPECT_STREQ(pSchema->name, "user");
|
||||
|
||||
pSchema = &pMeta->pSchema[3];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
|
||||
EXPECT_EQ(pSchema->bytes, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE);
|
||||
EXPECT_STREQ(pSchema->name, "ip:port");
|
||||
}
|
||||
|
||||
{
|
||||
SRetrieveTableMsg* pReq = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
||||
pReq->showId = htonl(showId);
|
||||
pReq->free = 0;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
SRetrieveTableRsp* pRsp = (SRetrieveTableRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
pRsp->numOfRows = htonl(pRsp->numOfRows);
|
||||
pRsp->offset = htobe64(pRsp->offset);
|
||||
pRsp->useconds = htobe64(pRsp->useconds);
|
||||
pRsp->compLen = htonl(pRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRsp->numOfRows, 0);
|
||||
EXPECT_EQ(pRsp->offset, 0);
|
||||
EXPECT_EQ(pRsp->useconds, 0);
|
||||
EXPECT_EQ(pRsp->completed, 1);
|
||||
EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRsp->compressed, 0);
|
||||
EXPECT_EQ(pRsp->reserved, 0);
|
||||
EXPECT_EQ(pRsp->compLen, 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, SKillStreamMsg_01) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
|
||||
{
|
||||
SKillStreamMsg* pReq = (SKillStreamMsg*)rpcMallocCont(sizeof(SKillStreamMsg));
|
||||
pReq->connId = htonl(connId);
|
||||
pReq->streamId = htonl(3579);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SKillStreamMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_KILL_STREAM;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
ASSERT_EQ(pMsg->contLen, 0);
|
||||
}
|
||||
|
||||
{
|
||||
SHeartBeatMsg* pReq = (SHeartBeatMsg*)rpcMallocCont(sizeof(SHeartBeatMsg));
|
||||
pReq->connId = htonl(connId);
|
||||
pReq->pid = htonl(1234);
|
||||
pReq->numOfQueries = htonl(0);
|
||||
pReq->numOfStreams = htonl(0);
|
||||
strcpy(pReq->app, "dndTestProfile");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SHeartBeatMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_HEARTBEAT;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
|
||||
SHeartBeatRsp* pRsp = (SHeartBeatRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
pRsp->connId = htonl(pRsp->connId);
|
||||
pRsp->queryId = htonl(pRsp->queryId);
|
||||
pRsp->streamId = htonl(pRsp->streamId);
|
||||
pRsp->totalDnodes = htonl(pRsp->totalDnodes);
|
||||
pRsp->onlineDnodes = htonl(pRsp->onlineDnodes);
|
||||
pRsp->epSet.port[0] = htons(pRsp->epSet.port[0]);
|
||||
|
||||
EXPECT_EQ(pRsp->connId, connId);
|
||||
EXPECT_EQ(pRsp->queryId, 0);
|
||||
EXPECT_EQ(pRsp->streamId, 3579);
|
||||
EXPECT_EQ(pRsp->totalDnodes, 1);
|
||||
EXPECT_EQ(pRsp->onlineDnodes, 1);
|
||||
EXPECT_EQ(pRsp->killConnection, 0);
|
||||
|
||||
EXPECT_EQ(pRsp->epSet.inUse, 0);
|
||||
EXPECT_EQ(pRsp->epSet.numOfEps, 1);
|
||||
EXPECT_EQ(pRsp->epSet.port[0], 9522);
|
||||
EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, SKillStreamMsg_02) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
|
||||
SKillStreamMsg* pReq = (SKillStreamMsg*)rpcMallocCont(sizeof(SKillStreamMsg));
|
||||
pReq->connId = htonl(2345);
|
||||
pReq->streamId = htonl(1234);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SKillStreamMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_KILL_QUERY;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_CONN_ID);
|
||||
}
|
||||
|
||||
TEST_F(DndTestProfile, SKillStreamMsg_03) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
int32_t showId = 0;
|
||||
|
||||
{
|
||||
SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pReq->type = TSDB_MGMT_TABLE_STREAMS;
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SShowMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
|
||||
SShowRsp* pRsp = (SShowRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
pRsp->showId = htonl(pRsp->showId);
|
||||
STableMetaMsg* pMeta = &pRsp->tableMeta;
|
||||
pMeta->contLen = htonl(pMeta->contLen);
|
||||
pMeta->numOfColumns = htons(pMeta->numOfColumns);
|
||||
pMeta->sversion = htons(pMeta->sversion);
|
||||
pMeta->tversion = htons(pMeta->tversion);
|
||||
pMeta->tid = htonl(pMeta->tid);
|
||||
pMeta->uid = htobe64(pMeta->uid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
showId = pRsp->showId;
|
||||
|
||||
EXPECT_NE(pRsp->showId, 0);
|
||||
EXPECT_EQ(pMeta->contLen, 0);
|
||||
EXPECT_STREQ(pMeta->tbFname, "");
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->precision, 0);
|
||||
EXPECT_EQ(pMeta->tableType, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, 10);
|
||||
EXPECT_EQ(pMeta->sversion, 0);
|
||||
EXPECT_EQ(pMeta->tversion, 0);
|
||||
EXPECT_EQ(pMeta->tid, 0);
|
||||
EXPECT_EQ(pMeta->uid, 0);
|
||||
EXPECT_STREQ(pMeta->sTableName, "");
|
||||
EXPECT_EQ(pMeta->suid, 0);
|
||||
|
||||
SSchema* pSchema = NULL;
|
||||
pSchema = &pMeta->pSchema[0];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT);
|
||||
EXPECT_EQ(pSchema->bytes, 4);
|
||||
EXPECT_STREQ(pSchema->name, "streamId");
|
||||
|
||||
pSchema = &pMeta->pSchema[1];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT);
|
||||
EXPECT_EQ(pSchema->bytes, 4);
|
||||
EXPECT_STREQ(pSchema->name, "connId");
|
||||
|
||||
pSchema = &pMeta->pSchema[2];
|
||||
pSchema->bytes = htons(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
|
||||
EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE);
|
||||
EXPECT_STREQ(pSchema->name, "user");
|
||||
}
|
||||
|
||||
{
|
||||
SRetrieveTableMsg* pReq = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
||||
pReq->showId = htonl(showId);
|
||||
pReq->free = 0;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
SRetrieveTableRsp* pRsp = (SRetrieveTableRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
pRsp->numOfRows = htonl(pRsp->numOfRows);
|
||||
pRsp->offset = htobe64(pRsp->offset);
|
||||
pRsp->useconds = htobe64(pRsp->useconds);
|
||||
pRsp->compLen = htonl(pRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRsp->numOfRows, 0);
|
||||
EXPECT_EQ(pRsp->offset, 0);
|
||||
EXPECT_EQ(pRsp->useconds, 0);
|
||||
EXPECT_EQ(pRsp->completed, 1);
|
||||
EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRsp->compressed, 0);
|
||||
EXPECT_EQ(pRsp->reserved, 0);
|
||||
EXPECT_EQ(pRsp->compLen, 0);
|
||||
}
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
|
|
@ -1,24 +1,8 @@
|
|||
add_executable(dnode_test_show "")
|
||||
|
||||
target_sources(dnode_test_show
|
||||
PRIVATE
|
||||
"show.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
aux_source_directory(. SHOW_SRC)
|
||||
add_executable(dnode_test_show ${SHOW_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_show
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dnode_test_show
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
|
|
|
@ -9,226 +9,79 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "deploy.h"
|
||||
#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 {}
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
const char* user = "root";
|
||||
const char* pass = "taosdata";
|
||||
const char* path = "/tmp/dndTestShow";
|
||||
const char* fqdn = "localhost";
|
||||
uint16_t port = 9523;
|
||||
|
||||
pServer = createServer(path, fqdn, port);
|
||||
ASSERT(pServer);
|
||||
pClient = createClient(user, pass, fqdn, port);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
stopServer(pServer);
|
||||
dropClient(pClient);
|
||||
}
|
||||
|
||||
static SServer* pServer;
|
||||
static SClient* pClient;
|
||||
static int32_t connId;
|
||||
};
|
||||
|
||||
SServer* DndTestShow::pServer;
|
||||
SClient* DndTestShow::pClient;
|
||||
int32_t DndTestShow::connId;
|
||||
Testbase DndTestShow::test;
|
||||
|
||||
TEST_F(DndTestShow, SShowMsg_01) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
TEST_F(DndTestShow, 01_ShowMsg_InvalidMsgMax) {
|
||||
int32_t contLen = sizeof(SShowMsg);
|
||||
|
||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(sizeof(SConnectMsg));
|
||||
pReq->pid = htonl(1234);
|
||||
strcpy(pReq->app, "dndTestShow");
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SConnectMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CONNECT;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
|
||||
SConnectRsp* pRsp = (SConnectRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
pRsp->connId = htonl(pRsp->connId);
|
||||
|
||||
EXPECT_EQ(pRsp->connId, 1);
|
||||
connId = pRsp->connId;
|
||||
}
|
||||
|
||||
TEST_F(DndTestShow, SShowMsg_02) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
|
||||
SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
SShowMsg* pReq = (SShowMsg*)rpcMallocCont(contLen);
|
||||
pReq->type = TSDB_MGMT_TABLE_MAX;
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SShowMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_SHOW, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE);
|
||||
}
|
||||
|
||||
TEST_F(DndTestShow, SShowMsg_03) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
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 rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SShowMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_SHOW, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_MSG_TYPE);
|
||||
}
|
||||
|
||||
TEST_F(DndTestShow, SShowMsg_04) {
|
||||
ASSERT_NE(pClient, nullptr);
|
||||
int32_t showId = 0;
|
||||
TEST_F(DndTestShow, 02_ShowMsg_Conn) {
|
||||
int32_t contLen = sizeof(SConnectMsg);
|
||||
|
||||
{
|
||||
SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pReq->type = TSDB_MGMT_TABLE_CONNS;
|
||||
strcpy(pReq->db, "");
|
||||
SConnectMsg* pReq = (SConnectMsg*)rpcMallocCont(contLen);
|
||||
pReq->pid = htonl(1234);
|
||||
strcpy(pReq->app, "dnode_test_show");
|
||||
strcpy(pReq->db, "");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SShowMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CONNECT, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_CONNS, "");
|
||||
|
||||
SShowRsp* pRsp = (SShowRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
pRsp->showId = htonl(pRsp->showId);
|
||||
STableMetaMsg* pMeta = &pRsp->tableMeta;
|
||||
pMeta->contLen = htonl(pMeta->contLen);
|
||||
pMeta->numOfColumns = htons(pMeta->numOfColumns);
|
||||
pMeta->sversion = htons(pMeta->sversion);
|
||||
pMeta->tversion = htons(pMeta->tversion);
|
||||
pMeta->tid = htonl(pMeta->tid);
|
||||
pMeta->uid = htobe64(pMeta->uid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
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);
|
||||
|
||||
showId = pRsp->showId;
|
||||
test.SendShowRetrieveMsg();
|
||||
|
||||
EXPECT_NE(pRsp->showId, 0);
|
||||
EXPECT_EQ(pMeta->contLen, 0);
|
||||
EXPECT_STREQ(pMeta->tbFname, "");
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->precision, 0);
|
||||
EXPECT_EQ(pMeta->tableType, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, 7);
|
||||
EXPECT_EQ(pMeta->sversion, 0);
|
||||
EXPECT_EQ(pMeta->tversion, 0);
|
||||
EXPECT_EQ(pMeta->tid, 0);
|
||||
EXPECT_EQ(pMeta->uid, 0);
|
||||
EXPECT_STREQ(pMeta->sTableName, "");
|
||||
EXPECT_EQ(pMeta->suid, 0);
|
||||
|
||||
SSchema* pSchema = NULL;
|
||||
pSchema = &pMeta->pSchema[0];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT);
|
||||
EXPECT_EQ(pSchema->bytes, 4);
|
||||
EXPECT_STREQ(pSchema->name, "connId");
|
||||
|
||||
pSchema = &pMeta->pSchema[1];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
|
||||
EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE);
|
||||
EXPECT_STREQ(pSchema->name, "user");
|
||||
|
||||
pSchema = &pMeta->pSchema[2];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
|
||||
EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE);
|
||||
EXPECT_STREQ(pSchema->name, "program");
|
||||
|
||||
pSchema = &pMeta->pSchema[3];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT);
|
||||
EXPECT_EQ(pSchema->bytes, 4);
|
||||
EXPECT_STREQ(pSchema->name, "pid");
|
||||
|
||||
pSchema = &pMeta->pSchema[4];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
|
||||
EXPECT_EQ(pSchema->bytes, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE);
|
||||
EXPECT_STREQ(pSchema->name, "ip:port");
|
||||
|
||||
pSchema = &pMeta->pSchema[5];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP);
|
||||
EXPECT_EQ(pSchema->bytes, 8);
|
||||
EXPECT_STREQ(pSchema->name, "login_time");
|
||||
|
||||
pSchema = &pMeta->pSchema[6];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP);
|
||||
EXPECT_EQ(pSchema->bytes, 8);
|
||||
EXPECT_STREQ(pSchema->name, "last_access");
|
||||
}
|
||||
|
||||
{
|
||||
SRetrieveTableMsg* pReq = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
||||
pReq->showId = htonl(showId);
|
||||
pReq->free = 0;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
SRetrieveTableRsp* pRsp = (SRetrieveTableRsp*)pMsg->pCont;
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
pRsp->numOfRows = htonl(pRsp->numOfRows);
|
||||
pRsp->offset = htobe64(pRsp->offset);
|
||||
pRsp->useconds = htobe64(pRsp->useconds);
|
||||
pRsp->compLen = htonl(pRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRsp->numOfRows, 1);
|
||||
EXPECT_EQ(pRsp->offset, 0);
|
||||
EXPECT_EQ(pRsp->useconds, 0);
|
||||
EXPECT_EQ(pRsp->completed, 1);
|
||||
EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRsp->compressed, 0);
|
||||
EXPECT_EQ(pRsp->reserved, 0);
|
||||
EXPECT_EQ(pRsp->compLen, 0);
|
||||
}
|
||||
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,24 +1,8 @@
|
|||
add_executable(dnode_test_stb "")
|
||||
|
||||
target_sources(dnode_test_stb
|
||||
PRIVATE
|
||||
"stb.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
aux_source_directory(. STB_SRC)
|
||||
add_executable(dnode_test_stb ${STB_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_stb
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dnode_test_stb
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
|
|
|
@ -9,176 +9,27 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "deploy.h"
|
||||
#include "base.h"
|
||||
|
||||
class DndTestStb : public ::testing::Test {
|
||||
protected:
|
||||
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
||||
ASSERT(pServer);
|
||||
return pServer;
|
||||
}
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_stb", 9101); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
initLog("/tmp/tdlog");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9101";
|
||||
pServer = CreateServer("/tmp/dnode_test_stb", fqdn, 9101, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9101);
|
||||
taosMsleep(1100);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
stopServer(pServer);
|
||||
dropClient(pClient);
|
||||
pServer = NULL;
|
||||
pClient = NULL;
|
||||
}
|
||||
|
||||
static SServer* pServer;
|
||||
static SClient* pClient;
|
||||
static int32_t connId;
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns, const char* db) {
|
||||
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pShow->type = showType;
|
||||
if (db != NULL) {
|
||||
strcpy(pShow->db, db);
|
||||
}
|
||||
SRpcMsg showRpcMsg = {0};
|
||||
showRpcMsg.pCont = pShow;
|
||||
showRpcMsg.contLen = sizeof(SShowMsg);
|
||||
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &showRpcMsg);
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pShowRsp, nullptr);
|
||||
pShowRsp->showId = htonl(pShowRsp->showId);
|
||||
pMeta = &pShowRsp->tableMeta;
|
||||
pMeta->numOfTags = htonl(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htonl(pMeta->numOfColumns);
|
||||
pMeta->sversion = htonl(pMeta->sversion);
|
||||
pMeta->tversion = htonl(pMeta->tversion);
|
||||
pMeta->tuid = htobe64(pMeta->tuid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
showId = pShowRsp->showId;
|
||||
|
||||
EXPECT_NE(pShowRsp->showId, 0);
|
||||
EXPECT_STREQ(pMeta->tbFname, showName);
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, columns);
|
||||
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);
|
||||
}
|
||||
|
||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, type);
|
||||
EXPECT_EQ(pSchema->bytes, bytes);
|
||||
EXPECT_STREQ(pSchema->name, name);
|
||||
}
|
||||
|
||||
void SendThenCheckShowRetrieveMsg(int32_t rows) {
|
||||
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
||||
pRetrieve->showId = htonl(showId);
|
||||
pRetrieve->free = 0;
|
||||
|
||||
SRpcMsg retrieveRpcMsg = {0};
|
||||
retrieveRpcMsg.pCont = pRetrieve;
|
||||
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
||||
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
||||
|
||||
sendMsg(pClient, &retrieveRpcMsg);
|
||||
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pRetrieveRsp, nullptr);
|
||||
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
||||
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
|
||||
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
|
||||
EXPECT_EQ(pRetrieveRsp->useconds, 0);
|
||||
// EXPECT_EQ(pRetrieveRsp->completed, completed);
|
||||
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRetrieveRsp->compressed, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->compLen, 0);
|
||||
|
||||
pData = pRetrieveRsp->data;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
void CheckInt8(int8_t val) {
|
||||
int8_t data = *((int8_t*)(pData + pos));
|
||||
pos += sizeof(int8_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt16(int16_t val) {
|
||||
int16_t data = *((int16_t*)(pData + pos));
|
||||
pos += sizeof(int16_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt32(int32_t val) {
|
||||
int32_t data = *((int32_t*)(pData + pos));
|
||||
pos += sizeof(int32_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt64(int64_t val) {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckTimestamp() {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_GT(data, 0);
|
||||
}
|
||||
|
||||
void CheckBinary(const char* val, int32_t len) {
|
||||
pos += sizeof(VarDataLenT);
|
||||
char* data = (char*)(pData + pos);
|
||||
pos += len;
|
||||
EXPECT_STREQ(data, val);
|
||||
}
|
||||
|
||||
int32_t showId;
|
||||
STableMetaMsg* pMeta;
|
||||
SRetrieveTableRsp* pRetrieveRsp;
|
||||
char* pData;
|
||||
int32_t pos;
|
||||
};
|
||||
|
||||
SServer* DndTestStb::pServer;
|
||||
SClient* DndTestStb::pClient;
|
||||
int32_t DndTestStb::connId;
|
||||
Testbase DndTestStb::test;
|
||||
|
||||
TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
||||
{
|
||||
SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(sizeof(SCreateDbMsg));
|
||||
int32_t contLen = sizeof(SCreateDbMsg);
|
||||
|
||||
SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->db, "1.d1");
|
||||
pReq->numOfVgroups = htonl(2);
|
||||
pReq->cacheBlockSize = htonl(16);
|
||||
|
@ -187,8 +38,8 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
|||
pReq->daysToKeep0 = htonl(3650);
|
||||
pReq->daysToKeep1 = htonl(3650);
|
||||
pReq->daysToKeep2 = htonl(3650);
|
||||
pReq->minRowsPerFileBlock = htonl(100);
|
||||
pReq->maxRowsPerFileBlock = htonl(4096);
|
||||
pReq->minRows = htonl(100);
|
||||
pReq->maxRows = htonl(4096);
|
||||
pReq->commitTime = htonl(3600);
|
||||
pReq->fsyncPeriod = htonl(3000);
|
||||
pReq->walLevel = 1;
|
||||
|
@ -200,13 +51,7 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
|||
pReq->cacheLastRow = 0;
|
||||
pReq->ignoreExist = 1;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateDbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_DB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_DB, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
@ -214,9 +59,9 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
|||
{
|
||||
int32_t cols = 2;
|
||||
int32_t tags = 3;
|
||||
int32_t size = (tags + cols) * sizeof(SSchema) + sizeof(SCreateStbMsg);
|
||||
int32_t contLen = (tags + cols) * sizeof(SSchema) + sizeof(SCreateStbMsg);
|
||||
|
||||
SCreateStbMsg* pReq = (SCreateStbMsg*)rpcMallocCont(size);
|
||||
SCreateStbMsg* pReq = (SCreateStbMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->name, "1.d1.stb");
|
||||
pReq->numOfTags = htonl(tags);
|
||||
pReq->numOfColumns = htonl(cols);
|
||||
|
@ -261,24 +106,21 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
|||
strcpy(pSchema->name, "tag3");
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = size;
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_STB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_STB, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_STB, "show stables", 4, "1.d1");
|
||||
CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, "name");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
CheckSchema(2, TSDB_DATA_TYPE_INT, 4, "columns");
|
||||
CheckSchema(3, TSDB_DATA_TYPE_INT, 4, "tags");
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1");
|
||||
CHECK_META("show stables", 4);
|
||||
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CHECK_SCHEMA(0, TSDB_DATA_TYPE_BINARY, TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE, "name");
|
||||
CHECK_SCHEMA(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
CHECK_SCHEMA(2, TSDB_DATA_TYPE_INT, 4, "columns");
|
||||
CHECK_SCHEMA(3, TSDB_DATA_TYPE_INT, 4, "tags");
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
CheckBinary("stb", TSDB_TABLE_NAME_LEN);
|
||||
CheckTimestamp();
|
||||
CheckInt32(2);
|
||||
|
@ -286,16 +128,12 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
|||
|
||||
// ----- meta ------
|
||||
{
|
||||
STableInfoMsg* pReq = (STableInfoMsg*)rpcMallocCont(sizeof(STableInfoMsg));
|
||||
int32_t contLen = sizeof(STableInfoMsg);
|
||||
|
||||
STableInfoMsg* pReq = (STableInfoMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->tableFname, "1.d1.stb");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(STableInfoMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_TABLE_META;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_TABLE_META, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
|
||||
|
@ -336,39 +174,31 @@ TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
|
|||
}
|
||||
|
||||
// restart
|
||||
stopServer(pServer);
|
||||
pServer = NULL;
|
||||
test.Restart();
|
||||
|
||||
uInfo("start all server");
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1");
|
||||
CHECK_META("show stables", 4);
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9101";
|
||||
pServer = startServer("/tmp/dnode_test_stb", fqdn, 9101, firstEp);
|
||||
|
||||
uInfo("all server is running");
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_STB, "show stables", 4, "1.d1");
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckBinary("stb", TSDB_TABLE_NAME_LEN);
|
||||
CheckTimestamp();
|
||||
CheckInt32(2);
|
||||
CheckInt32(3);
|
||||
|
||||
{
|
||||
SDropStbMsg* pReq = (SDropStbMsg*)rpcMallocCont(sizeof(SDropStbMsg));
|
||||
int32_t contLen = sizeof(SDropStbMsg);
|
||||
|
||||
SDropStbMsg* pReq = (SDropStbMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->name, "1.d1.stb");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SDropStbMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_STB;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_STB, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_STB, "show stables", 4, "1.d1");
|
||||
SendThenCheckShowRetrieveMsg(0);
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_STB, "1.d1");
|
||||
CHECK_META("show stables", 4);
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 0);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
aux_source_directory(src SUT_SRC)
|
||||
add_library(sut STATIC ${SUT_SRC})
|
||||
target_link_libraries(
|
||||
sut
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
sut
|
||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
|
@ -1,161 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "deploy.h"
|
||||
|
||||
void initLog(const char* path) {
|
||||
dDebugFlag = 143;
|
||||
vDebugFlag = 0;
|
||||
mDebugFlag = 207;
|
||||
cDebugFlag = 0;
|
||||
jniDebugFlag = 0;
|
||||
tmrDebugFlag = 0;
|
||||
uDebugFlag = 143;
|
||||
rpcDebugFlag = 0;
|
||||
odbcDebugFlag = 0;
|
||||
qDebugFlag = 0;
|
||||
wDebugFlag = 0;
|
||||
sDebugFlag = 0;
|
||||
tsdbDebugFlag = 0;
|
||||
cqDebugFlag = 0;
|
||||
tscEmbeddedInUtil = 1;
|
||||
|
||||
taosRemoveDir(path);
|
||||
taosMkDir(path);
|
||||
|
||||
char temp[PATH_MAX];
|
||||
snprintf(temp, PATH_MAX, "%s/taosdlog", path);
|
||||
if (taosInitLog(temp, tsNumOfLogLines, 1) != 0) {
|
||||
printf("failed to init log file\n");
|
||||
}
|
||||
}
|
||||
|
||||
void* runServer(void* param) {
|
||||
SServer* pServer = (SServer*)param;
|
||||
while (1) {
|
||||
taosMsleep(100);
|
||||
pthread_testcancel();
|
||||
}
|
||||
}
|
||||
|
||||
void initOption(SDnodeOpt* pOption, const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
pOption->sver = 1;
|
||||
pOption->numOfCores = 1;
|
||||
pOption->numOfSupportMnodes = 1;
|
||||
pOption->numOfSupportVnodes = 1;
|
||||
pOption->numOfSupportQnodes = 1;
|
||||
pOption->statusInterval = 1;
|
||||
pOption->numOfThreadsPerCore = 1;
|
||||
pOption->ratioOfQueryCores = 1;
|
||||
pOption->maxShellConns = 1000;
|
||||
pOption->shellActivityTimer = 30;
|
||||
pOption->serverPort = port;
|
||||
strcpy(pOption->dataDir, path);
|
||||
snprintf(pOption->localEp, TSDB_EP_LEN, "%s:%u", fqdn, port);
|
||||
snprintf(pOption->localFqdn, TSDB_FQDN_LEN, "%s", fqdn);
|
||||
snprintf(pOption->firstEp, TSDB_EP_LEN, "%s", firstEp);
|
||||
}
|
||||
|
||||
SServer* startServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
taosMkDir(path);
|
||||
|
||||
SDnodeOpt option = {0};
|
||||
initOption(&option, path, fqdn, port, firstEp);
|
||||
|
||||
SDnode* pDnode = dndInit(&option);
|
||||
ASSERT(pDnode);
|
||||
|
||||
SServer* pServer = (SServer*)calloc(1, sizeof(SServer));
|
||||
ASSERT(pServer);
|
||||
|
||||
pServer->pDnode = pDnode;
|
||||
pServer->threadId = taosCreateThread(runServer, pServer);
|
||||
ASSERT(pServer->threadId);
|
||||
|
||||
return pServer;
|
||||
}
|
||||
|
||||
SServer* createServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
taosRemoveDir(path);
|
||||
return startServer(path, fqdn, port, firstEp);
|
||||
}
|
||||
|
||||
void stopServer(SServer* pServer) {
|
||||
if (pServer == NULL) return;
|
||||
if (pServer->threadId != NULL) {
|
||||
taosDestoryThread(pServer->threadId);
|
||||
}
|
||||
|
||||
if (pServer->pDnode != NULL) {
|
||||
dndCleanup(pServer->pDnode);
|
||||
pServer->pDnode = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void processClientRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
||||
SClient* pClient = (SClient*)parent;
|
||||
pClient->pRsp = pMsg;
|
||||
uInfo("response:%s from dnode, pCont:%p contLen:%d code:0x%X", taosMsg[pMsg->msgType], pMsg->pCont, pMsg->contLen,
|
||||
pMsg->code);
|
||||
tsem_post(&pClient->sem);
|
||||
}
|
||||
|
||||
SClient* createClient(const char* user, const char* pass, const char* fqdn, uint16_t port) {
|
||||
SClient* pClient = (SClient*)calloc(1, sizeof(SClient));
|
||||
ASSERT(pClient);
|
||||
|
||||
char secretEncrypt[TSDB_PASSWORD_LEN] = {0};
|
||||
taosEncryptPass((uint8_t*)pass, strlen(pass), secretEncrypt);
|
||||
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.label = (char*)"DND-C";
|
||||
rpcInit.numOfThreads = 1;
|
||||
rpcInit.cfp = processClientRsp;
|
||||
rpcInit.sessions = 1024;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.idleTime = 30 * 1000;
|
||||
rpcInit.user = (char*)user;
|
||||
rpcInit.ckey = (char*)"key";
|
||||
rpcInit.parent = pClient;
|
||||
rpcInit.secret = (char*)secretEncrypt;
|
||||
rpcInit.parent = pClient;
|
||||
// rpcInit.spi = 1;
|
||||
|
||||
pClient->clientRpc = rpcOpen(&rpcInit);
|
||||
ASSERT(pClient->clientRpc);
|
||||
|
||||
tsem_init(&pClient->sem, 0, 0);
|
||||
strcpy(pClient->fqdn, fqdn);
|
||||
pClient->port = port;
|
||||
|
||||
return pClient;
|
||||
}
|
||||
|
||||
void dropClient(SClient* pClient) {
|
||||
tsem_destroy(&pClient->sem);
|
||||
rpcClose(pClient->clientRpc);
|
||||
}
|
||||
|
||||
void sendMsg(SClient* pClient, SRpcMsg* pMsg) {
|
||||
SEpSet epSet = {0};
|
||||
epSet.inUse = 0;
|
||||
epSet.numOfEps = 1;
|
||||
epSet.port[0] = pClient->port;
|
||||
memcpy(epSet.fqdn[0], pClient->fqdn, TSDB_FQDN_LEN);
|
||||
|
||||
rpcSendRequest(pClient->clientRpc, &epSet, pMsg, NULL);
|
||||
tsem_wait(&pClient->sem);
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "os.h"
|
||||
|
||||
#include "dnode.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "tnote.h"
|
||||
#include "trpc.h"
|
||||
#include "tthread.h"
|
||||
#include "ulog.h"
|
||||
#include "tdataformat.h"
|
||||
|
||||
typedef struct {
|
||||
SDnode* pDnode;
|
||||
pthread_t* threadId;
|
||||
} SServer;
|
||||
|
||||
typedef struct {
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
uint16_t port;
|
||||
void* clientRpc;
|
||||
SRpcMsg* pRsp;
|
||||
tsem_t sem;
|
||||
} SClient;
|
||||
|
||||
void initLog(const char* path);
|
||||
SServer* createServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp);
|
||||
SServer* startServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp);
|
||||
void stopServer(SServer* pServer);
|
||||
SClient* createClient(const char* user, const char* pass, const char* fqdn, uint16_t port);
|
||||
void dropClient(SClient* pClient);
|
||||
void sendMsg(SClient* pClient, SRpcMsg* pMsg);
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_TEST_BASE_H_
|
||||
#define _TD_TEST_BASE_H_
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "os.h"
|
||||
|
||||
#include "dnode.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tconfig.h"
|
||||
#include "tdataformat.h"
|
||||
#include "tglobal.h"
|
||||
#include "tnote.h"
|
||||
#include "trpc.h"
|
||||
#include "tthread.h"
|
||||
#include "ulog.h"
|
||||
|
||||
#include "client.h"
|
||||
#include "server.h"
|
||||
|
||||
class Testbase {
|
||||
public:
|
||||
void Init(const char* path, int16_t port);
|
||||
void Cleanup();
|
||||
void Restart();
|
||||
SRpcMsg* SendMsg(int8_t msgType, void* pCont, int32_t contLen);
|
||||
|
||||
private:
|
||||
void InitLog(const char* path);
|
||||
|
||||
private:
|
||||
TestServer server;
|
||||
TestClient client;
|
||||
int32_t connId;
|
||||
|
||||
public:
|
||||
void SendShowMetaMsg(int8_t showType, const char* db);
|
||||
void SendShowRetrieveMsg();
|
||||
|
||||
STableMetaMsg* GetShowMeta();
|
||||
SRetrieveTableRsp* GetRetrieveRsp();
|
||||
|
||||
int32_t GetMetaNum();
|
||||
const char* GetMetaTbName();
|
||||
int32_t GetMetaColId(int32_t index);
|
||||
int8_t GetMetaType(int32_t index);
|
||||
int32_t GetMetaBytes(int32_t index);
|
||||
const char* GetMetaName(int32_t index);
|
||||
|
||||
const char* GetShowName();
|
||||
int32_t GetShowRows();
|
||||
int8_t GetShowInt8();
|
||||
int16_t GetShowInt16();
|
||||
int32_t GetShowInt32();
|
||||
int64_t GetShowInt64();
|
||||
int64_t GetShowTimestamp();
|
||||
const char* GetShowBinary(int32_t len);
|
||||
|
||||
private:
|
||||
int32_t showId;
|
||||
STableMetaMsg* pMeta;
|
||||
SRetrieveTableRsp* pRetrieveRsp;
|
||||
char* pData;
|
||||
int32_t pos;
|
||||
};
|
||||
|
||||
#define CHECK_META(tbName, numOfColumns) \
|
||||
{ \
|
||||
EXPECT_EQ(test.GetMetaNum(), numOfColumns); \
|
||||
EXPECT_STREQ(test.GetMetaTbName(), tbName); \
|
||||
}
|
||||
|
||||
#define CHECK_SCHEMA(colId, type, bytes, colName) \
|
||||
{ \
|
||||
EXPECT_EQ(test.GetMetaType(colId), type); \
|
||||
EXPECT_EQ(test.GetMetaBytes(colId), bytes); \
|
||||
EXPECT_STREQ(test.GetMetaName(colId), colName); \
|
||||
}
|
||||
|
||||
#define CheckBinary(val, len) \
|
||||
{ EXPECT_STREQ(test.GetShowBinary(len), val); }
|
||||
|
||||
#define CheckInt8(val) \
|
||||
{ EXPECT_EQ(test.GetShowInt8(), val); }
|
||||
|
||||
#define CheckInt16(val) \
|
||||
{ EXPECT_EQ(test.GetShowInt16(), val); }
|
||||
|
||||
#define CheckInt32(val) \
|
||||
{ EXPECT_EQ(test.GetShowInt32(), val); }
|
||||
|
||||
#define CheckInt64(val) \
|
||||
{ EXPECT_EQ(test.GetShowInt64(), val); }
|
||||
|
||||
#define CheckTimestamp() \
|
||||
{ EXPECT_GT(test.GetShowTimestamp(), 0); }
|
||||
|
||||
#define IgnoreBinary(len) \
|
||||
{ test.GetShowBinary(len); }
|
||||
|
||||
#define IgnoreInt8() \
|
||||
{ test.GetShowInt8(); }
|
||||
|
||||
#define IgnoreInt16() \
|
||||
{ test.GetShowInt16(); }
|
||||
|
||||
#define IgnoreInt32() \
|
||||
{ test.GetShowInt32(); }
|
||||
|
||||
#define IgnoreInt64() \
|
||||
{ test.GetShowInt64(); }
|
||||
|
||||
#define IgnoreTimestamp() \
|
||||
{ test.GetShowTimestamp(); }
|
||||
|
||||
#endif /* _TD_TEST_BASE_H_ */
|
|
@ -13,15 +13,24 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_TSDB_SMA_H_
|
||||
#define _TD_TSDB_SMA_H_
|
||||
#ifndef _TD_TEST_CLIENT_H_
|
||||
#define _TD_TEST_CLIENT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
class TestClient {
|
||||
public:
|
||||
bool Init(const char* user, const char* pass, const char* fqdn, uint16_t port);
|
||||
void Cleanup();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
SRpcMsg* SendMsg(SRpcMsg* pMsg);
|
||||
void SetRpcRsp(SRpcMsg* pRsp);
|
||||
tsem_t* GetSem();
|
||||
|
||||
#endif /*_TD_TSDB_SMA_H_*/
|
||||
private:
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
uint16_t port;
|
||||
void* clientRpc;
|
||||
SRpcMsg* pRsp;
|
||||
tsem_t sem;
|
||||
};
|
||||
|
||||
#endif /* _TD_TEST_CLIENT_H_ */
|
|
@ -13,15 +13,26 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_TSDB_IDX_H_
|
||||
#define _TD_TSDB_IDX_H_
|
||||
#ifndef _TD_TEST_SERVER_H_
|
||||
#define _TD_TEST_SERVER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
class TestServer {
|
||||
public:
|
||||
bool Start(const char* path, const char* fqdn, uint16_t port, const char* firstEp);
|
||||
void Stop();
|
||||
void Restart();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
private:
|
||||
SDnodeOpt BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp);
|
||||
bool DoStart();
|
||||
|
||||
#endif /*_TD_TSDB_IDX_H_*/
|
||||
private:
|
||||
SDnode* pDnode;
|
||||
pthread_t* threadId;
|
||||
char path[PATH_MAX];
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
char firstEp[TSDB_EP_LEN];
|
||||
uint16_t port;
|
||||
};
|
||||
|
||||
#endif /* _TD_TEST_SERVER_H_ */
|
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
|
||||
void Testbase::InitLog(const char* path) {
|
||||
dDebugFlag = 207;
|
||||
vDebugFlag = 0;
|
||||
mDebugFlag = 207;
|
||||
cDebugFlag = 0;
|
||||
jniDebugFlag = 0;
|
||||
tmrDebugFlag = 0;
|
||||
uDebugFlag = 143;
|
||||
rpcDebugFlag = 0;
|
||||
odbcDebugFlag = 0;
|
||||
qDebugFlag = 0;
|
||||
wDebugFlag = 0;
|
||||
sDebugFlag = 0;
|
||||
tsdbDebugFlag = 0;
|
||||
cqDebugFlag = 0;
|
||||
tscEmbeddedInUtil = 1;
|
||||
|
||||
taosRemoveDir(path);
|
||||
taosMkDir(path);
|
||||
|
||||
char temp[PATH_MAX];
|
||||
snprintf(temp, PATH_MAX, "%s/taosdlog", path);
|
||||
if (taosInitLog(temp, tsNumOfLogLines, 1) != 0) {
|
||||
printf("failed to init log file\n");
|
||||
}
|
||||
}
|
||||
|
||||
void Testbase::Init(const char* path, int16_t port) {
|
||||
char fqdn[] = "localhost";
|
||||
char firstEp[TSDB_EP_LEN] = {0};
|
||||
snprintf(firstEp, TSDB_EP_LEN, "%s:%u", fqdn, port);
|
||||
|
||||
InitLog("/tmp/tdlog");
|
||||
server.Start(path, fqdn, port, firstEp);
|
||||
client.Init("root", "taosdata", fqdn, port);
|
||||
taosMsleep(1100);
|
||||
}
|
||||
|
||||
void Testbase::Cleanup() {
|
||||
server.Stop();
|
||||
client.Cleanup();
|
||||
}
|
||||
|
||||
void Testbase::Restart() { server.Restart(); }
|
||||
|
||||
SRpcMsg* Testbase::SendMsg(int8_t msgType, void* pCont, int32_t contLen) {
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pCont;
|
||||
rpcMsg.contLen = contLen;
|
||||
rpcMsg.msgType = msgType;
|
||||
|
||||
return client.SendMsg(&rpcMsg);
|
||||
}
|
||||
|
||||
void Testbase::SendShowMetaMsg(int8_t showType, const char* db) {
|
||||
int32_t contLen = sizeof(SShowMsg);
|
||||
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(contLen);
|
||||
pShow->type = showType;
|
||||
strcpy(pShow->db, db);
|
||||
|
||||
SRpcMsg* pMsg = SendMsg(TSDB_MSG_TYPE_SHOW, pShow, contLen);
|
||||
SShowRsp* pShowRsp = (SShowRsp*)pMsg->pCont;
|
||||
|
||||
ASSERT(pShowRsp != nullptr);
|
||||
pShowRsp->showId = htonl(pShowRsp->showId);
|
||||
pMeta = &pShowRsp->tableMeta;
|
||||
pMeta->numOfTags = htonl(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htonl(pMeta->numOfColumns);
|
||||
pMeta->sversion = htonl(pMeta->sversion);
|
||||
pMeta->tversion = htonl(pMeta->tversion);
|
||||
pMeta->tuid = htobe64(pMeta->tuid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
showId = pShowRsp->showId;
|
||||
}
|
||||
|
||||
int32_t Testbase::GetMetaColId(int32_t index) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
pSchema->colId = htonl(pSchema->colId);
|
||||
return pSchema->colId;
|
||||
}
|
||||
|
||||
int8_t Testbase::GetMetaType(int32_t index) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
return pSchema->type;
|
||||
}
|
||||
|
||||
int32_t Testbase::GetMetaBytes(int32_t index) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
return pSchema->bytes;
|
||||
}
|
||||
|
||||
const char* Testbase::GetMetaName(int32_t index) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
return pSchema->name;
|
||||
}
|
||||
|
||||
int32_t Testbase::GetMetaNum() { return pMeta->numOfColumns; }
|
||||
|
||||
const char* Testbase::GetMetaTbName() { return pMeta->tbFname; }
|
||||
|
||||
void Testbase::SendShowRetrieveMsg() {
|
||||
int32_t contLen = sizeof(SRetrieveTableMsg);
|
||||
|
||||
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(contLen);
|
||||
pRetrieve->showId = htonl(showId);
|
||||
pRetrieve->free = 0;
|
||||
|
||||
SRpcMsg* pMsg = SendMsg(TSDB_MSG_TYPE_SHOW_RETRIEVE, pRetrieve, contLen);
|
||||
pRetrieveRsp = (SRetrieveTableRsp*)pMsg->pCont;
|
||||
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
||||
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
|
||||
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
|
||||
|
||||
pData = pRetrieveRsp->data;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
const char* Testbase::GetShowName() { return pMeta->tbFname; }
|
||||
|
||||
int8_t Testbase::GetShowInt8() {
|
||||
int8_t data = *((int8_t*)(pData + pos));
|
||||
pos += sizeof(int8_t);
|
||||
return data;
|
||||
}
|
||||
|
||||
int16_t Testbase::GetShowInt16() {
|
||||
int16_t data = *((int16_t*)(pData + pos));
|
||||
pos += sizeof(int16_t);
|
||||
return data;
|
||||
}
|
||||
|
||||
int32_t Testbase::GetShowInt32() {
|
||||
int32_t data = *((int32_t*)(pData + pos));
|
||||
pos += sizeof(int32_t);
|
||||
return data;
|
||||
}
|
||||
|
||||
int64_t Testbase::GetShowInt64() {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
return data;
|
||||
}
|
||||
|
||||
int64_t Testbase::GetShowTimestamp() {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
return data;
|
||||
}
|
||||
|
||||
const char* Testbase::GetShowBinary(int32_t len) {
|
||||
pos += sizeof(VarDataLenT);
|
||||
char* data = (char*)(pData + pos);
|
||||
pos += len;
|
||||
return data;
|
||||
}
|
||||
|
||||
int32_t Testbase::GetShowRows() { return pRetrieveRsp->numOfRows; }
|
||||
|
||||
STableMetaMsg* Testbase::GetShowMeta() { return pMeta; }
|
||||
|
||||
SRetrieveTableRsp* Testbase::GetRetrieveRsp() { return pRetrieveRsp; }
|
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
|
||||
static void processClientRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
||||
TestClient* client = (TestClient*)parent;
|
||||
client->SetRpcRsp(pMsg);
|
||||
uInfo("response:%s from dnode, code:0x%x", taosMsg[pMsg->msgType], pMsg->code);
|
||||
tsem_post(client->GetSem());
|
||||
}
|
||||
|
||||
void TestClient::SetRpcRsp(SRpcMsg* pRsp) { this->pRsp = pRsp; };
|
||||
|
||||
tsem_t* TestClient::GetSem() { return &sem; }
|
||||
|
||||
bool TestClient::Init(const char* user, const char* pass, const char* fqdn, uint16_t port) {
|
||||
char secretEncrypt[TSDB_PASSWORD_LEN] = {0};
|
||||
taosEncryptPass((uint8_t*)pass, strlen(pass), secretEncrypt);
|
||||
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.label = (char*)"DND-C";
|
||||
rpcInit.numOfThreads = 1;
|
||||
rpcInit.cfp = processClientRsp;
|
||||
rpcInit.sessions = 1024;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.idleTime = 30 * 1000;
|
||||
rpcInit.user = (char*)user;
|
||||
rpcInit.ckey = (char*)"key";
|
||||
rpcInit.parent = this;
|
||||
rpcInit.secret = (char*)secretEncrypt;
|
||||
// rpcInit.spi = 1;
|
||||
|
||||
clientRpc = rpcOpen(&rpcInit);
|
||||
ASSERT(clientRpc);
|
||||
|
||||
tsem_init(&sem, 0, 0);
|
||||
strcpy(this->fqdn, fqdn);
|
||||
this->port = port;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TestClient::Cleanup() {
|
||||
tsem_destroy(&sem);
|
||||
rpcClose(clientRpc);
|
||||
}
|
||||
|
||||
SRpcMsg* TestClient::SendMsg(SRpcMsg* pMsg) {
|
||||
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);
|
||||
tsem_wait(&sem);
|
||||
|
||||
return pRsp;
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "base.h"
|
||||
|
||||
void* serverLoop(void* param) {
|
||||
while (1) {
|
||||
taosMsleep(100);
|
||||
pthread_testcancel();
|
||||
}
|
||||
}
|
||||
|
||||
SDnodeOpt TestServer::BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
SDnodeOpt option = {0};
|
||||
option.sver = 1;
|
||||
option.numOfCores = 1;
|
||||
option.numOfSupportMnodes = 1;
|
||||
option.numOfSupportVnodes = 1;
|
||||
option.numOfSupportQnodes = 1;
|
||||
option.statusInterval = 1;
|
||||
option.numOfThreadsPerCore = 1;
|
||||
option.ratioOfQueryCores = 1;
|
||||
option.maxShellConns = 1000;
|
||||
option.shellActivityTimer = 30;
|
||||
option.serverPort = port;
|
||||
strcpy(option.dataDir, path);
|
||||
snprintf(option.localEp, TSDB_EP_LEN, "%s:%u", fqdn, port);
|
||||
snprintf(option.localFqdn, TSDB_FQDN_LEN, "%s", fqdn);
|
||||
snprintf(option.firstEp, TSDB_EP_LEN, "%s", firstEp);
|
||||
return option;
|
||||
}
|
||||
|
||||
bool TestServer::DoStart() {
|
||||
SDnodeOpt option = BuildOption(path, fqdn, port, firstEp);
|
||||
taosMkDir(path);
|
||||
|
||||
pDnode = dndInit(&option);
|
||||
if (pDnode != NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
threadId = taosCreateThread(serverLoop, NULL);
|
||||
if (threadId != NULL) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void TestServer::Restart() {
|
||||
uInfo("start all server");
|
||||
Stop();
|
||||
DoStart();
|
||||
uInfo("all server is running");
|
||||
}
|
||||
|
||||
bool TestServer::Start(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
strcpy(this->path, path);
|
||||
strcpy(this->fqdn, fqdn);
|
||||
this->port = port;
|
||||
strcpy(this->firstEp, firstEp);
|
||||
|
||||
taosRemoveDir(path);
|
||||
return DoStart();
|
||||
}
|
||||
|
||||
void TestServer::Stop() {
|
||||
if (threadId != NULL) {
|
||||
taosDestoryThread(threadId);
|
||||
threadId = NULL;
|
||||
}
|
||||
|
||||
if (pDnode != NULL) {
|
||||
dndCleanup(pDnode);
|
||||
pDnode = NULL;
|
||||
}
|
||||
}
|
|
@ -1,24 +1,8 @@
|
|||
add_executable(dnode_test_user "")
|
||||
|
||||
target_sources(dnode_test_user
|
||||
PRIVATE
|
||||
"user.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
aux_source_directory(. USER_SRC)
|
||||
add_executable(dnode_test_user ${USER_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_user
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dnode_test_user
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
|
|
|
@ -9,168 +9,34 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "deploy.h"
|
||||
#include "base.h"
|
||||
|
||||
class DndTestUser : public ::testing::Test {
|
||||
protected:
|
||||
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
||||
ASSERT(pServer);
|
||||
return pServer;
|
||||
}
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_user", 9140); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
initLog("/tmp/tdlog");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9140";
|
||||
pServer = CreateServer("/tmp/dnode_test_user", fqdn, 9140, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9140);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
stopServer(pServer);
|
||||
dropClient(pClient);
|
||||
pServer = NULL;
|
||||
pClient = NULL;
|
||||
}
|
||||
|
||||
static SServer* pServer;
|
||||
static SClient* pClient;
|
||||
static int32_t connId;
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns) {
|
||||
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pShow->type = showType;
|
||||
strcpy(pShow->db, "");
|
||||
|
||||
SRpcMsg showRpcMsg = {0};
|
||||
showRpcMsg.pCont = pShow;
|
||||
showRpcMsg.contLen = sizeof(SShowMsg);
|
||||
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &showRpcMsg);
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pShowRsp, nullptr);
|
||||
pShowRsp->showId = htonl(pShowRsp->showId);
|
||||
pMeta = &pShowRsp->tableMeta;
|
||||
pMeta->numOfTags = htonl(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htonl(pMeta->numOfColumns);
|
||||
pMeta->sversion = htonl(pMeta->sversion);
|
||||
pMeta->tversion = htonl(pMeta->tversion);
|
||||
pMeta->tuid = htobe64(pMeta->tuid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
showId = pShowRsp->showId;
|
||||
|
||||
EXPECT_NE(pShowRsp->showId, 0);
|
||||
EXPECT_STREQ(pMeta->tbFname, showName);
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, columns);
|
||||
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);
|
||||
}
|
||||
|
||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, type);
|
||||
EXPECT_EQ(pSchema->bytes, bytes);
|
||||
EXPECT_STREQ(pSchema->name, name);
|
||||
}
|
||||
|
||||
void SendThenCheckShowRetrieveMsg(int32_t rows) {
|
||||
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
||||
pRetrieve->showId = htonl(showId);
|
||||
pRetrieve->free = 0;
|
||||
|
||||
SRpcMsg retrieveRpcMsg = {0};
|
||||
retrieveRpcMsg.pCont = pRetrieve;
|
||||
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
||||
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
||||
|
||||
sendMsg(pClient, &retrieveRpcMsg);
|
||||
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pRetrieveRsp, nullptr);
|
||||
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
||||
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
|
||||
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
|
||||
EXPECT_EQ(pRetrieveRsp->useconds, 0);
|
||||
// EXPECT_EQ(pRetrieveRsp->completed, completed);
|
||||
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRetrieveRsp->compressed, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->compLen, 0);
|
||||
|
||||
pData = pRetrieveRsp->data;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
void CheckInt16(int16_t val) {
|
||||
int16_t data = *((int16_t*)(pData + pos));
|
||||
pos += sizeof(int16_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt64(int64_t val) {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckTimestamp() {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_GT(data, 0);
|
||||
}
|
||||
|
||||
void CheckBinary(const char* val, int32_t len) {
|
||||
pos += sizeof(VarDataLenT);
|
||||
char* data = (char*)(pData + pos);
|
||||
pos += len;
|
||||
EXPECT_STREQ(data, val);
|
||||
}
|
||||
|
||||
int32_t showId;
|
||||
STableMetaMsg* pMeta;
|
||||
SRetrieveTableRsp* pRetrieveRsp;
|
||||
char* pData;
|
||||
int32_t pos;
|
||||
};
|
||||
|
||||
SServer* DndTestUser::pServer;
|
||||
SClient* DndTestUser::pClient;
|
||||
int32_t DndTestUser::connId;
|
||||
Testbase DndTestUser::test;
|
||||
|
||||
TEST_F(DndTestUser, 01_ShowUser) {
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
||||
CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "name");
|
||||
CheckSchema(1, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "privilege");
|
||||
CheckSchema(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
|
||||
CheckSchema(3, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "account");
|
||||
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);
|
||||
|
||||
SendThenCheckShowRetrieveMsg(1);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("super", 10);
|
||||
CheckTimestamp();
|
||||
|
@ -179,39 +45,35 @@ TEST_F(DndTestUser, 01_ShowUser) {
|
|||
|
||||
TEST_F(DndTestUser, 02_Create_Drop_Alter_User) {
|
||||
{
|
||||
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(sizeof(SCreateUserMsg));
|
||||
int32_t contLen = sizeof(SCreateUserMsg);
|
||||
|
||||
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "u1");
|
||||
strcpy(pReq->pass, "p1");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateUserMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_USER;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(sizeof(SCreateUserMsg));
|
||||
int32_t contLen = sizeof(SCreateUserMsg);
|
||||
|
||||
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "u2");
|
||||
strcpy(pReq->pass, "p2");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateUserMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_USER;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
||||
SendThenCheckShowRetrieveMsg(3);
|
||||
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);
|
||||
|
@ -226,22 +88,23 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) {
|
|||
CheckBinary("root", TSDB_USER_LEN);
|
||||
|
||||
{
|
||||
SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(sizeof(SAlterUserMsg));
|
||||
int32_t contLen = sizeof(SAlterUserMsg);
|
||||
|
||||
SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "u1");
|
||||
strcpy(pReq->pass, "p2");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SAlterUserMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_ALTER_USER;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
||||
SendThenCheckShowRetrieveMsg(3);
|
||||
|
||||
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);
|
||||
|
@ -256,21 +119,22 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) {
|
|||
CheckBinary("root", TSDB_USER_LEN);
|
||||
|
||||
{
|
||||
SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(sizeof(SDropUserMsg));
|
||||
int32_t contLen = sizeof(SDropUserMsg);
|
||||
|
||||
SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "u1");
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SDropUserMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_USER;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
||||
SendThenCheckShowRetrieveMsg(2);
|
||||
|
||||
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);
|
||||
|
@ -281,19 +145,14 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) {
|
|||
CheckBinary("root", TSDB_USER_LEN);
|
||||
|
||||
// restart
|
||||
stopServer(pServer);
|
||||
pServer = NULL;
|
||||
test.Restart();
|
||||
|
||||
uInfo("start all server");
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, "");
|
||||
CHECK_META("show users", 4);
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9140";
|
||||
pServer = startServer("/tmp/dnode_test_user", fqdn, 9140, firstEp);
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
|
||||
uInfo("all server is running");
|
||||
|
||||
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
||||
SendThenCheckShowRetrieveMsg(2);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("u2", TSDB_USER_LEN);
|
||||
CheckBinary("super", 10);
|
||||
|
|
|
@ -1,24 +1,8 @@
|
|||
add_executable(dnode_test_vgroup "")
|
||||
|
||||
target_sources(dnode_test_vgroup
|
||||
PRIVATE
|
||||
"vgroup.cpp"
|
||||
"../sut/deploy.cpp"
|
||||
)
|
||||
|
||||
aux_source_directory(. VGROUP_SRC)
|
||||
add_executable(dnode_test_vgroup ${VGROUP_SRC})
|
||||
target_link_libraries(
|
||||
dnode_test_vgroup
|
||||
PUBLIC dnode
|
||||
PUBLIC util
|
||||
PUBLIC os
|
||||
PUBLIC gtest_main
|
||||
)
|
||||
|
||||
target_include_directories(dnode_test_vgroup
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../sut"
|
||||
PUBLIC sut
|
||||
)
|
||||
|
||||
add_test(
|
||||
|
|
|
@ -9,216 +9,121 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "deploy.h"
|
||||
#include "base.h"
|
||||
|
||||
class DndTestVgroup : public ::testing::Test {
|
||||
protected:
|
||||
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
||||
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
||||
ASSERT(pServer);
|
||||
return pServer;
|
||||
}
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dnode_test_vgroup", 9150); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static void SetUpTestSuite() {
|
||||
initLog("/tmp/tdlog");
|
||||
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9150";
|
||||
pServer = CreateServer("/tmp/dnode_test_vgroup", fqdn, 9150, firstEp);
|
||||
pClient = createClient("root", "taosdata", fqdn, 9150);
|
||||
taosMsleep(1100);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
stopServer(pServer);
|
||||
dropClient(pClient);
|
||||
pServer = NULL;
|
||||
pClient = NULL;
|
||||
}
|
||||
|
||||
static SServer* pServer;
|
||||
static SClient* pClient;
|
||||
static int32_t connId;
|
||||
static Testbase test;
|
||||
|
||||
public:
|
||||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns, const char* db) {
|
||||
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
||||
pShow->type = showType;
|
||||
if (db != NULL) {
|
||||
strcpy(pShow->db, db);
|
||||
}
|
||||
SRpcMsg showRpcMsg = {0};
|
||||
showRpcMsg.pCont = pShow;
|
||||
showRpcMsg.contLen = sizeof(SShowMsg);
|
||||
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
||||
|
||||
sendMsg(pClient, &showRpcMsg);
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pShowRsp, nullptr);
|
||||
pShowRsp->showId = htonl(pShowRsp->showId);
|
||||
pMeta = &pShowRsp->tableMeta;
|
||||
pMeta->numOfTags = htonl(pMeta->numOfTags);
|
||||
pMeta->numOfColumns = htonl(pMeta->numOfColumns);
|
||||
pMeta->sversion = htonl(pMeta->sversion);
|
||||
pMeta->tversion = htonl(pMeta->tversion);
|
||||
pMeta->tuid = htobe64(pMeta->tuid);
|
||||
pMeta->suid = htobe64(pMeta->suid);
|
||||
|
||||
showId = pShowRsp->showId;
|
||||
|
||||
EXPECT_NE(pShowRsp->showId, 0);
|
||||
EXPECT_STREQ(pMeta->tbFname, showName);
|
||||
EXPECT_EQ(pMeta->numOfTags, 0);
|
||||
EXPECT_EQ(pMeta->numOfColumns, columns);
|
||||
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);
|
||||
}
|
||||
|
||||
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
||||
SSchema* pSchema = &pMeta->pSchema[index];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
EXPECT_EQ(pSchema->colId, 0);
|
||||
EXPECT_EQ(pSchema->type, type);
|
||||
EXPECT_EQ(pSchema->bytes, bytes);
|
||||
EXPECT_STREQ(pSchema->name, name);
|
||||
}
|
||||
|
||||
void SendThenCheckShowRetrieveMsg(int32_t rows) {
|
||||
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
||||
pRetrieve->showId = htonl(showId);
|
||||
pRetrieve->free = 0;
|
||||
|
||||
SRpcMsg retrieveRpcMsg = {0};
|
||||
retrieveRpcMsg.pCont = pRetrieve;
|
||||
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
||||
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
||||
|
||||
sendMsg(pClient, &retrieveRpcMsg);
|
||||
|
||||
ASSERT_NE(pClient->pRsp, nullptr);
|
||||
ASSERT_EQ(pClient->pRsp->code, 0);
|
||||
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
||||
|
||||
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
||||
ASSERT_NE(pRetrieveRsp, nullptr);
|
||||
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
||||
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
|
||||
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
|
||||
|
||||
EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
|
||||
EXPECT_EQ(pRetrieveRsp->useconds, 0);
|
||||
// EXPECT_EQ(pRetrieveRsp->completed, completed);
|
||||
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
||||
EXPECT_EQ(pRetrieveRsp->compressed, 0);
|
||||
EXPECT_EQ(pRetrieveRsp->compLen, 0);
|
||||
|
||||
pData = pRetrieveRsp->data;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
void CheckInt8(int8_t val) {
|
||||
int8_t data = *((int8_t*)(pData + pos));
|
||||
pos += sizeof(int8_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt16(int16_t val) {
|
||||
int16_t data = *((int16_t*)(pData + pos));
|
||||
pos += sizeof(int16_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt32(int32_t val) {
|
||||
int32_t data = *((int32_t*)(pData + pos));
|
||||
pos += sizeof(int32_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckInt64(int64_t val) {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_EQ(data, val);
|
||||
}
|
||||
|
||||
void CheckTimestamp() {
|
||||
int64_t data = *((int64_t*)(pData + pos));
|
||||
pos += sizeof(int64_t);
|
||||
EXPECT_GT(data, 0);
|
||||
}
|
||||
|
||||
void CheckBinary(const char* val, int32_t len) {
|
||||
pos += sizeof(VarDataLenT);
|
||||
char* data = (char*)(pData + pos);
|
||||
pos += len;
|
||||
EXPECT_STREQ(data, val);
|
||||
}
|
||||
|
||||
int32_t showId;
|
||||
STableMetaMsg* pMeta;
|
||||
SRetrieveTableRsp* pRetrieveRsp;
|
||||
char* pData;
|
||||
int32_t pos;
|
||||
};
|
||||
|
||||
SServer* DndTestVgroup::pServer;
|
||||
SClient* DndTestVgroup::pClient;
|
||||
int32_t DndTestVgroup::connId;
|
||||
|
||||
Testbase DndTestVgroup::test;
|
||||
|
||||
TEST_F(DndTestVgroup, 01_Create_Restart_Drop_Vnode) {
|
||||
{
|
||||
SCreateVnodeMsg* pReq = (SCreateVnodeMsg*)rpcMallocCont(sizeof(SCreateVnodeMsg));
|
||||
pReq->vgId = htonl(2);
|
||||
pReq->dnodeId = htonl(1);
|
||||
strcpy(pReq->db, "1.d1");
|
||||
pReq->dbUid = htobe64(9527);
|
||||
pReq->cacheBlockSize = htonl(16);
|
||||
pReq->totalBlocks = htonl(10);
|
||||
pReq->daysPerFile = htonl(10);
|
||||
pReq->daysToKeep0 = htonl(3650);
|
||||
pReq->daysToKeep1 = htonl(3650);
|
||||
pReq->daysToKeep2 = htonl(3650);
|
||||
pReq->minRows = htonl(100);
|
||||
pReq->minRows = htonl(4096);
|
||||
pReq->commitTime = htonl(3600);
|
||||
pReq->fsyncPeriod = htonl(3000);
|
||||
pReq->walLevel = 1;
|
||||
pReq->precision = 0;
|
||||
pReq->compression = 2;
|
||||
pReq->replica = 1;
|
||||
pReq->quorum = 1;
|
||||
pReq->update = 0;
|
||||
pReq->cacheLastRow = 0;
|
||||
pReq->selfIndex = 0;
|
||||
for (int r = 0; r < pReq->replica; ++r) {
|
||||
SReplica* pReplica = &pReq->replicas[r];
|
||||
pReplica->id = htonl(1);
|
||||
pReplica->port = htons(9150);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
int32_t contLen = sizeof(SCreateVnodeMsg);
|
||||
|
||||
SCreateVnodeMsg* pReq = (SCreateVnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->vgId = htonl(2);
|
||||
pReq->dnodeId = htonl(1);
|
||||
strcpy(pReq->db, "1.d1");
|
||||
pReq->dbUid = htobe64(9527);
|
||||
pReq->vgVersion = htonl(1);
|
||||
pReq->cacheBlockSize = htonl(16);
|
||||
pReq->totalBlocks = htonl(10);
|
||||
pReq->daysPerFile = htonl(10);
|
||||
pReq->daysToKeep0 = htonl(3650);
|
||||
pReq->daysToKeep1 = htonl(3650);
|
||||
pReq->daysToKeep2 = htonl(3650);
|
||||
pReq->minRows = htonl(100);
|
||||
pReq->minRows = htonl(4096);
|
||||
pReq->commitTime = htonl(3600);
|
||||
pReq->fsyncPeriod = htonl(3000);
|
||||
pReq->walLevel = 1;
|
||||
pReq->precision = 0;
|
||||
pReq->compression = 2;
|
||||
pReq->replica = 1;
|
||||
pReq->quorum = 1;
|
||||
pReq->update = 0;
|
||||
pReq->cacheLastRow = 0;
|
||||
pReq->selfIndex = 0;
|
||||
for (int r = 0; r < pReq->replica; ++r) {
|
||||
SReplica* pReplica = &pReq->replicas[r];
|
||||
pReplica->id = htonl(1);
|
||||
pReplica->port = htons(9150);
|
||||
}
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_CREATE_VNODE_IN, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SCreateVnodeMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_VNODE_IN;
|
||||
|
||||
sendMsg(pClient, &rpcMsg);
|
||||
SRpcMsg* pMsg = pClient->pRsp;
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
taosMsleep(1000000);
|
||||
}
|
||||
|
||||
}
|
||||
{
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
int32_t contLen = sizeof(SAlterVnodeMsg);
|
||||
|
||||
SAlterVnodeMsg* pReq = (SAlterVnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->vgId = htonl(2);
|
||||
pReq->dnodeId = htonl(1);
|
||||
strcpy(pReq->db, "1.d1");
|
||||
pReq->dbUid = htobe64(9527);
|
||||
pReq->vgVersion = htonl(2);
|
||||
pReq->cacheBlockSize = htonl(16);
|
||||
pReq->totalBlocks = htonl(10);
|
||||
pReq->daysPerFile = htonl(10);
|
||||
pReq->daysToKeep0 = htonl(3650);
|
||||
pReq->daysToKeep1 = htonl(3650);
|
||||
pReq->daysToKeep2 = htonl(3650);
|
||||
pReq->minRows = htonl(100);
|
||||
pReq->minRows = htonl(4096);
|
||||
pReq->commitTime = htonl(3600);
|
||||
pReq->fsyncPeriod = htonl(3000);
|
||||
pReq->walLevel = 1;
|
||||
pReq->precision = 0;
|
||||
pReq->compression = 2;
|
||||
pReq->replica = 1;
|
||||
pReq->quorum = 1;
|
||||
pReq->update = 0;
|
||||
pReq->cacheLastRow = 0;
|
||||
pReq->selfIndex = 0;
|
||||
for (int r = 0; r < pReq->replica; ++r) {
|
||||
SReplica* pReplica = &pReq->replicas[r];
|
||||
pReplica->id = htonl(1);
|
||||
pReplica->port = htons(9150);
|
||||
}
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_ALTER_VNODE_IN, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
int32_t contLen = sizeof(SDropVnodeMsg);
|
||||
|
||||
SDropVnodeMsg* pReq = (SDropVnodeMsg*)rpcMallocCont(contLen);
|
||||
pReq->vgId = htonl(2);
|
||||
pReq->dnodeId = htonl(1);
|
||||
strcpy(pReq->db, "1.d1");
|
||||
pReq->dbUid = htobe64(9527);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = sizeof(SDropVnodeMsg);
|
||||
rpcMsg.msgType = TSDB_MSG_TYPE_DROP_VNODE_IN;
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TSDB_MSG_TYPE_DROP_VNODE_IN, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,15 +61,14 @@ typedef enum {
|
|||
} EAuthOp;
|
||||
|
||||
typedef enum {
|
||||
TRN_STAGE_PREPARE = 1,
|
||||
TRN_STAGE_EXECUTE = 2,
|
||||
TRN_STAGE_PREPARE = 0,
|
||||
TRN_STAGE_EXECUTE = 1,
|
||||
TRN_STAGE_ROLLBACK = 2,
|
||||
TRN_STAGE_COMMIT = 3,
|
||||
TRN_STAGE_ROLLBACK = 4,
|
||||
TRN_STAGE_RETRY = 5,
|
||||
TRN_STAGE_OVER = 6,
|
||||
TRN_STAGE_OVER = 4,
|
||||
} ETrnStage;
|
||||
|
||||
typedef enum { TRN_POLICY_ROLLBACK = 1, TRN_POLICY_RETRY = 2 } ETrnPolicy;
|
||||
typedef enum { TRN_POLICY_ROLLBACK = 0, TRN_POLICY_RETRY = 1 } ETrnPolicy;
|
||||
|
||||
typedef enum {
|
||||
DND_STATUS_OFFLINE = 0,
|
||||
|
|
|
@ -70,6 +70,7 @@ typedef struct SMnode {
|
|||
tmr_h timer;
|
||||
char *path;
|
||||
SMnodeCfg cfg;
|
||||
int64_t checkTime;
|
||||
SSdb *pSdb;
|
||||
SDnode *pDnode;
|
||||
SArray *pSteps;
|
||||
|
|
|
@ -22,6 +22,16 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
SEpSet epSet;
|
||||
int8_t msgType;
|
||||
int8_t msgSent;
|
||||
int8_t msgReceived;
|
||||
int32_t errCode;
|
||||
int32_t contLen;
|
||||
void *pCont;
|
||||
} STransAction;
|
||||
|
||||
int32_t mndInitTrans(SMnode *pMnode);
|
||||
void mndCleanupTrans(SMnode *pMnode);
|
||||
|
||||
|
@ -30,12 +40,15 @@ void mndTransDrop(STrans *pTrans);
|
|||
int32_t mndTransAppendRedolog(STrans *pTrans, SSdbRaw *pRaw);
|
||||
int32_t mndTransAppendUndolog(STrans *pTrans, SSdbRaw *pRaw);
|
||||
int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw);
|
||||
int32_t mndTransAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, int8_t msgType, int32_t contLen, void *pCont);
|
||||
int32_t mndTransAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, int8_t msgType, int32_t contLen, void *pCont);
|
||||
int32_t mndTransAppendRedoAction(STrans *pTrans, STransAction *pAction);
|
||||
int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction);
|
||||
|
||||
int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans);
|
||||
void mndTransApply(SMnode *pMnode, SSdbRaw *pRaw, STransMsg *pMsg, int32_t code);
|
||||
char *mndTransStageStr(ETrnStage stage);
|
||||
char *mndTransPolicyStr(ETrnPolicy policy);
|
||||
void mndTransHandleActionRsp(SMnodeMsg *pMsg);
|
||||
|
||||
char *mndTransStageStr(ETrnStage stage);
|
||||
char *mndTransPolicyStr(ETrnPolicy policy);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -26,8 +26,9 @@ int32_t mndInitVgroup(SMnode *pMnode);
|
|||
void mndCleanupVgroup(SMnode *pMnode);
|
||||
SVgObj *mndAcquireVgroup(SMnode *pMnode, int32_t vgId);
|
||||
void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup);
|
||||
int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups);
|
||||
SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup);
|
||||
int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups);
|
||||
SEpSet mndGetVgroupEpset(SMnode *pMnode, SVgObj *pVgroup);
|
||||
|
||||
SCreateVnodeMsg *mndBuildCreateVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup);
|
||||
SDropVnodeMsg *mndBuildDropVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup);
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
#include "mndAcct.h"
|
||||
#include "mndShow.h"
|
||||
|
||||
#define SDB_ACCT_VER 1
|
||||
#define TSDB_ACCT_VER_NUMBER 1
|
||||
#define TSDB_ACCT_RESERVE_SIZE 64
|
||||
|
||||
static int32_t mndCreateDefaultAcct(SMnode *pMnode);
|
||||
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct);
|
||||
|
@ -70,7 +71,7 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
|
|||
}
|
||||
|
||||
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) {
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, SDB_ACCT_VER, sizeof(SAcctObj));
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, TSDB_ACCT_VER_NUMBER, sizeof(SAcctObj) + TSDB_ACCT_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
|
@ -85,6 +86,7 @@ static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) {
|
|||
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);
|
||||
|
||||
return pRaw;
|
||||
|
@ -94,7 +96,7 @@ static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) {
|
|||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
if (sver != SDB_ACCT_VER) {
|
||||
if (sver != TSDB_ACCT_VER_NUMBER) {
|
||||
mError("failed to decode acct since %s", terrstr());
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
return NULL;
|
||||
|
@ -116,13 +118,13 @@ static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) {
|
|||
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)
|
||||
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mndAcctActionInsert(SSdb *pSdb, SAcctObj *pAcct) {
|
||||
mTrace("acct:%s, perform insert action", pAcct->acct);
|
||||
memset(&pAcct->info, 0, sizeof(SAcctInfo));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -134,12 +136,9 @@ static int32_t mndAcctActionDelete(SSdb *pSdb, SAcctObj *pAcct) {
|
|||
static int32_t mndAcctActionUpdate(SSdb *pSdb, SAcctObj *pOldAcct, SAcctObj *pNewAcct) {
|
||||
mTrace("acct:%s, perform update action", pOldAcct->acct);
|
||||
|
||||
memcpy(pOldAcct->acct, pNewAcct->acct, TSDB_USER_LEN);
|
||||
pOldAcct->createdTime = pNewAcct->createdTime;
|
||||
pOldAcct->updateTime = pNewAcct->updateTime;
|
||||
pOldAcct->acctId = pNewAcct->acctId;
|
||||
pOldAcct->status = pNewAcct->status;
|
||||
pOldAcct->cfg = pNewAcct->cfg;
|
||||
memcpy(&pOldAcct->cfg, &pNewAcct->cfg, sizeof(SAcctInfo));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@
|
|||
#include "mndShow.h"
|
||||
#include "mndTrans.h"
|
||||
|
||||
#define SDB_CLUSTER_VER 1
|
||||
#define TSDB_CLUSTER_VER_NUMBE 1
|
||||
#define TSDB_CLUSTER_RESERVE_SIZE 64
|
||||
|
||||
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster);
|
||||
static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw);
|
||||
|
@ -62,7 +63,7 @@ int32_t mndGetClusterName(SMnode *pMnode, char *clusterName, int32_t len) {
|
|||
}
|
||||
|
||||
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) {
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_CLUSTER, SDB_CLUSTER_VER, sizeof(SClusterObj));
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_CLUSTER, TSDB_CLUSTER_VER_NUMBE, sizeof(SClusterObj) + TSDB_CLUSTER_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
|
@ -70,6 +71,7 @@ static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) {
|
|||
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)
|
||||
|
||||
return pRaw;
|
||||
}
|
||||
|
@ -78,7 +80,7 @@ static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) {
|
|||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
if (sver != SDB_CLUSTER_VER) {
|
||||
if (sver != TSDB_CLUSTER_VER_NUMBE) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
mError("failed to decode cluster since %s", terrstr());
|
||||
return NULL;
|
||||
|
@ -93,6 +95,7 @@ static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) {
|
|||
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)
|
||||
|
||||
return pRow;
|
||||
}
|
||||
|
@ -169,6 +172,7 @@ static int32_t mndGetClusterMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg
|
|||
|
||||
pShow->numOfRows = 1;
|
||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||
strcpy(pMeta->tbFname, mndShowStr(pShow->type));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -16,13 +16,12 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "mndDb.h"
|
||||
#include "mndDnode.h"
|
||||
#include "mndMnode.h"
|
||||
#include "mndShow.h"
|
||||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
#include "mndVgroup.h"
|
||||
|
||||
#define TSDB_DB_VER_NUM 1
|
||||
#define TSDB_DB_VER_NUMBER 1
|
||||
#define TSDB_DB_RESERVE_SIZE 64
|
||||
|
||||
static SSdbRaw *mndDbActionEncode(SDbObj *pDb);
|
||||
|
@ -66,7 +65,7 @@ int32_t mndInitDb(SMnode *pMnode) {
|
|||
void mndCleanupDb(SMnode *pMnode) {}
|
||||
|
||||
static SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_DB, TSDB_DB_VER_NUM, sizeof(SDbObj) + TSDB_DB_RESERVE_SIZE);
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_DB, TSDB_DB_VER_NUMBER, sizeof(SDbObj) + TSDB_DB_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
|
@ -106,7 +105,7 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) {
|
|||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
if (sver != TSDB_DB_VER_NUM) {
|
||||
if (sver != TSDB_DB_VER_NUMBER) {
|
||||
mError("failed to decode db since %s", terrstr());
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
return NULL;
|
||||
|
@ -160,7 +159,7 @@ static int32_t mndDbActionDelete(SSdb *pSdb, SDbObj *pDb) {
|
|||
|
||||
static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOldDb, SDbObj *pNewDb) {
|
||||
mTrace("db:%s, perform update action", pOldDb->name);
|
||||
pOldDb->updateTime = pNewDb->createdTime;
|
||||
pOldDb->updateTime = pNewDb->updateTime;
|
||||
pOldDb->cfgVersion = pNewDb->cfgVersion;
|
||||
pOldDb->vgVersion = pNewDb->vgVersion;
|
||||
memcpy(&pOldDb->cfg, &pNewDb->cfg, sizeof(SDbCfg));
|
||||
|
@ -168,8 +167,12 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOldDb, SDbObj *pNewDb) {
|
|||
}
|
||||
|
||||
SDbObj *mndAcquireDb(SMnode *pMnode, char *db) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
return sdbAcquire(pSdb, SDB_DB, db);
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SDbObj *pDb = sdbAcquire(pSdb, SDB_DB, db);
|
||||
if (pDb == NULL) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||
}
|
||||
return pDb;
|
||||
}
|
||||
|
||||
void mndReleaseDb(SMnode *pMnode, SDbObj *pDb) {
|
||||
|
@ -242,68 +245,74 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) {
|
|||
if (pCfg->cacheLastRow < 0) pCfg->cacheLastRow = TSDB_DEFAULT_CACHE_LAST_ROW;
|
||||
}
|
||||
|
||||
static int32_t mndSetRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
static int32_t mndSetCreateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
SSdbRaw *pDbRaw = mndDbActionEncode(pDb);
|
||||
if (pDbRaw == NULL || mndTransAppendRedolog(pTrans, pDbRaw) != 0) return -1;
|
||||
sdbSetRawStatus(pDbRaw, SDB_STATUS_CREATING);
|
||||
if (pDbRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pDbRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pDbRaw, SDB_STATUS_CREATING) != 0) return -1;
|
||||
|
||||
for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
|
||||
if (pVgRaw == NULL || mndTransAppendRedolog(pTrans, pVgRaw) != 0) return -1;
|
||||
sdbSetRawStatus(pVgRaw, SDB_STATUS_CREATING);
|
||||
if (pVgRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pVgRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pVgRaw, SDB_STATUS_CREATING) != 0) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
static int32_t mndSetCreateDbUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
SSdbRaw *pDbRaw = mndDbActionEncode(pDb);
|
||||
if (pDbRaw == NULL || mndTransAppendUndolog(pTrans, pDbRaw) != 0) return -1;
|
||||
sdbSetRawStatus(pDbRaw, SDB_STATUS_DROPPED);
|
||||
if (pDbRaw == NULL) return -1;
|
||||
if (mndTransAppendUndolog(pTrans, pDbRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pDbRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
|
||||
for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
|
||||
if (pVgRaw == NULL || mndTransAppendUndolog(pTrans, pVgRaw) != 0) return -1;
|
||||
sdbSetRawStatus(pVgRaw, SDB_STATUS_DROPPED);
|
||||
if (pVgRaw == NULL) return -1;
|
||||
if (mndTransAppendUndolog(pTrans, pVgRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pVgRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
static int32_t mndSetCreateDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
SSdbRaw *pDbRaw = mndDbActionEncode(pDb);
|
||||
if (pDbRaw == NULL || mndTransAppendCommitlog(pTrans, pDbRaw) != 0) return -1;
|
||||
sdbSetRawStatus(pDbRaw, SDB_STATUS_READY);
|
||||
if (pDbRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pDbRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pDbRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
|
||||
for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
for (int32_t v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
|
||||
if (pVgRaw == NULL || mndTransAppendCommitlog(pTrans, pVgRaw) != 0) return -1;
|
||||
sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
|
||||
if (pVgRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pVgRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pVgRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
SVgObj *pVgroup = pVgroups + v;
|
||||
static int32_t mndSetCreateDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
for (int32_t vg = 0; vg < pDb->cfg.numOfVgroups; ++vg) {
|
||||
SVgObj *pVgroup = pVgroups + vg;
|
||||
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) {
|
||||
return -1;
|
||||
}
|
||||
STransAction action = {0};
|
||||
SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
|
||||
|
||||
SEpSet epset = mndGetDnodeEpset(pDnode);
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) return -1;
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
SCreateVnodeMsg *pMsg = mndBuildCreateVnodeMsg(pMnode, pDnode, pDb, pVgroup);
|
||||
if (pMsg == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (pMsg == NULL) return -1;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &epset, TSDB_MSG_TYPE_ALTER_VNODE_IN, sizeof(SCreateVnodeMsg), pMsg) != 0) {
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SCreateVnodeMsg);
|
||||
action.msgType = TSDB_MSG_TYPE_CREATE_VNODE_IN;
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
return -1;
|
||||
}
|
||||
|
@ -313,26 +322,26 @@ static int32_t mndSetRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SV
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
|
||||
SVgObj *pVgroup = pVgroups + v;
|
||||
static int32_t mndSetCreateDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroups) {
|
||||
for (int32_t vg = 0; vg < pDb->cfg.numOfVgroups; ++vg) {
|
||||
SVgObj *pVgroup = pVgroups + vg;
|
||||
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) {
|
||||
return -1;
|
||||
}
|
||||
STransAction action = {0};
|
||||
SVnodeGid *pVgid = pVgroup->vnodeGid + vn;
|
||||
|
||||
SEpSet epset = mndGetDnodeEpset(pDnode);
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) return -1;
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
SDropVnodeMsg *pMsg = mndBuildDropVnodeMsg(pMnode, pDnode, pDb, pVgroup);
|
||||
if (pMsg == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (pMsg == NULL) return -1;
|
||||
|
||||
if (mndTransAppendUndoAction(pTrans, &epset, TSDB_MSG_TYPE_DROP_VNODE_IN, sizeof(SDropVnodeMsg), pMsg) != 0) {
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SDropVnodeMsg);
|
||||
action.msgType = TSDB_MSG_TYPE_DROP_VNODE_IN;
|
||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
return -1;
|
||||
}
|
||||
|
@ -344,14 +353,14 @@ static int32_t mndSetUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SV
|
|||
|
||||
static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreate, SUserObj *pUser) {
|
||||
SDbObj dbObj = {0};
|
||||
tstrncpy(dbObj.name, pCreate->db, TSDB_FULL_DB_NAME_LEN);
|
||||
tstrncpy(dbObj.acct, pUser->acct, TSDB_USER_LEN);
|
||||
memcpy(dbObj.name, pCreate->db, TSDB_FULL_DB_NAME_LEN);
|
||||
memcpy(dbObj.acct, pUser->acct, TSDB_USER_LEN);
|
||||
dbObj.createdTime = taosGetTimestampMs();
|
||||
dbObj.updateTime = dbObj.createdTime;
|
||||
dbObj.uid = mndGenerateUid(dbObj.name, TSDB_FULL_DB_NAME_LEN);
|
||||
dbObj.hashMethod = 1;
|
||||
dbObj.cfgVersion = 1;
|
||||
dbObj.vgVersion = 1;
|
||||
dbObj.hashMethod = 1;
|
||||
dbObj.cfg = (SDbCfg){.numOfVgroups = pCreate->numOfVgroups,
|
||||
.cacheBlockSize = pCreate->cacheBlockSize,
|
||||
.totalBlocks = pCreate->totalBlocks,
|
||||
|
@ -359,8 +368,8 @@ static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreat
|
|||
.daysToKeep0 = pCreate->daysToKeep0,
|
||||
.daysToKeep1 = pCreate->daysToKeep1,
|
||||
.daysToKeep2 = pCreate->daysToKeep2,
|
||||
.minRows = pCreate->minRowsPerFileBlock,
|
||||
.maxRows = pCreate->maxRowsPerFileBlock,
|
||||
.minRows = pCreate->minRows,
|
||||
.maxRows = pCreate->maxRows,
|
||||
.fsyncPeriod = pCreate->fsyncPeriod,
|
||||
.commitTime = pCreate->commitTime,
|
||||
.precision = pCreate->precision,
|
||||
|
@ -396,29 +405,30 @@ static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreat
|
|||
mError("db:%s, failed to create since %s", pCreate->db, terrstr());
|
||||
goto CREATE_DB_OVER;
|
||||
}
|
||||
|
||||
mDebug("trans:%d, used to create db:%s", pTrans->id, pCreate->db);
|
||||
|
||||
if (mndSetRedoLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) {
|
||||
if (mndSetCreateDbRedoLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) {
|
||||
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_DB_OVER;
|
||||
}
|
||||
|
||||
if (mndSetUndoLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) {
|
||||
if (mndSetCreateDbUndoLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) {
|
||||
mError("trans:%d, failed to set undo log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_DB_OVER;
|
||||
}
|
||||
|
||||
if (mndSetCommitLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) {
|
||||
if (mndSetCreateDbCommitLogs(pMnode, pTrans, &dbObj, pVgroups) != 0) {
|
||||
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_DB_OVER;
|
||||
}
|
||||
|
||||
if (mndSetRedoActions(pMnode, pTrans, &dbObj, pVgroups) != 0) {
|
||||
if (mndSetCreateDbRedoActions(pMnode, pTrans, &dbObj, pVgroups) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto CREATE_DB_OVER;
|
||||
}
|
||||
|
||||
if (mndSetUndoActions(pMnode, pTrans, &dbObj, pVgroups) != 0) {
|
||||
if (mndSetCreateDbUndoActions(pMnode, pTrans, &dbObj, pVgroups) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto CREATE_DB_OVER;
|
||||
}
|
||||
|
@ -447,8 +457,8 @@ static int32_t mndProcessCreateDbMsg(SMnodeMsg *pMsg) {
|
|||
pCreate->daysToKeep0 = htonl(pCreate->daysToKeep0);
|
||||
pCreate->daysToKeep1 = htonl(pCreate->daysToKeep1);
|
||||
pCreate->daysToKeep2 = htonl(pCreate->daysToKeep2);
|
||||
pCreate->minRowsPerFileBlock = htonl(pCreate->minRowsPerFileBlock);
|
||||
pCreate->maxRowsPerFileBlock = htonl(pCreate->maxRowsPerFileBlock);
|
||||
pCreate->minRows = htonl(pCreate->minRows);
|
||||
pCreate->maxRows = htonl(pCreate->maxRows);
|
||||
pCreate->commitTime = htonl(pCreate->commitTime);
|
||||
pCreate->fsyncPeriod = htonl(pCreate->fsyncPeriod);
|
||||
|
||||
|
@ -456,7 +466,7 @@ static int32_t mndProcessCreateDbMsg(SMnodeMsg *pMsg) {
|
|||
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pCreate->db);
|
||||
if (pDb != NULL) {
|
||||
sdbRelease(pMnode->pSdb, pDb);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
if (pCreate->ignoreExist) {
|
||||
mDebug("db:%s, already exist, ignore exist is set", pCreate->db);
|
||||
return 0;
|
||||
|
@ -485,57 +495,77 @@ static int32_t mndProcessCreateDbMsg(SMnodeMsg *pMsg) {
|
|||
}
|
||||
|
||||
static int32_t mndSetDbCfgFromAlterDbMsg(SDbObj *pDb, SAlterDbMsg *pAlter) {
|
||||
bool changed = false;
|
||||
terrno = TSDB_CODE_MND_DB_OPTION_UNCHANGED;
|
||||
|
||||
if (pAlter->totalBlocks >= 0 && pAlter->totalBlocks != pDb->cfg.totalBlocks) {
|
||||
pDb->cfg.totalBlocks = pAlter->totalBlocks;
|
||||
changed = true;
|
||||
terrno = 0;
|
||||
}
|
||||
|
||||
if (pAlter->daysToKeep0 >= 0 && pAlter->daysToKeep0 != pDb->cfg.daysToKeep0) {
|
||||
pDb->cfg.daysToKeep0 = pAlter->daysToKeep0;
|
||||
changed = true;
|
||||
terrno = 0;
|
||||
}
|
||||
|
||||
if (pAlter->daysToKeep1 >= 0 && pAlter->daysToKeep1 != pDb->cfg.daysToKeep1) {
|
||||
pDb->cfg.daysToKeep1 = pAlter->daysToKeep1;
|
||||
changed = true;
|
||||
terrno = 0;
|
||||
}
|
||||
|
||||
if (pAlter->daysToKeep2 >= 0 && pAlter->daysToKeep2 != pDb->cfg.daysToKeep2) {
|
||||
pDb->cfg.daysToKeep2 = pAlter->daysToKeep2;
|
||||
changed = true;
|
||||
terrno = 0;
|
||||
}
|
||||
|
||||
if (pAlter->fsyncPeriod >= 0 && pAlter->fsyncPeriod != pDb->cfg.fsyncPeriod) {
|
||||
pDb->cfg.fsyncPeriod = pAlter->fsyncPeriod;
|
||||
changed = true;
|
||||
terrno = 0;
|
||||
}
|
||||
|
||||
if (pAlter->walLevel >= 0 && pAlter->walLevel != pDb->cfg.walLevel) {
|
||||
pDb->cfg.walLevel = pAlter->walLevel;
|
||||
changed = true;
|
||||
terrno = 0;
|
||||
}
|
||||
|
||||
if (pAlter->quorum >= 0 && pAlter->quorum != pDb->cfg.quorum) {
|
||||
pDb->cfg.quorum = pAlter->quorum;
|
||||
changed = true;
|
||||
terrno = 0;
|
||||
}
|
||||
|
||||
if (pAlter->cacheLastRow >= 0 && pAlter->cacheLastRow != pDb->cfg.cacheLastRow) {
|
||||
pDb->cfg.cacheLastRow = pAlter->cacheLastRow;
|
||||
changed = true;
|
||||
terrno = 0;
|
||||
}
|
||||
|
||||
if (!changed) {
|
||||
terrno = TSDB_CODE_MND_DB_OPTION_UNCHANGED;
|
||||
return -1;
|
||||
}
|
||||
return terrno;
|
||||
}
|
||||
|
||||
static int32_t mndSetUpdateDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) {
|
||||
SSdbRaw *pRedoRaw = mndDbActionEncode(pNewDb);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetUpdateDbUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) {
|
||||
SSdbRaw *pUndoRaw = mndDbActionEncode(pOldDb);
|
||||
if (pUndoRaw == NULL) return -1;
|
||||
if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetUpdateDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { return 0; }
|
||||
|
||||
static int32_t mndSetUpdateDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { return 0; }
|
||||
|
||||
static int32_t mndSetUpdateDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb) { return 0; }
|
||||
|
||||
static int32_t mndUpdateDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pOldDb, SDbObj *pNewDb) {
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
|
||||
if (pTrans == NULL) {
|
||||
mError("db:%s, failed to update since %s", pOldDb->name, terrstr());
|
||||
|
@ -544,30 +574,41 @@ static int32_t mndUpdateDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pOldDb, SDbO
|
|||
|
||||
mDebug("trans:%d, used to update db:%s", pTrans->id, pOldDb->name);
|
||||
|
||||
SSdbRaw *pRedoRaw = mndDbActionEncode(pNewDb);
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
if (mndSetUpdateDbRedoLogs(pMnode, pTrans, pOldDb, pNewDb) != 0) {
|
||||
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||
goto UPDATE_DB_OVER;
|
||||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY);
|
||||
|
||||
SSdbRaw *pUndoRaw = mndDbActionEncode(pOldDb);
|
||||
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
|
||||
mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
if (mndSetUpdateDbUndoLogs(pMnode, pTrans, pOldDb, pNewDb) != 0) {
|
||||
mError("trans:%d, failed to set undo log since %s", pTrans->id, terrstr());
|
||||
goto UPDATE_DB_OVER;
|
||||
}
|
||||
|
||||
if (mndSetUpdateDbCommitLogs(pMnode, pTrans, pOldDb, pNewDb) != 0) {
|
||||
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||
goto UPDATE_DB_OVER;
|
||||
}
|
||||
|
||||
if (mndSetUpdateDbRedoActions(pMnode, pTrans, pOldDb, pNewDb) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto UPDATE_DB_OVER;
|
||||
}
|
||||
|
||||
if (mndSetUpdateDbUndoActions(pMnode, pTrans, pOldDb, pNewDb) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto UPDATE_DB_OVER;
|
||||
}
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
goto UPDATE_DB_OVER;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
||||
UPDATE_DB_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessAlterDbMsg(SMnodeMsg *pMsg) {
|
||||
|
@ -610,46 +651,82 @@ static int32_t mndProcessAlterDbMsg(SMnodeMsg *pMsg) {
|
|||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndSetDropDbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
||||
SSdbRaw *pRedoRaw = mndDbActionEncode(pDb);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetDropDbUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
||||
SSdbRaw *pUndoRaw = mndDbActionEncode(pDb);
|
||||
if (pUndoRaw == NULL) return -1;
|
||||
if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetDropDbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
||||
SSdbRaw *pCommitRaw = mndDbActionEncode(pDb);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetDropDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { return 0; }
|
||||
|
||||
static int32_t mndSetDropDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { return 0; }
|
||||
|
||||
static int32_t mndDropDb(SMnode *pMnode, SMnodeMsg *pMsg, SDbObj *pDb) {
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
|
||||
if (pTrans == NULL) {
|
||||
mError("db:%s, failed to drop since %s", pDb->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
mDebug("trans:%d, used to drop db:%s", pTrans->id, pDb->name);
|
||||
|
||||
SSdbRaw *pRedoRaw = mndDbActionEncode(pDb);
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
if (mndSetDropDbRedoLogs(pMnode, pTrans, pDb) != 0) {
|
||||
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||
goto DROP_DB_OVER;
|
||||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING);
|
||||
|
||||
SSdbRaw *pUndoRaw = mndDbActionEncode(pDb);
|
||||
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
|
||||
mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
if (mndSetDropDbUndoLogs(pMnode, pTrans, pDb) != 0) {
|
||||
mError("trans:%d, failed to set undo log since %s", pTrans->id, terrstr());
|
||||
goto DROP_DB_OVER;
|
||||
}
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY);
|
||||
|
||||
SSdbRaw *pCommitRaw = mndDbActionEncode(pDb);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
if (mndSetDropDbCommitLogs(pMnode, pTrans, pDb) != 0) {
|
||||
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||
goto DROP_DB_OVER;
|
||||
}
|
||||
|
||||
if (mndSetDropDbRedoActions(pMnode, pTrans, pDb) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto DROP_DB_OVER;
|
||||
}
|
||||
|
||||
if (mndSetDropDbUndoActions(pMnode, pTrans, pDb) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto DROP_DB_OVER;
|
||||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
goto DROP_DB_OVER;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
||||
DROP_DB_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropDbMsg(SMnodeMsg *pMsg) {
|
||||
|
@ -751,29 +828,27 @@ static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) {
|
|||
static int32_t mndProcessSyncDbMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SSyncDbMsg *pSync = pMsg->rpcMsg.pCont;
|
||||
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pMsg->db);
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pMsg->db);
|
||||
if (pDb == NULL) {
|
||||
mError("db:%s, failed to process sync db msg since %s", pMsg->db, terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCompactDbMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SCompactDbMsg *pCompact = pMsg->rpcMsg.pCont;
|
||||
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pMsg->db);
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pMsg->db);
|
||||
if (pDb == NULL) {
|
||||
mError("db:%s, failed to process compact db msg since %s", pMsg->db, terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndGetDbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
#include "mndMnode.h"
|
||||
#include "mndShow.h"
|
||||
#include "mndTrans.h"
|
||||
#include "ttime.h"
|
||||
#include "tep.h"
|
||||
#include "ttime.h"
|
||||
|
||||
#define TSDB_DNODE_VER 1
|
||||
#define TSDB_DNODE_VER_NUMBER 1
|
||||
#define TSDB_DNODE_RESERVE_SIZE 64
|
||||
#define TSDB_CONFIG_OPTION_LEN 16
|
||||
#define TSDB_CONIIG_VALUE_LEN 48
|
||||
|
@ -101,14 +101,14 @@ static int32_t mndCreateDefaultDnode(SMnode *pMnode) {
|
|||
|
||||
SSdbRaw *pRaw = mndDnodeActionEncode(&dnodeObj);
|
||||
if (pRaw == NULL) return -1;
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
if (sdbSetRawStatus(pRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
|
||||
mDebug("dnode:%d, will be created while deploy sdb", dnodeObj.id);
|
||||
return sdbWrite(pMnode->pSdb, pRaw);
|
||||
}
|
||||
|
||||
static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) {
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_DNODE, TSDB_DNODE_VER, sizeof(SDnodeObj) + TSDB_DNODE_RESERVE_SIZE);
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_DNODE, TSDB_DNODE_VER_NUMBER, sizeof(SDnodeObj) + TSDB_DNODE_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
|
@ -127,7 +127,7 @@ static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) {
|
|||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
if (sver != TSDB_DNODE_VER) {
|
||||
if (sver != TSDB_DNODE_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
mError("failed to decode dnode since %s", terrstr());
|
||||
return NULL;
|
||||
|
@ -150,21 +150,8 @@ static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) {
|
|||
|
||||
static int32_t mndDnodeActionInsert(SSdb *pSdb, SDnodeObj *pDnode) {
|
||||
mTrace("dnode:%d, perform insert action", pDnode->id);
|
||||
|
||||
pDnode->rebootTime = 0;
|
||||
pDnode->lastAccessTime = 0;
|
||||
pDnode->accessTimes = 0;
|
||||
pDnode->numOfMnodes = 0;
|
||||
pDnode->numOfVnodes = 0;
|
||||
pDnode->numOfQnodes = 0;
|
||||
pDnode->numOfSupportMnodes = 0;
|
||||
pDnode->numOfSupportVnodes = 0;
|
||||
pDnode->numOfSupportQnodes = 0;
|
||||
pDnode->numOfCores = 0;
|
||||
pDnode->status = DND_STATUS_OFFLINE;
|
||||
pDnode->offlineReason = DND_REASON_STATUS_NOT_RECEIVED;
|
||||
snprintf(pDnode->ep, TSDB_EP_LEN, "%s:%u", pDnode->fqdn, pDnode->port);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -225,7 +212,7 @@ int32_t mndGetDnodeSize(SMnode *pMnode) {
|
|||
bool mndIsDnodeInReadyStatus(SMnode *pMnode, SDnodeObj *pDnode) {
|
||||
int64_t ms = taosGetTimestampMs();
|
||||
int64_t interval = ABS(pDnode->lastAccessTime - ms);
|
||||
if (interval > 3000 * pMnode->cfg.statusInterval) {
|
||||
if (interval > 3500 * pMnode->cfg.statusInterval) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -267,12 +254,9 @@ static int32_t mndCheckClusterCfgPara(SMnode *pMnode, const SClusterCfg *pCfg) {
|
|||
return DND_REASON_STATUS_INTERVAL_NOT_MATCH;
|
||||
}
|
||||
|
||||
int64_t checkTime = 0;
|
||||
char timestr[32] = "1970-01-01 00:00:00.00";
|
||||
(void)taosParseTime(timestr, &checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
||||
if ((0 != strcasecmp(pCfg->timezone, pMnode->cfg.timezone)) && (checkTime != pCfg->checkTime)) {
|
||||
if ((0 != strcasecmp(pCfg->timezone, pMnode->cfg.timezone)) && (pMnode->checkTime != pCfg->checkTime)) {
|
||||
mError("timezone [%s - %s] [%" PRId64 " - %" PRId64 "] cfg inconsistent", pCfg->timezone, pMnode->cfg.timezone,
|
||||
pCfg->checkTime, checkTime);
|
||||
pCfg->checkTime, pMnode->checkTime);
|
||||
return DND_REASON_TIME_ZONE_NOT_MATCH;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,8 @@
|
|||
#include "mndShow.h"
|
||||
#include "mndTrans.h"
|
||||
|
||||
#define SDB_MNODE_VER 1
|
||||
#define TSDB_MNODE_VER_NUMBER 1
|
||||
#define TSDB_MNODE_RESERVE_SIZE 64
|
||||
|
||||
static int32_t mndCreateDefaultMnode(SMnode *pMnode);
|
||||
static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pMnodeObj);
|
||||
|
@ -60,8 +61,12 @@ int32_t mndInitMnode(SMnode *pMnode) {
|
|||
void mndCleanupMnode(SMnode *pMnode) {}
|
||||
|
||||
static SMnodeObj *mndAcquireMnode(SMnode *pMnode, int32_t mnodeId) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
return sdbAcquire(pSdb, SDB_MNODE, &mnodeId);
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SMnodeObj *pObj = sdbAcquire(pSdb, SDB_MNODE, &mnodeId);
|
||||
if (pObj == NULL) {
|
||||
terrno = TSDB_CODE_MND_MNODE_NOT_EXIST;
|
||||
}
|
||||
return pObj;
|
||||
}
|
||||
|
||||
static void mndReleaseMnode(SMnode *pMnode, SMnodeObj *pMnodeObj) {
|
||||
|
@ -97,13 +102,14 @@ static int32_t mndCreateDefaultMnode(SMnode *pMnode) {
|
|||
}
|
||||
|
||||
static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pMnodeObj) {
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_MNODE, SDB_MNODE_VER, sizeof(SMnodeObj));
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_MNODE, TSDB_MNODE_VER_NUMBER, sizeof(SMnodeObj) + TSDB_MNODE_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
SDB_SET_INT32(pRaw, dataPos, pMnodeObj->id);
|
||||
SDB_SET_INT64(pRaw, dataPos, pMnodeObj->createdTime)
|
||||
SDB_SET_INT64(pRaw, dataPos, pMnodeObj->updateTime)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_MNODE_RESERVE_SIZE)
|
||||
|
||||
return pRaw;
|
||||
}
|
||||
|
@ -112,7 +118,7 @@ static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw) {
|
|||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
if (sver != SDB_MNODE_VER) {
|
||||
if (sver != TSDB_MNODE_VER_NUMBER) {
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
mError("failed to decode mnode since %s", terrstr());
|
||||
return NULL;
|
||||
|
@ -126,6 +132,7 @@ static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_INT32(pRaw, pRow, dataPos, &pMnodeObj->id)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pMnodeObj->createdTime)
|
||||
SDB_GET_INT64(pRaw, pRow, dataPos, &pMnodeObj->updateTime)
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_MNODE_RESERVE_SIZE)
|
||||
|
||||
return pRow;
|
||||
}
|
||||
|
|
|
@ -23,29 +23,25 @@
|
|||
#define QUERY_ID_SIZE 20
|
||||
#define QUERY_OBJ_ID_SIZE 18
|
||||
#define SUBQUERY_INFO_SIZE 6
|
||||
#define QUERY_STREAM_SAVE_SIZE 20
|
||||
#define QUERY_SAVE_SIZE 20
|
||||
|
||||
typedef struct {
|
||||
char user[TSDB_USER_LEN];
|
||||
char app[TSDB_APP_NAME_LEN]; // app name that invokes taosc
|
||||
int32_t pid; // pid of app that invokes taosc
|
||||
int64_t appStartTime; // app start time
|
||||
int32_t id;
|
||||
int8_t killed;
|
||||
int8_t align;
|
||||
uint16_t port;
|
||||
uint32_t ip;
|
||||
int64_t stime;
|
||||
int64_t lastAccess;
|
||||
int32_t queryId;
|
||||
int32_t streamId;
|
||||
int32_t numOfQueries;
|
||||
int32_t numOfStreams;
|
||||
SStreamDesc *pStreams;
|
||||
SQueryDesc *pQueries;
|
||||
int32_t id;
|
||||
char user[TSDB_USER_LEN];
|
||||
char app[TSDB_APP_NAME_LEN]; // app name that invokes taosc
|
||||
int64_t appStartTimeMs; // app start time
|
||||
int32_t pid; // pid of app that invokes taosc
|
||||
uint32_t ip;
|
||||
uint16_t port;
|
||||
int8_t killed;
|
||||
int64_t loginTimeMs;
|
||||
int64_t lastAccessTimeMs;
|
||||
int32_t queryId;
|
||||
int32_t numOfQueries;
|
||||
SQueryDesc *pQueries;
|
||||
} SConnObj;
|
||||
|
||||
static SConnObj *mndCreateConn(SMnode *pMnode, char *user, uint32_t ip, uint16_t port, int32_t pid, const char *app, int64_t startTime);
|
||||
static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid, const char *app, int64_t startTime);
|
||||
static void mndFreeConn(SConnObj *pConn);
|
||||
static SConnObj *mndAcquireConn(SMnode *pMnode, int32_t connId);
|
||||
static void mndReleaseConn(SMnode *pMnode, SConnObj *pConn);
|
||||
|
@ -54,16 +50,12 @@ static void mndCancelGetNextConn(SMnode *pMnode, void *pIter);
|
|||
static int32_t mndProcessHeartBeatMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessConnectMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessKillQueryMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessKillStreamMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessKillConnectionMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndGetConnsMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveConns(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||
static int32_t mndGetQueryMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveQueries(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||
static void mndCancelGetNextQuery(SMnode *pMnode, void *pIter);
|
||||
static int32_t mndGetStreamMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveStreams(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||
static void mndCancelGetNextStream(SMnode *pMnode, void *pIter);
|
||||
|
||||
int32_t mndInitProfile(SMnode *pMnode) {
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
|
@ -79,7 +71,6 @@ int32_t mndInitProfile(SMnode *pMnode) {
|
|||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_HEARTBEAT, mndProcessHeartBeatMsg);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CONNECT, mndProcessConnectMsg);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_KILL_QUERY, mndProcessKillQueryMsg);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_KILL_STREAM, mndProcessKillStreamMsg);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_KILL_CONN, mndProcessKillConnectionMsg);
|
||||
|
||||
mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_CONNS, mndGetConnsMeta);
|
||||
|
@ -88,9 +79,6 @@ int32_t mndInitProfile(SMnode *pMnode) {
|
|||
mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_QUERIES, mndGetQueryMeta);
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_QUERIES, mndRetrieveQueries);
|
||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_QUERIES, mndCancelGetNextQuery);
|
||||
mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_STREAMS, mndGetStreamMeta);
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_STREAMS, mndRetrieveStreams);
|
||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_STREAMS, mndCancelGetNextStream);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -103,46 +91,43 @@ void mndCleanupProfile(SMnode *pMnode) {
|
|||
}
|
||||
}
|
||||
|
||||
static SConnObj *mndCreateConn(SMnode *pMnode, char *user, uint32_t ip, uint16_t port, int32_t pid, const char *app, int64_t startTime) {
|
||||
static SConnObj *mndCreateConn(SMnode *pMnode, SRpcConnInfo *pInfo, int32_t pid, const char *app, int64_t startTime) {
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
|
||||
int32_t connId = atomic_add_fetch_32(&pMgmt->connId, 1);
|
||||
if (connId == 0) atomic_add_fetch_32(&pMgmt->connId, 1);
|
||||
if (startTime == 0) startTime = taosGetTimestampMs();
|
||||
|
||||
SConnObj connObj = {.pid = pid,
|
||||
.appStartTime = startTime,
|
||||
.id = connId,
|
||||
SConnObj connObj = {.id = connId,
|
||||
.appStartTimeMs = startTime,
|
||||
.pid = pid,
|
||||
.ip = pInfo->clientIp,
|
||||
.port = pInfo->clientPort,
|
||||
.killed = 0,
|
||||
.port = port,
|
||||
.ip = ip,
|
||||
.stime = taosGetTimestampMs(),
|
||||
.lastAccess = 0,
|
||||
.loginTimeMs = taosGetTimestampMs(),
|
||||
.lastAccessTimeMs = 0,
|
||||
.queryId = 0,
|
||||
.streamId = 0,
|
||||
.numOfQueries = 0,
|
||||
.numOfStreams = 0,
|
||||
.pStreams = NULL,
|
||||
.pQueries = NULL};
|
||||
|
||||
connObj.lastAccess = connObj.stime;
|
||||
tstrncpy(connObj.user, user, TSDB_USER_LEN);
|
||||
connObj.lastAccessTimeMs = connObj.loginTimeMs;
|
||||
tstrncpy(connObj.user, pInfo->user, TSDB_USER_LEN);
|
||||
tstrncpy(connObj.app, app, TSDB_APP_NAME_LEN);
|
||||
|
||||
int32_t keepTime = pMnode->cfg.shellActivityTimer * 3;
|
||||
SConnObj *pConn = taosCachePut(pMgmt->cache, &connId, sizeof(int32_t), &connObj, sizeof(connObj), keepTime * 1000);
|
||||
if (pConn == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("conn:%d, data:%p failed to put into cache since %s, user:%s", connId, pConn, user, terrstr());
|
||||
mError("conn:%d, data:%p failed to put into cache since %s, user:%s", connId, pConn, pInfo->user, terrstr());
|
||||
return NULL;
|
||||
} else {
|
||||
mTrace("conn:%d, data:%p created, user:%s", pConn->id, pConn, user);
|
||||
mTrace("conn:%d, data:%p created, user:%s", pConn->id, pConn, pInfo->user);
|
||||
return pConn;
|
||||
}
|
||||
}
|
||||
|
||||
static void mndFreeConn(SConnObj *pConn) {
|
||||
tfree(pConn->pQueries);
|
||||
tfree(pConn->pStreams);
|
||||
mTrace("conn:%d, data:%p destroyed", pConn->id, pConn);
|
||||
}
|
||||
|
||||
|
@ -156,7 +141,7 @@ static SConnObj *mndAcquireConn(SMnode *pMnode, int32_t connId) {
|
|||
}
|
||||
|
||||
int32_t keepTime = pMnode->cfg.shellActivityTimer * 3;
|
||||
pConn->lastAccess = keepTime * 1000 + (uint64_t)taosGetTimestampMs();
|
||||
pConn->lastAccessTimeMs = keepTime * 1000 + (uint64_t)taosGetTimestampMs();
|
||||
|
||||
mTrace("conn:%d, data:%p acquired from cache", pConn->id, pConn);
|
||||
return pConn;
|
||||
|
@ -219,7 +204,7 @@ static int32_t mndProcessConnectMsg(SMnodeMsg *pMsg) {
|
|||
mndReleaseDb(pMnode, pDb);
|
||||
}
|
||||
|
||||
SConnObj *pConn = mndCreateConn(pMnode, info.user, info.clientIp, info.clientPort, pReq->pid, pReq->app, pReq->startTime);
|
||||
SConnObj *pConn = mndCreateConn(pMnode, &info, pReq->pid, pReq->app, pReq->startTime);
|
||||
if (pConn == NULL) {
|
||||
mError("user:%s, failed to login from %s while create connection since %s", pMsg->user, ip, terrstr());
|
||||
return -1;
|
||||
|
@ -254,16 +239,14 @@ static int32_t mndProcessConnectMsg(SMnodeMsg *pMsg) {
|
|||
|
||||
static int32_t mndSaveQueryStreamList(SConnObj *pConn, SHeartBeatMsg *pMsg) {
|
||||
pConn->numOfQueries = 0;
|
||||
pConn->numOfStreams = 0;
|
||||
int32_t numOfQueries = htonl(pMsg->numOfQueries);
|
||||
int32_t numOfStreams = htonl(pMsg->numOfStreams);
|
||||
|
||||
if (numOfQueries > 0) {
|
||||
if (pConn->pQueries == NULL) {
|
||||
pConn->pQueries = calloc(sizeof(SQueryDesc), QUERY_STREAM_SAVE_SIZE);
|
||||
pConn->pQueries = calloc(sizeof(SQueryDesc), QUERY_SAVE_SIZE);
|
||||
}
|
||||
|
||||
pConn->numOfQueries = MIN(QUERY_STREAM_SAVE_SIZE, numOfQueries);
|
||||
pConn->numOfQueries = MIN(QUERY_SAVE_SIZE, numOfQueries);
|
||||
|
||||
int32_t saveSize = pConn->numOfQueries * sizeof(SQueryDesc);
|
||||
if (saveSize > 0 && pConn->pQueries != NULL) {
|
||||
|
@ -271,19 +254,6 @@ static int32_t mndSaveQueryStreamList(SConnObj *pConn, SHeartBeatMsg *pMsg) {
|
|||
}
|
||||
}
|
||||
|
||||
if (numOfStreams > 0) {
|
||||
if (pConn->pStreams == NULL) {
|
||||
pConn->pStreams = calloc(sizeof(SStreamDesc), QUERY_STREAM_SAVE_SIZE);
|
||||
}
|
||||
|
||||
pConn->numOfStreams = MIN(QUERY_STREAM_SAVE_SIZE, numOfStreams);
|
||||
|
||||
int32_t saveSize = pConn->numOfStreams * sizeof(SStreamDesc);
|
||||
if (saveSize > 0 && pConn->pStreams != NULL) {
|
||||
memcpy(pConn->pStreams, pMsg->pData + numOfQueries * sizeof(SQueryDesc), saveSize);
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -303,7 +273,7 @@ static int32_t mndProcessHeartBeatMsg(SMnodeMsg *pMsg) {
|
|||
|
||||
SConnObj *pConn = mndAcquireConn(pMnode, pReq->connId);
|
||||
if (pConn == NULL) {
|
||||
pConn = mndCreateConn(pMnode, info.user, info.clientIp, info.clientPort, pReq->pid, pReq->app, 0);
|
||||
pConn = mndCreateConn(pMnode, &info, pReq->pid, pReq->app, 0);
|
||||
if (pConn == NULL) {
|
||||
mError("user:%s, conn:%d is freed and failed to create new conn since %s", pMsg->user, pReq->connId, terrstr());
|
||||
return -1;
|
||||
|
@ -343,11 +313,6 @@ static int32_t mndProcessHeartBeatMsg(SMnodeMsg *pMsg) {
|
|||
pRsp->killConnection = 1;
|
||||
}
|
||||
|
||||
if (pConn->streamId != 0) {
|
||||
pRsp->streamId = htonl(pConn->streamId);
|
||||
pConn->streamId = 0;
|
||||
}
|
||||
|
||||
if (pConn->queryId != 0) {
|
||||
pRsp->queryId = htonl(pConn->queryId);
|
||||
pConn->queryId = 0;
|
||||
|
@ -395,37 +360,6 @@ static int32_t mndProcessKillQueryMsg(SMnodeMsg *pMsg) {
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t mndProcessKillStreamMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pMsg->user);
|
||||
if (pUser == NULL) return 0;
|
||||
if (!pUser->superUser) {
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
}
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
|
||||
SKillStreamMsg *pKill = pMsg->rpcMsg.pCont;
|
||||
int32_t connId = htonl(pKill->connId);
|
||||
int32_t streamId = htonl(pKill->streamId);
|
||||
mDebug("kill stream msg is received, streamId:%d", streamId);
|
||||
|
||||
SConnObj *pConn = taosCacheAcquireByKey(pMgmt->cache, &connId, sizeof(int32_t));
|
||||
if (pConn == NULL) {
|
||||
mError("connId:%d, failed to kill streamId:%d, conn not exist", connId, streamId);
|
||||
terrno = TSDB_CODE_MND_INVALID_CONN_ID;
|
||||
return -1;
|
||||
} else {
|
||||
mInfo("connId:%d, streamId:%d is killed by user:%s", connId, streamId, pMsg->user);
|
||||
pConn->streamId = streamId;
|
||||
taosCacheRelease(pMgmt->cache, (void **)&pConn, false);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mndProcessKillConnectionMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
|
@ -525,6 +459,7 @@ static int32_t mndGetConnsMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
|
||||
pShow->numOfRows = taosHashGetSize(pMgmt->cache->pHashTable);
|
||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||
strcpy(pMeta->tbFname, mndShowStr(pShow->type));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -567,12 +502,12 @@ static int32_t mndRetrieveConns(SMnodeMsg *pMsg, SShowObj *pShow, char *data, in
|
|||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = pConn->stime;
|
||||
*(int64_t *)pWrite = pConn->loginTimeMs;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
if (pConn->lastAccess < pConn->stime) pConn->lastAccess = pConn->stime;
|
||||
*(int64_t *)pWrite = pConn->lastAccess;
|
||||
if (pConn->lastAccessTimeMs < pConn->loginTimeMs) pConn->lastAccessTimeMs = pConn->loginTimeMs;
|
||||
*(int64_t *)pWrite = pConn->lastAccessTimeMs;
|
||||
cols++;
|
||||
|
||||
numOfRows++;
|
||||
|
@ -623,7 +558,7 @@ static int32_t mndGetQueryMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 24;
|
||||
pShow->bytes[cols] = 22 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "qid");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
|
@ -693,6 +628,7 @@ static int32_t mndGetQueryMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
|
|||
|
||||
pShow->numOfRows = 1000000;
|
||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||
strcpy(pMeta->tbFname, mndShowStr(pShow->type));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -790,6 +726,7 @@ static int32_t mndRetrieveQueries(SMnodeMsg *pMsg, SShowObj *pShow, char *data,
|
|||
}
|
||||
}
|
||||
|
||||
mndVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
|
||||
pShow->numOfReads += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
||||
|
@ -798,173 +735,3 @@ static void mndCancelGetNextQuery(SMnode *pMnode, void *pIter) {
|
|||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
taosHashCancelIterate(pMgmt->cache->pHashTable, pIter);
|
||||
}
|
||||
|
||||
static int32_t mndGetStreamMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
|
||||
SUserObj *pUser = mndAcquireUser(pMnode, pMsg->user);
|
||||
if (pUser == NULL) return 0;
|
||||
if (!pUser->superUser) {
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
}
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
|
||||
int32_t cols = 0;
|
||||
SSchema *pSchema = pMeta->pSchema;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "streamId");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "connId");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "user");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "destination");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "ip:port");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "create_time");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "exec");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BIGINT;
|
||||
strcpy(pSchema[cols].name, "time(us)");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "sql");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "cycles");
|
||||
pSchema[cols].bytes = htonl(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htonl(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
for (int32_t i = 1; i < cols; ++i) {
|
||||
pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
|
||||
}
|
||||
|
||||
pShow->numOfRows = 1000000;
|
||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveStreams(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
int32_t numOfRows = 0;
|
||||
SConnObj *pConn = NULL;
|
||||
int32_t cols = 0;
|
||||
char *pWrite;
|
||||
void *pIter;
|
||||
char ipStr[TSDB_IPv4ADDR_LEN + 6];
|
||||
|
||||
while (numOfRows < rows) {
|
||||
pIter = mndGetNextConn(pMnode, pShow->pIter, &pConn);
|
||||
if (pConn == NULL) {
|
||||
pShow->pIter = pIter;
|
||||
break;
|
||||
}
|
||||
|
||||
if (numOfRows + pConn->numOfStreams >= rows) {
|
||||
mndCancelGetNextConn(pMnode, pIter);
|
||||
break;
|
||||
}
|
||||
|
||||
pShow->pIter = pIter;
|
||||
for (int32_t i = 0; i < pConn->numOfStreams; ++i) {
|
||||
SStreamDesc *pDesc = pConn->pStreams + i;
|
||||
cols = 0;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = htobe64(pDesc->streamId);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = htobe64(pConn->id);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pConn->user, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->dstTable, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
snprintf(ipStr, sizeof(ipStr), "%s:%u", taosIpStr(pConn->ip), pConn->port);
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, ipStr, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = htobe64(pDesc->ctime);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = htobe64(pDesc->stime);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = htobe64(pDesc->useconds);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->sql, pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *)pWrite = (int32_t)htobe64(pDesc->num);
|
||||
cols++;
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
}
|
||||
|
||||
pShow->numOfReads += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
static void mndCancelGetNextStream(SMnode *pMnode, void *pIter) {
|
||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||
taosHashCancelIterate(pMgmt->cache->pHashTable, pIter);
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ static int32_t mndProcessShowMsg(SMnodeMsg *pMnodeMsg) {
|
|||
ShowMetaFp metaFp = pMgmt->metaFps[type];
|
||||
if (metaFp == NULL) {
|
||||
terrno = TSDB_CODE_MND_INVALID_MSG_TYPE;
|
||||
mError("failed to process show-meta msg:%s since no message handle", mndShowStr(type));
|
||||
mError("failed to process show-meta msg:%s since %s", mndShowStr(type), terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,9 +21,10 @@
|
|||
#include "mndShow.h"
|
||||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
#include "mndVgroup.h"
|
||||
#include "tname.h"
|
||||
|
||||
#define TSDB_STB_VER_NUM 1
|
||||
#define TSDB_STB_VER_NUMBER 1
|
||||
#define TSDB_STB_RESERVE_SIZE 64
|
||||
|
||||
static SSdbRaw *mndStbActionEncode(SStbObj *pStb);
|
||||
|
@ -70,7 +71,7 @@ void mndCleanupStb(SMnode *pMnode) {}
|
|||
|
||||
static SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
||||
int32_t size = sizeof(SStbObj) + (pStb->numOfColumns + pStb->numOfTags) * sizeof(SSchema) + TSDB_STB_RESERVE_SIZE;
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_STB, TSDB_STB_VER_NUM, size);
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_STB, TSDB_STB_VER_NUMBER, size);
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
|
@ -103,7 +104,7 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
|||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
if (sver != TSDB_STB_VER_NUM) {
|
||||
if (sver != TSDB_STB_VER_NUMBER) {
|
||||
mError("failed to decode stable since %s", terrstr());
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
return NULL;
|
||||
|
@ -176,8 +177,12 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOldStb, SStbObj *pNewStb
|
|||
}
|
||||
|
||||
SStbObj *mndAcquireStb(SMnode *pMnode, char *stbName) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
return sdbAcquire(pSdb, SDB_STB, stbName);
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SStbObj *pStb = sdbAcquire(pSdb, SDB_STB, stbName);
|
||||
if (pStb == NULL) {
|
||||
terrno = TSDB_CODE_MND_STB_NOT_EXIST;
|
||||
}
|
||||
return pStb;
|
||||
}
|
||||
|
||||
void mndReleaseStb(SMnode *pMnode, SStbObj *pStb) {
|
||||
|
@ -195,7 +200,54 @@ static SDbObj *mndAcquireDbByStb(SMnode *pMnode, char *stbName) {
|
|||
return mndAcquireDb(pMnode, db);
|
||||
}
|
||||
|
||||
static int32_t mndCheckStbMsg(SCreateStbMsg *pCreate) {
|
||||
static SCreateStbInternalMsg *mndBuildCreateStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb) {
|
||||
int32_t totalCols = pStb->numOfTags + pStb->numOfColumns;
|
||||
int32_t contLen = totalCols * sizeof(SSchema) + sizeof(SCreateStbInternalMsg);
|
||||
|
||||
SCreateStbInternalMsg *pCreate = calloc(1, contLen);
|
||||
if (pCreate == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pCreate->head.contLen = htonl(contLen);
|
||||
pCreate->head.vgId = htonl(pVgroup->vgId);
|
||||
memcpy(pCreate->name, pStb->name, TSDB_TABLE_FNAME_LEN);
|
||||
pCreate->suid = htobe64(pStb->uid);
|
||||
pCreate->sverson = htonl(pStb->version);
|
||||
pCreate->ttl = 0;
|
||||
pCreate->keep = 0;
|
||||
pCreate->numOfTags = htonl(pStb->numOfTags);
|
||||
pCreate->numOfColumns = htonl(pStb->numOfColumns);
|
||||
|
||||
memcpy(pCreate->pSchema, pStb->pSchema, totalCols * sizeof(SSchema));
|
||||
for (int32_t t = 0; t < totalCols; ++t) {
|
||||
SSchema *pSchema = &pCreate->pSchema[t];
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
pSchema->colId = htonl(pSchema->colId);
|
||||
}
|
||||
|
||||
return pCreate;
|
||||
}
|
||||
|
||||
static SDropStbInternalMsg *mndBuildDropStbMsg(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb) {
|
||||
int32_t contLen = sizeof(SDropStbInternalMsg);
|
||||
|
||||
SDropStbInternalMsg *pDrop = calloc(1, contLen);
|
||||
if (pDrop == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pDrop->head.contLen = htonl(contLen);
|
||||
pDrop->head.vgId = htonl(pVgroup->vgId);
|
||||
memcpy(pDrop->name, pStb->name, TSDB_TABLE_FNAME_LEN);
|
||||
pDrop->suid = htobe64(pStb->uid);
|
||||
|
||||
return pDrop;
|
||||
}
|
||||
|
||||
static int32_t mndCheckCreateStbMsg(SCreateStbMsg *pCreate) {
|
||||
pCreate->numOfColumns = htonl(pCreate->numOfColumns);
|
||||
pCreate->numOfTags = htonl(pCreate->numOfTags);
|
||||
int32_t totalCols = pCreate->numOfColumns + pCreate->numOfTags;
|
||||
|
@ -244,6 +296,103 @@ static int32_t mndCheckStbMsg(SCreateStbMsg *pCreate) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateStbRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
|
||||
SSdbRaw *pRedoRaw = mndStbActionEncode(pStb);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING) != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateStbUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
|
||||
SSdbRaw *pUndoRaw = mndStbActionEncode(pStb);
|
||||
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 mndSetCreateStbCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
|
||||
SSdbRaw *pCommitRaw = mndStbActionEncode(pStb);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SVgObj *pVgroup = NULL;
|
||||
void *pIter = NULL;
|
||||
|
||||
while (1) {
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
if (pVgroup->dbUid != pDb->uid) continue;
|
||||
|
||||
SCreateStbInternalMsg *pMsg = mndBuildCreateStbMsg(pMnode, pVgroup, pStb);
|
||||
if (pMsg == NULL) {
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
action.pCont = pMsg;
|
||||
action.contLen = htonl(pMsg->head.contLen);
|
||||
action.msgType = TSDB_MSG_TYPE_CREATE_STB_IN;
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
return -1;
|
||||
}
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetCreateStbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SVgObj *pVgroup = NULL;
|
||||
void *pIter = NULL;
|
||||
|
||||
while (1) {
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
if (pVgroup->dbUid != pDb->uid) continue;
|
||||
|
||||
SDropStbInternalMsg *pMsg = mndBuildDropStbMsg(pMnode, pVgroup, pStb);
|
||||
if (pMsg == NULL) {
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
action.pCont = pMsg;
|
||||
action.contLen = sizeof(SDropStbInternalMsg);
|
||||
action.msgType = TSDB_MSG_TYPE_DROP_STB_IN;
|
||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||
free(pMsg);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
return -1;
|
||||
}
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateStbMsg *pCreate, SDbObj *pDb) {
|
||||
SStbObj stbObj = {0};
|
||||
tstrncpy(stbObj.name, pCreate->name, TSDB_TABLE_FNAME_LEN);
|
||||
|
@ -265,6 +414,7 @@ static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateStbMsg *pCre
|
|||
}
|
||||
memcpy(stbObj.pSchema, pCreate->pSchema, totalSize);
|
||||
|
||||
int32_t code = 0;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
|
||||
if (pTrans == NULL) {
|
||||
mError("stb:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
|
@ -272,29 +422,30 @@ static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateStbMsg *pCre
|
|||
}
|
||||
mDebug("trans:%d, used to create stb:%s", pTrans->id, pCreate->name);
|
||||
|
||||
SSdbRaw *pRedoRaw = mndStbActionEncode(&stbObj);
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
if (mndSetCreateStbRedoLogs(pMnode, pTrans, pDb, &stbObj) != 0) {
|
||||
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_STB_OVER;
|
||||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING);
|
||||
|
||||
SSdbRaw *pUndoRaw = mndStbActionEncode(&stbObj);
|
||||
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
|
||||
mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
if (mndSetCreateStbUndoLogs(pMnode, pTrans, pDb, &stbObj) != 0) {
|
||||
mError("trans:%d, failed to set undo log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_STB_OVER;
|
||||
}
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
SSdbRaw *pCommitRaw = mndStbActionEncode(&stbObj);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
if (mndSetCreateStbCommitLogs(pMnode, pTrans, pDb, &stbObj) != 0) {
|
||||
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||
goto CREATE_STB_OVER;
|
||||
}
|
||||
|
||||
if (mndSetCreateStbRedoActions(pMnode, pTrans, pDb, &stbObj) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto CREATE_STB_OVER;
|
||||
}
|
||||
|
||||
if (mndSetCreateStbUndoActions(pMnode, pTrans, pDb, &stbObj) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto CREATE_STB_OVER;
|
||||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
|
@ -302,8 +453,11 @@ static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateStbMsg *pCre
|
|||
return -1;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
||||
CREATE_STB_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateStbMsg(SMnodeMsg *pMsg) {
|
||||
|
@ -312,7 +466,7 @@ static int32_t mndProcessCreateStbMsg(SMnodeMsg *pMsg) {
|
|||
|
||||
mDebug("stb:%s, start to create", pCreate->name);
|
||||
|
||||
if (mndCheckStbMsg(pCreate) != 0) {
|
||||
if (mndCheckCreateStbMsg(pCreate) != 0) {
|
||||
mError("stb:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -349,7 +503,10 @@ static int32_t mndProcessCreateStbMsg(SMnodeMsg *pMsg) {
|
|||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateStbInRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
static int32_t mndProcessCreateStbInRsp(SMnodeMsg *pMsg) {
|
||||
mndTransHandleActionRsp(pMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCheckAlterStbMsg(SAlterStbMsg *pAlter) {
|
||||
SSchema *pSchema = &pAlter->schema;
|
||||
|
@ -410,9 +567,44 @@ static int32_t mndProcessAlterStbMsg(SMnodeMsg *pMsg) {
|
|||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndProcessAlterStbInRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
static int32_t mndProcessAlterStbInRsp(SMnodeMsg *pMsg) {
|
||||
mndTransHandleActionRsp(pMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetDropStbRedoLogs(SMnode *pMnode, STrans *pTrans, SStbObj *pStb) {
|
||||
SSdbRaw *pRedoRaw = mndStbActionEncode(pStb);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING) != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetDropStbUndoLogs(SMnode *pMnode, STrans *pTrans, SStbObj *pStb) {
|
||||
SSdbRaw *pUndoRaw = mndStbActionEncode(pStb);
|
||||
if (pUndoRaw == NULL) return -1;
|
||||
if (mndTransAppendUndolog(pTrans, pUndoRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY) != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetDropStbCommitLogs(SMnode *pMnode, STrans *pTrans, SStbObj *pStb) {
|
||||
SSdbRaw *pCommitRaw = mndStbActionEncode(pStb);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndSetDropStbRedoActions(SMnode *pMnode, STrans *pTrans, SStbObj *pStb) { return 0; }
|
||||
|
||||
static int32_t mndSetDropStbUndoActions(SMnode *pMnode, STrans *pTrans, SStbObj *pStb) { return 0; }
|
||||
|
||||
static int32_t mndDropStb(SMnode *pMnode, SMnodeMsg *pMsg, SStbObj *pStb) {
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
|
||||
if (pTrans == NULL) {
|
||||
mError("stb:%s, failed to drop since %s", pStb->name, terrstr());
|
||||
|
@ -420,36 +612,39 @@ static int32_t mndDropStb(SMnode *pMnode, SMnodeMsg *pMsg, SStbObj *pStb) {
|
|||
}
|
||||
mDebug("trans:%d, used to drop stb:%s", pTrans->id, pStb->name);
|
||||
|
||||
SSdbRaw *pRedoRaw = mndStbActionEncode(pStb);
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
if (mndSetDropStbRedoLogs(pMnode, pTrans, pStb) != 0) {
|
||||
mError("trans:%d, failed to set redo log since %s", pTrans->id, terrstr());
|
||||
goto DROP_STB_OVER;
|
||||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPING);
|
||||
|
||||
SSdbRaw *pUndoRaw = mndStbActionEncode(pStb);
|
||||
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
|
||||
mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
if (mndSetDropStbUndoLogs(pMnode, pTrans, pStb) != 0) {
|
||||
mError("trans:%d, failed to set undo log since %s", pTrans->id, terrstr());
|
||||
goto DROP_STB_OVER;
|
||||
}
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_READY);
|
||||
|
||||
SSdbRaw *pCommitRaw = mndStbActionEncode(pStb);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
if (mndSetDropStbCommitLogs(pMnode, pTrans, pStb) != 0) {
|
||||
mError("trans:%d, failed to set commit log since %s", pTrans->id, terrstr());
|
||||
goto DROP_STB_OVER;
|
||||
}
|
||||
|
||||
if (mndSetDropStbRedoActions(pMnode, pTrans, pStb) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto DROP_STB_OVER;
|
||||
}
|
||||
|
||||
if (mndSetDropStbUndoActions(pMnode, pTrans, pStb) != 0) {
|
||||
mError("trans:%d, failed to set redo actions since %s", pTrans->id, terrstr());
|
||||
goto DROP_STB_OVER;
|
||||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
goto DROP_STB_OVER;
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
||||
DROP_STB_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
}
|
||||
|
@ -484,7 +679,10 @@ static int32_t mndProcessDropStbMsg(SMnodeMsg *pMsg) {
|
|||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropStbInRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
static int32_t mndProcessDropStbInRsp(SMnodeMsg *pMsg) {
|
||||
mndTransHandleActionRsp(pMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
|
|
|
@ -17,17 +17,10 @@
|
|||
#include "mndTrans.h"
|
||||
#include "mndSync.h"
|
||||
|
||||
#define TSDB_TRANS_VER 1
|
||||
#define TSDB_TRANS_VER_NUMBER 1
|
||||
#define TSDB_TRN_ARRAY_SIZE 8
|
||||
#define TSDB_TRN_RESERVE_SIZE 64
|
||||
|
||||
typedef struct {
|
||||
SEpSet epSet;
|
||||
int8_t msgType;
|
||||
int32_t contLen;
|
||||
void *pCont;
|
||||
} STransAction;
|
||||
|
||||
static SSdbRaw *mndTransActionEncode(STrans *pTrans);
|
||||
static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans);
|
||||
|
@ -37,11 +30,11 @@ static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans);
|
|||
static void mndTransSetRpcHandle(STrans *pTrans, void *rpcHandle);
|
||||
static void mndTransSendRpcRsp(STrans *pTrans, int32_t code);
|
||||
static int32_t mndTransAppendLog(SArray *pArray, SSdbRaw *pRaw);
|
||||
static int32_t mndTransAppendAction(SArray *pArray, SEpSet *pEpSet, int8_t msgType, int32_t contLen, void *pCont);
|
||||
static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction);
|
||||
static void mndTransDropLogs(SArray *pArray);
|
||||
static void mndTransDropActions(SArray *pArray);
|
||||
static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray);
|
||||
static int32_t mndTransExecuteActions(SMnode *pMnode, SArray *pArray);
|
||||
static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pArray);
|
||||
static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTransExecuteUndoLogs(SMnode *pMnode, STrans *pTrans);
|
||||
static int32_t mndTransExecuteCommitLogs(SMnode *pMnode, STrans *pTrans);
|
||||
|
@ -100,7 +93,7 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
|
|||
rawDataLen += (sizeof(STransAction) + pAction->contLen);
|
||||
}
|
||||
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_TRANS, TSDB_TRANS_VER, rawDataLen);
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_TRANS, TSDB_TRANS_VER_NUMBER, rawDataLen);
|
||||
if (pRaw == NULL) {
|
||||
mError("trans:%d, failed to alloc raw since %s", pTrans->id, terrstr());
|
||||
return NULL;
|
||||
|
@ -167,7 +160,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (sver != TSDB_TRANS_VER) {
|
||||
if (sver != TSDB_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;
|
||||
|
@ -324,8 +317,12 @@ static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOldTrans, STrans *pNewT
|
|||
}
|
||||
|
||||
STrans *mndAcquireTrans(SMnode *pMnode, int32_t transId) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
return sdbAcquire(pSdb, SDB_TRANS, &transId);
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
STrans *pTrans = sdbAcquire(pSdb, SDB_TRANS, &transId);
|
||||
if (pTrans == NULL) {
|
||||
terrno = TSDB_CODE_MND_TRANS_NOT_EXIST;
|
||||
}
|
||||
return pTrans;
|
||||
}
|
||||
|
||||
void mndReleaseTrans(SMnode *pMnode, STrans *pTrans) {
|
||||
|
@ -343,10 +340,8 @@ char *mndTransStageStr(ETrnStage stage) {
|
|||
return "commit";
|
||||
case TRN_STAGE_ROLLBACK:
|
||||
return "rollback";
|
||||
case TRN_STAGE_RETRY:
|
||||
return "retry";
|
||||
case TRN_STAGE_OVER:
|
||||
return "stop";
|
||||
return "over";
|
||||
default:
|
||||
return "undefined";
|
||||
}
|
||||
|
@ -388,7 +383,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, void *rpcHandle) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
mDebug("trans:%d, data:%p is created", pTrans->id, pTrans);
|
||||
mDebug("trans:%d, is created", pTrans->id);
|
||||
return pTrans;
|
||||
}
|
||||
|
||||
|
@ -417,7 +412,7 @@ void mndTransDrop(STrans *pTrans) {
|
|||
mndTransDropActions(pTrans->redoActions);
|
||||
mndTransDropActions(pTrans->undoActions);
|
||||
|
||||
mDebug("trans:%d, data:%p is dropped", pTrans->id, pTrans);
|
||||
// mDebug("trans:%d, is dropped, data:%p", pTrans->id, pTrans);
|
||||
tfree(pTrans);
|
||||
}
|
||||
|
||||
|
@ -459,10 +454,8 @@ int32_t mndTransAppendCommitlog(STrans *pTrans, SSdbRaw *pRaw) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndTransAppendAction(SArray *pArray, SEpSet *pEpSet, int8_t msgType, int32_t contLen, void *pCont) {
|
||||
STransAction action = {.epSet = *pEpSet, .msgType = msgType, .contLen = contLen, .pCont = pCont};
|
||||
|
||||
void *ptr = taosArrayPush(pArray, &action);
|
||||
static int32_t mndTransAppendAction(SArray *pArray, STransAction *pAction) {
|
||||
void *ptr = taosArrayPush(pArray, pAction);
|
||||
if (ptr == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
|
@ -471,15 +464,15 @@ static int32_t mndTransAppendAction(SArray *pArray, SEpSet *pEpSet, int8_t msgTy
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndTransAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, int8_t msgType, int32_t contLen, void *pCont) {
|
||||
int32_t code = mndTransAppendAction(pTrans->redoActions, pEpSet, msgType, contLen, pCont);
|
||||
mTrace("trans:%d, msg:%s len:%d append to redo actions", pTrans->id, taosMsg[msgType], contLen);
|
||||
int32_t mndTransAppendRedoAction(STrans *pTrans, STransAction *pAction) {
|
||||
int32_t code = mndTransAppendAction(pTrans->redoActions, pAction);
|
||||
mTrace("trans:%d, msg:%s append to redo actions, code:0x%x", pTrans->id, taosMsg[pAction->msgType], code);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t mndTransAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, int8_t msgType, int32_t contLen, void *pCont) {
|
||||
int32_t code = mndTransAppendAction(pTrans->undoActions, pEpSet, msgType, contLen, pCont);
|
||||
mTrace("trans:%d, msg:%s len:%d append to undo actions", pTrans->id, taosMsg[msgType], contLen);
|
||||
int32_t mndTransAppendUndoAction(STrans *pTrans, STransAction *pAction) {
|
||||
int32_t code = mndTransAppendAction(pTrans->undoActions, pAction);
|
||||
mTrace("trans:%d, msg:%s append to undo actions, code:0x%x", pTrans->id, taosMsg[pAction->msgType], code);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -493,7 +486,7 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
|
|||
}
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
mTrace("trans:%d, start sync", pTrans->id);
|
||||
mTrace("trans:%d, sync to other nodes", pTrans->id);
|
||||
int32_t code = mndSyncPropose(pMnode, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to sync since %s", pTrans->id, terrstr());
|
||||
|
@ -515,7 +508,6 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
mDebug("trans:%d, prepare finished", pNewTrans->id);
|
||||
pNewTrans->rpcHandle = pTrans->rpcHandle;
|
||||
mndTransExecute(pMnode, pNewTrans);
|
||||
mndReleaseTrans(pMnode, pNewTrans);
|
||||
|
@ -533,7 +525,7 @@ int32_t mndTransCommit(SMnode *pMnode, STrans *pTrans) {
|
|||
sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
if (taosArrayGetSize(pTrans->commitLogs) != 0) {
|
||||
mTrace("trans:%d, start sync", pTrans->id);
|
||||
mTrace("trans:%d, sync to other nodes", pTrans->id);
|
||||
int32_t code = mndSyncPropose(pMnode, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to sync since %s", pTrans->id, terrstr());
|
||||
|
@ -563,7 +555,7 @@ int32_t mndTransRollback(SMnode *pMnode, STrans *pTrans) {
|
|||
}
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
mTrace("trans:%d, start sync", pTrans->id);
|
||||
mTrace("trans:%d, sync to other nodes", pTrans->id);
|
||||
int32_t code = mndSyncPropose(pMnode, pRaw);
|
||||
if (code != 0) {
|
||||
mError("trans:%d, failed to sync since %s", pTrans->id, terrstr());
|
||||
|
@ -596,6 +588,50 @@ void mndTransApply(SMnode *pMnode, SSdbRaw *pRaw, STransMsg *pMsg, int32_t code)
|
|||
// todo
|
||||
}
|
||||
|
||||
void mndTransHandleActionRsp(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
int64_t sig = (int64_t)(pMsg->rpcMsg.ahandle);
|
||||
int32_t transId = (int32_t)(sig >> 32);
|
||||
int32_t action = (int32_t)((sig << 32) >> 32);
|
||||
|
||||
STrans *pTrans = mndAcquireTrans(pMnode, transId);
|
||||
if (pTrans == NULL) {
|
||||
mError("trans:%d, failed to get transId from vnode rsp since %s", transId, terrstr());
|
||||
goto HANDLE_ACTION_RSP_OVER;
|
||||
}
|
||||
|
||||
SArray *pArray = NULL;
|
||||
if (pTrans->stage == TRN_STAGE_EXECUTE) {
|
||||
pArray = pTrans->redoActions;
|
||||
} else if (pTrans->stage == TRN_STAGE_ROLLBACK) {
|
||||
pArray = pTrans->undoActions;
|
||||
} else {
|
||||
}
|
||||
|
||||
if (pArray == NULL) {
|
||||
mError("trans:%d, invalid trans stage:%s", transId, mndTransStageStr(pTrans->stage));
|
||||
goto HANDLE_ACTION_RSP_OVER;
|
||||
}
|
||||
|
||||
int32_t actionNum = taosArrayGetSize(pTrans->redoActions);
|
||||
if (action < 0 || action > actionNum) {
|
||||
mError("trans:%d, invalid action:%d", transId, action);
|
||||
goto HANDLE_ACTION_RSP_OVER;
|
||||
}
|
||||
|
||||
STransAction *pAction = taosArrayGet(pArray, action);
|
||||
if (pAction != NULL) {
|
||||
pAction->msgReceived = 1;
|
||||
pAction->errCode = pMsg->code;
|
||||
}
|
||||
|
||||
mDebug("trans:%d, action:%d response is received, code:0x%x", transId, action, pMsg->code);
|
||||
mndTransExecute(pMnode, pTrans);
|
||||
|
||||
HANDLE_ACTION_RSP_OVER:
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
}
|
||||
|
||||
static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t arraySize = taosArrayGetSize(pArray);
|
||||
|
@ -618,7 +654,7 @@ static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans) {
|
|||
if (code != 0) {
|
||||
mError("trans:%d, failed to execute redo logs since %s", pTrans->id, terrstr())
|
||||
} else {
|
||||
mTrace("trans:%d, execute redo logs finished", pTrans->id)
|
||||
mDebug("trans:%d, execute redo logs finished", pTrans->id)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -632,7 +668,7 @@ static int32_t mndTransExecuteUndoLogs(SMnode *pMnode, STrans *pTrans) {
|
|||
if (code != 0) {
|
||||
mError("trans:%d, failed to execute undo logs since %s", pTrans->id, terrstr())
|
||||
} else {
|
||||
mTrace("trans:%d, execute undo logs finished", pTrans->id)
|
||||
mDebug("trans:%d, execute undo logs finished", pTrans->id)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -646,47 +682,70 @@ static int32_t mndTransExecuteCommitLogs(SMnode *pMnode, STrans *pTrans) {
|
|||
if (code != 0) {
|
||||
mError("trans:%d, failed to execute commit logs since %s", pTrans->id, terrstr())
|
||||
} else {
|
||||
mTrace("trans:%d, execute commit logs finished", pTrans->id)
|
||||
mDebug("trans:%d, execute commit logs finished", pTrans->id)
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndTransExecuteActions(SMnode *pMnode, SArray *pArray) {
|
||||
#if 0
|
||||
int32_t arraySize = taosArrayGetSize(pArray);
|
||||
for (int32_t i = 0; i < arraySize; ++i) {
|
||||
STransAction *pAction = taosArrayGet(pArray, i);
|
||||
static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pArray) {
|
||||
int32_t numOfActions = taosArrayGetSize(pArray);
|
||||
if (numOfActions == 0) return 0;
|
||||
|
||||
SRpcMsg rpcMsg = {.msgType = pAction->msgType, .contLen = pAction->contLen};
|
||||
for (int32_t action = 0; action < numOfActions; ++action) {
|
||||
STransAction *pAction = taosArrayGet(pArray, action);
|
||||
if (pAction == NULL) continue;
|
||||
if (pAction->msgSent) continue;
|
||||
|
||||
int64_t signature = pTrans->id;
|
||||
signature = (signature << 32);
|
||||
signature += action;
|
||||
|
||||
SRpcMsg rpcMsg = {.msgType = pAction->msgType, .contLen = pAction->contLen, .ahandle = (void *)signature};
|
||||
rpcMsg.pCont = rpcMallocCont(pAction->contLen);
|
||||
if (rpcMsg.pCont == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
int32_t numOfReceivedMsgs = 0;
|
||||
int32_t errorCode = 0;
|
||||
for (int32_t action = 0; action < numOfActions; ++action) {
|
||||
STransAction *pAction = taosArrayGet(pArray, action);
|
||||
if (pAction == NULL) continue;
|
||||
if (pAction->msgSent && pAction->msgReceived) {
|
||||
numOfReceivedMsgs++;
|
||||
if (pAction->errCode != 0) {
|
||||
errorCode = pAction->errCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (numOfReceivedMsgs == numOfActions) {
|
||||
mDebug("trans:%d, all %d actions executed, code:0x%x", pTrans->id, numOfActions, errorCode);
|
||||
terrno = errorCode;
|
||||
return errorCode;
|
||||
} else {
|
||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t mndTransExecuteRedoActions(SMnode *pMnode, STrans *pTrans) {
|
||||
if (taosArrayGetSize(pTrans->redoActions) <= 0) return 0;
|
||||
|
||||
mTrace("trans:%d, start to execute redo actions", pTrans->id);
|
||||
return mndTransExecuteActions(pMnode, pTrans->redoActions);
|
||||
return mndTransExecuteActions(pMnode, pTrans, pTrans->redoActions);
|
||||
}
|
||||
|
||||
static int32_t mndTransExecuteUndoActions(SMnode *pMnode, STrans *pTrans) {
|
||||
if (taosArrayGetSize(pTrans->undoActions) <= 0) return 0;
|
||||
|
||||
mTrace("trans:%d, start to execute undo actions", pTrans->id);
|
||||
return mndTransExecuteActions(pMnode, pTrans->undoActions);
|
||||
return mndTransExecuteActions(pMnode, pTrans, pTrans->undoActions);
|
||||
}
|
||||
|
||||
static int32_t mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans) {
|
||||
|
@ -694,7 +753,7 @@ static int32_t mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans) {
|
|||
|
||||
if (code == 0) {
|
||||
pTrans->stage = TRN_STAGE_EXECUTE;
|
||||
mTrace("trans:%d, stage from prepare to execute", pTrans->id);
|
||||
mDebug("trans:%d, stage from prepare to execute", pTrans->id);
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
mError("trans:%d, stage from prepare to rollback since %s", pTrans->id, terrstr());
|
||||
|
@ -708,17 +767,17 @@ static int32_t mndTransPerformExecuteStage(SMnode *pMnode, STrans *pTrans) {
|
|||
|
||||
if (code == 0) {
|
||||
pTrans->stage = TRN_STAGE_COMMIT;
|
||||
mTrace("trans:%d, stage from execute to commit", pTrans->id);
|
||||
mDebug("trans:%d, stage from execute to commit", pTrans->id);
|
||||
} else if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) {
|
||||
mTrace("trans:%d, stage keep on execute since %s", pTrans->id, terrstr(code));
|
||||
mDebug("trans:%d, stage keep on execute since %s", pTrans->id, tstrerror(code));
|
||||
return code;
|
||||
} else {
|
||||
if (pTrans->policy == TRN_POLICY_ROLLBACK) {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
mError("trans:%d, stage from execute to rollback since %s", pTrans->id, terrstr());
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_RETRY;
|
||||
mError("trans:%d, stage from execute to retry since %s", pTrans->id, terrstr());
|
||||
pTrans->stage = TRN_STAGE_EXECUTE;
|
||||
mError("trans:%d, stage keep on execute since %s", pTrans->id, terrstr());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -726,29 +785,16 @@ static int32_t mndTransPerformExecuteStage(SMnode *pMnode, STrans *pTrans) {
|
|||
}
|
||||
|
||||
static int32_t mndTransPerformCommitStage(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = mndTransExecuteCommitLogs(pMnode, pTrans);
|
||||
|
||||
if (code == 0) {
|
||||
pTrans->stage = TRN_STAGE_OVER;
|
||||
mTrace("trans:%d, commit stage finished", pTrans->id);
|
||||
} else {
|
||||
if (pTrans->policy == TRN_POLICY_ROLLBACK) {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
mError("trans:%d, stage from commit to rollback since %s", pTrans->id, terrstr());
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_RETRY;
|
||||
mError("trans:%d, stage from commit to retry since %s", pTrans->id, terrstr());
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
mndTransExecuteCommitLogs(pMnode, pTrans);
|
||||
pTrans->stage = TRN_STAGE_OVER;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = mndTransExecuteUndoActions(pMnode, pTrans);
|
||||
|
||||
if (code == 0) {
|
||||
mTrace("trans:%d, rollbacked", pTrans->id);
|
||||
mDebug("trans:%d, rollbacked", pTrans->id);
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_ROLLBACK;
|
||||
mError("trans:%d, stage keep on rollback since %s", pTrans->id, terrstr());
|
||||
|
@ -757,20 +803,6 @@ static int32_t mndTransPerformRollbackStage(SMnode *pMnode, STrans *pTrans) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndTransPerformRetryStage(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = mndTransExecuteRedoActions(pMnode, pTrans);
|
||||
|
||||
if (code == 0) {
|
||||
pTrans->stage = TRN_STAGE_COMMIT;
|
||||
mTrace("trans:%d, stage from retry to commit", pTrans->id);
|
||||
} else {
|
||||
pTrans->stage = TRN_STAGE_RETRY;
|
||||
mError("trans:%d, stage keep on retry since %s", pTrans->id, terrstr());
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static void mndTransExecute(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t code = 0;
|
||||
|
||||
|
@ -785,7 +817,7 @@ static void mndTransExecute(SMnode *pMnode, STrans *pTrans) {
|
|||
case TRN_STAGE_COMMIT:
|
||||
code = mndTransCommit(pMnode, pTrans);
|
||||
if (code == 0) {
|
||||
code = mndTransPerformCommitStage(pMnode, pTrans);
|
||||
mndTransPerformCommitStage(pMnode, pTrans);
|
||||
}
|
||||
break;
|
||||
case TRN_STAGE_ROLLBACK:
|
||||
|
@ -794,9 +826,6 @@ static void mndTransExecute(SMnode *pMnode, STrans *pTrans) {
|
|||
code = mndTransRollback(pMnode, pTrans);
|
||||
}
|
||||
break;
|
||||
case TRN_STAGE_RETRY:
|
||||
code = mndTransPerformRetryStage(pMnode, pTrans);
|
||||
break;
|
||||
default:
|
||||
mndTransSendRpcRsp(pTrans, 0);
|
||||
return;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "mndTrans.h"
|
||||
#include "tkey.h"
|
||||
|
||||
#define TSDB_USER_VER 1
|
||||
#define TSDB_USER_VER_NUMBER 1
|
||||
#define TSDB_USER_RESERVE_SIZE 64
|
||||
|
||||
static int32_t mndCreateDefaultUsers(SMnode *pMnode);
|
||||
|
@ -94,7 +94,7 @@ static int32_t mndCreateDefaultUsers(SMnode *pMnode) {
|
|||
}
|
||||
|
||||
static SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, TSDB_USER_VER, sizeof(SUserObj) + TSDB_USER_RESERVE_SIZE);
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, TSDB_USER_VER_NUMBER, sizeof(SUserObj) + TSDB_USER_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
|
@ -114,7 +114,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
|
|||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
if (sver != TSDB_USER_VER) {
|
||||
if (sver != TSDB_USER_VER_NUMBER) {
|
||||
mError("failed to decode user since %s", terrstr());
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
return NULL;
|
||||
|
@ -175,8 +175,12 @@ static int32_t mndUserActionUpdate(SSdb *pSdb, SUserObj *pOldUser, SUserObj *pNe
|
|||
}
|
||||
|
||||
SUserObj *mndAcquireUser(SMnode *pMnode, char *userName) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
return sdbAcquire(pSdb, SDB_USER, userName);
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SUserObj *pUser = sdbAcquire(pSdb, SDB_USER, userName);
|
||||
if (pUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||
}
|
||||
return pUser;
|
||||
}
|
||||
|
||||
void mndReleaseUser(SMnode *pMnode, SUserObj *pUser) {
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "mndShow.h"
|
||||
#include "mndTrans.h"
|
||||
|
||||
#define TSDB_VGROUP_VER_NUM 1
|
||||
#define TSDB_VGROUP_VER_NUMBER 1
|
||||
#define TSDB_VGROUP_RESERVE_SIZE 64
|
||||
|
||||
static SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw);
|
||||
|
@ -70,7 +70,7 @@ int32_t mndInitVgroup(SMnode *pMnode) {
|
|||
void mndCleanupVgroup(SMnode *pMnode) {}
|
||||
|
||||
SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) {
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_VGROUP, TSDB_VGROUP_VER_NUM, sizeof(SVgObj) + TSDB_VGROUP_RESERVE_SIZE);
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_VGROUP, TSDB_VGROUP_VER_NUMBER, sizeof(SVgObj) + TSDB_VGROUP_RESERVE_SIZE);
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
|
@ -98,7 +98,7 @@ SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
|
|||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
if (sver != TSDB_VGROUP_VER_NUM) {
|
||||
if (sver != TSDB_VGROUP_VER_NUMBER) {
|
||||
mError("failed to decode vgroup since %s", terrstr());
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
return NULL;
|
||||
|
@ -142,14 +142,20 @@ static int32_t mndVgroupActionUpdate(SSdb *pSdb, SVgObj *pOldVgroup, SVgObj *pNe
|
|||
mTrace("vgId:%d, perform update action", pOldVgroup->vgId);
|
||||
pOldVgroup->updateTime = pNewVgroup->updateTime;
|
||||
pOldVgroup->version = pNewVgroup->version;
|
||||
pOldVgroup->hashBegin = pNewVgroup->hashBegin;
|
||||
pOldVgroup->hashEnd = pNewVgroup->hashEnd;
|
||||
pOldVgroup->replica = pNewVgroup->replica;
|
||||
memcpy(pOldVgroup->vnodeGid, pNewVgroup->vnodeGid, TSDB_MAX_REPLICA * sizeof(SVnodeGid));
|
||||
return 0;
|
||||
}
|
||||
|
||||
SVgObj *mndAcquireVgroup(SMnode *pMnode, int32_t vgId) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
return sdbAcquire(pSdb, SDB_VGROUP, &vgId);
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SVgObj *pVgroup = sdbAcquire(pSdb, SDB_VGROUP, &vgId);
|
||||
if (pVgroup == NULL) {
|
||||
terrno = TSDB_CODE_MND_VGROUP_NOT_EXIST;
|
||||
}
|
||||
return pVgroup;
|
||||
}
|
||||
|
||||
void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup) {
|
||||
|
@ -158,16 +164,17 @@ void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup) {
|
|||
}
|
||||
|
||||
SCreateVnodeMsg *mndBuildCreateVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup) {
|
||||
SCreateVnodeMsg *pCreate = malloc(sizeof(SCreateVnodeMsg));
|
||||
SCreateVnodeMsg *pCreate = calloc(1, sizeof(SCreateVnodeMsg));
|
||||
if (pCreate == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pCreate->dnodeId = htonl(pDnode->id);
|
||||
pCreate->vgId = htonl(pVgroup->vgId);
|
||||
pCreate->dnodeId = htonl(pDnode->id);
|
||||
memcpy(pCreate->db, pDb->name, TSDB_FULL_DB_NAME_LEN);
|
||||
pCreate->dbUid = htobe64(pDb->uid);
|
||||
pCreate->vgVersion = htonl(pVgroup->version);
|
||||
pCreate->cacheBlockSize = htonl(pDb->cfg.cacheBlockSize);
|
||||
pCreate->totalBlocks = htonl(pDb->cfg.totalBlocks);
|
||||
pCreate->daysPerFile = htonl(pDb->cfg.daysPerFile);
|
||||
|
@ -193,7 +200,6 @@ SCreateVnodeMsg *mndBuildCreateVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbOb
|
|||
SDnodeObj *pVgidDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pVgidDnode == NULL) {
|
||||
free(pCreate);
|
||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -217,7 +223,7 @@ SCreateVnodeMsg *mndBuildCreateVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbOb
|
|||
}
|
||||
|
||||
SDropVnodeMsg *mndBuildDropVnodeMsg(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup) {
|
||||
SDropVnodeMsg *pDrop = malloc(sizeof(SDropVnodeMsg));
|
||||
SDropVnodeMsg *pDrop = calloc(1, sizeof(SDropVnodeMsg));
|
||||
if (pDrop == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
|
@ -269,7 +275,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t alloceVgroups = 0;
|
||||
int32_t allocedVgroups = 0;
|
||||
int32_t maxVgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP);
|
||||
uint32_t hashMin = 0;
|
||||
uint32_t hashMax = UINT32_MAX;
|
||||
|
@ -281,7 +287,6 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
|
|||
pVgroup->createdTime = taosGetTimestampMs();
|
||||
pVgroup->updateTime = pVgroups->createdTime;
|
||||
pVgroup->version = 1;
|
||||
pVgroup->dbUid = pDb->uid;
|
||||
pVgroup->hashBegin = hashMin + hashInterval * v;
|
||||
if (v == pDb->cfg.numOfVgroups - 1) {
|
||||
pVgroup->hashEnd = hashMax;
|
||||
|
@ -290,6 +295,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
|
|||
}
|
||||
|
||||
memcpy(pVgroup->dbName, pDb->name, TSDB_FULL_DB_NAME_LEN);
|
||||
pVgroup->dbUid = pDb->uid;
|
||||
pVgroup->replica = pDb->cfg.replications;
|
||||
|
||||
if (mndGetAvailableDnode(pMnode, pVgroup) != 0) {
|
||||
|
@ -298,22 +304,46 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
alloceVgroups++;
|
||||
allocedVgroups++;
|
||||
}
|
||||
|
||||
*ppVgroups = pVgroups;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
SEpSet mndGetVgroupEpset(SMnode *pMnode, SVgObj *pVgroup) {
|
||||
SEpSet epset = {0};
|
||||
|
||||
for (int32_t v = 0; v < pVgroup->replica; ++v) {
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[v];
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) continue;
|
||||
|
||||
if (pVgid->role == TAOS_SYNC_STATE_LEADER) {
|
||||
epset.inUse = epset.numOfEps;
|
||||
}
|
||||
|
||||
epset.port[epset.numOfEps] = pDnode->port;
|
||||
memcpy(&epset.fqdn[epset.numOfEps], pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
epset.numOfEps++;
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
}
|
||||
|
||||
return epset;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateVnodeRsp(SMnodeMsg *pMsg) {
|
||||
mndTransHandleActionRsp(pMsg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessAlterVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
static int32_t mndProcessDropVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
static int32_t mndProcessSyncVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
static int32_t mndProcessCompactVnodeRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
|
||||
static int32_t mndGetVgroupMaxReplica(SMnode *pMnode, char *dbName, int8_t *pReplica, int32_t *pNumOfVgroups) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, dbName);
|
||||
if (pDb == NULL) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||
|
@ -329,7 +359,7 @@ static int32_t mndGetVgroupMaxReplica(SMnode *pMnode, char *dbName, int8_t *pRep
|
|||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
if (strcmp(pVgroup->dbName, dbName) == 0) {
|
||||
if (pVgroup->dbUid == pDb->uid) {
|
||||
replica = MAX(replica, pVgroup->replica);
|
||||
numOfVgroups++;
|
||||
}
|
||||
|
@ -441,11 +471,25 @@ static void mndCancelGetNextVgroup(SMnode *pMnode, void *pIter) {
|
|||
}
|
||||
|
||||
static int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId) {
|
||||
if (dnodeId == 0) {
|
||||
return 0;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfVnodes = 0;
|
||||
void *pIter = NULL;
|
||||
|
||||
while (1) {
|
||||
SVgObj *pVgroup = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
for (int32_t v = 0; v < pVgroup->replica; ++v) {
|
||||
if (pVgroup->vnodeGid[v].dnodeId == dnodeId) {
|
||||
numOfVnodes++;
|
||||
}
|
||||
}
|
||||
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return numOfVnodes;
|
||||
}
|
||||
|
||||
static int32_t mndGetVnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
|
|
|
@ -225,7 +225,7 @@ static int32_t mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) {
|
|||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
|
||||
mDebug("start to open mnode in %s", path);
|
||||
|
@ -237,6 +237,9 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char timestr[24] = "1970-01-01 00:00:00.00";
|
||||
(void)taosParseTime(timestr, &pMnode->checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
||||
|
||||
pMnode->pSteps = taosArrayInit(24, sizeof(SMnodeStep));
|
||||
if (pMnode->pSteps == NULL) {
|
||||
free(pMnode);
|
||||
|
|
|
@ -240,6 +240,8 @@ void sdbRelease(SSdb *pSdb, void *pObj) {
|
|||
}
|
||||
|
||||
void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) {
|
||||
*ppObj = NULL;
|
||||
|
||||
SHashObj *hash = sdbGetHash(pSdb, type);
|
||||
if (hash == NULL) return NULL;
|
||||
|
||||
|
|
|
@ -27,12 +27,12 @@ SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) {
|
|||
pRaw->sver = sver;
|
||||
pRaw->dataLen = dataLen;
|
||||
|
||||
mTrace("raw:%p, is created, len:%d", pRaw, dataLen);
|
||||
// mTrace("raw:%p, is created, len:%d", pRaw, dataLen);
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
void sdbFreeRaw(SSdbRaw *pRaw) {
|
||||
mTrace("raw:%p, is freed", pRaw);
|
||||
// mTrace("raw:%p, is freed", pRaw);
|
||||
free(pRaw);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,5 +19,5 @@ target_link_libraries(
|
|||
|
||||
# test
|
||||
if(${BUILD_TEST})
|
||||
#add_subdirectory(test)
|
||||
add_subdirectory(test)
|
||||
endif(${BUILD_TEST})
|
|
@ -71,6 +71,7 @@ struct SVnode {
|
|||
SWal* pWal;
|
||||
SVnodeSync* pSync;
|
||||
SVnodeFS* pFs;
|
||||
tsem_t canCommit;
|
||||
};
|
||||
|
||||
int vnodeScheduleTask(SVnodeTask* task);
|
||||
|
|
|
@ -38,9 +38,10 @@ int vnodeCommit(void *arg) {
|
|||
|
||||
metaCommit(pVnode->pMeta);
|
||||
tqCommit(pVnode->pTq);
|
||||
tsdbCommit(pVnode->pTq);
|
||||
tsdbCommit(pVnode->pTsdb);
|
||||
|
||||
vnodeBufPoolRecycle(pVnode);
|
||||
tsem_post(&(pVnode->canCommit));
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -15,53 +15,31 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "vnodeInt.h"
|
||||
#include "tqueue.h"
|
||||
|
||||
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg) { return 0; }
|
||||
SVnode *vnodeCreate(int32_t vgId, const char *path, const SVnodeCfg *pCfg) { return NULL; }
|
||||
void vnodeDrop(SVnode *pVnode) {}
|
||||
|
||||
int32_t vnodeCompact(SVnode *pVnode) { return 0; }
|
||||
|
||||
int32_t vnodeSync(SVnode *pVnode) { return 0; }
|
||||
|
||||
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) { return 0; }
|
||||
|
||||
SVnodeMsg *vnodeInitMsg(int32_t msgNum) {
|
||||
SVnodeMsg *pMsg = taosAllocateQitem(msgNum * sizeof(SRpcMsg *) + sizeof(SVnodeMsg));
|
||||
if (pMsg == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
} else {
|
||||
pMsg->allocNum = msgNum;
|
||||
return pMsg;
|
||||
}
|
||||
int vnodeProcessQueryReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||
vInfo("query message is processed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t vnodeAppendMsg(SVnodeMsg *pMsg, SRpcMsg *pRpcMsg) {
|
||||
if (pMsg->curNum >= pMsg->allocNum) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pMsg->rpcMsg[pMsg->curNum++] = *pRpcMsg;
|
||||
int vnodeProcessFetchReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||
vInfo("fetch message is processed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vnodeCleanupMsg(SVnodeMsg *pMsg) {
|
||||
for (int32_t i = 0; i < pMsg->curNum; ++i) {
|
||||
rpcFreeCont(pMsg->rpcMsg[i].pCont);
|
||||
}
|
||||
taosFreeQitem(pMsg);
|
||||
int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||
vInfo("sync message is processed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vnodeProcessMsg(SVnode *pVnode, SVnodeMsg *pMsg, EVnMsgType msgType) {
|
||||
switch (msgType) {
|
||||
case VN_MSG_TYPE_WRITE:
|
||||
break;
|
||||
case VN_MSG_TYPE_APPLY:
|
||||
break;
|
||||
case VN_MSG_TYPE_SYNC:
|
||||
break;
|
||||
case VN_MSG_TYPE_QUERY:
|
||||
break;
|
||||
case VN_MSG_TYPE_FETCH:
|
||||
break;
|
||||
}
|
||||
}
|
||||
int vnodeProcessConsumeReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||
vInfo("consume message is processed");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -74,11 +74,14 @@ static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg) {
|
|||
pVnode->path = strdup(path);
|
||||
vnodeOptionsCopy(&(pVnode->config), pVnodeCfg);
|
||||
|
||||
tsem_init(&(pVnode->canCommit), 0, 1);
|
||||
|
||||
return pVnode;
|
||||
}
|
||||
|
||||
static void vnodeFree(SVnode *pVnode) {
|
||||
if (pVnode) {
|
||||
tsem_destroy(&(pVnode->canCommit));
|
||||
tfree(pVnode->path);
|
||||
free(pVnode);
|
||||
}
|
||||
|
|
|
@ -27,14 +27,14 @@ int vnodeProcessNoWalWMsgs(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
|
||||
SRpcMsg *pMsg;
|
||||
SRpcMsg * pMsg;
|
||||
SVnodeReq *pVnodeReq;
|
||||
|
||||
for (int i = 0; i < taosArrayGetSize(pMsgs); i++) {
|
||||
pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i);
|
||||
|
||||
// ser request version
|
||||
void *pBuf = pMsg->pCont;
|
||||
void * pBuf = pMsg->pCont;
|
||||
int64_t ver = pVnode->state.processed++;
|
||||
taosEncodeFixedU64(&pBuf, ver);
|
||||
|
||||
|
@ -45,68 +45,63 @@ int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
|
|||
|
||||
walFsync(pVnode->pWal, false);
|
||||
|
||||
// Apply each request now
|
||||
for (int i = 0; i < taosArrayGetSize(pMsgs); i++) {
|
||||
pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i);
|
||||
SVnodeReq vReq;
|
||||
|
||||
// Apply the request
|
||||
{
|
||||
void *ptr = vnodeMalloc(pVnode, pMsg->contLen);
|
||||
if (ptr == NULL) {
|
||||
// TODO: handle error
|
||||
}
|
||||
|
||||
// TODO: copy here need to be extended
|
||||
memcpy(ptr, pMsg->pCont, pMsg->contLen);
|
||||
|
||||
// todo: change the interface here
|
||||
uint64_t ver;
|
||||
taosDecodeFixedU64(pMsg->pCont, &ver);
|
||||
if (tqPushMsg(pVnode->pTq, ptr, ver) < 0) {
|
||||
// TODO: handle error
|
||||
}
|
||||
|
||||
vnodeParseReq(pMsg->pCont, &vReq, pMsg->msgType);
|
||||
|
||||
switch (pMsg->msgType) {
|
||||
case TSDB_MSG_TYPE_CREATE_TABLE:
|
||||
if (metaCreateTable(pVnode->pMeta, &(vReq.ctReq)) < 0) {
|
||||
// TODO: handle error
|
||||
}
|
||||
|
||||
// TODO: maybe need to clear the requst struct
|
||||
break;
|
||||
case TSDB_MSG_TYPE_DROP_TABLE:
|
||||
if (metaDropTable(pVnode->pMeta, vReq.dtReq.uid) < 0) {
|
||||
// TODO: handle error
|
||||
}
|
||||
break;
|
||||
case TSDB_MSG_TYPE_SUBMIT:
|
||||
if (tsdbInsertData(pVnode->pTsdb, (SSubmitMsg *)ptr) < 0) {
|
||||
// TODO: handle error
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pVnode->state.applied = ver;
|
||||
}
|
||||
|
||||
// Check if it needs to commit
|
||||
if (vnodeShouldCommit(pVnode)) {
|
||||
if (vnodeAsyncCommit(pVnode) < 0) {
|
||||
// TODO: handle error
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: Integrate RAFT module here
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||
// TODO
|
||||
SVnodeReq vReq;
|
||||
void * ptr = vnodeMalloc(pVnode, pMsg->contLen);
|
||||
if (ptr == NULL) {
|
||||
// TODO: handle error
|
||||
}
|
||||
|
||||
// TODO: copy here need to be extended
|
||||
memcpy(ptr, pMsg->pCont, pMsg->contLen);
|
||||
|
||||
// todo: change the interface here
|
||||
uint64_t ver;
|
||||
taosDecodeFixedU64(pMsg->pCont, &ver);
|
||||
if (tqPushMsg(pVnode->pTq, ptr, ver) < 0) {
|
||||
// TODO: handle error
|
||||
}
|
||||
|
||||
vnodeParseReq(pMsg->pCont, &vReq, pMsg->msgType);
|
||||
|
||||
switch (pMsg->msgType) {
|
||||
case TSDB_MSG_TYPE_CREATE_STB_IN:
|
||||
case TSDB_MSG_TYPE_CREATE_TABLE:
|
||||
if (metaCreateTable(pVnode->pMeta, &(vReq.ctReq)) < 0) {
|
||||
// TODO: handle error
|
||||
}
|
||||
|
||||
// TODO: maybe need to clear the requst struct
|
||||
break;
|
||||
case TSDB_MSG_TYPE_DROP_STB_IN:
|
||||
case TSDB_MSG_TYPE_DROP_TABLE:
|
||||
if (metaDropTable(pVnode->pMeta, vReq.dtReq.uid) < 0) {
|
||||
// TODO: handle error
|
||||
}
|
||||
break;
|
||||
case TSDB_MSG_TYPE_SUBMIT:
|
||||
if (tsdbInsertData(pVnode->pTsdb, (SSubmitMsg *)ptr) < 0) {
|
||||
// TODO: handle error
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
pVnode->state.applied = ver;
|
||||
|
||||
// Check if it needs to commit
|
||||
if (vnodeShouldCommit(pVnode)) {
|
||||
tsem_wait(&(pVnode->canCommit));
|
||||
if (vnodeAsyncCommit(pVnode) < 0) {
|
||||
// TODO: handle error
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,8 @@ static void vtBuildCreateStbReq(tb_uid_t suid, char *tbname, SRpcMsg **ppMsg) {
|
|||
pSchema = vtCreateBasicSchema();
|
||||
pTagSchema = vtCreateBasicTagSchema();
|
||||
|
||||
SVnodeReq vCreateSTbReq = VNODE_INIT_CREATE_STB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema);
|
||||
SVnodeReq vCreateSTbReq;
|
||||
vnodeSetCreateStbReq(&vCreateSTbReq, tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema);
|
||||
|
||||
zs = vnodeBuildReq(NULL, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
|
||||
pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + zs);
|
||||
|
@ -104,7 +105,8 @@ static void vtBuildCreateCtbReq(tb_uid_t suid, char *tbname, SRpcMsg **ppMsg) {
|
|||
int tz;
|
||||
SKVRow pTag = vtCreateBasicTag();
|
||||
|
||||
SVnodeReq vCreateCTbReq = VNODE_INIT_CREATE_CTB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pTag);
|
||||
SVnodeReq vCreateCTbReq;
|
||||
vnodeSetCreateCtbReq(&vCreateCTbReq, tbname, UINT32_MAX, UINT32_MAX, suid, pTag);
|
||||
|
||||
tz = vnodeBuildReq(NULL, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
|
||||
pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + tz);
|
||||
|
@ -166,6 +168,21 @@ static void vtClearMsgBatch(SArray *pMsgArr) {
|
|||
taosArrayClear(pMsgArr);
|
||||
}
|
||||
|
||||
static void vtProcessAndApplyReqs(SVnode *pVnode, SArray *pMsgArr) {
|
||||
int rcode;
|
||||
SRpcMsg *pReq;
|
||||
SRpcMsg *pRsp;
|
||||
|
||||
rcode = vnodeProcessWMsgs(pVnode, pMsgArr);
|
||||
GTEST_ASSERT_EQ(rcode, 0);
|
||||
|
||||
for (size_t i = 0; i < taosArrayGetSize(pMsgArr); i++) {
|
||||
pReq = *(SRpcMsg **)taosArrayGet(pMsgArr, i);
|
||||
rcode = vnodeApplyWMsg(pVnode, pReq, NULL);
|
||||
GTEST_ASSERT_EQ(rcode, 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(vnodeApiTest, vnode_simple_create_table_test) {
|
||||
tb_uid_t suid = 1638166374163;
|
||||
SRpcMsg *pMsg;
|
||||
|
@ -189,8 +206,7 @@ TEST(vnodeApiTest, vnode_simple_create_table_test) {
|
|||
sprintf(tbname, "st");
|
||||
vtBuildCreateStbReq(suid, tbname, &pMsg);
|
||||
taosArrayPush(pMsgArr, &pMsg);
|
||||
rcode = vnodeProcessWMsgs(pVnode, pMsgArr);
|
||||
ASSERT_EQ(rcode, 0);
|
||||
vtProcessAndApplyReqs(pVnode, pMsgArr);
|
||||
vtClearMsgBatch(pMsgArr);
|
||||
|
||||
// CREATE A LOT OF CHILD TABLES
|
||||
|
@ -203,8 +219,7 @@ TEST(vnodeApiTest, vnode_simple_create_table_test) {
|
|||
}
|
||||
|
||||
// Process request batch
|
||||
rcode = vnodeProcessWMsgs(pVnode, pMsgArr);
|
||||
ASSERT_EQ(rcode, 0);
|
||||
vtProcessAndApplyReqs(pVnode, pMsgArr);
|
||||
|
||||
// Clear request batch
|
||||
vtClearMsgBatch(pMsgArr);
|
||||
|
@ -242,16 +257,14 @@ TEST(vnodeApiTest, vnode_simple_insert_test) {
|
|||
sprintf(tbname, "st");
|
||||
vtBuildCreateStbReq(suid, tbname, &pMsg);
|
||||
taosArrayPush(pMsgArr, &pMsg);
|
||||
rcode = vnodeProcessWMsgs(pVnode, pMsgArr);
|
||||
GTEST_ASSERT_EQ(rcode, 0);
|
||||
vtProcessAndApplyReqs(pVnode, pMsgArr);
|
||||
vtClearMsgBatch(pMsgArr);
|
||||
|
||||
// 2. CREATE A CHILD TABLE
|
||||
sprintf(tbname, "t0");
|
||||
vtBuildCreateCtbReq(suid, tbname, &pMsg);
|
||||
taosArrayPush(pMsgArr, &pMsg);
|
||||
rcode = vnodeProcessWMsgs(pVnode, pMsgArr);
|
||||
GTEST_ASSERT_EQ(rcode, 0);
|
||||
vtProcessAndApplyReqs(pVnode, pMsgArr);
|
||||
vtClearMsgBatch(pMsgArr);
|
||||
|
||||
// 3. WRITE A LOT OF TIME-SERIES DATA
|
||||
|
@ -260,8 +273,7 @@ TEST(vnodeApiTest, vnode_simple_insert_test) {
|
|||
vtBuildSubmitReq(&pMsg);
|
||||
taosArrayPush(pMsgArr, &pMsg);
|
||||
}
|
||||
rcode = vnodeProcessWMsgs(pVnode, pMsgArr);
|
||||
GTEST_ASSERT_EQ(rcode, 0);
|
||||
vtProcessAndApplyReqs(pVnode, pMsgArr);
|
||||
vtClearMsgBatch(pMsgArr);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,7 @@
|
|||
*/
|
||||
|
||||
#include "tqInt.h"
|
||||
#include "osSocket.h"
|
||||
#include "tqMetaStore.h"
|
||||
#include "osAtomic.h"
|
||||
|
||||
// static
|
||||
// read next version data
|
||||
|
@ -61,15 +59,19 @@ STQ* tqOpen(const char* path, STqCfg* tqConfig, STqLogHandle* tqLogHandle, SMemA
|
|||
pTq->path = strdup(path);
|
||||
pTq->tqConfig = tqConfig;
|
||||
pTq->tqLogHandle = tqLogHandle;
|
||||
#if 0
|
||||
pTq->tqMemRef.pAllocatorFactory = allocFac;
|
||||
pTq->tqMemRef.pAllocator = allocFac->create(allocFac);
|
||||
if (pTq->tqMemRef.pAllocator == NULL) {
|
||||
// TODO: error code of buffer pool
|
||||
}
|
||||
#endif
|
||||
pTq->tqMeta = tqStoreOpen(path, (FTqSerialize)tqSerializeGroup, (FTqDeserialize)tqDeserializeGroup, free, 0);
|
||||
if (pTq->tqMeta == NULL) {
|
||||
free(pTq);
|
||||
#if 0
|
||||
allocFac->destroy(allocFac, pTq->tqMemRef.pAllocator);
|
||||
#endi
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -144,6 +146,7 @@ int tqCreateGroup(STQ* pTq, int64_t topicId, int64_t cgId, int64_t cId, STqGroup
|
|||
// TODO
|
||||
return -1;
|
||||
}
|
||||
*ppGroup = pGroup;
|
||||
memset(pGroup, 0, sizeof(STqGroup));
|
||||
|
||||
pGroup->topicList = tdListNew(sizeof(STqTopic));
|
||||
|
|
|
@ -1,10 +1,24 @@
|
|||
aux_source_directory(src TSDB_SRC)
|
||||
add_library(tsdb ${TSDB_SRC})
|
||||
if(0)
|
||||
add_library(tsdb ${TSDB_SRC})
|
||||
else(0)
|
||||
add_library(tsdb "")
|
||||
target_sources(tsdb
|
||||
PRIVATE
|
||||
"src/tsdbCommit.c"
|
||||
"src/tsdbMain.c"
|
||||
"src/tsdbMemTable.c"
|
||||
"src/tsdbOptions.c"
|
||||
"src/tsdbWrite.c"
|
||||
)
|
||||
endif(0)
|
||||
|
||||
target_include_directories(
|
||||
tsdb
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/dnode/vnode/tsdb"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
|
||||
target_link_libraries(
|
||||
tsdb
|
||||
PUBLIC os
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#ifndef _TD_TSDB_COMMIT_H_
|
||||
#define _TD_TSDB_COMMIT_H_
|
||||
|
||||
#if 0
|
||||
typedef struct {
|
||||
int minFid;
|
||||
int midFid;
|
||||
|
@ -53,5 +54,6 @@ static FORCE_INLINE int tsdbGetFidLevel(int fid, SRtn *pRtn) {
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TD_TSDB_COMMIT_H_ */
|
|
@ -19,8 +19,12 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
|
||||
void *tsdbCompactImpl(STsdbRepo *pRepo);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef _TD_TSDB_FS_H_
|
||||
#define _TD_TSDB_FS_H_
|
||||
|
||||
#if 0
|
||||
|
||||
#define TSDB_FS_VERSION 0
|
||||
|
||||
// ================== TSDB global config
|
||||
|
@ -113,4 +115,6 @@ static FORCE_INLINE int tsdbUnLockFS(STsdbFS* pFs) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _TD_TSDB_FS_H_ */
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef _TS_TSDB_FILE_H_
|
||||
#define _TS_TSDB_FILE_H_
|
||||
|
||||
#if 0
|
||||
|
||||
#define TSDB_FILE_HEAD_SIZE 512
|
||||
#define TSDB_FILE_DELIMITER 0xF00AFA0F
|
||||
#define TSDB_FILE_INIT_MAGIC 0xFFFFFFFF
|
||||
|
@ -364,4 +366,5 @@ static FORCE_INLINE bool tsdbFSetIsOk(SDFileSet* pSet) {
|
|||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* _TS_TSDB_FILE_H_ */
|
|
@ -16,10 +16,14 @@
|
|||
#ifndef _TD_TSDB_HEALTH_H_
|
||||
#define _TD_TSDB_HEALTH_H_
|
||||
|
||||
#if 0
|
||||
|
||||
bool tsdbUrgeQueryFree(STsdbRepo* pRepo);
|
||||
int32_t tsdbInsertNewBlock(STsdbRepo* pRepo);
|
||||
|
||||
bool tsdbIdleMemEnough();
|
||||
bool tsdbAllowNewBlock(STsdbRepo* pRepo);
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _TD_TSDB_BUFFER_H_ */
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#ifndef _TD_TSDB_READ_IMPL_H_
|
||||
#define _TD_TSDB_READ_IMPL_H_
|
||||
#if 0
|
||||
|
||||
#include "tfs.h"
|
||||
#include "tsdb.h"
|
||||
|
@ -150,4 +151,6 @@ static FORCE_INLINE int tsdbMakeRoom(void **ppBuf, size_t size) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /*_TD_TSDB_READ_IMPL_H_*/
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef TSDB_ROW_MERGE_BUF_H
|
||||
#define TSDB_ROW_MERGE_BUF_H
|
||||
|
||||
#if 0
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -42,4 +44,6 @@ static FORCE_INLINE void tsdbFreeMergeBuf(SMergeBuf buf) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* ifndef TSDB_ROW_MERGE_BUF_H */
|
|
@ -16,6 +16,7 @@
|
|||
#ifndef _TD_TSDB_INT_H_
|
||||
#define _TD_TSDB_INT_H_
|
||||
|
||||
#if 0
|
||||
// // TODO: remove the include
|
||||
// #include <errno.h>
|
||||
// #include <fcntl.h>
|
||||
|
@ -144,4 +145,5 @@ static FORCE_INLINE int tsdbGetNextMaxTables(int tid) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /* _TD_TSDB_INT_H_ */
|
File diff suppressed because it is too large
Load Diff
|
@ -1,14 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue